client: Use decoupled CKEditor

This commit is contained in:
Elian Doran 2024-11-09 09:43:30 +02:00
parent dd6e762dab
commit 4f39188198
No known key found for this signature in database
4 changed files with 29 additions and 19 deletions

View File

@ -2,43 +2,48 @@
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/ */
import { ClassicEditor as ClassicEditorBase } from '@ckeditor/ckeditor5-editor-classic'; import { DecoupledEditor as DecoupledEditorBase } from '@ckeditor/ckeditor5-editor-decoupled';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { Alignment } from '@ckeditor/ckeditor5-alignment';
import { FontSize, FontFamily, FontColor, FontBackgroundColor } from '@ckeditor/ckeditor5-font';
import { CKFinderUploadAdapter } from '@ckeditor/ckeditor5-adapter-ckfinder'; import { CKFinderUploadAdapter } from '@ckeditor/ckeditor5-adapter-ckfinder';
import { Autoformat } from '@ckeditor/ckeditor5-autoformat'; import { Autoformat } from '@ckeditor/ckeditor5-autoformat';
import { Bold, Italic } from '@ckeditor/ckeditor5-basic-styles'; import { Bold, Italic, Strikethrough, Underline } from '@ckeditor/ckeditor5-basic-styles';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote'; import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { CKBox } from '@ckeditor/ckeditor5-ckbox'; import { CKBox } from '@ckeditor/ckeditor5-ckbox';
import { CKFinder } from '@ckeditor/ckeditor5-ckfinder'; import { CKFinder } from '@ckeditor/ckeditor5-ckfinder';
import { EasyImage } from '@ckeditor/ckeditor5-easy-image'; import { EasyImage } from '@ckeditor/ckeditor5-easy-image';
import { Heading } from '@ckeditor/ckeditor5-heading'; import { Heading } from '@ckeditor/ckeditor5-heading';
import { Image, ImageCaption, ImageStyle, ImageToolbar, ImageUpload, PictureEditing } from '@ckeditor/ckeditor5-image'; import { Image, ImageCaption, ImageResize, ImageStyle, ImageToolbar, ImageUpload, PictureEditing } from '@ckeditor/ckeditor5-image';
import { Indent } from '@ckeditor/ckeditor5-indent'; import { Indent, IndentBlock } from '@ckeditor/ckeditor5-indent';
import { Link } from '@ckeditor/ckeditor5-link'; import { Link } from '@ckeditor/ckeditor5-link';
import { List } from '@ckeditor/ckeditor5-list'; import { List, ListProperties } from '@ckeditor/ckeditor5-list';
import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed'; import { MediaEmbed } from '@ckeditor/ckeditor5-media-embed';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph'; import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
import { PasteFromOffice } from '@ckeditor/ckeditor5-paste-from-office'; import { PasteFromOffice } from '@ckeditor/ckeditor5-paste-from-office';
import { Table, TableToolbar } from '@ckeditor/ckeditor5-table'; import { Table, TableToolbar } from '@ckeditor/ckeditor5-table';
import { TextTransformation, Typing } from '@ckeditor/ckeditor5-typing'; import { TextTransformation } from '@ckeditor/ckeditor5-typing';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services'; import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import { Enter, ShiftEnter } from '@ckeditor/ckeditor5-enter'; export default class DecoupledEditor extends DecoupledEditorBase {
import { SelectAll } from '@ckeditor/ckeditor5-select-all'; static builtinPlugins: (typeof TextTransformation | typeof Essentials | typeof Alignment | typeof FontBackgroundColor | typeof FontColor | typeof FontFamily | typeof FontSize | typeof CKFinderUploadAdapter | typeof Paragraph | typeof Heading | typeof Autoformat | typeof Bold | typeof Italic | typeof Strikethrough | typeof Underline | typeof BlockQuote | typeof Image | typeof ImageCaption | typeof ImageResize | typeof ImageStyle | typeof ImageToolbar | typeof ImageUpload | typeof CloudServices | typeof CKBox | typeof CKFinder | typeof EasyImage | typeof List | typeof ListProperties | typeof Indent | typeof IndentBlock | typeof Link | typeof MediaEmbed | typeof PasteFromOffice | typeof Table | typeof TableToolbar | typeof PictureEditing)[];
import { Undo } from '@ckeditor/ckeditor5-undo';
export default class ClassicEditor extends ClassicEditorBase {
static builtinPlugins: (typeof TextTransformation | typeof Typing | typeof Enter | typeof ShiftEnter | typeof SelectAll | typeof Undo | typeof CKFinderUploadAdapter | typeof Paragraph | typeof Heading | typeof Autoformat | typeof Bold | typeof Italic | typeof BlockQuote | typeof Image | typeof ImageCaption | typeof ImageStyle | typeof ImageToolbar | typeof ImageUpload | typeof CloudServices | typeof CKBox | typeof CKFinder | typeof EasyImage | typeof List | typeof Indent | typeof Link | typeof MediaEmbed | typeof PasteFromOffice | typeof Table | typeof TableToolbar | typeof PictureEditing | {
new (): Clipboard;
prototype: Clipboard;
})[];
static defaultConfig: { static defaultConfig: {
toolbar: { toolbar: {
items: string[]; items: string[];
}; };
image: { image: {
resizeUnit: "px";
toolbar: string[]; toolbar: string[];
}; };
table: { table: {
contentToolbar: string[]; contentToolbar: string[];
}; };
list: {
properties: {
styles: boolean;
startIndex: boolean;
reversed: boolean;
};
};
language: string; language: string;
}; };
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -133,7 +133,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
// display of $widget in both branches. // display of $widget in both branches.
this.$widget.show(); this.$widget.show();
this.watchdog = new EditorWatchdog(ClassicEditor, { this.watchdog = new EditorWatchdog(DecoupledEditor, {
// An average number of milliseconds between the last editor errors (defaults to 5000). // An average number of milliseconds between the last editor errors (defaults to 5000).
// When the period of time between errors is lower than that and the crashNumberLimit // When the period of time between errors is lower than that and the crashNumberLimit
// is also reached, the watchdog changes its state to crashedPermanently, and it stops // is also reached, the watchdog changes its state to crashedPermanently, and it stops
@ -169,10 +169,15 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
}); });
this.watchdog.setCreator(async (elementOrData, editorConfig) => { this.watchdog.setCreator(async (elementOrData, editorConfig) => {
const editor = await ClassicEditor.create(elementOrData, editorConfig); const editor = await DecoupledEditor.create(elementOrData, editorConfig);
await initSyntaxHighlighting(editor); await initSyntaxHighlighting(editor);
const $parentSplit = this.$widget.parents(".note-split.type-text");
const $classicToolbarWidget = $parentSplit.find("> .ribbon-container .classic-toolbar-widget");
$classicToolbarWidget.empty();
$classicToolbarWidget[0].appendChild(editor.ui.view.toolbar.element);
editor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate()); editor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate());
if (glob.isDev && ENABLE_INSPECTOR) { if (glob.isDev && ENABLE_INSPECTOR) {