@ckeditor/ckeditor5-engine 36.0.0 → 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/datatransfer.js +24 -27
- 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
|
@@ -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,36 +30,24 @@ 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
52
|
/**
|
|
65
53
|
* Sets {@link module:engine/view/documentselection~DocumentSelection selection's} ranges and direction to the
|
|
@@ -67,63 +55,64 @@ export default class DowncastWriter {
|
|
|
67
55
|
*
|
|
68
56
|
* Usage:
|
|
69
57
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* // Sets selection to the given range.
|
|
60
|
+
* const range = writer.createRange( start, end );
|
|
61
|
+
* writer.setSelection( range );
|
|
73
62
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
63
|
+
* // Sets backward selection to the given range.
|
|
64
|
+
* const range = writer.createRange( start, end );
|
|
65
|
+
* writer.setSelection( range );
|
|
77
66
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
67
|
+
* // Sets selection to given ranges.
|
|
68
|
+
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
|
|
69
|
+
* writer.setSelection( range );
|
|
81
70
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
71
|
+
* // Sets selection to the other selection.
|
|
72
|
+
* const otherSelection = writer.createSelection();
|
|
73
|
+
* writer.setSelection( otherSelection );
|
|
85
74
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
75
|
+
* // Sets collapsed selection at the given position.
|
|
76
|
+
* const position = writer.createPositionFromPath( root, path );
|
|
77
|
+
* writer.setSelection( position );
|
|
89
78
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
79
|
+
* // Sets collapsed selection at the position of given item and offset.
|
|
80
|
+
* const paragraph = writer.createContainerElement( 'p' );
|
|
81
|
+
* writer.setSelection( paragraph, offset );
|
|
82
|
+
* ```
|
|
93
83
|
*
|
|
94
84
|
* Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
|
|
95
85
|
* that element and ends after the last child of that element.
|
|
96
86
|
*
|
|
97
|
-
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* writer.setSelection( paragraph, 'in' );
|
|
89
|
+
* ```
|
|
98
90
|
*
|
|
99
91
|
* Creates a range on the {@link module:engine/view/item~Item item} which starts before the item and ends just after the item.
|
|
100
92
|
*
|
|
101
|
-
*
|
|
93
|
+
* ```ts
|
|
94
|
+
* writer.setSelection( paragraph, 'on' );
|
|
102
95
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
96
|
+
* // Removes all ranges.
|
|
97
|
+
* writer.setSelection( null );
|
|
98
|
+
* ```
|
|
105
99
|
*
|
|
106
100
|
* `DowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
107
101
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
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.
|
|
102
|
+
* ```ts
|
|
103
|
+
* // Sets selection as backward.
|
|
104
|
+
* writer.setSelection( range, { backward: true } );
|
|
105
|
+
*
|
|
106
|
+
* // Sets selection as fake.
|
|
107
|
+
* // Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
108
|
+
* // This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
109
|
+
* // represented in other way, for example by applying proper CSS class.
|
|
110
|
+
* writer.setSelection( range, { fake: true } );
|
|
111
|
+
*
|
|
112
|
+
* // Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
113
|
+
* // (and be properly handled by screen readers).
|
|
114
|
+
* writer.setSelection( range, { fake: true, label: 'foo' } );
|
|
115
|
+
* ```
|
|
127
116
|
*/
|
|
128
117
|
setSelection(...args) {
|
|
129
118
|
this.document.selection._setTo(...args);
|
|
@@ -134,19 +123,16 @@ export default class DowncastWriter {
|
|
|
134
123
|
* The location can be specified in the same form as {@link module:engine/view/view~View#createPositionAt view.createPositionAt()}
|
|
135
124
|
* parameters.
|
|
136
125
|
*
|
|
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}.
|
|
126
|
+
* @param Offset or one of the flags. Used only when the first parameter is a {@link module:engine/view/item~Item view item}.
|
|
140
127
|
*/
|
|
141
|
-
setSelectionFocus(
|
|
142
|
-
this.document.selection._setFocus(
|
|
128
|
+
setSelectionFocus(itemOrPosition, offset) {
|
|
129
|
+
this.document.selection._setFocus(itemOrPosition, offset);
|
|
143
130
|
}
|
|
144
131
|
/**
|
|
145
132
|
* Creates a new {@link module:engine/view/documentfragment~DocumentFragment} instance.
|
|
146
133
|
*
|
|
147
|
-
* @param
|
|
148
|
-
*
|
|
149
|
-
* @returns {module:engine/view/documentfragment~DocumentFragment} The created document fragment.
|
|
134
|
+
* @param children A list of nodes to be inserted into the created document fragment.
|
|
135
|
+
* @returns The created document fragment.
|
|
150
136
|
*/
|
|
151
137
|
createDocumentFragment(children) {
|
|
152
138
|
return new DocumentFragment(this.document, children);
|
|
@@ -154,10 +140,12 @@ export default class DowncastWriter {
|
|
|
154
140
|
/**
|
|
155
141
|
* Creates a new {@link module:engine/view/text~Text text node}.
|
|
156
142
|
*
|
|
157
|
-
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* writer.createText( 'foo' );
|
|
145
|
+
* ```
|
|
158
146
|
*
|
|
159
|
-
* @param
|
|
160
|
-
* @returns
|
|
147
|
+
* @param data The text's data.
|
|
148
|
+
* @returns The created text node.
|
|
161
149
|
*/
|
|
162
150
|
createText(data) {
|
|
163
151
|
return new Text(this.document, data);
|
|
@@ -165,23 +153,25 @@ export default class DowncastWriter {
|
|
|
165
153
|
/**
|
|
166
154
|
* Creates a new {@link module:engine/view/attributeelement~AttributeElement}.
|
|
167
155
|
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
156
|
+
* ```ts
|
|
157
|
+
* writer.createAttributeElement( 'strong' );
|
|
158
|
+
* writer.createAttributeElement( 'a', { href: 'foo.bar' } );
|
|
170
159
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
160
|
+
* // Make `<a>` element contain other attributes element so the `<a>` element is not broken.
|
|
161
|
+
* writer.createAttributeElement( 'a', { href: 'foo.bar' }, { priority: 5 } );
|
|
173
162
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
163
|
+
* // Set `id` of a marker element so it is not joined or merged with "normal" elements.
|
|
164
|
+
* writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
|
|
165
|
+
* ```
|
|
176
166
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @param
|
|
179
|
-
* @param
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
182
|
-
* @param
|
|
167
|
+
* @param name Name of the element.
|
|
168
|
+
* @param attributes Element's attributes.
|
|
169
|
+
* @param options Element's options.
|
|
170
|
+
* @param options.priority Element's {@link module:engine/view/attributeelement~AttributeElement#priority priority}.
|
|
171
|
+
* @param options.id Element's {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
172
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
183
173
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
184
|
-
* @returns
|
|
174
|
+
* @returns Created element.
|
|
185
175
|
*/
|
|
186
176
|
createAttributeElement(name, attributes, options = {}) {
|
|
187
177
|
const attributeElement = new AttributeElement(this.document, name, attributes);
|
|
@@ -213,18 +203,20 @@ export default class DowncastWriter {
|
|
|
213
203
|
/**
|
|
214
204
|
* Creates a new {@link module:engine/view/editableelement~EditableElement}.
|
|
215
205
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
206
|
+
* ```ts
|
|
207
|
+
* writer.createEditableElement( 'div' );
|
|
208
|
+
* writer.createEditableElement( 'div', { id: 'foo-1234' } );
|
|
209
|
+
* ```
|
|
218
210
|
*
|
|
219
211
|
* Note: The editable element is to be used in the editing pipeline. Usually, together with
|
|
220
212
|
* {@link module:widget/utils~toWidgetEditable `toWidgetEditable()`}.
|
|
221
213
|
*
|
|
222
|
-
* @param
|
|
223
|
-
* @param
|
|
224
|
-
* @param
|
|
225
|
-
* @param
|
|
214
|
+
* @param name Name of the element.
|
|
215
|
+
* @param attributes Elements attributes.
|
|
216
|
+
* @param options Element's options.
|
|
217
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
226
218
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
227
|
-
* @returns
|
|
219
|
+
* @returns Created element.
|
|
228
220
|
*/
|
|
229
221
|
createEditableElement(name, attributes, options = {}) {
|
|
230
222
|
const editableElement = new EditableElement(this.document, name, attributes);
|
|
@@ -236,15 +228,17 @@ export default class DowncastWriter {
|
|
|
236
228
|
/**
|
|
237
229
|
* Creates a new {@link module:engine/view/emptyelement~EmptyElement}.
|
|
238
230
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* writer.createEmptyElement( 'img' );
|
|
233
|
+
* writer.createEmptyElement( 'img', { id: 'foo-1234' } );
|
|
234
|
+
* ```
|
|
241
235
|
*
|
|
242
|
-
* @param
|
|
243
|
-
* @param
|
|
244
|
-
* @param
|
|
245
|
-
* @param
|
|
236
|
+
* @param name Name of the element.
|
|
237
|
+
* @param attributes Elements attributes.
|
|
238
|
+
* @param options Element's options.
|
|
239
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
246
240
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
247
|
-
* @returns
|
|
241
|
+
* @returns Created element.
|
|
248
242
|
*/
|
|
249
243
|
createEmptyElement(name, attributes, options = {}) {
|
|
250
244
|
const emptyElement = new EmptyElement(this.document, name, attributes);
|
|
@@ -256,27 +250,31 @@ export default class DowncastWriter {
|
|
|
256
250
|
/**
|
|
257
251
|
* Creates a new {@link module:engine/view/uielement~UIElement}.
|
|
258
252
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* writer.createUIElement( 'span' );
|
|
255
|
+
* writer.createUIElement( 'span', { id: 'foo-1234' } );
|
|
256
|
+
* ```
|
|
261
257
|
*
|
|
262
258
|
* A custom render function can be provided as the third parameter:
|
|
263
259
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
260
|
+
* ```ts
|
|
261
|
+
* writer.createUIElement( 'span', null, function( domDocument ) {
|
|
262
|
+
* const domElement = this.toDomElement( domDocument );
|
|
263
|
+
* domElement.innerHTML = '<b>this is ui element</b>';
|
|
267
264
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
265
|
+
* return domElement;
|
|
266
|
+
* } );
|
|
267
|
+
* ```
|
|
270
268
|
*
|
|
271
269
|
* Unlike {@link #createRawElement raw elements}, UI elements are by no means editor content, for instance,
|
|
272
270
|
* they are ignored by the editor selection system.
|
|
273
271
|
*
|
|
274
272
|
* You should not use UI elements as data containers. Check out {@link #createRawElement} instead.
|
|
275
273
|
*
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
279
|
-
* @returns
|
|
274
|
+
* @param name The name of the element.
|
|
275
|
+
* @param attributes Element attributes.
|
|
276
|
+
* @param renderFunction A custom render function.
|
|
277
|
+
* @returns The created element.
|
|
280
278
|
*/
|
|
281
279
|
createUIElement(name, attributes, renderFunction) {
|
|
282
280
|
const uiElement = new UIElement(this.document, name, attributes);
|
|
@@ -288,9 +286,11 @@ export default class DowncastWriter {
|
|
|
288
286
|
/**
|
|
289
287
|
* Creates a new {@link module:engine/view/rawelement~RawElement}.
|
|
290
288
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
|
|
291
|
+
* domElement.innerHTML = '<b>This is the raw content of the raw element.</b>';
|
|
292
|
+
* } );
|
|
293
|
+
* ```
|
|
294
294
|
*
|
|
295
295
|
* Raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
|
|
296
296
|
* even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
|
|
@@ -304,13 +304,13 @@ export default class DowncastWriter {
|
|
|
304
304
|
* You should not use raw elements to render the UI in the editor content. Check out {@link #createUIElement `#createUIElement()`}
|
|
305
305
|
* instead.
|
|
306
306
|
*
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
307
|
+
* @param name The name of the element.
|
|
308
|
+
* @param attributes Element attributes.
|
|
309
|
+
* @param renderFunction A custom render function.
|
|
310
|
+
* @param options Element's options.
|
|
311
|
+
* @param options.renderUnsafeAttributes A list of attribute names that should be rendered in the editing
|
|
312
312
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
313
|
-
* @returns
|
|
313
|
+
* @returns The created element.
|
|
314
314
|
*/
|
|
315
315
|
createRawElement(name, attributes, renderFunction, options = {}) {
|
|
316
316
|
const rawElement = new RawElement(this.document, name, attributes);
|
|
@@ -325,11 +325,12 @@ export default class DowncastWriter {
|
|
|
325
325
|
/**
|
|
326
326
|
* Adds or overwrites the element's attribute with a specified key and value.
|
|
327
327
|
*
|
|
328
|
-
*
|
|
328
|
+
* ```ts
|
|
329
|
+
* writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
|
|
330
|
+
* ```
|
|
329
331
|
*
|
|
330
|
-
* @param
|
|
331
|
-
* @param
|
|
332
|
-
* @param {module:engine/view/element~Element} element
|
|
332
|
+
* @param key The attribute key.
|
|
333
|
+
* @param value The attribute value.
|
|
333
334
|
*/
|
|
334
335
|
setAttribute(key, value, element) {
|
|
335
336
|
element._setAttribute(key, value);
|
|
@@ -337,10 +338,11 @@ export default class DowncastWriter {
|
|
|
337
338
|
/**
|
|
338
339
|
* Removes attribute from the element.
|
|
339
340
|
*
|
|
340
|
-
*
|
|
341
|
+
* ```ts
|
|
342
|
+
* writer.removeAttribute( 'href', linkElement );
|
|
343
|
+
* ```
|
|
341
344
|
*
|
|
342
|
-
* @param
|
|
343
|
-
* @param {module:engine/view/element~Element} element
|
|
345
|
+
* @param key Attribute key.
|
|
344
346
|
*/
|
|
345
347
|
removeAttribute(key, element) {
|
|
346
348
|
element._removeAttribute(key);
|
|
@@ -348,11 +350,10 @@ export default class DowncastWriter {
|
|
|
348
350
|
/**
|
|
349
351
|
* Adds specified class to the element.
|
|
350
352
|
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
* @param {module:engine/view/element~Element} element
|
|
353
|
+
* ```ts
|
|
354
|
+
* writer.addClass( 'foo', linkElement );
|
|
355
|
+
* writer.addClass( [ 'foo', 'bar' ], linkElement );
|
|
356
|
+
* ```
|
|
356
357
|
*/
|
|
357
358
|
addClass(className, element) {
|
|
358
359
|
element._addClass(className);
|
|
@@ -360,11 +361,10 @@ export default class DowncastWriter {
|
|
|
360
361
|
/**
|
|
361
362
|
* Removes specified class from the element.
|
|
362
363
|
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @param {module:engine/view/element~Element} element
|
|
364
|
+
* ```ts
|
|
365
|
+
* writer.removeClass( 'foo', linkElement );
|
|
366
|
+
* writer.removeClass( [ 'foo', 'bar' ], linkElement );
|
|
367
|
+
* ```
|
|
368
368
|
*/
|
|
369
369
|
removeClass(className, element) {
|
|
370
370
|
element._removeClass(className);
|
|
@@ -380,15 +380,14 @@ export default class DowncastWriter {
|
|
|
380
380
|
/**
|
|
381
381
|
* Removes specified style from the element.
|
|
382
382
|
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
383
|
+
* ```ts
|
|
384
|
+
* writer.removeStyle( 'color', element ); // Removes 'color' style.
|
|
385
|
+
* writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
|
|
386
|
+
* ```
|
|
385
387
|
*
|
|
386
388
|
* **Note**: This method can work with normalized style names if
|
|
387
389
|
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
388
390
|
* 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
391
|
*/
|
|
393
392
|
removeStyle(property, element) {
|
|
394
393
|
element._removeStyle(property);
|
|
@@ -396,10 +395,6 @@ export default class DowncastWriter {
|
|
|
396
395
|
/**
|
|
397
396
|
* Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM,
|
|
398
397
|
* 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
398
|
*/
|
|
404
399
|
setCustomProperty(key, value, element) {
|
|
405
400
|
element._setCustomProperty(key, value);
|
|
@@ -407,9 +402,7 @@ export default class DowncastWriter {
|
|
|
407
402
|
/**
|
|
408
403
|
* Removes a custom property stored under the given key.
|
|
409
404
|
*
|
|
410
|
-
* @
|
|
411
|
-
* @param {module:engine/view/element~Element} element
|
|
412
|
-
* @returns {Boolean} Returns true if property was removed.
|
|
405
|
+
* @returns Returns true if property was removed.
|
|
413
406
|
*/
|
|
414
407
|
removeCustomProperty(key, element) {
|
|
415
408
|
return element._removeCustomProperty(key);
|
|
@@ -420,10 +413,12 @@ export default class DowncastWriter {
|
|
|
420
413
|
*
|
|
421
414
|
* In following examples `<p>` is a container, `<b>` and `<u>` are attribute elements:
|
|
422
415
|
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
416
|
+
* ```html
|
|
417
|
+
* <p>foo<b><u>bar{}</u></b></p> -> <p>foo<b><u>bar</u></b>[]</p>
|
|
418
|
+
* <p>foo<b><u>{}bar</u></b></p> -> <p>foo{}<b><u>bar</u></b></p>
|
|
419
|
+
* <p>foo<b><u>b{}ar</u></b></p> -> <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
|
|
420
|
+
* <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>
|
|
421
|
+
* ```
|
|
427
422
|
*
|
|
428
423
|
* **Note:** {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment} is treated like a container.
|
|
429
424
|
*
|
|
@@ -446,10 +441,8 @@ export default class DowncastWriter {
|
|
|
446
441
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
447
442
|
* @see module:engine/view/containerelement~ContainerElement
|
|
448
443
|
* @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.
|
|
444
|
+
* @param positionOrRange The position where to break attribute elements.
|
|
445
|
+
* @returns The new position or range, after breaking the attribute elements.
|
|
453
446
|
*/
|
|
454
447
|
breakAttributes(positionOrRange) {
|
|
455
448
|
if (positionOrRange instanceof Position) {
|
|
@@ -464,10 +457,12 @@ export default class DowncastWriter {
|
|
|
464
457
|
* 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
458
|
* if the position is at the beginning or at the end of its parent element.
|
|
466
459
|
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
460
|
+
* ```html
|
|
461
|
+
* <p>foo^bar</p> -> <p>foo</p><p>bar</p>
|
|
462
|
+
* <div><p>foo</p>^<p>bar</p></div> -> <div><p>foo</p></div><div><p>bar</p></div>
|
|
463
|
+
* <p>^foobar</p> -> ^<p>foobar</p>
|
|
464
|
+
* <p>foobar^</p> -> <p>foobar</p>^
|
|
465
|
+
* ```
|
|
471
466
|
*
|
|
472
467
|
* **Note:** The difference between {@link module:engine/view/downcastwriter~DowncastWriter#breakAttributes breakAttributes()} and
|
|
473
468
|
* {@link module:engine/view/downcastwriter~DowncastWriter#breakContainer breakContainer()} is that `breakAttributes()` breaks all
|
|
@@ -478,8 +473,8 @@ export default class DowncastWriter {
|
|
|
478
473
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
479
474
|
* @see module:engine/view/containerelement~ContainerElement
|
|
480
475
|
* @see module:engine/view/downcastwriter~DowncastWriter#breakAttributes
|
|
481
|
-
* @param
|
|
482
|
-
* @returns
|
|
476
|
+
* @param position The position where to break the element.
|
|
477
|
+
* @returns The position between broken elements. If an element has not been broken,
|
|
483
478
|
* the returned position is placed either before or after it.
|
|
484
479
|
*/
|
|
485
480
|
breakContainer(position) {
|
|
@@ -518,14 +513,18 @@ export default class DowncastWriter {
|
|
|
518
513
|
*
|
|
519
514
|
* In following examples `<p>` is a container and `<b>` is an attribute element:
|
|
520
515
|
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
516
|
+
* ```html
|
|
517
|
+
* <p>foo[]bar</p> -> <p>foo{}bar</p>
|
|
518
|
+
* <p><b>foo</b>[]<b>bar</b></p> -> <p><b>foo{}bar</b></p>
|
|
519
|
+
* <p><b foo="bar">a</b>[]<b foo="baz">b</b></p> -> <p><b foo="bar">a</b>[]<b foo="baz">b</b></p>
|
|
520
|
+
* ```
|
|
524
521
|
*
|
|
525
522
|
* It will also take care about empty attributes when merging:
|
|
526
523
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
524
|
+
* ```html
|
|
525
|
+
* <p><b>[]</b></p> -> <p>[]</p>
|
|
526
|
+
* <p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
|
|
527
|
+
* ```
|
|
529
528
|
*
|
|
530
529
|
* **Note:** Difference between {@link module:engine/view/downcastwriter~DowncastWriter#mergeAttributes mergeAttributes} and
|
|
531
530
|
* {@link module:engine/view/downcastwriter~DowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
@@ -535,8 +534,8 @@ export default class DowncastWriter {
|
|
|
535
534
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
536
535
|
* @see module:engine/view/containerelement~ContainerElement
|
|
537
536
|
* @see module:engine/view/downcastwriter~DowncastWriter#mergeContainers
|
|
538
|
-
* @param
|
|
539
|
-
* @returns
|
|
537
|
+
* @param position Merge position.
|
|
538
|
+
* @returns Position after merge.
|
|
540
539
|
*/
|
|
541
540
|
mergeAttributes(position) {
|
|
542
541
|
const positionOffset = position.offset;
|
|
@@ -580,8 +579,10 @@ export default class DowncastWriter {
|
|
|
580
579
|
* Merges two {@link module:engine/view/containerelement~ContainerElement container elements} that are before and after given position.
|
|
581
580
|
* Precisely, the element after the position is removed and it's contents are moved to element before the position.
|
|
582
581
|
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
582
|
+
* ```html
|
|
583
|
+
* <p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
|
|
584
|
+
* <div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
|
|
585
|
+
* ```
|
|
585
586
|
*
|
|
586
587
|
* **Note:** Difference between {@link module:engine/view/downcastwriter~DowncastWriter#mergeAttributes mergeAttributes} and
|
|
587
588
|
* {@link module:engine/view/downcastwriter~DowncastWriter#mergeContainers mergeContainers} is that `mergeAttributes` merges two
|
|
@@ -591,8 +592,8 @@ export default class DowncastWriter {
|
|
|
591
592
|
* @see module:engine/view/attributeelement~AttributeElement
|
|
592
593
|
* @see module:engine/view/containerelement~ContainerElement
|
|
593
594
|
* @see module:engine/view/downcastwriter~DowncastWriter#mergeAttributes
|
|
594
|
-
* @param
|
|
595
|
-
* @returns
|
|
595
|
+
* @param position Merge position.
|
|
596
|
+
* @returns Position after merge.
|
|
596
597
|
*/
|
|
597
598
|
mergeContainers(position) {
|
|
598
599
|
const prev = position.nodeBefore;
|
|
@@ -623,15 +624,9 @@ export default class DowncastWriter {
|
|
|
623
624
|
* {@link module:engine/view/rawelement~RawElement RawElements} or
|
|
624
625
|
* {@link module:engine/view/uielement~UIElement UIElements}.
|
|
625
626
|
*
|
|
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.
|
|
627
|
+
* @param position Insertion position.
|
|
628
|
+
* @param nodes Node or nodes to insert.
|
|
629
|
+
* @returns Range around inserted nodes.
|
|
635
630
|
*/
|
|
636
631
|
insert(position, nodes) {
|
|
637
632
|
nodes = isIterable(nodes) ? [...nodes] : [nodes];
|
|
@@ -677,10 +672,10 @@ export default class DowncastWriter {
|
|
|
677
672
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
678
673
|
* same parent container.
|
|
679
674
|
*
|
|
680
|
-
* @param
|
|
675
|
+
* @param rangeOrItem Range to remove from container
|
|
681
676
|
* or an {@link module:engine/view/item~Item item} to remove. If range is provided, after removing, it will be updated
|
|
682
677
|
* to a collapsed range showing the new position.
|
|
683
|
-
* @returns
|
|
678
|
+
* @returns Document fragment containing removed nodes.
|
|
684
679
|
*/
|
|
685
680
|
remove(rangeOrItem) {
|
|
686
681
|
const range = rangeOrItem instanceof Range ? rangeOrItem : Range._createOn(rangeOrItem);
|
|
@@ -712,8 +707,8 @@ export default class DowncastWriter {
|
|
|
712
707
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
713
708
|
* same parent container.
|
|
714
709
|
*
|
|
715
|
-
* @param
|
|
716
|
-
* @param
|
|
710
|
+
* @param range Range to clear.
|
|
711
|
+
* @param element Element to remove.
|
|
717
712
|
*/
|
|
718
713
|
clear(range, element) {
|
|
719
714
|
validateRangeContainer(range, this.document);
|
|
@@ -764,9 +759,9 @@ export default class DowncastWriter {
|
|
|
764
759
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
765
760
|
* same parent container.
|
|
766
761
|
*
|
|
767
|
-
* @param
|
|
768
|
-
* @param
|
|
769
|
-
* @returns
|
|
762
|
+
* @param sourceRange Range containing nodes to move.
|
|
763
|
+
* @param targetPosition Position to insert.
|
|
764
|
+
* @returns Range in target container. Inserted nodes are placed between
|
|
770
765
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions.
|
|
771
766
|
*/
|
|
772
767
|
move(sourceRange, targetPosition) {
|
|
@@ -801,9 +796,9 @@ export default class DowncastWriter {
|
|
|
801
796
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
|
|
802
797
|
* is collapsed and different than view selection.
|
|
803
798
|
*
|
|
804
|
-
* @param
|
|
805
|
-
* @param
|
|
806
|
-
* @returns
|
|
799
|
+
* @param range Range to wrap.
|
|
800
|
+
* @param attribute Attribute element to use as wrapper.
|
|
801
|
+
* @returns range Range after wrapping, spanning over wrapping attribute element.
|
|
807
802
|
*/
|
|
808
803
|
wrap(range, attribute) {
|
|
809
804
|
if (!(attribute instanceof AttributeElement)) {
|
|
@@ -835,9 +830,6 @@ export default class DowncastWriter {
|
|
|
835
830
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when
|
|
836
831
|
* {@link module:engine/view/range~Range#start start} and {@link module:engine/view/range~Range#end end} positions are not placed inside
|
|
837
832
|
* same parent container.
|
|
838
|
-
*
|
|
839
|
-
* @param {module:engine/view/range~Range} range
|
|
840
|
-
* @param {module:engine/view/attributeelement~AttributeElement} attribute
|
|
841
833
|
*/
|
|
842
834
|
unwrap(range, attribute) {
|
|
843
835
|
if (!(attribute instanceof AttributeElement)) {
|
|
@@ -877,9 +869,9 @@ export default class DowncastWriter {
|
|
|
877
869
|
*
|
|
878
870
|
* Since this function creates a new element and removes the given one, the new element is returned to keep reference.
|
|
879
871
|
*
|
|
880
|
-
* @param
|
|
881
|
-
* @param
|
|
882
|
-
* @returns
|
|
872
|
+
* @param newName New name for element.
|
|
873
|
+
* @param viewElement Element to be renamed.
|
|
874
|
+
* @returns Element created due to rename.
|
|
883
875
|
*/
|
|
884
876
|
rename(newName, viewElement) {
|
|
885
877
|
const newElement = new ContainerElement(this.document, newName, viewElement.getAttributes());
|
|
@@ -900,7 +892,7 @@ export default class DowncastWriter {
|
|
|
900
892
|
*
|
|
901
893
|
* Keep in mind that group names are equal to the `id` property of the attribute element.
|
|
902
894
|
*
|
|
903
|
-
* @param
|
|
895
|
+
* @param groupName Name of the group to clear.
|
|
904
896
|
*/
|
|
905
897
|
clearClonedElementsGroup(groupName) {
|
|
906
898
|
this._cloneGroups.delete(groupName);
|
|
@@ -918,10 +910,7 @@ export default class DowncastWriter {
|
|
|
918
910
|
* * {@link #createPositionBefore},
|
|
919
911
|
* * {@link #createPositionAfter},
|
|
920
912
|
*
|
|
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}
|
|
913
|
+
* @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
914
|
*/
|
|
926
915
|
createPositionAt(itemOrPosition, offset) {
|
|
927
916
|
return Position._createAt(itemOrPosition, offset);
|
|
@@ -929,8 +918,7 @@ export default class DowncastWriter {
|
|
|
929
918
|
/**
|
|
930
919
|
* Creates a new position after given view item.
|
|
931
920
|
*
|
|
932
|
-
* @param
|
|
933
|
-
* @returns {module:engine/view/position~Position}
|
|
921
|
+
* @param item View item after which the position should be located.
|
|
934
922
|
*/
|
|
935
923
|
createPositionAfter(item) {
|
|
936
924
|
return Position._createAfter(item);
|
|
@@ -938,8 +926,7 @@ export default class DowncastWriter {
|
|
|
938
926
|
/**
|
|
939
927
|
* Creates a new position before given view item.
|
|
940
928
|
*
|
|
941
|
-
* @param
|
|
942
|
-
* @returns {module:engine/view/position~Position}
|
|
929
|
+
* @param item View item before which the position should be located.
|
|
943
930
|
*/
|
|
944
931
|
createPositionBefore(item) {
|
|
945
932
|
return Position._createBefore(item);
|
|
@@ -949,18 +936,14 @@ export default class DowncastWriter {
|
|
|
949
936
|
*
|
|
950
937
|
* **Note:** This factory method creates its own {@link module:engine/view/position~Position} instances basing on passed values.
|
|
951
938
|
*
|
|
952
|
-
* @param
|
|
953
|
-
* @param
|
|
954
|
-
* @returns {module:engine/view/range~Range}
|
|
939
|
+
* @param start Start position.
|
|
940
|
+
* @param end End position. If not set, range will be collapsed at `start` position.
|
|
955
941
|
*/
|
|
956
|
-
createRange(
|
|
957
|
-
return new Range(
|
|
942
|
+
createRange(start, end) {
|
|
943
|
+
return new Range(start, end);
|
|
958
944
|
}
|
|
959
945
|
/**
|
|
960
946
|
* 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
947
|
*/
|
|
965
948
|
createRangeOn(item) {
|
|
966
949
|
return Range._createOn(item);
|
|
@@ -969,8 +952,7 @@ export default class DowncastWriter {
|
|
|
969
952
|
* Creates a range inside an {@link module:engine/view/element~Element element} which starts before the first child of
|
|
970
953
|
* that element and ends after the last child of that element.
|
|
971
954
|
*
|
|
972
|
-
* @param
|
|
973
|
-
* @returns {module:engine/view/range~Range}
|
|
955
|
+
* @param element Element which is a parent for the range.
|
|
974
956
|
*/
|
|
975
957
|
createRangeIn(element) {
|
|
976
958
|
return Range._createIn(element);
|
|
@@ -978,44 +960,48 @@ export default class DowncastWriter {
|
|
|
978
960
|
/**
|
|
979
961
|
* Creates new {@link module:engine/view/selection~Selection} instance.
|
|
980
962
|
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
963
|
+
* ```ts
|
|
964
|
+
* // Creates empty selection without ranges.
|
|
965
|
+
* const selection = writer.createSelection();
|
|
983
966
|
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
967
|
+
* // Creates selection at the given range.
|
|
968
|
+
* const range = writer.createRange( start, end );
|
|
969
|
+
* const selection = writer.createSelection( range );
|
|
987
970
|
*
|
|
988
|
-
*
|
|
989
|
-
*
|
|
990
|
-
*
|
|
971
|
+
* // Creates selection at the given ranges
|
|
972
|
+
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
|
|
973
|
+
* const selection = writer.createSelection( ranges );
|
|
991
974
|
*
|
|
992
|
-
*
|
|
993
|
-
*
|
|
994
|
-
*
|
|
975
|
+
* // Creates selection from the other selection.
|
|
976
|
+
* const otherSelection = writer.createSelection();
|
|
977
|
+
* const selection = writer.createSelection( otherSelection );
|
|
995
978
|
*
|
|
996
|
-
*
|
|
997
|
-
*
|
|
979
|
+
* // Creates selection from the document selection.
|
|
980
|
+
* const selection = writer.createSelection( editor.editing.view.document.selection );
|
|
998
981
|
*
|
|
999
|
-
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
982
|
+
* // Creates selection at the given position.
|
|
983
|
+
* const position = writer.createPositionFromPath( root, path );
|
|
984
|
+
* const selection = writer.createSelection( position );
|
|
1002
985
|
*
|
|
1003
|
-
*
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
986
|
+
* // Creates collapsed selection at the position of given item and offset.
|
|
987
|
+
* const paragraph = writer.createContainerElement( 'p' );
|
|
988
|
+
* const selection = writer.createSelection( paragraph, offset );
|
|
1006
989
|
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
990
|
+
* // Creates a range inside an {@link module:engine/view/element~Element element} which starts before the
|
|
991
|
+
* // first child of that element and ends after the last child of that element.
|
|
992
|
+
* const selection = writer.createSelection( paragraph, 'in' );
|
|
1010
993
|
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
994
|
+
* // Creates a range on an {@link module:engine/view/item~Item item} which starts before the item and ends
|
|
995
|
+
* // just after the item.
|
|
996
|
+
* const selection = writer.createSelection( paragraph, 'on' );
|
|
997
|
+
* ```
|
|
1014
998
|
*
|
|
1015
999
|
* `Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
1016
1000
|
*
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* // Creates backward selection.
|
|
1003
|
+
* const selection = writer.createSelection( range, { backward: true } );
|
|
1004
|
+
* ```
|
|
1019
1005
|
*
|
|
1020
1006
|
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
1021
1007
|
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
@@ -1024,16 +1010,10 @@ export default class DowncastWriter {
|
|
|
1024
1010
|
* Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
|
|
1025
1011
|
* (and be properly handled by screen readers).
|
|
1026
1012
|
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
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}
|
|
1013
|
+
* ```ts
|
|
1014
|
+
* // Creates fake selection with label.
|
|
1015
|
+
* const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
|
|
1016
|
+
* ```
|
|
1037
1017
|
*/
|
|
1038
1018
|
createSelection(...args) {
|
|
1039
1019
|
return new Selection(...args);
|
|
@@ -1042,28 +1022,32 @@ export default class DowncastWriter {
|
|
|
1042
1022
|
* Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
|
|
1043
1023
|
* `elementToStructure()`} conversion helper.
|
|
1044
1024
|
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* const viewSlot = conversionApi.writer.createSlot();
|
|
1027
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1047
1028
|
*
|
|
1048
|
-
*
|
|
1029
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
1030
|
+
* ```
|
|
1049
1031
|
*
|
|
1050
1032
|
* It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):
|
|
1051
1033
|
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
1034
|
+
* ```ts
|
|
1035
|
+
* const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
|
|
1036
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1054
1037
|
*
|
|
1055
|
-
*
|
|
1038
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
1039
|
+
* ```
|
|
1056
1040
|
*
|
|
1057
1041
|
* While providing a filtered slot, make sure to provide slots for all child nodes. A single node can not be downcasted into
|
|
1058
1042
|
* multiple slots.
|
|
1059
1043
|
*
|
|
1060
1044
|
* **Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.
|
|
1061
1045
|
*
|
|
1062
|
-
* @param
|
|
1063
|
-
* @returns
|
|
1046
|
+
* @param modeOrFilter The filter for child nodes.
|
|
1047
|
+
* @returns The slot element to be placed in to the view structure while processing
|
|
1064
1048
|
* {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`}.
|
|
1065
1049
|
*/
|
|
1066
|
-
createSlot(modeOrFilter) {
|
|
1050
|
+
createSlot(modeOrFilter = 'children') {
|
|
1067
1051
|
if (!this._slotFactory) {
|
|
1068
1052
|
/**
|
|
1069
1053
|
* The `createSlot()` method is only allowed inside the `elementToStructure` downcast helper callback.
|
|
@@ -1077,8 +1061,8 @@ export default class DowncastWriter {
|
|
|
1077
1061
|
/**
|
|
1078
1062
|
* Registers a slot factory.
|
|
1079
1063
|
*
|
|
1080
|
-
* @
|
|
1081
|
-
* @param
|
|
1064
|
+
* @internal
|
|
1065
|
+
* @param slotFactory The slot factory.
|
|
1082
1066
|
*/
|
|
1083
1067
|
_registerSlotFactory(slotFactory) {
|
|
1084
1068
|
this._slotFactory = slotFactory;
|
|
@@ -1086,7 +1070,7 @@ export default class DowncastWriter {
|
|
|
1086
1070
|
/**
|
|
1087
1071
|
* Clears the registered slot factory.
|
|
1088
1072
|
*
|
|
1089
|
-
* @
|
|
1073
|
+
* @internal
|
|
1090
1074
|
*/
|
|
1091
1075
|
_clearSlotFactory() {
|
|
1092
1076
|
this._slotFactory = null;
|
|
@@ -1095,17 +1079,10 @@ export default class DowncastWriter {
|
|
|
1095
1079
|
* Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion
|
|
1096
1080
|
* and merging them afterwards if requested by the breakAttributes param.
|
|
1097
1081
|
*
|
|
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.
|
|
1082
|
+
* @param position Insertion position.
|
|
1083
|
+
* @param nodes Node or nodes to insert.
|
|
1084
|
+
* @param breakAttributes Whether attributes should be broken.
|
|
1085
|
+
* @returns Range around inserted nodes.
|
|
1109
1086
|
*/
|
|
1110
1087
|
_insertNodes(position, nodes, breakAttributes) {
|
|
1111
1088
|
let parentElement;
|
|
@@ -1148,12 +1125,6 @@ export default class DowncastWriter {
|
|
|
1148
1125
|
/**
|
|
1149
1126
|
* Wraps children with provided `wrapElement`. Only children contained in `parent` element between
|
|
1150
1127
|
* `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
1128
|
*/
|
|
1158
1129
|
_wrapChildren(parent, startOffset, endOffset, wrapElement) {
|
|
1159
1130
|
let i = startOffset;
|
|
@@ -1219,12 +1190,6 @@ export default class DowncastWriter {
|
|
|
1219
1190
|
/**
|
|
1220
1191
|
* Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between
|
|
1221
1192
|
* `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
1193
|
*/
|
|
1229
1194
|
_unwrapChildren(parent, startOffset, endOffset, unwrapElement) {
|
|
1230
1195
|
let i = startOffset;
|
|
@@ -1304,10 +1269,7 @@ export default class DowncastWriter {
|
|
|
1304
1269
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1305
1270
|
* an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.
|
|
1306
1271
|
*
|
|
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.
|
|
1272
|
+
* @returns New range after wrapping, spanning over wrapping attribute element.
|
|
1311
1273
|
*/
|
|
1312
1274
|
_wrapRange(range, attribute) {
|
|
1313
1275
|
// Break attributes at range start and end.
|
|
@@ -1331,10 +1293,7 @@ export default class DowncastWriter {
|
|
|
1331
1293
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-invalid-attribute` when passed attribute element is not
|
|
1332
1294
|
* an instance of {@link module:engine/view/attributeelement~AttributeElement AttributeElement}.
|
|
1333
1295
|
*
|
|
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.
|
|
1296
|
+
* @returns New position after wrapping.
|
|
1338
1297
|
*/
|
|
1339
1298
|
_wrapPosition(position, attribute) {
|
|
1340
1299
|
// Return same position when trying to wrap with attribute similar to position parent.
|
|
@@ -1368,14 +1327,13 @@ export default class DowncastWriter {
|
|
|
1368
1327
|
return movePositionToTextNode(newPosition);
|
|
1369
1328
|
}
|
|
1370
1329
|
/**
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
*
|
|
1377
|
-
*
|
|
1378
|
-
* @returns {Boolean} Returns `true` if elements are merged.
|
|
1330
|
+
* Wraps one {@link module:engine/view/attributeelement~AttributeElement AttributeElement} into another by
|
|
1331
|
+
* merging them if possible. When merging is possible - all attributes, styles and classes are moved from wrapper
|
|
1332
|
+
* element to element being wrapped.
|
|
1333
|
+
*
|
|
1334
|
+
* @param wrapper Wrapper AttributeElement.
|
|
1335
|
+
* @param toWrap AttributeElement to wrap using wrapper element.
|
|
1336
|
+
* @returns Returns `true` if elements are merged.
|
|
1379
1337
|
*/
|
|
1380
1338
|
_wrapAttributeElement(wrapper, toWrap) {
|
|
1381
1339
|
if (!canBeJoined(wrapper, toWrap)) {
|
|
@@ -1430,10 +1388,9 @@ export default class DowncastWriter {
|
|
|
1430
1388
|
* corresponding attributes, classes and styles. All attributes, classes and styles from wrapper should be present
|
|
1431
1389
|
* inside element being unwrapped.
|
|
1432
1390
|
*
|
|
1433
|
-
* @
|
|
1434
|
-
* @param
|
|
1435
|
-
* @
|
|
1436
|
-
* @returns {Boolean} Returns `true` if elements are unwrapped.
|
|
1391
|
+
* @param wrapper Wrapper AttributeElement.
|
|
1392
|
+
* @param toUnwrap AttributeElement to unwrap using wrapper element.
|
|
1393
|
+
* @returns Returns `true` if elements are unwrapped.
|
|
1437
1394
|
**/
|
|
1438
1395
|
_unwrapAttributeElement(wrapper, toUnwrap) {
|
|
1439
1396
|
if (!canBeJoined(wrapper, toUnwrap)) {
|
|
@@ -1482,11 +1439,10 @@ export default class DowncastWriter {
|
|
|
1482
1439
|
/**
|
|
1483
1440
|
* Helper function used by other `DowncastWriter` methods. Breaks attribute elements at the boundaries of given range.
|
|
1484
1441
|
*
|
|
1485
|
-
* @
|
|
1486
|
-
* @param
|
|
1487
|
-
* @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.
|
|
1442
|
+
* @param range Range which `start` and `end` positions will be used to break attributes.
|
|
1443
|
+
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
1488
1444
|
* This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
|
|
1489
|
-
* @returns
|
|
1445
|
+
* @returns New range with located at break positions.
|
|
1490
1446
|
*/
|
|
1491
1447
|
_breakAttributesRange(range, forceSplitText = false) {
|
|
1492
1448
|
const rangeStart = range.start;
|
|
@@ -1513,11 +1469,10 @@ export default class DowncastWriter {
|
|
|
1513
1469
|
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-cannot-break-ui-element` when break position
|
|
1514
1470
|
* is placed inside {@link module:engine/view/uielement~UIElement UIElement}.
|
|
1515
1471
|
*
|
|
1516
|
-
* @
|
|
1517
|
-
* @param
|
|
1518
|
-
* @param {Boolean} [forceSplitText=false] If set to `true`, will break text nodes even if they are directly in container element.
|
|
1472
|
+
* @param position Position where to break attributes.
|
|
1473
|
+
* @param forceSplitText If set to `true`, will break text nodes even if they are directly in container element.
|
|
1519
1474
|
* This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.
|
|
1520
|
-
* @returns
|
|
1475
|
+
* @returns New position after breaking the attributes.
|
|
1521
1476
|
*/
|
|
1522
1477
|
_breakAttributes(position, forceSplitText = false) {
|
|
1523
1478
|
const positionOffset = position.offset;
|
|
@@ -1620,8 +1575,7 @@ export default class DowncastWriter {
|
|
|
1620
1575
|
*
|
|
1621
1576
|
* Does nothing if added element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
1622
1577
|
*
|
|
1623
|
-
* @
|
|
1624
|
-
* @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to save.
|
|
1578
|
+
* @param element Attribute element to save.
|
|
1625
1579
|
*/
|
|
1626
1580
|
_addToClonedElementsGroup(element) {
|
|
1627
1581
|
// Add only if the element is in document tree.
|
|
@@ -1656,8 +1610,7 @@ export default class DowncastWriter {
|
|
|
1656
1610
|
*
|
|
1657
1611
|
* Does nothing if the element has no {@link module:engine/view/attributeelement~AttributeElement#id id}.
|
|
1658
1612
|
*
|
|
1659
|
-
* @
|
|
1660
|
-
* @param {module:engine/view/attributeelement~AttributeElement} element Attribute element to remove.
|
|
1613
|
+
* @param element Attribute element to remove.
|
|
1661
1614
|
*/
|
|
1662
1615
|
_removeFromClonedElementsGroup(element) {
|
|
1663
1616
|
// Traverse the element's children recursively to find other attribute elements that also got removed.
|
|
@@ -1690,13 +1643,14 @@ function _hasNonUiChildren(parent) {
|
|
|
1690
1643
|
*
|
|
1691
1644
|
* @error view-writer-wrap-invalid-attribute
|
|
1692
1645
|
*/
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1646
|
+
/**
|
|
1647
|
+
* Returns first parent container of specified {@link module:engine/view/position~Position Position}.
|
|
1648
|
+
* Position's parent node is checked as first, then next parents are checked.
|
|
1649
|
+
* Note that {@link module:engine/view/documentfragment~DocumentFragment DocumentFragment} is treated like a container.
|
|
1650
|
+
*
|
|
1651
|
+
* @param position Position used as a start point to locate parent container.
|
|
1652
|
+
* @returns Parent container element or `undefined` if container is not found.
|
|
1653
|
+
*/
|
|
1700
1654
|
function getParentContainer(position) {
|
|
1701
1655
|
let parent = position.parent;
|
|
1702
1656
|
while (!isContainerOrFragment(parent)) {
|
|
@@ -1707,14 +1661,12 @@ function getParentContainer(position) {
|
|
|
1707
1661
|
}
|
|
1708
1662
|
return parent;
|
|
1709
1663
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
// @param {module:engine/view/attributeelement~AttributeElement} b
|
|
1717
|
-
// @returns {Boolean}
|
|
1664
|
+
/**
|
|
1665
|
+
* Checks if first {@link module:engine/view/attributeelement~AttributeElement AttributeElement} provided to the function
|
|
1666
|
+
* can be wrapped outside second element. It is done by comparing elements'
|
|
1667
|
+
* {@link module:engine/view/attributeelement~AttributeElement#priority priorities}, if both have same priority
|
|
1668
|
+
* {@link module:engine/view/element~Element#getIdentity identities} are compared.
|
|
1669
|
+
*/
|
|
1718
1670
|
function shouldABeOutsideB(a, b) {
|
|
1719
1671
|
if (a.priority < b.priority) {
|
|
1720
1672
|
return true;
|
|
@@ -1725,15 +1677,18 @@ function shouldABeOutsideB(a, b) {
|
|
|
1725
1677
|
// When priorities are equal and names are different - use identities.
|
|
1726
1678
|
return a.getIdentity() < b.getIdentity();
|
|
1727
1679
|
}
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1680
|
+
/**
|
|
1681
|
+
* Returns new position that is moved to near text node. Returns same position if there is no text node before of after
|
|
1682
|
+
* specified position.
|
|
1683
|
+
*
|
|
1684
|
+
* ```html
|
|
1685
|
+
* <p>foo[]</p> -> <p>foo{}</p>
|
|
1686
|
+
* <p>[]foo</p> -> <p>{}foo</p>
|
|
1687
|
+
* ```
|
|
1688
|
+
*
|
|
1689
|
+
* @returns Position located inside text node or same position if there is no text nodes
|
|
1690
|
+
* before or after position location.
|
|
1691
|
+
*/
|
|
1737
1692
|
function movePositionToTextNode(position) {
|
|
1738
1693
|
const nodeBefore = position.nodeBefore;
|
|
1739
1694
|
if (nodeBefore && nodeBefore.is('$text')) {
|
|
@@ -1745,14 +1700,18 @@ function movePositionToTextNode(position) {
|
|
|
1745
1700
|
}
|
|
1746
1701
|
return position;
|
|
1747
1702
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1703
|
+
/**
|
|
1704
|
+
* Breaks text node into two text nodes when possible.
|
|
1705
|
+
*
|
|
1706
|
+
* ```html
|
|
1707
|
+
* <p>foo{}bar</p> -> <p>foo[]bar</p>
|
|
1708
|
+
* <p>{}foobar</p> -> <p>[]foobar</p>
|
|
1709
|
+
* <p>foobar{}</p> -> <p>foobar[]</p>
|
|
1710
|
+
* ```
|
|
1711
|
+
*
|
|
1712
|
+
* @param position Position that need to be placed inside text node.
|
|
1713
|
+
* @returns New position after breaking text node.
|
|
1714
|
+
*/
|
|
1756
1715
|
function breakTextNode(position) {
|
|
1757
1716
|
if (position.offset == position.parent.data.length) {
|
|
1758
1717
|
return new Position(position.parent.parent, position.parent.index + 1);
|
|
@@ -1769,12 +1728,13 @@ function breakTextNode(position) {
|
|
|
1769
1728
|
// Return new position between two newly created text nodes.
|
|
1770
1729
|
return new Position(position.parent.parent, position.parent.index + 1);
|
|
1771
1730
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1731
|
+
/**
|
|
1732
|
+
* Merges two text nodes into first node. Removes second node and returns merge position.
|
|
1733
|
+
*
|
|
1734
|
+
* @param t1 First text node to merge. Data from second text node will be moved at the end of this text node.
|
|
1735
|
+
* @param t2 Second text node to merge. This node will be removed after merging.
|
|
1736
|
+
* @returns Position after merging text nodes.
|
|
1737
|
+
*/
|
|
1778
1738
|
function mergeTextNodes(t1, t2) {
|
|
1779
1739
|
// Merge text data into first text node and remove second one.
|
|
1780
1740
|
const nodeBeforeLength = t1.data.length;
|
|
@@ -1783,13 +1743,12 @@ function mergeTextNodes(t1, t2) {
|
|
|
1783
1743
|
return new Position(t1, nodeBeforeLength);
|
|
1784
1744
|
}
|
|
1785
1745
|
const validNodesToInsert = [Text, AttributeElement, ContainerElement, EmptyElement, RawElement, UIElement];
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
// @param {Object} errorContext
|
|
1746
|
+
/**
|
|
1747
|
+
* Checks if provided nodes are valid to insert.
|
|
1748
|
+
*
|
|
1749
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-insert-invalid-node` when nodes to insert
|
|
1750
|
+
* contains instances that are not supported ones (see error description for valid ones.
|
|
1751
|
+
*/
|
|
1793
1752
|
function validateNodesToInsert(nodes, errorContext) {
|
|
1794
1753
|
for (const node of nodes) {
|
|
1795
1754
|
if (!validNodesToInsert.some((validNode => node instanceof validNode))) { // eslint-disable-line no-use-before-define
|
|
@@ -1815,19 +1774,19 @@ function validateNodesToInsert(nodes, errorContext) {
|
|
|
1815
1774
|
}
|
|
1816
1775
|
}
|
|
1817
1776
|
}
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1777
|
+
/**
|
|
1778
|
+
* Checks if node is ContainerElement or DocumentFragment, because in most cases they should be treated the same way.
|
|
1779
|
+
*
|
|
1780
|
+
* @returns Returns `true` if node is instance of ContainerElement or DocumentFragment.
|
|
1781
|
+
*/
|
|
1822
1782
|
function isContainerOrFragment(node) {
|
|
1823
1783
|
return node && (node.is('containerElement') || node.is('documentFragment'));
|
|
1824
1784
|
}
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
// @param {Object} errorContext
|
|
1785
|
+
/**
|
|
1786
|
+
* Checks if {@link module:engine/view/range~Range#start range start} and {@link module:engine/view/range~Range#end range end} are placed
|
|
1787
|
+
* inside same {@link module:engine/view/containerelement~ContainerElement container element}.
|
|
1788
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-writer-invalid-range-container` when validation fails.
|
|
1789
|
+
*/
|
|
1831
1790
|
function validateRangeContainer(range, errorContext) {
|
|
1832
1791
|
const startContainer = getParentContainer(range.start);
|
|
1833
1792
|
const endContainer = getParentContainer(range.end);
|
|
@@ -1851,13 +1810,10 @@ function validateRangeContainer(range, errorContext) {
|
|
|
1851
1810
|
throw new CKEditorError('view-writer-invalid-range-container', errorContext);
|
|
1852
1811
|
}
|
|
1853
1812
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
// @param {module:engine/view/element~Element} a
|
|
1859
|
-
// @param {module:engine/view/element~Element} b
|
|
1860
|
-
// @returns {Boolean}
|
|
1813
|
+
/**
|
|
1814
|
+
* Checks if two attribute elements can be joined together. Elements can be joined together if, and only if
|
|
1815
|
+
* they do not have ids specified.
|
|
1816
|
+
*/
|
|
1861
1817
|
function canBeJoined(a, b) {
|
|
1862
1818
|
return a.id === null && b.id === null;
|
|
1863
1819
|
}
|