@ckeditor/ckeditor5-core 30.0.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 (111) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +18 -0
  3. package/lang/contexts.json +8 -0
  4. package/lang/translations/af.po +41 -0
  5. package/lang/translations/ar.po +41 -0
  6. package/lang/translations/ast.po +41 -0
  7. package/lang/translations/az.po +41 -0
  8. package/lang/translations/bg.po +41 -0
  9. package/lang/translations/ca.po +41 -0
  10. package/lang/translations/cs.po +41 -0
  11. package/lang/translations/da.po +41 -0
  12. package/lang/translations/de-ch.po +41 -0
  13. package/lang/translations/de.po +41 -0
  14. package/lang/translations/el.po +41 -0
  15. package/lang/translations/en-au.po +41 -0
  16. package/lang/translations/en-gb.po +41 -0
  17. package/lang/translations/en.po +41 -0
  18. package/lang/translations/eo.po +41 -0
  19. package/lang/translations/es.po +41 -0
  20. package/lang/translations/et.po +41 -0
  21. package/lang/translations/eu.po +41 -0
  22. package/lang/translations/fa.po +41 -0
  23. package/lang/translations/fi.po +41 -0
  24. package/lang/translations/fr.po +41 -0
  25. package/lang/translations/gl.po +41 -0
  26. package/lang/translations/he.po +41 -0
  27. package/lang/translations/hi.po +41 -0
  28. package/lang/translations/hr.po +41 -0
  29. package/lang/translations/hu.po +41 -0
  30. package/lang/translations/id.po +41 -0
  31. package/lang/translations/it.po +41 -0
  32. package/lang/translations/ja.po +41 -0
  33. package/lang/translations/km.po +41 -0
  34. package/lang/translations/kn.po +41 -0
  35. package/lang/translations/ko.po +41 -0
  36. package/lang/translations/ku.po +41 -0
  37. package/lang/translations/lt.po +41 -0
  38. package/lang/translations/lv.po +41 -0
  39. package/lang/translations/nb.po +41 -0
  40. package/lang/translations/ne.po +41 -0
  41. package/lang/translations/nl.po +41 -0
  42. package/lang/translations/no.po +41 -0
  43. package/lang/translations/oc.po +41 -0
  44. package/lang/translations/pl.po +41 -0
  45. package/lang/translations/pt-br.po +41 -0
  46. package/lang/translations/pt.po +41 -0
  47. package/lang/translations/ro.po +41 -0
  48. package/lang/translations/ru.po +41 -0
  49. package/lang/translations/sk.po +41 -0
  50. package/lang/translations/sl.po +41 -0
  51. package/lang/translations/sq.po +41 -0
  52. package/lang/translations/sr-latn.po +41 -0
  53. package/lang/translations/sr.po +41 -0
  54. package/lang/translations/sv.po +41 -0
  55. package/lang/translations/th.po +41 -0
  56. package/lang/translations/tk.po +41 -0
  57. package/lang/translations/tr.po +41 -0
  58. package/lang/translations/tt.po +41 -0
  59. package/lang/translations/ug.po +41 -0
  60. package/lang/translations/uk.po +41 -0
  61. package/lang/translations/vi.po +41 -0
  62. package/lang/translations/zh-cn.po +41 -0
  63. package/lang/translations/zh.po +41 -0
  64. package/package.json +65 -0
  65. package/src/command.js +244 -0
  66. package/src/commandcollection.js +109 -0
  67. package/src/context.js +355 -0
  68. package/src/contextplugin.js +61 -0
  69. package/src/editingkeystrokehandler.js +72 -0
  70. package/src/editor/editor.js +448 -0
  71. package/src/editor/editorconfig.jsdoc +325 -0
  72. package/src/editor/editorui.js +275 -0
  73. package/src/editor/editorwithui.jsdoc +29 -0
  74. package/src/editor/utils/attachtoform.js +67 -0
  75. package/src/editor/utils/dataapimixin.js +81 -0
  76. package/src/editor/utils/elementapimixin.js +65 -0
  77. package/src/editor/utils/securesourceelement.js +49 -0
  78. package/src/index.js +95 -0
  79. package/src/multicommand.js +101 -0
  80. package/src/pendingactions.js +155 -0
  81. package/src/plugin.js +292 -0
  82. package/src/plugincollection.js +597 -0
  83. package/theme/icons/align-bottom.svg +1 -0
  84. package/theme/icons/align-center.svg +1 -0
  85. package/theme/icons/align-justify.svg +1 -0
  86. package/theme/icons/align-left.svg +1 -0
  87. package/theme/icons/align-middle.svg +1 -0
  88. package/theme/icons/align-right.svg +1 -0
  89. package/theme/icons/align-top.svg +1 -0
  90. package/theme/icons/cancel.svg +1 -0
  91. package/theme/icons/caption.svg +1 -0
  92. package/theme/icons/check.svg +1 -0
  93. package/theme/icons/cog.svg +1 -0
  94. package/theme/icons/eraser.svg +1 -0
  95. package/theme/icons/image.svg +1 -0
  96. package/theme/icons/low-vision.svg +1 -0
  97. package/theme/icons/object-center.svg +1 -0
  98. package/theme/icons/object-full-width.svg +1 -0
  99. package/theme/icons/object-inline-left.svg +1 -0
  100. package/theme/icons/object-inline-right.svg +1 -0
  101. package/theme/icons/object-inline.svg +1 -0
  102. package/theme/icons/object-left.svg +1 -0
  103. package/theme/icons/object-right.svg +1 -0
  104. package/theme/icons/object-size-full.svg +1 -0
  105. package/theme/icons/object-size-large.svg +1 -0
  106. package/theme/icons/object-size-medium.svg +1 -0
  107. package/theme/icons/object-size-small.svg +1 -0
  108. package/theme/icons/pencil.svg +1 -0
  109. package/theme/icons/pilcrow.svg +1 -0
  110. package/theme/icons/quote.svg +1 -0
  111. package/theme/icons/three-vertical-dots.svg +1 -0
