ckeditor5-elements-actions 0.0.0-stage → 49.0.0-alpha.4

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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -2
  3. package/dist/augmentation.d.ts +19 -0
  4. package/dist/augmentation.d.ts.map +1 -0
  5. package/dist/augmentation.js +2 -0
  6. package/dist/augmentation.js.map +1 -0
  7. package/dist/elementActions.d.ts +18 -0
  8. package/dist/elementActions.d.ts.map +1 -0
  9. package/dist/elementActions.js +29 -0
  10. package/dist/elementActions.js.map +1 -0
  11. package/dist/elementClipboard.d.ts +18 -0
  12. package/dist/elementClipboard.d.ts.map +1 -0
  13. package/dist/elementClipboard.js +32 -0
  14. package/dist/elementClipboard.js.map +1 -0
  15. package/dist/elementCopyCommand.d.ts +30 -0
  16. package/dist/elementCopyCommand.d.ts.map +1 -0
  17. package/dist/elementCopyCommand.js +64 -0
  18. package/dist/elementCopyCommand.js.map +1 -0
  19. package/dist/elementDeleteCommand.d.ts +19 -0
  20. package/dist/elementDeleteCommand.d.ts.map +1 -0
  21. package/dist/elementDeleteCommand.js +47 -0
  22. package/dist/elementDeleteCommand.js.map +1 -0
  23. package/dist/elementDuplicateCommand.d.ts +22 -0
  24. package/dist/elementDuplicateCommand.d.ts.map +1 -0
  25. package/dist/elementDuplicateCommand.js +49 -0
  26. package/dist/elementDuplicateCommand.js.map +1 -0
  27. package/dist/elementMoveCommand.d.ts +32 -0
  28. package/dist/elementMoveCommand.d.ts.map +1 -0
  29. package/dist/elementMoveCommand.js +59 -0
  30. package/dist/elementMoveCommand.js.map +1 -0
  31. package/dist/elementPasteCommand.d.ts +38 -0
  32. package/dist/elementPasteCommand.d.ts.map +1 -0
  33. package/dist/elementPasteCommand.js +100 -0
  34. package/dist/elementPasteCommand.js.map +1 -0
  35. package/dist/icons.d.ts +40 -0
  36. package/dist/icons.d.ts.map +1 -0
  37. package/dist/icons.js +57 -0
  38. package/dist/icons.js.map +1 -0
  39. package/dist/index.d.ts +16 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +19 -0
  42. package/dist/index.js.map +1 -0
  43. package/package.json +45 -3
  44. package/src/augmentation.ts +28 -0
  45. package/src/elementActions.ts +31 -0
  46. package/src/elementClipboard.ts +35 -0
  47. package/src/elementCopyCommand.ts +75 -0
  48. package/src/elementDeleteCommand.ts +58 -0
  49. package/src/elementDuplicateCommand.ts +64 -0
  50. package/src/elementMoveCommand.ts +74 -0
  51. package/src/elementPasteCommand.ts +129 -0
  52. package/src/icons.ts +73 -0
  53. package/src/index.ts +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Kildyushov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # ckeditor5-elements-actions
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Element actions for CKEditor 5 Elements, the commands that act on a whole element:
4
+
5
+ - `ElementActions` registers `moveElementUp`, `moveElementDown`, `duplicateElement` and `deleteElement`, which move an
6
+ element within its parent, insert an empty copy of it after it, or delete it.
7
+ - `ElementClipboard` registers `copyElement`, `cutElement`, `pasteElement`, `pasteElementBefore` and `pasteElementAfter`,
8
+ which copy, cut and paste an element, through the CKEditor clipboard pipeline.
9
+
10
+ The commands have titles and icons, so they are menu items and buttons as they are.
11
+
12
+ ## Installation
13
+
14
+ This package is part of `ckeditor5-elements`. Install the whole package to use it:
15
+
16
+ ```sh
17
+ npm install ckeditor5 ckeditor5-elements
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { ElementActions, ElementClipboard, ElementContextMenu } from 'ckeditor5-elements';
24
+ import 'ckeditor5-elements/index.css';
25
+
26
+ // In the editor config:
27
+ plugins: [..., ElementActions, ElementClipboard, ElementContextMenu],
28
+ elementContextMenu: (element, editor) => [
29
+ editor.commands.get('moveElementUp'),
30
+ editor.commands.get('moveElementDown'),
31
+ '|',
32
+ editor.commands.get('duplicateElement'),
33
+ editor.commands.get('deleteElement'),
34
+ '|',
35
+ editor.commands.get('copyElement'),
36
+ editor.commands.get('cutElement'),
37
+ editor.commands.get('pasteElementAfter')
38
+ ]
39
+ ```
40
+
41
+ ```ts
42
+ await editor.execute('copyElement', element);
43
+ await editor.execute('pasteElementAfter'); // The element at the selection.
44
+ ```
45
+
46
+ See the [Actions](https://ivankild.github.io/ckeditor5-elements/guide/actions) and
47
+ [Clipboard](https://ivankild.github.io/ckeditor5-elements/guide/clipboard) guides of the documentation.
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1,19 @@
1
+ import type { ElementActions, ElementClipboard, ElementCopyCommand, ElementDeleteCommand, ElementDuplicateCommand, ElementMoveCommand, ElementPasteCommand } from './index.js';
2
+ declare module 'ckeditor5' {
3
+ interface PluginsMap {
4
+ [ElementActions.pluginName]: ElementActions;
5
+ [ElementClipboard.pluginName]: ElementClipboard;
6
+ }
7
+ interface CommandsMap {
8
+ moveElementUp: ElementMoveCommand;
9
+ moveElementDown: ElementMoveCommand;
10
+ duplicateElement: ElementDuplicateCommand;
11
+ deleteElement: ElementDeleteCommand;
12
+ copyElement: ElementCopyCommand;
13
+ cutElement: ElementCopyCommand;
14
+ pasteElement: ElementPasteCommand;
15
+ pasteElementBefore: ElementPasteCommand;
16
+ pasteElementAfter: ElementPasteCommand;
17
+ }
18
+ }
19
+ //# sourceMappingURL=augmentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentation.d.ts","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,QAAQ,WAAW,CAAC;IAC1B,UAAU,UAAU;QACnB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC;QAC5C,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;KAChD;IAED,UAAU,WAAW;QACpB,aAAa,EAAE,kBAAkB,CAAC;QAClC,eAAe,EAAE,kBAAkB,CAAC;QACpC,gBAAgB,EAAE,uBAAuB,CAAC;QAC1C,aAAa,EAAE,oBAAoB,CAAC;QACpC,WAAW,EAAE,kBAAkB,CAAC;QAChC,UAAU,EAAE,kBAAkB,CAAC;QAC/B,YAAY,EAAE,mBAAmB,CAAC;QAClC,kBAAkB,EAAE,mBAAmB,CAAC;QACxC,iBAAiB,EAAE,mBAAmB,CAAC;KACvC;CACD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=augmentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentation.js","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { Plugin } from 'ckeditor5';
2
+ /**
3
+ * Registers commands that act on an element: `moveElementUp`, `moveElementDown`, `duplicateElement` and
4
+ * `deleteElement`.
5
+ *
6
+ * ```ts
7
+ * editor.execute('duplicateElement'); // The element at the selection.
8
+ * editor.commands.get('moveElementUp').executeFor(element); // The given element.
9
+ * ```
10
+ *
11
+ * The commands have titles and icons, so they can be menu items (e.g. in the `elementContextMenu` config of
12
+ * `ElementContextMenu`) and buttons.
13
+ */
14
+ export default class ElementActions extends Plugin {
15
+ static get pluginName(): 'ElementActions';
16
+ init(): void;
17
+ }
18
+ //# sourceMappingURL=elementActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementActions.d.ts","sourceRoot":"","sources":["../src/elementActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKnC;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;IACjD,WAAkB,UAAU,IAAI,gBAAgB,CAE/C;IAEM,IAAI,IAAI,IAAI;CAQnB"}
@@ -0,0 +1,29 @@
1
+ import { Plugin } from 'ckeditor5';
2
+ import ElementDeleteCommand from './elementDeleteCommand.js';
3
+ import ElementDuplicateCommand from './elementDuplicateCommand.js';
4
+ import ElementMoveCommand from './elementMoveCommand.js';
5
+ /**
6
+ * Registers commands that act on an element: `moveElementUp`, `moveElementDown`, `duplicateElement` and
7
+ * `deleteElement`.
8
+ *
9
+ * ```ts
10
+ * editor.execute('duplicateElement'); // The element at the selection.
11
+ * editor.commands.get('moveElementUp').executeFor(element); // The given element.
12
+ * ```
13
+ *
14
+ * The commands have titles and icons, so they can be menu items (e.g. in the `elementContextMenu` config of
15
+ * `ElementContextMenu`) and buttons.
16
+ */
17
+ export default class ElementActions extends Plugin {
18
+ static get pluginName() {
19
+ return 'ElementActions';
20
+ }
21
+ init() {
22
+ const editor = this.editor;
23
+ editor.commands.add('moveElementUp', new ElementMoveCommand(editor, 'up'));
24
+ editor.commands.add('moveElementDown', new ElementMoveCommand(editor, 'down'));
25
+ editor.commands.add('duplicateElement', new ElementDuplicateCommand(editor));
26
+ editor.commands.add('deleteElement', new ElementDeleteCommand(editor));
27
+ }
28
+ }
29
+ //# sourceMappingURL=elementActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementActions.js","sourceRoot":"","sources":["../src/elementActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAC7D,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;IAC1C,MAAM,KAAK,UAAU;QAC3B,OAAO,gBAAyB,CAAC;IAClC,CAAC;IAEM,IAAI;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE3B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3E,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/E,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7E,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;CACD"}
@@ -0,0 +1,18 @@
1
+ import { ClipboardPipeline, Notification, Plugin } from 'ckeditor5';
2
+ /**
3
+ * Registers clipboard commands that act on an element:
4
+ * `copyElement`, `cutElement`, `pasteElement`, `pasteElementBefore` and `pasteElementAfter`.
5
+ *
6
+ * ```ts
7
+ * await editor.execute('copyElement', element);
8
+ * ```
9
+ *
10
+ * The commands have titles and icons, so they can be menu items (e.g. in the `elementContextMenu` config of
11
+ * `ElementContextMenu`) and buttons. Copying and pasting go through the clipboard pipeline, as Ctrl+C and Ctrl+V do.
12
+ */
13
+ export default class ElementClipboard extends Plugin {
14
+ static get requires(): readonly [typeof ClipboardPipeline, typeof Notification];
15
+ static get pluginName(): 'ElementClipboard';
16
+ init(): void;
17
+ }
18
+ //# sourceMappingURL=elementClipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementClipboard.d.ts","sourceRoot":"","sources":["../src/elementClipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAIpE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,MAAM;IACnD,WAAkB,QAAQ,IAAI,SAAS,CAAC,OAAO,iBAAiB,EAAE,OAAO,YAAY,CAAC,CAGrF;IAED,WAAkB,UAAU,IAAI,kBAAkB,CAEjD;IAEM,IAAI,IAAI,IAAI;CASnB"}
@@ -0,0 +1,32 @@
1
+ import { ClipboardPipeline, Notification, Plugin } from 'ckeditor5';
2
+ import ElementCopyCommand from './elementCopyCommand.js';
3
+ import ElementPasteCommand from './elementPasteCommand.js';
4
+ /**
5
+ * Registers clipboard commands that act on an element:
6
+ * `copyElement`, `cutElement`, `pasteElement`, `pasteElementBefore` and `pasteElementAfter`.
7
+ *
8
+ * ```ts
9
+ * await editor.execute('copyElement', element);
10
+ * ```
11
+ *
12
+ * The commands have titles and icons, so they can be menu items (e.g. in the `elementContextMenu` config of
13
+ * `ElementContextMenu`) and buttons. Copying and pasting go through the clipboard pipeline, as Ctrl+C and Ctrl+V do.
14
+ */
15
+ export default class ElementClipboard extends Plugin {
16
+ static get requires() {
17
+ // The buttons of the commands report failures (e.g. no clipboard permission) with notifications.
18
+ return [ClipboardPipeline, Notification];
19
+ }
20
+ static get pluginName() {
21
+ return 'ElementClipboard';
22
+ }
23
+ init() {
24
+ const editor = this.editor;
25
+ editor.commands.add('copyElement', new ElementCopyCommand(editor));
26
+ editor.commands.add('cutElement', new ElementCopyCommand(editor, { cut: true }));
27
+ editor.commands.add('pasteElement', new ElementPasteCommand(editor, 'replace'));
28
+ editor.commands.add('pasteElementBefore', new ElementPasteCommand(editor, 'before'));
29
+ editor.commands.add('pasteElementAfter', new ElementPasteCommand(editor, 'after'));
30
+ }
31
+ }
32
+ //# sourceMappingURL=elementClipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementClipboard.js","sourceRoot":"","sources":["../src/elementClipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,mBAAmB,MAAM,0BAA0B,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,MAAM;IAC5C,MAAM,KAAK,QAAQ;QACzB,iGAAiG;QACjG,OAAO,CAAC,iBAAiB,EAAE,YAAY,CAAU,CAAC;IACnD,CAAC;IAEM,MAAM,KAAK,UAAU;QAC3B,OAAO,kBAA2B,CAAC;IACpC,CAAC;IAEM,IAAI;QACV,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE3B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACjF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAChF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACpF,CAAC;CACD"}
@@ -0,0 +1,30 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Copies an element to the system clipboard, as HTML and plain text. With `cut: true`, it also removes the element.
5
+ *
6
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
7
+ * selection (see {@link ElementOrPositionCommand}). Parts of a structure, such as table cells, rows and captions, cannot
8
+ * be copied on their own, so the command is disabled for them.
9
+ *
10
+ * The content goes through the clipboard pipeline, as with Ctrl+C: other plugins can change it (they listen to the
11
+ * `outputTransformation` event of `ClipboardPipeline`, and to `clipboardOutput` of the editing view document).
12
+ *
13
+ * Requires a secure context (HTTPS or `localhost`), as it uses the asynchronous Clipboard API.
14
+ */
15
+ export default class ElementCopyCommand extends ElementOrPositionCommand {
16
+ /**
17
+ * Whether the element is removed after copying.
18
+ */
19
+ readonly cut: boolean;
20
+ constructor(editor: Editor, { cut }?: {
21
+ cut?: boolean;
22
+ });
23
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
24
+ /**
25
+ * Copies the element (and removes it, with `cut: true`). Resolves when the clipboard has been written; rejects when
26
+ * the browser does not allow it.
27
+ */
28
+ execute(elementOrPosition?: ElementOrPosition): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=elementCopyCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementCopyCommand.d.ts","sourceRoot":"","sources":["../src/elementCopyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgF,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACtH,OAAO,EAAE,wBAAwB,EAA8B,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGvH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;IACvE;;OAEG;IACH,SAAgB,GAAG,EAAE,OAAO,CAAC;gBAEjB,MAAM,EAAE,MAAM,EAAE,EAAE,GAAW,EAAE,GAAE;QAAE,GAAG,CAAC,EAAE,OAAO,CAAA;KAAO;cAWhD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAMhF;;;OAGG;IACmB,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CA+BnF"}
@@ -0,0 +1,64 @@
1
+ import { ClipboardPipeline, ViewDataTransfer } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, isInDocument, isStandalone } from 'ckeditor5-elements-core';
3
+ import { copyIcon, cutIcon } from './icons.js';
4
+ /**
5
+ * Copies an element to the system clipboard, as HTML and plain text. With `cut: true`, it also removes the element.
6
+ *
7
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
8
+ * selection (see {@link ElementOrPositionCommand}). Parts of a structure, such as table cells, rows and captions, cannot
9
+ * be copied on their own, so the command is disabled for them.
10
+ *
11
+ * The content goes through the clipboard pipeline, as with Ctrl+C: other plugins can change it (they listen to the
12
+ * `outputTransformation` event of `ClipboardPipeline`, and to `clipboardOutput` of the editing view document).
13
+ *
14
+ * Requires a secure context (HTTPS or `localhost`), as it uses the asynchronous Clipboard API.
15
+ */
16
+ export default class ElementCopyCommand extends ElementOrPositionCommand {
17
+ /**
18
+ * Whether the element is removed after copying.
19
+ */
20
+ cut;
21
+ constructor(editor, { cut = false } = {}) {
22
+ super(editor);
23
+ this.cut = cut;
24
+ this.title = cut ? editor.t('Cut') : editor.t('Copy');
25
+ this.icon = cut ? cutIcon : copyIcon;
26
+ // Copying does not change the data, so it stays enabled in read-only mode.
27
+ this.affectsData = cut;
28
+ }
29
+ _isEnabledFor(elementOrPosition) {
30
+ const element = this._getElement(elementOrPosition);
31
+ return window.isSecureContext && !!element && isStandalone(this.editor.model.schema, element);
32
+ }
33
+ /**
34
+ * Copies the element (and removes it, with `cut: true`). Resolves when the clipboard has been written; rejects when
35
+ * the browser does not allow it.
36
+ */
37
+ async execute(elementOrPosition) {
38
+ const editor = this.editor;
39
+ const model = editor.model;
40
+ const element = this._getElement(elementOrPosition);
41
+ if (!element || !isStandalone(model.schema, element)) {
42
+ return;
43
+ }
44
+ const dataTransfer = new ViewDataTransfer(new DataTransfer());
45
+ // Always "copy": the pipeline would remove the content of the document selection when cutting.
46
+ editor.plugins.get(ClipboardPipeline).fire('outputTransformation', {
47
+ dataTransfer,
48
+ content: model.getSelectedContent(model.createSelection(element, 'on')),
49
+ method: 'copy'
50
+ });
51
+ await navigator.clipboard.write([
52
+ new ClipboardItem({
53
+ 'text/html': new Blob([dataTransfer.getData('text/html')], { type: 'text/html' }),
54
+ 'text/plain': new Blob([dataTransfer.getData('text/plain')], { type: 'text/plain' })
55
+ })
56
+ ]);
57
+ if (this.cut && isInDocument(element) && model.canEditAt(element)) {
58
+ model.change(writer => {
59
+ writer.remove(element);
60
+ });
61
+ }
62
+ }
63
+ }
64
+ //# sourceMappingURL=elementCopyCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementCopyCommand.js","sourceRoot":"","sources":["../src/elementCopyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAwD,MAAM,WAAW,CAAC;AACtH,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,YAAY,EAA0B,MAAM,yBAAyB,CAAC;AACvH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,Y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AE9D,+FAA+F;QAC/F,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAqC,sBAAsB,EAAE;YACtG,YAAY;YACZ,OAAO,EAAE,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACvE,MAAM,EAAE,MAAM;SACd,CAAC,CAAC;QAEH,MAAM,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;YAC/B,IAAI,aAAa,CAAC;gBACjB,WAAW,EAAE,IAAI,IAAI,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;gBACjF,YAAY,EAAE,IAAI,IAAI,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;aACpF,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACnE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,19 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Deletes an element. When it was the only element in its parent, e.g. in a note, the parent gets an empty paragraph
5
+ * with the selection, so that it can still be written in.
6
+ *
7
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
8
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled for parts of a structure, such as table
9
+ * cells.
10
+ */
11
+ export default class ElementDeleteCommand extends ElementOrPositionCommand {
12
+ constructor(editor: Editor);
13
+ /**
14
+ * Deletes the element.
15
+ */
16
+ execute(elementOrPosition?: ElementOrPosition): void;
17
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
18
+ }
19
+ //# sourceMappingURL=elementDeleteCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementDeleteCommand.d.ts","sourceRoot":"","sources":["../src/elementDeleteCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAgB,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGzG;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,wBAAwB;gBAC7D,MAAM,EAAE,MAAM;IAO1B;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;cA4BjD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;CAMhF"}
@@ -0,0 +1,47 @@
1
+ import {} from 'ckeditor5';
2
+ import { ElementOrPositionCommand, isStandalone } from 'ckeditor5-elements-core';
3
+ import { deleteIcon } from './icons.js';
4
+ /**
5
+ * Deletes an element. When it was the only element in its parent, e.g. in a note, the parent gets an empty paragraph
6
+ * with the selection, so that it can still be written in.
7
+ *
8
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
9
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled for parts of a structure, such as table
10
+ * cells.
11
+ */
12
+ export default class ElementDeleteCommand extends ElementOrPositionCommand {
13
+ constructor(editor) {
14
+ super(editor);
15
+ this.title = editor.t('Delete');
16
+ this.icon = deleteIcon;
17
+ }
18
+ /**
19
+ * Deletes the element.
20
+ */
21
+ execute(elementOrPosition) {
22
+ const model = this.editor.model;
23
+ const element = this._getElement(elementOrPosition);
24
+ if (!element || !this._isEnabledFor(element)) {
25
+ return;
26
+ }
27
+ model.change(writer => {
28
+ const parent = element.parent;
29
+ writer.remove(element);
30
+ // The root gets a paragraph from the editor itself.
31
+ if (parent?.is('element') &&
32
+ !parent.is('rootElement') &&
33
+ parent.isEmpty &&
34
+ model.schema.checkChild(parent, 'paragraph')) {
35
+ const paragraph = writer.createElement('paragraph');
36
+ writer.append(paragraph, parent);
37
+ writer.setSelection(paragraph, 0);
38
+ }
39
+ });
40
+ }
41
+ _isEnabledFor(elementOrPosition) {
42
+ const model = this.editor.model;
43
+ const element = this._getElement(elementOrPosition);
44
+ return !!element && isStandalone(model.schema, element) && model.canEditAt(element);
45
+ }
46
+ }
47
+ //# sourceMappingURL=elementDeleteCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementDeleteCommand.js","sourceRoot":"","sources":["../src/elementDeleteCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAA0B,MAAM,yBAAyB,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,wBAAwB;IACzE,YAAY,MAAc;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QAEpD,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9C,OAAO;QACR,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACrB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAE9B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAEvB,oDAAoD;YACpD,IACC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC;gBACrB,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC;gBACzB,MAAM,CAAC,OAAO;gBACd,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,EAC3C,CAAC;gBACF,MAAM,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAEpD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBACjC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;YACnC,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAEkB,aAAa,CAAC,iBAAqC;QACrE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QAEpD,OAAO,CAAC,CAAC,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACrF,CAAC;CACD"}
@@ -0,0 +1,22 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Duplicates an element: inserts the same element, empty, after it, and puts the selection in it: in the copy of an
5
+ * element that holds text, or in a new paragraph in the copy of an element that holds blocks.
6
+ *
7
+ * The copy has the same name and attributes. A list item gets a new list item id, so it is a new list item, not a second
8
+ * block of the same one. Objects, e.g. an image or a table, are copied with their content, as they cannot be empty.
9
+ *
10
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
11
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled for parts of a structure, such as table
12
+ * cells.
13
+ */
14
+ export default class ElementDuplicateCommand extends ElementOrPositionCommand {
15
+ constructor(editor: Editor);
16
+ /**
17
+ * Inserts the copy of the element after it.
18
+ */
19
+ execute(elementOrPosition?: ElementOrPosition): void;
20
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
21
+ }
22
+ //# sourceMappingURL=elementDuplicateCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementDuplicateCommand.d.ts","sourceRoot":"","sources":["../src/elementDuplicateCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACN,wBAAwB,EAGxB,KAAK,iBAAiB,EACtB,MAAM,yBAAyB,CAAC;AAGjC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,wBAAwB;gBAChE,MAAM,EAAE,MAAM;IAO1B;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;cAoBjD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;CAYhF"}
@@ -0,0 +1,49 @@
1
+ import { uid } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, isStandalone, selectNewElement } from 'ckeditor5-elements-core';
3
+ import { duplicateIcon } from './icons.js';
4
+ /**
5
+ * Duplicates an element: inserts the same element, empty, after it, and puts the selection in it: in the copy of an
6
+ * element that holds text, or in a new paragraph in the copy of an element that holds blocks.
7
+ *
8
+ * The copy has the same name and attributes. A list item gets a new list item id, so it is a new list item, not a second
9
+ * block of the same one. Objects, e.g. an image or a table, are copied with their content, as they cannot be empty.
10
+ *
11
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
12
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled for parts of a structure, such as table
13
+ * cells.
14
+ */
15
+ export default class ElementDuplicateCommand extends ElementOrPositionCommand {
16
+ constructor(editor) {
17
+ super(editor);
18
+ this.title = editor.t('Duplicate');
19
+ this.icon = duplicateIcon;
20
+ }
21
+ /**
22
+ * Inserts the copy of the element after it.
23
+ */
24
+ execute(elementOrPosition) {
25
+ const model = this.editor.model;
26
+ const element = this._getElement(elementOrPosition);
27
+ if (!element || !this._isEnabledFor(element)) {
28
+ return;
29
+ }
30
+ model.change(writer => {
31
+ const copy = writer.cloneElement(element, model.schema.isObject(element));
32
+ if (copy.hasAttribute('listItemId')) {
33
+ writer.setAttribute('listItemId', uid(), copy);
34
+ }
35
+ writer.insert(copy, writer.createPositionAfter(element));
36
+ selectNewElement(writer, copy);
37
+ });
38
+ }
39
+ _isEnabledFor(elementOrPosition) {
40
+ const model = this.editor.model;
41
+ const element = this._getElement(elementOrPosition);
42
+ if (!element || !isStandalone(model.schema, element)) {
43
+ return false;
44
+ }
45
+ const position = model.createPositionAfter(element);
46
+ return model.canEditAt(position) && model.schema.checkChild(position, element);
47
+ }
48
+ }
49
+ //# sourceMappingURL=elementDuplicateCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementDuplicateCommand.js","sourceRoot":"","sources":["../src/elementDuplicateCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAe,MAAM,WAAW,CAAC;AAC7C,OAAO,EACN,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,wBAAwB;IAC5E,YAAY,MAAc;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC3B,CAAC;IAED;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,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@@ -0,0 +1,32 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Where the element moves.
5
+ */
6
+ export type ElementMoveDirection = 'up' | 'down';
7
+ /**
8
+ * Moves an element up or down: swaps it with the element before or after it, in the same parent. The selection stays
9
+ * in the element.
10
+ *
11
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
12
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled when there is no element before it (up) or
13
+ * after it (down), e.g. for the first element of a note, and for parts of a structure, such as table cells.
14
+ */
15
+ export default class ElementMoveCommand extends ElementOrPositionCommand {
16
+ /**
17
+ * Where the element moves.
18
+ */
19
+ readonly direction: ElementMoveDirection;
20
+ constructor(editor: Editor, direction: ElementMoveDirection);
21
+ /**
22
+ * Moves the element up or down.
23
+ */
24
+ execute(elementOrPosition?: ElementOrPosition): void;
25
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
26
+ /**
27
+ * Returns the element the element swaps with: the one before it (up) or after it (down), if it is an element.
28
+ */
29
+ private _getSibling;
30
+ private _canMove;
31
+ }
32
+ //# sourceMappingURL=elementMoveCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementMoveCommand.d.ts","sourceRoot":"","sources":["../src/elementMoveCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAqB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAgB,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGzG;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,GAAG,MAAM,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;IACvE;;OAEG;IACH,SAAgB,SAAS,EAAE,oBAAoB,CAAC;gBAEpC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB;IAQ3D;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;cAkBjD,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAOhF;;OAEG;IACH,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,QAAQ;CAKhB"}
@@ -0,0 +1,59 @@
1
+ import {} from 'ckeditor5';
2
+ import { ElementOrPositionCommand, isStandalone } from 'ckeditor5-elements-core';
3
+ import { moveDownIcon, moveUpIcon } from './icons.js';
4
+ /**
5
+ * Moves an element up or down: swaps it with the element before or after it, in the same parent. The selection stays
6
+ * in the element.
7
+ *
8
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
9
+ * selection (see {@link ElementOrPositionCommand}). The command is disabled when there is no element before it (up) or
10
+ * after it (down), e.g. for the first element of a note, and for parts of a structure, such as table cells.
11
+ */
12
+ export default class ElementMoveCommand extends ElementOrPositionCommand {
13
+ /**
14
+ * Where the element moves.
15
+ */
16
+ direction;
17
+ constructor(editor, direction) {
18
+ super(editor);
19
+ this.direction = direction;
20
+ this.title = direction === 'up' ? editor.t('Move up') : editor.t('Move down');
21
+ this.icon = direction === 'up' ? moveUpIcon : moveDownIcon;
22
+ }
23
+ /**
24
+ * Moves the element up or down.
25
+ */
26
+ execute(elementOrPosition) {
27
+ const element = this._getElement(elementOrPosition);
28
+ const sibling = element && this._getSibling(element);
29
+ if (!element || !sibling || !this._canMove(element, sibling)) {
30
+ return;
31
+ }
32
+ this.editor.model.change(writer => {
33
+ // Either way, the selection stays in the element: it moves with the element, or the sibling moves past it.
34
+ if (this.direction === 'up') {
35
+ writer.move(writer.createRangeOn(element), writer.createPositionBefore(sibling));
36
+ }
37
+ else {
38
+ writer.move(writer.createRangeOn(sibling), writer.createPositionBefore(element));
39
+ }
40
+ });
41
+ }
42
+ _isEnabledFor(elementOrPosition) {
43
+ const element = this._getElement(elementOrPosition);
44
+ const sibling = element && this._getSibling(element);
45
+ return !!element && !!sibling && this._canMove(element, sibling);
46
+ }
47
+ /**
48
+ * Returns the element the element swaps with: the one before it (up) or after it (down), if it is an element.
49
+ */
50
+ _getSibling(element) {
51
+ const sibling = this.direction === 'up' ? element.previousSibling : element.nextSibling;
52
+ return sibling?.is('element') ? sibling : null;
53
+ }
54
+ _canMove(element, sibling) {
55
+ const model = this.editor.model;
56
+ return isStandalone(model.schema, element) && model.canEditAt(element) && model.canEditAt(sibling);
57
+ }
58
+ }
59
+ //# sourceMappingURL=elementMoveCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementMoveCommand.js","sourceRoot":"","sources":["../src/elementMoveCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAA0B,MAAM,yBAAyB,CAAC;AACzG,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAOtD;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,wBAAwB;IACvE;;OAEG;IACa,SAAS,CAAuB;IAEhD,YAAY,MAAc,EAAE,SAA+B;QAC1D,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC;IAC5D,CAAC;IAED;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC,W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,OAAqB,EAAE,OAAqB;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAEhC,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpG,CAAC;CACD"}
@@ -0,0 +1,38 @@
1
+ import { type Editor } from 'ckeditor5';
2
+ import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
3
+ /**
4
+ * Where the pasted content goes, relative to the element:
5
+ *
6
+ * * `'replace'` – replaces the element,
7
+ * * `'before'` – before the element,
8
+ * * `'after'` – after the element.
9
+ */
10
+ export type ElementPastePlacement = 'replace' | 'before' | 'after';
11
+ /**
12
+ * Pastes the system clipboard content relative to an element.
13
+ *
14
+ * The element is the given one, the parent of the given position, or the selected element or the parent of the
15
+ * selection (see {@link ElementOrPositionCommand}). Parts of a structure, such as table cells, rows and captions, cannot
16
+ * be replaced, nor have content pasted next to them, so the command is disabled for them.
17
+ *
18
+ * The content is pasted as with Ctrl+V: it goes through the clipboard pipeline (the `clipboardInput` event of the
19
+ * editing view document), so other plugins process it, e.g. paste from Office cleans up content from Word, and image
20
+ * upload uploads the images on the clipboard. The selection is moved to the pasted content.
21
+ *
22
+ * Requires a secure context (HTTPS or `localhost`), as it uses the asynchronous Clipboard API.
23
+ * The browser may ask the user for permission.
24
+ */
25
+ export default class ElementPasteCommand extends ElementOrPositionCommand {
26
+ /**
27
+ * Where the pasted content goes, relative to the element.
28
+ */
29
+ readonly placement: ElementPastePlacement;
30
+ constructor(editor: Editor, placement: ElementPastePlacement);
31
+ protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
32
+ /**
33
+ * Pastes the clipboard content relative to the element. Resolves when the content has been pasted; rejects when the
34
+ * browser does not allow reading the clipboard.
35
+ */
36
+ execute(elementOrPosition?: ElementOrPosition): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=elementPasteCommand.d.ts.map