@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
|
@@ -1,251 +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/view/documentfragment
|
|
7
|
-
*/
|
|
8
|
-
import { ViewTypeCheckable } from './typecheckable.js';
|
|
9
|
-
import { ViewText } from './text.js';
|
|
10
|
-
import { ViewTextProxy } from './textproxy.js';
|
|
11
|
-
import { EmitterMixin, isIterable } from '@ckeditor/ckeditor5-utils';
|
|
12
|
-
/**
|
|
13
|
-
* Document fragment.
|
|
14
|
-
*
|
|
15
|
-
* To create a new document fragment instance use the
|
|
16
|
-
* {@link module:engine/view/upcastwriter~ViewUpcastWriter#createDocumentFragment `ViewUpcastWriter#createDocumentFragment()`}
|
|
17
|
-
* method.
|
|
18
|
-
*/
|
|
19
|
-
export class ViewDocumentFragment extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckable) {
|
|
20
|
-
/**
|
|
21
|
-
* The document to which this document fragment belongs.
|
|
22
|
-
*/
|
|
23
|
-
document;
|
|
24
|
-
/**
|
|
25
|
-
* Array of child nodes.
|
|
26
|
-
*/
|
|
27
|
-
_children = [];
|
|
28
|
-
/**
|
|
29
|
-
* Map of custom properties.
|
|
30
|
-
* Custom properties can be added to document fragment instance.
|
|
31
|
-
*/
|
|
32
|
-
_customProperties = new Map();
|
|
33
|
-
/**
|
|
34
|
-
* Creates new DocumentFragment instance.
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
* @param document The document to which this document fragment belongs.
|
|
38
|
-
* @param children A list of nodes to be inserted into the created document fragment.
|
|
39
|
-
*/
|
|
40
|
-
constructor(document, children) {
|
|
41
|
-
super();
|
|
42
|
-
this.document = document;
|
|
43
|
-
if (children) {
|
|
44
|
-
this._insertChild(0, children);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Iterable interface.
|
|
49
|
-
*
|
|
50
|
-
* Iterates over nodes added to this document fragment.
|
|
51
|
-
*/
|
|
52
|
-
[Symbol.iterator]() {
|
|
53
|
-
return this._children[Symbol.iterator]();
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Number of child nodes in this document fragment.
|
|
57
|
-
*/
|
|
58
|
-
get childCount() {
|
|
59
|
-
return this._children.length;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Is `true` if there are no nodes inside this document fragment, `false` otherwise.
|
|
63
|
-
*/
|
|
64
|
-
get isEmpty() {
|
|
65
|
-
return this.childCount === 0;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Artificial root of `DocumentFragment`. Returns itself. Added for compatibility reasons.
|
|
69
|
-
*/
|
|
70
|
-
get root() {
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Artificial parent of `DocumentFragment`. Returns `null`. Added for compatibility reasons.
|
|
75
|
-
*/
|
|
76
|
-
get parent() {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Artificial element name. Returns `undefined`. Added for compatibility reasons.
|
|
81
|
-
*/
|
|
82
|
-
get name() {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Artificial element getFillerOffset. Returns `undefined`. Added for compatibility reasons.
|
|
87
|
-
*/
|
|
88
|
-
get getFillerOffset() {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the custom property value for the given key.
|
|
93
|
-
*/
|
|
94
|
-
getCustomProperty(key) {
|
|
95
|
-
return this._customProperties.get(key);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Returns an iterator which iterates over this document fragment's custom properties.
|
|
99
|
-
* Iterator provides `[ key, value ]` pairs for each stored property.
|
|
100
|
-
*/
|
|
101
|
-
*getCustomProperties() {
|
|
102
|
-
yield* this._customProperties.entries();
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Converts `ViewDocumentFragment` instance to plain object and returns it.
|
|
106
|
-
* Takes care of converting all of this document fragment's children.
|
|
107
|
-
*
|
|
108
|
-
* @returns `ViewDocumentFragment` instance converted to plain object.
|
|
109
|
-
*/
|
|
110
|
-
toJSON() {
|
|
111
|
-
const json = [];
|
|
112
|
-
for (const node of this._children) {
|
|
113
|
-
json.push(node.toJSON());
|
|
114
|
-
}
|
|
115
|
-
return json;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* {@link module:engine/view/documentfragment~ViewDocumentFragment#_insertChild Insert} a child node or a list of child nodes at the end
|
|
119
|
-
* and sets the parent of these nodes to this fragment.
|
|
120
|
-
*
|
|
121
|
-
* @internal
|
|
122
|
-
* @param items Items to be inserted.
|
|
123
|
-
* @returns Number of appended nodes.
|
|
124
|
-
*/
|
|
125
|
-
_appendChild(items) {
|
|
126
|
-
return this._insertChild(this.childCount, items);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Gets child at the given index.
|
|
130
|
-
*
|
|
131
|
-
* @param index Index of child.
|
|
132
|
-
* @returns Child node.
|
|
133
|
-
*/
|
|
134
|
-
getChild(index) {
|
|
135
|
-
return this._children[index];
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Gets index of the given child node. Returns `-1` if child node is not found.
|
|
139
|
-
*
|
|
140
|
-
* @param node Child node.
|
|
141
|
-
* @returns Index of the child node.
|
|
142
|
-
*/
|
|
143
|
-
getChildIndex(node) {
|
|
144
|
-
return this._children.indexOf(node);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Gets child nodes iterator.
|
|
148
|
-
*
|
|
149
|
-
* @returns Child nodes iterator.
|
|
150
|
-
*/
|
|
151
|
-
getChildren() {
|
|
152
|
-
return this._children[Symbol.iterator]();
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Inserts a child node or a list of child nodes on the given index and sets the parent of these nodes to
|
|
156
|
-
* this fragment.
|
|
157
|
-
*
|
|
158
|
-
* @internal
|
|
159
|
-
* @param index Position where nodes should be inserted.
|
|
160
|
-
* @param items Items to be inserted.
|
|
161
|
-
* @returns Number of inserted nodes.
|
|
162
|
-
*/
|
|
163
|
-
_insertChild(index, items) {
|
|
164
|
-
this._fireChange('children', this, { index });
|
|
165
|
-
let count = 0;
|
|
166
|
-
const nodes = normalize(this.document, items);
|
|
167
|
-
for (const node of nodes) {
|
|
168
|
-
// If node that is being added to this element is already inside another element, first remove it from the old parent.
|
|
169
|
-
if (node.parent !== null) {
|
|
170
|
-
node._remove();
|
|
171
|
-
}
|
|
172
|
-
node.parent = this;
|
|
173
|
-
this._children.splice(index, 0, node);
|
|
174
|
-
index++;
|
|
175
|
-
count++;
|
|
176
|
-
}
|
|
177
|
-
return count;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Removes number of child nodes starting at the given index and set the parent of these nodes to `null`.
|
|
181
|
-
*
|
|
182
|
-
* @internal
|
|
183
|
-
* @param index Number of the first node to remove.
|
|
184
|
-
* @param howMany Number of nodes to remove.
|
|
185
|
-
* @returns The array of removed nodes.
|
|
186
|
-
*/
|
|
187
|
-
_removeChildren(index, howMany = 1) {
|
|
188
|
-
this._fireChange('children', this, { index });
|
|
189
|
-
for (let i = index; i < index + howMany; i++) {
|
|
190
|
-
this._children[i].parent = null;
|
|
191
|
-
}
|
|
192
|
-
return this._children.splice(index, howMany);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* @internal
|
|
196
|
-
* @param type Type of the change.
|
|
197
|
-
* @param node Changed node.
|
|
198
|
-
* @param data Additional data.
|
|
199
|
-
* @fires module:engine/view/node~ViewNode#event:change
|
|
200
|
-
*/
|
|
201
|
-
_fireChange(type, node, data) {
|
|
202
|
-
this.fire(`change:${type}`, node, data);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Sets a custom property. They can be used to add special data to elements.
|
|
206
|
-
*
|
|
207
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#setCustomProperty
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
_setCustomProperty(key, value) {
|
|
211
|
-
this._customProperties.set(key, value);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Removes the custom property stored under the given key.
|
|
215
|
-
*
|
|
216
|
-
* @see module:engine/view/downcastwriter~ViewDowncastWriter#removeCustomProperty
|
|
217
|
-
* @internal
|
|
218
|
-
* @returns Returns true if property was removed.
|
|
219
|
-
*/
|
|
220
|
-
_removeCustomProperty(key) {
|
|
221
|
-
return this._customProperties.delete(key);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
225
|
-
// Proper overload would interfere with that.
|
|
226
|
-
ViewDocumentFragment.prototype.is = function (type) {
|
|
227
|
-
return type === 'documentFragment' || type === 'view:documentFragment';
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Converts strings to Text and non-iterables to arrays.
|
|
231
|
-
*/
|
|
232
|
-
function normalize(document, nodes) {
|
|
233
|
-
// Separate condition because string is iterable.
|
|
234
|
-
if (typeof nodes == 'string') {
|
|
235
|
-
return [new ViewText(document, nodes)];
|
|
236
|
-
}
|
|
237
|
-
if (!isIterable(nodes)) {
|
|
238
|
-
nodes = [nodes];
|
|
239
|
-
}
|
|
240
|
-
// Array.from to enable .map() on non-arrays.
|
|
241
|
-
return Array.from(nodes)
|
|
242
|
-
.map(node => {
|
|
243
|
-
if (typeof node == 'string') {
|
|
244
|
-
return new ViewText(document, node);
|
|
245
|
-
}
|
|
246
|
-
if (node instanceof ViewTextProxy) {
|
|
247
|
-
return new ViewText(document, node.data);
|
|
248
|
-
}
|
|
249
|
-
return node;
|
|
250
|
-
});
|
|
251
|
-
}
|
|
@@ -1,270 +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/view/documentselection
|
|
7
|
-
*/
|
|
8
|
-
import { ViewTypeCheckable } from './typecheckable.js';
|
|
9
|
-
import { ViewSelection } from './selection.js';
|
|
10
|
-
import { EmitterMixin } from '@ckeditor/ckeditor5-utils';
|
|
11
|
-
/**
|
|
12
|
-
* Class representing the document selection in the view.
|
|
13
|
-
*
|
|
14
|
-
* Its instance is available in {@link module:engine/view/document~ViewDocument#selection `Document#selection`}.
|
|
15
|
-
*
|
|
16
|
-
* It is similar to {@link module:engine/view/selection~ViewSelection} but
|
|
17
|
-
* it has a read-only API and can be modified only by the writer available in
|
|
18
|
-
* the {@link module:engine/view/view~EditingView#change `View#change()`} block
|
|
19
|
-
* (so via {@link module:engine/view/downcastwriter~ViewDowncastWriter#setSelection `ViewDowncastWriter#setSelection()`}).
|
|
20
|
-
*/
|
|
21
|
-
export class ViewDocumentSelection extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckable) {
|
|
22
|
-
/**
|
|
23
|
-
* Selection is used internally (`ViewDocumentSelection` is a proxy to that selection).
|
|
24
|
-
*/
|
|
25
|
-
_selection;
|
|
26
|
-
constructor(...args) {
|
|
27
|
-
super();
|
|
28
|
-
this._selection = new ViewSelection();
|
|
29
|
-
// Delegate change event to be fired on ViewDocumentSelection instance.
|
|
30
|
-
this._selection.delegate('change').to(this);
|
|
31
|
-
// Set selection data.
|
|
32
|
-
if (args.length) {
|
|
33
|
-
this._selection.setTo(...args);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Returns true if selection instance is marked as `fake`.
|
|
38
|
-
*
|
|
39
|
-
* @see #_setTo
|
|
40
|
-
*/
|
|
41
|
-
get isFake() {
|
|
42
|
-
return this._selection.isFake;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Returns fake selection label.
|
|
46
|
-
*
|
|
47
|
-
* @see #_setTo
|
|
48
|
-
*/
|
|
49
|
-
get fakeSelectionLabel() {
|
|
50
|
-
return this._selection.fakeSelectionLabel;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Selection anchor. Anchor may be described as a position where the selection starts. Together with
|
|
54
|
-
* {@link #focus focus} they define the direction of selection, which is important
|
|
55
|
-
* when expanding/shrinking selection. Anchor is always the start or end of the most recent added range.
|
|
56
|
-
* It may be a bit unintuitive when there are multiple ranges in selection.
|
|
57
|
-
*
|
|
58
|
-
* @see #focus
|
|
59
|
-
*/
|
|
60
|
-
get anchor() {
|
|
61
|
-
return this._selection.anchor;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Selection focus. Focus is a position where the selection ends.
|
|
65
|
-
*
|
|
66
|
-
* @see #anchor
|
|
67
|
-
*/
|
|
68
|
-
get focus() {
|
|
69
|
-
return this._selection.focus;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Returns whether the selection is collapsed. Selection is collapsed when there is exactly one range which is
|
|
73
|
-
* collapsed.
|
|
74
|
-
*/
|
|
75
|
-
get isCollapsed() {
|
|
76
|
-
return this._selection.isCollapsed;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Returns number of ranges in selection.
|
|
80
|
-
*/
|
|
81
|
-
get rangeCount() {
|
|
82
|
-
return this._selection.rangeCount;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Specifies whether the {@link #focus} precedes {@link #anchor}.
|
|
86
|
-
*/
|
|
87
|
-
get isBackward() {
|
|
88
|
-
return this._selection.isBackward;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* {@link module:engine/view/editableelement~ViewEditableElement ViewEditableElement} instance that contains this selection, or `null`
|
|
92
|
-
* if the selection is not inside an editable element.
|
|
93
|
-
*/
|
|
94
|
-
get editableElement() {
|
|
95
|
-
return this._selection.editableElement;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Used for the compatibility with the {@link module:engine/view/selection~ViewSelection#isEqual} method.
|
|
99
|
-
*
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
get _ranges() {
|
|
103
|
-
return this._selection._ranges;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Returns an iterable that contains copies of all ranges added to the selection.
|
|
107
|
-
*/
|
|
108
|
-
*getRanges() {
|
|
109
|
-
yield* this._selection.getRanges();
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Returns copy of the first range in the selection. First range is the one which
|
|
113
|
-
* {@link module:engine/view/range~ViewRange#start start} position
|
|
114
|
-
* {@link module:engine/view/position~ViewPosition#isBefore is before} start
|
|
115
|
-
* position of all other ranges (not to confuse with the first range added to the selection).
|
|
116
|
-
* Returns `null` if no ranges are added to selection.
|
|
117
|
-
*/
|
|
118
|
-
getFirstRange() {
|
|
119
|
-
return this._selection.getFirstRange();
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns copy of the last range in the selection. Last range is the one which {@link module:engine/view/range~ViewRange#end end}
|
|
123
|
-
* position {@link module:engine/view/position~ViewPosition#isAfter is after} end position of all other ranges (not to confuse
|
|
124
|
-
* with the last range added to the selection). Returns `null` if no ranges are added to selection.
|
|
125
|
-
*/
|
|
126
|
-
getLastRange() {
|
|
127
|
-
return this._selection.getLastRange();
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Returns copy of the first position in the selection. First position is the position that
|
|
131
|
-
* {@link module:engine/view/position~ViewPosition#isBefore is before} any other position in the selection ranges.
|
|
132
|
-
* Returns `null` if no ranges are added to selection.
|
|
133
|
-
*/
|
|
134
|
-
getFirstPosition() {
|
|
135
|
-
return this._selection.getFirstPosition();
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Returns copy of the last position in the selection. Last position is the position that
|
|
139
|
-
* {@link module:engine/view/position~ViewPosition#isAfter is after} any other position in the selection ranges.
|
|
140
|
-
* Returns `null` if no ranges are added to selection.
|
|
141
|
-
*/
|
|
142
|
-
getLastPosition() {
|
|
143
|
-
return this._selection.getLastPosition();
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns the selected element. {@link module:engine/view/element~ViewElement Element} is considered as selected if there is only
|
|
147
|
-
* one range in the selection, and that range contains exactly one element.
|
|
148
|
-
* Returns `null` if there is no selected element.
|
|
149
|
-
*/
|
|
150
|
-
getSelectedElement() {
|
|
151
|
-
return this._selection.getSelectedElement();
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Checks whether, this selection is equal to given selection. Selections are equal if they have same directions,
|
|
155
|
-
* same number of ranges and all ranges from one selection equal to a range from other selection.
|
|
156
|
-
*
|
|
157
|
-
* @param otherSelection Selection to compare with.
|
|
158
|
-
* @returns `true` if selections are equal, `false` otherwise.
|
|
159
|
-
*/
|
|
160
|
-
isEqual(otherSelection) {
|
|
161
|
-
return this._selection.isEqual(otherSelection);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Checks whether this selection is similar to given selection. Selections are similar if they have same directions, same
|
|
165
|
-
* number of ranges, and all {@link module:engine/view/range~ViewRange#getTrimmed trimmed} ranges from one selection are
|
|
166
|
-
* equal to any trimmed range from other selection.
|
|
167
|
-
*
|
|
168
|
-
* @param otherSelection Selection to compare with.
|
|
169
|
-
* @returns `true` if selections are similar, `false` otherwise.
|
|
170
|
-
*/
|
|
171
|
-
isSimilar(otherSelection) {
|
|
172
|
-
return this._selection.isSimilar(otherSelection);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Converts `ViewDocumentSelection` instance to plain object and returns it.
|
|
176
|
-
*
|
|
177
|
-
* @returns `ViewDocumentSelection` instance converted to plain object.
|
|
178
|
-
*/
|
|
179
|
-
toJSON() {
|
|
180
|
-
return this._selection.toJSON();
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Sets this selection's ranges and direction to the specified location based on the given
|
|
184
|
-
* {@link module:engine/view/selection~ViewSelectable selectable}.
|
|
185
|
-
*
|
|
186
|
-
* ```ts
|
|
187
|
-
* // Sets selection to the given range.
|
|
188
|
-
* const range = writer.createRange( start, end );
|
|
189
|
-
* documentSelection._setTo( range );
|
|
190
|
-
*
|
|
191
|
-
* // Sets selection to given ranges.
|
|
192
|
-
* const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
|
|
193
|
-
* documentSelection._setTo( range );
|
|
194
|
-
*
|
|
195
|
-
* // Sets selection to the other selection.
|
|
196
|
-
* const otherSelection = writer.createSelection();
|
|
197
|
-
* documentSelection._setTo( otherSelection );
|
|
198
|
-
*
|
|
199
|
-
* // Sets collapsed selection at the given position.
|
|
200
|
-
* const position = writer.createPositionAt( root, offset );
|
|
201
|
-
* documentSelection._setTo( position );
|
|
202
|
-
*
|
|
203
|
-
* // Sets collapsed selection at the position of given item and offset.
|
|
204
|
-
* documentSelection._setTo( paragraph, offset );
|
|
205
|
-
* ```
|
|
206
|
-
*
|
|
207
|
-
* Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
|
|
208
|
-
* that element and ends after the last child of that element.
|
|
209
|
-
*
|
|
210
|
-
* ```ts
|
|
211
|
-
* documentSelection._setTo( paragraph, 'in' );
|
|
212
|
-
* ```
|
|
213
|
-
*
|
|
214
|
-
* Creates a range on an {@link module:engine/view/item~ViewItem item} which starts before the item and ends just after the item.
|
|
215
|
-
*
|
|
216
|
-
* ```ts
|
|
217
|
-
* documentSelection._setTo( paragraph, 'on' );
|
|
218
|
-
*
|
|
219
|
-
* // Clears selection. Removes all ranges.
|
|
220
|
-
* documentSelection._setTo( null );
|
|
221
|
-
* ```
|
|
222
|
-
*
|
|
223
|
-
* `Selection#_setTo()` method allow passing additional options (`backward`, `fake` and `label`) as the last argument.
|
|
224
|
-
*
|
|
225
|
-
* ```ts
|
|
226
|
-
* // Sets selection as backward.
|
|
227
|
-
* documentSelection._setTo( range, { backward: true } );
|
|
228
|
-
* ```
|
|
229
|
-
*
|
|
230
|
-
* Fake selection does not render as browser native selection over selected elements and is hidden to the user.
|
|
231
|
-
* This way, no native selection UI artifacts are displayed to the user and selection over elements can be
|
|
232
|
-
* represented in other way, for example by applying proper CSS class.
|
|
233
|
-
*
|
|
234
|
-
* Additionally fake's selection label can be provided. It will be used to des cribe fake selection in DOM
|
|
235
|
-
* (and be properly handled by screen readers).
|
|
236
|
-
*
|
|
237
|
-
* ```ts
|
|
238
|
-
* // Creates fake selection with label.
|
|
239
|
-
* documentSelection._setTo( range, { fake: true, label: 'foo' } );
|
|
240
|
-
* ```
|
|
241
|
-
*
|
|
242
|
-
* @internal
|
|
243
|
-
* @fires change
|
|
244
|
-
*/
|
|
245
|
-
_setTo(...args) {
|
|
246
|
-
this._selection.setTo(...args);
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Moves {@link #focus} to the specified location.
|
|
250
|
-
*
|
|
251
|
-
* The location can be specified in the same form as
|
|
252
|
-
* {@link module:engine/view/view~EditingView#createPositionAt view.createPositionAt()}
|
|
253
|
-
* parameters.
|
|
254
|
-
*
|
|
255
|
-
* @internal
|
|
256
|
-
* @fires change
|
|
257
|
-
* @param offset Offset or one of the flags. Used only when first parameter is a {@link module:engine/view/item~ViewItem view item}.
|
|
258
|
-
*/
|
|
259
|
-
_setFocus(itemOrPosition, offset) {
|
|
260
|
-
this._selection.setFocus(itemOrPosition, offset);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// The magic of type inference using `is` method is centralized in `TypeCheckable` class.
|
|
264
|
-
// Proper overload would interfere with that.
|
|
265
|
-
ViewDocumentSelection.prototype.is = function (type) {
|
|
266
|
-
return type === 'selection' ||
|
|
267
|
-
type == 'documentSelection' ||
|
|
268
|
-
type == 'view:selection' ||
|
|
269
|
-
type == 'view:documentSelection';
|
|
270
|
-
};
|