@ckeditor/ckeditor5-utils 35.3.2 → 35.4.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/package.json +5 -5
- package/src/areconnectedthroughproperties.js +5 -7
- package/src/ckeditorerror.js +51 -70
- package/src/collection.js +106 -148
- package/src/comparearrays.js +10 -8
- package/src/config.js +29 -83
- package/src/count.js +5 -3
- package/src/diff.js +7 -5
- package/src/difftochanges.js +17 -14
- package/src/dom/createelement.js +11 -9
- package/src/dom/emittermixin.js +43 -84
- package/src/dom/getancestors.js +2 -2
- package/src/dom/getborderwidths.js +2 -2
- package/src/dom/getcommonancestor.js +3 -3
- package/src/dom/getdatafromelement.js +2 -2
- package/src/dom/getpositionedancestor.js +1 -2
- package/src/dom/global.js +8 -10
- package/src/dom/indexof.js +2 -2
- package/src/dom/insertat.js +3 -3
- package/src/dom/iscomment.js +0 -3
- package/src/dom/isnode.js +0 -3
- package/src/dom/isrange.js +0 -3
- package/src/dom/istext.js +0 -3
- package/src/dom/isvisible.js +0 -3
- package/src/dom/iswindow.js +0 -3
- package/src/dom/position.js +110 -133
- package/src/dom/rect.js +42 -52
- package/src/dom/remove.js +1 -1
- package/src/dom/resizeobserver.js +10 -35
- package/src/dom/scroll.js +85 -91
- package/src/dom/setdatainelement.js +2 -2
- package/src/dom/tounit.js +1 -10
- package/src/elementreplacer.js +2 -2
- package/src/emittermixin.js +48 -48
- package/src/env.js +14 -75
- package/src/eventinfo.js +2 -2
- package/src/fastdiff.js +115 -96
- package/src/first.js +0 -3
- package/src/focustracker.js +10 -18
- package/src/index.js +17 -0
- package/src/inserttopriorityarray.js +2 -2
- package/src/isiterable.js +2 -2
- package/src/keyboard.js +20 -21
- package/src/keystrokehandler.js +26 -24
- package/src/language.js +1 -2
- package/src/locale.js +11 -14
- package/src/mapsequal.js +3 -3
- package/src/mix.js +15 -13
- package/src/nth.js +0 -4
- package/src/objecttomap.js +6 -4
- package/src/observablemixin.js +126 -150
- package/src/priorities.js +0 -9
- package/src/splicearray.js +12 -11
- package/src/spy.js +1 -1
- package/src/tomap.js +7 -5
- package/src/translation-service.js +70 -52
- package/src/uid.js +5 -3
- package/src/unicode.js +9 -15
- package/src/version.js +32 -26
package/src/first.js
CHANGED
package/src/focustracker.js
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
/* global setTimeout, clearTimeout */
|
|
6
|
-
/* eslint-disable new-cap */
|
|
7
6
|
/**
|
|
8
7
|
* @module utils/focustracker
|
|
9
8
|
*/
|
|
10
9
|
import DomEmitterMixin from './dom/emittermixin';
|
|
11
|
-
import
|
|
10
|
+
import ObservableMixin from './observablemixin';
|
|
12
11
|
import CKEditorError from './ckeditorerror';
|
|
13
12
|
/**
|
|
14
13
|
* Allows observing a group of `Element`s whether at least one of them is focused.
|
|
@@ -21,22 +20,23 @@ import CKEditorError from './ckeditorerror';
|
|
|
21
20
|
* (have e.g. `tabindex="-1"`).
|
|
22
21
|
*
|
|
23
22
|
* Check out the {@glink framework/guides/deep-dive/ui/focus-tracking "Deep dive into focus tracking" guide} to learn more.
|
|
24
|
-
*
|
|
25
|
-
* @mixes module:utils/dom/emittermixin~EmitterMixin
|
|
26
|
-
* @mixes module:utils/observablemixin~ObservableMixin
|
|
27
23
|
*/
|
|
28
|
-
export default class FocusTracker extends DomEmitterMixin(
|
|
24
|
+
export default class FocusTracker extends DomEmitterMixin(ObservableMixin()) {
|
|
29
25
|
constructor() {
|
|
30
26
|
super();
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
/**
|
|
28
|
+
* List of registered elements.
|
|
29
|
+
*/
|
|
33
30
|
this._elements = new Set();
|
|
31
|
+
/**
|
|
32
|
+
* Event loop timeout.
|
|
33
|
+
*/
|
|
34
34
|
this._nextEventLoopTimeout = null;
|
|
35
|
+
this.set('isFocused', false);
|
|
36
|
+
this.set('focusedElement', null);
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Starts tracking the specified element.
|
|
38
|
-
*
|
|
39
|
-
* @param {Element} element
|
|
40
40
|
*/
|
|
41
41
|
add(element) {
|
|
42
42
|
if (this._elements.has(element)) {
|
|
@@ -53,8 +53,6 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Stops tracking the specified element and stops listening on this element.
|
|
56
|
-
*
|
|
57
|
-
* @param {Element} element
|
|
58
56
|
*/
|
|
59
57
|
remove(element) {
|
|
60
58
|
if (element === this.focusedElement) {
|
|
@@ -75,9 +73,6 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
|
|
|
75
73
|
}
|
|
76
74
|
/**
|
|
77
75
|
* Stores currently focused element and set {#isFocused} as `true`.
|
|
78
|
-
*
|
|
79
|
-
* @private
|
|
80
|
-
* @param {Element} element Element which has been focused.
|
|
81
76
|
*/
|
|
82
77
|
_focus(element) {
|
|
83
78
|
clearTimeout(this._nextEventLoopTimeout);
|
|
@@ -87,9 +82,6 @@ export default class FocusTracker extends DomEmitterMixin(Observable) {
|
|
|
87
82
|
/**
|
|
88
83
|
* Clears currently focused element and set {@link #isFocused} as `false`.
|
|
89
84
|
* This method uses `setTimeout` to change order of fires `blur` and `focus` events.
|
|
90
|
-
*
|
|
91
|
-
* @private
|
|
92
|
-
* @fires blur
|
|
93
85
|
*/
|
|
94
86
|
_blur() {
|
|
95
87
|
clearTimeout(this._nextEventLoopTimeout);
|
package/src/index.js
CHANGED
|
@@ -7,20 +7,35 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { default as env } from './env';
|
|
9
9
|
export { default as diff } from './diff';
|
|
10
|
+
export { default as fastDiff } from './fastdiff';
|
|
10
11
|
export { default as mix } from './mix';
|
|
11
12
|
export { default as EmitterMixin } from './emittermixin';
|
|
13
|
+
export { default as EventInfo } from './eventinfo';
|
|
12
14
|
export { default as ObservableMixin } from './observablemixin';
|
|
13
15
|
export { default as CKEditorError, logError, logWarning } from './ckeditorerror';
|
|
14
16
|
export { default as ElementReplacer } from './elementreplacer';
|
|
17
|
+
export { default as count } from './count';
|
|
18
|
+
export { default as compareArrays } from './comparearrays';
|
|
15
19
|
export { default as createElement } from './dom/createelement';
|
|
20
|
+
export { default as Config } from './config';
|
|
21
|
+
export { default as isIterable } from './isiterable';
|
|
16
22
|
export { default as DomEmitterMixin } from './dom/emittermixin';
|
|
17
23
|
export { default as global } from './dom/global';
|
|
24
|
+
export { default as getAncestors } from './dom/getancestors';
|
|
18
25
|
export { default as getDataFromElement } from './dom/getdatafromelement';
|
|
26
|
+
export { default as isText } from './dom/istext';
|
|
19
27
|
export { default as Rect } from './dom/rect';
|
|
20
28
|
export { default as ResizeObserver } from './dom/resizeobserver';
|
|
21
29
|
export { default as setDataInElement } from './dom/setdatainelement';
|
|
22
30
|
export { default as toUnit } from './dom/tounit';
|
|
31
|
+
export { default as indexOf } from './dom/indexof';
|
|
32
|
+
export { default as insertAt } from './dom/insertat';
|
|
33
|
+
export { default as isComment } from './dom/iscomment';
|
|
34
|
+
export { default as isNode } from './dom/isnode';
|
|
35
|
+
export { default as isRange } from './dom/isrange';
|
|
23
36
|
export { default as isVisible } from './dom/isvisible';
|
|
37
|
+
export { getOptimalPosition } from './dom/position';
|
|
38
|
+
export { default as remove } from './dom/remove';
|
|
24
39
|
export * from './dom/scroll';
|
|
25
40
|
export * from './keyboard';
|
|
26
41
|
export * from './language';
|
|
@@ -33,5 +48,7 @@ export { default as toArray } from './toarray';
|
|
|
33
48
|
export { default as toMap } from './tomap';
|
|
34
49
|
export { default as priorities } from './priorities';
|
|
35
50
|
export { default as insertToPriorityArray } from './inserttopriorityarray';
|
|
51
|
+
export { default as spliceArray } from './splicearray';
|
|
36
52
|
export { default as uid } from './uid';
|
|
53
|
+
export * from './unicode';
|
|
37
54
|
export { default as version } from './version';
|
|
@@ -6,8 +6,8 @@ import priorities from './priorities';
|
|
|
6
6
|
/**
|
|
7
7
|
* Inserts any object with priority at correct index by priority so registered objects are always sorted from highest to lowest priority.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
9
|
+
* @param objects Array of objects with priority to insert object to.
|
|
10
|
+
* @param objectToInsert Object with `priority` property.
|
|
11
11
|
*/
|
|
12
12
|
export default function insertToPriorityArray(objects, objectToInsert) {
|
|
13
13
|
const priority = priorities.get(objectToInsert.priority);
|
package/src/isiterable.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Checks if value implements iterator interface.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @returns
|
|
11
|
+
* @param value The value to check.
|
|
12
|
+
* @returns True if value implements iterator interface.
|
|
13
13
|
*/
|
|
14
14
|
export default function isIterable(value) {
|
|
15
15
|
return !!(value && value[Symbol.iterator]);
|
package/src/keyboard.js
CHANGED
|
@@ -35,9 +35,8 @@ const keyCodeNames = Object.fromEntries(Object.entries(keyCodes).map(([name, cod
|
|
|
35
35
|
*
|
|
36
36
|
* Note: Key names are matched with {@link module:utils/keyboard~keyCodes} in a case-insensitive way.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* or
|
|
40
|
-
* @returns {Number} Key or keystroke code.
|
|
38
|
+
* @param key A key name (see {@link module:utils/keyboard~keyCodes}) or a keystroke data object.
|
|
39
|
+
* @returns Key or keystroke code.
|
|
41
40
|
*/
|
|
42
41
|
export function getCode(key) {
|
|
43
42
|
let keyCode;
|
|
@@ -81,8 +80,8 @@ export function getCode(key) {
|
|
|
81
80
|
* For example, a registered keystroke `Ctrl+A` will be translated to `Cmd+A` on macOS. To disable the translation of some keystroke,
|
|
82
81
|
* use the forced modifier: `Ctrl!+A` (note the exclamation mark).
|
|
83
82
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @returns
|
|
83
|
+
* @param keystroke The keystroke definition.
|
|
84
|
+
* @returns Keystroke code.
|
|
86
85
|
*/
|
|
87
86
|
export function parseKeystroke(keystroke) {
|
|
88
87
|
if (typeof keystroke == 'string') {
|
|
@@ -96,8 +95,8 @@ export function parseKeystroke(keystroke) {
|
|
|
96
95
|
* Translates any keystroke string text like `"Ctrl+A"` to an
|
|
97
96
|
* environment–specific keystroke, i.e. `"⌘A"` on macOS.
|
|
98
97
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @returns
|
|
98
|
+
* @param keystroke The keystroke text.
|
|
99
|
+
* @returns The keystroke text specific for the environment.
|
|
101
100
|
*/
|
|
102
101
|
export function getEnvKeystrokeText(keystroke) {
|
|
103
102
|
let keystrokeCode = parseKeystroke(keystroke);
|
|
@@ -115,8 +114,7 @@ export function getEnvKeystrokeText(keystroke) {
|
|
|
115
114
|
/**
|
|
116
115
|
* Returns `true` if the provided key code represents one of the arrow keys.
|
|
117
116
|
*
|
|
118
|
-
* @param
|
|
119
|
-
* @returns {Boolean}
|
|
117
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
120
118
|
*/
|
|
121
119
|
export function isArrowKeyCode(keyCode) {
|
|
122
120
|
return keyCode == keyCodes.arrowright ||
|
|
@@ -131,10 +129,10 @@ export function isArrowKeyCode(keyCode) {
|
|
|
131
129
|
* For instance, in right–to–left (RTL) content languages, pressing the left arrow means moving the selection right (forward)
|
|
132
130
|
* in the model structure. Similarly, pressing the right arrow moves the selection left (backward).
|
|
133
131
|
*
|
|
134
|
-
* @param
|
|
135
|
-
* @param
|
|
132
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
133
|
+
* @param contentLanguageDirection The content language direction, corresponding to
|
|
136
134
|
* {@link module:utils/locale~Locale#contentLanguageDirection}.
|
|
137
|
-
* @returns
|
|
135
|
+
* @returns Localized arrow direction or `undefined` for non-arrow key codes.
|
|
138
136
|
*/
|
|
139
137
|
export function getLocalizedArrowKeyCodeDirection(keyCode, contentLanguageDirection) {
|
|
140
138
|
const isLtrContent = contentLanguageDirection === 'ltr';
|
|
@@ -149,12 +147,14 @@ export function getLocalizedArrowKeyCodeDirection(keyCode, contentLanguageDirect
|
|
|
149
147
|
return 'down';
|
|
150
148
|
}
|
|
151
149
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Converts a key name to the key code with mapping based on the env.
|
|
152
|
+
*
|
|
153
|
+
* See: {@link module:utils/keyboard~getCode}.
|
|
154
|
+
*
|
|
155
|
+
* @param key The key name (see {@link module:utils/keyboard~keyCodes}).
|
|
156
|
+
* @returns Key code.
|
|
157
|
+
*/
|
|
158
158
|
function getEnvKeyCode(key) {
|
|
159
159
|
// Don't remap modifier key for forced modifiers.
|
|
160
160
|
if (key.endsWith('!')) {
|
|
@@ -170,10 +170,9 @@ function getEnvKeyCode(key) {
|
|
|
170
170
|
* For instance, in right–to–left (RTL) languages, pressing the left arrow means moving forward
|
|
171
171
|
* in the model structure. Similarly, pressing the right arrow moves the selection backward.
|
|
172
172
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
173
|
+
* @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
|
|
174
|
+
* @param contentLanguageDirection The content language direction, corresponding to
|
|
175
175
|
* {@link module:utils/locale~Locale#contentLanguageDirection}.
|
|
176
|
-
* @returns {Boolean}
|
|
177
176
|
*/
|
|
178
177
|
export function isForwardArrowKeyCode(keyCode, contentLanguageDirection) {
|
|
179
178
|
const localizedKeyCodeDirection = getLocalizedArrowKeyCodeDirection(keyCode, contentLanguageDirection);
|
package/src/keystrokehandler.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @module utils/keystrokehandler
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
8
|
+
import DomEmitterMixin from './dom/emittermixin';
|
|
9
9
|
import { getCode, parseKeystroke } from './keyboard';
|
|
10
10
|
/**
|
|
11
11
|
* Keystroke handler allows registering callbacks for given keystrokes.
|
|
@@ -13,27 +13,31 @@ import { getCode, parseKeystroke } from './keyboard';
|
|
|
13
13
|
* The most frequent use of this class is through the {@link module:core/editor/editor~Editor#keystrokes `editor.keystrokes`}
|
|
14
14
|
* property. It allows listening to keystrokes executed in the editing view:
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* editor.keystrokes.set( 'Ctrl+A', ( keyEvtData, cancel ) => {
|
|
18
|
+
* console.log( 'Ctrl+A has been pressed' );
|
|
19
|
+
* cancel();
|
|
20
|
+
* } );
|
|
21
|
+
* ```
|
|
20
22
|
*
|
|
21
23
|
* However, this utility class can be used in various part of the UI. For instance, a certain {@link module:ui/view~View}
|
|
22
24
|
* can use it like this:
|
|
23
25
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* class MyView extends View {
|
|
28
|
+
* constructor() {
|
|
29
|
+
* this.keystrokes = new KeystrokeHandler();
|
|
27
30
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
31
|
+
* this.keystrokes.set( 'tab', handleTabKey );
|
|
32
|
+
* }
|
|
30
33
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
34
|
+
* render() {
|
|
35
|
+
* super.render();
|
|
33
36
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* this.keystrokes.listenTo( this.element );
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
37
41
|
*
|
|
38
42
|
* That keystroke handler will listen to `keydown` events fired in this view's main element.
|
|
39
43
|
*
|
|
@@ -43,12 +47,10 @@ export default class KeystrokeHandler {
|
|
|
43
47
|
* Creates an instance of the keystroke handler.
|
|
44
48
|
*/
|
|
45
49
|
constructor() {
|
|
46
|
-
this._listener = new
|
|
50
|
+
this._listener = new (DomEmitterMixin())();
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* Starts listening for `keydown` events from a given emitter.
|
|
50
|
-
*
|
|
51
|
-
* @param {module:utils/emittermixin~Emitter|HTMLElement|Window} emitter
|
|
52
54
|
*/
|
|
53
55
|
listenTo(emitter) {
|
|
54
56
|
// The #_listener works here as a kind of dispatcher. It groups the events coming from the same
|
|
@@ -67,13 +69,13 @@ export default class KeystrokeHandler {
|
|
|
67
69
|
/**
|
|
68
70
|
* Registers a handler for the specified keystroke.
|
|
69
71
|
*
|
|
70
|
-
* @param
|
|
72
|
+
* @param keystroke Keystroke defined in a format accepted by
|
|
71
73
|
* the {@link module:utils/keyboard~parseKeystroke} function.
|
|
72
|
-
* @param
|
|
74
|
+
* @param callback A function called with the
|
|
73
75
|
* {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
|
|
74
76
|
* a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
+
* @param options Additional options.
|
|
78
|
+
* @param options.priority The priority of the keystroke
|
|
77
79
|
* callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
|
|
78
80
|
* are called in the order they were added.
|
|
79
81
|
*/
|
|
@@ -99,8 +101,8 @@ export default class KeystrokeHandler {
|
|
|
99
101
|
/**
|
|
100
102
|
* Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
|
|
101
103
|
*
|
|
102
|
-
* @param
|
|
103
|
-
* @returns
|
|
104
|
+
* @param keyEvtData Key event data.
|
|
105
|
+
* @returns Whether the keystroke was handled.
|
|
104
106
|
*/
|
|
105
107
|
press(keyEvtData) {
|
|
106
108
|
return !!this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
|
package/src/language.js
CHANGED
|
@@ -12,8 +12,7 @@ const RTL_LANGUAGE_CODES = [
|
|
|
12
12
|
/**
|
|
13
13
|
* Helps determine whether a language text direction is LTR or RTL.
|
|
14
14
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @returns {module:utils/language~LanguageDirection}
|
|
15
|
+
* @param languageCode The ISO 639-1 or ISO 639-2 language code.
|
|
17
16
|
*/
|
|
18
17
|
export function getLanguageDirection(languageCode) {
|
|
19
18
|
return RTL_LANGUAGE_CODES.includes(languageCode) ? 'rtl' : 'ltr';
|
package/src/locale.js
CHANGED
|
@@ -17,16 +17,16 @@ export default class Locale {
|
|
|
17
17
|
* Creates a new instance of the locale class. Learn more about
|
|
18
18
|
* {@glink features/ui-language configuring the language of the editor}.
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
20
|
+
* @param options Locale configuration.
|
|
21
|
+
* @param options.uiLanguage The editor UI language code in the
|
|
22
22
|
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
|
|
23
|
-
* @param
|
|
23
|
+
* @param options.contentLanguage The editor content language code in the
|
|
24
24
|
* [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
|
|
25
25
|
* See {@link #contentLanguage}.
|
|
26
26
|
*/
|
|
27
|
-
constructor(
|
|
28
|
-
this.uiLanguage =
|
|
29
|
-
this.contentLanguage =
|
|
27
|
+
constructor({ uiLanguage = 'en', contentLanguage } = {}) {
|
|
28
|
+
this.uiLanguage = uiLanguage;
|
|
29
|
+
this.contentLanguage = contentLanguage || this.uiLanguage;
|
|
30
30
|
this.uiLanguageDirection = getLanguageDirection(this.uiLanguage);
|
|
31
31
|
this.contentLanguageDirection = getLanguageDirection(this.contentLanguage);
|
|
32
32
|
this.t = (message, values) => this._t(message, values);
|
|
@@ -38,12 +38,12 @@ export default class Locale {
|
|
|
38
38
|
* properties instead.
|
|
39
39
|
*
|
|
40
40
|
* @deprecated
|
|
41
|
-
* @member {String}
|
|
42
41
|
*/
|
|
43
42
|
get language() {
|
|
44
43
|
/**
|
|
45
44
|
* 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
|
|
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
47
|
*
|
|
48
48
|
* @error locale-deprecated-language-property
|
|
49
49
|
*/
|
|
@@ -54,11 +54,6 @@ export default class Locale {
|
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
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
57
|
*/
|
|
63
58
|
_t(message, values = []) {
|
|
64
59
|
values = toArray(values);
|
|
@@ -71,7 +66,9 @@ export default class Locale {
|
|
|
71
66
|
return interpolateString(translatedString, values);
|
|
72
67
|
}
|
|
73
68
|
}
|
|
74
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Fills the `%0, %1, ...` string placeholders with values.
|
|
71
|
+
*/
|
|
75
72
|
function interpolateString(string, values) {
|
|
76
73
|
return string.replace(/%(\d+)/g, (match, index) => {
|
|
77
74
|
return (index < values.length) ? values[index] : match;
|
package/src/mapsequal.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Checks whether given {Map}s are equal, that is has same size and same key-value pairs.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
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
14
|
*/
|
|
15
15
|
export default function mapsEqual(mapA, mapB) {
|
|
16
16
|
if (mapA.size != mapB.size) {
|
package/src/mix.js
CHANGED
|
@@ -9,25 +9,27 @@
|
|
|
9
9
|
* Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
|
|
10
10
|
* prototype of first object (a constructor).
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* ```
|
|
13
|
+
* class Editor {
|
|
14
|
+
* ...
|
|
15
|
+
* }
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* const SomeMixin = {
|
|
18
|
+
* a() {
|
|
19
|
+
* return 'a';
|
|
20
|
+
* }
|
|
21
|
+
* };
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
+
* mix( Editor, SomeMixin, ... );
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
+
* new Editor().a(); // -> 'a'
|
|
26
|
+
* ```
|
|
25
27
|
*
|
|
26
28
|
* Note: Properties which already exist in the base class will not be overriden.
|
|
27
29
|
*
|
|
28
|
-
* @
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
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.
|
|
31
33
|
*/
|
|
32
34
|
export default function mix(baseClass, ...mixins) {
|
|
33
35
|
mixins.forEach(mixin => {
|
package/src/nth.js
CHANGED
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
* If it's a normal iterator, then it consumes **all items up to the given index**.
|
|
13
13
|
* Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
14
14
|
* guide to learn differences between these interfaces.
|
|
15
|
-
*
|
|
16
|
-
* @param {Number} index
|
|
17
|
-
* @param {Iterable.<*>} iterable
|
|
18
|
-
* @returns {*}
|
|
19
15
|
*/
|
|
20
16
|
export default function nth(index, iterable) {
|
|
21
17
|
for (const item of iterable) {
|
package/src/objecttomap.js
CHANGED
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Transforms object to map.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const map = objectToMap( { 'foo': 1, 'bar': 2 } );
|
|
13
|
+
* map.get( 'foo' ); // 1
|
|
14
|
+
* ```
|
|
13
15
|
*
|
|
14
16
|
* **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
|
|
15
17
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
18
|
+
* @param obj Object to transform.
|
|
19
|
+
* @returns Map created from object.
|
|
18
20
|
*/
|
|
19
21
|
export default function objectToMap(obj) {
|
|
20
22
|
const map = new Map();
|