@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
package/src/view/range.js DELETED
@@ -1,451 +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/range
7
- */
8
- import { ViewTypeCheckable } from './typecheckable.js';
9
- import { ViewPosition } from './position.js';
10
- import { ViewTreeWalker } from './treewalker.js';
11
- /**
12
- * Range in the view tree. A range is represented by its start and end {@link module:engine/view/position~ViewPosition positions}.
13
- *
14
- * In order to create a new position instance use the `createPosition*()` factory methods available in:
15
- *
16
- * * {@link module:engine/view/view~EditingView}
17
- * * {@link module:engine/view/downcastwriter~ViewDowncastWriter}
18
- * * {@link module:engine/view/upcastwriter~ViewUpcastWriter}
19
- */
20
- export class ViewRange extends ViewTypeCheckable {
21
- /**
22
- * Start position.
23
- */
24
- start;
25
- /**
26
- * End position.
27
- */
28
- end;
29
- /**
30
- * Creates a range spanning from `start` position to `end` position.
31
- *
32
- * **Note:** Constructor creates it's own {@link module:engine/view/position~ViewPosition} instances basing on passed values.
33
- *
34
- * @param start Start position.
35
- * @param end End position. If not set, range will be collapsed at the `start` position.
36
- */
37
- constructor(start, end = null) {
38
- super();
39
- this.start = start.clone();
40
- this.end = end ? end.clone() : start.clone();
41
- }
42
- /**
43
- * Iterable interface.
44
- *
45
- * Iterates over all {@link module:engine/view/item~ViewItem view items} that are in this range and returns
46
- * them together with additional information like length or {@link module:engine/view/position~ViewPosition positions},
47
- * grouped as {@link module:engine/view/treewalker~ViewTreeWalkerValue}.
48
- *
49
- * This iterator uses {@link module:engine/view/treewalker~ViewTreeWalker TreeWalker} with `boundaries` set to this range and
50
- * `ignoreElementEnd` option
51
- * set to `true`.
52
- */
53
- *[Symbol.iterator]() {
54
- yield* new ViewTreeWalker({ boundaries: this, ignoreElementEnd: true });
55
- }
56
- /**
57
- * Returns whether the range is collapsed, that is it start and end positions are equal.
58
- */
59
- get isCollapsed() {
60
- return this.start.isEqual(this.end);
61
- }
62
- /**
63
- * Returns whether this range is flat, that is if {@link module:engine/view/range~ViewRange#start start} position and
64
- * {@link module:engine/view/range~ViewRange#end end} position are in the same
65
- * {@link module:engine/view/position~ViewPosition#parent parent}.
66
- */
67
- get isFlat() {
68
- return this.start.parent === this.end.parent;
69
- }
70
- /**
71
- * Range root element.
72
- */
73
- get root() {
74
- return this.start.root;
75
- }
76
- /**
77
- * Creates a maximal range that has the same content as this range but is expanded in both ways (at the beginning
78
- * and at the end).
79
- *
80
- * For example:
81
- *
82
- * ```html
83
- * <p>Foo</p><p><b>{Bar}</b></p> -> <p>Foo</p>[<p><b>Bar</b>]</p>
84
- * <p><b>foo</b>{bar}<span></span></p> -> <p><b>foo[</b>bar<span></span>]</p>
85
- * ```
86
- *
87
- * Note that in the sample above:
88
- *
89
- * - `<p>` have type of {@link module:engine/view/containerelement~ViewContainerElement},
90
- * - `<b>` have type of {@link module:engine/view/attributeelement~ViewAttributeElement},
91
- * - `<span>` have type of {@link module:engine/view/uielement~ViewUIElement}.
92
- *
93
- * @returns Enlarged range.
94
- */
95
- getEnlarged() {
96
- let start = this.start.getLastMatchingPosition(enlargeTrimSkip, { direction: 'backward' });
97
- let end = this.end.getLastMatchingPosition(enlargeTrimSkip);
98
- // Fix positions, in case if they are in Text node.
99
- if (start.parent.is('$text') && start.isAtStart) {
100
- start = ViewPosition._createBefore(start.parent);
101
- }
102
- if (end.parent.is('$text') && end.isAtEnd) {
103
- end = ViewPosition._createAfter(end.parent);
104
- }
105
- return new ViewRange(start, end);
106
- }
107
- /**
108
- * Creates a minimum range that has the same content as this range but is trimmed in both ways (at the beginning
109
- * and at the end).
110
- *
111
- * For example:
112
- *
113
- * ```html
114
- * <p>Foo</p>[<p><b>Bar</b>]</p> -> <p>Foo</p><p><b>{Bar}</b></p>
115
- * <p><b>foo[</b>bar<span></span>]</p> -> <p><b>foo</b>{bar}<span></span></p>
116
- * ```
117
- *
118
- * Note that in the sample above:
119
- *
120
- * - `<p>` have type of {@link module:engine/view/containerelement~ViewContainerElement},
121
- * - `<b>` have type of {@link module:engine/view/attributeelement~ViewAttributeElement},
122
- * - `<span>` have type of {@link module:engine/view/uielement~ViewUIElement}.
123
- *
124
- * @returns Shrunk range.
125
- */
126
- getTrimmed() {
127
- let start = this.start.getLastMatchingPosition(enlargeTrimSkip);
128
- if (start.isAfter(this.end) || start.isEqual(this.end)) {
129
- return new ViewRange(start, start);
130
- }
131
- let end = this.end.getLastMatchingPosition(enlargeTrimSkip, { direction: 'backward' });
132
- const nodeAfterStart = start.nodeAfter;
133
- const nodeBeforeEnd = end.nodeBefore;
134
- // Because TreeWalker prefers positions next to text node, we need to move them manually into these text nodes.
135
- if (nodeAfterStart && nodeAfterStart.is('$text')) {
136
- start = new ViewPosition(nodeAfterStart, 0);
137
- }
138
- if (nodeBeforeEnd && nodeBeforeEnd.is('$text')) {
139
- end = new ViewPosition(nodeBeforeEnd, nodeBeforeEnd.data.length);
140
- }
141
- return new ViewRange(start, end);
142
- }
143
- /**
144
- * Two ranges are equal if their start and end positions are equal.
145
- *
146
- * @param otherRange Range to compare with.
147
- * @returns `true` if ranges are equal, `false` otherwise
148
- */
149
- isEqual(otherRange) {
150
- return this == otherRange || (this.start.isEqual(otherRange.start) && this.end.isEqual(otherRange.end));
151
- }
152
- /**
153
- * Checks whether this range contains given {@link module:engine/view/position~ViewPosition position}.
154
- *
155
- * @param position Position to check.
156
- * @returns `true` if given {@link module:engine/view/position~ViewPosition position} is contained in this range, `false` otherwise.
157
- */
158
- containsPosition(position) {
159
- return position.isAfter(this.start) && position.isBefore(this.end);
160
- }
161
- /**
162
- * Checks whether this range contains given {@link module:engine/view/range~ViewRange range}.
163
- *
164
- * @param otherRange Range to check.
165
- * @param loose Whether the check is loose or strict. If the check is strict (`false`), compared range cannot
166
- * start or end at the same position as this range boundaries. If the check is loose (`true`), compared range can start, end or
167
- * even be equal to this range. Note that collapsed ranges are always compared in strict mode.
168
- * @returns `true` if given {@link module:engine/view/range~ViewRange range} boundaries are contained by this range, `false`
169
- * otherwise.
170
- */
171
- containsRange(otherRange, loose = false) {
172
- if (otherRange.isCollapsed) {
173
- loose = false;
174
- }
175
- const containsStart = this.containsPosition(otherRange.start) || (loose && this.start.isEqual(otherRange.start));
176
- const containsEnd = this.containsPosition(otherRange.end) || (loose && this.end.isEqual(otherRange.end));
177
- return containsStart && containsEnd;
178
- }
179
- /**
180
- * Computes which part(s) of this {@link module:engine/view/range~ViewRange range} is not a part of given
181
- * {@link module:engine/view/range~ViewRange range}.
182
- * Returned array contains zero, one or two {@link module:engine/view/range~ViewRange ranges}.
183
- *
184
- * Examples:
185
- *
186
- * ```ts
187
- * let foo = downcastWriter.createText( 'foo' );
188
- * let img = downcastWriter.createContainerElement( 'img' );
189
- * let bar = downcastWriter.createText( 'bar' );
190
- * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
191
- *
192
- * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
193
- * let otherRange = view.createRange( // "oo", img, "ba" are in range.
194
- * view.createPositionAt( foo, 1 ),
195
- * view.createPositionAt( bar, 2 )
196
- * );
197
- * let transformed = range.getDifference( otherRange );
198
- * // transformed array has no ranges because `otherRange` contains `range`
199
- *
200
- * otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
201
- * transformed = range.getDifference( otherRange );
202
- * // transformed array has one range: from ( p, 2 ) to ( bar, 1 )
203
- *
204
- * otherRange = view.createRange( view.createPositionAt( p, 1 ), view.createPositionAt( p, 2 ) ); // img is in range.
205
- * transformed = range.getDifference( otherRange );
206
- * // transformed array has two ranges: from ( foo, 1 ) to ( p, 1 ) and from ( p, 2 ) to ( bar, 1 )
207
- * ```
208
- *
209
- * @param otherRange Range to differentiate against.
210
- * @returns The difference between ranges.
211
- */
212
- getDifference(otherRange) {
213
- const ranges = [];
214
- if (this.isIntersecting(otherRange)) {
215
- // Ranges intersect.
216
- if (this.containsPosition(otherRange.start)) {
217
- // Given range start is inside this range. This means that we have to
218
- // add shrunken range - from the start to the middle of this range.
219
- ranges.push(new ViewRange(this.start, otherRange.start));
220
- }
221
- if (this.containsPosition(otherRange.end)) {
222
- // Given range end is inside this range. This means that we have to
223
- // add shrunken range - from the middle of this range to the end.
224
- ranges.push(new ViewRange(otherRange.end, this.end));
225
- }
226
- }
227
- else {
228
- // Ranges do not intersect, return the original range.
229
- ranges.push(this.clone());
230
- }
231
- return ranges;
232
- }
233
- /**
234
- * Returns an intersection of this {@link module:engine/view/range~ViewRange range}
235
- * and given {@link module:engine/view/range~ViewRange range}.
236
- * Intersection is a common part of both of those ranges. If ranges has no common part, returns `null`.
237
- *
238
- * Examples:
239
- *
240
- * ```ts
241
- * let foo = downcastWriter.createText( 'foo' );
242
- * let img = downcastWriter.createContainerElement( 'img' );
243
- * let bar = downcastWriter.createText( 'bar' );
244
- * let p = downcastWriter.createContainerElement( 'p', null, [ foo, img, bar ] );
245
- *
246
- * let range = view.createRange( view.createPositionAt( foo, 2 ), view.createPositionAt( bar, 1 ); // "o", img, "b" are in range.
247
- * let otherRange = view.createRange( view.createPositionAt( foo, 1 ), view.createPositionAt( p, 2 ); // "oo", img are in range.
248
- * let transformed = range.getIntersection( otherRange ); // range from ( foo, 1 ) to ( p, 2 ).
249
- *
250
- * otherRange = view.createRange( view.createPositionAt( bar, 1 ), view.createPositionAt( bar, 3 ); "ar" is in range.
251
- * transformed = range.getIntersection( otherRange ); // null - no common part.
252
- * ```
253
- *
254
- * @param otherRange Range to check for intersection.
255
- * @returns A common part of given ranges or `null` if ranges have no common part.
256
- */
257
- getIntersection(otherRange) {
258
- if (this.isIntersecting(otherRange)) {
259
- // Ranges intersect, so a common range will be returned.
260
- // At most, it will be same as this range.
261
- let commonRangeStart = this.start;
262
- let commonRangeEnd = this.end;
263
- if (this.containsPosition(otherRange.start)) {
264
- // Given range start is inside this range. This means thaNt we have to
265
- // shrink common range to the given range start.
266
- commonRangeStart = otherRange.start;
267
- }
268
- if (this.containsPosition(otherRange.end)) {
269
- // Given range end is inside this range. This means that we have to
270
- // shrink common range to the given range end.
271
- commonRangeEnd = otherRange.end;
272
- }
273
- return new ViewRange(commonRangeStart, commonRangeEnd);
274
- }
275
- // Ranges do not intersect, so they do not have common part.
276
- return null;
277
- }
278
- /**
279
- * Creates a {@link module:engine/view/treewalker~ViewTreeWalker TreeWalker} instance with this range as a boundary.
280
- *
281
- * @param options Object with configuration options. See {@link module:engine/view/treewalker~ViewTreeWalker}.
282
- */
283
- getWalker(options = {}) {
284
- options.boundaries = this;
285
- return new ViewTreeWalker(options);
286
- }
287
- /**
288
- * Returns a {@link module:engine/view/node~ViewNode} or {@link module:engine/view/documentfragment~ViewDocumentFragment}
289
- * which is a common ancestor of range's both ends (in which the entire range is contained).
290
- */
291
- getCommonAncestor() {
292
- return this.start.getCommonAncestor(this.end);
293
- }
294
- /**
295
- * Returns an {@link module:engine/view/element~ViewElement Element} contained by the range.
296
- * The element will be returned when it is the **only** node within the range and **fully–contained**
297
- * at the same time.
298
- */
299
- getContainedElement() {
300
- if (this.isCollapsed) {
301
- return null;
302
- }
303
- let nodeAfterStart = this.start.nodeAfter;
304
- let nodeBeforeEnd = this.end.nodeBefore;
305
- // Handle the situation when the range position is at the beginning / at the end of a text node.
306
- // In such situation `.nodeAfter` and `.nodeBefore` are `null` but the range still might be spanning
307
- // over one element.
308
- //
309
- // <p>Foo{<span class="widget"></span>}bar</p> vs <p>Foo[<span class="widget"></span>]bar</p>
310
- //
311
- // These are basically the same range, only the difference is if the range position is at
312
- // at the end/at the beginning of a text node or just before/just after the text node.
313
- //
314
- if (this.start.parent.is('$text') && this.start.isAtEnd && this.start.parent.nextSibling) {
315
- nodeAfterStart = this.start.parent.nextSibling;
316
- }
317
- if (this.end.parent.is('$text') && this.end.isAtStart && this.end.parent.previousSibling) {
318
- nodeBeforeEnd = this.end.parent.previousSibling;
319
- }
320
- if (nodeAfterStart && nodeAfterStart.is('element') && nodeAfterStart === nodeBeforeEnd) {
321
- return nodeAfterStart;
322
- }
323
- return null;
324
- }
325
- /**
326
- * Clones this range.
327
- */
328
- clone() {
329
- return new ViewRange(this.start, this.end);
330
- }
331
- /**
332
- * Returns an iterator that iterates over all {@link module:engine/view/item~ViewItem view items} that are in this range and returns
333
- * them.
334
- *
335
- * This method uses {@link module:engine/view/treewalker~ViewTreeWalker} with `boundaries` set to this range
336
- * and `ignoreElementEnd` option set to `true`. However it returns only {@link module:engine/view/item~ViewItem items},
337
- * not {@link module:engine/view/treewalker~ViewTreeWalkerValue}.
338
- *
339
- * You may specify additional options for the tree walker. See {@link module:engine/view/treewalker~ViewTreeWalker} for
340
- * a full list of available options.
341
- *
342
- * @param options Object with configuration options. See {@link module:engine/view/treewalker~ViewTreeWalker}.
343
- */
344
- *getItems(options = {}) {
345
- options.boundaries = this;
346
- options.ignoreElementEnd = true;
347
- const treeWalker = new ViewTreeWalker(options);
348
- for (const value of treeWalker) {
349
- yield value.item;
350
- }
351
- }
352
- /**
353
- * Returns an iterator that iterates over all {@link module:engine/view/position~ViewPosition positions} that are boundaries or
354
- * contained in this range.
355
- *
356
- * This method uses {@link module:engine/view/treewalker~ViewTreeWalker} with `boundaries` set to this range. However it returns only
357
- * {@link module:engine/view/position~ViewPosition positions}, not {@link module:engine/view/treewalker~ViewTreeWalkerValue}.
358
- *
359
- * You may specify additional options for the tree walker. See {@link module:engine/view/treewalker~ViewTreeWalker} for
360
- * a full list of available options.
361
- *
362
- * @param options Object with configuration options. See {@link module:engine/view/treewalker~ViewTreeWalker}.
363
- */
364
- *getPositions(options = {}) {
365
- options.boundaries = this;
366
- const treeWalker = new ViewTreeWalker(options);
367
- yield treeWalker.position;
368
- for (const value of treeWalker) {
369
- yield value.nextPosition;
370
- }
371
- }
372
- /**
373
- * Checks and returns whether this range intersects with the given range.
374
- *
375
- * @param otherRange Range to compare with.
376
- * @returns True if ranges intersect.
377
- */
378
- isIntersecting(otherRange) {
379
- return this.start.isBefore(otherRange.end) && this.end.isAfter(otherRange.start);
380
- }
381
- /**
382
- * Converts `ViewRange` instance to plain object and returns it.
383
- *
384
- * @returns `ViewRange` instance converted to plain object.
385
- */
386
- toJSON() {
387
- return {
388
- start: this.start.toJSON(),
389
- end: this.end.toJSON()
390
- };
391
- }
392
- /**
393
- * Creates a range from the given parents and offsets.
394
- *
395
- * @internal
396
- * @param startElement Start position parent element.
397
- * @param startOffset Start position offset.
398
- * @param endElement End position parent element.
399
- * @param endOffset End position offset.
400
- * @returns Created range.
401
- */
402
- static _createFromParentsAndOffsets(startElement, startOffset, endElement, endOffset) {
403
- return new this(new ViewPosition(startElement, startOffset), new ViewPosition(endElement, endOffset));
404
- }
405
- /**
406
- * Creates a new range, spreading from specified {@link module:engine/view/position~ViewPosition position} to a position moved by
407
- * given `shift`. If `shift` is a negative value, shifted position is treated as the beginning of the range.
408
- *
409
- * @internal
410
- * @param position Beginning of the range.
411
- * @param shift How long the range should be.
412
- */
413
- static _createFromPositionAndShift(position, shift) {
414
- const start = position;
415
- const end = position.getShiftedBy(shift);
416
- return shift > 0 ? new this(start, end) : new this(end, start);
417
- }
418
- /**
419
- * Creates a range inside an {@link module:engine/view/element~ViewElement element} which starts before the first child of
420
- * that element and ends after the last child of that element.
421
- *
422
- * @internal
423
- * @param element Element which is a parent for the range.
424
- */
425
- static _createIn(element) {
426
- return this._createFromParentsAndOffsets(element, 0, element, element.childCount);
427
- }
428
- /**
429
- * Creates a range that starts before given {@link module:engine/view/item~ViewItem view item} and ends after it.
430
- *
431
- * @internal
432
- */
433
- static _createOn(item) {
434
- const size = item.is('$textProxy') ? item.offsetSize : 1;
435
- return this._createFromPositionAndShift(ViewPosition._createBefore(item), size);
436
- }
437
- }
438
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
439
- // Proper overload would interfere with that.
440
- ViewRange.prototype.is = function (type) {
441
- return type === 'range' || type === 'view:range';
442
- };
443
- /**
444
- * Function used by getEnlarged and getTrimmed methods.
445
- */
446
- function enlargeTrimSkip(value) {
447
- if (value.item.is('attributeElement') || value.item.is('uiElement')) {
448
- return true;
449
- }
450
- return false;
451
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /* eslint-disable @typescript-eslint/no-unused-vars */
6
- /**
7
- * @module engine/view/rawelement
8
- */
9
- import { ViewElement } from './element.js';
10
- import { ViewNode } from './node.js';
11
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
12
- /**
13
- * The raw element class.
14
- *
15
- * The raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or
16
- * even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures
17
- * in the editor content without, for instance, worrying about compatibility with other editor features.
18
- * Raw elements are a perfect tool for integration with external frameworks and data sources.
19
- *
20
- * Unlike {@link module:engine/view/uielement~ViewUIElement UI elements}, raw elements act like real editor
21
- * content (similar to {@link module:engine/view/containerelement~ViewContainerElement} or
22
- * {@link module:engine/view/emptyelement~ViewEmptyElement}), they are considered by the editor selection and
23
- * {@link module:widget/utils~toWidget they can work as widgets}.
24
- *
25
- * To create a new raw element, use the
26
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createRawElement `downcastWriter#createRawElement()`} method.
27
- */
28
- export class ViewRawElement extends ViewElement {
29
- /**
30
- * Creates a new instance of a raw element.
31
- *
32
- * Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} when the `children`
33
- * parameter is passed to inform that the usage of `ViewRawElement` is incorrect (adding child nodes to `ViewRawElement` is forbidden).
34
- *
35
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#createRawElement
36
- * @internal
37
- * @param document The document instance to which this element belongs.
38
- * @param name Node name.
39
- * @param attrs Collection of attributes.
40
- * @param children A list of nodes to be inserted into created element.
41
- */
42
- constructor(document, name, attrs, children) {
43
- super(document, name, attrs, children);
44
- // Returns `null` because filler is not needed for raw elements.
45
- this.getFillerOffset = getFillerOffset;
46
- }
47
- /**
48
- * Converts `ViewRawElement` instance to plain object and returns it.
49
- *
50
- * @returns `ViewRawElement` instance converted to plain object.
51
- */
52
- toJSON() {
53
- const json = super.toJSON();
54
- json.type = 'RawElement';
55
- return json;
56
- }
57
- /**
58
- * Overrides the {@link module:engine/view/element~ViewElement#_insertChild} method.
59
- * Throws the `view-rawelement-cannot-add` {@link module:utils/ckeditorerror~CKEditorError CKEditorError} to prevent
60
- * adding any child nodes to a raw element.
61
- *
62
- * @internal
63
- */
64
- _insertChild(index, items) {
65
- if (items && (items instanceof ViewNode || Array.from(items).length > 0)) {
66
- /**
67
- * Cannot add children to a {@link module:engine/view/rawelement~ViewRawElement} instance.
68
- *
69
- * @error view-rawelement-cannot-add
70
- */
71
- throw new CKEditorError('view-rawelement-cannot-add', [this, items]);
72
- }
73
- return 0;
74
- }
75
- /**
76
- * This allows rendering the children of a {@link module:engine/view/rawelement~ViewRawElement} on the DOM level.
77
- * This method is called by the {@link module:engine/view/domconverter~ViewDomConverter} with the raw DOM element
78
- * passed as an argument, leaving the number and shape of the children up to the integrator.
79
- *
80
- * This method **must be defined** for the raw element to work:
81
- *
82
- * ```ts
83
- * const myRawElement = downcastWriter.createRawElement( 'div' );
84
- *
85
- * myRawElement.render = function( domElement, domConverter ) {
86
- * domConverter.setContentOf( domElement, '<b>This is the raw content of myRawElement.</b>' );
87
- * };
88
- * ```
89
- *
90
- * @param domElement The native DOM element representing the raw view element.
91
- * @param domConverter Instance of the ViewDomConverter used to optimize the output.
92
- */
93
- render(domElement, domConverter) { }
94
- }
95
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
96
- // Proper overload would interfere with that.
97
- ViewRawElement.prototype.is = function (type, name) {
98
- if (!name) {
99
- return type === 'rawElement' || type === 'view:rawElement' ||
100
- // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
101
- type === this.name || type === 'view:' + this.name ||
102
- type === 'element' || type === 'view:element' ||
103
- type === 'node' || type === 'view:node';
104
- }
105
- else {
106
- return name === this.name && (type === 'rawElement' || type === 'view:rawElement' ||
107
- type === 'element' || type === 'view:element');
108
- }
109
- };
110
- /**
111
- * Returns `null` because block filler is not needed for raw elements.
112
- */
113
- function getFillerOffset() {
114
- return null;
115
- }