@ckeditor/ckeditor5-engine 45.2.1 → 46.0.0-alpha.1

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 (241) hide show
  1. package/dist/index.js +2563 -2257
  2. package/dist/index.js.map +1 -1
  3. package/package.json +3 -3
  4. package/src/controller/datacontroller.d.ts +33 -32
  5. package/src/controller/datacontroller.js +29 -28
  6. package/src/controller/editingcontroller.d.ts +8 -8
  7. package/src/controller/editingcontroller.js +10 -10
  8. package/src/conversion/conversion.d.ts +18 -19
  9. package/src/conversion/conversion.js +4 -4
  10. package/src/conversion/conversionhelpers.d.ts +1 -1
  11. package/src/conversion/conversionhelpers.js +1 -1
  12. package/src/conversion/downcastdispatcher.d.ts +63 -69
  13. package/src/conversion/downcastdispatcher.js +16 -16
  14. package/src/conversion/downcasthelpers.d.ts +94 -83
  15. package/src/conversion/downcasthelpers.js +63 -53
  16. package/src/conversion/mapper.d.ts +27 -27
  17. package/src/conversion/mapper.js +15 -15
  18. package/src/conversion/modelconsumable.d.ts +26 -26
  19. package/src/conversion/modelconsumable.js +23 -23
  20. package/src/conversion/upcastdispatcher.d.ts +33 -32
  21. package/src/conversion/upcastdispatcher.js +19 -19
  22. package/src/conversion/upcasthelpers.d.ts +46 -38
  23. package/src/conversion/upcasthelpers.js +33 -24
  24. package/src/conversion/viewconsumable.d.ts +50 -45
  25. package/src/conversion/viewconsumable.js +32 -27
  26. package/src/dataprocessor/basichtmlwriter.d.ts +4 -2
  27. package/src/dataprocessor/basichtmlwriter.js +3 -1
  28. package/src/dataprocessor/dataprocessor.d.ts +7 -6
  29. package/src/dataprocessor/htmldataprocessor.d.ts +10 -10
  30. package/src/dataprocessor/htmldataprocessor.js +6 -6
  31. package/src/dataprocessor/htmlwriter.d.ts +1 -1
  32. package/src/dataprocessor/xmldataprocessor.d.ts +10 -10
  33. package/src/dataprocessor/xmldataprocessor.js +6 -6
  34. package/src/dev-utils/model.d.ts +25 -26
  35. package/src/dev-utils/model.js +35 -36
  36. package/src/dev-utils/operationreplayer.d.ts +5 -3
  37. package/src/dev-utils/operationreplayer.js +4 -2
  38. package/src/dev-utils/utils.d.ts +8 -0
  39. package/src/dev-utils/utils.js +8 -0
  40. package/src/dev-utils/view.d.ts +66 -63
  41. package/src/dev-utils/view.js +144 -134
  42. package/src/index.d.ts +135 -106
  43. package/src/index.js +120 -71
  44. package/src/legacyerrors.d.ts +5 -0
  45. package/src/legacyerrors.js +17 -0
  46. package/src/model/batch.d.ts +2 -15
  47. package/src/model/batch.js +1 -23
  48. package/src/model/differ.d.ts +54 -31
  49. package/src/model/differ.js +15 -15
  50. package/src/model/document.d.ts +31 -31
  51. package/src/model/document.js +13 -13
  52. package/src/model/documentfragment.d.ts +45 -45
  53. package/src/model/documentfragment.js +40 -40
  54. package/src/model/documentselection.d.ts +92 -92
  55. package/src/model/documentselection.js +71 -70
  56. package/src/model/element.d.ts +31 -31
  57. package/src/model/element.js +29 -29
  58. package/src/model/history.d.ts +3 -3
  59. package/src/model/history.js +2 -2
  60. package/src/model/item.d.ts +4 -5
  61. package/src/model/liveposition.d.ts +31 -31
  62. package/src/model/liveposition.js +18 -18
  63. package/src/model/liverange.d.ts +42 -38
  64. package/src/model/liverange.js +17 -16
  65. package/src/model/markercollection.d.ts +41 -40
  66. package/src/model/markercollection.js +22 -20
  67. package/src/model/model.d.ts +82 -81
  68. package/src/model/model.js +54 -54
  69. package/src/model/node.d.ts +48 -48
  70. package/src/model/node.js +31 -31
  71. package/src/model/nodelist.d.ts +17 -17
  72. package/src/model/nodelist.js +11 -11
  73. package/src/model/operation/attributeoperation.d.ts +10 -10
  74. package/src/model/operation/attributeoperation.js +7 -7
  75. package/src/model/operation/detachoperation.d.ts +11 -9
  76. package/src/model/operation/detachoperation.js +8 -6
  77. package/src/model/operation/insertoperation.d.ts +13 -13
  78. package/src/model/operation/insertoperation.js +15 -15
  79. package/src/model/operation/markeroperation.d.ts +12 -12
  80. package/src/model/operation/markeroperation.js +5 -5
  81. package/src/model/operation/mergeoperation.d.ts +16 -16
  82. package/src/model/operation/mergeoperation.js +18 -18
  83. package/src/model/operation/moveoperation.d.ts +16 -16
  84. package/src/model/operation/moveoperation.js +18 -15
  85. package/src/model/operation/nooperation.d.ts +4 -4
  86. package/src/model/operation/nooperation.js +2 -2
  87. package/src/model/operation/operation.d.ts +10 -10
  88. package/src/model/operation/operation.js +5 -5
  89. package/src/model/operation/operationfactory.d.ts +4 -4
  90. package/src/model/operation/operationfactory.js +12 -12
  91. package/src/model/operation/renameoperation.d.ts +10 -10
  92. package/src/model/operation/renameoperation.js +7 -7
  93. package/src/model/operation/rootattributeoperation.d.ts +12 -12
  94. package/src/model/operation/rootattributeoperation.js +8 -8
  95. package/src/model/operation/rootoperation.d.ts +8 -8
  96. package/src/model/operation/rootoperation.js +3 -3
  97. package/src/model/operation/splitoperation.d.ts +17 -17
  98. package/src/model/operation/splitoperation.js +19 -19
  99. package/src/model/operation/transform.d.ts +11 -8
  100. package/src/model/operation/transform.js +66 -49
  101. package/src/model/operation/utils.d.ts +24 -23
  102. package/src/model/operation/utils.js +20 -20
  103. package/src/model/position.d.ts +101 -97
  104. package/src/model/position.js +69 -64
  105. package/src/model/range.d.ts +90 -90
  106. package/src/model/range.js +87 -87
  107. package/src/model/rootelement.d.ts +11 -11
  108. package/src/model/rootelement.js +9 -9
  109. package/src/model/schema.d.ts +158 -154
  110. package/src/model/schema.js +93 -90
  111. package/src/model/selection.d.ts +73 -73
  112. package/src/model/selection.js +62 -62
  113. package/src/model/text.d.ts +11 -10
  114. package/src/model/text.js +11 -10
  115. package/src/model/textproxy.d.ts +39 -38
  116. package/src/model/textproxy.js +31 -30
  117. package/src/model/treewalker.d.ts +37 -37
  118. package/src/model/treewalker.js +14 -14
  119. package/src/model/typecheckable.d.ts +45 -45
  120. package/src/model/typecheckable.js +1 -1
  121. package/src/model/utils/autoparagraphing.d.ts +7 -7
  122. package/src/model/utils/deletecontent.d.ts +7 -5
  123. package/src/model/utils/deletecontent.js +13 -11
  124. package/src/model/utils/getselectedcontent.d.ts +6 -5
  125. package/src/model/utils/getselectedcontent.js +2 -1
  126. package/src/model/utils/insertcontent.d.ts +9 -8
  127. package/src/model/utils/insertcontent.js +41 -40
  128. package/src/model/utils/insertobject.d.ts +9 -9
  129. package/src/model/utils/insertobject.js +4 -4
  130. package/src/model/utils/modifyselection.d.ts +5 -4
  131. package/src/model/utils/modifyselection.js +12 -11
  132. package/src/model/utils/selection-post-fixer.d.ts +12 -8
  133. package/src/model/utils/selection-post-fixer.js +15 -11
  134. package/src/model/writer.d.ts +102 -101
  135. package/src/model/writer.js +99 -98
  136. package/src/view/attributeelement.d.ts +29 -29
  137. package/src/view/attributeelement.js +25 -25
  138. package/src/view/containerelement.d.ts +16 -15
  139. package/src/view/containerelement.js +15 -14
  140. package/src/view/datatransfer.d.ts +7 -7
  141. package/src/view/datatransfer.js +1 -1
  142. package/src/view/document.d.ts +25 -25
  143. package/src/view/document.js +15 -15
  144. package/src/view/documentfragment.d.ts +21 -21
  145. package/src/view/documentfragment.js +14 -14
  146. package/src/view/documentselection.d.ts +65 -63
  147. package/src/view/documentselection.js +27 -25
  148. package/src/view/domconverter.d.ts +96 -91
  149. package/src/view/domconverter.js +78 -73
  150. package/src/view/downcastwriter.d.ts +185 -181
  151. package/src/view/downcastwriter.js +222 -210
  152. package/src/view/editableelement.d.ts +13 -13
  153. package/src/view/editableelement.js +8 -8
  154. package/src/view/element.d.ts +75 -74
  155. package/src/view/element.js +58 -58
  156. package/src/view/elementdefinition.d.ts +3 -4
  157. package/src/view/emptyelement.d.ts +13 -13
  158. package/src/view/emptyelement.js +13 -13
  159. package/src/view/filler.d.ts +14 -3
  160. package/src/view/filler.js +12 -1
  161. package/src/view/item.d.ts +4 -5
  162. package/src/view/matcher.d.ts +22 -19
  163. package/src/view/matcher.js +6 -6
  164. package/src/view/node.d.ts +33 -33
  165. package/src/view/node.js +9 -9
  166. package/src/view/observer/arrowkeysobserver.d.ts +10 -10
  167. package/src/view/observer/arrowkeysobserver.js +5 -5
  168. package/src/view/observer/bubblingemittermixin.d.ts +5 -5
  169. package/src/view/observer/bubblingemittermixin.js +2 -9
  170. package/src/view/observer/bubblingeventinfo.d.ts +9 -9
  171. package/src/view/observer/bubblingeventinfo.js +1 -1
  172. package/src/view/observer/clickobserver.d.ts +8 -8
  173. package/src/view/observer/clickobserver.js +4 -4
  174. package/src/view/observer/compositionobserver.d.ts +19 -19
  175. package/src/view/observer/compositionobserver.js +6 -6
  176. package/src/view/observer/domeventdata.d.ts +9 -9
  177. package/src/view/observer/domeventdata.js +2 -2
  178. package/src/view/observer/domeventobserver.d.ts +3 -3
  179. package/src/view/observer/domeventobserver.js +5 -5
  180. package/src/view/observer/fakeselectionobserver.d.ts +9 -9
  181. package/src/view/observer/fakeselectionobserver.js +8 -8
  182. package/src/view/observer/focusobserver.d.ts +16 -16
  183. package/src/view/observer/focusobserver.js +7 -7
  184. package/src/view/observer/inputobserver.d.ts +18 -18
  185. package/src/view/observer/inputobserver.js +5 -5
  186. package/src/view/observer/keyobserver.d.ts +11 -11
  187. package/src/view/observer/keyobserver.js +3 -3
  188. package/src/view/observer/mouseobserver.d.ts +16 -16
  189. package/src/view/observer/mouseobserver.js +3 -3
  190. package/src/view/observer/mutationobserver.d.ts +21 -21
  191. package/src/view/observer/mutationobserver.js +7 -7
  192. package/src/view/observer/observer.d.ts +12 -12
  193. package/src/view/observer/observer.js +6 -6
  194. package/src/view/observer/selectionobserver.d.ts +33 -33
  195. package/src/view/observer/selectionobserver.js +14 -14
  196. package/src/view/observer/tabobserver.d.ts +10 -10
  197. package/src/view/observer/tabobserver.js +5 -5
  198. package/src/view/observer/touchobserver.d.ts +13 -13
  199. package/src/view/observer/touchobserver.js +3 -3
  200. package/src/view/placeholder.d.ts +21 -21
  201. package/src/view/placeholder.js +23 -23
  202. package/src/view/position.d.ts +49 -49
  203. package/src/view/position.js +42 -42
  204. package/src/view/range.d.ts +76 -74
  205. package/src/view/range.js +67 -65
  206. package/src/view/rawelement.d.ts +19 -19
  207. package/src/view/rawelement.js +16 -16
  208. package/src/view/renderer.d.ts +14 -14
  209. package/src/view/renderer.js +7 -7
  210. package/src/view/rooteditableelement.d.ts +8 -7
  211. package/src/view/rooteditableelement.js +7 -6
  212. package/src/view/selection.d.ts +66 -64
  213. package/src/view/selection.js +50 -48
  214. package/src/view/styles/background.d.ts +2 -2
  215. package/src/view/styles/background.js +9 -9
  216. package/src/view/styles/border.d.ts +2 -2
  217. package/src/view/styles/border.js +13 -13
  218. package/src/view/styles/margin.d.ts +2 -2
  219. package/src/view/styles/margin.js +5 -5
  220. package/src/view/styles/padding.d.ts +2 -2
  221. package/src/view/styles/padding.js +5 -5
  222. package/src/view/styles/utils.d.ts +24 -24
  223. package/src/view/styles/utils.js +25 -25
  224. package/src/view/stylesmap.d.ts +28 -32
  225. package/src/view/stylesmap.js +52 -39
  226. package/src/view/text.d.ts +11 -11
  227. package/src/view/text.js +10 -10
  228. package/src/view/textproxy.d.ts +33 -32
  229. package/src/view/textproxy.js +23 -22
  230. package/src/view/tokenlist.d.ts +14 -14
  231. package/src/view/tokenlist.js +10 -10
  232. package/src/view/treewalker.d.ts +42 -40
  233. package/src/view/treewalker.js +36 -35
  234. package/src/view/typecheckable.d.ts +76 -75
  235. package/src/view/typecheckable.js +1 -1
  236. package/src/view/uielement.d.ts +22 -21
  237. package/src/view/uielement.js +17 -16
  238. package/src/view/upcastwriter.d.ts +70 -70
  239. package/src/view/upcastwriter.js +42 -42
  240. package/src/view/view.d.ts +70 -69
  241. package/src/view/view.js +56 -55
