@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.
- package/LICENSE.md +17 -0
- package/README.md +18 -0
- package/lang/contexts.json +8 -0
- package/lang/translations/af.po +41 -0
- package/lang/translations/ar.po +41 -0
- package/lang/translations/ast.po +41 -0
- package/lang/translations/az.po +41 -0
- package/lang/translations/bg.po +41 -0
- package/lang/translations/ca.po +41 -0
- package/lang/translations/cs.po +41 -0
- package/lang/translations/da.po +41 -0
- package/lang/translations/de-ch.po +41 -0
- package/lang/translations/de.po +41 -0
- package/lang/translations/el.po +41 -0
- package/lang/translations/en-au.po +41 -0
- package/lang/translations/en-gb.po +41 -0
- package/lang/translations/en.po +41 -0
- package/lang/translations/eo.po +41 -0
- package/lang/translations/es.po +41 -0
- package/lang/translations/et.po +41 -0
- package/lang/translations/eu.po +41 -0
- package/lang/translations/fa.po +41 -0
- package/lang/translations/fi.po +41 -0
- package/lang/translations/fr.po +41 -0
- package/lang/translations/gl.po +41 -0
- package/lang/translations/he.po +41 -0
- package/lang/translations/hi.po +41 -0
- package/lang/translations/hr.po +41 -0
- package/lang/translations/hu.po +41 -0
- package/lang/translations/id.po +41 -0
- package/lang/translations/it.po +41 -0
- package/lang/translations/ja.po +41 -0
- package/lang/translations/km.po +41 -0
- package/lang/translations/kn.po +41 -0
- package/lang/translations/ko.po +41 -0
- package/lang/translations/ku.po +41 -0
- package/lang/translations/lt.po +41 -0
- package/lang/translations/lv.po +41 -0
- package/lang/translations/nb.po +41 -0
- package/lang/translations/ne.po +41 -0
- package/lang/translations/nl.po +41 -0
- package/lang/translations/no.po +41 -0
- package/lang/translations/oc.po +41 -0
- package/lang/translations/pl.po +41 -0
- package/lang/translations/pt-br.po +41 -0
- package/lang/translations/pt.po +41 -0
- package/lang/translations/ro.po +41 -0
- package/lang/translations/ru.po +41 -0
- package/lang/translations/sk.po +41 -0
- package/lang/translations/sl.po +41 -0
- package/lang/translations/sq.po +41 -0
- package/lang/translations/sr-latn.po +41 -0
- package/lang/translations/sr.po +41 -0
- package/lang/translations/sv.po +41 -0
- package/lang/translations/th.po +41 -0
- package/lang/translations/tk.po +41 -0
- package/lang/translations/tr.po +41 -0
- package/lang/translations/tt.po +41 -0
- package/lang/translations/ug.po +41 -0
- package/lang/translations/uk.po +41 -0
- package/lang/translations/vi.po +41 -0
- package/lang/translations/zh-cn.po +41 -0
- package/lang/translations/zh.po +41 -0
- package/package.json +65 -0
- package/src/command.js +244 -0
- package/src/commandcollection.js +109 -0
- package/src/context.js +355 -0
- package/src/contextplugin.js +61 -0
- package/src/editingkeystrokehandler.js +72 -0
- package/src/editor/editor.js +448 -0
- package/src/editor/editorconfig.jsdoc +325 -0
- package/src/editor/editorui.js +275 -0
- package/src/editor/editorwithui.jsdoc +29 -0
- package/src/editor/utils/attachtoform.js +67 -0
- package/src/editor/utils/dataapimixin.js +81 -0
- package/src/editor/utils/elementapimixin.js +65 -0
- package/src/editor/utils/securesourceelement.js +49 -0
- package/src/index.js +95 -0
- package/src/multicommand.js +101 -0
- package/src/pendingactions.js +155 -0
- package/src/plugin.js +292 -0
- package/src/plugincollection.js +597 -0
- package/theme/icons/align-bottom.svg +1 -0
- package/theme/icons/align-center.svg +1 -0
- package/theme/icons/align-justify.svg +1 -0
- package/theme/icons/align-left.svg +1 -0
- package/theme/icons/align-middle.svg +1 -0
- package/theme/icons/align-right.svg +1 -0
- package/theme/icons/align-top.svg +1 -0
- package/theme/icons/cancel.svg +1 -0
- package/theme/icons/caption.svg +1 -0
- package/theme/icons/check.svg +1 -0
- package/theme/icons/cog.svg +1 -0
- package/theme/icons/eraser.svg +1 -0
- package/theme/icons/image.svg +1 -0
- package/theme/icons/low-vision.svg +1 -0
- package/theme/icons/object-center.svg +1 -0
- package/theme/icons/object-full-width.svg +1 -0
- package/theme/icons/object-inline-left.svg +1 -0
- package/theme/icons/object-inline-right.svg +1 -0
- package/theme/icons/object-inline.svg +1 -0
- package/theme/icons/object-left.svg +1 -0
- package/theme/icons/object-right.svg +1 -0
- package/theme/icons/object-size-full.svg +1 -0
- package/theme/icons/object-size-large.svg +1 -0
- package/theme/icons/object-size-medium.svg +1 -0
- package/theme/icons/object-size-small.svg +1 -0
- package/theme/icons/pencil.svg +1 -0
- package/theme/icons/pilcrow.svg +1 -0
- package/theme/icons/quote.svg +1 -0
- package/theme/icons/three-vertical-dots.svg +1 -0
package/src/plugin.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
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/plugin
|
|
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 CKEditor plugin classes.
|
|
15
|
+
*
|
|
16
|
+
* @implements module:core/plugin~PluginInterface
|
|
17
|
+
* @mixes module:utils/observablemixin~ObservableMixin
|
|
18
|
+
*/
|
|
19
|
+
export default class Plugin {
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
constructor( editor ) {
|
|
24
|
+
/**
|
|
25
|
+
* The editor instance.
|
|
26
|
+
*
|
|
27
|
+
* Note that most editors implement the {@link module:core/editor/editorwithui~EditorWithUI} interface in addition
|
|
28
|
+
* to the base {@link module:core/editor/editor~Editor} interface. However, editors with an external UI
|
|
29
|
+
* (i.e. Bootstrap-based) or a headless editor may not implement the {@link module:core/editor/editorwithui~EditorWithUI}
|
|
30
|
+
* interface.
|
|
31
|
+
*
|
|
32
|
+
* Because of above, to make plugins more universal, it is recommended to split features into:
|
|
33
|
+
* - The "editing" part that only uses the {@link module:core/editor/editor~Editor} interface.
|
|
34
|
+
* - The "UI" part that uses both the {@link module:core/editor/editor~Editor} interface and
|
|
35
|
+
* the {@link module:core/editor/editorwithui~EditorWithUI} interface.
|
|
36
|
+
*
|
|
37
|
+
* @readonly
|
|
38
|
+
* @member {module:core/editor/editor~Editor} #editor
|
|
39
|
+
*/
|
|
40
|
+
this.editor = editor;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Flag indicating whether a plugin is enabled or disabled.
|
|
44
|
+
* A disabled plugin will not transform text.
|
|
45
|
+
*
|
|
46
|
+
* Plugin can be simply disabled like that:
|
|
47
|
+
*
|
|
48
|
+
* // Disable the plugin so that no toolbars are visible.
|
|
49
|
+
* editor.plugins.get( 'TextTransformation' ).isEnabled = false;
|
|
50
|
+
*
|
|
51
|
+
* You can also use {@link #forceDisabled} method.
|
|
52
|
+
*
|
|
53
|
+
* @observable
|
|
54
|
+
* @readonly
|
|
55
|
+
* @member {Boolean} #isEnabled
|
|
56
|
+
*/
|
|
57
|
+
this.set( 'isEnabled', true );
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Holds identifiers for {@link #forceDisabled} mechanism.
|
|
61
|
+
*
|
|
62
|
+
* @type {Set.<String>}
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
this._disableStack = new Set();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Disables the plugin.
|
|
70
|
+
*
|
|
71
|
+
* Plugin may be disabled by multiple features or algorithms (at once). When disabling a plugin, unique id should be passed
|
|
72
|
+
* (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the plugin.
|
|
73
|
+
* The plugin becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
|
|
74
|
+
*
|
|
75
|
+
* Disabling and enabling a plugin:
|
|
76
|
+
*
|
|
77
|
+
* plugin.isEnabled; // -> true
|
|
78
|
+
* plugin.forceDisabled( 'MyFeature' );
|
|
79
|
+
* plugin.isEnabled; // -> false
|
|
80
|
+
* plugin.clearForceDisabled( 'MyFeature' );
|
|
81
|
+
* plugin.isEnabled; // -> true
|
|
82
|
+
*
|
|
83
|
+
* Plugin disabled by multiple features:
|
|
84
|
+
*
|
|
85
|
+
* plugin.forceDisabled( 'MyFeature' );
|
|
86
|
+
* plugin.forceDisabled( 'OtherFeature' );
|
|
87
|
+
* plugin.clearForceDisabled( 'MyFeature' );
|
|
88
|
+
* plugin.isEnabled; // -> false
|
|
89
|
+
* plugin.clearForceDisabled( 'OtherFeature' );
|
|
90
|
+
* plugin.isEnabled; // -> true
|
|
91
|
+
*
|
|
92
|
+
* Multiple disabling with the same identifier is redundant:
|
|
93
|
+
*
|
|
94
|
+
* plugin.forceDisabled( 'MyFeature' );
|
|
95
|
+
* plugin.forceDisabled( 'MyFeature' );
|
|
96
|
+
* plugin.clearForceDisabled( 'MyFeature' );
|
|
97
|
+
* plugin.isEnabled; // -> true
|
|
98
|
+
*
|
|
99
|
+
* **Note:** some plugins or algorithms may have more complex logic when it comes to enabling or disabling certain plugins,
|
|
100
|
+
* so the plugin might be still disabled after {@link #clearForceDisabled} was used.
|
|
101
|
+
*
|
|
102
|
+
* @param {String} id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the plugin.
|
|
103
|
+
*/
|
|
104
|
+
forceDisabled( id ) {
|
|
105
|
+
this._disableStack.add( id );
|
|
106
|
+
|
|
107
|
+
if ( this._disableStack.size == 1 ) {
|
|
108
|
+
this.on( 'set:isEnabled', forceDisable, { priority: 'highest' } );
|
|
109
|
+
this.isEnabled = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
|
|
115
|
+
*
|
|
116
|
+
* @param {String} id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
|
|
117
|
+
*/
|
|
118
|
+
clearForceDisabled( id ) {
|
|
119
|
+
this._disableStack.delete( id );
|
|
120
|
+
|
|
121
|
+
if ( this._disableStack.size == 0 ) {
|
|
122
|
+
this.off( 'set:isEnabled', forceDisable );
|
|
123
|
+
this.isEnabled = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @inheritDoc
|
|
129
|
+
*/
|
|
130
|
+
destroy() {
|
|
131
|
+
this.stopListening();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @inheritDoc
|
|
136
|
+
*/
|
|
137
|
+
static get isContextPlugin() {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
mix( Plugin, ObservableMixin );
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The base interface for CKEditor plugins.
|
|
146
|
+
*
|
|
147
|
+
* In its minimal form a plugin can be a simple function that accepts {@link module:core/editor/editor~Editor the editor}
|
|
148
|
+
* as a parameter:
|
|
149
|
+
*
|
|
150
|
+
* // A simple plugin that enables a data processor.
|
|
151
|
+
* function MyPlugin( editor ) {
|
|
152
|
+
* editor.data.processor = new MyDataProcessor();
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* In most cases however, you will want to inherit from the {@link module:core/plugin~Plugin} class which implements the
|
|
156
|
+
* {@link module:utils/observablemixin~ObservableMixin} and is, therefore, more convenient:
|
|
157
|
+
*
|
|
158
|
+
* class MyPlugin extends Plugin {
|
|
159
|
+
* init() {
|
|
160
|
+
* // `listenTo()` and `editor` are available thanks to `Plugin`.
|
|
161
|
+
* // By using `listenTo()` you will ensure that the listener is removed when
|
|
162
|
+
* // the plugin is destroyed.
|
|
163
|
+
* this.listenTo( this.editor.data, 'ready', () => {
|
|
164
|
+
* // Do something when the data is ready.
|
|
165
|
+
* } );
|
|
166
|
+
* }
|
|
167
|
+
* }
|
|
168
|
+
*
|
|
169
|
+
* The plugin can also implement methods (e.g. {@link module:core/plugin~PluginInterface#init `init()`} or
|
|
170
|
+
* {@link module:core/plugin~PluginInterface#destroy `destroy()`}) which, when present, will be used to properly
|
|
171
|
+
* initialize and destroy the plugin.
|
|
172
|
+
*
|
|
173
|
+
* **Note:** When defined as a plain function, the plugin acts as a constructor and will be
|
|
174
|
+
* called in parallel with other plugins' {@link module:core/plugin~PluginInterface#constructor constructors}.
|
|
175
|
+
* This means the code of that plugin will be executed **before** {@link module:core/plugin~PluginInterface#init `init()`} and
|
|
176
|
+
* {@link module:core/plugin~PluginInterface#afterInit `afterInit()`} methods of other plugins and, for instance,
|
|
177
|
+
* you cannot use it to extend other plugins' {@glink framework/guides/architecture/editing-engine#schema schema}
|
|
178
|
+
* rules as they are defined later on during the `init()` stage.
|
|
179
|
+
*
|
|
180
|
+
* @interface PluginInterface
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Creates a new plugin instance. This is the first step of the plugin initialization.
|
|
185
|
+
* See also {@link #init} and {@link #afterInit}.
|
|
186
|
+
*
|
|
187
|
+
* A plugin is always instantiated after its {@link module:core/plugin~PluginInterface.requires dependencies} and the
|
|
188
|
+
* {@link #init} and {@link #afterInit} methods are called in the same order.
|
|
189
|
+
*
|
|
190
|
+
* Usually, you will want to put your plugin's initialization code in the {@link #init} method.
|
|
191
|
+
* The constructor can be understood as "before init" and used in special cases, just like
|
|
192
|
+
* {@link #afterInit} serves the special "after init" scenarios (e.g.the code which depends on other
|
|
193
|
+
* plugins, but which does not {@link module:core/plugin~PluginInterface.requires explicitly require} them).
|
|
194
|
+
*
|
|
195
|
+
* @method #constructor
|
|
196
|
+
* @param {module:core/editor/editor~Editor} editor
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* An array of plugins required by this plugin.
|
|
201
|
+
*
|
|
202
|
+
* To keep the plugin class definition tight it is recommended to define this property as a static getter:
|
|
203
|
+
*
|
|
204
|
+
* import Image from './image.js';
|
|
205
|
+
*
|
|
206
|
+
* export default class ImageCaption {
|
|
207
|
+
* static get requires() {
|
|
208
|
+
* return [ Image ];
|
|
209
|
+
* }
|
|
210
|
+
* }
|
|
211
|
+
*
|
|
212
|
+
* @static
|
|
213
|
+
* @readonly
|
|
214
|
+
* @member {Array.<Function>|undefined} module:core/plugin~PluginInterface.requires
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* An optional name of the plugin. If set, the plugin will be available in
|
|
219
|
+
* {@link module:core/plugincollection~PluginCollection#get} by its
|
|
220
|
+
* name and its constructor. If not, then only by its constructor.
|
|
221
|
+
*
|
|
222
|
+
* The name should reflect the constructor name.
|
|
223
|
+
*
|
|
224
|
+
* To keep the plugin class definition tight, it is recommended to define this property as a static getter:
|
|
225
|
+
*
|
|
226
|
+
* export default class ImageCaption {
|
|
227
|
+
* static get pluginName() {
|
|
228
|
+
* return 'ImageCaption';
|
|
229
|
+
* }
|
|
230
|
+
* }
|
|
231
|
+
*
|
|
232
|
+
* Note: The native `Function.name` property could not be used to keep the plugin name because
|
|
233
|
+
* it will be mangled during code minification.
|
|
234
|
+
*
|
|
235
|
+
* Naming a plugin is necessary to enable removing it through the
|
|
236
|
+
* {@link module:core/editor/editorconfig~EditorConfig#removePlugins `config.removePlugins`} option.
|
|
237
|
+
*
|
|
238
|
+
* @static
|
|
239
|
+
* @readonly
|
|
240
|
+
* @member {String|undefined} module:core/plugin~PluginInterface.pluginName
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The second stage (after plugin {@link #constructor}) of the plugin initialization.
|
|
245
|
+
* Unlike the plugin constructor this method can be asynchronous.
|
|
246
|
+
*
|
|
247
|
+
* A plugin's `init()` method is called after its {@link module:core/plugin~PluginInterface.requires dependencies} are initialized,
|
|
248
|
+
* so in the same order as the constructors of these plugins.
|
|
249
|
+
*
|
|
250
|
+
* **Note:** This method is optional. A plugin instance does not need to have it defined.
|
|
251
|
+
*
|
|
252
|
+
* @method #init
|
|
253
|
+
* @returns {null|Promise}
|
|
254
|
+
*/
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The third (and last) stage of the plugin initialization. See also {@link #constructor} and {@link #init}.
|
|
258
|
+
*
|
|
259
|
+
* **Note:** This method is optional. A plugin instance does not need to have it defined.
|
|
260
|
+
*
|
|
261
|
+
* @method #afterInit
|
|
262
|
+
* @returns {null|Promise}
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Destroys the plugin.
|
|
267
|
+
*
|
|
268
|
+
* **Note:** This method is optional. A plugin instance does not need to have it defined.
|
|
269
|
+
*
|
|
270
|
+
* @method #destroy
|
|
271
|
+
* @returns {null|Promise}
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* A flag which defines if a plugin is allowed or not allowed to be used directly by a {@link module:core/context~Context}.
|
|
276
|
+
*
|
|
277
|
+
* @static
|
|
278
|
+
* @readonly
|
|
279
|
+
* @member {Boolean} module:core/plugin~PluginInterface.isContextPlugin
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* An array of loaded plugins.
|
|
284
|
+
*
|
|
285
|
+
* @typedef {Array.<module:core/plugin~PluginInterface>} module:core/plugin~LoadedPlugins
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
// Helper function that forces plugin to be disabled.
|
|
289
|
+
function forceDisable( evt ) {
|
|
290
|
+
evt.return = false;
|
|
291
|
+
evt.stop();
|
|
292
|
+
}
|