@ckeditor/ckeditor5-utils 34.2.0 → 35.1.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 +324 -0
- package/LICENSE.md +1 -1
- package/package.json +19 -8
- package/src/areconnectedthroughproperties.js +54 -71
- package/src/ckeditorerror.js +92 -114
- package/src/collection.js +594 -762
- package/src/comparearrays.js +22 -28
- package/src/config.js +193 -223
- package/src/count.js +8 -12
- package/src/diff.js +85 -110
- package/src/difftochanges.js +47 -57
- package/src/dom/createelement.js +17 -25
- package/src/dom/emittermixin.js +202 -263
- package/src/dom/getancestors.js +9 -13
- package/src/dom/getborderwidths.js +10 -13
- package/src/dom/getcommonancestor.js +9 -15
- package/src/dom/getdatafromelement.js +5 -9
- package/src/dom/getpositionedancestor.js +9 -14
- package/src/dom/global.js +15 -4
- package/src/dom/indexof.js +7 -11
- package/src/dom/insertat.js +2 -4
- package/src/dom/iscomment.js +2 -5
- package/src/dom/isnode.js +10 -12
- package/src/dom/isrange.js +2 -4
- package/src/dom/istext.js +2 -4
- package/src/dom/isvisible.js +2 -4
- package/src/dom/iswindow.js +11 -16
- package/src/dom/position.js +220 -410
- package/src/dom/rect.js +335 -414
- package/src/dom/remove.js +5 -8
- package/src/dom/resizeobserver.js +109 -342
- package/src/dom/scroll.js +151 -183
- package/src/dom/setdatainelement.js +5 -9
- package/src/dom/tounit.js +10 -12
- package/src/elementreplacer.js +30 -44
- package/src/emittermixin.js +368 -634
- package/src/env.js +109 -116
- package/src/eventinfo.js +12 -65
- package/src/fastdiff.js +96 -128
- package/src/first.js +8 -12
- package/src/focustracker.js +77 -133
- package/src/index.js +0 -9
- package/src/inserttopriorityarray.js +9 -30
- package/src/isiterable.js +2 -4
- package/src/keyboard.js +117 -196
- package/src/keystrokehandler.js +72 -88
- package/src/language.js +9 -15
- package/src/locale.js +61 -158
- package/src/mapsequal.js +12 -17
- package/src/mix.js +17 -16
- package/src/nth.js +8 -11
- package/src/objecttomap.js +7 -11
- package/src/observablemixin.js +474 -778
- package/src/priorities.js +20 -32
- package/src/spy.js +3 -6
- package/src/toarray.js +2 -13
- package/src/tomap.js +8 -10
- package/src/translation-service.js +57 -93
- package/src/uid.js +34 -38
- package/src/unicode.js +28 -43
- package/src/version.js +134 -143
package/src/locale.js
CHANGED
|
@@ -2,175 +2,78 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/locale
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/* globals console */
|
|
11
|
-
|
|
12
9
|
import toArray from './toarray';
|
|
13
10
|
import { _translate } from './translation-service';
|
|
14
11
|
import { getLanguageDirection } from './language';
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* Represents the localization services.
|
|
18
14
|
*/
|
|
19
15
|
export default class Locale {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Translates the given message to the {@link #uiLanguage}. This method is also available in
|
|
80
|
-
* {@link module:core/editor/editor~Editor#t `Editor`} and {@link module:ui/view~View#t `View`}.
|
|
81
|
-
*
|
|
82
|
-
* This method's context is statically bound to the `Locale` instance and **should always be called as a function**:
|
|
83
|
-
*
|
|
84
|
-
* const t = locale.t;
|
|
85
|
-
* t( 'Label' );
|
|
86
|
-
*
|
|
87
|
-
* The message can be either a string or an object implementing the {@link module:utils/translation-service~Message} interface.
|
|
88
|
-
*
|
|
89
|
-
* The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter.
|
|
90
|
-
* For an array of values, the `%<index>` will be changed to an element of that array at the given index.
|
|
91
|
-
* For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.
|
|
92
|
-
*
|
|
93
|
-
* t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
|
|
94
|
-
* t( 'Created file "%0", fileName );
|
|
95
|
-
*
|
|
96
|
-
* The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form
|
|
97
|
-
* will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used
|
|
98
|
-
* as a default plural translation when the translation for the target language is missing.
|
|
99
|
-
*
|
|
100
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
|
|
101
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
|
|
102
|
-
* t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.
|
|
103
|
-
*
|
|
104
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
|
|
105
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
|
|
106
|
-
* t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
|
|
107
|
-
*
|
|
108
|
-
* * The message should provide an ID using the `id` property when the message strings are not unique and their
|
|
109
|
-
* translations should be different.
|
|
110
|
-
*
|
|
111
|
-
* translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
|
|
112
|
-
* translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
|
|
113
|
-
*
|
|
114
|
-
* @method #t
|
|
115
|
-
* @param {String|module:utils/translation-service~Message} message A message that will be localized (translated).
|
|
116
|
-
* @param {String|Number|Array.<String|Number>} [values] A value or an array of values that will fill message placeholders.
|
|
117
|
-
* For messages supporting plural forms the first value will determine the plural form.
|
|
118
|
-
* @returns {String}
|
|
119
|
-
*/
|
|
120
|
-
this.t = ( message, values ) => this._t( message, values );
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
125
|
-
*
|
|
126
|
-
* **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
|
|
127
|
-
* properties instead.
|
|
128
|
-
*
|
|
129
|
-
* @deprecated
|
|
130
|
-
* @member {String}
|
|
131
|
-
*/
|
|
132
|
-
get language() {
|
|
133
|
-
/**
|
|
134
|
-
* The {@link module:utils/locale~Locale#language `Locale#language`} property was deprecated and will
|
|
135
|
-
* be removed in the near future. Please use the {@link #uiLanguage} and {@link #contentLanguage} properties instead.
|
|
136
|
-
*
|
|
137
|
-
* @error locale-deprecated-language-property
|
|
138
|
-
*/
|
|
139
|
-
console.warn(
|
|
140
|
-
'locale-deprecated-language-property: ' +
|
|
141
|
-
'The Locale#language property has been deprecated and will be removed in the near future. ' +
|
|
142
|
-
'Please use #uiLanguage and #contentLanguage properties instead.' );
|
|
143
|
-
|
|
144
|
-
return this.uiLanguage;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* An unbound version of the {@link #t} method.
|
|
149
|
-
*
|
|
150
|
-
* @private
|
|
151
|
-
* @param {String|module:utils/translation-service~Message} message
|
|
152
|
-
* @param {Number|String|Array.<Number|String>} [values]
|
|
153
|
-
* @returns {String}
|
|
154
|
-
*/
|
|
155
|
-
_t( message, values = [] ) {
|
|
156
|
-
values = toArray( values );
|
|
157
|
-
|
|
158
|
-
if ( typeof message === 'string' ) {
|
|
159
|
-
message = { string: message };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const hasPluralForm = !!message.plural;
|
|
163
|
-
const quantity = hasPluralForm ? values[ 0 ] : 1;
|
|
164
|
-
|
|
165
|
-
const translatedString = _translate( this.uiLanguage, message, quantity );
|
|
166
|
-
|
|
167
|
-
return interpolateString( translatedString, values );
|
|
168
|
-
}
|
|
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 {Object} [options] Locale configuration.
|
|
21
|
+
* @param {String} [options.uiLanguage='en'] 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 {String} [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(options = {}) {
|
|
28
|
+
this.uiLanguage = options.uiLanguage || 'en';
|
|
29
|
+
this.contentLanguage = options.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
|
+
* @member {String}
|
|
42
|
+
*/
|
|
43
|
+
get language() {
|
|
44
|
+
/**
|
|
45
|
+
* The {@link module:utils/locale~Locale#language `Locale#language`} property was deprecated and will
|
|
46
|
+
* be removed in the near future. Please use the {@link #uiLanguage} and {@link #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
|
+
* @private
|
|
59
|
+
* @param {String|module:utils/translation-service~Message} message
|
|
60
|
+
* @param {Number|String|Array.<Number|String>} [values]
|
|
61
|
+
* @returns {String}
|
|
62
|
+
*/
|
|
63
|
+
_t(message, values = []) {
|
|
64
|
+
values = toArray(values);
|
|
65
|
+
if (typeof message === 'string') {
|
|
66
|
+
message = { string: message };
|
|
67
|
+
}
|
|
68
|
+
const hasPluralForm = !!message.plural;
|
|
69
|
+
const quantity = hasPluralForm ? values[0] : 1;
|
|
70
|
+
const translatedString = _translate(this.uiLanguage, message, quantity);
|
|
71
|
+
return interpolateString(translatedString, values);
|
|
72
|
+
}
|
|
169
73
|
}
|
|
170
|
-
|
|
171
74
|
// Fills the `%0, %1, ...` string placeholders with values.
|
|
172
|
-
function interpolateString(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
75
|
+
function interpolateString(string, values) {
|
|
76
|
+
return string.replace(/%(\d+)/g, (match, index) => {
|
|
77
|
+
return (index < values.length) ? values[index] : match;
|
|
78
|
+
});
|
|
176
79
|
}
|
package/src/mapsequal.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/mapsequal
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Checks whether given {Map}s are equal, that is has same size and same key-value pairs.
|
|
12
10
|
*
|
|
@@ -14,19 +12,16 @@
|
|
|
14
12
|
* @param {Map} mapB The second map to compare.
|
|
15
13
|
* @returns {Boolean} `true` if given maps are equal, `false` otherwise.
|
|
16
14
|
*/
|
|
17
|
-
export default function mapsEqual(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return true;
|
|
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;
|
|
32
27
|
}
|
package/src/mix.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/mix
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
12
10
|
* prototype of first object (a constructor).
|
|
@@ -27,21 +25,24 @@
|
|
|
27
25
|
*
|
|
28
26
|
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
27
|
*
|
|
28
|
+
* @depreciated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
|
|
30
29
|
* @param {Function} [baseClass] Class which prototype will be extended.
|
|
31
30
|
* @param {Object} [...mixins] Objects from which to get properties.
|
|
32
31
|
*/
|
|
33
|
-
export default function mix(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
export default function mix(baseClass, ...mixins) {
|
|
33
|
+
mixins.forEach(mixin => {
|
|
34
|
+
const propertyNames = Object.getOwnPropertyNames(mixin);
|
|
35
|
+
const propertySymbols = Object.getOwnPropertySymbols(mixin);
|
|
36
|
+
propertyNames.concat(propertySymbols).forEach(key => {
|
|
37
|
+
if (key in baseClass.prototype) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (typeof mixin == 'function' && (key == 'length' || key == 'name' || key == 'prototype')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const sourceDescriptor = Object.getOwnPropertyDescriptor(mixin, key);
|
|
44
|
+
sourceDescriptor.enumerable = false;
|
|
45
|
+
Object.defineProperty(baseClass.prototype, key, sourceDescriptor);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
47
48
|
}
|
package/src/nth.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/nth
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
12
10
|
*
|
|
@@ -19,13 +17,12 @@
|
|
|
19
17
|
* @param {Iterable.<*>} iterable
|
|
20
18
|
* @returns {*}
|
|
21
19
|
*/
|
|
22
|
-
export default function nth(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return null;
|
|
20
|
+
export default function nth(index, iterable) {
|
|
21
|
+
for (const item of iterable) {
|
|
22
|
+
if (index === 0) {
|
|
23
|
+
return item;
|
|
24
|
+
}
|
|
25
|
+
index -= 1;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
31
28
|
}
|
package/src/objecttomap.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* @module utils/objecttomap
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Transforms object to map.
|
|
12
10
|
*
|
|
@@ -15,15 +13,13 @@
|
|
|
15
13
|
*
|
|
16
14
|
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
|
|
17
15
|
*
|
|
18
|
-
* @param {Object} obj Object to transform.
|
|
16
|
+
* @param {Object|null} obj Object to transform.
|
|
19
17
|
* @returns {Map} Map created from object.
|
|
20
18
|
*/
|
|
21
|
-
export default function objectToMap(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return map;
|
|
19
|
+
export default function objectToMap(obj) {
|
|
20
|
+
const map = new Map();
|
|
21
|
+
for (const key in obj) {
|
|
22
|
+
map.set(key, obj[key]);
|
|
23
|
+
}
|
|
24
|
+
return map;
|
|
29
25
|
}
|