@ckeditor/ckeditor5-engine 47.6.1 → 48.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/LICENSE.md +1 -1
- package/{src → dist}/engineconfig.d.ts +6 -15
- package/dist/index-editor.css +38 -15
- package/dist/index.css +37 -37
- package/dist/index.css.map +1 -1
- package/{src → dist}/index.d.ts +0 -1
- package/dist/index.js +588 -94
- package/dist/index.js.map +1 -1
- package/{src → dist}/model/model.d.ts +10 -4
- package/{src → dist}/model/selection.d.ts +1 -1
- package/{src → dist}/view/downcastwriter.d.ts +3 -2
- package/{src → dist}/view/element.d.ts +2 -2
- package/{src → dist}/view/matcher.d.ts +4 -2
- package/dist/view/styles/background.d.ts +18 -0
- package/{src → dist}/view/styles/border.d.ts +0 -12
- package/{src → dist}/view/styles/margin.d.ts +0 -13
- package/{src → dist}/view/styles/padding.d.ts +0 -13
- package/{src → dist}/view/styles/utils.d.ts +12 -0
- package/package.json +20 -39
- package/src/controller/datacontroller.js +0 -522
- package/src/controller/editingcontroller.js +0 -181
- package/src/conversion/conversion.js +0 -606
- package/src/conversion/conversionhelpers.js +0 -33
- package/src/conversion/downcastdispatcher.js +0 -563
- package/src/conversion/downcasthelpers.js +0 -2160
- package/src/conversion/mapper.js +0 -1050
- package/src/conversion/modelconsumable.js +0 -331
- package/src/conversion/upcastdispatcher.js +0 -470
- package/src/conversion/upcasthelpers.js +0 -952
- package/src/conversion/viewconsumable.js +0 -541
- package/src/dataprocessor/basichtmlwriter.js +0 -22
- package/src/dataprocessor/dataprocessor.js +0 -5
- package/src/dataprocessor/htmldataprocessor.js +0 -107
- package/src/dataprocessor/htmlwriter.js +0 -5
- package/src/dataprocessor/xmldataprocessor.js +0 -127
- package/src/dev-utils/model.js +0 -396
- package/src/dev-utils/operationreplayer.js +0 -116
- package/src/dev-utils/utils.js +0 -122
- package/src/dev-utils/view.js +0 -990
- package/src/engineconfig.js +0 -5
- package/src/index.js +0 -134
- package/src/legacyerrors.js +0 -17
- package/src/model/batch.js +0 -98
- package/src/model/differ.js +0 -1288
- package/src/model/document.js +0 -398
- package/src/model/documentfragment.js +0 -332
- package/src/model/documentselection.js +0 -1026
- package/src/model/element.js +0 -323
- package/src/model/history.js +0 -206
- package/src/model/item.js +0 -5
- package/src/model/liveposition.js +0 -93
- package/src/model/liverange.js +0 -121
- package/src/model/markercollection.js +0 -436
- package/src/model/model.js +0 -866
- package/src/model/node.js +0 -371
- package/src/model/nodelist.js +0 -244
- package/src/model/operation/attributeoperation.js +0 -172
- package/src/model/operation/detachoperation.js +0 -87
- package/src/model/operation/insertoperation.js +0 -153
- package/src/model/operation/markeroperation.js +0 -136
- package/src/model/operation/mergeoperation.js +0 -184
- package/src/model/operation/moveoperation.js +0 -179
- package/src/model/operation/nooperation.js +0 -48
- package/src/model/operation/operation.js +0 -78
- package/src/model/operation/operationfactory.js +0 -44
- package/src/model/operation/renameoperation.js +0 -128
- package/src/model/operation/rootattributeoperation.js +0 -173
- package/src/model/operation/rootoperation.js +0 -106
- package/src/model/operation/splitoperation.js +0 -214
- package/src/model/operation/transform.js +0 -2211
- package/src/model/operation/utils.js +0 -217
- package/src/model/position.js +0 -1041
- package/src/model/range.js +0 -880
- package/src/model/rootelement.js +0 -82
- package/src/model/schema.js +0 -1542
- package/src/model/selection.js +0 -814
- package/src/model/text.js +0 -92
- package/src/model/textproxy.js +0 -202
- package/src/model/treewalker.js +0 -313
- package/src/model/typecheckable.js +0 -16
- package/src/model/utils/autoparagraphing.js +0 -63
- package/src/model/utils/deletecontent.js +0 -509
- package/src/model/utils/getselectedcontent.js +0 -126
- package/src/model/utils/insertcontent.js +0 -750
- package/src/model/utils/insertobject.js +0 -135
- package/src/model/utils/modifyselection.js +0 -187
- package/src/model/utils/selection-post-fixer.js +0 -264
- package/src/model/writer.js +0 -1318
- package/src/view/attributeelement.js +0 -220
- package/src/view/containerelement.js +0 -91
- package/src/view/datatransfer.js +0 -106
- package/src/view/document.js +0 -139
- package/src/view/documentfragment.js +0 -251
- package/src/view/documentselection.js +0 -270
- package/src/view/domconverter.js +0 -1661
- package/src/view/downcastwriter.js +0 -1589
- package/src/view/editableelement.js +0 -74
- package/src/view/element.js +0 -1053
- package/src/view/elementdefinition.js +0 -5
- package/src/view/emptyelement.js +0 -83
- package/src/view/filler.js +0 -161
- package/src/view/item.js +0 -5
- package/src/view/matcher.js +0 -437
- package/src/view/node.js +0 -238
- package/src/view/observer/arrowkeysobserver.js +0 -40
- package/src/view/observer/bubblingemittermixin.js +0 -215
- package/src/view/observer/bubblingeventinfo.js +0 -49
- package/src/view/observer/clickobserver.js +0 -26
- package/src/view/observer/compositionobserver.js +0 -64
- package/src/view/observer/domeventdata.js +0 -63
- package/src/view/observer/domeventobserver.js +0 -81
- package/src/view/observer/fakeselectionobserver.js +0 -95
- package/src/view/observer/focusobserver.js +0 -166
- package/src/view/observer/inputobserver.js +0 -236
- package/src/view/observer/keyobserver.js +0 -36
- package/src/view/observer/mouseobserver.js +0 -26
- package/src/view/observer/mutationobserver.js +0 -219
- package/src/view/observer/observer.js +0 -92
- package/src/view/observer/pointerobserver.js +0 -26
- package/src/view/observer/selectionobserver.js +0 -318
- package/src/view/observer/tabobserver.js +0 -42
- package/src/view/observer/touchobserver.js +0 -26
- package/src/view/placeholder.js +0 -285
- package/src/view/position.js +0 -341
- package/src/view/range.js +0 -451
- package/src/view/rawelement.js +0 -115
- package/src/view/renderer.js +0 -1148
- package/src/view/rooteditableelement.js +0 -78
- package/src/view/selection.js +0 -594
- package/src/view/styles/background.d.ts +0 -33
- package/src/view/styles/background.js +0 -74
- package/src/view/styles/border.js +0 -316
- package/src/view/styles/margin.js +0 -34
- package/src/view/styles/padding.js +0 -34
- package/src/view/styles/utils.js +0 -219
- package/src/view/stylesmap.js +0 -941
- package/src/view/text.js +0 -110
- package/src/view/textproxy.js +0 -136
- package/src/view/tokenlist.js +0 -194
- package/src/view/treewalker.js +0 -389
- package/src/view/typecheckable.js +0 -19
- package/src/view/uielement.js +0 -194
- package/src/view/upcastwriter.js +0 -363
- package/src/view/view.js +0 -579
- package/theme/placeholder.css +0 -36
- package/theme/renderer.css +0 -9
- /package/{src → dist}/controller/datacontroller.d.ts +0 -0
- /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
- /package/{src → dist}/conversion/conversion.d.ts +0 -0
- /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
- /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/mapper.d.ts +0 -0
- /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
- /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
- /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
- /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
- /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
- /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
- /package/{src → dist}/dev-utils/model.d.ts +0 -0
- /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
- /package/{src → dist}/dev-utils/utils.d.ts +0 -0
- /package/{src → dist}/dev-utils/view.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/model/batch.d.ts +0 -0
- /package/{src → dist}/model/differ.d.ts +0 -0
- /package/{src → dist}/model/document.d.ts +0 -0
- /package/{src → dist}/model/documentfragment.d.ts +0 -0
- /package/{src → dist}/model/documentselection.d.ts +0 -0
- /package/{src → dist}/model/element.d.ts +0 -0
- /package/{src → dist}/model/history.d.ts +0 -0
- /package/{src → dist}/model/item.d.ts +0 -0
- /package/{src → dist}/model/liveposition.d.ts +0 -0
- /package/{src → dist}/model/liverange.d.ts +0 -0
- /package/{src → dist}/model/markercollection.d.ts +0 -0
- /package/{src → dist}/model/node.d.ts +0 -0
- /package/{src → dist}/model/nodelist.d.ts +0 -0
- /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
- /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
- /package/{src → dist}/model/operation/operation.d.ts +0 -0
- /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
- /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
- /package/{src → dist}/model/operation/transform.d.ts +0 -0
- /package/{src → dist}/model/operation/utils.d.ts +0 -0
- /package/{src → dist}/model/position.d.ts +0 -0
- /package/{src → dist}/model/range.d.ts +0 -0
- /package/{src → dist}/model/rootelement.d.ts +0 -0
- /package/{src → dist}/model/schema.d.ts +0 -0
- /package/{src → dist}/model/text.d.ts +0 -0
- /package/{src → dist}/model/textproxy.d.ts +0 -0
- /package/{src → dist}/model/treewalker.d.ts +0 -0
- /package/{src → dist}/model/typecheckable.d.ts +0 -0
- /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
- /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
- /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
- /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
- /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
- /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
- /package/{src → dist}/model/writer.d.ts +0 -0
- /package/{src → dist}/view/attributeelement.d.ts +0 -0
- /package/{src → dist}/view/containerelement.d.ts +0 -0
- /package/{src → dist}/view/datatransfer.d.ts +0 -0
- /package/{src → dist}/view/document.d.ts +0 -0
- /package/{src → dist}/view/documentfragment.d.ts +0 -0
- /package/{src → dist}/view/documentselection.d.ts +0 -0
- /package/{src → dist}/view/domconverter.d.ts +0 -0
- /package/{src → dist}/view/editableelement.d.ts +0 -0
- /package/{src → dist}/view/elementdefinition.d.ts +0 -0
- /package/{src → dist}/view/emptyelement.d.ts +0 -0
- /package/{src → dist}/view/filler.d.ts +0 -0
- /package/{src → dist}/view/item.d.ts +0 -0
- /package/{src → dist}/view/node.d.ts +0 -0
- /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
- /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
- /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
- /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/observer.d.ts +0 -0
- /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
- /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
- /package/{src → dist}/view/placeholder.d.ts +0 -0
- /package/{src → dist}/view/position.d.ts +0 -0
- /package/{src → dist}/view/range.d.ts +0 -0
- /package/{src → dist}/view/rawelement.d.ts +0 -0
- /package/{src → dist}/view/renderer.d.ts +0 -0
- /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
- /package/{src → dist}/view/selection.d.ts +0 -0
- /package/{src → dist}/view/stylesmap.d.ts +0 -0
- /package/{src → dist}/view/text.d.ts +0 -0
- /package/{src → dist}/view/textproxy.d.ts +0 -0
- /package/{src → dist}/view/tokenlist.d.ts +0 -0
- /package/{src → dist}/view/treewalker.d.ts +0 -0
- /package/{src → dist}/view/typecheckable.d.ts +0 -0
- /package/{src → dist}/view/uielement.d.ts +0 -0
- /package/{src → dist}/view/upcastwriter.d.ts +0 -0
- /package/{src → dist}/view/view.d.ts +0 -0
package/src/model/node.js
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
6
|
-
/**
|
|
7
|
-
* @module engine/model/node
|
|
8
|
-
*/
|
|
9
|
-
import { ModelTypeCheckable } from './typecheckable.js';
|
|
10
|
-
import { compareArrays, toMap } from '@ckeditor/ckeditor5-utils';
|
|
11
|
-
/**
|
|
12
|
-
* Model node. Most basic structure of model tree.
|
|
13
|
-
*
|
|
14
|
-
* This is an abstract class that is a base for other classes representing different nodes in model.
|
|
15
|
-
*
|
|
16
|
-
* **Note:** If a node is detached from the model tree, you can manipulate it using it's API.
|
|
17
|
-
* However, it is **very important** that nodes already attached to model tree should be only changed through
|
|
18
|
-
* {@link module:engine/model/writer~ModelWriter Writer API}.
|
|
19
|
-
*
|
|
20
|
-
* Changes done by `Node` methods, like {@link module:engine/model/element~ModelElement#_insertChild _insertChild} or
|
|
21
|
-
* {@link module:engine/model/node~ModelNode#_setAttribute _setAttribute}
|
|
22
|
-
* do not generate {@link module:engine/model/operation/operation~Operation operations}
|
|
23
|
-
* which are essential for correct editor work if you modify nodes in {@link module:engine/model/document~ModelDocument document} root.
|
|
24
|
-
*
|
|
25
|
-
* The flow of working on `Node` (and classes that inherits from it) is as such:
|
|
26
|
-
* 1. You can create a `Node` instance, modify it using it's API.
|
|
27
|
-
* 2. Add `Node` to the model using `Batch` API.
|
|
28
|
-
* 3. Change `Node` that was already added to the model using `Batch` API.
|
|
29
|
-
*
|
|
30
|
-
* Similarly, you cannot use `Batch` API on a node that has not been added to the model tree, with the exception
|
|
31
|
-
* of {@link module:engine/model/writer~ModelWriter#insert inserting} that node to the model tree.
|
|
32
|
-
*
|
|
33
|
-
* Be aware that using {@link module:engine/model/writer~ModelWriter#remove remove from Batch API} does not allow to use `Node` API because
|
|
34
|
-
* the information about `Node` is still kept in model document.
|
|
35
|
-
*
|
|
36
|
-
* In case of {@link module:engine/model/element~ModelElement element node}, adding and removing children also counts as changing a node and
|
|
37
|
-
* follows same rules.
|
|
38
|
-
*/
|
|
39
|
-
export class ModelNode extends ModelTypeCheckable {
|
|
40
|
-
/**
|
|
41
|
-
* Parent of this node. It could be {@link module:engine/model/element~ModelElement}
|
|
42
|
-
* or {@link module:engine/model/documentfragment~ModelDocumentFragment}.
|
|
43
|
-
* Equals to `null` if the node has no parent.
|
|
44
|
-
*/
|
|
45
|
-
parent = null;
|
|
46
|
-
/**
|
|
47
|
-
* Attributes set on this node.
|
|
48
|
-
*/
|
|
49
|
-
_attrs;
|
|
50
|
-
/**
|
|
51
|
-
* Index of this node in its parent or `null` if the node has no parent.
|
|
52
|
-
*
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
_index = null;
|
|
56
|
-
/**
|
|
57
|
-
* Offset at which this node starts in its parent or `null` if the node has no parent.
|
|
58
|
-
*
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
_startOffset = null;
|
|
62
|
-
/**
|
|
63
|
-
* Creates a model node.
|
|
64
|
-
*
|
|
65
|
-
* This is an abstract class, so this constructor should not be used directly.
|
|
66
|
-
*
|
|
67
|
-
* @param attrs Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
68
|
-
*/
|
|
69
|
-
constructor(attrs) {
|
|
70
|
-
super();
|
|
71
|
-
this._attrs = toMap(attrs);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* {@link module:engine/model/document~ModelDocument Document} that owns this root element.
|
|
75
|
-
*/
|
|
76
|
-
get document() {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Index of this node in its parent or `null` if the node has no parent.
|
|
81
|
-
*/
|
|
82
|
-
get index() {
|
|
83
|
-
return this._index;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Offset at which this node starts in its parent. It is equal to the sum of {@link #offsetSize offsetSize}
|
|
87
|
-
* of all its previous siblings. Equals to `null` if node has no parent.
|
|
88
|
-
*/
|
|
89
|
-
get startOffset() {
|
|
90
|
-
return this._startOffset;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Offset size of this node.
|
|
94
|
-
*
|
|
95
|
-
* Represents how much "offset space" is occupied by the node in its parent. It is important for
|
|
96
|
-
* {@link module:engine/model/position~ModelPosition position}. When node has `offsetSize` greater
|
|
97
|
-
* than `1`, position can be placed between that node start and end. `offsetSize` greater than `1` is for
|
|
98
|
-
* nodes that represents more than one entity, i.e. a {@link module:engine/model/text~ModelText text node}.
|
|
99
|
-
*/
|
|
100
|
-
get offsetSize() {
|
|
101
|
-
return 1;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Offset at which this node ends in its parent. It is equal to the sum of this node's
|
|
105
|
-
* {@link module:engine/model/node~ModelNode#startOffset start offset} and {@link #offsetSize offset size}.
|
|
106
|
-
* Equals to `null` if the node has no parent.
|
|
107
|
-
*/
|
|
108
|
-
get endOffset() {
|
|
109
|
-
if (this.startOffset === null) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return this.startOffset + this.offsetSize;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Node's next sibling or `null` if the node is a last child of it's parent or if the node has no parent.
|
|
116
|
-
*/
|
|
117
|
-
get nextSibling() {
|
|
118
|
-
const index = this.index;
|
|
119
|
-
return (index !== null && this.parent.getChild(index + 1)) || null;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Node's previous sibling or `null` if the node is a first child of it's parent or if the node has no parent.
|
|
123
|
-
*/
|
|
124
|
-
get previousSibling() {
|
|
125
|
-
const index = this.index;
|
|
126
|
-
return (index !== null && this.parent.getChild(index - 1)) || null;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* The top-most ancestor of the node. If node has no parent it is the root itself. If the node is a part
|
|
130
|
-
* of {@link module:engine/model/documentfragment~ModelDocumentFragment}, it's `root` is equal to that `DocumentFragment`.
|
|
131
|
-
*/
|
|
132
|
-
get root() {
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
134
|
-
let root = this;
|
|
135
|
-
while (root.parent) {
|
|
136
|
-
root = root.parent;
|
|
137
|
-
}
|
|
138
|
-
return root;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Returns `true` if the node is inside a document root that is attached to the document.
|
|
142
|
-
*/
|
|
143
|
-
isAttached() {
|
|
144
|
-
// If the node has no parent it means that it is a root.
|
|
145
|
-
// But this is not a `RootElement`, so it means that it is not attached.
|
|
146
|
-
//
|
|
147
|
-
// If this is not the root, check if this element's root is attached.
|
|
148
|
-
return this.parent === null ? false : this.root.isAttached();
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Gets path to the node. The path is an array containing starting offsets of consecutive ancestors of this node,
|
|
152
|
-
* beginning from {@link module:engine/model/node~ModelNode#root root}, down to this node's starting offset. The path can be used to
|
|
153
|
-
* create {@link module:engine/model/position~ModelPosition Position} instance.
|
|
154
|
-
*
|
|
155
|
-
* ```ts
|
|
156
|
-
* const abc = new Text( 'abc' );
|
|
157
|
-
* const foo = new Text( 'foo' );
|
|
158
|
-
* const h1 = new ModelElement( 'h1', null, new Text( 'header' ) );
|
|
159
|
-
* const p = new ModelElement( 'p', null, [ abc, foo ] );
|
|
160
|
-
* const div = new ModelElement( 'div', null, [ h1, p ] );
|
|
161
|
-
* foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
|
|
162
|
-
* h1.getPath(); // Returns [ 0 ].
|
|
163
|
-
* div.getPath(); // Returns [].
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
getPath() {
|
|
167
|
-
const path = [];
|
|
168
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
169
|
-
let node = this;
|
|
170
|
-
while (node.parent) {
|
|
171
|
-
path.unshift(node.startOffset);
|
|
172
|
-
node = node.parent;
|
|
173
|
-
}
|
|
174
|
-
return path;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Returns ancestors array of this node.
|
|
178
|
-
*
|
|
179
|
-
* @param options Options object.
|
|
180
|
-
* @param options.includeSelf When set to `true` this node will be also included in parent's array.
|
|
181
|
-
* @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
|
|
182
|
-
* otherwise root element will be the first item in the array.
|
|
183
|
-
* @returns Array with ancestors.
|
|
184
|
-
*/
|
|
185
|
-
getAncestors(options = {}) {
|
|
186
|
-
const ancestors = [];
|
|
187
|
-
let parent = options.includeSelf ? this : this.parent;
|
|
188
|
-
while (parent) {
|
|
189
|
-
ancestors[options.parentFirst ? 'push' : 'unshift'](parent);
|
|
190
|
-
parent = parent.parent;
|
|
191
|
-
}
|
|
192
|
-
return ancestors;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Returns a {@link module:engine/model/element~ModelElement} or {@link module:engine/model/documentfragment~ModelDocumentFragment}
|
|
196
|
-
* which is a common ancestor of both nodes.
|
|
197
|
-
*
|
|
198
|
-
* @param node The second node.
|
|
199
|
-
* @param options Options object.
|
|
200
|
-
* @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
|
|
201
|
-
* Which means that if e.g. node A is inside B, then their common ancestor will be B.
|
|
202
|
-
*/
|
|
203
|
-
getCommonAncestor(node, options = {}) {
|
|
204
|
-
const ancestorsA = this.getAncestors(options);
|
|
205
|
-
const ancestorsB = node.getAncestors(options);
|
|
206
|
-
let i = 0;
|
|
207
|
-
while (ancestorsA[i] == ancestorsB[i] && ancestorsA[i]) {
|
|
208
|
-
i++;
|
|
209
|
-
}
|
|
210
|
-
return i === 0 ? null : ancestorsA[i - 1];
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
|
|
214
|
-
* in different {@link module:engine/model/documentfragment~ModelDocumentFragment}s).
|
|
215
|
-
*
|
|
216
|
-
* @param node Node to compare with.
|
|
217
|
-
*/
|
|
218
|
-
isBefore(node) {
|
|
219
|
-
// Given node is not before this node if they are same.
|
|
220
|
-
if (this == node) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
// Return `false` if it is impossible to compare nodes.
|
|
224
|
-
if (this.root !== node.root) {
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
const thisPath = this.getPath();
|
|
228
|
-
const nodePath = node.getPath();
|
|
229
|
-
const result = compareArrays(thisPath, nodePath);
|
|
230
|
-
switch (result) {
|
|
231
|
-
case 'prefix':
|
|
232
|
-
return true;
|
|
233
|
-
case 'extension':
|
|
234
|
-
return false;
|
|
235
|
-
default:
|
|
236
|
-
return thisPath[result] < nodePath[result];
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
|
|
241
|
-
* in different {@link module:engine/model/documentfragment~ModelDocumentFragment}s).
|
|
242
|
-
*
|
|
243
|
-
* @param node Node to compare with.
|
|
244
|
-
*/
|
|
245
|
-
isAfter(node) {
|
|
246
|
-
// Given node is not before this node if they are same.
|
|
247
|
-
if (this == node) {
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
// Return `false` if it is impossible to compare nodes.
|
|
251
|
-
if (this.root !== node.root) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
// In other cases, just check if the `node` is before, and return the opposite.
|
|
255
|
-
return !this.isBefore(node);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Checks if the node has an attribute with given key.
|
|
259
|
-
*
|
|
260
|
-
* @param key Key of attribute to check.
|
|
261
|
-
* @returns `true` if attribute with given key is set on node, `false` otherwise.
|
|
262
|
-
*/
|
|
263
|
-
hasAttribute(key) {
|
|
264
|
-
return this._attrs.has(key);
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Gets an attribute value for given key or `undefined` if that attribute is not set on node.
|
|
268
|
-
*
|
|
269
|
-
* @param key Key of attribute to look for.
|
|
270
|
-
* @returns Attribute value or `undefined`.
|
|
271
|
-
*/
|
|
272
|
-
getAttribute(key) {
|
|
273
|
-
return this._attrs.get(key);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Returns iterator that iterates over this node's attributes.
|
|
277
|
-
*
|
|
278
|
-
* Attributes are returned as arrays containing two items. First one is attribute key and second is attribute value.
|
|
279
|
-
* This format is accepted by native `Map` object and also can be passed in `Node` constructor.
|
|
280
|
-
*/
|
|
281
|
-
getAttributes() {
|
|
282
|
-
return this._attrs.entries();
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Returns iterator that iterates over this node's attribute keys.
|
|
286
|
-
*/
|
|
287
|
-
getAttributeKeys() {
|
|
288
|
-
return this._attrs.keys();
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Converts `Node` to plain object and returns it.
|
|
292
|
-
*
|
|
293
|
-
* @returns `Node` converted to plain object.
|
|
294
|
-
*/
|
|
295
|
-
toJSON() {
|
|
296
|
-
const json = {};
|
|
297
|
-
// Serializes attributes to the object.
|
|
298
|
-
// attributes = { a: 'foo', b: 1, c: true }.
|
|
299
|
-
if (this._attrs.size) {
|
|
300
|
-
json.attributes = Array.from(this._attrs).reduce((result, attr) => {
|
|
301
|
-
result[attr[0]] = attr[1];
|
|
302
|
-
return result;
|
|
303
|
-
}, {});
|
|
304
|
-
}
|
|
305
|
-
return json;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Creates a copy of this node, that is a node with exactly same attributes, and returns it.
|
|
309
|
-
*
|
|
310
|
-
* @internal
|
|
311
|
-
* @returns Node with same attributes as this node.
|
|
312
|
-
*/
|
|
313
|
-
_clone(_deep) {
|
|
314
|
-
return new this.constructor(this._attrs);
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Removes this node from its parent.
|
|
318
|
-
*
|
|
319
|
-
* @internal
|
|
320
|
-
* @see module:engine/model/writer~ModelWriter#remove
|
|
321
|
-
*/
|
|
322
|
-
_remove() {
|
|
323
|
-
this.parent._removeChildren(this.index);
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Sets attribute on the node. If attribute with the same key already is set, it's value is overwritten.
|
|
327
|
-
*
|
|
328
|
-
* @see module:engine/model/writer~ModelWriter#setAttribute
|
|
329
|
-
* @internal
|
|
330
|
-
* @param key Key of attribute to set.
|
|
331
|
-
* @param value Attribute value.
|
|
332
|
-
*/
|
|
333
|
-
_setAttribute(key, value) {
|
|
334
|
-
this._attrs.set(key, value);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Removes all attributes from the node and sets given attributes.
|
|
338
|
-
*
|
|
339
|
-
* @see module:engine/model/writer~ModelWriter#setAttributes
|
|
340
|
-
* @internal
|
|
341
|
-
* @param attrs Attributes to set. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
342
|
-
*/
|
|
343
|
-
_setAttributesTo(attrs) {
|
|
344
|
-
this._attrs = toMap(attrs);
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Removes an attribute with given key from the node.
|
|
348
|
-
*
|
|
349
|
-
* @see module:engine/model/writer~ModelWriter#removeAttribute
|
|
350
|
-
* @internal
|
|
351
|
-
* @param key Key of attribute to remove.
|
|
352
|
-
* @returns `true` if the attribute was set on the element, `false` otherwise.
|
|
353
|
-
*/
|
|
354
|
-
_removeAttribute(key) {
|
|
355
|
-
return this._attrs.delete(key);
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Removes all attributes from the node.
|
|
359
|
-
*
|
|
360
|
-
* @see module:engine/model/writer~ModelWriter#clearAttributes
|
|
361
|
-
* @internal
|
|
362
|
-
*/
|
|
363
|
-
_clearAttributes() {
|
|
364
|
-
this._attrs.clear();
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
368
|
-
// Proper overload would interfere with that.
|
|
369
|
-
ModelNode.prototype.is = function (type) {
|
|
370
|
-
return type === 'node' || type === 'model:node';
|
|
371
|
-
};
|
package/src/model/nodelist.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module engine/model/nodelist
|
|
7
|
-
*/
|
|
8
|
-
import { ModelNode } from './node.js';
|
|
9
|
-
import { CKEditorError, spliceArray } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
/**
|
|
11
|
-
* Provides an interface to operate on a list of {@link module:engine/model/node~ModelNode nodes}. `NodeList` is used internally
|
|
12
|
-
* in classes like {@link module:engine/model/element~ModelElement Element}
|
|
13
|
-
* or {@link module:engine/model/documentfragment~ModelDocumentFragment ModelDocumentFragment}.
|
|
14
|
-
*/
|
|
15
|
-
export class ModelNodeList {
|
|
16
|
-
/**
|
|
17
|
-
* Nodes contained in this node list.
|
|
18
|
-
*/
|
|
19
|
-
_nodes = [];
|
|
20
|
-
/**
|
|
21
|
-
* This array maps numbers (offsets) to node that is placed at that offset.
|
|
22
|
-
*
|
|
23
|
-
* This array is similar to `_nodes` with the difference that one node may occupy multiple consecutive items in the array.
|
|
24
|
-
*
|
|
25
|
-
* This array is needed to quickly retrieve a node that is placed at given offset.
|
|
26
|
-
*/
|
|
27
|
-
_offsetToNode = [];
|
|
28
|
-
/**
|
|
29
|
-
* Creates a node list.
|
|
30
|
-
*
|
|
31
|
-
* @internal
|
|
32
|
-
* @param nodes Nodes contained in this node list.
|
|
33
|
-
*/
|
|
34
|
-
constructor(nodes) {
|
|
35
|
-
if (nodes) {
|
|
36
|
-
this._insertNodes(0, nodes);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Iterable interface.
|
|
41
|
-
*
|
|
42
|
-
* Iterates over all nodes contained inside this node list.
|
|
43
|
-
*/
|
|
44
|
-
[Symbol.iterator]() {
|
|
45
|
-
return this._nodes[Symbol.iterator]();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Number of nodes contained inside this node list.
|
|
49
|
-
*/
|
|
50
|
-
get length() {
|
|
51
|
-
return this._nodes.length;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Sum of {@link module:engine/model/node~ModelNode#offsetSize offset sizes} of all nodes contained inside this node list.
|
|
55
|
-
*/
|
|
56
|
-
get maxOffset() {
|
|
57
|
-
return this._offsetToNode.length;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Gets the node at the given index. Returns `null` if incorrect index was passed.
|
|
61
|
-
*/
|
|
62
|
-
getNode(index) {
|
|
63
|
-
return this._nodes[index] || null;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Gets the node at the given offset. Returns `null` if incorrect offset was passed.
|
|
67
|
-
*/
|
|
68
|
-
getNodeAtOffset(offset) {
|
|
69
|
-
return this._offsetToNode[offset] || null;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns an index of the given node or `null` if given node does not have a parent.
|
|
73
|
-
*
|
|
74
|
-
* This is an alias to {@link module:engine/model/node~ModelNode#index}.
|
|
75
|
-
*/
|
|
76
|
-
getNodeIndex(node) {
|
|
77
|
-
return node.index;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Returns the offset at which given node is placed in its parent or `null` if given node does not have a parent.
|
|
81
|
-
*
|
|
82
|
-
* This is an alias to {@link module:engine/model/node~ModelNode#startOffset}.
|
|
83
|
-
*/
|
|
84
|
-
getNodeStartOffset(node) {
|
|
85
|
-
return node.startOffset;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Converts index to offset in node list.
|
|
89
|
-
*
|
|
90
|
-
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-index-out-of-bounds` if given index is less
|
|
91
|
-
* than `0` or more than {@link #length}.
|
|
92
|
-
*/
|
|
93
|
-
indexToOffset(index) {
|
|
94
|
-
if (index == this._nodes.length) {
|
|
95
|
-
return this.maxOffset;
|
|
96
|
-
}
|
|
97
|
-
const node = this._nodes[index];
|
|
98
|
-
if (!node) {
|
|
99
|
-
/**
|
|
100
|
-
* Given index cannot be found in the node list.
|
|
101
|
-
*
|
|
102
|
-
* @error model-nodelist-index-out-of-bounds
|
|
103
|
-
*/
|
|
104
|
-
throw new CKEditorError('model-nodelist-index-out-of-bounds', this);
|
|
105
|
-
}
|
|
106
|
-
return this.getNodeStartOffset(node);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Converts offset in node list to index.
|
|
110
|
-
*
|
|
111
|
-
* Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `model-nodelist-offset-out-of-bounds` if given offset is less
|
|
112
|
-
* than `0` or more than {@link #maxOffset}.
|
|
113
|
-
*/
|
|
114
|
-
offsetToIndex(offset) {
|
|
115
|
-
if (offset == this._offsetToNode.length) {
|
|
116
|
-
return this._nodes.length;
|
|
117
|
-
}
|
|
118
|
-
const node = this._offsetToNode[offset];
|
|
119
|
-
if (!node) {
|
|
120
|
-
/**
|
|
121
|
-
* Given offset cannot be found in the node list.
|
|
122
|
-
*
|
|
123
|
-
* @error model-nodelist-offset-out-of-bounds
|
|
124
|
-
* @param {number} offset The offset value.
|
|
125
|
-
* @param {module:engine/model/nodelist~ModelNodeList} nodeList Stringified node list.
|
|
126
|
-
*/
|
|
127
|
-
throw new CKEditorError('model-nodelist-offset-out-of-bounds', this, {
|
|
128
|
-
offset,
|
|
129
|
-
nodeList: this
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return this.getNodeIndex(node);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Inserts given nodes at given index.
|
|
136
|
-
*
|
|
137
|
-
* @internal
|
|
138
|
-
* @param index Index at which nodes should be inserted.
|
|
139
|
-
* @param nodes Nodes to be inserted.
|
|
140
|
-
*/
|
|
141
|
-
_insertNodes(index, nodes) {
|
|
142
|
-
const nodesArray = [];
|
|
143
|
-
// Validation.
|
|
144
|
-
for (const node of nodes) {
|
|
145
|
-
if (!(node instanceof ModelNode)) {
|
|
146
|
-
/**
|
|
147
|
-
* Trying to insert an object which is not a Node instance.
|
|
148
|
-
*
|
|
149
|
-
* @error model-nodelist-insertnodes-not-node
|
|
150
|
-
*/
|
|
151
|
-
throw new CKEditorError('model-nodelist-insertnodes-not-node', this);
|
|
152
|
-
}
|
|
153
|
-
nodesArray.push(node);
|
|
154
|
-
}
|
|
155
|
-
let offset = this.indexToOffset(index);
|
|
156
|
-
// Splice nodes array and offsets array into the nodelist.
|
|
157
|
-
spliceArray(this._nodes, nodesArray, index);
|
|
158
|
-
spliceArray(this._offsetToNode, makeOffsetsArray(nodesArray), offset);
|
|
159
|
-
// Refresh indexes and offsets for nodes inside this node list. We need to do this for all inserted nodes and all nodes after them.
|
|
160
|
-
for (let i = index; i < this._nodes.length; i++) {
|
|
161
|
-
this._nodes[i]._index = i;
|
|
162
|
-
this._nodes[i]._startOffset = offset;
|
|
163
|
-
offset += this._nodes[i].offsetSize;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Removes one or more nodes starting at the given index.
|
|
168
|
-
*
|
|
169
|
-
* @internal
|
|
170
|
-
* @param indexStart Index of the first node to remove.
|
|
171
|
-
* @param howMany Number of nodes to remove.
|
|
172
|
-
* @returns Array containing removed nodes.
|
|
173
|
-
*/
|
|
174
|
-
_removeNodes(indexStart, howMany = 1) {
|
|
175
|
-
if (howMany == 0) {
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
// Remove nodes from this nodelist.
|
|
179
|
-
let offset = this.indexToOffset(indexStart);
|
|
180
|
-
const nodes = this._nodes.splice(indexStart, howMany);
|
|
181
|
-
const lastNode = nodes[nodes.length - 1];
|
|
182
|
-
const removedOffsetSum = lastNode.startOffset + lastNode.offsetSize - offset;
|
|
183
|
-
this._offsetToNode.splice(offset, removedOffsetSum);
|
|
184
|
-
// Reset index and start offset properties for the removed nodes -- they do not have a parent anymore.
|
|
185
|
-
for (const node of nodes) {
|
|
186
|
-
node._index = null;
|
|
187
|
-
node._startOffset = null;
|
|
188
|
-
}
|
|
189
|
-
for (let i = indexStart; i < this._nodes.length; i++) {
|
|
190
|
-
this._nodes[i]._index = i;
|
|
191
|
-
this._nodes[i]._startOffset = offset;
|
|
192
|
-
offset += this._nodes[i].offsetSize;
|
|
193
|
-
}
|
|
194
|
-
return nodes;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Removes children nodes provided as an array. These nodes do not need to be direct siblings.
|
|
198
|
-
*
|
|
199
|
-
* This method is faster than removing nodes one by one, as it recalculates offsets only once.
|
|
200
|
-
*
|
|
201
|
-
* @internal
|
|
202
|
-
* @param nodes Array of nodes.
|
|
203
|
-
*/
|
|
204
|
-
_removeNodesArray(nodes) {
|
|
205
|
-
if (nodes.length == 0) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
for (const node of nodes) {
|
|
209
|
-
node._index = null;
|
|
210
|
-
node._startOffset = null;
|
|
211
|
-
}
|
|
212
|
-
this._nodes = this._nodes.filter(node => node.index !== null);
|
|
213
|
-
this._offsetToNode = this._offsetToNode.filter(node => node.index !== null);
|
|
214
|
-
let offset = 0;
|
|
215
|
-
for (let i = 0; i < this._nodes.length; i++) {
|
|
216
|
-
this._nodes[i]._index = i;
|
|
217
|
-
this._nodes[i]._startOffset = offset;
|
|
218
|
-
offset += this._nodes[i].offsetSize;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Converts `NodeList` instance to an array containing nodes that were inserted in the node list. Nodes
|
|
223
|
-
* are also converted to their plain object representation.
|
|
224
|
-
*
|
|
225
|
-
* @returns `NodeList` instance converted to `Array`.
|
|
226
|
-
*/
|
|
227
|
-
toJSON() {
|
|
228
|
-
return this._nodes.map(node => node.toJSON());
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Creates an array of nodes in the format as in {@link module:engine/model/nodelist~ModelNodeList#_offsetToNode}, i.e. one node will
|
|
233
|
-
* occupy multiple items if its offset size is greater than one.
|
|
234
|
-
*/
|
|
235
|
-
function makeOffsetsArray(nodes) {
|
|
236
|
-
const offsets = [];
|
|
237
|
-
let index = 0;
|
|
238
|
-
for (const node of nodes) {
|
|
239
|
-
for (let i = 0; i < node.offsetSize; i++) {
|
|
240
|
-
offsets[index++] = node;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return offsets;
|
|
244
|
-
}
|