@ckeditor/ckeditor5-core 36.0.0 → 37.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.
@@ -2,17 +2,17 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
6
5
  /**
7
6
  * @module core/editor/utils/securesourceelement
8
7
  */
8
+ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
9
  /**
10
10
  * Marks the source element on which the editor was initialized. This prevents other editor instances from using this element.
11
11
  *
12
12
  * Running multiple editor instances on the same source element causes various issues and it is
13
13
  * crucial this helper is called as soon as the source element is known to prevent collisions.
14
14
  *
15
- * @param {module:core/editor/editor~Editor} editor Editor instance.
15
+ * @param editor Editor instance.
16
16
  */
17
17
  export default function secureSourceElement(editor) {
18
18
  const sourceElement = editor.sourceElement;
@@ -28,7 +28,7 @@ export default function secureSourceElement(editor) {
28
28
  * created with an unique DOM element.
29
29
  *
30
30
  * @error editor-source-element-already-used
31
- * @param {HTMLElement} element DOM element that caused the collision.
31
+ * @param element DOM element that caused the collision.
32
32
  */
33
33
  throw new CKEditorError('editor-source-element-already-used', editor);
34
34
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,58 @@
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
7
+ */
8
+ export { default as Plugin, type PluginDependencies, type PluginConstructor } from './plugin';
9
+ export { default as Command, type CommandExecuteEvent } from './command';
10
+ export { default as MultiCommand } from './multicommand';
11
+ export type { CommandsMap } from './commandcollection';
12
+ export type { PluginsMap, default as PluginCollection } from './plugincollection';
13
+ export { default as Context, type ContextConfig } from './context';
14
+ export { default as ContextPlugin, type ContextPluginDependencies } from './contextplugin';
15
+ export { type EditingKeystrokeCallback } from './editingkeystrokehandler';
16
+ export { default as Editor, type EditorReadyEvent, type EditorDestroyEvent } from './editor/editor';
17
+ export type { EditorConfig, LanguageConfig, ToolbarConfig, ToolbarConfigItem } from './editor/editorconfig';
18
+ export { default as attachToForm } from './editor/utils/attachtoform';
19
+ export { default as DataApiMixin, type DataApi } from './editor/utils/dataapimixin';
20
+ export { default as ElementApiMixin, type ElementApi } from './editor/utils/elementapimixin';
21
+ export { default as secureSourceElement } from './editor/utils/securesourceelement';
22
+ export { default as PendingActions, type PendingAction } from './pendingactions';
23
+ export declare const icons: {
24
+ bold: string;
25
+ cancel: string;
26
+ caption: string;
27
+ check: string;
28
+ cog: string;
29
+ eraser: string;
30
+ image: string;
31
+ lowVision: string;
32
+ importExport: string;
33
+ paragraph: string;
34
+ plus: string;
35
+ text: string;
36
+ alignBottom: string;
37
+ alignMiddle: string;
38
+ alignTop: string;
39
+ alignLeft: string;
40
+ alignCenter: string;
41
+ alignRight: string;
42
+ alignJustify: string;
43
+ objectLeft: string;
44
+ objectCenter: string;
45
+ objectRight: string;
46
+ objectFullWidth: string;
47
+ objectInline: string;
48
+ objectBlockLeft: string;
49
+ objectBlockRight: string;
50
+ objectSizeFull: string;
51
+ objectSizeLarge: string;
52
+ objectSizeSmall: string;
53
+ objectSizeMedium: string;
54
+ pencil: string;
55
+ pilcrow: string;
56
+ quote: string;
57
+ threeVerticalDots: string;
58
+ };
@@ -0,0 +1,66 @@
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/multicommand
7
+ */
8
+ import Command from './command';
9
+ import { type PriorityString } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * A CKEditor command that aggregates other commands.
12
+ *
13
+ * This command is used to proxy multiple commands. The multi-command is enabled when
14
+ * at least one of its registered child commands is enabled.
15
+ * When executing a multi-command, the first enabled command with highest priority will be executed.
16
+ *
17
+ * ```ts
18
+ * const multiCommand = new MultiCommand( editor );
19
+ *
20
+ * const commandFoo = new Command( editor );
21
+ * const commandBar = new Command( editor );
22
+ *
23
+ * // Register a child command.
24
+ * multiCommand.registerChildCommand( commandFoo );
25
+ * // Register a child command with a low priority.
26
+ * multiCommand.registerChildCommand( commandBar, { priority: 'low' } );
27
+ *
28
+ * // Enable one of the commands.
29
+ * commandBar.isEnabled = true;
30
+ *
31
+ * multiCommand.execute(); // Will execute commandBar.
32
+ * ```
33
+ */
34
+ export default class MultiCommand extends Command {
35
+ /**
36
+ * Registered child commands definitions.
37
+ */
38
+ private _childCommandsDefinitions;
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ refresh(): void;
43
+ /**
44
+ * Executes the first enabled command which has the highest priority of all registered child commands.
45
+ *
46
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
47
+ */
48
+ execute(...args: Array<unknown>): unknown;
49
+ /**
50
+ * Registers a child command.
51
+ *
52
+ * @param options An object with configuration options.
53
+ * @param options.priority Priority of a command to register.
54
+ */
55
+ registerChildCommand(command: Command, options?: {
56
+ priority?: PriorityString;
57
+ }): void;
58
+ /**
59
+ * Checks if any of child commands is enabled.
60
+ */
61
+ private _checkEnabled;
62
+ /**
63
+ * Returns a first enabled command with the highest priority or `undefined` if none of them is enabled.
64
+ */
65
+ private _getFirstEnabledCommand;
66
+ }
@@ -2,11 +2,11 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- import Command from './command';
6
- import { insertToPriorityArray } from '@ckeditor/ckeditor5-utils';
7
5
  /**
8
6
  * @module core/multicommand
9
7
  */
8
+ import Command from './command';
9
+ import { insertToPriorityArray } from '@ckeditor/ckeditor5-utils';
10
10
  /**
11
11
  * A CKEditor command that aggregates other commands.
12
12
  *
@@ -14,34 +14,28 @@ import { insertToPriorityArray } from '@ckeditor/ckeditor5-utils';
14
14
  * at least one of its registered child commands is enabled.
15
15
  * When executing a multi-command, the first enabled command with highest priority will be executed.
16
16
  *
17
- * const multiCommand = new MultiCommand( editor );
18
- *
19
- * const commandFoo = new Command( editor );
20
- * const commandBar = new Command( editor );
17
+ * ```ts
18
+ * const multiCommand = new MultiCommand( editor );
21
19
  *
22
- * // Register a child command.
23
- * multiCommand.registerChildCommand( commandFoo );
24
- * // Register a child command with a low priority.
25
- * multiCommand.registerChildCommand( commandBar, { priority: 'low' } );
20
+ * const commandFoo = new Command( editor );
21
+ * const commandBar = new Command( editor );
26
22
  *
27
- * // Enable one of the commands.
28
- * commandBar.isEnabled = true;
23
+ * // Register a child command.
24
+ * multiCommand.registerChildCommand( commandFoo );
25
+ * // Register a child command with a low priority.
26
+ * multiCommand.registerChildCommand( commandBar, { priority: 'low' } );
29
27
  *
30
- * multiCommand.execute(); // Will execute commandBar.
28
+ * // Enable one of the commands.
29
+ * commandBar.isEnabled = true;
31
30
  *
32
- * @extends module:core/command~Command
31
+ * multiCommand.execute(); // Will execute commandBar.
32
+ * ```
33
33
  */
34
34
  export default class MultiCommand extends Command {
35
- /**
36
- * @inheritDoc
37
- */
38
- constructor(editor) {
39
- super(editor);
35
+ constructor() {
36
+ super(...arguments);
40
37
  /**
41
38
  * Registered child commands definitions.
42
- *
43
- * @type {Array.<Object>}
44
- * @private
45
39
  */
46
40
  this._childCommandsDefinitions = [];
47
41
  }
@@ -54,7 +48,7 @@ export default class MultiCommand extends Command {
54
48
  /**
55
49
  * Executes the first enabled command which has the highest priority of all registered child commands.
56
50
  *
57
- * @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
51
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
58
52
  */
59
53
  execute(...args) {
60
54
  const command = this._getFirstEnabledCommand();
@@ -63,9 +57,8 @@ export default class MultiCommand extends Command {
63
57
  /**
64
58
  * Registers a child command.
65
59
  *
66
- * @param {module:core/command~Command} command
67
- * @param {Object} options An object with configuration options.
68
- * @param {module:utils/priorities~PriorityString} [options.priority='normal'] Priority of a command to register.
60
+ * @param options An object with configuration options.
61
+ * @param options.priority Priority of a command to register.
69
62
  */
70
63
  registerChildCommand(command, options = {}) {
71
64
  insertToPriorityArray(this._childCommandsDefinitions, { command, priority: options.priority || 'normal' });
@@ -75,17 +68,12 @@ export default class MultiCommand extends Command {
75
68
  }
76
69
  /**
77
70
  * Checks if any of child commands is enabled.
78
- *
79
- * @private
80
71
  */
81
72
  _checkEnabled() {
82
73
  this.isEnabled = !!this._getFirstEnabledCommand();
83
74
  }
84
75
  /**
85
76
  * Returns a first enabled command with the highest priority or `undefined` if none of them is enabled.
86
- *
87
- * @returns {module:core/command~Command|undefined}
88
- * @private
89
77
  */
90
78
  _getFirstEnabledCommand() {
91
79
  const commandDefinition = this._childCommandsDefinitions.find(({ command }) => command.isEnabled);
@@ -0,0 +1,122 @@
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/pendingactions
7
+ */
8
+ import ContextPlugin from './contextplugin';
9
+ import { type CollectionAddEvent, type CollectionRemoveEvent, type Observable } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * The list of pending editor actions.
12
+ *
13
+ * This plugin should be used to synchronise plugins that execute long-lasting actions
14
+ * (e.g. file upload) with the editor integration. It gives the developer who integrates the editor
15
+ * an easy way to check if there are any actions pending whenever such information is needed.
16
+ * All plugins that register a pending action also provide a message about the action that is ongoing
17
+ * which can be displayed to the user. This lets them decide if they want to interrupt the action or wait.
18
+ *
19
+ * Adding and updating a pending action:
20
+ *
21
+ * ```ts
22
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
23
+ * const action = pendingActions.add( 'Upload in progress: 0%.' );
24
+ *
25
+ * // You can update the message:
26
+ * action.message = 'Upload in progress: 10%.';
27
+ * ```
28
+ *
29
+ * Removing a pending action:
30
+ *
31
+ * ```ts
32
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
33
+ * const action = pendingActions.add( 'Unsaved changes.' );
34
+ *
35
+ * pendingActions.remove( action );
36
+ * ```
37
+ *
38
+ * Getting pending actions:
39
+ *
40
+ * ```ts
41
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
42
+ *
43
+ * const action1 = pendingActions.add( 'Action 1' );
44
+ * const action2 = pendingActions.add( 'Action 2' );
45
+ *
46
+ * pendingActions.first; // Returns action1
47
+ * Array.from( pendingActions ); // Returns [ action1, action2 ]
48
+ * ```
49
+ *
50
+ * This plugin is used by features like {@link module:upload/filerepository~FileRepository} to register their ongoing actions
51
+ * and by features like {@link module:autosave/autosave~Autosave} to detect whether there are any ongoing actions.
52
+ * Read more about saving the data in the {@glink installation/getting-started/getting-and-setting-data Saving and getting data} guide.
53
+ */
54
+ export default class PendingActions extends ContextPlugin implements Iterable<PendingAction> {
55
+ /**
56
+ * Defines whether there is any registered pending action.
57
+ *
58
+ * @readonly
59
+ * @observable
60
+ */
61
+ hasAny: boolean;
62
+ /**
63
+ * A list of pending actions.
64
+ */
65
+ private _actions;
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ static get pluginName(): 'PendingActions';
70
+ /**
71
+ * @inheritDoc
72
+ */
73
+ init(): void;
74
+ /**
75
+ * Adds an action to the list of pending actions.
76
+ *
77
+ * This method returns an action object with an observable message property.
78
+ * The action object can be later used in the {@link #remove} method. It also allows you to change the message.
79
+ *
80
+ * @param message The action message.
81
+ * @returns An observable object that represents a pending action.
82
+ */
83
+ add(message: string): PendingAction;
84
+ /**
85
+ * Removes an action from the list of pending actions.
86
+ *
87
+ * @param action An action object.
88
+ */
89
+ remove(action: PendingAction): void;
90
+ /**
91
+ * Returns the first action from the list or null if the list is empty
92
+ *
93
+ * @returns The pending action object.
94
+ */
95
+ get first(): PendingAction | null;
96
+ /**
97
+ * Iterable interface.
98
+ */
99
+ [Symbol.iterator](): Iterator<PendingAction>;
100
+ }
101
+ export interface PendingAction extends Observable {
102
+ message: string;
103
+ }
104
+ /**
105
+ * Fired when an action is added to the list.
106
+ *
107
+ * @eventName add
108
+ * @param action The added action.
109
+ */
110
+ export type PendingActionsAddEvent = CollectionAddEvent<PendingAction>;
111
+ /**
112
+ * Fired when an action is removed from the list.
113
+ *
114
+ * @eventName remove
115
+ * @param action The removed action.
116
+ */
117
+ export type PendingActionsRemoveEvent = CollectionRemoveEvent<PendingAction>;
118
+ declare module '@ckeditor/ckeditor5-core' {
119
+ interface PluginsMap {
120
+ [PendingActions.pluginName]: PendingActions;
121
+ }
122
+ }
@@ -18,34 +18,38 @@ import { CKEditorError, Collection, ObservableMixin } from '@ckeditor/ckeditor5-
18
18
  *
19
19
  * Adding and updating a pending action:
20
20
  *
21
- * const pendingActions = editor.plugins.get( 'PendingActions' );
22
- * const action = pendingActions.add( 'Upload in progress: 0%.' );
21
+ * ```ts
22
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
23
+ * const action = pendingActions.add( 'Upload in progress: 0%.' );
23
24
  *
24
- * // You can update the message:
25
- * action.message = 'Upload in progress: 10%.';
25
+ * // You can update the message:
26
+ * action.message = 'Upload in progress: 10%.';
27
+ * ```
26
28
  *
27
29
  * Removing a pending action:
28
30
  *
29
- * const pendingActions = editor.plugins.get( 'PendingActions' );
30
- * const action = pendingActions.add( 'Unsaved changes.' );
31
+ * ```ts
32
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
33
+ * const action = pendingActions.add( 'Unsaved changes.' );
31
34
  *
32
- * pendingActions.remove( action );
35
+ * pendingActions.remove( action );
36
+ * ```
33
37
  *
34
38
  * Getting pending actions:
35
39
  *
36
- * const pendingActions = editor.plugins.get( 'PendingActions' );
40
+ * ```ts
41
+ * const pendingActions = editor.plugins.get( 'PendingActions' );
37
42
  *
38
- * const action1 = pendingActions.add( 'Action 1' );
39
- * const action2 = pendingActions.add( 'Action 2' );
43
+ * const action1 = pendingActions.add( 'Action 1' );
44
+ * const action2 = pendingActions.add( 'Action 2' );
40
45
  *
41
- * pendingActions.first; // Returns action1
42
- * Array.from( pendingActions ); // Returns [ action1, action2 ]
46
+ * pendingActions.first; // Returns action1
47
+ * Array.from( pendingActions ); // Returns [ action1, action2 ]
48
+ * ```
43
49
  *
44
50
  * This plugin is used by features like {@link module:upload/filerepository~FileRepository} to register their ongoing actions
45
51
  * and by features like {@link module:autosave/autosave~Autosave} to detect whether there are any ongoing actions.
46
52
  * Read more about saving the data in the {@glink installation/getting-started/getting-and-setting-data Saving and getting data} guide.
47
- *
48
- * @extends module:core/contextplugin~ContextPlugin
49
53
  */
50
54
  export default class PendingActions extends ContextPlugin {
51
55
  /**
@@ -58,20 +62,7 @@ export default class PendingActions extends ContextPlugin {
58
62
  * @inheritDoc
59
63
  */
60
64
  init() {
61
- /**
62
- * Defines whether there is any registered pending action.
63
- *
64
- * @readonly
65
- * @observable
66
- * @member {Boolean} #hasAny
67
- */
68
65
  this.set('hasAny', false);
69
- /**
70
- * A list of pending actions.
71
- *
72
- * @private
73
- * @type {module:utils/collection~Collection}
74
- */
75
66
  this._actions = new Collection({ idProperty: '_id' });
76
67
  this._actions.delegate('add', 'remove').to(this);
77
68
  }
@@ -81,8 +72,8 @@ export default class PendingActions extends ContextPlugin {
81
72
  * This method returns an action object with an observable message property.
82
73
  * The action object can be later used in the {@link #remove} method. It also allows you to change the message.
83
74
  *
84
- * @param {String} message The action message.
85
- * @returns {Object} An observable object that represents a pending action.
75
+ * @param message The action message.
76
+ * @returns An observable object that represents a pending action.
86
77
  */
87
78
  add(message) {
88
79
  if (typeof message !== 'string') {
@@ -102,7 +93,7 @@ export default class PendingActions extends ContextPlugin {
102
93
  /**
103
94
  * Removes an action from the list of pending actions.
104
95
  *
105
- * @param {Object} action An action object.
96
+ * @param action An action object.
106
97
  */
107
98
  remove(action) {
108
99
  this._actions.remove(action);
@@ -111,15 +102,13 @@ export default class PendingActions extends ContextPlugin {
111
102
  /**
112
103
  * Returns the first action from the list or null if the list is empty
113
104
  *
114
- * returns {Object|null} The pending action object.
105
+ * @returns The pending action object.
115
106
  */
116
107
  get first() {
117
108
  return this._actions.get(0);
118
109
  }
119
110
  /**
120
111
  * Iterable interface.
121
- *
122
- * @returns {Iterable.<*>}
123
112
  */
124
113
  [Symbol.iterator]() {
125
114
  return this._actions[Symbol.iterator]();