@ckeditor/ckeditor5-engine 36.0.1 → 37.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +25 -24
- package/src/controller/datacontroller.d.ts +331 -0
- package/src/controller/datacontroller.js +72 -116
- 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 +503 -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 +369 -0
- package/src/conversion/viewconsumable.js +139 -173
- 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 +108 -0
- package/src/index.js +4 -0
- package/src/model/batch.d.ts +106 -0
- package/src/model/differ.d.ts +329 -0
- package/src/model/document.d.ts +246 -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 +885 -0
- package/src/model/model.js +59 -81
- 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/mergeoperation.js +1 -1
- 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/splitoperation.js +1 -1
- package/src/model/operation/transform.d.ts +100 -0
- package/src/model/operation/utils.d.ts +71 -0
- package/src/model/operation/utils.js +1 -1
- 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 +19 -19
- 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 +285 -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 +823 -0
- package/src/model/writer.js +6 -61
- 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 +149 -0
- package/src/view/documentfragment.js +39 -81
- package/src/view/documentselection.d.ts +306 -0
- package/src/view/documentselection.js +42 -143
- package/src/view/domconverter.d.ts +650 -0
- package/src/view/domconverter.js +157 -283
- package/src/view/downcastwriter.d.ts +996 -0
- package/src/view/downcastwriter.js +259 -426
- package/src/view/editableelement.d.ts +52 -0
- package/src/view/editableelement.js +9 -49
- package/src/view/element.d.ts +468 -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 +163 -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 +43 -0
- package/src/view/observer/fakeselectionobserver.js +0 -16
- 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 +66 -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 +144 -0
- package/src/view/observer/selectionobserver.js +17 -107
- 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 +448 -0
- package/src/view/uielement.d.ts +96 -0
- package/src/view/uielement.js +29 -63
- package/src/view/upcastwriter.d.ts +417 -0
- package/src/view/upcastwriter.js +86 -157
- package/src/view/view.d.ts +417 -0
- package/src/view/view.js +47 -175
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* @module
|
|
6
|
+
* @module engine/view/downcastwriter
|
|
7
7
|
*/
|
|
8
8
|
import Position from './position';
|
|
9
9
|
import Range from './range';
|
|
@@ -30,101 +30,25 @@ import { isPlainObject } from 'lodash-es';
|
|
|
30
30
|
* To work with ordinary views (e.g. parsed from a pasted content) use the
|
|
31
31
|
* {@link module:engine/view/upcastwriter~UpcastWriter upcast writer}.
|
|
32
32
|
*
|
|
33
|
-
* Read more about changing the view in the {@glink framework/
|
|
34
|
-
* section of the {@glink framework/
|
|
33
|
+
* Read more about changing the view in the {@glink framework/architecture/editing-engine#changing-the-view Changing the view}
|
|
34
|
+
* section of the {@glink framework/architecture/editing-engine Editing engine architecture} guide.
|
|
35
35
|
*/
|
|
36
36
|
export default class DowncastWriter {
|
|
37
37
|
/**
|
|
38
|
-
* @param
|
|
38
|
+
* @param document The view document instance.
|
|
39
39
|
*/
|
|
40
40
|
constructor(document) {
|
|
41
|
-
/**
|
|
42
|
-
* The view document instance in which this writer operates.
|
|
43
|
-
*
|
|
44
|
-
* @readonly
|
|
45
|
-
* @type {module:engine/view/document~Document}
|
|
46
|
-
*/
|
|
47
|
-
this.document = document;
|
|
48
41
|
/**
|
|
49
42
|
* Holds references to the attribute groups that share the same {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
50
43
|
* The keys are `id`s, the values are `Set`s holding {@link module:engine/view/attributeelement~AttributeElement}s.
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
* @type {Map.<String,Set>}
|
|
54
44
|
*/
|
|
55
45
|
this._cloneGroups = new Map();
|
|
56
46
|
/**
|
|
57
47
|
* The slot factory used by the `elementToStructure` downcast helper.
|
|
58
|
-
*
|
|
59
|
-
* @private
|
|
60
|
-
* @type {Function|null}
|
|
61
48
|
*/
|
|
62
49
|
this._slotFactory = null;
|
|
50
|
+
this.document = document;
|
|
63
51
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Sets {@link module:engine/view/documentselection~DocumentSelection selection's} ranges and direction to the
|
|
66
|
-
* specified location based on the given {@link module:engine/view/selection~Selectable selectable}.
|
|
67
|
-
*
|
|
68
|
-
* Usage:
|
|
69
|
-
*
|
|
70
|
-
* // Sets selection to the given range.
|
|
71
|
-
* const range = writer.createRange( start, end );
|
|
72
|
-
* writer.setSelection( range );
|
|
73
|
-
*
|
|
74
|
-
* // Sets backward selection to the given range.
|
|
75
|
-
* const range = writer.createRange( start, end );
|
|
76
|
-
* writer.setSelection( range );
|
|
77
|
-
*
|
|
78
|
-
* // Sets selection to given ranges.
|
|
79
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
|
|
80
|
-
* writer.setSelection( range );
|
|
81
|
-
*
|
|
82
|
-
* // Sets selection to the other selection.
|
|
83
|
-
* const otherSelection = writer.createSelection();
|
|
84
|
-
* writer.setSelection( otherSelection );
|
|
85
|
-
*
|
|
86
|
-
* // Sets collapsed selection at the given position.
|
|
87
|
-
* const position = writer.createPositionFromPath( root, path );
|
|
88
|
-
* writer.setSelection( position );
|
|
89
|
-
*
|
|
90
|
-
* // Sets collapsed selection at the position of given item and offset.
|
|
91
|
-
* const paragraph = writer.createContainerElement( 'p' );
|
|
92
|
-
* writer.setSelection( paragraph, offset );
|
|
93
|
-
*
|
|
94
|
-
* Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
|
|
95
|
-
* that element and ends after the last child of that element.
|
|
96
|
-
*
|
|
97
|
-
* writer.setSelection( paragraph, 'in' );
|
|
98
|
-
*
|
|
99
|
-
* Creates a range on the {@link module:engine/view/item~Item item} which starts before the item and ends just after the item.
|
|
100
|
-
*
|
|
101
|
-
* writer.setSelection( paragraph, 'on' );
|
|
102
|
-
*
|
|
103
|
-
* // Removes all ranges.
|
|
104
|
-
* writer.setSelection( null );
|
|
105
|
-
*
|
|
106
|
-
* `DowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
107
|
-
*
|
|
108
|
-
* // Sets selection as backward.
|
|
109
|
-
* writer.setSelection( range, { backward: true } );
|
|
110
|
-
*
|
|
111
|
-
* // Sets selection as fake.
|
|
112
|
-
* // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
113
|
-
* // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
114
|
-
* // represented in other way, for example by applying proper CSS class.
|
|
115
|
-
* writer.setSelection( range, { fake: true } );
|
|
116
|
-
*
|
|
117
|
-
* // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
118
|
-
* // (and be properly handled by screen readers).
|
|
119
|
-
* writer.setSelection( range, { fake: true, label: 'foo' } );
|
|
120
|
-
*
|
|
121
|
-
* @param {module:engine/view/selection~Selectable} selectable
|
|
122
|
-
* @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] Sets place or offset of the selection.
|
|
123
|
-
* @param {Object} [options]
|
|
124
|
-
* @param {Boolean} [options.backward] Sets this selection instance to be backward.
|
|
125
|
-
* @param {Boolean} [options.fake] Sets this selection instance to be marked as `fake`.
|
|
126
|
-
* @param {String} [options.label] Label for the fake selection.
|
|
127
|
-
*/
|
|
128
52
|
setSelection(...args) {
|
|
129
53
|
this.document.selection._setTo(...args);
|
|
130
54
|
}
|
|
@@ -134,19 +58,16 @@ export default class DowncastWriter {
|
|
|
134
58
|
* The location can be specified in the same form as {@link module:engine/view/view~View#createPositionAt view.createPositionAt()}
|
|
135
59
|
* parameters.
|
|
136
60
|
*
|
|
137
|
-
* @param {module:engine/view/item~Item
|
|
138
|
-
* @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
|
|
139
|
-
* first parameter is a {@link module:engine/view/item~Item view item}.
|
|
61
|
+
* @param Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~Item view item}.
|
|
140
62
|
*/
|
|
141
|
-
setSelectionFocus(
|
|
142
|
-
this.document.selection._setFocus(
|
|
63
|
+
setSelectionFocus(itemOrPosition, offset) {
|
|
64
|
+
this.document.selection._setFocus(itemOrPosition, offset);
|
|
143
65
|
}
|
|
144
66
|
/**
|
|
145
67
|
* Creates a new {@link module:engine/view/documentfragment~DocumentFragment} instance.
|
|
146
68
|
*
|
|
147
|
-
* @param
|
|
148
|
-
*
|
|
149
|
-
* @returns {module:engine/view/documentfragment~DocumentFragment} The created document fragment.
|
|
69
|
+
* @param children A list of nodes to be inserted into the created document fragment.
|
|
70
|
+
* @returns The created document fragment.
|
|
150
71
|
*/
|
|
151
72
|
createDocumentFragment(children) {
|
|
152
73
|
return new DocumentFragment(this.document, children);
|
|
@@ -154,10 +75,12 @@ export default class DowncastWriter {
|
|
|
154
75
|
/**
|
|
155
76
|
* Creates a new {@link module:engine/view/text~Text text node}.
|
|
156
77
|
*
|
|
157
|
-
*
|
|
78
|
+
* ```ts
|
|
79
|
+
* writer.createText( 'foo' );
|
|
80
|
+
* ```
|
|
158
81
|
*
|
|
159
|
-
* @param
|
|
160
|
-
* @returns
|
|
82
|
+
* @param data The text's data.
|
|
83
|
+
* @returns The created text node.
|
|
161
84
|
*/
|
|
162
85
|
createText(data) {
|
|
163
86
|
return new Text(this.document, data);
|
|
@@ -165,23 +88,25 @@ export default class DowncastWriter {
|
|
|
165
88
|
/**
|
|
166
89
|
* Creates a new {@link module:engine/view/attributeelement~AttributeElement}.
|
|
167
90
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* writer.createAttributeElement( 'strong' );
|
|
93
|
+
* writer.createAttributeElement( 'a', { href: 'foo.bar' } );
|
|
170
94
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
95
|
+
* // Make `<a>` element contain other attributes element so the `<a>` element is not broken.
|
|
96
|
+
* writer.createAttributeElement( 'a', { href: 'foo.bar' }, { priority: 5 } );
|
|
173
97
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
98
|
+
* // Set `id` of a marker element so it is not joined or merged with "normal" elements.
|
|
99
|
+
* writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
|
|
100
|
+
* ```
|
|
176
101
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
182
|
-
* @param
|
|
102
|
+
* @param name Name of the element.
|
|
103
|
+
* @param attributes Element's attributes.
|
|
104
|
+
* @param options Element's options.
|
|
105
|
+
* @param options.priority Element's {@link module:engine/view/attributeelement~AttributeElement#priority priority}.
|
|
106
|
+
* @param options.id Element's {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
107
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
183
108
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
184
|
-
* @returns
|
|
109
|
+
* @returns Created element.
|
|
185
110
|
*/
|
|
186
111
|
createAttributeElement(name, attributes, options = {}) {
|
|
187
112
|
const attributeElement = new AttributeElement(this.document, name, attributes);
|
|
@@ -213,18 +138,20 @@ export default class DowncastWriter {
|
|
|
213
138
|
/**
|
|
214
139
|
* Creates a new {@link module:engine/view/editableelement~EditableElement}.
|
|
215
140
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* writer.createEditableElement( 'div' );
|
|
143
|
+
* writer.createEditableElement( 'div', { id: 'foo-1234' } );
|
|
144
|
+
* ```
|
|
218
145
|
*
|
|
219
146
|
* Note: The editable element is to be used in the editing pipeline. Usually, together with
|
|
220
147
|
* {@link module:widget/utils~toWidgetEditable `toWidgetEditable()`}.
|
|
221
148
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @param
|
|
224
|
-
* @param
|
|
225
|
-
* @param
|
|
149
|
+
* @param name Name of the element.
|
|
150
|
+
* @param attributes Elements attributes.
|
|
151
|
+
* @param options Element's options.
|
|
152
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
226
153
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
227
|
-
* @returns
|
|
154
|
+
* @returns Created element.
|
|
228
155
|
*/
|
|
229
156
|
createEditableElement(name, attributes, options = {}) {
|
|
230
157
|
const editableElement = new EditableElement(this.document, name, attributes);
|
|
@@ -236,15 +163,17 @@ export default class DowncastWriter {
|
|
|
236
163
|
/**
|
|
237
164
|
* Creates a new {@link module:engine/view/emptyelement~EmptyElement}.
|
|
238
165
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
166
|
+
* ```ts
|
|
167
|
+
* writer.createEmptyElement( 'img' );
|
|
168
|
+
* writer.createEmptyElement( 'img', { id: 'foo-1234' } );
|
|
169
|
+
* ```
|
|
241
170
|
*
|
|
242
|
-
* @param
|
|
243
|
-
* @param
|
|
244
|
-
* @param
|
|
245
|
-
* @param
|
|
171
|
+
* @param name Name of the element.
|
|
172
|
+
* @param attributes Elements attributes.
|
|
173
|
+
* @param options Element's options.
|
|
174
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
246
175
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
247
|
-
* @returns
|
|
176
|
+
* @returns Created element.
|
|
248
177
|
*/
|
|
249
178
|
createEmptyElement(name, attributes, options = {}) {
|
|
250
179
|
const emptyElement = new EmptyElement(this.document, name, attributes);
|
|
@@ -256,27 +185,31 @@ export default class DowncastWriter {
|
|
|
256
185
|
/**
|
|
257
186
|
* Creates a new {@link module:engine/view/uielement~UIElement}.
|
|
258
187
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* writer.createUIElement( 'span' );
|
|
190
|
+
* writer.createUIElement( 'span', { id: 'foo-1234' } );
|
|
191
|
+
* ```
|
|
261
192
|
*
|
|
262
193
|
* A custom render function can be provided as the third parameter:
|
|
263
194
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* writer.createUIElement( 'span', null, function( domDocument ) {
|
|
197
|
+
* const domElement = this.toDomElement( domDocument );
|
|
198
|
+
* domElement.innerHTML = '<b>this is ui element</b>';
|
|
267
199
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
200
|
+
* return domElement;
|
|
201
|
+
* } );
|
|
202
|
+
* ```
|
|
270
203
|
*
|
|
271
204
|
* Unlike {@link #createRawElement raw elements}, UI elements are by no means editor content, for instance,
|
|
272
205
|
* they are ignored by the editor selection system.
|
|
273
206
|
*
|
|
274
207
|
* You should not use UI elements as data containers. Check out {@link #createRawElement} instead.
|
|
275
208
|
*
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
279
|
-
* @returns
|
|
209
|
+
* @param name The name of the element.
|
|
210
|
+
* @param attributes Element attributes.
|
|
211
|
+
* @param renderFunction A custom render function.
|
|
212
|
+
* @returns The created element.
|
|
280
213
|
*/
|
|
281
214
|
createUIElement(name, attributes, renderFunction) {
|
|
282
215
|
const uiElement = new UIElement(this.document, name, attributes);
|
|
@@ -288,9 +221,11 @@ export default class DowncastWriter {
|
|
|
288
221
|
/**
|
|
289
222
|
* Creates a new {@link module:engine/view/rawelement~RawElement}.
|
|
290
223
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
224
|
+
* ```ts
|
|
225
|
+
* writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
|
|
226
|
+
* domElement.innerHTML = '<b>This is the raw content of the raw element.</b>';
|
|
227
|
+
* } );
|
|
228
|
+
* ```
|
|
294
229
|
*
|
|
295
230
|
* Raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
|
|
296
231
|
* even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
|
|
@@ -304,13 +239,13 @@ export default class DowncastWriter {
|
|
|
304
239
|
* You should not use raw elements to render the UI in the editor content. Check out {@link #createUIElement `#createUIElement()`}
|
|
305
240
|
* instead.
|
|
306
241
|
*
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
242
|
+
* @param name The name of the element.
|
|
243
|
+
* @param attributes Element attributes.
|
|
244
|
+
* @param renderFunction A custom render function.
|
|
245
|
+
* @param options Element's options.
|
|
246
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
312
247
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
313
|
-
* @returns
|
|
248
|
+
* @returns The created element.
|
|
314
249
|
*/
|
|
315
250
|
createRawElement(name, attributes, renderFunction, options = {}) {
|
|
316
251
|
const rawElement = new RawElement(this.document, name, attributes);
|
|
@@ -325,11 +260,12 @@ export default class DowncastWriter {
|
|
|
325
260
|
/**
|
|
326
261
|
* Adds or overwrites the element's attribute with a specified key and value.
|
|
327
262
|
*
|
|
328
|
-
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
|
|
265
|
+
* ```
|
|
329
266
|
*
|
|
330
|
-
* @param
|
|
331
|
-
* @param
|
|
332
|
-
* @param {module:engine/view/element~Element} element
|
|
267
|
+
* @param key The attribute key.
|
|
268
|
+
* @param value The attribute value.
|
|
333
269
|
*/
|
|
334
270
|
setAttribute(key, value, element) {
|
|
335
271
|
element._setAttribute(key, value);
|
|
@@ -337,10 +273,11 @@ export default class DowncastWriter {
|
|
|
337
273
|
/**
|
|
338
274
|
* Removes attribute from the element.
|
|
339
275
|
*
|
|
340
|
-
*
|
|
276
|
+
* ```ts
|
|
277
|
+
* writer.removeAttribute( 'href', linkElement );
|
|
278
|
+
* ```
|
|
341
279
|
*
|
|
342
|
-
* @param
|
|
343
|
-
* @param {module:engine/view/element~Element} element
|
|
280
|
+
* @param key Attribute key.
|
|
344
281
|
*/
|
|
345
282
|
removeAttribute(key, element) {
|
|
346
283
|
element._removeAttribute(key);
|
|
@@ -348,11 +285,10 @@ export default class DowncastWriter {
|
|
|
348
285
|
/**
|
|
349
286
|
* Adds specified class to the element.
|
|
350
287
|
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* @param {module:engine/view/element~Element} element
|
|
288
|
+
* ```ts
|
|
289
|
+
* writer.addClass( 'foo', linkElement );
|
|
290
|
+
* writer.addClass( [ 'foo', 'bar' ], linkElement );
|
|
291
|
+
* ```
|
|
356
292
|
*/
|
|
357
293
|
addClass(className, element) {
|
|
358
294
|
element._addClass(className);
|
|
@@ -360,11 +296,10 @@ export default class DowncastWriter {
|
|
|
360
296
|
/**
|
|
361
297
|
* Removes specified class from the element.
|
|
362
298
|
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @param {module:engine/view/element~Element} element
|
|
299
|
+
* ```ts
|
|
300
|
+
* writer.removeClass( 'foo', linkElement );
|
|
301
|
+
* writer.removeClass( [ 'foo', 'bar' ], linkElement );
|
|
302
|
+
* ```
|
|
368
303
|
*/
|
|
369
304
|
removeClass(className, element) {
|
|
370
305
|
element._removeClass(className);
|
|
@@ -380,15 +315,14 @@ export default class DowncastWriter {
|
|
|
380
315
|
/**
|
|
381
316
|
* Removes specified style from the element.
|
|
382
317
|
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
318
|
+
* ```ts
|
|
319
|
+
* writer.removeStyle( 'color', element ); // Removes 'color' style.
|
|
320
|
+
* writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
|
|
321
|
+
* ```
|
|
385
322
|
*
|
|
386
323
|
* **Note**: This method can work with normalized style names if
|
|
387
324
|
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
388
325
|
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
|
|
389
|
-
*
|
|
390
|
-
* @param {Array.<String>|String} property
|
|
391
|
-
* @param {module:engine/view/element~Element} element
|
|
392
326
|
*/
|
|
393
327
|
removeStyle(property, element) {
|
|
394
328
|
element._removeStyle(property);
|
|
@@ -396,10 +330,6 @@ export default class DowncastWriter {
|
|
|
396
330
|
/**
|
|
397
331
|
* Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM,
|
|
398
332
|
* so they can be used to add special data to elements.
|
|
399
|
-
*
|
|
400
|
-
* @param {String|Symbol} key
|
|
401
|
-
* @param {*} value
|
|
402
|
-
* @param {module:engine/view/element~Element} element
|
|
403
333
|
*/
|
|
404
334
|
setCustomProperty(key, value, element) {
|
|
405
335
|
element._setCustomProperty(key, value);
|
|
@@ -407,9 +337,7 @@ export default class DowncastWriter {
|
|
|
407
337
|
/**
|
|
408
338
|
* Removes a custom property stored under the given key.
|
|
409
339
|
*
|
|
410
|
-
* @
|
|
411
|
-
* @param {module:engine/view/element~Element} element
|
|
412
|
-
* @returns {Boolean} Returns true if property was removed.
|
|
340
|
+
* @returns Returns true if property was removed.
|
|
413
341
|
*/
|
|
414
342
|
removeCustomProperty(key, element) {
|
|
415
343
|
return element._removeCustomProperty(key);
|
|
@@ -420,10 +348,12 @@ export default class DowncastWriter {
|
|
|
420
348
|
*
|
|
421
349
|
* In following examples `<p>` is a container, `<b>` and `<u>` are attribute elements:
|
|
422
350
|
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
351
|
+
* ```html
|
|
352
|
+
* <p>foo<b><u>bar{}</u></b></p> -> <p>foo<b><u>bar</u></b>[]</p>
|
|
353
|
+
* <p>foo<b><u>{}bar</u></b></p> -> <p>foo{}<b><u>bar</u></b></p>
|
|
354
|
+
* <p>foo<b><u>b{}ar</u></b></p> -> <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
|
|
355
|
+
* <p><b>fo{o</b><u>ba}r</u></p> -> <p><b>fo</b><b>o</b><u>ba</u><u>r</u></b></p>
|
|
356
|
+
* ```
|
|
427
357
|
*
|
|
428
358
|
* **Note:** {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment} is treated like a container.
|
|
429
359
|
*
|
|
@@ -446,10 +376,8 @@ export default class DowncastWriter {
|
|
|
446
376
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
447
377
|
* @see module:engine/view/containerelement~ContainerElement
|
|
448
378
|
* @see module:engine/view/downcastwriter~DowncastWriter#breakContainer
|
|
449
|
-
* @param
|
|
450
|
-
*
|
|
451
|
-
* @returns {module:engine/view/position~Position|module:engine/view/range~Range} The new position or range, after breaking the
|
|
452
|
-
* attribute elements.
|
|
379
|
+
* @param positionOrRange The position where to break attribute elements.
|
|
380
|
+
* @returns The new position or range, after breaking the attribute elements.
|
|
453
381
|
*/
|
|
454
382
|
breakAttributes(positionOrRange) {
|
|
455
383
|
if (positionOrRange instanceof Position) {
|
|
@@ -464,10 +392,12 @@ export default class DowncastWriter {
|
|
|
464
392
|
* The position has to be directly inside the container element and cannot be in the root. It does not break the conrainer view element
|
|
465
393
|
* if the position is at the beginning or at the end of its parent element.
|
|
466
394
|
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
395
|
+
* ```html
|
|
396
|
+
* <p>foo^bar</p> -> <p>foo</p><p>bar</p>
|
|
397
|
+
* <div><p>foo</p>^<p>bar</p></div> -> <div><p>foo</p></div><div><p>bar</p></div>
|
|
398
|
+
* <p>^foobar</p> -> ^<p>foobar</p>
|
|
399
|
+
* <p>foobar^</p> -> <p>foobar</p>^
|
|
400
|
+
* ```
|
|
471
401
|
*
|
|
472
402
|
* **Note:** The difference between {@link module:engine/view/downcastwriter~DowncastWriter#breakAttributes breakAttributes()} and
|
|
473
403
|
* {@link module:engine/view/downcastwriter~DowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
|
|
@@ -478,8 +408,8 @@ export default class DowncastWriter {
|
|
|
478
408
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
479
409
|
* @see module:engine/view/containerelement~ContainerElement
|
|
480
410
|
* @see module:engine/view/downcastwriter~DowncastWriter#breakAttributes
|
|
481
|
-
* @param
|
|
482
|
-
* @returns
|
|
411
|
+
* @param position The position where to break the element.
|
|
412
|
+
* @returns The position between broken elements. If an element has not been broken,
|
|
483
413
|
* the returned position is placed either before or after it.
|
|
484
414
|
*/
|
|
485
415
|
breakContainer(position) {
|
|
@@ -518,14 +448,18 @@ export default class DowncastWriter {
|
|
|
518
448
|
*
|
|
519
449
|
* In following examples `<p>` is a container and `<b>` is an attribute element:
|
|
520
450
|
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
451
|
+
* ```html
|
|
452
|
+
* <p>foo[]bar</p> -> <p>foo{}bar</p>
|
|
453
|
+
* <p><b>foo</b>[]<b>bar</b></p> -> <p><b>foo{}bar</b></p>
|
|
454
|
+
* <p><b foo="bar">a</b>[]<b foo="baz">b</b></p> -> <p><b foo="bar">a</b>[]<b foo="baz">b</b></p>
|
|
455
|
+
* ```
|
|
524
456
|
*
|
|
525
457
|
* It will also take care about empty attributes when merging:
|
|
526
458
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
459
|
+
* ```html
|
|
460
|
+
* <p><b>[]</b></p> -> <p>[]</p>
|
|
461
|
+
* <p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
|
|
462
|
+
* ```
|
|
529
463
|
*
|
|
530
464
|
* **Note:** Difference between {@link module:engine/view/downcastwriter~DowncastWriter#mergeAttributes mergeAttributes} and
|
|
531
465
|
* {@link module:engine/view/downcastwriter~DowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
@@ -535,8 +469,8 @@ export default class DowncastWriter {
|
|
|
535
469
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
536
470
|
* @see module:engine/view/containerelement~ContainerElement
|
|
537
471
|
* @see module:engine/view/downcastwriter~DowncastWriter#mergeContainers
|
|
538
|
-
* @param
|
|
539
|
-
* @returns
|
|
472
|
+
* @param position Merge position.
|
|
473
|
+
* @returns Position after merge.
|
|
540
474
|
*/
|
|
541
475
|
mergeAttributes(position) {
|
|
542
476
|
const positionOffset = position.offset;
|
|
@@ -580,8 +514,10 @@ export default class DowncastWriter {
|
|
|
580
514
|
* Merges two {@link module:engine/view/containerelement~ContainerElement container elements} that are before and after given position.
|
|
581
515
|
* Precisely, the element after the position is removed and it's contents are moved to element before the position.
|
|
582
516
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
517
|
+
* ```html
|
|
518
|
+
* <p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
|
|
519
|
+
* <div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
|
|
520
|
+
* ```
|
|
585
521
|
*
|
|
586
522
|
* **Note:** Difference between {@link module:engine/view/downcastwriter~DowncastWriter#mergeAttributes mergeAttributes} and
|
|
587
523
|
* {@link module:engine/view/downcastwriter~DowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
@@ -591,8 +527,8 @@ export default class DowncastWriter {
|
|
|
591
527
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
592
528
|
* @see module:engine/view/containerelement~ContainerElement
|
|
593
529
|
* @see module:engine/view/downcastwriter~DowncastWriter#mergeAttributes
|
|
594
|
-
* @param
|
|
595
|
-
* @returns
|
|
530
|
+
* @param position Merge position.
|
|
531
|
+
* @returns Position after merge.
|
|
596
532
|
*/
|
|
597
533
|
mergeContainers(position) {
|
|
598
534
|
const prev = position.nodeBefore;
|
|
@@ -623,15 +559,9 @@ export default class DowncastWriter {
|
|
|
623
559
|
* {@link module:engine/view/rawelement~RawElement RawElements} or
|
|
624
560
|
* {@link module:engine/view/uielement~UIElement UIElements}.
|
|
625
561
|
*
|
|
626
|
-
* @param
|
|
627
|
-
* @param
|
|
628
|
-
*
|
|
629
|
-
* module:engine/view/rawelement~RawElement|module:engine/view/uielement~UIElement|
|
|
630
|
-
* Iterable.<module:engine/view/text~Text|
|
|
631
|
-
* module:engine/view/attributeelement~AttributeElement|module:engine/view/containerelement~ContainerElement|
|
|
632
|
-
* module:engine/view/emptyelement~EmptyElement|module:engine/view/rawelement~RawElement|
|
|
633
|
-
* module:engine/view/uielement~UIElement>} nodes Node or nodes to insert.
|
|
634
|
-
* @returns {module:engine/view/range~Range} Range around inserted nodes.
|
|
562
|
+
* @param position Insertion position.
|
|
563
|
+
* @param nodes Node or nodes to insert.
|
|
564
|
+
* @returns Range around inserted nodes.
|
|
635
565
|
*/
|
|
636
566
|
insert(position, nodes) {
|
|
637
567
|
nodes = isIterable(nodes) ? [...nodes] : [nodes];
|
|
@@ -677,10 +607,10 @@ export default class DowncastWriter {
|
|
|
677
607
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
678
608
|
* same parent container.
|
|
679
609
|
*
|
|
680
|
-
* @param
|
|
610
|
+
* @param rangeOrItem Range to remove from container
|
|
681
611
|
* or an {@link module:engine/view/item~Item item} to remove. If range is provided, after removing, it will be updated
|
|
682
612
|
* to a collapsed range showing the new position.
|
|
683
|
-
* @returns
|
|
613
|
+
* @returns Document fragment containing removed nodes.
|
|
684
614
|
*/
|
|
685
615
|
remove(rangeOrItem) {
|
|
686
616
|
const range = rangeOrItem instanceof Range ? rangeOrItem : Range._createOn(rangeOrItem);
|
|
@@ -712,8 +642,8 @@ export default class DowncastWriter {
|
|
|
712
642
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
713
643
|
* same parent container.
|
|
714
644
|
*
|
|
715
|
-
* @param
|
|
716
|
-
* @param
|
|
645
|
+
* @param range Range to clear.
|
|
646
|
+
* @param element Element to remove.
|
|
717
647
|
*/
|
|
718
648
|
clear(range, element) {
|
|
719
649
|
validateRangeContainer(range, this.document);
|
|
@@ -764,9 +694,9 @@ export default class DowncastWriter {
|
|
|
764
694
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
765
695
|
* same parent container.
|
|
766
696
|
*
|
|
767
|
-
* @param
|
|
768
|
-
* @param
|
|
769
|
-
* @returns
|
|
697
|
+
* @param sourceRange Range containing nodes to move.
|
|
698
|
+
* @param targetPosition Position to insert.
|
|
699
|
+
* @returns Range in target container. Inserted nodes are placed between
|
|
770
700
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions.
|
|
771
701
|
*/
|
|
772
702
|
move(sourceRange, targetPosition) {
|
|
@@ -801,9 +731,9 @@ export default class DowncastWriter {
|
|
|
801
731
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
|
|
802
732
|
* is collapsed and different than view selection.
|
|
803
733
|
*
|
|
804
|
-
* @param
|
|
805
|
-
* @param
|
|
806
|
-
* @returns
|
|
734
|
+
* @param range Range to wrap.
|
|
735
|
+
* @param attribute Attribute element to use as wrapper.
|
|
736
|
+
* @returns range Range after wrapping, spanning over wrapping attribute element.
|
|
807
737
|
*/
|
|
808
738
|
wrap(range, attribute) {
|
|
809
739
|
if (!(attribute instanceof AttributeElement)) {
|
|
@@ -835,9 +765,6 @@ export default class DowncastWriter {
|
|
|
835
765
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
836
766
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
837
767
|
* same parent container.
|
|
838
|
-
*
|
|
839
|
-
* @param {module:engine/view/range~Range} range
|
|
840
|
-
* @param {module:engine/view/attributeelement~AttributeElement} attribute
|
|
841
768
|
*/
|
|
842
769
|
unwrap(range, attribute) {
|
|
843
770
|
if (!(attribute instanceof AttributeElement)) {
|
|
@@ -877,9 +804,9 @@ export default class DowncastWriter {
|
|
|
877
804
|
*
|
|
878
805
|
* Since this function creates a new element and removes the given one, the new element is returned to keep reference.
|
|
879
806
|
*
|
|
880
|
-
* @param
|
|
881
|
-
* @param
|
|
882
|
-
* @returns
|
|
807
|
+
* @param newName New name for element.
|
|
808
|
+
* @param viewElement Element to be renamed.
|
|
809
|
+
* @returns Element created due to rename.
|
|
883
810
|
*/
|
|
884
811
|
rename(newName, viewElement) {
|
|
885
812
|
const newElement = new ContainerElement(this.document, newName, viewElement.getAttributes());
|
|
@@ -900,7 +827,7 @@ export default class DowncastWriter {
|
|
|
900
827
|
*
|
|
901
828
|
* Keep in mind that group names are equal to the `id` property of the attribute element.
|
|
902
829
|
*
|
|
903
|
-
* @param
|
|
830
|
+
* @param groupName Name of the group to clear.
|
|
904
831
|
*/
|
|
905
832
|
clearClonedElementsGroup(groupName) {
|
|
906
833
|
this._cloneGroups.delete(groupName);
|
|
@@ -918,10 +845,7 @@ export default class DowncastWriter {
|
|
|
918
845
|
* * {@link #createPositionBefore},
|
|
919
846
|
* * {@link #createPositionAfter},
|
|
920
847
|
*
|
|
921
|
-
* @param {module:engine/view/item~Item
|
|
922
|
-
* @param {Number|'end'|'before'|'after'} [offset] Offset or one of the flags. Used only when
|
|
923
|
-
* first parameter is a {@link module:engine/view/item~Item view item}.
|
|
924
|
-
* @returns {module:engine/view/position~Position}
|
|
848
|
+
* @param offset Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~Item view item}.
|
|
925
849
|
*/
|
|
926
850
|
createPositionAt(itemOrPosition, offset) {
|
|
927
851
|
return Position._createAt(itemOrPosition, offset);
|
|
@@ -929,8 +853,7 @@ export default class DowncastWriter {
|
|
|
929
853
|
/**
|
|
930
854
|
* Creates a new position after given view item.
|
|
931
855
|
*
|
|
932
|
-
* @param
|
|
933
|
-
* @returns {module:engine/view/position~Position}
|
|
856
|
+
* @param item View item after which the position should be located.
|
|
934
857
|
*/
|
|
935
858
|
createPositionAfter(item) {
|
|
936
859
|
return Position._createAfter(item);
|
|
@@ -938,8 +861,7 @@ export default class DowncastWriter {
|
|
|
938
861
|
/**
|
|
939
862
|
* Creates a new position before given view item.
|
|
940
863
|
*
|
|
941
|
-
* @param
|
|
942
|
-
* @returns {module:engine/view/position~Position}
|
|
864
|
+
* @param item View item before which the position should be located.
|
|
943
865
|
*/
|
|
944
866
|
createPositionBefore(item) {
|
|
945
867
|
return Position._createBefore(item);
|
|
@@ -949,18 +871,14 @@ export default class DowncastWriter {
|
|
|
949
871
|
*
|
|
950
872
|
* **Note:** This factory method creates its own {@link module:engine/view/position~Position} instances basing on passed values.
|
|
951
873
|
*
|
|
952
|
-
* @param
|
|
953
|
-
* @param
|
|
954
|
-
* @returns {module:engine/view/range~Range}
|
|
874
|
+
* @param start Start position.
|
|
875
|
+
* @param end End position. If not set, range will be collapsed at `start` position.
|
|
955
876
|
*/
|
|
956
|
-
createRange(
|
|
957
|
-
return new Range(
|
|
877
|
+
createRange(start, end) {
|
|
878
|
+
return new Range(start, end);
|
|
958
879
|
}
|
|
959
880
|
/**
|
|
960
881
|
* Creates a range that starts before given {@link module:engine/view/item~Item view item} and ends after it.
|
|
961
|
-
*
|
|
962
|
-
* @param {module:engine/view/item~Item} item
|
|
963
|
-
* @returns {module:engine/view/range~Range}
|
|
964
882
|
*/
|
|
965
883
|
createRangeOn(item) {
|
|
966
884
|
return Range._createOn(item);
|
|
@@ -969,72 +887,11 @@ export default class DowncastWriter {
|
|
|
969
887
|
* Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
|
|
970
888
|
* that element and ends after the last child of that element.
|
|
971
889
|
*
|
|
972
|
-
* @param
|
|
973
|
-
* @returns {module:engine/view/range~Range}
|
|
890
|
+
* @param element Element which is a parent for the range.
|
|
974
891
|
*/
|
|
975
892
|
createRangeIn(element) {
|
|
976
893
|
return Range._createIn(element);
|
|
977
894
|
}
|
|
978
|
-
/**
|
|
979
|
-
* Creates new {@link module:engine/view/selection~Selection} instance.
|
|
980
|
-
*
|
|
981
|
-
* // Creates empty selection without ranges.
|
|
982
|
-
* const selection = writer.createSelection();
|
|
983
|
-
*
|
|
984
|
-
* // Creates selection at the given range.
|
|
985
|
-
* const range = writer.createRange( start, end );
|
|
986
|
-
* const selection = writer.createSelection( range );
|
|
987
|
-
*
|
|
988
|
-
* // Creates selection at the given ranges
|
|
989
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
990
|
-
* const selection = writer.createSelection( ranges );
|
|
991
|
-
*
|
|
992
|
-
* // Creates selection from the other selection.
|
|
993
|
-
* const otherSelection = writer.createSelection();
|
|
994
|
-
* const selection = writer.createSelection( otherSelection );
|
|
995
|
-
*
|
|
996
|
-
* // Creates selection from the document selection.
|
|
997
|
-
* const selection = writer.createSelection( editor.editing.view.document.selection );
|
|
998
|
-
*
|
|
999
|
-
* // Creates selection at the given position.
|
|
1000
|
-
* const position = writer.createPositionFromPath( root, path );
|
|
1001
|
-
* const selection = writer.createSelection( position );
|
|
1002
|
-
*
|
|
1003
|
-
* // Creates collapsed selection at the position of given item and offset.
|
|
1004
|
-
* const paragraph = writer.createContainerElement( 'p' );
|
|
1005
|
-
* const selection = writer.createSelection( paragraph, offset );
|
|
1006
|
-
*
|
|
1007
|
-
* // Creates a range inside an {@link module:engine/view/element~Element element} which starts before the
|
|
1008
|
-
* // first child of that element and ends after the last child of that element.
|
|
1009
|
-
* const selection = writer.createSelection( paragraph, 'in' );
|
|
1010
|
-
*
|
|
1011
|
-
* // Creates a range on an {@link module:engine/view/item~Item item} which starts before the item and ends
|
|
1012
|
-
* // just after the item.
|
|
1013
|
-
* const selection = writer.createSelection( paragraph, 'on' );
|
|
1014
|
-
*
|
|
1015
|
-
* `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
1016
|
-
*
|
|
1017
|
-
* // Creates backward selection.
|
|
1018
|
-
* const selection = writer.createSelection( range, { backward: true } );
|
|
1019
|
-
*
|
|
1020
|
-
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
1021
|
-
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
1022
|
-
* represented in other way, for example by applying proper CSS class.
|
|
1023
|
-
*
|
|
1024
|
-
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
1025
|
-
* (and be properly handled by screen readers).
|
|
1026
|
-
*
|
|
1027
|
-
* // Creates fake selection with label.
|
|
1028
|
-
* const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
|
|
1029
|
-
*
|
|
1030
|
-
* @param {module:engine/view/selection~Selectable} [selectable=null]
|
|
1031
|
-
* @param {Number|'before'|'end'|'after'|'on'|'in'} [placeOrOffset] Offset or place when selectable is an `Item`.
|
|
1032
|
-
* @param {Object} [options]
|
|
1033
|
-
* @param {Boolean} [options.backward] Sets this selection instance to be backward.
|
|
1034
|
-
* @param {Boolean} [options.fake] Sets this selection instance to be marked as `fake`.
|
|
1035
|
-
* @param {String} [options.label] Label for the fake selection.
|
|
1036
|
-
* @returns {module:engine/view/selection~Selection}
|
|
1037
|
-
*/
|
|
1038
895
|
createSelection(...args) {
|
|
1039
896
|
return new Selection(...args);
|
|
1040
897
|
}
|
|
@@ -1042,28 +899,32 @@ export default class DowncastWriter {
|
|
|
1042
899
|
* Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
|
|
1043
900
|
* `elementToStructure()`} conversion helper.
|
|
1044
901
|
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
902
|
+
* ```ts
|
|
903
|
+
* const viewSlot = conversionApi.writer.createSlot();
|
|
904
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1047
905
|
*
|
|
1048
|
-
*
|
|
906
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
907
|
+
* ```
|
|
1049
908
|
*
|
|
1050
909
|
* It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):
|
|
1051
910
|
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
911
|
+
* ```ts
|
|
912
|
+
* const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
|
|
913
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1054
914
|
*
|
|
1055
|
-
*
|
|
915
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
916
|
+
* ```
|
|
1056
917
|
*
|
|
1057
918
|
* While providing a filtered slot, make sure to provide slots for all child nodes. A single node can not be downcasted into
|
|
1058
919
|
* multiple slots.
|
|
1059
920
|
*
|
|
1060
921
|
* **Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.
|
|
1061
922
|
*
|
|
1062
|
-
* @param
|
|
1063
|
-
* @returns
|
|
923
|
+
* @param modeOrFilter The filter for child nodes.
|
|
924
|
+
* @returns The slot element to be placed in to the view structure while processing
|
|
1064
925
|
* {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`}.
|
|
1065
926
|
*/
|
|
1066
|
-
createSlot(modeOrFilter) {
|
|
927
|
+
createSlot(modeOrFilter = 'children') {
|
|
1067
928
|
if (!this._slotFactory) {
|
|
1068
929
|
/**
|
|
1069
930
|
* The `createSlot()` method is only allowed inside the `elementToStructure` downcast helper callback.
|
|
@@ -1077,8 +938,8 @@ export default class DowncastWriter {
|
|
|
1077
938
|
/**
|
|
1078
939
|
* Registers a slot factory.
|
|
1079
940
|
*
|
|
1080
|
-
* @
|
|
1081
|
-
* @param
|
|
941
|
+
* @internal
|
|
942
|
+
* @param slotFactory The slot factory.
|
|
1082
943
|
*/
|
|
1083
944
|
_registerSlotFactory(slotFactory) {
|
|
1084
945
|
this._slotFactory = slotFactory;
|
|
@@ -1086,7 +947,7 @@ export default class DowncastWriter {
|
|
|
1086
947
|
/**
|
|
1087
948
|
* Clears the registered slot factory.
|
|
1088
949
|
*
|
|
1089
|
-
* @
|
|
950
|
+
* @internal
|
|
1090
951
|
*/
|
|
1091
952
|
_clearSlotFactory() {
|
|
1092
953
|
this._slotFactory = null;
|
|
@@ -1095,17 +956,10 @@ export default class DowncastWriter {
|
|
|
1095
956
|
* Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion
|
|
1096
957
|
* and merging them afterwards if requested by the breakAttributes param.
|
|
1097
958
|
*
|
|
1098
|
-
* @
|
|
1099
|
-
* @param
|
|
1100
|
-
* @param
|
|
1101
|
-
*
|
|
1102
|
-
* module:engine/view/rawelement~RawElement|module:engine/view/uielement~UIElement|
|
|
1103
|
-
* Iterable.<module:engine/view/text~Text|
|
|
1104
|
-
* module:engine/view/attributeelement~AttributeElement|module:engine/view/containerelement~ContainerElement|
|
|
1105
|
-
* module:engine/view/emptyelement~EmptyElement|module:engine/view/rawelement~RawElement|
|
|
1106
|
-
* module:engine/view/uielement~UIElement>} nodes Node or nodes to insert.
|
|
1107
|
-
* @param {Boolean} breakAttributes Whether attributes should be broken.
|
|
1108
|
-
* @returns {module:engine/view/range~Range} Range around inserted nodes.
|
|
959
|
+
* @param position Insertion position.
|
|
960
|
+
* @param nodes Node or nodes to insert.
|
|
961
|
+
* @param breakAttributes Whether attributes should be broken.
|
|
962
|
+
* @returns Range around inserted nodes.
|
|
1109
963
|
*/
|
|
1110
964
|
_insertNodes(position, nodes, breakAttributes) {
|
|
1111
965
|
let parentElement;
|
|
@@ -1148,12 +1002,6 @@ export default class DowncastWriter {
|
|
|
1148
1002
|
/**
|
|
1149
1003
|
* Wraps children with provided `wrapElement`. Only children contained in `parent` element between
|
|
1150
1004
|
* `startOffset` and `endOffset` will be wrapped.
|
|
1151
|
-
*
|
|
1152
|
-
* @private
|
|
1153
|
-
* @param {module:engine/view/element~Element} parent
|
|
1154
|
-
* @param {Number} startOffset
|
|
1155
|
-
* @param {Number} endOffset
|
|
1156
|
-
* @param {module:engine/view/element~Element} wrapElement
|
|
1157
1005
|
*/
|
|
1158
1006
|
_wrapChildren(parent, startOffset, endOffset, wrapElement) {
|
|
1159
1007
|
let i = startOffset;
|
|
@@ -1219,12 +1067,6 @@ export default class DowncastWriter {
|
|
|
1219
1067
|
/**
|
|
1220
1068
|
* Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between
|
|
1221
1069
|
* `startOffset` and `endOffset` will be unwrapped.
|
|
1222
|
-
*
|
|
1223
|
-
* @private
|
|
1224
|
-
* @param {module:engine/view/element~Element} parent
|
|
1225
|
-
* @param {Number} startOffset
|
|
1226
|
-
* @param {Number} endOffset
|
|
1227
|
-
* @param {module:engine/view/element~Element} unwrapElement
|
|
1228
1070
|
*/
|
|
1229
1071
|
_unwrapChildren(parent, startOffset, endOffset, unwrapElement) {
|
|
1230
1072
|
let i = startOffset;
|
|
@@ -1304,10 +1146,7 @@ export default class DowncastWriter {
|
|
|
1304
1146
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1305
1147
|
* an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.
|
|
1306
1148
|
*
|
|
1307
|
-
* @
|
|
1308
|
-
* @param {module:engine/view/range~Range} range
|
|
1309
|
-
* @param {module:engine/view/attributeelement~AttributeElement} attribute
|
|
1310
|
-
* @returns {module:engine/view/range~Range} New range after wrapping, spanning over wrapping attribute element.
|
|
1149
|
+
* @returns New range after wrapping, spanning over wrapping attribute element.
|
|
1311
1150
|
*/
|
|
1312
1151
|
_wrapRange(range, attribute) {
|
|
1313
1152
|
// Break attributes at range start and end.
|
|
@@ -1331,10 +1170,7 @@ export default class DowncastWriter {
|
|
|
1331
1170
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1332
1171
|
* an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.
|
|
1333
1172
|
*
|
|
1334
|
-
* @
|
|
1335
|
-
* @param {module:engine/view/position~Position} position
|
|
1336
|
-
* @param {module:engine/view/attributeelement~AttributeElement} attribute
|
|
1337
|
-
* @returns {module:engine/view/position~Position} New position after wrapping.
|
|
1173
|
+
* @returns New position after wrapping.
|
|
1338
1174
|
*/
|
|
1339
1175
|
_wrapPosition(position, attribute) {
|
|
1340
1176
|
// Return same position when trying to wrap with attribute similar to position parent.
|
|
@@ -1368,14 +1204,13 @@ export default class DowncastWriter {
|
|
|
1368
1204
|
return movePositionToTextNode(newPosition);
|
|
1369
1205
|
}
|
|
1370
1206
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1377
|
-
*
|
|
1378
|
-
* @returns {Boolean} Returns `true` if elements are merged.
|
|
1207
|
+
* Wraps one {@link module:engine/view/attributeelement~AttributeElement AttributeElement} into another by
|
|
1208
|
+
* merging them if possible. When merging is possible - all attributes, styles and classes are moved from wrapper
|
|
1209
|
+
* element to element being wrapped.
|
|
1210
|
+
*
|
|
1211
|
+
* @param wrapper Wrapper AttributeElement.
|
|
1212
|
+
* @param toWrap AttributeElement to wrap using wrapper element.
|
|
1213
|
+
* @returns Returns `true` if elements are merged.
|
|
1379
1214
|
*/
|
|
1380
1215
|
_wrapAttributeElement(wrapper, toWrap) {
|
|
1381
1216
|
if (!canBeJoined(wrapper, toWrap)) {
|
|
@@ -1430,10 +1265,9 @@ export default class DowncastWriter {
|
|
|
1430
1265
|
* corresponding attributes, classes and styles. All attributes, classes and styles from wrapper should be present
|
|
1431
1266
|
* inside element being unwrapped.
|
|
1432
1267
|
*
|
|
1433
|
-
* @
|
|
1434
|
-
* @param
|
|
1435
|
-
* @
|
|
1436
|
-
* @returns {Boolean} Returns `true` if elements are unwrapped.
|
|
1268
|
+
* @param wrapper Wrapper AttributeElement.
|
|
1269
|
+
* @param toUnwrap AttributeElement to unwrap using wrapper element.
|
|
1270
|
+
* @returns Returns `true` if elements are unwrapped.
|
|
1437
1271
|
**/
|
|
1438
1272
|
_unwrapAttributeElement(wrapper, toUnwrap) {
|
|
1439
1273
|
if (!canBeJoined(wrapper, toUnwrap)) {
|
|
@@ -1482,11 +1316,10 @@ export default class DowncastWriter {
|
|
|
1482
1316
|
/**
|
|
1483
1317
|
* Helper function used by other `DowncastWriter` methods. Breaks attribute elements at the boundaries of given range.
|
|
1484
1318
|
*
|
|
1485
|
-
* @
|
|
1486
|
-
* @param
|
|
1487
|
-
* @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.
|
|
1319
|
+
* @param range Range which `start` and `end` positions will be used to break attributes.
|
|
1320
|
+
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
1488
1321
|
* This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
|
|
1489
|
-
* @returns
|
|
1322
|
+
* @returns New range with located at break positions.
|
|
1490
1323
|
*/
|
|
1491
1324
|
_breakAttributesRange(range, forceSplitText = false) {
|
|
1492
1325
|
const rangeStart = range.start;
|
|
@@ -1513,11 +1346,10 @@ export default class DowncastWriter {
|
|
|
1513
1346
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position
|
|
1514
1347
|
* is placed inside {@link module:engine/view/uielement~UIElement UIElement}.
|
|
1515
1348
|
*
|
|
1516
|
-
* @
|
|
1517
|
-
* @param
|
|
1518
|
-
* @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.
|
|
1349
|
+
* @param position Position where to break attributes.
|
|
1350
|
+
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
1519
1351
|
* This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
|
|
1520
|
-
* @returns
|
|
1352
|
+
* @returns New position after breaking the attributes.
|
|
1521
1353
|
*/
|
|
1522
1354
|
_breakAttributes(position, forceSplitText = false) {
|
|
1523
1355
|
const positionOffset = position.offset;
|
|
@@ -1620,8 +1452,7 @@ export default class DowncastWriter {
|
|
|
1620
1452
|
*
|
|
1621
1453
|
* Does nothing if added element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
1622
1454
|
*
|
|
1623
|
-
* @
|
|
1624
|
-
* @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to save.
|
|
1455
|
+
* @param element Attribute element to save.
|
|
1625
1456
|
*/
|
|
1626
1457
|
_addToClonedElementsGroup(element) {
|
|
1627
1458
|
// Add only if the element is in document tree.
|
|
@@ -1656,8 +1487,7 @@ export default class DowncastWriter {
|
|
|
1656
1487
|
*
|
|
1657
1488
|
* Does nothing if the element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
1658
1489
|
*
|
|
1659
|
-
* @
|
|
1660
|
-
* @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to remove.
|
|
1490
|
+
* @param element Attribute element to remove.
|
|
1661
1491
|
*/
|
|
1662
1492
|
_removeFromClonedElementsGroup(element) {
|
|
1663
1493
|
// Traverse the element's children recursively to find other attribute elements that also got removed.
|
|
@@ -1690,13 +1520,14 @@ function _hasNonUiChildren(parent) {
|
|
|
1690
1520
|
*
|
|
1691
1521
|
* @error view-writer-wrap-invalid-attribute
|
|
1692
1522
|
*/
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1523
|
+
/**
|
|
1524
|
+
* Returns first parent container of specified {@link module:engine/view/position~Position Position}.
|
|
1525
|
+
* Position's parent node is checked as first, then next parents are checked.
|
|
1526
|
+
* Note that {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment} is treated like a container.
|
|
1527
|
+
*
|
|
1528
|
+
* @param position Position used as a start point to locate parent container.
|
|
1529
|
+
* @returns Parent container element or `undefined` if container is not found.
|
|
1530
|
+
*/
|
|
1700
1531
|
function getParentContainer(position) {
|
|
1701
1532
|
let parent = position.parent;
|
|
1702
1533
|
while (!isContainerOrFragment(parent)) {
|
|
@@ -1707,14 +1538,12 @@ function getParentContainer(position) {
|
|
|
1707
1538
|
}
|
|
1708
1539
|
return parent;
|
|
1709
1540
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
// @param {module:engine/view/attributeelement~AttributeElement} b
|
|
1717
|
-
// @returns {Boolean}
|
|
1541
|
+
/**
|
|
1542
|
+
* Checks if first {@link module:engine/view/attributeelement~AttributeElement AttributeElement} provided to the function
|
|
1543
|
+
* can be wrapped outside second element. It is done by comparing elements'
|
|
1544
|
+
* {@link module:engine/view/attributeelement~AttributeElement#priority priorities}, if both have same priority
|
|
1545
|
+
* {@link module:engine/view/element~Element#getIdentity identities} are compared.
|
|
1546
|
+
*/
|
|
1718
1547
|
function shouldABeOutsideB(a, b) {
|
|
1719
1548
|
if (a.priority < b.priority) {
|
|
1720
1549
|
return true;
|
|
@@ -1725,15 +1554,18 @@ function shouldABeOutsideB(a, b) {
|
|
|
1725
1554
|
// When priorities are equal and names are different - use identities.
|
|
1726
1555
|
return a.getIdentity() < b.getIdentity();
|
|
1727
1556
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1557
|
+
/**
|
|
1558
|
+
* Returns new position that is moved to near text node. Returns same position if there is no text node before of after
|
|
1559
|
+
* specified position.
|
|
1560
|
+
*
|
|
1561
|
+
* ```html
|
|
1562
|
+
* <p>foo[]</p> -> <p>foo{}</p>
|
|
1563
|
+
* <p>[]foo</p> -> <p>{}foo</p>
|
|
1564
|
+
* ```
|
|
1565
|
+
*
|
|
1566
|
+
* @returns Position located inside text node or same position if there is no text nodes
|
|
1567
|
+
* before or after position location.
|
|
1568
|
+
*/
|
|
1737
1569
|
function movePositionToTextNode(position) {
|
|
1738
1570
|
const nodeBefore = position.nodeBefore;
|
|
1739
1571
|
if (nodeBefore && nodeBefore.is('$text')) {
|
|
@@ -1745,14 +1577,18 @@ function movePositionToTextNode(position) {
|
|
|
1745
1577
|
}
|
|
1746
1578
|
return position;
|
|
1747
1579
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1580
|
+
/**
|
|
1581
|
+
* Breaks text node into two text nodes when possible.
|
|
1582
|
+
*
|
|
1583
|
+
* ```html
|
|
1584
|
+
* <p>foo{}bar</p> -> <p>foo[]bar</p>
|
|
1585
|
+
* <p>{}foobar</p> -> <p>[]foobar</p>
|
|
1586
|
+
* <p>foobar{}</p> -> <p>foobar[]</p>
|
|
1587
|
+
* ```
|
|
1588
|
+
*
|
|
1589
|
+
* @param position Position that need to be placed inside text node.
|
|
1590
|
+
* @returns New position after breaking text node.
|
|
1591
|
+
*/
|
|
1756
1592
|
function breakTextNode(position) {
|
|
1757
1593
|
if (position.offset == position.parent.data.length) {
|
|
1758
1594
|
return new Position(position.parent.parent, position.parent.index + 1);
|
|
@@ -1769,12 +1605,13 @@ function breakTextNode(position) {
|
|
|
1769
1605
|
// Return new position between two newly created text nodes.
|
|
1770
1606
|
return new Position(position.parent.parent, position.parent.index + 1);
|
|
1771
1607
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1608
|
+
/**
|
|
1609
|
+
* Merges two text nodes into first node. Removes second node and returns merge position.
|
|
1610
|
+
*
|
|
1611
|
+
* @param t1 First text node to merge. Data from second text node will be moved at the end of this text node.
|
|
1612
|
+
* @param t2 Second text node to merge. This node will be removed after merging.
|
|
1613
|
+
* @returns Position after merging text nodes.
|
|
1614
|
+
*/
|
|
1778
1615
|
function mergeTextNodes(t1, t2) {
|
|
1779
1616
|
// Merge text data into first text node and remove second one.
|
|
1780
1617
|
const nodeBeforeLength = t1.data.length;
|
|
@@ -1783,13 +1620,12 @@ function mergeTextNodes(t1, t2) {
|
|
|
1783
1620
|
return new Position(t1, nodeBeforeLength);
|
|
1784
1621
|
}
|
|
1785
1622
|
const validNodesToInsert = [Text, AttributeElement, ContainerElement, EmptyElement, RawElement, UIElement];
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
// @param {Object} errorContext
|
|
1623
|
+
/**
|
|
1624
|
+
* Checks if provided nodes are valid to insert.
|
|
1625
|
+
*
|
|
1626
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert
|
|
1627
|
+
* contains instances that are not supported ones (see error description for valid ones.
|
|
1628
|
+
*/
|
|
1793
1629
|
function validateNodesToInsert(nodes, errorContext) {
|
|
1794
1630
|
for (const node of nodes) {
|
|
1795
1631
|
if (!validNodesToInsert.some((validNode => node instanceof validNode))) { // eslint-disable-line no-use-before-define
|
|
@@ -1815,19 +1651,19 @@ function validateNodesToInsert(nodes, errorContext) {
|
|
|
1815
1651
|
}
|
|
1816
1652
|
}
|
|
1817
1653
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1654
|
+
/**
|
|
1655
|
+
* Checks if node is ContainerElement or DocumentFragment, because in most cases they should be treated the same way.
|
|
1656
|
+
*
|
|
1657
|
+
* @returns Returns `true` if node is instance of ContainerElement or DocumentFragment.
|
|
1658
|
+
*/
|
|
1822
1659
|
function isContainerOrFragment(node) {
|
|
1823
1660
|
return node && (node.is('containerElement') || node.is('documentFragment'));
|
|
1824
1661
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
// @param {Object} errorContext
|
|
1662
|
+
/**
|
|
1663
|
+
* Checks if {@link module:engine/view/range~Range#start range start} and {@link module:engine/view/range~Range#end range end} are placed
|
|
1664
|
+
* inside same {@link module:engine/view/containerelement~ContainerElement container element}.
|
|
1665
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when validation fails.
|
|
1666
|
+
*/
|
|
1831
1667
|
function validateRangeContainer(range, errorContext) {
|
|
1832
1668
|
const startContainer = getParentContainer(range.start);
|
|
1833
1669
|
const endContainer = getParentContainer(range.end);
|
|
@@ -1851,13 +1687,10 @@ function validateRangeContainer(range, errorContext) {
|
|
|
1851
1687
|
throw new CKEditorError('view-writer-invalid-range-container', errorContext);
|
|
1852
1688
|
}
|
|
1853
1689
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
// @param {module:engine/view/element~Element} a
|
|
1859
|
-
// @param {module:engine/view/element~Element} b
|
|
1860
|
-
// @returns {Boolean}
|
|
1690
|
+
/**
|
|
1691
|
+
* Checks if two attribute elements can be joined together. Elements can be joined together if, and only if
|
|
1692
|
+
* they do not have ids specified.
|
|
1693
|
+
*/
|
|
1861
1694
|
function canBeJoined(a, b) {
|
|
1862
1695
|
return a.id === null && b.id === null;
|
|
1863
1696
|
}
|