@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.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/README.md +1 -1
- package/package.json +24 -23
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +62 -109
- package/src/controller/editingcontroller.d.ts +98 -0
- package/src/controller/editingcontroller.js +22 -46
- package/src/conversion/conversion.d.ts +476 -0
- package/src/conversion/conversion.js +328 -347
- package/src/conversion/conversionhelpers.d.ts +26 -0
- package/src/conversion/conversionhelpers.js +1 -5
- package/src/conversion/downcastdispatcher.d.ts +547 -0
- package/src/conversion/downcastdispatcher.js +74 -152
- package/src/conversion/downcasthelpers.d.ts +1226 -0
- package/src/conversion/downcasthelpers.js +843 -762
- package/src/conversion/mapper.d.ts +499 -0
- package/src/conversion/mapper.js +84 -99
- package/src/conversion/modelconsumable.d.ts +201 -0
- package/src/conversion/modelconsumable.js +96 -99
- package/src/conversion/upcastdispatcher.d.ts +492 -0
- package/src/conversion/upcastdispatcher.js +73 -100
- package/src/conversion/upcasthelpers.d.ts +499 -0
- package/src/conversion/upcasthelpers.js +406 -373
- package/src/conversion/viewconsumable.d.ts +177 -0
- package/src/conversion/viewconsumable.js +157 -162
- package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
- package/src/dataprocessor/basichtmlwriter.js +0 -9
- package/src/dataprocessor/dataprocessor.d.ts +61 -0
- package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
- package/src/dataprocessor/htmldataprocessor.js +6 -28
- package/src/dataprocessor/htmlwriter.d.ts +16 -0
- package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
- package/src/dataprocessor/xmldataprocessor.js +8 -40
- package/src/dev-utils/model.d.ts +124 -0
- package/src/dev-utils/model.js +41 -38
- package/src/dev-utils/operationreplayer.d.ts +51 -0
- package/src/dev-utils/operationreplayer.js +6 -14
- package/src/dev-utils/utils.d.ts +37 -0
- package/src/dev-utils/utils.js +5 -18
- package/src/dev-utils/view.d.ts +319 -0
- package/src/dev-utils/view.js +205 -226
- package/src/index.d.ts +105 -0
- package/src/index.js +1 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +245 -0
- package/src/model/document.js +1 -1
- package/src/model/documentfragment.d.ts +196 -0
- package/src/model/documentfragment.js +2 -2
- package/src/model/documentselection.d.ts +420 -0
- package/src/model/element.d.ts +165 -0
- package/src/model/history.d.ts +114 -0
- package/src/model/item.d.ts +14 -0
- package/src/model/liveposition.d.ts +77 -0
- package/src/model/liverange.d.ts +102 -0
- package/src/model/markercollection.d.ts +335 -0
- package/src/model/model.d.ts +812 -0
- package/src/model/model.js +59 -30
- package/src/model/node.d.ts +256 -0
- package/src/model/nodelist.d.ts +91 -0
- package/src/model/operation/attributeoperation.d.ts +98 -0
- package/src/model/operation/detachoperation.d.ts +55 -0
- package/src/model/operation/insertoperation.d.ts +85 -0
- package/src/model/operation/markeroperation.d.ts +86 -0
- package/src/model/operation/mergeoperation.d.ts +95 -0
- package/src/model/operation/moveoperation.d.ts +91 -0
- package/src/model/operation/nooperation.d.ts +33 -0
- package/src/model/operation/operation.d.ts +89 -0
- package/src/model/operation/operationfactory.d.ts +18 -0
- package/src/model/operation/renameoperation.d.ts +78 -0
- package/src/model/operation/rootattributeoperation.d.ts +97 -0
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.d.ts +104 -0
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/position.d.ts +539 -0
- package/src/model/position.js +1 -1
- package/src/model/range.d.ts +458 -0
- package/src/model/range.js +1 -1
- package/src/model/rootelement.d.ts +40 -0
- package/src/model/schema.d.ts +1176 -0
- package/src/model/schema.js +15 -15
- package/src/model/selection.d.ts +472 -0
- package/src/model/text.d.ts +66 -0
- package/src/model/text.js +0 -2
- package/src/model/textproxy.d.ts +144 -0
- package/src/model/treewalker.d.ts +186 -0
- package/src/model/treewalker.js +19 -10
- package/src/model/typecheckable.d.ts +255 -0
- package/src/model/utils/autoparagraphing.d.ts +37 -0
- package/src/model/utils/deletecontent.d.ts +58 -0
- package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
- package/src/model/utils/getselectedcontent.d.ts +30 -0
- package/src/model/utils/insertcontent.d.ts +46 -0
- package/src/model/utils/insertcontent.js +2 -12
- package/src/model/utils/insertobject.d.ts +44 -0
- package/src/model/utils/insertobject.js +3 -14
- package/src/model/utils/modifyselection.d.ts +48 -0
- package/src/model/utils/selection-post-fixer.d.ts +65 -0
- package/src/model/writer.d.ts +726 -0
- package/src/model/writer.js +6 -4
- package/src/view/attributeelement.d.ts +108 -0
- package/src/view/attributeelement.js +25 -69
- package/src/view/containerelement.d.ts +49 -0
- package/src/view/containerelement.js +10 -43
- package/src/view/datatransfer.d.ts +75 -0
- package/src/view/document.d.ts +184 -0
- package/src/view/document.js +15 -84
- package/src/view/documentfragment.d.ts +150 -0
- package/src/view/documentfragment.js +40 -81
- package/src/view/documentselection.d.ts +219 -0
- package/src/view/documentselection.js +75 -121
- package/src/view/domconverter.d.ts +620 -0
- package/src/view/domconverter.js +159 -276
- package/src/view/downcastwriter.d.ts +804 -0
- package/src/view/downcastwriter.js +336 -380
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +466 -0
- package/src/view/element.js +150 -222
- package/src/view/elementdefinition.d.ts +87 -0
- package/src/view/emptyelement.d.ts +41 -0
- package/src/view/emptyelement.js +11 -44
- package/src/view/filler.d.ts +111 -0
- package/src/view/filler.js +24 -21
- package/src/view/item.d.ts +14 -0
- package/src/view/matcher.d.ts +486 -0
- package/src/view/matcher.js +247 -218
- package/src/view/node.d.ts +160 -0
- package/src/view/node.js +26 -100
- package/src/view/observer/arrowkeysobserver.d.ts +41 -0
- package/src/view/observer/arrowkeysobserver.js +0 -13
- package/src/view/observer/bubblingemittermixin.d.ts +166 -0
- package/src/view/observer/bubblingemittermixin.js +36 -25
- package/src/view/observer/bubblingeventinfo.d.ts +47 -0
- package/src/view/observer/bubblingeventinfo.js +3 -29
- package/src/view/observer/clickobserver.d.ts +43 -0
- package/src/view/observer/clickobserver.js +9 -19
- package/src/view/observer/compositionobserver.d.ts +82 -0
- package/src/view/observer/compositionobserver.js +13 -42
- package/src/view/observer/domeventdata.d.ts +50 -0
- package/src/view/observer/domeventdata.js +5 -30
- package/src/view/observer/domeventobserver.d.ts +69 -0
- package/src/view/observer/domeventobserver.js +19 -21
- package/src/view/observer/fakeselectionobserver.d.ts +46 -0
- package/src/view/observer/fakeselectionobserver.js +2 -15
- package/src/view/observer/focusobserver.d.ts +82 -0
- package/src/view/observer/focusobserver.js +14 -40
- package/src/view/observer/inputobserver.d.ts +86 -0
- package/src/view/observer/inputobserver.js +18 -64
- package/src/view/observer/keyobserver.d.ts +67 -0
- package/src/view/observer/keyobserver.js +8 -42
- package/src/view/observer/mouseobserver.d.ts +89 -0
- package/src/view/observer/mouseobserver.js +8 -28
- package/src/view/observer/mutationobserver.d.ts +82 -0
- package/src/view/observer/mutationobserver.js +7 -37
- package/src/view/observer/observer.d.ts +84 -0
- package/src/view/observer/observer.js +12 -25
- package/src/view/observer/selectionobserver.d.ts +143 -0
- package/src/view/observer/selectionobserver.js +9 -99
- package/src/view/observer/tabobserver.d.ts +42 -0
- package/src/view/observer/tabobserver.js +0 -14
- package/src/view/placeholder.d.ts +85 -0
- package/src/view/placeholder.js +26 -43
- package/src/view/position.d.ts +189 -0
- package/src/view/position.js +36 -83
- package/src/view/range.d.ts +279 -0
- package/src/view/range.js +79 -122
- package/src/view/rawelement.d.ts +73 -0
- package/src/view/rawelement.js +34 -48
- package/src/view/renderer.d.ts +265 -0
- package/src/view/renderer.js +105 -193
- package/src/view/rooteditableelement.d.ts +41 -0
- package/src/view/rooteditableelement.js +12 -40
- package/src/view/selection.d.ts +375 -0
- package/src/view/selection.js +79 -153
- package/src/view/styles/background.d.ts +33 -0
- package/src/view/styles/background.js +14 -12
- package/src/view/styles/border.d.ts +43 -0
- package/src/view/styles/border.js +58 -48
- package/src/view/styles/margin.d.ts +29 -0
- package/src/view/styles/margin.js +13 -11
- package/src/view/styles/padding.d.ts +29 -0
- package/src/view/styles/padding.js +13 -11
- package/src/view/styles/utils.d.ts +93 -0
- package/src/view/styles/utils.js +22 -48
- package/src/view/stylesmap.d.ts +675 -0
- package/src/view/stylesmap.js +249 -244
- package/src/view/text.d.ts +74 -0
- package/src/view/text.js +16 -46
- package/src/view/textproxy.d.ts +97 -0
- package/src/view/textproxy.js +10 -59
- package/src/view/treewalker.d.ts +195 -0
- package/src/view/treewalker.js +43 -106
- package/src/view/typecheckable.d.ts +401 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +28 -62
- package/src/view/upcastwriter.d.ts +328 -0
- package/src/view/upcastwriter.js +124 -134
- package/src/view/view.d.ts +327 -0
- package/src/view/view.js +79 -150
package/src/dev-utils/view.js
CHANGED
|
@@ -44,26 +44,24 @@ const domConverterStub = {
|
|
|
44
44
|
/**
|
|
45
45
|
* Writes the content of the {@link module:engine/view/document~Document document} to an HTML-like string.
|
|
46
46
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param {Object} [options]
|
|
49
|
-
* @param {Boolean} [options.withoutSelection=false] Whether to write the selection. When set to `true`, the selection will
|
|
47
|
+
* @param options.withoutSelection Whether to write the selection. When set to `true`, the selection will
|
|
50
48
|
* not be included in the returned string.
|
|
51
|
-
* @param
|
|
49
|
+
* @param options.rootName The name of the root from which the data should be stringified. If not provided,
|
|
52
50
|
* the default `main` name will be used.
|
|
53
|
-
* @param
|
|
51
|
+
* @param options.showType When set to `true`, the type of elements will be printed (`<container:p>`
|
|
54
52
|
* instead of `<p>`, `<attribute:b>` instead of `<b>` and `<empty:img>` instead of `<img>`).
|
|
55
|
-
* @param
|
|
53
|
+
* @param options.showPriority When set to `true`, the attribute element's priority will be printed
|
|
56
54
|
* (`<span view-priority="12">`, `<b view-priority="10">`).
|
|
57
|
-
* @param
|
|
55
|
+
* @param options.showAttributeElementId When set to `true`, the attribute element's ID will be printed
|
|
58
56
|
* (`<span id="marker:foo">`).
|
|
59
|
-
* @param
|
|
57
|
+
* @param options.renderUIElements When set to `true`, the inner content of each
|
|
60
58
|
* {@link module:engine/view/uielement~UIElement} will be printed.
|
|
61
|
-
* @param
|
|
59
|
+
* @param options.renderRawElements When set to `true`, the inner content of each
|
|
62
60
|
* {@link module:engine/view/rawelement~RawElement} will be printed.
|
|
63
|
-
* @param
|
|
61
|
+
* @param options.domConverter When set to an actual {@link module:engine/view/domconverter~DomConverter DomConverter}
|
|
64
62
|
* instance, it lets the conversion go through exactly the same flow the editing view is going through,
|
|
65
63
|
* i.e. with view data filtering. Otherwise the simple stub is used.
|
|
66
|
-
* @returns
|
|
64
|
+
* @returns The stringified data.
|
|
67
65
|
*/
|
|
68
66
|
export function getData(view, options = {}) {
|
|
69
67
|
if (!(view instanceof View)) {
|
|
@@ -90,10 +88,8 @@ getData._stringify = stringify;
|
|
|
90
88
|
/**
|
|
91
89
|
* Sets the content of a view {@link module:engine/view/document~Document document} provided as an HTML-like string.
|
|
92
90
|
*
|
|
93
|
-
* @param
|
|
94
|
-
* @param
|
|
95
|
-
* @param {Object} options
|
|
96
|
-
* @param {String} [options.rootName='main'] The root name where parsed data will be stored. If not provided,
|
|
91
|
+
* @param data An HTML-like string to write into the document.
|
|
92
|
+
* @param options.rootName The root name where parsed data will be stored. If not provided,
|
|
97
93
|
* the default `main` name will be used.
|
|
98
94
|
*/
|
|
99
95
|
export function setData(view, data, options = {}) {
|
|
@@ -117,46 +113,56 @@ setData._parse = parse;
|
|
|
117
113
|
*
|
|
118
114
|
* A root element can be provided as {@link module:engine/view/text~Text text}:
|
|
119
115
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
118
|
+
* stringify( text ); // 'foobar'
|
|
119
|
+
* ```
|
|
122
120
|
*
|
|
123
121
|
* or as an {@link module:engine/view/element~Element element}:
|
|
124
122
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* const element = downcastWriter.createElement( 'p', null, downcastWriter.createText( 'foobar' ) );
|
|
125
|
+
* stringify( element ); // '<p>foobar</p>'
|
|
126
|
+
* ```
|
|
127
127
|
*
|
|
128
128
|
* or as a {@link module:engine/view/documentfragment~DocumentFragment document fragment}:
|
|
129
129
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
132
|
+
* const b = downcastWriter.createElement( 'b', { name: 'test' }, text );
|
|
133
|
+
* const p = downcastWriter.createElement( 'p', { style: 'color:red;' } );
|
|
134
|
+
* const fragment = downcastWriter.createDocumentFragment( [ p, b ] );
|
|
134
135
|
*
|
|
135
|
-
*
|
|
136
|
+
* stringify( fragment ); // '<p style="color:red;"></p><b name="test">foobar</b>'
|
|
137
|
+
* ```
|
|
136
138
|
*
|
|
137
139
|
* Additionally, a {@link module:engine/view/documentselection~DocumentSelection selection} instance can be provided.
|
|
138
140
|
* Ranges from the selection will then be included in the output data.
|
|
139
141
|
* If a range position is placed inside the element node, it will be represented with `[` and `]`:
|
|
140
142
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
145
|
+
* const b = downcastWriter.createElement( 'b', null, text );
|
|
146
|
+
* const p = downcastWriter.createElement( 'p', null, b );
|
|
147
|
+
* const selection = downcastWriter.createSelection(
|
|
148
|
+
* downcastWriter.createRangeIn( p )
|
|
149
|
+
* );
|
|
147
150
|
*
|
|
148
|
-
*
|
|
151
|
+
* stringify( p, selection ); // '<p>[<b>foobar</b>]</p>'
|
|
152
|
+
* ```
|
|
149
153
|
*
|
|
150
154
|
* If a range is placed inside the text node, it will be represented with `{` and `}`:
|
|
151
155
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
158
|
+
* const b = downcastWriter.createElement( 'b', null, text );
|
|
159
|
+
* const p = downcastWriter.createElement( 'p', null, b );
|
|
160
|
+
* const selection = downcastWriter.createSelection(
|
|
161
|
+
* downcastWriter.createRange( downcastWriter.createPositionAt( text, 1 ), downcastWriter.createPositionAt( text, 5 ) )
|
|
162
|
+
* );
|
|
158
163
|
*
|
|
159
|
-
*
|
|
164
|
+
* stringify( p, selection ); // '<p><b>f{ooba}r</b></p>'
|
|
165
|
+
* ```
|
|
160
166
|
*
|
|
161
167
|
* ** Note: **
|
|
162
168
|
* It is possible to unify selection markers to `[` and `]` for both (inside and outside text)
|
|
@@ -165,25 +171,29 @@ setData._parse = parse;
|
|
|
165
171
|
*
|
|
166
172
|
* Multiple ranges are supported:
|
|
167
173
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
176
|
+
* const selection = downcastWriter.createSelection( [
|
|
177
|
+
* downcastWriter.createRange( downcastWriter.createPositionAt( text, 0 ), downcastWriter.createPositionAt( text, 1 ) ),
|
|
178
|
+
* downcastWriter.createRange( downcastWriter.createPositionAt( text, 3 ), downcastWriter.createPositionAt( text, 5 ) )
|
|
179
|
+
* ] );
|
|
173
180
|
*
|
|
174
|
-
*
|
|
181
|
+
* stringify( text, selection ); // '{f}oo{ba}r'
|
|
182
|
+
* ```
|
|
175
183
|
*
|
|
176
184
|
* A {@link module:engine/view/range~Range range} or {@link module:engine/view/position~Position position} instance can be provided
|
|
177
185
|
* instead of the {@link module:engine/view/documentselection~DocumentSelection selection} instance. If a range instance
|
|
178
186
|
* is provided, it will be converted to a selection containing this range. If a position instance is provided, it will
|
|
179
187
|
* be converted to a selection containing one range collapsed at this position.
|
|
180
188
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* const text = downcastWriter.createText( 'foobar' );
|
|
191
|
+
* const range = downcastWriter.createRange( downcastWriter.createPositionAt( text, 0 ), downcastWriter.createPositionAt( text, 1 ) );
|
|
192
|
+
* const position = downcastWriter.createPositionAt( text, 3 );
|
|
184
193
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
194
|
+
* stringify( text, range ); // '{f}oobar'
|
|
195
|
+
* stringify( text, position ); // 'foo{}bar'
|
|
196
|
+
* ```
|
|
187
197
|
*
|
|
188
198
|
* An additional `options` object can be provided.
|
|
189
199
|
* If `options.showType` is set to `true`, element's types will be
|
|
@@ -192,55 +202,58 @@ setData._parse = parse;
|
|
|
192
202
|
* {@link module:engine/view/emptyelement~EmptyElement empty elements}
|
|
193
203
|
* and {@link module:engine/view/uielement~UIElement UI elements}:
|
|
194
204
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
205
|
+
* ```ts
|
|
206
|
+
* const attribute = downcastWriter.createAttributeElement( 'b' );
|
|
207
|
+
* const container = downcastWriter.createContainerElement( 'p' );
|
|
208
|
+
* const empty = downcastWriter.createEmptyElement( 'img' );
|
|
209
|
+
* const ui = downcastWriter.createUIElement( 'span' );
|
|
210
|
+
* getData( attribute, null, { showType: true } ); // '<attribute:b></attribute:b>'
|
|
211
|
+
* getData( container, null, { showType: true } ); // '<container:p></container:p>'
|
|
212
|
+
* getData( empty, null, { showType: true } ); // '<empty:img></empty:img>'
|
|
213
|
+
* getData( ui, null, { showType: true } ); // '<ui:span></ui:span>'
|
|
214
|
+
* ```
|
|
203
215
|
*
|
|
204
216
|
* If `options.showPriority` is set to `true`, a priority will be displayed for all
|
|
205
217
|
* {@link module:engine/view/attributeelement~AttributeElement attribute elements}.
|
|
206
218
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* const attribute = downcastWriter.createAttributeElement( 'b' );
|
|
221
|
+
* attribute._priority = 20;
|
|
222
|
+
* getData( attribute, null, { showPriority: true } ); // <b view-priority="20"></b>
|
|
223
|
+
* ```
|
|
210
224
|
*
|
|
211
225
|
* If `options.showAttributeElementId` is set to `true`, the attribute element's id will be displayed for all
|
|
212
226
|
* {@link module:engine/view/attributeelement~AttributeElement attribute elements} that have it set.
|
|
213
227
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* @param
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* @param
|
|
226
|
-
* @param {Boolean} [options.showType=false] When set to `true`, the type of elements will be printed (`<container:p>`
|
|
228
|
+
* ```ts
|
|
229
|
+
* const attribute = downcastWriter.createAttributeElement( 'span' );
|
|
230
|
+
* attribute._id = 'marker:foo';
|
|
231
|
+
* getData( attribute, null, { showAttributeElementId: true } ); // <span view-id="marker:foo"></span>
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @param node The node to stringify.
|
|
235
|
+
* @param selectionOrPositionOrRange A selection instance whose ranges will be included in the returned string data.
|
|
236
|
+
* If a range instance is provided, it will be converted to a selection containing this range. If a position instance
|
|
237
|
+
* is provided, it will be converted to a selection containing one range collapsed at this position.
|
|
238
|
+
* @param options An object with additional options.
|
|
239
|
+
* @param options.showType When set to `true`, the type of elements will be printed (`<container:p>`
|
|
227
240
|
* instead of `<p>`, `<attribute:b>` instead of `<b>` and `<empty:img>` instead of `<img>`).
|
|
228
|
-
* @param
|
|
241
|
+
* @param options.showPriority When set to `true`, the attribute element's priority will be printed
|
|
229
242
|
* (`<span view-priority="12">`, `<b view-priority="10">`).
|
|
230
|
-
* @param
|
|
243
|
+
* @param options.showAttributeElementId When set to `true`, attribute element's id will be printed
|
|
231
244
|
* (`<span id="marker:foo">`).
|
|
232
|
-
* @param
|
|
245
|
+
* @param options.ignoreRoot When set to `true`, the root's element opening and closing will not be printed.
|
|
233
246
|
* Mainly used by the `getData` function to ignore the {@link module:engine/view/document~Document document's} root element.
|
|
234
|
-
* @param
|
|
247
|
+
* @param options.sameSelectionCharacters When set to `true`, the selection inside the text will be marked as
|
|
235
248
|
* `{` and `}` and the selection outside the text as `[` and `]`. When set to `false`, both will be marked as `[` and `]` only.
|
|
236
|
-
* @param
|
|
249
|
+
* @param options.renderUIElements When set to `true`, the inner content of each
|
|
237
250
|
* {@link module:engine/view/uielement~UIElement} will be printed.
|
|
238
|
-
* @param
|
|
251
|
+
* @param options.renderRawElements When set to `true`, the inner content of each
|
|
239
252
|
* {@link module:engine/view/rawelement~RawElement} will be printed.
|
|
240
|
-
* @param
|
|
253
|
+
* @param options.domConverter When set to an actual {@link module:engine/view/domconverter~DomConverter DomConverter}
|
|
241
254
|
* instance, it lets the conversion go through exactly the same flow the editing view is going through,
|
|
242
255
|
* i.e. with view data filtering. Otherwise the simple stub is used.
|
|
243
|
-
* @returns
|
|
256
|
+
* @returns An HTML-like string representing the view.
|
|
244
257
|
*/
|
|
245
258
|
export function stringify(node, selectionOrPositionOrRange = null, options = {}) {
|
|
246
259
|
let selection;
|
|
@@ -258,26 +271,36 @@ export function stringify(node, selectionOrPositionOrRange = null, options = {})
|
|
|
258
271
|
* Parses an HTML-like string and returns a view tree.
|
|
259
272
|
* A simple string will be converted to a {@link module:engine/view/text~Text text} node:
|
|
260
273
|
*
|
|
261
|
-
*
|
|
274
|
+
* ```ts
|
|
275
|
+
* parse( 'foobar' ); // Returns an instance of text.
|
|
276
|
+
* ```
|
|
262
277
|
*
|
|
263
278
|
* {@link module:engine/view/element~Element Elements} will be parsed with attributes as children:
|
|
264
279
|
*
|
|
265
|
-
*
|
|
280
|
+
* ```ts
|
|
281
|
+
* parse( '<b name="baz">foobar</b>' ); // Returns an instance of element with the `baz` attribute and a text child node.
|
|
282
|
+
* ```
|
|
266
283
|
*
|
|
267
284
|
* Multiple nodes provided on root level will be converted to a
|
|
268
285
|
* {@link module:engine/view/documentfragment~DocumentFragment document fragment}:
|
|
269
286
|
*
|
|
270
|
-
*
|
|
287
|
+
* ```ts
|
|
288
|
+
* parse( '<b>foo</b><i>bar</i>' ); // Returns a document fragment with two child elements.
|
|
289
|
+
* ```
|
|
271
290
|
*
|
|
272
291
|
* The method can parse multiple {@link module:engine/view/range~Range ranges} provided in string data and return a
|
|
273
292
|
* {@link module:engine/view/documentselection~DocumentSelection selection} instance containing these ranges. Ranges placed inside
|
|
274
293
|
* {@link module:engine/view/text~Text text} nodes should be marked using `{` and `}` brackets:
|
|
275
294
|
*
|
|
276
|
-
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* const { text, selection } = parse( 'f{ooba}r' );
|
|
297
|
+
* ```
|
|
277
298
|
*
|
|
278
299
|
* Ranges placed outside text nodes should be marked using `[` and `]` brackets:
|
|
279
300
|
*
|
|
280
|
-
*
|
|
301
|
+
* ```ts
|
|
302
|
+
* const { root, selection } = parse( '<p>[<b>foobar</b>]</p>' );
|
|
303
|
+
* ```
|
|
281
304
|
*
|
|
282
305
|
* ** Note: **
|
|
283
306
|
* It is possible to unify selection markers to `[` and `]` for both (inside and outside text)
|
|
@@ -286,7 +309,9 @@ export function stringify(node, selectionOrPositionOrRange = null, options = {})
|
|
|
286
309
|
* Sometimes there is a need for defining the order of ranges inside the created selection. This can be achieved by providing
|
|
287
310
|
* the range order array as an additional parameter:
|
|
288
311
|
*
|
|
289
|
-
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* const { root, selection } = parse( '{fo}ob{ar}{ba}z', { order: [ 2, 3, 1 ] } );
|
|
314
|
+
* ```
|
|
290
315
|
*
|
|
291
316
|
* In the example above, the first range (`{fo}`) will be added to the selection as the second one, the second range (`{ar}`) will be
|
|
292
317
|
* added as the third and the third range (`{ba}`) will be added as the first one.
|
|
@@ -296,38 +321,39 @@ export function stringify(node, selectionOrPositionOrRange = null, options = {})
|
|
|
296
321
|
* by the `end` position and {@link module:engine/view/documentselection~DocumentSelection#focus selection focus} is
|
|
297
322
|
* represented by the `start` position), use the `lastRangeBackward` flag:
|
|
298
323
|
*
|
|
299
|
-
*
|
|
324
|
+
* ```ts
|
|
325
|
+
* const { root, selection } = parse( `{foo}bar{baz}`, { lastRangeBackward: true } );
|
|
326
|
+
* ```
|
|
300
327
|
*
|
|
301
328
|
* Some more examples and edge cases:
|
|
302
329
|
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
330
|
+
* ```ts
|
|
331
|
+
* // Returns an empty document fragment.
|
|
332
|
+
* parse( '' );
|
|
305
333
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
334
|
+
* // Returns an empty document fragment and a collapsed selection.
|
|
335
|
+
* const { root, selection } = parse( '[]' );
|
|
308
336
|
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
337
|
+
* // Returns an element and a selection that is placed inside the document fragment containing that element.
|
|
338
|
+
* const { root, selection } = parse( '[<a></a>]' );
|
|
339
|
+
* ```
|
|
311
340
|
*
|
|
312
|
-
* @param
|
|
313
|
-
* @param
|
|
314
|
-
* @param {Array.<Number>} [options.order] An array with the order of parsed ranges added to the returned
|
|
341
|
+
* @param data An HTML-like string to be parsed.
|
|
342
|
+
* @param options.order An array with the order of parsed ranges added to the returned
|
|
315
343
|
* {@link module:engine/view/documentselection~DocumentSelection Selection} instance. Each element should represent the
|
|
316
344
|
* desired position of each range in the selection instance. For example: `[2, 3, 1]` means that the first range will be
|
|
317
345
|
* placed as the second, the second as the third and the third as the first.
|
|
318
|
-
* @param
|
|
346
|
+
* @param options.lastRangeBackward If set to `true`, the last range will be added as backward to the returned
|
|
319
347
|
* {@link module:engine/view/documentselection~DocumentSelection selection} instance.
|
|
320
|
-
* @param
|
|
321
|
-
* [options.rootElement=null] The default root to use when parsing elements.
|
|
348
|
+
* @param options.rootElement The default root to use when parsing elements.
|
|
322
349
|
* When set to `null`, the root element will be created automatically. If set to
|
|
323
350
|
* {@link module:engine/view/element~Element Element} or {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment},
|
|
324
351
|
* this node will be used as the root for all parsed nodes.
|
|
325
|
-
* @param
|
|
352
|
+
* @param options.sameSelectionCharacters When set to `false`, the selection inside the text should be marked using
|
|
326
353
|
* `{` and `}` and the selection outside the ext using `[` and `]`. When set to `true`, both should be marked with `[` and `]` only.
|
|
327
|
-
* @param
|
|
328
|
-
* @returns
|
|
329
|
-
*
|
|
330
|
-
* to parse.
|
|
354
|
+
* @param options.stylesProcessor Styles processor.
|
|
355
|
+
* @returns Returns the parsed view node or an object with two fields: `view` and `selection` when selection ranges were included in the
|
|
356
|
+
* data to parse.
|
|
331
357
|
*/
|
|
332
358
|
export function parse(data, options = {}) {
|
|
333
359
|
const viewDocument = new ViewDocument(new StylesProcessor());
|
|
@@ -373,15 +399,13 @@ export function parse(data, options = {}) {
|
|
|
373
399
|
}
|
|
374
400
|
/**
|
|
375
401
|
* Private helper class used for converting ranges represented as text inside view {@link module:engine/view/text~Text text nodes}.
|
|
376
|
-
*
|
|
377
|
-
* @private
|
|
378
402
|
*/
|
|
379
403
|
class RangeParser {
|
|
380
404
|
/**
|
|
381
405
|
* Creates a range parser instance.
|
|
382
406
|
*
|
|
383
|
-
* @param
|
|
384
|
-
* @param
|
|
407
|
+
* @param options The range parser configuration.
|
|
408
|
+
* @param options.sameSelectionCharacters When set to `true`, the selection inside the text is marked as
|
|
385
409
|
* `{` and `}` and the selection outside the text as `[` and `]`. When set to `false`, both are marked as `[` and `]`.
|
|
386
410
|
*/
|
|
387
411
|
constructor(options) {
|
|
@@ -392,11 +416,11 @@ class RangeParser {
|
|
|
392
416
|
* The method will remove all occurrences of `{`, `}`, `[` and `]` from found text nodes. If a text node is empty after
|
|
393
417
|
* the process, it will be removed, too.
|
|
394
418
|
*
|
|
395
|
-
* @param
|
|
396
|
-
* @param
|
|
419
|
+
* @param node The starting node.
|
|
420
|
+
* @param order The order of ranges. Each element should represent the desired position of the range after
|
|
397
421
|
* sorting. For example: `[2, 3, 1]` means that the first range will be placed as the second, the second as the third and the third
|
|
398
422
|
* as the first.
|
|
399
|
-
* @returns
|
|
423
|
+
* @returns An array with ranges found.
|
|
400
424
|
*/
|
|
401
425
|
parse(node, order) {
|
|
402
426
|
this._positions = [];
|
|
@@ -417,8 +441,7 @@ class RangeParser {
|
|
|
417
441
|
* Gathers positions of brackets inside the view tree starting from the provided node. The method will remove all occurrences of
|
|
418
442
|
* `{`, `}`, `[` and `]` from found text nodes. If a text node is empty after the process, it will be removed, too.
|
|
419
443
|
*
|
|
420
|
-
* @
|
|
421
|
-
* @param {module:engine/view/node~Node} node Staring node.
|
|
444
|
+
* @param node Staring node.
|
|
422
445
|
*/
|
|
423
446
|
_getPositions(node) {
|
|
424
447
|
if (node.is('documentFragment') || node.is('element')) {
|
|
@@ -500,10 +523,9 @@ class RangeParser {
|
|
|
500
523
|
* For example: `[2, 3, 1]` means that the first range will be placed as the second, the second as the third and the third
|
|
501
524
|
* as the first.
|
|
502
525
|
*
|
|
503
|
-
* @
|
|
504
|
-
* @param
|
|
505
|
-
* @
|
|
506
|
-
* @returns {Array} Sorted ranges array.
|
|
526
|
+
* @param ranges Ranges to sort.
|
|
527
|
+
* @param rangesOrder An array with new range order.
|
|
528
|
+
* @returns Sorted ranges array.
|
|
507
529
|
*/
|
|
508
530
|
_sortRanges(ranges, rangesOrder) {
|
|
509
531
|
const sortedRanges = [];
|
|
@@ -519,9 +541,6 @@ class RangeParser {
|
|
|
519
541
|
}
|
|
520
542
|
/**
|
|
521
543
|
* Uses all found bracket positions to create ranges from them.
|
|
522
|
-
*
|
|
523
|
-
* @private
|
|
524
|
-
* @returns {Array.<module:engine/view/range~Range>}
|
|
525
544
|
*/
|
|
526
545
|
_createRanges() {
|
|
527
546
|
const ranges = [];
|
|
@@ -554,28 +573,24 @@ class RangeParser {
|
|
|
554
573
|
}
|
|
555
574
|
/**
|
|
556
575
|
* Private helper class used for converting the view tree to a string.
|
|
557
|
-
*
|
|
558
|
-
* @private
|
|
559
576
|
*/
|
|
560
577
|
class ViewStringify {
|
|
561
578
|
/**
|
|
562
579
|
* Creates a view stringify instance.
|
|
563
580
|
*
|
|
564
|
-
* @param
|
|
565
|
-
* @param
|
|
566
|
-
*
|
|
567
|
-
* @param {Object} options An options object.
|
|
568
|
-
* @param {Boolean} [options.showType=false] When set to `true`, the type of elements will be printed (`<container:p>`
|
|
581
|
+
* @param selection A selection whose ranges should also be converted to a string.
|
|
582
|
+
* @param options An options object.
|
|
583
|
+
* @param options.showType When set to `true`, the type of elements will be printed (`<container:p>`
|
|
569
584
|
* instead of `<p>`, `<attribute:b>` instead of `<b>` and `<empty:img>` instead of `<img>`).
|
|
570
|
-
* @param
|
|
571
|
-
* @param
|
|
585
|
+
* @param options.showPriority When set to `true`, the attribute element's priority will be printed.
|
|
586
|
+
* @param options.ignoreRoot When set to `true`, the root's element opening and closing tag will not
|
|
572
587
|
* be outputted.
|
|
573
|
-
* @param
|
|
588
|
+
* @param options.sameSelectionCharacters When set to `true`, the selection inside the text is marked as
|
|
574
589
|
* `{` and `}` and the selection outside the text as `[` and `]`. When set to `false`, both are marked as `[` and `]`.
|
|
575
|
-
* @param
|
|
590
|
+
* @param options.renderUIElements When set to `true`, the inner content of each
|
|
576
591
|
* {@link module:engine/view/uielement~UIElement} will be printed.
|
|
577
|
-
* @param
|
|
578
|
-
* @param
|
|
592
|
+
* @param options.renderRawElements When set to `true`, the inner content of each
|
|
593
|
+
* @param options.domConverter When set to an actual {@link module:engine/view/domconverter~DomConverter DomConverter}
|
|
579
594
|
* instance, it lets the conversion go through exactly the same flow the editing view is going through,
|
|
580
595
|
* i.e. with view data filtering. Otherwise the simple stub is used.
|
|
581
596
|
* {@link module:engine/view/rawelement~RawElement} will be printed.
|
|
@@ -599,7 +614,7 @@ class ViewStringify {
|
|
|
599
614
|
/**
|
|
600
615
|
* Converts the view to a string.
|
|
601
616
|
*
|
|
602
|
-
* @returns
|
|
617
|
+
* @returns String representation of the view elements.
|
|
603
618
|
*/
|
|
604
619
|
stringify() {
|
|
605
620
|
let result = '';
|
|
@@ -611,10 +626,6 @@ class ViewStringify {
|
|
|
611
626
|
/**
|
|
612
627
|
* Executes a simple walker that iterates over all elements in the view tree starting from the root element.
|
|
613
628
|
* Calls the `callback` with parsed chunks of string data.
|
|
614
|
-
*
|
|
615
|
-
* @private
|
|
616
|
-
* @param {module:engine/view/documentfragment~DocumentFragment|module:engine/view/element~Element|module:engine/view/text~Text} root
|
|
617
|
-
* @param {Function} callback
|
|
618
629
|
*/
|
|
619
630
|
_walkView(root, callback) {
|
|
620
631
|
const ignore = this.ignoreRoot && this.root === root;
|
|
@@ -652,10 +663,6 @@ class ViewStringify {
|
|
|
652
663
|
/**
|
|
653
664
|
* Checks if a given {@link module:engine/view/element~Element element} has a {@link module:engine/view/range~Range#start range start}
|
|
654
665
|
* or a {@link module:engine/view/range~Range#start range end} placed at a given offset and returns its string representation.
|
|
655
|
-
*
|
|
656
|
-
* @private
|
|
657
|
-
* @param {module:engine/view/element~Element} element
|
|
658
|
-
* @param {Number} offset
|
|
659
666
|
*/
|
|
660
667
|
_stringifyElementRanges(element, offset) {
|
|
661
668
|
let start = '';
|
|
@@ -681,9 +688,6 @@ class ViewStringify {
|
|
|
681
688
|
* {@link module:engine/view/range~Range#start range start} or a
|
|
682
689
|
* {@link module:engine/view/range~Range#start range end} placed somewhere inside. Returns a string representation of text
|
|
683
690
|
* with range delimiters placed inside.
|
|
684
|
-
*
|
|
685
|
-
* @private
|
|
686
|
-
* @param {module:engine/view/text~Text} node
|
|
687
691
|
*/
|
|
688
692
|
_stringifyTextRanges(node) {
|
|
689
693
|
const length = node.data.length;
|
|
@@ -732,10 +736,6 @@ class ViewStringify {
|
|
|
732
736
|
* `<attribute:a>` or `<empty:img>`), contain priority information ( `<attribute:a view-priority="20">` ),
|
|
733
737
|
* or contain element id ( `<attribute:span view-id="foo">` ). Element attributes will also be included
|
|
734
738
|
* (`<a href="https://ckeditor.com" name="foobar">`).
|
|
735
|
-
*
|
|
736
|
-
* @private
|
|
737
|
-
* @param {module:engine/view/element~Element} element
|
|
738
|
-
* @returns {String}
|
|
739
739
|
*/
|
|
740
740
|
_stringifyElementOpen(element) {
|
|
741
741
|
const priority = this._stringifyElementPriority(element);
|
|
@@ -750,10 +750,6 @@ class ViewStringify {
|
|
|
750
750
|
* Converts the passed {@link module:engine/view/element~Element element} to a closing tag.
|
|
751
751
|
* Depending on the current configuration, the closing tag can be simple (`</a>`) or contain a type prefix (`</container:p>`,
|
|
752
752
|
* `</attribute:a>` or `</empty:img>`).
|
|
753
|
-
*
|
|
754
|
-
* @private
|
|
755
|
-
* @param {module:engine/view/element~Element} element
|
|
756
|
-
* @returns {String}
|
|
757
753
|
*/
|
|
758
754
|
_stringifyElementClose(element) {
|
|
759
755
|
const type = this._stringifyElementType(element);
|
|
@@ -770,10 +766,6 @@ class ViewStringify {
|
|
|
770
766
|
* * 'ui' for {@link module:engine/view/uielement~UIElement UI elements},
|
|
771
767
|
* * 'raw' for {@link module:engine/view/rawelement~RawElement raw elements},
|
|
772
768
|
* * an empty string when the current configuration is preventing showing elements' types.
|
|
773
|
-
*
|
|
774
|
-
* @private
|
|
775
|
-
* @param {module:engine/view/element~Element} element
|
|
776
|
-
* @returns {String}
|
|
777
769
|
*/
|
|
778
770
|
_stringifyElementType(element) {
|
|
779
771
|
if (this.showType) {
|
|
@@ -791,10 +783,6 @@ class ViewStringify {
|
|
|
791
783
|
* The priority string representation will be returned when the passed element is an instance of
|
|
792
784
|
* {@link module:engine/view/attributeelement~AttributeElement attribute element} and the current configuration allows to show the
|
|
793
785
|
* priority. Otherwise returns an empty string.
|
|
794
|
-
*
|
|
795
|
-
* @private
|
|
796
|
-
* @param {module:engine/view/element~Element} element
|
|
797
|
-
* @returns {String}
|
|
798
786
|
*/
|
|
799
787
|
_stringifyElementPriority(element) {
|
|
800
788
|
if (this.showPriority && element.is('attributeElement')) {
|
|
@@ -808,10 +796,6 @@ class ViewStringify {
|
|
|
808
796
|
* The id string representation will be returned when the passed element is an instance of
|
|
809
797
|
* {@link module:engine/view/attributeelement~AttributeElement attribute element}, the element has an id
|
|
810
798
|
* and the current configuration allows to show the id. Otherwise returns an empty string.
|
|
811
|
-
*
|
|
812
|
-
* @private
|
|
813
|
-
* @param {module:engine/view/element~Element} element
|
|
814
|
-
* @returns {String}
|
|
815
799
|
*/
|
|
816
800
|
_stringifyElementId(element) {
|
|
817
801
|
if (this.showAttributeElementId && element.is('attributeElement') && element.id) {
|
|
@@ -822,10 +806,6 @@ class ViewStringify {
|
|
|
822
806
|
/**
|
|
823
807
|
* Converts the passed {@link module:engine/view/element~Element element} attributes to their string representation.
|
|
824
808
|
* If an element has no attributes, an empty string is returned.
|
|
825
|
-
*
|
|
826
|
-
* @private
|
|
827
|
-
* @param {module:engine/view/element~Element} element
|
|
828
|
-
* @returns {String}
|
|
829
809
|
*/
|
|
830
810
|
_stringifyElementAttributes(element) {
|
|
831
811
|
const attributes = [];
|
|
@@ -851,18 +831,18 @@ class ViewStringify {
|
|
|
851
831
|
return attributes.join(' ');
|
|
852
832
|
}
|
|
853
833
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
834
|
+
/**
|
|
835
|
+
* Converts {@link module:engine/view/element~Element elements} to
|
|
836
|
+
* {@link module:engine/view/attributeelement~AttributeElement attribute elements},
|
|
837
|
+
* {@link module:engine/view/containerelement~ContainerElement container elements},
|
|
838
|
+
* {@link module:engine/view/emptyelement~EmptyElement empty elements} or
|
|
839
|
+
* {@link module:engine/view/uielement~UIElement UI elements}.
|
|
840
|
+
* It converts the whole tree starting from the `rootNode`. The conversion is based on element names.
|
|
841
|
+
* See the `_convertElement` method for more details.
|
|
842
|
+
*
|
|
843
|
+
* @param rootNode The root node to convert.
|
|
844
|
+
* @returns The root node of converted elements.
|
|
845
|
+
*/
|
|
866
846
|
function _convertViewElements(rootNode) {
|
|
867
847
|
if (rootNode.is('element') || rootNode.is('documentFragment')) {
|
|
868
848
|
// Convert element or leave document fragment.
|
|
@@ -888,29 +868,28 @@ function _convertViewElements(rootNode) {
|
|
|
888
868
|
}
|
|
889
869
|
return rootNode;
|
|
890
870
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
// element converted according to its name.
|
|
871
|
+
/**
|
|
872
|
+
* Converts an {@link module:engine/view/element~Element element} to
|
|
873
|
+
* {@link module:engine/view/attributeelement~AttributeElement attribute element},
|
|
874
|
+
* {@link module:engine/view/containerelement~ContainerElement container element},
|
|
875
|
+
* {@link module:engine/view/emptyelement~EmptyElement empty element} or
|
|
876
|
+
* {@link module:engine/view/uielement~UIElement UI element}.
|
|
877
|
+
* If the element's name is in the format of `attribute:b`, it will be converted to
|
|
878
|
+
* an {@link module:engine/view/attributeelement~AttributeElement attribute element} with a priority of 11.
|
|
879
|
+
* Additionally, attribute elements may have specified priority (for example `view-priority="11"`) and/or
|
|
880
|
+
* id (for example `view-id="foo"`).
|
|
881
|
+
* If the element's name is in the format of `container:p`, it will be converted to
|
|
882
|
+
* a {@link module:engine/view/containerelement~ContainerElement container element}.
|
|
883
|
+
* If the element's name is in the format of `empty:img`, it will be converted to
|
|
884
|
+
* an {@link module:engine/view/emptyelement~EmptyElement empty element}.
|
|
885
|
+
* If the element's name is in the format of `ui:span`, it will be converted to
|
|
886
|
+
* a {@link module:engine/view/uielement~UIElement UI element}.
|
|
887
|
+
* If the element's name does not contain any additional information, a {@link module:engine/view/element~Element view Element} will be
|
|
888
|
+
* returned.
|
|
889
|
+
*
|
|
890
|
+
* @param viewElement A view element to convert.
|
|
891
|
+
* @returns A tree view element converted according to its name.
|
|
892
|
+
*/
|
|
914
893
|
function _convertElement(viewDocument, viewElement) {
|
|
915
894
|
const info = _convertElementNameAndInfo(viewElement);
|
|
916
895
|
const ElementConstructor = allowedTypes[info.type];
|
|
@@ -929,19 +908,21 @@ function _convertElement(viewDocument, viewElement) {
|
|
|
929
908
|
}
|
|
930
909
|
return newElement;
|
|
931
910
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
911
|
+
/**
|
|
912
|
+
* Converts the `view-priority` attribute and the {@link module:engine/view/element~Element#name element's name} information needed for
|
|
913
|
+
* creating {@link module:engine/view/attributeelement~AttributeElement attribute element},
|
|
914
|
+
* {@link module:engine/view/containerelement~ContainerElement container element},
|
|
915
|
+
* {@link module:engine/view/emptyelement~EmptyElement empty element} or
|
|
916
|
+
* {@link module:engine/view/uielement~UIElement UI element}.
|
|
917
|
+
* The name can be provided in two formats: as a simple element's name (`div`), or as a type and name (`container:div`,
|
|
918
|
+
* `attribute:span`, `empty:img`, `ui:span`);
|
|
919
|
+
*
|
|
920
|
+
* @param viewElement The element whose name should be converted.
|
|
921
|
+
* @returns An object with parsed information:
|
|
922
|
+
* * `name` The parsed name of the element.
|
|
923
|
+
* * `type` The parsed type of the element. It can be `attribute`, `container` or `empty`.
|
|
924
|
+
* * `priority` The parsed priority of the element.
|
|
925
|
+
*/
|
|
945
926
|
function _convertElementNameAndInfo(viewElement) {
|
|
946
927
|
const parts = viewElement.name.split(':');
|
|
947
928
|
const priority = _convertPriority(viewElement.getAttribute('view-priority'));
|
|
@@ -968,17 +949,15 @@ function _convertElementNameAndInfo(viewElement) {
|
|
|
968
949
|
}
|
|
969
950
|
throw new Error(`Parse error - cannot parse element's name: ${viewElement.name}.`);
|
|
970
951
|
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// @returns {String|null}
|
|
952
|
+
/**
|
|
953
|
+
* Checks if the element's type is allowed. Returns `attribute`, `container`, `empty` or `null`.
|
|
954
|
+
*/
|
|
975
955
|
function _convertType(type) {
|
|
976
956
|
return type in allowedTypes ? type : null;
|
|
977
957
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
// returns {Number|null}
|
|
958
|
+
/**
|
|
959
|
+
* Checks if a given priority is allowed. Returns null if the priority cannot be converted.
|
|
960
|
+
*/
|
|
982
961
|
function _convertPriority(priorityString) {
|
|
983
962
|
const priority = parseInt(priorityString, 10);
|
|
984
963
|
if (!isNaN(priority)) {
|