@ckeditor/ckeditor5-clipboard 40.0.0 → 40.2.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/CHANGELOG.md +25 -25
- package/LICENSE.md +3 -3
- package/package.json +6 -6
- package/src/augmentation.d.ts +15 -15
- 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 +260 -260
- package/src/clipboardpipeline.js +266 -266
- package/src/dragdrop.d.ts +102 -102
- package/src/dragdrop.js +577 -577
- package/src/dragdropblocktoolbar.d.ts +47 -47
- package/src/dragdropblocktoolbar.js +121 -121
- package/src/dragdroptarget.d.ts +94 -94
- package/src/dragdroptarget.js +373 -363
- package/src/index.d.ts +16 -16
- package/src/index.js +14 -14
- 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 +39 -37
- package/src/utils/viewtoplaintext.d.ts +15 -15
- package/src/utils/viewtoplaintext.js +67 -50
|
@@ -1,37 +1,39 @@
|
|
|
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) {
|
|
15
|
-
text = text
|
|
16
|
-
// Encode
|
|
17
|
-
.replace(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.replace(
|
|
21
|
-
// Creates a
|
|
22
|
-
.replace(/\r?\n/g, '
|
|
23
|
-
//
|
|
24
|
-
.replace(/\
|
|
25
|
-
//
|
|
26
|
-
.replace(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.replace(/\s
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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) {
|
|
15
|
+
text = text
|
|
16
|
+
// Encode &.
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
// Encode <>.
|
|
19
|
+
.replace(/</g, '<')
|
|
20
|
+
.replace(/>/g, '>')
|
|
21
|
+
// Creates a paragraph for each double line break.
|
|
22
|
+
.replace(/\r?\n\r?\n/g, '</p><p>')
|
|
23
|
+
// Creates a line break for each single line break.
|
|
24
|
+
.replace(/\r?\n/g, '<br>')
|
|
25
|
+
// Replace tabs with four spaces.
|
|
26
|
+
.replace(/\t/g, ' ')
|
|
27
|
+
// Preserve trailing spaces (only the first and last one – the rest is handled below).
|
|
28
|
+
.replace(/^\s/, ' ')
|
|
29
|
+
.replace(/\s$/, ' ')
|
|
30
|
+
// Preserve other subsequent spaces now.
|
|
31
|
+
.replace(/\s\s/g, ' ');
|
|
32
|
+
if (text.includes('</p><p>') || text.includes('<br>')) {
|
|
33
|
+
// If we created paragraphs above, add the trailing ones.
|
|
34
|
+
text = `<p>${text}</p>`;
|
|
35
|
+
}
|
|
36
|
+
// TODO:
|
|
37
|
+
// * What about '\nfoo' vs ' foo'?
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
@@ -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/viewtoplaintext
|
|
7
|
-
*/
|
|
8
|
-
import type { ViewDocumentFragment, ViewItem } from '@ckeditor/ckeditor5-engine';
|
|
9
|
-
/**
|
|
10
|
-
* Converts {@link module:engine/view/item~Item view item} and all of its children to plain text.
|
|
11
|
-
*
|
|
12
|
-
* @param viewItem View item to convert.
|
|
13
|
-
* @returns Plain text representation of `viewItem`.
|
|
14
|
-
*/
|
|
15
|
-
export default function viewToPlainText(viewItem: ViewItem | ViewDocumentFragment): 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/viewtoplaintext
|
|
7
|
+
*/
|
|
8
|
+
import type { ViewDocumentFragment, ViewItem } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
/**
|
|
10
|
+
* Converts {@link module:engine/view/item~Item view item} and all of its children to plain text.
|
|
11
|
+
*
|
|
12
|
+
* @param viewItem View item to convert.
|
|
13
|
+
* @returns Plain text representation of `viewItem`.
|
|
14
|
+
*/
|
|
15
|
+
export default function viewToPlainText(viewItem: ViewItem | ViewDocumentFragment): string;
|
|
@@ -1,50 +1,67 @@
|
|
|
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
|
-
// Elements which should not have empty-line padding.
|
|
6
|
-
// Most `view.ContainerElement` want to be separate by new-line, but some are creating one structure
|
|
7
|
-
// together (like `<li>`) so it is better to separate them by only one "\n".
|
|
8
|
-
const smallPaddingElements = ['figcaption', 'li'];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (viewItem.is('$text') || viewItem.is('$textProxy')) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
// Elements which should not have empty-line padding.
|
|
6
|
+
// Most `view.ContainerElement` want to be separate by new-line, but some are creating one structure
|
|
7
|
+
// together (like `<li>`) so it is better to separate them by only one "\n".
|
|
8
|
+
const smallPaddingElements = ['figcaption', 'li'];
|
|
9
|
+
const listElements = ['ol', 'ul'];
|
|
10
|
+
/**
|
|
11
|
+
* Converts {@link module:engine/view/item~Item view item} and all of its children to plain text.
|
|
12
|
+
*
|
|
13
|
+
* @param viewItem View item to convert.
|
|
14
|
+
* @returns Plain text representation of `viewItem`.
|
|
15
|
+
*/
|
|
16
|
+
export default function viewToPlainText(viewItem) {
|
|
17
|
+
if (viewItem.is('$text') || viewItem.is('$textProxy')) {
|
|
18
|
+
return viewItem.data;
|
|
19
|
+
}
|
|
20
|
+
if (viewItem.is('element', 'img') && viewItem.hasAttribute('alt')) {
|
|
21
|
+
return viewItem.getAttribute('alt');
|
|
22
|
+
}
|
|
23
|
+
if (viewItem.is('element', 'br')) {
|
|
24
|
+
return '\n'; // Convert soft breaks to single line break (#8045).
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Item is a document fragment, attribute element or container element. It doesn't
|
|
28
|
+
* have it's own text value, so we need to convert its children elements.
|
|
29
|
+
*/
|
|
30
|
+
let text = '';
|
|
31
|
+
let prev = null;
|
|
32
|
+
for (const child of viewItem.getChildren()) {
|
|
33
|
+
text += newLinePadding(child, prev) + viewToPlainText(child);
|
|
34
|
+
prev = child;
|
|
35
|
+
}
|
|
36
|
+
return text;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns new line padding to prefix the given elements with.
|
|
40
|
+
*/
|
|
41
|
+
function newLinePadding(element, previous) {
|
|
42
|
+
if (!previous) {
|
|
43
|
+
// Don't add padding to first elements in a level.
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
if (element.is('element', 'li') && !element.isEmpty && element.getChild(0).is('containerElement')) {
|
|
47
|
+
// Separate document list items with empty lines.
|
|
48
|
+
return '\n\n';
|
|
49
|
+
}
|
|
50
|
+
if (listElements.includes(element.name) && listElements.includes(previous.name)) {
|
|
51
|
+
/**
|
|
52
|
+
* Because `<ul>` and `<ol>` are AttributeElements, two consecutive lists will not have any padding between
|
|
53
|
+
* them (see the `if` statement below). To fix this, we need to make an exception for this case.
|
|
54
|
+
*/
|
|
55
|
+
return '\n\n';
|
|
56
|
+
}
|
|
57
|
+
if (!element.is('containerElement') && !previous.is('containerElement')) {
|
|
58
|
+
// Don't add padding between non-container elements.
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
if (smallPaddingElements.includes(element.name) || smallPaddingElements.includes(previous.name)) {
|
|
62
|
+
// Add small padding between selected container elements.
|
|
63
|
+
return '\n';
|
|
64
|
+
}
|
|
65
|
+
// Add empty lines between container elements.
|
|
66
|
+
return '\n\n';
|
|
67
|
+
}
|