@ckeditor/ckeditor5-utils 40.0.0 → 40.2.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 (135) hide show
  1. package/CHANGELOG.md +26 -26
  2. package/LICENSE.md +3 -3
  3. package/package.json +1 -1
  4. package/src/abortabledebounce.d.ts +17 -0
  5. package/src/abortabledebounce.js +22 -0
  6. package/src/areconnectedthroughproperties.d.ts +11 -11
  7. package/src/areconnectedthroughproperties.js +73 -73
  8. package/src/ckeditorerror.d.ts +123 -123
  9. package/src/ckeditorerror.js +176 -176
  10. package/src/collection.d.ts +433 -427
  11. package/src/collection.js +583 -575
  12. package/src/comparearrays.d.ts +30 -30
  13. package/src/comparearrays.js +47 -47
  14. package/src/config.d.ts +163 -163
  15. package/src/config.js +163 -162
  16. package/src/count.d.ts +18 -18
  17. package/src/count.js +24 -24
  18. package/src/delay.d.ts +19 -19
  19. package/src/delay.js +26 -26
  20. package/src/diff.d.ts +31 -31
  21. package/src/diff.js +115 -115
  22. package/src/difftochanges.d.ts +59 -59
  23. package/src/difftochanges.js +79 -79
  24. package/src/dom/createelement.d.ts +57 -57
  25. package/src/dom/createelement.js +40 -40
  26. package/src/dom/emittermixin.d.ts +142 -142
  27. package/src/dom/emittermixin.js +239 -239
  28. package/src/dom/findclosestscrollableancestor.d.ts +11 -11
  29. package/src/dom/findclosestscrollableancestor.js +31 -31
  30. package/src/dom/getancestors.d.ts +17 -17
  31. package/src/dom/getancestors.js +27 -27
  32. package/src/dom/getborderwidths.d.ts +24 -24
  33. package/src/dom/getborderwidths.js +24 -24
  34. package/src/dom/getcommonancestor.d.ts +12 -12
  35. package/src/dom/getcommonancestor.js +25 -25
  36. package/src/dom/getdatafromelement.d.ts +14 -14
  37. package/src/dom/getdatafromelement.js +20 -20
  38. package/src/dom/getpositionedancestor.d.ts +10 -10
  39. package/src/dom/getpositionedancestor.js +22 -22
  40. package/src/dom/global.d.ts +32 -32
  41. package/src/dom/global.js +35 -35
  42. package/src/dom/indexof.d.ts +14 -14
  43. package/src/dom/indexof.js +21 -21
  44. package/src/dom/insertat.d.ts +15 -15
  45. package/src/dom/insertat.js +17 -17
  46. package/src/dom/iscomment.d.ts +11 -11
  47. package/src/dom/iscomment.js +14 -14
  48. package/src/dom/isnode.d.ts +11 -11
  49. package/src/dom/isnode.js +21 -21
  50. package/src/dom/isrange.d.ts +11 -11
  51. package/src/dom/isrange.js +13 -13
  52. package/src/dom/istext.d.ts +11 -11
  53. package/src/dom/istext.js +13 -13
  54. package/src/dom/isvalidattributename.d.ts +10 -10
  55. package/src/dom/isvalidattributename.js +22 -22
  56. package/src/dom/isvisible.d.ts +18 -18
  57. package/src/dom/isvisible.js +20 -20
  58. package/src/dom/iswindow.d.ts +11 -11
  59. package/src/dom/iswindow.js +22 -22
  60. package/src/dom/position.d.ts +211 -211
  61. package/src/dom/position.js +313 -313
  62. package/src/dom/rect.d.ts +195 -195
  63. package/src/dom/rect.js +474 -474
  64. package/src/dom/remove.d.ts +13 -13
  65. package/src/dom/remove.js +18 -18
  66. package/src/dom/resizeobserver.d.ts +74 -74
  67. package/src/dom/resizeobserver.js +126 -126
  68. package/src/dom/scroll.d.ts +73 -73
  69. package/src/dom/scroll.js +383 -383
  70. package/src/dom/setdatainelement.d.ts +14 -14
  71. package/src/dom/setdatainelement.js +20 -20
  72. package/src/dom/tounit.d.ts +22 -22
  73. package/src/dom/tounit.js +16 -16
  74. package/src/elementreplacer.d.ts +31 -31
  75. package/src/elementreplacer.js +43 -43
  76. package/src/emittermixin.d.ts +312 -312
  77. package/src/emittermixin.js +453 -453
  78. package/src/env.d.ts +117 -117
  79. package/src/env.js +122 -122
  80. package/src/eventinfo.d.ts +58 -58
  81. package/src/eventinfo.js +26 -26
  82. package/src/fastdiff.d.ts +112 -112
  83. package/src/fastdiff.js +248 -248
  84. package/src/first.d.ts +11 -11
  85. package/src/first.js +17 -17
  86. package/src/focustracker.d.ts +75 -75
  87. package/src/focustracker.js +95 -95
  88. package/src/index.d.ts +64 -61
  89. package/src/index.js +63 -60
  90. package/src/inserttopriorityarray.d.ts +30 -30
  91. package/src/inserttopriorityarray.js +21 -21
  92. package/src/isiterable.d.ts +14 -14
  93. package/src/isiterable.js +16 -16
  94. package/src/keyboard.d.ts +126 -126
  95. package/src/keyboard.js +221 -221
  96. package/src/keystrokehandler.d.ts +87 -87
  97. package/src/keystrokehandler.js +122 -122
  98. package/src/language.d.ts +17 -17
  99. package/src/language.js +19 -19
  100. package/src/locale.d.ts +120 -120
  101. package/src/locale.js +76 -76
  102. package/src/mapsequal.d.ts +15 -15
  103. package/src/mapsequal.js +27 -27
  104. package/src/mix.d.ts +85 -85
  105. package/src/mix.js +50 -50
  106. package/src/nth.d.ts +16 -16
  107. package/src/nth.js +24 -24
  108. package/src/objecttomap.d.ts +23 -23
  109. package/src/objecttomap.js +27 -27
  110. package/src/observablemixin.d.ts +560 -560
  111. package/src/observablemixin.js +580 -580
  112. package/src/priorities.d.ts +33 -33
  113. package/src/priorities.js +23 -23
  114. package/src/retry.d.ts +33 -0
  115. package/src/retry.js +47 -0
  116. package/src/splicearray.d.ts +26 -26
  117. package/src/splicearray.js +40 -40
  118. package/src/spy.d.ts +21 -21
  119. package/src/spy.js +22 -22
  120. package/src/toarray.d.ts +25 -25
  121. package/src/toarray.js +7 -7
  122. package/src/tomap.d.ts +19 -19
  123. package/src/tomap.js +29 -29
  124. package/src/translation-service.d.ts +168 -168
  125. package/src/translation-service.js +198 -198
  126. package/src/uid.d.ts +15 -15
  127. package/src/uid.js +57 -57
  128. package/src/unicode.d.ts +54 -54
  129. package/src/unicode.js +85 -85
  130. package/src/verifylicense.d.ts +15 -15
  131. package/src/verifylicense.js +87 -87
  132. package/src/version.d.ts +10 -10
  133. package/src/version.js +153 -153
  134. package/src/wait.d.ts +16 -0
  135. package/src/wait.js +29 -0
