@ckeditor/ckeditor5-utils 0.0.0-internal-20241017.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 (213) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +22 -0
  4. package/dist/abortabledebounce.d.ts +21 -0
  5. package/dist/areconnectedthroughproperties.d.ts +15 -0
  6. package/dist/ckeditorerror.d.ts +127 -0
  7. package/dist/collection.d.ts +437 -0
  8. package/dist/comparearrays.d.ts +34 -0
  9. package/dist/config.d.ts +167 -0
  10. package/dist/count.d.ts +22 -0
  11. package/dist/crc32.d.ts +30 -0
  12. package/dist/delay.d.ts +23 -0
  13. package/dist/diff.d.ts +35 -0
  14. package/dist/difftochanges.d.ts +63 -0
  15. package/dist/dom/createelement.d.ts +61 -0
  16. package/dist/dom/emittermixin.d.ts +146 -0
  17. package/dist/dom/findclosestscrollableancestor.d.ts +15 -0
  18. package/dist/dom/getancestors.d.ts +21 -0
  19. package/dist/dom/getborderwidths.d.ts +28 -0
  20. package/dist/dom/getcommonancestor.d.ts +16 -0
  21. package/dist/dom/getdatafromelement.d.ts +18 -0
  22. package/dist/dom/getpositionedancestor.d.ts +14 -0
  23. package/dist/dom/getrangefrommouseevent.d.ts +21 -0
  24. package/dist/dom/global.d.ts +36 -0
  25. package/dist/dom/indexof.d.ts +18 -0
  26. package/dist/dom/insertat.d.ts +19 -0
  27. package/dist/dom/iscomment.d.ts +15 -0
  28. package/dist/dom/isnode.d.ts +15 -0
  29. package/dist/dom/isrange.d.ts +15 -0
  30. package/dist/dom/istext.d.ts +15 -0
  31. package/dist/dom/isvalidattributename.d.ts +14 -0
  32. package/dist/dom/isvisible.d.ts +19 -0
  33. package/dist/dom/iswindow.d.ts +15 -0
  34. package/dist/dom/position.d.ts +215 -0
  35. package/dist/dom/rect.d.ts +199 -0
  36. package/dist/dom/remove.d.ts +17 -0
  37. package/dist/dom/resizeobserver.d.ts +78 -0
  38. package/dist/dom/scroll.d.ts +77 -0
  39. package/dist/dom/setdatainelement.d.ts +18 -0
  40. package/dist/dom/tounit.d.ts +26 -0
  41. package/dist/elementreplacer.d.ts +35 -0
  42. package/dist/emittermixin.d.ts +316 -0
  43. package/dist/env.d.ts +144 -0
  44. package/dist/eventinfo.d.ts +62 -0
  45. package/dist/fastdiff.d.ts +116 -0
  46. package/dist/first.d.ts +15 -0
  47. package/dist/focustracker.d.ts +83 -0
  48. package/dist/index-content.css +4 -0
  49. package/dist/index-editor.css +4 -0
  50. package/dist/index.css +4 -0
  51. package/dist/index.d.ts +70 -0
  52. package/dist/index.js +5871 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/inserttopriorityarray.d.ts +34 -0
  55. package/dist/isiterable.d.ts +18 -0
  56. package/dist/keyboard.d.ts +130 -0
  57. package/dist/keystrokehandler.d.ts +101 -0
  58. package/dist/language.d.ts +21 -0
  59. package/dist/locale.d.ts +145 -0
  60. package/dist/mapsequal.d.ts +19 -0
  61. package/dist/mix.d.ts +89 -0
  62. package/dist/nth.d.ts +20 -0
  63. package/dist/objecttomap.d.ts +27 -0
  64. package/dist/observablemixin.d.ts +564 -0
  65. package/dist/parsebase64encodedobject.d.ts +15 -0
  66. package/dist/priorities.d.ts +37 -0
  67. package/dist/retry.d.ts +37 -0
  68. package/dist/splicearray.d.ts +30 -0
  69. package/dist/spy.d.ts +25 -0
  70. package/dist/toarray.d.ts +29 -0
  71. package/dist/tomap.d.ts +23 -0
  72. package/dist/translation-service.d.ts +178 -0
  73. package/dist/uid.d.ts +19 -0
  74. package/dist/unicode.d.ts +58 -0
  75. package/dist/version.d.ts +14 -0
  76. package/dist/wait.d.ts +20 -0
  77. package/package.json +36 -0
  78. package/src/abortabledebounce.d.ts +17 -0
  79. package/src/abortabledebounce.js +22 -0
  80. package/src/areconnectedthroughproperties.d.ts +11 -0
  81. package/src/areconnectedthroughproperties.js +73 -0
  82. package/src/ckeditorerror.d.ts +123 -0
  83. package/src/ckeditorerror.js +176 -0
  84. package/src/collection.d.ts +433 -0
  85. package/src/collection.js +583 -0
  86. package/src/comparearrays.d.ts +30 -0
  87. package/src/comparearrays.js +47 -0
  88. package/src/config.d.ts +163 -0
  89. package/src/config.js +163 -0
  90. package/src/count.d.ts +18 -0
  91. package/src/count.js +25 -0
  92. package/src/crc32.d.ts +26 -0
  93. package/src/crc32.js +61 -0
  94. package/src/delay.d.ts +19 -0
  95. package/src/delay.js +26 -0
  96. package/src/diff.d.ts +31 -0
  97. package/src/diff.js +115 -0
  98. package/src/difftochanges.d.ts +59 -0
  99. package/src/difftochanges.js +79 -0
  100. package/src/dom/createelement.d.ts +57 -0
  101. package/src/dom/createelement.js +40 -0
  102. package/src/dom/emittermixin.d.ts +142 -0
  103. package/src/dom/emittermixin.js +239 -0
  104. package/src/dom/findclosestscrollableancestor.d.ts +11 -0
  105. package/src/dom/findclosestscrollableancestor.js +31 -0
  106. package/src/dom/getancestors.d.ts +17 -0
  107. package/src/dom/getancestors.js +27 -0
  108. package/src/dom/getborderwidths.d.ts +24 -0
  109. package/src/dom/getborderwidths.js +24 -0
  110. package/src/dom/getcommonancestor.d.ts +12 -0
  111. package/src/dom/getcommonancestor.js +25 -0
  112. package/src/dom/getdatafromelement.d.ts +14 -0
  113. package/src/dom/getdatafromelement.js +20 -0
  114. package/src/dom/getpositionedancestor.d.ts +10 -0
  115. package/src/dom/getpositionedancestor.js +22 -0
  116. package/src/dom/getrangefrommouseevent.d.ts +17 -0
  117. package/src/dom/getrangefrommouseevent.js +33 -0
  118. package/src/dom/global.d.ts +32 -0
  119. package/src/dom/global.js +35 -0
  120. package/src/dom/indexof.d.ts +14 -0
  121. package/src/dom/indexof.js +21 -0
  122. package/src/dom/insertat.d.ts +15 -0
  123. package/src/dom/insertat.js +17 -0
  124. package/src/dom/iscomment.d.ts +11 -0
  125. package/src/dom/iscomment.js +14 -0
  126. package/src/dom/isnode.d.ts +11 -0
  127. package/src/dom/isnode.js +21 -0
  128. package/src/dom/isrange.d.ts +11 -0
  129. package/src/dom/isrange.js +13 -0
  130. package/src/dom/istext.d.ts +11 -0
  131. package/src/dom/istext.js +13 -0
  132. package/src/dom/isvalidattributename.d.ts +10 -0
  133. package/src/dom/isvalidattributename.js +22 -0
  134. package/src/dom/isvisible.d.ts +15 -0
  135. package/src/dom/isvisible.js +30 -0
  136. package/src/dom/iswindow.d.ts +11 -0
  137. package/src/dom/iswindow.js +22 -0
  138. package/src/dom/position.d.ts +211 -0
  139. package/src/dom/position.js +313 -0
  140. package/src/dom/rect.d.ts +195 -0
  141. package/src/dom/rect.js +474 -0
  142. package/src/dom/remove.d.ts +13 -0
  143. package/src/dom/remove.js +18 -0
  144. package/src/dom/resizeobserver.d.ts +74 -0
  145. package/src/dom/resizeobserver.js +127 -0
  146. package/src/dom/scroll.d.ts +73 -0
  147. package/src/dom/scroll.js +383 -0
  148. package/src/dom/setdatainelement.d.ts +14 -0
  149. package/src/dom/setdatainelement.js +20 -0
  150. package/src/dom/tounit.d.ts +22 -0
  151. package/src/dom/tounit.js +16 -0
  152. package/src/elementreplacer.d.ts +31 -0
  153. package/src/elementreplacer.js +43 -0
  154. package/src/emittermixin.d.ts +312 -0
  155. package/src/emittermixin.js +453 -0
  156. package/src/env.d.ts +140 -0
  157. package/src/env.js +145 -0
  158. package/src/eventinfo.d.ts +58 -0
  159. package/src/eventinfo.js +26 -0
  160. package/src/fastdiff.d.ts +112 -0
  161. package/src/fastdiff.js +248 -0
  162. package/src/first.d.ts +11 -0
  163. package/src/first.js +17 -0
  164. package/src/focustracker.d.ts +79 -0
  165. package/src/focustracker.js +101 -0
  166. package/src/index.d.ts +66 -0
  167. package/src/index.js +65 -0
  168. package/src/inserttopriorityarray.d.ts +30 -0
  169. package/src/inserttopriorityarray.js +21 -0
  170. package/src/isiterable.d.ts +14 -0
  171. package/src/isiterable.js +16 -0
  172. package/src/keyboard.d.ts +126 -0
  173. package/src/keyboard.js +252 -0
  174. package/src/keystrokehandler.d.ts +97 -0
  175. package/src/keystrokehandler.js +122 -0
  176. package/src/language.d.ts +17 -0
  177. package/src/language.js +20 -0
  178. package/src/locale.d.ts +141 -0
  179. package/src/locale.js +78 -0
  180. package/src/mapsequal.d.ts +15 -0
  181. package/src/mapsequal.js +27 -0
  182. package/src/mix.d.ts +85 -0
  183. package/src/mix.js +50 -0
  184. package/src/nth.d.ts +16 -0
  185. package/src/nth.js +24 -0
  186. package/src/objecttomap.d.ts +23 -0
  187. package/src/objecttomap.js +27 -0
  188. package/src/observablemixin.d.ts +560 -0
  189. package/src/observablemixin.js +580 -0
  190. package/src/parsebase64encodedobject.d.ts +11 -0
  191. package/src/parsebase64encodedobject.js +22 -0
  192. package/src/priorities.d.ts +33 -0
  193. package/src/priorities.js +23 -0
  194. package/src/retry.d.ts +33 -0
  195. package/src/retry.js +47 -0
  196. package/src/splicearray.d.ts +26 -0
  197. package/src/splicearray.js +40 -0
  198. package/src/spy.d.ts +21 -0
  199. package/src/spy.js +22 -0
  200. package/src/toarray.d.ts +25 -0
  201. package/src/toarray.js +7 -0
  202. package/src/tomap.d.ts +19 -0
  203. package/src/tomap.js +29 -0
  204. package/src/translation-service.d.ts +174 -0
  205. package/src/translation-service.js +209 -0
  206. package/src/uid.d.ts +15 -0
  207. package/src/uid.js +45 -0
  208. package/src/unicode.d.ts +54 -0
  209. package/src/unicode.js +85 -0
  210. package/src/version.d.ts +10 -0
  211. package/src/version.js +179 -0
  212. package/src/wait.d.ts +16 -0
  213. package/src/wait.js +29 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { type PriorityString } from './priorities.js';
