@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
package/src/view/element.js
CHANGED
|
@@ -11,7 +11,6 @@ import TextProxy from './textproxy';
|
|
|
11
11
|
import { isIterable, toArray, toMap } from '@ckeditor/ckeditor5-utils';
|
|
12
12
|
import { default as Matcher } from './matcher';
|
|
13
13
|
import { default as StylesMap } from './stylesmap';
|
|
14
|
-
import { isPlainObject } from 'lodash-es';
|
|
15
14
|
// @if CK_DEBUG_ENGINE // const { convertMapToTags } = require( '../dev-utils/utils' );
|
|
16
15
|
/**
|
|
17
16
|
* View element.
|
|
@@ -35,8 +34,6 @@ import { isPlainObject } from 'lodash-es';
|
|
|
35
34
|
* {@link module:engine/controller/datacontroller~DataController#set data.set} it is not possible to define the type of the element.
|
|
36
35
|
* In such cases the {@link module:engine/view/upcastwriter~UpcastWriter#createElement `UpcastWriter#createElement()`} method
|
|
37
36
|
* should be used to create generic view elements.
|
|
38
|
-
*
|
|
39
|
-
* @extends module:engine/view/node~Node
|
|
40
37
|
*/
|
|
41
38
|
export default class Element extends Node {
|
|
42
39
|
/**
|
|
@@ -44,49 +41,43 @@ export default class Element extends Node {
|
|
|
44
41
|
*
|
|
45
42
|
* Attributes can be passed in various formats:
|
|
46
43
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* new Element( viewDocument, 'div', { class: 'editor', contentEditable: 'true' } ); // object
|
|
46
|
+
* new Element( viewDocument, 'div', [ [ 'class', 'editor' ], [ 'contentEditable', 'true' ] ] ); // map-like iterator
|
|
47
|
+
* new Element( viewDocument, 'div', mapOfAttributes ); // map
|
|
48
|
+
* ```
|
|
50
49
|
*
|
|
51
|
-
* @
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* A list of nodes to be inserted into created element.
|
|
50
|
+
* @internal
|
|
51
|
+
* @param document The document instance to which this element belongs.
|
|
52
|
+
* @param name Node name.
|
|
53
|
+
* @param attrs Collection of attributes.
|
|
54
|
+
* @param children A list of nodes to be inserted into created element.
|
|
57
55
|
*/
|
|
58
56
|
constructor(document, name, attrs, children) {
|
|
59
57
|
super(document);
|
|
60
58
|
/**
|
|
61
|
-
*
|
|
59
|
+
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
60
|
+
* implemented in the {@link module:engine/view/domconverter~DomConverter} (for instance,
|
|
61
|
+
* {@link module:engine/view/domconverter~DomConverter#shouldRenderAttribute}) would filter them out.
|
|
62
62
|
*
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
|
|
66
|
-
this.name = name;
|
|
67
|
-
/**
|
|
68
|
-
* Map of attributes, where attributes names are keys and attributes values are values.
|
|
63
|
+
* These attributes can be specified as an option when the element is created by
|
|
64
|
+
* the {@link module:engine/view/downcastwriter~DowncastWriter}. To check whether an unsafe an attribute should
|
|
65
|
+
* be permitted, use the {@link #shouldRenderUnsafeAttribute} method.
|
|
69
66
|
*
|
|
70
|
-
* @
|
|
71
|
-
* @member {Map} #_attrs
|
|
67
|
+
* @internal
|
|
72
68
|
*/
|
|
73
|
-
this.
|
|
69
|
+
this._unsafeAttributesToRender = [];
|
|
74
70
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @protected
|
|
78
|
-
* @member {Array.<module:engine/view/node~Node>}
|
|
71
|
+
* Map of custom properties.
|
|
72
|
+
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
79
73
|
*/
|
|
74
|
+
this._customProperties = new Map();
|
|
75
|
+
this.name = name;
|
|
76
|
+
this._attrs = parseAttributes(attrs);
|
|
80
77
|
this._children = [];
|
|
81
78
|
if (children) {
|
|
82
79
|
this._insertChild(0, children);
|
|
83
80
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Set of classes associated with element instance.
|
|
86
|
-
*
|
|
87
|
-
* @protected
|
|
88
|
-
* @member {Set}
|
|
89
|
-
*/
|
|
90
81
|
this._classes = new Set();
|
|
91
82
|
if (this._attrs.has('class')) {
|
|
92
83
|
// Remove class attribute and handle it by class set.
|
|
@@ -94,55 +85,21 @@ export default class Element extends Node {
|
|
|
94
85
|
parseClasses(this._classes, classString);
|
|
95
86
|
this._attrs.delete('class');
|
|
96
87
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Normalized styles.
|
|
99
|
-
*
|
|
100
|
-
* @protected
|
|
101
|
-
* @member {module:engine/view/stylesmap~StylesMap} module:engine/view/element~Element#_styles
|
|
102
|
-
*/
|
|
103
88
|
this._styles = new StylesMap(this.document.stylesProcessor);
|
|
104
89
|
if (this._attrs.has('style')) {
|
|
105
90
|
// Remove style attribute and handle it by styles map.
|
|
106
91
|
this._styles.setTo(this._attrs.get('style'));
|
|
107
92
|
this._attrs.delete('style');
|
|
108
93
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Map of custom properties.
|
|
111
|
-
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
112
|
-
*
|
|
113
|
-
* @protected
|
|
114
|
-
* @member {Map}
|
|
115
|
-
*/
|
|
116
|
-
this._customProperties = new Map();
|
|
117
|
-
/**
|
|
118
|
-
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
119
|
-
* implemented in the {@link module:engine/view/domconverter~DomConverter} (for instance,
|
|
120
|
-
* {@link module:engine/view/domconverter~DomConverter#shouldRenderAttribute}) would filter them out.
|
|
121
|
-
*
|
|
122
|
-
* These attributes can be specified as an option when the element is created by
|
|
123
|
-
* the {@link module:engine/view/downcastwriter~DowncastWriter}. To check whether an unsafe an attribute should
|
|
124
|
-
* be permitted, use the {@link #shouldRenderUnsafeAttribute} method.
|
|
125
|
-
*
|
|
126
|
-
* @private
|
|
127
|
-
* @readonly
|
|
128
|
-
* @member {Array.<String>}
|
|
129
|
-
*/
|
|
130
|
-
this._unsafeAttributesToRender = [];
|
|
131
94
|
}
|
|
132
95
|
/**
|
|
133
96
|
* Number of element's children.
|
|
134
|
-
*
|
|
135
|
-
* @readonly
|
|
136
|
-
* @type {Number}
|
|
137
97
|
*/
|
|
138
98
|
get childCount() {
|
|
139
99
|
return this._children.length;
|
|
140
100
|
}
|
|
141
101
|
/**
|
|
142
102
|
* Is `true` if there are no nodes inside this element, `false` otherwise.
|
|
143
|
-
*
|
|
144
|
-
* @readonly
|
|
145
|
-
* @type {Boolean}
|
|
146
103
|
*/
|
|
147
104
|
get isEmpty() {
|
|
148
105
|
return this._children.length === 0;
|
|
@@ -150,8 +107,8 @@ export default class Element extends Node {
|
|
|
150
107
|
/**
|
|
151
108
|
* Gets child at the given index.
|
|
152
109
|
*
|
|
153
|
-
* @param
|
|
154
|
-
* @returns
|
|
110
|
+
* @param index Index of child.
|
|
111
|
+
* @returns Child node.
|
|
155
112
|
*/
|
|
156
113
|
getChild(index) {
|
|
157
114
|
return this._children[index];
|
|
@@ -159,8 +116,8 @@ export default class Element extends Node {
|
|
|
159
116
|
/**
|
|
160
117
|
* Gets index of the given child node. Returns `-1` if child node is not found.
|
|
161
118
|
*
|
|
162
|
-
* @param
|
|
163
|
-
* @returns
|
|
119
|
+
* @param node Child node.
|
|
120
|
+
* @returns Index of the child node.
|
|
164
121
|
*/
|
|
165
122
|
getChildIndex(node) {
|
|
166
123
|
return this._children.indexOf(node);
|
|
@@ -168,7 +125,7 @@ export default class Element extends Node {
|
|
|
168
125
|
/**
|
|
169
126
|
* Gets child nodes iterator.
|
|
170
127
|
*
|
|
171
|
-
* @returns
|
|
128
|
+
* @returns Child nodes iterator.
|
|
172
129
|
*/
|
|
173
130
|
getChildren() {
|
|
174
131
|
return this._children[Symbol.iterator]();
|
|
@@ -176,7 +133,7 @@ export default class Element extends Node {
|
|
|
176
133
|
/**
|
|
177
134
|
* Returns an iterator that contains the keys for attributes. Order of inserting attributes is not preserved.
|
|
178
135
|
*
|
|
179
|
-
* @returns
|
|
136
|
+
* @returns Keys for attributes.
|
|
180
137
|
*/
|
|
181
138
|
*getAttributeKeys() {
|
|
182
139
|
if (this._classes.size > 0) {
|
|
@@ -192,8 +149,6 @@ export default class Element extends Node {
|
|
|
192
149
|
*
|
|
193
150
|
* Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
|
|
194
151
|
* This format is accepted by native `Map` object and also can be passed in `Node` constructor.
|
|
195
|
-
*
|
|
196
|
-
* @returns {Iterable.<*>}
|
|
197
152
|
*/
|
|
198
153
|
*getAttributes() {
|
|
199
154
|
yield* this._attrs.entries();
|
|
@@ -207,8 +162,8 @@ export default class Element extends Node {
|
|
|
207
162
|
/**
|
|
208
163
|
* Gets attribute by key. If attribute is not present - returns undefined.
|
|
209
164
|
*
|
|
210
|
-
* @param
|
|
211
|
-
* @returns
|
|
165
|
+
* @param key Attribute key.
|
|
166
|
+
* @returns Attribute value.
|
|
212
167
|
*/
|
|
213
168
|
getAttribute(key) {
|
|
214
169
|
if (key == 'class') {
|
|
@@ -226,8 +181,8 @@ export default class Element extends Node {
|
|
|
226
181
|
/**
|
|
227
182
|
* Returns a boolean indicating whether an attribute with the specified key exists in the element.
|
|
228
183
|
*
|
|
229
|
-
* @param
|
|
230
|
-
* @returns
|
|
184
|
+
* @param key Attribute key.
|
|
185
|
+
* @returns `true` if attribute with the specified key exists in the element, `false` otherwise.
|
|
231
186
|
*/
|
|
232
187
|
hasAttribute(key) {
|
|
233
188
|
if (key == 'class') {
|
|
@@ -242,9 +197,6 @@ export default class Element extends Node {
|
|
|
242
197
|
* Checks if this element is similar to other element.
|
|
243
198
|
* Both elements should have the same name and attributes to be considered as similar. Two similar elements
|
|
244
199
|
* can contain different set of children nodes.
|
|
245
|
-
*
|
|
246
|
-
* @param {module:engine/view/element~Element} otherElement
|
|
247
|
-
* @returns {Boolean}
|
|
248
200
|
*/
|
|
249
201
|
isSimilar(otherElement) {
|
|
250
202
|
if (!(otherElement instanceof Element)) {
|
|
@@ -288,10 +240,10 @@ export default class Element extends Node {
|
|
|
288
240
|
* Returns true if class is present.
|
|
289
241
|
* If more then one class is provided - returns true only when all classes are present.
|
|
290
242
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
243
|
+
* ```ts
|
|
244
|
+
* element.hasClass( 'foo' ); // Returns true if 'foo' class is present.
|
|
245
|
+
* element.hasClass( 'foo', 'bar' ); // Returns true if 'foo' and 'bar' classes are both present.
|
|
246
|
+
* ```
|
|
295
247
|
*/
|
|
296
248
|
hasClass(...className) {
|
|
297
249
|
for (const name of className) {
|
|
@@ -303,8 +255,6 @@ export default class Element extends Node {
|
|
|
303
255
|
}
|
|
304
256
|
/**
|
|
305
257
|
* Returns iterator that contains all class names.
|
|
306
|
-
*
|
|
307
|
-
* @returns {Iterable.<String>}
|
|
308
258
|
*/
|
|
309
259
|
getClassNames() {
|
|
310
260
|
return this._classes.keys();
|
|
@@ -319,21 +269,20 @@ export default class Element extends Node {
|
|
|
319
269
|
*
|
|
320
270
|
* For an element with style set to `'margin:1px'`:
|
|
321
271
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
272
|
+
* ```ts
|
|
273
|
+
* // Enable 'margin' shorthand processing:
|
|
274
|
+
* editor.data.addStyleProcessorRules( addMarginRules );
|
|
324
275
|
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
276
|
+
* const element = view.change( writer => {
|
|
277
|
+
* const element = writer.createElement();
|
|
278
|
+
* writer.setStyle( 'margin', '1px' );
|
|
279
|
+
* writer.setStyle( 'margin-bottom', '3em' );
|
|
329
280
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
281
|
+
* return element;
|
|
282
|
+
* } );
|
|
332
283
|
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* @param {String} property
|
|
336
|
-
* @returns {String|undefined}
|
|
284
|
+
* element.getStyle( 'margin' ); // -> 'margin: 1px 1px 3em;'
|
|
285
|
+
* ```
|
|
337
286
|
*/
|
|
338
287
|
getStyle(property) {
|
|
339
288
|
return this._styles.getAsString(property);
|
|
@@ -343,20 +292,26 @@ export default class Element extends Node {
|
|
|
343
292
|
*
|
|
344
293
|
* For an element with style set to: margin:1px 2px 3em;
|
|
345
294
|
*
|
|
346
|
-
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* element.getNormalizedStyle( 'margin' ) );
|
|
297
|
+
* ```
|
|
347
298
|
*
|
|
348
299
|
* will return:
|
|
349
300
|
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
301
|
+
* ```ts
|
|
302
|
+
* {
|
|
303
|
+
* top: '1px',
|
|
304
|
+
* right: '2px',
|
|
305
|
+
* bottom: '3em',
|
|
306
|
+
* left: '2px' // a normalized value from margin shorthand
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
356
309
|
*
|
|
357
310
|
* and reading for single style value:
|
|
358
311
|
*
|
|
359
|
-
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* styles.getNormalizedStyle( 'margin-left' );
|
|
314
|
+
* ```
|
|
360
315
|
*
|
|
361
316
|
* Will return a `2px` string.
|
|
362
317
|
*
|
|
@@ -364,9 +319,7 @@ export default class Element extends Node {
|
|
|
364
319
|
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
365
320
|
* See {@link module:engine/view/stylesmap~StylesMap#getNormalized `StylesMap#getNormalized()`} for details.
|
|
366
321
|
*
|
|
367
|
-
*
|
|
368
|
-
* @param {String} property Name of CSS property
|
|
369
|
-
* @returns {Object|String|undefined}
|
|
322
|
+
* @param property Name of CSS property
|
|
370
323
|
*/
|
|
371
324
|
getNormalizedStyle(property) {
|
|
372
325
|
return this._styles.getNormalized(property);
|
|
@@ -374,8 +327,7 @@ export default class Element extends Node {
|
|
|
374
327
|
/**
|
|
375
328
|
* Returns iterator that contains all style names.
|
|
376
329
|
*
|
|
377
|
-
* @param
|
|
378
|
-
* @returns {Iterable.<String>}
|
|
330
|
+
* @param expand Expand shorthand style properties and return all equivalent style representations.
|
|
379
331
|
*/
|
|
380
332
|
getStyleNames(expand) {
|
|
381
333
|
return this._styles.getStyleNames(expand);
|
|
@@ -384,10 +336,10 @@ export default class Element extends Node {
|
|
|
384
336
|
* Returns true if style keys are present.
|
|
385
337
|
* If more then one style property is provided - returns true only when all properties are present.
|
|
386
338
|
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
339
|
+
* ```ts
|
|
340
|
+
* element.hasStyle( 'color' ); // Returns true if 'border-top' style is present.
|
|
341
|
+
* element.hasStyle( 'color', 'border-top' ); // Returns true if 'color' and 'border-top' styles are both present.
|
|
342
|
+
* ```
|
|
391
343
|
*/
|
|
392
344
|
hasStyle(...property) {
|
|
393
345
|
for (const name of property) {
|
|
@@ -402,9 +354,8 @@ export default class Element extends Node {
|
|
|
402
354
|
* Provided patterns should be compatible with {@link module:engine/view/matcher~Matcher Matcher} as it is used internally.
|
|
403
355
|
*
|
|
404
356
|
* @see module:engine/view/matcher~Matcher
|
|
405
|
-
* @param
|
|
406
|
-
*
|
|
407
|
-
* @returns {module:engine/view/element~Element|null} Found element or `null` if no matching ancestor was found.
|
|
357
|
+
* @param patterns Patterns used to match correct ancestor. See {@link module:engine/view/matcher~Matcher}.
|
|
358
|
+
* @returns Found element or `null` if no matching ancestor was found.
|
|
408
359
|
*/
|
|
409
360
|
findAncestor(...patterns) {
|
|
410
361
|
const matcher = new Matcher(...patterns);
|
|
@@ -419,9 +370,6 @@ export default class Element extends Node {
|
|
|
419
370
|
}
|
|
420
371
|
/**
|
|
421
372
|
* Returns the custom property value for the given key.
|
|
422
|
-
*
|
|
423
|
-
* @param {String|Symbol} key
|
|
424
|
-
* @returns {*}
|
|
425
373
|
*/
|
|
426
374
|
getCustomProperty(key) {
|
|
427
375
|
return this._customProperties.get(key);
|
|
@@ -429,8 +377,6 @@ export default class Element extends Node {
|
|
|
429
377
|
/**
|
|
430
378
|
* Returns an iterator which iterates over this element's custom properties.
|
|
431
379
|
* Iterator provides `[ key, value ]` pairs for each stored property.
|
|
432
|
-
*
|
|
433
|
-
* @returns {Iterable.<*>}
|
|
434
380
|
*/
|
|
435
381
|
*getCustomProperties() {
|
|
436
382
|
yield* this._customProperties.entries();
|
|
@@ -440,23 +386,25 @@ export default class Element extends Node {
|
|
|
440
386
|
* Two elements that {@link #isSimilar are similar} will have same identity string.
|
|
441
387
|
* It has the following format:
|
|
442
388
|
*
|
|
443
|
-
*
|
|
389
|
+
* ```ts
|
|
390
|
+
* 'name class="class1,class2" style="style1:value1;style2:value2" attr1="val1" attr2="val2"'
|
|
391
|
+
* ```
|
|
444
392
|
*
|
|
445
393
|
* For example:
|
|
446
394
|
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
395
|
+
* ```ts
|
|
396
|
+
* const element = writer.createContainerElement( 'foo', {
|
|
397
|
+
* banana: '10',
|
|
398
|
+
* apple: '20',
|
|
399
|
+
* style: 'color: red; border-color: white;',
|
|
400
|
+
* class: 'baz'
|
|
401
|
+
* } );
|
|
453
402
|
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
403
|
+
* // returns 'foo class="baz" style="border-color:white;color:red" apple="20" banana="10"'
|
|
404
|
+
* element.getIdentity();
|
|
405
|
+
* ```
|
|
456
406
|
*
|
|
457
407
|
* **Note**: Classes, styles and other attributes are sorted alphabetically.
|
|
458
|
-
*
|
|
459
|
-
* @returns {String}
|
|
460
408
|
*/
|
|
461
409
|
getIdentity() {
|
|
462
410
|
const classes = Array.from(this._classes).sort().join(',');
|
|
@@ -473,8 +421,7 @@ export default class Element extends Node {
|
|
|
473
421
|
*
|
|
474
422
|
* Unsafe attribute names can be specified when creating an element via {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
475
423
|
*
|
|
476
|
-
* @param
|
|
477
|
-
* @returns {Boolean}
|
|
424
|
+
* @param attributeName The name of the attribute to be checked.
|
|
478
425
|
*/
|
|
479
426
|
shouldRenderUnsafeAttribute(attributeName) {
|
|
480
427
|
return this._unsafeAttributesToRender.includes(attributeName);
|
|
@@ -482,10 +429,10 @@ export default class Element extends Node {
|
|
|
482
429
|
/**
|
|
483
430
|
* Clones provided element.
|
|
484
431
|
*
|
|
485
|
-
* @
|
|
486
|
-
* @param
|
|
432
|
+
* @internal
|
|
433
|
+
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
487
434
|
* element will be cloned without any children.
|
|
488
|
-
* @returns
|
|
435
|
+
* @returns Clone of this element.
|
|
489
436
|
*/
|
|
490
437
|
_clone(deep = false) {
|
|
491
438
|
const childrenClone = [];
|
|
@@ -515,10 +462,10 @@ export default class Element extends Node {
|
|
|
515
462
|
* and sets the parent of these nodes to this element.
|
|
516
463
|
*
|
|
517
464
|
* @see module:engine/view/downcastwriter~DowncastWriter#insert
|
|
518
|
-
* @
|
|
519
|
-
* @param
|
|
520
|
-
* @fires
|
|
521
|
-
* @returns
|
|
465
|
+
* @internal
|
|
466
|
+
* @param items Items to be inserted.
|
|
467
|
+
* @fires change
|
|
468
|
+
* @returns Number of appended nodes.
|
|
522
469
|
*/
|
|
523
470
|
_appendChild(items) {
|
|
524
471
|
return this._insertChild(this.childCount, items);
|
|
@@ -529,11 +476,10 @@ export default class Element extends Node {
|
|
|
529
476
|
*
|
|
530
477
|
* @internal
|
|
531
478
|
* @see module:engine/view/downcastwriter~DowncastWriter#insert
|
|
532
|
-
* @
|
|
533
|
-
* @param
|
|
534
|
-
* @
|
|
535
|
-
* @
|
|
536
|
-
* @returns {Number} Number of inserted nodes.
|
|
479
|
+
* @param index Position where nodes should be inserted.
|
|
480
|
+
* @param items Items to be inserted.
|
|
481
|
+
* @fires change
|
|
482
|
+
* @returns Number of inserted nodes.
|
|
537
483
|
*/
|
|
538
484
|
_insertChild(index, items) {
|
|
539
485
|
this._fireChange('children', this);
|
|
@@ -556,11 +502,11 @@ export default class Element extends Node {
|
|
|
556
502
|
* Removes number of child nodes starting at the given index and set the parent of these nodes to `null`.
|
|
557
503
|
*
|
|
558
504
|
* @see module:engine/view/downcastwriter~DowncastWriter#remove
|
|
559
|
-
* @
|
|
560
|
-
* @param
|
|
561
|
-
* @param
|
|
562
|
-
* @fires
|
|
563
|
-
* @returns
|
|
505
|
+
* @internal
|
|
506
|
+
* @param index Number of the first node to remove.
|
|
507
|
+
* @param howMany Number of nodes to remove.
|
|
508
|
+
* @fires change
|
|
509
|
+
* @returns The array of removed nodes.
|
|
564
510
|
*/
|
|
565
511
|
_removeChildren(index, howMany = 1) {
|
|
566
512
|
this._fireChange('children', this);
|
|
@@ -573,10 +519,10 @@ export default class Element extends Node {
|
|
|
573
519
|
* Adds or overwrite attribute with a specified key and value.
|
|
574
520
|
*
|
|
575
521
|
* @see module:engine/view/downcastwriter~DowncastWriter#setAttribute
|
|
576
|
-
* @
|
|
577
|
-
* @param
|
|
578
|
-
* @param
|
|
579
|
-
* @fires
|
|
522
|
+
* @internal
|
|
523
|
+
* @param key Attribute key.
|
|
524
|
+
* @param value Attribute value.
|
|
525
|
+
* @fires change
|
|
580
526
|
*/
|
|
581
527
|
_setAttribute(key, value) {
|
|
582
528
|
const stringValue = String(value);
|
|
@@ -595,10 +541,10 @@ export default class Element extends Node {
|
|
|
595
541
|
* Removes attribute from the element.
|
|
596
542
|
*
|
|
597
543
|
* @see module:engine/view/downcastwriter~DowncastWriter#removeAttribute
|
|
598
|
-
* @
|
|
599
|
-
* @param
|
|
600
|
-
* @returns
|
|
601
|
-
* @fires
|
|
544
|
+
* @internal
|
|
545
|
+
* @param key Attribute key.
|
|
546
|
+
* @returns Returns true if an attribute existed and has been removed.
|
|
547
|
+
* @fires change
|
|
602
548
|
*/
|
|
603
549
|
_removeAttribute(key) {
|
|
604
550
|
this._fireChange('attributes', this);
|
|
@@ -624,13 +570,14 @@ export default class Element extends Node {
|
|
|
624
570
|
/**
|
|
625
571
|
* Adds specified class.
|
|
626
572
|
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
573
|
+
* ```ts
|
|
574
|
+
* element._addClass( 'foo' ); // Adds 'foo' class.
|
|
575
|
+
* element._addClass( [ 'foo', 'bar' ] ); // Adds 'foo' and 'bar' classes.
|
|
576
|
+
* ```
|
|
629
577
|
*
|
|
630
578
|
* @see module:engine/view/downcastwriter~DowncastWriter#addClass
|
|
631
|
-
* @
|
|
632
|
-
* @
|
|
633
|
-
* @fires module:engine/view/node~Node#change
|
|
579
|
+
* @internal
|
|
580
|
+
* @fires change
|
|
634
581
|
*/
|
|
635
582
|
_addClass(className) {
|
|
636
583
|
this._fireChange('attributes', this);
|
|
@@ -641,13 +588,14 @@ export default class Element extends Node {
|
|
|
641
588
|
/**
|
|
642
589
|
* Removes specified class.
|
|
643
590
|
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
591
|
+
* ```ts
|
|
592
|
+
* element._removeClass( 'foo' ); // Removes 'foo' class.
|
|
593
|
+
* element._removeClass( [ 'foo', 'bar' ] ); // Removes both 'foo' and 'bar' classes.
|
|
594
|
+
* ```
|
|
646
595
|
*
|
|
647
596
|
* @see module:engine/view/downcastwriter~DowncastWriter#removeClass
|
|
648
|
-
* @
|
|
649
|
-
* @
|
|
650
|
-
* @fires module:engine/view/node~Node#change
|
|
597
|
+
* @internal
|
|
598
|
+
* @fires change
|
|
651
599
|
*/
|
|
652
600
|
_removeClass(className) {
|
|
653
601
|
this._fireChange('attributes', this);
|
|
@@ -657,7 +605,7 @@ export default class Element extends Node {
|
|
|
657
605
|
}
|
|
658
606
|
_setStyle(property, value) {
|
|
659
607
|
this._fireChange('attributes', this);
|
|
660
|
-
if (
|
|
608
|
+
if (typeof property != 'string') {
|
|
661
609
|
this._styles.set(property);
|
|
662
610
|
}
|
|
663
611
|
else {
|
|
@@ -667,17 +615,18 @@ export default class Element extends Node {
|
|
|
667
615
|
/**
|
|
668
616
|
* Removes specified style.
|
|
669
617
|
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
618
|
+
* ```ts
|
|
619
|
+
* element._removeStyle( 'color' ); // Removes 'color' style.
|
|
620
|
+
* element._removeStyle( [ 'color', 'border-top' ] ); // Removes both 'color' and 'border-top' styles.
|
|
621
|
+
* ```
|
|
672
622
|
*
|
|
673
623
|
* **Note**: This method can work with normalized style names if
|
|
674
624
|
* {@link module:engine/controller/datacontroller~DataController#addStyleProcessorRules a particular style processor rule is enabled}.
|
|
675
625
|
* See {@link module:engine/view/stylesmap~StylesMap#remove `StylesMap#remove()`} for details.
|
|
676
626
|
*
|
|
677
627
|
* @see module:engine/view/downcastwriter~DowncastWriter#removeStyle
|
|
678
|
-
* @
|
|
679
|
-
* @
|
|
680
|
-
* @fires module:engine/view/node~Node#change
|
|
628
|
+
* @internal
|
|
629
|
+
* @fires change
|
|
681
630
|
*/
|
|
682
631
|
_removeStyle(property) {
|
|
683
632
|
this._fireChange('attributes', this);
|
|
@@ -690,9 +639,7 @@ export default class Element extends Node {
|
|
|
690
639
|
* so they can be used to add special data to elements.
|
|
691
640
|
*
|
|
692
641
|
* @see module:engine/view/downcastwriter~DowncastWriter#setCustomProperty
|
|
693
|
-
* @
|
|
694
|
-
* @param {String|Symbol} key
|
|
695
|
-
* @param {*} value
|
|
642
|
+
* @internal
|
|
696
643
|
*/
|
|
697
644
|
_setCustomProperty(key, value) {
|
|
698
645
|
this._customProperties.set(key, value);
|
|
@@ -701,37 +648,15 @@ export default class Element extends Node {
|
|
|
701
648
|
* Removes the custom property stored under the given key.
|
|
702
649
|
*
|
|
703
650
|
* @see module:engine/view/downcastwriter~DowncastWriter#removeCustomProperty
|
|
704
|
-
* @
|
|
705
|
-
* @
|
|
706
|
-
* @returns {Boolean} Returns true if property was removed.
|
|
651
|
+
* @internal
|
|
652
|
+
* @returns Returns true if property was removed.
|
|
707
653
|
*/
|
|
708
654
|
_removeCustomProperty(key) {
|
|
709
655
|
return this._customProperties.delete(key);
|
|
710
656
|
}
|
|
711
657
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
*
|
|
715
|
-
* element.is( 'element' ); // -> true
|
|
716
|
-
* element.is( 'node' ); // -> true
|
|
717
|
-
* element.is( 'view:element' ); // -> true
|
|
718
|
-
* element.is( 'view:node' ); // -> true
|
|
719
|
-
*
|
|
720
|
-
* element.is( 'model:element' ); // -> false
|
|
721
|
-
* element.is( 'documentSelection' ); // -> false
|
|
722
|
-
*
|
|
723
|
-
* Assuming that the object being checked is an element, you can also check its
|
|
724
|
-
* {@link module:engine/view/element~Element#name name}:
|
|
725
|
-
*
|
|
726
|
-
* element.is( 'element', 'img' ); // -> true if this is an <img> element
|
|
727
|
-
* text.is( 'element', 'img' ); -> false
|
|
728
|
-
*
|
|
729
|
-
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
730
|
-
*
|
|
731
|
-
* @param {String} type Type to check.
|
|
732
|
-
* @param {String} [name] Element name.
|
|
733
|
-
* @returns {Boolean}
|
|
734
|
-
*/
|
|
658
|
+
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
659
|
+
// Proper overload would interfere with that.
|
|
735
660
|
Element.prototype.is = function (type, name) {
|
|
736
661
|
if (!name) {
|
|
737
662
|
return type === 'element' || type === 'view:element' ||
|
|
@@ -742,12 +667,14 @@ Element.prototype.is = function (type, name) {
|
|
|
742
667
|
return name === this.name && (type === 'element' || type === 'view:element');
|
|
743
668
|
}
|
|
744
669
|
};
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Parses attributes provided to the element constructor before they are applied to an element. If attributes are passed
|
|
672
|
+
* as an object (instead of `Iterable`), the object is transformed to the map. Attributes with `null` value are removed.
|
|
673
|
+
* Attributes with non-`String` value are converted to `String`.
|
|
674
|
+
*
|
|
675
|
+
* @param attrs Attributes to parse.
|
|
676
|
+
* @returns Parsed attributes.
|
|
677
|
+
*/
|
|
751
678
|
function parseAttributes(attrs) {
|
|
752
679
|
const attrsMap = toMap(attrs);
|
|
753
680
|
for (const [key, value] of attrsMap) {
|
|
@@ -760,20 +687,21 @@ function parseAttributes(attrs) {
|
|
|
760
687
|
}
|
|
761
688
|
return attrsMap;
|
|
762
689
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
690
|
+
/**
|
|
691
|
+
* Parses class attribute and puts all classes into classes set.
|
|
692
|
+
* Classes set s cleared before insertion.
|
|
693
|
+
*
|
|
694
|
+
* @param classesSet Set to insert parsed classes.
|
|
695
|
+
* @param classesString String with classes to parse.
|
|
696
|
+
*/
|
|
768
697
|
function parseClasses(classesSet, classesString) {
|
|
769
698
|
const classArray = classesString.split(/\s+/);
|
|
770
699
|
classesSet.clear();
|
|
771
700
|
classArray.forEach(name => classesSet.add(name));
|
|
772
701
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
// @returns {Iterable.<module:engine/view/node~Node>}
|
|
702
|
+
/**
|
|
703
|
+
* Converts strings to Text and non-iterables to arrays.
|
|
704
|
+
*/
|
|
777
705
|
function normalize(document, nodes) {
|
|
778
706
|
// Separate condition because string is iterable.
|
|
779
707
|
if (typeof nodes == 'string') {
|