@ckeditor/ckeditor5-clipboard 48.1.1 → 48.2.0-alpha.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/dist/clipboardobserver.d.ts +7 -2
- package/dist/clipboardpipeline.d.ts +4 -0
- package/dist/index.js +41 -43
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -93,9 +93,14 @@ export interface ClipboardInputEventData {
|
|
|
93
93
|
*/
|
|
94
94
|
targetRanges: Array<ViewRange> | null;
|
|
95
95
|
/**
|
|
96
|
-
* The content of clipboard input.
|
|
96
|
+
* The content of clipboard input. Defaults to `text/html`. Falls-back to `text/plain`.
|
|
97
97
|
*/
|
|
98
|
-
content
|
|
98
|
+
content: string | ViewDocumentFragment;
|
|
99
|
+
/**
|
|
100
|
+
* Custom data stored by the `clipboardInput` event handlers. Custom properties of this object can be defined and use to
|
|
101
|
+
* pass parameters between listeners. Content of this property is passed to the `inputTransformation` event.
|
|
102
|
+
*/
|
|
103
|
+
extraContent?: unknown;
|
|
99
104
|
}
|
|
100
105
|
/**
|
|
101
106
|
* Fired when the user drags the content over one of the editing roots of the editor.
|
|
@@ -133,6 +133,10 @@ export interface ClipboardInputTransformationData {
|
|
|
133
133
|
* the {@glink framework/deep-dive/clipboard clipboard deep-dive} guide.
|
|
134
134
|
*/
|
|
135
135
|
content: ViewDocumentFragment;
|
|
136
|
+
/**
|
|
137
|
+
* Custom data stored by the `clipboardInput` event handlers. Content of this property is passed from the `clipboardInput` event.
|
|
138
|
+
*/
|
|
139
|
+
extraContent?: unknown;
|
|
136
140
|
/**
|
|
137
141
|
* The data transfer instance.
|
|
138
142
|
*/
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,34 @@ import { mapValues, throttle } from 'es-toolkit/compat';
|
|
|
9
9
|
import { Widget, isWidget } from '@ckeditor/ckeditor5-widget/dist/index.js';
|
|
10
10
|
import { View } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
14
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
15
|
+
*/ /**
|
|
16
|
+
* @module clipboard/utils/plaintexttohtml
|
|
17
|
+
*/ /**
|
|
18
|
+
* Converts plain text to its HTML-ized version.
|
|
19
|
+
*
|
|
20
|
+
* @param text The plain text to convert.
|
|
21
|
+
* @returns HTML generated from the plain text.
|
|
22
|
+
*/ function plainTextToHtml(text) {
|
|
23
|
+
text = text// Encode &.
|
|
24
|
+
.replace(/&/g, '&')// Encode <>.
|
|
25
|
+
.replace(/</g, '<').replace(/>/g, '>')// Creates a paragraph for each double line break.
|
|
26
|
+
.replace(/\r?\n\r?\n/g, '</p><p>')// Creates a line break for each single line break.
|
|
27
|
+
.replace(/\r?\n/g, '<br>')// Replace tabs with four spaces.
|
|
28
|
+
.replace(/\t/g, ' ')// Preserve trailing spaces (only the first and last one – the rest is handled below).
|
|
29
|
+
.replace(/^\s/, ' ').replace(/\s$/, ' ')// Preserve other subsequent spaces now.
|
|
30
|
+
.replace(/\s\s/g, ' ');
|
|
31
|
+
if (text.includes('</p><p>') || text.includes('<br>')) {
|
|
32
|
+
// If we created paragraphs above, add the trailing ones.
|
|
33
|
+
text = `<p>${text}</p>`;
|
|
34
|
+
}
|
|
35
|
+
// TODO:
|
|
36
|
+
// * What about '\nfoo' vs ' foo'?
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
|
|
12
40
|
/**
|
|
13
41
|
* Clipboard events observer.
|
|
14
42
|
*
|
|
@@ -60,9 +88,17 @@ import { View } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
|
60
88
|
const targetRanges = data.dropRange ? [
|
|
61
89
|
data.dropRange
|
|
62
90
|
] : null;
|
|
91
|
+
const dataTransfer = data.dataTransfer;
|
|
63
92
|
const eventInfo = new EventInfo(viewDocument, type);
|
|
93
|
+
let content = '';
|
|
94
|
+
if (dataTransfer.getData('text/html')) {
|
|
95
|
+
content = dataTransfer.getData('text/html');
|
|
96
|
+
} else if (dataTransfer.getData('text/plain')) {
|
|
97
|
+
content = plainTextToHtml(dataTransfer.getData('text/plain'));
|
|
98
|
+
}
|
|
64
99
|
viewDocument.fire(eventInfo, {
|
|
65
|
-
dataTransfer
|
|
100
|
+
dataTransfer,
|
|
101
|
+
content,
|
|
66
102
|
method: evt.name,
|
|
67
103
|
targetRanges,
|
|
68
104
|
target: data.target,
|
|
@@ -93,34 +129,6 @@ import { View } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
|
93
129
|
}
|
|
94
130
|
}
|
|
95
131
|
|
|
96
|
-
/**
|
|
97
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
98
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
99
|
-
*/ /**
|
|
100
|
-
* @module clipboard/utils/plaintexttohtml
|
|
101
|
-
*/ /**
|
|
102
|
-
* Converts plain text to its HTML-ized version.
|
|
103
|
-
*
|
|
104
|
-
* @param text The plain text to convert.
|
|
105
|
-
* @returns HTML generated from the plain text.
|
|
106
|
-
*/ function plainTextToHtml(text) {
|
|
107
|
-
text = text// Encode &.
|
|
108
|
-
.replace(/&/g, '&')// Encode <>.
|
|
109
|
-
.replace(/</g, '<').replace(/>/g, '>')// Creates a paragraph for each double line break.
|
|
110
|
-
.replace(/\r?\n\r?\n/g, '</p><p>')// Creates a line break for each single line break.
|
|
111
|
-
.replace(/\r?\n/g, '<br>')// Replace tabs with four spaces.
|
|
112
|
-
.replace(/\t/g, ' ')// Preserve trailing spaces (only the first and last one – the rest is handled below).
|
|
113
|
-
.replace(/^\s/, ' ').replace(/\s$/, ' ')// Preserve other subsequent spaces now.
|
|
114
|
-
.replace(/\s\s/g, ' ');
|
|
115
|
-
if (text.includes('</p><p>') || text.includes('<br>')) {
|
|
116
|
-
// If we created paragraphs above, add the trailing ones.
|
|
117
|
-
text = `<p>${text}</p>`;
|
|
118
|
-
}
|
|
119
|
-
// TODO:
|
|
120
|
-
// * What about '\nfoo' vs ' foo'?
|
|
121
|
-
return text;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
132
|
/**
|
|
125
133
|
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
126
134
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
@@ -175,7 +183,7 @@ const listElements = [
|
|
|
175
183
|
return viewItem.getAttribute('alt');
|
|
176
184
|
}
|
|
177
185
|
if (viewItem.is('element', 'br')) {
|
|
178
|
-
return '\n'; // Convert soft breaks to single line break (
|
|
186
|
+
return '\n'; // Convert soft breaks to single line break (https://github.com/ckeditor/ckeditor5/issues/8045).
|
|
179
187
|
}
|
|
180
188
|
/**
|
|
181
189
|
* Item is a document fragment, attribute element or container element. It doesn't
|
|
@@ -880,25 +888,15 @@ const listElements = [
|
|
|
880
888
|
});
|
|
881
889
|
this.listenTo(viewDocument, 'clipboardInput', (evt, data)=>{
|
|
882
890
|
const dataTransfer = data.dataTransfer;
|
|
883
|
-
let content;
|
|
884
|
-
// Some feature could already inject content in the higher priority event handler (i.e., codeBlock).
|
|
885
|
-
if (data.content) {
|
|
886
|
-
content = data.content;
|
|
887
|
-
} else {
|
|
888
|
-
let contentData = '';
|
|
889
|
-
if (dataTransfer.getData('text/html')) {
|
|
890
|
-
contentData = normalizeClipboardData(dataTransfer.getData('text/html'));
|
|
891
|
-
} else if (dataTransfer.getData('text/plain')) {
|
|
892
|
-
contentData = plainTextToHtml(dataTransfer.getData('text/plain'));
|
|
893
|
-
}
|
|
894
|
-
content = this.editor.data.htmlProcessor.toView(contentData);
|
|
895
|
-
}
|
|
896
891
|
const eventInfo = new EventInfo(this, 'inputTransformation');
|
|
897
892
|
const sourceEditorId = dataTransfer.getData('application/ckeditor5-editor-id') || null;
|
|
893
|
+
// Some feature could already inject content in the higher priority event handler (i.e., codeBlock, paste from office).
|
|
894
|
+
const content = typeof data.content == 'string' ? this.editor.data.htmlProcessor.toView(normalizeClipboardData(data.content)) : data.content;
|
|
898
895
|
this.fire(eventInfo, {
|
|
899
896
|
content,
|
|
900
897
|
dataTransfer,
|
|
901
898
|
sourceEditorId,
|
|
899
|
+
extraContent: data.extraContent,
|
|
902
900
|
targetRanges: data.targetRanges,
|
|
903
901
|
method: data.method
|
|
904
902
|
});
|