@ckeditor/ckeditor5-utils 36.0.1 → 37.0.0-alpha.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 (65) hide show
  1. package/package.json +7 -6
  2. package/src/areconnectedthroughproperties.d.ts +11 -0
  3. package/src/ckeditorerror.d.ts +123 -0
  4. package/src/collection.d.ts +427 -0
  5. package/src/comparearrays.d.ts +30 -0
  6. package/src/config.d.ts +163 -0
  7. package/src/count.d.ts +18 -0
  8. package/src/diff.d.ts +31 -0
  9. package/src/difftochanges.d.ts +59 -0
  10. package/src/dom/createelement.d.ts +55 -0
  11. package/src/dom/createelement.js +6 -9
  12. package/src/dom/emittermixin.d.ts +142 -0
  13. package/src/dom/findclosestscrollableancestor.d.ts +14 -0
  14. package/src/dom/getancestors.d.ts +17 -0
  15. package/src/dom/getborderwidths.d.ts +24 -0
  16. package/src/dom/getcommonancestor.d.ts +12 -0
  17. package/src/dom/getdatafromelement.d.ts +14 -0
  18. package/src/dom/getpositionedancestor.d.ts +10 -0
  19. package/src/dom/global.d.ts +32 -0
  20. package/src/dom/indexof.d.ts +14 -0
  21. package/src/dom/insertat.d.ts +15 -0
  22. package/src/dom/iscomment.d.ts +11 -0
  23. package/src/dom/isnode.d.ts +11 -0
  24. package/src/dom/isrange.d.ts +11 -0
  25. package/src/dom/istext.d.ts +11 -0
  26. package/src/dom/isvisible.d.ts +18 -0
  27. package/src/dom/iswindow.d.ts +11 -0
  28. package/src/dom/position.d.ts +208 -0
  29. package/src/dom/position.js +1 -1
  30. package/src/dom/rect.d.ts +184 -0
  31. package/src/dom/remove.d.ts +13 -0
  32. package/src/dom/resizeobserver.d.ts +70 -0
  33. package/src/dom/scroll.d.ts +27 -0
  34. package/src/dom/setdatainelement.d.ts +14 -0
  35. package/src/dom/tounit.d.ts +22 -0
  36. package/src/elementreplacer.d.ts +31 -0
  37. package/src/emittermixin.d.ts +312 -0
  38. package/src/env.d.ts +117 -0
  39. package/src/eventinfo.d.ts +58 -0
  40. package/src/fastdiff.d.ts +112 -0
  41. package/src/first.d.ts +11 -0
  42. package/src/focustracker.d.ts +73 -0
  43. package/src/focustracker.js +1 -1
  44. package/src/index.d.ts +56 -0
  45. package/src/inserttopriorityarray.d.ts +30 -0
  46. package/src/isiterable.d.ts +14 -0
  47. package/src/keyboard.d.ts +126 -0
  48. package/src/keystrokehandler.d.ts +83 -0
  49. package/src/language.d.ts +17 -0
  50. package/src/locale.d.ts +120 -0
  51. package/src/mapsequal.d.ts +15 -0
  52. package/src/mix.d.ts +85 -0
  53. package/src/nth.d.ts +16 -0
  54. package/src/objecttomap.d.ts +23 -0
  55. package/src/observablemixin.d.ts +574 -0
  56. package/src/priorities.d.ts +33 -0
  57. package/src/splicearray.d.ts +26 -0
  58. package/src/spy.d.ts +21 -0
  59. package/src/toarray.d.ts +25 -0
  60. package/src/tomap.d.ts +19 -0
  61. package/src/translation-service.d.ts +168 -0
  62. package/src/uid.d.ts +15 -0
  63. package/src/unicode.d.ts +54 -0
  64. package/src/version.d.ts +9 -0
  65. package/src/version.js +4 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "36.0.1",
3
+ "version": "37.0.0-alpha.0",
4
4
  "description": "Miscellaneous utilities used by CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -14,10 +14,10 @@
14
14
  "lodash-es": "^4.17.15"
15
15
  },
16
16
  "devDependencies": {
17
- "@ckeditor/ckeditor5-build-classic": "^36.0.1",
18
- "@ckeditor/ckeditor5-editor-classic": "^36.0.1",
19
- "@ckeditor/ckeditor5-core": "^36.0.1",
20
- "@ckeditor/ckeditor5-engine": "^36.0.1",
17
+ "@ckeditor/ckeditor5-build-classic": "^37.0.0-alpha.0",
18
+ "@ckeditor/ckeditor5-editor-classic": "^37.0.0-alpha.0",
19
+ "@ckeditor/ckeditor5-core": "^37.0.0-alpha.0",
20
+ "@ckeditor/ckeditor5-engine": "^37.0.0-alpha.0",
21
21
  "@types/lodash-es": "^4.17.6",
22
22
  "typescript": "^4.8.4"
23
23
  },
