@ckeditor/ckeditor5-engine 35.0.1 → 35.1.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 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +175 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +899 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +654 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +191 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/dataprocessor/basichtmlwriter
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals document */
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Basic HTML writer. It uses the native `innerHTML` property for basic conversion
|
|
14
11
|
* from a document fragment to an HTML string.
|
|
@@ -16,17 +13,16 @@
|
|
|
16
13
|
* @implements module:engine/dataprocessor/htmlwriter~HtmlWriter
|
|
17
14
|
*/
|
|
18
15
|
export default class BasicHtmlWriter {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns an HTML string created from the document fragment.
|
|
18
|
+
*
|
|
19
|
+
* @param {DocumentFragment} fragment
|
|
20
|
+
* @returns {String}
|
|
21
|
+
*/
|
|
22
|
+
getHtml(fragment) {
|
|
23
|
+
const doc = document.implementation.createHTMLDocument('');
|
|
24
|
+
const container = doc.createElement('div');
|
|
25
|
+
container.appendChild(fragment);
|
|
26
|
+
return container.innerHTML;
|
|
27
|
+
}
|
|
32
28
|
}
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/dataprocessor/htmldataprocessor
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals DOMParser */
|
|
11
|
-
|
|
12
9
|
import BasicHtmlWriter from './basichtmlwriter';
|
|
13
10
|
import DomConverter from '../view/domconverter';
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* The HTML data processor class.
|
|
17
13
|
* This data processor implementation uses HTML as input and output data.
|
|
@@ -19,116 +15,104 @@ import DomConverter from '../view/domconverter';
|
|
|
19
15
|
* @implements module:engine/dataprocessor/dataprocessor~DataProcessor
|
|
20
16
|
*/
|
|
21
17
|
export default class HtmlDataProcessor {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const document = this.domParser.parseFromString( data, 'text/html' );
|
|
125
|
-
const fragment = document.createDocumentFragment();
|
|
126
|
-
const bodyChildNodes = document.body.childNodes;
|
|
127
|
-
|
|
128
|
-
while ( bodyChildNodes.length > 0 ) {
|
|
129
|
-
fragment.appendChild( bodyChildNodes[ 0 ] );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return fragment;
|
|
133
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new instance of the HTML data processor class.
|
|
20
|
+
*
|
|
21
|
+
* @param {module:engine/view/document~Document} document The view document instance.
|
|
22
|
+
*/
|
|
23
|
+
constructor(document) {
|
|
24
|
+
/**
|
|
25
|
+
* A DOM parser instance used to parse an HTML string to an HTML document.
|
|
26
|
+
*
|
|
27
|
+
* @member {DOMParser}
|
|
28
|
+
*/
|
|
29
|
+
this.domParser = new DOMParser();
|
|
30
|
+
/**
|
|
31
|
+
* A DOM converter used to convert DOM elements to view elements.
|
|
32
|
+
*
|
|
33
|
+
* @member {module:engine/view/domconverter~DomConverter}
|
|
34
|
+
*/
|
|
35
|
+
this.domConverter = new DomConverter(document, { renderingMode: 'data' });
|
|
36
|
+
/**
|
|
37
|
+
* A basic HTML writer instance used to convert DOM elements to an HTML string.
|
|
38
|
+
*
|
|
39
|
+
* @member {module:engine/dataprocessor/htmlwriter~HtmlWriter}
|
|
40
|
+
*/
|
|
41
|
+
this.htmlWriter = new BasicHtmlWriter();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts a provided {@link module:engine/view/documentfragment~DocumentFragment document fragment}
|
|
45
|
+
* to data format — in this case to an HTML string.
|
|
46
|
+
*
|
|
47
|
+
* @param {module:engine/view/documentfragment~DocumentFragment} viewFragment
|
|
48
|
+
* @returns {String} HTML string.
|
|
49
|
+
*/
|
|
50
|
+
toData(viewFragment) {
|
|
51
|
+
// Convert view DocumentFragment to DOM DocumentFragment.
|
|
52
|
+
const domFragment = this.domConverter.viewToDom(viewFragment);
|
|
53
|
+
// Convert DOM DocumentFragment to HTML output.
|
|
54
|
+
return this.htmlWriter.getHtml(domFragment);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts the provided HTML string to a view tree.
|
|
58
|
+
*
|
|
59
|
+
* @param {String} data An HTML string.
|
|
60
|
+
* @returns {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment|null} A converted view element.
|
|
61
|
+
*/
|
|
62
|
+
toView(data) {
|
|
63
|
+
// Convert input HTML data to DOM DocumentFragment.
|
|
64
|
+
const domFragment = this._toDom(data);
|
|
65
|
+
// Convert DOM DocumentFragment to view DocumentFragment.
|
|
66
|
+
return this.domConverter.domToView(domFragment);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Registers a {@link module:engine/view/matcher~MatcherPattern} for view elements whose content should be treated as raw data
|
|
70
|
+
* and not processed during the conversion from the DOM to the view elements.
|
|
71
|
+
*
|
|
72
|
+
* The raw data can be later accessed by a
|
|
73
|
+
* {@link module:engine/view/element~Element#getCustomProperty custom property of a view element} called `"$rawContent"`.
|
|
74
|
+
*
|
|
75
|
+
* @param {module:engine/view/matcher~MatcherPattern} pattern Pattern matching all view elements whose content should
|
|
76
|
+
* be treated as raw data.
|
|
77
|
+
*/
|
|
78
|
+
registerRawContentMatcher(pattern) {
|
|
79
|
+
this.domConverter.registerRawContentMatcher(pattern);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* If the processor is set to use marked fillers, it will insert ` ` fillers wrapped in `<span>` elements
|
|
83
|
+
* (`<span data-cke-filler="true"> </span>`) instead of regular ` ` characters.
|
|
84
|
+
*
|
|
85
|
+
* This mode allows for a more precise handling of the block fillers (so they do not leak into the editor content) but
|
|
86
|
+
* bloats the editor data with additional markup.
|
|
87
|
+
*
|
|
88
|
+
* This mode may be required by some features and will be turned on by them automatically.
|
|
89
|
+
*
|
|
90
|
+
* @param {'default'|'marked'} type Whether to use the default or the marked ` ` block fillers.
|
|
91
|
+
*/
|
|
92
|
+
useFillerType(type) {
|
|
93
|
+
this.domConverter.blockFillerMode = type == 'marked' ? 'markedNbsp' : 'nbsp';
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Converts an HTML string to its DOM representation. Returns a document fragment containing nodes parsed from
|
|
97
|
+
* the provided data.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
* @param {String} data
|
|
101
|
+
* @returns {DocumentFragment}
|
|
102
|
+
*/
|
|
103
|
+
_toDom(data) {
|
|
104
|
+
// Wrap data with a <body> tag so leading non-layout nodes (like <script>, <style>, HTML comment)
|
|
105
|
+
// will be preserved in the body collection.
|
|
106
|
+
// Do it only for data that is not a full HTML document.
|
|
107
|
+
if (!data.match(/<(?:html|body|head|meta)(?:\s[^>]*)?>/i)) {
|
|
108
|
+
data = `<body>${data}</body>`;
|
|
109
|
+
}
|
|
110
|
+
const document = this.domParser.parseFromString(data, 'text/html');
|
|
111
|
+
const fragment = document.createDocumentFragment();
|
|
112
|
+
const bodyChildNodes = document.body.childNodes;
|
|
113
|
+
while (bodyChildNodes.length > 0) {
|
|
114
|
+
fragment.appendChild(bodyChildNodes[0]);
|
|
115
|
+
}
|
|
116
|
+
return fragment;
|
|
117
|
+
}
|
|
134
118
|
}
|
|
@@ -2,21 +2,4 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module engine/dataprocessor/htmlwriter
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The HTML writer interface.
|
|
12
|
-
*
|
|
13
|
-
* @interface module:engine/dataprocessor/htmlwriter~HtmlWriter
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns an HTML string created from a document fragment.
|
|
18
|
-
*
|
|
19
|
-
* @method module:engine/dataprocessor/htmlwriter~HtmlWriter#getHtml
|
|
20
|
-
* @param {DocumentFragment} fragment
|
|
21
|
-
* @returns {String}
|
|
22
|
-
*/
|
|
5
|
+
export {};
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/dataprocessor/xmldataprocessor
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals DOMParser */
|
|
11
|
-
|
|
12
9
|
import BasicHtmlWriter from './basichtmlwriter';
|
|
13
10
|
import DomConverter from '../view/domconverter';
|
|
14
|
-
|
|
15
11
|
/**
|
|
16
12
|
* The XML data processor class.
|
|
17
13
|
* This data processor implementation uses XML as input and output data.
|
|
@@ -21,137 +17,120 @@ import DomConverter from '../view/domconverter';
|
|
|
21
17
|
* @implements module:engine/dataprocessor/dataprocessor~DataProcessor
|
|
22
18
|
*/
|
|
23
19
|
export default class XmlDataProcessor {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// Parse validation.
|
|
142
|
-
const parserError = parsedDocument.querySelector( 'parsererror' );
|
|
143
|
-
|
|
144
|
-
if ( parserError ) {
|
|
145
|
-
throw new Error( 'Parse error - ' + parserError.textContent );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const fragment = parsedDocument.createDocumentFragment();
|
|
149
|
-
const nodes = parsedDocument.documentElement.childNodes;
|
|
150
|
-
|
|
151
|
-
while ( nodes.length > 0 ) {
|
|
152
|
-
fragment.appendChild( nodes[ 0 ] );
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return fragment;
|
|
156
|
-
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new instance of the XML data processor class.
|
|
22
|
+
*
|
|
23
|
+
* @param {module:engine/view/document~Document} document The view document instance.
|
|
24
|
+
* @param {Object} options Configuration options.
|
|
25
|
+
* @param {Array.<String>} [options.namespaces=[]] A list of namespaces allowed to use in the XML input.
|
|
26
|
+
*/
|
|
27
|
+
constructor(document, options = {}) {
|
|
28
|
+
/**
|
|
29
|
+
* A list of namespaces allowed to use in the XML input.
|
|
30
|
+
*
|
|
31
|
+
* For example, registering namespaces [ 'attribute', 'container' ] allows to use `<attirbute:tagName></attribute:tagName>`
|
|
32
|
+
* and `<container:tagName></container:tagName>` input. It is mainly for debugging.
|
|
33
|
+
*
|
|
34
|
+
* @member {Array.<String>}
|
|
35
|
+
*/
|
|
36
|
+
this.namespaces = options.namespaces || [];
|
|
37
|
+
/**
|
|
38
|
+
* DOM parser instance used to parse an XML string to an XML document.
|
|
39
|
+
*
|
|
40
|
+
* @member {DOMParser}
|
|
41
|
+
*/
|
|
42
|
+
this.domParser = new DOMParser();
|
|
43
|
+
/**
|
|
44
|
+
* DOM converter used to convert DOM elements to view elements.
|
|
45
|
+
*
|
|
46
|
+
* @member {module:engine/view/domconverter~DomConverter}
|
|
47
|
+
*/
|
|
48
|
+
this.domConverter = new DomConverter(document, { renderingMode: 'data' });
|
|
49
|
+
/**
|
|
50
|
+
* A basic HTML writer instance used to convert DOM elements to an XML string.
|
|
51
|
+
* There is no need to use a dedicated XML writer because the basic HTML writer works well in this case.
|
|
52
|
+
*
|
|
53
|
+
* @member {module:engine/dataprocessor/htmlwriter~HtmlWriter}
|
|
54
|
+
*/
|
|
55
|
+
this.htmlWriter = new BasicHtmlWriter();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Converts the provided {@link module:engine/view/documentfragment~DocumentFragment document fragment}
|
|
59
|
+
* to data format — in this case an XML string.
|
|
60
|
+
*
|
|
61
|
+
* @param {module:engine/view/documentfragment~DocumentFragment} viewFragment
|
|
62
|
+
* @returns {String} An XML string.
|
|
63
|
+
*/
|
|
64
|
+
toData(viewFragment) {
|
|
65
|
+
// Convert view DocumentFragment to DOM DocumentFragment.
|
|
66
|
+
const domFragment = this.domConverter.viewToDom(viewFragment);
|
|
67
|
+
// Convert DOM DocumentFragment to XML output.
|
|
68
|
+
// There is no need to use dedicated for XML serializing method because BasicHtmlWriter works well in this case.
|
|
69
|
+
return this.htmlWriter.getHtml(domFragment);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Converts the provided XML string to a view tree.
|
|
73
|
+
*
|
|
74
|
+
* @param {String} data An XML string.
|
|
75
|
+
* @returns {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment|null} A converted view element.
|
|
76
|
+
*/
|
|
77
|
+
toView(data) {
|
|
78
|
+
// Convert input XML data to DOM DocumentFragment.
|
|
79
|
+
const domFragment = this._toDom(data);
|
|
80
|
+
// Convert DOM DocumentFragment to view DocumentFragment.
|
|
81
|
+
return this.domConverter.domToView(domFragment, { keepOriginalCase: true });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Registers a {@link module:engine/view/matcher~MatcherPattern} for view elements whose content should be treated as raw data
|
|
85
|
+
* and not processed during the conversion from XML to view elements.
|
|
86
|
+
*
|
|
87
|
+
* The raw data can be later accessed by a
|
|
88
|
+
* {@link module:engine/view/element~Element#getCustomProperty custom property of a view element} called `"$rawContent"`.
|
|
89
|
+
*
|
|
90
|
+
* @param {module:engine/view/matcher~MatcherPattern} pattern Pattern matching all view elements whose content should
|
|
91
|
+
* be treated as raw data.
|
|
92
|
+
*/
|
|
93
|
+
registerRawContentMatcher(pattern) {
|
|
94
|
+
this.domConverter.registerRawContentMatcher(pattern);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* If the processor is set to use marked fillers, it will insert ` ` fillers wrapped in `<span>` elements
|
|
98
|
+
* (`<span data-cke-filler="true"> </span>`) instead of regular ` ` characters.
|
|
99
|
+
*
|
|
100
|
+
* This mode allows for a more precise handling of block fillers (so they do not leak into editor content) but
|
|
101
|
+
* bloats the editor data with additional markup.
|
|
102
|
+
*
|
|
103
|
+
* This mode may be required by some features and will be turned on by them automatically.
|
|
104
|
+
*
|
|
105
|
+
* @param {'default'|'marked'} type Whether to use the default or the marked ` ` block fillers.
|
|
106
|
+
*/
|
|
107
|
+
useFillerType(type) {
|
|
108
|
+
this.domConverter.blockFillerMode = type == 'marked' ? 'markedNbsp' : 'nbsp';
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Converts an XML string to its DOM representation. Returns a document fragment containing nodes parsed from
|
|
112
|
+
* the provided data.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
* @param {String} data
|
|
116
|
+
* @returns {DocumentFragment}
|
|
117
|
+
*/
|
|
118
|
+
_toDom(data) {
|
|
119
|
+
// Stringify namespaces.
|
|
120
|
+
const namespaces = this.namespaces.map(nsp => `xmlns:${nsp}="nsp"`).join(' ');
|
|
121
|
+
// Wrap data into root element with optional namespace definitions.
|
|
122
|
+
data = `<xml ${namespaces}>${data}</xml>`;
|
|
123
|
+
const parsedDocument = this.domParser.parseFromString(data, 'text/xml');
|
|
124
|
+
// Parse validation.
|
|
125
|
+
const parserError = parsedDocument.querySelector('parsererror');
|
|
126
|
+
if (parserError) {
|
|
127
|
+
throw new Error('Parse error - ' + parserError.textContent);
|
|
128
|
+
}
|
|
129
|
+
const fragment = parsedDocument.createDocumentFragment();
|
|
130
|
+
const nodes = parsedDocument.documentElement.childNodes;
|
|
131
|
+
while (nodes.length > 0) {
|
|
132
|
+
fragment.appendChild(nodes[0]);
|
|
133
|
+
}
|
|
134
|
+
return fragment;
|
|
135
|
+
}
|
|
157
136
|
}
|