@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/locale.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
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/locale
|
|
7
|
-
*/
|
|
8
|
-
/* globals console */
|
|
9
|
-
import toArray from './toarray';
|
|
10
|
-
import { _translate } from './translation-service';
|
|
11
|
-
import { getLanguageDirection } from './language';
|
|
12
|
-
/**
|
|
13
|
-
* Represents the localization services.
|
|
14
|
-
*/
|
|
15
|
-
export default class Locale {
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new instance of the locale class. Learn more about
|
|
18
|
-
* {@glink features/ui-language configuring the language of the editor}.
|
|
19
|
-
*
|
|
20
|
-
* @param options Locale configuration.
|
|
21
|
-
* @param options.uiLanguage The editor UI language code in the
|
|
22
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
|
|
23
|
-
* @param options.contentLanguage The editor content language code in the
|
|
24
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
|
|
25
|
-
* See {@link #contentLanguage}.
|
|
26
|
-
*/
|
|
27
|
-
constructor({ uiLanguage = 'en', contentLanguage } = {}) {
|
|
28
|
-
this.uiLanguage = uiLanguage;
|
|
29
|
-
this.contentLanguage = contentLanguage || this.uiLanguage;
|
|
30
|
-
this.uiLanguageDirection = getLanguageDirection(this.uiLanguage);
|
|
31
|
-
this.contentLanguageDirection = getLanguageDirection(this.contentLanguage);
|
|
32
|
-
this.t = (message, values) => this._t(message, values);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
36
|
-
*
|
|
37
|
-
* **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
|
|
38
|
-
* properties instead.
|
|
39
|
-
*
|
|
40
|
-
* @deprecated
|
|
41
|
-
*/
|
|
42
|
-
get language() {
|
|
43
|
-
/**
|
|
44
|
-
* The {@link module:utils/locale~Locale#language `Locale#language`} property was deprecated and will
|
|
45
|
-
* be removed in the near future. Please use the {@link module:utils/locale~Locale#uiLanguage `Locale#uiLanguage`} and
|
|
46
|
-
* {@link module:utils/locale~Locale#contentLanguage `Locale#contentLanguage`} properties instead.
|
|
47
|
-
*
|
|
48
|
-
* @error locale-deprecated-language-property
|
|
49
|
-
*/
|
|
50
|
-
console.warn('locale-deprecated-language-property: ' +
|
|
51
|
-
'The Locale#language property has been deprecated and will be removed in the near future. ' +
|
|
52
|
-
'Please use #uiLanguage and #contentLanguage properties instead.');
|
|
53
|
-
return this.uiLanguage;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* An unbound version of the {@link #t} method.
|
|
57
|
-
*/
|
|
58
|
-
_t(message, values = []) {
|
|
59
|
-
values = toArray(values);
|
|
60
|
-
if (typeof message === 'string') {
|
|
61
|
-
message = { string: message };
|
|
62
|
-
}
|
|
63
|
-
const hasPluralForm = !!message.plural;
|
|
64
|
-
const quantity = hasPluralForm ? values[0] : 1;
|
|
65
|
-
const translatedString = _translate(this.uiLanguage, message, quantity);
|
|
66
|
-
return interpolateString(translatedString, values);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Fills the `%0, %1, ...` string placeholders with values.
|
|
71
|
-
*/
|
|
72
|
-
function interpolateString(string, values) {
|
|
73
|
-
return string.replace(/%(\d+)/g, (match, index) => {
|
|
74
|
-
return (index < values.length) ? values[index] : match;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
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/locale
|
|
7
|
+
*/
|
|
8
|
+
/* globals console */
|
|
9
|
+
import toArray from './toarray';
|
|
10
|
+
import { _translate } from './translation-service';
|
|
11
|
+
import { getLanguageDirection } from './language';
|
|
12
|
+
/**
|
|
13
|
+
* Represents the localization services.
|
|
14
|
+
*/
|
|
15
|
+
export default class Locale {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new instance of the locale class. Learn more about
|
|
18
|
+
* {@glink features/ui-language configuring the language of the editor}.
|
|
19
|
+
*
|
|
20
|
+
* @param options Locale configuration.
|
|
21
|
+
* @param options.uiLanguage The editor UI language code in the
|
|
22
|
+
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
|
|
23
|
+
* @param options.contentLanguage The editor content language code in the
|
|
24
|
+
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
|
|
25
|
+
* See {@link #contentLanguage}.
|
|
26
|
+
*/
|
|
27
|
+
constructor({ uiLanguage = 'en', contentLanguage } = {}) {
|
|
28
|
+
this.uiLanguage = uiLanguage;
|
|
29
|
+
this.contentLanguage = contentLanguage || this.uiLanguage;
|
|
30
|
+
this.uiLanguageDirection = getLanguageDirection(this.uiLanguage);
|
|
31
|
+
this.contentLanguageDirection = getLanguageDirection(this.contentLanguage);
|
|
32
|
+
this.t = (message, values) => this._t(message, values);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
36
|
+
*
|
|
37
|
+
* **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
|
|
38
|
+
* properties instead.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated
|
|
41
|
+
*/
|
|
42
|
+
get language() {
|
|
43
|
+
/**
|
|
44
|
+
* The {@link module:utils/locale~Locale#language `Locale#language`} property was deprecated and will
|
|
45
|
+
* be removed in the near future. Please use the {@link module:utils/locale~Locale#uiLanguage `Locale#uiLanguage`} and
|
|
46
|
+
* {@link module:utils/locale~Locale#contentLanguage `Locale#contentLanguage`} properties instead.
|
|
47
|
+
*
|
|
48
|
+
* @error locale-deprecated-language-property
|
|
49
|
+
*/
|
|
50
|
+
console.warn('locale-deprecated-language-property: ' +
|
|
51
|
+
'The Locale#language property has been deprecated and will be removed in the near future. ' +
|
|
52
|
+
'Please use #uiLanguage and #contentLanguage properties instead.');
|
|
53
|
+
return this.uiLanguage;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* An unbound version of the {@link #t} method.
|
|
57
|
+
*/
|
|
58
|
+
_t(message, values = []) {
|
|
59
|
+
values = toArray(values);
|
|
60
|
+
if (typeof message === 'string') {
|
|
61
|
+
message = { string: message };
|
|
62
|
+
}
|
|
63
|
+
const hasPluralForm = !!message.plural;
|
|
64
|
+
const quantity = hasPluralForm ? values[0] : 1;
|
|
65
|
+
const translatedString = _translate(this.uiLanguage, message, quantity);
|
|
66
|
+
return interpolateString(translatedString, values);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Fills the `%0, %1, ...` string placeholders with values.
|
|
71
|
+
*/
|
|
72
|
+
function interpolateString(string, values) {
|
|
73
|
+
return string.replace(/%(\d+)/g, (match, index) => {
|
|
74
|
+
return (index < values.length) ? values[index] : match;
|
|
75
|
+
});
|
|
76
|
+
}
|
package/src/mapsequal.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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/mapsequal
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Checks whether given `Map`s are equal, that is has same size and same key-value pairs.
|
|
10
|
-
*
|
|
11
|
-
* @param mapA The first map to compare.
|
|
12
|
-
* @param mapB The second map to compare.
|
|
13
|
-
* @returns `true` if given maps are equal, `false` otherwise.
|
|
14
|
-
*/
|
|
15
|
-
export default function mapsEqual<Key>(mapA: Map<Key, unknown>, mapB: Map<Key, unknown>): boolean;
|
|
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/mapsequal
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether given `Map`s are equal, that is has same size and same key-value pairs.
|
|
10
|
+
*
|
|
11
|
+
* @param mapA The first map to compare.
|
|
12
|
+
* @param mapB The second map to compare.
|
|
13
|
+
* @returns `true` if given maps are equal, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export default function mapsEqual<Key>(mapA: Map<Key, unknown>, mapB: Map<Key, unknown>): boolean;
|
package/src/mapsequal.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
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/mapsequal
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Checks whether given `Map`s are equal, that is has same size and same key-value pairs.
|
|
10
|
-
*
|
|
11
|
-
* @param mapA The first map to compare.
|
|
12
|
-
* @param mapB The second map to compare.
|
|
13
|
-
* @returns `true` if given maps are equal, `false` otherwise.
|
|
14
|
-
*/
|
|
15
|
-
export default function mapsEqual(mapA, mapB) {
|
|
16
|
-
if (mapA.size != mapB.size) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
for (const attr of mapA.entries()) {
|
|
20
|
-
const valA = JSON.stringify(attr[1]);
|
|
21
|
-
const valB = JSON.stringify(mapB.get(attr[0]));
|
|
22
|
-
if (valA !== valB) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
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/mapsequal
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether given `Map`s are equal, that is has same size and same key-value pairs.
|
|
10
|
+
*
|
|
11
|
+
* @param mapA The first map to compare.
|
|
12
|
+
* @param mapB The second map to compare.
|
|
13
|
+
* @returns `true` if given maps are equal, `false` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export default function mapsEqual(mapA, mapB) {
|
|
16
|
+
if (mapA.size != mapB.size) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
for (const attr of mapA.entries()) {
|
|
20
|
+
const valA = JSON.stringify(attr[1]);
|
|
21
|
+
const valB = JSON.stringify(mapB.get(attr[0]));
|
|
22
|
+
if (valA !== valB) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
package/src/mix.d.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
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/mix
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
10
|
-
* prototype of first object (a constructor).
|
|
11
|
-
*
|
|
12
|
-
* ```
|
|
13
|
-
* class Editor {
|
|
14
|
-
* ...
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* const SomeMixin = {
|
|
18
|
-
* a() {
|
|
19
|
-
* return 'a';
|
|
20
|
-
* }
|
|
21
|
-
* };
|
|
22
|
-
*
|
|
23
|
-
* mix( Editor, SomeMixin, ... );
|
|
24
|
-
*
|
|
25
|
-
* new Editor().a(); // -> 'a'
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
|
-
*
|
|
30
|
-
* @deprecated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
|
|
31
|
-
* @param baseClass Class which prototype will be extended.
|
|
32
|
-
* @param mixins Objects from which to get properties.
|
|
33
|
-
*/
|
|
34
|
-
export default function mix(baseClass: Function, ...mixins: Array<object>): void;
|
|
35
|
-
/**
|
|
36
|
-
* Helper type that represents constructor creating given objects. Can be used as a type constraint.
|
|
37
|
-
*
|
|
38
|
-
* ```ts
|
|
39
|
-
* // The function accepts any class constructor.
|
|
40
|
-
* function MyFunction<Ctor extends Constructor>( ctor: Ctor ) {
|
|
41
|
-
* // ...
|
|
42
|
-
* }
|
|
43
|
-
*
|
|
44
|
-
* // The function accepts any class constructor of type derived from `MyBase`.
|
|
45
|
-
* function MyFunction<Ctor extends Constructor<MyBase>>( ctor: Ctor ) {
|
|
46
|
-
* // ...
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export type Constructor<Instance = object> = abstract new (...args: Array<any>) => Instance;
|
|
51
|
-
/**
|
|
52
|
-
* Helper type that creates constructor types from a base class and a mixin interface.
|
|
53
|
-
*
|
|
54
|
-
* ```ts
|
|
55
|
-
* interface MyMixinInterface {
|
|
56
|
-
* mixinMethod(): void;
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* function MyMixin<Base extends Constructor>( base: Base ): Mixed<Base, MyMixinInterface> {
|
|
60
|
-
* // ...
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* class BaseClass {
|
|
64
|
-
* baseMethod(): void {
|
|
65
|
-
* // ...
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* const MixedClass = MyMixin( BaseClass );
|
|
70
|
-
*
|
|
71
|
-
* // Contains both `mixinMethod()` and `baseMethod()`.
|
|
72
|
-
* const myObject = new MixedClass();
|
|
73
|
-
* myObject.mixinMethod();
|
|
74
|
-
* myObject.baseMethod();
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @typeParam Base A type of constructor of a class to apply mixin to.
|
|
78
|
-
* @typeParam Mixin An interface representing mixin.
|
|
79
|
-
*/
|
|
80
|
-
export type Mixed<Base extends Constructor, Mixin extends object> = {
|
|
81
|
-
new (...args: ConstructorParameters<Base>): Mixin & InstanceType<Base>;
|
|
82
|
-
prototype: Mixin & InstanceType<Base>;
|
|
83
|
-
} & {
|
|
84
|
-
[K in keyof Base]: Base[K];
|
|
85
|
-
};
|
|
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/mix
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
10
|
+
* prototype of first object (a constructor).
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* class Editor {
|
|
14
|
+
* ...
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* const SomeMixin = {
|
|
18
|
+
* a() {
|
|
19
|
+
* return 'a';
|
|
20
|
+
* }
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* mix( Editor, SomeMixin, ... );
|
|
24
|
+
*
|
|
25
|
+
* new Editor().a(); // -> 'a'
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
|
|
31
|
+
* @param baseClass Class which prototype will be extended.
|
|
32
|
+
* @param mixins Objects from which to get properties.
|
|
33
|
+
*/
|
|
34
|
+
export default function mix(baseClass: Function, ...mixins: Array<object>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Helper type that represents constructor creating given objects. Can be used as a type constraint.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* // The function accepts any class constructor.
|
|
40
|
+
* function MyFunction<Ctor extends Constructor>( ctor: Ctor ) {
|
|
41
|
+
* // ...
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* // The function accepts any class constructor of type derived from `MyBase`.
|
|
45
|
+
* function MyFunction<Ctor extends Constructor<MyBase>>( ctor: Ctor ) {
|
|
46
|
+
* // ...
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export type Constructor<Instance = object> = abstract new (...args: Array<any>) => Instance;
|
|
51
|
+
/**
|
|
52
|
+
* Helper type that creates constructor types from a base class and a mixin interface.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* interface MyMixinInterface {
|
|
56
|
+
* mixinMethod(): void;
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* function MyMixin<Base extends Constructor>( base: Base ): Mixed<Base, MyMixinInterface> {
|
|
60
|
+
* // ...
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* class BaseClass {
|
|
64
|
+
* baseMethod(): void {
|
|
65
|
+
* // ...
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
*
|
|
69
|
+
* const MixedClass = MyMixin( BaseClass );
|
|
70
|
+
*
|
|
71
|
+
* // Contains both `mixinMethod()` and `baseMethod()`.
|
|
72
|
+
* const myObject = new MixedClass();
|
|
73
|
+
* myObject.mixinMethod();
|
|
74
|
+
* myObject.baseMethod();
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @typeParam Base A type of constructor of a class to apply mixin to.
|
|
78
|
+
* @typeParam Mixin An interface representing mixin.
|
|
79
|
+
*/
|
|
80
|
+
export type Mixed<Base extends Constructor, Mixin extends object> = {
|
|
81
|
+
new (...args: ConstructorParameters<Base>): Mixin & InstanceType<Base>;
|
|
82
|
+
prototype: Mixin & InstanceType<Base>;
|
|
83
|
+
} & {
|
|
84
|
+
[K in keyof Base]: Base[K];
|
|
85
|
+
};
|
package/src/mix.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
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/mix
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
10
|
-
* prototype of first object (a constructor).
|
|
11
|
-
*
|
|
12
|
-
* ```
|
|
13
|
-
* class Editor {
|
|
14
|
-
* ...
|
|
15
|
-
* }
|
|
16
|
-
*
|
|
17
|
-
* const SomeMixin = {
|
|
18
|
-
* a() {
|
|
19
|
-
* return 'a';
|
|
20
|
-
* }
|
|
21
|
-
* };
|
|
22
|
-
*
|
|
23
|
-
* mix( Editor, SomeMixin, ... );
|
|
24
|
-
*
|
|
25
|
-
* new Editor().a(); // -> 'a'
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
|
-
*
|
|
30
|
-
* @deprecated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
|
|
31
|
-
* @param baseClass Class which prototype will be extended.
|
|
32
|
-
* @param mixins Objects from which to get properties.
|
|
33
|
-
*/
|
|
34
|
-
export default function mix(baseClass, ...mixins) {
|
|
35
|
-
mixins.forEach(mixin => {
|
|
36
|
-
const propertyNames = Object.getOwnPropertyNames(mixin);
|
|
37
|
-
const propertySymbols = Object.getOwnPropertySymbols(mixin);
|
|
38
|
-
propertyNames.concat(propertySymbols).forEach(key => {
|
|
39
|
-
if (key in baseClass.prototype) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (typeof mixin == 'function' && (key == 'length' || key == 'name' || key == 'prototype')) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const sourceDescriptor = Object.getOwnPropertyDescriptor(mixin, key);
|
|
46
|
-
sourceDescriptor.enumerable = false;
|
|
47
|
-
Object.defineProperty(baseClass.prototype, key, sourceDescriptor);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
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/mix
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
10
|
+
* prototype of first object (a constructor).
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* class Editor {
|
|
14
|
+
* ...
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* const SomeMixin = {
|
|
18
|
+
* a() {
|
|
19
|
+
* return 'a';
|
|
20
|
+
* }
|
|
21
|
+
* };
|
|
22
|
+
*
|
|
23
|
+
* mix( Editor, SomeMixin, ... );
|
|
24
|
+
*
|
|
25
|
+
* new Editor().a(); // -> 'a'
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
|
|
31
|
+
* @param baseClass Class which prototype will be extended.
|
|
32
|
+
* @param mixins Objects from which to get properties.
|
|
33
|
+
*/
|
|
34
|
+
export default function mix(baseClass, ...mixins) {
|
|
35
|
+
mixins.forEach(mixin => {
|
|
36
|
+
const propertyNames = Object.getOwnPropertyNames(mixin);
|
|
37
|
+
const propertySymbols = Object.getOwnPropertySymbols(mixin);
|
|
38
|
+
propertyNames.concat(propertySymbols).forEach(key => {
|
|
39
|
+
if (key in baseClass.prototype) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (typeof mixin == 'function' && (key == 'length' || key == 'name' || key == 'prototype')) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const sourceDescriptor = Object.getOwnPropertyDescriptor(mixin, key);
|
|
46
|
+
sourceDescriptor.enumerable = false;
|
|
47
|
+
Object.defineProperty(baseClass.prototype, key, sourceDescriptor);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
package/src/nth.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
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/nth
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
10
|
-
*
|
|
11
|
-
* If the iterable is a generator, then it consumes **all its items**.
|
|
12
|
-
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
13
|
-
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
14
|
-
* guide to learn differences between these interfaces.
|
|
15
|
-
*/
|
|
16
|
-
export default function nth<T>(index: number, iterable: Iterable<T>): T | null;
|
|
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/nth
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
10
|
+
*
|
|
11
|
+
* If the iterable is a generator, then it consumes **all its items**.
|
|
12
|
+
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
13
|
+
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
14
|
+
* guide to learn differences between these interfaces.
|
|
15
|
+
*/
|
|
16
|
+
export default function nth<T>(index: number, iterable: Iterable<T>): T | null;
|
package/src/nth.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
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/nth
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
10
|
-
*
|
|
11
|
-
* If the iterable is a generator, then it consumes **all its items**.
|
|
12
|
-
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
13
|
-
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
14
|
-
* guide to learn differences between these interfaces.
|
|
15
|
-
*/
|
|
16
|
-
export default function nth(index, iterable) {
|
|
17
|
-
for (const item of iterable) {
|
|
18
|
-
if (index === 0) {
|
|
19
|
-
return item;
|
|
20
|
-
}
|
|
21
|
-
index -= 1;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
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/nth
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
10
|
+
*
|
|
11
|
+
* If the iterable is a generator, then it consumes **all its items**.
|
|
12
|
+
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
13
|
+
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
14
|
+
* guide to learn differences between these interfaces.
|
|
15
|
+
*/
|
|
16
|
+
export default function nth(index, iterable) {
|
|
17
|
+
for (const item of iterable) {
|
|
18
|
+
if (index === 0) {
|
|
19
|
+
return item;
|
|
20
|
+
}
|
|
21
|
+
index -= 1;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
package/src/objecttomap.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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/objecttomap
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Transforms object to map.
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* const map = objectToMap( { 'foo': 1, 'bar': 2 } );
|
|
13
|
-
* map.get( 'foo' ); // 1
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
|
|
17
|
-
*
|
|
18
|
-
* @param obj Object to transform.
|
|
19
|
-
* @returns Map created from object.
|
|
20
|
-
*/
|
|
21
|
-
export default function objectToMap<T>(obj: {
|
|
22
|
-
readonly [key: string]: T;
|
|
23
|
-
} | null | undefined): Map<string, T>;
|
|
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/objecttomap
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Transforms object to map.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const map = objectToMap( { 'foo': 1, 'bar': 2 } );
|
|
13
|
+
* map.get( 'foo' ); // 1
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
|
|
17
|
+
*
|
|
18
|
+
* @param obj Object to transform.
|
|
19
|
+
* @returns Map created from object.
|
|
20
|
+
*/
|
|
21
|
+
export default function objectToMap<T>(obj: {
|
|
22
|
+
readonly [key: string]: T;
|
|
23
|
+
} | null | undefined): Map<string, T>;
|