@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,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,83 +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/view/emptyelement
7
- */
8
- import { ViewElement } from './element.js';
9
- import { ViewNode } from './node.js';
10
- import { CKEditorError } from '@ckeditor/ckeditor5-utils';
11
- /**
12
- * Empty element class. It is used to represent elements that cannot contain any child nodes (for example `<img>` elements).
13
- *
14
- * To create a new empty element use the
15
- * {@link module:engine/view/downcastwriter~ViewDowncastWriter#createEmptyElement `downcastWriter#createEmptyElement()`} method.
16
- */
17
- export class ViewEmptyElement extends ViewElement {
18
- /**
19
- * Creates new instance of ViewEmptyElement.
20
- *
21
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-emptyelement-cannot-add` when third parameter is passed,
22
- * to inform that usage of ViewEmptyElement is incorrect (adding child nodes to ViewEmptyElement is forbidden).
23
- *
24
- * @see module:engine/view/downcastwriter~ViewDowncastWriter#createEmptyElement
25
- * @internal
26
- * @param document The document instance to which this element belongs.
27
- * @param name Node name.
28
- * @param attributes Collection of attributes.
29
- * @param children A list of nodes to be inserted into created element.
30
- */
31
- constructor(document, name, attributes, children) {
32
- super(document, name, attributes, children);
33
- this.getFillerOffset = getFillerOffset;
34
- }
35
- /**
36
- * Converts `ViewEmptyElement` instance to plain object and returns it.
37
- *
38
- * @returns `ViewEmptyElement` instance converted to plain object.
39
- */
40
- toJSON() {
41
- const json = super.toJSON();
42
- json.type = 'EmptyElement';
43
- return json;
44
- }
45
- /**
46
- * Overrides {@link module:engine/view/element~ViewElement#_insertChild} method.
47
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent
48
- * adding any child nodes to ViewEmptyElement.
49
- *
50
- * @internal
51
- */
52
- _insertChild(index, items) {
53
- if (items && (items instanceof ViewNode || Array.from(items).length > 0)) {
54
- /**
55
- * Cannot add children to {@link module:engine/view/emptyelement~ViewEmptyElement}.
56
- *
57
- * @error view-emptyelement-cannot-add
58
- */
59
- throw new CKEditorError('view-emptyelement-cannot-add', [this, items]);
60
- }
61
- return 0;
62
- }
63
- }
64
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
65
- // Proper overload would interfere with that.
66
- ViewEmptyElement.prototype.is = function (type, name) {
67
- if (!name) {
68
- return type === 'emptyElement' || type === 'view:emptyElement' ||
69
- // From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
70
- type === 'element' || type === 'view:element' ||
71
- type === 'node' || type === 'view:node';
72
- }
73
- else {
74
- return name === this.name && (type === 'emptyElement' || type === 'view:emptyElement' ||
75
- type === 'element' || type === 'view:element');
76
- }
77
- };
78
- /**
79
- * Returns `null` because block filler is not needed for ViewEmptyElements.
80
- */
81
- function getFillerOffset() {
82
- return null;
83
- }
@@ -1,161 +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 { keyCodes, isText } from '@ckeditor/ckeditor5-utils';
6
- /**
7
- * Set of utilities related to handling block and inline fillers.
8
- *
9
- * Browsers do not allow to put caret in elements which does not have height. Because of it, we need to fill all
10
- * empty elements which should be selectable with elements or characters called "fillers". Unfortunately there is no one
11
- * universal filler, this is why two types are uses:
12
- *
13
- * * Block filler is an element which fill block elements, like `<p>`. CKEditor uses `<br>` as a block filler during the editing,
14
- * as browsers do natively. So instead of an empty `<p>` there will be `<p><br></p>`. The advantage of block filler is that
15
- * it is transparent for the selection, so when the caret is before the `<br>` and user presses right arrow he will be
16
- * moved to the next paragraph, not after the `<br>`. The disadvantage is that it breaks a block, so it cannot be used
17
- * in the middle of a line of text. The {@link module:engine/view/filler~BR_FILLER `<br>` filler} can be replaced with any other
18
- * character in the data output, for instance {@link module:engine/view/filler~NBSP_FILLER non-breaking space} or
19
- * {@link module:engine/view/filler~MARKED_NBSP_FILLER marked non-breaking space}.
20
- *
21
- * * Inline filler is a filler which does not break a line of text, so it can be used inside the text, for instance in the empty
22
- * `<b>` surrendered by text: `foo<b></b>bar`, if we want to put the caret there. CKEditor uses a sequence of the zero-width
23
- * spaces as an {@link module:engine/view/filler~INLINE_FILLER inline filler} having the predetermined
24
- * {@link module:engine/view/filler~INLINE_FILLER_LENGTH length}. A sequence is used, instead of a single character to
25
- * avoid treating random zero-width spaces as the inline filler. Disadvantage of the inline filler is that it is not
26
- * transparent for the selection. The arrow key moves the caret between zero-width spaces characters, so the additional
27
- * code is needed to handle the caret.
28
- *
29
- * Both inline and block fillers are handled by the {@link module:engine/view/renderer~ViewRenderer renderer} and are not present in the
30
- * view.
31
- *
32
- * @module engine/view/filler
33
- */
34
- /**
35
- * Non-breaking space filler creator. This function creates the `&nbsp;` text node.
36
- * It defines how the filler is created.
37
- *
38
- * @see module:engine/view/filler~MARKED_NBSP_FILLER
39
- * @see module:engine/view/filler~BR_FILLER
40
- * @internal
41
- */
42
- export const NBSP_FILLER = (domDocument) => domDocument.createTextNode('\u00A0');
43
- /**
44
- * Marked non-breaking space filler creator. This function creates the `<span data-cke-filler="true">&nbsp;</span>` element.
45
- * It defines how the filler is created.
46
- *
47
- * @see module:engine/view/filler~NBSP_FILLER
48
- * @see module:engine/view/filler~BR_FILLER
49
- * @internal
50
- */
51
- export const MARKED_NBSP_FILLER = (domDocument) => {
52
- const span = domDocument.createElement('span');
53
- span.dataset.ckeFiller = 'true';
54
- span.innerText = '\u00A0';
55
- return span;
56
- };
57
- /**
58
- * `<br>` filler creator. This function creates the `<br data-cke-filler="true">` element.
59
- * It defines how the filler is created.
60
- *
61
- * @see module:engine/view/filler~NBSP_FILLER
62
- * @see module:engine/view/filler~MARKED_NBSP_FILLER
63
- * @internal
64
- */
65
- export const BR_FILLER = (domDocument) => {
66
- const fillerBr = domDocument.createElement('br');
67
- fillerBr.dataset.ckeFiller = 'true';
68
- return fillerBr;
69
- };
70
- /**
71
- * Length of the {@link module:engine/view/filler~INLINE_FILLER INLINE_FILLER}.
72
- *
73
- * @internal
74
- */
75
- export const INLINE_FILLER_LENGTH = 7;
76
- /**
77
- * Inline filler which is a sequence of the word joiners.
78
- *
79
- * @internal
80
- */
81
- export const INLINE_FILLER = '\u2060'.repeat(INLINE_FILLER_LENGTH);
82
- /**
83
- * Checks if the node is a text node which starts with the {@link module:engine/view/filler~INLINE_FILLER inline filler}.
84
- *
85
- * ```ts
86
- * startsWithFiller( document.createTextNode( INLINE_FILLER ) ); // true
87
- * startsWithFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ); // true
88
- * startsWithFiller( document.createTextNode( 'foo' ) ); // false
89
- * startsWithFiller( document.createElement( 'p' ) ); // false
90
- * ```
91
- *
92
- * @param domNode DOM node.
93
- * @returns True if the text node starts with the {@link module:engine/view/filler~INLINE_FILLER inline filler}.
94
- * @internal
95
- */
96
- export function startsWithFiller(domNode) {
97
- if (typeof domNode == 'string') {
98
- return domNode.substr(0, INLINE_FILLER_LENGTH) === INLINE_FILLER;
99
- }
100
- return isText(domNode) && (domNode.data.substr(0, INLINE_FILLER_LENGTH) === INLINE_FILLER);
101
- }
102
- /**
103
- * Checks if the text node contains only the {@link module:engine/view/filler~INLINE_FILLER inline filler}.
104
- *
105
- * ```ts
106
- * isInlineFiller( document.createTextNode( INLINE_FILLER ) ); // true
107
- * isInlineFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ); // false
108
- * ```
109
- *
110
- * @param domText DOM text node.
111
- * @returns True if the text node contains only the {@link module:engine/view/filler~INLINE_FILLER inline filler}.
112
- * @internal
113
- */
114
- export function isInlineFiller(domText) {
115
- return domText.data.length == INLINE_FILLER_LENGTH && startsWithFiller(domText);
116
- }
117
- /**
118
- * Get string data from the text node, removing an {@link module:engine/view/filler~INLINE_FILLER inline filler} from it,
119
- * if text node contains it.
120
- *
121
- * ```ts
122
- * getDataWithoutFiller( document.createTextNode( INLINE_FILLER + 'foo' ) ) == 'foo' // true
123
- * getDataWithoutFiller( document.createTextNode( 'foo' ) ) == 'foo' // true
124
- * ```
125
- *
126
- * @param domText DOM text node, possible with inline filler.
127
- * @returns Data without filler.
128
- * @internal
129
- */
130
- export function getDataWithoutFiller(domText) {
131
- const data = typeof domText == 'string' ? domText : domText.data;
132
- if (startsWithFiller(domText)) {
133
- return data.slice(INLINE_FILLER_LENGTH);
134
- }
135
- return data;
136
- }
137
- /**
138
- * Assign key observer which move cursor from the end of the inline filler to the beginning of it when
139
- * the left arrow is pressed, so the filler does not break navigation.
140
- *
141
- * @param view View controller instance we should inject quirks handling on.
142
- * @internal
143
- */
144
- export function injectQuirksHandling(view) {
145
- view.document.on('arrowKey', jumpOverInlineFiller, { priority: 'low' });
146
- }
147
- /**
148
- * Move cursor from the end of the inline filler to the beginning of it when, so the filler does not break navigation.
149
- */
150
- function jumpOverInlineFiller(evt, data) {
151
- if (data.keyCode == keyCodes.arrowleft) {
152
- const domSelection = data.domTarget.ownerDocument.defaultView.getSelection();
153
- if (domSelection.rangeCount == 1 && domSelection.getRangeAt(0).collapsed) {
154
- const domParent = domSelection.getRangeAt(0).startContainer;
155
- const domOffset = domSelection.getRangeAt(0).startOffset;
156
- if (startsWithFiller(domParent) && domOffset <= INLINE_FILLER_LENGTH) {
157
- domSelection.collapse(domParent, 0);
158
- }
159
- }
160
- }
161
- }
package/src/view/item.js DELETED
@@ -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,437 +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 { logWarning } from '@ckeditor/ckeditor5-utils';
6
- import { normalizeConsumables } from '../conversion/viewconsumable.js';
7
- /**
8
- * View matcher class.
9
- * Instance of this class can be used to find {@link module:engine/view/element~ViewElement elements} that match given pattern.
10
- */
11
- export class Matcher {
12
- _patterns = [];
13
- /**
14
- * Creates new instance of Matcher.
15
- *
16
- * @param pattern Match patterns. See {@link module:engine/view/matcher~Matcher#add add method} for more information.
17
- */
18
- constructor(...pattern) {
19
- this.add(...pattern);
20
- }
21
- /**
22
- * Adds pattern or patterns to matcher instance.
23
- *
24
- * ```ts
25
- * // String.
26
- * matcher.add( 'div' );
27
- *
28
- * // Regular expression.
29
- * matcher.add( /^\w/ );
30
- *
31
- * // Single class.
32
- * matcher.add( {
33
- * classes: 'foobar'
34
- * } );
35
- * ```
36
- *
37
- * See {@link module:engine/view/matcher~MatcherPattern} for more examples.
38
- *
39
- * Multiple patterns can be added in one call:
40
- *
41
- * ```ts
42
- * matcher.add( 'div', { classes: 'foobar' } );
43
- * ```
44
- *
45
- * @param pattern Object describing pattern details. If string or regular expression
46
- * is provided it will be used to match element's name. Pattern can be also provided in a form
47
- * of a function - then this function will be called with each {@link module:engine/view/element~ViewElement element} as a parameter.
48
- * Function's return value will be stored under `match` key of the object returned from
49
- * {@link module:engine/view/matcher~Matcher#match match} or {@link module:engine/view/matcher~Matcher#matchAll matchAll} methods.
50
- */
51
- add(...pattern) {
52
- for (let item of pattern) {
53
- // String or RegExp pattern is used as element's name.
54
- if (typeof item == 'string' || item instanceof RegExp) {
55
- item = { name: item };
56
- }
57
- this._patterns.push(item);
58
- }
59
- }
60
- /**
61
- * Matches elements for currently stored patterns. Returns match information about first found
62
- * {@link module:engine/view/element~ViewElement element}, otherwise returns `null`.
63
- *
64
- * Example of returned object:
65
- *
66
- * ```ts
67
- * {
68
- * element: <instance of found element>,
69
- * pattern: <pattern used to match found element>,
70
- * match: {
71
- * name: true,
72
- * attributes: [
73
- * [ 'title' ],
74
- * [ 'href' ],
75
- * [ 'class', 'foo' ],
76
- * [ 'style', 'color' ],
77
- * [ 'style', 'position' ]
78
- * ]
79
- * }
80
- * }
81
- * ```
82
- *
83
- * You could use the `match` field from the above returned object as an input for the
84
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#test `ViewConsumable#test()`} and
85
- * {@link module:engine/conversion/viewconsumable~ViewConsumable#consume `ViewConsumable#consume()`} methods.
86
- *
87
- * @see module:engine/view/matcher~Matcher#add
88
- * @see module:engine/view/matcher~Matcher#matchAll
89
- * @param element View element to match against stored patterns.
90
- * @returns The match information about found element or `null`.
91
- */
92
- match(...element) {
93
- for (const singleElement of element) {
94
- for (const pattern of this._patterns) {
95
- const match = this._isElementMatching(singleElement, pattern);
96
- if (match) {
97
- return {
98
- element: singleElement,
99
- pattern,
100
- match
101
- };
102
- }
103
- }
104
- }
105
- return null;
106
- }
107
- /**
108
- * Matches elements for currently stored patterns. Returns array of match information with all found
109
- * {@link module:engine/view/element~ViewElement elements}. If no element is found - returns `null`.
110
- *
111
- * @see module:engine/view/matcher~Matcher#add
112
- * @see module:engine/view/matcher~Matcher#match
113
- * @param element View element to match against stored patterns.
114
- * @returns Array with match information about found elements or `null`. For more information
115
- * see {@link module:engine/view/matcher~Matcher#match match method} description.
116
- */
117
- matchAll(...element) {
118
- const results = [];
119
- for (const singleElement of element) {
120
- for (const pattern of this._patterns) {
121
- const match = this._isElementMatching(singleElement, pattern);
122
- if (match) {
123
- results.push({
124
- element: singleElement,
125
- pattern,
126
- match
127
- });
128
- }
129
- }
130
- }
131
- return results.length > 0 ? results : null;
132
- }
133
- /**
134
- * Returns the name of the element to match if there is exactly one pattern added to the matcher instance
135
- * and it matches element name defined by `string` (not `RegExp`). Otherwise, returns `null`.
136
- *
137
- * @returns Element name trying to match.
138
- */
139
- getElementName() {
140
- if (this._patterns.length !== 1) {
141
- return null;
142
- }
143
- const pattern = this._patterns[0];
144
- const name = pattern.name;
145
- return (typeof pattern != 'function' && name && !(name instanceof RegExp)) ? name : null;
146
- }
147
- /**
148
- * Returns match information if {@link module:engine/view/element~ViewElement element} is matching provided pattern.
149
- * If element cannot be matched to provided pattern - returns `null`.
150
- *
151
- * @returns Returns object with match information or null if element is not matching.
152
- */
153
- _isElementMatching(element, pattern) {
154
- // If pattern is provided as function - return result of that function;
155
- if (typeof pattern == 'function') {
156
- const match = pattern(element);
157
- // In some places we use Matcher with callback pattern that returns boolean.
158
- if (!match || typeof match != 'object') {
159
- return match;
160
- }
161
- return normalizeConsumables(match);
162
- }
163
- const match = {};
164
- // Check element's name.
165
- if (pattern.name) {
166
- match.name = matchName(pattern.name, element.name);
167
- if (!match.name) {
168
- return null;
169
- }
170
- }
171
- const attributesMatch = [];
172
- // Check element's attributes.
173
- if (pattern.attributes && !matchAttributes(pattern.attributes, element, attributesMatch)) {
174
- return null;
175
- }
176
- // Check element's classes.
177
- if (pattern.classes && !matchClasses(pattern.classes, element, attributesMatch)) {
178
- return null;
179
- }
180
- // Check element's styles.
181
- if (pattern.styles && !matchStyles(pattern.styles, element, attributesMatch)) {
182
- return null;
183
- }
184
- // Note the `attributesMatch` array is populated by the above calls.
185
- if (attributesMatch.length) {
186
- match.attributes = attributesMatch;
187
- }
188
- return match;
189
- }
190
- }
191
- /**
192
- * Returns true if the given `item` matches the pattern.
193
- *
194
- * @internal
195
- * @param pattern A pattern representing a key/value we want to match.
196
- * @param item An actual item key/value (e.g. `'src'`, `'background-color'`, `'ck-widget'`) we're testing against pattern.
197
- */
198
- export function isPatternMatched(pattern, item) {
199
- return pattern === true ||
200
- pattern === item ||
201
- pattern instanceof RegExp && !!String(item).match(pattern);
202
- }
203
- /**
204
- * Checks if name can be matched by provided pattern.
205
- *
206
- * @returns Returns `true` if name can be matched, `false` otherwise.
207
- */
208
- function matchName(pattern, name) {
209
- // If pattern is provided as RegExp - test against this regexp.
210
- if (pattern instanceof RegExp) {
211
- return !!name.match(pattern);
212
- }
213
- return pattern === name;
214
- }
215
- /**
216
- * Bring all the possible pattern forms to an array of tuples where first item is a key, second is a value,
217
- * and third optional is a token value.
218
- *
219
- * Examples:
220
- *
221
- * Boolean pattern value:
222
- *
223
- * ```ts
224
- * true
225
- * ```
226
- *
227
- * to
228
- *
229
- * ```ts
230
- * [ [ true, true ] ]
231
- * ```
232
- *
233
- * Textual pattern value:
234
- *
235
- * ```ts
236
- * 'attribute-name-or-class-or-style'
237
- * ```
238
- *
239
- * to
240
- *
241
- * ```ts
242
- * [ [ 'attribute-name-or-class-or-style', true ] ]
243
- * ```
244
- *
245
- * Regular expression:
246
- *
247
- * ```ts
248
- * /^data-.*$/
249
- * ```
250
- *
251
- * to
252
- *
253
- * ```ts
254
- * [ [ /^data-.*$/, true ] ]
255
- * ```
256
- *
257
- * Objects (plain or with `key` and `value` specified explicitly):
258
- *
259
- * ```ts
260
- * {
261
- * src: /^https:.*$/
262
- * }
263
- * ```
264
- *
265
- * or
266
- *
267
- * ```ts
268
- * [ {
269
- * key: 'src',
270
- * value: /^https:.*$/
271
- * } ]
272
- * ```
273
- *
274
- * to:
275
- *
276
- * ```ts
277
- * [ [ 'src', /^https:.*$/ ] ]
278
- * ```
279
- *
280
- * @returns Returns an array of objects or null if provided patterns were not in an expected form.
281
- */
282
- function normalizePatterns(patterns, prefix) {
283
- if (Array.isArray(patterns)) {
284
- return patterns.map(pattern => {
285
- if (typeof pattern !== 'object' || pattern instanceof RegExp) {
286
- return prefix ?
287
- [prefix, pattern, true] :
288
- [pattern, true];
289
- }
290
- if (pattern.key === undefined || pattern.value === undefined) {
291
- // Documented at the end of matcher.js.
292
- logWarning('matcher-pattern-missing-key-or-value', pattern);
293
- }
294
- return prefix ?
295
- [prefix, pattern.key, pattern.value] :
296
- [pattern.key, pattern.value];
297
- });
298
- }
299
- if (typeof patterns !== 'object' || patterns instanceof RegExp) {
300
- return [
301
- prefix ?
302
- [prefix, patterns, true] :
303
- [patterns, true]
304
- ];
305
- }
306
- // Below we do what Object.entries() does, but faster
307
- const normalizedPatterns = [];
308
- for (const key in patterns) {
309
- // Replace with Object.hasOwn() when we upgrade to es2022.
310
- if (Object.prototype.hasOwnProperty.call(patterns, key)) {
311
- normalizedPatterns.push(prefix ?
312
- [prefix, key, patterns[key]] :
313
- [key, patterns[key]]);
314
- }
315
- }
316
- return normalizedPatterns;
317
- }
318
- /**
319
- * Checks if attributes of provided element can be matched against provided patterns.
320
- *
321
- * @param patterns Object with information about attributes to match. Each key of the object will be
322
- * used as attribute name. Value of each key can be a string or regular expression to match against attribute value.
323
- * @param element Element which attributes will be tested.
324
- * @param match An array to populate with matching tuples.
325
- * @returns Returns array with matched attribute names or `null` if no attributes were matched.
326
- */
327
- function matchAttributes(patterns, element, match) {
328
- let excludeAttributes;
329
- // `style` and `class` attribute keys are deprecated. Only allow them in object pattern
330
- // for backward compatibility.
331
- if (typeof patterns === 'object' && !(patterns instanceof RegExp) && !Array.isArray(patterns)) {
332
- if (patterns.style !== undefined) {
333
- // Documented at the end of matcher.js.
334
- logWarning('matcher-pattern-deprecated-attributes-style-key', patterns);
335
- }
336
- if (patterns.class !== undefined) {
337
- // Documented at the end of matcher.js.
338
- logWarning('matcher-pattern-deprecated-attributes-class-key', patterns);
339
- }
340
- }
341
- else {
342
- excludeAttributes = ['class', 'style'];
343
- }
344
- return element._collectAttributesMatch(normalizePatterns(patterns), match, excludeAttributes);
345
- }
346
- /**
347
- * Checks if classes of provided element can be matched against provided patterns.
348
- *
349
- * @param patterns Array of strings or regular expressions to match against element's classes.
350
- * @param element Element which classes will be tested.
351
- * @param match An array to populate with matching tuples.
352
- * @returns Returns array with matched class names or `null` if no classes were matched.
353
- */
354
- function matchClasses(patterns, element, match) {
355
- return element._collectAttributesMatch(normalizePatterns(patterns, 'class'), match);
356
- }
357
- /**
358
- * Checks if styles of provided element can be matched against provided patterns.
359
- *
360
- * @param patterns Object with information about styles to match. Each key of the object will be
361
- * used as style name. Value of each key can be a string or regular expression to match against style value.
362
- * @param element Element which styles will be tested.
363
- * @param match An array to populate with matching tuples.
364
- * @returns Returns array with matched style names or `null` if no styles were matched.
365
- */
366
- function matchStyles(patterns, element, match) {
367
- return element._collectAttributesMatch(normalizePatterns(patterns, 'style'), match);
368
- }
369
- /**
370
- * The key-value matcher pattern is missing key or value. Both must be present.
371
- * Refer the documentation: {@link module:engine/view/matcher~MatcherPattern}.
372
- *
373
- * @param pattern Pattern with missing properties.
374
- * @error matcher-pattern-missing-key-or-value
375
- */
376
- /**
377
- * The key-value matcher pattern for `attributes` option is using deprecated `style` key.
378
- *
379
- * Use `styles` matcher pattern option instead:
380
- *
381
- * ```ts
382
- * // Instead of:
383
- * const pattern = {
384
- * attributes: {
385
- * key1: 'value1',
386
- * key2: 'value2',
387
- * style: /^border.*$/
388
- * }
389
- * }
390
- *
391
- * // Use:
392
- * const pattern = {
393
- * attributes: {
394
- * key1: 'value1',
395
- * key2: 'value2'
396
- * },
397
- * styles: /^border.*$/
398
- * }
399
- * ```
400
- *
401
- * Refer to the {@glink updating/guides/update-to-29##update-to-ckeditor-5-v2910 Migration to v29.1.0} guide
402
- * and {@link module:engine/view/matcher~MatcherPattern} documentation.
403
- *
404
- * @param pattern Pattern with missing properties.
405
- * @error matcher-pattern-deprecated-attributes-style-key
406
- */
407
- /**
408
- * The key-value matcher pattern for `attributes` option is using deprecated `class` key.
409
- *
410
- * Use `classes` matcher pattern option instead:
411
- *
412
- * ```ts
413
- * // Instead of:
414
- * const pattern = {
415
- * attributes: {
416
- * key1: 'value1',
417
- * key2: 'value2',
418
- * class: 'foobar'
419
- * }
420
- * }
421
- *
422
- * // Use:
423
- * const pattern = {
424
- * attributes: {
425
- * key1: 'value1',
426
- * key2: 'value2'
427
- * },
428
- * classes: 'foobar'
429
- * }
430
- * ```
431
- *
432
- * Refer to the {@glink updating/guides/update-to-29##update-to-ckeditor-5-v2910 Migration to v29.1.0} guide
433
- * and the {@link module:engine/view/matcher~MatcherPattern} documentation.
434
- *
435
- * @param pattern Pattern with missing properties.
436
- * @error matcher-pattern-deprecated-attributes-class-key
437
- */