@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/model/text.js DELETED
@@ -1,92 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module engine/model/text
7
- */
8
- import { ModelNode } from './node.js';
9
- // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
10
- /**
11
- * Model text node. Type of {@link module:engine/model/node~ModelNode node} that
12
- * contains {@link module:engine/model/text~ModelText#data text data}.
13
- *
14
- * **Important:** see {@link module:engine/model/node~ModelNode} to read about restrictions using `Text` and `Node` API.
15
- *
16
- * **Note:** keep in mind that `Text` instances might indirectly got removed from model tree when model is changed.
17
- * This happens when {@link module:engine/model/writer~ModelWriter model writer} is used to change model and the text node is merged with
18
- * another text node. Then, both text nodes are removed and a new text node is inserted into the model. Because of
19
- * this behavior, keeping references to `Text` is not recommended. Instead, consider creating
20
- * {@link module:engine/model/liveposition~ModelLivePosition live position} placed before the text node.
21
- */
22
- export class ModelText extends ModelNode {
23
- /**
24
- * Text data contained in this text node.
25
- *
26
- * @internal
27
- */
28
- _data;
29
- /**
30
- * Creates a text node.
31
- *
32
- * **Note:** Constructor of this class shouldn't be used directly in the code.
33
- * Use the {@link module:engine/model/writer~ModelWriter#createText} method instead.
34
- *
35
- * @internal
36
- * @param data Node's text.
37
- * @param attrs Node's attributes. See {@link module:utils/tomap~toMap} for a list of accepted values.
38
- */
39
- constructor(data, attrs) {
40
- super(attrs);
41
- this._data = data || '';
42
- }
43
- /**
44
- * @inheritDoc
45
- */
46
- get offsetSize() {
47
- return this.data.length;
48
- }
49
- /**
50
- * Returns a text data contained in the node.
51
- */
52
- get data() {
53
- return this._data;
54
- }
55
- /**
56
- * Converts `Text` instance to plain object and returns it.
57
- *
58
- * @returns`Text` instance converted to plain object.
59
- */
60
- toJSON() {
61
- const json = super.toJSON();
62
- json.data = this.data;
63
- return json;
64
- }
65
- /**
66
- * Creates a copy of this text node and returns it. Created text node has same text data and attributes as original text node.
67
- *
68
- * @internal
69
- * @returns `Text` instance created using given plain object.
70
- */
71
- _clone() {
72
- return new ModelText(this.data, this.getAttributes());
73
- }
74
- /**
75
- * Creates a `Text` instance from given plain object (i.e. parsed JSON string).
76
- *
77
- * @param json Plain object to be converted to `Text`.
78
- * @returns `Text` instance created using given plain object.
79
- */
80
- static fromJSON(json) {
81
- return new ModelText(json.data, json.attributes);
82
- }
83
- }
84
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
85
- // Proper overload would interfere with that.
86
- ModelText.prototype.is = function (type) {
87
- return type === '$text' || type === 'model:$text' ||
88
- // This are legacy values kept for backward compatibility.
89
- type === 'text' || type === 'model:text' ||
90
- // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
91
- type === 'node' || type === 'model:node';
92
- };
@@ -1,202 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module engine/model/textproxy
7
- */
8
- import { ModelTypeCheckable } from './typecheckable.js';
9
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
10
- // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
11
- /**
12
- * `ModelTextProxy` represents a part of {@link module:engine/model/text~ModelText text node}.
13
- *
14
- * Since {@link module:engine/model/position~ModelPosition positions} can be placed between characters of a text node,
15
- * {@link module:engine/model/range~ModelRange ranges} may contain only parts of text nodes.
16
- * When {@link module:engine/model/range~ModelRange#getItems getting items}
17
- * contained in such range, we need to represent a part of that text node, since returning the whole text node would be incorrect.
18
- * `ModelTextProxy` solves this issue.
19
- *
20
- * `ModelTextProxy` has an API similar to {@link module:engine/model/text~ModelText Text} and allows to do
21
- * most of the common tasks performed on model nodes.
22
- *
23
- * **Note:** Some `ModelTextProxy` instances may represent whole text node, not just a part of it.
24
- * See {@link module:engine/model/textproxy~ModelTextProxy#isPartial}.
25
- *
26
- * **Note:** `ModelTextProxy` is not an instance of {@link module:engine/model/node~ModelNode node}. Keep this in mind when using it as a
27
- * parameter of methods.
28
- *
29
- * **Note:** `ModelTextProxy` is a readonly interface. If you want to perform changes on model data represented by a `ModelTextProxy`
30
- * use {@link module:engine/model/writer~ModelWriter model writer API}.
31
- *
32
- * **Note:** `ModelTextProxy` instances are created on the fly, basing on the current state of model. Because of this, it is
33
- * highly unrecommended to store references to `ModelTextProxy` instances. `ModelTextProxy` instances are not refreshed when
34
- * model changes, so they might get invalidated. Instead, consider creating {@link module:engine/model/liveposition~ModelLivePosition live
35
- * position}.
36
- *
37
- * `ModelTextProxy` instances are created by {@link module:engine/model/treewalker~ModelTreeWalker model tree walker}.
38
- * You should not need to create an instance of this class by your own.
39
- */
40
- export class ModelTextProxy extends ModelTypeCheckable {
41
- /**
42
- * Text node which part is represented by this text proxy.
43
- */
44
- textNode;
45
- /**
46
- * Text data represented by this text proxy.
47
- */
48
- data;
49
- /**
50
- * Offset in {@link module:engine/model/textproxy~ModelTextProxy#textNode text node} from which the text proxy starts.
51
- */
52
- offsetInText;
53
- /**
54
- * Creates a text proxy.
55
- *
56
- * @internal
57
- * @param textNode Text node which part is represented by this text proxy.
58
- * @param offsetInText Offset in {@link module:engine/model/textproxy~ModelTextProxy#textNode text node} from which the text proxy
59
- * starts.
60
- * @param length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
61
- */
62
- constructor(textNode, offsetInText, length) {
63
- super();
64
- this.textNode = textNode;
65
- if (offsetInText < 0 || offsetInText > textNode.offsetSize) {
66
- /**
67
- * Given `offsetInText` value is incorrect.
68
- *
69
- * @error model-textproxy-wrong-offsetintext
70
- */
71
- throw new CKEditorError('model-textproxy-wrong-offsetintext', this);
72
- }
73
- if (length < 0 || offsetInText + length > textNode.offsetSize) {
74
- /**
75
- * Given `length` value is incorrect.
76
- *
77
- * @error model-textproxy-wrong-length
78
- */
79
- throw new CKEditorError('model-textproxy-wrong-length', this);
80
- }
81
- this.data = textNode.data.substring(offsetInText, offsetInText + length);
82
- this.offsetInText = offsetInText;
83
- }
84
- /**
85
- * Offset at which this text proxy starts in it's parent.
86
- *
87
- * @see module:engine/model/node~ModelNode#startOffset
88
- */
89
- get startOffset() {
90
- return this.textNode.startOffset !== null ? this.textNode.startOffset + this.offsetInText : null;
91
- }
92
- /**
93
- * Offset size of this text proxy. Equal to the number of characters represented by the text proxy.
94
- *
95
- * @see module:engine/model/node~ModelNode#offsetSize
96
- */
97
- get offsetSize() {
98
- return this.data.length;
99
- }
100
- /**
101
- * Offset at which this text proxy ends in it's parent.
102
- *
103
- * @see module:engine/model/node~ModelNode#endOffset
104
- */
105
- get endOffset() {
106
- return this.startOffset !== null ? this.startOffset + this.offsetSize : null;
107
- }
108
- /**
109
- * Flag indicating whether `ModelTextProxy` instance covers only part of the original
110
- * {@link module:engine/model/text~ModelText text node} (`true`) or the whole text node (`false`).
111
- *
112
- * This is `false` when text proxy starts at the very beginning of
113
- * {@link module:engine/model/textproxy~ModelTextProxy#textNode textNode}
114
- * ({@link module:engine/model/textproxy~ModelTextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
115
- * text node size.
116
- */
117
- get isPartial() {
118
- return this.offsetSize !== this.textNode.offsetSize;
119
- }
120
- /**
121
- * Parent of this text proxy, which is same as parent of text node represented by this text proxy.
122
- */
123
- get parent() {
124
- return this.textNode.parent;
125
- }
126
- /**
127
- * Root of this text proxy, which is same as root of text node represented by this text proxy.
128
- */
129
- get root() {
130
- return this.textNode.root;
131
- }
132
- /**
133
- * Gets path to this text proxy.
134
- *
135
- * @see module:engine/model/node~ModelNode#getPath
136
- */
137
- getPath() {
138
- const path = this.textNode.getPath();
139
- if (path.length > 0) {
140
- path[path.length - 1] += this.offsetInText;
141
- }
142
- return path;
143
- }
144
- /**
145
- * Returns ancestors array of this text proxy.
146
- *
147
- * @param options Options object.
148
- * @param options.includeSelf When set to `true` this text proxy will be also included in parent's array.
149
- * @param options.parentFirst When set to `true`, array will be sorted from text proxy parent to root element,
150
- * otherwise root element will be the first item in the array.
151
- * @returns Array with ancestors.
152
- */
153
- getAncestors(options = {}) {
154
- const ancestors = [];
155
- let parent = options.includeSelf ? this : this.parent;
156
- while (parent) {
157
- ancestors[options.parentFirst ? 'push' : 'unshift'](parent);
158
- parent = parent.parent;
159
- }
160
- return ancestors;
161
- }
162
- /**
163
- * Checks if this text proxy has an attribute for given key.
164
- *
165
- * @param key Key of attribute to check.
166
- * @returns `true` if attribute with given key is set on text proxy, `false` otherwise.
167
- */
168
- hasAttribute(key) {
169
- return this.textNode.hasAttribute(key);
170
- }
171
- /**
172
- * Gets an attribute value for given key or `undefined` if that attribute is not set on text proxy.
173
- *
174
- * @param key Key of attribute to look for.
175
- * @returns Attribute value or `undefined`.
176
- */
177
- getAttribute(key) {
178
- return this.textNode.getAttribute(key);
179
- }
180
- /**
181
- * Returns iterator that iterates over this node's attributes. Attributes are returned as arrays containing two
182
- * items. First one is attribute key and second is attribute value.
183
- *
184
- * This format is accepted by native `Map` object and also can be passed in `Node` constructor.
185
- */
186
- getAttributes() {
187
- return this.textNode.getAttributes();
188
- }
189
- /**
190
- * Returns iterator that iterates over this node's attribute keys.
191
- */
192
- getAttributeKeys() {
193
- return this.textNode.getAttributeKeys();
194
- }
195
- }
196
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
197
- // Proper overload would interfere with that.
198
- ModelTextProxy.prototype.is = function (type) {
199
- return type === '$textProxy' || type === 'model:$textProxy' ||
200
- // This are legacy values kept for backward compatibility.
201
- type === 'textProxy' || type === 'model:textProxy';
202
- };
@@ -1,313 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { ModelPosition, getTextNodeAtPosition, getNodeAfterPosition, getNodeBeforePosition } from './position.js';
6
- import { ModelTextProxy } from './textproxy.js';
7
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
8
- /**
9
- * Position iterator class. It allows to iterate forward and backward over the document.
10
- */
11
- export class ModelTreeWalker {
12
- /**
13
- * Walking direction. Defaults `'forward'`.
14
- */
15
- direction;
16
- /**
17
- * Iterator boundaries.
18
- *
19
- * When the iterator is walking `'forward'` on the end of boundary or is walking `'backward'`
20
- * on the start of boundary, then `{ done: true }` is returned.
21
- *
22
- * If boundaries are not defined they are set before first and after last child of the root node.
23
- */
24
- boundaries;
25
- /**
26
- * Flag indicating whether all consecutive characters with the same attributes should be
27
- * returned as one {@link module:engine/model/textproxy~ModelTextProxy} (`true`) or one by one (`false`).
28
- */
29
- singleCharacters;
30
- /**
31
- * Flag indicating whether iterator should enter elements or not. If the iterator is shallow child nodes of any
32
- * iterated node will not be returned along with `elementEnd` tag.
33
- */
34
- shallow;
35
- /**
36
- * Flag indicating whether iterator should ignore `elementEnd` tags. If the option is true walker will not
37
- * return a parent node of the start position. If this option is `true` each {@link module:engine/model/element~ModelElement} will
38
- * be returned once, while if the option is `false` they might be returned twice:
39
- * for `'elementStart'` and `'elementEnd'`.
40
- */
41
- ignoreElementEnd;
42
- /**
43
- * Iterator position. This is always static position, even if the initial position was a
44
- * {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
45
- * on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
46
- * is `'backward'` position starts from the end.
47
- */
48
- _position;
49
- /**
50
- * Start boundary cached for optimization purposes.
51
- */
52
- _boundaryStartParent;
53
- /**
54
- * End boundary cached for optimization purposes.
55
- */
56
- _boundaryEndParent;
57
- /**
58
- * Parent of the most recently visited node. Cached for optimization purposes.
59
- */
60
- _visitedParent;
61
- /**
62
- * Creates a range iterator. All parameters are optional, but you have to specify either `boundaries` or `startPosition`.
63
- *
64
- * @param options Object with configuration.
65
- */
66
- constructor(options) {
67
- if (!options || (!options.boundaries && !options.startPosition)) {
68
- /**
69
- * Neither boundaries nor starting position of a `TreeWalker` have been defined.
70
- *
71
- * @error model-tree-walker-no-start-position
72
- */
73
- throw new CKEditorError('model-tree-walker-no-start-position', null);
74
- }
75
- const direction = options.direction || 'forward';
76
- if (direction != 'forward' && direction != 'backward') {
77
- /**
78
- * Only `backward` and `forward` direction allowed.
79
- *
80
- * @error model-tree-walker-unknown-direction
81
- */
82
- throw new CKEditorError('model-tree-walker-unknown-direction', options, { direction });
83
- }
84
- this.direction = direction;
85
- this.boundaries = options.boundaries || null;
86
- if (options.startPosition) {
87
- this._position = options.startPosition.clone();
88
- }
89
- else {
90
- this._position = ModelPosition._createAt(this.boundaries[this.direction == 'backward' ? 'end' : 'start']);
91
- }
92
- // Reset position stickiness in case it was set to other value, as the stickiness is kept after cloning.
93
- this.position.stickiness = 'toNone';
94
- this.singleCharacters = !!options.singleCharacters;
95
- this.shallow = !!options.shallow;
96
- this.ignoreElementEnd = !!options.ignoreElementEnd;
97
- this._boundaryStartParent = this.boundaries ? this.boundaries.start.parent : null;
98
- this._boundaryEndParent = this.boundaries ? this.boundaries.end.parent : null;
99
- this._visitedParent = this.position.parent;
100
- }
101
- /**
102
- * Iterable interface.
103
- *
104
- * @returns {Iterable.<module:engine/model/treewalker~ModelTreeWalkerValue>}
105
- */
106
- [Symbol.iterator]() {
107
- return this;
108
- }
109
- /**
110
- * Iterator position. This is always static position, even if the initial position was a
111
- * {@link module:engine/model/liveposition~ModelLivePosition live position}. If start position is not defined then position depends
112
- * on {@link #direction}. If direction is `'forward'` position starts form the beginning, when direction
113
- * is `'backward'` position starts from the end.
114
- */
115
- get position() {
116
- return this._position;
117
- }
118
- /**
119
- * Moves {@link #position} in the {@link #direction} skipping values as long as the callback function returns `true`.
120
- *
121
- * For example:
122
- *
123
- * ```ts
124
- * walker.skip( value => value.type == 'text' ); // <paragraph>[]foo</paragraph> -> <paragraph>foo[]</paragraph>
125
- * walker.skip( () => true ); // Move the position to the end: <paragraph>[]foo</paragraph> -> <paragraph>foo</paragraph>[]
126
- * walker.skip( () => false ); // Do not move the position.
127
- * ```
128
- *
129
- * @param skip Callback function. Gets {@link module:engine/model/treewalker~ModelTreeWalkerValue} and should
130
- * return `true` if the value should be skipped or `false` if not.
131
- */
132
- skip(skip) {
133
- let done, value, prevPosition, prevVisitedParent;
134
- do {
135
- prevPosition = this.position;
136
- prevVisitedParent = this._visitedParent;
137
- ({ done, value } = this.next());
138
- } while (!done && skip(value));
139
- if (!done) {
140
- this._position = prevPosition;
141
- this._visitedParent = prevVisitedParent;
142
- }
143
- }
144
- /**
145
- * Moves tree walker {@link #position} to provided `position`. Tree walker will
146
- * continue traversing from that position.
147
- *
148
- * Note: in contrary to {@link ~ModelTreeWalker#skip}, this method does not iterate over the nodes along the way.
149
- * It simply sets the current tree walker position to a new one.
150
- * From the performance standpoint, it is better to use {@link ~ModelTreeWalker#jumpTo} rather than {@link ~ModelTreeWalker#skip}.
151
- *
152
- * If the provided position is before the start boundary, the position will be
153
- * set to the start boundary. If the provided position is after the end boundary,
154
- * the position will be set to the end boundary.
155
- * This is done to prevent the treewalker from traversing outside the boundaries.
156
- *
157
- * @param position Position to jump to.
158
- */
159
- jumpTo(position) {
160
- if (this._boundaryStartParent && position.isBefore(this.boundaries.start)) {
161
- position = this.boundaries.start;
162
- }
163
- else if (this._boundaryEndParent && position.isAfter(this.boundaries.end)) {
164
- position = this.boundaries.end;
165
- }
166
- this._position = position.clone();
167
- this._visitedParent = position.parent;
168
- }
169
- /**
170
- * Gets the next tree walker's value.
171
- */
172
- next() {
173
- if (this.direction == 'forward') {
174
- return this._next();
175
- }
176
- else {
177
- return this._previous();
178
- }
179
- }
180
- /**
181
- * Makes a step forward in model. Moves the {@link #position} to the next position and returns the encountered value.
182
- */
183
- _next() {
184
- const previousPosition = this.position;
185
- const position = this.position.clone();
186
- const parent = this._visitedParent;
187
- // We are at the end of the root.
188
- if (parent.parent === null && position.offset === parent.maxOffset) {
189
- return { done: true, value: undefined };
190
- }
191
- // We reached the walker boundary.
192
- if (parent === this._boundaryEndParent && position.offset == this.boundaries.end.offset) {
193
- return { done: true, value: undefined };
194
- }
195
- // Get node just after the current position.
196
- // Use a highly optimized version instead of checking the text node first and then getting the node after. See #6582.
197
- const textNodeAtPosition = getTextNodeAtPosition(position, parent);
198
- const node = textNodeAtPosition || getNodeAfterPosition(position, parent, textNodeAtPosition);
199
- if (node && node.is('model:element')) {
200
- if (!this.shallow) {
201
- // Manual operations on path internals for optimization purposes. Here and in the rest of the method.
202
- position.path.push(0);
203
- this._visitedParent = node;
204
- }
205
- else {
206
- // We are past the walker boundaries.
207
- if (this.boundaries && this.boundaries.end.isBefore(position)) {
208
- return { done: true, value: undefined };
209
- }
210
- position.offset++;
211
- }
212
- this._position = position;
213
- return formatReturnValue('elementStart', node, previousPosition, position, 1);
214
- }
215
- if (node && node.is('model:$text')) {
216
- let charactersCount;
217
- if (this.singleCharacters) {
218
- charactersCount = 1;
219
- }
220
- else {
221
- let offset = node.endOffset;
222
- if (this._boundaryEndParent == parent && this.boundaries.end.offset < offset) {
223
- offset = this.boundaries.end.offset;
224
- }
225
- charactersCount = offset - position.offset;
226
- }
227
- const offsetInTextNode = position.offset - node.startOffset;
228
- const item = new ModelTextProxy(node, offsetInTextNode, charactersCount);
229
- position.offset += charactersCount;
230
- this._position = position;
231
- return formatReturnValue('text', item, previousPosition, position, charactersCount);
232
- }
233
- // `node` is not set, we reached the end of current `parent`.
234
- position.path.pop();
235
- position.offset++;
236
- this._position = position;
237
- this._visitedParent = parent.parent;
238
- if (this.ignoreElementEnd) {
239
- return this._next();
240
- }
241
- return formatReturnValue('elementEnd', parent, previousPosition, position);
242
- }
243
- /**
244
- * Makes a step backward in model. Moves the {@link #position} to the previous position and returns the encountered value.
245
- */
246
- _previous() {
247
- const previousPosition = this.position;
248
- const position = this.position.clone();
249
- const parent = this._visitedParent;
250
- // We are at the beginning of the root.
251
- if (parent.parent === null && position.offset === 0) {
252
- return { done: true, value: undefined };
253
- }
254
- // We reached the walker boundary.
255
- if (parent == this._boundaryStartParent && position.offset == this.boundaries.start.offset) {
256
- return { done: true, value: undefined };
257
- }
258
- // Get node just before the current position.
259
- // Use a highly optimized version instead of checking the text node first and then getting the node before. See #6582.
260
- const positionParent = position.parent;
261
- const textNodeAtPosition = getTextNodeAtPosition(position, positionParent);
262
- const node = textNodeAtPosition || getNodeBeforePosition(position, positionParent, textNodeAtPosition);
263
- if (node && node.is('model:element')) {
264
- position.offset--;
265
- if (this.shallow) {
266
- this._position = position;
267
- return formatReturnValue('elementStart', node, previousPosition, position, 1);
268
- }
269
- position.path.push(node.maxOffset);
270
- this._position = position;
271
- this._visitedParent = node;
272
- if (this.ignoreElementEnd) {
273
- return this._previous();
274
- }
275
- return formatReturnValue('elementEnd', node, previousPosition, position);
276
- }
277
- if (node && node.is('model:$text')) {
278
- let charactersCount;
279
- if (this.singleCharacters) {
280
- charactersCount = 1;
281
- }
282
- else {
283
- let offset = node.startOffset;
284
- if (this._boundaryStartParent == parent && this.boundaries.start.offset > offset) {
285
- offset = this.boundaries.start.offset;
286
- }
287
- charactersCount = position.offset - offset;
288
- }
289
- const offsetInTextNode = position.offset - node.startOffset;
290
- const item = new ModelTextProxy(node, offsetInTextNode - charactersCount, charactersCount);
291
- position.offset -= charactersCount;
292
- this._position = position;
293
- return formatReturnValue('text', item, previousPosition, position, charactersCount);
294
- }
295
- // `node` is not set, we reached the beginning of current `parent`.
296
- position.path.pop();
297
- this._position = position;
298
- this._visitedParent = parent.parent;
299
- return formatReturnValue('elementStart', parent, previousPosition, position, 1);
300
- }
301
- }
302
- function formatReturnValue(type, item, previousPosition, nextPosition, length) {
303
- return {
304
- done: false,
305
- value: {
306
- type,
307
- item,
308
- previousPosition,
309
- nextPosition,
310
- length
311
- }
312
- };
313
- }
@@ -1,16 +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
- export class ModelTypeCheckable {
6
- /* istanbul ignore next -- @preserve */
7
- is() {
8
- // There are a lot of overloads above.
9
- // Overriding method in derived classes remove them and only `is( type: string ): boolean` is visible which we don't want.
10
- // One option would be to copy them all to all classes, but that's ugly.
11
- // It's best when TypeScript compiler doesn't see those overloads, except the one in the top base class.
12
- // To overload a method, but not let the compiler see it, do after class definition:
13
- // `MyClass.prototype.is = function( type: string ) {...}`
14
- throw new Error('is() method is abstract');
15
- }
16
- }
@@ -1,63 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module engine/model/utils/autoparagraphing
7
- */
8
- /**
9
- * Fixes all empty roots.
10
- *
11
- * @internal
12
- * @param writer The model writer.
13
- * @returns `true` if any change has been applied, `false` otherwise.
14
- */
15
- export function autoParagraphEmptyRoots(writer) {
16
- const { schema, document } = writer.model;
17
- for (const root of document.getRoots()) {
18
- if (root.isEmpty && !schema.checkChild(root, '$text')) {
19
- // If paragraph element is allowed in the root, create paragraph element.
20
- if (schema.checkChild(root, 'paragraph')) {
21
- writer.insertElement('paragraph', root);
22
- // Other roots will get fixed in the next post-fixer round. Those will be triggered
23
- // in the same batch no matter if this method was triggered by the post-fixing or not
24
- // (the above insertElement call will trigger the post-fixers).
25
- return true;
26
- }
27
- }
28
- }
29
- return false;
30
- }
31
- /**
32
- * Checks if the given node wrapped with a paragraph would be accepted by the schema in the given position.
33
- *
34
- * @internal
35
- * @param position The position at which to check.
36
- * @param nodeOrType The child node or child type to check.
37
- * @param schema A schema instance used for element validation.
38
- */
39
- export function isParagraphable(position, nodeOrType, schema) {
40
- const context = schema.createContext(position);
41
- // When paragraph is allowed in this context...
42
- if (!schema.checkChild(context, 'paragraph')) {
43
- return false;
44
- }
45
- // And a node would be allowed in this paragraph...
46
- if (!schema.checkChild(context.push('paragraph'), nodeOrType)) {
47
- return false;
48
- }
49
- return true;
50
- }
51
- /**
52
- * Inserts a new paragraph at the given position and returns a position inside that paragraph.
53
- *
54
- * @internal
55
- * @param position The position where a paragraph should be inserted.
56
- * @param writer The model writer.
57
- * @returns Position inside the created paragraph.
58
- */
59
- export function wrapInParagraph(position, writer) {
60
- const paragraph = writer.createElement('paragraph');
61
- writer.insert(paragraph, position);
62
- return writer.createPositionAt(paragraph, 0);
63
- }