@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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# !!! IMPORTANT !!!
|
|
4
|
+
#
|
|
5
|
+
# Before you edit this file, please keep in mind that contributing to the project
|
|
6
|
+
# translations is possible ONLY via the Transifex online service.
|
|
7
|
+
#
|
|
8
|
+
# To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
|
|
9
|
+
#
|
|
10
|
+
# To learn more, check out the official contributor's guide:
|
|
11
|
+
# https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
|
|
12
|
+
#
|
|
13
|
+
msgid ""
|
|
14
|
+
msgstr ""
|
|
15
|
+
"Language-Team: Chinese (Taiwan) (https://www.transifex.com/ckeditor/teams/11143/zh_TW/)\n"
|
|
16
|
+
"Language: zh_TW\n"
|
|
17
|
+
"Plural-Forms: nplurals=1; plural=0;\n"
|
|
18
|
+
|
|
19
|
+
msgctxt "Label for the Cancel button."
|
|
20
|
+
msgid "Cancel"
|
|
21
|
+
msgstr "取消"
|
|
22
|
+
|
|
23
|
+
msgctxt "The label used by a button next to the color palette in the color picker that removes the color (resets it to an empty value, example usages in font color or table properties)."
|
|
24
|
+
msgid "Remove color"
|
|
25
|
+
msgstr "移除顏色"
|
|
26
|
+
|
|
27
|
+
msgctxt "The label used by a button next to the color palette in the color picker that restores the default value if the default table properties are specified."
|
|
28
|
+
msgid "Restore default"
|
|
29
|
+
msgstr ""
|
|
30
|
+
|
|
31
|
+
msgctxt "Label for the Save button."
|
|
32
|
+
msgid "Save"
|
|
33
|
+
msgstr "儲存"
|
|
34
|
+
|
|
35
|
+
msgctxt "Label of a toolbar button which reveals more toolbar items."
|
|
36
|
+
msgid "Show more items"
|
|
37
|
+
msgstr "顯示更多"
|
|
38
|
+
|
|
39
|
+
msgctxt "Label for an ‘X of Y’ status of a typical next/previous navigation. For instance, ‘Page 5 of 20’ or 'Search result 5 of 20'."
|
|
40
|
+
msgid "%0 of %1"
|
|
41
|
+
msgstr "%0/%1"
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ckeditor/ckeditor5-core",
|
|
3
|
+
"version": "30.0.0",
|
|
4
|
+
"description": "The core architecture of CKEditor 5 – the best browser-based rich text editor.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wysiwyg",
|
|
7
|
+
"rich text",
|
|
8
|
+
"editor",
|
|
9
|
+
"html",
|
|
10
|
+
"contentEditable",
|
|
11
|
+
"editing",
|
|
12
|
+
"operational transformation",
|
|
13
|
+
"ot",
|
|
14
|
+
"collaboration",
|
|
15
|
+
"collaborative",
|
|
16
|
+
"real-time",
|
|
17
|
+
"framework",
|
|
18
|
+
"ckeditor",
|
|
19
|
+
"ckeditor5",
|
|
20
|
+
"ckeditor 5",
|
|
21
|
+
"ckeditor5-lib",
|
|
22
|
+
"ckeditor5-dll"
|
|
23
|
+
],
|
|
24
|
+
"main": "src/index.js",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@ckeditor/ckeditor5-engine": "^30.0.0",
|
|
27
|
+
"@ckeditor/ckeditor5-ui": "^30.0.0",
|
|
28
|
+
"@ckeditor/ckeditor5-utils": "^30.0.0",
|
|
29
|
+
"lodash-es": "^4.17.15"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@ckeditor/ckeditor5-autoformat": "^30.0.0",
|
|
33
|
+
"@ckeditor/ckeditor5-basic-styles": "^30.0.0",
|
|
34
|
+
"@ckeditor/ckeditor5-block-quote": "^30.0.0",
|
|
35
|
+
"@ckeditor/ckeditor5-editor-classic": "^30.0.0",
|
|
36
|
+
"@ckeditor/ckeditor5-essentials": "^30.0.0",
|
|
37
|
+
"@ckeditor/ckeditor5-heading": "^30.0.0",
|
|
38
|
+
"@ckeditor/ckeditor5-image": "^30.0.0",
|
|
39
|
+
"@ckeditor/ckeditor5-indent": "^30.0.0",
|
|
40
|
+
"@ckeditor/ckeditor5-link": "^30.0.0",
|
|
41
|
+
"@ckeditor/ckeditor5-list": "^30.0.0",
|
|
42
|
+
"@ckeditor/ckeditor5-media-embed": "^30.0.0",
|
|
43
|
+
"@ckeditor/ckeditor5-paragraph": "^30.0.0",
|
|
44
|
+
"@ckeditor/ckeditor5-table": "^30.0.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=12.0.0",
|
|
48
|
+
"npm": ">=5.7.1"
|
|
49
|
+
},
|
|
50
|
+
"author": "CKSource (http://cksource.com/)",
|
|
51
|
+
"license": "GPL-2.0-or-later",
|
|
52
|
+
"homepage": "https://ckeditor.com/ckeditor-5",
|
|
53
|
+
"bugs": "https://github.com/ckeditor/ckeditor5/issues",
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "https://github.com/ckeditor/ckeditor5.git",
|
|
57
|
+
"directory": "packages/ckeditor5-core"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"lang",
|
|
61
|
+
"src",
|
|
62
|
+
"theme",
|
|
63
|
+
"ckeditor5-metadata.json"
|
|
64
|
+
]
|
|
65
|
+
}
|
package/src/command.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
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/command
|
|
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 commands.
|
|
15
|
+
*
|
|
16
|
+
* Commands are the main way to manipulate editor contents and state. They are mostly used by UI elements (or by other
|
|
17
|
+
* commands) to make changes in the model. Commands are available in every part of code that has access to
|
|
18
|
+
* the {@link module:core/editor/editor~Editor editor} instance.
|
|
19
|
+
*
|
|
20
|
+
* Instances of registered commands can be retrieved from {@link module:core/editor/editor~Editor#commands `editor.commands`}.
|
|
21
|
+
* The easiest way to execute a command is through {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
|
|
22
|
+
*
|
|
23
|
+
* By default commands are disabled when the editor is in {@link module:core/editor/editor~Editor#isReadOnly read-only} mode.
|
|
24
|
+
*
|
|
25
|
+
* @mixes module:utils/observablemixin~ObservableMixin
|
|
26
|
+
*/
|
|
27
|
+
export default class Command {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new `Command` instance.
|
|
30
|
+
*
|
|
31
|
+
* @param {module:core/editor/editor~Editor} editor Editor on which this command will be used.
|
|
32
|
+
*/
|
|
33
|
+
constructor( editor ) {
|
|
34
|
+
/**
|
|
35
|
+
* The editor on which this command will be used.
|
|
36
|
+
*
|
|
37
|
+
* @readonly
|
|
38
|
+
* @member {module:core/editor/editor~Editor}
|
|
39
|
+
*/
|
|
40
|
+
this.editor = editor;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The value of the command. A concrete command class should define what it represents for it.
|
|
44
|
+
*
|
|
45
|
+
* For example, the `'bold'` command's value indicates whether the selection starts in a bolded text.
|
|
46
|
+
* And the value of the `'link'` command may be an object with links details.
|
|
47
|
+
*
|
|
48
|
+
* It is possible for a command to have no value (e.g. for stateless actions such as `'uploadImage'`).
|
|
49
|
+
*
|
|
50
|
+
* A concrete command class should control this value by overriding the {@link #refresh `refresh()`} method.
|
|
51
|
+
*
|
|
52
|
+
* @observable
|
|
53
|
+
* @readonly
|
|
54
|
+
* @member #value
|
|
55
|
+
*/
|
|
56
|
+
this.set( 'value', undefined );
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Flag indicating whether a command is enabled or disabled.
|
|
60
|
+
* A disabled command will do nothing when executed.
|
|
61
|
+
*
|
|
62
|
+
* A concrete command class should control this value by overriding the {@link #refresh `refresh()`} method.
|
|
63
|
+
*
|
|
64
|
+
* It is possible to disable a command from "outside". For instance, in your integration you may want to disable
|
|
65
|
+
* a certain set of commands for the time being. To do that, you can use the fact that `isEnabled` is observable
|
|
66
|
+
* and it fires the `set:isEnabled` event every time anyone tries to modify its value:
|
|
67
|
+
*
|
|
68
|
+
* function disableCommand( cmd ) {
|
|
69
|
+
* cmd.on( 'set:isEnabled', forceDisable, { priority: 'highest' } );
|
|
70
|
+
*
|
|
71
|
+
* cmd.isEnabled = false;
|
|
72
|
+
*
|
|
73
|
+
* // Make it possible to enable the command again.
|
|
74
|
+
* return () => {
|
|
75
|
+
* cmd.off( 'set:isEnabled', forceDisable );
|
|
76
|
+
* cmd.refresh();
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* function forceDisable( evt ) {
|
|
80
|
+
* evt.return = false;
|
|
81
|
+
* evt.stop();
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // Usage:
|
|
86
|
+
*
|
|
87
|
+
* // Disabling the command.
|
|
88
|
+
* const enableBold = disableCommand( editor.commands.get( 'bold' ) );
|
|
89
|
+
*
|
|
90
|
+
* // Enabling the command again.
|
|
91
|
+
* enableBold();
|
|
92
|
+
*
|
|
93
|
+
* @observable
|
|
94
|
+
* @readonly
|
|
95
|
+
* @member {Boolean} #isEnabled
|
|
96
|
+
*/
|
|
97
|
+
this.set( 'isEnabled', false );
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Holds identifiers for {@link #forceDisabled} mechanism.
|
|
101
|
+
*
|
|
102
|
+
* @type {Set.<String>}
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
this._disableStack = new Set();
|
|
106
|
+
|
|
107
|
+
this.decorate( 'execute' );
|
|
108
|
+
|
|
109
|
+
// By default every command is refreshed when changes are applied to the model.
|
|
110
|
+
this.listenTo( this.editor.model.document, 'change', () => {
|
|
111
|
+
this.refresh();
|
|
112
|
+
} );
|
|
113
|
+
|
|
114
|
+
this.on( 'execute', evt => {
|
|
115
|
+
if ( !this.isEnabled ) {
|
|
116
|
+
evt.stop();
|
|
117
|
+
}
|
|
118
|
+
}, { priority: 'high' } );
|
|
119
|
+
|
|
120
|
+
// By default commands are disabled when the editor is in read-only mode.
|
|
121
|
+
this.listenTo( editor, 'change:isReadOnly', ( evt, name, value ) => {
|
|
122
|
+
if ( value ) {
|
|
123
|
+
this.forceDisabled( 'readOnlyMode' );
|
|
124
|
+
} else {
|
|
125
|
+
this.clearForceDisabled( 'readOnlyMode' );
|
|
126
|
+
}
|
|
127
|
+
} );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
|
|
132
|
+
* in this method.
|
|
133
|
+
*
|
|
134
|
+
* This method is automatically called when
|
|
135
|
+
* {@link module:engine/model/document~Document#event:change any changes are applied to the document}.
|
|
136
|
+
*/
|
|
137
|
+
refresh() {
|
|
138
|
+
this.isEnabled = true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Disables the command.
|
|
143
|
+
*
|
|
144
|
+
* Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
|
|
145
|
+
* (e.g. feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
|
|
146
|
+
* The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
|
|
147
|
+
*
|
|
148
|
+
* Disabling and enabling a command:
|
|
149
|
+
*
|
|
150
|
+
* command.isEnabled; // -> true
|
|
151
|
+
* command.forceDisabled( 'MyFeature' );
|
|
152
|
+
* command.isEnabled; // -> false
|
|
153
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
154
|
+
* command.isEnabled; // -> true
|
|
155
|
+
*
|
|
156
|
+
* Command disabled by multiple features:
|
|
157
|
+
*
|
|
158
|
+
* command.forceDisabled( 'MyFeature' );
|
|
159
|
+
* command.forceDisabled( 'OtherFeature' );
|
|
160
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
161
|
+
* command.isEnabled; // -> false
|
|
162
|
+
* command.clearForceDisabled( 'OtherFeature' );
|
|
163
|
+
* command.isEnabled; // -> true
|
|
164
|
+
*
|
|
165
|
+
* Multiple disabling with the same identifier is redundant:
|
|
166
|
+
*
|
|
167
|
+
* command.forceDisabled( 'MyFeature' );
|
|
168
|
+
* command.forceDisabled( 'MyFeature' );
|
|
169
|
+
* command.clearForceDisabled( 'MyFeature' );
|
|
170
|
+
* command.isEnabled; // -> true
|
|
171
|
+
*
|
|
172
|
+
* **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
|
|
173
|
+
* so the command might be still disabled after {@link #clearForceDisabled} was used.
|
|
174
|
+
*
|
|
175
|
+
* @param {String} id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
|
|
176
|
+
*/
|
|
177
|
+
forceDisabled( id ) {
|
|
178
|
+
this._disableStack.add( id );
|
|
179
|
+
|
|
180
|
+
if ( this._disableStack.size == 1 ) {
|
|
181
|
+
this.on( 'set:isEnabled', forceDisable, { priority: 'highest' } );
|
|
182
|
+
this.isEnabled = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
|
|
188
|
+
*
|
|
189
|
+
* @param {String} id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
|
|
190
|
+
*/
|
|
191
|
+
clearForceDisabled( id ) {
|
|
192
|
+
this._disableStack.delete( id );
|
|
193
|
+
|
|
194
|
+
if ( this._disableStack.size == 0 ) {
|
|
195
|
+
this.off( 'set:isEnabled', forceDisable );
|
|
196
|
+
this.refresh();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Executes the command.
|
|
202
|
+
*
|
|
203
|
+
* A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
|
|
204
|
+
* to the command.
|
|
205
|
+
*
|
|
206
|
+
* The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
|
|
207
|
+
* This behavior is implemented by a high priority listener to the {@link #event:execute} event.
|
|
208
|
+
*
|
|
209
|
+
* In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
|
|
210
|
+
*
|
|
211
|
+
* This method may return a value, which would be forwarded all the way down to the
|
|
212
|
+
* {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
|
|
213
|
+
*
|
|
214
|
+
* @fires execute
|
|
215
|
+
*/
|
|
216
|
+
execute() {}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Destroys the command.
|
|
220
|
+
*/
|
|
221
|
+
destroy() {
|
|
222
|
+
this.stopListening();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Event fired by the {@link #execute} method. The command action is a listener to this event so it's
|
|
227
|
+
* possible to change/cancel the behavior of the command by listening to this event.
|
|
228
|
+
*
|
|
229
|
+
* See {@link module:utils/observablemixin~ObservableMixin#decorate} for more information and samples.
|
|
230
|
+
*
|
|
231
|
+
* **Note:** This event is fired even if command is disabled. However, it is automatically blocked
|
|
232
|
+
* by a high priority listener in order to prevent command execution.
|
|
233
|
+
*
|
|
234
|
+
* @event execute
|
|
235
|
+
*/
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
mix( Command, ObservableMixin );
|
|
239
|
+
|
|
240
|
+
// Helper function that forces command to be disabled.
|
|
241
|
+
function forceDisable( evt ) {
|
|
242
|
+
evt.return = false;
|
|
243
|
+
evt.stop();
|
|
244
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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/commandcollection
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
|
|
14
|
+
*/
|
|
15
|
+
export default class CommandCollection {
|
|
16
|
+
/**
|
|
17
|
+
* Creates collection instance.
|
|
18
|
+
*/
|
|
19
|
+
constructor() {
|
|
20
|
+
/**
|
|
21
|
+
* Command map.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
* @member {Map}
|
|
25
|
+
*/
|
|
26
|
+
this._commands = new Map();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Registers a new command.
|
|
31
|
+
*
|
|
32
|
+
* @param {String} commandName The name of the command.
|
|
33
|
+
* @param {module:core/command~Command} command
|
|
34
|
+
*/
|
|
35
|
+
add( commandName, command ) {
|
|
36
|
+
this._commands.set( commandName, command );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves a command from the collection.
|
|
41
|
+
*
|
|
42
|
+
* @param {String} commandName The name of the command.
|
|
43
|
+
* @returns {module:core/command~Command}
|
|
44
|
+
*/
|
|
45
|
+
get( commandName ) {
|
|
46
|
+
return this._commands.get( commandName );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Executes a command.
|
|
51
|
+
*
|
|
52
|
+
* @param {String} commandName The name of the command.
|
|
53
|
+
* @param {*} [...commandParams] Command parameters.
|
|
54
|
+
* @returns {*} The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
|
|
55
|
+
*/
|
|
56
|
+
execute( commandName, ...args ) {
|
|
57
|
+
const command = this.get( commandName );
|
|
58
|
+
|
|
59
|
+
if ( !command ) {
|
|
60
|
+
/**
|
|
61
|
+
* Command does not exist.
|
|
62
|
+
*
|
|
63
|
+
* @error commandcollection-command-not-found
|
|
64
|
+
* @param {String} commandName Name of the command.
|
|
65
|
+
*/
|
|
66
|
+
throw new CKEditorError( 'commandcollection-command-not-found', this, { commandName } );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return command.execute( ...args );
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns iterator of command names.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Iterable.<String>}
|
|
76
|
+
*/
|
|
77
|
+
* names() {
|
|
78
|
+
yield* this._commands.keys();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns iterator of command instances.
|
|
83
|
+
*
|
|
84
|
+
* @returns {Iterable.<module:core/command~Command>}
|
|
85
|
+
*/
|
|
86
|
+
* commands() {
|
|
87
|
+
yield* this._commands.values();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Iterable interface.
|
|
92
|
+
*
|
|
93
|
+
* Returns `[ commandName, commandInstance ]` pairs.
|
|
94
|
+
*
|
|
95
|
+
* @returns {Iterable.<Array>}
|
|
96
|
+
*/
|
|
97
|
+
[ Symbol.iterator ]() {
|
|
98
|
+
return this._commands[ Symbol.iterator ]();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Destroys all collection commands.
|
|
103
|
+
*/
|
|
104
|
+
destroy() {
|
|
105
|
+
for ( const command of this.commands() ) {
|
|
106
|
+
command.destroy();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|