@ckeditor/ckeditor5-engine 35.0.1 → 35.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -4
- package/package.json +30 -24
- package/src/controller/datacontroller.js +467 -561
- package/src/controller/editingcontroller.js +168 -204
- package/src/conversion/conversion.js +541 -565
- package/src/conversion/conversionhelpers.js +24 -28
- package/src/conversion/downcastdispatcher.js +457 -686
- package/src/conversion/downcasthelpers.js +1583 -1965
- package/src/conversion/mapper.js +518 -707
- package/src/conversion/modelconsumable.js +240 -283
- package/src/conversion/upcastdispatcher.js +372 -718
- package/src/conversion/upcasthelpers.js +707 -818
- package/src/conversion/viewconsumable.js +524 -581
- package/src/dataprocessor/basichtmlwriter.js +12 -16
- package/src/dataprocessor/dataprocessor.js +5 -0
- package/src/dataprocessor/htmldataprocessor.js +100 -116
- package/src/dataprocessor/htmlwriter.js +1 -18
- package/src/dataprocessor/xmldataprocessor.js +116 -137
- package/src/dev-utils/model.js +260 -352
- package/src/dev-utils/operationreplayer.js +106 -126
- package/src/dev-utils/utils.js +34 -51
- package/src/dev-utils/view.js +632 -753
- package/src/index.js +0 -11
- package/src/model/batch.js +111 -127
- package/src/model/differ.js +988 -1233
- package/src/model/document.js +340 -449
- package/src/model/documentfragment.js +327 -364
- package/src/model/documentselection.js +996 -1189
- package/src/model/element.js +306 -410
- package/src/model/history.js +224 -262
- package/src/model/item.js +5 -0
- package/src/model/liveposition.js +84 -145
- package/src/model/liverange.js +108 -185
- package/src/model/markercollection.js +379 -480
- package/src/model/model.js +883 -1034
- package/src/model/node.js +419 -463
- package/src/model/nodelist.js +175 -201
- package/src/model/operation/attributeoperation.js +153 -182
- package/src/model/operation/detachoperation.js +64 -83
- package/src/model/operation/insertoperation.js +135 -166
- package/src/model/operation/markeroperation.js +114 -140
- package/src/model/operation/mergeoperation.js +163 -191
- package/src/model/operation/moveoperation.js +157 -187
- package/src/model/operation/nooperation.js +28 -38
- package/src/model/operation/operation.js +106 -125
- package/src/model/operation/operationfactory.js +30 -34
- package/src/model/operation/renameoperation.js +109 -135
- package/src/model/operation/rootattributeoperation.js +155 -188
- package/src/model/operation/splitoperation.js +196 -232
- package/src/model/operation/transform.js +1833 -2204
- package/src/model/operation/utils.js +140 -204
- package/src/model/position.js +899 -1053
- package/src/model/range.js +910 -1028
- package/src/model/rootelement.js +77 -97
- package/src/model/schema.js +1189 -1835
- package/src/model/selection.js +745 -862
- package/src/model/text.js +90 -114
- package/src/model/textproxy.js +204 -240
- package/src/model/treewalker.js +316 -397
- package/src/model/typecheckable.js +16 -0
- package/src/model/utils/autoparagraphing.js +32 -44
- package/src/model/utils/deletecontent.js +334 -418
- package/src/model/utils/findoptimalinsertionrange.js +25 -36
- package/src/model/utils/getselectedcontent.js +96 -118
- package/src/model/utils/insertcontent.js +654 -773
- package/src/model/utils/insertobject.js +96 -119
- package/src/model/utils/modifyselection.js +120 -158
- package/src/model/utils/selection-post-fixer.js +153 -201
- package/src/model/writer.js +1305 -1474
- package/src/view/attributeelement.js +189 -225
- package/src/view/containerelement.js +75 -85
- package/src/view/document.js +172 -215
- package/src/view/documentfragment.js +200 -249
- package/src/view/documentselection.js +338 -367
- package/src/view/domconverter.js +1370 -1617
- package/src/view/downcastwriter.js +1747 -2076
- package/src/view/editableelement.js +81 -97
- package/src/view/element.js +739 -890
- package/src/view/elementdefinition.js +5 -0
- package/src/view/emptyelement.js +82 -92
- package/src/view/filler.js +35 -50
- package/src/view/item.js +5 -0
- package/src/view/matcher.js +260 -559
- package/src/view/node.js +274 -360
- package/src/view/observer/arrowkeysobserver.js +19 -28
- package/src/view/observer/bubblingemittermixin.js +120 -263
- package/src/view/observer/bubblingeventinfo.js +47 -55
- package/src/view/observer/clickobserver.js +7 -13
- package/src/view/observer/compositionobserver.js +14 -24
- package/src/view/observer/domeventdata.js +57 -67
- package/src/view/observer/domeventobserver.js +40 -64
- package/src/view/observer/fakeselectionobserver.js +81 -96
- package/src/view/observer/focusobserver.js +45 -61
- package/src/view/observer/inputobserver.js +7 -13
- package/src/view/observer/keyobserver.js +17 -27
- package/src/view/observer/mouseobserver.js +7 -14
- package/src/view/observer/mutationobserver.js +220 -315
- package/src/view/observer/observer.js +81 -102
- package/src/view/observer/selectionobserver.js +191 -246
- package/src/view/observer/tabobserver.js +23 -36
- package/src/view/placeholder.js +128 -173
- package/src/view/position.js +350 -401
- package/src/view/range.js +453 -513
- package/src/view/rawelement.js +85 -112
- package/src/view/renderer.js +874 -1018
- package/src/view/rooteditableelement.js +80 -90
- package/src/view/selection.js +608 -689
- package/src/view/styles/background.js +43 -44
- package/src/view/styles/border.js +220 -276
- package/src/view/styles/margin.js +8 -17
- package/src/view/styles/padding.js +8 -16
- package/src/view/styles/utils.js +127 -160
- package/src/view/stylesmap.js +728 -905
- package/src/view/text.js +102 -126
- package/src/view/textproxy.js +144 -170
- package/src/view/treewalker.js +383 -479
- package/src/view/typecheckable.js +19 -0
- package/src/view/uielement.js +166 -187
- package/src/view/upcastwriter.js +395 -449
- package/src/view/view.js +569 -664
- package/src/dataprocessor/dataprocessor.jsdoc +0 -64
- package/src/model/item.jsdoc +0 -14
- package/src/view/elementdefinition.jsdoc +0 -59
- package/src/view/item.jsdoc +0 -14
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/view/attributeelement
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Element from './element';
|
|
11
9
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
12
|
-
|
|
13
10
|
// Default attribute priority.
|
|
14
11
|
const DEFAULT_PRIORITY = 10;
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Attribute elements are used to represent formatting elements in the view (think – `<b>`, `<span style="font-size: 2em">`, etc.).
|
|
18
14
|
* Most often they are created when downcasting model text attributes.
|
|
@@ -27,238 +23,206 @@ const DEFAULT_PRIORITY = 10;
|
|
|
27
23
|
* @extends module:engine/view/element~Element
|
|
28
24
|
*/
|
|
29
25
|
export default class AttributeElement extends Element {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
} else {
|
|
164
|
-
return name === this.name && (
|
|
165
|
-
type === 'attributeElement' || type === 'view:attributeElement' ||
|
|
166
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
167
|
-
type === 'element' || type === 'view:element'
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Checks if this element is similar to other element.
|
|
174
|
-
*
|
|
175
|
-
* If none of elements has set {@link module:engine/view/attributeelement~AttributeElement#id}, then both elements
|
|
176
|
-
* should have the same name, attributes and priority to be considered as similar. Two similar elements can contain
|
|
177
|
-
* different set of children nodes.
|
|
178
|
-
*
|
|
179
|
-
* If at least one element has {@link module:engine/view/attributeelement~AttributeElement#id} set, then both
|
|
180
|
-
* elements have to have the same {@link module:engine/view/attributeelement~AttributeElement#id} value to be
|
|
181
|
-
* considered similar.
|
|
182
|
-
*
|
|
183
|
-
* Similarity is important for {@link module:engine/view/downcastwriter~DowncastWriter}. For example:
|
|
184
|
-
*
|
|
185
|
-
* * two following similar elements can be merged together into one, longer element,
|
|
186
|
-
* * {@link module:engine/view/downcastwriter~DowncastWriter#unwrap} checks similarity of passed element and processed element to
|
|
187
|
-
* decide whether processed element should be unwrapped,
|
|
188
|
-
* * etc.
|
|
189
|
-
*
|
|
190
|
-
* @param {module:engine/view/element~Element} otherElement
|
|
191
|
-
* @returns {Boolean}
|
|
192
|
-
*/
|
|
193
|
-
isSimilar( otherElement ) {
|
|
194
|
-
// If any element has an `id` set, just compare the ids.
|
|
195
|
-
if ( this.id !== null || otherElement.id !== null ) {
|
|
196
|
-
return this.id === otherElement.id;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return super.isSimilar( otherElement ) && this.priority == otherElement.priority;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Clones provided element with priority.
|
|
204
|
-
*
|
|
205
|
-
* @protected
|
|
206
|
-
* @param {Boolean} deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
207
|
-
* element will be cloned without any children.
|
|
208
|
-
* @returns {module:engine/view/attributeelement~AttributeElement} Clone of this element.
|
|
209
|
-
*/
|
|
210
|
-
_clone( deep ) {
|
|
211
|
-
const cloned = super._clone( deep );
|
|
212
|
-
|
|
213
|
-
// Clone priority too.
|
|
214
|
-
cloned._priority = this._priority;
|
|
215
|
-
|
|
216
|
-
// And id too.
|
|
217
|
-
cloned._id = this._id;
|
|
218
|
-
|
|
219
|
-
return cloned;
|
|
220
|
-
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an attribute element.
|
|
28
|
+
*
|
|
29
|
+
* @see module:engine/view/downcastwriter~DowncastWriter#createAttributeElement
|
|
30
|
+
* @see module:engine/view/element~Element
|
|
31
|
+
* @protected
|
|
32
|
+
* @param {module:engine/view/document~Document} document The document instance to which this element belongs.
|
|
33
|
+
* @param {String} name Node name.
|
|
34
|
+
* @param {Object|Iterable} [attrs] Collection of attributes.
|
|
35
|
+
* @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]
|
|
36
|
+
* A list of nodes to be inserted into created element.
|
|
37
|
+
*/
|
|
38
|
+
constructor(...args) {
|
|
39
|
+
super(...args);
|
|
40
|
+
/**
|
|
41
|
+
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
42
|
+
*
|
|
43
|
+
* @method #getFillerOffset
|
|
44
|
+
* @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
45
|
+
*/
|
|
46
|
+
this.getFillerOffset = getFillerOffset;
|
|
47
|
+
/**
|
|
48
|
+
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
49
|
+
*
|
|
50
|
+
* @protected
|
|
51
|
+
* @member {Number}
|
|
52
|
+
*/
|
|
53
|
+
this._priority = DEFAULT_PRIORITY;
|
|
54
|
+
/**
|
|
55
|
+
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
56
|
+
* and then two elements are considered similar if, and only if they have the same `_id`.
|
|
57
|
+
*
|
|
58
|
+
* @protected
|
|
59
|
+
* @member {String|Number}
|
|
60
|
+
*/
|
|
61
|
+
this._id = null;
|
|
62
|
+
/**
|
|
63
|
+
* Keeps all the attribute elements that have the same {@link module:engine/view/attributeelement~AttributeElement#id ids}
|
|
64
|
+
* and still exist in the view tree.
|
|
65
|
+
*
|
|
66
|
+
* This property is managed by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
67
|
+
*
|
|
68
|
+
* @protected
|
|
69
|
+
* @member {Set.<module:engine/view/attributeelement~AttributeElement>|null}
|
|
70
|
+
*/
|
|
71
|
+
this._clonesGroup = null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Element priority. Decides in what order elements are wrapped by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
75
|
+
*
|
|
76
|
+
* @readonly
|
|
77
|
+
* @type {Number}
|
|
78
|
+
*/
|
|
79
|
+
get priority() {
|
|
80
|
+
return this._priority;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Element identifier. If set, it is used by {@link module:engine/view/element~Element#isSimilar},
|
|
84
|
+
* and then two elements are considered similar if, and only if they have the same `id`.
|
|
85
|
+
*
|
|
86
|
+
* @readonly
|
|
87
|
+
* @type {String|Number}
|
|
88
|
+
*/
|
|
89
|
+
get id() {
|
|
90
|
+
return this._id;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns all {@link module:engine/view/attributeelement~AttributeElement attribute elements} that has the
|
|
94
|
+
* same {@link module:engine/view/attributeelement~AttributeElement#id id} and are in the view tree (were not removed).
|
|
95
|
+
*
|
|
96
|
+
* Note: If this element has been removed from the tree, returned set will not include it.
|
|
97
|
+
*
|
|
98
|
+
* Throws {@link module:utils/ckeditorerror~CKEditorError attribute-element-get-elements-with-same-id-no-id}
|
|
99
|
+
* if this element has no `id`.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Set.<module:engine/view/attributeelement~AttributeElement>} Set containing all the attribute elements
|
|
102
|
+
* with the same `id` that were added and not removed from the view tree.
|
|
103
|
+
*/
|
|
104
|
+
getElementsWithSameId() {
|
|
105
|
+
if (this.id === null) {
|
|
106
|
+
/**
|
|
107
|
+
* Cannot get elements with the same id for an attribute element without id.
|
|
108
|
+
*
|
|
109
|
+
* @error attribute-element-get-elements-with-same-id-no-id
|
|
110
|
+
*/
|
|
111
|
+
throw new CKEditorError('attribute-element-get-elements-with-same-id-no-id', this);
|
|
112
|
+
}
|
|
113
|
+
return new Set(this._clonesGroup);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Checks if this element is similar to other element.
|
|
117
|
+
*
|
|
118
|
+
* If none of elements has set {@link module:engine/view/attributeelement~AttributeElement#id}, then both elements
|
|
119
|
+
* should have the same name, attributes and priority to be considered as similar. Two similar elements can contain
|
|
120
|
+
* different set of children nodes.
|
|
121
|
+
*
|
|
122
|
+
* If at least one element has {@link module:engine/view/attributeelement~AttributeElement#id} set, then both
|
|
123
|
+
* elements have to have the same {@link module:engine/view/attributeelement~AttributeElement#id} value to be
|
|
124
|
+
* considered similar.
|
|
125
|
+
*
|
|
126
|
+
* Similarity is important for {@link module:engine/view/downcastwriter~DowncastWriter}. For example:
|
|
127
|
+
*
|
|
128
|
+
* * two following similar elements can be merged together into one, longer element,
|
|
129
|
+
* * {@link module:engine/view/downcastwriter~DowncastWriter#unwrap} checks similarity of passed element and processed element to
|
|
130
|
+
* decide whether processed element should be unwrapped,
|
|
131
|
+
* * etc.
|
|
132
|
+
*
|
|
133
|
+
* @param {module:engine/view/element~Element} otherElement
|
|
134
|
+
* @returns {Boolean}
|
|
135
|
+
*/
|
|
136
|
+
isSimilar(otherElement) {
|
|
137
|
+
// If any element has an `id` set, just compare the ids.
|
|
138
|
+
if (this.id !== null || otherElement.id !== null) {
|
|
139
|
+
return this.id === otherElement.id;
|
|
140
|
+
}
|
|
141
|
+
return super.isSimilar(otherElement) && this.priority == otherElement.priority;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Clones provided element with priority.
|
|
145
|
+
*
|
|
146
|
+
* @protected
|
|
147
|
+
* @param {Boolean} deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
148
|
+
* element will be cloned without any children.
|
|
149
|
+
* @returns {module:engine/view/attributeelement~AttributeElement} Clone of this element.
|
|
150
|
+
*/
|
|
151
|
+
_clone(deep = false) {
|
|
152
|
+
const cloned = super._clone(deep);
|
|
153
|
+
// Clone priority too.
|
|
154
|
+
cloned._priority = this._priority;
|
|
155
|
+
// And id too.
|
|
156
|
+
cloned._id = this._id;
|
|
157
|
+
return cloned;
|
|
158
|
+
}
|
|
221
159
|
}
|
|
222
|
-
|
|
160
|
+
AttributeElement.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
|
|
223
161
|
/**
|
|
224
|
-
*
|
|
162
|
+
* Checks whether this object is of the given.
|
|
163
|
+
*
|
|
164
|
+
* attributeElement.is( 'attributeElement' ); // -> true
|
|
165
|
+
* attributeElement.is( 'element' ); // -> true
|
|
166
|
+
* attributeElement.is( 'node' ); // -> true
|
|
167
|
+
* attributeElement.is( 'view:attributeElement' ); // -> true
|
|
168
|
+
* attributeElement.is( 'view:element' ); // -> true
|
|
169
|
+
* attributeElement.is( 'view:node' ); // -> true
|
|
170
|
+
*
|
|
171
|
+
* attributeElement.is( 'model:element' ); // -> false
|
|
172
|
+
* attributeElement.is( 'documentFragment' ); // -> false
|
|
173
|
+
*
|
|
174
|
+
* Assuming that the object being checked is an attribute element, you can also check its
|
|
175
|
+
* {@link module:engine/view/attributeelement~AttributeElement#name name}:
|
|
225
176
|
*
|
|
226
|
-
*
|
|
177
|
+
* attributeElement.is( 'element', 'b' ); // -> true if this is a bold element
|
|
178
|
+
* attributeElement.is( 'attributeElement', 'b' ); // -> same as above
|
|
179
|
+
* text.is( 'element', 'b' ); -> false
|
|
180
|
+
*
|
|
181
|
+
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
182
|
+
*
|
|
183
|
+
* @param {String} type Type to check.
|
|
184
|
+
* @param {String} [name] Element name.
|
|
185
|
+
* @returns {Boolean}
|
|
227
186
|
*/
|
|
228
|
-
AttributeElement.
|
|
229
|
-
|
|
187
|
+
AttributeElement.prototype.is = function (type, name) {
|
|
188
|
+
if (!name) {
|
|
189
|
+
return type === 'attributeElement' || type === 'view:attributeElement' ||
|
|
190
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
191
|
+
type === 'element' || type === 'view:element' ||
|
|
192
|
+
type === 'node' || type === 'view:node';
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return name === this.name && (type === 'attributeElement' || type === 'view:attributeElement' ||
|
|
196
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
197
|
+
type === 'element' || type === 'view:element');
|
|
198
|
+
}
|
|
199
|
+
};
|
|
230
200
|
// Returns block {@link module:engine/view/filler~Filler filler} offset or `null` if block filler is not needed.
|
|
231
201
|
//
|
|
232
202
|
// @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
233
203
|
function getFillerOffset() {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Render block filler at the end of element (after all ui elements).
|
|
255
|
-
return this.childCount;
|
|
204
|
+
// <b>foo</b> does not need filler.
|
|
205
|
+
if (nonUiChildrenCount(this)) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
let element = this.parent;
|
|
209
|
+
// <p><b></b></p> needs filler -> <p><b><br></b></p>
|
|
210
|
+
while (element && element.is('attributeElement')) {
|
|
211
|
+
if (nonUiChildrenCount(element) > 1) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
element = element.parent;
|
|
215
|
+
}
|
|
216
|
+
if (!element || nonUiChildrenCount(element) > 1) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
// Render block filler at the end of element (after all ui elements).
|
|
220
|
+
return this.childCount;
|
|
256
221
|
}
|
|
257
|
-
|
|
258
222
|
// Returns total count of children that are not {@link module:engine/view/uielement~UIElement UIElements}.
|
|
259
223
|
//
|
|
260
224
|
// @param {module:engine/view/element~Element} element
|
|
261
225
|
// @returns {Number}
|
|
262
|
-
function nonUiChildrenCount(
|
|
263
|
-
|
|
226
|
+
function nonUiChildrenCount(element) {
|
|
227
|
+
return Array.from(element.getChildren()).filter(element => !element.is('uiElement')).length;
|
|
264
228
|
}
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module engine/view/containerelement
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import Element from './element';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Containers are elements which define document structure. They define boundaries for
|
|
14
11
|
* {@link module:engine/view/attributeelement~AttributeElement attributes}. They are mostly used for block elements like `<p>` or `<div>`.
|
|
@@ -31,93 +28,86 @@ import Element from './element';
|
|
|
31
28
|
* @extends module:engine/view/element~Element
|
|
32
29
|
*/
|
|
33
30
|
export default class ContainerElement extends Element {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Checks whether this object is of the given.
|
|
60
|
-
*
|
|
61
|
-
* containerElement.is( 'containerElement' ); // -> true
|
|
62
|
-
* containerElement.is( 'element' ); // -> true
|
|
63
|
-
* containerElement.is( 'node' ); // -> true
|
|
64
|
-
* containerElement.is( 'view:containerElement' ); // -> true
|
|
65
|
-
* containerElement.is( 'view:element' ); // -> true
|
|
66
|
-
* containerElement.is( 'view:node' ); // -> true
|
|
67
|
-
*
|
|
68
|
-
* containerElement.is( 'model:element' ); // -> false
|
|
69
|
-
* containerElement.is( 'documentFragment' ); // -> false
|
|
70
|
-
*
|
|
71
|
-
* Assuming that the object being checked is a container element, you can also check its
|
|
72
|
-
* {@link module:engine/view/containerelement~ContainerElement#name name}:
|
|
73
|
-
*
|
|
74
|
-
* containerElement.is( 'element', 'div' ); // -> true if this is a div container element
|
|
75
|
-
* containerElement.is( 'contaienrElement', 'div' ); // -> same as above
|
|
76
|
-
* text.is( 'element', 'div' ); -> false
|
|
77
|
-
*
|
|
78
|
-
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
79
|
-
*
|
|
80
|
-
* @param {String} type Type to check.
|
|
81
|
-
* @param {String} [name] Element name.
|
|
82
|
-
* @returns {Boolean}
|
|
83
|
-
*/
|
|
84
|
-
is( type, name = null ) {
|
|
85
|
-
if ( !name ) {
|
|
86
|
-
return type === 'containerElement' || type === 'view:containerElement' ||
|
|
87
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
88
|
-
type === 'element' || type === 'view:element' ||
|
|
89
|
-
type === 'node' || type === 'view:node';
|
|
90
|
-
} else {
|
|
91
|
-
return name === this.name && (
|
|
92
|
-
type === 'containerElement' || type === 'view:containerElement' ||
|
|
93
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
94
|
-
type === 'element' || type === 'view:element'
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a container element.
|
|
33
|
+
*
|
|
34
|
+
* @see module:engine/view/downcastwriter~DowncastWriter#createContainerElement
|
|
35
|
+
* @see module:engine/view/element~Element
|
|
36
|
+
* @protected
|
|
37
|
+
* @param {module:engine/view/document~Document} document The document instance to which this element belongs.
|
|
38
|
+
* @param {String} name Node name.
|
|
39
|
+
* @param {Object|Iterable} [attrs] Collection of attributes.
|
|
40
|
+
* @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>} [children]
|
|
41
|
+
* A list of nodes to be inserted into created element.
|
|
42
|
+
*/
|
|
43
|
+
constructor(...args) {
|
|
44
|
+
super(...args);
|
|
45
|
+
/**
|
|
46
|
+
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
47
|
+
*
|
|
48
|
+
* @method #getFillerOffset
|
|
49
|
+
* @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
50
|
+
*/
|
|
51
|
+
this.getFillerOffset = getFillerOffset;
|
|
52
|
+
}
|
|
98
53
|
}
|
|
99
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether this object is of the given.
|
|
56
|
+
*
|
|
57
|
+
* containerElement.is( 'containerElement' ); // -> true
|
|
58
|
+
* containerElement.is( 'element' ); // -> true
|
|
59
|
+
* containerElement.is( 'node' ); // -> true
|
|
60
|
+
* containerElement.is( 'view:containerElement' ); // -> true
|
|
61
|
+
* containerElement.is( 'view:element' ); // -> true
|
|
62
|
+
* containerElement.is( 'view:node' ); // -> true
|
|
63
|
+
*
|
|
64
|
+
* containerElement.is( 'model:element' ); // -> false
|
|
65
|
+
* containerElement.is( 'documentFragment' ); // -> false
|
|
66
|
+
*
|
|
67
|
+
* Assuming that the object being checked is a container element, you can also check its
|
|
68
|
+
* {@link module:engine/view/containerelement~ContainerElement#name name}:
|
|
69
|
+
*
|
|
70
|
+
* containerElement.is( 'element', 'div' ); // -> true if this is a div container element
|
|
71
|
+
* containerElement.is( 'contaienrElement', 'div' ); // -> same as above
|
|
72
|
+
* text.is( 'element', 'div' ); -> false
|
|
73
|
+
*
|
|
74
|
+
* {@link module:engine/view/node~Node#is Check the entire list of view objects} which implement the `is()` method.
|
|
75
|
+
*
|
|
76
|
+
* @param {String} type Type to check.
|
|
77
|
+
* @param {String} [name] Element name.
|
|
78
|
+
* @returns {Boolean}
|
|
79
|
+
*/
|
|
80
|
+
ContainerElement.prototype.is = function (type, name) {
|
|
81
|
+
if (!name) {
|
|
82
|
+
return type === 'containerElement' || type === 'view:containerElement' ||
|
|
83
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
84
|
+
type === 'element' || type === 'view:element' ||
|
|
85
|
+
type === 'node' || type === 'view:node';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return name === this.name && (type === 'containerElement' || type === 'view:containerElement' ||
|
|
89
|
+
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
90
|
+
type === 'element' || type === 'view:element');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
100
93
|
/**
|
|
101
94
|
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
102
95
|
*
|
|
103
96
|
* @returns {Number|null} Block filler offset or `null` if block filler is not needed.
|
|
104
97
|
*/
|
|
105
98
|
export function getFillerOffset() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// If there are only UI elements – render the bogus at the end of the element.
|
|
122
|
-
return this.childCount;
|
|
99
|
+
const children = [...this.getChildren()];
|
|
100
|
+
const lastChild = children[this.childCount - 1];
|
|
101
|
+
// Block filler is required after a `<br>` if it's the last element in its container. See #1422.
|
|
102
|
+
if (lastChild && lastChild.is('element', 'br')) {
|
|
103
|
+
return this.childCount;
|
|
104
|
+
}
|
|
105
|
+
for (const child of children) {
|
|
106
|
+
// If there's any non-UI element – don't render the bogus.
|
|
107
|
+
if (!child.is('uiElement')) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// If there are only UI elements – render the bogus at the end of the element.
|
|
112
|
+
return this.childCount;
|
|
123
113
|
}
|