@ckeditor/ckeditor5-engine 41.2.0 → 41.3.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/content-index.css +4 -0
  2. package/dist/editor-index.css +23 -0
  3. package/dist/index.css +49 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +36728 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/types/controller/datacontroller.d.ts +335 -0
  8. package/dist/types/controller/editingcontroller.d.ts +98 -0
  9. package/dist/types/conversion/conversion.d.ts +478 -0
  10. package/dist/types/conversion/conversionhelpers.d.ts +26 -0
  11. package/dist/types/conversion/downcastdispatcher.d.ts +562 -0
  12. package/dist/types/conversion/downcasthelpers.d.ts +1190 -0
  13. package/dist/types/conversion/mapper.d.ts +503 -0
  14. package/dist/types/conversion/modelconsumable.d.ts +201 -0
  15. package/dist/types/conversion/upcastdispatcher.d.ts +492 -0
  16. package/dist/types/conversion/upcasthelpers.d.ts +499 -0
  17. package/dist/types/conversion/viewconsumable.d.ts +369 -0
  18. package/dist/types/dataprocessor/basichtmlwriter.d.ts +18 -0
  19. package/dist/types/dataprocessor/dataprocessor.d.ts +61 -0
  20. package/dist/types/dataprocessor/htmldataprocessor.d.ts +76 -0
  21. package/dist/types/dataprocessor/htmlwriter.d.ts +16 -0
  22. package/dist/types/dataprocessor/xmldataprocessor.d.ts +90 -0
  23. package/dist/types/dev-utils/model.d.ts +124 -0
  24. package/dist/types/dev-utils/operationreplayer.d.ts +51 -0
  25. package/dist/types/dev-utils/utils.d.ts +37 -0
  26. package/dist/types/dev-utils/view.d.ts +319 -0
  27. package/dist/types/index.d.ts +113 -0
  28. package/dist/types/model/batch.d.ts +106 -0
  29. package/dist/types/model/differ.d.ts +415 -0
  30. package/dist/types/model/document.d.ts +274 -0
  31. package/dist/types/model/documentfragment.d.ts +200 -0
  32. package/dist/types/model/documentselection.d.ts +420 -0
  33. package/dist/types/model/element.d.ts +165 -0
  34. package/dist/types/model/history.d.ts +114 -0
  35. package/dist/types/model/item.d.ts +14 -0
  36. package/dist/types/model/liveposition.d.ts +77 -0
  37. package/dist/types/model/liverange.d.ts +102 -0
  38. package/dist/types/model/markercollection.d.ts +335 -0
  39. package/dist/types/model/model.d.ts +919 -0
  40. package/dist/types/model/node.d.ts +255 -0
  41. package/dist/types/model/nodelist.d.ts +91 -0
  42. package/dist/types/model/operation/attributeoperation.d.ts +103 -0
  43. package/dist/types/model/operation/detachoperation.d.ts +60 -0
  44. package/dist/types/model/operation/insertoperation.d.ts +90 -0
  45. package/dist/types/model/operation/markeroperation.d.ts +91 -0
  46. package/dist/types/model/operation/mergeoperation.d.ts +100 -0
  47. package/dist/types/model/operation/moveoperation.d.ts +96 -0
  48. package/dist/types/model/operation/nooperation.d.ts +38 -0
  49. package/dist/types/model/operation/operation.d.ts +96 -0
  50. package/dist/types/model/operation/operationfactory.d.ts +18 -0
  51. package/dist/types/model/operation/renameoperation.d.ts +83 -0
  52. package/dist/types/model/operation/rootattributeoperation.d.ts +98 -0
  53. package/dist/types/model/operation/rootoperation.d.ts +76 -0
  54. package/dist/types/model/operation/splitoperation.d.ts +109 -0
  55. package/dist/types/model/operation/transform.d.ts +100 -0
  56. package/dist/types/model/operation/utils.d.ts +71 -0
  57. package/dist/types/model/position.d.ts +538 -0
  58. package/dist/types/model/range.d.ts +458 -0
  59. package/dist/types/model/rootelement.d.ts +60 -0
  60. package/dist/types/model/schema.d.ts +1206 -0
  61. package/dist/types/model/selection.d.ts +482 -0
  62. package/dist/types/model/text.d.ts +66 -0
  63. package/dist/types/model/textproxy.d.ts +144 -0
  64. package/dist/types/model/treewalker.d.ts +186 -0
  65. package/dist/types/model/typecheckable.d.ts +285 -0
  66. package/dist/types/model/utils/autoparagraphing.d.ts +37 -0
  67. package/dist/types/model/utils/deletecontent.d.ts +58 -0
  68. package/dist/types/model/utils/getselectedcontent.d.ts +30 -0
  69. package/dist/types/model/utils/insertcontent.d.ts +46 -0
  70. package/dist/types/model/utils/insertobject.d.ts +47 -0
  71. package/dist/types/model/utils/modifyselection.d.ts +48 -0
  72. package/dist/types/model/utils/selection-post-fixer.d.ts +74 -0
  73. package/dist/types/model/writer.d.ts +851 -0
  74. package/dist/types/view/attributeelement.d.ts +108 -0
  75. package/dist/types/view/containerelement.d.ts +49 -0
  76. package/dist/types/view/datatransfer.d.ts +79 -0
  77. package/dist/types/view/document.d.ts +184 -0
  78. package/dist/types/view/documentfragment.d.ts +153 -0
  79. package/dist/types/view/documentselection.d.ts +306 -0
  80. package/dist/types/view/domconverter.d.ts +652 -0
  81. package/dist/types/view/downcastwriter.d.ts +996 -0
  82. package/dist/types/view/editableelement.d.ts +62 -0
  83. package/dist/types/view/element.d.ts +468 -0
  84. package/dist/types/view/elementdefinition.d.ts +87 -0
  85. package/dist/types/view/emptyelement.d.ts +41 -0
  86. package/dist/types/view/filler.d.ts +111 -0
  87. package/dist/types/view/item.d.ts +14 -0
  88. package/dist/types/view/matcher.d.ts +486 -0
  89. package/dist/types/view/node.d.ts +162 -0
  90. package/dist/types/view/observer/arrowkeysobserver.d.ts +45 -0
  91. package/dist/types/view/observer/bubblingemittermixin.d.ts +166 -0
  92. package/dist/types/view/observer/bubblingeventinfo.d.ts +47 -0
  93. package/dist/types/view/observer/clickobserver.d.ts +43 -0
  94. package/dist/types/view/observer/compositionobserver.d.ts +82 -0
  95. package/dist/types/view/observer/domeventdata.d.ts +50 -0
  96. package/dist/types/view/observer/domeventobserver.d.ts +73 -0
  97. package/dist/types/view/observer/fakeselectionobserver.d.ts +47 -0
  98. package/dist/types/view/observer/focusobserver.d.ts +82 -0
  99. package/dist/types/view/observer/inputobserver.d.ts +86 -0
  100. package/dist/types/view/observer/keyobserver.d.ts +66 -0
  101. package/dist/types/view/observer/mouseobserver.d.ts +89 -0
  102. package/dist/types/view/observer/mutationobserver.d.ts +86 -0
  103. package/dist/types/view/observer/observer.d.ts +89 -0
  104. package/dist/types/view/observer/selectionobserver.d.ts +148 -0
  105. package/dist/types/view/observer/tabobserver.d.ts +46 -0
  106. package/dist/types/view/placeholder.d.ts +96 -0
  107. package/dist/types/view/position.d.ts +188 -0
  108. package/dist/types/view/range.d.ts +279 -0
  109. package/dist/types/view/rawelement.d.ts +73 -0
  110. package/dist/types/view/renderer.d.ts +265 -0
  111. package/dist/types/view/rooteditableelement.d.ts +41 -0
  112. package/dist/types/view/selection.d.ts +375 -0
  113. package/dist/types/view/styles/background.d.ts +33 -0
  114. package/dist/types/view/styles/border.d.ts +43 -0
  115. package/dist/types/view/styles/margin.d.ts +29 -0
  116. package/dist/types/view/styles/padding.d.ts +29 -0
  117. package/dist/types/view/styles/utils.d.ts +93 -0
  118. package/dist/types/view/stylesmap.d.ts +673 -0
  119. package/dist/types/view/text.d.ts +74 -0
  120. package/dist/types/view/textproxy.d.ts +97 -0
  121. package/dist/types/view/treewalker.d.ts +195 -0
  122. package/dist/types/view/typecheckable.d.ts +448 -0
  123. package/dist/types/view/uielement.d.ts +96 -0
  124. package/dist/types/view/upcastwriter.d.ts +417 -0
  125. package/dist/types/view/view.d.ts +487 -0
  126. package/package.json +3 -2
  127. package/src/model/node.d.ts +0 -1
  128. package/src/model/node.js +0 -2
  129. package/src/model/position.d.ts +0 -1
  130. package/src/model/position.js +0 -2
  131. package/src/view/node.d.ts +0 -1
  132. package/src/view/node.js +0 -2
  133. package/src/view/position.d.ts +0 -1
  134. package/src/view/position.js +0 -2
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
9
+ import type { default as Document, ChangeType } from './document.js';
10
+ import type DocumentFragment from './documentfragment.js';
11
+ import type Element from './element.js';
12
+ declare const Node_base: import("@ckeditor/ckeditor5-utils").Mixed<typeof TypeCheckable, import("@ckeditor/ckeditor5-utils").Emitter>;
13
+ /**
14
+ * Abstract view node class.
15
+ *
16
+ * This is an abstract class. Its constructor should not be used directly.
17
+ * Use the {@link module:engine/view/downcastwriter~DowncastWriter} or {@link module:engine/view/upcastwriter~UpcastWriter}
18
+ * to create new instances of view nodes.
19
+ */
20
+ export default abstract class Node extends Node_base {
21
+ /**
22
+ * The document instance to which this node belongs.
23
+ */
24
+ readonly document: Document;
25
+ /**
26
+ * Parent element. Null by default. Set by {@link module:engine/view/element~Element#_insertChild}.
27
+ */
28
+ readonly parent: Element | DocumentFragment | null;
29
+ /**
30
+ * Creates a tree view node.
31
+ *
32
+ * @param document The document instance to which this node belongs.
33
+ */
34
+ protected constructor(document: Document);
35
+ /**
36
+ * Index of the node in the parent element or null if the node has no parent.
37
+ *
38
+ * Accessing this property throws an error if this node's parent element does not contain it.
39
+ * This means that view tree got broken.
40
+ */
41
+ get index(): number | null;
42
+ /**
43
+ * Node's next sibling, or `null` if it is the last child.
44
+ */
45
+ get nextSibling(): Node | null;
46
+ /**
47
+ * Node's previous sibling, or `null` if it is the first child.
48
+ */
49
+ get previousSibling(): Node | null;
50
+ /**
51
+ * Top-most ancestor of the node. If the node has no parent it is the root itself.
52
+ */
53
+ get root(): Element | DocumentFragment;
54
+ /**
55
+ * Returns true if the node is in a tree rooted in the document (is a descendant of one of its roots).
56
+ */
57
+ isAttached(): boolean;
58
+ /**
59
+ * Gets a path to the node. The path is an array containing indices of consecutive ancestors of this node,
60
+ * beginning from {@link module:engine/view/node~Node#root root}, down to this node's index.
61
+ *
62
+ * ```ts
63
+ * const abc = downcastWriter.createText( 'abc' );
64
+ * const foo = downcastWriter.createText( 'foo' );
65
+ * const h1 = downcastWriter.createElement( 'h1', null, downcastWriter.createText( 'header' ) );
66
+ * const p = downcastWriter.createElement( 'p', null, [ abc, foo ] );
67
+ * const div = downcastWriter.createElement( 'div', null, [ h1, p ] );
68
+ * foo.getPath(); // Returns [ 1, 3 ]. `foo` is in `p` which is in `div`. `p` starts at offset 1, while `foo` at 3.
69
+ * h1.getPath(); // Returns [ 0 ].
70
+ * div.getPath(); // Returns [].
71
+ * ```
72
+ *
73
+ * @returns The path.
74
+ */
75
+ getPath(): Array<number>;
76
+ /**
77
+ * Returns ancestors array of this node.
78
+ *
79
+ * @param options Options object.
80
+ * @param options.includeSelf When set to `true` this node will be also included in parent's array.
81
+ * @param options.parentFirst When set to `true`, array will be sorted from node's parent to root element,
82
+ * otherwise root element will be the first item in the array.
83
+ * @returns Array with ancestors.
84
+ */
85
+ getAncestors(options?: {
86
+ includeSelf?: boolean;
87
+ parentFirst?: boolean;
88
+ }): Array<Node | DocumentFragment>;
89
+ /**
90
+ * Returns a {@link module:engine/view/element~Element} or {@link module:engine/view/documentfragment~DocumentFragment}
91
+ * which is a common ancestor of both nodes.
92
+ *
93
+ * @param node The second node.
94
+ * @param options Options object.
95
+ * @param options.includeSelf When set to `true` both nodes will be considered "ancestors" too.
96
+ * Which means that if e.g. node A is inside B, then their common ancestor will be B.
97
+ */
98
+ getCommonAncestor(node: Node, options?: {
99
+ includeSelf?: boolean;
100
+ }): Element | DocumentFragment | null;
101
+ /**
102
+ * Returns whether this node is before given node. `false` is returned if nodes are in different trees (for example,
103
+ * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
104
+ *
105
+ * @param node Node to compare with.
106
+ */
107
+ isBefore(node: Node): boolean;
108
+ /**
109
+ * Returns whether this node is after given node. `false` is returned if nodes are in different trees (for example,
110
+ * in different {@link module:engine/view/documentfragment~DocumentFragment}s).
111
+ *
112
+ * @param node Node to compare with.
113
+ */
114
+ isAfter(node: Node): boolean;
115
+ /**
116
+ * Removes node from parent.
117
+ *
118
+ * @internal
119
+ */
120
+ _remove(): void;
121
+ /**
122
+ * @internal
123
+ * @param type Type of the change.
124
+ * @param node Changed node.
125
+ * @fires change
126
+ */
127
+ _fireChange(type: ChangeType, node: Node): void;
128
+ /**
129
+ * Custom toJSON method to solve child-parent circular dependencies.
130
+ *
131
+ * @returns Clone of this object with the parent property removed.
132
+ */
133
+ toJSON(): unknown;
134
+ /**
135
+ * Clones this node.
136
+ *
137
+ * @internal
138
+ * @returns Clone of this node.
139
+ */
140
+ abstract _clone(deep?: boolean): Node;
141
+ /**
142
+ * Checks if provided node is similar to this node.
143
+ *
144
+ * @returns True if nodes are similar.
145
+ */
146
+ abstract isSimilar(other: Node): boolean;
147
+ }
148
+ /**
149
+ * Fired when list of {@link module:engine/view/element~Element elements} children, attributes or data changes.
150
+ *
151
+ * Change event is bubbled – it is fired on all ancestors.
152
+ *
153
+ * @eventName ~Node#change
154
+ * @eventName ~Node#change:children
155
+ * @eventName ~Node#change:attributes
156
+ * @eventName ~Node#change:text
157
+ */
158
+ export type ViewNodeChangeEvent = {
159
+ name: 'change' | `change:${ChangeType}`;
160
+ args: [changedNode: Node];
161
+ };
162
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
9
+ import type View from '../view.js';
10
+ import type { KeyEventData } from './keyobserver.js';
11
+ import type { BubblingEvent } from './bubblingemittermixin.js';
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
+ * @inheritDoc
28
+ */
29
+ stopObserving(): void;
30
+ }
31
+ /**
32
+ * Event fired when the user presses an arrow keys.
33
+ *
34
+ * Introduced by {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver}.
35
+ *
36
+ * Note that because {@link module:engine/view/observer/arrowkeysobserver~ArrowKeysObserver} is attached by the
37
+ * {@link module:engine/view/view~View} this event is available by default.
38
+ *
39
+ * @eventName module:engine/view/document~Document#arrowKey
40
+ * @param data
41
+ */
42
+ export type ViewDocumentArrowKeyEvent = BubblingEvent<{
43
+ name: 'arrowKey';
44
+ args: [data: KeyEventData];
45
+ }>;
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
10
+ import type Node from '../node.js';
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
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/bubblingeventinfo
7
+ */
8
+ import { EventInfo } from '@ckeditor/ckeditor5-utils';
9
+ import type Document from '../document.js';
10
+ import type Node from '../node.js';
11
+ import type Range from '../range.js';
12
+ /**
13
+ * The event object passed to bubbling event callbacks. It is used to provide information about the event as well as a tool to
14
+ * manipulate it.
15
+ */
16
+ export default class BubblingEventInfo<TName extends string = string, TReturn = unknown> extends EventInfo<TName, TReturn> {
17
+ /**
18
+ * The view range that the bubbling should start from.
19
+ */
20
+ readonly startRange: Range;
21
+ /**
22
+ * The current event phase.
23
+ */
24
+ private _eventPhase;
25
+ /**
26
+ * The current bubbling target.
27
+ */
28
+ private _currentTarget;
29
+ /**
30
+ * @param source The emitter.
31
+ * @param name The event name.
32
+ * @param startRange The view range that the bubbling should start from.
33
+ */
34
+ constructor(source: object, name: TName, startRange: Range);
35
+ /**
36
+ * The current event phase.
37
+ */
38
+ get eventPhase(): EventPhase;
39
+ /**
40
+ * The current bubbling target.
41
+ */
42
+ get currentTarget(): Document | Node | null;
43
+ }
44
+ /**
45
+ * The phase the event is in.
46
+ */
47
+ export type EventPhase = 'none' | 'capturing' | 'atTarget' | 'bubbling';
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/clickobserver
7
+ */
8
+ import DomEventObserver from './domeventobserver.js';
9
+ import type DomEventData from './domeventdata.js';
10
+ import type { BubblingEvent } from './bubblingemittermixin.js';
11
+ /**
12
+ * {@link module:engine/view/document~Document#event:click Click} event observer.
13
+ *
14
+ * Note that this observer is not available by default. To make it available it needs to be added to
15
+ * {@link module:engine/view/view~View view controller} by a {@link module:engine/view/view~View#addObserver} method.
16
+ */
17
+ export default class ClickObserver extends DomEventObserver<'click'> {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ readonly domEventType: "click";
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ onDomEvent(domEvent: MouseEvent): void;
26
+ }
27
+ /**
28
+ * Fired when one of the editables has been clicked.
29
+ *
30
+ * Introduced by {@link module:engine/view/observer/clickobserver~ClickObserver}.
31
+ *
32
+ * Note that this event is not available by default. To make it available
33
+ * {@link module:engine/view/observer/clickobserver~ClickObserver} needs to be added
34
+ * to {@link module:engine/view/view~View} by a {@link module:engine/view/view~View#addObserver} method.
35
+ *
36
+ * @see module:engine/view/observer/clickobserver~ClickObserver
37
+ * @eventName module:engine/view/document~Document#click
38
+ * @param data Event data.
39
+ */
40
+ export type ViewDocumentClickEvent = BubblingEvent<{
41
+ name: 'click';
42
+ args: [data: DomEventData<MouseEvent>];
43
+ }>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/compositionobserver
7
+ */
8
+ import DomEventObserver from './domeventobserver.js';
9
+ import type View from '../view.js';
10
+ import type DomEventData from './domeventdata.js';
11
+ /**
12
+ * {@link module:engine/view/document~Document#event:compositionstart Compositionstart},
13
+ * {@link module:engine/view/document~Document#event:compositionupdate compositionupdate} and
14
+ * {@link module:engine/view/document~Document#event:compositionend compositionend} events observer.
15
+ *
16
+ * Note that this observer is attached by the {@link module:engine/view/view~View} and is available by default.
17
+ */
18
+ export default class CompositionObserver extends DomEventObserver<'compositionstart' | 'compositionupdate' | 'compositionend'> {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ readonly domEventType: readonly ["compositionstart", "compositionupdate", "compositionend"];
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ constructor(view: View);
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ onDomEvent(domEvent: CompositionEvent): void;
31
+ }
32
+ export interface CompositionEventData extends DomEventData<CompositionEvent> {
33
+ data: string | null;
34
+ }
35
+ /**
36
+ * Fired when composition starts inside one of the editables.
37
+ *
38
+ * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
39
+ *
40
+ * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
41
+ * {@link module:engine/view/view~View} this event is available by default.
42
+ *
43
+ * @see module:engine/view/observer/compositionobserver~CompositionObserver
44
+ * @eventName module:engine/view/document~Document#compositionstart
45
+ * @param data Event data.
46
+ */
47
+ export type ViewDocumentCompositionStartEvent = {
48
+ name: 'compositionstart';
49
+ args: [data: CompositionEventData];
50
+ };
51
+ /**
52
+ * Fired when composition is updated inside one of the editables.
53
+ *
54
+ * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
55
+ *
56
+ * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
57
+ * {@link module:engine/view/view~View} this event is available by default.
58
+ *
59
+ * @see module:engine/view/observer/compositionobserver~CompositionObserver
60
+ * @eventName module:engine/view/document~Document#compositionupdate
61
+ * @param data Event data.
62
+ */
63
+ export type ViewDocumentCompositionUpdateEvent = {
64
+ name: 'compositionupdate';
65
+ args: [data: CompositionEventData];
66
+ };
67
+ /**
68
+ * Fired when composition ends inside one of the editables.
69
+ *
70
+ * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
71
+ *
72
+ * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
73
+ * {@link module:engine/view/view~View} this event is available by default.
74
+ *
75
+ * @see module:engine/view/observer/compositionobserver~CompositionObserver
76
+ * @eventName module:engine/view/document~Document#compositionend
77
+ * @param data Event data.
78
+ */
79
+ export type ViewDocumentCompositionEndEvent = {
80
+ name: 'compositionend';
81
+ args: [data: CompositionEventData];
82
+ };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ import type Document from '../document.js';
6
+ import type Element from '../element.js';
7
+ import type View from '../view.js';
8
+ /**
9
+ * Information about a DOM event in context of the {@link module:engine/view/document~Document}.
10
+ * It wraps the native event, which usually should not be used as the wrapper contains
11
+ * additional data (like key code for keyboard events).
12
+ *
13
+ * @typeParam TEvent The type of DOM Event that this class represents.
14
+ */
15
+ export default class DomEventData<TEvent extends Event = Event> {
16
+ /**
17
+ * Instance of the view controller.
18
+ */
19
+ readonly view: View;
20
+ /**
21
+ * The instance of the document.
22
+ */
23
+ readonly document: Document;
24
+ /**
25
+ * The DOM event.
26
+ */
27
+ readonly domEvent: TEvent;
28
+ /**
29
+ * The DOM target.
30
+ */
31
+ readonly domTarget: HTMLElement;
32
+ /**
33
+ * @param view The instance of the view controller.
34
+ * @param domEvent The DOM event.
35
+ * @param additionalData Additional properties that the instance should contain.
36
+ */
37
+ constructor(view: View, domEvent: TEvent, additionalData?: object);
38
+ /**
39
+ * The tree view element representing the target.
40
+ */
41
+ get target(): Element;
42
+ /**
43
+ * Prevents the native's event default action.
44
+ */
45
+ preventDefault(): void;
46
+ /**
47
+ * Stops native event propagation.
48
+ */
49
+ stopPropagation(): void;
50
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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/domeventobserver
7
+ */
8
+ import Observer from './observer.js';
9
+ import type { EventInfo } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * Base class for DOM event observers. This class handles
12
+ * {@link module:engine/view/observer/observer~Observer#observe adding} listeners to DOM elements,
13
+ * {@link module:engine/view/observer/observer~Observer#disable disabling} and
14
+ * {@link module:engine/view/observer/observer~Observer#enable re-enabling} events.
15
+ * Child class needs to define
16
+ * {@link module:engine/view/observer/domeventobserver~DomEventObserver#domEventType DOM event type} and
17
+ * {@link module:engine/view/observer/domeventobserver~DomEventObserver#onDomEvent callback}.
18
+ *
19
+ * For instance:
20
+ *
21
+ * ```ts
22
+ * class ClickObserver extends DomEventObserver<'click'> {
23
+ * // It can also be defined as a normal property in the constructor.
24
+ * get domEventType(): 'click' {
25
+ * return 'click';
26
+ * }
27
+ *
28
+ * onDomEvent( domEvent: MouseEvent ): void {
29
+ * this.fire( 'click', domEvent );
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * @typeParam EventType DOM Event type name or an union of those.
35
+ * @typeParam AdditionalData Additional data passed along with the event.
36
+ */
37
+ export default abstract class DomEventObserver<EventType extends keyof HTMLElementEventMap, AdditionalData extends object = object> extends Observer {
38
+ /**
39
+ * Type of the DOM event the observer should listen to. Array of types can be defined
40
+ * if the observer should listen to multiple DOM events.
41
+ */
42
+ abstract get domEventType(): EventType | ReadonlyArray<EventType>;
43
+ /**
44
+ * If set to `true` DOM events will be listened on the capturing phase.
45
+ * Default value is `false`.
46
+ */
47
+ useCapture: boolean;
48
+ /**
49
+ * Callback which should be called when the DOM event occurred. Note that the callback will not be called if
50
+ * observer {@link #isEnabled is not enabled}.
51
+ *
52
+ * @see #domEventType
53
+ */
54
+ abstract onDomEvent(event: HTMLElementEventMap[EventType]): void;
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ observe(domElement: HTMLElement): void;
59
+ /**
60
+ * @inheritDoc
61
+ */
62
+ stopObserving(domElement: HTMLElement): void;
63
+ /**
64
+ * Calls `Document#fire()` if observer {@link #isEnabled is enabled}.
65
+ *
66
+ * @see module:utils/emittermixin~Emitter#fire
67
+ * @param eventType The event type (name).
68
+ * @param domEvent The DOM event.
69
+ * @param additionalData The additional data which should extend the
70
+ * {@link module:engine/view/observer/domeventdata~DomEventData event data} object.
71
+ */
72
+ fire(eventType: string | EventInfo, domEvent: Event, additionalData?: AdditionalData): void;
73
+ }