@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
package/dist/spy.d.ts ADDED
@@ -0,0 +1,25 @@
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/spy
11
+ */
12
+ /**
13
+ * Creates a spy function (ala Sinon.js) that can be used to inspect call to it.
14
+ *
15
+ * The following are the present features:
16
+ *
17
+ * * spy.called: property set to `true` if the function has been called at least once.
18
+ *
19
+ * @returns The spy function.
20
+ */
21
+ declare function spy(): {
22
+ (): void;
23
+ called?: boolean;
24
+ };
25
+ export default spy;
@@ -0,0 +1,29 @@
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/toarray
11
+ */
12
+ /**
13
+ * Transforms any value to an array. If the provided value is already an array, it is returned unchanged.
14
+ *
15
+ * @label MUTABLE
16
+ * @param data The value to transform to an array.
17
+ * @returns An array created from data.
18
+ */
19
+ export default function toArray<T>(data: ArrayOrItem<T>): Array<T>;
20
+ /**
21
+ * Transforms any value to an array. If the provided value is already an array, it is returned unchanged.
22
+ *
23
+ * @label IMMUTABLE
24
+ * @param data The value to transform to an array.
25
+ * @returns An array created from data.
26
+ */
27
+ export default function toArray<T>(data: ReadonlyArrayOrItem<T>): ReadonlyArray<T>;
28
+ export type ArrayOrItem<T> = T | Array<T>;
29
+ export type ReadonlyArrayOrItem<T> = T | ReadonlyArray<T>;
@@ -0,0 +1,23 @@
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
+ * Transforms object or iterable to map. Iterable needs to be in the format acceptable by the `Map` constructor.
11
+ *
12
+ * ```ts
13
+ * map = toMap( { 'foo': 1, 'bar': 2 } );
14
+ * map = toMap( [ [ 'foo', 1 ], [ 'bar', 2 ] ] );
15
+ * map = toMap( anotherMap );
16
+ * ```
17
+ *
18
+ * @param data Object or iterable to transform.
19
+ * @returns Map created from data.
20
+ */
21
+ export default function toMap<T>(data: {
22
+ readonly [key: string]: T;
23
+ } | Iterable<readonly [string, T]> | null | undefined): Map<string, T>;
@@ -0,0 +1,178 @@
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/translation-service
11
+ */
12
+ import type { Translations } from './locale.js';
13
+ import { type ArrayOrItem } from './toarray.js';
14
+ declare global {
15
+ var CKEDITOR_TRANSLATIONS: Translations;
16
+ }
17
+ /**
18
+ * Adds translations to existing ones or overrides the existing translations. These translations will later
19
+ * be available for the {@link module:utils/locale~Locale#t `t()`} function.
20
+ *
21
+ * The `translations` is an object which consists of `messageId: translation` pairs. Note that the message ID can be
22
+ * either constructed from the message string or from the message ID if it was passed
23
+ * (this happens rarely and mostly for short messages or messages with placeholders).
24
+ * Since the editor displays only the message string, the message ID can be found either in the source code or in the
25
+ * built translations for another language.
26
+ *
27
+ * ```ts
28
+ * add( 'pl', {
29
+ * 'Cancel': 'Anuluj',
30
+ * 'IMAGE': 'obraz', // Note that the `IMAGE` comes from the message ID, while the string can be `image`.
31
+ * } );
32
+ * ```
33
+ *
34
+ * If the message is supposed to support various plural forms, make sure to provide an array with the singular form and all plural forms:
35
+ *
36
+ * ```ts
37
+ * add( 'pl', {
38
+ * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
39
+ * } );
40
+ * ```
41
+ *
42
+ * You should also specify the third argument (the `getPluralForm()` function) that will be used to determine the plural form if no
43
+ * language file was loaded for that language. All language files coming from CKEditor 5 sources will have this option set, so
44
+ * these plural form rules will be reused by other translations added to the registered languages. The `getPluralForm()` function
45
+ * can return either a Boolean or a number.
46
+ *
47
+ * ```ts
48
+ * add( 'en', {
49
+ * // ... Translations.
50
+ * }, n => n !== 1 );
51
+ * add( 'pl', {
52
+ * // ... Translations.
53
+ * }, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
54
+ * ```
55
+ *
56
+ * All translations extend the global `window.CKEDITOR_TRANSLATIONS` object. An example of this object can be found below:
57
+ *
58
+ * ```ts
59
+ * {
60
+ * pl: {
61
+ * dictionary: {
62
+ * 'Cancel': 'Anuluj',
63
+ * 'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ]
64
+ * },
65
+ * // A function that returns the plural form index.
66
+ * getPluralForm: n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
67
+ * }
68
+ * // Other languages.
69
+ * }
70
+ * ```
71
+ *
72
+ * If you cannot import this function from this module (e.g. because you use a CKEditor 5 build), you can
73
+ * still add translations by extending the global `window.CKEDITOR_TRANSLATIONS` object by using a function like
74
+ * the one below:
75
+ *
76
+ * ```ts
77
+ * function addTranslations( language, translations, getPluralForm ) {
78
+ * if ( !global.window.CKEDITOR_TRANSLATIONS ) {
79
+ * global.window.CKEDITOR_TRANSLATIONS = {};
80
+ * }
81
+
82
+ * if ( !global.window.CKEDITOR_TRANSLATIONS[ language ] ) {
83
+ * global.window.CKEDITOR_TRANSLATIONS[ language ] = {};
84
+ * }
85
+ *
86
+ * const languageTranslations = global.window.CKEDITOR_TRANSLATIONS[ language ];
87
+ *
88
+ * languageTranslations.dictionary = languageTranslations.dictionary || {};
89
+ * languageTranslations.getPluralForm = getPluralForm || languageTranslations.getPluralForm;
90
+ *
91
+ * // Extend the dictionary for the given language.
92
+ * Object.assign( languageTranslations.dictionary, translations );
93
+ * }
94
+ * ```
95
+ *
96
+ * @param language Target language.
97
+ * @param translations An object with translations which will be added to the dictionary.
98
+ * For each message ID the value should be either a translation or an array of translations if the message
99
+ * should support plural forms.
100
+ * @param getPluralForm A function that returns the plural form index (a number).
101
+ */
102
+ export declare function add(language: string, translations: {
103
+ readonly [messageId: string]: string | ReadonlyArray<string>;
104
+ }, getPluralForm?: (n: number) => number): void;
105
+ /**
106
+ * **Note:** This method is internal, use {@link module:utils/locale~Locale#t the `t()` function} instead to translate
107
+ * the editor UI parts.
108
+ *
109
+ * This function is responsible for translating messages to the specified language. It uses translations added perviously
110
+ * by {@link module:utils/translation-service~add} (a translations dictionary and the `getPluralForm()` function
111
+ * to provide accurate translations of plural forms).
112
+ *
113
+ * When no translation is defined in the dictionary or the dictionary does not exist, this function returns
114
+ * the original message string or the message plural depending on the number of elements.
115
+ *
116
+ * ```ts
117
+ * translate( 'pl', { string: 'Cancel' } ); // 'Cancel'
118
+ * ```
119
+ *
120
+ * The third optional argument is the number of elements, based on which the single form or one of the plural forms
121
+ * should be picked when the message is supposed to support various plural forms.
122
+ *
123
+ * ```ts
124
+ * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space'
125
+ * translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 ); // 'Add %0 spaces'
126
+ * ```
127
+ *
128
+ * The message should provide an ID using the `id` property when the message strings are not unique and their
129
+ * translations should be different.
130
+ *
131
+ * ```ts
132
+ * translate( 'en', { string: 'image', id: 'ADD_IMAGE' } );
133
+ * translate( 'en', { string: 'image', id: 'AN_IMAGE' } );
134
+ * ```
135
+ *
136
+ * @internal
137
+ * @param language Target language.
138
+ * @param message A message that will be translated.
139
+ * @param quantity The number of elements for which a plural form should be picked from the target language dictionary.
140
+ * @param translations Translations passed in editor config, if not provided use the global `window.CKEDITOR_TRANSLATIONS`.
141
+ * @returns Translated sentence.
142
+ */
143
+ export declare function _translate(language: string, message: Message, quantity?: number, translations?: Translations): string;
144
+ /**
145
+ * Clears dictionaries for test purposes.
146
+ *
147
+ * @internal
148
+ */
149
+ export declare function _clear(): void;
150
+ /**
151
+ * If array then merge objects which are inside otherwise return given object.
152
+ *
153
+ * @internal
154
+ * @param translations Translations passed in editor config.
155
+ */
156
+ export declare function _unifyTranslations(translations?: ArrayOrItem<Translations>): Translations | undefined;
157
+ /**
158
+ * The internationalization message interface. A message that implements this interface can be passed to the `t()` function
159
+ * to be translated to the target UI language.
160
+ */
161
+ export interface Message {
162
+ /**
163
+ * The message string to translate. Acts as a default translation if the translation for a given language
164
+ * is not defined. When the message is supposed to support plural forms, the string should be the English singular form of the message.
165
+ */
166
+ readonly string: string;
167
+ /**
168
+ * The message ID. If passed, the message ID is taken from this property instead of the `message.string`.
169
+ * This property is useful when various messages share the same message string, for example, the `editor` string in `in the editor`
170
+ * and `my editor` sentences.
171
+ */
172
+ readonly id?: string;
173
+ /**
174
+ * The plural form of the message. This property should be skipped when a message is not supposed
175
+ * to support plural forms. Otherwise it should always be set to a string with the English plural form of the message.
176
+ */
177
+ readonly plural?: string;
178
+ }
package/dist/uid.d.ts ADDED
@@ -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
+ * Returns a unique id. The id starts with an "e" character and a randomly generated string of
11
+ * 32 alphanumeric characters.
12
+ *
13
+ * **Note**: The characters the unique id is built from correspond to the hex number notation
14
+ * (from "0" to "9", from "a" to "f"). In other words, each id corresponds to an "e" followed
15
+ * by 16 8-bit numbers next to each other.
16
+ *
17
+ * @returns An unique id string.
18
+ */
19
+ export default function uid(): string;
@@ -0,0 +1,58 @@
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
+ * Set of utils to handle unicode characters.
11
+ *
12
+ * @module utils/unicode
13
+ */
14
+ /**
15
+ * Checks whether given `character` is a combining mark.
16
+ *
17
+ * @param character Character to check.
18
+ */
19
+ export declare function isCombiningMark(character: string): boolean;
20
+ /**
21
+ * Checks whether given `character` is a high half of surrogate pair.
22
+ *
23
+ * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
24
+ * consist of high surrogate pair character followed by low surrogate pair character.
25
+ *
26
+ * @param character Character to check.
27
+ */
28
+ export declare function isHighSurrogateHalf(character: string): boolean;
29
+ /**
30
+ * Checks whether given `character` is a low half of surrogate pair.
31
+ *
32
+ * Using UTF-16 terminology, a surrogate pair denotes UTF-16 character using two UTF-8 characters. The surrogate pair
33
+ * consist of high surrogate pair character followed by low surrogate pair character.
34
+ *
35
+ * @param character Character to check.
36
+ */
37
+ export declare function isLowSurrogateHalf(character: string): boolean;
38
+ /**
39
+ * Checks whether given offset in a string is inside a surrogate pair (between two surrogate halves).
40
+ *
41
+ * @param string String to check.
42
+ * @param offset Offset to check.
43
+ */
44
+ export declare function isInsideSurrogatePair(string: string, offset: number): boolean;
45
+ /**
46
+ * Checks whether given offset in a string is between base character and combining mark or between two combining marks.
47
+ *
48
+ * @param string String to check.
49
+ * @param offset Offset to check.
50
+ */
51
+ export declare function isInsideCombinedSymbol(string: string, offset: number): boolean;
52
+ /**
53
+ * Checks whether given offset in a string is inside multi-character emoji sequence.
54
+ *
55
+ * @param string String to check.
56
+ * @param offset Offset to check.
57
+ */
58
+ export declare function isInsideEmojiSequence(string: string, offset: number): boolean;
@@ -0,0 +1,14 @@
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
+ declare const version = "0.0.0-internal-20241017.0";
10
+ export default version;
11
+ export declare const releaseDate: Date;
12
+ declare global {
13
+ var CKEDITOR_VERSION: string;
14
+ }
package/dist/wait.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/wait
11
+ */
12
+ /**
13
+ * Returns a promise that is resolved after the specified time.
14
+ *
15
+ * @param timeout The time in milliseconds to wait.
16
+ * @param options.signal A signal to abort the waiting.
17
+ */
18
+ export default function wait(timeout: number, options?: {
19
+ signal?: AbortSignal;
20
+ }): Promise<void>;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@ckeditor/ckeditor5-utils",
3
+ "version": "0.0.0-internal-20241017.0",
4
+ "description": "Miscellaneous utilities used by CKEditor 5.",
5
+ "keywords": [
6
+ "ckeditor",
7
+ "ckeditor5",
8
+ "ckeditor 5",
9
+ "ckeditor5-lib",
10
+ "ckeditor5-dll"
11
+ ],
12
+ "type": "module",
13
+ "main": "src/index.js",
14
+ "dependencies": {
15
+ "lodash-es": "4.17.21"
16
+ },
17
+ "author": "CKSource (http://cksource.com/)",
18
+ "license": "GPL-2.0-or-later",
19
+ "homepage": "https://ckeditor.com/ckeditor-5",
20
+ "bugs": "https://github.com/ckeditor/ckeditor5/issues",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/ckeditor/ckeditor5.git",
24
+ "directory": "packages/ckeditor5-utils"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "lang",
29
+ "src/**/*.js",
30
+ "src/**/*.d.ts",
31
+ "theme",
32
+ "ckeditor5-metadata.json",
33
+ "CHANGELOG.md"
34
+ ],
35
+ "types": "src/index.d.ts"
36
+ }
@@ -0,0 +1,17 @@
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
+ * @module utils/abortabledebounce
7
+ */
8
+ /**
9
+ * Returns a function wrapper that will execute the provided function and abort any previous call that is still in progress.
10
+ *
11
+ * @param func The function to be called. It will be provided with `AbortSignal` as the first parameter.
12
+ */
13
+ export default function abortableDebounce<Args extends Array<any>, Ret>(func: (signal: AbortSignal, ...args: Args) => Ret): AbortableFunc<Args, Ret>;
14
+ export interface AbortableFunc<Args extends Array<any>, Ret> {
15
+ (...args: Args): Ret;
16
+ abort(): void;
17
+ }
@@ -0,0 +1,22 @@
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
+ * @module utils/abortabledebounce
7
+ */
8
+ /**
9
+ * Returns a function wrapper that will execute the provided function and abort any previous call that is still in progress.
10
+ *
11
+ * @param func The function to be called. It will be provided with `AbortSignal` as the first parameter.
12
+ */
13
+ export default function abortableDebounce(func) {
14
+ let controller = new AbortController();
15
+ function abortable(...args) {
16
+ controller.abort();
17
+ controller = new AbortController();
18
+ return func(controller.signal, ...args);
19
+ }
20
+ abortable.abort = () => controller.abort();
21
+ return abortable;
22
+ }
@@ -0,0 +1,11 @@
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
+ * @module utils/areconnectedthroughproperties
7
+ */
8
+ /**
9
+ * Traverses both structures to find out whether there is a reference that is shared between both structures.
10
+ */
11
+ export default function areConnectedThroughProperties(obj1: object, obj2: object): boolean;
@@ -0,0 +1,73 @@
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
+ * @module utils/areconnectedthroughproperties
7
+ */
8
+ /* globals EventTarget, Event */
9
+ /**
10
+ * Traverses both structures to find out whether there is a reference that is shared between both structures.
11
+ */
12
+ export default function areConnectedThroughProperties(obj1, obj2) {
13
+ if (obj1 === obj2 && isObject(obj1)) {
14
+ return true;
15
+ }
16
+ const subNodes1 = getSubNodes(obj1);
17
+ const subNodes2 = getSubNodes(obj2);
18
+ for (const node of subNodes1) {
19
+ if (subNodes2.has(node)) {
20
+ return true;
21
+ }
22
+ }
23
+ return false;
24
+ }
25
+ /**
26
+ * Traverses JS structure and stores all sub-nodes, including the head node.
27
+ * It walks into each iterable structures with the `try catch` block to omit errors that might be thrown during
28
+ * tree walking. All primitives, functions and built-ins are skipped.
29
+ */
30
+ function getSubNodes(head) {
31
+ const nodes = [head];
32
+ // Nodes are stored to prevent infinite looping.
33
+ const subNodes = new Set();
34
+ while (nodes.length > 0) {
35
+ const node = nodes.shift();
36
+ if (subNodes.has(node) || shouldNodeBeSkipped(node)) {
37
+ continue;
38
+ }
39
+ subNodes.add(node);
40
+ // Handle arrays, maps, sets, custom collections that implements `[ Symbol.iterator ]()`, etc.
41
+ if (node[Symbol.iterator]) {
42
+ // The custom editor iterators might cause some problems if the editor is crashed.
43
+ try {
44
+ nodes.push(...node);
45
+ }
46
+ catch (err) {
47
+ // eslint-disable-line no-empty
48
+ }
49
+ }
50
+ else {
51
+ nodes.push(...Object.values(node));
52
+ }
53
+ }
54
+ return subNodes;
55
+ }
56
+ function shouldNodeBeSkipped(node) {
57
+ const type = Object.prototype.toString.call(node);
58
+ return (type === '[object Number]' ||
59
+ type === '[object Boolean]' ||
60
+ type === '[object String]' ||
61
+ type === '[object Symbol]' ||
62
+ type === '[object Function]' ||
63
+ type === '[object Date]' ||
64
+ type === '[object RegExp]' ||
65
+ node === undefined ||
66
+ node === null ||
67
+ // Skip native DOM objects, e.g. Window, nodes, events, etc.
68
+ node instanceof EventTarget ||
69
+ node instanceof Event);
70
+ }
71
+ function isObject(structure) {
72
+ return typeof structure === 'object' && structure !== null;
73
+ }
@@ -0,0 +1,123 @@
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
+ * @module utils/ckeditorerror
7
+ */
8
+ /**
9
+ * URL to the documentation with error codes.
10
+ */
11
+ export declare const DOCUMENTATION_URL = "https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html";
12
+ /**
13
+ * The CKEditor error class.
14
+ *
15
+ * You should throw `CKEditorError` when:
16
+ *
17
+ * * An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be handled
18
+ * by the {@link module:watchdog/watchdog~Watchdog watchdog} (if it is integrated),
19
+ * * If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give
20
+ * feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not
21
+ * stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use
22
+ * {@link module:utils/ckeditorerror~logWarning `logWarning()`} and
23
+ * {@link module:utils/ckeditorerror~logError `logError()`}
24
+ * to improve developers experience and let them see the a working editor as soon as possible.
25
+ *
26
+ * ```ts
27
+ * /**
28
+ * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
29
+ * *
30
+ * * @error plugin-load
31
+ * * @param pluginName The name of the plugin that could not be loaded.
32
+ * * @param moduleName The name of the module which tried to load this plugin.
33
+ * *\/
34
+ * throw new CKEditorError( 'plugin-load', {
35
+ * pluginName: 'foo',
36
+ * moduleName: 'bar'
37
+ * } );
38
+ * ```
39
+ */
40
+ export default class CKEditorError extends Error {
41
+ /**
42
+ * A context of the error by which the Watchdog is able to determine which editor crashed.
43
+ */
44
+ readonly context: object | null | undefined;
45
+ /**
46
+ * The additional error data passed to the constructor. Undefined if none was passed.
47
+ */
48
+ readonly data?: object;
49
+ /**
50
+ * Creates an instance of the CKEditorError class.
51
+ *
52
+ * @param errorName The error id in an `error-name` format. A link to this error documentation page will be added
53
+ * to the thrown error's `message`.
54
+ * @param context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
55
+ * is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
56
+ * a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
57
+ * The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
58
+ * to check if the object works as the context.
59
+ * @param data Additional data describing the error. A stringified version of this object
60
+ * will be appended to the error message, so the data are quickly visible in the console. The original
61
+ * data object will also be later available under the {@link #data} property.
62
+ */
63
+ constructor(errorName: string, context?: object | null, data?: object);
64
+ /**
65
+ * Checks if the error is of the `CKEditorError` type.
66
+ */
67
+ is(type: string): boolean;
68
+ /**
69
+ * A utility that ensures that the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
70
+ * It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
71
+ * of a {@link module:utils/ckeditorerror~CKEditorError} error.
72
+ *
73
+ * @param err The error to rethrow.
74
+ * @param context An object connected through properties with the editor instance. This context will be used
75
+ * by the watchdog to verify which editor should be restarted.
76
+ */
77
+ static rethrowUnexpectedError(err: Error, context: object): never;
78
+ }
79
+ /**
80
+ * Logs a warning to the console with a properly formatted message and adds a link to the documentation.
81
+ * Use whenever you want to log a warning to the console.
82
+ *
83
+ * ```ts
84
+ * /**
85
+ * * There was a problem processing the configuration of the toolbar. The item with the given
86
+ * * name does not exist, so it was omitted when rendering the toolbar.
87
+ * *
88
+ * * @error toolbarview-item-unavailable
89
+ * * @param {String} name The name of the component.
90
+ * *\/
91
+ * logWarning( 'toolbarview-item-unavailable', { name } );
92
+ * ```
93
+ *
94
+ * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to throw an error and when to log
95
+ * a warning or an error to the console.
96
+ *
97
+ * @param errorName The error name to be logged.
98
+ * @param data Additional data to be logged.
99
+ */
100
+ export declare function logWarning(errorName: string, data?: object): void;
101
+ /**
102
+ * Logs an error to the console with a properly formatted message and adds a link to the documentation.
103
+ * Use whenever you want to log an error to the console.
104
+ *
105
+ * ```ts
106
+ * /**
107
+ * * There was a problem processing the configuration of the toolbar. The item with the given
108
+ * * name does not exist, so it was omitted when rendering the toolbar.
109
+ * *
110
+ * * @error toolbarview-item-unavailable
111
+ * * @param {String} name The name of the component.
112
+ * *\/
113
+ * logError( 'toolbarview-item-unavailable', { name } );
114
+ * ```
115
+ *
116
+ * **Note**: In most cases logging a warning using {@link module:utils/ckeditorerror~logWarning} is enough.
117
+ *
118
+ * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to use each method.
119
+ *
120
+ * @param errorName The error name to be logged.
121
+ * @param data Additional data to be logged.
122
+ */
123
+ export declare function logError(errorName: string, data?: object): void;