@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/pendingactions.d.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
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 ~PendingActions#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 ~PendingActions#remove
|
|
115
|
-
* @param action The removed action.
|
|
116
|
-
*/
|
|
117
|
-
export type PendingActionsRemoveEvent = CollectionRemoveEvent<PendingAction>;
|
|
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 ~PendingActions#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 ~PendingActions#remove
|
|
115
|
+
* @param action The removed action.
|
|
116
|
+
*/
|
|
117
|
+
export type PendingActionsRemoveEvent = CollectionRemoveEvent<PendingAction>;
|
package/src/pendingactions.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
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 { CKEditorError, Collection, ObservableMixin } 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 {
|
|
55
|
-
/**
|
|
56
|
-
* @inheritDoc
|
|
57
|
-
*/
|
|
58
|
-
static get pluginName() {
|
|
59
|
-
return 'PendingActions';
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @inheritDoc
|
|
63
|
-
*/
|
|
64
|
-
init() {
|
|
65
|
-
this.set('hasAny', false);
|
|
66
|
-
this._actions = new Collection({ idProperty: '_id' });
|
|
67
|
-
this._actions.delegate('add', 'remove').to(this);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Adds an action to the list of pending actions.
|
|
71
|
-
*
|
|
72
|
-
* This method returns an action object with an observable message property.
|
|
73
|
-
* The action object can be later used in the {@link #remove} method. It also allows you to change the message.
|
|
74
|
-
*
|
|
75
|
-
* @param message The action message.
|
|
76
|
-
* @returns An observable object that represents a pending action.
|
|
77
|
-
*/
|
|
78
|
-
add(message) {
|
|
79
|
-
if (typeof message !== 'string') {
|
|
80
|
-
/**
|
|
81
|
-
* The message must be a string.
|
|
82
|
-
*
|
|
83
|
-
* @error pendingactions-add-invalid-message
|
|
84
|
-
*/
|
|
85
|
-
throw new CKEditorError('pendingactions-add-invalid-message', this);
|
|
86
|
-
}
|
|
87
|
-
const action = new (ObservableMixin())();
|
|
88
|
-
action.set('message', message);
|
|
89
|
-
this._actions.add(action);
|
|
90
|
-
this.hasAny = true;
|
|
91
|
-
return action;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Removes an action from the list of pending actions.
|
|
95
|
-
*
|
|
96
|
-
* @param action An action object.
|
|
97
|
-
*/
|
|
98
|
-
remove(action) {
|
|
99
|
-
this._actions.remove(action);
|
|
100
|
-
this.hasAny = !!this._actions.length;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns the first action from the list or null if the list is empty
|
|
104
|
-
*
|
|
105
|
-
* @returns The pending action object.
|
|
106
|
-
*/
|
|
107
|
-
get first() {
|
|
108
|
-
return this._actions.get(0);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Iterable interface.
|
|
112
|
-
*/
|
|
113
|
-
[Symbol.iterator]() {
|
|
114
|
-
return this._actions[Symbol.iterator]();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
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 { CKEditorError, Collection, ObservableMixin } 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 {
|
|
55
|
+
/**
|
|
56
|
+
* @inheritDoc
|
|
57
|
+
*/
|
|
58
|
+
static get pluginName() {
|
|
59
|
+
return 'PendingActions';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc
|
|
63
|
+
*/
|
|
64
|
+
init() {
|
|
65
|
+
this.set('hasAny', false);
|
|
66
|
+
this._actions = new Collection({ idProperty: '_id' });
|
|
67
|
+
this._actions.delegate('add', 'remove').to(this);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Adds an action to the list of pending actions.
|
|
71
|
+
*
|
|
72
|
+
* This method returns an action object with an observable message property.
|
|
73
|
+
* The action object can be later used in the {@link #remove} method. It also allows you to change the message.
|
|
74
|
+
*
|
|
75
|
+
* @param message The action message.
|
|
76
|
+
* @returns An observable object that represents a pending action.
|
|
77
|
+
*/
|
|
78
|
+
add(message) {
|
|
79
|
+
if (typeof message !== 'string') {
|
|
80
|
+
/**
|
|
81
|
+
* The message must be a string.
|
|
82
|
+
*
|
|
83
|
+
* @error pendingactions-add-invalid-message
|
|
84
|
+
*/
|
|
85
|
+
throw new CKEditorError('pendingactions-add-invalid-message', this);
|
|
86
|
+
}
|
|
87
|
+
const action = new (ObservableMixin())();
|
|
88
|
+
action.set('message', message);
|
|
89
|
+
this._actions.add(action);
|
|
90
|
+
this.hasAny = true;
|
|
91
|
+
return action;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Removes an action from the list of pending actions.
|
|
95
|
+
*
|
|
96
|
+
* @param action An action object.
|
|
97
|
+
*/
|
|
98
|
+
remove(action) {
|
|
99
|
+
this._actions.remove(action);
|
|
100
|
+
this.hasAny = !!this._actions.length;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the first action from the list or null if the list is empty
|
|
104
|
+
*
|
|
105
|
+
* @returns The pending action object.
|
|
106
|
+
*/
|
|
107
|
+
get first() {
|
|
108
|
+
return this._actions.get(0);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Iterable interface.
|
|
112
|
+
*/
|
|
113
|
+
[Symbol.iterator]() {
|
|
114
|
+
return this._actions[Symbol.iterator]();
|
|
115
|
+
}
|
|
116
|
+
}
|