package/src/context.js ADDED
@@ -0,0 +1,355 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module core/context
8
+ */
9
+
10
+ import Config from '@ckeditor/ckeditor5-utils/src/config';
11
+ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
12
+ import PluginCollection from './plugincollection';
13
+ import Locale from '@ckeditor/ckeditor5-utils/src/locale';
14
+ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
15
+
16
+ /**
17
+ * Provides a common, higher-level environment for solutions that use multiple {@link module:core/editor/editor~Editor editors}
18
+ * or plugins that work outside the editor. Use it instead of {@link module:core/editor/editor~Editor.create `Editor.create()`}
19
+ * in advanced application integrations.
20
+ *
21
+ * All configuration options passed to a context will be used as default options for editor instances initialized in that context.
22
+ *
23
+ * {@link module:core/contextplugin~ContextPlugin Context plugins} passed to a context instance will be shared among all
24
+ * editor instances initialized in this context. These will be the same plugin instances for all the editors.
25
+ *
26
+ * **Note:** The context can only be initialized with {@link module:core/contextplugin~ContextPlugin context plugins}
27
+ * (e.g. [comments](https://ckeditor.com/collaboration/comments/)). Regular {@link module:core/plugin~Plugin plugins} require an
28
+ * editor instance to work and cannot be added to a context.
29
+ *
30
+ * **Note:** You can add a context plugin to an editor instance, though.
31
+ *
32
+ * If you are using multiple editor instances on one page and use any context plugins, create a context to share the configuration and
33
+ * plugins among these editors. Some plugins will use the information about all existing editors to better integrate between them.
34
+ *
35
+ * If you are using plugins that do not require an editor to work (e.g. [comments](https://ckeditor.com/collaboration/comments/)),
36
+ * enable and configure them using the context.
37
+ *
38
+ * If you are using only a single editor on each page, use {@link module:core/editor/editor~Editor.create `Editor.create()`} instead.
39
+ * In such case, a context instance will be created by the editor instance in a transparent way.
40
+ *
41
+ * See {@link module:core/context~Context.create `Context.create()`} for usage examples.
42
+ */
43
+ export default class Context {
44
+ /**
45
+ * Creates a context instance with a given configuration.
46
+ *
47
+ * Usually not to be used directly. See the static {@link module:core/context~Context.create `create()`} method.
48
+ *
49
+ * @param {Object} [config={}] The context configuration.
50
+ */
51
+ constructor( config ) {
52
+ /**
53
+ * Stores all the configurations specific to this context instance.
54
+ *
55
+ * @readonly
56
+ * @type {module:utils/config~Config}
57
+ */
58
+ this.config = new Config( config, this.constructor.defaultConfig );
59
+
60
+ const availablePlugins = this.constructor.builtinPlugins;
61
+
62
+ this.config.define( 'plugins', availablePlugins );
63
+
64
+ /**
65
+ * The plugins loaded and in use by this context instance.
66
+ *
67
+ * @readonly
68
+ * @type {module:core/plugincollection~PluginCollection}
69
+ */
70
+ this.plugins = new PluginCollection( this, availablePlugins );
71
+
72
+ const languageConfig = this.config.get( 'language' ) || {};
73
+
74
+ /**
75
+ * @readonly
76
+ * @type {module:utils/locale~Locale}
77
+ */
78
+ this.locale = new Locale( {
79
+ uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
80
+ contentLanguage: this.config.get( 'language.content' )
81
+ } );
82
+
83
+ /**
84
+ * Shorthand for {@link module:utils/locale~Locale#t}.
85
+ *
86
+ * @see module:utils/locale~Locale#t
87
+ * @method #t
88
+ */
89
+ this.t = this.locale.t;
90
+
91
+ /**
92
+ * A list of editors that this context instance is injected to.
93
+ *
94
+ * @readonly
95
+ * @type {module:utils/collection~Collection}
96
+ */
97
+ this.editors = new Collection();
98
+
99
+ /**
100
+ * Reference to the editor which created the context.
101
+ * Null when the context was created outside of the editor.
102
+ *
103
+ * It is used to destroy the context when removing the editor that has created the context.
104
+ *
105
+ * @private
106
+ * @type {module:core/editor/editor~Editor|null}
107
+ */
108
+ this._contextOwner = null;
109
+ }
110
+
111
+ /**
112
+ * Loads and initializes plugins specified in the configuration.
113
+ *
114
+ * @returns {Promise.<module:core/plugin~LoadedPlugins>} A promise which resolves
115
+ * once the initialization is completed, providing an array of loaded plugins.
116
+ */
117
+ initPlugins() {
118
+ const plugins = this.config.get( 'plugins' ) || [];
119
+ const substitutePlugins = this.config.get( 'substitutePlugins' ) || [];
120
+
121
+ // Plugins for substitution should be checked as well.
122
+ for ( const Plugin of plugins.concat( substitutePlugins ) ) {
123
+ if ( typeof Plugin != 'function' ) {
124
+ /**
125
+ * Only a constructor function is allowed as a {@link module:core/contextplugin~ContextPlugin context plugin}.
126
+ *
127
+ * @error context-initplugins-constructor-only
128
+ */
129
+ throw new CKEditorError(
130
+ 'context-initplugins-constructor-only',
131
+ null,
132
+ { Plugin }
133
+ );
134
+ }
135
+
136
+ if ( Plugin.isContextPlugin !== true ) {
137
+ /**
138
+ * Only a plugin marked as a {@link module:core/contextplugin~ContextPlugin.isContextPlugin context plugin}
139
+ * is allowed to be used with a context.
140
+ *
141
+ * @error context-initplugins-invalid-plugin
142
+ */
143
+ throw new CKEditorError(
144
+ 'context-initplugins-invalid-plugin',
145
+ null,
146
+ { Plugin }
147
+ );
148
+ }
149
+ }
150
+
151
+ return this.plugins.init( plugins, [], substitutePlugins );
152
+ }
153
+
154
+ /**
155
+ * Destroys the context instance and all editors used with the context,
156
+ * releasing all resources used by the context.
157
+ *
158
+ * @returns {Promise} A promise that resolves once the context instance is fully destroyed.
159
+ */
160
+ destroy() {
161
+ return Promise.all( Array.from( this.editors, editor => editor.destroy() ) )
162
+ .then( () => this.plugins.destroy() );
163
+ }
164
+
165
+ /**
166
+ * Adds a reference to the editor which is used with this context.
167
+ *
168
+ * When the given editor has created the context, the reference to this editor will be stored
169
+ * as a {@link ~Context#_contextOwner}.
170
+ *
171
+ * This method should only be used by the editor.
172
+ *
173
+ * @protected
174
+ * @param {module:core/editor/editor~Editor} editor
175
+ * @param {Boolean} isContextOwner Stores the given editor as a context owner.
176
+ */
177
+ _addEditor( editor, isContextOwner ) {
178
+ if ( this._contextOwner ) {
179
+ /**
180
+ * Cannot add multiple editors to the context which is created by the editor.
181
+ *
182
+ * @error context-addeditor-private-context
183
+ */
184
+ throw new CKEditorError( 'context-addeditor-private-context' );
185
+ }
186
+
187
+ this.editors.add( editor );
188
+
189
+ if ( isContextOwner ) {
190
+ this._contextOwner = editor;
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Removes a reference to the editor which was used with this context.
196
+ * When the context was created by the given editor, the context will be destroyed.
197
+ *
198
+ * This method should only be used by the editor.
199
+ *
200
+ * @protected
201
+ * @param {module:core/editor/editor~Editor} editor
202
+ * @return {Promise} A promise that resolves once the editor is removed from the context or when the context was destroyed.
203
+ */
204
+ _removeEditor( editor ) {
205
+ if ( this.editors.has( editor ) ) {
206
+ this.editors.remove( editor );
207
+ }
208
+
209
+ if ( this._contextOwner === editor ) {
210
+ return this.destroy();
211
+ }
212
+
213
+ return Promise.resolve();
214
+ }
215
+
216
+ /**
217
+ * Returns the context configuration which will be copied to the editors created using this context.
218
+ *
219
+ * The configuration returned by this method has the plugins configuration removed &mdash; plugins are shared with all editors
220
+ * through another mechanism.
221
+ *
222
+ * This method should only be used by the editor.
223
+ *
224
+ * @protected
225
+ * @returns {Object} Configuration as a plain object.
226
+ */
227
+ _getEditorConfig() {
228
+ const result = {};
229
+
230
+ for ( const name of this.config.names() ) {
231
+ if ( ![ 'plugins', 'removePlugins', 'extraPlugins' ].includes( name ) ) {
232
+ result[ name ] = this.config.get( name );
233
+ }
234
+ }
235
+
236
+ return result;
237
+ }
238
+
239
+ /**
240
+ * Creates and initializes a new context instance.
241
+ *
242
+ * const commonConfig = { ... }; // Configuration for all the plugins and editors.
243
+ * const editorPlugins = [ ... ]; // Regular plugins here.
244
+ *
245
+ * Context
246
+ * .create( {
247
+ * // Only context plugins here.
248
+ * plugins: [ ... ],
249
+ *
250
+ * // Configure the language for all the editors (it cannot be overwritten).
251
+ * language: { ... },
252
+ *
253
+ * // Configuration for context plugins.
254
+ * comments: { ... },
255
+ * ...
256
+ *
257
+ * // Default configuration for editor plugins.
258
+ * toolbar: { ... },
259
+ * image: { ... },
260
+ * ...
261
+ * } )
262
+ * .then( context => {
263
+ * const promises = [];
264
+ *
265
+ * promises.push( ClassicEditor.create(
266
+ * document.getElementById( 'editor1' ),
267
+ * {
268
+ * editorPlugins,
269
+ * context
270
+ * }
271
+ * ) );
272
+ *
273
+ * promises.push( ClassicEditor.create(
274
+ * document.getElementById( 'editor2' ),
275
+ * {
276
+ * editorPlugins,
277
+ * context,
278
+ * toolbar: { ... } // You can overwrite the configuration of the context.
279
+ * }
280
+ * ) );
281
+ *
282
+ * return Promise.all( promises );
283
+ * } );
284
+ *
285
+ * @param {Object} [config] The context configuration.
286
+ * @returns {Promise} A promise resolved once the context is ready. The promise resolves with the created context instance.
287
+ */
288
+ static create( config ) {
289
+ return new Promise( resolve => {
290
+ const context = new this( config );
291
+
292
+ resolve( context.initPlugins().then( () => context ) );
293
+ } );
294
+ }
295
+ }
296
+
297
+ /**
298
+ * An array of plugins built into the `Context` class.
299
+ *
300
+ * It is used in CKEditor 5 builds featuring `Context` to provide a list of context plugins which are later automatically initialized
301
+ * during the context initialization.
302
+ *
303
+ * They will be automatically initialized by `Context` unless `config.plugins` is passed.
304
+ *
305
+ * // Build some context plugins into the Context class first.
306
+ * Context.builtinPlugins = [ FooPlugin, BarPlugin ];
307
+ *
308
+ * // Normally, you need to define config.plugins, but since Context.builtinPlugins was
309
+ * // defined, now you can call create() without any configuration.
310
+ * Context
311
+ * .create()
312
+ * .then( context => {
313
+ * context.plugins.get( FooPlugin ); // -> An instance of the Foo plugin.
314
+ * context.plugins.get( BarPlugin ); // -> An instance of the Bar plugin.
315
+ * } );
316
+ *
317
+ * See also {@link module:core/context~Context.defaultConfig `Context.defaultConfig`}
318
+ * and {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}.
319
+ *
320
+ * @static
321
+ * @member {Array.<Function>} module:core/context~Context.builtinPlugins
322
+ */
323
+
324
+ /**
325
+ * The default configuration which is built into the `Context` class.
326
+ *
327
+ * It is used in CKEditor 5 builds featuring `Context` to provide the default configuration options which are later used during the
328
+ * context initialization.
329
+ *
330
+ * Context.defaultConfig = {
331
+ * foo: 1,
332
+ * bar: 2
333
+ * };
334
+ *
335
+ * Context
336
+ * .create()
337
+ * .then( context => {
338
+ * context.config.get( 'foo' ); // -> 1
339
+ * context.config.get( 'bar' ); // -> 2
340
+ * } );
341
+ *
342
+ * // The default options can be overridden by the configuration passed to create().
343
+ * Context
344
+ * .create( { bar: 3 } )
345
+ * .then( context => {
346
+ * context.config.get( 'foo' ); // -> 1
347
+ * context.config.get( 'bar' ); // -> 3
348
+ * } );
349
+ *
350
+ * See also {@link module:core/context~Context.builtinPlugins `Context.builtinPlugins`}
351
+ * and {@link module:core/editor/editor~Editor.defaultConfig `Editor.defaultConfig`}.
352
+ *
353
+ * @static
354
+ * @member {Object} module:core/context~Context.defaultConfig
355
+ */
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module core/contextplugin
8
+ */
9
+
10
+ import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
11
+ import mix from '@ckeditor/ckeditor5-utils/src/mix';
12
+
13
+ /**
14
+ * The base class for {@link module:core/context~Context} plugin classes.
15
+ *
16
+ * A context plugin can either be initialized for an {@link module:core/editor/editor~Editor editor} or for
17
+ * a {@link module:core/context~Context context}. In other words, it can either
18
+ * work within one editor instance or with one or more editor instances that use a single context.
19
+ * It is the context plugin's role to implement handling for both modes.
20
+ *
21
+ * There are a few rules for interaction between the editor plugins and context plugins:
22
+ *
23
+ * * A context plugin can require another context plugin.
24
+ * * An {@link module:core/plugin~Plugin editor plugin} can require a context plugin.
25
+ * * A context plugin MUST NOT require an {@link module:core/plugin~Plugin editor plugin}.
26
+ *
27
+ * @implements module:core/plugin~PluginInterface
28
+ * @mixes module:utils/observablemixin~ObservableMixin
29
+ */
30
+ export default class ContextPlugin {
31
+ /**
32
+ * Creates a new plugin instance.
33
+ *
34
+ * @param {module:core/context~Context|module:core/editor/editor~Editor} context
35
+ */
36
+ constructor( context ) {
37
+ /**
38
+ * The context instance.
39
+ *
40
+ * @readonly
41
+ * @type {module:core/context~Context|module:core/editor/editor~Editor}
42
+ */
43
+ this.context = context;
44
+ }
45
+
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ destroy() {
50
+ this.stopListening();
51
+ }
52
+
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ static get isContextPlugin() {
57
+ return true;
58
+ }
59
+ }
60
+
61
+ mix( ContextPlugin, ObservableMixin );
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+
6
+ /**
7
+ * @module core/editingkeystrokehandler
8
+ */
9
+
10
+ import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
11
+
12
+ /**
13
+ * A keystroke handler for editor editing. Its instance is available
14
+ * in {@link module:core/editor/editor~Editor#keystrokes} so plugins
15
+ * can register their keystrokes.
16
+ *
17
+ * E.g. an undo plugin would do this:
18
+ *
19
+ * editor.keystrokes.set( 'Ctrl+Z', 'undo' );
20
+ * editor.keystrokes.set( 'Ctrl+Shift+Z', 'redo' );
21
+ * editor.keystrokes.set( 'Ctrl+Y', 'redo' );
22
+ *
23
+ * @extends module:utils/keystrokehandler~KeystrokeHandler
24
+ */
25
+ export default class EditingKeystrokeHandler extends KeystrokeHandler {
26
+ /**
27
+ * Creates an instance of the keystroke handler.
28
+ *
29
+ * @param {module:core/editor/editor~Editor} editor
30
+ */
31
+ constructor( editor ) {
32
+ super();
33
+
34
+ /**
35
+ * The editor instance.
36
+ *
37
+ * @readonly
38
+ * @member {module:core/editor/editor~Editor}
39
+ */
40
+ this.editor = editor;
41
+ }
42
+
43
+ /**
44
+ * Registers a handler for the specified keystroke.
45
+ *
46
+ * The handler can be specified as a command name or a callback.
47
+ *
48
+ * @param {String|Array.<String|Number>} keystroke Keystroke defined in a format accepted by
49
+ * the {@link module:utils/keyboard~parseKeystroke} function.
50
+ * @param {Function|String} callback If a string is passed, then the keystroke will
51
+ * {@link module:core/editor/editor~Editor#execute execute a command}.
52
+ * If a function, then it will be called with the
53
+ * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
54
+ * a `cancel()` helper to both `preventDefault()` and `stopPropagation()` of the event.
55
+ * @param {Object} [options={}] Additional options.
56
+ * @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of the keystroke
57
+ * callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
58
+ * are called in the order they were added.
59
+ */
60
+ set( keystroke, callback, options = {} ) {
61
+ if ( typeof callback == 'string' ) {
62
+ const commandName = callback;
63
+
64
+ callback = ( evtData, cancel ) => {
65
+ this.editor.execute( commandName );
66
+ cancel();
67
+ };
68
+ }
69
+
70
+ super.set( keystroke, callback, options );
71
+ }
72
+ }