@ckeditor/ckeditor5-engine 45.2.1 → 46.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/dist/index.js +2563 -2257
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/controller/datacontroller.d.ts +33 -32
- package/src/controller/datacontroller.js +29 -28
- package/src/controller/editingcontroller.d.ts +8 -8
- package/src/controller/editingcontroller.js +10 -10
- package/src/conversion/conversion.d.ts +18 -19
- package/src/conversion/conversion.js +4 -4
- package/src/conversion/conversionhelpers.d.ts +1 -1
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.d.ts +63 -69
- package/src/conversion/downcastdispatcher.js +16 -16
- package/src/conversion/downcasthelpers.d.ts +94 -83
- package/src/conversion/downcasthelpers.js +63 -53
- package/src/conversion/mapper.d.ts +27 -27
- package/src/conversion/mapper.js +15 -15
- package/src/conversion/modelconsumable.d.ts +26 -26
- package/src/conversion/modelconsumable.js +23 -23
- package/src/conversion/upcastdispatcher.d.ts +33 -32
- package/src/conversion/upcastdispatcher.js +19 -19
- package/src/conversion/upcasthelpers.d.ts +46 -38
- package/src/conversion/upcasthelpers.js +33 -24
- package/src/conversion/viewconsumable.d.ts +50 -45
- package/src/conversion/viewconsumable.js +32 -27
- package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
- package/src/dataprocessor/basichtmlwriter.js +3 -1
- package/src/dataprocessor/dataprocessor.d.ts +7 -6
- package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/htmldataprocessor.js +6 -6
- package/src/dataprocessor/htmlwriter.d.ts +1 -1
- package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
- package/src/dataprocessor/xmldataprocessor.js +6 -6
- package/src/dev-utils/model.d.ts +25 -26
- package/src/dev-utils/model.js +35 -36
- package/src/dev-utils/operationreplayer.d.ts +5 -3
- package/src/dev-utils/operationreplayer.js +4 -2
- package/src/dev-utils/utils.d.ts +8 -0
- package/src/dev-utils/utils.js +8 -0
- package/src/dev-utils/view.d.ts +66 -63
- package/src/dev-utils/view.js +144 -134
- package/src/index.d.ts +135 -106
- package/src/index.js +120 -71
- package/src/legacyerrors.d.ts +5 -0
- package/src/legacyerrors.js +17 -0
- package/src/model/batch.d.ts +2 -15
- package/src/model/batch.js +1 -23
- package/src/model/differ.d.ts +54 -31
- package/src/model/differ.js +15 -15
- package/src/model/document.d.ts +31 -31
- package/src/model/document.js +13 -13
- package/src/model/documentfragment.d.ts +45 -45
- package/src/model/documentfragment.js +40 -40
- package/src/model/documentselection.d.ts +92 -92
- package/src/model/documentselection.js +71 -70
- package/src/model/element.d.ts +31 -31
- package/src/model/element.js +29 -29
- package/src/model/history.d.ts +3 -3
- package/src/model/history.js +2 -2
- package/src/model/item.d.ts +4 -5
- package/src/model/liveposition.d.ts +31 -31
- package/src/model/liveposition.js +18 -18
- package/src/model/liverange.d.ts +42 -38
- package/src/model/liverange.js +17 -16
- package/src/model/markercollection.d.ts +41 -40
- package/src/model/markercollection.js +22 -20
- package/src/model/model.d.ts +82 -81
- package/src/model/model.js +54 -54
- package/src/model/node.d.ts +48 -48
- package/src/model/node.js +31 -31
- package/src/model/nodelist.d.ts +17 -17
- package/src/model/nodelist.js +11 -11
- package/src/model/operation/attributeoperation.d.ts +10 -10
- package/src/model/operation/attributeoperation.js +7 -7
- package/src/model/operation/detachoperation.d.ts +11 -9
- package/src/model/operation/detachoperation.js +8 -6
- package/src/model/operation/insertoperation.d.ts +13 -13
- package/src/model/operation/insertoperation.js +15 -15
- package/src/model/operation/markeroperation.d.ts +12 -12
- package/src/model/operation/markeroperation.js +5 -5
- package/src/model/operation/mergeoperation.d.ts +16 -16
- package/src/model/operation/mergeoperation.js +18 -18
- package/src/model/operation/moveoperation.d.ts +16 -16
- package/src/model/operation/moveoperation.js +18 -15
- package/src/model/operation/nooperation.d.ts +4 -4
- package/src/model/operation/nooperation.js +2 -2
- package/src/model/operation/operation.d.ts +10 -10
- package/src/model/operation/operation.js +5 -5
- package/src/model/operation/operationfactory.d.ts +4 -4
- package/src/model/operation/operationfactory.js +12 -12
- package/src/model/operation/renameoperation.d.ts +10 -10
- package/src/model/operation/renameoperation.js +7 -7
- package/src/model/operation/rootattributeoperation.d.ts +12 -12
- package/src/model/operation/rootattributeoperation.js +8 -8
- package/src/model/operation/rootoperation.d.ts +8 -8
- package/src/model/operation/rootoperation.js +3 -3
- package/src/model/operation/splitoperation.d.ts +17 -17
- package/src/model/operation/splitoperation.js +19 -19
- package/src/model/operation/transform.d.ts +11 -8
- package/src/model/operation/transform.js +66 -49
- package/src/model/operation/utils.d.ts +24 -23
- package/src/model/operation/utils.js +20 -20
- package/src/model/position.d.ts +101 -97
- package/src/model/position.js +69 -64
- package/src/model/range.d.ts +90 -90
- package/src/model/range.js +87 -87
- package/src/model/rootelement.d.ts +11 -11
- package/src/model/rootelement.js +9 -9
- package/src/model/schema.d.ts +158 -154
- package/src/model/schema.js +93 -90
- package/src/model/selection.d.ts +73 -73
- package/src/model/selection.js +62 -62
- package/src/model/text.d.ts +11 -10
- package/src/model/text.js +11 -10
- package/src/model/textproxy.d.ts +39 -38
- package/src/model/textproxy.js +31 -30
- package/src/model/treewalker.d.ts +37 -37
- package/src/model/treewalker.js +14 -14
- package/src/model/typecheckable.d.ts +45 -45
- package/src/model/typecheckable.js +1 -1
- package/src/model/utils/autoparagraphing.d.ts +7 -7
- package/src/model/utils/deletecontent.d.ts +7 -5
- package/src/model/utils/deletecontent.js +13 -11
- package/src/model/utils/getselectedcontent.d.ts +6 -5
- package/src/model/utils/getselectedcontent.js +2 -1
- package/src/model/utils/insertcontent.d.ts +9 -8
- package/src/model/utils/insertcontent.js +41 -40
- package/src/model/utils/insertobject.d.ts +9 -9
- package/src/model/utils/insertobject.js +4 -4
- package/src/model/utils/modifyselection.d.ts +5 -4
- package/src/model/utils/modifyselection.js +12 -11
- package/src/model/utils/selection-post-fixer.d.ts +12 -8
- package/src/model/utils/selection-post-fixer.js +15 -11
- package/src/model/writer.d.ts +102 -101
- package/src/model/writer.js +99 -98
- package/src/view/attributeelement.d.ts +29 -29
- package/src/view/attributeelement.js +25 -25
- package/src/view/containerelement.d.ts +16 -15
- package/src/view/containerelement.js +15 -14
- package/src/view/datatransfer.d.ts +7 -7
- package/src/view/datatransfer.js +1 -1
- package/src/view/document.d.ts +25 -25
- package/src/view/document.js +15 -15
- package/src/view/documentfragment.d.ts +21 -21
- package/src/view/documentfragment.js +14 -14
- package/src/view/documentselection.d.ts +65 -63
- package/src/view/documentselection.js +27 -25
- package/src/view/domconverter.d.ts +94 -89
- package/src/view/domconverter.js +78 -73
- package/src/view/downcastwriter.d.ts +185 -181
- package/src/view/downcastwriter.js +222 -210
- package/src/view/editableelement.d.ts +13 -13
- package/src/view/editableelement.js +8 -8
- package/src/view/element.d.ts +75 -74
- package/src/view/element.js +58 -58
- package/src/view/elementdefinition.d.ts +3 -4
- package/src/view/emptyelement.d.ts +13 -13
- package/src/view/emptyelement.js +13 -13
- package/src/view/filler.d.ts +14 -3
- package/src/view/filler.js +12 -1
- package/src/view/item.d.ts +4 -5
- package/src/view/matcher.d.ts +22 -19
- package/src/view/matcher.js +6 -6
- package/src/view/node.d.ts +33 -33
- package/src/view/node.js +9 -9
- package/src/view/observer/arrowkeysobserver.d.ts +10 -10
- package/src/view/observer/arrowkeysobserver.js +5 -5
- package/src/view/observer/bubblingemittermixin.d.ts +5 -5
- package/src/view/observer/bubblingemittermixin.js +2 -9
- package/src/view/observer/bubblingeventinfo.d.ts +9 -9
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.d.ts +8 -8
- package/src/view/observer/clickobserver.js +4 -4
- package/src/view/observer/compositionobserver.d.ts +19 -19
- package/src/view/observer/compositionobserver.js +6 -6
- package/src/view/observer/domeventdata.d.ts +9 -9
- package/src/view/observer/domeventdata.js +2 -2
- package/src/view/observer/domeventobserver.d.ts +3 -3
- package/src/view/observer/domeventobserver.js +5 -5
- package/src/view/observer/fakeselectionobserver.d.ts +9 -9
- package/src/view/observer/fakeselectionobserver.js +8 -8
- package/src/view/observer/focusobserver.d.ts +16 -16
- package/src/view/observer/focusobserver.js +7 -7
- package/src/view/observer/inputobserver.d.ts +18 -18
- package/src/view/observer/inputobserver.js +5 -5
- package/src/view/observer/keyobserver.d.ts +11 -11
- package/src/view/observer/keyobserver.js +3 -3
- package/src/view/observer/mouseobserver.d.ts +16 -16
- package/src/view/observer/mouseobserver.js +3 -3
- package/src/view/observer/mutationobserver.d.ts +21 -21
- package/src/view/observer/mutationobserver.js +7 -7
- package/src/view/observer/observer.d.ts +12 -12
- package/src/view/observer/observer.js +6 -6
- package/src/view/observer/selectionobserver.d.ts +33 -33
- package/src/view/observer/selectionobserver.js +14 -14
- package/src/view/observer/tabobserver.d.ts +10 -10
- package/src/view/observer/tabobserver.js +5 -5
- package/src/view/observer/touchobserver.d.ts +13 -13
- package/src/view/observer/touchobserver.js +3 -3
- package/src/view/placeholder.d.ts +21 -21
- package/src/view/placeholder.js +23 -23
- package/src/view/position.d.ts +49 -49
- package/src/view/position.js +42 -42
- package/src/view/range.d.ts +76 -74
- package/src/view/range.js +67 -65
- package/src/view/rawelement.d.ts +19 -19
- package/src/view/rawelement.js +16 -16
- package/src/view/renderer.d.ts +14 -14
- package/src/view/renderer.js +7 -7
- package/src/view/rooteditableelement.d.ts +8 -7
- package/src/view/rooteditableelement.js +7 -6
- package/src/view/selection.d.ts +66 -64
- package/src/view/selection.js +50 -48
- package/src/view/styles/background.d.ts +2 -2
- package/src/view/styles/background.js +9 -9
- package/src/view/styles/border.d.ts +2 -2
- package/src/view/styles/border.js +13 -13
- package/src/view/styles/margin.d.ts +2 -2
- package/src/view/styles/margin.js +5 -5
- package/src/view/styles/padding.d.ts +2 -2
- package/src/view/styles/padding.js +5 -5
- package/src/view/styles/utils.d.ts +24 -24
- package/src/view/styles/utils.js +25 -25
- package/src/view/stylesmap.d.ts +28 -32
- package/src/view/stylesmap.js +52 -39
- package/src/view/text.d.ts +11 -11
- package/src/view/text.js +10 -10
- package/src/view/textproxy.d.ts +33 -32
- package/src/view/textproxy.js +23 -22
- package/src/view/tokenlist.d.ts +14 -14
- package/src/view/tokenlist.js +10 -10
- package/src/view/treewalker.d.ts +42 -40
- package/src/view/treewalker.js +36 -35
- package/src/view/typecheckable.d.ts +76 -75
- package/src/view/typecheckable.js +1 -1
- package/src/view/uielement.d.ts +22 -21
- package/src/view/uielement.js +17 -16
- package/src/view/upcastwriter.d.ts +70 -70
- package/src/view/upcastwriter.js +42 -42
- package/src/view/view.d.ts +70 -69
- package/src/view/view.js +56 -55
package/src/model/textproxy.js
CHANGED
|
@@ -5,39 +5,39 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module engine/model/textproxy
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import { ModelTypeCheckable } from './typecheckable.js';
|
|
9
9
|
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
10
10
|
// @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
|
|
11
11
|
/**
|
|
12
|
-
* `
|
|
12
|
+
* `ModelTextProxy` represents a part of {@link module:engine/model/text~ModelText text node}.
|
|
13
13
|
*
|
|
14
|
-
* Since {@link module:engine/model/position~
|
|
15
|
-
* {@link module:engine/model/range~
|
|
16
|
-
* getting items}
|
|
14
|
+
* Since {@link module:engine/model/position~ModelPosition positions} can be placed between characters of a text node,
|
|
15
|
+
* {@link module:engine/model/range~ModelRange ranges} may contain only parts of text nodes.
|
|
16
|
+
* When {@link module:engine/model/range~ModelRange#getItems getting items}
|
|
17
17
|
* contained in such range, we need to represent a part of that text node, since returning the whole text node would be incorrect.
|
|
18
|
-
* `
|
|
18
|
+
* `ModelTextProxy` solves this issue.
|
|
19
19
|
*
|
|
20
|
-
* `
|
|
21
|
-
* on model nodes.
|
|
20
|
+
* `ModelTextProxy` has an API similar to {@link module:engine/model/text~ModelText Text} and allows to do
|
|
21
|
+
* most of the common tasks performed on model nodes.
|
|
22
22
|
*
|
|
23
|
-
* **Note:** Some `
|
|
24
|
-
* See {@link module:engine/model/textproxy~
|
|
23
|
+
* **Note:** Some `ModelTextProxy` instances may represent whole text node, not just a part of it.
|
|
24
|
+
* See {@link module:engine/model/textproxy~ModelTextProxy#isPartial}.
|
|
25
25
|
*
|
|
26
|
-
* **Note:** `
|
|
26
|
+
* **Note:** `ModelTextProxy` is not an instance of {@link module:engine/model/node~ModelNode node}. Keep this in mind when using it as a
|
|
27
27
|
* parameter of methods.
|
|
28
28
|
*
|
|
29
|
-
* **Note:** `
|
|
30
|
-
* use {@link module:engine/model/writer~
|
|
29
|
+
* **Note:** `ModelTextProxy` is a readonly interface. If you want to perform changes on model data represented by a `ModelTextProxy`
|
|
30
|
+
* use {@link module:engine/model/writer~ModelWriter model writer API}.
|
|
31
31
|
*
|
|
32
|
-
* **Note:** `
|
|
33
|
-
* highly unrecommended to store references to `
|
|
34
|
-
* model changes, so they might get invalidated. Instead, consider creating {@link module:engine/model/liveposition~
|
|
32
|
+
* **Note:** `ModelTextProxy` instances are created on the fly, basing on the current state of model. Because of this, it is
|
|
33
|
+
* highly unrecommended to store references to `ModelTextProxy` instances. `ModelTextProxy` instances are not refreshed when
|
|
34
|
+
* model changes, so they might get invalidated. Instead, consider creating {@link module:engine/model/liveposition~ModelLivePosition live
|
|
35
35
|
* position}.
|
|
36
36
|
*
|
|
37
|
-
* `
|
|
38
|
-
* an instance of this class by your own.
|
|
37
|
+
* `ModelTextProxy` instances are created by {@link module:engine/model/treewalker~ModelTreeWalker model tree walker}.
|
|
38
|
+
* You should not need to create an instance of this class by your own.
|
|
39
39
|
*/
|
|
40
|
-
export
|
|
40
|
+
export class ModelTextProxy extends ModelTypeCheckable {
|
|
41
41
|
/**
|
|
42
42
|
* Text node which part is represented by this text proxy.
|
|
43
43
|
*/
|
|
@@ -47,7 +47,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
47
47
|
*/
|
|
48
48
|
data;
|
|
49
49
|
/**
|
|
50
|
-
* Offset in {@link module:engine/model/textproxy~
|
|
50
|
+
* Offset in {@link module:engine/model/textproxy~ModelTextProxy#textNode text node} from which the text proxy starts.
|
|
51
51
|
*/
|
|
52
52
|
offsetInText;
|
|
53
53
|
/**
|
|
@@ -55,7 +55,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
55
55
|
*
|
|
56
56
|
* @internal
|
|
57
57
|
* @param textNode Text node which part is represented by this text proxy.
|
|
58
|
-
* @param offsetInText Offset in {@link module:engine/model/textproxy~
|
|
58
|
+
* @param offsetInText Offset in {@link module:engine/model/textproxy~ModelTextProxy#textNode text node} from which the text proxy
|
|
59
59
|
* starts.
|
|
60
60
|
* @param length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
|
|
61
61
|
*/
|
|
@@ -84,7 +84,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
84
84
|
/**
|
|
85
85
|
* Offset at which this text proxy starts in it's parent.
|
|
86
86
|
*
|
|
87
|
-
* @see module:engine/model/node~
|
|
87
|
+
* @see module:engine/model/node~ModelNode#startOffset
|
|
88
88
|
*/
|
|
89
89
|
get startOffset() {
|
|
90
90
|
return this.textNode.startOffset !== null ? this.textNode.startOffset + this.offsetInText : null;
|
|
@@ -92,7 +92,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
92
92
|
/**
|
|
93
93
|
* Offset size of this text proxy. Equal to the number of characters represented by the text proxy.
|
|
94
94
|
*
|
|
95
|
-
* @see module:engine/model/node~
|
|
95
|
+
* @see module:engine/model/node~ModelNode#offsetSize
|
|
96
96
|
*/
|
|
97
97
|
get offsetSize() {
|
|
98
98
|
return this.data.length;
|
|
@@ -100,17 +100,18 @@ export default class TextProxy extends TypeCheckable {
|
|
|
100
100
|
/**
|
|
101
101
|
* Offset at which this text proxy ends in it's parent.
|
|
102
102
|
*
|
|
103
|
-
* @see module:engine/model/node~
|
|
103
|
+
* @see module:engine/model/node~ModelNode#endOffset
|
|
104
104
|
*/
|
|
105
105
|
get endOffset() {
|
|
106
106
|
return this.startOffset !== null ? this.startOffset + this.offsetSize : null;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
|
-
* Flag indicating whether `
|
|
110
|
-
* (`true`) or the whole text node (`false`).
|
|
109
|
+
* Flag indicating whether `ModelTextProxy` instance covers only part of the original
|
|
110
|
+
* {@link module:engine/model/text~ModelText text node} (`true`) or the whole text node (`false`).
|
|
111
111
|
*
|
|
112
|
-
* This is `false` when text proxy starts at the very beginning of
|
|
113
|
-
*
|
|
112
|
+
* This is `false` when text proxy starts at the very beginning of
|
|
113
|
+
* {@link module:engine/model/textproxy~ModelTextProxy#textNode textNode}
|
|
114
|
+
* ({@link module:engine/model/textproxy~ModelTextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
|
|
114
115
|
* text node size.
|
|
115
116
|
*/
|
|
116
117
|
get isPartial() {
|
|
@@ -131,7 +132,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
131
132
|
/**
|
|
132
133
|
* Gets path to this text proxy.
|
|
133
134
|
*
|
|
134
|
-
* @see module:engine/model/node~
|
|
135
|
+
* @see module:engine/model/node~ModelNode#getPath
|
|
135
136
|
*/
|
|
136
137
|
getPath() {
|
|
137
138
|
const path = this.textNode.getPath();
|
|
@@ -194,7 +195,7 @@ export default class TextProxy extends TypeCheckable {
|
|
|
194
195
|
}
|
|
195
196
|
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
196
197
|
// Proper overload would interfere with that.
|
|
197
|
-
|
|
198
|
+
ModelTextProxy.prototype.is = function (type) {
|
|
198
199
|
return type === '$textProxy' || type === 'model:$textProxy' ||
|
|
199
200
|
// This are legacy values kept for backward compatibility.
|
|
200
201
|
type === 'textProxy' || type === 'model:textProxy';
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import type
|
|
7
|
-
import type
|
|
5
|
+
import { ModelPosition } from './position.js';
|
|
6
|
+
import { type ModelItem } from './item.js';
|
|
7
|
+
import { type ModelRange } from './range.js';
|
|
8
8
|
/**
|
|
9
9
|
* Position iterator class. It allows to iterate forward and backward over the document.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export declare class ModelTreeWalker implements Iterable<ModelTreeWalkerValue> {
|
|
12
12
|
/**
|
|
13
13
|
* Walking direction. Defaults `'forward'`.
|
|
14
14
|
*/
|
|
15
|
-
readonly direction:
|
|
15
|
+
readonly direction: ModelTreeWalkerDirection;
|
|
16
16
|
/**
|
|
17
17
|
* Iterator boundaries.
|
|
18
18
|
*
|
|
@@ -21,10 +21,10 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
21
21
|
*
|
|
22
22
|
* If boundaries are not defined they are set before first and after last child of the root node.
|
|
23
23
|
*/
|
|
24
|
-
readonly boundaries:
|
|
24
|
+
readonly boundaries: ModelRange | null;
|
|
25
25
|
/**
|
|
26
26
|
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
27
|
-
* returned as one {@link module:engine/model/textproxy~
|
|
27
|
+
* returned as one {@link module:engine/model/textproxy~ModelTextProxy} (`true`) or one by one (`false`).
|
|
28
28
|
*/
|
|
29
29
|
readonly singleCharacters: boolean;
|
|
30
30
|
/**
|
|
@@ -34,14 +34,14 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
34
34
|
readonly shallow: boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Flag indicating whether iterator should ignore `elementEnd` tags. If the option is true walker will not
|
|
37
|
-
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~
|
|
37
|
+
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~ModelElement} will
|
|
38
38
|
* be returned once, while if the option is `false` they might be returned twice:
|
|
39
39
|
* for `'elementStart'` and `'elementEnd'`.
|
|
40
40
|
*/
|
|
41
41
|
readonly ignoreElementEnd: boolean;
|
|
42
42
|
/**
|
|
43
43
|
* Iterator position. This is always static position, even if the initial position was a
|
|
44
|
-
* {@link module:engine/model/liveposition~
|
|
44
|
+
* {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
|
|
45
45
|
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
46
46
|
* is `'backward'` position starts from the end.
|
|
47
47
|
*/
|
|
@@ -63,20 +63,20 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
63
63
|
*
|
|
64
64
|
* @param options Object with configuration.
|
|
65
65
|
*/
|
|
66
|
-
constructor(options:
|
|
66
|
+
constructor(options: ModelTreeWalkerOptions);
|
|
67
67
|
/**
|
|
68
68
|
* Iterable interface.
|
|
69
69
|
*
|
|
70
|
-
* @returns {Iterable.<module:engine/model/treewalker~
|
|
70
|
+
* @returns {Iterable.<module:engine/model/treewalker~ModelTreeWalkerValue>}
|
|
71
71
|
*/
|
|
72
|
-
[Symbol.iterator](): IterableIterator<
|
|
72
|
+
[Symbol.iterator](): IterableIterator<ModelTreeWalkerValue>;
|
|
73
73
|
/**
|
|
74
74
|
* Iterator position. This is always static position, even if the initial position was a
|
|
75
|
-
* {@link module:engine/model/liveposition~
|
|
75
|
+
* {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
|
|
76
76
|
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
77
77
|
* is `'backward'` position starts from the end.
|
|
78
78
|
*/
|
|
79
|
-
get position():
|
|
79
|
+
get position(): ModelPosition;
|
|
80
80
|
/**
|
|
81
81
|
* Moves {@link #position} in the {@link #direction} skipping values as long as the callback function returns `true`.
|
|
82
82
|
*
|
|
@@ -88,17 +88,17 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
88
88
|
* walker.skip( () => false ); // Do not move the position.
|
|
89
89
|
* ```
|
|
90
90
|
*
|
|
91
|
-
* @param skip Callback function. Gets {@link module:engine/model/treewalker~
|
|
91
|
+
* @param skip Callback function. Gets {@link module:engine/model/treewalker~ModelTreeWalkerValue} and should
|
|
92
92
|
* return `true` if the value should be skipped or `false` if not.
|
|
93
93
|
*/
|
|
94
|
-
skip(skip: (value:
|
|
94
|
+
skip(skip: (value: ModelTreeWalkerValue) => boolean): void;
|
|
95
95
|
/**
|
|
96
96
|
* Moves tree walker {@link #position} to provided `position`. Tree walker will
|
|
97
97
|
* continue traversing from that position.
|
|
98
98
|
*
|
|
99
|
-
* Note: in contrary to {@link ~
|
|
99
|
+
* Note: in contrary to {@link ~ModelTreeWalker#skip}, this method does not iterate over the nodes along the way.
|
|
100
100
|
* It simply sets the current tree walker position to a new one.
|
|
101
|
-
* From the performance standpoint, it is better to use {@link ~
|
|
101
|
+
* From the performance standpoint, it is better to use {@link ~ModelTreeWalker#jumpTo} rather than {@link ~ModelTreeWalker#skip}.
|
|
102
102
|
*
|
|
103
103
|
* If the provided position is before the start boundary, the position will be
|
|
104
104
|
* set to the start boundary. If the provided position is after the end boundary,
|
|
@@ -107,11 +107,11 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
107
107
|
*
|
|
108
108
|
* @param position Position to jump to.
|
|
109
109
|
*/
|
|
110
|
-
jumpTo(position:
|
|
110
|
+
jumpTo(position: ModelPosition): void;
|
|
111
111
|
/**
|
|
112
112
|
* Gets the next tree walker's value.
|
|
113
113
|
*/
|
|
114
|
-
next(): IteratorResult<
|
|
114
|
+
next(): IteratorResult<ModelTreeWalkerValue>;
|
|
115
115
|
/**
|
|
116
116
|
* Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
|
|
117
117
|
*/
|
|
@@ -122,20 +122,20 @@ export default class TreeWalker implements Iterable<TreeWalkerValue> {
|
|
|
122
122
|
private _previous;
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
|
-
* Type of the step made by {@link module:engine/model/treewalker~
|
|
125
|
+
* Type of the step made by {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
126
126
|
* Possible values: `'elementStart'` if walker is at the beginning of a node, `'elementEnd'` if walker is at the end of node,
|
|
127
127
|
* or `'text'` if walker traversed over text.
|
|
128
128
|
*/
|
|
129
|
-
export type
|
|
129
|
+
export type ModelTreeWalkerValueType = 'elementStart' | 'elementEnd' | 'text';
|
|
130
130
|
/**
|
|
131
|
-
* Object returned by {@link module:engine/model/treewalker~
|
|
131
|
+
* Object returned by {@link module:engine/model/treewalker~ModelTreeWalker} when traversing tree model.
|
|
132
132
|
*/
|
|
133
|
-
export interface
|
|
134
|
-
type:
|
|
133
|
+
export interface ModelTreeWalkerValue {
|
|
134
|
+
type: ModelTreeWalkerValueType;
|
|
135
135
|
/**
|
|
136
|
-
* Item between old and new positions of {@link module:engine/model/treewalker~
|
|
136
|
+
* Item between old and new positions of {@link module:engine/model/treewalker~ModelTreeWalker}.
|
|
137
137
|
*/
|
|
138
|
-
item:
|
|
138
|
+
item: ModelItem;
|
|
139
139
|
/**
|
|
140
140
|
* Previous position of the iterator.
|
|
141
141
|
* * Forward iteration: For `'elementEnd'` it is the last position inside the element. For all other types it is the
|
|
@@ -143,7 +143,7 @@ export interface TreeWalkerValue {
|
|
|
143
143
|
* * Backward iteration: For `'elementStart'` it is the first position inside the element. For all other types it is
|
|
144
144
|
* the position after item.
|
|
145
145
|
*/
|
|
146
|
-
previousPosition:
|
|
146
|
+
previousPosition: ModelPosition;
|
|
147
147
|
/**
|
|
148
148
|
* Next position of the iterator.
|
|
149
149
|
* * Forward iteration: For `'elementStart'` it is the first position inside the element. For all other types it is
|
|
@@ -151,7 +151,7 @@ export interface TreeWalkerValue {
|
|
|
151
151
|
* * Backward iteration: For `'elementEnd'` it is last position inside element. For all other types it is the position
|
|
152
152
|
* before the item.
|
|
153
153
|
*/
|
|
154
|
-
nextPosition:
|
|
154
|
+
nextPosition: ModelPosition;
|
|
155
155
|
/**
|
|
156
156
|
* Length of the item. For `'elementStart'` it is 1. For `'text'` it is the length of the text. For `'elementEnd'` it is `undefined`.
|
|
157
157
|
*/
|
|
@@ -160,31 +160,31 @@ export interface TreeWalkerValue {
|
|
|
160
160
|
/**
|
|
161
161
|
* Tree walking direction.
|
|
162
162
|
*/
|
|
163
|
-
export type
|
|
163
|
+
export type ModelTreeWalkerDirection = 'forward' | 'backward';
|
|
164
164
|
/**
|
|
165
165
|
* The configuration of TreeWalker.
|
|
166
166
|
*
|
|
167
167
|
* All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
|
|
168
168
|
*/
|
|
169
|
-
export interface
|
|
169
|
+
export interface ModelTreeWalkerOptions {
|
|
170
170
|
/**
|
|
171
171
|
* Walking direction.
|
|
172
172
|
*
|
|
173
173
|
* @default 'forward'
|
|
174
174
|
*/
|
|
175
|
-
direction?:
|
|
175
|
+
direction?: ModelTreeWalkerDirection;
|
|
176
176
|
/**
|
|
177
177
|
* Range to define boundaries of the iterator.
|
|
178
178
|
*/
|
|
179
|
-
boundaries?:
|
|
179
|
+
boundaries?: ModelRange | null;
|
|
180
180
|
/**
|
|
181
181
|
* Starting position.
|
|
182
182
|
*/
|
|
183
|
-
startPosition?:
|
|
183
|
+
startPosition?: ModelPosition;
|
|
184
184
|
/**
|
|
185
185
|
* Flag indicating whether all consecutive characters with the same attributes
|
|
186
|
-
* should be returned one by one as multiple {@link module:engine/model/textproxy~
|
|
187
|
-
* {@link module:engine/model/textproxy~
|
|
186
|
+
* should be returned one by one as multiple {@link module:engine/model/textproxy~ModelTextProxy} (`true`) objects or as one
|
|
187
|
+
* {@link module:engine/model/textproxy~ModelTextProxy} (`false`).
|
|
188
188
|
*/
|
|
189
189
|
singleCharacters?: boolean;
|
|
190
190
|
/**
|
|
@@ -195,7 +195,7 @@ export interface TreeWalkerOptions {
|
|
|
195
195
|
/**
|
|
196
196
|
* Flag indicating whether iterator should ignore `elementEnd` tags.
|
|
197
197
|
* If the option is true walker will not return a parent node of start position. If this option is `true`
|
|
198
|
-
* each {@link module:engine/model/element~
|
|
198
|
+
* each {@link module:engine/model/element~ModelElement} will be returned once, while if the option is `false` they might be returned
|
|
199
199
|
* twice: for `'elementStart'` and `'elementEnd'`.
|
|
200
200
|
*/
|
|
201
201
|
ignoreElementEnd?: boolean;
|
package/src/model/treewalker.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import { ModelPosition, getTextNodeAtPosition, getNodeAfterPosition, getNodeBeforePosition } from './position.js';
|
|
6
|
+
import { ModelTextProxy } from './textproxy.js';
|
|
7
7
|
import { CKEditorError } from '@ckeditor/ckeditor5-utils';
|
|
8
8
|
/**
|
|
9
9
|
* Position iterator class. It allows to iterate forward and backward over the document.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export class ModelTreeWalker {
|
|
12
12
|
/**
|
|
13
13
|
* Walking direction. Defaults `'forward'`.
|
|
14
14
|
*/
|
|
@@ -24,7 +24,7 @@ export default class TreeWalker {
|
|
|
24
24
|
boundaries;
|
|
25
25
|
/**
|
|
26
26
|
* Flag indicating whether all consecutive characters with the same attributes should be
|
|
27
|
-
* returned as one {@link module:engine/model/textproxy~
|
|
27
|
+
* returned as one {@link module:engine/model/textproxy~ModelTextProxy} (`true`) or one by one (`false`).
|
|
28
28
|
*/
|
|
29
29
|
singleCharacters;
|
|
30
30
|
/**
|
|
@@ -34,14 +34,14 @@ export default class TreeWalker {
|
|
|
34
34
|
shallow;
|
|
35
35
|
/**
|
|
36
36
|
* Flag indicating whether iterator should ignore `elementEnd` tags. If the option is true walker will not
|
|
37
|
-
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~
|
|
37
|
+
* return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~ModelElement} will
|
|
38
38
|
* be returned once, while if the option is `false` they might be returned twice:
|
|
39
39
|
* for `'elementStart'` and `'elementEnd'`.
|
|
40
40
|
*/
|
|
41
41
|
ignoreElementEnd;
|
|
42
42
|
/**
|
|
43
43
|
* Iterator position. This is always static position, even if the initial position was a
|
|
44
|
-
* {@link module:engine/model/liveposition~
|
|
44
|
+
* {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
|
|
45
45
|
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
46
46
|
* is `'backward'` position starts from the end.
|
|
47
47
|
*/
|
|
@@ -87,7 +87,7 @@ export default class TreeWalker {
|
|
|
87
87
|
this._position = options.startPosition.clone();
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
this._position =
|
|
90
|
+
this._position = ModelPosition._createAt(this.boundaries[this.direction == 'backward' ? 'end' : 'start']);
|
|
91
91
|
}
|
|
92
92
|
// Reset position stickiness in case it was set to other value, as the stickiness is kept after cloning.
|
|
93
93
|
this.position.stickiness = 'toNone';
|
|
@@ -101,14 +101,14 @@ export default class TreeWalker {
|
|
|
101
101
|
/**
|
|
102
102
|
* Iterable interface.
|
|
103
103
|
*
|
|
104
|
-
* @returns {Iterable.<module:engine/model/treewalker~
|
|
104
|
+
* @returns {Iterable.<module:engine/model/treewalker~ModelTreeWalkerValue>}
|
|
105
105
|
*/
|
|
106
106
|
[Symbol.iterator]() {
|
|
107
107
|
return this;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* Iterator position. This is always static position, even if the initial position was a
|
|
111
|
-
* {@link module:engine/model/liveposition~
|
|
111
|
+
* {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
|
|
112
112
|
* on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
|
|
113
113
|
* is `'backward'` position starts from the end.
|
|
114
114
|
*/
|
|
@@ -126,7 +126,7 @@ export default class TreeWalker {
|
|
|
126
126
|
* walker.skip( () => false ); // Do not move the position.
|
|
127
127
|
* ```
|
|
128
128
|
*
|
|
129
|
-
* @param skip Callback function. Gets {@link module:engine/model/treewalker~
|
|
129
|
+
* @param skip Callback function. Gets {@link module:engine/model/treewalker~ModelTreeWalkerValue} and should
|
|
130
130
|
* return `true` if the value should be skipped or `false` if not.
|
|
131
131
|
*/
|
|
132
132
|
skip(skip) {
|
|
@@ -145,9 +145,9 @@ export default class TreeWalker {
|
|
|
145
145
|
* Moves tree walker {@link #position} to provided `position`. Tree walker will
|
|
146
146
|
* continue traversing from that position.
|
|
147
147
|
*
|
|
148
|
-
* Note: in contrary to {@link ~
|
|
148
|
+
* Note: in contrary to {@link ~ModelTreeWalker#skip}, this method does not iterate over the nodes along the way.
|
|
149
149
|
* It simply sets the current tree walker position to a new one.
|
|
150
|
-
* From the performance standpoint, it is better to use {@link ~
|
|
150
|
+
* From the performance standpoint, it is better to use {@link ~ModelTreeWalker#jumpTo} rather than {@link ~ModelTreeWalker#skip}.
|
|
151
151
|
*
|
|
152
152
|
* If the provided position is before the start boundary, the position will be
|
|
153
153
|
* set to the start boundary. If the provided position is after the end boundary,
|
|
@@ -225,7 +225,7 @@ export default class TreeWalker {
|
|
|
225
225
|
charactersCount = offset - position.offset;
|
|
226
226
|
}
|
|
227
227
|
const offsetInTextNode = position.offset - node.startOffset;
|
|
228
|
-
const item = new
|
|
228
|
+
const item = new ModelTextProxy(node, offsetInTextNode, charactersCount);
|
|
229
229
|
position.offset += charactersCount;
|
|
230
230
|
this._position = position;
|
|
231
231
|
return formatReturnValue('text', item, previousPosition, position, charactersCount);
|
|
@@ -287,7 +287,7 @@ export default class TreeWalker {
|
|
|
287
287
|
charactersCount = position.offset - offset;
|
|
288
288
|
}
|
|
289
289
|
const offsetInTextNode = position.offset - node.startOffset;
|
|
290
|
-
const item = new
|
|
290
|
+
const item = new ModelTextProxy(node, offsetInTextNode - charactersCount, charactersCount);
|
|
291
291
|
position.offset -= charactersCount;
|
|
292
292
|
this._position = position;
|
|
293
293
|
return formatReturnValue('text', item, previousPosition, position, charactersCount);
|