@ckeditor/ckeditor5-engine 36.0.1 → 37.0.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 (203) hide show
  1. package/README.md +1 -1
  2. package/package.json +25 -24
  3. package/src/controller/datacontroller.d.ts +331 -0
  4. package/src/controller/datacontroller.js +72 -116
  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 +503 -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 +369 -0
  24. package/src/conversion/viewconsumable.js +139 -173
  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 +108 -0
  42. package/src/index.js +4 -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 +246 -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 +885 -0
  57. package/src/model/model.js +59 -81
  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/mergeoperation.js +1 -1
  66. package/src/model/operation/moveoperation.d.ts +91 -0
  67. package/src/model/operation/nooperation.d.ts +33 -0
  68. package/src/model/operation/operation.d.ts +89 -0
  69. package/src/model/operation/operationfactory.d.ts +18 -0
  70. package/src/model/operation/renameoperation.d.ts +78 -0
  71. package/src/model/operation/rootattributeoperation.d.ts +97 -0
  72. package/src/model/operation/rootattributeoperation.js +1 -1
  73. package/src/model/operation/splitoperation.d.ts +104 -0
  74. package/src/model/operation/splitoperation.js +1 -1
  75. package/src/model/operation/transform.d.ts +100 -0
  76. package/src/model/operation/utils.d.ts +71 -0
  77. package/src/model/operation/utils.js +1 -1
  78. package/src/model/position.d.ts +539 -0
  79. package/src/model/position.js +1 -1
  80. package/src/model/range.d.ts +458 -0
  81. package/src/model/range.js +1 -1
  82. package/src/model/rootelement.d.ts +40 -0
  83. package/src/model/schema.d.ts +1176 -0
  84. package/src/model/schema.js +19 -19
  85. package/src/model/selection.d.ts +472 -0
  86. package/src/model/text.d.ts +66 -0
  87. package/src/model/text.js +0 -2
  88. package/src/model/textproxy.d.ts +144 -0
  89. package/src/model/treewalker.d.ts +186 -0
  90. package/src/model/treewalker.js +19 -10
  91. package/src/model/typecheckable.d.ts +285 -0
  92. package/src/model/utils/autoparagraphing.d.ts +37 -0
  93. package/src/model/utils/deletecontent.d.ts +58 -0
  94. package/src/model/utils/findoptimalinsertionrange.d.ts +32 -0
  95. package/src/model/utils/getselectedcontent.d.ts +30 -0
  96. package/src/model/utils/insertcontent.d.ts +46 -0
  97. package/src/model/utils/insertcontent.js +2 -12
  98. package/src/model/utils/insertobject.d.ts +44 -0
  99. package/src/model/utils/insertobject.js +3 -14
  100. package/src/model/utils/modifyselection.d.ts +48 -0
  101. package/src/model/utils/selection-post-fixer.d.ts +65 -0
  102. package/src/model/writer.d.ts +823 -0
  103. package/src/model/writer.js +6 -61
  104. package/src/view/attributeelement.d.ts +108 -0
  105. package/src/view/attributeelement.js +25 -69
  106. package/src/view/containerelement.d.ts +49 -0
  107. package/src/view/containerelement.js +10 -43
  108. package/src/view/datatransfer.d.ts +75 -0
  109. package/src/view/document.d.ts +184 -0
  110. package/src/view/document.js +15 -84
  111. package/src/view/documentfragment.d.ts +149 -0
  112. package/src/view/documentfragment.js +39 -81
  113. package/src/view/documentselection.d.ts +306 -0
  114. package/src/view/documentselection.js +42 -143
  115. package/src/view/domconverter.d.ts +650 -0
  116. package/src/view/domconverter.js +157 -283
  117. package/src/view/downcastwriter.d.ts +996 -0
  118. package/src/view/downcastwriter.js +259 -426
  119. package/src/view/editableelement.d.ts +52 -0
  120. package/src/view/editableelement.js +9 -49
  121. package/src/view/element.d.ts +468 -0
  122. package/src/view/element.js +150 -222
  123. package/src/view/elementdefinition.d.ts +87 -0
  124. package/src/view/emptyelement.d.ts +41 -0
  125. package/src/view/emptyelement.js +11 -44
  126. package/src/view/filler.d.ts +111 -0
  127. package/src/view/filler.js +24 -21
  128. package/src/view/item.d.ts +14 -0
  129. package/src/view/matcher.d.ts +486 -0
  130. package/src/view/matcher.js +247 -218
  131. package/src/view/node.d.ts +163 -0
  132. package/src/view/node.js +26 -100
  133. package/src/view/observer/arrowkeysobserver.d.ts +41 -0
  134. package/src/view/observer/arrowkeysobserver.js +0 -13
  135. package/src/view/observer/bubblingemittermixin.d.ts +166 -0
  136. package/src/view/observer/bubblingemittermixin.js +36 -25
  137. package/src/view/observer/bubblingeventinfo.d.ts +47 -0
  138. package/src/view/observer/bubblingeventinfo.js +3 -29
  139. package/src/view/observer/clickobserver.d.ts +43 -0
  140. package/src/view/observer/clickobserver.js +9 -19
  141. package/src/view/observer/compositionobserver.d.ts +82 -0
  142. package/src/view/observer/compositionobserver.js +13 -42
  143. package/src/view/observer/domeventdata.d.ts +50 -0
  144. package/src/view/observer/domeventdata.js +5 -30
  145. package/src/view/observer/domeventobserver.d.ts +69 -0
  146. package/src/view/observer/domeventobserver.js +19 -21
  147. package/src/view/observer/fakeselectionobserver.d.ts +43 -0
  148. package/src/view/observer/fakeselectionobserver.js +0 -16
  149. package/src/view/observer/focusobserver.d.ts +82 -0
  150. package/src/view/observer/focusobserver.js +14 -40
  151. package/src/view/observer/inputobserver.d.ts +86 -0
  152. package/src/view/observer/inputobserver.js +18 -64
  153. package/src/view/observer/keyobserver.d.ts +66 -0
  154. package/src/view/observer/keyobserver.js +8 -42
  155. package/src/view/observer/mouseobserver.d.ts +89 -0
  156. package/src/view/observer/mouseobserver.js +8 -28
  157. package/src/view/observer/mutationobserver.d.ts +82 -0
  158. package/src/view/observer/mutationobserver.js +7 -37
  159. package/src/view/observer/observer.d.ts +84 -0
  160. package/src/view/observer/observer.js +12 -25
  161. package/src/view/observer/selectionobserver.d.ts +144 -0
  162. package/src/view/observer/selectionobserver.js +17 -107
  163. package/src/view/observer/tabobserver.d.ts +42 -0
  164. package/src/view/observer/tabobserver.js +0 -14
  165. package/src/view/placeholder.d.ts +85 -0
  166. package/src/view/placeholder.js +26 -43
  167. package/src/view/position.d.ts +189 -0
  168. package/src/view/position.js +36 -83
  169. package/src/view/range.d.ts +279 -0
  170. package/src/view/range.js +79 -122
  171. package/src/view/rawelement.d.ts +73 -0
  172. package/src/view/rawelement.js +34 -48
  173. package/src/view/renderer.d.ts +265 -0
  174. package/src/view/renderer.js +105 -193
  175. package/src/view/rooteditableelement.d.ts +41 -0
  176. package/src/view/rooteditableelement.js +12 -40
  177. package/src/view/selection.d.ts +375 -0
  178. package/src/view/selection.js +79 -153
  179. package/src/view/styles/background.d.ts +33 -0
  180. package/src/view/styles/background.js +14 -12
  181. package/src/view/styles/border.d.ts +43 -0
  182. package/src/view/styles/border.js +58 -48
  183. package/src/view/styles/margin.d.ts +29 -0
  184. package/src/view/styles/margin.js +13 -11
  185. package/src/view/styles/padding.d.ts +29 -0
  186. package/src/view/styles/padding.js +13 -11
  187. package/src/view/styles/utils.d.ts +93 -0
  188. package/src/view/styles/utils.js +22 -48
  189. package/src/view/stylesmap.d.ts +675 -0
  190. package/src/view/stylesmap.js +249 -244
  191. package/src/view/text.d.ts +74 -0
  192. package/src/view/text.js +16 -46
  193. package/src/view/textproxy.d.ts +97 -0
  194. package/src/view/textproxy.js +10 -59
  195. package/src/view/treewalker.d.ts +195 -0
  196. package/src/view/treewalker.js +43 -106
  197. package/src/view/typecheckable.d.ts +448 -0
  198. package/src/view/uielement.d.ts +96 -0
  199. package/src/view/uielement.js +29 -63
  200. package/src/view/upcastwriter.d.ts +417 -0
  201. package/src/view/upcastwriter.js +86 -157
  202. package/src/view/view.d.ts +417 -0
  203. package/src/view/view.js +47 -175
