@ckeditor/ckeditor5-core 40.0.0 → 40.2.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.
- package/CHANGELOG.md +28 -28
- package/LICENSE.md +3 -3
- package/README.md +1 -1
- package/lang/contexts.json +5 -1
- package/lang/translations/af.po +16 -0
- package/lang/translations/ar.po +16 -0
- package/lang/translations/ast.po +16 -0
- package/lang/translations/az.po +16 -0
- package/lang/translations/bg.po +16 -0
- package/lang/translations/bn.po +16 -0
- package/lang/translations/bs.po +16 -0
- package/lang/translations/ca.po +16 -0
- package/lang/translations/cs.po +16 -0
- package/lang/translations/da.po +16 -0
- package/lang/translations/de-ch.po +16 -0
- package/lang/translations/de.po +16 -0
- package/lang/translations/el.po +16 -0
- package/lang/translations/en-au.po +16 -0
- package/lang/translations/en-gb.po +16 -0
- package/lang/translations/en.po +16 -0
- package/lang/translations/eo.po +16 -0
- package/lang/translations/es-co.po +16 -0
- package/lang/translations/es.po +16 -0
- package/lang/translations/et.po +16 -0
- package/lang/translations/eu.po +16 -0
- package/lang/translations/fa.po +16 -0
- package/lang/translations/fi.po +16 -0
- package/lang/translations/fr.po +16 -0
- package/lang/translations/gl.po +16 -0
- package/lang/translations/gu.po +16 -0
- package/lang/translations/he.po +16 -0
- package/lang/translations/hi.po +16 -0
- package/lang/translations/hr.po +16 -0
- package/lang/translations/hu.po +16 -0
- package/lang/translations/hy.po +16 -0
- package/lang/translations/id.po +16 -0
- package/lang/translations/it.po +16 -0
- package/lang/translations/ja.po +16 -0
- package/lang/translations/jv.po +16 -0
- package/lang/translations/km.po +16 -0
- package/lang/translations/kn.po +16 -0
- package/lang/translations/ko.po +16 -0
- package/lang/translations/ku.po +16 -0
- package/lang/translations/lt.po +16 -0
- package/lang/translations/lv.po +16 -0
- package/lang/translations/ms.po +16 -0
- package/lang/translations/nb.po +16 -0
- package/lang/translations/ne.po +16 -0
- package/lang/translations/nl.po +16 -0
- package/lang/translations/no.po +16 -0
- package/lang/translations/oc.po +16 -0
- package/lang/translations/pl.po +16 -0
- package/lang/translations/pt-br.po +16 -0
- package/lang/translations/pt.po +16 -0
- package/lang/translations/ro.po +16 -0
- package/lang/translations/ru.po +16 -0
- package/lang/translations/si.po +16 -0
- package/lang/translations/sk.po +16 -0
- package/lang/translations/sl.po +16 -0
- package/lang/translations/sq.po +16 -0
- package/lang/translations/sr-latn.po +17 -1
- package/lang/translations/sr.po +16 -0
- package/lang/translations/sv.po +16 -0
- package/lang/translations/th.po +16 -0
- package/lang/translations/tk.po +16 -0
- package/lang/translations/tr.po +16 -0
- package/lang/translations/tt.po +16 -0
- package/lang/translations/ug.po +17 -1
- package/lang/translations/uk.po +16 -0
- package/lang/translations/ur.po +16 -0
- package/lang/translations/uz.po +16 -0
- package/lang/translations/vi.po +16 -0
- package/lang/translations/zh-cn.po +16 -0
- package/lang/translations/zh.po +16 -0
- package/package.json +3 -3
- package/src/augmentation.d.ts +10 -10
- package/src/augmentation.js +5 -5
- package/src/command.d.ts +189 -189
- package/src/command.js +185 -185
- package/src/commandcollection.d.ts +83 -83
- package/src/commandcollection.js +83 -83
- package/src/context.d.ts +237 -237
- package/src/context.js +225 -225
- package/src/contextplugin.d.ts +61 -61
- package/src/contextplugin.js +43 -43
- package/src/editingkeystrokehandler.d.ts +56 -56
- package/src/editingkeystrokehandler.js +57 -57
- package/src/editor/editor.d.ts +417 -417
- package/src/editor/editor.js +316 -316
- package/src/editor/editorconfig.d.ts +661 -660
- package/src/editor/editorconfig.js +5 -5
- package/src/editor/utils/attachtoform.d.ts +15 -15
- package/src/editor/utils/attachtoform.js +57 -57
- package/src/editor/utils/dataapimixin.d.ts +75 -75
- package/src/editor/utils/dataapimixin.js +24 -24
- package/src/editor/utils/elementapimixin.d.ts +35 -31
- package/src/editor/utils/elementapimixin.js +43 -42
- package/src/editor/utils/securesourceelement.d.ts +17 -17
- package/src/editor/utils/securesourceelement.js +35 -35
- package/src/index.d.ts +66 -62
- package/src/index.js +103 -95
- package/src/multicommand.d.ts +66 -66
- package/src/multicommand.js +82 -82
- package/src/pendingactions.d.ts +117 -117
- package/src/pendingactions.js +116 -116
- package/src/plugin.d.ts +274 -274
- package/src/plugin.js +106 -106
- package/src/plugincollection.d.ts +117 -117
- package/src/plugincollection.js +473 -473
- package/theme/icons/image-asset-manager.svg +1 -0
- package/theme/icons/image-upload.svg +1 -0
- package/theme/icons/image-url.svg +1 -0
- package/theme/icons/image.svg +1 -1
- package/theme/icons/low-vision.svg +1 -1
- package/theme/icons/text-alternative.svg +1 -0
package/src/context.js
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module core/context
|
|
7
|
-
*/
|
|
8
|
-
import { Config, Collection, CKEditorError, Locale } from '@ckeditor/ckeditor5-utils';
|
|
9
|
-
import PluginCollection from './plugincollection';
|
|
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 default class Context {
|
|
38
|
-
/**
|
|
39
|
-
* Creates a context instance with a given configuration.
|
|
40
|
-
*
|
|
41
|
-
* Usually not to be used directly. See the static {@link module:core/context~Context.create `create()`} method.
|
|
42
|
-
*
|
|
43
|
-
* @param config The context configuration.
|
|
44
|
-
*/
|
|
45
|
-
constructor(config) {
|
|
46
|
-
/**
|
|
47
|
-
* Reference to the editor which created the context.
|
|
48
|
-
* Null when the context was created outside of the editor.
|
|
49
|
-
*
|
|
50
|
-
* It is used to destroy the context when removing the editor that has created the context.
|
|
51
|
-
*/
|
|
52
|
-
this._contextOwner = null;
|
|
53
|
-
this.config = new Config(config, this.constructor.defaultConfig);
|
|
54
|
-
const availablePlugins = this.constructor.builtinPlugins;
|
|
55
|
-
this.config.define('plugins', availablePlugins);
|
|
56
|
-
this.plugins = new PluginCollection(this, availablePlugins);
|
|
57
|
-
const languageConfig = this.config.get('language') || {};
|
|
58
|
-
this.locale = new Locale({
|
|
59
|
-
uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
|
|
60
|
-
contentLanguage: this.config.get('language.content')
|
|
61
|
-
});
|
|
62
|
-
this.t = this.locale.t;
|
|
63
|
-
this.editors = new Collection();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Loads and initializes plugins specified in the configuration.
|
|
67
|
-
*
|
|
68
|
-
* @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
|
|
69
|
-
*/
|
|
70
|
-
initPlugins() {
|
|
71
|
-
const plugins = this.config.get('plugins') || [];
|
|
72
|
-
const substitutePlugins = this.config.get('substitutePlugins') || [];
|
|
73
|
-
// Plugins for substitution should be checked as well.
|
|
74
|
-
for (const Plugin of plugins.concat(substitutePlugins)) {
|
|
75
|
-
if (typeof Plugin != 'function') {
|
|
76
|
-
/**
|
|
77
|
-
* Only a constructor function is allowed as a {@link module:core/contextplugin~ContextPlugin context plugin}.
|
|
78
|
-
*
|
|
79
|
-
* @error context-initplugins-constructor-only
|
|
80
|
-
*/
|
|
81
|
-
throw new CKEditorError('context-initplugins-constructor-only', null, { Plugin });
|
|
82
|
-
}
|
|
83
|
-
if (Plugin.isContextPlugin !== true) {
|
|
84
|
-
/**
|
|
85
|
-
* Only a plugin marked as a {@link module:core/contextplugin~ContextPlugin.isContextPlugin context plugin}
|
|
86
|
-
* is allowed to be used with a context.
|
|
87
|
-
*
|
|
88
|
-
* @error context-initplugins-invalid-plugin
|
|
89
|
-
*/
|
|
90
|
-
throw new CKEditorError('context-initplugins-invalid-plugin', null, { Plugin });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return this.plugins.init(plugins, [], substitutePlugins);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Destroys the context instance and all editors used with the context,
|
|
97
|
-
* releasing all resources used by the context.
|
|
98
|
-
*
|
|
99
|
-
* @returns A promise that resolves once the context instance is fully destroyed.
|
|
100
|
-
*/
|
|
101
|
-
destroy() {
|
|
102
|
-
return Promise.all(Array.from(this.editors, editor => editor.destroy()))
|
|
103
|
-
.then(() => this.plugins.destroy());
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Adds a reference to the editor which is used with this context.
|
|
107
|
-
*
|
|
108
|
-
* When the given editor has created the context, the reference to this editor will be stored
|
|
109
|
-
* as a {@link ~Context#_contextOwner}.
|
|
110
|
-
*
|
|
111
|
-
* This method should only be used by the editor.
|
|
112
|
-
*
|
|
113
|
-
* @internal
|
|
114
|
-
* @param isContextOwner Stores the given editor as a context owner.
|
|
115
|
-
*/
|
|
116
|
-
_addEditor(editor, isContextOwner) {
|
|
117
|
-
if (this._contextOwner) {
|
|
118
|
-
/**
|
|
119
|
-
* Cannot add multiple editors to the context which is created by the editor.
|
|
120
|
-
*
|
|
121
|
-
* @error context-addeditor-private-context
|
|
122
|
-
*/
|
|
123
|
-
throw new CKEditorError('context-addeditor-private-context');
|
|
124
|
-
}
|
|
125
|
-
this.editors.add(editor);
|
|
126
|
-
if (isContextOwner) {
|
|
127
|
-
this._contextOwner = editor;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Removes a reference to the editor which was used with this context.
|
|
132
|
-
* When the context was created by the given editor, the context will be destroyed.
|
|
133
|
-
*
|
|
134
|
-
* This method should only be used by the editor.
|
|
135
|
-
*
|
|
136
|
-
* @internal
|
|
137
|
-
* @return A promise that resolves once the editor is removed from the context or when the context was destroyed.
|
|
138
|
-
*/
|
|
139
|
-
_removeEditor(editor) {
|
|
140
|
-
if (this.editors.has(editor)) {
|
|
141
|
-
this.editors.remove(editor);
|
|
142
|
-
}
|
|
143
|
-
if (this._contextOwner === editor) {
|
|
144
|
-
return this.destroy();
|
|
145
|
-
}
|
|
146
|
-
return Promise.resolve();
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Returns the context configuration which will be copied to the editors created using this context.
|
|
150
|
-
*
|
|
151
|
-
* The configuration returned by this method has the plugins configuration removed &
|
|
152
|
-
* through another mechanism.
|
|
153
|
-
*
|
|
154
|
-
* This method should only be used by the editor.
|
|
155
|
-
*
|
|
156
|
-
* @internal
|
|
157
|
-
* @returns Configuration as a plain object.
|
|
158
|
-
*/
|
|
159
|
-
_getEditorConfig() {
|
|
160
|
-
const result = {};
|
|
161
|
-
for (const name of this.config.names()) {
|
|
162
|
-
if (!['plugins', 'removePlugins', 'extraPlugins'].includes(name)) {
|
|
163
|
-
result[name] = this.config.get(name);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Creates and initializes a new context instance.
|
|
170
|
-
*
|
|
171
|
-
* ```ts
|
|
172
|
-
* const commonConfig = { ... }; // Configuration for all the plugins and editors.
|
|
173
|
-
* const editorPlugins = [ ... ]; // Regular plugins here.
|
|
174
|
-
*
|
|
175
|
-
* Context
|
|
176
|
-
* .create( {
|
|
177
|
-
* // Only context plugins here.
|
|
178
|
-
* plugins: [ ... ],
|
|
179
|
-
*
|
|
180
|
-
* // Configure the language for all the editors (it cannot be overwritten).
|
|
181
|
-
* language: { ... },
|
|
182
|
-
*
|
|
183
|
-
* // Configuration for context plugins.
|
|
184
|
-
* comments: { ... },
|
|
185
|
-
* ...
|
|
186
|
-
*
|
|
187
|
-
* // Default configuration for editor plugins.
|
|
188
|
-
* toolbar: { ... },
|
|
189
|
-
* image: { ... },
|
|
190
|
-
* ...
|
|
191
|
-
* } )
|
|
192
|
-
* .then( context => {
|
|
193
|
-
* const promises = [];
|
|
194
|
-
*
|
|
195
|
-
* promises.push( ClassicEditor.create(
|
|
196
|
-
* document.getElementById( 'editor1' ),
|
|
197
|
-
* {
|
|
198
|
-
* editorPlugins,
|
|
199
|
-
* context
|
|
200
|
-
* }
|
|
201
|
-
* ) );
|
|
202
|
-
*
|
|
203
|
-
* promises.push( ClassicEditor.create(
|
|
204
|
-
* document.getElementById( 'editor2' ),
|
|
205
|
-
* {
|
|
206
|
-
* editorPlugins,
|
|
207
|
-
* context,
|
|
208
|
-
* toolbar: { ... } // You can overwrite the configuration of the context.
|
|
209
|
-
* }
|
|
210
|
-
* ) );
|
|
211
|
-
*
|
|
212
|
-
* return Promise.all( promises );
|
|
213
|
-
* } );
|
|
214
|
-
* ```
|
|
215
|
-
*
|
|
216
|
-
* @param config The context configuration.
|
|
217
|
-
* @returns A promise resolved once the context is ready. The promise resolves with the created context instance.
|
|
218
|
-
*/
|
|
219
|
-
static create(config) {
|
|
220
|
-
return new Promise(resolve => {
|
|
221
|
-
const context = new this(config);
|
|
222
|
-
resolve(context.initPlugins().then(() => context));
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module core/context
|
|
7
|
+
*/
|
|
8
|
+
import { Config, Collection, CKEditorError, Locale } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
import PluginCollection from './plugincollection';
|
|
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 default class Context {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a context instance with a given configuration.
|
|
40
|
+
*
|
|
41
|
+
* Usually not to be used directly. See the static {@link module:core/context~Context.create `create()`} method.
|
|
42
|
+
*
|
|
43
|
+
* @param config The context configuration.
|
|
44
|
+
*/
|
|
45
|
+
constructor(config) {
|
|
46
|
+
/**
|
|
47
|
+
* Reference to the editor which created the context.
|
|
48
|
+
* Null when the context was created outside of the editor.
|
|
49
|
+
*
|
|
50
|
+
* It is used to destroy the context when removing the editor that has created the context.
|
|
51
|
+
*/
|
|
52
|
+
this._contextOwner = null;
|
|
53
|
+
this.config = new Config(config, this.constructor.defaultConfig);
|
|
54
|
+
const availablePlugins = this.constructor.builtinPlugins;
|
|
55
|
+
this.config.define('plugins', availablePlugins);
|
|
56
|
+
this.plugins = new PluginCollection(this, availablePlugins);
|
|
57
|
+
const languageConfig = this.config.get('language') || {};
|
|
58
|
+
this.locale = new Locale({
|
|
59
|
+
uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
|
|
60
|
+
contentLanguage: this.config.get('language.content')
|
|
61
|
+
});
|
|
62
|
+
this.t = this.locale.t;
|
|
63
|
+
this.editors = new Collection();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Loads and initializes plugins specified in the configuration.
|
|
67
|
+
*
|
|
68
|
+
* @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
|
|
69
|
+
*/
|
|
70
|
+
initPlugins() {
|
|
71
|
+
const plugins = this.config.get('plugins') || [];
|
|
72
|
+
const substitutePlugins = this.config.get('substitutePlugins') || [];
|
|
73
|
+
// Plugins for substitution should be checked as well.
|
|
74
|
+
for (const Plugin of plugins.concat(substitutePlugins)) {
|
|
75
|
+
if (typeof Plugin != 'function') {
|
|
76
|
+
/**
|
|
77
|
+
* Only a constructor function is allowed as a {@link module:core/contextplugin~ContextPlugin context plugin}.
|
|
78
|
+
*
|
|
79
|
+
* @error context-initplugins-constructor-only
|
|
80
|
+
*/
|
|
81
|
+
throw new CKEditorError('context-initplugins-constructor-only', null, { Plugin });
|
|
82
|
+
}
|
|
83
|
+
if (Plugin.isContextPlugin !== true) {
|
|
84
|
+
/**
|
|
85
|
+
* Only a plugin marked as a {@link module:core/contextplugin~ContextPlugin.isContextPlugin context plugin}
|
|
86
|
+
* is allowed to be used with a context.
|
|
87
|
+
*
|
|
88
|
+
* @error context-initplugins-invalid-plugin
|
|
89
|
+
*/
|
|
90
|
+
throw new CKEditorError('context-initplugins-invalid-plugin', null, { Plugin });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return this.plugins.init(plugins, [], substitutePlugins);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Destroys the context instance and all editors used with the context,
|
|
97
|
+
* releasing all resources used by the context.
|
|
98
|
+
*
|
|
99
|
+
* @returns A promise that resolves once the context instance is fully destroyed.
|
|
100
|
+
*/
|
|
101
|
+
destroy() {
|
|
102
|
+
return Promise.all(Array.from(this.editors, editor => editor.destroy()))
|
|
103
|
+
.then(() => this.plugins.destroy());
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Adds a reference to the editor which is used with this context.
|
|
107
|
+
*
|
|
108
|
+
* When the given editor has created the context, the reference to this editor will be stored
|
|
109
|
+
* as a {@link ~Context#_contextOwner}.
|
|
110
|
+
*
|
|
111
|
+
* This method should only be used by the editor.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
* @param isContextOwner Stores the given editor as a context owner.
|
|
115
|
+
*/
|
|
116
|
+
_addEditor(editor, isContextOwner) {
|
|
117
|
+
if (this._contextOwner) {
|
|
118
|
+
/**
|
|
119
|
+
* Cannot add multiple editors to the context which is created by the editor.
|
|
120
|
+
*
|
|
121
|
+
* @error context-addeditor-private-context
|
|
122
|
+
*/
|
|
123
|
+
throw new CKEditorError('context-addeditor-private-context');
|
|
124
|
+
}
|
|
125
|
+
this.editors.add(editor);
|
|
126
|
+
if (isContextOwner) {
|
|
127
|
+
this._contextOwner = editor;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Removes a reference to the editor which was used with this context.
|
|
132
|
+
* When the context was created by the given editor, the context will be destroyed.
|
|
133
|
+
*
|
|
134
|
+
* This method should only be used by the editor.
|
|
135
|
+
*
|
|
136
|
+
* @internal
|
|
137
|
+
* @return A promise that resolves once the editor is removed from the context or when the context was destroyed.
|
|
138
|
+
*/
|
|
139
|
+
_removeEditor(editor) {
|
|
140
|
+
if (this.editors.has(editor)) {
|
|
141
|
+
this.editors.remove(editor);
|
|
142
|
+
}
|
|
143
|
+
if (this._contextOwner === editor) {
|
|
144
|
+
return this.destroy();
|
|
145
|
+
}
|
|
146
|
+
return Promise.resolve();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Returns the context configuration which will be copied to the editors created using this context.
|
|
150
|
+
*
|
|
151
|
+
* The configuration returned by this method has the plugins configuration removed – plugins are shared with all editors
|
|
152
|
+
* through another mechanism.
|
|
153
|
+
*
|
|
154
|
+
* This method should only be used by the editor.
|
|
155
|
+
*
|
|
156
|
+
* @internal
|
|
157
|
+
* @returns Configuration as a plain object.
|
|
158
|
+
*/
|
|
159
|
+
_getEditorConfig() {
|
|
160
|
+
const result = {};
|
|
161
|
+
for (const name of this.config.names()) {
|
|
162
|
+
if (!['plugins', 'removePlugins', 'extraPlugins'].includes(name)) {
|
|
163
|
+
result[name] = this.config.get(name);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates and initializes a new context instance.
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* const commonConfig = { ... }; // Configuration for all the plugins and editors.
|
|
173
|
+
* const editorPlugins = [ ... ]; // Regular plugins here.
|
|
174
|
+
*
|
|
175
|
+
* Context
|
|
176
|
+
* .create( {
|
|
177
|
+
* // Only context plugins here.
|
|
178
|
+
* plugins: [ ... ],
|
|
179
|
+
*
|
|
180
|
+
* // Configure the language for all the editors (it cannot be overwritten).
|
|
181
|
+
* language: { ... },
|
|
182
|
+
*
|
|
183
|
+
* // Configuration for context plugins.
|
|
184
|
+
* comments: { ... },
|
|
185
|
+
* ...
|
|
186
|
+
*
|
|
187
|
+
* // Default configuration for editor plugins.
|
|
188
|
+
* toolbar: { ... },
|
|
189
|
+
* image: { ... },
|
|
190
|
+
* ...
|
|
191
|
+
* } )
|
|
192
|
+
* .then( context => {
|
|
193
|
+
* const promises = [];
|
|
194
|
+
*
|
|
195
|
+
* promises.push( ClassicEditor.create(
|
|
196
|
+
* document.getElementById( 'editor1' ),
|
|
197
|
+
* {
|
|
198
|
+
* editorPlugins,
|
|
199
|
+
* context
|
|
200
|
+
* }
|
|
201
|
+
* ) );
|
|
202
|
+
*
|
|
203
|
+
* promises.push( ClassicEditor.create(
|
|
204
|
+
* document.getElementById( 'editor2' ),
|
|
205
|
+
* {
|
|
206
|
+
* editorPlugins,
|
|
207
|
+
* context,
|
|
208
|
+
* toolbar: { ... } // You can overwrite the configuration of the context.
|
|
209
|
+
* }
|
|
210
|
+
* ) );
|
|
211
|
+
*
|
|
212
|
+
* return Promise.all( promises );
|
|
213
|
+
* } );
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* @param config The context configuration.
|
|
217
|
+
* @returns A promise resolved once the context is ready. The promise resolves with the created context instance.
|
|
218
|
+
*/
|
|
219
|
+
static create(config) {
|
|
220
|
+
return new Promise(resolve => {
|
|
221
|
+
const context = new this(config);
|
|
222
|
+
resolve(context.initPlugins().then(() => context));
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
package/src/contextplugin.d.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module core/contextplugin
|
|
7
|
-
*/
|
|
8
|
-
import { type Collection, type Config, type Locale, type LocaleTranslate } from '@ckeditor/ckeditor5-utils';
|
|
9
|
-
import type Editor from './editor/editor';
|
|
10
|
-
import type { EditorConfig } from './editor/editorconfig';
|
|
11
|
-
import type Context from './context';
|
|
12
|
-
import type { PluginDependencies, PluginInterface } from './plugin';
|
|
13
|
-
import type PluginCollection from './plugincollection';
|
|
14
|
-
declare const ContextPlugin_base: {
|
|
15
|
-
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
|
16
|
-
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* The base class for {@link module:core/context~Context} plugin classes.
|
|
20
|
-
*
|
|
21
|
-
* A context plugin can either be initialized for an {@link module:core/editor/editor~Editor editor} or for
|
|
22
|
-
* a {@link module:core/context~Context context}. In other words, it can either
|
|
23
|
-
* work within one editor instance or with one or more editor instances that use a single context.
|
|
24
|
-
* It is the context plugin's role to implement handling for both modes.
|
|
25
|
-
*
|
|
26
|
-
* There are a few rules for interaction between the editor plugins and context plugins:
|
|
27
|
-
*
|
|
28
|
-
* * A context plugin can require another context plugin.
|
|
29
|
-
* * An {@link module:core/plugin~Plugin editor plugin} can require a context plugin.
|
|
30
|
-
* * A context plugin MUST NOT require an {@link module:core/plugin~Plugin editor plugin}.
|
|
31
|
-
*/
|
|
32
|
-
export default class ContextPlugin extends ContextPlugin_base implements PluginInterface {
|
|
33
|
-
/**
|
|
34
|
-
* The context or editor instance.
|
|
35
|
-
*/
|
|
36
|
-
readonly context: ContextInterface;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new plugin instance.
|
|
39
|
-
*/
|
|
40
|
-
constructor(context: Context | Editor);
|
|
41
|
-
/**
|
|
42
|
-
* @inheritDoc
|
|
43
|
-
*/
|
|
44
|
-
destroy(): void;
|
|
45
|
-
/**
|
|
46
|
-
* @inheritDoc
|
|
47
|
-
*/
|
|
48
|
-
static get isContextPlugin(): true;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The common interface of {@link module:core/context~Context} and {@link module:core/editor/editor~Editor}.
|
|
52
|
-
*/
|
|
53
|
-
export interface ContextInterface {
|
|
54
|
-
config: Config<Omit<EditorConfig, 'plugins' | 'substitutePlugins' | 'removePlugins' | 'extraPlugins'>>;
|
|
55
|
-
plugins: PluginCollection<Context | Editor>;
|
|
56
|
-
locale: Locale;
|
|
57
|
-
t: LocaleTranslate;
|
|
58
|
-
editors?: Collection<Editor>;
|
|
59
|
-
}
|
|
60
|
-
export type ContextPluginDependencies = PluginDependencies<Context | Editor>;
|
|
61
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module core/contextplugin
|
|
7
|
+
*/
|
|
8
|
+
import { type Collection, type Config, type Locale, type LocaleTranslate } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
import type Editor from './editor/editor';
|
|
10
|
+
import type { EditorConfig } from './editor/editorconfig';
|
|
11
|
+
import type Context from './context';
|
|
12
|
+
import type { PluginDependencies, PluginInterface } from './plugin';
|
|
13
|
+
import type PluginCollection from './plugincollection';
|
|
14
|
+
declare const ContextPlugin_base: {
|
|
15
|
+
new (): import("@ckeditor/ckeditor5-utils").Observable;
|
|
16
|
+
prototype: import("@ckeditor/ckeditor5-utils").Observable;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The base class for {@link module:core/context~Context} plugin classes.
|
|
20
|
+
*
|
|
21
|
+
* A context plugin can either be initialized for an {@link module:core/editor/editor~Editor editor} or for
|
|
22
|
+
* a {@link module:core/context~Context context}. In other words, it can either
|
|
23
|
+
* work within one editor instance or with one or more editor instances that use a single context.
|
|
24
|
+
* It is the context plugin's role to implement handling for both modes.
|
|
25
|
+
*
|
|
26
|
+
* There are a few rules for interaction between the editor plugins and context plugins:
|
|
27
|
+
*
|
|
28
|
+
* * A context plugin can require another context plugin.
|
|
29
|
+
* * An {@link module:core/plugin~Plugin editor plugin} can require a context plugin.
|
|
30
|
+
* * A context plugin MUST NOT require an {@link module:core/plugin~Plugin editor plugin}.
|
|
31
|
+
*/
|
|
32
|
+
export default class ContextPlugin extends ContextPlugin_base implements PluginInterface {
|
|
33
|
+
/**
|
|
34
|
+
* The context or editor instance.
|
|
35
|
+
*/
|
|
36
|
+
readonly context: ContextInterface;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new plugin instance.
|
|
39
|
+
*/
|
|
40
|
+
constructor(context: Context | Editor);
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
destroy(): void;
|
|
45
|
+
/**
|
|
46
|
+
* @inheritDoc
|
|
47
|
+
*/
|
|
48
|
+
static get isContextPlugin(): true;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The common interface of {@link module:core/context~Context} and {@link module:core/editor/editor~Editor}.
|
|
52
|
+
*/
|
|
53
|
+
export interface ContextInterface {
|
|
54
|
+
config: Config<Omit<EditorConfig, 'plugins' | 'substitutePlugins' | 'removePlugins' | 'extraPlugins'>>;
|
|
55
|
+
plugins: PluginCollection<Context | Editor>;
|
|
56
|
+
locale: Locale;
|
|
57
|
+
t: LocaleTranslate;
|
|
58
|
+
editors?: Collection<Editor>;
|
|
59
|
+
}
|
|
60
|
+
export type ContextPluginDependencies = PluginDependencies<Context | Editor>;
|
|
61
|
+
export {};
|
package/src/contextplugin.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
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 default class ContextPlugin extends ObservableMixin() {
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new plugin instance.
|
|
26
|
-
*/
|
|
27
|
-
constructor(context) {
|
|
28
|
-
super();
|
|
29
|
-
this.context = context;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
destroy() {
|
|
35
|
-
this.stopListening();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @inheritDoc
|
|
39
|
-
*/
|
|
40
|
-
static get isContextPlugin() {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
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 default class ContextPlugin extends ObservableMixin() {
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new plugin instance.
|
|
26
|
+
*/
|
|
27
|
+
constructor(context) {
|
|
28
|
+
super();
|
|
29
|
+
this.context = context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
destroy() {
|
|
35
|
+
this.stopListening();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @inheritDoc
|
|
39
|
+
*/
|
|
40
|
+
static get isContextPlugin() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|