@ckeditor/ckeditor5-clipboard 0.0.0-internal-20241017.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 (226) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +22 -0
  4. package/dist/augmentation.d.ts +20 -0
  5. package/dist/clipboard.d.ts +44 -0
  6. package/dist/clipboardmarkersutils.d.ts +208 -0
  7. package/dist/clipboardobserver.d.ts +316 -0
  8. package/dist/clipboardpipeline.d.ts +273 -0
  9. package/dist/dragdrop.d.ts +110 -0
  10. package/dist/dragdropblocktoolbar.d.ts +55 -0
  11. package/dist/dragdroptarget.d.ts +102 -0
  12. package/dist/index-content.css +4 -0
  13. package/dist/index-editor.css +27 -0
  14. package/dist/index.css +42 -0
  15. package/dist/index.css.map +1 -0
  16. package/dist/index.d.ts +22 -0
  17. package/dist/index.js +2183 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/lineview.d.ts +49 -0
  20. package/dist/pasteplaintext.d.ts +36 -0
  21. package/dist/translations/ar.d.ts +8 -0
  22. package/dist/translations/ar.js +5 -0
  23. package/dist/translations/ar.umd.js +11 -0
  24. package/dist/translations/bg.d.ts +8 -0
  25. package/dist/translations/bg.js +5 -0
  26. package/dist/translations/bg.umd.js +11 -0
  27. package/dist/translations/bn.d.ts +8 -0
  28. package/dist/translations/bn.js +5 -0
  29. package/dist/translations/bn.umd.js +11 -0
  30. package/dist/translations/ca.d.ts +8 -0
  31. package/dist/translations/ca.js +5 -0
  32. package/dist/translations/ca.umd.js +11 -0
  33. package/dist/translations/cs.d.ts +8 -0
  34. package/dist/translations/cs.js +5 -0
  35. package/dist/translations/cs.umd.js +11 -0
  36. package/dist/translations/da.d.ts +8 -0
  37. package/dist/translations/da.js +5 -0
  38. package/dist/translations/da.umd.js +11 -0
  39. package/dist/translations/de.d.ts +8 -0
  40. package/dist/translations/de.js +5 -0
  41. package/dist/translations/de.umd.js +11 -0
  42. package/dist/translations/el.d.ts +8 -0
  43. package/dist/translations/el.js +5 -0
  44. package/dist/translations/el.umd.js +11 -0
  45. package/dist/translations/en.d.ts +8 -0
  46. package/dist/translations/en.js +5 -0
  47. package/dist/translations/en.umd.js +11 -0
  48. package/dist/translations/es-co.d.ts +8 -0
  49. package/dist/translations/es-co.js +5 -0
  50. package/dist/translations/es-co.umd.js +11 -0
  51. package/dist/translations/es.d.ts +8 -0
  52. package/dist/translations/es.js +5 -0
  53. package/dist/translations/es.umd.js +11 -0
  54. package/dist/translations/et.d.ts +8 -0
  55. package/dist/translations/et.js +5 -0
  56. package/dist/translations/et.umd.js +11 -0
  57. package/dist/translations/fi.d.ts +8 -0
  58. package/dist/translations/fi.js +5 -0
  59. package/dist/translations/fi.umd.js +11 -0
  60. package/dist/translations/fr.d.ts +8 -0
  61. package/dist/translations/fr.js +5 -0
  62. package/dist/translations/fr.umd.js +11 -0
  63. package/dist/translations/gl.d.ts +8 -0
  64. package/dist/translations/gl.js +5 -0
  65. package/dist/translations/gl.umd.js +11 -0
  66. package/dist/translations/he.d.ts +8 -0
  67. package/dist/translations/he.js +5 -0
  68. package/dist/translations/he.umd.js +11 -0
  69. package/dist/translations/hi.d.ts +8 -0
  70. package/dist/translations/hi.js +5 -0
  71. package/dist/translations/hi.umd.js +11 -0
  72. package/dist/translations/hr.d.ts +8 -0
  73. package/dist/translations/hr.js +5 -0
  74. package/dist/translations/hr.umd.js +11 -0
  75. package/dist/translations/hu.d.ts +8 -0
  76. package/dist/translations/hu.js +5 -0
  77. package/dist/translations/hu.umd.js +11 -0
  78. package/dist/translations/id.d.ts +8 -0
  79. package/dist/translations/id.js +5 -0
  80. package/dist/translations/id.umd.js +11 -0
  81. package/dist/translations/it.d.ts +8 -0
  82. package/dist/translations/it.js +5 -0
  83. package/dist/translations/it.umd.js +11 -0
  84. package/dist/translations/ja.d.ts +8 -0
  85. package/dist/translations/ja.js +5 -0
  86. package/dist/translations/ja.umd.js +11 -0
  87. package/dist/translations/ko.d.ts +8 -0
  88. package/dist/translations/ko.js +5 -0
  89. package/dist/translations/ko.umd.js +11 -0
  90. package/dist/translations/lt.d.ts +8 -0
  91. package/dist/translations/lt.js +5 -0
  92. package/dist/translations/lt.umd.js +11 -0
  93. package/dist/translations/lv.d.ts +8 -0
  94. package/dist/translations/lv.js +5 -0
  95. package/dist/translations/lv.umd.js +11 -0
  96. package/dist/translations/ms.d.ts +8 -0
  97. package/dist/translations/ms.js +5 -0
  98. package/dist/translations/ms.umd.js +11 -0
  99. package/dist/translations/nl.d.ts +8 -0
  100. package/dist/translations/nl.js +5 -0
  101. package/dist/translations/nl.umd.js +11 -0
  102. package/dist/translations/no.d.ts +8 -0
  103. package/dist/translations/no.js +5 -0
  104. package/dist/translations/no.umd.js +11 -0
  105. package/dist/translations/pl.d.ts +8 -0
  106. package/dist/translations/pl.js +5 -0
  107. package/dist/translations/pl.umd.js +11 -0
  108. package/dist/translations/pt-br.d.ts +8 -0
  109. package/dist/translations/pt-br.js +5 -0
  110. package/dist/translations/pt-br.umd.js +11 -0
  111. package/dist/translations/pt.d.ts +8 -0
  112. package/dist/translations/pt.js +5 -0
  113. package/dist/translations/pt.umd.js +11 -0
  114. package/dist/translations/ro.d.ts +8 -0
  115. package/dist/translations/ro.js +5 -0
  116. package/dist/translations/ro.umd.js +11 -0
  117. package/dist/translations/ru.d.ts +8 -0
  118. package/dist/translations/ru.js +5 -0
  119. package/dist/translations/ru.umd.js +11 -0
  120. package/dist/translations/sk.d.ts +8 -0
  121. package/dist/translations/sk.js +5 -0
  122. package/dist/translations/sk.umd.js +11 -0
  123. package/dist/translations/sr-latn.d.ts +8 -0
  124. package/dist/translations/sr-latn.js +5 -0
  125. package/dist/translations/sr-latn.umd.js +11 -0
  126. package/dist/translations/sr.d.ts +8 -0
  127. package/dist/translations/sr.js +5 -0
  128. package/dist/translations/sr.umd.js +11 -0
  129. package/dist/translations/sv.d.ts +8 -0
  130. package/dist/translations/sv.js +5 -0
  131. package/dist/translations/sv.umd.js +11 -0
  132. package/dist/translations/th.d.ts +8 -0
  133. package/dist/translations/th.js +5 -0
  134. package/dist/translations/th.umd.js +11 -0
  135. package/dist/translations/tr.d.ts +8 -0
  136. package/dist/translations/tr.js +5 -0
  137. package/dist/translations/tr.umd.js +11 -0
  138. package/dist/translations/uk.d.ts +8 -0
  139. package/dist/translations/uk.js +5 -0
  140. package/dist/translations/uk.umd.js +11 -0
  141. package/dist/translations/vi.d.ts +8 -0
  142. package/dist/translations/vi.js +5 -0
  143. package/dist/translations/vi.umd.js +11 -0
  144. package/dist/translations/zh-cn.d.ts +8 -0
  145. package/dist/translations/zh-cn.js +5 -0
  146. package/dist/translations/zh-cn.umd.js +11 -0
  147. package/dist/translations/zh.d.ts +8 -0
  148. package/dist/translations/zh.js +5 -0
  149. package/dist/translations/zh.umd.js +11 -0
  150. package/dist/utils/normalizeclipboarddata.d.ts +19 -0
  151. package/dist/utils/plaintexttohtml.d.ts +18 -0
  152. package/dist/utils/viewtoplaintext.d.ts +19 -0
  153. package/lang/contexts.json +5 -0
  154. package/lang/translations/ar.po +30 -0
  155. package/lang/translations/bg.po +30 -0
  156. package/lang/translations/bn.po +30 -0
  157. package/lang/translations/ca.po +30 -0
  158. package/lang/translations/cs.po +30 -0
  159. package/lang/translations/da.po +30 -0
  160. package/lang/translations/de.po +30 -0
  161. package/lang/translations/el.po +30 -0
  162. package/lang/translations/en.po +30 -0
  163. package/lang/translations/es-co.po +30 -0
  164. package/lang/translations/es.po +30 -0
  165. package/lang/translations/et.po +30 -0
  166. package/lang/translations/fi.po +30 -0
  167. package/lang/translations/fr.po +30 -0
  168. package/lang/translations/gl.po +30 -0
  169. package/lang/translations/he.po +30 -0
  170. package/lang/translations/hi.po +30 -0
  171. package/lang/translations/hr.po +30 -0
  172. package/lang/translations/hu.po +30 -0
  173. package/lang/translations/id.po +30 -0
  174. package/lang/translations/it.po +30 -0
  175. package/lang/translations/ja.po +30 -0
  176. package/lang/translations/ko.po +30 -0
  177. package/lang/translations/lt.po +30 -0
  178. package/lang/translations/lv.po +30 -0
  179. package/lang/translations/ms.po +30 -0
  180. package/lang/translations/nl.po +30 -0
  181. package/lang/translations/no.po +30 -0
  182. package/lang/translations/pl.po +30 -0
  183. package/lang/translations/pt-br.po +30 -0
  184. package/lang/translations/pt.po +30 -0
  185. package/lang/translations/ro.po +30 -0
  186. package/lang/translations/ru.po +30 -0
  187. package/lang/translations/sk.po +30 -0
  188. package/lang/translations/sr-latn.po +30 -0
  189. package/lang/translations/sr.po +30 -0
  190. package/lang/translations/sv.po +30 -0
  191. package/lang/translations/th.po +30 -0
  192. package/lang/translations/tr.po +30 -0
  193. package/lang/translations/uk.po +30 -0
  194. package/lang/translations/vi.po +30 -0
  195. package/lang/translations/zh-cn.po +30 -0
  196. package/lang/translations/zh.po +30 -0
  197. package/package.json +42 -0
  198. package/src/augmentation.d.ts +16 -0
  199. package/src/augmentation.js +5 -0
  200. package/src/clipboard.d.ts +40 -0
  201. package/src/clipboard.js +66 -0
  202. package/src/clipboardmarkersutils.d.ts +204 -0
  203. package/src/clipboardmarkersutils.js +505 -0
  204. package/src/clipboardobserver.d.ts +312 -0
  205. package/src/clipboardobserver.js +75 -0
  206. package/src/clipboardpipeline.d.ts +269 -0
  207. package/src/clipboardpipeline.js +283 -0
  208. package/src/dragdrop.d.ts +106 -0
  209. package/src/dragdrop.js +583 -0
  210. package/src/dragdropblocktoolbar.d.ts +51 -0
  211. package/src/dragdropblocktoolbar.js +127 -0
  212. package/src/dragdroptarget.d.ts +98 -0
  213. package/src/dragdroptarget.js +385 -0
  214. package/src/index.d.ts +18 -0
  215. package/src/index.js +16 -0
  216. package/src/lineview.d.ts +45 -0
  217. package/src/lineview.js +44 -0
  218. package/src/pasteplaintext.d.ts +32 -0
  219. package/src/pasteplaintext.js +102 -0
  220. package/src/utils/normalizeclipboarddata.d.ts +15 -0
  221. package/src/utils/normalizeclipboarddata.js +27 -0
  222. package/src/utils/plaintexttohtml.d.ts +14 -0
  223. package/src/utils/plaintexttohtml.js +39 -0
  224. package/src/utils/viewtoplaintext.d.ts +15 -0
  225. package/src/utils/viewtoplaintext.js +72 -0
  226. package/theme/clipboard.css +38 -0
