@ckeditor/ckeditor5-utils 41.3.1 → 41.4.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.
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +4 -0
- package/dist/index.js +5491 -0
- package/dist/index.js.map +1 -0
- package/dist/types/abortabledebounce.d.ts +21 -0
- package/dist/types/areconnectedthroughproperties.d.ts +15 -0
- package/dist/types/ckeditorerror.d.ts +127 -0
- package/dist/types/collection.d.ts +437 -0
- package/dist/types/comparearrays.d.ts +34 -0
- package/dist/types/config.d.ts +167 -0
- package/dist/types/count.d.ts +22 -0
- package/dist/types/delay.d.ts +23 -0
- package/dist/types/diff.d.ts +35 -0
- package/dist/types/difftochanges.d.ts +63 -0
- package/dist/types/dom/createelement.d.ts +61 -0
- package/dist/types/dom/emittermixin.d.ts +146 -0
- package/dist/types/dom/findclosestscrollableancestor.d.ts +15 -0
- package/dist/types/dom/getancestors.d.ts +21 -0
- package/dist/types/dom/getborderwidths.d.ts +28 -0
- package/dist/types/dom/getcommonancestor.d.ts +16 -0
- package/dist/types/dom/getdatafromelement.d.ts +18 -0
- package/dist/types/dom/getpositionedancestor.d.ts +14 -0
- package/dist/types/dom/global.d.ts +36 -0
- package/dist/types/dom/indexof.d.ts +18 -0
- package/dist/types/dom/insertat.d.ts +19 -0
- package/dist/types/dom/iscomment.d.ts +15 -0
- package/dist/types/dom/isnode.d.ts +15 -0
- package/dist/types/dom/isrange.d.ts +15 -0
- package/dist/types/dom/istext.d.ts +15 -0
- package/dist/types/dom/isvalidattributename.d.ts +14 -0
- package/dist/types/dom/isvisible.d.ts +22 -0
- package/dist/types/dom/iswindow.d.ts +15 -0
- package/dist/types/dom/position.d.ts +215 -0
- package/dist/types/dom/rect.d.ts +199 -0
- package/dist/types/dom/remove.d.ts +17 -0
- package/dist/types/dom/resizeobserver.d.ts +78 -0
- package/dist/types/dom/scroll.d.ts +77 -0
- package/dist/types/dom/setdatainelement.d.ts +18 -0
- package/dist/types/dom/tounit.d.ts +26 -0
- package/dist/types/elementreplacer.d.ts +35 -0
- package/dist/types/emittermixin.d.ts +316 -0
- package/dist/types/env.d.ts +137 -0
- package/dist/types/eventinfo.d.ts +62 -0
- package/dist/types/fastdiff.d.ts +116 -0
- package/dist/types/first.d.ts +15 -0
- package/dist/types/focustracker.d.ts +79 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/inserttopriorityarray.d.ts +34 -0
- package/dist/types/isiterable.d.ts +18 -0
- package/dist/types/keyboard.d.ts +130 -0
- package/dist/types/keystrokehandler.d.ts +91 -0
- package/dist/types/language.d.ts +21 -0
- package/dist/types/locale.d.ts +145 -0
- package/dist/types/mapsequal.d.ts +19 -0
- package/dist/types/mix.d.ts +89 -0
- package/dist/types/nth.d.ts +20 -0
- package/dist/types/objecttomap.d.ts +27 -0
- package/dist/types/observablemixin.d.ts +564 -0
- package/dist/types/priorities.d.ts +37 -0
- package/dist/types/retry.d.ts +37 -0
- package/dist/types/splicearray.d.ts +30 -0
- package/dist/types/spy.d.ts +25 -0
- package/dist/types/toarray.d.ts +29 -0
- package/dist/types/tomap.d.ts +23 -0
- package/dist/types/translation-service.d.ts +178 -0
- package/dist/types/uid.d.ts +19 -0
- package/dist/types/unicode.d.ts +58 -0
- package/dist/types/verifylicense.d.ts +19 -0
- package/dist/types/version.d.ts +14 -0
- package/dist/types/wait.d.ts +20 -0
- package/package.json +2 -1
- package/src/env.d.ts +16 -0
- package/src/env.js +16 -0
- package/src/locale.d.ts +1 -1
- package/src/version.d.ts +1 -1
- package/src/version.js +2 -2
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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/env
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Safely returns `userAgent` from browser's navigator API in a lower case.
|
|
14
|
+
* If navigator API is not available it will return an empty string.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getUserAgent(): string;
|
|
17
|
+
/**
|
|
18
|
+
* A namespace containing environment and browser information.
|
|
19
|
+
*/
|
|
20
|
+
export interface EnvType {
|
|
21
|
+
/**
|
|
22
|
+
* Indicates that the application is running on Macintosh.
|
|
23
|
+
*/
|
|
24
|
+
readonly isMac: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Indicates that the application is running on Windows.
|
|
27
|
+
*/
|
|
28
|
+
readonly isWindows: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Indicates that the application is running in Firefox (Gecko).
|
|
31
|
+
*/
|
|
32
|
+
readonly isGecko: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Indicates that the application is running in Safari.
|
|
35
|
+
*/
|
|
36
|
+
readonly isSafari: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Indicates the the application is running in iOS.
|
|
39
|
+
*/
|
|
40
|
+
readonly isiOS: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Indicates that the application is running on Android mobile device.
|
|
43
|
+
*/
|
|
44
|
+
readonly isAndroid: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Indicates that the application is running in a browser using the Blink engine.
|
|
47
|
+
*/
|
|
48
|
+
readonly isBlink: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Indicates that the the user agent has enabled a forced colors mode (e.g. Windows High Contrast mode).
|
|
51
|
+
*/
|
|
52
|
+
readonly isMediaForcedColors: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Indicates that "prefer reduced motion" browser setting is active.
|
|
55
|
+
*/
|
|
56
|
+
readonly isMotionReduced: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Environment features information.
|
|
59
|
+
*/
|
|
60
|
+
readonly features: EnvFeaturesType;
|
|
61
|
+
}
|
|
62
|
+
export interface EnvFeaturesType {
|
|
63
|
+
/**
|
|
64
|
+
* Indicates that the environment supports ES2018 Unicode property escapes — like `\p{P}` or `\p{L}`.
|
|
65
|
+
* More information about unicode properties might be found
|
|
66
|
+
* [in Unicode Standard Annex #44](https://www.unicode.org/reports/tr44/#GC_Values_Table).
|
|
67
|
+
*/
|
|
68
|
+
readonly isRegExpUnicodePropertySupported: boolean;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A namespace containing environment and browser information.
|
|
72
|
+
*/
|
|
73
|
+
declare const env: EnvType;
|
|
74
|
+
export default env;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if User Agent represented by the string is running on Macintosh.
|
|
77
|
+
*
|
|
78
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
79
|
+
* @returns Whether User Agent is running on Macintosh or not.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isMac(userAgent: string): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if User Agent represented by the string is running on Windows.
|
|
84
|
+
*
|
|
85
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
86
|
+
* @returns Whether User Agent is running on Windows or not.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isWindows(userAgent: string): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if User Agent represented by the string is Firefox (Gecko).
|
|
91
|
+
*
|
|
92
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
93
|
+
* @returns Whether User Agent is Firefox or not.
|
|
94
|
+
*/
|
|
95
|
+
export declare function isGecko(userAgent: string): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Checks if User Agent represented by the string is Safari.
|
|
98
|
+
*
|
|
99
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
100
|
+
* @returns Whether User Agent is Safari or not.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isSafari(userAgent: string): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if User Agent represented by the string is running in iOS.
|
|
105
|
+
*
|
|
106
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
107
|
+
* @returns Whether User Agent is running in iOS or not.
|
|
108
|
+
*/
|
|
109
|
+
export declare function isiOS(userAgent: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Checks if User Agent represented by the string is Android mobile device.
|
|
112
|
+
*
|
|
113
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
114
|
+
* @returns Whether User Agent is Safari or not.
|
|
115
|
+
*/
|
|
116
|
+
export declare function isAndroid(userAgent: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Checks if User Agent represented by the string is Blink engine.
|
|
119
|
+
*
|
|
120
|
+
* @param userAgent **Lowercase** `navigator.userAgent` string.
|
|
121
|
+
* @returns Whether User Agent is Blink engine or not.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isBlink(userAgent: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Checks if the current environment supports ES2018 Unicode properties like `\p{P}` or `\p{L}`.
|
|
126
|
+
* More information about unicode properties might be found
|
|
127
|
+
* [in Unicode Standard Annex #44](https://www.unicode.org/reports/tr44/#GC_Values_Table).
|
|
128
|
+
*/
|
|
129
|
+
export declare function isRegExpUnicodePropertySupported(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Checks if the user agent has enabled a forced colors mode (e.g. Windows High Contrast mode).
|
|
132
|
+
*/
|
|
133
|
+
export declare function isMediaForcedColors(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Checks if user enabled "prefers reduced motion" setting in browser.
|
|
136
|
+
*/
|
|
137
|
+
export declare function isMotionReduced(): boolean;
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
* The event object passed to event callbacks. It is used to provide information about the event as well as a tool to
|
|
11
|
+
* manipulate it.
|
|
12
|
+
*/
|
|
13
|
+
export default class EventInfo<TName extends string = string, TReturn = unknown> {
|
|
14
|
+
/**
|
|
15
|
+
* The object that fired the event.
|
|
16
|
+
*/
|
|
17
|
+
readonly source: object;
|
|
18
|
+
/**
|
|
19
|
+
* The event name.
|
|
20
|
+
*/
|
|
21
|
+
readonly name: TName;
|
|
22
|
+
/**
|
|
23
|
+
* Path this event has followed. See {@link module:utils/emittermixin~Emitter#delegate}.
|
|
24
|
+
*/
|
|
25
|
+
path: Array<object>;
|
|
26
|
+
/**
|
|
27
|
+
* Stops the event emitter to call further callbacks for this event interaction.
|
|
28
|
+
*/
|
|
29
|
+
readonly stop: {
|
|
30
|
+
(): void;
|
|
31
|
+
called?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Removes the current callback from future interactions of this event.
|
|
35
|
+
*/
|
|
36
|
+
readonly off: {
|
|
37
|
+
(): void;
|
|
38
|
+
called?: boolean;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The value which will be returned by {@link module:utils/emittermixin~Emitter#fire}.
|
|
42
|
+
*
|
|
43
|
+
* It's `undefined` by default and can be changed by an event listener:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* dataController.fire( 'getSelectedContent', ( evt ) => {
|
|
47
|
+
* // This listener will make `dataController.fire( 'getSelectedContent' )`
|
|
48
|
+
* // always return an empty DocumentFragment.
|
|
49
|
+
* evt.return = new DocumentFragment();
|
|
50
|
+
*
|
|
51
|
+
* // Make sure no other listeners are executed.
|
|
52
|
+
* evt.stop();
|
|
53
|
+
* } );
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
return: TReturn | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* @param source The emitter.
|
|
59
|
+
* @param name The event name.
|
|
60
|
+
*/
|
|
61
|
+
constructor(source: object, name: TName);
|
|
62
|
+
}
|