@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
|
@@ -1,37 +1,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
|
-
.replace(/>/g, '>')
|
|
19
|
-
// Creates a paragraph for each double line break.
|
|
20
|
-
.replace(/\r?\n\r?\n/g, '</p><p>')
|
|
21
|
-
// Creates a line break for each single line break.
|
|
22
|
-
.replace(/\r?\n/g, '<br>')
|
|
23
|
-
// Replace tabs with four spaces.
|
|
24
|
-
.replace(/\t/g, ' ')
|
|
25
|
-
// Preserve trailing spaces (only the first and last one – the rest is handled below).
|
|
26
|
-
.replace(/^\s/, ' ')
|
|
27
|
-
.replace(/\s$/, ' ')
|
|
28
|
-
// Preserve other subsequent spaces now.
|
|
29
|
-
.replace(/\s\s/g, ' ');
|
|
30
|
-
if (text.includes('</p><p>') || text.includes('<br>')) {
|
|
31
|
-
// If we created paragraphs above, add the trailing ones.
|
|
32
|
-
text = `<p>${text}</p>`;
|
|
33
|
-
}
|
|
34
|
-
// TODO:
|
|
35
|
-
// * What about '\nfoo' vs ' foo'?
|
|
36
|
-
return text;
|
|
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
|
+
.replace(/>/g, '>')
|
|
19
|
+
// Creates a paragraph for each double line break.
|
|
20
|
+
.replace(/\r?\n\r?\n/g, '</p><p>')
|
|
21
|
+
// Creates a line break for each single line break.
|
|
22
|
+
.replace(/\r?\n/g, '<br>')
|
|
23
|
+
// Replace tabs with four spaces.
|
|
24
|
+
.replace(/\t/g, ' ')
|
|
25
|
+
// Preserve trailing spaces (only the first and last one – the rest is handled below).
|
|
26
|
+
.replace(/^\s/, ' ')
|
|
27
|
+
.replace(/\s$/, ' ')
|
|
28
|
+
// Preserve other subsequent spaces now.
|
|
29
|
+
.replace(/\s\s/g, ' ');
|
|
30
|
+
if (text.includes('</p><p>') || text.includes('<br>')) {
|
|
31
|
+
// If we created paragraphs above, add the trailing ones.
|
|
32
|
+
text = `<p>${text}</p>`;
|
|
33
|
+
}
|
|
34
|
+
// TODO:
|
|
35
|
+
// * What about '\nfoo' vs ' foo'?
|
|
36
|
+
return text;
|
|
37
|
+
}
|
|
@@ -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,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
|
-
/**
|
|
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) {
|
|
16
|
-
let text = '';
|
|
17
|
-
if (viewItem.is('$text') || viewItem.is('$textProxy')) {
|
|
18
|
-
// If item is `Text` or `TextProxy` simple take its text data.
|
|
19
|
-
text = viewItem.data;
|
|
20
|
-
}
|
|
21
|
-
else if (viewItem.is('element', 'img') && viewItem.hasAttribute('alt')) {
|
|
22
|
-
// Special case for images - use alt attribute if it is provided.
|
|
23
|
-
text = viewItem.getAttribute('alt');
|
|
24
|
-
}
|
|
25
|
-
else if (viewItem.is('element', 'br')) {
|
|
26
|
-
// A soft break should be converted into a single line break (#8045).
|
|
27
|
-
text = '\n';
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// Other elements are document fragments, attribute elements or container elements.
|
|
31
|
-
// They don't have their own text value, so convert their children.
|
|
32
|
-
let prev = null;
|
|
33
|
-
for (const child of viewItem.getChildren()) {
|
|
34
|
-
const childText = viewToPlainText(child);
|
|
35
|
-
// Separate container element children with one or more new-line characters.
|
|
36
|
-
if (prev && (prev.is('containerElement') || child.is('containerElement'))) {
|
|
37
|
-
if (smallPaddingElements.includes(prev.name) ||
|
|
38
|
-
smallPaddingElements.includes(child.name)) {
|
|
39
|
-
text += '\n';
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
text += '\n\n';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
text += childText;
|
|
46
|
-
prev = child;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return text;
|
|
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
|
+
/**
|
|
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) {
|
|
16
|
+
let text = '';
|
|
17
|
+
if (viewItem.is('$text') || viewItem.is('$textProxy')) {
|
|
18
|
+
// If item is `Text` or `TextProxy` simple take its text data.
|
|
19
|
+
text = viewItem.data;
|
|
20
|
+
}
|
|
21
|
+
else if (viewItem.is('element', 'img') && viewItem.hasAttribute('alt')) {
|
|
22
|
+
// Special case for images - use alt attribute if it is provided.
|
|
23
|
+
text = viewItem.getAttribute('alt');
|
|
24
|
+
}
|
|
25
|
+
else if (viewItem.is('element', 'br')) {
|
|
26
|
+
// A soft break should be converted into a single line break (#8045).
|
|
27
|
+
text = '\n';
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Other elements are document fragments, attribute elements or container elements.
|
|
31
|
+
// They don't have their own text value, so convert their children.
|
|
32
|
+
let prev = null;
|
|
33
|
+
for (const child of viewItem.getChildren()) {
|
|
34
|
+
const childText = viewToPlainText(child);
|
|
35
|
+
// Separate container element children with one or more new-line characters.
|
|
36
|
+
if (prev && (prev.is('containerElement') || child.is('containerElement'))) {
|
|
37
|
+
if (smallPaddingElements.includes(prev.name) ||
|
|
38
|
+
smallPaddingElements.includes(child.name)) {
|
|
39
|
+
text += '\n';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
text += '\n\n';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
text += childText;
|
|
46
|
+
prev = child;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return text;
|
|
50
|
+
}
|