-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cloud injector error reporting.
- Loading branch information
Showing
5 changed files
with
184 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
*/ | ||
|
||
import React, { type ReactNode } from 'react'; | ||
import type { Plugin } from 'ckeditor5'; | ||
|
||
import { getCKCdnClassicEditor } from './getCKCdnClassicEditor.js'; | ||
import { CKEditor, useCKEditorCloud } from '../../src/index.js'; | ||
|
||
type CKEditorCloudLocalPluginsDemoProps = { | ||
content: string; | ||
}; | ||
|
||
declare global { | ||
interface Window { | ||
MyLocalPlugin: typeof Plugin; | ||
} | ||
} | ||
|
||
export const CKEditorCloudLocalPluginsDemo = ( { content }: CKEditorCloudLocalPluginsDemoProps ): ReactNode => { | ||
const cloud = useCKEditorCloud( { | ||
version: '43.0.0', | ||
plugins: { | ||
MyLocalPlugin: [ | ||
'/demos/cdn-react/local-plugin.umd.js' | ||
] | ||
} | ||
} ); | ||
|
||
if ( cloud.status !== 'success' ) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
const CKEditorClassic = getCKCdnClassicEditor( { | ||
cloud, | ||
additionalPlugins: [ | ||
cloud.loadedPlugins.MyLocalPlugin | ||
], | ||
overrideConfig: { | ||
toolbar: { | ||
items: [ | ||
'highlight', | ||
'|', 'undo', 'redo', | ||
'|', 'heading', | ||
'|', 'bold', 'italic', | ||
'|', 'link', 'uploadImage', 'insertTable', 'blockQuote', 'mediaEmbed', | ||
'|', 'bulletedList', 'numberedList', 'outdent', 'indent', | ||
'|', 'MathType', 'ChemType' | ||
] | ||
} | ||
} | ||
} ); | ||
|
||
return ( | ||
<CKEditor | ||
editor={ CKEditorClassic } | ||
data={ content } | ||
/> | ||
); | ||
}; |
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,100 @@ | ||
/** | ||
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options | ||
*/ | ||
|
||
/* global window */ | ||
|
||
const { Plugin, Command, ButtonView } = window.CKEDITOR; | ||
|
||
class HighlightCommand extends Command { | ||
execute() { | ||
const model = this.editor.model; | ||
const selection = model.document.selection; | ||
|
||
model.change( writer => { | ||
const ranges = model.schema.getValidRanges( selection.getRanges(), 'highlight' ); | ||
|
||
for ( const range of ranges ) { | ||
if ( this.value ) { | ||
writer.removeAttribute( 'highlight', range ); | ||
} else { | ||
writer.setAttribute( 'highlight', true, range ); | ||
} | ||
} | ||
} ); | ||
} | ||
|
||
refresh() { | ||
const model = this.editor.model; | ||
const selection = model.document.selection; | ||
const isAllowed = model.schema.checkAttributeInSelection( selection, 'highlight' ); | ||
|
||
this.isEnabled = isAllowed; | ||
this.value = this.isHighlightedNodeSelected(); | ||
} | ||
|
||
isHighlightedNodeSelected() { | ||
const { model } = this.editor; | ||
const { schema } = model; | ||
const selection = model.document.selection; | ||
|
||
if ( selection.isCollapsed ) { | ||
return selection.hasAttribute( 'highlight' ); | ||
} | ||
|
||
return selection.getRanges().some( range => | ||
Array | ||
.from( range.getItems() ) | ||
.some( item => | ||
schema.checkAttribute( item, 'highlight' ) && | ||
item.hasAttribute( 'highlight' ) | ||
) | ||
); | ||
} | ||
} | ||
|
||
window.MyLocalPlugin = class MyCustomPlugin extends Plugin { | ||
static get pluginName() { | ||
return 'MyCustomPlugin'; | ||
} | ||
|
||
init() { | ||
const editor = this.editor; | ||
|
||
editor.model.schema.extend( '$text', { allowAttributes: 'highlight' } ); | ||
|
||
editor.conversion.attributeToElement( { | ||
model: 'highlight', | ||
view: { | ||
name: 'span', | ||
styles: { | ||
'background-color': 'yellow' | ||
} | ||
} | ||
} ); | ||
|
||
const command = new HighlightCommand( editor ); | ||
|
||
editor.commands.add( 'highlight', command ); | ||
|
||
editor.ui.componentFactory.add( 'highlight', locale => { | ||
const view = new ButtonView( locale ); | ||
|
||
view.bind( 'isOn' ).to( command, 'value' ); | ||
view.set( { | ||
label: 'Highlight', | ||
withText: true, | ||
tooltip: true | ||
} ); | ||
|
||
view.on( 'execute', () => { | ||
editor.execute( 'highlight' ); | ||
editor.editing.view.focus(); | ||
} ); | ||
|
||
return view; | ||
} ); | ||
} | ||
}; | ||
|
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