@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,172 +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/attributeoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { _setAttribute } from './utils.js';
10
- import { ModelRange } from '../range.js';
11
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
12
- import { isEqual } from 'es-toolkit/compat';
13
- /**
14
- * Operation to change nodes' attribute.
15
- *
16
- * Using this class you can add, remove or change value of the attribute.
17
- */
18
- export class AttributeOperation extends Operation {
19
- /**
20
- * Range on which operation should be applied.
21
- *
22
- * @readonly
23
- */
24
- range;
25
- /**
26
- * Key of an attribute to change or remove.
27
- *
28
- * @readonly
29
- */
30
- key;
31
- /**
32
- * Old value of the attribute with given key or `null`, if attribute was not set before.
33
- *
34
- * @readonly
35
- */
36
- oldValue;
37
- /**
38
- * New value of the attribute with given key or `null`, if operation should remove attribute.
39
- *
40
- * @readonly
41
- */
42
- newValue;
43
- /**
44
- * Creates an operation that changes, removes or adds attributes.
45
- *
46
- * If only `newValue` is set, attribute will be added on a node. Note that all nodes in operation's range must not
47
- * have an attribute with the same key as the added attribute.
48
- *
49
- * If only `oldValue` is set, then attribute with given key will be removed. Note that all nodes in operation's range
50
- * must have an attribute with that key added.
51
- *
52
- * If both `newValue` and `oldValue` are set, then the operation will change the attribute value. Note that all nodes in
53
- * operation's ranges must already have an attribute with given key and `oldValue` as value
54
- *
55
- * @param range Range on which the operation should be applied. Must be a flat range.
56
- * @param key Key of an attribute to change or remove.
57
- * @param oldValue Old value of the attribute with given key or `null`, if attribute was not set before.
58
- * @param newValue New value of the attribute with given key or `null`, if operation should remove attribute.
59
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
60
- * can be applied or `null` if the operation operates on detached (non-document) tree.
61
- */
62
- constructor(range, key, oldValue, newValue, baseVersion) {
63
- super(baseVersion);
64
- this.range = range.clone();
65
- this.key = key;
66
- this.oldValue = oldValue === undefined ? null : oldValue;
67
- this.newValue = newValue === undefined ? null : newValue;
68
- }
69
- /**
70
- * @inheritDoc
71
- */
72
- get type() {
73
- if (this.oldValue === null) {
74
- return 'addAttribute';
75
- }
76
- else if (this.newValue === null) {
77
- return 'removeAttribute';
78
- }
79
- else {
80
- return 'changeAttribute';
81
- }
82
- }
83
- /**
84
- * @inheritDoc
85
- */
86
- get affectedSelectable() {
87
- return this.range.clone();
88
- }
89
- /**
90
- * Creates and returns an operation that has the same parameters as this operation.
91
- */
92
- clone() {
93
- return new AttributeOperation(this.range, this.key, this.oldValue, this.newValue, this.baseVersion);
94
- }
95
- /**
96
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
97
- */
98
- getReversed() {
99
- return new AttributeOperation(this.range, this.key, this.newValue, this.oldValue, this.baseVersion + 1);
100
- }
101
- /**
102
- * @inheritDoc
103
- */
104
- toJSON() {
105
- const json = super.toJSON();
106
- json.range = this.range.toJSON();
107
- return json;
108
- }
109
- /**
110
- * @inheritDoc
111
- * @internal
112
- */
113
- _validate() {
114
- if (!this.range.isFlat) {
115
- /**
116
- * The range to change is not flat.
117
- *
118
- * @error attribute-operation-range-not-flat
119
- */
120
- throw new CKEditorError('attribute-operation-range-not-flat', this);
121
- }
122
- for (const item of this.range.getItems({ shallow: true })) {
123
- if (this.oldValue !== null && !isEqual(item.getAttribute(this.key), this.oldValue)) {
124
- /**
125
- * Changed node has different attribute value than operation's old attribute value.
126
- *
127
- * @error attribute-operation-wrong-old-value
128
- * @param {module:engine/model/item~ModelItem} root The item element.
129
- * @param {string} key The key of the attribute.
130
- * @param {never} value The value.
131
- */
132
- throw new CKEditorError('attribute-operation-wrong-old-value', this, { item, key: this.key, value: this.oldValue });
133
- }
134
- if (this.oldValue === null && this.newValue !== null && item.hasAttribute(this.key)) {
135
- /**
136
- * The attribute with given key already exists for the given node.
137
- *
138
- * @error attribute-operation-attribute-exists
139
- * @param {module:engine/model/item~ModelItem} root The item element.
140
- * @param {string} key The key of the attribute.
141
- */
142
- throw new CKEditorError('attribute-operation-attribute-exists', this, { node: item, key: this.key });
143
- }
144
- }
145
- }
146
- /**
147
- * @inheritDoc
148
- * @internal
149
- */
150
- _execute() {
151
- // If value to set is same as old value, don't do anything.
152
- if (!isEqual(this.oldValue, this.newValue)) {
153
- // Execution.
154
- _setAttribute(this.range, this.key, this.newValue);
155
- }
156
- }
157
- /**
158
- * @inheritDoc
159
- */
160
- static get className() {
161
- return 'AttributeOperation';
162
- }
163
- /**
164
- * Creates `AttributeOperation` object from deserialized object, i.e. from parsed JSON string.
165
- *
166
- * @param json Deserialized JSON object.
167
- * @param document Document on which this operation will be applied.
168
- */
169
- static fromJSON(json, document) {
170
- return new AttributeOperation(ModelRange.fromJSON(json.range, document), json.key, json.oldValue, json.newValue, json.baseVersion);
171
- }
172
- }
@@ -1,87 +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/detachoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { ModelRange } from '../range.js';
10
- import { _remove } from './utils.js';
11
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
12
- // @if CK_DEBUG_ENGINE // const ModelRange = require( '../range' ).default;
13
- /**
14
- * Operation to permanently remove node from detached root.
15
- * Note this operation is only a local operation and won't be send to the other clients.
16
- *
17
- * @internal
18
- */
19
- export class DetachOperation extends Operation {
20
- /**
21
- * Position before the first {@link module:engine/model/item~ModelItem model item} to detach.
22
- */
23
- sourcePosition;
24
- /**
25
- * Offset size of moved range.
26
- */
27
- howMany;
28
- /**
29
- * Creates an insert operation.
30
- *
31
- * @param sourcePosition Position before the first {@link module:engine/model/item~ModelItem model item} to move.
32
- * @param howMany Offset size of moved range. Moved range will start from `sourcePosition` and end at
33
- * `sourcePosition` with offset shifted by `howMany`.
34
- */
35
- constructor(sourcePosition, howMany) {
36
- super(null);
37
- this.sourcePosition = sourcePosition.clone();
38
- this.howMany = howMany;
39
- }
40
- /**
41
- * @inheritDoc
42
- */
43
- get type() {
44
- return 'detach';
45
- }
46
- /**
47
- * @inheritDoc
48
- */
49
- get affectedSelectable() {
50
- return null;
51
- }
52
- /**
53
- * @inheritDoc
54
- */
55
- toJSON() {
56
- const json = super.toJSON();
57
- json.sourcePosition = this.sourcePosition.toJSON();
58
- return json;
59
- }
60
- /**
61
- * @inheritDoc
62
- * @internal
63
- */
64
- _validate() {
65
- if (this.sourcePosition.root.document) {
66
- /**
67
- * Cannot detach document node.
68
- *
69
- * @error detach-operation-on-document-node
70
- */
71
- throw new CKEditorError('detach-operation-on-document-node', this);
72
- }
73
- }
74
- /**
75
- * @inheritDoc
76
- * @internal
77
- */
78
- _execute() {
79
- _remove(ModelRange._createFromPositionAndShift(this.sourcePosition, this.howMany));
80
- }
81
- /**
82
- * @inheritDoc
83
- */
84
- static get className() {
85
- return 'DetachOperation';
86
- }
87
- }
@@ -1,153 +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/insertoperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { ModelPosition } from '../position.js';
10
- import { ModelNodeList } from '../nodelist.js';
11
- import { MoveOperation } from './moveoperation.js';
12
- import { _insert, _normalizeNodes } from './utils.js';
13
- import { ModelText } from '../text.js';
14
- import { ModelElement } from '../element.js';
15
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
16
- /**
17
- * Operation to insert one or more nodes at given position in the model.
18
- */
19
- export class InsertOperation extends Operation {
20
- /**
21
- * Position of insertion.
22
- *
23
- * @readonly
24
- */
25
- position;
26
- /**
27
- * List of nodes to insert.
28
- *
29
- * @readonly
30
- */
31
- nodes;
32
- /**
33
- * Flag deciding how the operation should be transformed. If set to `true`, nodes might get additional attributes
34
- * during operational transformation. This happens when the operation insertion position is inside of a range
35
- * where attributes have changed.
36
- */
37
- shouldReceiveAttributes;
38
- /**
39
- * Creates an insert operation.
40
- *
41
- * @param position Position of insertion.
42
- * @param nodes The list of nodes to be inserted.
43
- * @param baseVersion Document {@link module:engine/model/document~ModelDocument#version} on which operation
44
- * can be applied or `null` if the operation operates on detached (non-document) tree.
45
- */
46
- constructor(position, nodes, baseVersion) {
47
- super(baseVersion);
48
- this.position = position.clone();
49
- this.position.stickiness = 'toNone';
50
- this.nodes = new ModelNodeList(_normalizeNodes(nodes));
51
- this.shouldReceiveAttributes = false;
52
- }
53
- /**
54
- * @inheritDoc
55
- */
56
- get type() {
57
- return 'insert';
58
- }
59
- /**
60
- * Total offset size of inserted nodes.
61
- */
62
- get howMany() {
63
- return this.nodes.maxOffset;
64
- }
65
- /**
66
- * @inheritDoc
67
- */
68
- get affectedSelectable() {
69
- return this.position.clone();
70
- }
71
- /**
72
- * Creates and returns an operation that has the same parameters as this operation.
73
- */
74
- clone() {
75
- const nodes = new ModelNodeList([...this.nodes].map(node => node._clone(true)));
76
- const insert = new InsertOperation(this.position, nodes, this.baseVersion);
77
- insert.shouldReceiveAttributes = this.shouldReceiveAttributes;
78
- return insert;
79
- }
80
- /**
81
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
82
- */
83
- getReversed() {
84
- const graveyard = this.position.root.document.graveyard;
85
- const gyPosition = new ModelPosition(graveyard, [0]);
86
- return new MoveOperation(this.position, this.nodes.maxOffset, gyPosition, this.baseVersion + 1);
87
- }
88
- /**
89
- * @inheritDoc
90
- * @internal
91
- */
92
- _validate() {
93
- const targetElement = this.position.parent;
94
- if (!targetElement || targetElement.maxOffset < this.position.offset) {
95
- /**
96
- * Insertion position is invalid.
97
- *
98
- * @error insert-operation-position-invalid
99
- */
100
- throw new CKEditorError('insert-operation-position-invalid', this);
101
- }
102
- }
103
- /**
104
- * @inheritDoc
105
- * @internal
106
- */
107
- _execute() {
108
- // What happens here is that we want original nodes be passed to writer because we want original nodes
109
- // to be inserted to the model. But in InsertOperation, we want to keep those nodes as they were added
110
- // to the operation, not modified. For example, text nodes can get merged or cropped while Elements can
111
- // get children. It is important that InsertOperation has the copy of original nodes in intact state.
112
- const originalNodes = this.nodes;
113
- this.nodes = new ModelNodeList([...originalNodes].map(node => node._clone(true)));
114
- _insert(this.position, originalNodes);
115
- }
116
- /**
117
- * @inheritDoc
118
- */
119
- toJSON() {
120
- const json = super.toJSON();
121
- json.position = this.position.toJSON();
122
- json.nodes = this.nodes.toJSON();
123
- return json;
124
- }
125
- /**
126
- * @inheritDoc
127
- */
128
- static get className() {
129
- return 'InsertOperation';
130
- }
131
- /**
132
- * Creates `InsertOperation` object from deserialized object, i.e. from parsed JSON string.
133
- *
134
- * @param json Deserialized JSON object.
135
- * @param document Document on which this operation will be applied.
136
- */
137
- static fromJSON(json, document) {
138
- const children = [];
139
- for (const child of json.nodes) {
140
- if (child.name) {
141
- // If child has name property, it is an Element.
142
- children.push(ModelElement.fromJSON(child));
143
- }
144
- else {
145
- // Otherwise, it is a Text node.
146
- children.push(ModelText.fromJSON(child));
147
- }
148
- }
149
- const insert = new InsertOperation(ModelPosition.fromJSON(json.position, document), children, json.baseVersion);
150
- insert.shouldReceiveAttributes = json.shouldReceiveAttributes;
151
- return insert;
152
- }
153
- }
@@ -1,136 +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/markeroperation
7
- */
8
- import { Operation } from './operation.js';
9
- import { ModelRange } from '../range.js';
10
- export class MarkerOperation extends Operation {
11
- /**
12
- * Marker name.
13
- *
14
- * @readonly
15
- */
16
- name;
17
- /**
18
- * Marker range before the change.
19
- *
20
- * @readonly
21
- */
22
- oldRange;
23
- /**
24
- * Marker range after the change.
25
- *
26
- * @readonly
27
- */
28
- newRange;
29
- /**
30
- * Specifies whether the marker operation affects the data produced by the data pipeline
31
- * (is persisted in the editor's data).
32
- *
33
- * @readonly
34
- */
35
- affectsData;
36
- /**
37
- * Marker collection on which change should be executed.
38
- */
39
- _markers;
40
- /**
41
- * @param name Marker name.
42
- * @param oldRange Marker range before the change.
43
- * @param newRange Marker range after the change.
44
- * @param markers Marker collection on which change should be executed.
45
- * @param affectsData Specifies whether the marker operation affects the data produced by the data pipeline
46
- * (is persisted in the editor's data).
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(name, oldRange, newRange, markers, affectsData, baseVersion) {
51
- super(baseVersion);
52
- this.name = name;
53
- this.oldRange = oldRange ? oldRange.clone() : null;
54
- this.newRange = newRange ? newRange.clone() : null;
55
- this.affectsData = affectsData;
56
- this._markers = markers;
57
- }
58
- /**
59
- * @inheritDoc
60
- */
61
- get type() {
62
- return 'marker';
63
- }
64
- /**
65
- * @inheritDoc
66
- */
67
- get affectedSelectable() {
68
- const ranges = [];
69
- if (this.oldRange) {
70
- ranges.push(this.oldRange.clone());
71
- }
72
- if (this.newRange) {
73
- if (this.oldRange) {
74
- ranges.push(...this.newRange.getDifference(this.oldRange));
75
- }
76
- else {
77
- ranges.push(this.newRange.clone());
78
- }
79
- }
80
- return ranges;
81
- }
82
- /**
83
- * Creates and returns an operation that has the same parameters as this operation.
84
- */
85
- clone() {
86
- return new MarkerOperation(this.name, this.oldRange, this.newRange, this._markers, this.affectsData, this.baseVersion);
87
- }
88
- /**
89
- * See {@link module:engine/model/operation/operation~Operation#getReversed `Operation#getReversed()`}.
90
- */
91
- getReversed() {
92
- return new MarkerOperation(this.name, this.newRange, this.oldRange, this._markers, this.affectsData, this.baseVersion + 1);
93
- }
94
- /**
95
- * @inheritDoc
96
- * @internal
97
- */
98
- _execute() {
99
- if (this.newRange) {
100
- this._markers._set(this.name, this.newRange, true, this.affectsData);
101
- }
102
- else {
103
- this._markers._remove(this.name);
104
- }
105
- }
106
- /**
107
- * @inheritDoc
108
- * @internal
109
- */
110
- toJSON() {
111
- const json = super.toJSON();
112
- if (this.oldRange) {
113
- json.oldRange = this.oldRange.toJSON();
114
- }
115
- if (this.newRange) {
116
- json.newRange = this.newRange.toJSON();
117
- }
118
- delete json._markers;
119
- return json;
120
- }
121
- /**
122
- * @inheritDoc
123
- */
124
- static get className() {
125
- return 'MarkerOperation';
126
- }
127
- /**
128
- * Creates `MarkerOperation` object from deserialized object, i.e. from parsed JSON string.
129
- *
130
- * @param json Deserialized JSON object.
131
- * @param document Document on which this operation will be applied.
132
- */
133
- static fromJSON(json, document) {
134
- return new MarkerOperation(json.name, json.oldRange ? ModelRange.fromJSON(json.oldRange, document) : null, json.newRange ? ModelRange.fromJSON(json.newRange, document) : null, document.model.markers, json.affectsData, json.baseVersion);
135
- }
136
- }