@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/element.js
DELETED
|
@@ -1,323 +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/element
|
|
7
|
-
*/
|
|
8
|
-
import { ModelNode } from './node.js';
|
|
9
|
-
import { ModelNodeList } from './nodelist.js';
|
|
10
|
-
import { ModelText } from './text.js';
|
|
11
|
-
import { ModelTextProxy } from './textproxy.js';
|
|
12
|
-
import { isIterable } from '@ckeditor/ckeditor5-utils';
|
|
13
|
-
// @if CK_DEBUG_ENGINE // const { stringifyMap, convertMapToStringifiedObject, convertMapToTags } = require( '../dev-utils/utils' );
|
|
14
|
-
/**
|
|
15
|
-
* Model element. Type of {@link module:engine/model/node~ModelNode node} that has a
|
|
16
|
-
* {@link module:engine/model/element~ModelElement#name name} and {@link module:engine/model/element~ModelElement#getChildren child nodes}.
|
|
17
|
-
*
|
|
18
|
-
* **Important**: see {@link module:engine/model/node~ModelNode} to read about restrictions using `Element` and `Node` API.
|
|
19
|
-
*/
|
|
20
|
-
export class ModelElement extends ModelNode {
|
|
21
|
-
/**
|
|
22
|
-
* Element name.
|
|
23
|
-
*/
|
|
24
|
-
name;
|
|
25
|
-
/**
|
|
26
|
-
* List of children nodes.
|
|
27
|
-
*/
|
|
28
|
-
_children = new ModelNodeList();
|
|
29
|
-
/**
|
|
30
|
-
* Creates a model element.
|
|
31
|
-
*
|
|
32
|
-
* **Note:** Constructor of this class shouldn't be used directly in the code.
|
|
33
|
-
* Use the {@link module:engine/model/writer~ModelWriter#createElement} method instead.
|
|
34
|
-
*
|
|
35
|
-
* @internal
|
|
36
|
-
* @param name Element's name.
|
|
37
|
-
* @param attrs Element's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
|
|
38
|
-
* @param children One or more nodes to be inserted as children of created element.
|
|
39
|
-
*/
|
|
40
|
-
constructor(name, attrs, children) {
|
|
41
|
-
super(attrs);
|
|
42
|
-
this.name = name;
|
|
43
|
-
if (children) {
|
|
44
|
-
this._insertChild(0, children);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Number of this element's children.
|
|
49
|
-
*/
|
|
50
|
-
get childCount() {
|
|
51
|
-
return this._children.length;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Sum of {@link module:engine/model/node~ModelNode#offsetSize offset sizes} of all of this element's children.
|
|
55
|
-
*/
|
|
56
|
-
get maxOffset() {
|
|
57
|
-
return this._children.maxOffset;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Is `true` if there are no nodes inside this element, `false` otherwise.
|
|
61
|
-
*/
|
|
62
|
-
get isEmpty() {
|
|
63
|
-
return this.childCount === 0;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Gets the child at the given index. Returns `null` if incorrect index was passed.
|
|
67
|
-
*
|
|
68
|
-
* @param index Index in this element.
|
|
69
|
-
* @returns Child node.
|
|
70
|
-
*/
|
|
71
|
-
getChild(index) {
|
|
72
|
-
return this._children.getNode(index);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Gets the child at the given offset. Returns `null` if incorrect index was passed.
|
|
76
|
-
*
|
|
77
|
-
* @param offset Offset in this element.
|
|
78
|
-
* @returns Child node.
|
|
79
|
-
*/
|
|
80
|
-
getChildAtOffset(offset) {
|
|
81
|
-
return this._children.getNodeAtOffset(offset);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns an iterator that iterates over all of this element's children.
|
|
85
|
-
*/
|
|
86
|
-
getChildren() {
|
|
87
|
-
return this._children[Symbol.iterator]();
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns an index of the given child node. Returns `null` if given node is not a child of this element.
|
|
91
|
-
*
|
|
92
|
-
* @param node Child node to look for.
|
|
93
|
-
* @returns Child node's index in this element.
|
|
94
|
-
*/
|
|
95
|
-
getChildIndex(node) {
|
|
96
|
-
return this._children.getNodeIndex(node);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Returns the starting offset of given child. Starting offset is equal to the sum of
|
|
100
|
-
* {@link module:engine/model/node~ModelNode#offsetSize offset sizes} of all node's siblings that are before it. Returns `null` if
|
|
101
|
-
* given node is not a child of this element.
|
|
102
|
-
*
|
|
103
|
-
* @param node Child node to look for.
|
|
104
|
-
* @returns Child node's starting offset.
|
|
105
|
-
*/
|
|
106
|
-
getChildStartOffset(node) {
|
|
107
|
-
return this._children.getNodeStartOffset(node);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Returns index of a node that occupies given offset. If given offset is too low, returns `0`. If given offset is
|
|
111
|
-
* too high, returns {@link module:engine/model/element~ModelElement#getChildIndex index after last child}.
|
|
112
|
-
*
|
|
113
|
-
* ```ts
|
|
114
|
-
* const textNode = new Text( 'foo' );
|
|
115
|
-
* const pElement = new Element( 'p' );
|
|
116
|
-
* const divElement = new Element( [ textNode, pElement ] );
|
|
117
|
-
* divElement.offsetToIndex( -1 ); // Returns 0, because offset is too low.
|
|
118
|
-
* divElement.offsetToIndex( 0 ); // Returns 0, because offset 0 is taken by `textNode` which is at index 0.
|
|
119
|
-
* divElement.offsetToIndex( 1 ); // Returns 0, because `textNode` has `offsetSize` equal to 3, so it occupies offset 1 too.
|
|
120
|
-
* divElement.offsetToIndex( 2 ); // Returns 0.
|
|
121
|
-
* divElement.offsetToIndex( 3 ); // Returns 1.
|
|
122
|
-
* divElement.offsetToIndex( 4 ); // Returns 2. There are no nodes at offset 4, so last available index is returned.
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
offsetToIndex(offset) {
|
|
126
|
-
return this._children.offsetToIndex(offset);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Returns a descendant node by its path relative to this element.
|
|
130
|
-
*
|
|
131
|
-
* ```ts
|
|
132
|
-
* // <this>a<b>c</b></this>
|
|
133
|
-
* this.getNodeByPath( [ 0 ] ); // -> "a"
|
|
134
|
-
* this.getNodeByPath( [ 1 ] ); // -> <b>
|
|
135
|
-
* this.getNodeByPath( [ 1, 0 ] ); // -> "c"
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @param relativePath Path of the node to find, relative to this element.
|
|
139
|
-
*/
|
|
140
|
-
getNodeByPath(relativePath) {
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
|
|
142
|
-
let node = this;
|
|
143
|
-
for (const offset of relativePath) {
|
|
144
|
-
node = node.getChildAtOffset(offset);
|
|
145
|
-
}
|
|
146
|
-
return node;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Returns the parent element of the given name. Returns null if the element is not inside the desired parent.
|
|
150
|
-
*
|
|
151
|
-
* @param parentName The name of the parent element to find.
|
|
152
|
-
* @param options Options object.
|
|
153
|
-
* @param options.includeSelf When set to `true` this node will be also included while searching.
|
|
154
|
-
*/
|
|
155
|
-
findAncestor(parentName, options = {}) {
|
|
156
|
-
let parent = options.includeSelf ? this : this.parent;
|
|
157
|
-
while (parent) {
|
|
158
|
-
if (parent.name === parentName) {
|
|
159
|
-
return parent;
|
|
160
|
-
}
|
|
161
|
-
parent = parent.parent;
|
|
162
|
-
}
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Converts `Element` instance to plain object and returns it. Takes care of converting all of this element's children.
|
|
167
|
-
*
|
|
168
|
-
* @returns `Element` instance converted to plain object.
|
|
169
|
-
*/
|
|
170
|
-
toJSON() {
|
|
171
|
-
const json = super.toJSON();
|
|
172
|
-
json.name = this.name;
|
|
173
|
-
if (this._children.length > 0) {
|
|
174
|
-
json.children = [];
|
|
175
|
-
for (const node of this._children) {
|
|
176
|
-
json.children.push(node.toJSON());
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return json;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
|
|
183
|
-
* If clone is deep, the original element's children are also cloned. If not, then empty element is returned.
|
|
184
|
-
*
|
|
185
|
-
* @internal
|
|
186
|
-
* @param deep If set to `true` clones element and all its children recursively. When set to `false`,
|
|
187
|
-
* element will be cloned without any child.
|
|
188
|
-
*/
|
|
189
|
-
_clone(deep = false) {
|
|
190
|
-
const children = deep ? cloneNodes(this._children) : undefined;
|
|
191
|
-
return new ModelElement(this.name, this.getAttributes(), children);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* {@link module:engine/model/element~ModelElement#_insertChild Inserts} one or more nodes at the end of this element.
|
|
195
|
-
*
|
|
196
|
-
* @see module:engine/model/writer~ModelWriter#append
|
|
197
|
-
* @internal
|
|
198
|
-
* @param nodes Nodes to be inserted.
|
|
199
|
-
*/
|
|
200
|
-
_appendChild(nodes) {
|
|
201
|
-
this._insertChild(this.childCount, nodes);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Inserts one or more nodes at the given index and sets {@link module:engine/model/node~ModelNode#parent parent} of these nodes
|
|
205
|
-
* to this element.
|
|
206
|
-
*
|
|
207
|
-
* @see module:engine/model/writer~ModelWriter#insert
|
|
208
|
-
* @internal
|
|
209
|
-
* @param index Index at which nodes should be inserted.
|
|
210
|
-
* @param items Items to be inserted.
|
|
211
|
-
*/
|
|
212
|
-
_insertChild(index, items) {
|
|
213
|
-
const nodes = normalize(items);
|
|
214
|
-
for (const node of nodes) {
|
|
215
|
-
// If node that is being added to this element is already inside another element, first remove it from the old parent.
|
|
216
|
-
if (node.parent !== null) {
|
|
217
|
-
node._remove();
|
|
218
|
-
}
|
|
219
|
-
node.parent = this;
|
|
220
|
-
}
|
|
221
|
-
this._children._insertNodes(index, nodes);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Removes one or more nodes starting at the given index and sets
|
|
225
|
-
* {@link module:engine/model/node~ModelNode#parent parent} of these nodes to `null`.
|
|
226
|
-
*
|
|
227
|
-
* @see module:engine/model/writer~ModelWriter#remove
|
|
228
|
-
* @internal
|
|
229
|
-
* @param index Index of the first node to remove.
|
|
230
|
-
* @param howMany Number of nodes to remove.
|
|
231
|
-
* @returns Array containing removed nodes.
|
|
232
|
-
*/
|
|
233
|
-
_removeChildren(index, howMany = 1) {
|
|
234
|
-
const nodes = this._children._removeNodes(index, howMany);
|
|
235
|
-
for (const node of nodes) {
|
|
236
|
-
node.parent = null;
|
|
237
|
-
}
|
|
238
|
-
return nodes;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Removes children nodes provided as an array and sets
|
|
242
|
-
* the {@link module:engine/model/node~ModelNode#parent parent} of these nodes to `null`.
|
|
243
|
-
*
|
|
244
|
-
* These nodes do not need to be direct siblings.
|
|
245
|
-
*
|
|
246
|
-
* This method is faster than removing nodes one by one, as it recalculates offsets only once.
|
|
247
|
-
*
|
|
248
|
-
* @internal
|
|
249
|
-
* @param nodes Array of nodes.
|
|
250
|
-
*/
|
|
251
|
-
_removeChildrenArray(nodes) {
|
|
252
|
-
this._children._removeNodesArray(nodes);
|
|
253
|
-
for (const node of nodes) {
|
|
254
|
-
node.parent = null;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Creates an `Element` instance from given plain object (i.e. parsed JSON string).
|
|
259
|
-
* Converts `Element` children to proper nodes.
|
|
260
|
-
*
|
|
261
|
-
* @param json Plain object to be converted to `Element`.
|
|
262
|
-
* @returns `Element` instance created using given plain object.
|
|
263
|
-
*/
|
|
264
|
-
static fromJSON(json) {
|
|
265
|
-
let children;
|
|
266
|
-
if (json.children) {
|
|
267
|
-
children = [];
|
|
268
|
-
for (const child of json.children) {
|
|
269
|
-
if (child.name) {
|
|
270
|
-
// If child has name property, it is an Element.
|
|
271
|
-
children.push(ModelElement.fromJSON(child));
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
// Otherwise, it is a Text node.
|
|
275
|
-
children.push(ModelText.fromJSON(child));
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return new ModelElement(json.name, json.attributes, children);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
283
|
-
// Proper overload would interfere with that.
|
|
284
|
-
ModelElement.prototype.is = function (type, name) {
|
|
285
|
-
if (!name) {
|
|
286
|
-
return type === 'element' || type === 'model:element' ||
|
|
287
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
288
|
-
type === 'node' || type === 'model:node';
|
|
289
|
-
}
|
|
290
|
-
return name === this.name && (type === 'element' || type === 'model:element');
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* Converts strings to Text and non-iterables to arrays.
|
|
294
|
-
*/
|
|
295
|
-
function normalize(nodes) {
|
|
296
|
-
// Separate condition because string is iterable.
|
|
297
|
-
if (typeof nodes == 'string') {
|
|
298
|
-
return [new ModelText(nodes)];
|
|
299
|
-
}
|
|
300
|
-
if (!isIterable(nodes)) {
|
|
301
|
-
nodes = [nodes];
|
|
302
|
-
}
|
|
303
|
-
const normalizedNodes = [];
|
|
304
|
-
for (const node of nodes) {
|
|
305
|
-
if (typeof node == 'string') {
|
|
306
|
-
normalizedNodes.push(new ModelText(node));
|
|
307
|
-
}
|
|
308
|
-
else if (node instanceof ModelTextProxy) {
|
|
309
|
-
normalizedNodes.push(new ModelText(node.data, node.getAttributes()));
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
normalizedNodes.push(node);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return normalizedNodes;
|
|
316
|
-
}
|
|
317
|
-
function cloneNodes(nodes) {
|
|
318
|
-
const clonedNodes = [];
|
|
319
|
-
for (const node of nodes) {
|
|
320
|
-
clonedNodes.push(node._clone(true));
|
|
321
|
-
}
|
|
322
|
-
return clonedNodes;
|
|
323
|
-
}
|
package/src/model/history.js
DELETED
|
@@ -1,206 +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
|
-
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
6
|
-
/**
|
|
7
|
-
* @module engine/model/history
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* `History` keeps the track of all the operations applied to the {@link module:engine/model/document~ModelDocument document}.
|
|
11
|
-
*/
|
|
12
|
-
export class History {
|
|
13
|
-
/**
|
|
14
|
-
* Operations added to the history.
|
|
15
|
-
*/
|
|
16
|
-
_operations = [];
|
|
17
|
-
/**
|
|
18
|
-
* Holds an information which {@link module:engine/model/operation/operation~Operation operation} undoes which
|
|
19
|
-
* {@link module:engine/model/operation/operation~Operation operation}.
|
|
20
|
-
*
|
|
21
|
-
* Keys of the map are "undoing operations", that is operations that undone some other operations. For each key, the
|
|
22
|
-
* value is an operation that has been undone by the "undoing operation".
|
|
23
|
-
*/
|
|
24
|
-
_undoPairs = new Map();
|
|
25
|
-
/**
|
|
26
|
-
* Holds all undone operations.
|
|
27
|
-
*/
|
|
28
|
-
_undoneOperations = new Set();
|
|
29
|
-
/**
|
|
30
|
-
* A map that allows retrieving the operations fast based on the given base version.
|
|
31
|
-
*/
|
|
32
|
-
_baseVersionToOperationIndex = new Map();
|
|
33
|
-
/**
|
|
34
|
-
* The history version.
|
|
35
|
-
*/
|
|
36
|
-
_version = 0;
|
|
37
|
-
/**
|
|
38
|
-
* The gap pairs kept in the <from,to> format.
|
|
39
|
-
*
|
|
40
|
-
* Anytime the `history.version` is set to a version larger than `history.version + 1`,
|
|
41
|
-
* a new <lastHistoryVersion, newHistoryVersion> entry is added to the map.
|
|
42
|
-
*/
|
|
43
|
-
_gaps = new Map();
|
|
44
|
-
/**
|
|
45
|
-
* The version of the last operation in the history.
|
|
46
|
-
*
|
|
47
|
-
* The history version is incremented automatically when a new operation is added to the history.
|
|
48
|
-
* Setting the version manually should be done only in rare circumstances when a gap is planned
|
|
49
|
-
* between history versions. When doing so, a gap will be created and the history will accept adding
|
|
50
|
-
* an operation with base version equal to the new history version.
|
|
51
|
-
*/
|
|
52
|
-
get version() {
|
|
53
|
-
return this._version;
|
|
54
|
-
}
|
|
55
|
-
set version(version) {
|
|
56
|
-
// Store a gap if there are some operations already in the history and the
|
|
57
|
-
// new version does not increment the latest one.
|
|
58
|
-
if (this._operations.length && version > this._version + 1) {
|
|
59
|
-
this._gaps.set(this._version, version);
|
|
60
|
-
}
|
|
61
|
-
this._version = version;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The last history operation.
|
|
65
|
-
*/
|
|
66
|
-
get lastOperation() {
|
|
67
|
-
return this._operations[this._operations.length - 1];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Adds an operation to the history and increments the history version.
|
|
71
|
-
*
|
|
72
|
-
* The operation's base version should be equal to the history version. Otherwise an error is thrown.
|
|
73
|
-
*/
|
|
74
|
-
addOperation(operation) {
|
|
75
|
-
if (operation.baseVersion !== this.version) {
|
|
76
|
-
/**
|
|
77
|
-
* Only operations with matching versions can be added to the history.
|
|
78
|
-
*
|
|
79
|
-
* @error model-document-history-addoperation-incorrect-version
|
|
80
|
-
* @param {module:engine/model/operation/operation~Operation} operation The current operation.
|
|
81
|
-
* @param {number} historyVersion The current document history version.
|
|
82
|
-
*/
|
|
83
|
-
throw new CKEditorError('model-document-history-addoperation-incorrect-version', this, {
|
|
84
|
-
operation,
|
|
85
|
-
historyVersion: this.version
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
this._operations.push(operation);
|
|
89
|
-
this._version++;
|
|
90
|
-
this._baseVersionToOperationIndex.set(operation.baseVersion, this._operations.length - 1);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Returns operations from the given range of operation base versions that were added to the history.
|
|
94
|
-
*
|
|
95
|
-
* Note that there may be gaps in operations base versions.
|
|
96
|
-
*
|
|
97
|
-
* @param fromBaseVersion Base version from which operations should be returned (inclusive).
|
|
98
|
-
* @param toBaseVersion Base version up to which operations should be returned (exclusive).
|
|
99
|
-
* @returns History operations for the given range, in chronological order.
|
|
100
|
-
*/
|
|
101
|
-
getOperations(fromBaseVersion, toBaseVersion = this.version) {
|
|
102
|
-
// When there is no operation in the history, return an empty array.
|
|
103
|
-
// After that we can be sure that `firstOperation`, `lastOperation` are not nullish.
|
|
104
|
-
if (!this._operations.length) {
|
|
105
|
-
return [];
|
|
106
|
-
}
|
|
107
|
-
const firstOperation = this._operations[0];
|
|
108
|
-
if (fromBaseVersion === undefined) {
|
|
109
|
-
fromBaseVersion = firstOperation.baseVersion;
|
|
110
|
-
}
|
|
111
|
-
// Change exclusive `toBaseVersion` to inclusive, so it will refer to the actual index.
|
|
112
|
-
// Thanks to that mapping from base versions to operation indexes are possible.
|
|
113
|
-
let inclusiveTo = toBaseVersion - 1;
|
|
114
|
-
// Check if "from" or "to" point to a gap between versions.
|
|
115
|
-
// If yes, then change the incorrect position to the proper side of the gap.
|
|
116
|
-
// Thanks to it, it will be possible to get index of the operation.
|
|
117
|
-
for (const [gapFrom, gapTo] of this._gaps) {
|
|
118
|
-
if (fromBaseVersion > gapFrom && fromBaseVersion < gapTo) {
|
|
119
|
-
fromBaseVersion = gapTo;
|
|
120
|
-
}
|
|
121
|
-
if (inclusiveTo > gapFrom && inclusiveTo < gapTo) {
|
|
122
|
-
inclusiveTo = gapFrom - 1;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// If the whole range is outside of the operation versions, then return an empty array.
|
|
126
|
-
if (inclusiveTo < firstOperation.baseVersion || fromBaseVersion > this.lastOperation.baseVersion) {
|
|
127
|
-
return [];
|
|
128
|
-
}
|
|
129
|
-
let fromIndex = this._baseVersionToOperationIndex.get(fromBaseVersion);
|
|
130
|
-
// If the range starts before the first operation, then use the first operation as the range's start.
|
|
131
|
-
if (fromIndex === undefined) {
|
|
132
|
-
fromIndex = 0;
|
|
133
|
-
}
|
|
134
|
-
let toIndex = this._baseVersionToOperationIndex.get(inclusiveTo);
|
|
135
|
-
// If the range ends after the last operation, then use the last operation as the range's end.
|
|
136
|
-
if (toIndex === undefined) {
|
|
137
|
-
toIndex = this._operations.length - 1;
|
|
138
|
-
}
|
|
139
|
-
// Return the part of the history operations based on the calculated start index and end index.
|
|
140
|
-
return this._operations.slice(fromIndex,
|
|
141
|
-
// The `toIndex` should be included in the returned operations, so add `1`.
|
|
142
|
-
toIndex + 1);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Returns operation from the history that bases on given `baseVersion`.
|
|
146
|
-
*
|
|
147
|
-
* @param baseVersion Base version of the operation to get.
|
|
148
|
-
* @returns Operation with given base version or `undefined` if there is no such operation in history.
|
|
149
|
-
*/
|
|
150
|
-
getOperation(baseVersion) {
|
|
151
|
-
const operationIndex = this._baseVersionToOperationIndex.get(baseVersion);
|
|
152
|
-
if (operationIndex === undefined) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
return this._operations[operationIndex];
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Marks in history that one operation is an operation that is undoing the other operation. By marking operation this way,
|
|
159
|
-
* history is keeping more context information about operations, which helps in operational transformation.
|
|
160
|
-
*
|
|
161
|
-
* @param undoneOperation Operation which is undone by `undoingOperation`.
|
|
162
|
-
* @param undoingOperation Operation which undoes `undoneOperation`.
|
|
163
|
-
*/
|
|
164
|
-
setOperationAsUndone(undoneOperation, undoingOperation) {
|
|
165
|
-
this._undoPairs.set(undoingOperation, undoneOperation);
|
|
166
|
-
this._undoneOperations.add(undoneOperation);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Checks whether given `operation` is undoing any other operation.
|
|
170
|
-
*
|
|
171
|
-
* @param operation Operation to check.
|
|
172
|
-
* @returns `true` if given `operation` is undoing any other operation, `false` otherwise.
|
|
173
|
-
*/
|
|
174
|
-
isUndoingOperation(operation) {
|
|
175
|
-
return this._undoPairs.has(operation);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Checks whether given `operation` has been undone by any other operation.
|
|
179
|
-
*
|
|
180
|
-
* @param operation Operation to check.
|
|
181
|
-
* @returns `true` if given `operation` has been undone any other operation, `false` otherwise.
|
|
182
|
-
*/
|
|
183
|
-
isUndoneOperation(operation) {
|
|
184
|
-
return this._undoneOperations.has(operation);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* For given `undoingOperation`, returns the operation which has been undone by it.
|
|
188
|
-
*
|
|
189
|
-
* @returns Operation that has been undone by given `undoingOperation` or `undefined`
|
|
190
|
-
* if given `undoingOperation` is not undoing any other operation.
|
|
191
|
-
*/
|
|
192
|
-
getUndoneOperation(undoingOperation) {
|
|
193
|
-
return this._undoPairs.get(undoingOperation);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Resets the history of operations.
|
|
197
|
-
*/
|
|
198
|
-
reset() {
|
|
199
|
-
this._version = 0;
|
|
200
|
-
this._undoPairs = new Map();
|
|
201
|
-
this._operations = [];
|
|
202
|
-
this._undoneOperations = new Set();
|
|
203
|
-
this._gaps = new Map();
|
|
204
|
-
this._baseVersionToOperationIndex = new Map();
|
|
205
|
-
}
|
|
206
|
-
}
|
package/src/model/item.js
DELETED
|
@@ -1,93 +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/liveposition
|
|
7
|
-
*/
|
|
8
|
-
import { ModelPosition } from './position.js';
|
|
9
|
-
import { CKEditorError, EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
/**
|
|
11
|
-
* `ModelLivePosition` is a type of {@link module:engine/model/position~ModelPosition Position}
|
|
12
|
-
* that updates itself as {@link module:engine/model/document~ModelDocument document}
|
|
13
|
-
* is changed through operations. It may be used as a bookmark.
|
|
14
|
-
*
|
|
15
|
-
* **Note:** Contrary to {@link module:engine/model/position~ModelPosition}, `ModelLivePosition` works only in roots that are
|
|
16
|
-
* {@link module:engine/model/rootelement~ModelRootElement}.
|
|
17
|
-
* If {@link module:engine/model/documentfragment~ModelDocumentFragment} is passed, error will be thrown.
|
|
18
|
-
*
|
|
19
|
-
* **Note:** Be very careful when dealing with `ModelLivePosition`. Each `ModelLivePosition` instance bind events that might
|
|
20
|
-
* have to be unbound.
|
|
21
|
-
* Use {@link module:engine/model/liveposition~ModelLivePosition#detach} whenever you don't need `ModelLivePosition` anymore.
|
|
22
|
-
*/
|
|
23
|
-
export class ModelLivePosition extends /* #__PURE__ */ EmitterMixin(ModelPosition) {
|
|
24
|
-
/**
|
|
25
|
-
* Creates a live position.
|
|
26
|
-
*
|
|
27
|
-
* @see module:engine/model/position~ModelPosition
|
|
28
|
-
*/
|
|
29
|
-
constructor(root, path, stickiness = 'toNone') {
|
|
30
|
-
super(root, path, stickiness);
|
|
31
|
-
if (!this.root.is('rootElement')) {
|
|
32
|
-
/**
|
|
33
|
-
* LivePosition's root has to be an instance of ModelRootElement.
|
|
34
|
-
*
|
|
35
|
-
* @error model-liveposition-root-not-rootelement
|
|
36
|
-
*/
|
|
37
|
-
throw new CKEditorError('model-liveposition-root-not-rootelement', root);
|
|
38
|
-
}
|
|
39
|
-
bindWithDocument.call(this);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Unbinds all events previously bound by `ModelLivePosition`. Use it whenever you don't need `ModelLivePosition` instance
|
|
43
|
-
* anymore (i.e. when leaving scope in which it was declared or before re-assigning variable that was
|
|
44
|
-
* referring to it).
|
|
45
|
-
*/
|
|
46
|
-
detach() {
|
|
47
|
-
this.stopListening();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Creates a {@link module:engine/model/position~ModelPosition position instance}, which is equal to this live position.
|
|
51
|
-
*/
|
|
52
|
-
toPosition() {
|
|
53
|
-
return new ModelPosition(this.root, this.path.slice(), this.stickiness);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Creates a `ModelLivePosition` instance that is equal to position.
|
|
57
|
-
*/
|
|
58
|
-
static fromPosition(position, stickiness) {
|
|
59
|
-
return new this(position.root, position.path.slice(), stickiness ? stickiness : position.stickiness);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
63
|
-
// Proper overload would interfere with that.
|
|
64
|
-
ModelLivePosition.prototype.is = function (type) {
|
|
65
|
-
return type === 'livePosition' || type === 'model:livePosition' ||
|
|
66
|
-
// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
|
|
67
|
-
type == 'position' || type === 'model:position';
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Binds this `ModelLivePosition` to the {@link module:engine/model/document~ModelDocument document} that owns
|
|
71
|
-
* this position's {@link module:engine/model/position~ModelPosition#root root}.
|
|
72
|
-
*/
|
|
73
|
-
function bindWithDocument() {
|
|
74
|
-
this.listenTo(this.root.document.model, 'applyOperation', (event, args) => {
|
|
75
|
-
const operation = args[0];
|
|
76
|
-
if (!operation.isDocumentOperation) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
transform.call(this, operation);
|
|
80
|
-
}, { priority: 'low' });
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Updates this position accordingly to the updates applied to the model. Bases on change events.
|
|
84
|
-
*/
|
|
85
|
-
function transform(operation) {
|
|
86
|
-
const result = this.getTransformedByOperation(operation);
|
|
87
|
-
if (!this.isEqual(result)) {
|
|
88
|
-
const oldPosition = this.toPosition();
|
|
89
|
-
this.path = result.path;
|
|
90
|
-
this.root = result.root;
|
|
91
|
-
this.fire('change', oldPosition);
|
|
92
|
-
}
|
|
93
|
-
}
|