@ckeditor/ckeditor5-utils 41.3.0-alpha.3 → 41.3.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 (74) hide show
  1. package/package.json +1 -2
  2. package/src/keyboard.js +5 -1
  3. package/src/locale.d.ts +1 -1
  4. package/src/version.d.ts +1 -1
  5. package/src/version.js +2 -2
  6. package/dist/content-index.css +0 -4
  7. package/dist/editor-index.css +0 -4
  8. package/dist/index.css +0 -4
  9. package/dist/types/abortabledebounce.d.ts +0 -21
  10. package/dist/types/areconnectedthroughproperties.d.ts +0 -15
  11. package/dist/types/ckeditorerror.d.ts +0 -127
  12. package/dist/types/collection.d.ts +0 -437
  13. package/dist/types/comparearrays.d.ts +0 -34
  14. package/dist/types/config.d.ts +0 -167
  15. package/dist/types/count.d.ts +0 -22
  16. package/dist/types/delay.d.ts +0 -23
  17. package/dist/types/diff.d.ts +0 -35
  18. package/dist/types/difftochanges.d.ts +0 -63
  19. package/dist/types/dom/createelement.d.ts +0 -61
  20. package/dist/types/dom/emittermixin.d.ts +0 -146
  21. package/dist/types/dom/findclosestscrollableancestor.d.ts +0 -15
  22. package/dist/types/dom/getancestors.d.ts +0 -21
  23. package/dist/types/dom/getborderwidths.d.ts +0 -28
  24. package/dist/types/dom/getcommonancestor.d.ts +0 -16
  25. package/dist/types/dom/getdatafromelement.d.ts +0 -18
  26. package/dist/types/dom/getpositionedancestor.d.ts +0 -14
  27. package/dist/types/dom/global.d.ts +0 -36
  28. package/dist/types/dom/indexof.d.ts +0 -18
  29. package/dist/types/dom/insertat.d.ts +0 -19
  30. package/dist/types/dom/iscomment.d.ts +0 -15
  31. package/dist/types/dom/isnode.d.ts +0 -15
  32. package/dist/types/dom/isrange.d.ts +0 -15
  33. package/dist/types/dom/istext.d.ts +0 -15
  34. package/dist/types/dom/isvalidattributename.d.ts +0 -14
  35. package/dist/types/dom/isvisible.d.ts +0 -22
  36. package/dist/types/dom/iswindow.d.ts +0 -15
  37. package/dist/types/dom/position.d.ts +0 -215
  38. package/dist/types/dom/rect.d.ts +0 -199
  39. package/dist/types/dom/remove.d.ts +0 -17
  40. package/dist/types/dom/resizeobserver.d.ts +0 -78
  41. package/dist/types/dom/scroll.d.ts +0 -77
  42. package/dist/types/dom/setdatainelement.d.ts +0 -18
  43. package/dist/types/dom/tounit.d.ts +0 -26
  44. package/dist/types/elementreplacer.d.ts +0 -35
  45. package/dist/types/emittermixin.d.ts +0 -316
  46. package/dist/types/env.d.ts +0 -121
  47. package/dist/types/eventinfo.d.ts +0 -62
  48. package/dist/types/fastdiff.d.ts +0 -116
  49. package/dist/types/first.d.ts +0 -15
  50. package/dist/types/focustracker.d.ts +0 -79
  51. package/dist/types/index.d.ts +0 -68
  52. package/dist/types/inserttopriorityarray.d.ts +0 -34
  53. package/dist/types/isiterable.d.ts +0 -18
  54. package/dist/types/keyboard.d.ts +0 -130
  55. package/dist/types/keystrokehandler.d.ts +0 -91
  56. package/dist/types/language.d.ts +0 -21
  57. package/dist/types/locale.d.ts +0 -145
  58. package/dist/types/mapsequal.d.ts +0 -19
  59. package/dist/types/mix.d.ts +0 -89
  60. package/dist/types/nth.d.ts +0 -20
  61. package/dist/types/objecttomap.d.ts +0 -27
  62. package/dist/types/observablemixin.d.ts +0 -564
  63. package/dist/types/priorities.d.ts +0 -37
  64. package/dist/types/retry.d.ts +0 -37
  65. package/dist/types/splicearray.d.ts +0 -30
  66. package/dist/types/spy.d.ts +0 -25
  67. package/dist/types/toarray.d.ts +0 -29
  68. package/dist/types/tomap.d.ts +0 -23
  69. package/dist/types/translation-service.d.ts +0 -178
  70. package/dist/types/uid.d.ts +0 -19
  71. package/dist/types/unicode.d.ts +0 -58
  72. package/dist/types/verifylicense.d.ts +0 -19
  73. package/dist/types/version.d.ts +0 -14
  74. package/dist/types/wait.d.ts +0 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-utils",