@@ -48,5 +48,6 @@
48
48
  "scripts": {
49
49
  "build": "tsc -p ./tsconfig.release.json",
50
50
  "postversion": "npm run build"
51
- }
51
+ },
52
+ "types": "src/index.d.ts"
52
53
  }
@@ -0,0 +1,11 @@
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/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,123 @@
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/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;
@@ -0,0 +1,427 @@
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
+ declare const Collection_base: {
6
+ new (): import("./emittermixin").Emitter;
7
+ prototype: import("./emittermixin").Emitter;
8
+ };
9
+ /**
10
+ * Collections are ordered sets of objects. Items in the collection can be retrieved by their indexes
11
+ * in the collection (like in an array) or by their ids.
12
+ *
13
+ * If an object without an `id` property is being added to the collection, the `id` property will be generated
14
+ * automatically. Note that the automatically generated id is unique only within this single collection instance.
15
+ *
16
+ * By default an item in the collection is identified by its `id` property. The name of the identifier can be
17
+ * configured through the constructor of the collection.
18
+ *
19
+ * @typeParam T The type of the collection element.
20
+ */
21
+ export default class Collection<T extends Record<string, any>> extends Collection_base implements Iterable<T> {
22
+ /**
23
+ * The internal list of items in the collection.
24
+ */
25
+ private readonly _items;
26
+ /**
27
+ * The internal map of items in the collection.
28
+ */
29
+ private readonly _itemMap;
30
+ /**
31
+ * The name of the property which is considered to identify an item.
32
+ */
33
+ private readonly _idProperty;
34
+ /**
35
+ * A collection instance this collection is bound to as a result
36
+ * of calling {@link #bindTo} method.
37
+ */
38
+ private _bindToCollection?;
39
+ /**
40
+ * A helper mapping external items of a bound collection ({@link #bindTo})
41
+ * and actual items of this collection. It provides information
42
+ * necessary to properly remove items bound to another collection.
43
+ *
44
+ * See {@link #_bindToInternalToExternalMap}.
45
+ */
46
+ private readonly _bindToExternalToInternalMap;
47
+ /**
48
+ * A helper mapping items of this collection to external items of a bound collection
49
+ * ({@link #bindTo}). It provides information necessary to manage the bindings, e.g.
50
+ * to avoid loops in two–way bindings.
51
+ *
52
+ * See {@link #_bindToExternalToInternalMap}.
53
+ */
54
+ private readonly _bindToInternalToExternalMap;
55
+ /**
56
+ * Stores indexes of skipped items from bound external collection.
57
+ */
58
+ private _skippedIndexesFromExternal;
59
+ /**
60
+ * Creates a new Collection instance.
61
+ *
62
+ * You can pass a configuration object as the argument of the constructor:
63
+ *
64
+ * ```ts
65
+ * const emptyCollection = new Collection<{ name: string }>( { idProperty: 'name' } );
66
+ * emptyCollection.add( { name: 'John' } );
67
+ * console.log( collection.get( 'John' ) ); // -> { name: 'John' }
68
+ * ```
69
+ *
70
+ * The collection is empty by default. You can add new items using the {@link #add} method:
71
+ *
72
+ * ```ts
73
+ * const collection = new Collection<{ id: string }>();
74
+ *
75
+ * collection.add( { id: 'John' } );
76
+ * console.log( collection.get( 0 ) ); // -> { id: 'John' }
77
+ * ```
78
+ *
79
+ * @label NO_ITEMS
80
+ * @param options The options object.
81
+ * @param options.idProperty The name of the property which is used to identify an item.
82
+ * Items that do not have such a property will be assigned one when added to the collection.
83
+ */
84
+ constructor(options?: {
85
+ readonly idProperty?: string;
86
+ });
87
+ /**
88
+ * Creates a new Collection instance with specified initial items.
89
+ *
90
+ * ```ts
91
+ * const collection = new Collection<{ id: string }>( [ { id: 'John' }, { id: 'Mike' } ] );
92
+ *
93
+ * console.log( collection.get( 0 ) ); // -> { id: 'John' }
94
+ * console.log( collection.get( 1 ) ); // -> { id: 'Mike' }
95
+ * console.log( collection.get( 'Mike' ) ); // -> { id: 'Mike' }
96
+ * ```
97
+ *
98
+ * You can always pass a configuration object as the last argument of the constructor:
99
+ *
100
+ * ```ts
101
+ * const nonEmptyCollection = new Collection<{ name: string }>( [ { name: 'John' } ], { idProperty: 'name' } );
102
+ * nonEmptyCollection.add( { name: 'George' } );
103
+ * console.log( collection.get( 'George' ) ); // -> { name: 'George' }
104
+ * console.log( collection.get( 'John' ) ); // -> { name: 'John' }
105
+ * ```
106
+ *
107
+ * @label INITIAL_ITEMS
108
+ * @param initialItems The initial items of the collection.
109
+ * @param options The options object.
110
+ * @param options.idProperty The name of the property which is used to identify an item.
111
+ * Items that do not have such a property will be assigned one when added to the collection.
112
+ */
113
+ constructor(initialItems: Iterable<T>, options?: {
114
+ readonly idProperty?: string;
115
+ });
116
+ /**
117
+ * The number of items available in the collection.
118
+ */
119
+ get length(): number;
120
+ /**
121
+ * Returns the first item from the collection or null when collection is empty.
122
+ */
123
+ get first(): T | null;
124
+ /**
125
+ * Returns the last item from the collection or null when collection is empty.
126
+ */
127
+ get last(): T | null;
128
+ /**
129
+ * Adds an item into the collection.
130
+ *
131
+ * If the item does not have an id, then it will be automatically generated and set on the item.
132
+ *
133
+ * @param item
134
+ * @param index The position of the item in the collection. The item
135
+ * is pushed to the collection when `index` not specified.
136
+ * @fires add
137
+ * @fires change
138
+ */
139
+ add(item: T, index?: number): this;
140
+ /**
141
+ * Adds multiple items into the collection.
142
+ *
143
+ * Any item not containing an id will get an automatically generated one.
144
+ *
145
+ * @param items
146
+ * @param index The position of the insertion. Items will be appended if no `index` is specified.
147
+ * @fires add
148
+ * @fires change
149
+ */
150
+ addMany(items: Iterable<T>, index?: number): this;
151
+ /**
152
+ * Gets an item by its ID or index.
153
+ *
154
+ * @param idOrIndex The item ID or index in the collection.
155
+ * @returns The requested item or `null` if such item does not exist.
156
+ */
157
+ get(idOrIndex: string | number): T | null;
158
+ /**
159
+ * Returns a Boolean indicating whether the collection contains an item.
160
+ *
161
+ * @param itemOrId The item or its ID in the collection.
162
+ * @returns `true` if the collection contains the item, `false` otherwise.
163
+ */
164
+ has(itemOrId: T | string): boolean;
165
+ /**
166
+ * Gets an index of an item in the collection.
167
+ * When an item is not defined in the collection, the index will equal -1.
168
+ *
169
+ * @param itemOrId The item or its ID in the collection.
170
+ * @returns The index of a given item.
171
+ */
172
+ getIndex(itemOrId: T | string): number;
173
+ /**
174
+ * Removes an item from the collection.
175
+ *
176
+ * @param subject The item to remove, its ID or index in the collection.
177
+ * @returns The removed item.
178
+ * @fires remove
179
+ * @fires change
180
+ */
181
+ remove(subject: T | number | string): T;
182
+ /**
183
+ * Executes the callback for each item in the collection and composes an array or values returned by this callback.
184
+ *
185
+ * @typeParam U The result type of the callback.
186
+ * @param callback
187
+ * @param ctx Context in which the `callback` will be called.
188
+ * @returns The result of mapping.
189
+ */
190
+ map<U>(callback: (item: T, index: number) => U, ctx?: any): Array<U>;
191
+ /**
192
+ * Finds the first item in the collection for which the `callback` returns a true value.
193
+ *
194
+ * @param callback
195
+ * @param ctx Context in which the `callback` will be called.
196
+ * @returns The item for which `callback` returned a true value.
197
+ */
198
+ find(callback: (item: T, index: number) => boolean, ctx?: any): T | undefined;
199
+ /**
200
+ * Returns an array with items for which the `callback` returned a true value.
201
+ *
202
+ * @param callback
203
+ * @param ctx Context in which the `callback` will be called.
204
+ * @returns The array with matching items.
205
+ */
206
+ filter(callback: (item: T, index: number) => boolean, ctx?: any): Array<T>;
207
+ /**
208
+ * Removes all items from the collection and destroys the binding created using
209
+ * {@link #bindTo}.
210
+ *
211
+ * @fires remove
212
+ * @fires change
213
+ */
214
+ clear(): void;
215
+ /**
216
+ * Binds and synchronizes the collection with another one.
217
+ *
218
+ * The binding can be a simple factory:
219
+ *
220
+ * ```ts
221
+ * class FactoryClass {
222
+ * public label: string;
223
+ *
224
+ * constructor( data: { label: string } ) {
225
+ * this.label = data.label;
226
+ * }
227
+ * }
228
+ *
229
+ * const source = new Collection<{ label: string }>( { idProperty: 'label' } );
230
+ * const target = new Collection<FactoryClass>();
231
+ *
232
+ * target.bindTo( source ).as( FactoryClass );
233
+ *
234
+ * source.add( { label: 'foo' } );
235
+ * source.add( { label: 'bar' } );
236
+ *
237
+ * console.log( target.length ); // 2
238
+ * console.log( target.get( 1 ).label ); // 'bar'
239
+ *
240
+ * source.remove( 0 );
241
+ * console.log( target.length ); // 1
242
+ * console.log( target.get( 0 ).label ); // 'bar'
243
+ * ```
244
+ *
245
+ * or the factory driven by a custom callback:
246
+ *
247
+ * ```ts
248
+ * class FooClass {
249
+ * public label: string;
250
+ *
251
+ * constructor( data: { label: string } ) {
252
+ * this.label = data.label;
253
+ * }
254
+ * }
255
+ *
256
+ * class BarClass {
257
+ * public label: string;
258
+ *
259
+ * constructor( data: { label: string } ) {
260
+ * this.label = data.label;
261
+ * }
262
+ * }
263
+ *
264
+ * const source = new Collection<{ label: string }>( { idProperty: 'label' } );
265
+ * const target = new Collection<FooClass | BarClass>();
266
+ *
267
+ * target.bindTo( source ).using( ( item ) => {
268
+ * if ( item.label == 'foo' ) {
269
+ * return new FooClass( item );
270
+ * } else {
271
+ * return new BarClass( item );
272
+ * }
273
+ * } );
274
+ *
275
+ * source.add( { label: 'foo' } );
276
+ * source.add( { label: 'bar' } );
277
+ *
278
+ * console.log( target.length ); // 2
279
+ * console.log( target.get( 0 ) instanceof FooClass ); // true
280
+ * console.log( target.get( 1 ) instanceof BarClass ); // true
281
+ * ```
282
+ *
283
+ * or the factory out of property name:
284
+ *
285
+ * ```ts
286
+ * const source = new Collection<{ nested: { value: string } }>();
287
+ * const target = new Collection<{ value: string }>();
288
+ *
289
+ * target.bindTo( source ).using( 'nested' );
290
+ *
291
+ * source.add( { nested: { value: 'foo' } } );
292
+ * source.add( { nested: { value: 'bar' } } );
293
+ *
294
+ * console.log( target.length ); // 2
295
+ * console.log( target.get( 0 ).value ); // 'foo'
296
+ * console.log( target.get( 1 ).value ); // 'bar'
297
+ * ```
298
+ *
299
+ * It's possible to skip specified items by returning null value:
300
+ *
301
+ * ```ts
302
+ * const source = new Collection<{ hidden: boolean }>();
303
+ * const target = new Collection<{ hidden: boolean }>();
304
+ *
305
+ * target.bindTo( source ).using( item => {
306
+ * if ( item.hidden ) {
307
+ * return null;
308
+ * }
309
+ *
310
+ * return item;
311
+ * } );
312
+ *
313
+ * source.add( { hidden: true } );
314
+ * source.add( { hidden: false } );
315
+ *
316
+ * console.log( source.length ); // 2
317
+ * console.log( target.length ); // 1
318
+ * ```
319
+ *
320
+ * **Note**: {@link #clear} can be used to break the binding.
321
+ *
322
+ * @typeParam S The type of `externalCollection` element.
323
+ * @param externalCollection A collection to be bound.
324
+ * @returns The binding chain object.
325
+ */
326
+ bindTo<S extends Record<string, any>>(externalCollection: Collection<S>): CollectionBindToChain<S, T>;
327
+ /**
328
+ * Finalizes and activates a binding initiated by {@link #bindTo}.
329
+ *
330
+ * @param factory A function which produces collection items.
331
+ */
332
+ private _setUpBindToBinding;
333
+ /**
334
+ * Returns an unique id property for a given `item`.
335
+ *
336
+ * The method will generate new id and assign it to the `item` if it doesn't have any.
337
+ *
338
+ * @param item Item to be added.
339
+ */
340
+ private _getItemIdBeforeAdding;
341
+ /**
342
+ * Core {@link #remove} method implementation shared in other functions.
343
+ *
344
+ * In contrast this method **does not** fire the {@link #event:change} event.
345
+ *
346
+ * @param subject The item to remove, its id or index in the collection.
347
+ * @returns Returns an array with the removed item and its index.
348
+ * @fires remove
349
+ */
350
+ private _remove;
351
+ /**
352
+ * Iterable interface.
353
+ */
354
+ [Symbol.iterator](): Iterator<T>;
355
+ }
356
+ /**
357
+ * Fired when an item is added to the collection.
358
+ *
359
+ * @eventName add
360
+ * @param item The added item.
361
+ * @param index An index where the addition occurred.
362
+ */
363
+ export type CollectionAddEvent<T = any> = {
364
+ name: 'add';
365
+ args: [item: T, index: number];
366
+ };
367
+ /**
368
+ * Fired when the collection was changed due to adding or removing items.
369
+ *
370
+ * @eventName change
371
+ * @param data Changed items.
372
+ */
373
+ export type CollectionChangeEvent<T = any> = {
374
+ name: 'change';
375
+ args: [data: CollectionChangeEventData<T>];
376
+ };
377
+ /**
378
+ * A structure describing the {@link ~Collection#event:change `Collection#change`} event.
379
+ */
380
+ export type CollectionChangeEventData<T = any> = {
381
+ /**
382
+ * A list of added items.
383
+ */
384
+ added: Iterable<T>;
385
+ /**
386
+ * A list of removed items.
387
+ */
388
+ removed: Iterable<T>;
389
+ /**
390
+ * An index where the addition or removal occurred.
391
+ */
392
+ index: number;
393
+ };
394
+ /**
395
+ * Fired when an item is removed from the collection.
396
+ *
397
+ * @eventName remove
398
+ * @param item The removed item.
399
+ * @param index Index from which item was removed.
400
+ */
401
+ export type CollectionRemoveEvent<T = any> = {
402
+ name: 'remove';
403
+ args: [item: T, index: number];
404
+ };
405
+ /**
406
+ * An object returned by the {@link module:utils/collection~Collection#bindTo `bindTo()`} method
407
+ * providing functions that specify the type of the binding.
408
+ *
409
+ * See the {@link module:utils/collection~Collection#bindTo `bindTo()`} documentation for examples.
410
+ */
411
+ export interface CollectionBindToChain<S, T> {
412
+ /**
413
+ * Creates the class factory binding in which items of the source collection are passed to
414
+ * the constructor of the specified class.
415
+ *
416
+ * @param Class The class constructor used to create instances in the factory.
417
+ */
418
+ as(Class: new (item: S) => T): void;
419
+ /**
420
+ * Creates a callback or a property binding.
421
+ *
422
+ * @param callbackOrProperty When the function is passed, it should return
423
+ * the collection items. When the string is provided, the property value is used to create the bound collection items.
424
+ */
425
+ using(callbackOrProperty: keyof S | ((item: S) => T | null)): void;
426
+ }
427
+ export {};
@@ -0,0 +1,30 @@
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/comparearrays
7
+ */
8
+ /**
9
+ * Compares how given arrays relate to each other. One array can be: same as another array, prefix of another array
10
+ * or completely different. If arrays are different, first index at which they differ is returned. Otherwise,
11
+ * a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
12
+ * it means that arrays differ.
13
+ *
14
+ * ```ts
15
+ * compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'same'
16
+ * compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'prefix'
17
+ * compareArrays( [ 0, 2 ], [ 0 ] ); // 'extension'
18
+ * compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
19
+ * compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
20
+ * ```
21
+ *
22
+ * @param a Array that is compared.
23
+ * @param b Array to compare with.
24
+ * @returns How array `a` is related to `b`.
25
+ */
26
+ export default function compareArrays(a: ReadonlyArray<unknown>, b: ReadonlyArray<unknown>): ArrayRelation | number;
27
+ /**
28
+ * Array relation.
29
+ */
30
+ export type ArrayRelation = 'extension' | 'same' | 'prefix';