-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
110 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
admin/src/components/CKEditorInput/plugins/StrapiEditorUsageData.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createIntegrationUsageDataPlugin } from '@ckeditor/ckeditor5-integrations-common'; | ||
import * as pkg from '../../../../../package.json' | ||
|
||
export const StrapiEditorUsageDataPlugin = createIntegrationUsageDataPlugin( | ||
'strapi', | ||
{ | ||
version: pkg.version, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,54 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { memo, useEffect } from 'react'; | ||
import { useCKEditorCloud } from '@ckeditor/ckeditor5-react'; | ||
|
||
const CKEditorProvider = ( { | ||
attribute, | ||
onChange, | ||
name, | ||
value, | ||
disabled = false, | ||
labelAction = null, | ||
intlLabel, | ||
required = false, | ||
description = null, | ||
error = null | ||
} ) => { | ||
const [ importedEditor, setImportedEditor ] = useState( null ); | ||
|
||
attribute, | ||
onChange, | ||
name, | ||
value, | ||
disabled = false, | ||
labelAction = null, | ||
intlLabel, | ||
required = false, | ||
description = null, | ||
error = null } ) => { | ||
|
||
// Clean up CDN scripts after unmounting the component. | ||
useEffect( () => { | ||
const importEditor = async () => { | ||
const module = await import( '../CKEditorInput' ); | ||
const CKEditorInput = module.default; | ||
|
||
setImportedEditor(<CKEditorInput | ||
attribute={ attribute } | ||
onChange={ onChange } | ||
name={ name } | ||
value={ value } | ||
disabled={ disabled } | ||
labelAction={ labelAction } | ||
required={ required } | ||
description={ description } | ||
error={ error } | ||
intlLabel={ intlLabel } | ||
/> ); | ||
}; | ||
|
||
const injectAssetsFromCDN = setInterval( () => { | ||
const CDNScript = document.querySelector( '#ckeditor5-cdn-script' ); | ||
const CDNStyles = document.querySelector( '#ckeditor5-cdn-styles' ); | ||
|
||
if ( !CDNStyles ) { | ||
_injectStylesFromCDN(); | ||
} | ||
|
||
if ( window.CKEDITOR ) { | ||
window.CKEditorCDNLoaded = true; | ||
|
||
importEditor(); | ||
|
||
clearInterval( injectAssetsFromCDN ); | ||
|
||
return; | ||
} | ||
|
||
if ( !CDNScript ) { | ||
_injectScriptFromCDN(); | ||
|
||
} | ||
}, 100 ) | ||
|
||
return () => { | ||
const CDNScript = document.querySelector( '#ckeditor5-cdn-script' ); | ||
const assets = document.querySelectorAll( '[data-injected-by="ckeditor-integration"]' ); | ||
|
||
if ( CDNScript ) { | ||
CDNScript.remove(); | ||
} | ||
assets.forEach( asset => asset.remove() ); | ||
|
||
window.CKEditorCDNLoaded = false; | ||
window.CKEDITOR_VERSION = null; | ||
} | ||
}, [] ); | ||
}, [] ) | ||
|
||
return ( | ||
<> | ||
{ window.CKEditorCDNLoaded && importedEditor } | ||
</> | ||
) | ||
} | ||
|
||
function _injectStylesFromCDN() { | ||
const link = document.createElement( 'link' ); | ||
|
||
link.rel = 'stylesheet'; | ||
link.href = 'https://cdn.ckeditor.com/ckeditor5/43.0.0/ckeditor5.css'; | ||
link.id = 'ckeditor5-cdn-styles'; | ||
|
||
document.head.appendChild( link ); | ||
} | ||
|
||
function _injectScriptFromCDN() { | ||
const script = document.createElement( 'script' ); | ||
const cloud = useCKEditorCloud( { | ||
version: '44.0.0', | ||
plugins: { | ||
CKEditorInput: async () => ( await import('../CKEditorInput') ).CKEditorInput | ||
} | ||
} ); | ||
|
||
script.src = "https://cdn.ckeditor.com/ckeditor5/43.0.0/ckeditor5.umd.js"; | ||
script.async = true; | ||
script.id = 'ckeditor5-cdn-script' | ||
if ( cloud.status !== 'success' ) { | ||
return null; | ||
} | ||
|
||
document.body.appendChild( script ); | ||
return ( | ||
<cloud.loadedPlugins.CKEditorInput | ||
attribute={ attribute } | ||
onChange={ onChange } | ||
name={ name } | ||
value={ value } | ||
disabled={ disabled } | ||
labelAction={ labelAction } | ||
required={ required } | ||
description={ description } | ||
error={ error } | ||
intlLabel={ intlLabel } | ||
/> | ||
) | ||
} | ||
|
||
export default CKEditorProvider; | ||
export default memo( CKEditorProvider ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters