@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.
Files changed (135) hide show
  1. package/CHANGELOG.md +26 -26
  2. package/LICENSE.md +3 -3
  3. package/package.json +1 -1
  4. package/src/abortabledebounce.d.ts +17 -0
  5. package/src/abortabledebounce.js +22 -0
  6. package/src/areconnectedthroughproperties.d.ts +11 -11
  7. package/src/areconnectedthroughproperties.js +73 -73
  8. package/src/ckeditorerror.d.ts +123 -123
  9. package/src/ckeditorerror.js +176 -176
  10. package/src/collection.d.ts +433 -427
  11. package/src/collection.js +583 -575
  12. package/src/comparearrays.d.ts +30 -30
  13. package/src/comparearrays.js +47 -47
  14. package/src/config.d.ts +163 -163
  15. package/src/config.js +163 -162
  16. package/src/count.d.ts +18 -18
  17. package/src/count.js +24 -24
  18. package/src/delay.d.ts +19 -19
  19. package/src/delay.js +26 -26
  20. package/src/diff.d.ts +31 -31
  21. package/src/diff.js +115 -115
  22. package/src/difftochanges.d.ts +59 -59
  23. package/src/difftochanges.js +79 -79
  24. package/src/dom/createelement.d.ts +57 -57
  25. package/src/dom/createelement.js +40 -40
  26. package/src/dom/emittermixin.d.ts +142 -142
  27. package/src/dom/emittermixin.js +239 -239
  28. package/src/dom/findclosestscrollableancestor.d.ts +11 -11
  29. package/src/dom/findclosestscrollableancestor.js +31 -31
  30. package/src/dom/getancestors.d.ts +17 -17
  31. package/src/dom/getancestors.js +27 -27
  32. package/src/dom/getborderwidths.d.ts +24 -24
  33. package/src/dom/getborderwidths.js +24 -24
  34. package/src/dom/getcommonancestor.d.ts +12 -12
  35. package/src/dom/getcommonancestor.js +25 -25
  36. package/src/dom/getdatafromelement.d.ts +14 -14
  37. package/src/dom/getdatafromelement.js +20 -20
  38. package/src/dom/getpositionedancestor.d.ts +10 -10
  39. package/src/dom/getpositionedancestor.js +22 -22
  40. package/src/dom/global.d.ts +32 -32
  41. package/src/dom/global.js +35 -35
  42. package/src/dom/indexof.d.ts +14 -14
  43. package/src/dom/indexof.js +21 -21
  44. package/src/dom/insertat.d.ts +15 -15
  45. package/src/dom/insertat.js +17 -17
  46. package/src/dom/iscomment.d.ts +11 -11
  47. package/src/dom/iscomment.js +14 -14
  48. package/src/dom/isnode.d.ts +11 -11
  49. package/src/dom/isnode.js +21 -21
  50. package/src/dom/isrange.d.ts +11 -11
  51. package/src/dom/isrange.js +13 -13
  52. package/src/dom/istext.d.ts +11 -11
  53. package/src/dom/istext.js +13 -13
  54. package/src/dom/isvalidattributename.d.ts +10 -10
  55. package/src/dom/isvalidattributename.js +22 -22
  56. package/src/dom/isvisible.d.ts +18 -18
  57. package/src/dom/isvisible.js +20 -20
  58. package/src/dom/iswindow.d.ts +11 -11
  59. package/src/dom/iswindow.js +22 -22
  60. package/src/dom/position.d.ts +211 -211
  61. package/src/dom/position.js +313 -313
  62. package/src/dom/rect.d.ts +195 -195
  63. package/src/dom/rect.js +474 -474
  64. package/src/dom/remove.d.ts +13 -13
  65. package/src/dom/remove.js +18 -18
  66. package/src/dom/resizeobserver.d.ts +74 -74
  67. package/src/dom/resizeobserver.js +126 -126
  68. package/src/dom/scroll.d.ts +73 -73
  69. package/src/dom/scroll.js +383 -383
  70. package/src/dom/setdatainelement.d.ts +14 -14
  71. package/src/dom/setdatainelement.js +20 -20
  72. package/src/dom/tounit.d.ts +22 -22
  73. package/src/dom/tounit.js +16 -16
  74. package/src/elementreplacer.d.ts +31 -31
  75. package/src/elementreplacer.js +43 -43
  76. package/src/emittermixin.d.ts +312 -312
  77. package/src/emittermixin.js +453 -453
  78. package/src/env.d.ts +117 -117
  79. package/src/env.js +122 -122
  80. package/src/eventinfo.d.ts +58 -58
  81. package/src/eventinfo.js +26 -26
  82. package/src/fastdiff.d.ts +112 -112
  83. package/src/fastdiff.js +248 -248
  84. package/src/first.d.ts +11 -11
  85. package/src/first.js +17 -17
  86. package/src/focustracker.d.ts +75 -75
  87. package/src/focustracker.js +95 -95
  88. package/src/index.d.ts +64 -61
  89. package/src/index.js +63 -60
  90. package/src/inserttopriorityarray.d.ts +30 -30
  91. package/src/inserttopriorityarray.js +21 -21
  92. package/src/isiterable.d.ts +14 -14
  93. package/src/isiterable.js +16 -16
  94. package/src/keyboard.d.ts +126 -126
  95. package/src/keyboard.js +221 -221
  96. package/src/keystrokehandler.d.ts +87 -87
  97. package/src/keystrokehandler.js +122 -122
  98. package/src/language.d.ts +17 -17
  99. package/src/language.js +19 -19
  100. package/src/locale.d.ts +120 -120
  101. package/src/locale.js +76 -76
  102. package/src/mapsequal.d.ts +15 -15
  103. package/src/mapsequal.js +27 -27
  104. package/src/mix.d.ts +85 -85
  105. package/src/mix.js +50 -50
  106. package/src/nth.d.ts +16 -16
  107. package/src/nth.js +24 -24
  108. package/src/objecttomap.d.ts +23 -23
  109. package/src/objecttomap.js +27 -27
  110. package/src/observablemixin.d.ts +560 -560
  111. package/src/observablemixin.js +580 -580
  112. package/src/priorities.d.ts +33 -33
  113. package/src/priorities.js +23 -23
  114. package/src/retry.d.ts +33 -0
  115. package/src/retry.js +47 -0
  116. package/src/splicearray.d.ts +26 -26
  117. package/src/splicearray.js +40 -40
  118. package/src/spy.d.ts +21 -21
  119. package/src/spy.js +22 -22
  120. package/src/toarray.d.ts +25 -25
  121. package/src/toarray.js +7 -7
  122. package/src/tomap.d.ts +19 -19
  123. package/src/tomap.js +29 -29
  124. package/src/translation-service.d.ts +168 -168
  125. package/src/translation-service.js +198 -198
  126. package/src/uid.d.ts +15 -15
  127. package/src/uid.js +57 -57
  128. package/src/unicode.d.ts +54 -54
  129. package/src/unicode.js +85 -85
  130. package/src/verifylicense.d.ts +15 -15
  131. package/src/verifylicense.js +87 -87
  132. package/src/version.d.ts +10 -10
  133. package/src/version.js +153 -153
  134. package/src/wait.d.ts +16 -0
  135. package/src/wait.js +29 -0