10
+ /**
11
+ * @module utils/inserttopriorityarray
12
+ */
13
+ /**
14
+ * The priority object descriptor.
15
+ *
16
+ * ```ts
17
+ * const objectWithPriority = {
18
+ * priority: 'high'
19
+ * }
20
+ * ```
21
+ */
22
+ export interface ObjectWithPriority {
23
+ /**
24
+ * Priority of the object.
25
+ */
26
+ priority: PriorityString;
27
+ }
28
+ /**
29
+ * Inserts any object with priority at correct index by priority so registered objects are always sorted from highest to lowest priority.
30
+ *
31
+ * @param objects Array of objects with priority to insert object to.
32
+ * @param objectToInsert Object with `priority` property.
33
+ */
34
+ export default function insertToPriorityArray<T extends ObjectWithPriority>(objects: Array<T>, objectToInsert: T): void;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/isiterable
11
+ */
12
+ /**
13
+ * Checks if value implements iterator interface.
14
+ *
15
+ * @param value The value to check.
16
+ * @returns True if value implements iterator interface.
17
+ */
18
+ export default function isIterable(value: any): value is Iterable<any>;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * A set of utilities related to keyboard support.
11
+ *
12
+ * @module utils/keyboard
13
+ */
14
+ import type { LanguageDirection } from './language.js';
15
+ /**
16
+ * An object with `keyName => keyCode` pairs for a set of known keys.
17
+ *
18
+ * Contains:
19
+ *
20
+ * * `a-z`,
21
+ * * `0-9`,
22
+ * * `f1-f12`,
23
+ * * `` ` ``, `-`, `=`, `[`, `]`, `;`, `'`, `,`, `.`, `/`, `\`,
24
+ * * `arrow(left|up|right|bottom)`,
25
+ * * `backspace`, `delete`, `enter`, `esc`, `tab`,
26
+ * * `ctrl`, `cmd`, `shift`, `alt`.
27
+ */
28
+ export declare const keyCodes: {
29
+ readonly [keyCode: string]: number;
30
+ };
31
+ /**
32
+ * Converts a key name or {@link module:utils/keyboard~KeystrokeInfo keystroke info} into a key code.
33
+ *
34
+ * Note: Key names are matched with {@link module:utils/keyboard#keyCodes} in a case-insensitive way.
35
+ *
36
+ * @param key A key name (see {@link module:utils/keyboard#keyCodes}) or a keystroke data object.
37
+ * @returns Key or keystroke code.
38
+ */
39
+ export declare function getCode(key: string | Readonly<KeystrokeInfo>): number;
40
+ /**
41
+ * Parses the keystroke and returns a keystroke code that will match the code returned by
42
+ * {@link module:utils/keyboard~getCode} for the corresponding {@link module:utils/keyboard~KeystrokeInfo keystroke info}.
43
+ *
44
+ * The keystroke can be passed in two formats:
45
+ *
46
+ * * as a single string – e.g. `ctrl + A`,
47
+ * * as an array of {@link module:utils/keyboard~keyCodes known key names} and key codes – e.g.:
48
+ * * `[ 'ctrl', 32 ]` (ctrl + space),
49
+ * * `[ 'ctrl', 'a' ]` (ctrl + A).
50
+ *
51
+ * Note: Key names are matched with {@link module:utils/keyboard#keyCodes} in a case-insensitive way.
52
+ *
53
+ * Note: Only keystrokes with a single non-modifier key are supported (e.g. `ctrl+A` is OK, but `ctrl+A+B` is not).
54
+ *
55
+ * Note: On macOS, keystroke handling is translating the `Ctrl` key to the `Cmd` key and handling only that keystroke.
56
+ * For example, a registered keystroke `Ctrl+A` will be translated to `Cmd+A` on macOS. To disable the translation of some keystroke,
57
+ * use the forced modifier: `Ctrl!+A` (note the exclamation mark).
58
+ *
59
+ * @param keystroke The keystroke definition.
60
+ * @returns Keystroke code.
61
+ */
62
+ export declare function parseKeystroke(keystroke: string | ReadonlyArray<number | string>): number;
63
+ /**
64
+ * Translates any keystroke string text like `"Ctrl+A"` to an
65
+ * environment–specific keystroke, i.e. `"⌘A"` on macOS.
66
+ *
67
+ * @param keystroke The keystroke text.
68
+ * @returns The keystroke text specific for the environment.
69
+ */
70
+ export declare function getEnvKeystrokeText(keystroke: string): string;
71
+ /**
72
+ * Returns `true` if the provided key code represents one of the arrow keys.
73
+ *
74
+ * @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
75
+ */
76
+ export declare function isArrowKeyCode(keyCode: number): boolean;
77
+ /**
78
+ * String representing a direction of an arrow key kode.
79
+ */
80
+ export type ArrowKeyCodeDirection = 'left' | 'up' | 'right' | 'down';
81
+ /**
82
+ * Returns the direction in which the {@link module:engine/model/documentselection~DocumentSelection selection}
83
+ * will move when the provided arrow key code is pressed considering the language direction of the editor content.
84
+ *
85
+ * For instance, in right–to–left (RTL) content languages, pressing the left arrow means moving the selection right (forward)
86
+ * in the model structure. Similarly, pressing the right arrow moves the selection left (backward).
87
+ *
88
+ * @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
89
+ * @param contentLanguageDirection The content language direction, corresponding to
90
+ * {@link module:utils/locale~Locale#contentLanguageDirection}.
91
+ * @returns Localized arrow direction or `undefined` for non-arrow key codes.
92
+ */
93
+ export declare function getLocalizedArrowKeyCodeDirection(keyCode: number, contentLanguageDirection: LanguageDirection): ArrowKeyCodeDirection | undefined;
94
+ /**
95
+ * Determines if the provided key code moves the {@link module:engine/model/documentselection~DocumentSelection selection}
96
+ * forward or backward considering the language direction of the editor content.
97
+ *
98
+ * For instance, in right–to–left (RTL) languages, pressing the left arrow means moving forward
99
+ * in the model structure. Similarly, pressing the right arrow moves the selection backward.
100
+ *
101
+ * @param keyCode A key code as in {@link module:utils/keyboard~KeystrokeInfo#keyCode}.
102
+ * @param contentLanguageDirection The content language direction, corresponding to
103
+ * {@link module:utils/locale~Locale#contentLanguageDirection}.
104
+ */
105
+ export declare function isForwardArrowKeyCode(keyCode: number, contentLanguageDirection: LanguageDirection): boolean;
106
+ /**
107
+ * Information about the keystroke.
108
+ */
109
+ export interface KeystrokeInfo {
110
+ /**
111
+ * The [key code](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode).
112
+ */
113
+ keyCode: number;
114
+ /**
115
+ * Whether the <kbd>Alt</kbd> modifier was pressed.
116
+ */
117
+ altKey: boolean;
118
+ /**
119
+ * Whether the <kbd>Cmd</kbd> modifier was pressed.
120
+ */
121
+ metaKey: boolean;
122
+ /**
123
+ * Whether the <kbd>Ctrl</kbd> modifier was pressed.
124
+ */
125
+ ctrlKey: boolean;
126
+ /**
127
+ * Whether the <kbd>Shift</kbd> modifier was pressed.
128
+ */
129
+ shiftKey: boolean;
130
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type { Emitter } from './emittermixin.js';
10
+ import { type KeystrokeInfo } from './keyboard.js';
11
+ import type { PriorityString } from './priorities.js';
12
+ /**
13
+ * Keystroke handler allows registering callbacks for given keystrokes.
14
+ *
15
+ * The most frequent use of this class is through the {@link module:core/editor/editor~Editor#keystrokes `editor.keystrokes`}
16
+ * property. It allows listening to keystrokes executed in the editing view:
17
+ *
18
+ * ```ts
19
+ * editor.keystrokes.set( 'Ctrl+A', ( keyEvtData, cancel ) => {
20
+ * console.log( 'Ctrl+A has been pressed' );
21
+ * cancel();
22
+ * } );
23
+ * ```
24
+ *
25
+ * However, this utility class can be used in various part of the UI. For instance, a certain {@link module:ui/view~View}
26
+ * can use it like this:
27
+ *
28
+ * ```ts
29
+ * class MyView extends View {
30
+ * constructor() {
31
+ * this.keystrokes = new KeystrokeHandler();
32
+ *
33
+ * this.keystrokes.set( 'tab', handleTabKey );
34
+ * }
35
+ *
36
+ * render() {
37
+ * super.render();
38
+ *
39
+ * this.keystrokes.listenTo( this.element );
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * That keystroke handler will listen to `keydown` events fired in this view's main element.
45
+ *
46
+ */
47
+ export default class KeystrokeHandler {
48
+ /**
49
+ * Listener used to listen to events for easier keystroke handler destruction.
50
+ */
51
+ private readonly _listener;
52
+ /**
53
+ * Creates an instance of the keystroke handler.
54
+ */
55
+ constructor();
56
+ /**
57
+ * Starts listening for `keydown` events from a given emitter.
58
+ */
59
+ listenTo(emitter: Emitter | HTMLElement | Window): void;
60
+ /**
61
+ * Registers a handler for the specified keystroke.
62
+ *
63
+ * @param keystroke Keystroke defined in a format accepted by
64
+ * the {@link module:utils/keyboard~parseKeystroke} function.
65
+ * @param callback A function called with the
66
+ * {@link module:engine/view/observer/keyobserver~KeyEventData key event data} object and
67
+ * a helper function to call both `preventDefault()` and `stopPropagation()` on the underlying event.
68
+ * @param options Additional options.
69
+ */
70
+ set(keystroke: string | ReadonlyArray<string | number>, callback: (ev: KeyboardEvent, cancel: () => void) => void, options?: KeystrokeHandlerOptions): void;
71
+ /**
72
+ * Triggers a keystroke handler for a specified key combination, if such a keystroke was {@link #set defined}.
73
+ *
74
+ * @param keyEvtData Key event data.
75
+ * @returns Whether the keystroke was handled.
76
+ */
77
+ press(keyEvtData: Readonly<KeystrokeInfo>): boolean;
78
+ /**
79
+ * Stops listening to `keydown` events from the given emitter.
80
+ */
81
+ stopListening(emitter?: Emitter | HTMLElement | Window): void;
82
+ /**
83
+ * Destroys the keystroke handler.
84
+ */
85
+ destroy(): void;
86
+ }
87
+ /**
88
+ * {@link module:utils/keystrokehandler~KeystrokeHandler#set} method options.
89
+ */
90
+ export interface KeystrokeHandlerOptions {
91
+ /**
92
+ * The priority of the keystroke callback. The higher the priority value the sooner the callback will be executed.
93
+ * Keystrokes having the same priority are called in the order they were added.
94
+ */
95
+ readonly priority?: PriorityString;
96
+ /**
97
+ * An optional callback function allowing for filtering keystrokes based on arbitrary criteria.
98
+ * The callback function receives `keydown` DOM event as a parameter.
99
+ */
100
+ readonly filter?: (keyEvtData: KeyboardEvent) => boolean;
101
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/language
11
+ */
12
+ /**
13
+ * String representing a language direction.
14
+ */
15
+ export type LanguageDirection = 'ltr' | 'rtl';
16
+ /**
17
+ * Helps determine whether a language text direction is LTR or RTL.
18
+ *
19
+ * @param languageCode The ISO 639-1 or ISO 639-2 language code.
20
+ */
21
+ export declare function getLanguageDirection(languageCode: string): LanguageDirection;
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/locale
11
+ */
12
+ import { type ArrayOrItem } from './toarray.js';
13
+ import { type Message } from './translation-service.js';
14
+ import { type LanguageDirection } from './language.js';
15
+ /**
16
+ * Represents the localization services.
17
+ */
18
+ export default class Locale {
19
+ /**
20
+ * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
21
+ *
22
+ * If the {@link #contentLanguage content language} was not specified in the `Locale` constructor,
23
+ * it also defines the language of the content.
24
+ */
25
+ readonly uiLanguage: string;
26
+ /**
27
+ * Text direction of the {@link #uiLanguage editor UI language}. Either `'ltr'` or `'rtl'`.
28
+ */
29
+ readonly uiLanguageDirection: LanguageDirection;
30
+ /**
31
+ * The editor content language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
32
+ *
33
+ * Usually the same as the {@link #uiLanguage editor language}, it can be customized by passing an optional
34
+ * argument to the `Locale` constructor.
35
+ */
36
+ readonly contentLanguage: string;
37
+ /**
38
+ * Text direction of the {@link #contentLanguage editor content language}.
39
+ *
40
+ * If the content language was passed directly to the `Locale` constructor, this property represents the
41
+ * direction of that language.
42
+ *
43
+ * If the {@link #contentLanguage editor content language} was derived from the {@link #uiLanguage editor language},
44
+ * the content language direction is the same as the {@link #uiLanguageDirection UI language direction}.
45
+ *
46
+ * The value is either `'ltr'` or `'rtl'`.
47
+ */
48
+ readonly contentLanguageDirection: LanguageDirection;
49
+ /**
50
+ * Translates the given message to the {@link #uiLanguage}. This method is also available in
51
+ * {@link module:core/editor/editor~Editor#t `Editor`} and {@link module:ui/view~View#t `View`}.
52
+ *
53
+ * This method's context is statically bound to the `Locale` instance and **should always be called as a function**:
54
+ *
55
+ * ```ts
56
+ * const t = locale.t;
57
+ * t( 'Label' );
58
+ * ```
59
+ *
60
+ * The message can be either a string or an object implementing the {@link module:utils/translation-service~Message} interface.
61
+ *
62
+ * The message may contain placeholders (`%<index>`) for value(s) that are passed as a `values` parameter.
63
+ * For an array of values, the `%<index>` will be changed to an element of that array at the given index.
64
+ * For a single value passed as the second argument, only the `%0` placeholders will be changed to the provided value.
65
+ *
66
+ * ```ts
67
+ * t( 'Created file "%0" in %1ms.', [ fileName, timeTaken ] );
68
+ * t( 'Created file "%0", fileName );
69
+ * ```
70
+ *
71
+ * The message supports plural forms. To specify the plural form, use the `plural` property. Singular or plural form
72
+ * will be chosen depending on the first value from the passed `values`. The value of the `plural` property is used
73
+ * as a default plural translation when the translation for the target language is missing.
74
+ *
75
+ * ```ts
76
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space' for the English language.
77
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Add 5 spaces' for the English language.
78
+ * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Add 2 spaces' for the English language.
79
+ *
80
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Dodaj spację' for the Polish language.
81
+ * t( { string: 'Add a space', plural: 'Add %0 spaces' }, 5 ); // 'Dodaj 5 spacji' for the Polish language.
82
+ * t( { string: '%1 a space', plural: '%1 %0 spaces' }, [ 2, 'Add' ] ); // 'Dodaj 2 spacje' for the Polish language.
83
+ * ```
84
+ *
85
+ * * The message should provide an ID using the `id` property when the message strings are not unique and their
86
+ * translations should be different.
87
+ *
88
+ * ```ts
89
+ * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
90
+ * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
91
+ * ```
92
+ */
93
+ readonly t: LocaleTranslate;
94
+ /**
95
+ * Object that contains translations.
96
+ */
97
+ translations?: Translations;
98
+ /**
99
+ * Creates a new instance of the locale class. Learn more about
100
+ * {@glink getting-started/setup/ui-language configuring the language of the editor}.
101
+ *
102
+ * @param options Locale configuration.
103
+ * @param options.uiLanguage The editor UI language code in the
104
+ * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. See {@link #uiLanguage}.
105
+ * @param options.contentLanguage The editor content language code in the
106
+ * [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format. If not specified, the same as `options.language`.
107
+ * See {@link #contentLanguage}.
108
+ * @param translations Translations passed as a editor config parameter.
109
+ */
110
+ constructor({ uiLanguage, contentLanguage, translations }?: {
111
+ readonly uiLanguage?: string;
112
+ readonly contentLanguage?: string;
113
+ readonly translations?: ArrayOrItem<Translations>;
114
+ });
115
+ /**
116
+ * The editor UI language code in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
117
+ *
118
+ * **Note**: This property was deprecated. Please use {@link #uiLanguage} and {@link #contentLanguage}
119
+ * properties instead.
120
+ *
121
+ * @deprecated
122
+ */
123
+ get language(): string;
124
+ /**
125
+ * An unbound version of the {@link #t} method.
126
+ */
127
+ private _t;
128
+ }
129
+ /**
130
+ * @param message A message that will be localized (translated).
131
+ * @param values A value or an array of values that will fill message placeholders.
132
+ * For messages supporting plural forms the first value will determine the plural form.
133
+ */
134
+ export type LocaleTranslate = (message: string | Message, values?: number | string | ReadonlyArray<number | string>) => string;
135
+ /**
136
+ * Translations object definition.
137
+ */
138
+ export type Translations = {
139
+ [language: string]: {
140
+ dictionary: {
141
+ [messageId: string]: string | ReadonlyArray<string>;
142
+ };
143
+ getPluralForm?: ((n: number) => number | boolean) | null;
144
+ };
145
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/mapsequal
11
+ */
12
+ /**
13
+ * Checks whether given `Map`s are equal, that is has same size and same key-value pairs.
14
+ *
15
+ * @param mapA The first map to compare.
16
+ * @param mapB The second map to compare.
17
+ * @returns `true` if given maps are equal, `false` otherwise.
18
+ */
19
+ export default function mapsEqual<Key>(mapA: Map<Key, unknown>, mapB: Map<Key, unknown>): boolean;
package/dist/mix.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/mix
11
+ */
12
+ /**
13
+ * Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
14
+ * prototype of first object (a constructor).
15
+ *
16
+ * ```
17
+ * class Editor {
18
+ * ...
19
+ * }
20
+ *
21
+ * const SomeMixin = {
22
+ * a() {
23
+ * return 'a';
24
+ * }
25
+ * };
26
+ *
27
+ * mix( Editor, SomeMixin, ... );
28
+ *
29
+ * new Editor().a(); // -> 'a'
30
+ * ```
31
+ *
32
+ * Note: Properties which already exist in the base class will not be overriden.
33
+ *
34
+ * @deprecated Use mixin pattern, see: https://www.typescriptlang.org/docs/handbook/mixins.html.
35
+ * @param baseClass Class which prototype will be extended.
36
+ * @param mixins Objects from which to get properties.
37
+ */
38
+ export default function mix(baseClass: Function, ...mixins: Array<object>): void;
39
+ /**
40
+ * Helper type that represents constructor creating given objects. Can be used as a type constraint.
41
+ *
42
+ * ```ts
43
+ * // The function accepts any class constructor.
44
+ * function MyFunction<Ctor extends Constructor>( ctor: Ctor ) {
45
+ * // ...
46
+ * }
47
+ *
48
+ * // The function accepts any class constructor of type derived from `MyBase`.
49
+ * function MyFunction<Ctor extends Constructor<MyBase>>( ctor: Ctor ) {
50
+ * // ...
51
+ * }
52
+ * ```
53
+ */
54
+ export type Constructor<Instance = object> = abstract new (...args: Array<any>) => Instance;
55
+ /**
56
+ * Helper type that creates constructor types from a base class and a mixin interface.
57
+ *
58
+ * ```ts
59
+ * interface MyMixinInterface {
60
+ * mixinMethod(): void;
61
+ * }
62
+ *
63
+ * function MyMixin<Base extends Constructor>( base: Base ): Mixed<Base, MyMixinInterface> {
64
+ * // ...
65
+ * }
66
+ *
67
+ * class BaseClass {
68
+ * baseMethod(): void {
69
+ * // ...
70
+ * }
71
+ * }
72
+ *
73
+ * const MixedClass = MyMixin( BaseClass );
74
+ *
75
+ * // Contains both `mixinMethod()` and `baseMethod()`.
76
+ * const myObject = new MixedClass();
77
+ * myObject.mixinMethod();
78
+ * myObject.baseMethod();
79
+ * ```
80
+ *
81
+ * @typeParam Base A type of constructor of a class to apply mixin to.
82
+ * @typeParam Mixin An interface representing mixin.
83
+ */
84
+ export type Mixed<Base extends Constructor, Mixin extends object> = {
85
+ new (...args: ConstructorParameters<Base>): Mixin & InstanceType<Base>;
86
+ prototype: Mixin & InstanceType<Base>;
87
+ } & {
88
+ [K in keyof Base]: Base[K];
89
+ };
package/dist/nth.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/nth
11
+ */
12
+ /**
13
+ * Returns `nth` (starts from `0` of course) item of the given `iterable`.
14
+ *
15
+ * If the iterable is a generator, then it consumes **all its items**.
16
+ * If it's a normal iterator, then it consumes **all items up to the given index**.
17
+ * Refer to the [Iterators and Generators](https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Iterators_and_Generators)
18
+ * guide to learn differences between these interfaces.
19
+ */
20
+ export default function nth<T>(index: number, iterable: Iterable<T>): T | null;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module utils/objecttomap
11
+ */
12
+ /**
13
+ * Transforms object to map.
14
+ *
15
+ * ```ts
16
+ * const map = objectToMap( { 'foo': 1, 'bar': 2 } );
17
+ * map.get( 'foo' ); // 1
18
+ * ```
19
+ *
20
+ * **Note**: For mixed data (`Object` or `Iterable`) there's a dedicated {@link module:utils/tomap~toMap} function.
21
+ *
22
+ * @param obj Object to transform.
23
+ * @returns Map created from object.
24
+ */
25
+ export default function objectToMap<T>(obj: {
26
+ readonly [key: string]: T;
27
+ } | null | undefined): Map<string, T>;