@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.
- package/dist/abortabledebounce.d.ts +19 -13
- package/dist/areconnectedthroughproperties.d.ts +7 -7
- package/dist/ckeditorerror.d.ts +113 -113
- package/dist/collection.d.ts +419 -415
- package/dist/collectstylesheets.d.ts +9 -9
- package/dist/comparearrays.d.ts +25 -25
- package/dist/config.d.ts +159 -156
- package/dist/count.d.ts +14 -14
- package/dist/crc32.d.ts +19 -19
- package/dist/decodelicensekey.d.ts +7 -7
- package/dist/delay.d.ts +13 -13
- package/dist/diff.d.ts +32 -27
- package/dist/difftochanges.d.ts +47 -47
- package/dist/dom/createelement.d.ts +43 -43
- package/dist/dom/emittermixin.d.ts +144 -135
- package/dist/dom/findclosestscrollableancestor.d.ts +8 -8
- package/dist/dom/getancestors.d.ts +13 -13
- package/dist/dom/getborderwidths.d.ts +16 -16
- package/dist/dom/getcommonancestor.d.ts +9 -9
- package/dist/dom/getdatafromelement.d.ts +10 -10
- package/dist/dom/getpositionedancestor.d.ts +7 -7
- package/dist/dom/getrangefrommouseevent.d.ts +12 -12
- package/dist/dom/getvisualviewportoffset.d.ts +7 -7
- package/dist/dom/global.d.ts +24 -24
- package/dist/dom/indexof.d.ts +10 -10
- package/dist/dom/insertat.d.ts +11 -11
- package/dist/dom/iscomment.d.ts +7 -7
- package/dist/dom/isnode.d.ts +7 -7
- package/dist/dom/isrange.d.ts +7 -7
- package/dist/dom/istext.d.ts +7 -7
- package/dist/dom/isvalidattributename.d.ts +7 -7
- package/dist/dom/isvisible.d.ts +12 -12
- package/dist/dom/iswindow.d.ts +7 -7
- package/dist/dom/position.d.ts +200 -200
- package/dist/dom/rect.d.ts +194 -194
- package/dist/dom/remove.d.ts +9 -9
- package/dist/dom/resizeobserver.d.ts +70 -70
- package/dist/dom/scroll.d.ts +75 -72
- package/dist/dom/setdatainelement.d.ts +10 -10
- package/dist/dom/tounit.d.ts +16 -16
- package/dist/elementreplacer.d.ts +26 -26
- package/dist/emittermixin.d.ts +290 -280
- package/dist/env.d.ts +124 -124
- package/dist/eventinfo.d.ts +58 -55
- package/dist/fastdiff.d.ts +112 -109
- package/dist/first.d.ts +7 -7
- package/dist/focustracker.d.ts +133 -131
- package/dist/formathtml.d.ts +15 -15
- package/dist/index-content.css +1 -0
- package/dist/index-editor.css +1 -0
- package/dist/index.css +0 -2
- package/dist/index.d.ts +78 -77
- package/dist/index.js +5695 -6360
- package/dist/index.js.map +1 -1
- package/dist/inserttopriorityarray.d.ts +23 -23
- package/dist/isfeatureblockedbylicensekey.d.ts +10 -10
- package/dist/isiterable.d.ts +10 -10
- package/dist/keyboard.d.ts +107 -109
- package/dist/keystrokehandler.d.ts +90 -90
- package/dist/language.d.ts +12 -12
- package/dist/legacyerrors.d.ts +0 -4
- package/dist/locale.d.ts +122 -122
- package/dist/mapsequal.d.ts +11 -11
- package/dist/mix.d.ts +54 -53
- package/dist/nth.d.ts +12 -12
- package/dist/objecttomap.d.ts +18 -18
- package/dist/observablemixin.d.ts +621 -539
- package/dist/parsebase64encodedobject.d.ts +7 -7
- package/dist/parsedimensionwithunit.d.ts +40 -0
- package/dist/priorities.d.ts +24 -24
- package/dist/retry.d.ts +27 -27
- package/dist/splicearray.d.ts +22 -22
- package/dist/spy.d.ts +15 -15
- package/dist/toarray.d.ts +17 -17
- package/dist/tomap.d.ts +15 -15
- package/dist/translation-service.d.ts +157 -157
- package/dist/uid.d.ts +12 -12
- package/dist/unicode.d.ts +42 -42
- package/dist/version.d.ts +5 -5
- package/dist/wait.d.ts +11 -11
- package/package.json +2 -2
- package/dist/index.css.map +0 -1
package/dist/collection.d.ts
CHANGED
|
@@ -1,433 +1,437 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export declare class Collection<T extends Record<string, any>> extends
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
371
|
-
|
|
371
|
+
name: "add";
|
|
372
|
+
args: [item: T, index: number];
|
|
372
373
|
};
|
|
373
374
|
/**
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
381
|
-
|
|
381
|
+
name: "change";
|
|
382
|
+
args: [data: CollectionChangeEventData<T>];
|
|
382
383
|
};
|
|
383
384
|
/**
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
* A structure describing the {@link ~Collection#event:change `Collection#change`} event.
|
|
386
|
+
*/
|
|
386
387
|
export type CollectionChangeEventData<T = any> = {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
|
|
409
|
-
|
|
409
|
+
name: "remove";
|
|
410
|
+
args: [item: T, index: number];
|
|
410
411
|
};
|
|
411
412
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
export interface CollectionBindToChain<
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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 {};
|