@ckeditor/ckeditor5-utils 0.0.0-internal-20241017.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 (213) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +22 -0
  4. package/dist/abortabledebounce.d.ts +21 -0
  5. package/dist/areconnectedthroughproperties.d.ts +15 -0
  6. package/dist/ckeditorerror.d.ts +127 -0
  7. package/dist/collection.d.ts +437 -0
  8. package/dist/comparearrays.d.ts +34 -0
  9. package/dist/config.d.ts +167 -0
  10. package/dist/count.d.ts +22 -0
  11. package/dist/crc32.d.ts +30 -0
  12. package/dist/delay.d.ts +23 -0
  13. package/dist/diff.d.ts +35 -0
  14. package/dist/difftochanges.d.ts +63 -0
  15. package/dist/dom/createelement.d.ts +61 -0
  16. package/dist/dom/emittermixin.d.ts +146 -0
  17. package/dist/dom/findclosestscrollableancestor.d.ts +15 -0
  18. package/dist/dom/getancestors.d.ts +21 -0
  19. package/dist/dom/getborderwidths.d.ts +28 -0
  20. package/dist/dom/getcommonancestor.d.ts +16 -0
  21. package/dist/dom/getdatafromelement.d.ts +18 -0
  22. package/dist/dom/getpositionedancestor.d.ts +14 -0
  23. package/dist/dom/getrangefrommouseevent.d.ts +21 -0
  24. package/dist/dom/global.d.ts +36 -0
  25. package/dist/dom/indexof.d.ts +18 -0
  26. package/dist/dom/insertat.d.ts +19 -0
  27. package/dist/dom/iscomment.d.ts +15 -0
  28. package/dist/dom/isnode.d.ts +15 -0
  29. package/dist/dom/isrange.d.ts +15 -0
  30. package/dist/dom/istext.d.ts +15 -0
  31. package/dist/dom/isvalidattributename.d.ts +14 -0
  32. package/dist/dom/isvisible.d.ts +19 -0
  33. package/dist/dom/iswindow.d.ts +15 -0
  34. package/dist/dom/position.d.ts +215 -0
  35. package/dist/dom/rect.d.ts +199 -0
  36. package/dist/dom/remove.d.ts +17 -0
  37. package/dist/dom/resizeobserver.d.ts +78 -0
  38. package/dist/dom/scroll.d.ts +77 -0
  39. package/dist/dom/setdatainelement.d.ts +18 -0
  40. package/dist/dom/tounit.d.ts +26 -0
  41. package/dist/elementreplacer.d.ts +35 -0
  42. package/dist/emittermixin.d.ts +316 -0
  43. package/dist/env.d.ts +144 -0
  44. package/dist/eventinfo.d.ts +62 -0
  45. package/dist/fastdiff.d.ts +116 -0
  46. package/dist/first.d.ts +15 -0
  47. package/dist/focustracker.d.ts +83 -0
  48. package/dist/index-content.css +4 -0
  49. package/dist/index-editor.css +4 -0
  50. package/dist/index.css +4 -0
  51. package/dist/index.d.ts +70 -0
  52. package/dist/index.js +5871 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/inserttopriorityarray.d.ts +34 -0
  55. package/dist/isiterable.d.ts +18 -0
  56. package/dist/keyboard.d.ts +130 -0
  57. package/dist/keystrokehandler.d.ts +101 -0
  58. package/dist/language.d.ts +21 -0
  59. package/dist/locale.d.ts +145 -0
  60. package/dist/mapsequal.d.ts +19 -0
  61. package/dist/mix.d.ts +89 -0
  62. package/dist/nth.d.ts +20 -0
  63. package/dist/objecttomap.d.ts +27 -0
  64. package/dist/observablemixin.d.ts +564 -0
  65. package/dist/parsebase64encodedobject.d.ts +15 -0
  66. package/dist/priorities.d.ts +37 -0
  67. package/dist/retry.d.ts +37 -0
  68. package/dist/splicearray.d.ts +30 -0
  69. package/dist/spy.d.ts +25 -0
  70. package/dist/toarray.d.ts +29 -0
  71. package/dist/tomap.d.ts +23 -0
  72. package/dist/translation-service.d.ts +178 -0
  73. package/dist/uid.d.ts +19 -0
  74. package/dist/unicode.d.ts +58 -0
  75. package/dist/version.d.ts +14 -0
  76. package/dist/wait.d.ts +20 -0
  77. package/package.json +36 -0
  78. package/src/abortabledebounce.d.ts +17 -0
  79. package/src/abortabledebounce.js +22 -0
  80. package/src/areconnectedthroughproperties.d.ts +11 -0
  81. package/src/areconnectedthroughproperties.js +73 -0
  82. package/src/ckeditorerror.d.ts +123 -0
  83. package/src/ckeditorerror.js +176 -0
  84. package/src/collection.d.ts +433 -0
  85. package/src/collection.js +583 -0
  86. package/src/comparearrays.d.ts +30 -0
  87. package/src/comparearrays.js +47 -0
  88. package/src/config.d.ts +163 -0
  89. package/src/config.js +163 -0
  90. package/src/count.d.ts +18 -0
  91. package/src/count.js +25 -0
  92. package/src/crc32.d.ts +26 -0
  93. package/src/crc32.js +61 -0
  94. package/src/delay.d.ts +19 -0
  95. package/src/delay.js +26 -0
  96. package/src/diff.d.ts +31 -0
  97. package/src/diff.js +115 -0
  98. package/src/difftochanges.d.ts +59 -0
  99. package/src/difftochanges.js +79 -0
  100. package/src/dom/createelement.d.ts +57 -0
  101. package/src/dom/createelement.js +40 -0
  102. package/src/dom/emittermixin.d.ts +142 -0
  103. package/src/dom/emittermixin.js +239 -0
  104. package/src/dom/findclosestscrollableancestor.d.ts +11 -0
  105. package/src/dom/findclosestscrollableancestor.js +31 -0
  106. package/src/dom/getancestors.d.ts +17 -0
  107. package/src/dom/getancestors.js +27 -0
  108. package/src/dom/getborderwidths.d.ts +24 -0
  109. package/src/dom/getborderwidths.js +24 -0
  110. package/src/dom/getcommonancestor.d.ts +12 -0
  111. package/src/dom/getcommonancestor.js +25 -0
  112. package/src/dom/getdatafromelement.d.ts +14 -0
  113. package/src/dom/getdatafromelement.js +20 -0
  114. package/src/dom/getpositionedancestor.d.ts +10 -0
  115. package/src/dom/getpositionedancestor.js +22 -0
  116. package/src/dom/getrangefrommouseevent.d.ts +17 -0
  117. package/src/dom/getrangefrommouseevent.js +33 -0
  118. package/src/dom/global.d.ts +32 -0
  119. package/src/dom/global.js +35 -0
  120. package/src/dom/indexof.d.ts +14 -0
  121. package/src/dom/indexof.js +21 -0
  122. package/src/dom/insertat.d.ts +15 -0
  123. package/src/dom/insertat.js +17 -0
  124. package/src/dom/iscomment.d.ts +11 -0
  125. package/src/dom/iscomment.js +14 -0
  126. package/src/dom/isnode.d.ts +11 -0
  127. package/src/dom/isnode.js +21 -0
  128. package/src/dom/isrange.d.ts +11 -0
  129. package/src/dom/isrange.js +13 -0
  130. package/src/dom/istext.d.ts +11 -0
  131. package/src/dom/istext.js +13 -0
  132. package/src/dom/isvalidattributename.d.ts +10 -0
  133. package/src/dom/isvalidattributename.js +22 -0
  134. package/src/dom/isvisible.d.ts +15 -0
  135. package/src/dom/isvisible.js +30 -0
  136. package/src/dom/iswindow.d.ts +11 -0
  137. package/src/dom/iswindow.js +22 -0
  138. package/src/dom/position.d.ts +211 -0
  139. package/src/dom/position.js +313 -0
  140. package/src/dom/rect.d.ts +195 -0
  141. package/src/dom/rect.js +474 -0
  142. package/src/dom/remove.d.ts +13 -0
  143. package/src/dom/remove.js +18 -0
  144. package/src/dom/resizeobserver.d.ts +74 -0
  145. package/src/dom/resizeobserver.js +127 -0
  146. package/src/dom/scroll.d.ts +73 -0
  147. package/src/dom/scroll.js +383 -0
  148. package/src/dom/setdatainelement.d.ts +14 -0
  149. package/src/dom/setdatainelement.js +20 -0
  150. package/src/dom/tounit.d.ts +22 -0
  151. package/src/dom/tounit.js +16 -0
  152. package/src/elementreplacer.d.ts +31 -0
  153. package/src/elementreplacer.js +43 -0
  154. package/src/emittermixin.d.ts +312 -0
  155. package/src/emittermixin.js +453 -0
  156. package/src/env.d.ts +140 -0
  157. package/src/env.js +145 -0
  158. package/src/eventinfo.d.ts +58 -0
  159. package/src/eventinfo.js +26 -0
  160. package/src/fastdiff.d.ts +112 -0
  161. package/src/fastdiff.js +248 -0
  162. package/src/first.d.ts +11 -0
  163. package/src/first.js +17 -0
  164. package/src/focustracker.d.ts +79 -0
  165. package/src/focustracker.js +101 -0
  166. package/src/index.d.ts +66 -0
  167. package/src/index.js +65 -0
  168. package/src/inserttopriorityarray.d.ts +30 -0
  169. package/src/inserttopriorityarray.js +21 -0
  170. package/src/isiterable.d.ts +14 -0
  171. package/src/isiterable.js +16 -0
  172. package/src/keyboard.d.ts +126 -0
  173. package/src/keyboard.js +252 -0
  174. package/src/keystrokehandler.d.ts +97 -0
  175. package/src/keystrokehandler.js +122 -0
  176. package/src/language.d.ts +17 -0
  177. package/src/language.js +20 -0
  178. package/src/locale.d.ts +141 -0
  179. package/src/locale.js +78 -0
  180. package/src/mapsequal.d.ts +15 -0
  181. package/src/mapsequal.js +27 -0
  182. package/src/mix.d.ts +85 -0
  183. package/src/mix.js +50 -0
  184. package/src/nth.d.ts +16 -0
  185. package/src/nth.js +24 -0
  186. package/src/objecttomap.d.ts +23 -0
  187. package/src/objecttomap.js +27 -0
  188. package/src/observablemixin.d.ts +560 -0
  189. package/src/observablemixin.js +580 -0
  190. package/src/parsebase64encodedobject.d.ts +11 -0
  191. package/src/parsebase64encodedobject.js +22 -0
  192. package/src/priorities.d.ts +33 -0
  193. package/src/priorities.js +23 -0
  194. package/src/retry.d.ts +33 -0
  195. package/src/retry.js +47 -0
  196. package/src/splicearray.d.ts +26 -0
  197. package/src/splicearray.js +40 -0
  198. package/src/spy.d.ts +21 -0
  199. package/src/spy.js +22 -0
  200. package/src/toarray.d.ts +25 -0
  201. package/src/toarray.js +7 -0
  202. package/src/tomap.d.ts +19 -0
  203. package/src/tomap.js +29 -0
  204. package/src/translation-service.d.ts +174 -0
  205. package/src/translation-service.js +209 -0
  206. package/src/uid.d.ts +15 -0
  207. package/src/uid.js +45 -0
  208. package/src/unicode.d.ts +54 -0
  209. package/src/unicode.js +85 -0
  210. package/src/version.d.ts +10 -0
  211. package/src/version.js +179 -0
  212. package/src/wait.d.ts +16 -0
  213. package/src/wait.js +29 -0
