@ckeditor/ckeditor5-clipboard 39.0.2 → 40.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +3 -3
- package/package.json +6 -6
- package/src/augmentation.d.ts +1 -2
- package/src/clipboardpipeline.d.ts +40 -1
- package/src/clipboardpipeline.js +28 -7
- package/src/dragdrop.d.ts +22 -20
- package/src/dragdrop.js +180 -258
- package/src/dragdropblocktoolbar.d.ts +1 -1
- package/src/dragdropblocktoolbar.js +13 -6
- package/src/dragdroptarget.d.ts +3 -3
- package/src/dragdroptarget.js +30 -19
- package/src/index.d.ts +1 -2
- package/src/index.js +0 -1
- package/src/utils/plaintexttohtml.js +2 -0
- package/src/utils/viewtoplaintext.js +48 -31
- package/src/dragdropexperimental.d.ts +0 -101
- package/src/dragdropexperimental.js +0 -522
package/LICENSE.md
CHANGED
|
@@ -2,7 +2,7 @@ Software License Agreement
|
|
|
2
2
|
==========================
|
|
3
3
|
|
|
4
4
|
**CKEditor 5 clipboard feature** – https://github.com/ckeditor/ckeditor5-clipboard <br>
|
|
5
|
-
Copyright (c) 2003
|
|
5
|
+
Copyright (c) 2003–2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
|
|
6
6
|
|
|
7
7
|
Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
|
|
8
8
|
|
|
@@ -13,9 +13,9 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
|
|
|
13
13
|
|
|
14
14
|
The following libraries are included in CKEditor under the [MIT license](https://opensource.org/licenses/MIT):
|
|
15
15
|
|
|
16
|
-
*
|
|
16
|
+
* Lodash - Copyright (c) JS Foundation and other contributors https://js.foundation/. Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors http://underscorejs.org/.
|
|
17
17
|
|
|
18
18
|
Trademarks
|
|
19
19
|
----------
|
|
20
20
|
|
|
21
|
-
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
|
|
21
|
+
**CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckeditor/ckeditor5-clipboard",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "40.1.0",
|
|
4
4
|
"description": "Clipboard integration feature for CKEditor 5.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ckeditor",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
],
|
|
13
13
|
"main": "src/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@ckeditor/ckeditor5-core": "
|
|
16
|
-
"@ckeditor/ckeditor5-engine": "
|
|
17
|
-
"@ckeditor/ckeditor5-ui": "
|
|
18
|
-
"@ckeditor/ckeditor5-utils": "
|
|
19
|
-
"@ckeditor/ckeditor5-widget": "
|
|
15
|
+
"@ckeditor/ckeditor5-core": "40.1.0",
|
|
16
|
+
"@ckeditor/ckeditor5-engine": "40.1.0",
|
|
17
|
+
"@ckeditor/ckeditor5-ui": "40.1.0",
|
|
18
|
+
"@ckeditor/ckeditor5-utils": "40.1.0",
|
|
19
|
+
"@ckeditor/ckeditor5-widget": "40.1.0",
|
|
20
20
|
"lodash-es": "4.17.21"
|
|
21
21
|
},
|
|
22
22
|
"author": "CKSource (http://cksource.com/)",
|
package/src/augmentation.d.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
import type { Clipboard, ClipboardPipeline, PastePlainText, DragDrop,
|
|
5
|
+
import type { Clipboard, ClipboardPipeline, PastePlainText, DragDrop, DragDropTarget, DragDropBlockToolbar } from './index';
|
|
6
6
|
declare module '@ckeditor/ckeditor5-core' {
|
|
7
7
|
interface PluginsMap {
|
|
8
8
|
[Clipboard.pluginName]: Clipboard;
|
|
9
9
|
[ClipboardPipeline.pluginName]: ClipboardPipeline;
|
|
10
10
|
[PastePlainText.pluginName]: PastePlainText;
|
|
11
11
|
[DragDrop.pluginName]: DragDrop;
|
|
12
|
-
[DragDropExperimental.pluginName]: DragDropExperimental;
|
|
13
12
|
[DragDropTarget.pluginName]: DragDropTarget;
|
|
14
13
|
[DragDropBlockToolbar.pluginName]: DragDropBlockToolbar;
|
|
15
14
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module clipboard/clipboardpipeline
|
|
7
7
|
*/
|
|
8
8
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import type { DataTransfer, DocumentFragment, Range, ViewDocumentFragment, ViewRange } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
import type { DataTransfer, DocumentFragment, Range, ViewDocumentFragment, ViewRange, Selection, DocumentSelection } from '@ckeditor/ckeditor5-engine';
|
|
10
10
|
/**
|
|
11
11
|
* The clipboard pipeline feature. It is responsible for intercepting the `paste` and `drop` events and
|
|
12
12
|
* passing the pasted content through a series of events in order to insert it into the editor's content.
|
|
@@ -77,6 +77,12 @@ export default class ClipboardPipeline extends Plugin {
|
|
|
77
77
|
* @inheritDoc
|
|
78
78
|
*/
|
|
79
79
|
init(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Fires Clipboard `'outputTransformation'` event for given parameters.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
_fireOutputTransformationEvent(dataTransfer: DataTransfer, selection: Selection | DocumentSelection, method: 'copy' | 'cut' | 'dragstart'): void;
|
|
80
86
|
/**
|
|
81
87
|
* The clipboard paste pipeline.
|
|
82
88
|
*/
|
|
@@ -219,3 +225,36 @@ export interface ViewDocumentClipboardOutputEventData {
|
|
|
219
225
|
*/
|
|
220
226
|
method: 'copy' | 'cut' | 'dragstart';
|
|
221
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Fired on {@link module:engine/view/document~Document#event:copy}, {@link module:engine/view/document~Document#event:cut}
|
|
230
|
+
* and {@link module:engine/view/document~Document#event:dragstart}. The content can be processed before it ends up in the clipboard.
|
|
231
|
+
*
|
|
232
|
+
* It is a part of the {@glink framework/deep-dive/clipboard#output-pipeline clipboard output pipeline}.
|
|
233
|
+
*
|
|
234
|
+
* @eventName ~ClipboardPipeline#outputTransformation
|
|
235
|
+
* @param data The event data.
|
|
236
|
+
*/
|
|
237
|
+
export type ClipboardOutputTransformationEvent = {
|
|
238
|
+
name: 'outputTransformation';
|
|
239
|
+
args: [data: ClipboardOutputTransformationData];
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* The value of the 'outputTransformation' event.
|
|
243
|
+
*/
|
|
244
|
+
export interface ClipboardOutputTransformationData {
|
|
245
|
+
/**
|
|
246
|
+
* The data transfer instance.
|
|
247
|
+
*
|
|
248
|
+
* @readonly
|
|
249
|
+
*/
|
|
250
|
+
dataTransfer: DataTransfer;
|
|
251
|
+
/**
|
|
252
|
+
* Content to be put into the clipboard. It can be modified by the event listeners.
|
|
253
|
+
* Read more about the clipboard pipelines in the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
|
|
254
|
+
*/
|
|
255
|
+
content: DocumentFragment;
|
|
256
|
+
/**
|
|
257
|
+
* Whether the event was triggered by a copy or cut operation.
|
|
258
|
+
*/
|
|
259
|
+
method: 'copy' | 'cut' | 'dragstart';
|
|
260
|
+
}
|
package/src/clipboardpipeline.js
CHANGED
|
@@ -40,11 +40,16 @@ import viewToPlainText from './utils/viewtoplaintext';
|
|
|
40
40
|
//
|
|
41
41
|
// ┌──────────────────────┐ ┌──────────────────────┐
|
|
42
42
|
// │ view.Document │ │ view.Document │ Retrieves the selected model.DocumentFragment
|
|
43
|
-
// │ copy │ │ cut │ and
|
|
43
|
+
// │ copy │ │ cut │ and fires the `outputTransformation` event.
|
|
44
44
|
// └───────────┬──────────┘ └───────────┬──────────┘
|
|
45
45
|
// │ │
|
|
46
46
|
// └────────────────┌────────────────┘
|
|
47
47
|
// │
|
|
48
|
+
// ┌───────────V───────────┐
|
|
49
|
+
// │ ClipboardPipeline │ Processes model.DocumentFragment and converts it to
|
|
50
|
+
// │ outputTransformation │ view.DocumentFragment.
|
|
51
|
+
// └───────────┬───────────┘
|
|
52
|
+
// │
|
|
48
53
|
// ┌─────────V────────┐
|
|
49
54
|
// │ view.Document │ Processes view.DocumentFragment to text/html and text/plain
|
|
50
55
|
// │ clipboardOutput │ and stores the results in data.dataTransfer.
|
|
@@ -128,6 +133,19 @@ export default class ClipboardPipeline extends Plugin {
|
|
|
128
133
|
this._setupPasteDrop();
|
|
129
134
|
this._setupCopyCut();
|
|
130
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Fires Clipboard `'outputTransformation'` event for given parameters.
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
_fireOutputTransformationEvent(dataTransfer, selection, method) {
|
|
142
|
+
const content = this.editor.model.getSelectedContent(selection);
|
|
143
|
+
this.fire('outputTransformation', {
|
|
144
|
+
dataTransfer,
|
|
145
|
+
content,
|
|
146
|
+
method
|
|
147
|
+
});
|
|
148
|
+
}
|
|
131
149
|
/**
|
|
132
150
|
* The clipboard paste pipeline.
|
|
133
151
|
*/
|
|
@@ -214,12 +232,7 @@ export default class ClipboardPipeline extends Plugin {
|
|
|
214
232
|
const onCopyCut = (evt, data) => {
|
|
215
233
|
const dataTransfer = data.dataTransfer;
|
|
216
234
|
data.preventDefault();
|
|
217
|
-
|
|
218
|
-
viewDocument.fire('clipboardOutput', {
|
|
219
|
-
dataTransfer,
|
|
220
|
-
content,
|
|
221
|
-
method: evt.name
|
|
222
|
-
});
|
|
235
|
+
this._fireOutputTransformationEvent(dataTransfer, modelDocument.selection, evt.name);
|
|
223
236
|
};
|
|
224
237
|
this.listenTo(viewDocument, 'copy', onCopyCut, { priority: 'low' });
|
|
225
238
|
this.listenTo(viewDocument, 'cut', (evt, data) => {
|
|
@@ -232,6 +245,14 @@ export default class ClipboardPipeline extends Plugin {
|
|
|
232
245
|
onCopyCut(evt, data);
|
|
233
246
|
}
|
|
234
247
|
}, { priority: 'low' });
|
|
248
|
+
this.listenTo(this, 'outputTransformation', (evt, data) => {
|
|
249
|
+
const content = editor.data.toView(data.content);
|
|
250
|
+
viewDocument.fire('clipboardOutput', {
|
|
251
|
+
dataTransfer: data.dataTransfer,
|
|
252
|
+
content,
|
|
253
|
+
method: data.method
|
|
254
|
+
});
|
|
255
|
+
}, { priority: 'low' });
|
|
235
256
|
this.listenTo(viewDocument, 'clipboardOutput', (evt, data) => {
|
|
236
257
|
if (!data.content.isEmpty) {
|
|
237
258
|
data.dataTransfer.setData('text/html', this.editor.data.htmlProcessor.toData(data.content));
|
package/src/dragdrop.d.ts
CHANGED
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
9
|
import { Widget } from '@ckeditor/ckeditor5-widget';
|
|
10
10
|
import ClipboardPipeline from './clipboardpipeline';
|
|
11
|
+
import DragDropTarget from './dragdroptarget';
|
|
12
|
+
import DragDropBlockToolbar from './dragdropblocktoolbar';
|
|
11
13
|
import '../theme/clipboard.css';
|
|
12
14
|
/**
|
|
13
15
|
* The drag and drop feature. It works on top of the {@link module:clipboard/clipboardpipeline~ClipboardPipeline}.
|
|
14
16
|
*
|
|
15
17
|
* Read more about the clipboard integration in the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
16
20
|
*/
|
|
17
21
|
export default class DragDrop extends Plugin {
|
|
18
22
|
/**
|
|
@@ -30,17 +34,21 @@ export default class DragDrop extends Plugin {
|
|
|
30
34
|
*/
|
|
31
35
|
private _draggableElement;
|
|
32
36
|
/**
|
|
33
|
-
* A
|
|
37
|
+
* A delayed callback removing draggable attributes.
|
|
34
38
|
*/
|
|
35
|
-
private
|
|
39
|
+
private _clearDraggableAttributesDelayed;
|
|
36
40
|
/**
|
|
37
|
-
*
|
|
41
|
+
* Whether the dragged content can be dropped only in block context.
|
|
38
42
|
*/
|
|
39
|
-
private
|
|
43
|
+
private _blockMode;
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
45
|
+
* DOM Emitter.
|
|
42
46
|
*/
|
|
43
|
-
private
|
|
47
|
+
private _domEmitter;
|
|
48
|
+
/**
|
|
49
|
+
* The DOM element used to generate dragged preview image.
|
|
50
|
+
*/
|
|
51
|
+
private _previewContainer?;
|
|
44
52
|
/**
|
|
45
53
|
* @inheritDoc
|
|
46
54
|
*/
|
|
@@ -48,7 +56,7 @@ export default class DragDrop extends Plugin {
|
|
|
48
56
|
/**
|
|
49
57
|
* @inheritDoc
|
|
50
58
|
*/
|
|
51
|
-
static get requires(): readonly [typeof ClipboardPipeline, typeof Widget];
|
|
59
|
+
static get requires(): readonly [typeof ClipboardPipeline, typeof Widget, typeof DragDropTarget, typeof DragDropBlockToolbar];
|
|
52
60
|
/**
|
|
53
61
|
* @inheritDoc
|
|
54
62
|
*/
|
|
@@ -78,23 +86,17 @@ export default class DragDrop extends Plugin {
|
|
|
78
86
|
*/
|
|
79
87
|
private _clearDraggableAttributes;
|
|
80
88
|
/**
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
private _setupDropMarker;
|
|
84
|
-
/**
|
|
85
|
-
* Updates the drop target marker to the provided range.
|
|
89
|
+
* Deletes the dragged content from its original range and clears the dragging state.
|
|
86
90
|
*
|
|
87
|
-
* @param
|
|
91
|
+
* @param moved Whether the move succeeded.
|
|
88
92
|
*/
|
|
89
|
-
private
|
|
93
|
+
private _finalizeDragging;
|
|
90
94
|
/**
|
|
91
|
-
*
|
|
95
|
+
* Sets the dragged source range based on event target and document selection.
|
|
92
96
|
*/
|
|
93
|
-
private
|
|
97
|
+
private _prepareDraggedRange;
|
|
94
98
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param moved Whether the move succeeded.
|
|
99
|
+
* Updates the dragged preview image.
|
|
98
100
|
*/
|
|
99
|
-
private
|
|
101
|
+
private _updatePreview;
|
|
100
102
|
}
|