From 2f8b8f1bebc2119000ef52430077b2141fa81c72 Mon Sep 17 00:00:00 2001 From: Kuba Niegowski Date: Fri, 24 May 2024 11:16:42 +0200 Subject: [PATCH] The EditorWatchdog, ContextWatchdog, and Context classes are now exposed as static fields of the Editor class. --- packages/ckeditor5-core/package.json | 1 + packages/ckeditor5-core/src/editor/editor.ts | 22 +++++++++++++++++ .../ckeditor5-core/tests/editor/editor.js | 16 +++++++++++++ .../src/ballooneditor.ts | 24 ------------------- .../src/classiceditor.ts | 24 ------------------- .../src/decouplededitor.ts | 24 ------------------- .../src/inlineeditor.ts | 24 ------------------- .../src/multirooteditor.ts | 24 ------------------- 8 files changed, 39 insertions(+), 120 deletions(-) diff --git a/packages/ckeditor5-core/package.json b/packages/ckeditor5-core/package.json index 17e8cde4abc..0ccc0c4eb0d 100644 --- a/packages/ckeditor5-core/package.json +++ b/packages/ckeditor5-core/package.json @@ -26,6 +26,7 @@ "dependencies": { "@ckeditor/ckeditor5-engine": "41.4.2", "@ckeditor/ckeditor5-utils": "41.4.2", + "@ckeditor/ckeditor5-watchdog": "41.4.2", "lodash-es": "4.17.21" }, "devDependencies": { diff --git a/packages/ckeditor5-core/src/editor/editor.ts b/packages/ckeditor5-core/src/editor/editor.ts index 142836260a7..d60e7996c64 100644 --- a/packages/ckeditor5-core/src/editor/editor.ts +++ b/packages/ckeditor5-core/src/editor/editor.ts @@ -25,6 +25,7 @@ import { } from '@ckeditor/ckeditor5-engine'; import type { EditorUI } from '@ckeditor/ckeditor5-ui'; +import { ContextWatchdog, EditorWatchdog } from '@ckeditor/ckeditor5-watchdog'; import Context from '../context.js'; import PluginCollection from '../plugincollection.js'; @@ -642,6 +643,27 @@ export default abstract class Editor extends /* #__PURE__ */ ObservableMixin() { public static create( ...args: Array ): void { // eslint-disable-line @typescript-eslint/no-unused-vars throw new Error( 'This is an abstract method.' ); } + + /** + * The {@link module:core/context~Context} class. + * + * Exposed as static editor field for easier access in editor builds. + */ + public static Context = Context; + + /** + * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. + * + * Exposed as static editor field for easier access in editor builds. + */ + public static EditorWatchdog = EditorWatchdog; + + /** + * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. + * + * Exposed as static editor field for easier access in editor builds. + */ + public static ContextWatchdog = ContextWatchdog; } /** diff --git a/packages/ckeditor5-core/tests/editor/editor.js b/packages/ckeditor5-core/tests/editor/editor.js index 4882f449c00..3a53bf18c30 100644 --- a/packages/ckeditor5-core/tests/editor/editor.js +++ b/packages/ckeditor5-core/tests/editor/editor.js @@ -20,6 +20,8 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror.js'; import testUtils from '../../tests/_utils/utils.js'; import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model.js'; import Accessibility from '../../src/accessibility.js'; +import EditorWatchdog from '@ckeditor/ckeditor5-watchdog/src/editorwatchdog.js'; +import ContextWatchdog from '@ckeditor/ckeditor5-watchdog/src/contextwatchdog.js'; class TestEditor extends Editor { static create( config ) { @@ -1347,6 +1349,20 @@ describe( 'Editor', () => { } ); } ); } ); + + describe( 'static fields', () => { + it( 'Editor.Context', () => { + expect( Editor.Context ).to.equal( Context ); + } ); + + it( 'Editor.EditorWatchdog', () => { + expect( Editor.EditorWatchdog ).to.equal( EditorWatchdog ); + } ); + + it( 'Editor.ContextWatchdog', () => { + expect( Editor.ContextWatchdog ).to.equal( ContextWatchdog ); + } ); + } ); } ); function getPlugins( editor ) { diff --git a/packages/ckeditor5-editor-balloon/src/ballooneditor.ts b/packages/ckeditor5-editor-balloon/src/ballooneditor.ts index 998de604287..e8ce61c801c 100644 --- a/packages/ckeditor5-editor-balloon/src/ballooneditor.ts +++ b/packages/ckeditor5-editor-balloon/src/ballooneditor.ts @@ -9,7 +9,6 @@ import { Editor, - Context, ElementApiMixin, attachToForm, secureSourceElement, @@ -20,8 +19,6 @@ import { import { BalloonToolbar } from 'ckeditor5/src/ui.js'; import { CKEditorError, getDataFromElement } from 'ckeditor5/src/utils.js'; -import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog.js'; - import BalloonEditorUI from './ballooneditorui.js'; import BalloonEditorUIView from './ballooneditoruiview.js'; @@ -219,27 +216,6 @@ export default class BalloonEditor extends /* #__PURE__ */ ElementApiMixin( Edit ); } ); } - - /** - * The {@link module:core/context~Context} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static Context = Context; - - /** - * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static EditorWatchdog = EditorWatchdog; - - /** - * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static ContextWatchdog = ContextWatchdog; } function getInitialData( sourceElementOrData: HTMLElement | string ): string { diff --git a/packages/ckeditor5-editor-classic/src/classiceditor.ts b/packages/ckeditor5-editor-classic/src/classiceditor.ts index 8a833e401f0..2280a25fff7 100644 --- a/packages/ckeditor5-editor-classic/src/classiceditor.ts +++ b/packages/ckeditor5-editor-classic/src/classiceditor.ts @@ -12,7 +12,6 @@ import ClassicEditorUIView from './classiceditoruiview.js'; import { Editor, - Context, ElementApiMixin, attachToForm, type EditorConfig, @@ -20,8 +19,6 @@ import { } from 'ckeditor5/src/core.js'; import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils.js'; -import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog.js'; - import { isElement as _isElement } from 'lodash-es'; /** @@ -203,27 +200,6 @@ export default class ClassicEditor extends /* #__PURE__ */ ElementApiMixin( Edit ); } ); } - - /** - * The {@link module:core/context~Context} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static Context = Context; - - /** - * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static EditorWatchdog = EditorWatchdog; - - /** - * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static ContextWatchdog = ContextWatchdog; } function getInitialData( sourceElementOrData: HTMLElement | string ): string { diff --git a/packages/ckeditor5-editor-decoupled/src/decouplededitor.ts b/packages/ckeditor5-editor-decoupled/src/decouplededitor.ts index 1994fabe3de..6bdc7a4b4b4 100644 --- a/packages/ckeditor5-editor-decoupled/src/decouplededitor.ts +++ b/packages/ckeditor5-editor-decoupled/src/decouplededitor.ts @@ -9,7 +9,6 @@ import { Editor, - Context, ElementApiMixin, secureSourceElement, type EditorConfig, @@ -20,8 +19,6 @@ import { getDataFromElement } from 'ckeditor5/src/utils.js'; -import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog.js'; - import DecoupledEditorUI from './decouplededitorui.js'; import DecoupledEditorUIView from './decouplededitoruiview.js'; @@ -245,27 +242,6 @@ export default class DecoupledEditor extends /* #__PURE__ */ ElementApiMixin( Ed ); } ); } - - /** - * The {@link module:core/context~Context} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static Context = Context; - - /** - * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static EditorWatchdog = EditorWatchdog; - - /** - * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static ContextWatchdog = ContextWatchdog; } function getInitialData( sourceElementOrData: HTMLElement | string ): string { diff --git a/packages/ckeditor5-editor-inline/src/inlineeditor.ts b/packages/ckeditor5-editor-inline/src/inlineeditor.ts index 23b1df53582..e64afb710db 100644 --- a/packages/ckeditor5-editor-inline/src/inlineeditor.ts +++ b/packages/ckeditor5-editor-inline/src/inlineeditor.ts @@ -9,7 +9,6 @@ import { Editor, - Context, ElementApiMixin, attachToForm, secureSourceElement, @@ -18,8 +17,6 @@ import { } from 'ckeditor5/src/core.js'; import { getDataFromElement, CKEditorError } from 'ckeditor5/src/utils.js'; -import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog.js'; - import InlineEditorUI from './inlineeditorui.js'; import InlineEditorUIView from './inlineeditoruiview.js'; @@ -206,27 +203,6 @@ export default class InlineEditor extends /* #__PURE__ */ ElementApiMixin( Edito ); } ); } - - /** - * The {@link module:core/context~Context} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static Context = Context; - - /** - * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static EditorWatchdog = EditorWatchdog; - - /** - * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static ContextWatchdog = ContextWatchdog; } function getInitialData( sourceElementOrData: HTMLElement | string ): string { diff --git a/packages/ckeditor5-editor-multi-root/src/multirooteditor.ts b/packages/ckeditor5-editor-multi-root/src/multirooteditor.ts index b4970c1f20e..47ed4e173f1 100644 --- a/packages/ckeditor5-editor-multi-root/src/multirooteditor.ts +++ b/packages/ckeditor5-editor-multi-root/src/multirooteditor.ts @@ -9,7 +9,6 @@ import { Editor, - Context, secureSourceElement, type EditorConfig, type EditorReadyEvent @@ -24,8 +23,6 @@ import { type DecoratedMethodEvent } from 'ckeditor5/src/utils.js'; -import { ContextWatchdog, EditorWatchdog } from 'ckeditor5/src/watchdog.js'; - import MultiRootEditorUI from './multirooteditorui.js'; import MultiRootEditorUIView from './multirooteditoruiview.js'; @@ -886,27 +883,6 @@ export default class MultiRootEditor extends Editor { } ); } - /** - * The {@link module:core/context~Context} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static Context = Context; - - /** - * The {@link module:watchdog/editorwatchdog~EditorWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static EditorWatchdog = EditorWatchdog; - - /** - * The {@link module:watchdog/contextwatchdog~ContextWatchdog} class. - * - * Exposed as static editor field for easier access in editor builds. - */ - public static ContextWatchdog = ContextWatchdog; - /** * @internal */