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