@@ -1,312 +1,312 @@
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 utils/emittermixin
7
- */
8
- import EventInfo from './eventinfo';
9
- import { type PriorityString } from './priorities';
10
- import type { Constructor, Mixed } from './mix';
11
- import './version';
12
- /**
13
- * Mixin that injects the {@link ~Emitter events API} into its host.
14
- *
15
- * This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
16
- *
17
- * ```ts
18
- * class BaseClass { ... }
19
- *
20
- * class MyClass extends EmitterMixin( BaseClass ) {
21
- * // This class derives from `BaseClass` and implements the `Emitter` interface.
22
- * }
23
- * ```
24
- *
25
- * Read more about the concept of emitters in the:
26
- * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
27
- * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
28
- * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
29
- *
30
- * @label EXTENDS
31
- */
32
- export default function EmitterMixin<Base extends Constructor>(base: Base): Mixed<Base, Emitter>;
33
- /**
34
- * Mixin that injects the {@link ~Emitter events API} into its host.
35
- *
36
- * This function creates a class that implements `Emitter` interface.
37
- *
38
- * ```ts
39
- * class MyClass extends EmitterMixin() {
40
- * // This class implements the `Emitter` interface.
41
- * }
42
- * ```
43
- *
44
- * Read more about the concept of emitters in the:
45
- * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
46
- * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
47
- * * {@glink framework/deep-dive/event-system Event system} deep dive guide.
48
- *
49
- * @label NO_ARGUMENTS
50
- */
51
- export default function EmitterMixin(): {
52
- new (): Emitter;
53
- prototype: Emitter;
54
- };
55
- /**
56
- * Emitter/listener interface.
57
- *
58
- * Can be easily implemented by a class by mixing the {@link module:utils/emittermixin~Emitter} mixin.
59
- *
60
- * ```ts
61
- * class MyClass extends EmitterMixin() {
62
- * // This class now implements the `Emitter` interface.
63
- * }
64
- * ```
65
- *
66
- * Read more about the usage of this interface in the:
67
- * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
68
- * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
69
- * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
70
- */
71
- export interface Emitter {
72
- /**
73
- * Registers a callback function to be executed when an event is fired.
74
- *
75
- * Shorthand for {@link #listenTo `this.listenTo( this, event, callback, options )`} (it makes the emitter
76
- * listen on itself).
77
- *
78
- * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
79
- * @param event The name of the event.
80
- * @param callback The function to be called on event.
81
- * @param options Additional options.
82
- */
83
- on<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
84
- /**
85
- * Registers a callback function to be executed on the next time the event is fired only. This is similar to
86
- * calling {@link #on} followed by {@link #off} in the callback.
87
- *
88
- * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
89
- * @param event The name of the event.
90
- * @param callback The function to be called on event.
91
- * @param options Additional options.
92
- */
93
- once<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
94
- /**
95
- * Stops executing the callback on the given event.
96
- * Shorthand for {@link #stopListening `this.stopListening( this, event, callback )`}.
97
- *
98
- * @param event The name of the event.
99
- * @param callback The function to stop being called.
100
- */
101
- off(event: string, callback: Function): void;
102
- /**
103
- * Registers a callback function to be executed when an event is fired in a specific (emitter) object.
104
- *
105
- * Events can be grouped in namespaces using `:`.
106
- * When namespaced event is fired, it additionally fires all callbacks for that namespace.
107
- *
108
- * ```ts
109
- * // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
110
- * myEmitter.on( 'myGroup', genericCallback );
111
- * myEmitter.on( 'myGroup:myEvent', specificCallback );
112
- *
113
- * // genericCallback is fired.
114
- * myEmitter.fire( 'myGroup' );
115
- * // both genericCallback and specificCallback are fired.
116
- * myEmitter.fire( 'myGroup:myEvent' );
117
- * // genericCallback is fired even though there are no callbacks for "foo".
118
- * myEmitter.fire( 'myGroup:foo' );
119
- * ```
120
- *
121
- * An event callback can {@link module:utils/eventinfo~EventInfo#stop stop the event} and
122
- * set the {@link module:utils/eventinfo~EventInfo#return return value} of the {@link #fire} method.
123
- *
124
- * @label BASE_EMITTER
125
- * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
126
- * @param emitter The object that fires the event.
127
- * @param event The name of the event.
128
- * @param callback The function to be called on event.
129
- * @param options Additional options.
130
- */
131
- listenTo<TEvent extends BaseEvent>(emitter: Emitter, event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
132
- /**
133
- * Stops listening for events. It can be used at different levels:
134
- *
135
- * * To stop listening to a specific callback.
136
- * * To stop listening to a specific event.
137
- * * To stop listening to all events fired by a specific object.
138
- * * To stop listening to all events fired by all objects.
139
- *
140
- * @label BASE_STOP
141
- * @param emitter The object to stop listening to. If omitted, stops it for all objects.
142
- * @param event (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
143
- * for all events from `emitter`.
144
- * @param callback (Requires the `event`) The function to be removed from the call list for the given
145
- * `event`.
146
- */
147
- stopListening(emitter?: Emitter, event?: string, callback?: Function): void;
148
- /**
149
- * Fires an event, executing all callbacks registered for it.
150
- *
151
- * The first parameter passed to callbacks is an {@link module:utils/eventinfo~EventInfo} object,
152
- * followed by the optional `args` provided in the `fire()` method call.
153
- *
154
- * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
155
- * @param eventOrInfo The name of the event or `EventInfo` object if event is delegated.
156
- * @param args Additional arguments to be passed to the callbacks.
157
- * @returns By default the method returns `undefined`. However, the return value can be changed by listeners
158
- * through modification of the {@link module:utils/eventinfo~EventInfo#return `evt.return`}'s property (the event info
159
- * is the first param of every callback).
160
- */
161
- fire<TEvent extends BaseEvent>(eventOrInfo: GetNameOrEventInfo<TEvent>, ...args: TEvent['args']): GetEventInfo<TEvent>['return'];
162
- /**
163
- * Delegates selected events to another {@link module:utils/emittermixin~Emitter}. For instance:
164
- *
165
- * ```ts
166
- * emitterA.delegate( 'eventX' ).to( emitterB );
167
- * emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
168
- * ```
169
- *
170
- * then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:
171
- *
172
- * ```ts
173
- * emitterA.fire( 'eventX', data );
174
- * ```
175
- *
176
- * and `eventY` is delegated (fired by) `emitterC` along with `data`:
177
- *
178
- * ```ts
179
- * emitterA.fire( 'eventY', data );
180
- * ```
181
- *
182
- * @param events Event names that will be delegated to another emitter.
183
- */
184
- delegate(...events: Array<string>): EmitterMixinDelegateChain;
185
- /**
186
- * Stops delegating events. It can be used at different levels:
187
- *
188
- * * To stop delegating all events.
189
- * * To stop delegating a specific event to all emitters.
190
- * * To stop delegating a specific event to a specific emitter.
191
- *
192
- * @param event The name of the event to stop delegating. If omitted, stops it all delegations.
193
- * @param emitter (requires `event`) The object to stop delegating a particular event to.
194
- * If omitted, stops delegation of `event` to all emitters.
195
- */
196
- stopDelegating(event?: string, emitter?: Emitter): void;
197
- }
198
- /**
199
- * Default type describing any event.
200
- *
201
- * Every custom event has to be compatible with `BaseEvent`.
202
- *
203
- * ```ts
204
- * type MyEvent = {
205
- * // In `fire<MyEvent>( name )`, `on<MyEvent>( name )`, `once<MyEvent>( name )` and `listenTo<MyEvent>( name )` calls
206
- * // the `name` argument will be type-checked to ensure it's `'myEvent'` or have `'myEvent:'` prefix.
207
- * // Required.
208
- * name: 'myEvent' | `myEvent:${ string }`;
209
- *
210
- * // In `fire<MyEvent>( name, a, b )` call, `a` and `b` parameters will be type-checked against `number` and `string`.
211
- * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the parameters of provided callback function
212
- * // will be automatically inferred as `EventInfo`, `number` and `string`.
213
- * // Required.
214
- * args: [ number, string ];
215
- *
216
- * // `fire<MyEvent>` will have return type `boolean | undefined`.
217
- * // Optional, unknown by default.
218
- * return: boolean;
219
- *
220
- * // `fire<MyEvent>( eventInfo )` will type-check that `eventInfo` is `MyEventInfo`, not a base `EventInfo` or string.
221
- * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the first callback parameter will be of this type.
222
- * // Optional.
223
- * eventInfo: MyEventInfo;
224
- *
225
- * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the `options` parameter will be of type
226
- * // `{ myOption?: boolean; priority?: PriorityString }
227
- * // Optional.
228
- * callbackOptions: { myOption?: boolean };
229
- * };
230
- * ```
231
- */
232
- export type BaseEvent = {
233
- name: string;
234
- args: Array<any>;
235
- };
236
- /**
237
- * Utility type that gets the `EventInfo` subclass for the given event.
238
- */
239
- export type GetEventInfo<TEvent extends BaseEvent> = TEvent extends {
240
- eventInfo: EventInfo;
241
- } ? TEvent['eventInfo'] : EventInfo<TEvent['name'], (TEvent extends {
242
- return: infer TReturn;
243
- } ? TReturn : unknown)>;
244
- /**
245
- * Utility type that gets the `EventInfo` subclass or event name type for the given event.
246
- */
247
- export type GetNameOrEventInfo<TEvent extends BaseEvent> = TEvent extends {
248
- eventInfo: EventInfo;
249
- } ? TEvent['eventInfo'] : TEvent['name'] | EventInfo<TEvent['name'], (TEvent extends {
250
- return: infer TReturn;
251
- } ? TReturn : unknown)>;
252
- /**
253
- * Utility type that gets the callback type for the given event.
254
- */
255
- export type GetCallback<TEvent extends BaseEvent> = (this: Emitter, ev: GetEventInfo<TEvent>, ...args: TEvent['args']) => void;
256
- /**
257
- * Utility type that gets the callback options for the given event.
258
- */
259
- export type GetCallbackOptions<TEvent extends BaseEvent> = TEvent extends {
260
- callbackOptions: infer TOptions;
261
- } ? TOptions & CallbackOptions : CallbackOptions;
262
- /**
263
- * Additional options for registering a callback.
264
- */
265
- export interface CallbackOptions {
266
- /**
267
- * The priority of this event callback. The higher
268
- * the priority value the sooner the callback will be fired. Events having the same priority are called in the
269
- * order they were added.
270
- *
271
- * @defaultValue `'normal'`
272
- */
273
- readonly priority?: PriorityString;
274
- }
275
- /**
276
- * Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter.
277
- * If not, returns `null`.
278
- *
279
- * @internal
280
- * @param listeningEmitter An emitter that listens.
281
- * @param listenedToEmitterId Unique emitter id of emitter listened to.
282
- */
283
- export declare function _getEmitterListenedTo(listeningEmitter: Emitter, listenedToEmitterId: string): Emitter | null;
284
- /**
285
- * Sets emitter's unique id.
286
- *
287
- * **Note:** `_emitterId` can be set only once.
288
- *
289
- * @internal
290
- * @param emitter An emitter for which id will be set.
291
- * @param id Unique id to set. If not passed, random unique id will be set.
292
- */
293
- export declare function _setEmitterId(emitter: Emitter, id?: string): void;
294
- /**
295
- * Returns emitter's unique id.
296
- *
297
- * @internal
298
- * @param emitter An emitter which id will be returned.
299
- */
300
- export declare function _getEmitterId(emitter: Emitter): string | undefined;
301
- /**
302
- * The return value of {@link ~Emitter#delegate}.
303
- */
304
- export interface EmitterMixinDelegateChain {
305
- /**
306
- * Selects destination for {@link module:utils/emittermixin~Emitter#delegate} events.
307
- *
308
- * @param emitter An `EmitterMixin` instance which is the destination for delegated events.
309
- * @param nameOrFunction A custom event name or function which converts the original name string.
310
- */
311
- to(emitter: Emitter, nameOrFunction?: string | ((name: string) => string)): void;
312
- }
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 utils/emittermixin
7
+ */
8
+ import EventInfo from './eventinfo';
9
+ import { type PriorityString } from './priorities';
10
+ import type { Constructor, Mixed } from './mix';
11
+ import './version';
12
+ /**
13
+ * Mixin that injects the {@link ~Emitter events API} into its host.
14
+ *
15
+ * This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
16
+ *
17
+ * ```ts
18
+ * class BaseClass { ... }
19
+ *
20
+ * class MyClass extends EmitterMixin( BaseClass ) {
21
+ * // This class derives from `BaseClass` and implements the `Emitter` interface.
22
+ * }
23
+ * ```
24
+ *
25
+ * Read more about the concept of emitters in the:
26
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
27
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
28
+ * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
29
+ *
30
+ * @label EXTENDS
31
+ */
32
+ export default function EmitterMixin<Base extends Constructor>(base: Base): Mixed<Base, Emitter>;
33
+ /**
34
+ * Mixin that injects the {@link ~Emitter events API} into its host.
35
+ *
36
+ * This function creates a class that implements `Emitter` interface.
37
+ *
38
+ * ```ts
39
+ * class MyClass extends EmitterMixin() {
40
+ * // This class implements the `Emitter` interface.
41
+ * }
42
+ * ```
43
+ *
44
+ * Read more about the concept of emitters in the:
45
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
46
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
47
+ * * {@glink framework/deep-dive/event-system Event system} deep dive guide.
48
+ *
49
+ * @label NO_ARGUMENTS
50
+ */
51
+ export default function EmitterMixin(): {
52
+ new (): Emitter;
53
+ prototype: Emitter;
54
+ };
55
+ /**
56
+ * Emitter/listener interface.
57
+ *
58
+ * Can be easily implemented by a class by mixing the {@link module:utils/emittermixin~Emitter} mixin.
59
+ *
60
+ * ```ts
61
+ * class MyClass extends EmitterMixin() {
62
+ * // This class now implements the `Emitter` interface.
63
+ * }
64
+ * ```
65
+ *
66
+ * Read more about the usage of this interface in the:
67
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
68
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
69
+ * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
70
+ */
71
+ export interface Emitter {
72
+ /**
73
+ * Registers a callback function to be executed when an event is fired.
74
+ *
75
+ * Shorthand for {@link #listenTo `this.listenTo( this, event, callback, options )`} (it makes the emitter
76
+ * listen on itself).
77
+ *
78
+ * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
79
+ * @param event The name of the event.
80
+ * @param callback The function to be called on event.
81
+ * @param options Additional options.
82
+ */
83
+ on<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
84
+ /**
85
+ * Registers a callback function to be executed on the next time the event is fired only. This is similar to
86
+ * calling {@link #on} followed by {@link #off} in the callback.
87
+ *
88
+ * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
89
+ * @param event The name of the event.
90
+ * @param callback The function to be called on event.
91
+ * @param options Additional options.
92
+ */
93
+ once<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
94
+ /**
95
+ * Stops executing the callback on the given event.
96
+ * Shorthand for {@link #stopListening `this.stopListening( this, event, callback )`}.
97
+ *
98
+ * @param event The name of the event.
99
+ * @param callback The function to stop being called.
100
+ */
101
+ off(event: string, callback: Function): void;
102
+ /**
103
+ * Registers a callback function to be executed when an event is fired in a specific (emitter) object.
104
+ *
105
+ * Events can be grouped in namespaces using `:`.
106
+ * When namespaced event is fired, it additionally fires all callbacks for that namespace.
107
+ *
108
+ * ```ts
109
+ * // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
110
+ * myEmitter.on( 'myGroup', genericCallback );
111
+ * myEmitter.on( 'myGroup:myEvent', specificCallback );
112
+ *
113
+ * // genericCallback is fired.
114
+ * myEmitter.fire( 'myGroup' );
115
+ * // both genericCallback and specificCallback are fired.
116
+ * myEmitter.fire( 'myGroup:myEvent' );
117
+ * // genericCallback is fired even though there are no callbacks for "foo".
118
+ * myEmitter.fire( 'myGroup:foo' );
119
+ * ```
120
+ *
121
+ * An event callback can {@link module:utils/eventinfo~EventInfo#stop stop the event} and
122
+ * set the {@link module:utils/eventinfo~EventInfo#return return value} of the {@link #fire} method.
123
+ *
124
+ * @label BASE_EMITTER
125
+ * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
126
+ * @param emitter The object that fires the event.
127
+ * @param event The name of the event.
128
+ * @param callback The function to be called on event.
129
+ * @param options Additional options.
130
+ */
131
+ listenTo<TEvent extends BaseEvent>(emitter: Emitter, event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
132
+ /**
133
+ * Stops listening for events. It can be used at different levels:
134
+ *
135
+ * * To stop listening to a specific callback.
136
+ * * To stop listening to a specific event.
137
+ * * To stop listening to all events fired by a specific object.
138
+ * * To stop listening to all events fired by all objects.
139
+ *
140
+ * @label BASE_STOP
141
+ * @param emitter The object to stop listening to. If omitted, stops it for all objects.
142
+ * @param event (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
143
+ * for all events from `emitter`.
144
+ * @param callback (Requires the `event`) The function to be removed from the call list for the given
145
+ * `event`.
146
+ */
147
+ stopListening(emitter?: Emitter, event?: string, callback?: Function): void;
148
+ /**
149
+ * Fires an event, executing all callbacks registered for it.
150
+ *
151
+ * The first parameter passed to callbacks is an {@link module:utils/eventinfo~EventInfo} object,
152
+ * followed by the optional `args` provided in the `fire()` method call.
153
+ *
154
+ * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
155
+ * @param eventOrInfo The name of the event or `EventInfo` object if event is delegated.
156
+ * @param args Additional arguments to be passed to the callbacks.
157
+ * @returns By default the method returns `undefined`. However, the return value can be changed by listeners
158
+ * through modification of the {@link module:utils/eventinfo~EventInfo#return `evt.return`}'s property (the event info
159
+ * is the first param of every callback).
160
+ */
161
+ fire<TEvent extends BaseEvent>(eventOrInfo: GetNameOrEventInfo<TEvent>, ...args: TEvent['args']): GetEventInfo<TEvent>['return'];
162
+ /**
163
+ * Delegates selected events to another {@link module:utils/emittermixin~Emitter}. For instance:
164
+ *
165
+ * ```ts
166
+ * emitterA.delegate( 'eventX' ).to( emitterB );
167
+ * emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
168
+ * ```
169
+ *
170
+ * then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:
171
+ *
172
+ * ```ts
173
+ * emitterA.fire( 'eventX', data );
174
+ * ```
175
+ *
176
+ * and `eventY` is delegated (fired by) `emitterC` along with `data`:
177
+ *
178
+ * ```ts
179
+ * emitterA.fire( 'eventY', data );
180
+ * ```
181
+ *
182
+ * @param events Event names that will be delegated to another emitter.
183
+ */
184
+ delegate(...events: Array<string>): EmitterMixinDelegateChain;
185
+ /**
186
+ * Stops delegating events. It can be used at different levels:
187
+ *
188
+ * * To stop delegating all events.
189
+ * * To stop delegating a specific event to all emitters.
190
+ * * To stop delegating a specific event to a specific emitter.
191
+ *
192
+ * @param event The name of the event to stop delegating. If omitted, stops it all delegations.
193
+ * @param emitter (requires `event`) The object to stop delegating a particular event to.
194
+ * If omitted, stops delegation of `event` to all emitters.
195
+ */
196
+ stopDelegating(event?: string, emitter?: Emitter): void;
197
+ }
198
+ /**
199
+ * Default type describing any event.
200
+ *
201
+ * Every custom event has to be compatible with `BaseEvent`.
202
+ *
203
+ * ```ts
204
+ * type MyEvent = {
205
+ * // In `fire<MyEvent>( name )`, `on<MyEvent>( name )`, `once<MyEvent>( name )` and `listenTo<MyEvent>( name )` calls
206
+ * // the `name` argument will be type-checked to ensure it's `'myEvent'` or have `'myEvent:'` prefix.
207
+ * // Required.
208
+ * name: 'myEvent' | `myEvent:${ string }`;
209
+ *
210
+ * // In `fire<MyEvent>( name, a, b )` call, `a` and `b` parameters will be type-checked against `number` and `string`.
211
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the parameters of provided callback function
212
+ * // will be automatically inferred as `EventInfo`, `number` and `string`.
213
+ * // Required.
214
+ * args: [ number, string ];
215
+ *
216
+ * // `fire<MyEvent>` will have return type `boolean | undefined`.
217
+ * // Optional, unknown by default.
218
+ * return: boolean;
219
+ *
220
+ * // `fire<MyEvent>( eventInfo )` will type-check that `eventInfo` is `MyEventInfo`, not a base `EventInfo` or string.
221
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the first callback parameter will be of this type.
222
+ * // Optional.
223
+ * eventInfo: MyEventInfo;
224
+ *
225
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the `options` parameter will be of type
226
+ * // `{ myOption?: boolean; priority?: PriorityString }
227
+ * // Optional.
228
+ * callbackOptions: { myOption?: boolean };
229
+ * };
230
+ * ```
231
+ */
232
+ export type BaseEvent = {
233
+ name: string;
234
+ args: Array<any>;
235
+ };
236
+ /**
237
+ * Utility type that gets the `EventInfo` subclass for the given event.
238
+ */
239
+ export type GetEventInfo<TEvent extends BaseEvent> = TEvent extends {
240
+ eventInfo: EventInfo;
241
+ } ? TEvent['eventInfo'] : EventInfo<TEvent['name'], (TEvent extends {
242
+ return: infer TReturn;
243
+ } ? TReturn : unknown)>;
244
+ /**
245
+ * Utility type that gets the `EventInfo` subclass or event name type for the given event.
246
+ */
247
+ export type GetNameOrEventInfo<TEvent extends BaseEvent> = TEvent extends {
248
+ eventInfo: EventInfo;
249
+ } ? TEvent['eventInfo'] : TEvent['name'] | EventInfo<TEvent['name'], (TEvent extends {
250
+ return: infer TReturn;
251
+ } ? TReturn : unknown)>;
252
+ /**
253
+ * Utility type that gets the callback type for the given event.
254
+ */
255
+ export type GetCallback<TEvent extends BaseEvent> = (this: Emitter, ev: GetEventInfo<TEvent>, ...args: TEvent['args']) => void;
256
+ /**
257
+ * Utility type that gets the callback options for the given event.
258
+ */
259
+ export type GetCallbackOptions<TEvent extends BaseEvent> = TEvent extends {
260
+ callbackOptions: infer TOptions;
261
+ } ? TOptions & CallbackOptions : CallbackOptions;
262
+ /**
263
+ * Additional options for registering a callback.
264
+ */
265
+ export interface CallbackOptions {
266
+ /**
267
+ * The priority of this event callback. The higher
268
+ * the priority value the sooner the callback will be fired. Events having the same priority are called in the
269
+ * order they were added.
270
+ *
271
+ * @defaultValue `'normal'`
272
+ */
273
+ readonly priority?: PriorityString;
274
+ }
275
+ /**
276
+ * Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter.
277
+ * If not, returns `null`.
278
+ *
279
+ * @internal
280
+ * @param listeningEmitter An emitter that listens.
281
+ * @param listenedToEmitterId Unique emitter id of emitter listened to.
282
+ */
283
+ export declare function _getEmitterListenedTo(listeningEmitter: Emitter, listenedToEmitterId: string): Emitter | null;
284
+ /**
285
+ * Sets emitter's unique id.
286
+ *
287
+ * **Note:** `_emitterId` can be set only once.
288
+ *
289
+ * @internal
290
+ * @param emitter An emitter for which id will be set.
291
+ * @param id Unique id to set. If not passed, random unique id will be set.
292
+ */
293
+ export declare function _setEmitterId(emitter: Emitter, id?: string): void;
294
+ /**
295
+ * Returns emitter's unique id.
296
+ *
297
+ * @internal
298
+ * @param emitter An emitter which id will be returned.
299
+ */
300
+ export declare function _getEmitterId(emitter: Emitter): string | undefined;
301
+ /**
302
+ * The return value of {@link ~Emitter#delegate}.
303
+ */
304
+ export interface EmitterMixinDelegateChain {
305
+ /**
306
+ * Selects destination for {@link module:utils/emittermixin~Emitter#delegate} events.
307
+ *
308
+ * @param emitter An `EmitterMixin` instance which is the destination for delegated events.
309
+ * @param nameOrFunction A custom event name or function which converts the original name string.
310
+ */
311
+ to(emitter: Emitter, nameOrFunction?: string | ((name: string) => string)): void;
312
+ }