@ckeditor/ckeditor5-clipboard 0.0.0-internal-20241017.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 +4 -0
- package/LICENSE.md +21 -0
- package/README.md +22 -0
- package/dist/augmentation.d.ts +20 -0
- package/dist/clipboard.d.ts +44 -0
- package/dist/clipboardmarkersutils.d.ts +208 -0
- package/dist/clipboardobserver.d.ts +316 -0
- package/dist/clipboardpipeline.d.ts +273 -0
- package/dist/dragdrop.d.ts +110 -0
- package/dist/dragdropblocktoolbar.d.ts +55 -0
- package/dist/dragdroptarget.d.ts +102 -0
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +27 -0
- package/dist/index.css +42 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +2183 -0
- package/dist/index.js.map +1 -0
- package/dist/lineview.d.ts +49 -0
- package/dist/pasteplaintext.d.ts +36 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/ar.umd.js +11 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bg.umd.js +11 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/bn.umd.js +11 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/ca.umd.js +11 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/cs.umd.js +11 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/da.umd.js +11 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/de.umd.js +11 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/el.umd.js +11 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/en.umd.js +11 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es-co.umd.js +11 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/es.umd.js +11 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/et.umd.js +11 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fi.umd.js +11 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/fr.umd.js +11 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/gl.umd.js +11 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/he.umd.js +11 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hi.umd.js +11 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hr.umd.js +11 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/hu.umd.js +11 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/id.umd.js +11 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/it.umd.js +11 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ja.umd.js +11 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ko.umd.js +11 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lt.umd.js +11 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/lv.umd.js +11 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/ms.umd.js +11 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/nl.umd.js +11 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/no.umd.js +11 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pl.umd.js +11 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt-br.umd.js +11 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/pt.umd.js +11 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ro.umd.js +11 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/ru.umd.js +11 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sk.umd.js +11 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr-latn.umd.js +11 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sr.umd.js +11 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/sv.umd.js +11 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/th.umd.js +11 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/tr.umd.js +11 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/uk.umd.js +11 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/vi.umd.js +11 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh-cn.umd.js +11 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/translations/zh.umd.js +11 -0
- package/dist/utils/normalizeclipboarddata.d.ts +19 -0
- package/dist/utils/plaintexttohtml.d.ts +18 -0
- package/dist/utils/viewtoplaintext.d.ts +19 -0
- package/lang/contexts.json +5 -0
- package/lang/translations/ar.po +30 -0
- package/lang/translations/bg.po +30 -0
- package/lang/translations/bn.po +30 -0
- package/lang/translations/ca.po +30 -0
- package/lang/translations/cs.po +30 -0
- package/lang/translations/da.po +30 -0
- package/lang/translations/de.po +30 -0
- package/lang/translations/el.po +30 -0
- package/lang/translations/en.po +30 -0
- package/lang/translations/es-co.po +30 -0
- package/lang/translations/es.po +30 -0
- package/lang/translations/et.po +30 -0
- package/lang/translations/fi.po +30 -0
- package/lang/translations/fr.po +30 -0
- package/lang/translations/gl.po +30 -0
- package/lang/translations/he.po +30 -0
- package/lang/translations/hi.po +30 -0
- package/lang/translations/hr.po +30 -0
- package/lang/translations/hu.po +30 -0
- package/lang/translations/id.po +30 -0
- package/lang/translations/it.po +30 -0
- package/lang/translations/ja.po +30 -0
- package/lang/translations/ko.po +30 -0
- package/lang/translations/lt.po +30 -0
- package/lang/translations/lv.po +30 -0
- package/lang/translations/ms.po +30 -0
- package/lang/translations/nl.po +30 -0
- package/lang/translations/no.po +30 -0
- package/lang/translations/pl.po +30 -0
- package/lang/translations/pt-br.po +30 -0
- package/lang/translations/pt.po +30 -0
- package/lang/translations/ro.po +30 -0
- package/lang/translations/ru.po +30 -0
- package/lang/translations/sk.po +30 -0
- package/lang/translations/sr-latn.po +30 -0
- package/lang/translations/sr.po +30 -0
- package/lang/translations/sv.po +30 -0
- package/lang/translations/th.po +30 -0
- package/lang/translations/tr.po +30 -0
- package/lang/translations/uk.po +30 -0
- package/lang/translations/vi.po +30 -0
- package/lang/translations/zh-cn.po +30 -0
- package/lang/translations/zh.po +30 -0
- package/package.json +42 -0
- package/src/augmentation.d.ts +16 -0
- package/src/augmentation.js +5 -0
- package/src/clipboard.d.ts +40 -0
- package/src/clipboard.js +66 -0
- package/src/clipboardmarkersutils.d.ts +204 -0
- package/src/clipboardmarkersutils.js +505 -0
- package/src/clipboardobserver.d.ts +312 -0
- package/src/clipboardobserver.js +75 -0
- package/src/clipboardpipeline.d.ts +269 -0
- package/src/clipboardpipeline.js +283 -0
- package/src/dragdrop.d.ts +106 -0
- package/src/dragdrop.js +583 -0
- package/src/dragdropblocktoolbar.d.ts +51 -0
- package/src/dragdropblocktoolbar.js +127 -0
- package/src/dragdroptarget.d.ts +98 -0
- package/src/dragdroptarget.js +385 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +16 -0
- package/src/lineview.d.ts +45 -0
- package/src/lineview.js +44 -0
- package/src/pasteplaintext.d.ts +32 -0
- package/src/pasteplaintext.js +102 -0
- package/src/utils/normalizeclipboarddata.d.ts +15 -0
- package/src/utils/normalizeclipboarddata.js +27 -0
- package/src/utils/plaintexttohtml.d.ts +14 -0
- package/src/utils/plaintexttohtml.js +39 -0
- package/src/utils/viewtoplaintext.d.ts +15 -0
- package/src/utils/viewtoplaintext.js +72 -0
- package/theme/clipboard.css +38 -0
package/src/lineview.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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 = /* #__PURE__ */ 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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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 isOfficialPlugin(): true;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get requires(): readonly [typeof ClipboardPipeline];
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
init(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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 isOfficialPlugin() {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @inheritDoc
|
|
31
|
+
*/
|
|
32
|
+
static get requires() {
|
|
33
|
+
return [ClipboardPipeline];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
init() {
|
|
39
|
+
const editor = this.editor;
|
|
40
|
+
const model = editor.model;
|
|
41
|
+
const view = editor.editing.view;
|
|
42
|
+
const selection = model.document.selection;
|
|
43
|
+
view.addObserver(ClipboardObserver);
|
|
44
|
+
editor.plugins.get(ClipboardPipeline).on('contentInsertion', (evt, data) => {
|
|
45
|
+
if (!isUnformattedInlineContent(data.content, model)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
model.change(writer => {
|
|
49
|
+
// Formatting attributes should be preserved.
|
|
50
|
+
const textAttributes = Array.from(selection.getAttributes())
|
|
51
|
+
.filter(([key]) => model.schema.getAttributeProperties(key).isFormatting);
|
|
52
|
+
if (!selection.isCollapsed) {
|
|
53
|
+
model.deleteContent(selection, { doNotAutoparagraph: true });
|
|
54
|
+
}
|
|
55
|
+
// Also preserve other attributes if they survived the content deletion (because they were not fully selected).
|
|
56
|
+
// For example linkHref is not a formatting attribute but it should be preserved if pasted text was in the middle
|
|
57
|
+
// of a link.
|
|
58
|
+
textAttributes.push(...selection.getAttributes());
|
|
59
|
+
const range = writer.createRangeIn(data.content);
|
|
60
|
+
for (const item of range.getItems()) {
|
|
61
|
+
for (const attribute of textAttributes) {
|
|
62
|
+
if (model.schema.checkAttribute(item, attribute[0])) {
|
|
63
|
+
writer.setAttribute(attribute[0], attribute[1], item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns true if specified `documentFragment` represents the unformatted inline content.
|
|
73
|
+
*/
|
|
74
|
+
function isUnformattedInlineContent(documentFragment, model) {
|
|
75
|
+
let range = model.createRangeIn(documentFragment);
|
|
76
|
+
// We consider three scenarios here. The document fragment may include:
|
|
77
|
+
//
|
|
78
|
+
// 1. Only text and inline objects. Then it could be unformatted inline content.
|
|
79
|
+
// 2. Exactly one block element on top-level, eg. <p>Foobar</p> or <h2>Title</h2>.
|
|
80
|
+
// In this case, check this element content, it could be treated as unformatted inline content.
|
|
81
|
+
// 3. More block elements or block objects, then it is not unformatted inline content.
|
|
82
|
+
//
|
|
83
|
+
// We will check for scenario 2. specifically, and if it happens, we will unwrap it and follow with the regular algorithm.
|
|
84
|
+
//
|
|
85
|
+
if (documentFragment.childCount == 1) {
|
|
86
|
+
const child = documentFragment.getChild(0);
|
|
87
|
+
if (child.is('element') && model.schema.isBlock(child) && !model.schema.isObject(child) && !model.schema.isLimit(child)) {
|
|
88
|
+
// Scenario 2. as described above.
|
|
89
|
+
range = model.createRangeIn(child);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const child of range.getItems()) {
|
|
93
|
+
if (!model.schema.isInline(child)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const attributeKeys = Array.from(child.getAttributeKeys());
|
|
97
|
+
if (attributeKeys.find(key => model.schema.getAttributeProperties(key).isFormatting)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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
|
+
// Do not add padding around the elements that won't be rendered.
|
|
66
|
+
if (element.is('element') && element.getCustomProperty('dataPipeline:transparentRendering') ||
|
|
67
|
+
previous.is('element') && previous.getCustomProperty('dataPipeline:transparentRendering')) {
|
|
68
|
+
return '';
|
|
69
|
+
}
|
|
70
|
+
// Add empty lines between container elements.
|
|
71
|
+
return '\n\n';
|
|
72
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2003-2024, 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
|
+
.ck.ck-editor__editable {
|
|
7
|
+
/*
|
|
8
|
+
* Vertical drop target (in text).
|
|
9
|
+
*/
|
|
10
|
+
& .ck.ck-clipboard-drop-target-position {
|
|
11
|
+
display: inline;
|
|
12
|
+
position: relative;
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
|
|
15
|
+
& span {
|
|
16
|
+
position: absolute;
|
|
17
|
+
width: 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Styles of the widget being dragged (its preview).
|
|
23
|
+
*/
|
|
24
|
+
& .ck-widget:-webkit-drag {
|
|
25
|
+
& > .ck-widget__selection-handle {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
& > .ck-widget__type-around {
|
|
30
|
+
display: none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ck.ck-clipboard-drop-target-line {
|
|
36
|
+
position: absolute;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
}
|