@@ -0,0 +1,283 @@
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
+ * @module clipboard/clipboardpipeline
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import { EventInfo } from '@ckeditor/ckeditor5-utils';
10
+ import ClipboardObserver from './clipboardobserver.js';
11
+ import plainTextToHtml from './utils/plaintexttohtml.js';
12
+ import normalizeClipboardHtml from './utils/normalizeclipboarddata.js';
13
+ import viewToPlainText from './utils/viewtoplaintext.js';
14
+ import ClipboardMarkersUtils from './clipboardmarkersutils.js';
15
+ // Input pipeline events overview:
16
+ //
17
+ // ┌──────────────────────┐ ┌──────────────────────┐
18
+ // │ view.Document │ │ view.Document │
19
+ // │ paste │ │ drop │
20
+ // └───────────┬──────────┘ └───────────┬──────────┘
21
+ // │ │
22
+ // └────────────────┌────────────────┘
23
+ // │
24
+ // ┌─────────V────────┐
25
+ // │ view.Document │ Retrieves text/html or text/plain from data.dataTransfer
26
+ // │ clipboardInput │ and processes it to view.DocumentFragment.
27
+ // └─────────┬────────┘
28
+ // │
29
+ // ┌───────────V───────────┐
30
+ // │ ClipboardPipeline │ Converts view.DocumentFragment to model.DocumentFragment.
31
+ // │ inputTransformation │
32
+ // └───────────┬───────────┘
33
+ // │
34
+ // ┌──────────V──────────┐
35
+ // │ ClipboardPipeline │ Calls model.insertContent().
36
+ // │ contentInsertion │
37
+ // └─────────────────────┘
38
+ //
39
+ //
40
+ // Output pipeline events overview:
41
+ //
42
+ // ┌──────────────────────┐ ┌──────────────────────┐
43
+ // │ view.Document │ │ view.Document │ Retrieves the selected model.DocumentFragment
44
+ // │ copy │ │ cut │ and fires the `outputTransformation` event.
45
+ // └───────────┬──────────┘ └───────────┬──────────┘
46
+ // │ │
47
+ // └────────────────┌────────────────┘
48
+ // │
49
+ // ┌───────────V───────────┐
50
+ // │ ClipboardPipeline │ Processes model.DocumentFragment and converts it to
51
+ // │ outputTransformation │ view.DocumentFragment.
52
+ // └───────────┬───────────┘
53
+ // │
54
+ // ┌─────────V────────┐
55
+ // │ view.Document │ Processes view.DocumentFragment to text/html and text/plain
56
+ // │ clipboardOutput │ and stores the results in data.dataTransfer.
57
+ // └──────────────────┘
58
+ //
59
+ /**
60
+ * The clipboard pipeline feature. It is responsible for intercepting the `paste` and `drop` events and
61
+ * passing the pasted content through a series of events in order to insert it into the editor's content.
62
+ * It also handles the `cut` and `copy` events to fill the native clipboard with the serialized editor's data.
63
+ *
64
+ * # Input pipeline
65
+ *
66
+ * The behavior of the default handlers (all at a `low` priority):
67
+ *
68
+ * ## Event: `paste` or `drop`
69
+ *
70
+ * 1. Translates the event data.
71
+ * 2. Fires the {@link module:engine/view/document~Document#event:clipboardInput `view.Document#clipboardInput`} event.
72
+ *
73
+ * ## Event: `view.Document#clipboardInput`
74
+ *
75
+ * 1. If the `data.content` event field is already set (by some listener on a higher priority), it takes this content and fires the event
76
+ * from the last point.
77
+ * 2. Otherwise, it retrieves `text/html` or `text/plain` from `data.dataTransfer`.
78
+ * 3. Normalizes the raw data by applying simple filters on string data.
79
+ * 4. Processes the raw data to {@link module:engine/view/documentfragment~DocumentFragment `view.DocumentFragment`} with the
80
+ * {@link module:engine/controller/datacontroller~DataController#htmlProcessor `DataController#htmlProcessor`}.
81
+ * 5. Fires the {@link module:clipboard/clipboardpipeline~ClipboardPipeline#event:inputTransformation
82
+ * `ClipboardPipeline#inputTransformation`} event with the view document fragment in the `data.content` event field.
83
+ *
84
+ * ## Event: `ClipboardPipeline#inputTransformation`
85
+ *
86
+ * 1. Converts {@link module:engine/view/documentfragment~DocumentFragment `view.DocumentFragment`} from the `data.content` field to
87
+ * {@link module:engine/model/documentfragment~DocumentFragment `model.DocumentFragment`}.
88
+ * 2. Fires the {@link module:clipboard/clipboardpipeline~ClipboardPipeline#event:contentInsertion `ClipboardPipeline#contentInsertion`}
89
+ * event with the model document fragment in the `data.content` event field.
90
+ * **Note**: The `ClipboardPipeline#contentInsertion` event is fired within a model change block to allow other handlers
91
+ * to run in the same block without post-fixers called in between (i.e., the selection post-fixer).
92
+ *
93
+ * ## Event: `ClipboardPipeline#contentInsertion`
94
+ *
95
+ * 1. Calls {@link module:engine/model/model~Model#insertContent `model.insertContent()`} to insert `data.content`
96
+ * at the current selection position.
97
+ *
98
+ * # Output pipeline
99
+ *
100
+ * The behavior of the default handlers (all at a `low` priority):
101
+ *
102
+ * ## Event: `copy`, `cut` or `dragstart`
103
+ *
104
+ * 1. Retrieves the selected {@link module:engine/model/documentfragment~DocumentFragment `model.DocumentFragment`} by calling
105
+ * {@link module:engine/model/model~Model#getSelectedContent `model#getSelectedContent()`}.
106
+ * 2. Converts the model document fragment to {@link module:engine/view/documentfragment~DocumentFragment `view.DocumentFragment`}.
107
+ * 3. Fires the {@link module:engine/view/document~Document#event:clipboardOutput `view.Document#clipboardOutput`} event
108
+ * with the view document fragment in the `data.content` event field.
109
+ *
110
+ * ## Event: `view.Document#clipboardOutput`
111
+ *
112
+ * 1. Processes `data.content` to HTML and plain text with the
113
+ * {@link module:engine/controller/datacontroller~DataController#htmlProcessor `DataController#htmlProcessor`}.
114
+ * 2. Updates the `data.dataTransfer` data for `text/html` and `text/plain` with the processed data.
115
+ * 3. For the `cut` method, calls {@link module:engine/model/model~Model#deleteContent `model.deleteContent()`}
116
+ * on the current selection.
117
+ *
118
+ * Read more about the clipboard integration in the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
119
+ */
120
+ export default class ClipboardPipeline extends Plugin {
121
+ /**
122
+ * @inheritDoc
123
+ */
124
+ static get pluginName() {
125
+ return 'ClipboardPipeline';
126
+ }
127
+ /**
128
+ * @inheritDoc
129
+ */
130
+ static get isOfficialPlugin() {
131
+ return true;
132
+ }
133
+ /**
134
+ * @inheritDoc
135
+ */
136
+ static get requires() {
137
+ return [ClipboardMarkersUtils];
138
+ }
139
+ /**
140
+ * @inheritDoc
141
+ */
142
+ init() {
143
+ const editor = this.editor;
144
+ const view = editor.editing.view;
145
+ view.addObserver(ClipboardObserver);
146
+ this._setupPasteDrop();
147
+ this._setupCopyCut();
148
+ }
149
+ /**
150
+ * Fires Clipboard `'outputTransformation'` event for given parameters.
151
+ *
152
+ * @internal
153
+ */
154
+ _fireOutputTransformationEvent(dataTransfer, selection, method) {
155
+ const clipboardMarkersUtils = this.editor.plugins.get('ClipboardMarkersUtils');
156
+ this.editor.model.enqueueChange({ isUndoable: method === 'cut' }, () => {
157
+ const documentFragment = clipboardMarkersUtils._copySelectedFragmentWithMarkers(method, selection);
158
+ this.fire('outputTransformation', {
159
+ dataTransfer,
160
+ content: documentFragment,
161
+ method
162
+ });
163
+ });
164
+ }
165
+ /**
166
+ * The clipboard paste pipeline.
167
+ */
168
+ _setupPasteDrop() {
169
+ const editor = this.editor;
170
+ const model = editor.model;
171
+ const view = editor.editing.view;
172
+ const viewDocument = view.document;
173
+ const clipboardMarkersUtils = this.editor.plugins.get('ClipboardMarkersUtils');
174
+ // Pasting is disabled when selection is in non-editable place.
175
+ // Dropping is disabled in drag and drop handler.
176
+ this.listenTo(viewDocument, 'clipboardInput', (evt, data) => {
177
+ if (data.method == 'paste' && !editor.model.canEditAt(editor.model.document.selection)) {
178
+ evt.stop();
179
+ }
180
+ }, { priority: 'highest' });
181
+ this.listenTo(viewDocument, 'clipboardInput', (evt, data) => {
182
+ const dataTransfer = data.dataTransfer;
183
+ let content;
184
+ // Some feature could already inject content in the higher priority event handler (i.e., codeBlock).
185
+ if (data.content) {
186
+ content = data.content;
187
+ }
188
+ else {
189
+ let contentData = '';
190
+ if (dataTransfer.getData('text/html')) {
191
+ contentData = normalizeClipboardHtml(dataTransfer.getData('text/html'));
192
+ }
193
+ else if (dataTransfer.getData('text/plain')) {
194
+ contentData = plainTextToHtml(dataTransfer.getData('text/plain'));
195
+ }
196
+ content = this.editor.data.htmlProcessor.toView(contentData);
197
+ }
198
+ const eventInfo = new EventInfo(this, 'inputTransformation');
199
+ this.fire(eventInfo, {
200
+ content,
201
+ dataTransfer,
202
+ targetRanges: data.targetRanges,
203
+ method: data.method
204
+ });
205
+ // If CKEditor handled the input, do not bubble the original event any further.
206
+ // This helps external integrations recognize this fact and act accordingly.
207
+ // https://github.com/ckeditor/ckeditor5-upload/issues/92
208
+ if (eventInfo.stop.called) {
209
+ evt.stop();
210
+ }
211
+ view.scrollToTheSelection();
212
+ }, { priority: 'low' });
213
+ this.listenTo(this, 'inputTransformation', (evt, data) => {
214
+ if (data.content.isEmpty) {
215
+ return;
216
+ }
217
+ const dataController = this.editor.data;
218
+ // Convert the pasted content into a model document fragment.
219
+ // The conversion is contextual, but in this case an "all allowed" context is needed
220
+ // and for that we use the $clipboardHolder item.
221
+ const modelFragment = dataController.toModel(data.content, '$clipboardHolder');
222
+ if (modelFragment.childCount == 0) {
223
+ return;
224
+ }
225
+ evt.stop();
226
+ // Fire content insertion event in a single change block to allow other handlers to run in the same block
227
+ // without post-fixers called in between (i.e., the selection post-fixer).
228
+ model.change(() => {
229
+ this.fire('contentInsertion', {
230
+ content: modelFragment,
231
+ method: data.method,
232
+ dataTransfer: data.dataTransfer,
233
+ targetRanges: data.targetRanges
234
+ });
235
+ });
236
+ }, { priority: 'low' });
237
+ this.listenTo(this, 'contentInsertion', (evt, data) => {
238
+ data.resultRange = clipboardMarkersUtils._pasteFragmentWithMarkers(data.content);
239
+ }, { priority: 'low' });
240
+ }
241
+ /**
242
+ * The clipboard copy/cut pipeline.
243
+ */
244
+ _setupCopyCut() {
245
+ const editor = this.editor;
246
+ const modelDocument = editor.model.document;
247
+ const view = editor.editing.view;
248
+ const viewDocument = view.document;
249
+ const onCopyCut = (evt, data) => {
250
+ const dataTransfer = data.dataTransfer;
251
+ data.preventDefault();
252
+ this._fireOutputTransformationEvent(dataTransfer, modelDocument.selection, evt.name);
253
+ };
254
+ this.listenTo(viewDocument, 'copy', onCopyCut, { priority: 'low' });
255
+ this.listenTo(viewDocument, 'cut', (evt, data) => {
256
+ // Cutting is disabled when selection is in non-editable place.
257
+ // See: https://github.com/ckeditor/ckeditor5-clipboard/issues/26.
258
+ if (!editor.model.canEditAt(editor.model.document.selection)) {
259
+ data.preventDefault();
260
+ }
261
+ else {
262
+ onCopyCut(evt, data);
263
+ }
264
+ }, { priority: 'low' });
265
+ this.listenTo(this, 'outputTransformation', (evt, data) => {
266
+ const content = editor.data.toView(data.content);
267
+ viewDocument.fire('clipboardOutput', {
268
+ dataTransfer: data.dataTransfer,
269
+ content,
270
+ method: data.method
271
+ });
272
+ }, { priority: 'low' });
273
+ this.listenTo(viewDocument, 'clipboardOutput', (evt, data) => {
274
+ if (!data.content.isEmpty) {
275
+ data.dataTransfer.setData('text/html', this.editor.data.htmlProcessor.toData(data.content));
276
+ data.dataTransfer.setData('text/plain', viewToPlainText(data.content));
277
+ }
278
+ if (data.method == 'cut') {
279
+ editor.model.deleteContent(modelDocument.selection);
280
+ }
281
+ }, { priority: 'low' });
282
+ }
283
+ }
@@ -0,0 +1,106 @@
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
+ * @module clipboard/dragdrop
7
+ */
8
+ import { Plugin } from '@ckeditor/ckeditor5-core';
9
+ import { Widget } from '@ckeditor/ckeditor5-widget';
10
+ import ClipboardPipeline from './clipboardpipeline.js';
11
+ import DragDropTarget from './dragdroptarget.js';
12
+ import DragDropBlockToolbar from './dragdropblocktoolbar.js';
13
+ import '../theme/clipboard.css';
14
+ /**
15
+ * The drag and drop feature. It works on top of the {@link module:clipboard/clipboardpipeline~ClipboardPipeline}.
16
+ *
17
+ * Read more about the clipboard integration in the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
18
+ *
19
+ * @internal
20
+ */
21
+ export default class DragDrop extends Plugin {
22
+ /**
23
+ * The live range over the original content that is being dragged.
24
+ */
25
+ private _draggedRange;
26
+ /**
27
+ * The UID of current dragging that is used to verify if the drop started in the same editor as the drag start.
28
+ *
29
+ * **Note**: This is a workaround for broken 'dragend' events (they are not fired if the source text node got removed).
30
+ */
31
+ private _draggingUid;
32
+ /**
33
+ * The reference to the model element that currently has a `draggable` attribute set (it is set while dragging).
34
+ */
35
+ private _draggableElement;
36
+ /**
37
+ * A delayed callback removing draggable attributes.
38
+ */
39
+ private _clearDraggableAttributesDelayed;
40
+ /**
41
+ * Whether the dragged content can be dropped only in block context.
42
+ */
43
+ private _blockMode;
44
+ /**
45
+ * DOM Emitter.
46
+ */
47
+ private _domEmitter;
48
+ /**
49
+ * The DOM element used to generate dragged preview image.
50
+ */
51
+ private _previewContainer?;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ static get pluginName(): "DragDrop";
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ static get isOfficialPlugin(): true;
60
+ /**
61
+ * @inheritDoc
62
+ */
63
+ static get requires(): readonly [typeof ClipboardPipeline, typeof Widget, typeof DragDropTarget, typeof DragDropBlockToolbar];
64
+ /**
65
+ * @inheritDoc
66
+ */
67
+ init(): void;
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ destroy(): void;
72
+ /**
73
+ * Drag and drop events handling.
74
+ */
75
+ private _setupDragging;
76
+ /**
77
+ * Integration with the `clipboardInput` event.
78
+ */
79
+ private _setupClipboardInputIntegration;
80
+ /**
81
+ * Integration with the `contentInsertion` event of the clipboard pipeline.
82
+ */
83
+ private _setupContentInsertionIntegration;
84
+ /**
85
+ * Adds listeners that add the `draggable` attribute to the elements while the mouse button is down so the dragging could start.
86
+ */
87
+ private _setupDraggableAttributeHandling;
88
+ /**
89
+ * Removes the `draggable` attribute from the element that was used for dragging.
90
+ */
91
+ private _clearDraggableAttributes;
92
+ /**
93
+ * Deletes the dragged content from its original range and clears the dragging state.
94
+ *
95
+ * @param moved Whether the move succeeded.
96
+ */
97
+ private _finalizeDragging;
98
+ /**
99
+ * Sets the dragged source range based on event target and document selection.
100
+ */
101
+ private _prepareDraggedRange;
102
+ /**
103
+ * Updates the dragged preview image.
104
+ */
105
+ private _updatePreview;
106
+ }