@ckeditor/ckeditor5-utils 40.0.0 → 40.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -26
- package/LICENSE.md +3 -3
- package/package.json +1 -1
- package/src/abortabledebounce.d.ts +17 -0
- package/src/abortabledebounce.js +22 -0
- package/src/areconnectedthroughproperties.d.ts +11 -11
- package/src/areconnectedthroughproperties.js +73 -73
- package/src/ckeditorerror.d.ts +123 -123
- package/src/ckeditorerror.js +176 -176
- package/src/collection.d.ts +433 -427
- package/src/collection.js +583 -575
- package/src/comparearrays.d.ts +30 -30
- package/src/comparearrays.js +47 -47
- package/src/config.d.ts +163 -163
- package/src/config.js +163 -162
- package/src/count.d.ts +18 -18
- package/src/count.js +24 -24
- package/src/delay.d.ts +19 -19
- package/src/delay.js +26 -26
- package/src/diff.d.ts +31 -31
- package/src/diff.js +115 -115
- package/src/difftochanges.d.ts +59 -59
- package/src/difftochanges.js +79 -79
- package/src/dom/createelement.d.ts +57 -57
- package/src/dom/createelement.js +40 -40
- package/src/dom/emittermixin.d.ts +142 -142
- package/src/dom/emittermixin.js +239 -239
- package/src/dom/findclosestscrollableancestor.d.ts +11 -11
- package/src/dom/findclosestscrollableancestor.js +31 -31
- package/src/dom/getancestors.d.ts +17 -17
- package/src/dom/getancestors.js +27 -27
- package/src/dom/getborderwidths.d.ts +24 -24
- package/src/dom/getborderwidths.js +24 -24
- package/src/dom/getcommonancestor.d.ts +12 -12
- package/src/dom/getcommonancestor.js +25 -25
- package/src/dom/getdatafromelement.d.ts +14 -14
- package/src/dom/getdatafromelement.js +20 -20
- package/src/dom/getpositionedancestor.d.ts +10 -10
- package/src/dom/getpositionedancestor.js +22 -22
- package/src/dom/global.d.ts +32 -32
- package/src/dom/global.js +35 -35
- package/src/dom/indexof.d.ts +14 -14
- package/src/dom/indexof.js +21 -21
- package/src/dom/insertat.d.ts +15 -15
- package/src/dom/insertat.js +17 -17
- package/src/dom/iscomment.d.ts +11 -11
- package/src/dom/iscomment.js +14 -14
- package/src/dom/isnode.d.ts +11 -11
- package/src/dom/isnode.js +21 -21
- package/src/dom/isrange.d.ts +11 -11
- package/src/dom/isrange.js +13 -13
- package/src/dom/istext.d.ts +11 -11
- package/src/dom/istext.js +13 -13
- package/src/dom/isvalidattributename.d.ts +10 -10
- package/src/dom/isvalidattributename.js +22 -22
- package/src/dom/isvisible.d.ts +18 -18
- package/src/dom/isvisible.js +20 -20
- package/src/dom/iswindow.d.ts +11 -11
- package/src/dom/iswindow.js +22 -22
- package/src/dom/position.d.ts +211 -211
- package/src/dom/position.js +313 -313
- package/src/dom/rect.d.ts +195 -195
- package/src/dom/rect.js +474 -474
- package/src/dom/remove.d.ts +13 -13
- package/src/dom/remove.js +18 -18
- package/src/dom/resizeobserver.d.ts +74 -74
- package/src/dom/resizeobserver.js +126 -126
- package/src/dom/scroll.d.ts +73 -73
- package/src/dom/scroll.js +383 -383
- package/src/dom/setdatainelement.d.ts +14 -14
- package/src/dom/setdatainelement.js +20 -20
- package/src/dom/tounit.d.ts +22 -22
- package/src/dom/tounit.js +16 -16
- package/src/elementreplacer.d.ts +31 -31
- package/src/elementreplacer.js +43 -43
- package/src/emittermixin.d.ts +312 -312
- package/src/emittermixin.js +453 -453
- package/src/env.d.ts +117 -117
- package/src/env.js +122 -122
- package/src/eventinfo.d.ts +58 -58
- package/src/eventinfo.js +26 -26
- package/src/fastdiff.d.ts +112 -112
- package/src/fastdiff.js +248 -248
- package/src/first.d.ts +11 -11
- package/src/first.js +17 -17
- package/src/focustracker.d.ts +75 -75
- package/src/focustracker.js +95 -95
- package/src/index.d.ts +64 -61
- package/src/index.js +63 -60
- package/src/inserttopriorityarray.d.ts +30 -30
- package/src/inserttopriorityarray.js +21 -21
- package/src/isiterable.d.ts +14 -14
- package/src/isiterable.js +16 -16
- package/src/keyboard.d.ts +126 -126
- package/src/keyboard.js +221 -221
- package/src/keystrokehandler.d.ts +87 -87
- package/src/keystrokehandler.js +122 -122
- package/src/language.d.ts +17 -17
- package/src/language.js +19 -19
- package/src/locale.d.ts +120 -120
- package/src/locale.js +76 -76
- package/src/mapsequal.d.ts +15 -15
- package/src/mapsequal.js +27 -27
- package/src/mix.d.ts +85 -85
- package/src/mix.js +50 -50
- package/src/nth.d.ts +16 -16
- package/src/nth.js +24 -24
- package/src/objecttomap.d.ts +23 -23
- package/src/objecttomap.js +27 -27
- package/src/observablemixin.d.ts +560 -560
- package/src/observablemixin.js +580 -580
- package/src/priorities.d.ts +33 -33
- package/src/priorities.js +23 -23
- package/src/retry.d.ts +33 -0
- package/src/retry.js +47 -0
- package/src/splicearray.d.ts +26 -26
- package/src/splicearray.js +40 -40
- package/src/spy.d.ts +21 -21
- package/src/spy.js +22 -22
- package/src/toarray.d.ts +25 -25
- package/src/toarray.js +7 -7
- package/src/tomap.d.ts +19 -19
- package/src/tomap.js +29 -29
- package/src/translation-service.d.ts +168 -168
- package/src/translation-service.js +198 -198
- package/src/uid.d.ts +15 -15
- package/src/uid.js +57 -57
- package/src/unicode.d.ts +54 -54
- package/src/unicode.js +85 -85
- package/src/verifylicense.d.ts +15 -15
- package/src/verifylicense.js +87 -87
- package/src/version.d.ts +10 -10
- package/src/version.js +153 -153
- package/src/wait.d.ts +16 -0
- package/src/wait.js +29 -0
package/src/comparearrays.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/comparearrays
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
|
|
10
|
-
* or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
|
|
11
|
-
* a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
|
|
12
|
-
* it means that arrays differ.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
|
|
16
|
-
* compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
|
|
17
|
-
* compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
|
|
18
|
-
* compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
|
|
19
|
-
* compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @param a Array that is compared.
|
|
23
|
-
* @param b Array to compare with.
|
|
24
|
-
* @returns How array `a` is related to `b`.
|
|
25
|
-
*/
|
|
26
|
-
export default function compareArrays(a: ReadonlyArray<unknown>, b: ReadonlyArray<unknown>): ArrayRelation | number;
|
|
27
|
-
/**
|
|
28
|
-
* Array relation.
|
|
29
|
-
*/
|
|
30
|
-
export type ArrayRelation = 'extension' | 'same' | 'prefix';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/comparearrays
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
|
|
10
|
+
* or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
|
|
11
|
+
* a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
|
|
12
|
+
* it means that arrays differ.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
|
|
16
|
+
* compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
|
|
17
|
+
* compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
|
|
18
|
+
* compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
|
|
19
|
+
* compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param a Array that is compared.
|
|
23
|
+
* @param b Array to compare with.
|
|
24
|
+
* @returns How array `a` is related to `b`.
|
|
25
|
+
*/
|
|
26
|
+
export default function compareArrays(a: ReadonlyArray<unknown>, b: ReadonlyArray<unknown>): ArrayRelation | number;
|
|
27
|
+
/**
|
|
28
|
+
* Array relation.
|
|
29
|
+
*/
|
|
30
|
+
export type ArrayRelation = 'extension' | 'same' | 'prefix';
|
package/src/comparearrays.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/comparearrays
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
|
|
10
|
-
* or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
|
|
11
|
-
* a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
|
|
12
|
-
* it means that arrays differ.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
|
|
16
|
-
* compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
|
|
17
|
-
* compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
|
|
18
|
-
* compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
|
|
19
|
-
* compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @param a Array that is compared.
|
|
23
|
-
* @param b Array to compare with.
|
|
24
|
-
* @returns How array `a` is related to `b`.
|
|
25
|
-
*/
|
|
26
|
-
export default function compareArrays(a, b) {
|
|
27
|
-
const minLen = Math.min(a.length, b.length);
|
|
28
|
-
for (let i = 0; i < minLen; i++) {
|
|
29
|
-
if (a[i] != b[i]) {
|
|
30
|
-
// The arrays are different.
|
|
31
|
-
return i;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// Both arrays were same at all points.
|
|
35
|
-
if (a.length == b.length) {
|
|
36
|
-
// If their length is also same, they are the same.
|
|
37
|
-
return 'same';
|
|
38
|
-
}
|
|
39
|
-
else if (a.length < b.length) {
|
|
40
|
-
// Compared array is shorter so it is a prefix of the other array.
|
|
41
|
-
return 'prefix';
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
// Compared array is longer so it is an extension of the other array.
|
|
45
|
-
return 'extension';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module utils/comparearrays
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
|
|
10
|
+
* or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
|
|
11
|
+
* a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
|
|
12
|
+
* it means that arrays differ.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
|
|
16
|
+
* compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
|
|
17
|
+
* compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
|
|
18
|
+
* compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
|
|
19
|
+
* compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param a Array that is compared.
|
|
23
|
+
* @param b Array to compare with.
|
|
24
|
+
* @returns How array `a` is related to `b`.
|
|
25
|
+
*/
|
|
26
|
+
export default function compareArrays(a, b) {
|
|
27
|
+
const minLen = Math.min(a.length, b.length);
|
|
28
|
+
for (let i = 0; i < minLen; i++) {
|
|
29
|
+
if (a[i] != b[i]) {
|
|
30
|
+
// The arrays are different.
|
|
31
|
+
return i;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Both arrays were same at all points.
|
|
35
|
+
if (a.length == b.length) {
|
|
36
|
+
// If their length is also same, they are the same.
|
|
37
|
+
return 'same';
|
|
38
|
+
}
|
|
39
|
+
else if (a.length < b.length) {
|
|
40
|
+
// Compared array is shorter so it is a prefix of the other array.
|
|
41
|
+
return 'prefix';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Compared array is longer so it is an extension of the other array.
|
|
45
|
+
return 'extension';
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/config.d.ts
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Handles a configuration dictionary.
|
|
7
|
-
*
|
|
8
|
-
* @typeParam Cfg A type of the configuration dictionary.
|
|
9
|
-
*/
|
|
10
|
-
export default class Config<Cfg> {
|
|
11
|
-
/**
|
|
12
|
-
* Store for the whole configuration.
|
|
13
|
-
*/
|
|
14
|
-
private readonly _config;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of the {@link ~Config} class.
|
|
17
|
-
*
|
|
18
|
-
* @param configurations The initial configurations to be set. Usually, provided by the user.
|
|
19
|
-
* @param defaultConfigurations The default configurations. Usually, provided by the system.
|
|
20
|
-
*/
|
|
21
|
-
constructor(configurations?: Partial<Cfg>, defaultConfigurations?: Partial<Cfg>);
|
|
22
|
-
/**
|
|
23
|
-
* Set configuration values.
|
|
24
|
-
*
|
|
25
|
-
* It also accepts setting a "deep configuration" by using dots in the name. For example, `'resize.width'` sets
|
|
26
|
-
* the value for the `width` configuration in the `resize` subset.
|
|
27
|
-
*
|
|
28
|
-
* ```ts
|
|
29
|
-
* config.set( 'resize.width', 500 );
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
33
|
-
* configurations. See {@link #set:CONFIG_OBJECT}.
|
|
34
|
-
*
|
|
35
|
-
* @label KEY_VALUE
|
|
36
|
-
* @param name The configuration name. Configuration names are case-sensitive.
|
|
37
|
-
* @param value The configuration value.
|
|
38
|
-
*/
|
|
39
|
-
set<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
40
|
-
/**
|
|
41
|
-
* Set configuration values.
|
|
42
|
-
*
|
|
43
|
-
* It accepts an object, which properties and values will be used to set configurations.
|
|
44
|
-
*
|
|
45
|
-
* ```ts
|
|
46
|
-
* config.set( {
|
|
47
|
-
* width: 500
|
|
48
|
-
* toolbar: {
|
|
49
|
-
* collapsed: true
|
|
50
|
-
* }
|
|
51
|
-
* } );
|
|
52
|
-
*
|
|
53
|
-
* // Equivalent to:
|
|
54
|
-
* config.set( 'width', 500 );
|
|
55
|
-
* config.set( 'toolbar.collapsed', true );
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* Passing an object as the value will amend the configuration, not replace it.
|
|
59
|
-
*
|
|
60
|
-
* ```ts
|
|
61
|
-
* config.set( 'toolbar', {
|
|
62
|
-
* collapsed: true,
|
|
63
|
-
* } );
|
|
64
|
-
*
|
|
65
|
-
* config.set( 'toolbar', {
|
|
66
|
-
* color: 'red',
|
|
67
|
-
* } );
|
|
68
|
-
*
|
|
69
|
-
* config.get( 'toolbar.collapsed' ); // true
|
|
70
|
-
* config.get( 'toolbar.color' ); // 'red'
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
74
|
-
* configurations. See {@link #set:KEY_VALUE}.
|
|
75
|
-
*
|
|
76
|
-
* @label CONFIG_OBJECT
|
|
77
|
-
* @param config The configuration object from which take properties as
|
|
78
|
-
* configuration entries. Configuration names are case-sensitive.
|
|
79
|
-
*/
|
|
80
|
-
set(config: Partial<Cfg>): void;
|
|
81
|
-
/**
|
|
82
|
-
* Does exactly the same as {@link #set:KEY_VALUE} with one exception – passed configuration extends
|
|
83
|
-
* existing one, but does not overwrite already defined values.
|
|
84
|
-
*
|
|
85
|
-
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
86
|
-
* rarely used for other needs.
|
|
87
|
-
*
|
|
88
|
-
* @label KEY_VALUE
|
|
89
|
-
* @param name The configuration name. Configuration names are case-sensitive.
|
|
90
|
-
* @param value The configuration value.
|
|
91
|
-
*/
|
|
92
|
-
define<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
93
|
-
/**
|
|
94
|
-
* Does exactly the same as {@link #set:CONFIG_OBJECT} with one exception – passed configuration extends
|
|
95
|
-
* existing one, but does not overwrite already defined values.
|
|
96
|
-
*
|
|
97
|
-
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
98
|
-
* rarely used for other needs.
|
|
99
|
-
*
|
|
100
|
-
* @label CONFIG_OBJECT
|
|
101
|
-
* @param config The configuration object from which take properties as
|
|
102
|
-
* configuration entries. Configuration names are case-sensitive.
|
|
103
|
-
*/
|
|
104
|
-
define(config: Partial<Cfg>): void;
|
|
105
|
-
/**
|
|
106
|
-
* Gets the value for a configuration entry.
|
|
107
|
-
*
|
|
108
|
-
* ```ts
|
|
109
|
-
* config.get( 'name' );
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* Deep configurations can be retrieved by separating each part with a dot.
|
|
113
|
-
*
|
|
114
|
-
* ```ts
|
|
115
|
-
* config.get( 'toolbar.collapsed' );
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* @param name The configuration name. Configuration names are case-sensitive.
|
|
119
|
-
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
120
|
-
*/
|
|
121
|
-
get<K extends string>(name: K): GetSubConfig<Cfg, K> | undefined;
|
|
122
|
-
/**
|
|
123
|
-
* Iterates over all top level configuration names.
|
|
124
|
-
*/
|
|
125
|
-
names(): Iterable<string>;
|
|
126
|
-
/**
|
|
127
|
-
* Saves passed configuration to the specified target (nested object).
|
|
128
|
-
*
|
|
129
|
-
* @param target Nested config object.
|
|
130
|
-
* @param name The configuration name or an object from which take properties as
|
|
131
|
-
* configuration entries. Configuration names are case-sensitive.
|
|
132
|
-
* @param value The configuration value. Used if a name is passed.
|
|
133
|
-
* @param isDefine Define if passed configuration should overwrite existing one.
|
|
134
|
-
*/
|
|
135
|
-
private _setToTarget;
|
|
136
|
-
/**
|
|
137
|
-
* Get specified configuration from specified source (nested object).
|
|
138
|
-
*
|
|
139
|
-
* @param source level of nested object.
|
|
140
|
-
* @param name The configuration name. Configuration names are case-sensitive.
|
|
141
|
-
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
142
|
-
*/
|
|
143
|
-
private _getFromSource;
|
|
144
|
-
/**
|
|
145
|
-
* Iterates through passed object and calls {@link #_setToTarget} method with object key and value for each property.
|
|
146
|
-
*
|
|
147
|
-
* @param target Nested config object.
|
|
148
|
-
* @param configuration Configuration data set
|
|
149
|
-
* @param isDefine Defines if passed configuration is default configuration or not.
|
|
150
|
-
*/
|
|
151
|
-
private _setObjectToTarget;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* An utility type excluding primitive values and arrays from the union.
|
|
155
|
-
*/
|
|
156
|
-
export type OnlyObject<T> = Exclude<T, undefined | null | string | number | boolean | Array<any>>;
|
|
157
|
-
/**
|
|
158
|
-
* An utility type extracting configuration value from the given name.
|
|
159
|
-
*
|
|
160
|
-
* @typeParam T The type of a configuration dictionary.
|
|
161
|
-
* @typeParam K The literal type of configuration name (dot-separated path).
|
|
162
|
-
*/
|
|
163
|
-
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;
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Handles a configuration dictionary.
|
|
7
|
+
*
|
|
8
|
+
* @typeParam Cfg A type of the configuration dictionary.
|
|
9
|
+
*/
|
|
10
|
+
export default class Config<Cfg> {
|
|
11
|
+
/**
|
|
12
|
+
* Store for the whole configuration.
|
|
13
|
+
*/
|
|
14
|
+
private readonly _config;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an instance of the {@link ~Config} class.
|
|
17
|
+
*
|
|
18
|
+
* @param configurations The initial configurations to be set. Usually, provided by the user.
|
|
19
|
+
* @param defaultConfigurations The default configurations. Usually, provided by the system.
|
|
20
|
+
*/
|
|
21
|
+
constructor(configurations?: Partial<Cfg>, defaultConfigurations?: Partial<Cfg>);
|
|
22
|
+
/**
|
|
23
|
+
* Set configuration values.
|
|
24
|
+
*
|
|
25
|
+
* It also accepts setting a "deep configuration" by using dots in the name. For example, `'resize.width'` sets
|
|
26
|
+
* the value for the `width` configuration in the `resize` subset.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* config.set( 'resize.width', 500 );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
33
|
+
* configurations. See {@link #set:CONFIG_OBJECT}.
|
|
34
|
+
*
|
|
35
|
+
* @label KEY_VALUE
|
|
36
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
37
|
+
* @param value The configuration value.
|
|
38
|
+
*/
|
|
39
|
+
set<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set configuration values.
|
|
42
|
+
*
|
|
43
|
+
* It accepts an object, which properties and values will be used to set configurations.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* config.set( {
|
|
47
|
+
* width: 500
|
|
48
|
+
* toolbar: {
|
|
49
|
+
* collapsed: true
|
|
50
|
+
* }
|
|
51
|
+
* } );
|
|
52
|
+
*
|
|
53
|
+
* // Equivalent to:
|
|
54
|
+
* config.set( 'width', 500 );
|
|
55
|
+
* config.set( 'toolbar.collapsed', true );
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* Passing an object as the value will amend the configuration, not replace it.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* config.set( 'toolbar', {
|
|
62
|
+
* collapsed: true,
|
|
63
|
+
* } );
|
|
64
|
+
*
|
|
65
|
+
* config.set( 'toolbar', {
|
|
66
|
+
* color: 'red',
|
|
67
|
+
* } );
|
|
68
|
+
*
|
|
69
|
+
* config.get( 'toolbar.collapsed' ); // true
|
|
70
|
+
* config.get( 'toolbar.color' ); // 'red'
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* It accepts both a name/value pair or an object, which properties and values will be used to set
|
|
74
|
+
* configurations. See {@link #set:KEY_VALUE}.
|
|
75
|
+
*
|
|
76
|
+
* @label CONFIG_OBJECT
|
|
77
|
+
* @param config The configuration object from which take properties as
|
|
78
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
79
|
+
*/
|
|
80
|
+
set(config: Partial<Cfg>): void;
|
|
81
|
+
/**
|
|
82
|
+
* Does exactly the same as {@link #set:KEY_VALUE} with one exception – passed configuration extends
|
|
83
|
+
* existing one, but does not overwrite already defined values.
|
|
84
|
+
*
|
|
85
|
+
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
86
|
+
* rarely used for other needs.
|
|
87
|
+
*
|
|
88
|
+
* @label KEY_VALUE
|
|
89
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
90
|
+
* @param value The configuration value.
|
|
91
|
+
*/
|
|
92
|
+
define<K extends string>(name: K, value: GetSubConfig<Cfg, K>): void;
|
|
93
|
+
/**
|
|
94
|
+
* Does exactly the same as {@link #set:CONFIG_OBJECT} with one exception – passed configuration extends
|
|
95
|
+
* existing one, but does not overwrite already defined values.
|
|
96
|
+
*
|
|
97
|
+
* This method is supposed to be called by plugin developers to setup plugin's configurations. It would be
|
|
98
|
+
* rarely used for other needs.
|
|
99
|
+
*
|
|
100
|
+
* @label CONFIG_OBJECT
|
|
101
|
+
* @param config The configuration object from which take properties as
|
|
102
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
103
|
+
*/
|
|
104
|
+
define(config: Partial<Cfg>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the value for a configuration entry.
|
|
107
|
+
*
|
|
108
|
+
* ```ts
|
|
109
|
+
* config.get( 'name' );
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* Deep configurations can be retrieved by separating each part with a dot.
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* config.get( 'toolbar.collapsed' );
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
119
|
+
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
120
|
+
*/
|
|
121
|
+
get<K extends string>(name: K): GetSubConfig<Cfg, K> | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Iterates over all top level configuration names.
|
|
124
|
+
*/
|
|
125
|
+
names(): Iterable<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Saves passed configuration to the specified target (nested object).
|
|
128
|
+
*
|
|
129
|
+
* @param target Nested config object.
|
|
130
|
+
* @param name The configuration name or an object from which take properties as
|
|
131
|
+
* configuration entries. Configuration names are case-sensitive.
|
|
132
|
+
* @param value The configuration value. Used if a name is passed.
|
|
133
|
+
* @param isDefine Define if passed configuration should overwrite existing one.
|
|
134
|
+
*/
|
|
135
|
+
private _setToTarget;
|
|
136
|
+
/**
|
|
137
|
+
* Get specified configuration from specified source (nested object).
|
|
138
|
+
*
|
|
139
|
+
* @param source level of nested object.
|
|
140
|
+
* @param name The configuration name. Configuration names are case-sensitive.
|
|
141
|
+
* @returns The configuration value or `undefined` if the configuration entry was not found.
|
|
142
|
+
*/
|
|
143
|
+
private _getFromSource;
|
|
144
|
+
/**
|
|
145
|
+
* Iterates through passed object and calls {@link #_setToTarget} method with object key and value for each property.
|
|
146
|
+
*
|
|
147
|
+
* @param target Nested config object.
|
|
148
|
+
* @param configuration Configuration data set
|
|
149
|
+
* @param isDefine Defines if passed configuration is default configuration or not.
|
|
150
|
+
*/
|
|
151
|
+
private _setObjectToTarget;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* An utility type excluding primitive values and arrays from the union.
|
|
155
|
+
*/
|
|
156
|
+
export type OnlyObject<T> = Exclude<T, undefined | null | string | number | boolean | Array<any>>;
|
|
157
|
+
/**
|
|
158
|
+
* An utility type extracting configuration value from the given name.
|
|
159
|
+
*
|
|
160
|
+
* @typeParam T The type of a configuration dictionary.
|
|
161
|
+
* @typeParam K The literal type of configuration name (dot-separated path).
|
|
162
|
+
*/
|
|
163
|
+
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;
|