@@ -1,122 +1,122 @@
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/keystrokehandler
7
- */
8
- import DomEmitterMixin from './dom/emittermixin';
9
- import { getCode, parseKeystroke } from './keyboard';
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 default class KeystrokeHandler {
46
- /**
47
- * Creates an instance of the keystroke handler.
48
- */
49
- constructor() {
50
- this._listener = new (DomEmitterMixin())();
51
- }
52
- /**
53
- * Starts listening for `keydown` events from a given emitter.
54
- */
55
- listenTo(emitter) {
56
- // The #_listener works here as a kind of dispatcher. It groups the events coming from the same
57
- // keystroke so the listeners can be attached to them with different priorities.
58
- //
59
- // E.g. all the keystrokes with the `keyCode` of 42 coming from the `emitter` are propagated
60
- // as a `_keydown:42` event by the `_listener`. If there's a callback created by the `set`
61
- // method for this 42 keystroke, it listens to the `_listener#_keydown:42` event only and interacts
62
- // only with other listeners of this particular event, thus making it possible to prioritize
63
- // the listeners and safely cancel execution, when needed. Instead of duplicating the Emitter logic,
64
- // the KeystrokeHandler re–uses it to do its job.
65
- this._listener.listenTo(emitter, 'keydown', (evt, keyEvtData) => {
66
- this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
67
- });
68
- }
69
- /**
70
- * Registers a handler for the specified keystroke.
71
- *
72
- * @param keystroke Keystroke defined in a format accepted by
73
- * the {@link module:utils/keyboard~parseKeystroke} function.
74
- * @param callback A function called with the
75
- * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
76
- * a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
77
- * @param options Additional options.
78
- * @param options.priority The priority of the keystroke
79
- * callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
80
- * are called in the order they were added.
81
- */
82
- set(keystroke, callback, options = {}) {
83
- const keyCode = parseKeystroke(keystroke);
84
- const priority = options.priority;
85
- // Execute the passed callback on KeystrokeHandler#_keydown.
86
- // TODO: https://github.com/ckeditor/ckeditor5-utils/issues/144
87
- this._listener.listenTo(this._listener, '_keydown:' + keyCode, (evt, keyEvtData) => {
88
- callback(keyEvtData, () => {
89
- // Stop the event in the DOM: no listener in the web page
90
- // will be triggered by this event.
91
- keyEvtData.preventDefault();
92
- keyEvtData.stopPropagation();
93
- // Stop the event in the KeystrokeHandler: no more callbacks
94
- // will be executed for this keystroke.
95
- evt.stop();
96
- });
97
- // Mark this keystroke as handled by the callback. See: #press.
98
- evt.return = true;
99
- }, { priority });
100
- }
101
- /**
102
- * Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
103
- *
104
- * @param keyEvtData Key event data.
105
- * @returns Whether the keystroke was handled.
106
- */
107
- press(keyEvtData) {
108
- return !!this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
109
- }
110
- /**
111
- * Stops listening to `keydown` events from the given emitter.
112
- */
113
- stopListening(emitter) {
114
- this._listener.stopListening(emitter);
115
- }
116
- /**
117
- * Destroys the keystroke handler.
118
- */
119
- destroy() {
120
- this.stopListening();
121
- }
122
- }
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/keystrokehandler
7
+ */
8
+ import DomEmitterMixin from './dom/emittermixin';
9
+ import { getCode, parseKeystroke } from './keyboard';
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 default class KeystrokeHandler {
46
+ /**
47
+ * Creates an instance of the keystroke handler.
48
+ */
49
+ constructor() {
50
+ this._listener = new (DomEmitterMixin())();
51
+ }
52
+ /**
53
+ * Starts listening for `keydown` events from a given emitter.
54
+ */
55
+ listenTo(emitter) {
56
+ // The #_listener works here as a kind of dispatcher. It groups the events coming from the same
57
+ // keystroke so the listeners can be attached to them with different priorities.
58
+ //
59
+ // E.g. all the keystrokes with the `keyCode` of 42 coming from the `emitter` are propagated
60
+ // as a `_keydown:42` event by the `_listener`. If there's a callback created by the `set`
61
+ // method for this 42 keystroke, it listens to the `_listener#_keydown:42` event only and interacts
62
+ // only with other listeners of this particular event, thus making it possible to prioritize
63
+ // the listeners and safely cancel execution, when needed. Instead of duplicating the Emitter logic,
64
+ // the KeystrokeHandler re–uses it to do its job.
65
+ this._listener.listenTo(emitter, 'keydown', (evt, keyEvtData) => {
66
+ this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
67
+ });
68
+ }
69
+ /**
70
+ * Registers a handler for the specified keystroke.
71
+ *
72
+ * @param keystroke Keystroke defined in a format accepted by
73
+ * the {@link module:utils/keyboard~parseKeystroke} function.
74
+ * @param callback A function called with the
75
+ * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
76
+ * a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
77
+ * @param options Additional options.
78
+ * @param options.priority The priority of the keystroke
79
+ * callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority
80
+ * are called in the order they were added.
81
+ */
82
+ set(keystroke, callback, options = {}) {
83
+ const keyCode = parseKeystroke(keystroke);
84
+ const priority = options.priority;
85
+ // Execute the passed callback on KeystrokeHandler#_keydown.
86
+ // TODO: https://github.com/ckeditor/ckeditor5-utils/issues/144
87
+ this._listener.listenTo(this._listener, '_keydown:' + keyCode, (evt, keyEvtData) => {
88
+ callback(keyEvtData, () => {
89
+ // Stop the event in the DOM: no listener in the web page
90
+ // will be triggered by this event.
91
+ keyEvtData.preventDefault();
92
+ keyEvtData.stopPropagation();
93
+ // Stop the event in the KeystrokeHandler: no more callbacks
94
+ // will be executed for this keystroke.
95
+ evt.stop();
96
+ });
97
+ // Mark this keystroke as handled by the callback. See: #press.
98
+ evt.return = true;
99
+ }, { priority });
100
+ }
101
+ /**
102
+ * Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
103
+ *
104
+ * @param keyEvtData Key event data.
105
+ * @returns Whether the keystroke was handled.
106
+ */
107
+ press(keyEvtData) {
108
+ return !!this._listener.fire('_keydown:' + getCode(keyEvtData), keyEvtData);
109
+ }
110
+ /**
111
+ * Stops listening to `keydown` events from the given emitter.
112
+ */
113
+ stopListening(emitter) {
114
+ this._listener.stopListening(emitter);
115
+ }
116
+ /**
117
+ * Destroys the keystroke handler.
118
+ */
119
+ destroy() {
120
+ this.stopListening();
121
+ }
122
+ }
package/src/language.d.ts CHANGED
@@ -1,17 +1,17 @@
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/language
7
- */
8
- /**
9
- * String representing a language direction.
10
- */
11
- export type LanguageDirection = 'ltr' | 'rtl';
12
- /**
13
- * Helps determine whether a language text direction is LTR or RTL.
14
- *
15
- * @param languageCode The ISO 639-1 or ISO 639-2 language code.
16
- */
17
- export declare function getLanguageDirection(languageCode: string): LanguageDirection;
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/language
7
+ */
8
+ /**
9
+ * String representing a language direction.
10
+ */
11
+ export type LanguageDirection = 'ltr' | 'rtl';
12
+ /**
13
+ * Helps determine whether a language text direction is LTR or RTL.
14
+ *
15
+ * @param languageCode The ISO 639-1 or ISO 639-2 language code.
16
+ */
17
+ export declare function getLanguageDirection(languageCode: string): LanguageDirection;
package/src/language.js CHANGED
@@ -1,19 +1,19 @@
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
- const RTL_LANGUAGE_CODES = [
6
- 'ar', 'ara',
7
- 'fa', 'per', 'fas',
8
- 'he', 'heb',
9
- 'ku', 'kur',
10
- 'ug', 'uig' // Uighur, Uyghur
11
- ];
12
- /**
13
- * Helps determine whether a language text direction is LTR or RTL.
14
- *
15
- * @param languageCode The ISO 639-1 or ISO 639-2 language code.
16
- */
17
- export function getLanguageDirection(languageCode) {
18
- return RTL_LANGUAGE_CODES.includes(languageCode) ? 'rtl' : 'ltr';
19
- }
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
+ const RTL_LANGUAGE_CODES = [
6
+ 'ar', 'ara',
7
+ 'fa', 'per', 'fas',
8
+ 'he', 'heb',
9
+ 'ku', 'kur',
10
+ 'ug', 'uig' // Uighur, Uyghur
11
+ ];
12
+ /**
13
+ * Helps determine whether a language text direction is LTR or RTL.
14
+ *
15
+ * @param languageCode The ISO 639-1 or ISO 639-2 language code.
16
+ */
17
+ export function getLanguageDirection(languageCode) {
18
+ return RTL_LANGUAGE_CODES.includes(languageCode) ? 'rtl' : 'ltr';
19
+ }
package/src/locale.d.ts CHANGED
@@ -1,120 +1,120 @@
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
- import { type Message } from './translation-service';
6
- import { type LanguageDirection } from './language';
7
- /**
8
- * Represents the localization services.
9
- */
10
- export default class Locale {
11
- /**
12
- * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
13
- *
14
- * If the {@link #contentLanguage content language} was not specified in the `Locale` constructor,
15
- * it also defines the language of the content.
16
- */
17
- readonly uiLanguage: string;
18
- /**
19
- * Text direction of the {@link #uiLanguage editor UI language}. Either `'ltr'` or `'rtl'`.
20
- */
21
- readonly uiLanguageDirection: LanguageDirection;
22
- /**
23
- * The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
24
- *
25
- * Usually the same as the {@link #uiLanguage editor language}, it can be customized by passing an optional
26
- * argument to the `Locale` constructor.
27
- */
28
- readonly contentLanguage: string;
29
- /**
30
- * Text direction of the {@link #contentLanguage editor content language}.
31
- *
32
- * If the content language was passed directly to the `Locale` constructor, this property represents the
33
- * direction of that language.
34
- *
35
- * If the {@link #contentLanguage editor content language} was derived from the {@link #uiLanguage editor language},
36
- * the content language direction is the same as the {@link #uiLanguageDirection UI language direction}.
37
- *
38
- * The value is either `'ltr'` or `'rtl'`.
39
- */
40
- readonly contentLanguageDirection: LanguageDirection;
41
- /**
42
- * Translates the given message to the {@link #uiLanguage}. This method is also available in
43
- * {@link module:core/editor/editor~Editor#t `Editor`} and {@link module:ui/view~View#t `View`}.
44
- *
45
- * This method's context is statically bound to the `Locale` instance and **should always be called as a function**:
46
- *
47
- * ```ts
48
- * const t = locale.t;
49
- * t( 'Label' );
50
- * ```
51
- *
52
- * The message can be either a string or an object implementing the {@link module:utils/translation-service~Message} interface.
53
- *
54
- * The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter.
55
- * For an array of values, the `%<index>` will be changed to an element of that array at the given index.
56
- * For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.
57
- *
58
- * ```ts
59
- * t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
60
- * t( 'Created file "%0", fileName );
61
- * ```
62
- *
63
- * The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form
64
- * will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used
65
- * as a default plural translation when the translation for the target language is missing.
66
- *
67
- * ```ts
68
- * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
69
- * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
70
- * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.
71
- *
72
- * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
73
- * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
74
- * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
75
- * ```
76
- *
77
- * * The message should provide an ID using the `id` property when the message strings are not unique and their
78
- * translations should be different.
79
- *
80
- * ```ts
81
- * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
82
- * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
83
- * ```
84
- */
85
- readonly t: LocaleTranslate;
86
- /**
87
- * Creates a new instance of the locale class. Learn more about
88
- * {@glink features/ui-language configuring the language of the editor}.
89
- *
90
- * @param options Locale configuration.
91
- * @param options.uiLanguage The editor UI language code in the
92
- * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
93
- * @param options.contentLanguage The editor content language code in the
94
- * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
95
- * See {@link #contentLanguage}.
96
- */
97
- constructor({ uiLanguage, contentLanguage }?: {
98
- readonly uiLanguage?: string;
99
- readonly contentLanguage?: string;
100
- });
101
- /**
102
- * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
103
- *
104
- * **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
105
- * properties instead.
106
- *
107
- * @deprecated
108
- */
109
- get language(): string;
110
- /**
111
- * An unbound version of the {@link #t} method.
112
- */
113
- private _t;
114
- }
115
- /**
116
- * @param message A message that will be localized (translated).
117
- * @param values A value or an array of values that will fill message placeholders.
118
- * For messages supporting plural forms the first value will determine the plural form.
119
- */
120
- export type LocaleTranslate = (message: string | Message, values?: number | string | ReadonlyArray<number | string>) => string;
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
+ import { type Message } from './translation-service';
6
+ import { type LanguageDirection } from './language';
7
+ /**
8
+ * Represents the localization services.
9
+ */
10
+ export default class Locale {
11
+ /**
12
+ * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
13
+ *
14
+ * If the {@link #contentLanguage content language} was not specified in the `Locale` constructor,
15
+ * it also defines the language of the content.
16
+ */
17
+ readonly uiLanguage: string;
18
+ /**
19
+ * Text direction of the {@link #uiLanguage editor UI language}. Either `'ltr'` or `'rtl'`.
20
+ */
21
+ readonly uiLanguageDirection: LanguageDirection;
22
+ /**
23
+ * The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
24
+ *
25
+ * Usually the same as the {@link #uiLanguage editor language}, it can be customized by passing an optional
26
+ * argument to the `Locale` constructor.
27
+ */
28
+ readonly contentLanguage: string;
29
+ /**
30
+ * Text direction of the {@link #contentLanguage editor content language}.
31
+ *
32
+ * If the content language was passed directly to the `Locale` constructor, this property represents the
33
+ * direction of that language.
34
+ *
35
+ * If the {@link #contentLanguage editor content language} was derived from the {@link #uiLanguage editor language},
36
+ * the content language direction is the same as the {@link #uiLanguageDirection UI language direction}.
37
+ *
38
+ * The value is either `'ltr'` or `'rtl'`.
39
+ */
40
+ readonly contentLanguageDirection: LanguageDirection;
41
+ /**
42
+ * Translates the given message to the {@link #uiLanguage}. This method is also available in
43
+ * {@link module:core/editor/editor~Editor#t `Editor`} and {@link module:ui/view~View#t `View`}.
44
+ *
45
+ * This method's context is statically bound to the `Locale` instance and **should always be called as a function**:
46
+ *
47
+ * ```ts
48
+ * const t = locale.t;
49
+ * t( 'Label' );
50
+ * ```
51
+ *
52
+ * The message can be either a string or an object implementing the {@link module:utils/translation-service~Message} interface.
53
+ *
54
+ * The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter.
55
+ * For an array of values, the `%<index>` will be changed to an element of that array at the given index.
56
+ * For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.
57
+ *
58
+ * ```ts
59
+ * t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
60
+ * t( 'Created file "%0", fileName );
61
+ * ```
62
+ *
63
+ * The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form
64
+ * will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used
65
+ * as a default plural translation when the translation for the target language is missing.
66
+ *
67
+ * ```ts
68
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
69
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
70
+ * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.
71
+ *
72
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
73
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
74
+ * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
75
+ * ```
76
+ *
77
+ * * The message should provide an ID using the `id` property when the message strings are not unique and their
78
+ * translations should be different.
79
+ *
80
+ * ```ts
81
+ * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
82
+ * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
83
+ * ```
84
+ */
85
+ readonly t: LocaleTranslate;
86
+ /**
87
+ * Creates a new instance of the locale class. Learn more about
88
+ * {@glink features/ui-language configuring the language of the editor}.
89
+ *
90
+ * @param options Locale configuration.
91
+ * @param options.uiLanguage The editor UI language code in the
92
+ * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
93
+ * @param options.contentLanguage The editor content language code in the
94
+ * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
95
+ * See {@link #contentLanguage}.
96
+ */
97
+ constructor({ uiLanguage, contentLanguage }?: {
98
+ readonly uiLanguage?: string;
99
+ readonly contentLanguage?: string;
100
+ });
101
+ /**
102
+ * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
103
+ *
104
+ * **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
105
+ * properties instead.
106
+ *
107
+ * @deprecated
108
+ */
109
+ get language(): string;
110
+ /**
111
+ * An unbound version of the {@link #t} method.
112
+ */
113
+ private _t;
114
+ }
115
+ /**
116
+ * @param message A message that will be localized (translated).
117
+ * @param values A value or an array of values that will fill message placeholders.
118
+ * For messages supporting plural forms the first value will determine the plural form.
119
+ */
120
+ export type LocaleTranslate = (message: string | Message, values?: number | string | ReadonlyArray<number | string>) => string;