@ckeditor/ckeditor5-engine 36.0.1 → 37.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 (200) hide show
  1. package/README.md +1 -1
  2. package/package.json +24 -23
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +62 -109
  5. package/src/controller/editingcontroller.d.ts +98 -0
  6. package/src/controller/editingcontroller.js +22 -46
  7. package/src/conversion/conversion.d.ts +476 -0
  8. package/src/conversion/conversion.js +328 -347
  9. package/src/conversion/conversionhelpers.d.ts +26 -0
  10. package/src/conversion/conversionhelpers.js +1 -5
  11. package/src/conversion/downcastdispatcher.d.ts +547 -0
  12. package/src/conversion/downcastdispatcher.js +74 -152
  13. package/src/conversion/downcasthelpers.d.ts +1226 -0
  14. package/src/conversion/downcasthelpers.js +843 -762
  15. package/src/conversion/mapper.d.ts +499 -0
  16. package/src/conversion/mapper.js +84 -99
  17. package/src/conversion/modelconsumable.d.ts +201 -0
  18. package/src/conversion/modelconsumable.js +96 -99
  19. package/src/conversion/upcastdispatcher.d.ts +492 -0
  20. package/src/conversion/upcastdispatcher.js +73 -100
  21. package/src/conversion/upcasthelpers.d.ts +499 -0
  22. package/src/conversion/upcasthelpers.js +406 -373
  23. package/src/conversion/viewconsumable.d.ts +177 -0
  24. package/src/conversion/viewconsumable.js +157 -162
  25. package/src/dataprocessor/basichtmlwriter.d.ts +18 -0
  26. package/src/dataprocessor/basichtmlwriter.js +0 -9
  27. package/src/dataprocessor/dataprocessor.d.ts +61 -0
  28. package/src/dataprocessor/htmldataprocessor.d.ts +76 -0
  29. package/src/dataprocessor/htmldataprocessor.js +6 -28
  30. package/src/dataprocessor/htmlwriter.d.ts +16 -0
  31. package/src/dataprocessor/xmldataprocessor.d.ts +90 -0
  32. package/src/dataprocessor/xmldataprocessor.js +8 -40
  33. package/src/dev-utils/model.d.ts +124 -0
  34. package/src/dev-utils/model.js +41 -38
  35. package/src/dev-utils/operationreplayer.d.ts +51 -0
  36. package/src/dev-utils/operationreplayer.js +6 -14
  37. package/src/dev-utils/utils.d.ts +37 -0
  38. package/src/dev-utils/utils.js +5 -18
  39. package/src/dev-utils/view.d.ts +319 -0
  40. package/src/dev-utils/view.js +205 -226
  41. package/src/index.d.ts +105 -0
  42. package/src/index.js +1 -0
  43. package/src/model/batch.d.ts +106 -0
  44. package/src/model/differ.d.ts +329 -0
  45. package/src/model/document.d.ts +245 -0
  46. package/src/model/document.js +1 -1
  47. package/src/model/documentfragment.d.ts +196 -0
  48. package/src/model/documentfragment.js +2 -2
  49. package/src/model/documentselection.d.ts +420 -0
  50. package/src/model/element.d.ts +165 -0
  51. package/src/model/history.d.ts +114 -0
  52. package/src/model/item.d.ts +14 -0
  53. package/src/model/liveposition.d.ts +77 -0
  54. package/src/model/liverange.d.ts +102 -0
  55. package/src/model/markercollection.d.ts +335 -0
  56. package/src/model/model.d.ts +812 -0
  57. package/src/model/model.js +59 -30
  58. package/src/model/node.d.ts +256 -0
  59. package/src/model/nodelist.d.ts +91 -0
  60. package/src/model/operation/attributeoperation.d.ts +98 -0
  61. package/src/model/operation/detachoperation.d.ts +55 -0
  62. package/src/model/operation/insertoperation.d.ts +85 -0
  63. package/src/model/operation/markeroperation.d.ts +86 -0
  64. package/src/model/operation/mergeoperation.d.ts +95 -0
  65. package/src/model/operation/moveoperation.d.ts +91 -0
  66. package/src/model/operation/nooperation.d.ts +33 -0
  67. package/src/model/operation/operation.d.ts +89 -0
  68. package/src/model/operation/operationfactory.d.ts +18 -0
  69. package/src/model/operation/renameoperation.d.ts +78 -0
  70. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  71. package/src/model/operation/rootattributeoperation.js +1 -1
  72. package/src/model/operation/splitoperation.d.ts +104 -0
  73. package/src/model/operation/transform.d.ts +100 -0
  74. package/src/model/operation/utils.d.ts +71 -0
  75. package/src/model/position.d.ts +539 -0
  76. package/src/model/position.js +1 -1
  77. package/src/model/range.d.ts +458 -0
  78. package/src/model/range.js +1 -1
  79. package/src/model/rootelement.d.ts +40 -0
  80. package/src/model/schema.d.ts +1176 -0
  81. package/src/model/schema.js +15 -15
  82. package/src/model/selection.d.ts +472 -0
  83. package/src/model/text.d.ts +66 -0
  84. package/src/model/text.js +0 -2
  85. package/src/model/textproxy.d.ts +144 -0
  86. package/src/model/treewalker.d.ts +186 -0
  87. package/src/model/treewalker.js +19 -10
  88. package/src/model/typecheckable.d.ts +255 -0
  89. package/src/model/utils/autoparagraphing.d.ts +37 -0
  90. package/src/model/utils/deletecontent.d.ts +58 -0
  91. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  92. package/src/model/utils/getselectedcontent.d.ts +30 -0
  93. package/src/model/utils/insertcontent.d.ts +46 -0
  94. package/src/model/utils/insertcontent.js +2 -12
  95. package/src/model/utils/insertobject.d.ts +44 -0
  96. package/src/model/utils/insertobject.js +3 -14
  97. package/src/model/utils/modifyselection.d.ts +48 -0
  98. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  99. package/src/model/writer.d.ts +726 -0
  100. package/src/model/writer.js +6 -4
  101. package/src/view/attributeelement.d.ts +108 -0
  102. package/src/view/attributeelement.js +25 -69
  103. package/src/view/containerelement.d.ts +49 -0
  104. package/src/view/containerelement.js +10 -43
  105. package/src/view/datatransfer.d.ts +75 -0
  106. package/src/view/document.d.ts +184 -0
  107. package/src/view/document.js +15 -84
  108. package/src/view/documentfragment.d.ts +150 -0
  109. package/src/view/documentfragment.js +40 -81
  110. package/src/view/documentselection.d.ts +219 -0
  111. package/src/view/documentselection.js +75 -121
  112. package/src/view/domconverter.d.ts +620 -0
  113. package/src/view/domconverter.js +159 -276
  114. package/src/view/downcastwriter.d.ts +804 -0
  115. package/src/view/downcastwriter.js +336 -380
  116. package/src/view/editableelement.d.ts +52 -0
  117. package/src/view/editableelement.js +9 -49
  118. package/src/view/element.d.ts +466 -0
  119. package/src/view/element.js +150 -222
  120. package/src/view/elementdefinition.d.ts +87 -0
  121. package/src/view/emptyelement.d.ts +41 -0
  122. package/src/view/emptyelement.js +11 -44
  123. package/src/view/filler.d.ts +111 -0
  124. package/src/view/filler.js +24 -21
  125. package/src/view/item.d.ts +14 -0
  126. package/src/view/matcher.d.ts +486 -0
  127. package/src/view/matcher.js +247 -218
  128. package/src/view/node.d.ts +160 -0
  129. package/src/view/node.js +26 -100
  130. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  131. package/src/view/observer/arrowkeysobserver.js +0 -13
  132. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  133. package/src/view/observer/bubblingemittermixin.js +36 -25
  134. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  135. package/src/view/observer/bubblingeventinfo.js +3 -29
  136. package/src/view/observer/clickobserver.d.ts +43 -0
  137. package/src/view/observer/clickobserver.js +9 -19
  138. package/src/view/observer/compositionobserver.d.ts +82 -0
  139. package/src/view/observer/compositionobserver.js +13 -42
  140. package/src/view/observer/domeventdata.d.ts +50 -0
  141. package/src/view/observer/domeventdata.js +5 -30
  142. package/src/view/observer/domeventobserver.d.ts +69 -0
  143. package/src/view/observer/domeventobserver.js +19 -21
  144. package/src/view/observer/fakeselectionobserver.d.ts +46 -0
  145. package/src/view/observer/fakeselectionobserver.js +2 -15
  146. package/src/view/observer/focusobserver.d.ts +82 -0
  147. package/src/view/observer/focusobserver.js +14 -40
  148. package/src/view/observer/inputobserver.d.ts +86 -0
  149. package/src/view/observer/inputobserver.js +18 -64
  150. package/src/view/observer/keyobserver.d.ts +67 -0
  151. package/src/view/observer/keyobserver.js +8 -42
  152. package/src/view/observer/mouseobserver.d.ts +89 -0
  153. package/src/view/observer/mouseobserver.js +8 -28
  154. package/src/view/observer/mutationobserver.d.ts +82 -0
  155. package/src/view/observer/mutationobserver.js +7 -37
  156. package/src/view/observer/observer.d.ts +84 -0
  157. package/src/view/observer/observer.js +12 -25
  158. package/src/view/observer/selectionobserver.d.ts +143 -0
  159. package/src/view/observer/selectionobserver.js +9 -99
  160. package/src/view/observer/tabobserver.d.ts +42 -0
  161. package/src/view/observer/tabobserver.js +0 -14
  162. package/src/view/placeholder.d.ts +85 -0
  163. package/src/view/placeholder.js +26 -43
  164. package/src/view/position.d.ts +189 -0
  165. package/src/view/position.js +36 -83
  166. package/src/view/range.d.ts +279 -0
  167. package/src/view/range.js +79 -122
  168. package/src/view/rawelement.d.ts +73 -0
  169. package/src/view/rawelement.js +34 -48
  170. package/src/view/renderer.d.ts +265 -0
  171. package/src/view/renderer.js +105 -193
  172. package/src/view/rooteditableelement.d.ts +41 -0
  173. package/src/view/rooteditableelement.js +12 -40
  174. package/src/view/selection.d.ts +375 -0
  175. package/src/view/selection.js +79 -153
  176. package/src/view/styles/background.d.ts +33 -0
  177. package/src/view/styles/background.js +14 -12
  178. package/src/view/styles/border.d.ts +43 -0
  179. package/src/view/styles/border.js +58 -48
  180. package/src/view/styles/margin.d.ts +29 -0
  181. package/src/view/styles/margin.js +13 -11
  182. package/src/view/styles/padding.d.ts +29 -0
  183. package/src/view/styles/padding.js +13 -11
  184. package/src/view/styles/utils.d.ts +93 -0
  185. package/src/view/styles/utils.js +22 -48
  186. package/src/view/stylesmap.d.ts +675 -0
  187. package/src/view/stylesmap.js +249 -244
  188. package/src/view/text.d.ts +74 -0
  189. package/src/view/text.js +16 -46
  190. package/src/view/textproxy.d.ts +97 -0
  191. package/src/view/textproxy.js +10 -59
  192. package/src/view/treewalker.d.ts +195 -0
  193. package/src/view/treewalker.js +43 -106
  194. package/src/view/typecheckable.d.ts +401 -0
  195. package/src/view/uielement.d.ts +96 -0
  196. package/src/view/uielement.js +28 -62
  197. package/src/view/upcastwriter.d.ts +328 -0
  198. package/src/view/upcastwriter.js +124 -134
  199. package/src/view/view.d.ts +327 -0
  200. package/src/view/view.js +79 -150
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module engine/view/node
7
+ */
8
+ import TypeCheckable from './typecheckable';
9
+ import '@ckeditor/ckeditor5-utils/src/version';
10
+ import type { default as Document, ChangeType } from './document';
11
+ import type DocumentFragment from './documentfragment';
12
+ import type Element from './element';
13
+ declare const Node_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof TypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
14
+ /**
15
+ * Abstract view node class.
16
+ *
17
+ * This is an abstract class. Its constructor should not be used directly.
18
+ * Use the {@link module:engine/view/downcastwriter~DowncastWriter} or {@link module:engine/view/upcastwriter~UpcastWriter}
19
+ * to create new instances of view nodes.
20
+ */
21
+ export default abstract class Node extends Node_base {
22
+ /**
23
+ * The document instance to which this node belongs.
24
+ */
25
+ readonly document: Document;
26
+ /**
27
+ * Parent element. Null by default. Set by {@link module:engine/view/element~Element#_insertChild}.
28
+ */
29
+ readonly parent: Element | DocumentFragment | null;
30
+ /**
31
+ * Creates a tree view node.
32
+ *
33
+ * @param document The document instance to which this node belongs.
34
+ */
35
+ protected constructor(document: Document);
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(): number | null;
43
+ /**
44
+ * Node's next sibling, or `null` if it is the last child.
45
+ */
46
+ get nextSibling(): Node | null;
47
+ /**
48
+ * Node's previous sibling, or `null` if it is the first child.
49
+ */
50
+ get previousSibling(): Node | null;
51
+ /**
52
+ * Top-most ancestor of the node. If the node has no parent it is the root itself.
53
+ */
54
+ get root(): Element | DocumentFragment;
55
+ /**
56
+ * Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
57
+ */
58
+ isAttached(): boolean;
59
+ /**
60
+ * Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node,
61
+ * beginning from {@link module:engine/view/node~Node#root root}, down to this node's index.
62
+ *
63
+ * ```ts
64
+ * const abc = downcastWriter.createText( 'abc' );
65
+ * const foo = downcastWriter.createText( 'foo' );
66
+ * const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
67
+ * const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
68
+ * const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
69
+ * foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
70
+ * h1.getPath(); // Returns [ 0 ].
71
+ * div.getPath(); // Returns [].
72
+ * ```
73
+ *
74
+ * @returns The path.
75
+ */
76
+ getPath(): Array<number>;
77
+ /**
78
+ * Returns ancestors array of this node.
79
+ *
80
+ * @param options Options object.
81
+ * @param options.includeSelf When set to `true` this node will be also included in parent's array.
82
+ * @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
83
+ * otherwise root element will be the first item in the array.
84
+ * @returns Array with ancestors.
85
+ */
86
+ getAncestors(options?: {
87
+ includeSelf?: boolean;
88
+ parentFirst?: boolean;
89
+ }): Array<Node | DocumentFragment>;
90
+ /**
91
+ * Returns a {@link module:engine/view/element~Element} or {@link module:engine/view/documentfragment~DocumentFragment}
92
+ * which is a common ancestor of both nodes.
93
+ *
94
+ * @param node The second node.
95
+ * @param options Options object.
96
+ * @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
97
+ * Which means that if e.g. node A is inside B, then their common ancestor will be B.
98
+ */
99
+ getCommonAncestor(node: Node, options?: {
100
+ includeSelf?: boolean;
101
+ }): Element | DocumentFragment | null;
102
+ /**
103
+ * Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
104
+ * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
105
+ *
106
+ * @param node Node to compare with.
107
+ */
108
+ isBefore(node: Node): boolean;
109
+ /**
110
+ * Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
111
+ * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
112
+ *
113
+ * @param node Node to compare with.
114
+ */
115
+ isAfter(node: Node): boolean;
116
+ /**
117
+ * Removes node from parent.
118
+ *
119
+ * @internal
120
+ */
121
+ _remove(): void;
122
+ /**
123
+ * @internal
124
+ * @param type Type of the change.
125
+ * @param node Changed node.
126
+ * @fires change
127
+ */
128
+ _fireChange(type: ChangeType, node: Node): void;
129
+ /**
130
+ * Custom toJSON method to solve child-parent circular dependencies.
131
+ *
132
+ * @returns Clone of this object with the parent property removed.
133
+ */
134
+ toJSON(): unknown;
135
+ /**
136
+ * Clones this node.
137
+ *
138
+ * @internal
139
+ * @returns Clone of this node.
140
+ */
141
+ abstract _clone(deep?: boolean): Node;
142
+ /**
143
+ * Checks if provided node is similar to this node.
144
+ *
145
+ * @returns True if nodes are similar.
146
+ */
147
+ abstract isSimilar(other: Node): boolean;
148
+ }
149
+ /**
150
+ * Fired when list of {@link module:engine/view/element~Element elements} children, attributes or data changes.
151
+ *
152
+ * Change event is bubbled – it is fired on all ancestors.
153
+ *
154
+ * @eventName change
155
+ */
156
+ export type ViewNodeChangeEvent = {
157
+ name: 'change' | `change:${ChangeType}`;
158
+ args: [changedNode: Node];
159
+ };
160
+ export {};
package/src/view/node.js CHANGED
@@ -16,31 +16,16 @@ import '@ckeditor/ckeditor5-utils/src/version';
16
16
  * This is an abstract class. Its constructor should not be used directly.