@@ -9,11 +9,20 @@ import { CKEditorError, EmitterMixin, EventInfo, toArray } from '@ckeditor/ckedi
9
9
  import BubblingEventInfo from './bubblingeventinfo';
10
10
  const contextsSymbol = Symbol('bubbling contexts');
11
11
  /**
12
- * Bubbling emitter mixin for the view document as described in the
13
- * {@link ~BubblingEmitter} interface.
12
+ * Bubbling emitter mixin for the view document as described in the {@link ~BubblingEmitter} interface.
14
13
  *
15
- * @mixin BubblingEmitterMixin
16
- * @implements module:engine/view/observer/bubblingemittermixin~BubblingEmitter
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
+ * ```
17
26
  */
18
27
  export default function BubblingEmitterMixin(base) {
19
28
  class Mixin extends base {
@@ -100,25 +109,26 @@ export default function BubblingEmitterMixin(base) {
100
109
  BubblingEmitterMixin[key] = mixin.prototype[key];
101
110
  });
102
111
  }
103
- // Update the event info bubbling fields.
104
- //
105
- // @param {module:utils/eventinfo~EventInfo} eventInfo The event info object to update.
106
- // @param {'none'|'capturing'|'atTarget'|'bubbling'} eventPhase The current event phase.
107
- // @param {module:engine/view/document~Document|module:engine/view/node~Node} currentTarget The current bubbling target.
112
+ /**
113
+ * Update the event info bubbling fields.
114
+ *
115
+ * @param eventInfo The event info object to update.
116
+ * @param eventPhase The current event phase.
117
+ * @param currentTarget The current bubbling target.
118
+ */
108
119
  function updateEventInfo(eventInfo, eventPhase, currentTarget) {
109
120
  if (eventInfo instanceof BubblingEventInfo) {
110
121
  eventInfo._eventPhase = eventPhase;
111
122
  eventInfo._currentTarget = currentTarget;
112
123
  }
113
124
  }
