@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
package/src/view/node.js DELETED
@@ -1,238 +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/node
7
- */
8
- import { ViewTypeCheckable } from './typecheckable.js';
9
- import { CKEditorError, EmitterMixin, compareArrays } from '@ckeditor/ckeditor5-utils';
10
- /**
11
- * Abstract view node class.
12
- *
13
- * This is an abstract class. Its constructor should not be used directly.
14
- * Use the {@link module:engine/view/downcastwriter~ViewDowncastWriter} or {@link module:engine/view/upcastwriter~ViewUpcastWriter}
15
- * to create new instances of view nodes.
16
- */
17
- export class ViewNode extends /* #__PURE__ */ EmitterMixin(ViewTypeCheckable) {
18
- /**
19
- * The document instance to which this node belongs.
20
- */
21
- document;
22
- /**
23
- * Parent element. Null by default. Set by {@link module:engine/view/element~ViewElement#_insertChild}.
24
- */
25
- parent;
26
- /**
27
- * Creates a tree view node.
28
- *
29
- * @param document The document instance to which this node belongs.
30
- */
31
- constructor(document) {
32
- super();
33
- this.document = document;
34
- this.parent = null;
35
- }
36
- /**
37
- * Index of the node in the parent element or null if the node has no parent.
38
- *
39
- * Accessing this property throws an error if this node's parent element does not contain it.
40
- * This means that view tree got broken.
41
- */
42
- get index() {
43
- let pos;
44
- if (!this.parent) {
45
- return null;
46
- }
47
- // No parent or child doesn't exist in parent's children.
48
- if ((pos = this.parent.getChildIndex(this)) == -1) {
49
- /**
50
- * The node's parent does not contain this node. It means that the document tree is corrupted.
51
- *
52
- * @error view-node-not-found-in-parent
53
- */
54
- throw new CKEditorError('view-node-not-found-in-parent', this);
55
- }
56
- return pos;
57
- }
58
- /**
59
- * Node's next sibling, or `null` if it is the last child.
60
- */
61
- get nextSibling() {
62
- const index = this.index;
63
- return (index !== null && this.parent.getChild(index + 1)) || null;
64
- }
65
- /**
66
- * Node's previous sibling, or `null` if it is the first child.
67
- */
68
- get previousSibling() {
69
- const index = this.index;
70
- return (index !== null && this.parent.getChild(index - 1)) || null;
71
- }
72
- /**
73
- * Top-most ancestor of the node. If the node has no parent it is the root itself.
74
- */
75
- get root() {
76
- // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
77
- let root = this;
78
- while (root.parent) {
79
- root = root.parent;
80
- }
81
- return root;
82
- }
83
- /**
84
- * Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
85
- */
86
- isAttached() {
87
- return this.root.is('rootElement');
88
- }
89
- /**
90
- * Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node,
91
- * beginning from {@link module:engine/view/node~ViewNode#root root}, down to this node's index.
92
- *
93
- * ```ts
94
- * const abc = downcastWriter.createText( 'abc' );
95
- * const foo = downcastWriter.createText( 'foo' );
96
- * const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
97
- * const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
98
- * const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
99
- * foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
100
- * h1.getPath(); // Returns [ 0 ].
101
- * div.getPath(); // Returns [].
102
- * ```
103
- *
104
- * @returns The path.
105
- */
106
- getPath() {
107
- const path = [];
108
- // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
109
- let node = this;
110
- while (node.parent) {
111
- path.unshift(node.index);
112
- node = node.parent;
113
- }
114
- return path;
115
- }
116
- /**
117
- * Returns ancestors array of this node.
118
- *
119
- * @param options Options object.
120
- * @param options.includeSelf When set to `true` this node will be also included in parent's array.
121
- * @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
122
- * otherwise root element will be the first item in the array.
123
- * @returns Array with ancestors.
124
- */
125
- getAncestors(options = {}) {
126
- const ancestors = [];
127
- let parent = options.includeSelf ? this : this.parent;
128
- while (parent) {
129
- ancestors[options.parentFirst ? 'push' : 'unshift'](parent);
130
- parent = parent.parent;
131
- }
132
- return ancestors;
133
- }
134
- /**
135
- * Returns a {@link module:engine/view/element~ViewElement} or {@link module:engine/view/documentfragment~ViewDocumentFragment}
136
- * which is a common ancestor of both nodes.
137
- *
138
- * @param node The second node.
139
- * @param options Options object.
140
- * @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
141
- * Which means that if e.g. node A is inside B, then their common ancestor will be B.
142
- */
143
- getCommonAncestor(node, options = {}) {
144
- const ancestorsA = this.getAncestors(options);
145
- const ancestorsB = node.getAncestors(options);
146
- let i = 0;
147
- while (ancestorsA[i] == ancestorsB[i] && ancestorsA[i]) {
148
- i++;
149
- }
150
- return i === 0 ? null : ancestorsA[i - 1];
151
- }
152
- /**
153
- * Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
154
- * in different {@link module:engine/view/documentfragment~ViewDocumentFragment}s).
155
- *
156
- * @param node Node to compare with.
157
- */
158
- isBefore(node) {
159
- // Given node is not before this node if they are same.
160
- if (this == node) {
161
- return false;
162
- }
163
- // Return `false` if it is impossible to compare nodes.
164
- if (this.root !== node.root) {
165
- return false;
166
- }
167
- const thisPath = this.getPath();
168
- const nodePath = node.getPath();
169
- const result = compareArrays(thisPath, nodePath);
170
- switch (result) {
171
- case 'prefix':
172
- return true;
173
- case 'extension':
174
- return false;
175
- default:
176
- return thisPath[result] < nodePath[result];
177
- }
178
- }
179
- /**
180
- * Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
181
- * in different {@link module:engine/view/documentfragment~ViewDocumentFragment}s).
182
- *
183
- * @param node Node to compare with.
184
- */
185
- isAfter(node) {
186
- // Given node is not before this node if they are same.
187
- if (this == node) {
188
- return false;
189
- }
190
- // Return `false` if it is impossible to compare nodes.
191
- if (this.root !== node.root) {
192
- return false;
193
- }
194
- // In other cases, just check if the `node` is before, and return the opposite.
195
- return !this.isBefore(node);
196
- }
197
- /**
198
- * Removes node from parent.
199
- *
200
- * @internal
201
- */
202
- _remove() {
203
- this.parent._removeChildren(this.index);
204
- }
205
- /**
206
- * @internal
207
- * @param type Type of the change.
208
- * @param node Changed node.
209
- * @param data Additional data.
210
- * @fires change
211
- */
212
- _fireChange(type, node, data) {
213
- this.fire(`change:${type}`, node, data);
214
- if (this.parent) {
215
- this.parent._fireChange(type, node, data);
216
- }
217
- }
218
- /**
219
- * Converts `ViewNode` to plain object and returns it.
220
- *
221
- * @returns `ViewNode` converted to plain object.
222
- */
223
- toJSON() {
224
- const json = {
225
- path: this.getPath(),
226
- type: 'Node'
227
- };
228
- if (this !== this.root && this.root.is('rootElement')) {
229
- json.root = this.root.toJSON();
230
- }
231
- return json;
232
- }
233
- }
234
- // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
235
- // Proper overload would interfere with that.
236
- ViewNode.prototype.is = function (type) {
237
- return type === 'node' || type === 'view:node';
238
- };
@@ -1,40 +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/observer/arrowkeysobserver
7
- */
8
- import { Observer } from './observer.js';
9
- import { BubblingEventInfo } from './bubblingeventinfo.js';
10
- import { isArrowKeyCode } from '@ckeditor/ckeditor5-utils';
11
- /**
12
- * Arrow keys observer introduces the {@link module:engine/view/document~ViewDocument#event:arrowKey `Document#arrowKey`} event.
13
- *
14
- * Note that this observer is attached by the {@link module:engine/view/view~EditingView} and is available by default.
15
- */
16
- export class ArrowKeysObserver extends Observer {
17
- /**
18
- * @inheritDoc
19
- */
20
- constructor(view) {
21
- super(view);
22
- this.document.on('keydown', (event, data) => {
23
- if (this.isEnabled && isArrowKeyCode(data.keyCode)) {
24
- const eventInfo = new BubblingEventInfo(this.document, 'arrowKey', this.document.selection.getFirstRange());
25
- this.document.fire(eventInfo, data);
26
- if (eventInfo.stop.called) {
27
- event.stop();
28
- }
29
- }
30
- });
31
- }
32
- /**
33
- * @inheritDoc
34
- */
35
- observe() { }
36
- /**
37
- * @inheritDoc
38
- */
39
- stopObserving() { }
40
- }
@@ -1,215 +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/observer/bubblingemittermixin
7
- */
8
- import { CKEditorError, EmitterMixin, EventInfo, toArray } from '@ckeditor/ckeditor5-utils';
9
- import { BubblingEventInfo } from './bubblingeventinfo.js';
10
- const bubblingEmitterSymbol = Symbol('bubblingEmitter');
11
- const callbackMapSymbol = Symbol('bubblingCallbacks');
12
- const contextsSymbol = Symbol('bubblingContexts');
13
- /**
14
- * Bubbling emitter mixin for the view document as described in the {@link ~BubblingEmitter} interface.
15
- *
16
- * This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
17
- * The base class must implement {@link module:utils/emittermixin~Emitter} interface.
18
- *
19
- * ```ts
20
- * class BaseClass extends EmitterMixin() {
21
- * // ...
22
- * }
23
- *
24
- * class MyClass extends BubblingEmitterMixin( BaseClass ) {
25
- * // This class derives from `BaseClass` and implements the `BubblingEmitter` interface.
26
- * }
27
- * ```
28
- */
29
- export function BubblingEmitterMixin(base) {
30
- class Mixin extends base {
31
- fire(eventOrInfo, ...eventArgs) {
32
- try {
33
- const eventInfo = eventOrInfo instanceof EventInfo ? eventOrInfo : new EventInfo(this, eventOrInfo);
34
- const bubblingEmitter = getBubblingEmitter(this);
35
- const customContexts = getCustomContexts(this);
36
- updateEventInfo(eventInfo, 'capturing', this);
37
- // The capture phase of the event.
38
- if (fireListenerFor(bubblingEmitter, '$capture', eventInfo, ...eventArgs)) {
39
- return eventInfo.return;
40
- }
41
- const startRange = eventInfo.startRange || this.selection.getFirstRange();
42
- const selectedElement = startRange ? startRange.getContainedElement() : null;
43
- const isCustomContext = selectedElement ? hasMatchingCustomContext(customContexts, selectedElement) : false;
44
- let node = selectedElement || getDeeperRangeParent(startRange);
45
- updateEventInfo(eventInfo, 'atTarget', node);
46
- // For the not yet bubbling event trigger for $text node if selection can be there and it's not a custom context selected.
47
- if (!isCustomContext) {
48
- if (fireListenerFor(bubblingEmitter, '$text', eventInfo, ...eventArgs)) {
49
- return eventInfo.return;
50
- }
51
- updateEventInfo(eventInfo, 'bubbling', node);
52
- }
53
- while (node) {
54
- if (node.is('element') && fireListenerFor(bubblingEmitter, node, eventInfo, ...eventArgs)) {
55
- return eventInfo.return;
56
- }
57
- node = node.parent;
58
- updateEventInfo(eventInfo, 'bubbling', node);
59
- }
60
- updateEventInfo(eventInfo, 'bubbling', this);
61
- // Document context.
62
- fireListenerFor(bubblingEmitter, '$document', eventInfo, ...eventArgs);
63
- return eventInfo.return;
64
- }
65
- catch (err) {
66
- // @if CK_DEBUG // throw err;
67
- /* istanbul ignore next -- @preserve */
68
- CKEditorError.rethrowUnexpectedError(err, this);
69
- }
70
- }
71
- _addEventListener(event, callback, options) {
72
- const contexts = toArray(options.context || '$document');
73
- const bubblingEmitter = getBubblingEmitter(this);
74
- const callbacksMap = getCallbackMap(this);
75
- for (const context of contexts) {
76
- if (typeof context == 'function') {
77
- getCustomContexts(this).add(context);
78
- }
79
- }
80
- // Wrap callback with current target match.
81
- const wrappedCallback = wrapCallback(this, contexts, callback);
82
- // Store for later removing of listeners.
83
- callbacksMap.set(callback, wrappedCallback);
84
- // Listen for the event.
85
- this.listenTo(bubblingEmitter, event, wrappedCallback, options);
86
- }
87
- _removeEventListener(event, callback) {
88
- const bubblingEmitter = getBubblingEmitter(this);
89
- const callbacksMap = getCallbackMap(this);
90
- const wrappedCallback = callbacksMap.get(callback);
91
- if (wrappedCallback) {
92
- callbacksMap.delete(callback);
93
- this.stopListening(bubblingEmitter, event, wrappedCallback);
94
- }
95
- }
96
- }
97
- return Mixin;
98
- }
99
- /**
100
- * Update the event info bubbling fields.
101
- *
102
- * @param eventInfo The event info object to update.
103
- * @param eventPhase The current event phase.
104
- * @param currentTarget The current bubbling target.
105
- */
106
- function updateEventInfo(eventInfo, eventPhase, currentTarget) {
107
- if (eventInfo instanceof BubblingEventInfo) {
108
- eventInfo._eventPhase = eventPhase;
109
- eventInfo._currentTarget = currentTarget;
110
- }
111
- }
112
- /**
113
- * Fires the listener for the specified context. Returns `true` if event was stopped.
114
- *
115
- * @param eventInfo The `EventInfo` object.
116
- * @param eventArgs Additional arguments to be passed to the callbacks.
117
- * @returns True if event stop was called.
118
- */
119
- function fireListenerFor(emitter, currentTarget, eventInfo, ...eventArgs) {
120
- emitter.fire(eventInfo, {
121
- currentTarget,
122
- eventArgs
123
- });
124
- // Similar to DOM Event#stopImmediatePropagation() this does not fire events
125
- // for other contexts on the same node.
126
- if (eventInfo.stop.called) {
127
- return true;
128
- }
129
- return false;
130
- }
131
- /**
132
- * Returns an event callback wrapped with context check condition.
133
- */
134
- function wrapCallback(emitter, contexts, callback) {
135
- return function (event, data) {
136
- const { currentTarget, eventArgs } = data;
137
- // Quick path for string based context ($capture, $text, $document).
138
- if (typeof currentTarget == 'string') {
139
- if (contexts.includes(currentTarget)) {
140
- callback.call(emitter, event, ...eventArgs);
141
- }
142
- return;
143
- }
144
- // The current target is a view element.
145
- // Special case for the root element as it could be handled ac $root context.
146
- // Note that it could also be matched later by custom context.
147
- if (currentTarget.is('rootElement') && contexts.includes('$root')) {
148
- callback.call(emitter, event, ...eventArgs);
149
- return;
150
- }
151
- // Check if it is a context for this element name.
152
- if (contexts.includes(currentTarget.name)) {
153
- callback.call(emitter, event, ...eventArgs);
154
- return;
155
- }
156
- // Check if dynamic context matches.
157
- for (const context of contexts) {
158
- if (typeof context == 'function' && context(currentTarget)) {
159
- callback.call(emitter, event, ...eventArgs);
160
- return;
161
- }
162
- }
163
- };
164
- }
165
- /**
166
- * Returns bubbling emitter for the source (emitter).
167
- */
168
- function getBubblingEmitter(source) {
169
- if (!source[bubblingEmitterSymbol]) {
170
- source[bubblingEmitterSymbol] = new (EmitterMixin())();
171
- }
172
- return source[bubblingEmitterSymbol];
173
- }
174
- /**
175
- * Returns map of callbacks (original to wrapped one).
176
- */
177
- function getCallbackMap(source) {
178
- if (!source[callbackMapSymbol]) {
179
- source[callbackMapSymbol] = new Map();
180
- }
181
- return source[callbackMapSymbol];
182
- }
183
- /**
184
- * Returns the set of registered custom contexts.
185
- */
186
- function getCustomContexts(source) {
187
- if (!source[contextsSymbol]) {
188
- source[contextsSymbol] = new Set();
189
- }
190
- return source[contextsSymbol];
191
- }
192
- /**
193
- * Returns true if any of custom context match the given element.
194
- */
195
- function hasMatchingCustomContext(customContexts, element) {
196
- for (const context of customContexts) {
197
- if (context(element)) {
198
- return true;
199
- }
200
- }
201
- return false;
202
- }
203
- /**
204
- * Returns the deeper parent element for the range.
205
- */
206
- function getDeeperRangeParent(range) {
207
- if (!range) {
208
- return null;
209
- }
210
- const startParent = range.start.parent;
211
- const endParent = range.end.parent;
212
- const startPath = startParent.getPath();
213
- const endPath = endParent.getPath();
214
- return startPath.length > endPath.length ? startParent : endParent;
215
- }
@@ -1,49 +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/observer/bubblingeventinfo
7
- */
8
- import { EventInfo } from '@ckeditor/ckeditor5-utils';
9
- /**
10
- * The event object passed to bubbling event callbacks. It is used to provide information about the event as well as a tool to
11
- * manipulate it.
12
- */
13
- export class BubblingEventInfo extends EventInfo {
14
- /**
15
- * The view range that the bubbling should start from.
16
- */
17
- startRange;
18
- /**
19
- * The current event phase.
20
- */
21
- _eventPhase;
22
- /**
23
- * The current bubbling target.
24
- */
25
- _currentTarget;
26
- /**
27
- * @param source The emitter.
28
- * @param name The event name.
29
- * @param startRange The view range that the bubbling should start from.
30
- */
31
- constructor(source, name, startRange) {
32
- super(source, name);
33
- this.startRange = startRange;
34
- this._eventPhase = 'none';
35
- this._currentTarget = null;
36
- }
37
- /**
38
- * The current event phase.
39
- */
40
- get eventPhase() {
41
- return this._eventPhase;
42
- }
43
- /**
44
- * The current bubbling target.
45
- */
46
- get currentTarget() {
47
- return this._currentTarget;
48
- }
49
- }
@@ -1,26 +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/observer/clickobserver
7
- */
8
- import { DomEventObserver } from './domeventobserver.js';
9
- /**
10
- * {@link module:engine/view/document~ViewDocument#event:click Click} event observer.
11
- *
12
- * Note that this observer is not available by default. To make it available it needs to be added to
13
- * {@link module:engine/view/view~EditingView view controller} by a {@link module:engine/view/view~EditingView#addObserver} method.
14
- */
15
- export class ClickObserver extends DomEventObserver {
16
- /**
17
- * @inheritDoc
18
- */
19
- domEventType = 'click';
20
- /**
21
- * @inheritDoc
22
- */
23
- onDomEvent(domEvent) {
24
- this.fire(domEvent.type, domEvent);
25
- }
26
- }
@@ -1,64 +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/observer/compositionobserver
7
- */
8
- import { DomEventObserver } from './domeventobserver.js';
9
- // @if CK_DEBUG_TYPING // const { _debouncedLine, _buildLogMessage } = require( '../../dev-utils/utils.js' );
10
- /**
11
- * {@link module:engine/view/document~ViewDocument#event:compositionstart Compositionstart},
12
- * {@link module:engine/view/document~ViewDocument#event:compositionupdate compositionupdate} and
13
- * {@link module:engine/view/document~ViewDocument#event:compositionend compositionend} events observer.
14
- *
15
- * Note that this observer is attached by the {@link module:engine/view/view~EditingView} and is available by default.
16
- */
17
- export class CompositionObserver extends DomEventObserver {
18
- /**
19
- * @inheritDoc
20
- */
21
- domEventType = ['compositionstart', 'compositionupdate', 'compositionend'];
22
- /**
23
- * @inheritDoc
24
- */
25
- constructor(view) {
26
- super(view);
27
- const document = this.document;
28
- document.on('compositionstart', () => {
29
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
30
- // @if CK_DEBUG_TYPING // console.log( ..._buildLogMessage( this, 'CompositionObserver',
31
- // @if CK_DEBUG_TYPING // '%c┌───────────────────────────── isComposing = true ─────────────────────────────┐',
32
- // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
33
- // @if CK_DEBUG_TYPING // ) );
34
- // @if CK_DEBUG_TYPING // }
35
- document.isComposing = true;
36
- });
37
- document.on('compositionend', () => {
38
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
39
- // @if CK_DEBUG_TYPING // console.log( ..._buildLogMessage( this, 'CompositionObserver',
40
- // @if CK_DEBUG_TYPING // '%c└───────────────────────────── isComposing = false ─────────────────────────────┘',
41
- // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
42
- // @if CK_DEBUG_TYPING // ) );
43
- // @if CK_DEBUG_TYPING // }
44
- document.isComposing = false;
45
- });
46
- }
47
- /**
48
- * @inheritDoc
49
- */
50
- onDomEvent(domEvent) {
51
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
52
- // @if CK_DEBUG_TYPING // _debouncedLine();
53
- // @if CK_DEBUG_TYPING // console.group( ..._buildLogMessage( this, 'CompositionObserver',
54
- // @if CK_DEBUG_TYPING // `${ domEvent.type }`
55
- // @if CK_DEBUG_TYPING // ) );
56
- // @if CK_DEBUG_TYPING // }
57
- this.fire(domEvent.type, domEvent, {
58
- data: domEvent.data
59
- });
60
- // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
61
- // @if CK_DEBUG_TYPING // console.groupEnd();
62
- // @if CK_DEBUG_TYPING // }
63
- }
64
- }