@ckeditor/ckeditor5-core 47.6.1 → 48.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE.md +1 -1
  2. package/{src → dist}/editor/editorconfig.d.ts +295 -20
  3. package/dist/editor/utils/normalizerootsconfig.d.ts +50 -0
  4. package/dist/index-content.css +10 -10
  5. package/dist/index-editor.css +5 -5
  6. package/dist/index.css +10 -16
  7. package/dist/index.css.map +1 -1
  8. package/{src → dist}/index.d.ts +2 -1
  9. package/dist/index.js +161 -6
  10. package/dist/index.js.map +1 -1
  11. package/package.json +23 -43
  12. package/lang/contexts.json +0 -38
  13. package/lang/translations/af.po +0 -156
  14. package/lang/translations/ar.po +0 -156
  15. package/lang/translations/ast.po +0 -156
  16. package/lang/translations/az.po +0 -156
  17. package/lang/translations/be.po +0 -156
  18. package/lang/translations/bg.po +0 -156
  19. package/lang/translations/bn.po +0 -156
  20. package/lang/translations/bs.po +0 -156
  21. package/lang/translations/ca.po +0 -156
  22. package/lang/translations/cs.po +0 -156
  23. package/lang/translations/da.po +0 -156
  24. package/lang/translations/de-ch.po +0 -156
  25. package/lang/translations/de.po +0 -156
  26. package/lang/translations/el.po +0 -156
  27. package/lang/translations/en-au.po +0 -156
  28. package/lang/translations/en-gb.po +0 -156
  29. package/lang/translations/en.po +0 -156
  30. package/lang/translations/eo.po +0 -156
  31. package/lang/translations/es-co.po +0 -156
  32. package/lang/translations/es.po +0 -156
  33. package/lang/translations/et.po +0 -156
  34. package/lang/translations/eu.po +0 -156
  35. package/lang/translations/fa.po +0 -156
  36. package/lang/translations/fi.po +0 -156
  37. package/lang/translations/fr.po +0 -156
  38. package/lang/translations/gl.po +0 -156
  39. package/lang/translations/gu.po +0 -156
  40. package/lang/translations/he.po +0 -156
  41. package/lang/translations/hi.po +0 -156
  42. package/lang/translations/hr.po +0 -156
  43. package/lang/translations/hu.po +0 -156
  44. package/lang/translations/hy.po +0 -156
  45. package/lang/translations/id.po +0 -156
  46. package/lang/translations/it.po +0 -156
  47. package/lang/translations/ja.po +0 -156
  48. package/lang/translations/jv.po +0 -156
  49. package/lang/translations/kk.po +0 -156
  50. package/lang/translations/km.po +0 -156
  51. package/lang/translations/kn.po +0 -156
  52. package/lang/translations/ko.po +0 -156
  53. package/lang/translations/ku.po +0 -156
  54. package/lang/translations/lt.po +0 -156
  55. package/lang/translations/lv.po +0 -156
  56. package/lang/translations/ms.po +0 -156
  57. package/lang/translations/nb.po +0 -156
  58. package/lang/translations/ne.po +0 -156
  59. package/lang/translations/nl.po +0 -156
  60. package/lang/translations/no.po +0 -156
  61. package/lang/translations/oc.po +0 -156
  62. package/lang/translations/pl.po +0 -156
  63. package/lang/translations/pt-br.po +0 -156
  64. package/lang/translations/pt.po +0 -156
  65. package/lang/translations/ro.po +0 -156
  66. package/lang/translations/ru.po +0 -156
  67. package/lang/translations/si.po +0 -156
  68. package/lang/translations/sk.po +0 -156
  69. package/lang/translations/sl.po +0 -156
  70. package/lang/translations/sq.po +0 -156
  71. package/lang/translations/sr-latn.po +0 -156
  72. package/lang/translations/sr.po +0 -156
  73. package/lang/translations/sv.po +0 -156
  74. package/lang/translations/th.po +0 -156
  75. package/lang/translations/ti.po +0 -156
  76. package/lang/translations/tk.po +0 -156
  77. package/lang/translations/tr.po +0 -156
  78. package/lang/translations/tt.po +0 -156
  79. package/lang/translations/ug.po +0 -156
  80. package/lang/translations/uk.po +0 -156
  81. package/lang/translations/ur.po +0 -156
  82. package/lang/translations/uz.po +0 -156
  83. package/lang/translations/vi.po +0 -156
  84. package/lang/translations/zh-cn.po +0 -156
  85. package/lang/translations/zh.po +0 -156
  86. package/src/accessibility.js +0 -332
  87. package/src/augmentation.js +0 -5
  88. package/src/command.js +0 -221
  89. package/src/commandcollection.js +0 -87
  90. package/src/context.js +0 -315
  91. package/src/contextplugin.js +0 -59
  92. package/src/editingkeystrokehandler.js +0 -61
  93. package/src/editor/editor.js +0 -1010
  94. package/src/editor/editorconfig.js +0 -5
  95. package/src/editor/utils/attachtoform.js +0 -57
  96. package/src/editor/utils/editorusagedata.js +0 -127
  97. package/src/editor/utils/elementapimixin.js +0 -42
  98. package/src/editor/utils/securesourceelement.js +0 -35
  99. package/src/index.js +0 -22
  100. package/src/multicommand.js +0 -79
  101. package/src/pendingactions.js +0 -127
  102. package/src/plugin.js +0 -132
  103. package/src/plugincollection.js +0 -506
  104. package/src/typings.js +0 -5
  105. package/theme/core.css +0 -21
  106. /package/{src → dist}/accessibility.d.ts +0 -0
  107. /package/{src → dist}/augmentation.d.ts +0 -0
  108. /package/{src → dist}/command.d.ts +0 -0
  109. /package/{src → dist}/commandcollection.d.ts +0 -0
  110. /package/{src → dist}/context.d.ts +0 -0
  111. /package/{src → dist}/contextplugin.d.ts +0 -0
  112. /package/{src → dist}/editingkeystrokehandler.d.ts +0 -0
  113. /package/{src → dist}/editor/editor.d.ts +0 -0
  114. /package/{src → dist}/editor/utils/attachtoform.d.ts +0 -0
  115. /package/{src → dist}/editor/utils/editorusagedata.d.ts +0 -0
  116. /package/{src → dist}/editor/utils/elementapimixin.d.ts +0 -0
  117. /package/{src → dist}/editor/utils/securesourceelement.d.ts +0 -0
  118. /package/{src → dist}/multicommand.d.ts +0 -0
  119. /package/{src → dist}/pendingactions.d.ts +0 -0
  120. /package/{src → dist}/plugin.d.ts +0 -0
  121. /package/{src → dist}/plugincollection.d.ts +0 -0
  122. /package/{src → dist}/typings.d.ts +0 -0