114
- // Fires the listener for the specified context. Returns `true` if event was stopped.
115
- //
116
- // @private
117
- // @param {Map.<String|Function, module:utils/emittermixin~Emitter>} eventContexts
118
- // @param {String|module:engine/view/node~Node} context
119
- // @param {module:utils/eventinfo~EventInfo} eventInfo The `EventInfo` object.
120
- // @param {...*} [eventArgs] Additional arguments to be passed to the callbacks.
121
- // @returns {Boolean} True if event stop was called.
125
+ /**
126
+ * Fires the listener for the specified context. Returns `true` if event was stopped.
127
+ *
128
+ * @param eventInfo The `EventInfo` object.
129
+ * @param eventArgs Additional arguments to be passed to the callbacks.
130
+ * @returns True if event stop was called.
131
+ */
122
132
  function fireListenerFor(eventContexts, context, eventInfo, ...eventArgs) {
123
133
  const emitter = typeof context == 'string' ? eventContexts.get(context) : getCustomContext(eventContexts, context);
124
134
  if (!emitter) {
@@ -127,12 +137,9 @@ function fireListenerFor(eventContexts, context, eventInfo, ...eventArgs) {
127
137
  emitter.fire(eventInfo, ...eventArgs);
128
138
  return eventInfo.stop.called;
129
139
  }
130
- // Returns an emitter for a specified view node.
131
- //
132
- // @private
133
- // @param {Map.<String|Function, module:utils/emittermixin~Emitter>} eventContexts
134
- // @param {module:engine/view/node~Node} node
135
- // @returns {module:utils/emittermixin~Emitter|null}
140
+ /**
141
+ * Returns an emitter for a specified view node.
142
+ */
136
143
  function getCustomContext(eventContexts, node) {
137
144
  for (const [context, emitter] of eventContexts) {
138
145
  if (typeof context == 'function' && context(node)) {
@@ -141,14 +148,18 @@ function getCustomContext(eventContexts, node) {
141
148
  }
142
149
  return null;
143
150
  }
144
- // Returns bubbling contexts map for the source (emitter).
151
+ /**
152
+ * Returns bubbling contexts map for the source (emitter).
153
+ */
145
154
  function getBubblingContexts(source) {
146
155
  if (!source[contextsSymbol]) {
147
156
  source[contextsSymbol] = new Map();
148
157
  }
149
158
  return source[contextsSymbol];
150
159
  }
151
- // Returns the deeper parent element for the range.
160
+ /**
161
+ * Returns the deeper parent element for the range.
162
+ */
152
163
  function getDeeperRangeParent(range) {
153
164
  if (!range) {
154
165
  return null;
@@ -0,0 +1,47 @@
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/bubblingeventinfo
7
+ */
8
+ import { EventInfo } from '@ckeditor/ckeditor5-utils';
9
+ import type Document from '../document';
10
+ import type Node from '../node';
11
+ import type Range from '../range';
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';
@@ -9,53 +9,27 @@ import { EventInfo } from '@ckeditor/ckeditor5-utils';
9
9
  /**
10
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
11
  * manipulate it.
12
- *
13
- * @extends module:utils/eventinfo~EventInfo
14
12
  */
15
13
  export default class BubblingEventInfo extends EventInfo {
16
14
  /**
17
- * @param {Object} source The emitter.
18
- * @param {String} name The event name.
19
- * @param {module:engine/view/range~Range} startRange The view range that the bubbling should start from.
15
+ * @param source The emitter.
16
+ * @param name The event name.
17
+ * @param startRange The view range that the bubbling should start from.
20
18
  */
21
19
  constructor(source, name, startRange) {
22
20
  super(source, name);
23
- /**
24
- * The view range that the bubbling should start from.
25
- *
26
- * @readonly
27
- * @member {module:engine/view/range~Range}
28
- */
29
21
  this.startRange = startRange;
30
- /**
31
- * The current event phase.
32
- *
33
- * @protected
34
- * @member {'none'|'capturing'|'atTarget'|'bubbling'}
35
- */
36
22
  this._eventPhase = 'none';
37
- /**
38
- * The current bubbling target.
39
- *
40
- * @protected
41
- * @member {module:engine/view/document~Document|module:engine/view/node~Node|null}
42
- */
43
23
  this._currentTarget = null;
44
24
  }
45
25
  /**
46
26
  * The current event phase.
47
- *
48
- * @readonly
49
- * @member {'none'|'capturing'|'atTarget'|'bubbling'}
50
27
  */
51
28
  get eventPhase() {
52
29
  return this._eventPhase;
53
30
  }
54
31
  /**
55
32
  * The current bubbling target.
56
- *
57
- * @readonly
58
- * @member {module:engine/view/document~Document|module:engine/view/node~Node|null}
59
33
  */
60
34
  get currentTarget() {
61
35
  return this._currentTarget;
@@ -0,0 +1,43 @@
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/clickobserver
7
+ */
8
+ import DomEventObserver from './domeventobserver';
9
+ import type DomEventData from './domeventdata';
10
+ import type { BubblingEvent } from './bubblingemittermixin';
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
+ }>;
@@ -10,30 +10,20 @@ import DomEventObserver from './domeventobserver';
10
10
  * {@link module:engine/view/document~Document#event:click Click} event observer.
11
11
  *
12
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~View view controller}
14
- * by a {@link module:engine/view/view~View#addObserver} method.
15
- *
16
- * @extends module:engine/view/observer/domeventobserver~DomEventObserver
13
+ * {@link module:engine/view/view~View view controller} by a {@link module:engine/view/view~View#addObserver} method.
17
14
  */
18
15
  export default class ClickObserver extends DomEventObserver {
19
- constructor(view) {
20
- super(view);
16
+ constructor() {
17
+ super(...arguments);
18
+ /**
19
+ * @inheritDoc
20
+ */
21
21
  this.domEventType = 'click';
22
22
  }
23
+ /**
24
+ * @inheritDoc
25
+ */
23
26
  onDomEvent(domEvent) {
24
27
  this.fire(domEvent.type, domEvent);
25
28
  }
26
29
  }
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
- * @event module:engine/view/document~Document#event:click
38
- * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
39
- */
@@ -0,0 +1,82 @@
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/compositionobserver
7
+ */
8
+ import DomEventObserver from './domeventobserver';
9
+ import type View from '../view';
10
+ import type DomEventData from './domeventdata';
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
+ };
@@ -12,16 +12,20 @@ import DomEventObserver from './domeventobserver';
12
12
  * {@link module:engine/view/document~Document#event:compositionend compositionend} events observer.
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/domeventobserver~DomEventObserver
17
15
  */
18
16
  export default class CompositionObserver extends DomEventObserver {
17
+ /**
18
+ * @inheritDoc
19
+ */
19
20
  constructor(view) {
20
21
  super(view);
22
+ /**
23
+ * @inheritDoc
24
+ */
21
25
  this.domEventType = ['compositionstart', 'compositionupdate', 'compositionend'];
22
26
  const document = this.document;
23
27
  document.on('compositionstart', () => {
24
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
28
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
25
29
  // @if CK_DEBUG_TYPING // console.log( '%c[CompositionObserver] ' +
26
30
  // @if CK_DEBUG_TYPING // '┌───────────────────────────── isComposing = true ─────────────────────────────┐',
27
31
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
@@ -30,7 +34,7 @@ export default class CompositionObserver extends DomEventObserver {
30
34
  document.isComposing = true;
31
35
  }, { priority: 'low' });
32
36
  document.on('compositionend', () => {
33
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
37
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
34
38
  // @if CK_DEBUG_TYPING // console.log( '%c[CompositionObserver] ' +
35
39
  // @if CK_DEBUG_TYPING // '└───────────────────────────── isComposing = false ─────────────────────────────┘',
36
40
  // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green'
@@ -39,51 +43,18 @@ export default class CompositionObserver extends DomEventObserver {
39
43
  document.isComposing = false;
40
44
  }, { priority: 'low' });
41
45
  }
46
+ /**
47
+ * @inheritDoc
48
+ */
42
49
  onDomEvent(domEvent) {
43
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
50
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
44
51
  // @if CK_DEBUG_TYPING // console.group( `%c[CompositionObserver]%c ${ domEvent.type }`, 'color: green', '' );
45
52
  // @if CK_DEBUG_TYPING // }
46
53
  this.fire(domEvent.type, domEvent, {
47
54
  data: domEvent.data
48
55
  });
49
- // @if CK_DEBUG_TYPING // if ( window.logCKETyping ) {
56
+ // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
50
57
  // @if CK_DEBUG_TYPING // console.groupEnd();
51
58
  // @if CK_DEBUG_TYPING // }
52
59
  }
53
60
  }
54
- /**
55
- * Fired when composition starts inside one of the editables.
56
- *
57
- * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
58
- *
59
- * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
60
- * {@link module:engine/view/view~View} this event is available by default.
61
- *
62
- * @see module:engine/view/observer/compositionobserver~CompositionObserver
63
- * @event module:engine/view/document~Document#event:compositionstart
64
- * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
65
- */
66
- /**
67
- * Fired when composition is updated inside one of the editables.
68
- *
69
- * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
70
- *
71
- * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
72
- * {@link module:engine/view/view~View} this event is available by default.
73
- *
74
- * @see module:engine/view/observer/compositionobserver~CompositionObserver
75
- * @event module:engine/view/document~Document#event:compositionupdate
76
- * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
77
- */
78
- /**
79
- * Fired when composition ends inside one of the editables.
80
- *
81
- * Introduced by {@link module:engine/view/observer/compositionobserver~CompositionObserver}.
82
- *
83
- * Note that because {@link module:engine/view/observer/compositionobserver~CompositionObserver} is attached by the
84
- * {@link module:engine/view/view~View} this event is available by default.
85
- *
86
- * @see module:engine/view/observer/compositionobserver~CompositionObserver
87
- * @event module:engine/view/document~Document#event:compositionend
88
- * @param {module:engine/view/observer/domeventdata~DomEventData} data Event data.
89
- */
@@ -0,0 +1,50 @@
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
+ import type Document from '../document';
6
+ import type Element from '../element';
7
+ import type View from '../view';
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
+ }
@@ -10,49 +10,24 @@ import { extend } from 'lodash-es';
10
10
  * Information about a DOM event in context of the {@link module:engine/view/document~Document}.
11
11
  * It wraps the native event, which usually should not be used as the wrapper contains
12
12
  * additional data (like key code for keyboard events).
13
+ *
14
+ * @typeParam TEvent The type of DOM Event that this class represents.
13
15
  */
14
16
  export default class DomEventData {
15
17
  /**
16
- * @param {module:engine/view/view~View} view The instance of the view controller.
17
- * @param {Event} domEvent The DOM event.
18
- * @param {Object} [additionalData] Additional properties that the instance should contain.
18
+ * @param view The instance of the view controller.
19
+ * @param domEvent The DOM event.
20
+ * @param additionalData Additional properties that the instance should contain.
19
21
  */
20
22
  constructor(view, domEvent, additionalData) {
21
- /**
22
- * Instance of the view controller.
23
- *
24
- * @readonly
25
- * @member {module:engine/view/view~View} module:engine/view/observer/observer~Observer.DomEvent#view
26
- */
27
23
  this.view = view;
28
- /**
29
- * The instance of the document.
30
- *
31
- * @readonly
32
- * @member {module:engine/view/document~Document} module:engine/view/observer/observer~Observer.DomEvent#document
33
- */
34
24
  this.document = view.document;
35
- /**
36
- * The DOM event.
37
- *
38
- * @readonly
39
- * @member {Event} module:engine/view/observer/observer~Observer.DomEvent#domEvent
40
- */
41
25
  this.domEvent = domEvent;
42
- /**
43
- * The DOM target.
44
- *
45
- * @readonly
46
- * @member {HTMLElement} module:engine/view/observer/observer~Observer.DomEvent#target
47
- */
48
26
  this.domTarget = domEvent.target;
49
27
  extend(this, additionalData);
50
28
  }
51
29
  /**
52
30
  * The tree view element representing the target.
53
- *
54
- * @readonly
55
- * @type module:engine/view/element~Element
56
31
  */
57
32
  get target() {
58
33
  return this.view.domConverter.mapDomToView(this.domTarget);
@@ -0,0 +1,69 @@
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/domeventobserver
7
+ */
8
+ import Observer from './observer';
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
+ * Calls `Document#fire()` if observer {@link #isEnabled is enabled}.
61
+ *
62
+ * @see module:utils/emittermixin~Emitter#fire
63
+ * @param eventType The event type (name).
64
+ * @param domEvent The DOM event.
65
+ * @param additionalData The additional data which should extend the
66
+ * {@link module:engine/view/observer/domeventdata~DomEventData event data} object.
67
+ */
68
+ fire(eventType: string | EventInfo, domEvent: Event, additionalData?: AdditionalData): void;
69
+ }