@ckeditor/ckeditor5-utils 34.2.0 → 35.0.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 +0 -92
- package/src/ckeditorerror.js +0 -217
- package/src/collection.js +0 -785
- package/src/comparearrays.js +0 -51
- package/src/config.js +0 -246
- package/src/count.js +0 -26
- package/src/diff.js +0 -138
- package/src/difftochanges.js +0 -86
- package/src/dom/createelement.js +0 -49
- package/src/dom/emittermixin.js +0 -341
- package/src/dom/getancestors.js +0 -31
- package/src/dom/getborderwidths.js +0 -27
- package/src/dom/getcommonancestor.js +0 -31
- package/src/dom/getdatafromelement.js +0 -24
- package/src/dom/getpositionedancestor.js +0 -28
- package/src/dom/global.js +0 -26
- package/src/dom/indexof.js +0 -25
- package/src/dom/insertat.js +0 -19
- package/src/dom/iscomment.js +0 -20
- package/src/dom/isnode.js +0 -26
- package/src/dom/isrange.js +0 -18
- package/src/dom/istext.js +0 -18
- package/src/dom/isvisible.js +0 -25
- package/src/dom/iswindow.js +0 -30
- package/src/dom/position.js +0 -518
- package/src/dom/rect.js +0 -443
- package/src/dom/remove.js +0 -21
- package/src/dom/resizeobserver.js +0 -378
- package/src/dom/scroll.js +0 -302
- package/src/dom/setdatainelement.js +0 -24
- package/src/dom/tounit.js +0 -27
- package/src/elementreplacer.js +0 -57
- package/src/emittermixin.js +0 -719
- package/src/env.js +0 -190
- package/src/eventinfo.js +0 -79
- package/src/fastdiff.js +0 -261
- package/src/first.js +0 -24
- package/src/focustracker.js +0 -157
- package/src/index.js +0 -45
- package/src/inserttopriorityarray.js +0 -42
- package/src/isiterable.js +0 -18
- package/src/keyboard.js +0 -301
- package/src/keystrokehandler.js +0 -130
- package/src/language.js +0 -26
- package/src/locale.js +0 -176
- package/src/mapsequal.js +0 -32
- package/src/mix.js +0 -47
- package/src/nth.js +0 -31
- package/src/objecttomap.js +0 -29
- package/src/observablemixin.js +0 -908
- package/src/priorities.js +0 -44
- package/src/spy.js +0 -25
- package/src/toarray.js +0 -18
- package/src/tomap.js +0 -29
- package/src/translation-service.js +0 -216
- package/src/uid.js +0 -59
- package/src/unicode.js +0 -106
- package/src/version.js +0 -157
package/src/language.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/language
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const RTL_LANGUAGE_CODES = [
|
|
11
|
-
'ar', 'ara', // Arabic
|
|
12
|
-
'fa', 'per', 'fas', // Persian
|
|
13
|
-
'he', 'heb', // Hebrew
|
|
14
|
-
'ku', 'kur', // Kurdish
|
|
15
|
-
'ug', 'uig' // Uighur, Uyghur
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Helps determine whether a language text direction is LTR or RTL.
|
|
20
|
-
*
|
|
21
|
-
* @param {String} language The ISO 639-1 or ISO 639-2 language code.
|
|
22
|
-
* @returns {'ltr'|'rtl'}
|
|
23
|
-
*/
|
|
24
|
-
export function getLanguageDirection( languageCode ) {
|
|
25
|
-
return RTL_LANGUAGE_CODES.includes( languageCode ) ? 'rtl' : 'ltr';
|
|
26
|
-
}
|
package/src/locale.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/locale
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/* globals console */
|
|
11
|
-
|
|
12
|
-
import toArray from './toarray';
|
|
13
|
-
import { _translate } from './translation-service';
|
|
14
|
-
import { getLanguageDirection } from './language';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Represents the localization services.
|
|
18
|
-
*/
|
|
19
|
-
export default class Locale {
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new instance of the locale class. Learn more about
|
|
22
|
-
* {@glink features/ui-language configuring the language of the editor}.
|
|
23
|
-
*
|
|
24
|
-
* @param {Object} [options] Locale configuration.
|
|
25
|
-
* @param {String} [options.uiLanguage='en'] The editor UI language code in the
|
|
26
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
|
|
27
|
-
* @param {String} [options.contentLanguage] The editor content language code in the
|
|
28
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
|
|
29
|
-
* See {@link #contentLanguage}.
|
|
30
|
-
*/
|
|
31
|
-
constructor( options = {} ) {
|
|
32
|
-
/**
|
|
33
|
-
* The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
34
|
-
*
|
|
35
|
-
* If the {@link #contentLanguage content language} was not specified in the `Locale` constructor,
|
|
36
|
-
* it also defines the language of the content.
|
|
37
|
-
*
|
|
38
|
-
* @readonly
|
|
39
|
-
* @member {String}
|
|
40
|
-
*/
|
|
41
|
-
this.uiLanguage = options.uiLanguage || 'en';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
45
|
-
*
|
|
46
|
-
* Usually the same as the {@link #uiLanguage editor language}, it can be customized by passing an optional
|
|
47
|
-
* argument to the `Locale` constructor.
|
|
48
|
-
*
|
|
49
|
-
* @readonly
|
|
50
|
-
* @member {String}
|
|
51
|
-
*/
|
|
52
|
-
this.contentLanguage = options.contentLanguage || this.uiLanguage;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Text direction of the {@link #uiLanguage editor UI language}. Either `'ltr'` or `'rtl'`.
|
|
56
|
-
*
|
|
57
|
-
* @readonly
|
|
58
|
-
* @member {String}
|
|
59
|
-
*/
|
|
60
|
-
this.uiLanguageDirection = getLanguageDirection( this.uiLanguage );
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Text direction of the {@link #contentLanguage editor content language}.
|
|
64
|
-
*
|
|
65
|
-
* If the content language was passed directly to the `Locale` constructor, this property represents the
|
|
66
|
-
* direction of that language.
|
|
67
|
-
*
|
|
68
|
-
* If the {@link #contentLanguage editor content language} was derived from the {@link #uiLanguage editor language},
|
|
69
|
-
* the content language direction is the same as the {@link #uiLanguageDirection UI language direction}.
|
|
70
|
-
*
|
|
71
|
-
* The value is either `'ltr'` or `'rtl'`.
|
|
72
|
-
*
|
|
73
|
-
* @readonly
|
|
74
|
-
* @member {String}
|
|
75
|
-
*/
|
|
76
|
-
this.contentLanguageDirection = getLanguageDirection( this.contentLanguage );
|
|
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
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Fills the `%0, %1, ...` string placeholders with values.
|
|
172
|
-
function interpolateString( string, values ) {
|
|
173
|
-
return string.replace( /%(\d+)/g, ( match, index ) => {
|
|
174
|
-
return ( index < values.length ) ? values[ index ] : match;
|
|
175
|
-
} );
|
|
176
|
-
}
|
package/src/mapsequal.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/mapsequal
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Checks whether given {Map}s are equal, that is has same size and same key-value pairs.
|
|
12
|
-
*
|
|
13
|
-
* @param {Map} mapA The first map to compare.
|
|
14
|
-
* @param {Map} mapB The second map to compare.
|
|
15
|
-
* @returns {Boolean} `true` if given maps are equal, `false` otherwise.
|
|
16
|
-
*/
|
|
17
|
-
export default function mapsEqual( mapA, mapB ) {
|
|
18
|
-
if ( mapA.size != mapB.size ) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
for ( const attr of mapA.entries() ) {
|
|
23
|
-
const valA = JSON.stringify( attr[ 1 ] );
|
|
24
|
-
const valB = JSON.stringify( mapB.get( attr[ 0 ] ) );
|
|
25
|
-
|
|
26
|
-
if ( valA !== valB ) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return true;
|
|
32
|
-
}
|
package/src/mix.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/mix
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
12
|
-
* prototype of first object (a constructor).
|
|
13
|
-
*
|
|
14
|
-
* class Editor {
|
|
15
|
-
* ...
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* const SomeMixin = {
|
|
19
|
-
* a() {
|
|
20
|
-
* return 'a';
|
|
21
|
-
* }
|
|
22
|
-
* };
|
|
23
|
-
*
|
|
24
|
-
* mix( Editor, SomeMixin, ... );
|
|
25
|
-
*
|
|
26
|
-
* new Editor().a(); // -> 'a'
|
|
27
|
-
*
|
|
28
|
-
* Note: Properties which already exist in the base class will not be overriden.
|
|
29
|
-
*
|
|
30
|
-
* @param {Function} [baseClass] Class which prototype will be extended.
|
|
31
|
-
* @param {Object} [...mixins] Objects from which to get properties.
|
|
32
|
-
*/
|
|
33
|
-
export default function mix( baseClass, ...mixins ) {
|
|
34
|
-
mixins.forEach( mixin => {
|
|
35
|
-
Object.getOwnPropertyNames( mixin ).concat( Object.getOwnPropertySymbols( mixin ) )
|
|
36
|
-
.forEach( key => {
|
|
37
|
-
if ( key in baseClass.prototype ) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const sourceDescriptor = Object.getOwnPropertyDescriptor( mixin, key );
|
|
42
|
-
sourceDescriptor.enumerable = false;
|
|
43
|
-
|
|
44
|
-
Object.defineProperty( baseClass.prototype, key, sourceDescriptor );
|
|
45
|
-
} );
|
|
46
|
-
} );
|
|
47
|
-
}
|
package/src/nth.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/nth
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns `nth` (starts from `0` of course) item of the given `iterable`.
|
|
12
|
-
*
|
|
13
|
-
* If the iterable is a generator, then it consumes **all its items**.
|
|
14
|
-
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
15
|
-
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
16
|
-
* guide to learn differences between these interfaces.
|
|
17
|
-
*
|
|
18
|
-
* @param {Number} index
|
|
19
|
-
* @param {Iterable.<*>} iterable
|
|
20
|
-
* @returns {*}
|
|
21
|
-
*/
|
|
22
|
-
export default function nth( index, iterable ) {
|
|
23
|
-
for ( const item of iterable ) {
|
|
24
|
-
if ( index === 0 ) {
|
|
25
|
-
return item;
|
|
26
|
-
}
|
|
27
|
-
index -= 1;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return null;
|
|
31
|
-
}
|
package/src/objecttomap.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2022, 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
|
-
/**
|
|
7
|
-
* @module utils/objecttomap
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Transforms object to map.
|
|
12
|
-
*
|
|
13
|
-
* const map = objectToMap( { 'foo': 1, 'bar': 2 } );
|
|
14
|
-
* map.get( 'foo' ); // 1
|
|
15
|
-
*
|
|
16
|
-
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} obj Object to transform.
|
|
19
|
-
* @returns {Map} Map created from object.
|
|
20
|
-
*/
|
|
21
|
-
export default function objectToMap( obj ) {
|
|
22
|
-
const map = new Map();
|
|
23
|
-
|
|
24
|
-
for ( const key in obj ) {
|
|
25
|
-
map.set( key, obj[ key ] );
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return map;
|
|
29
|
-
}
|