package/src/command.js DELETED
@@ -1,221 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module core/command
7
- */
8
- import { ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * Base class for the CKEditor commands.
11
- *
12
- * Commands are the main way to manipulate the editor contents and state. They are mostly used by UI elements (or by other
13
- * commands) to make changes in the model. Commands are available in every part of the code that has access to
14
- * the {@link module:core/editor/editor~Editor editor} instance.
15
- *
16
- * Instances of registered commands can be retrieved from {@link module:core/editor/editor~Editor#commands `editor.commands`}.
17
- * The easiest way to execute a command is through {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
18
- *
19
- * By default, commands are disabled when the editor is in the {@link module:core/editor/editor~Editor#isReadOnly read-only} mode
20
- * but commands with the {@link module:core/command~Command#affectsData `affectsData`} flag set to `false` will not be disabled.
21
- */
22
- export class Command extends /* #__PURE__ */ ObservableMixin() {
23
- /**
24
- * The editor on which this command will be used.
25
- */
26
- editor;
27
- /**
28
- * A flag indicating whether a command's `isEnabled` state should be changed depending on where the document
29
- * selection is placed.
30
- *
31
- * By default, it is set to `true`. If the document selection is placed in a
32
- * {@link module:engine/model/model~Model#canEditAt non-editable} place (such as non-editable root), the command becomes disabled.
33
- *
34
- * The flag should be changed to `false` in a concrete command's constructor if the command should not change its `isEnabled`
35
- * accordingly to the document selection.
36
- */
37
- _isEnabledBasedOnSelection;
38
- /**
39
- * A flag indicating whether a command execution changes the editor data or not.
40
- *
41
- * @see #affectsData
42
- */
43
- _affectsData;
44
- /**
45
- * Holds identifiers for {@link #forceDisabled} mechanism.
46
- */
47
- _disableStack;
48
- /**
49
- * `Command` class is commonly put in `config.plugins` array.
50
- *
51
- * This property helps with better error detection.
52
- *
53
- * @internal
54
- */
55
- static get _throwErrorWhenUsedAsAPlugin() {
56
- return true;
57
- }
58
- ;
59
- /**
60
- * Creates a new `Command` instance.
61
- *
62
- * @param editor The editor on which this command will be used.
63
- */
64
- constructor(editor) {
65
- super();
66
- this.editor = editor;
67
- this.set('value', undefined);
68
- this.set('isEnabled', false);
69
- this._affectsData = true;
70
- this._isEnabledBasedOnSelection = true;
71
- this._disableStack = new Set();
72
- this.decorate('execute');
73
- // By default, every command is refreshed when changes are applied to the model.
74
- this.listenTo(this.editor.model.document, 'change', () => {
75
- this.refresh();
76
- });
77
- this.listenTo(editor, 'change:isReadOnly', () => {
78
- this.refresh();
79
- });
80
- // By default, commands are disabled if the selection is in non-editable place or editor is in read-only mode.
81
- this.on('set:isEnabled', evt => {
82
- if (!this.affectsData) {
83
- return;
84
- }
85
- const selection = editor.model.document.selection;
86
- const selectionInGraveyard = selection.getFirstPosition().root.rootName == '$graveyard';
87
- const canEditAtSelection = !selectionInGraveyard && editor.model.canEditAt(selection);
88
- // Disable if editor is read only, or when selection is in a place which cannot be edited.
89
- //
90
- // Checking `editor.isReadOnly` is needed for all commands that have `_isEnabledBasedOnSelection == false`.
91
- // E.g. undo does not base on selection, but affects data and should be disabled when the editor is in read-only mode.
92
- if (editor.isReadOnly || this._isEnabledBasedOnSelection && !canEditAtSelection) {
93
- evt.return = false;
94
- evt.stop();
95
- }
96
- }, { priority: 'highest' });
97
- this.on('execute', evt => {
98
- if (!this.isEnabled) {
99
- evt.stop();
100
- }
101
- }, { priority: 'high' });
102
- }
103
- /**
104
- * A flag indicating whether a command execution changes the editor data or not.
105
- *
106
- * Commands with `affectsData` set to `false` will not be automatically disabled in
107
- * the {@link module:core/editor/editor~Editor#isReadOnly read-only mode} and
108
- * {@glink features/read-only#related-features other editor modes} with restricted user write permissions.
109
- *
110
- * **Note:** You do not have to set it for your every command. It is `true` by default.
111
- *
112
- * @default true
113
- */
114
- get affectsData() {
115
- return this._affectsData;
116
- }
117
- set affectsData(affectsData) {
118
- this._affectsData = affectsData;
119
- }
120
- /**
121
- * Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
122
- * in this method.
123
- *
124
- * This method is automatically called when
125
- * {@link module:engine/model/document~ModelDocument#event:change any changes are applied to the document}.
126
- */
127
- refresh() {
128
- this.isEnabled = true;
129
- }
130
- /**
131
- * Disables the command.
132
- *
133
- * Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
134
- * (e.g. the feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
135
- * The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
136
- *
137
- * Disabling and enabling a command:
138
- *
139
- * ```ts
140
- * command.isEnabled; // -> true
141
- * command.forceDisabled( 'MyFeature' );
142
- * command.isEnabled; // -> false
143
- * command.clearForceDisabled( 'MyFeature' );
144
- * command.isEnabled; // -> true
145
- * ```
146
- *
147
- * Command disabled by multiple features:
148
- *
149
- * ```ts
150
- * command.forceDisabled( 'MyFeature' );
151
- * command.forceDisabled( 'OtherFeature' );
152
- * command.clearForceDisabled( 'MyFeature' );
153
- * command.isEnabled; // -> false
154
- * command.clearForceDisabled( 'OtherFeature' );
155
- * command.isEnabled; // -> true
156
- * ```
157
- *
158
- * Multiple disabling with the same identifier is redundant:
159
- *
160
- * ```ts
161
- * command.forceDisabled( 'MyFeature' );
162
- * command.forceDisabled( 'MyFeature' );
163
- * command.clearForceDisabled( 'MyFeature' );
164
- * command.isEnabled; // -> true
165
- * ```
166
- *
167
- * **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
168
- * so the command might be still disabled after {@link #clearForceDisabled} was used.
169
- *
170
- * @param id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
171
- */
172
- forceDisabled(id) {
173
- this._disableStack.add(id);
174
- if (this._disableStack.size == 1) {
175
- this.on('set:isEnabled', forceDisable, { priority: 'highest' });
176
- this.isEnabled = false;
177
- }
178
- }
179
- /**
180
- * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
181
- *
182
- * @param id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
183
- */
184
- clearForceDisabled(id) {
185
- this._disableStack.delete(id);
186
- if (this._disableStack.size == 0) {
187
- this.off('set:isEnabled', forceDisable);
188
- this.refresh();
189
- }
190
- }
191
- /**
192
- * Executes the command.
193
- *
194
- * A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
195
- * to the command.
196
- *
197
- * The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
198
- * This behavior is implemented by a high priority listener to the {@link #event:execute} event.
199
- *
200
- * In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
201
- *
202
- * This method may return a value, which would be forwarded all the way down to the
203
- * {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
204
- *
205
- * @fires execute
206
- */
207
- execute(...args) { return undefined; } // eslint-disable-line @typescript-eslint/no-unused-vars
208
- /**
209
- * Destroys the command.
210
- */
211
- destroy() {
212
- this.stopListening();
213
- }
214
- }
215
- /**
216
- * Helper function that forces command to be disabled.
217
- */
218
- function forceDisable(evt) {
219
- evt.return = false;
220
- evt.stop();
221
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module core/commandcollection
7
- */
8
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
11
- */
12
- export class CommandCollection {
13
- /**
14
- * Command map.
15
- */
16
- _commands;
17
- /**
18
- * Creates collection instance.
19
- */
20
- constructor() {
21
- this._commands = new Map();
22
- }
23
- /**
24
- * Registers a new command.
25
- *
26
- * @param commandName The name of the command.
27
- */
28
- add(commandName, command) {
29
- this._commands.set(commandName, command);
30
- }
31
- /**
32
- * Retrieves a command from the collection.
33
- *
34
- * @param commandName The name of the command.
35
- */
36
- get(commandName) {
37
- return this._commands.get(commandName);
38
- }
39
- /**
40
- * Executes a command.
41
- *
42
- * @param commandName The name of the command.
43
- * @param commandParams Command parameters.
44
- * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
45
- */
46
- execute(commandName, ...commandParams) {
47
- const command = this.get(commandName);
48
- if (!command) {
49
- /**
50
- * Command does not exist.
51
- *
52
- * @error commandcollection-command-not-found
53
- * @param {string} commandName Name of the command.
54
- */
55
- throw new CKEditorError('commandcollection-command-not-found', this, { commandName });
56
- }
57
- return command.execute(...commandParams);
58
- }
59
- /**
60
- * Returns iterator of command names.
61
- */
62
- *names() {
63
- yield* this._commands.keys();
64
- }
65
- /**
66
- * Returns iterator of command instances.
67
- */
68
- *commands() {
69
- yield* this._commands.values();
70
- }
71
- /**
72
- * Iterable interface.
73
- *
74
- * Returns `[ commandName, commandInstance ]` pairs.
75
- */
76
- [Symbol.iterator]() {
77
- return this._commands[Symbol.iterator]();
78
- }
79
- /**
80
- * Destroys all collection commands.
81
- */
82
- destroy() {
83
- for (const command of this.commands()) {
84
- command.destroy();
85
- }
86
- }
87
- }
package/src/context.js DELETED
@@ -1,315 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module core/context
7
- */
8
- import { Config, Collection, CKEditorError, Locale } from '@ckeditor/ckeditor5-utils';
9
- import { PluginCollection } from './plugincollection.js';
10
- /**
11
- * Provides a common, higher-level environment for solutions that use multiple {@link module:core/editor/editor~Editor editors}
12
- * or plugins that work outside the editor. Use it instead of {@link module:core/editor/editor~Editor.create `Editor.create()`}
13
- * in advanced application integrations.
14
- *
15
- * All configuration options passed to a context will be used as default options for the editor instances initialized in that context.
16
- *
17
- * {@link module:core/contextplugin~ContextPlugin Context plugins} passed to a context instance will be shared among all
18
- * editor instances initialized in this context. These will be the same plugin instances for all the editors.
19
- *
20
- * **Note:** The context can only be initialized with {@link module:core/contextplugin~ContextPlugin context plugins}
21
- * (e.g. [comments](https://ckeditor.com/collaboration/comments/)). Regular {@link module:core/plugin~Plugin plugins} require an
22
- * editor instance to work and cannot be added to a context.
23
- *
24
- * **Note:** You can add a context plugin to an editor instance, though.
25
- *
26
- * If you are using multiple editor instances on one page and use any context plugins, create a context to share the configuration and
27
- * plugins among these editors. Some plugins will use the information about all existing editors to better integrate between them.
28
- *
29
- * If you are using plugins that do not require an editor to work (e.g. [comments](https://ckeditor.com/collaboration/comments/)),
30
- * enable and configure them using the context.
31
- *
32
- * If you are using only a single editor on each page, use {@link module:core/editor/editor~Editor.create `Editor.create()`} instead.
33
- * In such a case, a context instance will be created by the editor instance in a transparent way.
34
- *
35
- * See {@link ~Context.create `Context.create()`} for usage examples.
36
- */
37
- export class Context {
38
- /**
39
- * Stores all the configurations specific to this context instance.
40
- */
41
- config;
42
- /**
43
- * The plugins loaded and in use by this context instance.
44
- */
45
- plugins;
46
- locale;
47
- /**
48
- * Shorthand for {@link module:utils/locale~Locale#t}.
49
- */
50
- t;
51
- /**
52
- * A list of editors that this context instance is injected to.
53
- */
54
- editors;
55
- /**
56
- * The default configuration which is built into the `Context` class.
57
- *
58
- * It was used in the now deprecated CKEditor 5 builds featuring `Context` to provide the default configuration options
59
- * which are later used during the context initialization.
60
- *
61
- * ```ts
62
- * Context.defaultConfig = {
63
- * foo: 1,
64
- * bar: 2
65
- * };
66
- *
67
- * Context
68
- * .create()
69
- * .then( context => {
70
- * context.config.get( 'foo' ); // -> 1
71
- * context.config.get( 'bar' ); // -> 2
72
- * } );
73
- *
74
- * // The default options can be overridden by the configuration passed to create().
75
- * Context
76
- * .create( { bar: 3 } )
77
- * .then( context => {
78
- * context.config.get( 'foo' ); // -> 1
79
- * context.config.get( 'bar' ); // -> 3
80
- * } );
81
- * ```
82
- *
83
- * See also {@link module:core/context~Context.builtinPlugins `Context.builtinPlugins`}
84
- * and {@link module:core/editor/editor~Editor.defaultConfig `Editor.defaultConfig`}.
85
- */
86
- static defaultConfig;
87
- /**
88
- * An array of plugins built into the `Context` class.
89
- *
90
- * It was used in the now deprecated CKEditor 5 builds featuring `Context` to provide the default configuration options
91
- * which are later used during the context initialization.
92
- *
93
- * They will be automatically initialized by `Context` unless `config.plugins` is passed.
94
- *
95
- * ```ts
96
- * // Build some context plugins into the Context class first.
97
- * Context.builtinPlugins = [ FooPlugin, BarPlugin ];
98
- *
99
- * // Normally, you need to define config.plugins, but since Context.builtinPlugins was
100
- * // defined, now you can call create() without any configuration.
101
- * Context
102
- * .create()
103
- * .then( context => {
104
- * context.plugins.get( FooPlugin ); // -> An instance of the Foo plugin.
105
- * context.plugins.get( BarPlugin ); // -> An instance of the Bar plugin.
106
- * } );
107
- * ```
108
- *
109
- * See also {@link module:core/context~Context.defaultConfig `Context.defaultConfig`}
110
- * and {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}.
111
- */
112
- static builtinPlugins;
113
- /**
114
- * Reference to the editor which created the context.
115
- * Null when the context was created outside of the editor.
116
- *
117
- * It is used to destroy the context when removing the editor that has created the context.
118
- */
119
- _contextOwner = null;
120
- /**
121
- * Creates a context instance with a given configuration.
122
- *
123
- * Usually not to be used directly. See the static {@link module:core/context~Context.create `create()`} method.
124
- *
125
- * @param config The context configuration.
126
- */
127
- constructor(config) {
128
- // We don't pass translations to the config, because its behavior of splitting keys
129
- // with dots (e.g. `resize.width` => `resize: { width }`) breaks the translations.
130
- const { translations, ...rest } = config || {};
131
- this.config = new Config(rest, this.constructor.defaultConfig);
132
- const availablePlugins = this.constructor.builtinPlugins;
133
- this.config.define('plugins', availablePlugins);
134
- this.plugins = new PluginCollection(this, availablePlugins);
135
- const languageConfig = this.config.get('language') || {};
136
- this.locale = new Locale({
137
- uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
138
- contentLanguage: this.config.get('language.content'),
139
- translations
140
- });
141
- this.t = this.locale.t;
142
- this.editors = new Collection();
143
- }
144
- /**
145
- * Loads and initializes plugins specified in the configuration.
146
- *
147
- * @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
148
- */
149
- initPlugins() {
150
- const plugins = this.config.get('plugins') || [];
151
- const substitutePlugins = this.config.get('substitutePlugins') || [];
152
- // Plugins for substitution should be checked as well.
153
- for (const Plugin of plugins.concat(substitutePlugins)) {
154
- if (typeof Plugin != 'function') {
155
- /**
156
- * Only a constructor function is allowed as a {@link module:core/contextplugin~ContextPlugin context plugin}.
157
- *
158
- * @error context-initplugins-constructor-only
159
- */
160
- throw new CKEditorError('context-initplugins-constructor-only', null, { Plugin });
161
- }
162
- if (Plugin.isContextPlugin !== true) {
163
- /**
164
- * Only a plugin marked as a {@link module:core/contextplugin~ContextPlugin.isContextPlugin context plugin}
165
- * is allowed to be used with a context.
166
- *
167
- * @error context-initplugins-invalid-plugin
168
- */
169
- throw new CKEditorError('context-initplugins-invalid-plugin', null, { Plugin });
170
- }
171
- }
172
- return this.plugins.init(plugins, [], substitutePlugins);
173
- }
174
- /**
175
- * Destroys the context instance and all editors used with the context,
176
- * releasing all resources used by the context.
177
- *
178
- * @returns A promise that resolves once the context instance is fully destroyed.
179
- */
180
- destroy() {
181
- return Promise.all(Array.from(this.editors, editor => editor.destroy()))
182
- .then(() => this.plugins.destroy());
183
- }
184
- /**
185
- * Adds a reference to the editor which is used with this context.
186
- *
187
- * When the given editor has created the context, the reference to this editor will be stored
188
- * as a {@link ~Context#_contextOwner}.
189
- *
190
- * This method should only be used by the editor.
191
- *
192
- * @internal
193
- * @param isContextOwner Stores the given editor as a context owner.
194
- */
195
- _addEditor(editor, isContextOwner) {
196
- if (this._contextOwner) {
197
- /**
198
- * Cannot add multiple editors to the context which is created by the editor.
199
- *
200
- * @error context-addeditor-private-context
201
- */
202
- throw new CKEditorError('context-addeditor-private-context');
203
- }
204
- this.editors.add(editor);
205
- if (isContextOwner) {
206
- this._contextOwner = editor;
207
- }
208
- }
209
- /**
210
- * Removes a reference to the editor which was used with this context.
211
- * When the context was created by the given editor, the context will be destroyed.
212
- *
213
- * This method should only be used by the editor.
214
- *
215
- * @internal
216
- * @return A promise that resolves once the editor is removed from the context or when the context was destroyed.
217
- */
218
- _removeEditor(editor) {
219
- if (this.editors.has(editor)) {
220
- this.editors.remove(editor);
221
- }
222
- if (this._contextOwner === editor) {
223
- return this.destroy();
224
- }
225
- return Promise.resolve();
226
- }
227
- /**
228
- * Returns the context configuration which will be copied to the editors created using this context.
229
- *
230
- * The configuration returned by this method has the plugins configuration removed – plugins are shared with all editors
231
- * through another mechanism.
232
- *
233
- * This method should only be used by the editor.
234
- *
235
- * @internal
236
- * @returns Configuration as a plain object.
237
- */
238
- _getEditorConfig() {
239
- const result = {};
240
- for (const name of this.config.names()) {
241
- if (!['plugins', 'removePlugins', 'extraPlugins'].includes(name)) {
242
- result[name] = this.config.get(name);
243
- }
244
- }
245
- return result;
246
- }
247
- /**
248
- * Creates and initializes a new context instance.
249
- *
250
- * ```ts
251
- * const commonConfig = { ... }; // Configuration for all the plugins and editors.
252
- * const editorPlugins = [ ... ]; // Regular plugins here.
253
- *
254
- * Context
255
- * .create( {
256
- * // Only context plugins here.
257
- * plugins: [ ... ],
258
- *
259
- * // Configure the language for all the editors (it cannot be overwritten).
260
- * language: { ... },
261
- *
262
- * // Configuration for context plugins.
263
- * comments: { ... },
264
- * ...
265
- *
266
- * // Default configuration for editor plugins.
267
- * toolbar: { ... },
268
- * image: { ... },
269
- * ...
270
- * } )
271
- * .then( context => {
272
- * const promises = [];
273
- *
274
- * promises.push( ClassicEditor.create(
275
- * document.getElementById( 'editor1' ),
276
- * {
277
- * editorPlugins,
278
- * context
279
- * }
280
- * ) );
281
- *
282
- * promises.push( ClassicEditor.create(
283
- * document.getElementById( 'editor2' ),
284
- * {
285
- * editorPlugins,
286
- * context,
287
- * toolbar: { ... } // You can overwrite the configuration of the context.
288
- * }
289
- * ) );
290
- *
291
- * return Promise.all( promises );
292
- * } );
293
- * ```
294
- *
295
- * @param config The context configuration.
296
- * @returns A promise resolved once the context is ready. The promise resolves with the created context instance.
297
- */
298
- static create(config) {
299
- return new Promise(resolve => {
300
- const context = new this(config);
301
- resolve(context.initPlugins().then(() => context));
302
- });
303
- }
304
- /**
305
- * `Context` class is commonly put in `config.plugins` array.
306
- *
307
- * This property helps with better error detection.
308
- *
309
- * @internal
310
- */
311
- static get _throwErrorWhenUsedAsAPlugin() {
312
- return true;
313
- }
314
- ;
315
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module core/contextplugin
7
- */
8
- import { ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * The base class for {@link module:core/context~Context} plugin classes.
11
- *
12
- * A context plugin can either be initialized for an {@link module:core/editor/editor~Editor editor} or for
13
- * a {@link module:core/context~Context context}. In other words, it can either
14
- * work within one editor instance or with one or more editor instances that use a single context.
15
- * It is the context plugin's role to implement handling for both modes.
16
- *
17
- * There are a few rules for interaction between the editor plugins and context plugins:
18
- *
19
- * * A context plugin can require another context plugin.
20
- * * An {@link module:core/plugin~Plugin editor plugin} can require a context plugin.
21
- * * A context plugin MUST NOT require an {@link module:core/plugin~Plugin editor plugin}.
22
- */
23
- export class ContextPlugin extends /* #__PURE__ */ ObservableMixin() {
24
- /**
25
- * The context or editor instance.
26
- */
27
- context;
28
- /**
29
- * Creates a new plugin instance.
30
- */
31
- constructor(context) {
32
- super();
33
- this.context = context;
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- destroy() {
39
- this.stopListening();
40
- }
41
- /**
42
- * @inheritDoc
43
- */
44
- static get isContextPlugin() {
45
- return true;
46
- }
47
- /**
48
- * @inheritDoc
49
- */
50
- static get isOfficialPlugin() {
51
- return false;
52
- }
53
- /**
54
- * @inheritDoc
55
- */
56
- static get isPremiumPlugin() {
57
- return false;
58
- }
59
- }