@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.
Files changed (258) hide show
  1. package/LICENSE.md +1 -1
  2. package/{src → dist}/engineconfig.d.ts +6 -15
  3. package/dist/index-editor.css +38 -15
  4. package/dist/index.css +37 -37
  5. package/dist/index.css.map +1 -1
  6. package/{src → dist}/index.d.ts +0 -1
  7. package/dist/index.js +588 -94
  8. package/dist/index.js.map +1 -1
  9. package/{src → dist}/model/model.d.ts +10 -4
  10. package/{src → dist}/model/selection.d.ts +1 -1
  11. package/{src → dist}/view/downcastwriter.d.ts +3 -2
  12. package/{src → dist}/view/element.d.ts +2 -2
  13. package/{src → dist}/view/matcher.d.ts +4 -2
  14. package/dist/view/styles/background.d.ts +18 -0
  15. package/{src → dist}/view/styles/border.d.ts +0 -12
  16. package/{src → dist}/view/styles/margin.d.ts +0 -13
  17. package/{src → dist}/view/styles/padding.d.ts +0 -13
  18. package/{src → dist}/view/styles/utils.d.ts +12 -0
  19. package/package.json +20 -39
  20. package/src/controller/datacontroller.js +0 -522
  21. package/src/controller/editingcontroller.js +0 -181
  22. package/src/conversion/conversion.js +0 -606
  23. package/src/conversion/conversionhelpers.js +0 -33
  24. package/src/conversion/downcastdispatcher.js +0 -563
  25. package/src/conversion/downcasthelpers.js +0 -2160
  26. package/src/conversion/mapper.js +0 -1050
  27. package/src/conversion/modelconsumable.js +0 -331
  28. package/src/conversion/upcastdispatcher.js +0 -470
  29. package/src/conversion/upcasthelpers.js +0 -952
  30. package/src/conversion/viewconsumable.js +0 -541
  31. package/src/dataprocessor/basichtmlwriter.js +0 -22
  32. package/src/dataprocessor/dataprocessor.js +0 -5
  33. package/src/dataprocessor/htmldataprocessor.js +0 -107
  34. package/src/dataprocessor/htmlwriter.js +0 -5
  35. package/src/dataprocessor/xmldataprocessor.js +0 -127
  36. package/src/dev-utils/model.js +0 -396
  37. package/src/dev-utils/operationreplayer.js +0 -116
  38. package/src/dev-utils/utils.js +0 -122
  39. package/src/dev-utils/view.js +0 -990
  40. package/src/engineconfig.js +0 -5
  41. package/src/index.js +0 -134
  42. package/src/legacyerrors.js +0 -17
  43. package/src/model/batch.js +0 -98
  44. package/src/model/differ.js +0 -1288
  45. package/src/model/document.js +0 -398
  46. package/src/model/documentfragment.js +0 -332
  47. package/src/model/documentselection.js +0 -1026
  48. package/src/model/element.js +0 -323
  49. package/src/model/history.js +0 -206
  50. package/src/model/item.js +0 -5
  51. package/src/model/liveposition.js +0 -93
  52. package/src/model/liverange.js +0 -121
  53. package/src/model/markercollection.js +0 -436
  54. package/src/model/model.js +0 -866
  55. package/src/model/node.js +0 -371
  56. package/src/model/nodelist.js +0 -244
  57. package/src/model/operation/attributeoperation.js +0 -172
  58. package/src/model/operation/detachoperation.js +0 -87
  59. package/src/model/operation/insertoperation.js +0 -153
  60. package/src/model/operation/markeroperation.js +0 -136
  61. package/src/model/operation/mergeoperation.js +0 -184
  62. package/src/model/operation/moveoperation.js +0 -179
  63. package/src/model/operation/nooperation.js +0 -48
  64. package/src/model/operation/operation.js +0 -78
  65. package/src/model/operation/operationfactory.js +0 -44
  66. package/src/model/operation/renameoperation.js +0 -128
  67. package/src/model/operation/rootattributeoperation.js +0 -173
  68. package/src/model/operation/rootoperation.js +0 -106
  69. package/src/model/operation/splitoperation.js +0 -214
  70. package/src/model/operation/transform.js +0 -2211
  71. package/src/model/operation/utils.js +0 -217
  72. package/src/model/position.js +0 -1041
  73. package/src/model/range.js +0 -880
  74. package/src/model/rootelement.js +0 -82
  75. package/src/model/schema.js +0 -1542
  76. package/src/model/selection.js +0 -814
  77. package/src/model/text.js +0 -92
  78. package/src/model/textproxy.js +0 -202
  79. package/src/model/treewalker.js +0 -313
  80. package/src/model/typecheckable.js +0 -16
  81. package/src/model/utils/autoparagraphing.js +0 -63
  82. package/src/model/utils/deletecontent.js +0 -509
  83. package/src/model/utils/getselectedcontent.js +0 -126
  84. package/src/model/utils/insertcontent.js +0 -750
  85. package/src/model/utils/insertobject.js +0 -135
  86. package/src/model/utils/modifyselection.js +0 -187
  87. package/src/model/utils/selection-post-fixer.js +0 -264
  88. package/src/model/writer.js +0 -1318
  89. package/src/view/attributeelement.js +0 -220
  90. package/src/view/containerelement.js +0 -91
  91. package/src/view/datatransfer.js +0 -106
  92. package/src/view/document.js +0 -139
  93. package/src/view/documentfragment.js +0 -251
  94. package/src/view/documentselection.js +0 -270
  95. package/src/view/domconverter.js +0 -1661
  96. package/src/view/downcastwriter.js +0 -1589
  97. package/src/view/editableelement.js +0 -74
  98. package/src/view/element.js +0 -1053
  99. package/src/view/elementdefinition.js +0 -5
  100. package/src/view/emptyelement.js +0 -83
  101. package/src/view/filler.js +0 -161
  102. package/src/view/item.js +0 -5
  103. package/src/view/matcher.js +0 -437
  104. package/src/view/node.js +0 -238
  105. package/src/view/observer/arrowkeysobserver.js +0 -40
  106. package/src/view/observer/bubblingemittermixin.js +0 -215
  107. package/src/view/observer/bubblingeventinfo.js +0 -49
  108. package/src/view/observer/clickobserver.js +0 -26
  109. package/src/view/observer/compositionobserver.js +0 -64
  110. package/src/view/observer/domeventdata.js +0 -63
  111. package/src/view/observer/domeventobserver.js +0 -81
  112. package/src/view/observer/fakeselectionobserver.js +0 -95
  113. package/src/view/observer/focusobserver.js +0 -166
  114. package/src/view/observer/inputobserver.js +0 -236
  115. package/src/view/observer/keyobserver.js +0 -36
  116. package/src/view/observer/mouseobserver.js +0 -26
  117. package/src/view/observer/mutationobserver.js +0 -219
  118. package/src/view/observer/observer.js +0 -92
  119. package/src/view/observer/pointerobserver.js +0 -26
  120. package/src/view/observer/selectionobserver.js +0 -318
  121. package/src/view/observer/tabobserver.js +0 -42
  122. package/src/view/observer/touchobserver.js +0 -26
  123. package/src/view/placeholder.js +0 -285
  124. package/src/view/position.js +0 -341
  125. package/src/view/range.js +0 -451
  126. package/src/view/rawelement.js +0 -115
  127. package/src/view/renderer.js +0 -1148
  128. package/src/view/rooteditableelement.js +0 -78
  129. package/src/view/selection.js +0 -594
  130. package/src/view/styles/background.d.ts +0 -33
  131. package/src/view/styles/background.js +0 -74
  132. package/src/view/styles/border.js +0 -316
  133. package/src/view/styles/margin.js +0 -34
  134. package/src/view/styles/padding.js +0 -34
  135. package/src/view/styles/utils.js +0 -219
  136. package/src/view/stylesmap.js +0 -941
  137. package/src/view/text.js +0 -110
  138. package/src/view/textproxy.js +0 -136
  139. package/src/view/tokenlist.js +0 -194
  140. package/src/view/treewalker.js +0 -389
  141. package/src/view/typecheckable.js +0 -19
  142. package/src/view/uielement.js +0 -194
  143. package/src/view/upcastwriter.js +0 -363
  144. package/src/view/view.js +0 -579
  145. package/theme/placeholder.css +0 -36
  146. package/theme/renderer.css +0 -9
  147. /package/{src → dist}/controller/datacontroller.d.ts +0 -0
  148. /package/{src → dist}/controller/editingcontroller.d.ts +0 -0
  149. /package/{src → dist}/conversion/conversion.d.ts +0 -0
  150. /package/{src → dist}/conversion/conversionhelpers.d.ts +0 -0
  151. /package/{src → dist}/conversion/downcastdispatcher.d.ts +0 -0
  152. /package/{src → dist}/conversion/downcasthelpers.d.ts +0 -0
  153. /package/{src → dist}/conversion/mapper.d.ts +0 -0
  154. /package/{src → dist}/conversion/modelconsumable.d.ts +0 -0
  155. /package/{src → dist}/conversion/upcastdispatcher.d.ts +0 -0
  156. /package/{src → dist}/conversion/upcasthelpers.d.ts +0 -0
  157. /package/{src → dist}/conversion/viewconsumable.d.ts +0 -0
  158. /package/{src → dist}/dataprocessor/basichtmlwriter.d.ts +0 -0
  159. /package/{src → dist}/dataprocessor/dataprocessor.d.ts +0 -0
  160. /package/{src → dist}/dataprocessor/htmldataprocessor.d.ts +0 -0
  161. /package/{src → dist}/dataprocessor/htmlwriter.d.ts +0 -0
  162. /package/{src → dist}/dataprocessor/xmldataprocessor.d.ts +0 -0
  163. /package/{src → dist}/dev-utils/model.d.ts +0 -0
  164. /package/{src → dist}/dev-utils/operationreplayer.d.ts +0 -0
  165. /package/{src → dist}/dev-utils/utils.d.ts +0 -0
  166. /package/{src → dist}/dev-utils/view.d.ts +0 -0
  167. /package/{src → dist}/legacyerrors.d.ts +0 -0
  168. /package/{src → dist}/model/batch.d.ts +0 -0
  169. /package/{src → dist}/model/differ.d.ts +0 -0
  170. /package/{src → dist}/model/document.d.ts +0 -0
  171. /package/{src → dist}/model/documentfragment.d.ts +0 -0
  172. /package/{src → dist}/model/documentselection.d.ts +0 -0
  173. /package/{src → dist}/model/element.d.ts +0 -0
  174. /package/{src → dist}/model/history.d.ts +0 -0
  175. /package/{src → dist}/model/item.d.ts +0 -0
  176. /package/{src → dist}/model/liveposition.d.ts +0 -0
  177. /package/{src → dist}/model/liverange.d.ts +0 -0
  178. /package/{src → dist}/model/markercollection.d.ts +0 -0
  179. /package/{src → dist}/model/node.d.ts +0 -0
  180. /package/{src → dist}/model/nodelist.d.ts +0 -0
  181. /package/{src → dist}/model/operation/attributeoperation.d.ts +0 -0
  182. /package/{src → dist}/model/operation/detachoperation.d.ts +0 -0
  183. /package/{src → dist}/model/operation/insertoperation.d.ts +0 -0
  184. /package/{src → dist}/model/operation/markeroperation.d.ts +0 -0
  185. /package/{src → dist}/model/operation/mergeoperation.d.ts +0 -0
  186. /package/{src → dist}/model/operation/moveoperation.d.ts +0 -0
  187. /package/{src → dist}/model/operation/nooperation.d.ts +0 -0
  188. /package/{src → dist}/model/operation/operation.d.ts +0 -0
  189. /package/{src → dist}/model/operation/operationfactory.d.ts +0 -0
  190. /package/{src → dist}/model/operation/renameoperation.d.ts +0 -0
  191. /package/{src → dist}/model/operation/rootattributeoperation.d.ts +0 -0
  192. /package/{src → dist}/model/operation/rootoperation.d.ts +0 -0
  193. /package/{src → dist}/model/operation/splitoperation.d.ts +0 -0
  194. /package/{src → dist}/model/operation/transform.d.ts +0 -0
  195. /package/{src → dist}/model/operation/utils.d.ts +0 -0
  196. /package/{src → dist}/model/position.d.ts +0 -0
  197. /package/{src → dist}/model/range.d.ts +0 -0
  198. /package/{src → dist}/model/rootelement.d.ts +0 -0
  199. /package/{src → dist}/model/schema.d.ts +0 -0
  200. /package/{src → dist}/model/text.d.ts +0 -0
  201. /package/{src → dist}/model/textproxy.d.ts +0 -0
  202. /package/{src → dist}/model/treewalker.d.ts +0 -0
  203. /package/{src → dist}/model/typecheckable.d.ts +0 -0
  204. /package/{src → dist}/model/utils/autoparagraphing.d.ts +0 -0
  205. /package/{src → dist}/model/utils/deletecontent.d.ts +0 -0
  206. /package/{src → dist}/model/utils/getselectedcontent.d.ts +0 -0
  207. /package/{src → dist}/model/utils/insertcontent.d.ts +0 -0
  208. /package/{src → dist}/model/utils/insertobject.d.ts +0 -0
  209. /package/{src → dist}/model/utils/modifyselection.d.ts +0 -0
  210. /package/{src → dist}/model/utils/selection-post-fixer.d.ts +0 -0
  211. /package/{src → dist}/model/writer.d.ts +0 -0
  212. /package/{src → dist}/view/attributeelement.d.ts +0 -0
  213. /package/{src → dist}/view/containerelement.d.ts +0 -0
  214. /package/{src → dist}/view/datatransfer.d.ts +0 -0
  215. /package/{src → dist}/view/document.d.ts +0 -0
  216. /package/{src → dist}/view/documentfragment.d.ts +0 -0
  217. /package/{src → dist}/view/documentselection.d.ts +0 -0
  218. /package/{src → dist}/view/domconverter.d.ts +0 -0
  219. /package/{src → dist}/view/editableelement.d.ts +0 -0
  220. /package/{src → dist}/view/elementdefinition.d.ts +0 -0
  221. /package/{src → dist}/view/emptyelement.d.ts +0 -0
  222. /package/{src → dist}/view/filler.d.ts +0 -0
  223. /package/{src → dist}/view/item.d.ts +0 -0
  224. /package/{src → dist}/view/node.d.ts +0 -0
  225. /package/{src → dist}/view/observer/arrowkeysobserver.d.ts +0 -0
  226. /package/{src → dist}/view/observer/bubblingemittermixin.d.ts +0 -0
  227. /package/{src → dist}/view/observer/bubblingeventinfo.d.ts +0 -0
  228. /package/{src → dist}/view/observer/clickobserver.d.ts +0 -0
  229. /package/{src → dist}/view/observer/compositionobserver.d.ts +0 -0
  230. /package/{src → dist}/view/observer/domeventdata.d.ts +0 -0
  231. /package/{src → dist}/view/observer/domeventobserver.d.ts +0 -0
  232. /package/{src → dist}/view/observer/fakeselectionobserver.d.ts +0 -0
  233. /package/{src → dist}/view/observer/focusobserver.d.ts +0 -0
  234. /package/{src → dist}/view/observer/inputobserver.d.ts +0 -0
  235. /package/{src → dist}/view/observer/keyobserver.d.ts +0 -0
  236. /package/{src → dist}/view/observer/mouseobserver.d.ts +0 -0
  237. /package/{src → dist}/view/observer/mutationobserver.d.ts +0 -0
  238. /package/{src → dist}/view/observer/observer.d.ts +0 -0
  239. /package/{src → dist}/view/observer/pointerobserver.d.ts +0 -0
  240. /package/{src → dist}/view/observer/selectionobserver.d.ts +0 -0
  241. /package/{src → dist}/view/observer/tabobserver.d.ts +0 -0
  242. /package/{src → dist}/view/observer/touchobserver.d.ts +0 -0
  243. /package/{src → dist}/view/placeholder.d.ts +0 -0
  244. /package/{src → dist}/view/position.d.ts +0 -0
  245. /package/{src → dist}/view/range.d.ts +0 -0
  246. /package/{src → dist}/view/rawelement.d.ts +0 -0
  247. /package/{src → dist}/view/renderer.d.ts +0 -0
  248. /package/{src → dist}/view/rooteditableelement.d.ts +0 -0
  249. /package/{src → dist}/view/selection.d.ts +0 -0
  250. /package/{src → dist}/view/stylesmap.d.ts +0 -0
  251. /package/{src → dist}/view/text.d.ts +0 -0
  252. /package/{src → dist}/view/textproxy.d.ts +0 -0
  253. /package/{src → dist}/view/tokenlist.d.ts +0 -0
  254. /package/{src → dist}/view/treewalker.d.ts +0 -0
  255. /package/{src → dist}/view/typecheckable.d.ts +0 -0
  256. /package/{src → dist}/view/uielement.d.ts +0 -0
  257. /package/{src → dist}/view/upcastwriter.d.ts +0 -0
  258. /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
- };