@ckeditor/ckeditor5-clipboard 38.1.1 → 38.2.0-alpha.1
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/package.json +7 -6
- package/src/augmentation.d.ts +16 -16
- package/src/augmentation.js +5 -5
- package/src/clipboard.d.ts +31 -31
- package/src/clipboard.js +35 -35
- package/src/clipboardobserver.d.ts +312 -312
- package/src/clipboardobserver.js +94 -94
- package/src/clipboardpipeline.d.ts +221 -221
- package/src/clipboardpipeline.js +245 -245
- package/src/dragdrop.d.ts +100 -100
- package/src/dragdrop.js +655 -655
- package/src/dragdropblocktoolbar.d.ts +47 -47
- package/src/dragdropblocktoolbar.js +114 -114
- package/src/dragdropexperimental.d.ts +101 -101
- package/src/dragdropexperimental.js +522 -522
- package/src/dragdroptarget.d.ts +94 -94
- package/src/dragdroptarget.js +362 -362
- package/src/index.d.ts +17 -17
- package/src/index.js +15 -15
- package/src/lineview.d.ts +45 -45
- package/src/lineview.js +44 -44
- package/src/pasteplaintext.d.ts +28 -28
- package/src/pasteplaintext.js +82 -82
- package/src/utils/normalizeclipboarddata.d.ts +15 -15
- package/src/utils/normalizeclipboarddata.js +27 -27
- package/src/utils/plaintexttohtml.d.ts +14 -14
- package/src/utils/plaintexttohtml.js +37 -37
- package/src/utils/viewtoplaintext.d.ts +15 -15
- package/src/utils/viewtoplaintext.js +50 -50
package/src/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
|
7
|
-
*/
|
|
8
|
-
export { default as Clipboard } from './clipboard';
|
|
9
|
-
export { default as ClipboardPipeline, type ClipboardContentInsertionEvent, type ClipboardInputTransformationEvent, type ClipboardInputTransformationData, type ViewDocumentClipboardOutputEvent } from './clipboardpipeline';
|
|
10
|
-
export type { ClipboardEventData } from './clipboardobserver';
|
|
11
|
-
export { default as DragDrop } from './dragdrop';
|
|
12
|
-
export { default as PastePlainText } from './pasteplaintext';
|
|
13
|
-
export { default as DragDropExperimental } from './dragdropexperimental';
|
|
14
|
-
export { default as DragDropTarget } from './dragdroptarget';
|
|
15
|
-
export { default as DragDropBlockToolbar } from './dragdropblocktoolbar';
|
|
16
|
-
export type { ViewDocumentClipboardInputEvent, ViewDocumentCopyEvent, ViewDocumentCutEvent } from './clipboardobserver';
|
|
17
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
|
7
|
+
*/
|
|
8
|
+
export { default as Clipboard } from './clipboard.js';
|
|
9
|
+
export { default as ClipboardPipeline, type ClipboardContentInsertionEvent, type ClipboardInputTransformationEvent, type ClipboardInputTransformationData, type ViewDocumentClipboardOutputEvent } from './clipboardpipeline.js';
|
|
10
|
+
export type { ClipboardEventData } from './clipboardobserver.js';
|
|
11
|
+
export { default as DragDrop } from './dragdrop.js';
|
|
12
|
+
export { default as PastePlainText } from './pasteplaintext.js';
|
|
13
|
+
export { default as DragDropExperimental } from './dragdropexperimental.js';
|
|
14
|
+
export { default as DragDropTarget } from './dragdroptarget.js';
|
|
15
|
+
export { default as DragDropBlockToolbar } from './dragdropblocktoolbar.js';
|
|
16
|
+
export type { ViewDocumentClipboardInputEvent, ViewDocumentCopyEvent, ViewDocumentCutEvent } from './clipboardobserver.js';
|
|
17
|
+
import './augmentation.js';
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
|
7
|
-
*/
|
|
8
|
-
export { default as Clipboard } from './clipboard';
|
|
9
|
-
export { default as ClipboardPipeline } from './clipboardpipeline';
|
|
10
|
-
export { default as DragDrop } from './dragdrop';
|
|
11
|
-
export { default as PastePlainText } from './pasteplaintext';
|
|
12
|
-
export { default as DragDropExperimental } from './dragdropexperimental';
|
|
13
|
-
export { default as DragDropTarget } from './dragdroptarget';
|
|
14
|
-
export { default as DragDropBlockToolbar } from './dragdropblocktoolbar';
|
|
15
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
|
7
|
+
*/
|
|
8
|
+
export { default as Clipboard } from './clipboard.js';
|
|
9
|
+
export { default as ClipboardPipeline } from './clipboardpipeline.js';
|
|
10
|
+
export { default as DragDrop } from './dragdrop.js';
|
|
11
|
+
export { default as PastePlainText } from './pasteplaintext.js';
|
|
12
|
+
export { default as DragDropExperimental } from './dragdropexperimental.js';
|
|
13
|
+
export { default as DragDropTarget } from './dragdroptarget.js';
|
|
14
|
+
export { default as DragDropBlockToolbar } from './dragdropblocktoolbar.js';
|
|
15
|
+
import './augmentation.js';
|
package/src/lineview.d.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/lineview
|
|
7
|
-
*/
|
|
8
|
-
import { View } from '@ckeditor/ckeditor5-ui';
|
|
9
|
-
/**
|
|
10
|
-
* The horizontal drop target line view.
|
|
11
|
-
*/
|
|
12
|
-
export default class LineView extends View {
|
|
13
|
-
/**
|
|
14
|
-
* Controls whether the line is visible.
|
|
15
|
-
*
|
|
16
|
-
* @observable
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
isVisible: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Controls the line position x coordinate.
|
|
22
|
-
*
|
|
23
|
-
* @observable
|
|
24
|
-
* @default null
|
|
25
|
-
*/
|
|
26
|
-
left: number | null;
|
|
27
|
-
/**
|
|
28
|
-
* Controls the line width.
|
|
29
|
-
*
|
|
30
|
-
* @observable
|
|
31
|
-
* @default null
|
|
32
|
-
*/
|
|
33
|
-
width: number | null;
|
|
34
|
-
/**
|
|
35
|
-
* Controls the line position y coordinate.
|
|
36
|
-
*
|
|
37
|
-
* @observable
|
|
38
|
-
* @default null
|
|
39
|
-
*/
|
|
40
|
-
top: number | null;
|
|
41
|
-
/**
|
|
42
|
-
* @inheritDoc
|
|
43
|
-
*/
|
|
44
|
-
constructor();
|
|
45
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/lineview
|
|
7
|
+
*/
|
|
8
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
|
9
|
+
/**
|
|
10
|
+
* The horizontal drop target line view.
|
|
11
|
+
*/
|
|
12
|
+
export default class LineView extends View {
|
|
13
|
+
/**
|
|
14
|
+
* Controls whether the line is visible.
|
|
15
|
+
*
|
|
16
|
+
* @observable
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
isVisible: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Controls the line position x coordinate.
|
|
22
|
+
*
|
|
23
|
+
* @observable
|
|
24
|
+
* @default null
|
|
25
|
+
*/
|
|
26
|
+
left: number | null;
|
|
27
|
+
/**
|
|
28
|
+
* Controls the line width.
|
|
29
|
+
*
|
|
30
|
+
* @observable
|
|
31
|
+
* @default null
|
|
32
|
+
*/
|
|
33
|
+
width: number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Controls the line position y coordinate.
|
|
36
|
+
*
|
|
37
|
+
* @observable
|
|
38
|
+
* @default null
|
|
39
|
+
*/
|
|
40
|
+
top: number | null;
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
constructor();
|
|
45
|
+
}
|
package/src/lineview.js
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/lineview
|
|
7
|
-
*/
|
|
8
|
-
/* istanbul ignore file -- @preserve */
|
|
9
|
-
import { View } from '@ckeditor/ckeditor5-ui';
|
|
10
|
-
import { toUnit } from '@ckeditor/ckeditor5-utils';
|
|
11
|
-
const toPx = toUnit('px');
|
|
12
|
-
/**
|
|
13
|
-
* The horizontal drop target line view.
|
|
14
|
-
*/
|
|
15
|
-
export default class LineView extends View {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
constructor() {
|
|
20
|
-
super();
|
|
21
|
-
const bind = this.bindTemplate;
|
|
22
|
-
this.set({
|
|
23
|
-
isVisible: false,
|
|
24
|
-
left: null,
|
|
25
|
-
top: null,
|
|
26
|
-
width: null
|
|
27
|
-
});
|
|
28
|
-
this.setTemplate({
|
|
29
|
-
tag: 'div',
|
|
30
|
-
attributes: {
|
|
31
|
-
class: [
|
|
32
|
-
'ck',
|
|
33
|
-
'ck-clipboard-drop-target-line',
|
|
34
|
-
bind.if('isVisible', 'ck-hidden', value => !value)
|
|
35
|
-
],
|
|
36
|
-
style: {
|
|
37
|
-
left: bind.to('left', left => toPx(left)),
|
|
38
|
-
top: bind.to('top', top => toPx(top)),
|
|
39
|
-
width: bind.to('width', width => toPx(width))
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/lineview
|
|
7
|
+
*/
|
|
8
|
+
/* istanbul ignore file -- @preserve */
|
|
9
|
+
import { View } from '@ckeditor/ckeditor5-ui';
|
|
10
|
+
import { toUnit } from '@ckeditor/ckeditor5-utils';
|
|
11
|
+
const toPx = toUnit('px');
|
|
12
|
+
/**
|
|
13
|
+
* The horizontal drop target line view.
|
|
14
|
+
*/
|
|
15
|
+
export default class LineView extends View {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
const bind = this.bindTemplate;
|
|
22
|
+
this.set({
|
|
23
|
+
isVisible: false,
|
|
24
|
+
left: null,
|
|
25
|
+
top: null,
|
|
26
|
+
width: null
|
|
27
|
+
});
|
|
28
|
+
this.setTemplate({
|
|
29
|
+
tag: 'div',
|
|
30
|
+
attributes: {
|
|
31
|
+
class: [
|
|
32
|
+
'ck',
|
|
33
|
+
'ck-clipboard-drop-target-line',
|
|
34
|
+
bind.if('isVisible', 'ck-hidden', value => !value)
|
|
35
|
+
],
|
|
36
|
+
style: {
|
|
37
|
+
left: bind.to('left', left => toPx(left)),
|
|
38
|
+
top: bind.to('top', top => toPx(top)),
|
|
39
|
+
width: bind.to('width', width => toPx(width))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/pasteplaintext.d.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/pasteplaintext
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import ClipboardPipeline from './clipboardpipeline';
|
|
10
|
-
/**
|
|
11
|
-
* The plugin detects the user's intention to paste plain text.
|
|
12
|
-
*
|
|
13
|
-
* For example, it detects the <kbd>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>V</kbd> keystroke.
|
|
14
|
-
*/
|
|
15
|
-
export default class PastePlainText extends Plugin {
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
static get pluginName(): "PastePlainText";
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
static get requires(): readonly [typeof ClipboardPipeline];
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init(): void;
|
|
28
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/pasteplaintext
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import ClipboardPipeline from './clipboardpipeline.js';
|
|
10
|
+
/**
|
|
11
|
+
* The plugin detects the user's intention to paste plain text.
|
|
12
|
+
*
|
|
13
|
+
* For example, it detects the <kbd>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>V</kbd> keystroke.
|
|
14
|
+
*/
|
|
15
|
+
export default class PastePlainText extends Plugin {
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static get pluginName(): "PastePlainText";
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
static get requires(): readonly [typeof ClipboardPipeline];
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init(): void;
|
|
28
|
+
}
|
package/src/pasteplaintext.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/pasteplaintext
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import ClipboardObserver from './clipboardobserver';
|
|
10
|
-
import ClipboardPipeline from './clipboardpipeline';
|
|
11
|
-
/**
|
|
12
|
-
* The plugin detects the user's intention to paste plain text.
|
|
13
|
-
*
|
|
14
|
-
* For example, it detects the <kbd>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>V</kbd> keystroke.
|
|
15
|
-
*/
|
|
16
|
-
export default class PastePlainText extends Plugin {
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
static get pluginName() {
|
|
21
|
-
return 'PastePlainText';
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
static get requires() {
|
|
27
|
-
return [ClipboardPipeline];
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @inheritDoc
|
|
31
|
-
*/
|
|
32
|
-
init() {
|
|
33
|
-
const editor = this.editor;
|
|
34
|
-
const model = editor.model;
|
|
35
|
-
const view = editor.editing.view;
|
|
36
|
-
const viewDocument = view.document;
|
|
37
|
-
const selection = model.document.selection;
|
|
38
|
-
let shiftPressed = false;
|
|
39
|
-
view.addObserver(ClipboardObserver);
|
|
40
|
-
this.listenTo(viewDocument, 'keydown', (evt, data) => {
|
|
41
|
-
shiftPressed = data.shiftKey;
|
|
42
|
-
});
|
|
43
|
-
editor.plugins.get(ClipboardPipeline).on('contentInsertion', (evt, data) => {
|
|
44
|
-
// Plain text can be determined based on the event flag (#7799) or auto-detection (#1006). If detected,
|
|
45
|
-
// preserve selection attributes on pasted items.
|
|
46
|
-
if (!shiftPressed && !isPlainTextFragment(data.content, model.schema)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
model.change(writer => {
|
|
50
|
-
// Formatting attributes should be preserved.
|
|
51
|
-
const textAttributes = Array.from(selection.getAttributes())
|
|
52
|
-
.filter(([key]) => model.schema.getAttributeProperties(key).isFormatting);
|
|
53
|
-
if (!selection.isCollapsed) {
|
|
54
|
-
model.deleteContent(selection, { doNotAutoparagraph: true });
|
|
55
|
-
}
|
|
56
|
-
// Also preserve other attributes if they survived the content deletion (because they were not fully selected).
|
|
57
|
-
// For example linkHref is not a formatting attribute but it should be preserved if pasted text was in the middle
|
|
58
|
-
// of a link.
|
|
59
|
-
textAttributes.push(...selection.getAttributes());
|
|
60
|
-
const range = writer.createRangeIn(data.content);
|
|
61
|
-
for (const item of range.getItems()) {
|
|
62
|
-
if (item.is('$textProxy')) {
|
|
63
|
-
writer.setAttributes(textAttributes, item);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Returns true if specified `documentFragment` represents a plain text.
|
|
72
|
-
*/
|
|
73
|
-
function isPlainTextFragment(documentFragment, schema) {
|
|
74
|
-
if (documentFragment.childCount > 1) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const child = documentFragment.getChild(0);
|
|
78
|
-
if (schema.isObject(child)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return Array.from(child.getAttributeKeys()).length == 0;
|
|
82
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/pasteplaintext
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import ClipboardObserver from './clipboardobserver.js';
|
|
10
|
+
import ClipboardPipeline from './clipboardpipeline.js';
|
|
11
|
+
/**
|
|
12
|
+
* The plugin detects the user's intention to paste plain text.
|
|
13
|
+
*
|
|
14
|
+
* For example, it detects the <kbd>Ctrl/Cmd</kbd> + <kbd>Shift</kbd> + <kbd>V</kbd> keystroke.
|
|
15
|
+
*/
|
|
16
|
+
export default class PastePlainText extends Plugin {
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
static get pluginName() {
|
|
21
|
+
return 'PastePlainText';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get requires() {
|
|
27
|
+
return [ClipboardPipeline];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
init() {
|
|
33
|
+
const editor = this.editor;
|
|
34
|
+
const model = editor.model;
|
|
35
|
+
const view = editor.editing.view;
|
|
36
|
+
const viewDocument = view.document;
|
|
37
|
+
const selection = model.document.selection;
|
|
38
|
+
let shiftPressed = false;
|
|
39
|
+
view.addObserver(ClipboardObserver);
|
|
40
|
+
this.listenTo(viewDocument, 'keydown', (evt, data) => {
|
|
41
|
+
shiftPressed = data.shiftKey;
|
|
42
|
+
});
|
|
43
|
+
editor.plugins.get(ClipboardPipeline).on('contentInsertion', (evt, data) => {
|
|
44
|
+
// Plain text can be determined based on the event flag (#7799) or auto-detection (#1006). If detected,
|
|
45
|
+
// preserve selection attributes on pasted items.
|
|
46
|
+
if (!shiftPressed && !isPlainTextFragment(data.content, model.schema)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
model.change(writer => {
|
|
50
|
+
// Formatting attributes should be preserved.
|
|
51
|
+
const textAttributes = Array.from(selection.getAttributes())
|
|
52
|
+
.filter(([key]) => model.schema.getAttributeProperties(key).isFormatting);
|
|
53
|
+
if (!selection.isCollapsed) {
|
|
54
|
+
model.deleteContent(selection, { doNotAutoparagraph: true });
|
|
55
|
+
}
|
|
56
|
+
// Also preserve other attributes if they survived the content deletion (because they were not fully selected).
|
|
57
|
+
// For example linkHref is not a formatting attribute but it should be preserved if pasted text was in the middle
|
|
58
|
+
// of a link.
|
|
59
|
+
textAttributes.push(...selection.getAttributes());
|
|
60
|
+
const range = writer.createRangeIn(data.content);
|
|
61
|
+
for (const item of range.getItems()) {
|
|
62
|
+
if (item.is('$textProxy')) {
|
|
63
|
+
writer.setAttributes(textAttributes, item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns true if specified `documentFragment` represents a plain text.
|
|
72
|
+
*/
|
|
73
|
+
function isPlainTextFragment(documentFragment, schema) {
|
|
74
|
+
if (documentFragment.childCount > 1) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const child = documentFragment.getChild(0);
|
|
78
|
+
if (schema.isObject(child)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return Array.from(child.getAttributeKeys()).length == 0;
|
|
82
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/utils/normalizeclipboarddata
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Removes some popular browser quirks out of the clipboard data (HTML).
|
|
10
|
-
* Removes all HTML comments. These are considered an internal thing and it makes little sense if they leak into the editor data.
|
|
11
|
-
*
|
|
12
|
-
* @param data The HTML data to normalize.
|
|
13
|
-
* @returns Normalized HTML.
|
|
14
|
-
*/
|
|
15
|
-
export default function normalizeClipboardData(data: string): string;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/utils/normalizeclipboarddata
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Removes some popular browser quirks out of the clipboard data (HTML).
|
|
10
|
+
* Removes all HTML comments. These are considered an internal thing and it makes little sense if they leak into the editor data.
|
|
11
|
+
*
|
|
12
|
+
* @param data The HTML data to normalize.
|
|
13
|
+
* @returns Normalized HTML.
|
|
14
|
+
*/
|
|
15
|
+
export default function normalizeClipboardData(data: string): string;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/utils/normalizeclipboarddata
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Removes some popular browser quirks out of the clipboard data (HTML).
|
|
10
|
-
* Removes all HTML comments. These are considered an internal thing and it makes little sense if they leak into the editor data.
|
|
11
|
-
*
|
|
12
|
-
* @param data The HTML data to normalize.
|
|
13
|
-
* @returns Normalized HTML.
|
|
14
|
-
*/
|
|
15
|
-
export default function normalizeClipboardData(data) {
|
|
16
|
-
return data
|
|
17
|
-
.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g, (fullMatch, spaces) => {
|
|
18
|
-
// Handle the most popular and problematic case when even a single space becomes an nbsp;.
|
|
19
|
-
// Decode those to normal spaces. Read more in https://github.com/ckeditor/ckeditor5-clipboard/issues/2.
|
|
20
|
-
if (spaces.length == 1) {
|
|
21
|
-
return ' ';
|
|
22
|
-
}
|
|
23
|
-
return spaces;
|
|
24
|
-
})
|
|
25
|
-
// Remove all HTML comments.
|
|
26
|
-
.replace(/<!--[\s\S]*?-->/g, '');
|
|
27
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/utils/normalizeclipboarddata
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Removes some popular browser quirks out of the clipboard data (HTML).
|
|
10
|
+
* Removes all HTML comments. These are considered an internal thing and it makes little sense if they leak into the editor data.
|
|
11
|
+
*
|
|
12
|
+
* @param data The HTML data to normalize.
|
|
13
|
+
* @returns Normalized HTML.
|
|
14
|
+
*/
|
|
15
|
+
export default function normalizeClipboardData(data) {
|
|
16
|
+
return data
|
|
17
|
+
.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g, (fullMatch, spaces) => {
|
|
18
|
+
// Handle the most popular and problematic case when even a single space becomes an nbsp;.
|
|
19
|
+
// Decode those to normal spaces. Read more in https://github.com/ckeditor/ckeditor5-clipboard/issues/2.
|
|
20
|
+
if (spaces.length == 1) {
|
|
21
|
+
return ' ';
|
|
22
|
+
}
|
|
23
|
+
return spaces;
|
|
24
|
+
})
|
|
25
|
+
// Remove all HTML comments.
|
|
26
|
+
.replace(/<!--[\s\S]*?-->/g, '');
|
|
27
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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/utils/plaintexttohtml
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Converts plain text to its HTML-ized version.
|
|
10
|
-
*
|
|
11
|
-
* @param text The plain text to convert.
|
|
12
|
-
* @returns HTML generated from the plain text.
|
|
13
|
-
*/
|
|
14
|
-
export default function plainTextToHtml(text: string): string;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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/utils/plaintexttohtml
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Converts plain text to its HTML-ized version.
|
|
10
|
+
*
|
|
11
|
+
* @param text The plain text to convert.
|
|
12
|
+
* @returns HTML generated from the plain text.
|
|
13
|
+
*/
|
|
14
|
+
export default function plainTextToHtml(text: string): string;
|