17
17
  * Use the {@link module:engine/view/downcastwriter~DowncastWriter} or {@link module:engine/view/upcastwriter~UpcastWriter}
18
18
  * to create new instances of view nodes.
19
- *
20
- * @abstract
21
19
  */
22
20
  export default class Node extends EmitterMixin(TypeCheckable) {
23
21
  /**
24
22
  * Creates a tree view node.
25
23
  *
26
- * @protected
27
- * @param {module:engine/view/document~Document} document The document instance to which this node belongs.
24
+ * @param document The document instance to which this node belongs.
28
25
  */
29
26
  constructor(document) {
30
27
  super();
31
- /**
32
- * The document instance to which this node belongs.
33
- *
34
- * @readonly
35
- * @member {module:engine/view/document~Document}
36
- */
37
28
  this.document = document;
38
- /**
39
- * Parent element. Null by default. Set by {@link module:engine/view/element~Element#_insertChild}.
40
- *
41
- * @readonly
42
- * @member {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
43
- */
44
29
  this.parent = null;
45
30
  }
46
31
  /**
@@ -48,9 +33,6 @@ export default class Node extends EmitterMixin(TypeCheckable) {
48
33
  *
49
34
  * Accessing this property throws an error if this node's parent element does not contain it.
50
35
  * This means that view tree got broken.
51
- *
52
- * @readonly
53
- * @type {Number|null}
54
36
  */
55
37
  get index() {
56
38
  let pos;
@@ -70,9 +52,6 @@ export default class Node extends EmitterMixin(TypeCheckable) {
70
52
  }
71
53
  /**
72
54
  * Node's next sibling, or `null` if it is the last child.
73
- *
74
- * @readonly
75
- * @type {module:engine/view/node~Node|null}
76
55
  */
77
56
  get nextSibling() {
78
57
  const index = this.index;
@@ -80,9 +59,6 @@ export default class Node extends EmitterMixin(TypeCheckable) {
80
59
  }
81
60
  /**
82
61
  * Node's previous sibling, or `null` if it is the first child.
83
- *
84
- * @readonly
85
- * @type {module:engine/view/node~Node|null}
86
62
  */
87
63
  get previousSibling() {
88
64
  const index = this.index;
@@ -90,9 +66,6 @@ export default class Node extends EmitterMixin(TypeCheckable) {
90
66
  }
91
67
  /**
92
68
  * Top-most ancestor of the node. If the node has no parent it is the root itself.
93
- *
94
- * @readonly
95
- * @type {module:engine/view/node~Node|module:engine/view/documentfragment~DocumentFragment}
96
69
  */
97
70
  get root() {
98
71
  // eslint-disable-next-line @typescript-eslint/no-this-alias, consistent-this
@@ -104,8 +77,6 @@ export default class Node extends EmitterMixin(TypeCheckable) {
104
77
  }
105
78
  /**
106
79
  * Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
107
- *
108
- * @returns {Boolean}
109
80
  */
110
81
  isAttached() {
111
82
  return this.root.is('rootElement');
@@ -114,16 +85,18 @@ export default class Node extends EmitterMixin(TypeCheckable) {
114
85
  * Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node,
115
86
  * beginning from {@link module:engine/view/node~Node#root root}, down to this node's index.
116
87
  *
117
- * const abc = downcastWriter.createText( 'abc' );
118
- * const foo = downcastWriter.createText( 'foo' );
119
- * const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
120
- * const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
121
- * const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
122
- * foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
123
- * h1.getPath(); // Returns [ 0 ].
124
- * div.getPath(); // Returns [].
88
+ * ```ts
89
+ * const abc = downcastWriter.createText( 'abc' );
90
+ * const foo = downcastWriter.createText( 'foo' );
91
+ * const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
92
+ * const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
93
+ * const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
94
+ * foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
95
+ * h1.getPath(); // Returns [ 0 ].
96
+ * div.getPath(); // Returns [].
97
+ * ```
125
98
  *
126
- * @returns {Array.<Number>} The path.
99
+ * @returns The path.
127
100
  */
128
101
  getPath() {
129
102
  const path = [];
@@ -138,11 +111,11 @@ export default class Node extends EmitterMixin(TypeCheckable) {
138
111
  /**
139
112
  * Returns ancestors array of this node.
140
113
  *
141
- * @param {Object} options Options object.
142
- * @param {Boolean} [options.includeSelf=false] When set to `true` this node will be also included in parent's array.
143
- * @param {Boolean} [options.parentFirst=false] When set to `true`, array will be sorted from node's parent to root element,
114
+ * @param options Options object.
115
+ * @param options.includeSelf When set to `true` this node will be also included in parent's array.
116
+ * @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
144
117
  * otherwise root element will be the first item in the array.
145
- * @returns {Array} Array with ancestors.
118
+ * @returns Array with ancestors.
146
119
  */
147
120
  getAncestors(options = {}) {
148
121
  const ancestors = [];
@@ -157,11 +130,10 @@ export default class Node extends EmitterMixin(TypeCheckable) {
157
130
  * Returns a {@link module:engine/view/element~Element} or {@link module:engine/view/documentfragment~DocumentFragment}
158
131
  * which is a common ancestor of both nodes.
159
132
  *
160
- * @param {module:engine/view/node~Node} node The second node.
161
- * @param {Object} options Options object.
162
- * @param {Boolean} [options.includeSelf=false] When set to `true` both nodes will be considered "ancestors" too.
133
+ * @param node The second node.
134
+ * @param options Options object.
135
+ * @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
163
136
  * Which means that if e.g. node A is inside B, then their common ancestor will be B.
164
- * @returns {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment|null}
165
137
  */
166
138
  getCommonAncestor(node, options = {}) {
167
139
  const ancestorsA = this.getAncestors(options);
@@ -176,8 +148,7 @@ export default class Node extends EmitterMixin(TypeCheckable) {
176
148
  * Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
177
149
  * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
178
150
  *
179
- * @param {module:engine/view/node~Node} node Node to compare with.
180
- * @returns {Boolean}
151
+ * @param node Node to compare with.
181
152
  */
182
153
  isBefore(node) {
183
154
  // Given node is not before this node if they are same.
@@ -204,8 +175,7 @@ export default class Node extends EmitterMixin(TypeCheckable) {
204
175
  * Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
205
176
  * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
206
177
  *
207
- * @param {module:engine/view/node~Node} node Node to compare with.
208
- * @returns {Boolean}
178
+ * @param node Node to compare with.
209
179
  */
210
180
  isAfter(node) {
211
181
  // Given node is not before this node if they are same.
@@ -223,16 +193,14 @@ export default class Node extends EmitterMixin(TypeCheckable) {
223
193
  * Removes node from parent.
224
194
  *
225
195
  * @internal
226
- * @protected
227
196
  */
228
197
  _remove() {
229
198
  this.parent._removeChildren(this.index);
230
199
  }
231
200
  /**
232
201
  * @internal
233
- * @protected
234
- * @param {module:engine/view/document~ChangeType} type Type of the change.
235
- * @param {module:engine/view/node~Node} node Changed node.
202
+ * @param type Type of the change.
203
+ * @param node Changed node.
236
204
  * @fires change
237
205
  */
238
206
  _fireChange(type, node) {
@@ -244,7 +212,7 @@ export default class Node extends EmitterMixin(TypeCheckable) {
244
212
  /**
245
213
  * Custom toJSON method to solve child-parent circular dependencies.
246
214
  *
247
- * @returns {Object} Clone of this object with the parent property removed.
215
+ * @returns Clone of this object with the parent property removed.
248
216
  */
249
217
  toJSON() {
250
218
  const json = clone(this);
@@ -253,50 +221,8 @@ export default class Node extends EmitterMixin(TypeCheckable) {
253
221
  return json;
254
222
  }
255
223
  }
256
- /**
257
- * Checks whether this object is of the given type.
258
- *
259
- * This method is useful when processing view objects that are of unknown type. For example, a function
260
- * may return a {@link module:engine/view/documentfragment~DocumentFragment} or a {@link module:engine/view/node~Node}
261
- * that can be either a text node or an element. This method can be used to check what kind of object is returned.
262
- *
263
- * someObject.is( 'element' ); // -> true if this is an element
264
- * someObject.is( 'node' ); // -> true if this is a node (a text node or an element)
265
- * someObject.is( 'documentFragment' ); // -> true if this is a document fragment
266
- *
267
- * Since this method is also available on a range of model objects, you can prefix the type of the object with
268
- * `model:` or `view:` to check, for example, if this is the model's or view's element:
269
- *
270
- * viewElement.is( 'view:element' ); // -> true
271
- * viewElement.is( 'model:element' ); // -> false
272
- *
273
- * By using this method it is also possible to check a name of an element:
274
- *
275
- * imgElement.is( 'element', 'img' ); // -> true
276
- * imgElement.is( 'view:element', 'img' ); // -> same as above, but more precise
277
- *
278
- * The list of view objects which implement the `is()` method:
279
- *
280
- * * {@link module:engine/view/attributeelement~AttributeElement#is `AttributeElement#is()`}
281
- * * {@link module:engine/view/containerelement~ContainerElement#is `ContainerElement#is()`}
282
- * * {@link module:engine/view/documentfragment~DocumentFragment#is `DocumentFragment#is()`}
283
- * * {@link module:engine/view/documentselection~DocumentSelection#is `DocumentSelection#is()`}
284
- * * {@link module:engine/view/editableelement~EditableElement#is `EditableElement#is()`}
285
- * * {@link module:engine/view/element~Element#is `Element#is()`}
286
- * * {@link module:engine/view/emptyelement~EmptyElement#is `EmptyElement#is()`}
287
- * * {@link module:engine/view/node~Node#is `Node#is()`}
288
- * * {@link module:engine/view/position~Position#is `Position#is()`}
289
- * * {@link module:engine/view/range~Range#is `Range#is()`}
290
- * * {@link module:engine/view/rooteditableelement~RootEditableElement#is `RootEditableElement#is()`}
291
- * * {@link module:engine/view/selection~Selection#is `Selection#is()`}
292
- * * {@link module:engine/view/text~Text#is `Text#is()`}
293
- * * {@link module:engine/view/textproxy~TextProxy#is `TextProxy#is()`}
294
- * * {@link module:engine/view/uielement~UIElement#is `UIElement#is()`}
295
- *
296
- * @method #is
297
- * @param {String} type Type to check.
298
- * @returns {Boolean}
299
- */
224
+ // The magic of type inference using `is` method is centralized in `TypeCheckable` class.
225
+ // Proper overload would interfere with that.
300
226
  Node.prototype.is = function (type) {
301
227
  return type === 'node' || type === 'view:node';
302
228
  };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module engine/view/observer/arrowkeysobserver
7
+ */
8
+ import Observer from './observer';
9
+ import type View from '../view';
10
+ import type { KeyEventData } from './keyobserver';
11
+ import type { BubblingEvent } from './bubblingemittermixin';
12
+ /**
13
+ * Arrow keys observer introduces the {@link module:engine/view/document~Document#event:arrowKey `Document#arrowKey`} event.
14
+ *
15
+ * Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
16
+ */
17
+ export default class ArrowKeysObserver extends Observer {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ constructor(view: View);
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ observe(): void;
26
+ }
27
+ /**
28
+ * Event fired when the user presses an arrow keys.
29
+ *
30
+ * Introduced by {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver}.
31
+ *
32
+ * Note that because {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver} is attached by the
33
+ * {@link module:engine/view/view~View} this event is available by default.
34
+ *
35
+ * @eventName arrowKey
36
+ * @param data
37
+ */
38
+ export type ViewDocumentArrowKeyEvent = BubblingEvent<{
39
+ name: 'arrowKey';
40
+ args: [data: KeyEventData];
41
+ }>;
@@ -12,8 +12,6 @@ import { isArrowKeyCode } from '@ckeditor/ckeditor5-utils';
12
12
  * Arrow keys observer introduces the {@link module:engine/view/document~Document#event:arrowKey `Document#arrowKey`} event.
13
13
  *
14
14
  * Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
15
- *
16
- * @extends module:engine/view/observer/observer~Observer
17
15
  */
18
16
  export default class ArrowKeysObserver extends Observer {
19
17
  /**
@@ -36,14 +34,3 @@ export default class ArrowKeysObserver extends Observer {
36
34
  */
37
35
  observe() { }
38
36
  }
39
- /**
40
- * Event fired when the user presses an arrow keys.
41
- *
42
- * Introduced by {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver}.
43
- *
44
- * Note that because {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver} is attached by the
45
- * {@link module:engine/view/view~View} this event is available by default.
46
- *
47
- * @event module:engine/view/document~Document#event:arrowKey
48
- * @param {module:engine/view/observer/domeventdata~DomEventData} data
49
- */
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module engine/view/observer/bubblingemittermixin
7
+ */
8
+ import { type ArrayOrItem, type Emitter, type BaseEvent, type CallbackOptions, type Constructor, type Mixed } from '@ckeditor/ckeditor5-utils';
9
+ import BubblingEventInfo from './bubblingeventinfo';
10
+ import type Node from '../node';
11
+ /**
12
+ * Bubbling emitter mixin for the view document as described in the {@link ~BubblingEmitter} interface.
13
+ *
14
+ * This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
15
+ * The base class must implement {@link module:utils/emittermixin~Emitter} interface.
16
+ *
17
+ * ```ts
18
+ * class BaseClass extends EmitterMixin() {
19
+ * // ...
20
+ * }
21
+ *
22
+ * class MyClass extends BubblingEmitterMixin( BaseClass ) {
23
+ * // This class derives from `BaseClass` and implements the `BubblingEmitter` interface.
24
+ * }
25
+ * ```
26
+ */
27
+ export default function BubblingEmitterMixin<Base extends Constructor<Emitter>>(base: Base): Mixed<Base, BubblingEmitter>;
28
+ /**
29
+ * Bubbling emitter for the view document.
30
+ *
31
+ * Bubbling emitter is triggering events in the context of specified {@link module:engine/view/element~Element view element} name,
32
+ * predefined `'$text'`, `'$root'`, `'$document'` and `'$capture'` contexts, and context matchers provided as a function.
33
+ *
34
+ * Before bubbling starts, listeners for `'$capture'` context are triggered. Then the bubbling starts from the deeper selection
35
+ * position (by firing event on the `'$text'` context) and propagates the view document tree up to the `'$root'` and finally
36
+ * the listeners at `'$document'` context are fired (this is the default context).
37
+ *
38
+ * Examples:
39
+ *
40
+ * ```ts
41
+ * // Listeners registered in the context of the view element names:
42
+ * this.listenTo( viewDocument, 'enter', ( evt, data ) => {
43
+ * // ...
44
+ * }, { context: 'blockquote' } );
45
+ *
46
+ * this.listenTo( viewDocument, 'enter', ( evt, data ) => {
47
+ * // ...
48
+ * }, { context: 'li' } );
49
+ *
50
+ * // Listeners registered in the context of the '$text' and '$root' nodes.
51
+ * this.listenTo( view.document, 'arrowKey', ( evt, data ) => {
52
+ * // ...
53
+ * }, { context: '$text', priority: 'high' } );
54
+ *
55
+ * this.listenTo( view.document, 'arrowKey', ( evt, data ) => {
56
+ * // ...
57
+ * }, { context: '$root' } );
58
+ *
59
+ * // Listeners registered in the context of custom callback function.
60
+ * this.listenTo( view.document, 'arrowKey', ( evt, data ) => {
61
+ * // ...
62
+ * }, { context: isWidget } );
63
+ *
64
+ * this.listenTo( view.document, 'arrowKey', ( evt, data ) => {
65
+ * // ...
66
+ * }, { context: isWidget, priority: 'high' } );
67
+ * ```
68
+ *
69
+ * Example flow for selection in text:
70
+ *
71
+ * ```xml
72
+ * <blockquote><p>Foo[]bar</p></blockquote>
73
+ * ```
74
+ *
75
+ * Fired events on contexts:
76
+ * 1. `'$capture'`
77
+ * 2. `'$text'`
78
+ * 3. `'p'`
79
+ * 4. `'blockquote'`
80
+ * 5. `'$root'`
81
+ * 6. `'$document'`
82
+ *
83
+ * Example flow for selection on element (i.e., Widget):
84
+ *
85
+ * ```xml
86
+ * <blockquote><p>Foo[<widget/>]bar</p></blockquote>
87
+ * ```
88
+ *
89
+ * Fired events on contexts:
90
+ * 1. `'$capture'`
91
+ * 2. *widget* (custom matcher)
92
+ * 3. `'p'`
93
+ * 4. `'blockquote'`
94
+ * 5. `'$root'`
95
+ * 6. `'$document'`
96
+ *
97
+ * There could be multiple listeners registered for the same context and at different priority levels:
98
+ *
99
+ * ```html
100
+ * <p>Foo[]bar</p>
101
+ * ```
102
+ *
103
+ * 1. `'$capture'` at priorities:
104
+ * 1. `'highest'`
105
+ * 2. `'high'`
106
+ * 3. `'normal'`
107
+ * 4. `'low'`
108
+ * 5. `'lowest'`
109
+ * 2. `'$text'` at priorities:
110
+ * 1. `'highest'`
111
+ * 2. `'high'`
112
+ * 3. `'normal'`
113
+ * 4. `'low'`
114
+ * 5. `'lowest'`
115
+ * 3. `'p'` at priorities:
116
+ * 1. `'highest'`
117
+ * 2. `'high'`
118
+ * 3. `'normal'`
119
+ * 4. `'low'`
120
+ * 5. `'lowest'`
121
+ * 4. `'$root'` at priorities:
122
+ * 1. `'highest'`
123
+ * 2. `'high'`
124
+ * 3. `'normal'`
125
+ * 4. `'low'`
126
+ * 5. `'lowest'`
127
+ * 5. `'$document'` at priorities:
128
+ * 1. `'highest'`
129
+ * 2. `'high'`
130
+ * 3. `'normal'`
131
+ * 4. `'low'`
132
+ * 5. `'lowest'`
133
+ */
134
+ export type BubblingEmitter = Emitter;
135
+ /**
136
+ * A context matcher function.
137
+ *
138
+ * Should return true for nodes that that match the custom context.
139
+ */
140
+ export type BubblingEventContextFunction = (node: Node) => boolean;
141
+ /**
142
+ * Helper type that allows describing bubbling event. Extends `TEvent` so that:
143
+ *
144
+ * * the event is called with {@link module:engine/view/observer/bubblingeventinfo~BubblingEventInfo}`
145
+ * instead of {@link module:utils/eventinfo~EventInfo}, and
146
+ * * {@link ~BubblingCallbackOptions} can be specified as additional options.
147
+ *
148
+ * @typeParam TEvent The event description to extend.
149
+ */
150
+ export type BubblingEvent<TEvent extends BaseEvent> = TEvent & {
151
+ eventInfo: BubblingEventInfo<TEvent['name'], (TEvent extends {
152
+ return: infer TReturn;
153
+ } ? TReturn : unknown)>;
154
+ callbackOptions: BubblingCallbackOptions;
155
+ };
156
+ /**
157
+ * Additional options for registering a callback.
158
+ */
159
+ export interface BubblingCallbackOptions extends CallbackOptions {
160
+ /**
161
+ * Specifies the context in which the event should be triggered to call the callback.
162
+ *
163
+ * @see ~BubblingEmitter
164
+ */
165
+ context?: ArrayOrItem<string | BubblingEventContextFunction>;
166
+ }