@ckeditor/ckeditor5-utils 47.6.1 → 48.0.0-alpha.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/LICENSE.md +1 -1
- package/{src → dist}/dom/global.d.ts +1 -1
- package/{src → dist}/dom/rect.d.ts +8 -0
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +24 -5
- package/dist/index.js.map +1 -1
- package/{src → dist}/version.d.ts +1 -1
- package/package.json +20 -38
- package/src/abortabledebounce.js +0 -22
- package/src/areconnectedthroughproperties.js +0 -71
- package/src/ckeditorerror.js +0 -187
- package/src/collection.js +0 -620
- package/src/collectstylesheets.js +0 -52
- package/src/comparearrays.js +0 -47
- package/src/config.js +0 -167
- package/src/count.js +0 -25
- package/src/crc32.js +0 -61
- package/src/decodelicensekey.js +0 -30
- package/src/delay.js +0 -25
- package/src/diff.js +0 -115
- package/src/difftochanges.js +0 -79
- package/src/dom/createelement.js +0 -40
- package/src/dom/emittermixin.js +0 -237
- package/src/dom/findclosestscrollableancestor.js +0 -31
- package/src/dom/getancestors.js +0 -26
- package/src/dom/getborderwidths.js +0 -24
- package/src/dom/getcommonancestor.js +0 -25
- package/src/dom/getdatafromelement.js +0 -19
- package/src/dom/getpositionedancestor.js +0 -22
- package/src/dom/getrangefrommouseevent.js +0 -33
- package/src/dom/getvisualviewportoffset.js +0 -21
- package/src/dom/global.js +0 -35
- package/src/dom/indexof.js +0 -21
- package/src/dom/insertat.js +0 -17
- package/src/dom/iscomment.js +0 -13
- package/src/dom/isnode.js +0 -21
- package/src/dom/isrange.js +0 -13
- package/src/dom/istext.js +0 -13
- package/src/dom/isvalidattributename.js +0 -22
- package/src/dom/isvisible.js +0 -30
- package/src/dom/iswindow.js +0 -22
- package/src/dom/position.js +0 -322
- package/src/dom/rect.js +0 -498
- package/src/dom/remove.js +0 -18
- package/src/dom/resizeobserver.js +0 -134
- package/src/dom/scroll.js +0 -406
- package/src/dom/setdatainelement.js +0 -19
- package/src/dom/tounit.js +0 -16
- package/src/elementreplacer.js +0 -47
- package/src/emittermixin.js +0 -443
- package/src/env.js +0 -158
- package/src/eventinfo.js +0 -63
- package/src/fastdiff.js +0 -248
- package/src/first.js +0 -17
- package/src/focustracker.js +0 -329
- package/src/formathtml.js +0 -164
- package/src/index.js +0 -78
- package/src/inserttopriorityarray.js +0 -28
- package/src/isfeatureblockedbylicensekey.js +0 -17
- package/src/isiterable.js +0 -16
- package/src/keyboard.js +0 -256
- package/src/keystrokehandler.js +0 -126
- package/src/language.js +0 -21
- package/src/legacyerrors.js +0 -18
- package/src/locale.js +0 -135
- package/src/mapsequal.js +0 -27
- package/src/mix.js +0 -5
- package/src/nth.js +0 -24
- package/src/objecttomap.js +0 -27
- package/src/observablemixin.js +0 -575
- package/src/parsebase64encodedobject.js +0 -22
- package/src/priorities.js +0 -22
- package/src/retry.js +0 -48
- package/src/splicearray.js +0 -37
- package/src/spy.js +0 -21
- package/src/toarray.js +0 -7
- package/src/tomap.js +0 -29
- package/src/translation-service.js +0 -209
- package/src/uid.js +0 -45
- package/src/unicode.js +0 -85
- package/src/version.js +0 -177
- package/src/wait.js +0 -29
- /package/{src → dist}/abortabledebounce.d.ts +0 -0
- /package/{src → dist}/areconnectedthroughproperties.d.ts +0 -0
- /package/{src → dist}/ckeditorerror.d.ts +0 -0
- /package/{src → dist}/collection.d.ts +0 -0
- /package/{src → dist}/collectstylesheets.d.ts +0 -0
- /package/{src → dist}/comparearrays.d.ts +0 -0
- /package/{src → dist}/config.d.ts +0 -0
- /package/{src → dist}/count.d.ts +0 -0
- /package/{src → dist}/crc32.d.ts +0 -0
- /package/{src → dist}/decodelicensekey.d.ts +0 -0
- /package/{src → dist}/delay.d.ts +0 -0
- /package/{src → dist}/diff.d.ts +0 -0
- /package/{src → dist}/difftochanges.d.ts +0 -0
- /package/{src → dist}/dom/createelement.d.ts +0 -0
- /package/{src → dist}/dom/emittermixin.d.ts +0 -0
- /package/{src → dist}/dom/findclosestscrollableancestor.d.ts +0 -0
- /package/{src → dist}/dom/getancestors.d.ts +0 -0
- /package/{src → dist}/dom/getborderwidths.d.ts +0 -0
- /package/{src → dist}/dom/getcommonancestor.d.ts +0 -0
- /package/{src → dist}/dom/getdatafromelement.d.ts +0 -0
- /package/{src → dist}/dom/getpositionedancestor.d.ts +0 -0
- /package/{src → dist}/dom/getrangefrommouseevent.d.ts +0 -0
- /package/{src → dist}/dom/getvisualviewportoffset.d.ts +0 -0
- /package/{src → dist}/dom/indexof.d.ts +0 -0
- /package/{src → dist}/dom/insertat.d.ts +0 -0
- /package/{src → dist}/dom/iscomment.d.ts +0 -0
- /package/{src → dist}/dom/isnode.d.ts +0 -0
- /package/{src → dist}/dom/isrange.d.ts +0 -0
- /package/{src → dist}/dom/istext.d.ts +0 -0
- /package/{src → dist}/dom/isvalidattributename.d.ts +0 -0
- /package/{src → dist}/dom/isvisible.d.ts +0 -0
- /package/{src → dist}/dom/iswindow.d.ts +0 -0
- /package/{src → dist}/dom/position.d.ts +0 -0
- /package/{src → dist}/dom/remove.d.ts +0 -0
- /package/{src → dist}/dom/resizeobserver.d.ts +0 -0
- /package/{src → dist}/dom/scroll.d.ts +0 -0
- /package/{src → dist}/dom/setdatainelement.d.ts +0 -0
- /package/{src → dist}/dom/tounit.d.ts +0 -0
- /package/{src → dist}/elementreplacer.d.ts +0 -0
- /package/{src → dist}/emittermixin.d.ts +0 -0
- /package/{src → dist}/env.d.ts +0 -0
- /package/{src → dist}/eventinfo.d.ts +0 -0
- /package/{src → dist}/fastdiff.d.ts +0 -0
- /package/{src → dist}/first.d.ts +0 -0
- /package/{src → dist}/focustracker.d.ts +0 -0
- /package/{src → dist}/formathtml.d.ts +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/inserttopriorityarray.d.ts +0 -0
- /package/{src → dist}/isfeatureblockedbylicensekey.d.ts +0 -0
- /package/{src → dist}/isiterable.d.ts +0 -0
- /package/{src → dist}/keyboard.d.ts +0 -0
- /package/{src → dist}/keystrokehandler.d.ts +0 -0
- /package/{src → dist}/language.d.ts +0 -0
- /package/{src → dist}/legacyerrors.d.ts +0 -0
- /package/{src → dist}/locale.d.ts +0 -0
- /package/{src → dist}/mapsequal.d.ts +0 -0
- /package/{src → dist}/mix.d.ts +0 -0
- /package/{src → dist}/nth.d.ts +0 -0
- /package/{src → dist}/objecttomap.d.ts +0 -0
- /package/{src → dist}/observablemixin.d.ts +0 -0
- /package/{src → dist}/parsebase64encodedobject.d.ts +0 -0
- /package/{src → dist}/priorities.d.ts +0 -0
- /package/{src → dist}/retry.d.ts +0 -0
- /package/{src → dist}/splicearray.d.ts +0 -0
- /package/{src → dist}/spy.d.ts +0 -0
- /package/{src → dist}/toarray.d.ts +0 -0
- /package/{src → dist}/tomap.d.ts +0 -0
- /package/{src → dist}/translation-service.d.ts +0 -0
- /package/{src → dist}/uid.d.ts +0 -0
- /package/{src → dist}/unicode.d.ts +0 -0
- /package/{src → dist}/wait.d.ts +0 -0
package/src/keystrokehandler.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/keystrokehandler
|
|
7
|
-
*/
|
|
8
|
-
import { DomEmitterMixin } from './dom/emittermixin.js';
|
|
9
|
-
import { getCode, parseKeystroke } from './keyboard.js';
|
|
10
|
-
/**
|
|
11
|
-
* Keystroke handler allows registering callbacks for given keystrokes.
|
|
12
|
-
*
|
|
13
|
-
* The most frequent use of this class is through the {@link module:core/editor/editor~Editor#keystrokes `editor.keystrokes`}
|
|
14
|
-
* property. It allows listening to keystrokes executed in the editing view:
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* editor.keystrokes.set( 'Ctrl+A', ( keyEvtData, cancel ) => {
|
|
18
|
-
* console.log( 'Ctrl+A has been pressed' );
|
|
19
|
-
* cancel();
|
|
20
|
-
* } );
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* However, this utility class can be used in various part of the UI. For instance, a certain {@link module:ui/view~View}
|
|
24
|
-
* can use it like this:
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* class MyView extends View {
|
|
28
|
-
* constructor() {
|
|
29
|
-
* this.keystrokes = new KeystrokeHandler();
|
|
30
|
-
*
|
|
31
|
-
* this.keystrokes.set( 'tab', handleTabKey );
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* render() {
|
|
35
|
-
* super.render();
|
|
36
|
-
*
|
|
37
|
-
* this.keystrokes.listenTo( this.element );
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* That keystroke handler will listen to `keydown` events fired in this view's main element.
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
export class KeystrokeHandler {
|
|
46
|
-
/**
|
|
47
|
-
* Listener used to listen to events for easier keystroke handler destruction.
|
|
48
|
-
*/
|
|
49
|
-
_listener;
|
|
50
|
-
/**
|
|
51
|
-
* Creates an instance of the keystroke handler.
|
|
52
|
-
*/
|
|
53
|
-
constructor() {
|
|
54
|
-
this._listener = new (DomEmitterMixin())();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Starts listening for `keydown` events from a given emitter.
|
|
58
|
-
*/
|
|
59
|
-
listenTo(emitter) {
|
|
60
|
-
// The #_listener works here as a kind of dispatcher. It groups the events coming from the same
|
|
61
|
-
// keystroke so the listeners can be attached to them with different priorities.
|
|
62
|
-
//
|
|
63
|
-
// E.g. all the keystrokes with the `keyCode` of 42 coming from the `emitter` are propagated
|
|
64
|
-
// as a `_keydown:42` event by the `_listener`. If there's a callback created by the `set`
|
|
65
|
-
// method for this 42 keystroke, it listens to the `_listener#_keydown:42` event only and interacts
|
|
66
|
-
// only with other listeners of this particular event, thus making it possible to prioritize
|
|
67
|
-
// the listeners and safely cancel execution, when needed. Instead of duplicating the Emitter logic,
|
|
68
|
-
// the KeystrokeHandler re–uses it to do its job.
|
|
69
|
-
this._listener.listenTo(emitter, 'keydown', (evt, keyEvtData) => {
|
|
70
|
-
this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Registers a handler for the specified keystroke.
|
|
75
|
-
*
|
|
76
|
-
* @param keystroke Keystroke defined in a format accepted by
|
|
77
|
-
* the {@link module:utils/keyboard~parseKeystroke} function.
|
|
78
|
-
* @param callback A function called with the
|
|
79
|
-
* {@link module:engine/view/observer/keyobserver~ViewDocumentKeyEventData key event data} object and
|
|
80
|
-
* a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
|
|
81
|
-
* @param options Additional options.
|
|
82
|
-
*/
|
|
83
|
-
set(keystroke, callback, options = {}) {
|
|
84
|
-
const keyCode = parseKeystroke(keystroke);
|
|
85
|
-
const priority = options.priority;
|
|
86
|
-
// Execute the passed callback on KeystrokeHandler#_keydown.
|
|
87
|
-
// TODO: https://github.com/ckeditor/ckeditor5-utils/issues/144
|
|
88
|
-
this._listener.listenTo(this._listener, '_keydown:' + keyCode, (evt, keyEvtData) => {
|
|
89
|
-
if (options.filter && !options.filter(keyEvtData)) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
callback(keyEvtData, () => {
|
|
93
|
-
// Stop the event in the DOM: no listener in the web page
|
|
94
|
-
// will be triggered by this event.
|
|
95
|
-
keyEvtData.preventDefault();
|
|
96
|
-
keyEvtData.stopPropagation();
|
|
97
|
-
// Stop the event in the KeystrokeHandler: no more callbacks
|
|
98
|
-
// will be executed for this keystroke.
|
|
99
|
-
evt.stop();
|
|
100
|
-
});
|
|
101
|
-
// Mark this keystroke as handled by the callback. See: #press.
|
|
102
|
-
evt.return = true;
|
|
103
|
-
}, { priority });
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
|
|
107
|
-
*
|
|
108
|
-
* @param keyEvtData Key event data.
|
|
109
|
-
* @returns Whether the keystroke was handled.
|
|
110
|
-
*/
|
|
111
|
-
press(keyEvtData) {
|
|
112
|
-
return !!this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Stops listening to `keydown` events from the given emitter.
|
|
116
|
-
*/
|
|
117
|
-
stopListening(emitter) {
|
|
118
|
-
this._listener.stopListening(emitter);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Destroys the keystroke handler.
|
|
122
|
-
*/
|
|
123
|
-
destroy() {
|
|
124
|
-
this.stopListening();
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/language.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
const RTL_LANGUAGE_CODES = [
|
|
6
|
-
'ar', 'ara', // Arabic
|
|
7
|
-
'dv', 'div', // Dhivehi
|
|
8
|
-
'fa', 'per', 'fas', // Persian
|
|
9
|
-
'he', 'heb', // Hebrew
|
|
10
|
-
'ku', 'kur', // Kurdish
|
|
11
|
-
'ug', 'uig', // Uighur, Uyghur
|
|
12
|
-
'ur', 'urd' // Urdu
|
|
13
|
-
];
|
|
14
|
-
/**
|
|
15
|
-
* Helps determine whether a language text direction is LTR or RTL.
|
|
16
|
-
*
|
|
17
|
-
* @param languageCode The ISO 639-1 or ISO 639-2 language code.
|
|
18
|
-
*/
|
|
19
|
-
export function getLanguageDirection(languageCode) {
|
|
20
|
-
return RTL_LANGUAGE_CODES.includes(languageCode) ? 'rtl' : 'ltr';
|
|
21
|
-
}
|
package/src/legacyerrors.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/legacyerrors
|
|
7
|
-
*/
|
|
8
|
-
import { CKEditorError } from './ckeditorerror.js';
|
|
9
|
-
if (false) {
|
|
10
|
-
/**
|
|
11
|
-
* The `Locale#language` property was deprecated and will
|
|
12
|
-
* be removed in the near future. Please use the {@link module:utils/locale~Locale#uiLanguage `Locale#uiLanguage`} and
|
|
13
|
-
* {@link module:utils/locale~Locale#contentLanguage `Locale#contentLanguage`} properties instead.
|
|
14
|
-
*
|
|
15
|
-
* @error locale-deprecated-language-property
|
|
16
|
-
*/
|
|
17
|
-
throw new CKEditorError('locale-deprecated-language-property', null);
|
|
18
|
-
}
|
package/src/locale.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module utils/locale
|
|
7
|
-
*/
|
|
8
|
-
import { toArray } from './toarray.js';
|
|
9
|
-
import { _translate, _unifyTranslations } from './translation-service.js';
|
|
10
|
-
import { getLanguageDirection } from './language.js';
|
|
11
|
-
/**
|
|
12
|
-
* Represents the localization services.
|
|
13
|
-
*/
|
|
14
|
-
export class Locale {
|
|
15
|
-
/**
|
|
16
|
-
* The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
17
|
-
*
|
|
18
|
-
* If the {@link #contentLanguage content language} was not specified in the `Locale` constructor,
|
|
19
|
-
* it also defines the language of the content.
|
|
20
|
-
*/
|
|
21
|
-
uiLanguage;
|
|
22
|
-
/**
|
|
23
|
-
* Text direction of the {@link #uiLanguage editor UI language}. Either `'ltr'` or `'rtl'`.
|
|
24
|
-
*/
|
|
25
|
-
uiLanguageDirection;
|
|
26
|
-
/**
|
|
27
|
-
* The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
28
|
-
*
|
|
29
|
-
* Usually the same as the {@link #uiLanguage editor language}, it can be customized by passing an optional
|
|
30
|
-
* argument to the `Locale` constructor.
|
|
31
|
-
*/
|
|
32
|
-
contentLanguage;
|
|
33
|
-
/**
|
|
34
|
-
* Text direction of the {@link #contentLanguage editor content language}.
|
|
35
|
-
*
|
|
36
|
-
* If the content language was passed directly to the `Locale` constructor, this property represents the
|
|
37
|
-
* direction of that language.
|
|
38
|
-
*
|
|
39
|
-
* If the {@link #contentLanguage editor content language} was derived from the {@link #uiLanguage editor language},
|
|
40
|
-
* the content language direction is the same as the {@link #uiLanguageDirection UI language direction}.
|
|
41
|
-
*
|
|
42
|
-
* The value is either `'ltr'` or `'rtl'`.
|
|
43
|
-
*/
|
|
44
|
-
contentLanguageDirection;
|
|
45
|
-
/**
|
|
46
|
-
* Translates the given message to the {@link #uiLanguage}. This method is also available in
|
|
47
|
-
* {@link module:core/editor/editor~Editor#t `Editor`} and {@link module:ui/view~View#t `View`}.
|
|
48
|
-
*
|
|
49
|
-
* This method's context is statically bound to the `Locale` instance and **should always be called as a function**:
|
|
50
|
-
*
|
|
51
|
-
* ```ts
|
|
52
|
-
* const t = locale.t;
|
|
53
|
-
* t( 'Label' );
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* The message can be either a string or an object implementing the {@link module:utils/translation-service~Message} interface.
|
|
57
|
-
*
|
|
58
|
-
* The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter.
|
|
59
|
-
* For an array of values, the `%<index>` will be changed to an element of that array at the given index.
|
|
60
|
-
* For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.
|
|
61
|
-
*
|
|
62
|
-
* ```ts
|
|
63
|
-
* t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
|
|
64
|
-
* t( 'Created file "%0", fileName );
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form
|
|
68
|
-
* will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used
|
|
69
|
-
* as a default plural translation when the translation for the target language is missing.
|
|
70
|
-
*
|
|
71
|
-
* ```ts
|
|
72
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
|
|
73
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
|
|
74
|
-
* t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.
|
|
75
|
-
*
|
|
76
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
|
|
77
|
-
* t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
|
|
78
|
-
* t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* * The message should provide an ID using the `id` property when the message strings are not unique and their
|
|
82
|
-
* translations should be different.
|
|
83
|
-
*
|
|
84
|
-
* ```ts
|
|
85
|
-
* translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
|
|
86
|
-
* translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
t;
|
|
90
|
-
/**
|
|
91
|
-
* Object that contains translations.
|
|
92
|
-
*/
|
|
93
|
-
translations;
|
|
94
|
-
/**
|
|
95
|
-
* Creates a new instance of the locale class. Learn more about
|
|
96
|
-
* {@glink getting-started/setup/ui-language configuring the language of the editor}.
|
|
97
|
-
*
|
|
98
|
-
* @param options Locale configuration.
|
|
99
|
-
* @param options.uiLanguage The editor UI language code in the
|
|
100
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
|
|
101
|
-
* @param options.contentLanguage The editor content language code in the
|
|
102
|
-
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
|
|
103
|
-
* See {@link #contentLanguage}.
|
|
104
|
-
* @param options.translations Translations passed as a editor config parameter.
|
|
105
|
-
*/
|
|
106
|
-
constructor({ uiLanguage = 'en', contentLanguage, translations } = {}) {
|
|
107
|
-
this.uiLanguage = uiLanguage;
|
|
108
|
-
this.contentLanguage = contentLanguage || this.uiLanguage;
|
|
109
|
-
this.uiLanguageDirection = getLanguageDirection(this.uiLanguage);
|
|
110
|
-
this.contentLanguageDirection = getLanguageDirection(this.contentLanguage);
|
|
111
|
-
this.translations = _unifyTranslations(translations);
|
|
112
|
-
this.t = (message, values) => this._t(message, values);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* An unbound version of the {@link #t} method.
|
|
116
|
-
*/
|
|
117
|
-
_t(message, values = []) {
|
|
118
|
-
values = toArray(values);
|
|
119
|
-
if (typeof message === 'string') {
|
|
120
|
-
message = { string: message };
|
|
121
|
-
}
|
|
122
|
-
const hasPluralForm = !!message.plural;
|
|
123
|
-
const quantity = hasPluralForm ? values[0] : 1;
|
|
124
|
-
const translatedString = _translate(this.uiLanguage, message, quantity, this.translations);
|
|
125
|
-
return interpolateString(translatedString, values);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Fills the `%0, %1, ...` string placeholders with values.
|
|
130
|
-
*/
|
|
131
|
-
function interpolateString(string, values) {
|
|
132
|
-
return string.replace(/%(\d+)/g, (match, index) => {
|
|
133
|
-
return (index < values.length) ? values[index] : match;
|
|
134
|
-
});
|
|
135
|
-
}
|
package/src/mapsequal.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
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 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.js
DELETED
package/src/nth.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
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 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.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
|
|
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 function objectToMap(obj) {
|
|
22
|
-
const map = new Map();
|
|
23
|
-
for (const key in obj) {
|
|
24
|
-
map.set(key, obj[key]);
|
|
25
|
-
}
|
|
26
|
-
return map;
|
|
27
|
-
}
|