@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,167 @@
|
|
|
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
|
+
* Handles a configuration dictionary.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam Cfg A type of the configuration dictionary.
|
|
13
|
+
*/
|
|
14
|
+
export default class Config<Cfg> {
|
|
15
|
+
/**
|
|
16
|
+
* Store for the whole configuration.
|
|
17
|
+
*/
|
|
18
|
+
private readonly _config;
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of the {@link ~Config} class.
|
|
21
|
+
*
|
|
22
|
+
* @param configurations The initial configurations to be set. Usually, provided by the user.
|
|
23
|
+
* @param defaultConfigurations The default configurations. Usually, provided by the system.
|
|
24
|
+
*/
|
|
25
|
+
constructor(configurations?: Partial<Cfg>, defaultConfigurations?: Partial<Cfg>);
|
|
26
|
+
/**
|
|
27
|
+
* Set configuration values.
|
|
28
|
+
*
|
|
29
|
+
* It also accepts setting a "deep configuration" by using dots in the name. For example, `'resize.width'` sets
|
|
30
|
+
* the value for the `width` configuration in the `resize` subset.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* config.set( 'resize.width', 500 );
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
37
|
+
* configurations. See {@link #set:CONFIG_OBJECT}.
|
|
38
|
+
*
|
|
39
|
+
* @label KEY_VALUE
|
|
40
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
41
|
+
* @param value The configuration value.
|
|
42
|
+
*/
|
|
43
|
+
set<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Set configuration values.
|
|
46
|
+
*
|
|
47
|
+
* It accepts an object, which properties and values will be used to set configurations.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* config.set( {
|
|
51
|
+
* width: 500
|
|
52
|
+
* toolbar: {
|
|
53
|
+
* collapsed: true
|
|
54
|
+
* }
|
|
55
|
+
* } );
|
|
56
|
+
*
|
|
57
|
+
* // Equivalent to:
|
|
58
|
+
* config.set( 'width', 500 );
|
|
59
|
+
* config.set( 'toolbar.collapsed', true );
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Passing an object as the value will amend the configuration, not replace it.
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* config.set( 'toolbar', {
|
|
66
|
+
* collapsed: true,
|
|
67
|
+
* } );
|
|
68
|
+
*
|
|
69
|
+
* config.set( 'toolbar', {
|
|
70
|
+
* color: 'red',
|
|
71
|
+
* } );
|
|
72
|
+
*
|
|
73
|
+
* config.get( 'toolbar.collapsed' ); // true
|
|
74
|
+
* config.get( 'toolbar.color' ); // 'red'
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
78
|
+
* configurations. See {@link #set:KEY_VALUE}.
|
|
79
|
+
*
|
|
80
|
+
* @label CONFIG_OBJECT
|
|
81
|
+
* @param config The configuration object from which take properties as
|
|
82
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
83
|
+
*/
|
|
84
|
+
set(config: Partial<Cfg>): void;
|
|
85
|
+
/**
|
|
86
|
+
* Does exactly the same as {@link #set:KEY_VALUE} with one exception – passed configuration extends
|
|
87
|
+
* existing one, but does not overwrite already defined values.
|
|
88
|
+
*
|
|
89
|
+
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
90
|
+
* rarely used for other needs.
|
|
91
|
+
*
|
|
92
|
+
* @label KEY_VALUE
|
|
93
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
94
|
+
* @param value The configuration value.
|
|
95
|
+
*/
|
|
96
|
+
define<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
97
|
+
/**
|
|
98
|
+
* Does exactly the same as {@link #set:CONFIG_OBJECT} with one exception – passed configuration extends
|
|
99
|
+
* existing one, but does not overwrite already defined values.
|
|
100
|
+
*
|
|
101
|
+
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
102
|
+
* rarely used for other needs.
|
|
103
|
+
*
|
|
104
|
+
* @label CONFIG_OBJECT
|
|
105
|
+
* @param config The configuration object from which take properties as
|
|
106
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
107
|
+
*/
|
|
108
|
+
define(config: Partial<Cfg>): void;
|
|
109
|
+
/**
|
|
110
|
+
* Gets the value for a configuration entry.
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* config.get( 'name' );
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* Deep configurations can be retrieved by separating each part with a dot.
|
|
117
|
+
*
|
|
118
|
+
* ```ts
|
|
119
|
+
* config.get( 'toolbar.collapsed' );
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
123
|
+
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
124
|
+
*/
|
|
125
|
+
get<K extends string>(name: K): GetSubConfig<Cfg, K> | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Iterates over all top level configuration names.
|
|
128
|
+
*/
|
|
129
|
+
names(): Iterable<string>;
|
|
130
|
+
/**
|
|
131
|
+
* Saves passed configuration to the specified target (nested object).
|
|
132
|
+
*
|
|
133
|
+
* @param target Nested config object.
|
|
134
|
+
* @param name The configuration name or an object from which take properties as
|
|
135
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
136
|
+
* @param value The configuration value. Used if a name is passed.
|
|
137
|
+
* @param isDefine Define if passed configuration should overwrite existing one.
|
|
138
|
+
*/
|
|
139
|
+
private _setToTarget;
|
|
140
|
+
/**
|
|
141
|
+
* Get specified configuration from specified source (nested object).
|
|
142
|
+
*
|
|
143
|
+
* @param source level of nested object.
|
|
144
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
145
|
+
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
146
|
+
*/
|
|
147
|
+
private _getFromSource;
|
|
148
|
+
/**
|
|
149
|
+
* Iterates through passed object and calls {@link #_setToTarget} method with object key and value for each property.
|
|
150
|
+
*
|
|
151
|
+
* @param target Nested config object.
|
|
152
|
+
* @param configuration Configuration data set
|
|
153
|
+
* @param isDefine Defines if passed configuration is default configuration or not.
|
|
154
|
+
*/
|
|
155
|
+
private _setObjectToTarget;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* An utility type excluding primitive values and arrays from the union.
|
|
159
|
+
*/
|
|
160
|
+
export type OnlyObject<T> = Exclude<T, undefined | null | string | number | boolean | Array<any>>;
|
|
161
|
+
/**
|
|
162
|
+
* An utility type extracting configuration value from the given name.
|
|
163
|
+
*
|
|
164
|
+
* @typeParam T The type of a configuration dictionary.
|
|
165
|
+
* @typeParam K The literal type of configuration name (dot-separated path).
|
|
166
|
+
*/
|
|
167
|
+
export type GetSubConfig<T, K> = K extends keyof T ? T[K] : K extends `${infer K1}.${infer K2}` ? K1 extends keyof T ? GetSubConfig<OnlyObject<T[K1]>, K2> : unknown : unknown;
|
|
@@ -0,0 +1,22 @@
|
|
|
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/count
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns the number of items return by the iterator.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* count( [ 1, 2, 3, 4, 5 ] ); // 5;
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @param iterable Any iterable.
|
|
20
|
+
* @returns Number of items returned by that iterable.
|
|
21
|
+
*/
|
|
22
|
+
export default function count(iterable: Iterable<unknown>): number;
|
|
@@ -0,0 +1,23 @@
|
|
|
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/delay
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns a function wrapper that will trigger a function after a specified wait time.
|
|
14
|
+
* The timeout can be canceled by calling the cancel function on the returned wrapped function.
|
|
15
|
+
*
|
|
16
|
+
* @param func The function to wrap.
|
|
17
|
+
* @param wait The timeout in ms.
|
|
18
|
+
*/
|
|
19
|
+
export default function delay<T extends (...args: Array<any>) => any>(func: T, wait: number): DelayedFunc<T>;
|
|
20
|
+
export interface DelayedFunc<T extends (...args: Array<any>) => any> {
|
|
21
|
+
(...args: Parameters<T>): void;
|
|
22
|
+
cancel(): void;
|
|
23
|
+
}
|
|
@@ -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
|
+
* Calculates the difference between two arrays or strings producing an array containing a list of changes
|
|
11
|
+
* necessary to transform input into output.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
|
|
18
|
+
* Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items).
|
|
19
|
+
* Therefore, `diff()` automatically switches to {@link module:utils/fastdiff~fastDiff `fastDiff()`} when detecting
|
|
20
|
+
* such a scenario. The return formats of both functions are identical.
|
|
21
|
+
*
|
|
22
|
+
* @param a Input array or string.
|
|
23
|
+
* @param b Output array or string.
|
|
24
|
+
* @param cmp Optional function used to compare array values, by default === is used.
|
|
25
|
+
* @returns Array of changes.
|
|
26
|
+
*/
|
|
27
|
+
declare function diff<T>(a: ArrayLike<T>, b: ArrayLike<T>, cmp?: (a: T, b: T) => boolean): Array<DiffResult>;
|
|
28
|
+
declare namespace diff {
|
|
29
|
+
var fastDiff: typeof import("./fastdiff.js").default;
|
|
30
|
+
}
|
|
31
|
+
export default diff;
|
|
32
|
+
/**
|
|
33
|
+
* The element of the result of {@link module:utils/diff~diff} function.
|
|
34
|
+
*/
|
|
35
|
+
export type DiffResult = 'equal' | 'insert' | 'delete';
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import type { DiffResult } from './diff.js';
|
|
10
|
+
/**
|
|
11
|
+
* @module utils/difftochanges
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Creates a set of changes which need to be applied to the input in order to transform
|
|
15
|
+
* it into the output. This function can be used with strings or arrays.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const input = Array.from( 'abc' );
|
|
19
|
+
* const output = Array.from( 'xaby' );
|
|
20
|
+
* const changes = diffToChanges( diff( input, output ), output );
|
|
21
|
+
*
|
|
22
|
+
* changes.forEach( change => {
|
|
23
|
+
* if ( change.type == 'insert' ) {
|
|
24
|
+
* input.splice( change.index, 0, ...change.values );
|
|
25
|
+
* } else if ( change.type == 'delete' ) {
|
|
26
|
+
* input.splice( change.index, change.howMany );
|
|
27
|
+
* }
|
|
28
|
+
* } );
|
|
29
|
+
*
|
|
30
|
+
* input.join( '' ) == output.join( '' ); // -> true
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @typeParam T The type of output array element.
|
|
34
|
+
* @param diff Result of {@link module:utils/diff~diff}.
|
|
35
|
+
* @param output The string or array which was passed as diff's output.
|
|
36
|
+
* @returns Set of changes (insert or delete) which need to be applied to the input
|
|
37
|
+
* in order to transform it into the output.
|
|
38
|
+
*/
|
|
39
|
+
export default function diffToChanges<T>(diff: ReadonlyArray<DiffResult>, output: ArrayLike<T>): Array<Change<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* An object describing insertion change.
|
|
42
|
+
*
|
|
43
|
+
* @typeParam T The type of output array element.
|
|
44
|
+
*/
|
|
45
|
+
export interface InsertChange<T> {
|
|
46
|
+
type: 'insert';
|
|
47
|
+
index: number;
|
|
48
|
+
values: Array<T>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* An object describing deletion change.
|
|
52
|
+
*/
|
|
53
|
+
export interface DeleteChange {
|
|
54
|
+
type: 'delete';
|
|
55
|
+
index: number;
|
|
56
|
+
howMany: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The element of the result of {@link module:utils/difftochanges~diffToChanges} function.
|
|
60
|
+
*
|
|
61
|
+
* @typeParam T The type of output array element.
|
|
62
|
+
*/
|
|
63
|
+
export type Change<T> = InsertChange<T> | DeleteChange;
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
* Attributes to be applied to the HTML element.
|
|
11
|
+
*/
|
|
12
|
+
type HTMLElementAttributes = {
|
|
13
|
+
readonly [key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Attributes to be applied to the SVG element.
|
|
17
|
+
*/
|
|
18
|
+
type SVGElementAttributes = HTMLElementAttributes & {
|
|
19
|
+
xmlns: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Element or elements that will be added to the created element as children. Strings will be automatically turned into Text nodes.
|
|
23
|
+
*/
|
|
24
|
+
type ChildrenElements = Node | string | Iterable<Node | string>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates an SVG element with attributes and children elements.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
|
|
30
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg', id: 'foo' } ); // <mask id="foo">
|
|
31
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, 'foo' ); // <mask>foo</mask>
|
|
32
|
+
* createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, [ createElement(...) ] ); // <mask><...></mask>
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @label SVG_ELEMENT
|
|
36
|
+
* @param doc Document used to create the element.
|
|
37
|
+
* @param name Name of the SVG element.
|
|
38
|
+
* @param attributes Object where keys represent attribute keys and values represent attribute values.
|
|
39
|
+
* @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
|
|
40
|
+
* @returns SVG element.
|
|
41
|
+
*/
|
|
42
|
+
export default function createElement<T extends keyof SVGElementTagNameMap>(doc: Document, name: T, attributes: SVGElementAttributes, children?: ChildrenElements): SVGElementTagNameMap[T];
|
|
43
|
+
/**
|
|
44
|
+
* Creates an HTML element with attributes and children elements.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* createElement( document, 'p' ); // <p>
|
|
48
|
+
* createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
|
|
49
|
+
* createElement( document, 'p', null, 'foo' ); // <p>foo</p>
|
|
50
|
+
* createElement( document, 'p', null, [ createElement(...) ] ); // <p><...></p>
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @label HTML_ELEMENT
|
|
54
|
+
* @param doc Document used to create the element.
|
|
55
|
+
* @param name Name of the HTML element.
|
|
56
|
+
* @param attributes Object where keys represent attribute keys and values represent attribute values.
|
|
57
|
+
* @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
|
|
58
|
+
* @returns HTML element.
|
|
59
|
+
*/
|
|
60
|
+
export default function createElement<T extends keyof HTMLElementTagNameMap>(doc: Document, name: T, attributes?: HTMLElementAttributes, children?: ChildrenElements): HTMLElementTagNameMap[T];
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
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/emittermixin
|
|
11
|
+
*/
|
|
12
|
+
import { type Emitter, type CallbackOptions, type BaseEvent, type GetCallback } from '../emittermixin.js';
|
|
13
|
+
import type EventInfo from '../eventinfo.js';
|
|
14
|
+
import type { Constructor, Mixed } from '../mix.js';
|
|
15
|
+
/**
|
|
16
|
+
* Mixin that injects the DOM events API into its host. It provides the API
|
|
17
|
+
* compatible with {@link module:utils/emittermixin~Emitter}.
|
|
18
|
+
*
|
|
19
|
+
* This function creates a class that inherits from the provided `base` and implements `Emitter` interface.
|
|
20
|
+
*
|
|
21
|
+
* DOM emitter mixin is by default available in the {@link module:ui/view~View} class,
|
|
22
|
+
* but it can also be mixed into any other class:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
26
|
+
*
|
|
27
|
+
* class BaseClass { ... }
|
|
28
|
+
*
|
|
29
|
+
* class SomeView extends DomEmitterMixin( BaseClass ) {}
|
|
30
|
+
*
|
|
31
|
+
* const view = new SomeView();
|
|
32
|
+
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
33
|
+
* console.log( evt, domEvt );
|
|
34
|
+
* } );
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @label EXTENDS
|
|
38
|
+
*/
|
|
39
|
+
export default function DomEmitterMixin<Base extends Constructor<Emitter>>(base: Base): Mixed<Base, DomEmitter>;
|
|
40
|
+
/**
|
|
41
|
+
* Mixin that injects the DOM events API into its host. It provides the API
|
|
42
|
+
* compatible with {@link module:utils/emittermixin~Emitter}.
|
|
43
|
+
*
|
|
44
|
+
* This function creates a class that implements `Emitter` interface.
|
|
45
|
+
*
|
|
46
|
+
* DOM emitter mixin is by default available in the {@link module:ui/view~View} class,
|
|
47
|
+
* but it can also be mixed into any other class:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import DomEmitterMixin from '../utils/dom/emittermixin.js';
|
|
51
|
+
*
|
|
52
|
+
* class SomeView extends DomEmitterMixin() {}
|
|
53
|
+
*
|
|
54
|
+
* const view = new SomeView();
|
|
55
|
+
* view.listenTo( domElement, ( evt, domEvt ) => {
|
|
56
|
+
* console.log( evt, domEvt );
|
|
57
|
+
* } );
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @label NO_ARGUMENTS
|
|
61
|
+
*/
|
|
62
|
+
export default function DomEmitterMixin(): {
|
|
63
|
+
new (): DomEmitter;
|
|
64
|
+
prototype: DomEmitter;
|
|
65
|
+
};
|
|
66
|
+
export interface DomEventMap extends HTMLElementEventMap, WindowEventMap {
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Interface representing classes which mix in {@link module:utils/dom/emittermixin~DomEmitterMixin}.
|
|
70
|
+
*
|
|
71
|
+
* Can be easily implemented by a class by mixing the {@link module:utils/dom/emittermixin~DomEmitterMixin} mixin.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* class MyClass extends DomEmitterMixin( OtherBaseClass ) {
|
|
75
|
+
* // This class now implements the `Emitter` interface.
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface DomEmitter extends Emitter {
|
|
80
|
+
/**
|
|
81
|
+
* Registers a callback function to be executed when an event is fired in a specific Emitter or DOM Node.
|
|
82
|
+
* It is backwards compatible with {@link module:utils/emittermixin~Emitter#listenTo}.
|
|
83
|
+
*
|
|
84
|
+
* @label HTML_EMITTER
|
|
85
|
+
* @param emitter The object that fires the event.
|
|
86
|
+
* @param event The name of the event.
|
|
87
|
+
* @param callback The function to be called on event.
|
|
88
|
+
* @param options Additional options.
|
|
89
|
+
* @param options.useCapture Indicates that events of this type will be dispatched to the registered
|
|
90
|
+
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
|
|
91
|
+
* @param options.usePassive Indicates that the function specified by listener will never call preventDefault()
|
|
92
|
+
* and prevents blocking browser's main thread by this event handler.
|
|
93
|
+
*/
|
|
94
|
+
listenTo<K extends keyof DomEventMap>(emitter: Node | Window, event: K, callback: (this: this, ev: EventInfo, event: DomEventMap[K]) => void, options?: CallbackOptions & {
|
|
95
|
+
readonly useCapture?: boolean;
|
|
96
|
+
readonly usePassive?: boolean;
|
|
97
|
+
}): void;
|
|
98
|
+
/**
|
|
99
|
+
* Registers a callback function to be executed when an event is fired in a specific (emitter) object.
|
|
100
|
+
*
|
|
101
|
+
* Events can be grouped in namespaces using `:`.
|
|
102
|
+
* When namespaced event is fired, it additionally fires all callbacks for that namespace.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* // myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ).
|
|
106
|
+
* myEmitter.on( 'myGroup', genericCallback );
|
|
107
|
+
* myEmitter.on( 'myGroup:myEvent', specificCallback );
|
|
108
|
+
*
|
|
109
|
+
* // genericCallback is fired.
|
|
110
|
+
* myEmitter.fire( 'myGroup' );
|
|
111
|
+
* // both genericCallback and specificCallback are fired.
|
|
112
|
+
* myEmitter.fire( 'myGroup:myEvent' );
|
|
113
|
+
* // genericCallback is fired even though there are no callbacks for "foo".
|
|
114
|
+
* myEmitter.fire( 'myGroup:foo' );
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* An event callback can {@link module:utils/eventinfo~EventInfo#stop stop the event} and
|
|
118
|
+
* set the {@link module:utils/eventinfo~EventInfo#return return value} of the {@link #fire} method.
|
|
119
|
+
*
|
|
120
|
+
* @label DOM_EMITTER
|
|
121
|
+
* @typeParam TEvent The type describing the event. See {@link module:utils/emittermixin~BaseEvent}.
|
|
122
|
+
* @param emitter The object that fires the event.
|
|
123
|
+
* @param event The name of the event.
|
|
124
|
+
* @param callback The function to be called on event.
|
|
125
|
+
* @param options Additional options.
|
|
126
|
+
*/
|
|
127
|
+
listenTo<TEvent extends BaseEvent>(emitter: Emitter, event: TEvent['name'], callback: GetCallback<TEvent>, options?: CallbackOptions): void;
|
|
128
|
+
/**
|
|
129
|
+
* Stops listening for events. It can be used at different levels:
|
|
130
|
+
* It is backwards compatible with {@link module:utils/emittermixin~Emitter#listenTo}.
|
|
131
|
+
*
|
|
132
|
+
* * To stop listening to a specific callback.
|
|
133
|
+
* * To stop listening to a specific event.
|
|
134
|
+
* * To stop listening to all events fired by a specific object.
|
|
135
|
+
* * To stop listening to all events fired by all objects.
|
|
136
|
+
*
|
|
137
|
+
* @label DOM_STOP
|
|
138
|
+
* @param emitter The object to stop listening to.
|
|
139
|
+
* If omitted, stops it for all objects.
|
|
140
|
+
* @param event (Requires the `emitter`) The name of the event to stop listening to. If omitted, stops it
|
|
141
|
+
* for all events from `emitter`.
|
|
142
|
+
* @param callback (Requires the `event`) The function to be removed from the call list for the given
|
|
143
|
+
* `event`.
|
|
144
|
+
*/
|
|
145
|
+
stopListening(emitter?: Emitter | Node | Window, event?: string, callback?: Function): void;
|
|
146
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
* Returns the closest scrollable ancestor of a DOM element.
|
|
11
|
+
*
|
|
12
|
+
* @param domElement DOM element.
|
|
13
|
+
* @returns First ancestor of `domElement` that is scrollable or null if such ancestor doesn't exist.
|
|
14
|
+
*/
|
|
15
|
+
export default function findClosestScrollableAncestor(domElement: HTMLElement): HTMLElement | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
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/getancestors
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns all ancestors of given DOM node, starting from the top-most (root). Includes the given node itself. If the
|
|
14
|
+
* node is a part of `DocumentFragment` that `DocumentFragment` will be returned. In contrary, if the node is
|
|
15
|
+
* appended to a `Document`, that `Document` will not be returned (algorithms operating on DOM tree care for `Document#documentElement`
|
|
16
|
+
* at most, which will be returned).
|
|
17
|
+
*
|
|
18
|
+
* @param node DOM node.
|
|
19
|
+
* @returns Array of given `node` parents.
|
|
20
|
+
*/
|
|
21
|
+
export default function getAncestors(node: Node): Array<Node>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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/getborderwidths
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Returns an object containing CSS border widths of a specified HTML element.
|
|
14
|
+
*
|
|
15
|
+
* @param element An element which has CSS borders.
|
|
16
|
+
* @returns An object containing `top`, `left`, `right` and `bottom` properties
|
|
17
|
+
* with numerical values of the `border-[top,left,right,bottom]-width` CSS styles.
|
|
18
|
+
*/
|
|
19
|
+
export default function getBorderWidths(element: HTMLElement): BorderWidths;
|
|
20
|
+
/**
|
|
21
|
+
* An object describing widths of `HTMLElement` borders.
|
|
22
|
+
*/
|
|
23
|
+
export interface BorderWidths {
|
|
24
|
+
top: number;
|
|
25
|
+
right: number;
|
|
26
|
+
bottom: number;
|
|
27
|
+
left: number;
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
* Searches and returns the lowest common ancestor of two given nodes.
|
|
11
|
+
*
|
|
12
|
+
* @param nodeA First node.
|
|
13
|
+
* @param nodeB Second node.
|
|
14
|
+
* @returns Lowest common ancestor of both nodes or `null` if nodes do not have a common ancestor.
|
|
15
|
+
*/
|
|
16
|
+
export default function getCommonAncestor(nodeA: Node, nodeB: Node): Node | null;
|
|
@@ -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/getdatafromelement
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Gets data from a given source element.
|
|
14
|
+
*
|
|
15
|
+
* @param el The element from which the data will be retrieved.
|
|
16
|
+
* @returns The data string.
|
|
17
|
+
*/
|
|
18
|
+
export default function getDataFromElement(el: HTMLElement): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* For a given element, returns the nearest ancestor element which CSS position is not "static".
|
|
11
|
+
*
|
|
12
|
+
* @param element The native DOM element to be checked.
|
|
13
|
+
*/
|
|
14
|
+
export default function getPositionedAncestor(element?: HTMLElement): HTMLElement | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
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/global
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* A helper (module) giving an access to the global DOM objects such as `window` and `document`.
|
|
14
|
+
*/
|
|
15
|
+
export interface GlobalType {
|
|
16
|
+
readonly window: Window & typeof globalThis;
|
|
17
|
+
readonly document: Document;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A helper (module) giving an access to the global DOM objects such as `window` and
|
|
21
|
+
* `document`. Accessing these objects using this helper allows easy and bulletproof
|
|
22
|
+
* testing, i.e. stubbing native properties:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { global } from 'ckeditor5/utils';
|
|
26
|
+
*
|
|
27
|
+
* // This stub will work for any code using global module.
|
|
28
|
+
* testUtils.sinon.stub( global, 'window', {
|
|
29
|
+
* innerWidth: 10000
|
|
30
|
+
* } );
|
|
31
|
+
*
|
|
32
|
+
* console.log( global.window.innerWidth );
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare let globalVar: GlobalType;
|
|
36
|
+
export default globalVar;
|