@@ -2,12 +2,12 @@
2
2
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- import type { ElementAttributeValue } from './element.js';
5
+ import type { ViewElementAttributeValue } from './element.js';
6
6
  import { type ArrayOrItem } from '@ckeditor/ckeditor5-utils';
7
7
  /**
8
8
  * Styles map. Allows handling (adding, removing, retrieving) a set of style rules (usually, of an element).
9
9
  */
10
- export default class StylesMap implements ElementAttributeValue {
10
+ export declare class StylesMap implements ViewElementAttributeValue {
11
11
  /**
12
12
  * Keeps an internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
13
13
  * value access model using lodash's get, set, unset, etc methods.
@@ -61,7 +61,7 @@ export default class StylesMap implements ElementAttributeValue {
61
61
  *
62
62
  * ```ts
63
63
  * // Enable 'margin' shorthand processing:
64
- * editor.data.addStyleProcessorRules( addMarginRules );
64
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
65
65
  *
66
66
  * styles.setTo( 'margin:2px;' );
67
67
  *
@@ -94,7 +94,7 @@ export default class StylesMap implements ElementAttributeValue {
94
94
  *
95
95
  * ```ts
96
96
  * // Enable 'margin' shorthand processing:
97
- * editor.data.addStyleProcessorRules( addMarginRules );
97
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
98
98
  *
99
99
  * styles.set( 'margin', '2px' );
100
100
  * ```
@@ -173,7 +173,7 @@ export default class StylesMap implements ElementAttributeValue {
173
173
  *
174
174
  * ```ts
175
175
  * // Enable 'margin' shorthand processing:
176
- * editor.data.addStyleProcessorRules( addMarginRules );
176
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
177
177
  *
178
178
  * styles.setTo( 'margin:1px' );
179
179
  *
@@ -191,7 +191,7 @@ export default class StylesMap implements ElementAttributeValue {
191
191
  *
192
192
  * ```ts
193
193
  * // Enable 'margin' shorthand processing:
194
- * editor.data.addStyleProcessorRules( addMarginRules );
194
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
195
195
  *
196
196
  * const styles = new Styles();
197
197
  * styles.setTo( 'margin:1px 2px 3em;' );
@@ -227,7 +227,7 @@ export default class StylesMap implements ElementAttributeValue {
227
227
  *
228
228
  * ```ts
229
229
  * // Enable 'margin' shorthand processing:
230
- * editor.data.addStyleProcessorRules( addMarginRules );
230
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
231
231
  *
232
232
  * styles.set( 'margin' , '1px' );
233
233
  * styles.set( 'background', '#f00' );
@@ -243,7 +243,7 @@ export default class StylesMap implements ElementAttributeValue {
243
243
  *
244
244
  * ```ts
245
245
  * // Enable 'margin' shorthand processing:
246
- * editor.data.addStyleProcessorRules( addMarginRules );
246
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
247
247
  *
248
248
  * const styles = new Styles();
249
249
  * styles.setTo( 'margin:1px;' );
@@ -328,7 +328,7 @@ export default class StylesMap implements ElementAttributeValue {
328
328
  /**
329
329
  * Returns normalized styles entries for further processing.
330
330
  */
331
- getStylesEntries(): Array<PropertyDescriptor>;
331
+ getStylesEntries(): Array<StylePropertyDescriptor>;
332
332
  /**
333
333
  * Clones the attribute value.
334
334
  *
@@ -353,38 +353,34 @@ export default class StylesMap implements ElementAttributeValue {
353
353
  */
354
354
  _getConsumables(name?: string): Array<string>;
355
355
  /**
356
- * Used by {@link module:engine/view/element~Element#_canMergeAttributesFrom} to verify if the given attribute can be merged without
356
+ * Used by {@link module:engine/view/element~ViewElement#_canMergeAttributesFrom} to verify if the given attribute can be merged without
357
357
  * conflicts into the attribute.
358
358
  *
359
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
360
- * an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
359
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
360
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
361
361
  *
362
362
  * @internal
363
363
  */
364
364
  _canMergeFrom(other: StylesMap): boolean;
365
365
  /**
366
- * Used by {@link module:engine/view/element~Element#_mergeAttributesFrom} to merge a given attribute into the attribute.
366
+ * Used by {@link module:engine/view/element~ViewElement#_mergeAttributesFrom} to merge a given attribute into the attribute.
367
367
  *
368
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
369
- * an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
368
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
369
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
370
370
  *
371
371
  * @internal
372
372
  */
373
373
  _mergeFrom(other: StylesMap): void;
374
374
  /**
375
- * Used by {@link module:engine/view/element~Element#_canSubtractAttributesOf} to verify if the given attribute can be fully
375
+ * Used by {@link module:engine/view/element~ViewElement#_canSubtractAttributesOf} to verify if the given attribute can be fully
376
376
  * subtracted from the attribute.
377
377
  *
378
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
379
- * an {@link module:engine/view/attributeelement~AttributeElement} to unwrap the AttributeElement.
378
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
379
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to unwrap the ViewAttributeElement.
380
380
  *
381
381
  * @internal
382
382
  */
383
383
  _isMatching(other: StylesMap): boolean;
384
- /**
385
- * Removes empty objects upon removing an entry from internal object.
386
- */
387
- private _cleanEmptyObjectsOnPath;
388
384
  }
389
385
  /**
390
386
  * Style processor is responsible for writing and reading a normalized styles object.
@@ -474,7 +470,7 @@ export declare class StylesProcessor {
474
470
  *
475
471
  * @param name Name of style property.
476
472
  */
477
- getReducedForm(name: string, styles: Styles): Array<PropertyDescriptor>;
473
+ getReducedForm(name: string, styles: Styles): Array<StylePropertyDescriptor>;
478
474
  /**
479
475
  * Return all style properties. Also expand shorthand properties (e.g. `margin`, `background`) if respective extractor is available.
480
476
  *
@@ -550,7 +546,7 @@ export declare class StylesProcessor {
550
546
  * } );
551
547
  * ```
552
548
  */
553
- setNormalizer(name: string, callback: Normalizer): void;
549
+ setNormalizer(name: string, callback: StylesNormalizer): void;
554
550
  /**
555
551
  * Adds a extractor callback for a style property.
556
552
  *
@@ -595,7 +591,7 @@ export declare class StylesProcessor {
595
591
  *
596
592
  * @param callbackOrPath Callback that return a requested value or path string for single values.
597
593
  */
598
- setExtractor(name: string, callbackOrPath: Extractor): void;
594
+ setExtractor(name: string, callbackOrPath: StylesExtractor): void;
599
595
  /**
600
596
  * Adds a reducer callback for a style property.
601
597
  *
@@ -632,7 +628,7 @@ export declare class StylesProcessor {
632
628
  * } );
633
629
  * ```
634
630
  */
635
- setReducer(name: string, callback: Reducer): void;
631
+ setReducer(name: string, callback: StylesReducer): void;
636
632
  /**
637
633
  * Defines a style shorthand relation to other style notations.
638
634
  *
@@ -671,7 +667,7 @@ export declare class StylesProcessor {
671
667
  * const marginTopDescriptor = [ 'margin-top', '2px' ];
672
668
  * ```
673
669
  */
674
- export type PropertyDescriptor = [name: string, value: string];
670
+ export type StylePropertyDescriptor = [name: string, value: string];
675
671
  /**
676
672
  * An object describing values associated with the sides of a box, for instance margins, paddings,
677
673
  * border widths, border colors, etc.
@@ -692,7 +688,7 @@ export type PropertyDescriptor = [name: string, value: string];
692
688
  * };
693
689
  * ```
694
690
  */
695
- export type BoxSides = {
691
+ export type BoxStyleSides = {
696
692
  /**
697
693
  * Top side value.
698
694
  */
@@ -719,13 +715,13 @@ export interface Styles {
719
715
  /**
720
716
  * The value of style.
721
717
  */
722
- export type StyleValue = string | Array<string> | Styles | BoxSides;
718
+ export type StyleValue = string | Array<string> | Styles | BoxStyleSides;
723
719
  /**
724
720
  * A normalizer method for a style property.
725
721
  *
726
722
  * @see ~StylesProcessor#setNormalizer
727
723
  */
728
- export type Normalizer = (name: string) => {
724
+ export type StylesNormalizer = (name: string) => {
729
725
  path: string;
730
726
  value: StyleValue;
731
727
  };
@@ -734,10 +730,10 @@ export type Normalizer = (name: string) => {
734
730
  *
735
731
  * @see ~StylesProcessor#setExtractor
736
732
  */
737
- export type Extractor = string | ((name: string, styles: Styles) => StyleValue | undefined);
733
+ export type StylesExtractor = string | ((name: string, styles: Styles) => StyleValue | undefined);
738
734
  /**
739
735
  * A reducer callback for a style property.
740
736
  *
741
737
  * @see ~StylesProcessor#setReducer
742
738
  */
743
- export type Reducer = (value: StyleValue) => Array<PropertyDescriptor>;
739
+ export type StylesReducer = (value: StyleValue) => Array<StylePropertyDescriptor>;
@@ -5,13 +5,13 @@
5
5
  /**
6
6
  * @module engine/view/stylesmap
7
7
  */
8
- import { get, isObject, merge, set, unset } from 'es-toolkit/compat';
8
+ import { get, isObject, merge, set } from 'es-toolkit/compat';
9
9
  import { toArray } from '@ckeditor/ckeditor5-utils';
10
10
  import { isPatternMatched } from './matcher.js';
11
11
  /**
12
12
  * Styles map. Allows handling (adding, removing, retrieving) a set of style rules (usually, of an element).
13
13
  */
14
- export default class StylesMap {
14
+ export class StylesMap {
15
15
  /**
16
16
  * Keeps an internal representation of styles map. Normalized styles are kept as object tree to allow unified modification and
17
17
  * value access model using lodash's get, set, unset, etc methods.
@@ -83,7 +83,7 @@ export default class StylesMap {
83
83
  *
84
84
  * ```ts
85
85
  * // Enable 'margin' shorthand processing:
86
- * editor.data.addStyleProcessorRules( addMarginRules );
86
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
87
87
  *
88
88
  * styles.setTo( 'margin:2px;' );
89
89
  *
@@ -137,7 +137,7 @@ export default class StylesMap {
137
137
  *
138
138
  * ```ts
139
139
  * // Enable 'margin' shorthand processing:
140
- * editor.data.addStyleProcessorRules( addMarginRules );
140
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
141
141
  *
142
142
  * styles.setTo( 'margin:1px' );
143
143
  *
@@ -150,13 +150,26 @@ export default class StylesMap {
150
150
  * @param names Style name or an array of names.
151
151
  */
152
152
  remove(names) {
153
+ const normalizedStylesToRemove = {};
153
154
  for (const name of toArray(names)) {
155
+ // First, try the easy path, when the path reflects normalized styles structure.
156
+ const path = toPath(name);
157
+ const pathValue = get(this._styles, path);
158
+ if (pathValue) {
159
+ appendStyleValue(normalizedStylesToRemove, path, pathValue);
160
+ }
161
+ else {
162
+ // Easy path did not work, so try to get the value from the styles map.
163
+ const value = this.getAsString(name);
164
+ if (value !== undefined) {
165
+ this._styleProcessor.toNormalizedForm(name, value, normalizedStylesToRemove);
166
+ }
167
+ }
168
+ }
169
+ if (Object.keys(normalizedStylesToRemove).length) {
170
+ removeStyles(this._styles, normalizedStylesToRemove);
154
171
  this._cachedStyleNames = null;
155
172
  this._cachedExpandedStyleNames = null;
156
- const path = toPath(name);
157
- unset(this._styles, path);
158
- delete this._styles[name];
159
- this._cleanEmptyObjectsOnPath(path);
160
173
  }
161
174
  }
162
175
  /**
@@ -164,7 +177,7 @@ export default class StylesMap {
164
177
  *
165
178
  * ```ts
166
179
  * // Enable 'margin' shorthand processing:
167
- * editor.data.addStyleProcessorRules( addMarginRules );
180
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
168
181
  *
169
182
  * const styles = new Styles();
170
183
  * styles.setTo( 'margin:1px 2px 3em;' );
@@ -202,7 +215,7 @@ export default class StylesMap {
202
215
  *
203
216
  * ```ts
204
217
  * // Enable 'margin' shorthand processing:
205
- * editor.data.addStyleProcessorRules( addMarginRules );
218
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
206
219
  *
207
220
  * styles.set( 'margin' , '1px' );
208
221
  * styles.set( 'background', '#f00' );
@@ -226,7 +239,7 @@ export default class StylesMap {
226
239
  *
227
240
  * ```ts
228
241
  * // Enable 'margin' shorthand processing:
229
- * editor.data.addStyleProcessorRules( addMarginRules );
242
+ * editor.data.addStyleProcessorRules( addMarginStylesRules );
230
243
  *
231
244
  * const styles = new Styles();
232
245
  * styles.setTo( 'margin:1px;' );
@@ -422,11 +435,11 @@ export default class StylesMap {
422
435
  return result;
423
436
  }
424
437
  /**
425
- * Used by {@link module:engine/view/element~Element#_canMergeAttributesFrom} to verify if the given attribute can be merged without
438
+ * Used by {@link module:engine/view/element~ViewElement#_canMergeAttributesFrom} to verify if the given attribute can be merged without
426
439
  * conflicts into the attribute.
427
440
  *
428
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
429
- * an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
441
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
442
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
430
443
  *
431
444
  * @internal
432
445
  */
@@ -439,10 +452,10 @@ export default class StylesMap {
439
452
  return true;
440
453
  }
441
454
  /**
442
- * Used by {@link module:engine/view/element~Element#_mergeAttributesFrom} to merge a given attribute into the attribute.
455
+ * Used by {@link module:engine/view/element~ViewElement#_mergeAttributesFrom} to merge a given attribute into the attribute.
443
456
  *
444
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
445
- * an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
457
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
458
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to merge it with other ViewAttributeElement.
446
459
  *
447
460
  * @internal
448
461
  */
@@ -454,11 +467,11 @@ export default class StylesMap {
454
467
  }
455
468
  }
456
469
  /**
457
- * Used by {@link module:engine/view/element~Element#_canSubtractAttributesOf} to verify if the given attribute can be fully
470
+ * Used by {@link module:engine/view/element~ViewElement#_canSubtractAttributesOf} to verify if the given attribute can be fully
458
471
  * subtracted from the attribute.
459
472
  *
460
- * This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
461
- * an {@link module:engine/view/attributeelement~AttributeElement} to unwrap the AttributeElement.
473
+ * This method is indirectly used by the {@link module:engine/view/downcastwriter~ViewDowncastWriter} while down-casting
474
+ * an {@link module:engine/view/attributeelement~ViewAttributeElement} to unwrap the ViewAttributeElement.
462
475
  *
463
476
  * @internal
464
477
  */
@@ -470,25 +483,6 @@ export default class StylesMap {
470
483
  }
471
484
  return true;
472
485
  }
473
- /**
474
- * Removes empty objects upon removing an entry from internal object.
475
- */
476
- _cleanEmptyObjectsOnPath(path) {
477
- const pathParts = path.split('.');
478
- const isChildPath = pathParts.length > 1;
479
- if (!isChildPath) {
480
- return;
481
- }
482
- const parentPath = pathParts.splice(0, pathParts.length - 1).join('.');
483
- const parentObject = get(this._styles, parentPath);
484
- if (!parentObject) {
485
- return;
486
- }
487
- const isParentEmpty = !Object.keys(parentObject).length;
488
- if (isParentEmpty) {
489
- this.remove(parentPath);
490
- }
491
- }
492
486
  }
493
487
  /**
494
488
  * Style processor is responsible for writing and reading a normalized styles object.
@@ -926,3 +920,22 @@ function appendStyleValue(stylesObject, nameOrPath, valueOrObject) {
926
920
  }
927
921
  set(stylesObject, nameOrPath, valueToSet);
928
922
  }
923
+ /**
924
+ * Modifies the `styles` deeply nested object by removing properties defined in `toRemove`.
925
+ */
926
+ function removeStyles(styles, toRemove) {
927
+ for (const key of Object.keys(toRemove)) {
928
+ if (styles[key] !== null &&
929
+ !Array.isArray(styles[key]) &&
930
+ typeof styles[key] == 'object' &&
931
+ typeof toRemove[key] == 'object') {
932
+ removeStyles(styles[key], toRemove[key]);
933
+ if (!Object.keys(styles[key]).length) {
934
+ delete styles[key];
935
+ }
936
+ }
937
+ else {
938
+ delete styles[key];
939
+ }
940
+ }
941
+ }
@@ -5,33 +5,33 @@
5
5
  /**
6
6
  * @module engine/view/text
7
7
  */
8
- import Node from './node.js';
9
- import type Document from './document.js';
8
+ import { ViewNode } from './node.js';
9
+ import { type ViewDocument } from './document.js';
10
10
  /**
11
11
  * Tree view text node.
12
12
  *
13
13
  * The constructor of this class should not be used directly. To create a new text node instance
14
- * use the {@link module:engine/view/downcastwriter~DowncastWriter#createText `DowncastWriter#createText()`}
14
+ * use the {@link module:engine/view/downcastwriter~ViewDowncastWriter#createText `ViewDowncastWriter#createText()`}
15
15
  * method when working on data downcasted from the model or the
16
- * {@link module:engine/view/upcastwriter~UpcastWriter#createText `UpcastWriter#createText()`}
16
+ * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createText `ViewUpcastWriter#createText()`}
17
17
  * method when working on non-semantic views.
18
18
  */
19
- export default class Text extends Node {
19
+ export declare class ViewText extends ViewNode {
20
20
  /**
21
21
  * The text content.
22
22
  *
23
- * Setting the data fires the {@link module:engine/view/node~Node#event:change:text change event}.
23
+ * Setting the data fires the {@link module:engine/view/node~ViewNode#event:change:text change event}.
24
24
  */
25
25
  private _textData;
26
26
  /**
27
27
  * Creates a tree view text node.
28
28
  *
29
- * @see module:engine/view/downcastwriter~DowncastWriter#createText
29
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#createText
30
30
  * @internal
31
31
  * @param document The document instance to which this text node belongs.
32
32
  * @param data The text's data.
33
33
  */
34
- constructor(document: Document, data: string);
34
+ constructor(document: ViewDocument, data: string);
35
35
  /**
36
36
  * The text content.
37
37
  */
@@ -51,7 +51,7 @@ export default class Text extends Node {
51
51
  *
52
52
  * If the protected getter didn't exist, `foo._data` will return `undefined` and result of the merge will be invalid.
53
53
  *
54
- * The setter sets data and fires the {@link module:engine/view/node~Node#event:change:text change event}.
54
+ * The setter sets data and fires the {@link module:engine/view/node~ViewNode#event:change:text change event}.
55
55
  *
56
56
  * @internal
57
57
  */
@@ -63,12 +63,12 @@ export default class Text extends Node {
63
63
  *
64
64
  * @param otherNode Node to check if it is same as this node.
65
65
  */
66
- isSimilar(otherNode: Node): boolean;
66
+ isSimilar(otherNode: ViewNode): boolean;
67
67
  /**
68
68
  * Clones this node.
69
69
  *
70
70
  * @internal
71
71
  * @returns Text node that is a clone of this node.
72
72
  */
73
- _clone(): Text;
73
+ _clone(): ViewText;
74
74
  }
package/src/view/text.js CHANGED
@@ -5,27 +5,27 @@
5
5
  /**
6
6
  * @module engine/view/text
7
7
  */
8
- import Node from './node.js';
8
+ import { ViewNode } from './node.js';
9
9
  /**
10
10
  * Tree view text node.
11
11
  *
12
12
  * The constructor of this class should not be used directly. To create a new text node instance
13
- * use the {@link module:engine/view/downcastwriter~DowncastWriter#createText `DowncastWriter#createText()`}
13
+ * use the {@link module:engine/view/downcastwriter~ViewDowncastWriter#createText `ViewDowncastWriter#createText()`}
14
14
  * method when working on data downcasted from the model or the
15
- * {@link module:engine/view/upcastwriter~UpcastWriter#createText `UpcastWriter#createText()`}
15
+ * {@link module:engine/view/upcastwriter~ViewUpcastWriter#createText `ViewUpcastWriter#createText()`}
16
16
  * method when working on non-semantic views.
17
17
  */
18
- export default class Text extends Node {
18
+ export class ViewText extends ViewNode {
19
19
  /**
20
20
  * The text content.
21
21
  *
22
- * Setting the data fires the {@link module:engine/view/node~Node#event:change:text change event}.
22
+ * Setting the data fires the {@link module:engine/view/node~ViewNode#event:change:text change event}.
23
23
  */
24
24
  _textData;
25
25
  /**
26
26
  * Creates a tree view text node.
27
27
  *
28
- * @see module:engine/view/downcastwriter~DowncastWriter#createText
28
+ * @see module:engine/view/downcastwriter~ViewDowncastWriter#createText
29
29
  * @internal
30
30
  * @param document The document instance to which this text node belongs.
31
31
  * @param data The text's data.
@@ -55,7 +55,7 @@ export default class Text extends Node {
55
55
  *
56
56
  * If the protected getter didn't exist, `foo._data` will return `undefined` and result of the merge will be invalid.
57
57
  *
58
- * The setter sets data and fires the {@link module:engine/view/node~Node#event:change:text change event}.
58
+ * The setter sets data and fires the {@link module:engine/view/node~ViewNode#event:change:text change event}.
59
59
  *
60
60
  * @internal
61
61
  */
@@ -73,7 +73,7 @@ export default class Text extends Node {
73
73
  * @param otherNode Node to check if it is same as this node.
74
74
  */
75
75
  isSimilar(otherNode) {
76
- if (!(otherNode instanceof Text)) {
76
+ if (!(otherNode instanceof ViewText)) {
77
77
  return false;
78
78
  }
79
79
  return this === otherNode || this.data === otherNode.data;
@@ -85,12 +85,12 @@ export default class Text extends Node {
85
85
  * @returns Text node that is a clone of this node.
86
86
  */
87
87
  _clone() {
88
- return new Text(this.document, this.data);
88
+ return new ViewText(this.document, this.data);
89
89
  }
90
90
  }
91
91
  // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
92
92
  // Proper overload would interfere with that.
93
- Text.prototype.is = function (type) {
93
+ ViewText.prototype.is = function (type) {
94
94
  return type === '$text' || type === 'view:$text' ||
95
95
  // This are legacy values kept for backward compatibility.
96
96
  type === 'text' || type === 'view:text' ||
@@ -5,43 +5,44 @@
5
5
  /**
6
6
  * @module engine/view/textproxy
7
7
  */
8
- import TypeCheckable from './typecheckable.js';
9
- import type Document from './document.js';
10
- import type DocumentFragment from './documentfragment.js';
11
- import type Element from './element.js';
12
- import type Node from './node.js';
13
- import type Text from './text.js';
8
+ import { ViewTypeCheckable } from './typecheckable.js';
9
+ import { type ViewDocument } from './document.js';
10
+ import { type ViewDocumentFragment } from './documentfragment.js';
11
+ import { type ViewElement } from './element.js';
12
+ import { type ViewNode } from './node.js';
13
+ import { type ViewText } from './text.js';
14
14
  /**
15
- * TextProxy is a wrapper for substring of {@link module:engine/view/text~Text}. Instance of this class is created by
16
- * {@link module:engine/view/treewalker~TreeWalker} when only a part of {@link module:engine/view/text~Text} needs to be returned.
15
+ * ViewTextProxy is a wrapper for substring of {@link module:engine/view/text~ViewText}. Instance of this class is created by
16
+ * {@link module:engine/view/treewalker~ViewTreeWalker} when only a part of {@link module:engine/view/text~ViewText} needs to be returned.
17
17
  *
18
- * `TextProxy` has an API similar to {@link module:engine/view/text~Text Text} and allows to do most of the common tasks performed
18
+ * `ViewTextProxy` has an API similar to {@link module:engine/view/text~ViewText Text} and allows to do most of the common tasks performed
19
19
  * on view nodes.
20
20
  *
21
- * **Note:** Some `TextProxy` instances may represent whole text node, not just a part of it.
22
- * See {@link module:engine/view/textproxy~TextProxy#isPartial}.
21
+ * **Note:** Some `ViewTextProxy` instances may represent whole text node, not just a part of it.
22
+ * See {@link module:engine/view/textproxy~ViewTextProxy#isPartial}.
23
23
  *
24
- * **Note:** `TextProxy` is a readonly interface.
24
+ * **Note:** `ViewTextProxy` is a readonly interface.
25
25
  *
26
- * **Note:** `TextProxy` instances are created on the fly basing on the current state of parent {@link module:engine/view/text~Text}.
26
+ * **Note:** `ViewTextProxy` instances are created on the fly basing
27
+ * on the current state of parent {@link module:engine/view/text~ViewText}.
27
28
  * Because of this it is highly unrecommended to store references to `TextProxy instances because they might get
28
- * invalidated due to operations on Document. Also TextProxy is not a {@link module:engine/view/node~Node} so it cannot be
29
- * inserted as a child of {@link module:engine/view/element~Element}.
29
+ * invalidated due to operations on Document. Also ViewTextProxy is not a {@link module:engine/view/node~ViewNode} so it cannot be
30
+ * inserted as a child of {@link module:engine/view/element~ViewElement}.
30
31
  *
31
- * `TextProxy` instances are created by {@link module:engine/view/treewalker~TreeWalker view tree walker}. You should not need to create
32
- * an instance of this class by your own.
32
+ * `ViewTextProxy` instances are created by {@link module:engine/view/treewalker~ViewTreeWalker view tree walker}.
33
+ * You should not need to create an instance of this class by your own.
33
34
  */
34
- export default class TextProxy extends TypeCheckable {
35
+ export declare class ViewTextProxy extends ViewTypeCheckable {
35
36
  /**
36
- * Reference to the {@link module:engine/view/text~Text} element which TextProxy is a substring.
37
+ * Reference to the {@link module:engine/view/text~ViewText} element which ViewTextProxy is a substring.
37
38
  */
38
- readonly textNode: Text;
39
+ readonly textNode: ViewText;
39
40
  /**
40
41
  * Text data represented by this text proxy.
41
42
  */
42
43
  readonly data: string;
43
44
  /**
44
- * Offset in the `textNode` where this `TextProxy` instance starts.
45
+ * Offset in the `textNode` where this `ViewTextProxy` instance starts.
45
46
  */
46
47
  readonly offsetInText: number;
47
48
  /**
@@ -49,37 +50,37 @@ export default class TextProxy extends TypeCheckable {
49
50
  *
50
51
  * @internal
51
52
  * @param textNode Text node which part is represented by this text proxy.
52
- * @param offsetInText Offset in {@link module:engine/view/textproxy~TextProxy#textNode text node}
53
+ * @param offsetInText Offset in {@link module:engine/view/textproxy~ViewTextProxy#textNode text node}
53
54
  * from which the text proxy starts.
54
55
  * @param length Text proxy length, that is how many text node's characters, starting from `offsetInText` it represents.
55
56
  */
56
- constructor(textNode: Text, offsetInText: number, length: number);
57
+ constructor(textNode: ViewText, offsetInText: number, length: number);
57
58
  /**
58
59
  * Offset size of this node.
59
60
  */
60
61
  get offsetSize(): number;
61
62
  /**
62
- * Flag indicating whether `TextProxy` instance covers only part of the original {@link module:engine/view/text~Text text node}
63
+ * Flag indicating whether `ViewTextProxy` instance covers only part of the original {@link module:engine/view/text~ViewText text node}
63
64
  * (`true`) or the whole text node (`false`).
64
65
  *
65
- * This is `false` when text proxy starts at the very beginning of {@link module:engine/view/textproxy~TextProxy#textNode textNode}
66
- * ({@link module:engine/view/textproxy~TextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
66
+ * This is `false` when text proxy starts at the very beginning of {@link module:engine/view/textproxy~ViewTextProxy#textNode textNode}
67
+ * ({@link module:engine/view/textproxy~ViewTextProxy#offsetInText offsetInText} equals `0`) and text proxy sizes is equal to
67
68
  * text node size.
68
69
  */
69
70
  get isPartial(): boolean;
70
71
  /**
71
72
  * Parent of this text proxy, which is same as parent of text node represented by this text proxy.
72
73
  */
73
- get parent(): Element | DocumentFragment | null;
74
+ get parent(): ViewElement | ViewDocumentFragment | null;
74
75
  /**
75
76
  * Root of this text proxy, which is same as root of text node represented by this text proxy.
76
77
  */
77
- get root(): Node | DocumentFragment;
78
+ get root(): ViewNode | ViewDocumentFragment;
78
79
  /**
79
- * {@link module:engine/view/document~Document View document} that owns this text proxy, or `null` if the text proxy is inside
80
- * {@link module:engine/view/documentfragment~DocumentFragment document fragment}.
80
+ * {@link module:engine/view/document~ViewDocument View document} that owns this text proxy, or `null` if the text proxy is inside
81
+ * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment}.
81
82
  */
82
- get document(): Document | null;
83
+ get document(): ViewDocument | null;
83
84
  /**
84
85
  * Returns ancestors array of this text proxy.
85
86
  *
@@ -92,5 +93,5 @@ export default class TextProxy extends TypeCheckable {
92
93
  getAncestors(options?: {
93
94
  includeSelf?: boolean;
94
95
  parentFirst?: boolean;
95
- }): Array<Text | Element | DocumentFragment>;
96
+ }): Array<ViewText | ViewElement | ViewDocumentFragment>;
96
97
  }