@ckeditor/ckeditor5-clipboard 41.3.1 → 41.4.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.
Files changed (144) hide show
  1. package/dist/index-content.css +4 -0
  2. package/dist/index-editor.css +23 -0
  3. package/dist/index.css +42 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +1907 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/translations/ar.d.ts +8 -0
  8. package/dist/translations/ar.js +5 -0
  9. package/dist/translations/ar.umd.js +11 -0
  10. package/dist/translations/bg.d.ts +8 -0
  11. package/dist/translations/bg.js +5 -0
  12. package/dist/translations/bg.umd.js +11 -0
  13. package/dist/translations/bn.d.ts +8 -0
  14. package/dist/translations/bn.js +5 -0
  15. package/dist/translations/bn.umd.js +11 -0
  16. package/dist/translations/ca.d.ts +8 -0
  17. package/dist/translations/ca.js +5 -0
  18. package/dist/translations/ca.umd.js +11 -0
  19. package/dist/translations/cs.d.ts +8 -0
  20. package/dist/translations/cs.js +5 -0
  21. package/dist/translations/cs.umd.js +11 -0
  22. package/dist/translations/da.d.ts +8 -0
  23. package/dist/translations/da.js +5 -0
  24. package/dist/translations/da.umd.js +11 -0
  25. package/dist/translations/de.d.ts +8 -0
  26. package/dist/translations/de.js +5 -0
  27. package/dist/translations/de.umd.js +11 -0
  28. package/dist/translations/el.d.ts +8 -0
  29. package/dist/translations/el.js +5 -0
  30. package/dist/translations/el.umd.js +11 -0
  31. package/dist/translations/en.d.ts +8 -0
  32. package/dist/translations/en.js +5 -0
  33. package/dist/translations/en.umd.js +11 -0
  34. package/dist/translations/es-co.d.ts +8 -0
  35. package/dist/translations/es-co.js +5 -0
  36. package/dist/translations/es-co.umd.js +11 -0
  37. package/dist/translations/es.d.ts +8 -0
  38. package/dist/translations/es.js +5 -0
  39. package/dist/translations/es.umd.js +11 -0
  40. package/dist/translations/et.d.ts +8 -0
  41. package/dist/translations/et.js +5 -0
  42. package/dist/translations/et.umd.js +11 -0
  43. package/dist/translations/fi.d.ts +8 -0
  44. package/dist/translations/fi.js +5 -0
  45. package/dist/translations/fi.umd.js +11 -0
  46. package/dist/translations/fr.d.ts +8 -0
  47. package/dist/translations/fr.js +5 -0
  48. package/dist/translations/fr.umd.js +11 -0
  49. package/dist/translations/he.d.ts +8 -0
  50. package/dist/translations/he.js +5 -0
  51. package/dist/translations/he.umd.js +11 -0
  52. package/dist/translations/hi.d.ts +8 -0
  53. package/dist/translations/hi.js +5 -0
  54. package/dist/translations/hi.umd.js +11 -0
  55. package/dist/translations/hr.d.ts +8 -0
  56. package/dist/translations/hr.js +5 -0
  57. package/dist/translations/hr.umd.js +11 -0
  58. package/dist/translations/hu.d.ts +8 -0
  59. package/dist/translations/hu.js +5 -0
  60. package/dist/translations/hu.umd.js +11 -0
  61. package/dist/translations/id.d.ts +8 -0
  62. package/dist/translations/id.js +5 -0
  63. package/dist/translations/id.umd.js +11 -0
  64. package/dist/translations/it.d.ts +8 -0
  65. package/dist/translations/it.js +5 -0
  66. package/dist/translations/it.umd.js +11 -0
  67. package/dist/translations/ja.d.ts +8 -0
  68. package/dist/translations/ja.js +5 -0
  69. package/dist/translations/ja.umd.js +11 -0
  70. package/dist/translations/ko.d.ts +8 -0
  71. package/dist/translations/ko.js +5 -0
  72. package/dist/translations/ko.umd.js +11 -0
  73. package/dist/translations/lt.d.ts +8 -0
  74. package/dist/translations/lt.js +5 -0
  75. package/dist/translations/lt.umd.js +11 -0
  76. package/dist/translations/lv.d.ts +8 -0
  77. package/dist/translations/lv.js +5 -0
  78. package/dist/translations/lv.umd.js +11 -0
  79. package/dist/translations/ms.d.ts +8 -0
  80. package/dist/translations/ms.js +5 -0
  81. package/dist/translations/ms.umd.js +11 -0
  82. package/dist/translations/nl.d.ts +8 -0
  83. package/dist/translations/nl.js +5 -0
  84. package/dist/translations/nl.umd.js +11 -0
  85. package/dist/translations/no.d.ts +8 -0
  86. package/dist/translations/no.js +5 -0
  87. package/dist/translations/no.umd.js +11 -0
  88. package/dist/translations/pl.d.ts +8 -0
  89. package/dist/translations/pl.js +5 -0
  90. package/dist/translations/pl.umd.js +11 -0
  91. package/dist/translations/pt-br.d.ts +8 -0
  92. package/dist/translations/pt-br.js +5 -0
  93. package/dist/translations/pt-br.umd.js +11 -0
  94. package/dist/translations/pt.d.ts +8 -0
  95. package/dist/translations/pt.js +5 -0
  96. package/dist/translations/pt.umd.js +11 -0
  97. package/dist/translations/ro.d.ts +8 -0
  98. package/dist/translations/ro.js +5 -0
  99. package/dist/translations/ro.umd.js +11 -0
  100. package/dist/translations/ru.d.ts +8 -0
  101. package/dist/translations/ru.js +5 -0
  102. package/dist/translations/ru.umd.js +11 -0
  103. package/dist/translations/sk.d.ts +8 -0
  104. package/dist/translations/sk.js +5 -0
  105. package/dist/translations/sk.umd.js +11 -0
  106. package/dist/translations/sr.d.ts +8 -0
  107. package/dist/translations/sr.js +5 -0
  108. package/dist/translations/sr.umd.js +11 -0
  109. package/dist/translations/sv.d.ts +8 -0
  110. package/dist/translations/sv.js +5 -0
  111. package/dist/translations/sv.umd.js +11 -0
  112. package/dist/translations/th.d.ts +8 -0
  113. package/dist/translations/th.js +5 -0
  114. package/dist/translations/th.umd.js +11 -0
  115. package/dist/translations/tr.d.ts +8 -0
  116. package/dist/translations/tr.js +5 -0
  117. package/dist/translations/tr.umd.js +11 -0
  118. package/dist/translations/uk.d.ts +8 -0
  119. package/dist/translations/uk.js +5 -0
  120. package/dist/translations/uk.umd.js +11 -0
  121. package/dist/translations/vi.d.ts +8 -0
  122. package/dist/translations/vi.js +5 -0
  123. package/dist/translations/vi.umd.js +11 -0
  124. package/dist/translations/zh-cn.d.ts +8 -0
  125. package/dist/translations/zh-cn.js +5 -0
  126. package/dist/translations/zh-cn.umd.js +11 -0
  127. package/dist/translations/zh.d.ts +8 -0
  128. package/dist/translations/zh.js +5 -0
  129. package/dist/translations/zh.umd.js +11 -0
  130. package/dist/types/augmentation.d.ts +20 -0
  131. package/dist/types/clipboard.d.ts +40 -0
  132. package/dist/types/clipboardmarkersutils.d.ts +204 -0
  133. package/dist/types/clipboardobserver.d.ts +316 -0
  134. package/dist/types/clipboardpipeline.d.ts +269 -0
  135. package/dist/types/dragdrop.d.ts +106 -0
  136. package/dist/types/dragdropblocktoolbar.d.ts +51 -0
  137. package/dist/types/dragdroptarget.d.ts +98 -0
  138. package/dist/types/index.d.ts +21 -0
  139. package/dist/types/lineview.d.ts +49 -0
  140. package/dist/types/pasteplaintext.d.ts +32 -0
  141. package/dist/types/utils/normalizeclipboarddata.d.ts +19 -0
  142. package/dist/types/utils/plaintexttohtml.d.ts +18 -0
  143. package/dist/types/utils/viewtoplaintext.d.ts +19 -0
  144. package/package.json +7 -6
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ ( e => {
7
+ const { [ 'zh-cn' ]: { dictionary, getPluralForm } } = {"zh-cn":{"dictionary":{"Copy selected content":"复制选定的内容","Paste content":"粘贴内容","Paste content as plain text":"将内容粘贴为纯文本"},getPluralForm(n){return 0;}}};
8
+ e[ 'zh-cn' ] ||= { dictionary: {}, getPluralForm: null };
9
+ e[ 'zh-cn' ].dictionary = Object.assign( e[ 'zh-cn' ].dictionary, dictionary );
10
+ e[ 'zh-cn' ].getPluralForm = getPluralForm;
11
+ } )( window.CKEDITOR_TRANSLATIONS ||= {} );
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ import type { Translations } from 'ckeditor5';
7
+ declare const translations: Translations;
8
+ export default translations;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ export default {"zh":{"dictionary":{"Copy selected content":"複製所選內容","Paste content":"貼上內容","Paste content as plain text":"將內容貼上為純文字"},getPluralForm(n){return 0;}}}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ ( e => {
7
+ const { [ 'zh' ]: { dictionary, getPluralForm } } = {"zh":{"dictionary":{"Copy selected content":"複製所選內容","Paste content":"貼上內容","Paste content as plain text":"將內容貼上為純文字"},getPluralForm(n){return 0;}}};
8
+ e[ 'zh' ] ||= { dictionary: {}, getPluralForm: null };
9
+ e[ 'zh' ].dictionary = Object.assign( e[ 'zh' ].dictionary, dictionary );
10
+ e[ 'zh' ].getPluralForm = getPluralForm;
11
+ } )( window.CKEDITOR_TRANSLATIONS ||= {} );
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type { Clipboard, ClipboardPipeline, PastePlainText, DragDrop, DragDropTarget, DragDropBlockToolbar, ClipboardMarkersUtils } from './index.js';
10
+ declare module '@ckeditor/ckeditor5-core' {
11
+ interface PluginsMap {
12
+ [Clipboard.pluginName]: Clipboard;
13
+ [ClipboardPipeline.pluginName]: ClipboardPipeline;
14
+ [ClipboardMarkersUtils.pluginName]: ClipboardMarkersUtils;
15
+ [PastePlainText.pluginName]: PastePlainText;
16
+ [DragDrop.pluginName]: DragDrop;
17
+ [DragDropTarget.pluginName]: DragDropTarget;
18
+ [DragDropBlockToolbar.pluginName]: DragDropBlockToolbar;
19
+ }
20
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module clipboard/clipboard
11
+ */
12
+ import { Plugin } from '@ckeditor/ckeditor5-core';
13
+ import ClipboardPipeline from './clipboardpipeline.js';
14
+ import DragDrop from './dragdrop.js';
15
+ import PastePlainText from './pasteplaintext.js';
16
+ import ClipboardMarkersUtils from './clipboardmarkersutils.js';
17
+ /**
18
+ * The clipboard feature.
19
+ *
20
+ * Read more about the clipboard integration in the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
21
+ *
22
+ * This is a "glue" plugin which loads the following plugins:
23
+ * * {@link module:clipboard/clipboardpipeline~ClipboardPipeline}
24
+ * * {@link module:clipboard/dragdrop~DragDrop}
25
+ * * {@link module:clipboard/pasteplaintext~PastePlainText}
26
+ */
27
+ export default class Clipboard extends Plugin {
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName(): "Clipboard";
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ static get requires(): readonly [typeof ClipboardMarkersUtils, typeof ClipboardPipeline, typeof DragDrop, typeof PastePlainText];
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ init(): void;
40
+ }
@@ -0,0 +1,204 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { Plugin, type NonEmptyArray } from '@ckeditor/ckeditor5-core';
10
+ import { Range, type DocumentFragment, type Element, type DocumentSelection, type Selection, type Writer } from '@ckeditor/ckeditor5-engine';
11
+ /**
12
+ * Part of the clipboard logic. Responsible for collecting markers from selected fragments
13
+ * and restoring them with proper positions in pasted elements.
14
+ *
15
+ * @internal
16
+ */
17
+ export default class ClipboardMarkersUtils extends Plugin {
18
+ /**
19
+ * Map of marker names that can be copied.
20
+ *
21
+ * @internal
22
+ */
23
+ private _markersToCopy;
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get pluginName(): "ClipboardMarkersUtils";
28
+ /**
29
+ * Registers marker name as copyable in clipboard pipeline.
30
+ *
31
+ * @param markerName Name of marker that can be copied.
32
+ * @param config Configuration that describes what can be performed on specified marker.
33
+ * @internal
34
+ */
35
+ _registerMarkerToCopy(markerName: string, config: ClipboardMarkerConfiguration): void;
36
+ /**
37
+ * Performs copy markers on provided selection and paste it to fragment returned from `getCopiedFragment`.
38
+ *
39
+ * 1. Picks all markers in provided selection.
40
+ * 2. Inserts fake markers to document.
41
+ * 3. Gets copied selection fragment from document.
42
+ * 4. Removes fake elements from fragment and document.
43
+ * 5. Inserts markers in the place of removed fake markers.
44
+ *
45
+ * Due to selection modification, when inserting items, `getCopiedFragment` must *always* operate on `writer.model.document.selection'.
46
+ * Do not use any other custom selection object within callback, as this will lead to out-of-bounds exceptions in rare scenarios.
47
+ *
48
+ * @param action Type of clipboard action.
49
+ * @param writer An instance of the model writer.
50
+ * @param selection Selection to be checked.
51
+ * @param getCopiedFragment Callback that performs copy of selection and returns it as fragment.
52
+ * @internal
53
+ */
54
+ _copySelectedFragmentWithMarkers(action: ClipboardMarkerRestrictedAction, selection: Selection | DocumentSelection, getCopiedFragment?: (writer: Writer) => DocumentFragment): DocumentFragment;
55
+ /**
56
+ * Performs paste of markers on already pasted element.
57
+ *
58
+ * 1. Inserts fake markers that are present in fragment element (such fragment will be processed in `getPastedDocumentElement`).
59
+ * 2. Calls `getPastedDocumentElement` and gets element that is inserted into root model.
60
+ * 3. Removes all fake markers present in transformed element.
61
+ * 4. Inserts new markers with removed fake markers ranges into pasted fragment.
62
+ *
63
+ * There are multiple edge cases that have to be considered before calling this function:
64
+ *
65
+ * * `markers` are inserted into the same element that must be later transformed inside `getPastedDocumentElement`.
66
+ * * Fake marker elements inside `getPastedDocumentElement` can be cloned, but their ranges cannot overlap.
67
+ * * If `duplicateOnPaste` is `true` in marker config then associated marker ID is regenerated before pasting.
68
+ *
69
+ * @param action Type of clipboard action.
70
+ * @param markers Object that maps marker name to corresponding range.
71
+ * @param getPastedDocumentElement Getter used to get target markers element.
72
+ * @internal
73
+ */
74
+ _pasteMarkersIntoTransformedElement(markers: Record<string, Range> | Map<string, Range>, getPastedDocumentElement: (writer: Writer) => Element): Element;
75
+ /**
76
+ * Pastes document fragment with markers to document.
77
+ * If `duplicateOnPaste` is `true` in marker config then associated markers IDs
78
+ * are regenerated before pasting to avoid markers duplications in content.
79
+ *
80
+ * @param fragment Document fragment that should contain already processed by pipeline markers.
81
+ * @internal
82
+ */
83
+ _pasteFragmentWithMarkers(fragment: DocumentFragment): Range;
84
+ /**
85
+ * In some situations we have to perform copy on selected fragment with certain markers. This function allows to temporarily bypass
86
+ * restrictions on markers that we want to copy.
87
+ *
88
+ * This function executes `executor()` callback. For the duration of the callback, if the clipboard pipeline is used to copy
89
+ * content, markers with the specified name will be copied to the clipboard as well.
90
+ *
91
+ * @param markerName Which markers should be copied.
92
+ * @param executor Callback executed.
93
+ * @param config Optional configuration flags used to copy (such like partial copy flag).
94
+ * @internal
95
+ */
96
+ _forceMarkersCopy(markerName: string, executor: VoidFunction, config?: ClipboardMarkerConfiguration): void;
97
+ /**
98
+ * Checks if marker can be copied.
99
+ *
100
+ * @param markerName Name of checked marker.
101
+ * @param action Type of clipboard action. If null then checks only if marker is registered as copyable.
102
+ * @internal
103
+ */
104
+ _isMarkerCopyable(markerName: string, action: ClipboardMarkerRestrictedAction | null): boolean;
105
+ /**
106
+ * Checks if marker has any clipboard copy behavior configuration.
107
+ *
108
+ * @param markerName Name of checked marker.
109
+ */
110
+ _hasMarkerConfiguration(markerName: string): boolean;
111
+ /**
112
+ * Returns marker's configuration flags passed during registration.
113
+ *
114
+ * @param markerName Name of marker that should be returned.
115
+ * @internal
116
+ */
117
+ _getMarkerClipboardConfig(markerName: string): ClipboardMarkerConfiguration | null;
118
+ /**
119
+ * First step of copying markers. It looks for markers intersecting with given selection and inserts `$marker` elements
120
+ * at positions where document markers start or end. This way `$marker` elements can be easily copied together with
121
+ * the rest of the content of the selection.
122
+ *
123
+ * @param writer An instance of the model writer.
124
+ * @param selection Selection to be checked.
125
+ * @param action Type of clipboard action.
126
+ */
127
+ private _insertFakeMarkersIntoSelection;
128
+ /**
129
+ * Returns array of markers that can be copied in specified selection.
130
+ *
131
+ * If marker cannot be copied partially (according to `copyPartiallySelected` configuration flag) and
132
+ * is not present entirely in any selection range then it will be skipped.
133
+ *
134
+ * @param writer An instance of the model writer.
135
+ * @param selection Selection which will be checked.
136
+ * @param action Type of clipboard action. If null then checks only if marker is registered as copyable.
137
+ */
138
+ private _getCopyableMarkersFromSelection;
139
+ /**
140
+ * Picks all markers from markers map that can be pasted.
141
+ * If `duplicateOnPaste` is `true`, it regenerates their IDs to ensure uniqueness.
142
+ * If marker is not registered, it will be kept in the array anyway.
143
+ *
144
+ * @param markers Object that maps marker name to corresponding range.
145
+ * @param action Type of clipboard action. If null then checks only if marker is registered as copyable.
146
+ */
147
+ private _getPasteMarkersFromRangeMap;
148
+ /**
149
+ * Inserts specified array of fake markers elements to document and assigns them `type` and `name` attributes.
150
+ * Fake markers elements are used to calculate position of markers on pasted fragment that were transformed during
151
+ * steps between copy and paste.
152
+ *
153
+ * @param writer An instance of the model writer.
154
+ * @param markers Array of markers that will be inserted.
155
+ */
156
+ private _insertFakeMarkersElements;
157
+ /**
158
+ * Removes all `$marker` elements from the given document fragment.
159
+ *
160
+ * Returns an object where keys are marker names, and values are ranges corresponding to positions
161
+ * where `$marker` elements were inserted.
162
+ *
163
+ * If the document fragment had only one `$marker` element for given marker (start or end) the other boundary is set automatically
164
+ * (to the end or start of the document fragment, respectively).
165
+ *
166
+ * @param writer An instance of the model writer.
167
+ * @param rootElement The element to be checked.
168
+ */
169
+ private _removeFakeMarkersInsideElement;
170
+ /**
171
+ * Returns array that contains list of fake markers with corresponding `$marker` elements.
172
+ *
173
+ * For each marker, there can be two `$marker` elements or only one (if the document fragment contained
174
+ * only the beginning or only the end of a marker).
175
+ *
176
+ * @param writer An instance of the model writer.
177
+ * @param rootElement The element to be checked.
178
+ */
179
+ private _getAllFakeMarkersFromElement;
180
+ /**
181
+ * When copy of markers occurs we have to make sure that pasted markers have different names
182
+ * than source markers. This functions helps with assigning unique part to marker name to
183
+ * prevent duplicated markers error.
184
+ *
185
+ * @param name Name of marker
186
+ */
187
+ private _getUniqueMarkerName;
188
+ }
189
+ /**
190
+ * Specifies which action is performed during clipboard event.
191
+ *
192
+ * @internal
193
+ */
194
+ export type ClipboardMarkerRestrictedAction = 'copy' | 'cut' | 'dragstart';
195
+ /**
196
+ * Specifies behavior of markers during clipboard actions.
197
+ *
198
+ * @internal
199
+ */
200
+ export type ClipboardMarkerConfiguration = {
201
+ allowedActions: NonEmptyArray<ClipboardMarkerRestrictedAction> | 'all';
202
+ copyPartiallySelected?: boolean;
203
+ duplicateOnPaste?: boolean;
204
+ };
@@ -0,0 +1,316 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { DataTransfer, DomEventObserver, type DomEventData, type EditingView, type ViewDocumentFragment, type ViewElement, type ViewRange } from '@ckeditor/ckeditor5-engine';
10
+ /**
11
+ * Clipboard events observer.
12
+ *
13
+ * Fires the following events:
14
+ *
15
+ * * {@link module:engine/view/document~Document#event:clipboardInput},
16
+ * * {@link module:engine/view/document~Document#event:paste},
17
+ * * {@link module:engine/view/document~Document#event:copy},
18
+ * * {@link module:engine/view/document~Document#event:cut},
19
+ * * {@link module:engine/view/document~Document#event:drop},
20
+ * * {@link module:engine/view/document~Document#event:dragover},
21
+ * * {@link module:engine/view/document~Document#event:dragging},
22
+ * * {@link module:engine/view/document~Document#event:dragstart},
23
+ * * {@link module:engine/view/document~Document#event:dragend},
24
+ * * {@link module:engine/view/document~Document#event:dragenter},
25
+ * * {@link module:engine/view/document~Document#event:dragleave}.
26
+ *
27
+ * **Note**: This observer is not available by default (ckeditor5-engine does not add it on its own).
28
+ * To make it available, it needs to be added to {@link module:engine/view/document~Document} by using
29
+ * the {@link module:engine/view/view~View#addObserver `View#addObserver()`} method. Alternatively, you can load the
30
+ * {@link module:clipboard/clipboard~Clipboard} plugin which adds this observer automatically (because it uses it).
31
+ */
32
+ export default class ClipboardObserver extends DomEventObserver<'paste' | 'copy' | 'cut' | 'drop' | 'dragover' | 'dragstart' | 'dragend' | 'dragenter' | 'dragleave', ClipboardEventData> {
33
+ readonly domEventType: readonly ["paste", "copy", "cut", "drop", "dragover", "dragstart", "dragend", "dragenter", "dragleave"];
34
+ constructor(view: EditingView);
35
+ onDomEvent(domEvent: ClipboardEvent | DragEvent): void;
36
+ }
37
+ /**
38
+ * The data of 'paste', 'copy', 'cut', 'drop', 'dragover', 'dragstart', 'dragend', 'dragenter' and 'dragleave' events.
39
+ */
40
+ export interface ClipboardEventData {
41
+ /**
42
+ * The data transfer instance.
43
+ */
44
+ dataTransfer: DataTransfer;
45
+ /**
46
+ * The position into which the content is dropped.
47
+ */
48
+ dropRange?: ViewRange | null;
49
+ }
50
+ /**
51
+ * Fired as a continuation of the {@link module:engine/view/document~Document#event:paste} and
52
+ * {@link module:engine/view/document~Document#event:drop} events.
53
+ *
54
+ * It is a part of the {@glink framework/deep-dive/clipboard#input-pipeline clipboard input pipeline}.
55
+ *
56
+ * This event carries a `dataTransfer` object which comes from the clipboard and whose content should be processed
57
+ * and inserted into the editor.
58
+ *
59
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
60
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
61
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
62
+ * the observer must be added manually.
63
+ *
64
+ * @see module:clipboard/clipboardobserver~ClipboardObserver
65
+ * @see module:clipboard/clipboard~Clipboard
66
+ *
67
+ * @eventName module:engine/view/document~Document#clipboardInput
68
+ * @param data The event data.
69
+ */
70
+ export type ViewDocumentClipboardInputEvent = {
71
+ name: 'clipboardInput';
72
+ args: [data: DomEventData<ClipboardEvent | DragEvent> & ClipboardInputEventData];
73
+ };
74
+ /**
75
+ * The value of the {@link module:engine/view/document~Document#event:paste},
76
+ * {@link module:engine/view/document~Document#event:copy} and {@link module:engine/view/document~Document#event:cut} events.
77
+ *
78
+ * In order to access the clipboard data, use the `dataTransfer` property.
79
+ */
80
+ export interface ClipboardInputEventData {
81
+ /**
82
+ * Data transfer instance.
83
+ */
84
+ dataTransfer: DataTransfer;
85
+ /**
86
+ * Whether the event was triggered by a paste or a drop operation.
87
+ */
88
+ method: 'paste' | 'drop';
89
+ /**
90
+ * The tree view element representing the target.
91
+ */
92
+ target: ViewElement;
93
+ /**
94
+ * The ranges which are the target of the operation (usually – into which the content should be inserted).
95
+ * If the clipboard input was triggered by a paste operation, this property is not set. If by a drop operation,
96
+ * then it is the drop position (which can be different than the selection at the moment of the drop).
97
+ */
98
+ targetRanges: Array<ViewRange> | null;
99
+ /**
100
+ * The content of clipboard input.
101
+ */
102
+ content?: ViewDocumentFragment;
103
+ }
104
+ /**
105
+ * Fired when the user drags the content over one of the editing roots of the editor.
106
+ *
107
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
108
+ *
109
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
110
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
111
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
112
+ * the observer must be added manually.
113
+ *
114
+ * @see module:engine/view/document~Document#event:clipboardInput
115
+ *
116
+ * @eventName module:engine/view/document~Document#dragover
117
+ * @param data The event data.
118
+ */
119
+ export type ViewDocumentDragOverEvent = {
120
+ name: 'dragover';
121
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
122
+ };
123
+ /**
124
+ * Fired when the user dropped the content into one of the editing roots of the editor.
125
+ *
126
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
127
+ *
128
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
129
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
130
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
131
+ * the observer must be added manually.
132
+ *
133
+ * @see module:engine/view/document~Document#event:clipboardInput
134
+ *
135
+ * @eventName module:engine/view/document~Document#drop
136
+ * @param data The event data.
137
+ */
138
+ export type ViewDocumentDropEvent = {
139
+ name: 'drop';
140
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
141
+ };
142
+ /**
143
+ * Fired when the user pasted the content into one of the editing roots of the editor.
144
+ *
145
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
146
+ *
147
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
148
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
149
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
150
+ * the observer must be added manually.
151
+ *
152
+ * @see module:engine/view/document~Document#event:clipboardInput
153
+ *
154
+ * @eventName module:engine/view/document~Document#paste
155
+ * @param {module:clipboard/clipboardobserver~ClipboardEventData} data The event data.
156
+ */
157
+ export type ViewDocumentPasteEvent = {
158
+ name: 'paste';
159
+ args: [data: DomEventData<ClipboardEvent> & ClipboardEventData];
160
+ };
161
+ /**
162
+ * Fired when the user copied the content from one of the editing roots of the editor.
163
+ *
164
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
165
+ *
166
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
167
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
168
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
169
+ * the observer must be added manually.
170
+ *
171
+ * @see module:clipboard/clipboardobserver~ClipboardObserver
172
+ *
173
+ * @eventName module:engine/view/document~Document#copy
174
+ * @param data The event data.
175
+ */
176
+ export type ViewDocumentCopyEvent = {
177
+ name: 'copy';
178
+ args: [data: DomEventData<ClipboardEvent> & ClipboardEventData];
179
+ };
180
+ /**
181
+ * Fired when the user cut the content from one of the editing roots of the editor.
182
+ *
183
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
184
+ *
185
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
186
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
187
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
188
+ * the observer must be added manually.
189
+ *
190
+ * @see module:clipboard/clipboardobserver~ClipboardObserver
191
+ *
192
+ * @eventName module:engine/view/document~Document#cut
193
+ * @param data The event data.
194
+ */
195
+ export type ViewDocumentCutEvent = {
196
+ name: 'cut';
197
+ args: [data: DomEventData<ClipboardEvent> & ClipboardEventData];
198
+ };
199
+ /**
200
+ * Fired as a continuation of the {@link module:engine/view/document~Document#event:dragover} event.
201
+ *
202
+ * It is a part of the {@glink framework/deep-dive/clipboard#input-pipeline clipboard input pipeline}.
203
+ *
204
+ * This event carries a `dataTransfer` object which comes from the clipboard and whose content should be processed
205
+ * and inserted into the editor.
206
+ *
207
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
208
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
209
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
210
+ * the observer must be added manually.
211
+ *
212
+ * @see module:clipboard/clipboardobserver~ClipboardObserver
213
+ * @see module:clipboard/clipboard~Clipboard
214
+ *
215
+ * @eventName module:engine/view/document~Document#dragging
216
+ * @param data The event data.
217
+ */
218
+ export type ViewDocumentDraggingEvent = {
219
+ name: 'dragging';
220
+ args: [data: DomEventData<DragEvent> & DraggingEventData];
221
+ };
222
+ export interface DraggingEventData {
223
+ /**
224
+ * The data transfer instance.
225
+ */
226
+ dataTransfer: DataTransfer;
227
+ /**
228
+ * Whether the event was triggered by a paste or a drop operation.
229
+ */
230
+ method: 'dragover';
231
+ /**
232
+ * The tree view element representing the target.
233
+ */
234
+ target: Element;
235
+ /**
236
+ * Ranges which are the target of the operation (usually – into which the content should be inserted).
237
+ * It is the drop position (which can be different than the selection at the moment of drop).
238
+ */
239
+ targetRanges: Array<ViewRange> | null;
240
+ }
241
+ /**
242
+ * Fired when the user starts dragging the content in one of the editing roots of the editor.
243
+ *
244
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
245
+ *
246
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
247
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
248
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
249
+ * the observer must be added manually.
250
+ *
251
+ * @see module:engine/view/document~Document#event:clipboardInput
252
+ *
253
+ * @eventName module:engine/view/document~Document#dragstart
254
+ * @param data The event data.
255
+ */
256
+ export type ViewDocumentDragStartEvent = {
257
+ name: 'dragstart';
258
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
259
+ };
260
+ /**
261
+ * Fired when the user ended dragging the content.
262
+ *
263
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
264
+ *
265
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
266
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
267
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
268
+ * the observer must be added manually.
269
+ *
270
+ * @see module:engine/view/document~Document#event:clipboardInput
271
+ *
272
+ * @eventName module:engine/view/document~Document#dragend
273
+ * @param data The event data.
274
+ */
275
+ export type ViewDocumentDragEndEvent = {
276
+ name: 'dragend';
277
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
278
+ };
279
+ /**
280
+ * Fired when the user drags the content into one of the editing roots of the editor.
281
+ *
282
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
283
+ *
284
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
285
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
286
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
287
+ * the observer must be added manually.
288
+ *
289
+ * @see module:engine/view/document~Document#event:clipboardInput
290
+ *
291
+ * @eventName module:engine/view/document~Document#dragenter
292
+ * @param data The event data.
293
+ */
294
+ export type ViewDocumentDragEnterEvent = {
295
+ name: 'dragenter';
296
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
297
+ };
298
+ /**
299
+ * Fired when the user drags the content out of one of the editing roots of the editor.
300
+ *
301
+ * Introduced by {@link module:clipboard/clipboardobserver~ClipboardObserver}.
302
+ *
303
+ * **Note**: This event is not available by default. To make it available, {@link module:clipboard/clipboardobserver~ClipboardObserver}
304
+ * needs to be added to the {@link module:engine/view/document~Document} by using the {@link module:engine/view/view~View#addObserver}
305
+ * method. This is usually done by the {@link module:clipboard/clipboard~Clipboard} plugin, but if for some reason it is not loaded,
306
+ * the observer must be added manually.
307
+ *
308
+ * @see module:engine/view/document~Document#event:clipboardInput
309
+ *
310
+ * @eventName module:engine/view/document~Document#dragleave
311
+ * @param data The event data.
312
+ */
313
+ export type ViewDocumentDragLeaveEvent = {
314
+ name: 'dragleave';
315
+ args: [data: DomEventData<DragEvent> & ClipboardEventData];
316
+ };