@ckeditor/ckeditor5-utils 41.3.1 → 41.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/index-content.css +4 -0
  2. package/dist/index-editor.css +4 -0
  3. package/dist/index.css +4 -0
  4. package/dist/index.js +5491 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/types/abortabledebounce.d.ts +21 -0
  7. package/dist/types/areconnectedthroughproperties.d.ts +15 -0
  8. package/dist/types/ckeditorerror.d.ts +127 -0
  9. package/dist/types/collection.d.ts +437 -0
  10. package/dist/types/comparearrays.d.ts +34 -0
  11. package/dist/types/config.d.ts +167 -0
  12. package/dist/types/count.d.ts +22 -0
  13. package/dist/types/delay.d.ts +23 -0
  14. package/dist/types/diff.d.ts +35 -0
  15. package/dist/types/difftochanges.d.ts +63 -0
  16. package/dist/types/dom/createelement.d.ts +61 -0
  17. package/dist/types/dom/emittermixin.d.ts +146 -0
  18. package/dist/types/dom/findclosestscrollableancestor.d.ts +15 -0
  19. package/dist/types/dom/getancestors.d.ts +21 -0
  20. package/dist/types/dom/getborderwidths.d.ts +28 -0
  21. package/dist/types/dom/getcommonancestor.d.ts +16 -0
  22. package/dist/types/dom/getdatafromelement.d.ts +18 -0
  23. package/dist/types/dom/getpositionedancestor.d.ts +14 -0
  24. package/dist/types/dom/global.d.ts +36 -0
  25. package/dist/types/dom/indexof.d.ts +18 -0
  26. package/dist/types/dom/insertat.d.ts +19 -0
  27. package/dist/types/dom/iscomment.d.ts +15 -0
  28. package/dist/types/dom/isnode.d.ts +15 -0
  29. package/dist/types/dom/isrange.d.ts +15 -0
  30. package/dist/types/dom/istext.d.ts +15 -0
  31. package/dist/types/dom/isvalidattributename.d.ts +14 -0
  32. package/dist/types/dom/isvisible.d.ts +22 -0
  33. package/dist/types/dom/iswindow.d.ts +15 -0
  34. package/dist/types/dom/position.d.ts +215 -0
  35. package/dist/types/dom/rect.d.ts +199 -0
  36. package/dist/types/dom/remove.d.ts +17 -0
  37. package/dist/types/dom/resizeobserver.d.ts +78 -0
  38. package/dist/types/dom/scroll.d.ts +77 -0
  39. package/dist/types/dom/setdatainelement.d.ts +18 -0
  40. package/dist/types/dom/tounit.d.ts +26 -0
  41. package/dist/types/elementreplacer.d.ts +35 -0
  42. package/dist/types/emittermixin.d.ts +316 -0
  43. package/dist/types/env.d.ts +137 -0
  44. package/dist/types/eventinfo.d.ts +62 -0
  45. package/dist/types/fastdiff.d.ts +116 -0
  46. package/dist/types/first.d.ts +15 -0
  47. package/dist/types/focustracker.d.ts +79 -0
  48. package/dist/types/index.d.ts +68 -0
  49. package/dist/types/inserttopriorityarray.d.ts +34 -0
  50. package/dist/types/isiterable.d.ts +18 -0
  51. package/dist/types/keyboard.d.ts +130 -0
  52. package/dist/types/keystrokehandler.d.ts +91 -0
  53. package/dist/types/language.d.ts +21 -0
  54. package/dist/types/locale.d.ts +145 -0
  55. package/dist/types/mapsequal.d.ts +19 -0
  56. package/dist/types/mix.d.ts +89 -0
  57. package/dist/types/nth.d.ts +20 -0
  58. package/dist/types/objecttomap.d.ts +27 -0
  59. package/dist/types/observablemixin.d.ts +564 -0
  60. package/dist/types/priorities.d.ts +37 -0
  61. package/dist/types/retry.d.ts +37 -0
  62. package/dist/types/splicearray.d.ts +30 -0
  63. package/dist/types/spy.d.ts +25 -0
  64. package/dist/types/toarray.d.ts +29 -0
  65. package/dist/types/tomap.d.ts +23 -0
  66. package/dist/types/translation-service.d.ts +178 -0
  67. package/dist/types/uid.d.ts +19 -0
  68. package/dist/types/unicode.d.ts +58 -0
  69. package/dist/types/verifylicense.d.ts +19 -0
  70. package/dist/types/version.d.ts +14 -0
  71. package/dist/types/wait.d.ts +20 -0
  72. package/package.json +2 -1
  73. package/src/env.d.ts +16 -0
  74. package/src/env.js +16 -0
  75. package/src/locale.d.ts +1 -1
  76. package/src/version.d.ts +1 -1
  77. package/src/version.js +2 -2
@@ -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 features/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;
@@ -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
+ };
@@ -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>;