@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,541 +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/conversion/viewconsumable
7
- */
8
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * Class used for handling consumption of view {@link module:engine/view/element~ViewElement elements},
11
- * {@link module:engine/view/text~ViewText text nodes} and
12
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragments}.
13
- * Element's name and its parts (attributes, classes and styles) can be consumed separately. Consuming an element's name
14
- * does not consume its attributes, classes and styles.
15
- * To add items for consumption use {@link module:engine/conversion/viewconsumable~ViewConsumable#add add method}.
16
- * To test items use {@link module:engine/conversion/viewconsumable~ViewConsumable#test test method}.
17
- * To consume items use {@link module:engine/conversion/viewconsumable~ViewConsumable#consume consume method}.
18
- * To revert already consumed items use {@link module:engine/conversion/viewconsumable~ViewConsumable#revert revert method}.
19
- *
20
- * ```ts
21
- * viewConsumable.add( element, { name: true } ); // Adds element's name as ready to be consumed.
22
- * viewConsumable.add( textNode ); // Adds text node for consumption.
23
- * viewConsumable.add( docFragment ); // Adds document fragment for consumption.
24
- * viewConsumable.test( element, { name: true } ); // Tests if element's name can be consumed.
25
- * viewConsumable.test( textNode ); // Tests if text node can be consumed.
26
- * viewConsumable.test( docFragment ); // Tests if document fragment can be consumed.
27
- * viewConsumable.consume( element, { name: true } ); // Consume element's name.
28
- * viewConsumable.consume( textNode ); // Consume text node.
29
- * viewConsumable.consume( docFragment ); // Consume document fragment.
30
- * viewConsumable.revert( element, { name: true } ); // Revert already consumed element's name.
31
- * viewConsumable.revert( textNode ); // Revert already consumed text node.
32
- * viewConsumable.revert( docFragment ); // Revert already consumed document fragment.
33
- * ```
34
- */
35
- export class ViewConsumable {
36
- /**
37
- * Map of consumable elements. If {@link module:engine/view/element~ViewElement element} is used as a key,
38
- * {@link module:engine/conversion/viewconsumable~ViewElementConsumables ViewElementConsumables} instance is stored as value.
39
- * For {@link module:engine/view/text~ViewText text nodes} and
40
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragments} boolean value is stored as value.
41
- */
42
- _consumables = new Map();
43
- /**
44
- * Adds view {@link module:engine/view/element~ViewElement element}, {@link module:engine/view/text~ViewText text node} or
45
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment} as ready to be consumed.
46
- *
47
- * ```ts
48
- * viewConsumable.add( p, { name: true } ); // Adds element's name to consume.
49
- * viewConsumable.add( p, { attributes: 'name' } ); // Adds element's attribute.
50
- * viewConsumable.add( p, { classes: 'foobar' } ); // Adds element's class.
51
- * viewConsumable.add( p, { styles: 'color' } ); // Adds element's style
52
- * viewConsumable.add( p, { attributes: 'name', styles: 'color' } ); // Adds attribute and style.
53
- * viewConsumable.add( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be provided.
54
- * viewConsumable.add( textNode ); // Adds text node to consume.
55
- * viewConsumable.add( docFragment ); // Adds document fragment to consume.
56
- * ```
57
- *
58
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `viewconsumable-invalid-attribute` when `class` or `style`
59
- * attribute is provided - it should be handled separately by providing actual style/class.
60
- *
61
- * ```ts
62
- * viewConsumable.add( p, { attributes: 'style' } ); // This call will throw an exception.
63
- * viewConsumable.add( p, { styles: 'color' } ); // This is properly handled style.
64
- * ```
65
- *
66
- * @param consumables Used only if first parameter is {@link module:engine/view/element~ViewElement view element} instance.
67
- * @param consumables.name If set to true element's name will be included.
68
- * @param consumables.attributes Attribute name or array of attribute names.
69
- * @param consumables.classes Class name or array of class names.
70
- * @param consumables.styles Style name or array of style names.
71
- */
72
- add(element, consumables) {
73
- let elementConsumables;
74
- // For text nodes and document fragments just mark them as consumable.
75
- if (element.is('$text') || element.is('documentFragment')) {
76
- this._consumables.set(element, true);
77
- return;
78
- }
79
- // For elements create new ViewElementConsumables or update already existing one.
80
- if (!this._consumables.has(element)) {
81
- elementConsumables = new ViewElementConsumables(element);
82
- this._consumables.set(element, elementConsumables);
83
- }
84
- else {
85
- elementConsumables = this._consumables.get(element);
86
- }
87
- elementConsumables.add(consumables ? normalizeConsumables(consumables) : element._getConsumables());
88
- }
89
- /**
90
- * Tests if {@link module:engine/view/element~ViewElement view element}, {@link module:engine/view/text~ViewText text node} or
91
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment} can be consumed.
92
- * It returns `true` when all items included in method's call can be consumed. Returns `false` when
93
- * first already consumed item is found and `null` when first non-consumable item is found.
94
- *
95
- * ```ts
96
- * viewConsumable.test( p, { name: true } ); // Tests element's name.
97
- * viewConsumable.test( p, { attributes: 'name' } ); // Tests attribute.
98
- * viewConsumable.test( p, { classes: 'foobar' } ); // Tests class.
99
- * viewConsumable.test( p, { styles: 'color' } ); // Tests style.
100
- * viewConsumable.test( p, { attributes: 'name', styles: 'color' } ); // Tests attribute and style.
101
- * viewConsumable.test( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be tested.
102
- * viewConsumable.test( textNode ); // Tests text node.
103
- * viewConsumable.test( docFragment ); // Tests document fragment.
104
- * ```
105
- *
106
- * Testing classes and styles as attribute will test if all added classes/styles can be consumed.
107
- *
108
- * ```ts
109
- * viewConsumable.test( p, { attributes: 'class' } ); // Tests if all added classes can be consumed.
110
- * viewConsumable.test( p, { attributes: 'style' } ); // Tests if all added styles can be consumed.
111
- * ```
112
- *
113
- * @param consumables Used only if first parameter is {@link module:engine/view/element~ViewElement view element} instance.
114
- * @param consumables.name If set to true element's name will be included.
115
- * @param consumables.attributes Attribute name or array of attribute names.
116
- * @param consumables.classes Class name or array of class names.
117
- * @param consumables.styles Style name or array of style names.
118
- * @returns Returns `true` when all items included in method's call can be consumed. Returns `false`
119
- * when first already consumed item is found and `null` when first non-consumable item is found.
120
- */
121
- test(element, consumables) {
122
- const elementConsumables = this._consumables.get(element);
123
- if (elementConsumables === undefined) {
124
- return null;
125
- }
126
- // For text nodes and document fragments return stored boolean value.
127
- if (element.is('$text') || element.is('documentFragment')) {
128
- return elementConsumables;
129
- }
130
- // For elements test consumables object.
131
- return elementConsumables.test(normalizeConsumables(consumables));
132
- }
133
- /**
134
- * Consumes {@link module:engine/view/element~ViewElement view element}, {@link module:engine/view/text~ViewText text node} or
135
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment}.
136
- * It returns `true` when all items included in method's call can be consumed, otherwise returns `false`.
137
- *
138
- * ```ts
139
- * viewConsumable.consume( p, { name: true } ); // Consumes element's name.
140
- * viewConsumable.consume( p, { attributes: 'name' } ); // Consumes element's attribute.
141
- * viewConsumable.consume( p, { classes: 'foobar' } ); // Consumes element's class.
142
- * viewConsumable.consume( p, { styles: 'color' } ); // Consumes element's style.
143
- * viewConsumable.consume( p, { attributes: 'name', styles: 'color' } ); // Consumes attribute and style.
144
- * viewConsumable.consume( p, { classes: [ 'baz', 'bar' ] } ); // Multiple consumables can be consumed.
145
- * viewConsumable.consume( textNode ); // Consumes text node.
146
- * viewConsumable.consume( docFragment ); // Consumes document fragment.
147
- * ```
148
- *
149
- * Consuming classes and styles as attribute will test if all added classes/styles can be consumed.
150
- *
151
- * ```ts
152
- * viewConsumable.consume( p, { attributes: 'class' } ); // Consume only if all added classes can be consumed.
153
- * viewConsumable.consume( p, { attributes: 'style' } ); // Consume only if all added styles can be consumed.
154
- * ```
155
- *
156
- * @param consumables Used only if first parameter is {@link module:engine/view/element~ViewElement view element} instance.
157
- * @param consumables.name If set to true element's name will be included.
158
- * @param consumables.attributes Attribute name or array of attribute names.
159
- * @param consumables.classes Class name or array of class names.
160
- * @param consumables.styles Style name or array of style names.
161
- * @returns Returns `true` when all items included in method's call can be consumed,
162
- * otherwise returns `false`.
163
- */
164
- consume(element, consumables) {
165
- if (element.is('$text') || element.is('documentFragment')) {
166
- if (!this.test(element, consumables)) {
167
- return false;
168
- }
169
- // For text nodes and document fragments set value to false.
170
- this._consumables.set(element, false);
171
- return true;
172
- }
173
- // For elements - consume consumables object.
174
- const elementConsumables = this._consumables.get(element);
175
- if (elementConsumables === undefined) {
176
- return false;
177
- }
178
- return elementConsumables.consume(normalizeConsumables(consumables));
179
- }
180
- /**
181
- * Reverts {@link module:engine/view/element~ViewElement view element}, {@link module:engine/view/text~ViewText text node} or
182
- * {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment} so they can be consumed once again.
183
- * Method does not revert items that were never previously added for consumption, even if they are included in
184
- * method's call.
185
- *
186
- * ```ts
187
- * viewConsumable.revert( p, { name: true } ); // Reverts element's name.
188
- * viewConsumable.revert( p, { attributes: 'name' } ); // Reverts element's attribute.
189
- * viewConsumable.revert( p, { classes: 'foobar' } ); // Reverts element's class.
190
- * viewConsumable.revert( p, { styles: 'color' } ); // Reverts element's style.
191
- * viewConsumable.revert( p, { attributes: 'name', styles: 'color' } ); // Reverts attribute and style.
192
- * viewConsumable.revert( p, { classes: [ 'baz', 'bar' ] } ); // Multiple names can be reverted.
193
- * viewConsumable.revert( textNode ); // Reverts text node.
194
- * viewConsumable.revert( docFragment ); // Reverts document fragment.
195
- * ```
196
- *
197
- * Reverting classes and styles as attribute will revert all classes/styles that were previously added for
198
- * consumption.
199
- *
200
- * ```ts
201
- * viewConsumable.revert( p, { attributes: 'class' } ); // Reverts all classes added for consumption.
202
- * viewConsumable.revert( p, { attributes: 'style' } ); // Reverts all styles added for consumption.
203
- * ```
204
- *
205
- * @param consumables Used only if first parameter is {@link module:engine/view/element~ViewElement view element} instance.
206
- * @param consumables.name If set to true element's name will be included.
207
- * @param consumables.attributes Attribute name or array of attribute names.
208
- * @param consumables.classes Class name or array of class names.
209
- * @param consumables.styles Style name or array of style names.
210
- */
211
- revert(element, consumables) {
212
- const elementConsumables = this._consumables.get(element);
213
- if (elementConsumables !== undefined) {
214
- if (element.is('$text') || element.is('documentFragment')) {
215
- // For text nodes and document fragments - set consumable to true.
216
- this._consumables.set(element, true);
217
- }
218
- else {
219
- // For elements - revert items from consumables object.
220
- elementConsumables.revert(normalizeConsumables(consumables));
221
- }
222
- }
223
- }
224
- /**
225
- * Creates {@link module:engine/conversion/viewconsumable~ViewConsumable ViewConsumable} instance from
226
- * {@link module:engine/view/node~ViewNode node} or {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment}.
227
- * Instance will contain all elements, child nodes, attributes, styles and classes added for consumption.
228
- *
229
- * @param from View node or document fragment from which `ViewConsumable` will be created.
230
- * @param instance If provided, given `ViewConsumable` instance will be used
231
- * to add all consumables. It will be returned instead of a new instance.
232
- */
233
- static createFrom(from, instance) {
234
- if (!instance) {
235
- instance = new ViewConsumable();
236
- }
237
- if (from.is('$text')) {
238
- instance.add(from);
239
- }
240
- else if (from.is('element') || from.is('documentFragment')) {
241
- instance.add(from);
242
- for (const child of from.getChildren()) {
243
- ViewConsumable.createFrom(child, instance);
244
- }
245
- }
246
- return instance;
247
- }
248
- }
249
- /**
250
- * This is a private helper-class for {@link module:engine/conversion/viewconsumable~ViewConsumable}.
251
- * It represents and manipulates consumable parts of a single {@link module:engine/view/element~ViewElement}.
252
- *
253
- * @internal
254
- */
255
- export class ViewElementConsumables {
256
- element;
257
- /**
258
- * Flag indicating if name of the element can be consumed.
259
- */
260
- _canConsumeName = null;
261
- /**
262
- * A map of element's consumables.
263
- * * For plain attributes the value is a boolean indicating whether the attribute is available to consume.
264
- * * For token based attributes (like class list and style) the value is a map of tokens to booleans
265
- * indicating whether the token is available to consume on the given attribute.
266
- */
267
- _attributes = new Map();
268
- /**
269
- * Creates ViewElementConsumables instance.
270
- *
271
- * @param from View element from which `ViewElementConsumables` is being created.
272
- */
273
- constructor(from) {
274
- this.element = from;
275
- }
276
- /**
277
- * Adds consumable parts of the {@link module:engine/view/element~ViewElement view element}.
278
- * Element's name itself can be marked to be consumed (when element's name is consumed its attributes, classes and
279
- * styles still could be consumed):
280
- *
281
- * ```ts
282
- * consumables.add( { name: true } );
283
- * ```
284
- *
285
- * Attributes classes and styles:
286
- *
287
- * ```ts
288
- * consumables.add( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color'] ] } );
289
- * consumables.add( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
290
- * ```
291
- *
292
- * Note: This method accepts only {@link module:engine/view/element~ViewNormalizedConsumables}.
293
- * You can use {@link module:engine/conversion/viewconsumable~normalizeConsumables} helper to convert from
294
- * {@link module:engine/conversion/viewconsumable~Consumables} to `ViewNormalizedConsumables`.
295
- *
296
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `viewconsumable-invalid-attribute` when `class` or `style`
297
- * attribute is provided - it should be handled separately by providing `style` and `class` in consumables object.
298
- *
299
- * @param consumables Object describing which parts of the element can be consumed.
300
- */
301
- add(consumables) {
302
- if (consumables.name) {
303
- this._canConsumeName = true;
304
- }
305
- for (const [name, token] of consumables.attributes) {
306
- if (token) {
307
- let attributeTokens = this._attributes.get(name);
308
- if (!attributeTokens || typeof attributeTokens == 'boolean') {
309
- attributeTokens = new Map();
310
- this._attributes.set(name, attributeTokens);
311
- }
312
- attributeTokens.set(token, true);
313
- }
314
- else if (name == 'style' || name == 'class') {
315
- /**
316
- * Class and style attributes should be handled separately in
317
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#add `ViewConsumable#add()`}.
318
- *
319
- * What you have done is trying to use:
320
- *
321
- * ```ts
322
- * consumables.add( { attributes: [ 'class', 'style' ] } );
323
- * ```
324
- *
325
- * While each class and style should be registered separately:
326
- *
327
- * ```ts
328
- * consumables.add( { classes: 'some-class', styles: 'font-weight' } );
329
- * ```
330
- *
331
- * @error viewconsumable-invalid-attribute
332
- */
333
- throw new CKEditorError('viewconsumable-invalid-attribute', this);
334
- }
335
- else {
336
- this._attributes.set(name, true);
337
- }
338
- }
339
- }
340
- /**
341
- * Tests if parts of the {@link module:engine/view/element~ViewElement view element} can be consumed.
342
- *
343
- * Element's name can be tested:
344
- *
345
- * ```ts
346
- * consumables.test( { name: true } );
347
- * ```
348
- *
349
- * Attributes classes and styles:
350
- *
351
- * ```ts
352
- * consumables.test( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
353
- * consumables.test( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
354
- * ```
355
- *
356
- * @param consumables Object describing which parts of the element should be tested.
357
- * @returns `true` when all tested items can be consumed, `null` when even one of the items
358
- * was never marked for consumption and `false` when even one of the items was already consumed.
359
- */
360
- test(consumables) {
361
- // Check if name can be consumed.
362
- if (consumables.name && !this._canConsumeName) {
363
- return this._canConsumeName;
364
- }
365
- for (const [name, token] of consumables.attributes) {
366
- const value = this._attributes.get(name);
367
- // Return null if attribute is not found.
368
- if (value === undefined) {
369
- return null;
370
- }
371
- // Already consumed.
372
- if (value === false) {
373
- return false;
374
- }
375
- // Simple attribute is not consumed so continue to next attribute.
376
- if (value === true) {
377
- continue;
378
- }
379
- if (!token) {
380
- // Tokenized attribute but token is not specified so check if all tokens are not consumed.
381
- for (const tokenValue of value.values()) {
382
- // Already consumed token.
383
- if (!tokenValue) {
384
- return false;
385
- }
386
- }
387
- }
388
- else {
389
- const tokenValue = value.get(token);
390
- // Return null if token is not found.
391
- if (tokenValue === undefined) {
392
- return null;
393
- }
394
- // Already consumed.
395
- if (!tokenValue) {
396
- return false;
397
- }
398
- }
399
- }
400
- // Return true only if all can be consumed.
401
- return true;
402
- }
403
- /**
404
- * Tests if parts of the {@link module:engine/view/element~ViewElement view element} can be consumed and consumes them if available.
405
- * It returns `true` when all items included in method's call can be consumed, otherwise returns `false`.
406
- *
407
- * Element's name can be consumed:
408
- *
409
- * ```ts
410
- * consumables.consume( { name: true } );
411
- * ```
412
- *
413
- * Attributes classes and styles:
414
- *
415
- * ```ts
416
- * consumables.consume( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
417
- * consumables.consume( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
418
- * ```
419
- *
420
- * @param consumables Object describing which parts of the element should be consumed.
421
- * @returns `true` when all tested items can be consumed and `false` when even one of the items could not be consumed.
422
- */
423
- consume(consumables) {
424
- if (!this.test(consumables)) {
425
- return false;
426
- }
427
- if (consumables.name) {
428
- this._canConsumeName = false;
429
- }
430
- for (const [name, token] of consumables.attributes) {
431
- // `value` must be set, because `this.test()` returned `true`.
432
- const value = this._attributes.get(name);
433
- // Plain (not tokenized) not-consumed attribute.
434
- if (typeof value == 'boolean') {
435
- // Use Element API to collect related attributes.
436
- for (const [toConsume] of this.element._getConsumables(name, token).attributes) {
437
- this._attributes.set(toConsume, false);
438
- }
439
- }
440
- else if (!token) {
441
- // Tokenized attribute but token is not specified so consume all tokens.
442
- for (const token of value.keys()) {
443
- value.set(token, false);
444
- }
445
- }
446
- else {
447
- // Use Element API to collect related attribute tokens.
448
- for (const [, toConsume] of this.element._getConsumables(name, token).attributes) {
449
- value.set(toConsume, false);
450
- }
451
- }
452
- }
453
- return true;
454
- }
455
- /**
456
- * Revert already consumed parts of {@link module:engine/view/element~ViewElement view Element}, so they can be consumed once again.
457
- * Element's name can be reverted:
458
- *
459
- * ```ts
460
- * consumables.revert( { name: true } );
461
- * ```
462
- *
463
- * Attributes classes and styles:
464
- *
465
- * ```ts
466
- * consumables.revert( { attributes: [ [ 'title' ], [ 'class', 'foo' ], [ 'style', 'color' ] ] } );
467
- * consumables.revert( { attributes: [ [ 'title' ], [ 'name' ], [ 'class', 'foo' ], [ 'class', 'bar' ] ] } );
468
- * ```
469
- *
470
- * @param consumables Object describing which parts of the element should be reverted.
471
- */
472
- revert(consumables) {
473
- if (consumables.name) {
474
- this._canConsumeName = true;
475
- }
476
- for (const [name, token] of consumables.attributes) {
477
- const value = this._attributes.get(name);
478
- // Plain consumed attribute.
479
- if (value === false) {
480
- this._attributes.set(name, true);
481
- continue;
482
- }
483
- // Unknown attribute or not consumed.
484
- if (value === undefined || value === true) {
485
- continue;
486
- }
487
- if (!token) {
488
- // Tokenized attribute but token is not specified so revert all tokens.
489
- for (const token of value.keys()) {
490
- value.set(token, true);
491
- }
492
- }
493
- else {
494
- const tokenValue = value.get(token);
495
- if (tokenValue === false) {
496
- value.set(token, true);
497
- }
498
- // Note that revert of consumed related styles is not handled.
499
- }
500
- }
501
- }
502
- }
503
- /**
504
- * Normalizes a {@link module:engine/conversion/viewconsumable~Consumables} or {@link module:engine/view/matcher~Match}
505
- * to a {@link module:engine/view/element~ViewNormalizedConsumables}.
506
- *
507
- * @internal
508
- */
509
- export function normalizeConsumables(consumables) {
510
- const attributes = [];
511
- if ('attributes' in consumables && consumables.attributes) {
512
- normalizeConsumablePart(attributes, consumables.attributes);
513
- }
514
- if ('classes' in consumables && consumables.classes) {
515
- normalizeConsumablePart(attributes, consumables.classes, 'class');
516
- }
517
- if ('styles' in consumables && consumables.styles) {
518
- normalizeConsumablePart(attributes, consumables.styles, 'style');
519
- }
520
- return {
521
- name: consumables.name || false,
522
- attributes
523
- };
524
- }
525
- /**
526
- * Normalizes a list of consumable attributes to a common tuple format.
527
- */
528
- function normalizeConsumablePart(attributes, items, prefix) {
529
- if (typeof items == 'string') {
530
- attributes.push(prefix ? [prefix, items] : [items]);
531
- return;
532
- }
533
- for (const item of items) {
534
- if (Array.isArray(item)) {
535
- attributes.push(item);
536
- }
537
- else {
538
- attributes.push(prefix ? [prefix, item] : [item]);
539
- }
540
- }
541
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- import { global } from '@ckeditor/ckeditor5-utils';
6
- /**
7
- * Basic HTML writer. It uses the native `innerHTML` property for basic conversion
8
- * from a document fragment to an HTML string.
9
- *
10
- * @internal
11
- */
12
- export class BasicHtmlWriter {
13
- /**
14
- * Returns an HTML string created from the document fragment.
15
- */
16
- getHtml(fragment) {
17
- const doc = global.document.implementation.createHTMLDocument('');
18
- const container = doc.createElement('div');
19
- container.appendChild(fragment);
20
- return container.innerHTML;
21
- }
22
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- export {};
@@ -1,107 +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/dataprocessor/htmldataprocessor
7
- */
8
- import { BasicHtmlWriter } from './basichtmlwriter.js';
9
- import { ViewDomConverter } from '../view/domconverter.js';
10
- /**
11
- * The HTML data processor class.
12
- * This data processor implementation uses HTML as input and output data.
13
- */
14
- export class HtmlDataProcessor {
15
- /**
16
- * A DOM parser instance used to parse an HTML string to an HTML document.
17
- */
18
- domParser;
19
- /**
20
- * A DOM converter used to convert DOM elements to view elements.
21
- */
22
- domConverter;
23
- /**
24
- * A basic HTML writer instance used to convert DOM elements to an HTML string.
25
- */
26
- htmlWriter;
27
- skipComments = true;
28
- /**
29
- * Creates a new instance of the HTML data processor class.
30
- *
31
- * @param document The view document instance.
32
- */
33
- constructor(document) {
34
- this.domParser = new DOMParser();
35
- this.domConverter = new ViewDomConverter(document, { renderingMode: 'data' });
36
- this.htmlWriter = new BasicHtmlWriter();
37
- }
38
- /**
39
- * Converts a provided {@link module:engine/view/documentfragment~ViewDocumentFragment document fragment}
40
- * to data format – in this case to an HTML string.
41
- *
42
- * @returns HTML string.
43
- */
44
- toData(viewFragment) {
45
- // Convert view DocumentFragment to DOM DocumentFragment.
46
- const domFragment = this.domConverter.viewToDom(viewFragment);
47
- // Convert DOM DocumentFragment to HTML output.
48
- return this.htmlWriter.getHtml(domFragment);
49
- }
50
- /**
51
- * Converts the provided HTML string to a view tree.
52
- *
53
- * @param data An HTML string.
54
- * @returns A converted view element.
55
- */
56
- toView(data) {
57
- // Convert input HTML data to DOM DocumentFragment.
58
- const domFragment = this._toDom(data);
59
- // Convert DOM DocumentFragment to view DocumentFragment.
60
- return this.domConverter.domToView(domFragment, { skipComments: this.skipComments });
61
- }
62
- /**
63
- * Registers a {@link module:engine/view/matcher~MatcherPattern} for view elements whose content should be treated as raw data
64
- * and not processed during the conversion from the DOM to the view elements.
65
- *
66
- * The raw data can be later accessed by a
67
- * {@link module:engine/view/element~ViewElement#getCustomProperty custom property of a view element} called `"$rawContent"`.
68
- *
69
- * @param pattern Pattern matching all view elements whose content should be treated as raw data.
70
- */
71
- registerRawContentMatcher(pattern) {
72
- this.domConverter.registerRawContentMatcher(pattern);
73
- }
74
- /**
75
- * If the processor is set to use marked fillers, it will insert `&nbsp;` fillers wrapped in `<span>` elements
76
- * (`<span data-cke-filler="true">&nbsp;</span>`) instead of regular `&nbsp;` characters.
77
- *
78
- * This mode allows for a more precise handling of the block fillers (so they do not leak into the editor content) but
79
- * bloats the editor data with additional markup.
80
- *
81
- * This mode may be required by some features and will be turned on by them automatically.
82
- *
83
- * @param type Whether to use the default or the marked `&nbsp;` block fillers.
84
- */
85
- useFillerType(type) {
86
- this.domConverter.blockFillerMode = type == 'marked' ? 'markedNbsp' : 'nbsp';
87
- }
88
- /**
89
- * Converts an HTML string to its DOM representation. Returns a document fragment containing nodes parsed from
90
- * the provided data.
91
- */
92
- _toDom(data) {
93
- // Wrap data with a <body> tag so leading non-layout nodes (like <script>, <style>, HTML comment)
94
- // will be preserved in the body collection.
95
- // Do it only for data that is not a full HTML document.
96
- if (!/<(?:html|body|head|meta)(?:\s[^>]*)?>/i.test(data.trim().slice(0, 10000))) {
97
- data = `<body>${data}</body>`;
98
- }
99
- const document = this.domParser.parseFromString(data, 'text/html');
100
- const fragment = document.createDocumentFragment();
101
- const bodyChildNodes = document.body.childNodes;
102
- while (bodyChildNodes.length > 0) {
103
- fragment.appendChild(bodyChildNodes[0]);
104
- }
105
- return fragment;
106
- }
107
- }