@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,184 +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/operation/mergeoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { SplitOperation } from './splitoperation.js';
10
- import { ModelPosition } from '../position.js';
11
- import { ModelRange } from '../range.js';
12
- import { _move } from './utils.js';
13
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
14
- /**
15
- * Operation to merge two {@link module:engine/model/element~ModelElement elements}.
16
- *
17
- * The merged element is the parent of {@link ~MergeOperation#sourcePosition} and it is merged into the parent of
18
- * {@link ~MergeOperation#targetPosition}. All nodes from the merged element are moved to {@link ~MergeOperation#targetPosition}.
19
- *
20
- * The merged element is moved to the graveyard at {@link ~MergeOperation#graveyardPosition}.
21
- */
22
- export class MergeOperation extends Operation {
23
- /**
24
- * Position inside the merged element. All nodes from that element after that position will be moved to {@link #targetPosition}.
25
- */
26
- sourcePosition;
27
- /**
28
- * Summary offset size of nodes which will be moved from the merged element to the new parent.
29
- */
30
- howMany;
31
- /**
32
- * Position which the nodes from the merged elements will be moved to.
33
- */
34
- targetPosition;
35
- /**
36
- * Position in graveyard to which the merged element will be moved.
37
- */
38
- graveyardPosition;
39
- /**
40
- * Creates a merge operation.
41
- *
42
- * @param sourcePosition Position inside the merged element. All nodes from that
43
- * element after that position will be moved to {@link #targetPosition}.
44
- * @param howMany Summary offset size of nodes which will be moved from the merged element to the new parent.
45
- * @param targetPosition Position which the nodes from the merged elements will be moved to.
46
- * @param graveyardPosition Position in graveyard to which the merged element will be moved.
47
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
48
- * can be applied or `null` if the operation operates on detached (non-document) tree.
49
- */
50
- constructor(sourcePosition, howMany, targetPosition, graveyardPosition, baseVersion) {
51
- super(baseVersion);
52
- this.sourcePosition = sourcePosition.clone();
53
- // This is, and should always remain, the first position in its parent.
54
- this.sourcePosition.stickiness = 'toPrevious';
55
- this.howMany = howMany;
56
- this.targetPosition = targetPosition.clone();
57
- // Except of a rare scenario in `MergeOperation` x `MergeOperation` transformation,
58
- // this is, and should always remain, the last position in its parent.
59
- this.targetPosition.stickiness = 'toNext';
60
- this.graveyardPosition = graveyardPosition.clone();
61
- }
62
- /**
63
- * @inheritDoc
64
- */
65
- get type() {
66
- return 'merge';
67
- }
68
- /**
69
- * Position before the merged element (which will be deleted).
70
- */
71
- get deletionPosition() {
72
- return new ModelPosition(this.sourcePosition.root, this.sourcePosition.path.slice(0, -1));
73
- }
74
- /**
75
- * Artificial range that contains all the nodes from the merged element that will be moved to {@link ~MergeOperation#sourcePosition}.
76
- * The range starts at {@link ~MergeOperation#sourcePosition} and ends in the same parent, at `POSITIVE_INFINITY` offset.
77
- */
78
- get movedRange() {
79
- const end = this.sourcePosition.getShiftedBy(Number.POSITIVE_INFINITY);
80
- return new ModelRange(this.sourcePosition, end);
81
- }
82
- /**
83
- * @inheritDoc
84
- */
85
- get affectedSelectable() {
86
- const mergedElement = this.sourcePosition.parent;
87
- return [
88
- ModelRange._createOn(mergedElement),
89
- // These could be positions but `Selectable` type only supports `Iterable<Range>`.
90
- ModelRange._createFromPositionAndShift(this.targetPosition, 0),
91
- ModelRange._createFromPositionAndShift(this.graveyardPosition, 0)
92
- ];
93
- }
94
- /**
95
- * Creates and returns an operation that has the same parameters as this operation.
96
- */
97
- clone() {
98
- return new MergeOperation(this.sourcePosition, this.howMany, this.targetPosition, this.graveyardPosition, this.baseVersion);
99
- }
100
- /**
101
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
102
- */
103
- getReversed() {
104
- // Positions in this method are transformed by this merge operation because the split operation bases on
105
- // the context after this merge operation happened (because split operation reverses it).
106
- // So we need to acknowledge that the merge operation happened and those positions changed a little.
107
- const targetPosition = this.targetPosition._getTransformedByMergeOperation(this);
108
- const path = this.sourcePosition.path.slice(0, -1);
109
- const insertionPosition = new ModelPosition(this.sourcePosition.root, path)._getTransformedByMergeOperation(this);
110
- return new SplitOperation(targetPosition, this.howMany, insertionPosition, this.graveyardPosition, this.baseVersion + 1);
111
- }
112
- /**
113
- * @inheritDoc
114
- * @internal
115
- */
116
- _validate() {
117
- const sourceElement = this.sourcePosition.parent;
118
- const targetElement = this.targetPosition.parent;
119
- // Validate whether merge operation has correct parameters.
120
- if (!sourceElement.parent) {
121
- /**
122
- * Merge source position is invalid. The element to be merged must have a parent node.
123
- *
124
- * @error merge-operation-source-position-invalid
125
- */
126
- throw new CKEditorError('merge-operation-source-position-invalid', this);
127
- }
128
- else if (!targetElement.parent) {
129
- /**
130
- * Merge target position is invalid. The element to be merged must have a parent node.
131
- *
132
- * @error merge-operation-target-position-invalid
133
- */
134
- throw new CKEditorError('merge-operation-target-position-invalid', this);
135
- }
136
- else if (this.howMany !== Number.NEGATIVE_INFINITY && this.howMany != sourceElement.maxOffset) {
137
- /**
138
- * Merge operation specifies wrong number of nodes to move.
139
- *
140
- * @error merge-operation-how-many-invalid
141
- */
142
- throw new CKEditorError('merge-operation-how-many-invalid', this);
143
- }
144
- this.howMany = this.sourcePosition.parent.maxOffset;
145
- }
146
- /**
147
- * @inheritDoc
148
- * @internal
149
- */
150
- _execute() {
151
- const mergedElement = this.sourcePosition.parent;
152
- const sourceRange = ModelRange._createIn(mergedElement);
153
- _move(sourceRange, this.targetPosition);
154
- _move(ModelRange._createOn(mergedElement), this.graveyardPosition);
155
- }
156
- /**
157
- * @inheritDoc
158
- */
159
- toJSON() {
160
- const json = super.toJSON();
161
- json.sourcePosition = json.sourcePosition.toJSON();
162
- json.targetPosition = json.targetPosition.toJSON();
163
- json.graveyardPosition = json.graveyardPosition.toJSON();
164
- return json;
165
- }
166
- /**
167
- * @inheritDoc
168
- */
169
- static get className() {
170
- return 'MergeOperation';
171
- }
172
- /**
173
- * Creates `MergeOperation` object from deserialized object, i.e. from parsed JSON string.
174
- *
175
- * @param json Deserialized JSON object.
176
- * @param document Document on which this operation will be applied.
177
- */
178
- static fromJSON(json, document) {
179
- const sourcePosition = ModelPosition.fromJSON(json.sourcePosition, document);
180
- const targetPosition = ModelPosition.fromJSON(json.targetPosition, document);
181
- const graveyardPosition = ModelPosition.fromJSON(json.graveyardPosition, document);
182
- return new this(sourcePosition, json.howMany, targetPosition, graveyardPosition, json.baseVersion);
183
- }
184
- }
@@ -1,179 +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/operation/moveoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { ModelPosition } from '../position.js';
10
- import { ModelRange } from '../range.js';
11
- import { _move } from './utils.js';
12
- import { CKEditorError, compareArrays } from '@ckeditor/ckeditor5-utils';
13
- // @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;
14
- /**
15
- * Operation to move a range of {@link module:engine/model/item~ModelItem model items}
16
- * to given {@link module:engine/model/position~ModelPosition target position}.
17
- */
18
- export class MoveOperation extends Operation {
19
- /**
20
- * Position before the first {@link module:engine/model/item~ModelItem model item} to move.
21
- */
22
- sourcePosition;
23
- /**
24
- * Offset size of moved range.
25
- */
26
- howMany;
27
- /**
28
- * Position at which moved nodes will be inserted.
29
- */
30
- targetPosition;
31
- /**
32
- * Creates a move operation.
33
- *
34
- * @param sourcePosition Position before the first {@link module:engine/model/item~ModelItem model item} to move.
35
- * @param howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
36
- * `sourcePosition` with offset shifted by `howMany`.
37
- * @param targetPosition Position at which moved nodes will be inserted.
38
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
39
- * can be applied or `null` if the operation operates on detached (non-document) tree.
40
- */
41
- constructor(sourcePosition, howMany, targetPosition, baseVersion) {
42
- super(baseVersion);
43
- this.sourcePosition = sourcePosition.clone();
44
- // `'toNext'` because `sourcePosition` is a bit like a start of the moved range.
45
- this.sourcePosition.stickiness = 'toNext';
46
- this.howMany = howMany;
47
- this.targetPosition = targetPosition.clone();
48
- this.targetPosition.stickiness = 'toNone';
49
- }
50
- /**
51
- * @inheritDoc
52
- */
53
- get type() {
54
- if (this.targetPosition.root.rootName == this.sourcePosition.root.rootName) {
55
- return 'move';
56
- }
57
- else if (this.targetPosition.root.rootName == '$graveyard') {
58
- return 'remove';
59
- }
60
- else if (this.sourcePosition.root.rootName == '$graveyard') {
61
- return 'reinsert';
62
- }
63
- return 'move';
64
- }
65
- /**
66
- * @inheritDoc
67
- */
68
- get affectedSelectable() {
69
- return [
70
- ModelRange._createFromPositionAndShift(this.sourcePosition, this.howMany),
71
- ModelRange._createFromPositionAndShift(this.targetPosition, 0)
72
- ];
73
- }
74
- /**
75
- * Creates and returns an operation that has the same parameters as this operation.
76
- */
77
- clone() {
78
- return new MoveOperation(this.sourcePosition, this.howMany, this.targetPosition, this.baseVersion);
79
- }
80
- /**
81
- * Returns the start position of the moved range after it got moved. This may be different than
82
- * {@link module:engine/model/operation/moveoperation~MoveOperation#targetPosition} in some cases, i.e. when a range is moved
83
- * inside the same parent but {@link module:engine/model/operation/moveoperation~MoveOperation#targetPosition targetPosition}
84
- * is after {@link module:engine/model/operation/moveoperation~MoveOperation#sourcePosition sourcePosition}.
85
- *
86
- * ```
87
- * vv vv
88
- * abcdefg ===> adefbcg
89
- * ^ ^
90
- * targetPos movedRangeStart
91
- * offset 6 offset 4
92
- *```
93
- */
94
- getMovedRangeStart() {
95
- return this.targetPosition._getTransformedByDeletion(this.sourcePosition, this.howMany);
96
- }
97
- /**
98
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
99
- */
100
- getReversed() {
101
- const newTargetPosition = this.sourcePosition._getTransformedByInsertion(this.targetPosition, this.howMany);
102
- return new MoveOperation(this.getMovedRangeStart(), this.howMany, newTargetPosition, this.baseVersion + 1);
103
- }
104
- /**
105
- * @inheritDoc
106
- * @internal
107
- */
108
- _validate() {
109
- const sourceElement = this.sourcePosition.parent;
110
- const targetElement = this.targetPosition.parent;
111
- const sourceOffset = this.sourcePosition.offset;
112
- const targetOffset = this.targetPosition.offset;
113
- // Validate whether move operation has correct parameters.
114
- // Validation is pretty complex but move operation is one of the core ways to manipulate the document state.
115
- // We expect that many errors might be connected with one of scenarios described below.
116
- if (sourceOffset + this.howMany > sourceElement.maxOffset) {
117
- /**
118
- * The nodes which should be moved do not exist.
119
- *
120
- * @error move-operation-nodes-do-not-exist
121
- */
122
- throw new CKEditorError('move-operation-nodes-do-not-exist', this);
123
- }
124
- else if (sourceElement === targetElement && sourceOffset < targetOffset && targetOffset < sourceOffset + this.howMany) {
125
- /**
126
- * Trying to move a range of nodes into the middle of that range.
127
- *
128
- * @error move-operation-range-into-itself
129
- */
130
- throw new CKEditorError('move-operation-range-into-itself', this);
131
- }
132
- else if (this.sourcePosition.root == this.targetPosition.root) {
133
- if (compareArrays(this.sourcePosition.getParentPath(), this.targetPosition.getParentPath()) == 'prefix') {
134
- const i = this.sourcePosition.path.length - 1;
135
- if (this.targetPosition.path[i] >= sourceOffset && this.targetPosition.path[i] < sourceOffset + this.howMany) {
136
- /**
137
- * Trying to move a range of nodes into one of nodes from that range.
138
- *
139
- * @error move-operation-node-into-itself
140
- */
141
- throw new CKEditorError('move-operation-node-into-itself', this);
142
- }
143
- }
144
- }
145
- }
146
- /**
147
- * @inheritDoc
148
- * @internal
149
- */
150
- _execute() {
151
- _move(ModelRange._createFromPositionAndShift(this.sourcePosition, this.howMany), this.targetPosition);
152
- }
153
- /**
154
- * @inheritDoc
155
- */
156
- toJSON() {
157
- const json = super.toJSON();
158
- json.sourcePosition = this.sourcePosition.toJSON();
159
- json.targetPosition = this.targetPosition.toJSON();
160
- return json;
161
- }
162
- /**
163
- * @inheritDoc
164
- */
165
- static get className() {
166
- return 'MoveOperation';
167
- }
168
- /**
169
- * Creates `MoveOperation` object from deserialized object, i.e. from parsed JSON string.
170
- *
171
- * @param json Deserialized JSON object.
172
- * @param document Document on which this operation will be applied.
173
- */
174
- static fromJSON(json, document) {
175
- const sourcePosition = ModelPosition.fromJSON(json.sourcePosition, document);
176
- const targetPosition = ModelPosition.fromJSON(json.targetPosition, document);
177
- return new this(sourcePosition, json.howMany, targetPosition, json.baseVersion);
178
- }
179
- }
@@ -1,48 +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/operation/nooperation
7
- */
8
- import { Operation } from './operation.js';
9
- /**
10
- * Operation which is doing nothing ("empty operation", "do-nothing operation", "noop"). This is an operation,
11
- * which when executed does not change the tree model. It still has some parameters defined for transformation purposes.
12
- *
13
- * In most cases this operation is a result of transforming operations. When transformation returns
14
- * {@link module:engine/model/operation/nooperation~NoOperation} it means that changes done by the transformed operation
15
- * have already been applied.
16
- */
17
- export class NoOperation extends Operation {
18
- get type() {
19
- return 'noop';
20
- }
21
- /**
22
- * @inheritDoc
23
- */
24
- get affectedSelectable() {
25
- return null;
26
- }
27
- /**
28
- * Creates and returns an operation that has the same parameters as this operation.
29
- */
30
- clone() {
31
- return new NoOperation(this.baseVersion);
32
- }
33
- /**
34
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
35
- */
36
- getReversed() {
37
- return new NoOperation(this.baseVersion + 1);
38
- }
39
- /** @internal */
40
- _execute() {
41
- }
42
- /**
43
- * @inheritDoc
44
- */
45
- static get className() {
46
- return 'NoOperation';
47
- }
48
- }
@@ -1,78 +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
- * Abstract base operation class.
7
- */
8
- export class Operation {
9
- /**
10
- * {@link module:engine/model/document~ModelDocument#version} on which operation can be applied. If you try to
11
- * {@link module:engine/model/model~Model#applyOperation apply} operation with different base version than the
12
- * {@link module:engine/model/document~ModelDocument#version document version} the
13
- * {@link module:utils/ckeditorerror~CKEditorError model-document-applyOperation-wrong-version} error is thrown.
14
- */
15
- baseVersion;
16
- /**
17
- * Defines whether operation is executed on attached or detached {@link module:engine/model/item~ModelItem items}.
18
- */
19
- isDocumentOperation;
20
- /**
21
- * {@link module:engine/model/batch~Batch Batch} to which the operation is added or `null` if the operation is not
22
- * added to any batch yet.
23
- *
24
- * Note, that a {@link #isDocumentOperation non-document operation} has this property always set to `null`, and is never added
25
- * to any batch.
26
- */
27
- batch;
28
- /**
29
- * Base operation constructor.
30
- *
31
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
32
- * can be applied or `null` if the operation operates on detached (non-document) tree.
33
- */
34
- constructor(baseVersion) {
35
- this.baseVersion = baseVersion;
36
- this.isDocumentOperation = this.baseVersion !== null;
37
- this.batch = null;
38
- }
39
- /**
40
- * Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws
41
- * an error if operation is not valid.
42
- *
43
- * @internal
44
- */
45
- _validate() {
46
- }
47
- /**
48
- * Custom toJSON method to solve child-parent circular dependencies.
49
- *
50
- * @returns Clone of this object with the operation property replaced with string.
51
- */
52
- toJSON() {
53
- // This method creates only a shallow copy, all nested objects should be defined separately.
54
- // See https://github.com/ckeditor/ckeditor5-engine/issues/1477.
55
- const json = Object.assign({}, this);
56
- json.__className = this.constructor.className;
57
- // Remove reference to the parent `Batch` to avoid circular dependencies.
58
- delete json.batch;
59
- // This can be derived from `baseVersion` so we can remove it.
60
- delete json.isDocumentOperation;
61
- return json;
62
- }
63
- /**
64
- * Name of the operation class used for serialization.
65
- */
66
- static get className() {
67
- return 'Operation';
68
- }
69
- /**
70
- * Creates `Operation` object from deserialized object, i.e. from parsed JSON string.
71
- *
72
- * @param json Deserialized JSON object.
73
- * @param document Document on which this operation will be applied.
74
- */
75
- static fromJSON(json, document) {
76
- return new this(json.baseVersion);
77
- }
78
- }
@@ -1,44 +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/operation/operationfactory
7
- */
8
- import { AttributeOperation } from './attributeoperation.js';
9
- import { InsertOperation } from './insertoperation.js';
10
- import { MarkerOperation } from './markeroperation.js';
11
- import { MoveOperation } from './moveoperation.js';
12
- import { NoOperation } from './nooperation.js';
13
- import { Operation } from './operation.js';
14
- import { RenameOperation } from './renameoperation.js';
15
- import { RootAttributeOperation } from './rootattributeoperation.js';
16
- import { RootOperation } from './rootoperation.js';
17
- import { SplitOperation } from './splitoperation.js';
18
- import { MergeOperation } from './mergeoperation.js';
19
- const operations = {};
20
- operations[AttributeOperation.className] = AttributeOperation;
21
- operations[InsertOperation.className] = InsertOperation;
22
- operations[MarkerOperation.className] = MarkerOperation;
23
- operations[MoveOperation.className] = MoveOperation;
24
- operations[NoOperation.className] = NoOperation;
25
- operations[Operation.className] = Operation;
26
- operations[RenameOperation.className] = RenameOperation;
27
- operations[RootAttributeOperation.className] = RootAttributeOperation;
28
- operations[RootOperation.className] = RootOperation;
29
- operations[SplitOperation.className] = SplitOperation;
30
- operations[MergeOperation.className] = MergeOperation;
31
- /**
32
- * A factory class for creating operations.
33
- */
34
- export class OperationFactory {
35
- /**
36
- * Creates an operation instance from a JSON object (parsed JSON string).
37
- *
38
- * @param json Deserialized JSON object.
39
- * @param document Document on which this operation will be applied.
40
- */
41
- static fromJSON(json, document) {
42
- return operations[json.__className].fromJSON(json, document);
43
- }
44
- }
@@ -1,128 +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/operation/renameoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { ModelElement } from '../element.js';
10
- import { ModelPosition } from '../position.js';
11
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
12
- /**
13
- * Operation to change element's name.
14
- *
15
- * Using this class you can change element's name.
16
- */
17
- export class RenameOperation extends Operation {
18
- /**
19
- * Position before an element to change.
20
- */
21
- position;
22
- /**
23
- * Current name of the element.
24
- */
25
- oldName;
26
- /**
27
- * New name for the element.
28
- */
29
- newName;
30
- /**
31
- * Creates an operation that changes element's name.
32
- *
33
- * @param position Position before an element to change.
34
- * @param oldName Current name of the element.
35
- * @param newName New name for the element.
36
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
37
- * can be applied or `null` if the operation operates on detached (non-document) tree.
38
- */
39
- constructor(position, oldName, newName, baseVersion) {
40
- super(baseVersion);
41
- this.position = position;
42
- // This position sticks to the next node because it is a position before the node that we want to change.
43
- this.position.stickiness = 'toNext';
44
- this.oldName = oldName;
45
- this.newName = newName;
46
- }
47
- /**
48
- * @inheritDoc
49
- */
50
- get type() {
51
- return 'rename';
52
- }
53
- /**
54
- * @inheritDoc
55
- */
56
- get affectedSelectable() {
57
- return this.position.nodeAfter;
58
- }
59
- /**
60
- * Creates and returns an operation that has the same parameters as this operation.
61
- *
62
- * @returns Clone of this operation.
63
- */
64
- clone() {
65
- return new RenameOperation(this.position.clone(), this.oldName, this.newName, this.baseVersion);
66
- }
67
- /**
68
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
69
- */
70
- getReversed() {
71
- return new RenameOperation(this.position.clone(), this.newName, this.oldName, this.baseVersion + 1);
72
- }
73
- /**
74
- * @inheritDoc
75
- * @internal
76
- */
77
- _validate() {
78
- const element = this.position.nodeAfter;
79
- if (!(element instanceof ModelElement)) {
80
- /**
81
- * Given position is invalid or node after it is not instance of Element.
82
- *
83
- * @error rename-operation-wrong-position
84
- */
85
- throw new CKEditorError('rename-operation-wrong-position', this);
86
- }
87
- else if (this.oldName !== '' && element.name !== this.oldName) {
88
- /**
89
- * Element to change has different name than operation's old name.
90
- *
91
- * @error rename-operation-wrong-name
92
- */
93
- throw new CKEditorError('rename-operation-wrong-name', this);
94
- }
95
- this.oldName = element.name;
96
- }
97
- /**
98
- * @inheritDoc
99
- * @internal
100
- */
101
- _execute() {
102
- const element = this.position.nodeAfter;
103
- element.name = this.newName;
104
- }
105
- /**
106
- * @inheritDoc
107
- */
108
- toJSON() {
109
- const json = super.toJSON();
110
- json.position = this.position.toJSON();
111
- return json;
112
- }
113
- /**
114
- * @inheritDoc
115
- */
116
- static get className() {
117
- return 'RenameOperation';
118
- }
119
- /**
120
- * Creates `RenameOperation` object from deserialized object, i.e. from parsed JSON string.
121
- *
122
- * @param json Deserialized JSON object.
123
- * @param document Document on which this operation will be applied.
124
- */
125
- static fromJSON(json, document) {
126
- return new RenameOperation(ModelPosition.fromJSON(json.position, document), json.oldName, json.newName, json.baseVersion);
127
- }
128
- }