@@ -0,0 +1,78 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * A helper class which instances allow performing custom actions when native DOM elements are resized.
11
+ *
12
+ * ```ts
13
+ * const editableElement = editor.editing.view.getDomRoot();
14
+ *
15
+ * const observer = new ResizeObserver( editableElement, entry => {
16
+ * console.log( 'The editable element has been resized in DOM.' );
17
+ * console.log( entry.target ); // -> editableElement
18
+ * console.log( entry.contentRect.width ); // -> e.g. '423px'
19
+ * } );
20
+ * ```
21
+ *
22
+ * It uses the [native DOM resize observer](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
23
+ * under the hood.
24
+ */
25
+ export default class ResizeObserver {
26
+ /**
27
+ * The element observed by this observer.
28
+ */
29
+ private readonly _element;
30
+ /**
31
+ * The callback executed each time {@link #_element} is resized.
32
+ */
33
+ private readonly _callback;
34
+ /**
35
+ * The single native observer instance shared across all {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
36
+ */
37
+ private static _observerInstance;
38
+ /**
39
+ * A mapping of native DOM elements and their callbacks shared across all
40
+ * {@link module:utils/dom/resizeobserver~ResizeObserver} instances.
41
+ */
42
+ private static _elementCallbacks;
43
+ /**
44
+ * Creates an instance of the `ResizeObserver` class.
45
+ *
46
+ * @param element A DOM element that is to be observed for resizing. Note that
47
+ * the element must be visible (i.e. not detached from DOM) for the observer to work.
48
+ * @param callback A function called when the observed element was resized. It passes
49
+ * the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
50
+ * object with information about the resize event.
51
+ */
52
+ constructor(element: Element, callback: (entry: ResizeObserverEntry) => void);
53
+ /**
54
+ * The element observed by this observer.
55
+ */
56
+ get element(): Element;
57
+ /**
58
+ * Destroys the observer which disables the `callback` passed to the {@link #constructor}.
59
+ */
60
+ destroy(): void;
61
+ /**
62
+ * Registers a new resize callback for the DOM element.
63
+ */
64
+ private static _addElementCallback;
65
+ /**
66
+ * Removes a resize callback from the DOM element. If no callbacks are left
67
+ * for the element, it removes the element from the native observer.
68
+ */
69
+ private static _deleteElementCallback;
70
+ /**
71
+ * Returns are registered resize callbacks for the DOM element.
72
+ */
73
+ private static _getElementCallbacks;
74
+ /**
75
+ * Creates the single native observer shared across all `ResizeObserver` instances.
76
+ */
77
+ private static _createObserver;
78
+ }
@@ -0,0 +1,77 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ type IfTrue<T> = T extends true ? true : never;
10
+ /**
11
+ * Makes any page `HTMLElement` or `Range` (`target`) visible inside the browser viewport.
12
+ * This helper will scroll all `target` ancestors and the web browser viewport to reveal the target to
13
+ * the user. If the `target` is already visible, nothing will happen.
14
+ *
15
+ * @param options Additional configuration of the scrolling behavior.
16
+ * @param options.target A target, which supposed to become visible to the user.
17
+ * @param options.viewportOffset An offset from the edge of the viewport (in pixels)
18
+ * the `target` will be moved by if the viewport is scrolled. It enhances the user experience
19
+ * by keeping the `target` some distance from the edge of the viewport and thus making it easier to
20
+ * read or edit by the user.
21
+ * @param options.ancestorOffset An offset from the boundary of scrollable ancestors (if any)
22
+ * the `target` will be moved by if the viewport is scrolled. It enhances the user experience
23
+ * by keeping the `target` some distance from the edge of the ancestors and thus making it easier to
24
+ * read or edit by the user.
25
+ * @param options.alignToTop When set `true`, the helper will make sure the `target` is scrolled up
26
+ * to the top boundary of the viewport and/or scrollable ancestors if scrolled up. When not set
27
+ * (default), the `target` will be revealed by scrolling as little as possible. This option will
28
+ * not affect `targets` that must be scrolled down because they will appear at the top of the boundary
29
+ * anyway.
30
+ *
31
+ * ```
32
+ * scrollViewportToShowTarget() with scrollViewportToShowTarget() with
33
+ * Initial state alignToTop unset (default) alignToTop = true
34
+ *
35
+ * ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐ ┌────────────────────────────────┬─┐
36
+ * │ │▲│ │ │▲│ │ [ Target to be revealed ] │▲│
37
+ * │ │ │ │ │ │ │ │ │
38
+ * │ │█│ │ │ │ │ │ │
39
+ * │ │█│ │ │ │ │ │ │
40
+ * │ │ │ │ │█│ │ │ │
41
+ * │ │ │ │ │█│ │ │█│
42
+ * │ │ │ │ │ │ │ │█│
43
+ * │ │▼│ │ [ Target to be revealed ] │▼│ │ │▼│
44
+ * └────────────────────────────────┴─┘ └────────────────────────────────┴─┘ └────────────────────────────────┴─┘
45
+ *
46
+ *
47
+ * [ Target to be revealed ]
48
+ *```
49
+ *
50
+ * @param options.forceScroll When set `true`, the `target` will be aligned to the top of the viewport
51
+ * and scrollable ancestors whether it is already visible or not. This option will only work when `alignToTop`
52
+ * is `true`
53
+ */
54
+ export declare function scrollViewportToShowTarget<T extends boolean, U extends IfTrue<T>>({ target, viewportOffset, ancestorOffset, alignToTop, forceScroll }: {
55
+ readonly target: HTMLElement | Range;
56
+ readonly viewportOffset?: number | {
57
+ top: number;
58
+ bottom: number;
59
+ left: number;
60
+ right: number;
61
+ };
62
+ readonly ancestorOffset?: number;
63
+ readonly alignToTop?: T;
64
+ readonly forceScroll?: U;
65
+ }): void;
66
+ /**
67
+ * Makes any page `HTMLElement` or `Range` (target) visible within its scrollable ancestors,
68
+ * e.g. if they have `overflow: scroll` CSS style.
69
+ *
70
+ * @param target A target, which supposed to become visible to the user.
71
+ * @param ancestorOffset An offset between the target and the boundary of scrollable ancestors
72
+ * to be maintained while scrolling.
73
+ * @param limiterElement The outermost ancestor that should be scrolled. If specified, it can prevent
74
+ * scrolling the whole page.
75
+ */
76
+ export declare function scrollAncestorsToShowTarget(target: HTMLElement | Range, ancestorOffset?: number, limiterElement?: HTMLElement): void;
77
+ export {};
@@ -0,0 +1,18 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/dom/setdatainelement
11
+ */
12
+ /**
13
+ * Sets data in a given element.
14
+ *
15
+ * @param el The element in which the data will be set.
16
+ * @param data The data string.
17
+ */
18
+ export default function setDataInElement(el: HTMLElement, data: string): void;
@@ -0,0 +1,26 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/dom/tounit
11
+ */
12
+ /**
13
+ * Returns a helper function, which adds a desired trailing
14
+ * `unit` to the passed value.
15
+ *
16
+ * @param unit An unit like "px" or "em".
17
+ */
18
+ export default function toUnit(unit: string): ToUnitHelper;
19
+ /**
20
+ * A function, which adds a pre–defined trailing `unit`
21
+ * to the passed `value`.
22
+ *
23
+ * @param value A value to be given the unit.
24
+ * @returns A value with the trailing unit.
25
+ */
26
+ export type ToUnitHelper = (value: string | number) => string;
@@ -0,0 +1,35 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/elementreplacer
11
+ */
12
+ /**
13
+ * Utility class allowing to hide existing HTML elements or replace them with given ones in a way that doesn't remove
14
+ * the original elements from the DOM.
15
+ */
16
+ export default class ElementReplacer {
17
+ /**
18
+ * The elements replaced by {@link #replace} and their replacements.
19
+ */
20
+ private _replacedElements;
21
+ constructor();
22
+ /**
23
+ * Hides the `element` and, if specified, inserts the the given element next to it.
24
+ *
25
+ * The effect of this method can be reverted by {@link #restore}.
26
+ *
27
+ * @param element The element to replace.
28
+ * @param newElement The replacement element. If not passed, then the `element` will just be hidden.
29
+ */
30
+ replace(element: HTMLElement, newElement?: HTMLElement): void;
31
+ /**
32
+ * Restores what {@link #replace} did.
33
+ */
34
+ restore(): void;
35
+ }
@@ -0,0 +1,316 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/emittermixin
11
+ */
12
+ import EventInfo from './eventinfo.js';
13
+ import { type PriorityString } from './priorities.js';
14
+ import type { Constructor, Mixed } from './mix.js';
15
+ import './version.js';
16
+ /**
17
+ * Mixin that injects the {@link ~Emitter events API} into its host.
18
+ *
19
+ * This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
20
+ *
21
+ * ```ts
22
+ * class BaseClass { ... }
23
+ *
24
+ * class MyClass extends EmitterMixin( BaseClass ) {
25
+ * // This class derives from `BaseClass` and implements the `Emitter` interface.
26
+ * }
27
+ * ```
28
+ *
29
+ * Read more about the concept of emitters in the:
30
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
31
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
32
+ * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
33
+ *
34
+ * @label EXTENDS
35
+ */
36
+ export default function EmitterMixin<Base extends Constructor>(base: Base): Mixed<Base, Emitter>;
37
+ /**
38
+ * Mixin that injects the {@link ~Emitter events API} into its host.
39
+ *
40
+ * This function creates a class that implements `Emitter` interface.
41
+ *
42
+ * ```ts
43
+ * class MyClass extends EmitterMixin() {
44
+ * // This class implements the `Emitter` interface.
45
+ * }
46
+ * ```
47
+ *
48
+ * Read more about the concept of emitters in the:
49
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
50
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
51
+ * * {@glink framework/deep-dive/event-system Event system} deep dive guide.
52
+ *
53
+ * @label NO_ARGUMENTS
54
+ */
55
+ export default function EmitterMixin(): {
56
+ new (): Emitter;
57
+ prototype: Emitter;
58
+ };
59
+ /**
60
+ * Emitter/listener interface.
61
+ *
62
+ * Can be easily implemented by a class by mixing the {@link module:utils/emittermixin~Emitter} mixin.
63
+ *
64
+ * ```ts
65
+ * class MyClass extends EmitterMixin() {
66
+ * // This class now implements the `Emitter` interface.
67
+ * }
68
+ * ```
69
+ *
70
+ * Read more about the usage of this interface in the:
71
+ * * {@glink framework/architecture/core-editor-architecture#event-system-and-observables Event system and observables}
72
+ * section of the {@glink framework/architecture/core-editor-architecture Core editor architecture} guide.
73
+ * * {@glink framework/deep-dive/event-system Event system} deep-dive guide.
74
+ */
75
+ export interface Emitter {
76
+ /**
77
+ * Registers a callback function to be executed when an event is fired.
78
+ *
79
+ * Shorthand for {@link #listenTo `this.listenTo( this, event, callback, options )`} (it makes the emitter
80
+ * listen on itself).
81
+ *
82
+ * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
83
+ * @param event The name of the event.
84
+ * @param callback The function to be called on event.
85
+ * @param options Additional options.
86
+ */
87
+ on<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
88
+ /**
89
+ * Registers a callback function to be executed on the next time the event is fired only. This is similar to
90
+ * calling {@link #on} followed by {@link #off} in the callback.
91
+ *
92
+ * @typeParam TEvent The type descibing the event. See {@link module:utils/emittermixin~BaseEvent}.
93
+ * @param event The name of the event.
94
+ * @param callback The function to be called on event.
95
+ * @param options Additional options.
96
+ */
97
+ once<TEvent extends BaseEvent>(event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
98
+ /**
99
+ * Stops executing the callback on the given event.
100
+ * Shorthand for {@link #stopListening `this.stopListening( this, event, callback )`}.
101
+ *
102
+ * @param event The name of the event.
103
+ * @param callback The function to stop being called.
104
+ */
105
+ off(event: string, callback: Function): void;
106
+ /**
107
+ * Registers a callback function to be executed when an event is fired in a specific (emitter) object.
108
+ *
109
+ * Events can be grouped in namespaces using `:`.
110
+ * When namespaced event is fired, it additionally fires all callbacks for that namespace.
111
+ *
112
+ * ```ts
113
+ * // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
114
+ * myEmitter.on( 'myGroup', genericCallback );
115
+ * myEmitter.on( 'myGroup:myEvent', specificCallback );
116
+ *
117
+ * // genericCallback is fired.
118
+ * myEmitter.fire( 'myGroup' );
119
+ * // both genericCallback and specificCallback are fired.
120
+ * myEmitter.fire( 'myGroup:myEvent' );
121
+ * // genericCallback is fired even though there are no callbacks for "foo".
122
+ * myEmitter.fire( 'myGroup:foo' );
123
+ * ```
124
+ *
125
+ * An event callback can {@link module:utils/eventinfo~EventInfo#stop stop the event} and
126
+ * set the {@link module:utils/eventinfo~EventInfo#return return value} of the {@link #fire} method.
127
+ *
128
+ * @label BASE_EMITTER
129
+ * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
130
+ * @param emitter The object that fires the event.
131
+ * @param event The name of the event.
132
+ * @param callback The function to be called on event.
133
+ * @param options Additional options.
134
+ */
135
+ listenTo<TEvent extends BaseEvent>(emitter: Emitter, event: TEvent['name'], callback: GetCallback<TEvent>, options?: GetCallbackOptions<TEvent>): void;
136
+ /**
137
+ * Stops listening for events. It can be used at different levels:
138
+ *
139
+ * * To stop listening to a specific callback.
140
+ * * To stop listening to a specific event.
141
+ * * To stop listening to all events fired by a specific object.
142
+ * * To stop listening to all events fired by all objects.
143
+ *
144
+ * @label BASE_STOP
145
+ * @param emitter The object to stop listening to. If omitted, stops it for all objects.
146
+ * @param event (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
147
+ * for all events from `emitter`.
148
+ * @param callback (Requires the `event`) The function to be removed from the call list for the given
149
+ * `event`.
150
+ */
151
+ stopListening(emitter?: Emitter, event?: string, callback?: Function): void;
152
+ /**
153
+ * Fires an event, executing all callbacks registered for it.
154
+ *
155
+ * The first parameter passed to callbacks is an {@link module:utils/eventinfo~EventInfo} object,
156
+ * followed by the optional `args` provided in the `fire()` method call.
157
+ *
158
+ * @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
159
+ * @param eventOrInfo The name of the event or `EventInfo` object if event is delegated.
160
+ * @param args Additional arguments to be passed to the callbacks.
161
+ * @returns By default the method returns `undefined`. However, the return value can be changed by listeners
162
+ * through modification of the {@link module:utils/eventinfo~EventInfo#return `evt.return`}'s property (the event info
163
+ * is the first param of every callback).
164
+ */
165
+ fire<TEvent extends BaseEvent>(eventOrInfo: GetNameOrEventInfo<TEvent>, ...args: TEvent['args']): GetEventInfo<TEvent>['return'];
166
+ /**
167
+ * Delegates selected events to another {@link module:utils/emittermixin~Emitter}. For instance:
168
+ *
169
+ * ```ts
170
+ * emitterA.delegate( 'eventX' ).to( emitterB );
171
+ * emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );
172
+ * ```
173
+ *
174
+ * then `eventX` is delegated (fired by) `emitterB` and `emitterC` along with `data`:
175
+ *
176
+ * ```ts
177
+ * emitterA.fire( 'eventX', data );
178
+ * ```
179
+ *
180
+ * and `eventY` is delegated (fired by) `emitterC` along with `data`:
181
+ *
182
+ * ```ts
183
+ * emitterA.fire( 'eventY', data );
184
+ * ```
185
+ *
186
+ * @param events Event names that will be delegated to another emitter.
187
+ */
188
+ delegate(...events: Array<string>): EmitterMixinDelegateChain;
189
+ /**
190
+ * Stops delegating events. It can be used at different levels:
191
+ *
192
+ * * To stop delegating all events.
193
+ * * To stop delegating a specific event to all emitters.
194
+ * * To stop delegating a specific event to a specific emitter.
195
+ *
196
+ * @param event The name of the event to stop delegating. If omitted, stops it all delegations.
197
+ * @param emitter (requires `event`) The object to stop delegating a particular event to.
198
+ * If omitted, stops delegation of `event` to all emitters.
199
+ */
200
+ stopDelegating(event?: string, emitter?: Emitter): void;
201
+ }
202
+ /**
203
+ * Default type describing any event.
204
+ *
205
+ * Every custom event has to be compatible with `BaseEvent`.
206
+ *
207
+ * ```ts
208
+ * type MyEvent = {
209
+ * // In `fire<MyEvent>( name )`, `on<MyEvent>( name )`, `once<MyEvent>( name )` and `listenTo<MyEvent>( name )` calls
210
+ * // the `name` argument will be type-checked to ensure it's `'myEvent'` or have `'myEvent:'` prefix.
211
+ * // Required.
212
+ * name: 'myEvent' | `myEvent:${ string }`;
213
+ *
214
+ * // In `fire<MyEvent>( name, a, b )` call, `a` and `b` parameters will be type-checked against `number` and `string`.
215
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the parameters of provided callback function
216
+ * // will be automatically inferred as `EventInfo`, `number` and `string`.
217
+ * // Required.
218
+ * args: [ number, string ];
219
+ *
220
+ * // `fire<MyEvent>` will have return type `boolean | undefined`.
221
+ * // Optional, unknown by default.
222
+ * return: boolean;
223
+ *
224
+ * // `fire<MyEvent>( eventInfo )` will type-check that `eventInfo` is `MyEventInfo`, not a base `EventInfo` or string.
225
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the first callback parameter will be of this type.
226
+ * // Optional.
227
+ * eventInfo: MyEventInfo;
228
+ *
229
+ * // In `on<MyEvent>`, `once<MyEvent>` and `listenTo<MyEvent>` calls, the `options` parameter will be of type
230
+ * // `{ myOption?: boolean; priority?: PriorityString }
231
+ * // Optional.
232
+ * callbackOptions: { myOption?: boolean };
233
+ * };
234
+ * ```
235
+ */
236
+ export type BaseEvent = {
237
+ name: string;
238
+ args: Array<any>;
239
+ };
240
+ /**
241
+ * Utility type that gets the `EventInfo` subclass for the given event.
242
+ */
243
+ export type GetEventInfo<TEvent extends BaseEvent> = TEvent extends {
244
+ eventInfo: EventInfo;
245
+ } ? TEvent['eventInfo'] : EventInfo<TEvent['name'], (TEvent extends {
246
+ return: infer TReturn;
247
+ } ? TReturn : unknown)>;
248
+ /**
249
+ * Utility type that gets the `EventInfo` subclass or event name type for the given event.
250
+ */
251
+ export type GetNameOrEventInfo<TEvent extends BaseEvent> = TEvent extends {
252
+ eventInfo: EventInfo;
253
+ } ? TEvent['eventInfo'] : TEvent['name'] | EventInfo<TEvent['name'], (TEvent extends {
254
+ return: infer TReturn;
255
+ } ? TReturn : unknown)>;
256
+ /**
257
+ * Utility type that gets the callback type for the given event.
258
+ */
259
+ export type GetCallback<TEvent extends BaseEvent> = (this: Emitter, ev: GetEventInfo<TEvent>, ...args: TEvent['args']) => void;
260
+ /**
261
+ * Utility type that gets the callback options for the given event.
262
+ */
263
+ export type GetCallbackOptions<TEvent extends BaseEvent> = TEvent extends {
264
+ callbackOptions: infer TOptions;
265
+ } ? TOptions & CallbackOptions : CallbackOptions;
266
+ /**
267
+ * Additional options for registering a callback.
268
+ */
269
+ export interface CallbackOptions {
270
+ /**
271
+ * The priority of this event callback. The higher
272
+ * the priority value the sooner the callback will be fired. Events having the same priority are called in the
273
+ * order they were added.
274
+ *
275
+ * @defaultValue `'normal'`
276
+ */
277
+ readonly priority?: PriorityString;
278
+ }
279
+ /**
280
+ * Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter.
281
+ * If not, returns `null`.
282
+ *
283
+ * @internal
284
+ * @param listeningEmitter An emitter that listens.
285
+ * @param listenedToEmitterId Unique emitter id of emitter listened to.
286
+ */
287
+ export declare function _getEmitterListenedTo(listeningEmitter: Emitter, listenedToEmitterId: string): Emitter | null;
288
+ /**
289
+ * Sets emitter's unique id.
290
+ *
291
+ * **Note:** `_emitterId` can be set only once.
292
+ *
293
+ * @internal
294
+ * @param emitter An emitter for which id will be set.
295
+ * @param id Unique id to set. If not passed, random unique id will be set.
296
+ */
297
+ export declare function _setEmitterId(emitter: Emitter, id?: string): void;
298
+ /**
299
+ * Returns emitter's unique id.
300
+ *
301
+ * @internal
302
+ * @param emitter An emitter which id will be returned.
303
+ */
304
+ export declare function _getEmitterId(emitter: Emitter): string | undefined;
305
+ /**
306
+ * The return value of {@link ~Emitter#delegate}.
307
+ */
308
+ export interface EmitterMixinDelegateChain {
309
+ /**
310
+ * Selects destination for {@link module:utils/emittermixin~Emitter#delegate} events.
311
+ *
312
+ * @param emitter An `EmitterMixin` instance which is the destination for delegated events.
313
+ * @param nameOrFunction A custom event name or function which converts the original name string.
314
+ */
315
+ to(emitter: Emitter, nameOrFunction?: string | ((name: string) => string)): void;
316
+ }