3
- "version": "41.3.0-alpha.3",
3
+ "version": "41.3.0",
4
4
  "description": "Miscellaneous utilities used by CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -24,7 +24,6 @@
24
24
  "directory": "packages/ckeditor5-utils"
25
25
  },
26
26
  "files": [
27
- "dist",
28
27
  "lang",
29
28
  "src/**/*.js",
30
29
  "src/**/*.d.ts",
package/src/keyboard.js CHANGED
@@ -20,7 +20,9 @@ const keyCodesToGlyphs = {
20
20
  38: '↑',
21
21
  39: '→',
22
22
  40: '↓',
23
- 9: '⇥'
23
+ 9: '⇥',
24
+ 33: 'Page Up',
25
+ 34: 'Page Down'
24
26
  };
25
27
  /**
26
28
  * An object with `keyName => keyCode` pairs for a set of known keys.
@@ -196,6 +198,8 @@ export function isForwardArrowKeyCode(keyCode, contentLanguageDirection) {
196
198
  }
197
199
  function generateKnownKeyCodes() {
198
200
  const keyCodes = {
201
+ pageup: 33,
202
+ pagedown: 34,
199
203
  arrowleft: 37,
200
204
  arrowup: 38,
201
205
  arrowright: 39,
package/src/locale.d.ts CHANGED
@@ -136,6 +136,6 @@ export type Translations = {
136
136
  dictionary: {
137
137
  [messageId: string]: string | ReadonlyArray<string>;
138
138
  };
139
- getPluralForm: ((n: number) => number | boolean) | null;
139
+ getPluralForm?: (n: number) => number;
140
140
  };
141
141
  };
package/src/version.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- declare const version = "41.3.0-alpha.3";
5
+ declare const version = "41.3.0";
6
6
  export default version;
7
7
  export declare const releaseDate: Date;
8
8
  declare global {
package/src/version.js CHANGED
@@ -6,10 +6,10 @@
6
6
  * @module utils/version
7
7
  */
8
8
  import CKEditorError from './ckeditorerror.js';
9
- const version = '41.3.0-alpha.3';
9
+ const version = '41.3.0';
10
10
  export default version;
11
11
  // The second argument is not a month. It is `monthIndex` and starts from `0`.
12
- export const releaseDate = new Date(2024, 3, 2);
12
+ export const releaseDate = new Date(2024, 3, 10);
13
13
  /* istanbul ignore next -- @preserve */
14
14
  if (globalThis.CKEDITOR_VERSION) {
15
15
  /**
@@ -1,4 +0,0 @@
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
- */
@@ -1,4 +0,0 @@
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
- */
package/dist/index.css DELETED
@@ -1,4 +0,0 @@
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
- */
@@ -1,21 +0,0 @@
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/abortabledebounce
11
- */
12
- /**
13
- * Returns a function wrapper that will execute the provided function and abort any previous call that is still in progress.
14
- *
15
- * @param func The function to be called. It will be provided with `AbortSignal` as the first parameter.
16
- */
17
- export default function abortableDebounce<Args extends Array<any>, Ret>(func: (signal: AbortSignal, ...args: Args) => Ret): AbortableFunc<Args, Ret>;
18
- export interface AbortableFunc<Args extends Array<any>, Ret> {
19
- (...args: Args): Ret;
20
- abort(): void;
21
- }
@@ -1,15 +0,0 @@
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/areconnectedthroughproperties
11
- */
12
- /**
13
- * Traverses both structures to find out whether there is a reference that is shared between both structures.
14
- */
15
- export default function areConnectedThroughProperties(obj1: object, obj2: object): boolean;
@@ -1,127 +0,0 @@
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/ckeditorerror
11
- */
12
- /**
13
- * URL to the documentation with error codes.
14
- */
15
- export declare const DOCUMENTATION_URL = "https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html";
16
- /**
17
- * The CKEditor error class.
18
- *
19
- * You should throw `CKEditorError` when:
20
- *
21
- * * An unexpected situation occurred and the editor (most probably) will not work properly. Such exception will be handled
22
- * by the {@link module:watchdog/watchdog~Watchdog watchdog} (if it is integrated),
23
- * * If the editor is incorrectly integrated or the editor API is used in the wrong way. This way you will give
24
- * feedback to the developer as soon as possible. Keep in mind that for common integration issues which should not
25
- * stop editor initialization (like missing upload adapter, wrong name of a toolbar component) we use
26
- * {@link module:utils/ckeditorerror~logWarning `logWarning()`} and
27
- * {@link module:utils/ckeditorerror~logError `logError()`}
28
- * to improve developers experience and let them see the a working editor as soon as possible.
29
- *
30
- * ```ts
31
- * /**
32
- * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
33
- * *
34
- * * @error plugin-load
35
- * * @param pluginName The name of the plugin that could not be loaded.
36
- * * @param moduleName The name of the module which tried to load this plugin.
37
- * *\/
38
- * throw new CKEditorError( 'plugin-load', {
39
- * pluginName: 'foo',
40
- * moduleName: 'bar'
41
- * } );
42
- * ```
43
- */
44
- export default class CKEditorError extends Error {
45
- /**
46
- * A context of the error by which the Watchdog is able to determine which editor crashed.
47
- */
48
- readonly context: object | null | undefined;
49
- /**
50
- * The additional error data passed to the constructor. Undefined if none was passed.
51
- */
52
- readonly data?: object;
53
- /**
54
- * Creates an instance of the CKEditorError class.
55
- *
56
- * @param errorName The error id in an `error-name` format. A link to this error documentation page will be added
57
- * to the thrown error's `message`.
58
- * @param context A context of the error by which the {@link module:watchdog/watchdog~Watchdog watchdog}
59
- * is able to determine which editor crashed. It should be an editor instance or a property connected to it. It can be also
60
- * a `null` value if the editor should not be restarted in case of the error (e.g. during the editor initialization).
61
- * The error context should be checked using the `areConnectedThroughProperties( editor, context )` utility
62
- * to check if the object works as the context.
63
- * @param data Additional data describing the error. A stringified version of this object
64
- * will be appended to the error message, so the data are quickly visible in the console. The original
65
- * data object will also be later available under the {@link #data} property.
66
- */
67
- constructor(errorName: string, context?: object | null, data?: object);
68
- /**
69
- * Checks if the error is of the `CKEditorError` type.
70
- */
71
- is(type: string): boolean;
72
- /**
73
- * A utility that ensures that the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one.
74
- * It is useful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case
75
- * of a {@link module:utils/ckeditorerror~CKEditorError} error.
76
- *
77
- * @param err The error to rethrow.
78
- * @param context An object connected through properties with the editor instance. This context will be used
79
- * by the watchdog to verify which editor should be restarted.
80
- */
81
- static rethrowUnexpectedError(err: Error, context: object): never;
82
- }
83
- /**
84
- * Logs a warning to the console with a properly formatted message and adds a link to the documentation.
85
- * Use whenever you want to log a warning to the console.
86
- *
87
- * ```ts
88
- * /**
89
- * * There was a problem processing the configuration of the toolbar. The item with the given
90
- * * name does not exist, so it was omitted when rendering the toolbar.
91
- * *
92
- * * @error toolbarview-item-unavailable
93
- * * @param {String} name The name of the component.
94
- * *\/
95
- * logWarning( 'toolbarview-item-unavailable', { name } );
96
- * ```
97
- *
98
- * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to throw an error and when to log
99
- * a warning or an error to the console.
100
- *
101
- * @param errorName The error name to be logged.
102
- * @param data Additional data to be logged.
103
- */
104
- export declare function logWarning(errorName: string, data?: object): void;
105
- /**
106
- * Logs an error to the console with a properly formatted message and adds a link to the documentation.
107
- * Use whenever you want to log an error to the console.
108
- *
109
- * ```ts
110
- * /**
111
- * * There was a problem processing the configuration of the toolbar. The item with the given
112
- * * name does not exist, so it was omitted when rendering the toolbar.
113
- * *
114
- * * @error toolbarview-item-unavailable
115
- * * @param {String} name The name of the component.
116
- * *\/
117
- * logError( 'toolbarview-item-unavailable', { name } );
118
- * ```
119
- *
120
- * **Note**: In most cases logging a warning using {@link module:utils/ckeditorerror~logWarning} is enough.
121
- *
122
- * See also {@link module:utils/ckeditorerror~CKEditorError} for an explanation when to use each method.
123
- *
124
- * @param errorName The error name to be logged.
125
- * @param data Additional data to be logged.
126
- */
127
- export declare function logError(errorName: string, data?: object): void;
@@ -1,437 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
- */
9
- declare const Collection_base: {
10
- new (): import("./emittermixin.js").Emitter;
11
- prototype: import("./emittermixin.js").Emitter;
12
- };
13
- /**
14
- * Collections are ordered sets of objects. Items in the collection can be retrieved by their indexes
15
- * in the collection (like in an array) or by their ids.
16
- *
17
- * If an object without an `id` property is being added to the collection, the `id` property will be generated
18
- * automatically. Note that the automatically generated id is unique only within this single collection instance.
19
- *
20
- * By default an item in the collection is identified by its `id` property. The name of the identifier can be
21
- * configured through the constructor of the collection.
22
- *
23
- * @typeParam T The type of the collection element.
24
- */
25
- export default class Collection<T extends Record<string, any>> extends Collection_base implements Iterable<T> {
26
- /**
27
- * The internal list of items in the collection.
28
- */
29
- private readonly _items;
30
- /**
31
- * The internal map of items in the collection.
32
- */
33
- private readonly _itemMap;
34
- /**
35
- * The name of the property which is considered to identify an item.
36
- */
37
- private readonly _idProperty;
38
- /**
39
- * A collection instance this collection is bound to as a result
40
- * of calling {@link #bindTo} method.
41
- */
42
- private _bindToCollection?;
43
- /**
44
- * A helper mapping external items of a bound collection ({@link #bindTo})
45
- * and actual items of this collection. It provides information
46
- * necessary to properly remove items bound to another collection.
47
- *
48
- * See {@link #_bindToInternalToExternalMap}.
49
- */
50
- private readonly _bindToExternalToInternalMap;
51
- /**
52
- * A helper mapping items of this collection to external items of a bound collection
53
- * ({@link #bindTo}). It provides information necessary to manage the bindings, e.g.
54
- * to avoid loops in two–way bindings.
55
- *
56
- * See {@link #_bindToExternalToInternalMap}.
57
- */
58
- private readonly _bindToInternalToExternalMap;
59
- /**
60
- * Stores indexes of skipped items from bound external collection.
61
- */
62
- private _skippedIndexesFromExternal;
63
- /**
64
- * Creates a new Collection instance.
65
- *
66
- * You can pass a configuration object as the argument of the constructor:
67
- *
68
- * ```ts
69
- * const emptyCollection = new Collection<{ name: string }>( { idProperty: 'name' } );
70
- * emptyCollection.add( { name: 'John' } );
71
- * console.log( collection.get( 'John' ) ); // -> { name: 'John' }
72
- * ```
73
- *
74
- * The collection is empty by default. You can add new items using the {@link #add} method:
75
- *
76
- * ```ts
77
- * const collection = new Collection<{ id: string }>();
78
- *
79
- * collection.add( { id: 'John' } );
80
- * console.log( collection.get( 0 ) ); // -> { id: 'John' }
81
- * ```
82
- *
83
- * @label NO_ITEMS
84
- * @param options The options object.
85
- * @param options.idProperty The name of the property which is used to identify an item.
86
- * Items that do not have such a property will be assigned one when added to the collection.
87
- */
88
- constructor(options?: {
89
- readonly idProperty?: string;
90
- });
91
- /**
92
- * Creates a new Collection instance with specified initial items.
93
- *
94
- * ```ts
95
- * const collection = new Collection<{ id: string }>( [ { id: 'John' }, { id: 'Mike' } ] );
96
- *
97
- * console.log( collection.get( 0 ) ); // -> { id: 'John' }
98
- * console.log( collection.get( 1 ) ); // -> { id: 'Mike' }
99
- * console.log( collection.get( 'Mike' ) ); // -> { id: 'Mike' }
100
- * ```
101
- *
102
- * You can always pass a configuration object as the last argument of the constructor:
103
- *
104
- * ```ts
105
- * const nonEmptyCollection = new Collection<{ name: string }>( [ { name: 'John' } ], { idProperty: 'name' } );
106
- * nonEmptyCollection.add( { name: 'George' } );
107
- * console.log( collection.get( 'George' ) ); // -> { name: 'George' }
108
- * console.log( collection.get( 'John' ) ); // -> { name: 'John' }
109
- * ```
110
- *
111
- * @label INITIAL_ITEMS
112
- * @param initialItems The initial items of the collection.
113
- * @param options The options object.
114
- * @param options.idProperty The name of the property which is used to identify an item.
115
- * Items that do not have such a property will be assigned one when added to the collection.
116
- */
117
- constructor(initialItems: Iterable<T>, options?: {
118
- readonly idProperty?: string;
119
- });
120
- /**
121
- * The number of items available in the collection.
122
- */
123
- get length(): number;
124
- /**
125
- * Returns the first item from the collection or null when collection is empty.
126
- */
127
- get first(): T | null;
128
- /**
129
- * Returns the last item from the collection or null when collection is empty.
130
- */
131
- get last(): T | null;
132
- /**
133
- * Adds an item into the collection.
134
- *
135
- * If the item does not have an id, then it will be automatically generated and set on the item.
136
- *
137
- * @param item
138
- * @param index The position of the item in the collection. The item
139
- * is pushed to the collection when `index` not specified.
140
- * @fires add
141
- * @fires change
142
- */
143
- add(item: T, index?: number): this;
144
- /**
145
- * Adds multiple items into the collection.
146
- *
147
- * Any item not containing an id will get an automatically generated one.
148
- *
149
- * @param items
150
- * @param index The position of the insertion. Items will be appended if no `index` is specified.
151
- * @fires add
152
- * @fires change
153
- */
154
- addMany(items: Iterable<T>, index?: number): this;
155
- /**
156
- * Gets an item by its ID or index.
157
- *
158
- * @param idOrIndex The item ID or index in the collection.
159
- * @returns The requested item or `null` if such item does not exist.
160
- */
161
- get(idOrIndex: string | number): T | null;
162
- /**
163
- * Returns a Boolean indicating whether the collection contains an item.
164
- *
165
- * @param itemOrId The item or its ID in the collection.
166
- * @returns `true` if the collection contains the item, `false` otherwise.
167
- */
168
- has(itemOrId: T | string): boolean;
169
- /**
170
- * Gets an index of an item in the collection.
171
- * When an item is not defined in the collection, the index will equal -1.
172
- *
173
- * @param itemOrId The item or its ID in the collection.
174
- * @returns The index of a given item.
175
- */
176
- getIndex(itemOrId: T | string): number;
177
- /**
178
- * Removes an item from the collection.
179
- *
180
- * @param subject The item to remove, its ID or index in the collection.
181
- * @returns The removed item.
182
- * @fires remove
183
- * @fires change
184
- */
185
- remove(subject: T | number | string): T;
186
- /**
187
- * Executes the callback for each item in the collection and composes an array or values returned by this callback.
188
- *
189
- * @typeParam U The result type of the callback.
190
- * @param callback
191
- * @param ctx Context in which the `callback` will be called.
192
- * @returns The result of mapping.
193
- */
194
- map<U>(callback: (item: T, index: number) => U, ctx?: any): Array<U>;
195
- /**
196
- * Performs the specified action for each item in the collection.
197
- *
198
- * @param ctx Context in which the `callback` will be called.
199
- */
200
- forEach(callback: (item: T, index: number) => unknown, ctx?: any): void;
201
- /**
202
- * Finds the first item in the collection for which the `callback` returns a true value.
203
- *
204
- * @param callback
205
- * @param ctx Context in which the `callback` will be called.
206
- * @returns The item for which `callback` returned a true value.
207
- */
208
- find(callback: (item: T, index: number) => boolean, ctx?: any): T | undefined;
209
- /**
210
- * Returns an array with items for which the `callback` returned a true value.
211
- *
212
- * @param callback
213
- * @param ctx Context in which the `callback` will be called.
214
- * @returns The array with matching items.
215
- */
216
- filter(callback: (item: T, index: number) => boolean, ctx?: any): Array<T>;
217
- /**
218
- * Removes all items from the collection and destroys the binding created using
219
- * {@link #bindTo}.
220
- *
221
- * @fires remove
222
- * @fires change
223
- */
224
- clear(): void;
225
- /**
226
- * Binds and synchronizes the collection with another one.
227
- *
228
- * The binding can be a simple factory:
229
- *
230
- * ```ts
231
- * class FactoryClass {
232
- * public label: string;
233
- *
234
- * constructor( data: { label: string } ) {
235
- * this.label = data.label;
236
- * }
237
- * }
238
- *
239
- * const source = new Collection<{ label: string }>( { idProperty: 'label' } );
240
- * const target = new Collection<FactoryClass>();
241
- *
242
- * target.bindTo( source ).as( FactoryClass );
243
- *
244
- * source.add( { label: 'foo' } );
245
- * source.add( { label: 'bar' } );
246
- *
247
- * console.log( target.length ); // 2
248
- * console.log( target.get( 1 ).label ); // 'bar'
249
- *
250
- * source.remove( 0 );
251
- * console.log( target.length ); // 1
252
- * console.log( target.get( 0 ).label ); // 'bar'
253
- * ```
254
- *
255
- * or the factory driven by a custom callback:
256
- *
257
- * ```ts
258
- * class FooClass {
259
- * public label: string;
260
- *
261
- * constructor( data: { label: string } ) {
262
- * this.label = data.label;
263
- * }
264
- * }
265
- *
266
- * class BarClass {
267
- * public label: string;
268
- *
269
- * constructor( data: { label: string } ) {
270
- * this.label = data.label;
271
- * }
272
- * }
273
- *
274
- * const source = new Collection<{ label: string }>( { idProperty: 'label' } );
275
- * const target = new Collection<FooClass | BarClass>();
276
- *
277
- * target.bindTo( source ).using( ( item ) => {
278
- * if ( item.label == 'foo' ) {
279
- * return new FooClass( item );
280
- * } else {
281
- * return new BarClass( item );
282
- * }
283
- * } );
284
- *
285
- * source.add( { label: 'foo' } );
286
- * source.add( { label: 'bar' } );
287
- *
288
- * console.log( target.length ); // 2
289
- * console.log( target.get( 0 ) instanceof FooClass ); // true
290
- * console.log( target.get( 1 ) instanceof BarClass ); // true
291
- * ```
292
- *
293
- * or the factory out of property name:
294
- *
295
- * ```ts
296
- * const source = new Collection<{ nested: { value: string } }>();
297
- * const target = new Collection<{ value: string }>();
298
- *
299
- * target.bindTo( source ).using( 'nested' );
300
- *
301
- * source.add( { nested: { value: 'foo' } } );
302
- * source.add( { nested: { value: 'bar' } } );
303
- *
304
- * console.log( target.length ); // 2
305
- * console.log( target.get( 0 ).value ); // 'foo'
306
- * console.log( target.get( 1 ).value ); // 'bar'
307
- * ```
308
- *
309
- * It's possible to skip specified items by returning null value:
310
- *
311
- * ```ts
312
- * const source = new Collection<{ hidden: boolean }>();
313
- * const target = new Collection<{ hidden: boolean }>();
314
- *
315
- * target.bindTo( source ).using( item => {
316
- * if ( item.hidden ) {
317
- * return null;
318
- * }
319
- *
320
- * return item;
321
- * } );
322
- *
323
- * source.add( { hidden: true } );
324
- * source.add( { hidden: false } );
325
- *
326
- * console.log( source.length ); // 2
327
- * console.log( target.length ); // 1
328
- * ```
329
- *
330
- * **Note**: {@link #clear} can be used to break the binding.
331
- *
332
- * @typeParam S The type of `externalCollection` element.
333
- * @param externalCollection A collection to be bound.
334
- * @returns The binding chain object.
335
- */
336
- bindTo<S extends Record<string, any>>(externalCollection: Collection<S>): CollectionBindToChain<S, T>;
337
- /**
338
- * Finalizes and activates a binding initiated by {@link #bindTo}.
339
- *
340
- * @param factory A function which produces collection items.
341
- */
342
- private _setUpBindToBinding;
343
- /**
344
- * Returns an unique id property for a given `item`.
345
- *
346
- * The method will generate new id and assign it to the `item` if it doesn't have any.
347
- *
348
- * @param item Item to be added.
349
- */
350
- private _getItemIdBeforeAdding;
351
- /**
352
- * Core {@link #remove} method implementation shared in other functions.
353
- *
354
- * In contrast this method **does not** fire the {@link #event:change} event.
355
- *
356
- * @param subject The item to remove, its id or index in the collection.
357
- * @returns Returns an array with the removed item and its index.
358
- * @fires remove
359
- */
360
- private _remove;
361
- /**
362
- * Iterable interface.
363
- */
364
- [Symbol.iterator](): Iterator<T>;
365
- }
366
- /**
367
- * Fired when an item is added to the collection.
368
- *
369
- * @eventName ~Collection#add
370
- * @param item The added item.
371
- * @param index An index where the addition occurred.
372
- */
373
- export type CollectionAddEvent<T = any> = {
374
- name: 'add';
375
- args: [item: T, index: number];
376
- };
377
- /**
378
- * Fired when the collection was changed due to adding or removing items.
379
- *
380
- * @eventName ~Collection#change
381
- * @param data Changed items.
382
- */
383
- export type CollectionChangeEvent<T = any> = {
384
- name: 'change';
385
- args: [data: CollectionChangeEventData<T>];
386
- };
387
- /**
388
- * A structure describing the {@link ~Collection#event:change `Collection#change`} event.
389
- */
390
- export type CollectionChangeEventData<T = any> = {
391
- /**
392
- * A list of added items.
393
- */
394
- added: Iterable<T>;
395
- /**
396
- * A list of removed items.
397
- */
398
- removed: Iterable<T>;
399
- /**
400
- * An index where the addition or removal occurred.
401
- */
402
- index: number;
403
- };
404
- /**
405
- * Fired when an item is removed from the collection.
406
- *
407
- * @eventName ~Collection#remove
408
- * @param item The removed item.
409
- * @param index Index from which item was removed.
410
- */
411
- export type CollectionRemoveEvent<T = any> = {
412
- name: 'remove';
413
- args: [item: T, index: number];
414
- };
415
- /**
416
- * An object returned by the {@link module:utils/collection~Collection#bindTo `bindTo()`} method
417
- * providing functions that specify the type of the binding.
418
- *
419
- * See the {@link module:utils/collection~Collection#bindTo `bindTo()`} documentation for examples.
420
- */
421
- export interface CollectionBindToChain<S, T> {
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;
436
- }
437
- export {};