1 | /**
|
2 | * A function which when called will unsubscribe from the observable.
|
3 | *
|
4 | * @since 1.0.0
|
5 | */
|
6 | type UnsubscribeFunction = () => void;
|
7 | /**
|
8 | * The interface each component of uiloos/core implements so it
|
9 | * can be subscribed to.
|
10 | *
|
11 | * Note: there is no reason to ever implement the `Observable`
|
12 | * interface yourself. It is only exposed so bindings to frameworks
|
13 | * can use the type.
|
14 | *
|
15 | * @since 1.4.0
|
16 | */
|
17 | interface Observable<T, E> {
|
18 | /**
|
19 | * Subscribe to changes of the Observable. The function you provide
|
20 | * will get called whenever changes occur in the Observable.
|
21 | *
|
22 | * Returns an unsubscribe function which when called will
|
23 | * unsubscribe from the Observable.
|
24 | *
|
25 | * @param {Subscriber<T, E>} subscriber The subscriber which responds to changes in the Observable.
|
26 | * @returns {UnsubscribeFunction} A function which when called will unsubscribe from the Observable.
|
27 | *
|
28 | * @since 1.4.0
|
29 | */
|
30 | subscribe(subscriber: Subscriber<T, E>): UnsubscribeFunction;
|
31 | }
|
32 | /**
|
33 | * A function which when called will subscribe to the observable.
|
34 | *
|
35 | * @since 1.4.0
|
36 | */
|
37 | type Subscriber<T, E> = (observerable: T, event: E) => void;
|
38 |
|
39 | /**
|
40 | * Checks / validates the license for "uiloos".
|
41 | *
|
42 | * Note: you are not supposed to use this class directly. Use the
|
43 | * variable `licenseChecker` instead.
|
44 | *
|
45 | * @since 1.0.0
|
46 | */
|
47 | declare class _LicenseChecker {
|
48 | private _licenseKey;
|
49 | private _logOnSuccess;
|
50 | private _success;
|
51 | /**
|
52 | * With `activateLicense` you can set activate your license key for
|
53 | * uiloos. Make sure that you set your license key before using any
|
54 | * functionality that uiloos provides.
|
55 | *
|
56 | * You can purchase a license at https://www.uiloos.dev.
|
57 | *
|
58 | * @param {string} licenseKey The license key of uiloos you want to activate.
|
59 | * @param {ActivateLicenseOptions} options The optional options for the `activateLicense` function, can be used to suppress the "license activated" message.
|
60 | * @since 1.0.0
|
61 | */
|
62 | activateLicense(licenseKey: string, options?: ActivateLicenseOptions): void;
|
63 | /**
|
64 | * Checks the current license to see if it is valid.
|
65 | *
|
66 | * Note: this method is for internal use inside uiloos only.
|
67 | *
|
68 | * @since 1.0.0
|
69 | */
|
70 | _checkLicense(): void;
|
71 | }
|
72 | /**
|
73 | * The sole instance (a singleton) of the `_LicenseChecker` class.
|
74 | *
|
75 | * Use this instance of `_LicenseChecker` to call `activateLicense` to
|
76 | * activate your license.
|
77 | *
|
78 | * @see _LicenseChecker
|
79 | * @since 1.0.0
|
80 | *
|
81 | * @example
|
82 | *
|
83 | * Activating license
|
84 | *
|
85 | * You activate the license by calling "activateLicense" on the
|
86 | * "licenseChecker" instance.
|
87 | *
|
88 | * ```js
|
89 | * import { licenseChecker } from '@uiloos/core';
|
90 | * licenseChecker.activateLicense("{LICENSE-HERE}");
|
91 | * ```
|
92 | */
|
93 | declare let licenseChecker: _LicenseChecker;
|
94 | /**
|
95 | * The options for the `activateLicense` functions. Can be used
|
96 | * to silence the "license activated" message.
|
97 | *
|
98 | * @since 1.0.0
|
99 | */
|
100 | type ActivateLicenseOptions = {
|
101 | /**
|
102 | * Whether or not to silence the "license activated" message
|
103 | * when the license is valid.
|
104 | *
|
105 | * @since 1.0.0
|
106 | */
|
107 | logLicenseActivated: boolean;
|
108 | };
|
109 |
|
110 | /**
|
111 | * Configures the initial state of the `ActiveList`
|
112 | *
|
113 | * @since 1.0.0
|
114 | */
|
115 | type ActiveListConfig<T> = {
|
116 | /**
|
117 | * The contents which you want to display, can be an array of anything
|
118 | * you want.
|
119 | *
|
120 | * Note: the `ActiveList` will wrap each item in the `contents` array
|
121 | * inside of a `ActiveListContent` item.
|
122 | *
|
123 | * Defaults to `[]` meaning there is no content.
|
124 | *
|
125 | * @since 1.0.0
|
126 | */
|
127 | contents?: T[];
|
128 | /**
|
129 | * How many items can be active at the same time.
|
130 | *
|
131 | * When the value of `limit` is `false` there is no limit to the
|
132 | * number of active items.
|
133 | *
|
134 | * Defaults to `1`.
|
135 | *
|
136 | * @since 1.0.0
|
137 | */
|
138 | maxActivationLimit?: number | false;
|
139 | /**
|
140 | * How the limit is enforced. In other words what the behavior
|
141 | * should be when the limit is surpassed.
|
142 | *
|
143 | * The modes are strings which can be the following values:
|
144 | *
|
145 | * 1. 'circular': the first item which was added will be removed so
|
146 | * the last item can be added without violating the limit. This
|
147 | * basically means that the first one in is the first one out.
|
148 | *
|
149 | * 2. 'error': An error is thrown whenever the limit is surpassed,
|
150 | * the error is called the `ActiveListActivationLimitReachedError`.
|
151 | *
|
152 | * 3. 'ignore': Nothing happens when an item is added and the limit
|
153 | * is reached. The item is simply not added, but no error is
|
154 | * thrown.
|
155 | *
|
156 | * Defaults to 'circular'.
|
157 | *
|
158 | * @since 1.0.0
|
159 | */
|
160 | maxActivationLimitBehavior?: ActiveListMaxActivationLimitBehavior;
|
161 | /**
|
162 | * Which item or items in the content array are currently active.
|
163 | *
|
164 | * When the `active` is an array each item in the array is activated
|
165 | * from left to right one at a time.
|
166 | *
|
167 | * Note: "active" is chosen over the "activeIndexes" property.
|
168 | *
|
169 | * Defaults to `[]` meaning no content is active.
|
170 | *
|
171 | * @since 1.0.0
|
172 | */
|
173 | active?: T | T[];
|
174 | /**
|
175 | * Which index or indexes of the content array are currently active.
|
176 | *
|
177 | * When the `activeIndexes` is an array each index in the array
|
178 | * is activated from left to right one at a time.
|
179 | *
|
180 | * Note: "active" is chosen over the "activeIndexes" property.
|
181 | *
|
182 | * Defaults to `[]` meaning no content is active.
|
183 | *
|
184 | * @since 1.0.0
|
185 | */
|
186 | activeIndexes?: number | number[];
|
187 | /**
|
188 | * Whether or not the content starts back at the beginning when
|
189 | * the end of the content is reached, and whether the content should
|
190 | * go to the end when moving left of the start.
|
191 | *
|
192 | * Defaults to `true`.
|
193 | *
|
194 | * @since 1.0.0
|
195 | */
|
196 | isCircular?: boolean;
|
197 | /**
|
198 | * Whether or not `autoPlay` is enabled. When `autoPlay` is enabled
|
199 | * it will automatically move to the next content, based on the
|
200 | * `duration`.
|
201 | *
|
202 | * When `isCircular` is `true` content will move to the right
|
203 | * indefinitely. When `isCircular` is `false` it will stop autoPlay
|
204 | * at the end of the content.
|
205 | *
|
206 | * Note: autoPlay will only start when one or more contents are
|
207 | * currently active. The reason for this is that the `duration`, is
|
208 | * based on the `ActiveList` `lastActivatedContent` property.
|
209 | * Whenever there are no more items to activate the autoPlay will
|
210 | * stop.
|
211 | *
|
212 | * Defaults to no autoPlay.
|
213 | *
|
214 | * @since 1.0.0
|
215 | */
|
216 | autoPlay?: ActiveListAutoPlayConfig<T>;
|
217 | /**
|
218 | * Describes which strings should be associated with what
|
219 | * direction, will be the value of the `ActiveList` property
|
220 | * `direction`.
|
221 | *
|
222 | * So when setting the direction `next` to "up"` and the content
|
223 | * moves up, the `ActiveList.direction` will be "up". Useful when
|
224 | * wanting to apply CSS classes based on the direction.
|
225 | *
|
226 | * Defaults to `{ next: 'right', previous: 'left' }`.
|
227 | *
|
228 | * @since 1.0.0
|
229 | */
|
230 | directions?: ActiveListDirection;
|
231 | /**
|
232 | * For how many items the `history` may contain in the `ActiveList`.
|
233 | *
|
234 | * Defaults to `0` meaning that it will not track history.
|
235 | *
|
236 | * @since 1.0.0
|
237 | */
|
238 | keepHistoryFor?: number;
|
239 | /**
|
240 | * The `cooldown` is the number of milliseconds before another
|
241 | * activation / deactivation is allowed. For example if the
|
242 | * `cooldown` is `5000` the `ActiveList` will not allow
|
243 | * transitions until after 5 seconds have passed. Any activation /
|
244 | * deactivation in that period will simply be ignored.
|
245 | *
|
246 | * This can be useful when you have an animation which should be
|
247 | * finished before allowing user interaction again.
|
248 | *
|
249 | * This global `cooldown` is the same for all transitions you might trigger.
|
250 | * If you want a `cooldown` that differs per button use the `cooldown`
|
251 | * in the `ActiveListActivationOptions` instead.
|
252 | *
|
253 | * Note that the `cooldown` options with the `ActiveListActivationOptions` takes
|
254 | * precedence over this more global cooldown.
|
255 | *
|
256 | * IMPORTANT: `cooldown` is only ran when `isUserInteraction` within
|
257 | * the `ActiveListActivationOptions` is `true`. This means that `autoPlay`, which
|
258 | * is not a user interaction, ignores the `cooldown`.
|
259 | *
|
260 | * @since 1.0.0
|
261 | */
|
262 | cooldown?: ActiveListCooldownConfig<T>;
|
263 | };
|
264 | /**
|
265 | * Describes all the behaviors for when the limit of the ActiveList
|
266 | * is surpassed.
|
267 | *
|
268 | * 1. 'circular': the first item which was added will be removed so
|
269 | * the last item can be added without violating the limit. This
|
270 | * basically means that the first one in is the first one out.
|
271 | *
|
272 | * 2. 'error': An error is thrown whenever the limit is surpassed,
|
273 | * the error is called the `ActiveListActivationLimitReachedError`.
|
274 | *
|
275 | * 3. 'ignore': Nothing happens when an item is added and the limit
|
276 | * is reached. The item is simply not added, but no error is
|
277 | * thrown.
|
278 | *
|
279 | * @since 1.0.0
|
280 | */
|
281 | type ActiveListMaxActivationLimitBehavior = 'circular' | 'ignore' | 'error';
|
282 | /**
|
283 | * Represents options for activation / deactivation methods.
|
284 | *
|
285 | * @since 1.0.0
|
286 | */
|
287 | type ActiveListActivationOptions<T> = {
|
288 | /**
|
289 | * Whether or not the action was taken by a user / human. This
|
290 | * affects the `autoPlay` when `stopsOnUserInteraction` is `true`,
|
291 | * the `autoPlay` stops, when `false` the autoPlay is debounced.
|
292 | *
|
293 | * Also affects the `cooldown` when `isUserInteraction` is `true`,
|
294 | * the `cooldown` is checked, otherwise when `false`
|
295 | * the `cooldown` is ignored.
|
296 | *
|
297 | * Defaults to `true`.
|
298 | *
|
299 | * @since 1.0.0
|
300 | */
|
301 | isUserInteraction?: boolean;
|
302 | /**
|
303 | * The `cooldown` is the number of milliseconds before another
|
304 | * activation / deactivation is allowed. For example if the
|
305 | * `cooldown` is `5000` the `ActiveList` will not allow
|
306 | * transitions until after 5 seconds have passed. Any activation /
|
307 | * deactivation in that period will simply be ignored.
|
308 | *
|
309 | * This can be useful when you have an animation which should be
|
310 | * finished before allowing user interaction again.
|
311 | *
|
312 | * The benefit of this `cooldown` over the `cooldown` in the
|
313 | * `Config`, is that this `cooldown` can be different for different
|
314 | * actions. For example: it allows you to create two buttons each
|
315 | * with a different cooldown.
|
316 | *
|
317 | * Note that the `cooldown` options within the `ActiveListActivationOptions`
|
318 | * takes precedence over the `cooldown` in the `Config`.
|
319 | *
|
320 | * IMPORTANT: `cooldown` is only ran when `isUserInteraction` within
|
321 | * the `ActiveListActivationOptions` is `true`. This means that
|
322 | * `autoPlay`, which is not a user interaction, ignores the
|
323 | * `cooldown`.
|
324 | *
|
325 | * @since 1.0.0
|
326 | */
|
327 | cooldown?: ActiveListCooldownConfig<T>;
|
328 | };
|
329 | /**
|
330 | * The subscriber which is informed of all state changes the
|
331 | * ActiveList goes through.
|
332 | *
|
333 | * @param {ActiveList<T>} activeList The ActiveList which had changes.
|
334 | * @param {ActiveListEvent<T>} event The event that occurred.
|
335 | *
|
336 | * @since 1.0.0
|
337 | */
|
338 | type ActiveListSubscriber<T> = (activeList: ActiveList<T>, event: ActiveListEvent<T>) => void;
|
339 | /**
|
340 | * Represents a bundle of data which is given as the first parameter
|
341 | * to the ContentPredicate function. Based on this data the
|
342 | * ContentPredicate must either return `true` or `false`.
|
343 | *
|
344 | * @since 1.0.0
|
345 | */
|
346 | type ActiveListContentPredicateData<T> = {
|
347 | /**
|
348 | * The value the ActiveListContent wraps.
|
349 | *
|
350 | * @since 1.0.0
|
351 | */
|
352 | value: T;
|
353 | /**
|
354 | * The index the ActiveListContent has within the ActiveList
|
355 | *
|
356 | * @since 1.0.0
|
357 | */
|
358 | index: number;
|
359 | /**
|
360 | * A reference to the ActiveListContent which wraps the value.
|
361 | *
|
362 | * @since 1.0.0
|
363 | */
|
364 | content: ActiveListContent<T>;
|
365 | /**
|
366 | * A reference to the ActiveList itself.
|
367 | *
|
368 | * @since 1.0.0
|
369 | */
|
370 | activeList: ActiveList<T>;
|
371 | };
|
372 | /**
|
373 | * Represents a callback which is given all relevant data for the
|
374 | * action, and expects either `true` or `false` to be returned. If
|
375 | * `true` is returned will perform the action.
|
376 | *
|
377 | * @param {ActiveListContentPredicateData<T>} data The data for which this predicate will determine if the action needs to be performed.
|
378 | * @returns {boolean} Whether or not to perform the action associated with the predicate based on the given item and index.
|
379 | *
|
380 | * @since 1.0.0
|
381 | */
|
382 | type ActiveListContentPredicate<T> = (data: ActiveListContentPredicateData<T>) => boolean;
|
383 | /**
|
384 | * Represents a bundle of data which is given whenever the
|
385 | * AutoPlayDurationCallbackData function must determine the number
|
386 | * of milliseconds the content should be active for.
|
387 | *
|
388 | * @since 1.0.0
|
389 | */
|
390 | type ActiveListAutoPlayDurationCallbackData<T> = {
|
391 | /**
|
392 | * The value which is currently asking which autoPlay duration it should have.
|
393 | *
|
394 | * @since 1.0.0
|
395 | */
|
396 | value: T;
|
397 | /**
|
398 | * The index the value has within the ActiveList
|
399 | *
|
400 | * @since 1.0.0
|
401 | */
|
402 | index: number;
|
403 | /**
|
404 | * A reference to the ActiveListContent which wraps the value.
|
405 | *
|
406 | * @since 1.0.0
|
407 | */
|
408 | content: ActiveListContent<T>;
|
409 | /**
|
410 | * A reference to the ActiveList itself.
|
411 | *
|
412 | * @since 1.0.0
|
413 | */
|
414 | activeList: ActiveList<T>;
|
415 | };
|
416 | /**
|
417 | * Represents a callback function which is given all relevant autoPlay
|
418 | * duration data, and expects to be given back the number of
|
419 | * milliseconds the content should be active before autoPlay moves on.
|
420 | *
|
421 | * @param {ActiveListAutoPlayDurationCallbackData<T>} data An object containing all relevant duration data for which the callback function must determine the number of milliseconds the content is active for.
|
422 | * @returns {number} The time in milliseconds the content is active for the given AutoPlayDurationCallbackData.
|
423 | *
|
424 | * @since 1.0.0
|
425 | */
|
426 | type ActiveListAutoPlayDurationCallback<T> = (config: ActiveListAutoPlayDurationCallbackData<T>) => number;
|
427 | /**
|
428 | * Represents the configuration for AutoPlay. AutoPlay means
|
429 | * that the ActiveList will move to the next content by itself
|
430 | * after a duration.
|
431 | *
|
432 | * @since 1.0.0
|
433 | */
|
434 | type ActiveListAutoPlayConfig<T> = {
|
435 | /**
|
436 | * The time in milliseconds the ActiveListContent should remain active, before
|
437 | * moving to the next ActiveListContent.
|
438 | *
|
439 | * @since 1.0.0
|
440 | */
|
441 | duration: ActiveListAutoPlayDurationCallback<T> | number;
|
442 | /**
|
443 | * Whether or not the user interacting with the component should
|
444 | * stop the autoPlay.
|
445 | *
|
446 | * When `true` any activation / deactivation method called on
|
447 | * the `ActiveList` will stop the autoPlay. When `false` it will
|
448 | * debounce the autoPlay instead by the duration.
|
449 | *
|
450 | * Defaults to `false`.
|
451 | *
|
452 | * @since 1.0.0
|
453 | */
|
454 | stopsOnUserInteraction?: boolean;
|
455 | };
|
456 | /**
|
457 | * AutoPlay means that the ActiveList will move to the next content by
|
458 | * itself after a duration.
|
459 | *
|
460 | * Contains whether or not the autoPlay is playing via `isPlaying` and
|
461 | * the current duration via `duration`.
|
462 | *
|
463 | * @since 1.0.0
|
464 | */
|
465 | type ActiveListAutoPlay = {
|
466 | /**
|
467 | * Whether or not the ActiveList is playing. In other words whether
|
468 | * or not the ActiveList is going to cycle through the content
|
469 | * automatically.
|
470 | *
|
471 | * @since 1.0.0
|
472 | */
|
473 | isPlaying: boolean;
|
474 | /**
|
475 | * The amount of milliseconds the item should remain active before
|
476 | * jumping to the next item.
|
477 | *
|
478 | * This duration is the duration for the current item which is
|
479 | * playing. It is not affected by calling pause, meaning that
|
480 | * when the duration is set to 200ms and you pause after 100ms,
|
481 | * the duration will still be 200ms.
|
482 | *
|
483 | * When calling `stop`, or when `stop` is called when the autoPlay
|
484 | * reaches the end, the duration will be set to zero.
|
485 | *
|
486 | * @since 1.0.0
|
487 | */
|
488 | duration: number;
|
489 | /**
|
490 | * Whether or not the ActiveList had the autoPlay stopped at one
|
491 | * point before.
|
492 | *
|
493 | * Use case: say you are making a carousel which should stop on
|
494 | * any user interaction, so you set `stopsOnUserInteraction` to
|
495 | * `true`. Say you also have another feature: a pause whenever
|
496 | * the user hovers over the carousel. These two features would cause
|
497 | * a conflict:
|
498 | *
|
499 | * Whenever the mouse over happens you call `play()`, which negates
|
500 | * the `stopsOnUserInteraction`, causing the carousel to play again.
|
501 | *
|
502 | * To fix this problem you should on the mouse over not call
|
503 | * `play()` whenever `hasBeenStoppedBefore` is `true`.
|
504 | *
|
505 | * @since 1.1.0
|
506 | */
|
507 | hasBeenStoppedBefore: boolean;
|
508 | };
|
509 | /**
|
510 | * Represents the configuration of the cooldown.
|
511 | *
|
512 | * Can be two possible things:
|
513 | *
|
514 | * 1. A callback function which receives the relevant cooldown data,
|
515 | * and which is required to return the duration in milliseconds.
|
516 | * Useful for providing a different cooldown for different items.
|
517 | *
|
518 | * 2. A number in milliseconds. When it is a number all items will
|
519 | * have the same cooldown.
|
520 | *
|
521 | * @since 1.0.0
|
522 | */
|
523 | type ActiveListCooldownConfig<T> = ActiveListCooldownDurationCallback<T> | number;
|
524 | /**
|
525 | * Represents a bundle of data which is given whenever the
|
526 | * CooldownDurationCallback function must determine what the number of
|
527 | * milliseconds the content should be in a cooldown state.
|
528 | *
|
529 | * @since 1.0.0
|
530 | */
|
531 | type ActiveListCooldownDurationCallbackData<T> = {
|
532 | /**
|
533 | * The value which is currently asking which cooldown it should have.
|
534 | *
|
535 | * @since 1.0.0
|
536 | */
|
537 | value: T;
|
538 | /**
|
539 | * The index the value has within the ActiveList
|
540 | *
|
541 | * @since 1.0.0
|
542 | */
|
543 | index: number;
|
544 | /**
|
545 | * A reference to the ActiveListContent which wraps the value.
|
546 | *
|
547 | * @since 1.0.0
|
548 | */
|
549 | content: ActiveListContent<T>;
|
550 | /**
|
551 | * A reference to the ActiveList itself.
|
552 | *
|
553 | * @since 1.0.0
|
554 | */
|
555 | activeList: ActiveList<T>;
|
556 | };
|
557 | /**
|
558 | * Represents a callback function which is given all relevant cooldown
|
559 | * duration data, and expects to be given back the number of
|
560 | * milliseconds the content should be cooled down before it responds
|
561 | * to user interaction again.
|
562 | *
|
563 | * WARNING: do not return a negative number or zero in this callback
|
564 | * as this results in a `ActiveListCooldownDurationError`. The action
|
565 | * will still occur however, this means that the ActiveList is invalid
|
566 | * when this happens.
|
567 | *
|
568 | * @param {ActiveListCooldownDurationCallbackData<T>} data An object containing all relevant cooldown data for which the callback function must determine the cooldown duration in number of milliseconds.
|
569 | * @returns {number} The time in milliseconds of the duration of the cooldown for the given CooldownCallbackData.
|
570 | *
|
571 | * @since 1.0.0
|
572 | */
|
573 | type ActiveListCooldownDurationCallback<T> = (data: ActiveListCooldownDurationCallbackData<T>) => number;
|
574 | /**
|
575 | * A Cooldown is a time period in which all user made activations
|
576 | * and deactivations are prevented / ignored. Activations and
|
577 | * deactivations where the `isUserInteraction` is set to `false`
|
578 | * always bypass the cooldown.
|
579 | *
|
580 | * The use-case is a cooldown can guarantees that animations are
|
581 | * completed, before another is triggered.
|
582 | *
|
583 | * Contains whether or not the cooldown is active via `isActive` and
|
584 | * the current duration via `duration`.
|
585 | *
|
586 | * @since 1.0.0
|
587 | */
|
588 | type ActiveListCooldown = {
|
589 | /**
|
590 | * Whether or not the ActiveList is currently in the cooldown state.
|
591 | * When in cooldown all activations and deactivations are ignored.
|
592 | *
|
593 | * @since 1.0.0
|
594 | */
|
595 | isActive: boolean;
|
596 | /**
|
597 | * The amount of milliseconds the ActiveList should remain in
|
598 | * the cooldown state.
|
599 | *
|
600 | * @since 1.0.0
|
601 | */
|
602 | duration: number;
|
603 | };
|
604 | /**
|
605 | * Describes which strings should be associated with what
|
606 | * direction. For example it could be "right" and "left",
|
607 | * or "down" and "up".
|
608 | *
|
609 | * Will be the value of the `ActiveList` property `direction`.
|
610 | *
|
611 | * Useful for when animations have a certain direction and you
|
612 | * name your animation CSS classes `left-animation` and
|
613 | * `right-animation`.
|
614 | *
|
615 | * @since 1.0.0
|
616 | */
|
617 | type ActiveListDirection = {
|
618 | /**
|
619 | * The name of the direction when moving to the next item of the
|
620 | * `ActiveList`.
|
621 | *
|
622 | * Could for example be "right" or "down".
|
623 | *
|
624 | * @since 1.0.0
|
625 | */
|
626 | next: string;
|
627 | /**
|
628 | * The name of the direction when moving to the previous item of the
|
629 | * `ActiveList`.
|
630 | *
|
631 | * Could for example be "left" or "up".
|
632 | *
|
633 | * @since 1.0.0
|
634 | */
|
635 | previous: string;
|
636 | };
|
637 | /**
|
638 | * Represents whether the `ActiveListEvent` was inserted, removed, activated
|
639 | * swapped, etc etc.
|
640 | *
|
641 | * @since 1.0.0
|
642 | */
|
643 | type ActiveListEventType = 'INITIALIZED' | 'INSERTED' | 'REMOVED' | 'REMOVED_MULTIPLE' | 'ACTIVATED' | 'ACTIVATED_MULTIPLE' | 'SWAPPED' | 'MOVED' | 'DEACTIVATED' | 'DEACTIVATED_MULTIPLE' | 'AUTO_PLAY_PLAYING' | 'AUTO_PLAY_PAUSED' | 'AUTO_PLAY_STOPPED' | 'COOLDOWN_STARTED' | 'COOLDOWN_ENDED';
|
644 | /**
|
645 | * Represents an event which happened in the ActiveList. Based
|
646 | * on the `type` you can determine which event occurred.
|
647 | *
|
648 | * @since 1.0.0
|
649 | */
|
650 | type ActiveListBaseEvent = {
|
651 | /**
|
652 | * Which event occurred
|
653 | *
|
654 | * @since 1.0.0
|
655 | */
|
656 | type: ActiveListEventType;
|
657 | /**
|
658 | * The time the event occurred on as a Date object.
|
659 | *
|
660 | * @since 1.0.0
|
661 | */
|
662 | time: Date;
|
663 | };
|
664 | /**
|
665 | * Represents the initialization of the ActiveList
|
666 | *
|
667 | * @since 1.0.0
|
668 | */
|
669 | type ActiveListInitializedEvent<T> = ActiveListBaseEvent & {
|
670 | /**
|
671 | * Which type occurred
|
672 | *
|
673 | * @since 1.0.0
|
674 | */
|
675 | type: 'INITIALIZED';
|
676 | /**
|
677 | * The values which were active upon initialization.
|
678 | *
|
679 | * Note: these are the values at the time of the initialization, they might
|
680 | * no longer be accurate. Keep in mind that when the `value` is
|
681 | * an object or an array, they can still be mutated, because no
|
682 | * copy is made.
|
683 | *
|
684 | * @since 1.0.0
|
685 | */
|
686 | values: T[];
|
687 | /**
|
688 | * The indexes of the values which were active upon initialization.
|
689 | *
|
690 | * Note: these are the indexes at the time of the initialization, it might
|
691 | * no longer be accurate.
|
692 | *
|
693 | * @since 1.0.0
|
694 | */
|
695 | indexes: number[];
|
696 | };
|
697 | /**
|
698 | * Represents an insertion into the ActiveList.
|
699 | *
|
700 | * @since 1.0.0
|
701 | */
|
702 | type ActiveListInsertedEvent<T> = ActiveListBaseEvent & {
|
703 | /**
|
704 | * Which type occurred
|
705 | *
|
706 | * @since 1.0.0
|
707 | */
|
708 | type: 'INSERTED';
|
709 | /**
|
710 | * The value which was inserted.
|
711 | *
|
712 | * Note: this was the value at the time of insertion, it might
|
713 | * no longer be accurate. Keep in mind that when the `value` is
|
714 | * an object or an array, they can still be mutated, because no
|
715 | * copy is made.
|
716 | *
|
717 | * @since 1.0.0
|
718 | */
|
719 | value: T;
|
720 | /**
|
721 | * The index of the insertion.
|
722 | *
|
723 | * Note: this was the index at the time of the insertion, it might
|
724 | * no longer be accurate.
|
725 | *
|
726 | * @since 1.0.0
|
727 | */
|
728 | index: number;
|
729 | };
|
730 | /**
|
731 | * Represents an removal of an item of the ActiveList.
|
732 | *
|
733 | * @since 1.0.0
|
734 | */
|
735 | type ActiveListRemovedEvent<T> = ActiveListBaseEvent & {
|
736 | /**
|
737 | * Which type occurred
|
738 | *
|
739 | * @since 1.0.0
|
740 | */
|
741 | type: 'REMOVED';
|
742 | /**
|
743 | * The value which was removed.
|
744 | *
|
745 | * Note: this was the value at the time of removal, it might
|
746 | * no longer be accurate. Keep in mind that when the `value` is
|
747 | * an object or an array, they can still be mutated, because no
|
748 | * copy is made.
|
749 | *
|
750 | * @since 1.0.0
|
751 | */
|
752 | value: T;
|
753 | /**
|
754 | * The index of removed item.
|
755 | *
|
756 | * Note: this was the index at the time of the removal, it might
|
757 | * no longer be accurate.
|
758 | *
|
759 | * @since 1.0.0
|
760 | */
|
761 | index: number;
|
762 | };
|
763 | /**
|
764 | * Represents multiple removals of items in the ActiveList.
|
765 | *
|
766 | * @since 1.0.0
|
767 | */
|
768 | type ActiveListRemovedMultipleEvent<T> = ActiveListBaseEvent & {
|
769 | /**
|
770 | * Which type occurred
|
771 | *
|
772 | * @since 1.0.0
|
773 | */
|
774 | type: 'REMOVED_MULTIPLE';
|
775 | /**
|
776 | * The values which were removed
|
777 | *
|
778 | * Note: these are the values at the time of removal, they might
|
779 | * no longer be accurate. Keep in mind that when the `value` is
|
780 | * an object or an array, they can still be mutated, because no
|
781 | * copy is made.
|
782 | *
|
783 | * @since 1.0.0
|
784 | */
|
785 | values: T[];
|
786 | /**
|
787 | * The indexes of the removed items.
|
788 | *
|
789 | * Note: these are the indexes at the time of the removal, it might
|
790 | * no longer be accurate.
|
791 | *
|
792 | * @since 1.0.0
|
793 | */
|
794 | indexes: number[];
|
795 | };
|
796 | /**
|
797 | * Represents an activation of an ActiveList.
|
798 | *
|
799 | * @since 1.0.0
|
800 | */
|
801 | type ActiveListActivatedEvent<T> = ActiveListBaseEvent & {
|
802 | /**
|
803 | * Which type occurred
|
804 | *
|
805 | * @since 1.0.0
|
806 | */
|
807 | type: 'ACTIVATED';
|
808 | /**
|
809 | * The value which was activated.
|
810 | *
|
811 | * Note: this was the value at the time of activation, it might
|
812 | * no longer be accurate. Keep in mind that when the `value` is
|
813 | * an object or an array, they can still be mutated, because no
|
814 | * copy is made.
|
815 | *
|
816 | * @since 1.0.0
|
817 | */
|
818 | value: T;
|
819 | /**
|
820 | * The index of the activated item.
|
821 | *
|
822 | * Note: this was the index at the time of the activation, it might
|
823 | * no longer be accurate.
|
824 | *
|
825 | * @since 1.0.0
|
826 | */
|
827 | index: number;
|
828 | /**
|
829 | * The value which was deactivated, will be `null` when no value
|
830 | * was deactivated as part of the activation.
|
831 | *
|
832 | * A deactivation will only happen as part of an activation when
|
833 | * `maxActivationLimit` is set to a `number` and
|
834 | * `maxActivationLimitBehavior` is set to `circular`.
|
835 | *
|
836 | * Note: these are the values at the time of deactivation, they might
|
837 | * no longer be accurate. Keep in mind that when the `value` is
|
838 | * an object or an array, they can still be mutated, because no
|
839 | * copy is made.
|
840 | *
|
841 | * @since 1.5.0
|
842 | */
|
843 | deactivatedValue: T | null;
|
844 | /**
|
845 | * The index of the deactivated item, will be `-1` when no index
|
846 | * was deactivated as part of the activation.
|
847 | *
|
848 | * A deactivation will only happen as part of an activation when
|
849 | * `maxActivationLimit` is set to a `number` and
|
850 | * `maxActivationLimitBehavior` is set to `circular`.
|
851 | *
|
852 | * Note: this was the index at the time of the deactivation, it might
|
853 | * no longer be accurate.
|
854 | *
|
855 | * @since 1.5.0
|
856 | */
|
857 | deactivatedIndex: number;
|
858 | };
|
859 | /**
|
860 | * Represents multiple activations happening at the same time in an
|
861 | * ActiveList.
|
862 | *
|
863 | * @since 1.0.0
|
864 | */
|
865 | type ActiveListActivatedMultipleEvent<T> = ActiveListBaseEvent & {
|
866 | /**
|
867 | * Which type occurred
|
868 | *
|
869 | * @since 1.0.0
|
870 | */
|
871 | type: 'ACTIVATED_MULTIPLE';
|
872 | /**
|
873 | * The values which were activated.
|
874 | *
|
875 | * Note: these are the values at the time of activation, they might
|
876 | * no longer be accurate. Keep in mind that when the `value` is
|
877 | * an object or an array, they can still be mutated, because no
|
878 | * copy is made.
|
879 | *
|
880 | * @since 1.0.0
|
881 | */
|
882 | values: T[];
|
883 | /**
|
884 | * The indexes of the activated items.
|
885 | *
|
886 | * Note: these are the indexes at the time of the activation, it might
|
887 | * no longer be accurate.
|
888 | *
|
889 | * @since 1.0.0
|
890 | */
|
891 | indexes: number[];
|
892 | /**
|
893 | * The values which were deactivated.
|
894 | *
|
895 | * A deactivation will only happen as part of an activation when
|
896 | * `maxActivationLimit` is set to a `number` and
|
897 | * `maxActivationLimitBehavior` is set to `circular`.
|
898 | *
|
899 | * Note: these are the values at the time of deactivation, they might
|
900 | * no longer be accurate. Keep in mind that when the `value` is
|
901 | * an object or an array, they can still be mutated, because no
|
902 | * copy is made.
|
903 | *
|
904 | * @since 1.5.0
|
905 | */
|
906 | deactivatedValues: T[];
|
907 | /**
|
908 | * The indexes of the deactivated items.
|
909 | *
|
910 | * A deactivation will only happen as part of an activation when
|
911 | * `maxActivationLimit` is set to a `number` and
|
912 | * `maxActivationLimitBehavior` is set to `circular`.
|
913 | *
|
914 | * Note: these are the indexes at the time of the deactivation, it might
|
915 | * no longer be accurate.
|
916 | *
|
917 | * @since 1.5.0
|
918 | */
|
919 | deactivatedIndexes: number[];
|
920 | };
|
921 | /**
|
922 | * Represents a deactivation of an ActiveList.
|
923 | *
|
924 | * IMPORTANT: this event is only fired as a result of a direct
|
925 | * deactivation call. So not when activating an item also deactivated
|
926 | * an item due to a `maxActivationLimit` being set.
|
927 | *
|
928 | * @since 1.0.0
|
929 | */
|
930 | type ActiveListDeactivatedEvent<T> = ActiveListBaseEvent & {
|
931 | /**
|
932 | * Which type occurred
|
933 | *
|
934 | * @since 1.0.0
|
935 | */
|
936 | type: 'DEACTIVATED';
|
937 | /**
|
938 | * The value which was deactivated.
|
939 | *
|
940 | * Note: this was the value at the time of deactivation, it might
|
941 | * no longer be accurate. Keep in mind that when the `value` is
|
942 | * an object or an array, they can still be mutated, because no
|
943 | * copy is made.
|
944 | *
|
945 | * @since 1.0.0
|
946 | */
|
947 | value: T;
|
948 | /**
|
949 | * The index of the deactivated item.
|
950 | *
|
951 | * Note: this was the index at the time of the deactivation, it might
|
952 | * no longer be accurate.
|
953 | *
|
954 | * @since 1.0.0
|
955 | */
|
956 | index: number;
|
957 | };
|
958 | /**
|
959 | * Represents multiple deactivations happening at the same time in an
|
960 | * ActiveList.
|
961 | *
|
962 | * IMPORTANT: this event is only fired as a result of a direct
|
963 | * deactivation call. So not when activating an item also deactivated
|
964 | * an item due to a `maxActivationLimit` being set.
|
965 | *
|
966 | *
|
967 | * @since 1.0.0
|
968 | */
|
969 | type ActiveListDeactivatedMultipleEvent<T> = ActiveListBaseEvent & {
|
970 | /**
|
971 | * Which type occurred
|
972 | *
|
973 | * @since 1.0.0
|
974 | */
|
975 | type: 'DEACTIVATED_MULTIPLE';
|
976 | /**
|
977 | * The values which were deactivated.
|
978 | *
|
979 | * Note: these are the values at the time of deactivation, they might
|
980 | * no longer be accurate. Keep in mind that when the `value` is
|
981 | * an object or an array, they can still be mutated, because no
|
982 | * copy is made.
|
983 | *
|
984 | * @since 1.0.0
|
985 | */
|
986 | values: T[];
|
987 | /**
|
988 | * The indexes of the deactivated items.
|
989 | *
|
990 | * Note: these are the indexes at the time of the deactivation, it might
|
991 | * no longer be accurate.
|
992 | *
|
993 | * @since 1.0.0
|
994 | */
|
995 | indexes: number[];
|
996 | };
|
997 | /**
|
998 | * Represents an activation of an ActiveList.
|
999 | *
|
1000 | * @since 1.0.0
|
1001 | */
|
1002 | type ActiveListSwappedEvent<T> = ActiveListBaseEvent & {
|
1003 | /**
|
1004 | * Which type occurred
|
1005 | *
|
1006 | * @since 1.0.0
|
1007 | */
|
1008 | type: 'SWAPPED';
|
1009 | /**
|
1010 | * An object containing the value of the items which were swapped.
|
1011 | *
|
1012 | * @since 1.0.0
|
1013 | */
|
1014 | value: {
|
1015 | /**
|
1016 | * The value of the first item which was swapped.
|
1017 | *
|
1018 | * Note: this was the value at the time of the swap, it might
|
1019 | * no longer be accurate. Keep in mind that when the `value` is
|
1020 | * an object or an array, they can still be mutated, because no
|
1021 | * copy is made.
|
1022 | *
|
1023 | * @since 1.0.0
|
1024 | */
|
1025 | a: T;
|
1026 | /**
|
1027 | * The value of the second item which was swapped.
|
1028 | *
|
1029 | * Note: this was the value at the time of the swap, it might
|
1030 | * no longer be accurate. Keep in mind that when the `value` is
|
1031 | * an object or an array, they can still be mutated, because no
|
1032 | * copy is made.
|
1033 | *
|
1034 | * @since 1.0.0
|
1035 | */
|
1036 | b: T;
|
1037 | };
|
1038 | /**
|
1039 | * An object containing the indexes of the items which were swapped.
|
1040 | *
|
1041 | * @since 1.0.0
|
1042 | */
|
1043 | index: {
|
1044 | /**
|
1045 | * The index of the first item before it was swapped.
|
1046 | *
|
1047 | * Note: this was the index at the time of the activation, it might
|
1048 | * no longer be accurate.
|
1049 | *
|
1050 | * @since 1.0.0
|
1051 | */
|
1052 | a: number;
|
1053 | /**
|
1054 | * The index of the second item before it was swapped.
|
1055 | *
|
1056 | * Note: this was the index at the time of the activation, it might
|
1057 | * no longer be accurate.
|
1058 | *
|
1059 | * @since 1.0.0
|
1060 | */
|
1061 | b: number;
|
1062 | };
|
1063 | };
|
1064 | /**
|
1065 | * Represents an activation of an ActiveList.
|
1066 | *
|
1067 | * @since 1.0.0
|
1068 | */
|
1069 | type ActiveListMovedEvent<T> = ActiveListBaseEvent & {
|
1070 | /**
|
1071 | * Which type occurred
|
1072 | *
|
1073 | * @since 1.0.0
|
1074 | */
|
1075 | type: 'MOVED';
|
1076 | /**
|
1077 | * The value which was moved.
|
1078 | *
|
1079 | * Note: this was the value at the time of the move, it might
|
1080 | * no longer be accurate. Keep in mind that when the `value` is
|
1081 | * an object or an array, they can still be mutated, because no
|
1082 | * copy is made.
|
1083 | *
|
1084 | * @since 1.0.0
|
1085 | */
|
1086 | value: T;
|
1087 | /**
|
1088 | * An object containing the "from" and "to" index of the item which
|
1089 | * were moved.
|
1090 | *
|
1091 | * Note: this was the index at the time of the activation, it might
|
1092 | * no longer be accurate.
|
1093 | *
|
1094 | * @since 1.0.0
|
1095 | */
|
1096 | index: {
|
1097 | /**
|
1098 | * The index of the "from" item before it was moved.
|
1099 | *
|
1100 | * Note: this was the index at the time of the activation, it might
|
1101 | * no longer be accurate.
|
1102 | *
|
1103 | * @since 1.0.0
|
1104 | */
|
1105 | from: number;
|
1106 | /**
|
1107 | * The index of the "to" item before it was moved.
|
1108 | *
|
1109 | * Note: this was the index at the time of the activation, it might
|
1110 | * no longer be accurate.
|
1111 | *
|
1112 | * @since 1.0.0
|
1113 | */
|
1114 | to: number;
|
1115 | };
|
1116 | };
|
1117 | /**
|
1118 | * Represents an ActiveList autoPlay being restarted again when it was
|
1119 | * stopped or paused.
|
1120 | *
|
1121 | * Note: this event is not fired when a ActiveList is initialized
|
1122 | * even though this does start the autoPlay.
|
1123 | *
|
1124 | * @since 1.0.0
|
1125 | */
|
1126 | type ActiveListAutoPlayPlayingEvent = ActiveListBaseEvent & {
|
1127 | /**
|
1128 | * Which type occurred
|
1129 | *
|
1130 | * @since 1.0.0
|
1131 | */
|
1132 | type: 'AUTO_PLAY_PLAYING';
|
1133 | };
|
1134 | /**
|
1135 | * Represents an ActiveList autoPlay being paused.
|
1136 | *
|
1137 | * @since 1.0.0
|
1138 | */
|
1139 | type ActiveListAutoPlayPausedEvent = ActiveListBaseEvent & {
|
1140 | /**
|
1141 | * Which type occurred
|
1142 | *
|
1143 | * @since 1.0.0
|
1144 | */
|
1145 | type: 'AUTO_PLAY_PAUSED';
|
1146 | };
|
1147 | /**
|
1148 | * Represents an ActiveList autoPlay being stopped.
|
1149 | *
|
1150 | * Can be fired for four reasons:
|
1151 | *
|
1152 | * 1. The `stop` method on the `ActiveList` is called.
|
1153 | *
|
1154 | * 2. The autoPlay reached the last of the items, which can only
|
1155 | * happen when `isCircular` is `false`.
|
1156 | *
|
1157 | * 3. When all content items are removed when the autoPlay is playing.
|
1158 | * It will then stop automatically since there are no more items.
|
1159 | *
|
1160 | * 4. When no more items are left active, in this case the autoPlay
|
1161 | * will stop as well.
|
1162 | *
|
1163 | * Note: due to reasons 3 and 4 this event can be fired right before
|
1164 | * a 'REMOVED', 'REMOVED_MULTIPLE', 'DEACTIVATED' and
|
1165 | * 'DEACTIVATED_MULTIPLE' event.
|
1166 | *
|
1167 | * @since 1.0.0
|
1168 | */
|
1169 | type ActiveListAutoPlayStoppedEvent = ActiveListBaseEvent & {
|
1170 | /**
|
1171 | * Which type occurred
|
1172 | *
|
1173 | * @since 1.0.0
|
1174 | */
|
1175 | type: 'AUTO_PLAY_STOPPED';
|
1176 | };
|
1177 | /**
|
1178 | * Represents an ActiveList being in a cooldown state, meaning no
|
1179 | * activations or deactivations can occur.
|
1180 | *
|
1181 | * @since 1.0.0
|
1182 | */
|
1183 | type ActiveListCooldownStartedEvent = ActiveListBaseEvent & {
|
1184 | /**
|
1185 | * Which type occurred
|
1186 | *
|
1187 | * @since 1.0.0
|
1188 | */
|
1189 | type: 'COOLDOWN_STARTED';
|
1190 | };
|
1191 | /**
|
1192 | * Represents an ActiveList moving out of the cooldown state, meaning
|
1193 | * all activation and deactivations can occur again.
|
1194 | *
|
1195 | * @since 1.0.0
|
1196 | */
|
1197 | type ActiveListCooldownEndedEvent = ActiveListBaseEvent & {
|
1198 | /**
|
1199 | * Which type occurred
|
1200 | *
|
1201 | * @since 1.0.0
|
1202 | */
|
1203 | type: 'COOLDOWN_ENDED';
|
1204 | };
|
1205 | /**
|
1206 | * A ActiveListEvent represents an event happened in the ActiveList.
|
1207 | * For example the insertion, removal, or activation of a
|
1208 | * ActiveListContent<T>.
|
1209 | *
|
1210 | * @since 1.0.0
|
1211 | */
|
1212 | type ActiveListEvent<T> = ActiveListInitializedEvent<T> | ActiveListInsertedEvent<T> | ActiveListRemovedEvent<T> | ActiveListRemovedMultipleEvent<T> | ActiveListActivatedEvent<T> | ActiveListActivatedMultipleEvent<T> | ActiveListSwappedEvent<T> | ActiveListMovedEvent<T> | ActiveListDeactivatedEvent<T> | ActiveListDeactivatedMultipleEvent<T> | ActiveListAutoPlayPlayingEvent | ActiveListAutoPlayPausedEvent | ActiveListAutoPlayStoppedEvent | ActiveListCooldownStartedEvent | ActiveListCooldownEndedEvent;
|
1213 | /**
|
1214 | * Represents where the action needs to take place for when a
|
1215 | * predicate is provided.
|
1216 | *
|
1217 | * 1. When the mode is 'at', the `ActiveListContent` is inserted to the
|
1218 | * position where the predicate matches. This is the `default`
|
1219 | * mode.
|
1220 | *
|
1221 | * 2. When the mode is 'after', the `ActiveListContent` is inserted to after
|
1222 | * the position where the predicate matches.
|
1223 | *
|
1224 | * 3. When the mode is 'before', the `ActiveListContent` is inserted to
|
1225 | * before the position where the predicate matches.
|
1226 | *
|
1227 | * @since 1.0.0
|
1228 | */
|
1229 | type ActiveListPredicateMode = 'at' | 'before' | 'after';
|
1230 | /**
|
1231 | * Represents options for methods which require predicates.
|
1232 | *
|
1233 | * @since 1.0.0
|
1234 | */
|
1235 | type ActiveListPredicateOptions = {
|
1236 | /**
|
1237 | * Represents where the action needs to take place for when a
|
1238 | * predicate is provided.
|
1239 | *
|
1240 | * Represents where the action needs to take place for when a
|
1241 | * predicate is provided.
|
1242 | *
|
1243 | * 1. When the mode is 'at', the `ActiveListContent` is inserted to the
|
1244 | * position where the predicate matches. This is the `default`
|
1245 | * mode.
|
1246 | *
|
1247 | * 2. When the mode is 'after', the `ActiveListContent` is inserted to after
|
1248 | * the position where the predicate matches.
|
1249 | *
|
1250 | * 3. When the mode is 'before', the `ActiveListContent` is inserted to
|
1251 | * before the position where the predicate matches.
|
1252 | *
|
1253 | * @since 1.0.0
|
1254 | */
|
1255 | mode: ActiveListPredicateMode;
|
1256 | };
|
1257 |
|
1258 | /**
|
1259 | * Represents a piece of content in the `contents` array of the `ActiveList`.
|
1260 | *
|
1261 | * The purpose of the ActiveListContent is to act as a wrapper around the
|
1262 | * value which is actually in the contents array. It knows things like
|
1263 | * whether the item is active or not.
|
1264 | *
|
1265 | * It also contains methods to activate, remove, swap and move itself
|
1266 | * within the ActiveList.
|
1267 | *
|
1268 | * @since 1.0.0
|
1269 | */
|
1270 | declare class ActiveListContent<T> {
|
1271 | /**
|
1272 | * Reference to the ActiveList is it a part of.
|
1273 | *
|
1274 | * @since 1.0.0
|
1275 | */
|
1276 | activeList: ActiveList<T>;
|
1277 | /**
|
1278 | * The index of the `ActiveListContent` which it has within the `contents`.
|
1279 | *
|
1280 | * @since 1.0.0
|
1281 | */
|
1282 | index: number;
|
1283 | /**
|
1284 | * The actual `value` of the `ActiveListContent` it can be whatever the
|
1285 | * developer wants it to be.
|
1286 | *
|
1287 | * @since 1.0.0
|
1288 | */
|
1289 | value: T;
|
1290 | /**
|
1291 | * Whether or not the `ActiveListContent` is currently active.
|
1292 | *
|
1293 | * @since 1.0.0
|
1294 | */
|
1295 | isActive: boolean;
|
1296 | /**
|
1297 | * Whether or not the `ActiveListContent` has been active at least once
|
1298 | * in the past.
|
1299 | *
|
1300 | * @since 1.0.0
|
1301 | */
|
1302 | hasBeenActiveBefore: boolean;
|
1303 | /**
|
1304 | * Whether or not the `ActiveListContent` is considered to be the first
|
1305 | * item in the `contents`.
|
1306 | *
|
1307 | * @since 1.0.0
|
1308 | */
|
1309 | isFirst: boolean;
|
1310 | /**
|
1311 | * Whether or not the `ActiveListContent` is considered to be the last
|
1312 | * item in the `contents`.
|
1313 | *
|
1314 | * @since 1.0.0
|
1315 | */
|
1316 | isLast: boolean;
|
1317 | /**
|
1318 | * Whether this `ActiveListContent` has at least one other `ActiveListContent` coming
|
1319 | * after it in the `contents`
|
1320 | *
|
1321 | * @since 1.0.0
|
1322 | */
|
1323 | hasNext: boolean;
|
1324 | /**
|
1325 | * Whether this `ActiveListContent` has at least one other `ActiveListContent` coming
|
1326 | * before it in the `contents`.
|
1327 | *
|
1328 | * @since 1.0.0
|
1329 | */
|
1330 | hasPrevious: boolean;
|
1331 | /**
|
1332 | * Whether this `ActiveListContent` comes directly after the `ActiveListContent`, in the
|
1333 | * `contents` array, which is currently the `lastActiveList`.
|
1334 | *
|
1335 | * @since 1.0.0
|
1336 | */
|
1337 | isNext: boolean;
|
1338 | /**
|
1339 | * Whether this `ActiveListContent` comes directly before the `ActiveListContent`, in the
|
1340 | * `contents` array, which is currently the `lastActiveList`.
|
1341 | *
|
1342 | * @since 1.0.0
|
1343 | */
|
1344 | isPrevious: boolean;
|
1345 | /**
|
1346 | * Creates an ActiveListContent which belongs to the given ActiveList.
|
1347 | *
|
1348 | * Note: you should never create instances of ActiveListContent yourself. You
|
1349 | * are supposed to let ActiveList do this for you.
|
1350 | *
|
1351 | * @param {ActiveList<T>} activeList The ActiveList this ActiveListContent belongs to.
|
1352 | * @param {number} index The index of this ActiveListContent within the ActiveList.
|
1353 | * @param {T} value The value this ActiveListContent wraps.
|
1354 | *
|
1355 | * @since 1.0.0
|
1356 | */
|
1357 | constructor(activeList: ActiveList<T>, index: number, value: T);
|
1358 | /**
|
1359 | * When calling `activate` it will make this `ActiveListContent` active.
|
1360 | *
|
1361 | * @param {ActiveListActivationOptions<T>} [activationOptions] The activation options ActiveListActivationOptions<T>
|
1362 | *
|
1363 | * 1.0.0
|
1364 | */
|
1365 | activate(activationOptions?: ActiveListActivationOptions<T>): void;
|
1366 | /**
|
1367 | * When calling `deactivate` it will make this `ActiveListContent` inactive.
|
1368 | *
|
1369 | * @param {ActiveListActivationOptions<T>} [activationOptions] The activation options @see ActiveListActivationOptions<T>
|
1370 | *
|
1371 | * @since 1.0.0
|
1372 | */
|
1373 | deactivate(activationOptions?: ActiveListActivationOptions<T>): void;
|
1374 | /**
|
1375 | * When calling `toggle` it will flip the this `ActiveListContent`
|
1376 | * `isActive` state.
|
1377 | *
|
1378 | * So when `isActive` is `true` and `toggle` is called, `isActive`
|
1379 | * will become `false`. When `isActive` is `false` and `toggle` is
|
1380 | * called, `isActive` will become `true`.
|
1381 | *
|
1382 | * With the `activationOptions` you can determine the effects
|
1383 | * on `cooldown` and `autoPlay`.
|
1384 | *
|
1385 | * @param {ActiveListActivationOptions<T>} [activationOptions] The activation options @see ActiveListActivationOptions<T>
|
1386 | *
|
1387 | * @since 1.0.0
|
1388 | */
|
1389 | toggle(activationOptions?: ActiveListActivationOptions<T>): void;
|
1390 | /**
|
1391 | * When calling `remove` it will remove this `ActiveListContent`, and return
|
1392 | * the `value` the ActiveListContent held.
|
1393 | *
|
1394 | * @returns {T} The removed value
|
1395 | *
|
1396 | * @since 1.0.0
|
1397 | */
|
1398 | remove(): T;
|
1399 | /**
|
1400 | * Swaps the `ActiveListContent` with the `ActiveListContent` at the given index.
|
1401 | *
|
1402 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
1403 | * it will only get a new position.
|
1404 | *
|
1405 | * @param {number} index The index to swap the current `ActiveListContent` with.
|
1406 | * @throws {ActiveListItemNotFoundError} Item not found error
|
1407 | *
|
1408 | * @since 1.0.0
|
1409 | */
|
1410 | swapWith(item: T): void;
|
1411 | /**
|
1412 | * Swaps the `ActiveListContent` with the `ActiveListContent` at the given index.
|
1413 | *
|
1414 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
1415 | * it will only get a new position.
|
1416 | *
|
1417 | * @param {number} index] The index to swap the current `ActiveListContent` with.
|
1418 | * @throws {ActiveListIndexOutOfBoundsError} Index out of bounds error.
|
1419 | *
|
1420 | * @since 1.0.0
|
1421 | */
|
1422 | swapWithByIndex(index: number): void;
|
1423 | /**
|
1424 | * Swaps the `ActiveListContent` with the next `ActiveListContent` in the sequence.
|
1425 | *
|
1426 | * If `isCircular` of the `ActiveList` is `true` swapping whilst on
|
1427 | * the last index will make this `ActiveListContent` swap with the
|
1428 | * first index. If `isCircular` is `false` it will do nothing,
|
1429 | * and keep the `ActiveListContent` on the last index.
|
1430 | *
|
1431 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
1432 | * it will only get a new position.
|
1433 | *
|
1434 | * @since 1.0.0
|
1435 | */
|
1436 | swapWithNext(): void;
|
1437 | /**
|
1438 | * Swaps the `ActiveListContent` with the previous `ActiveListContent` in the sequence.
|
1439 | *
|
1440 | * If `isCircular` of the `ActiveList` is `true` swapping whilst on
|
1441 | * the first index will make this `ActiveListContent` swap with the
|
1442 | * last index. If `isCircular` is `false` it will do nothing,
|
1443 | * and keep the `ActiveListContent` on the first index.
|
1444 | *
|
1445 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
1446 | * it will only get a new position.
|
1447 | *
|
1448 | * @since 1.0.0
|
1449 | */
|
1450 | swapWithPrevious(): void;
|
1451 | /**
|
1452 | * Moves the `ActiveListContent` to the position at index "to".
|
1453 | *
|
1454 | * It is possible to move the `ActiveListContent` to the last place by making
|
1455 | * the "to" index the length of the `contents` array.
|
1456 | *
|
1457 | * Note: if the active `ActiveListContent` is moved it will stay active,
|
1458 | * meaning that the activeIndex will get updated.
|
1459 | *
|
1460 | * @param {number} to The location the `from` needs to move "to".
|
1461 | * @throws {ActiveListIndexOutOfBoundsError} Index out of bounds error.
|
1462 | *
|
1463 | * @since 1.0.0
|
1464 | */
|
1465 | moveToIndex(to: number): void;
|
1466 | /**
|
1467 | * Moves the `ActiveListContent` to the position of the item for which
|
1468 | * the predicate returns `true`.
|
1469 | *
|
1470 | * If no item matches the predicate nothing is moved.
|
1471 | *
|
1472 | * The position to where the `ActiveListContent` is inserted can be altered by
|
1473 | * providing a mode:
|
1474 | *
|
1475 | * 1. When the mode is 'at', the `ActiveListContent` is inserted to the
|
1476 | * position where the predicate matches. This is the `default`
|
1477 | * mode.
|
1478 | *
|
1479 | * 2. When the mode is 'after', the `ActiveListContent` is inserted to after
|
1480 | * the position where the predicate matches.
|
1481 | *
|
1482 | * 3. When the mode is 'before', the `ActiveListContent` is inserted to
|
1483 | * before the position where the predicate matches.
|
1484 | *
|
1485 | * @param {ActiveListContentPredicate<T>} predicate The predicate function which when `true` is returned moves the item to after that position.
|
1486 | * @param {ActiveListPredicateOptions} options The options for the predicate, when no options are provided the mode will default to "at".
|
1487 | *
|
1488 | * @since 1.0.0
|
1489 | */
|
1490 | moveToPredicate(predicate: ActiveListContentPredicate<T>, options?: ActiveListPredicateOptions): void;
|
1491 | /**
|
1492 | * Moves the `ActiveListContent` to the first position in the contents array.
|
1493 | *
|
1494 | * Note: if the active `ActiveListContent` is moved it will stay active,
|
1495 | * meaning that the activeIndex will get updated.
|
1496 | *
|
1497 | * @since 1.0.0
|
1498 | */
|
1499 | moveToFirst(): void;
|
1500 | /**
|
1501 | * Moves the `ActiveListContent` to the last position in the contents array.
|
1502 | *
|
1503 | * Note: if the active `ActiveListContent` is moved it will stay active,
|
1504 | * meaning that the activeIndex will get updated.
|
1505 | *
|
1506 | * @since 1.0.0
|
1507 | */
|
1508 | moveToLast(): void;
|
1509 | }
|
1510 |
|
1511 | /**
|
1512 | * ActiveList is a class which represents visual elements which
|
1513 | * have multiple pieces of content which can be active or inactive.
|
1514 | *
|
1515 | * The `ActiveList` can be used to implement multiple types of
|
1516 | * components:
|
1517 | *
|
1518 | * 1. A tabs component for which one tab can be active at a time.
|
1519 | *
|
1520 | * 2. A carrousel component: the user sees single slide, which will
|
1521 | * autoPlay to the next slide automatically.
|
1522 | *
|
1523 | * 3. A dropdown menu with one active menu item.
|
1524 | *
|
1525 | * 4. A accordion component from which the user can open multiple
|
1526 | * items at once.
|
1527 | *
|
1528 | * 5. A list the user can sort and move around.
|
1529 | *
|
1530 | * 6. Etc etc
|
1531 | *
|
1532 | * Another way of defining the ActiveList is that it is an array
|
1533 | * / list like data structure, because it supports things like
|
1534 | * insertion and removal.
|
1535 | *
|
1536 | * ActiveList will make sure that when content is inserted, that
|
1537 | * the active content is not affected.
|
1538 | *
|
1539 | * @since 1.0.0
|
1540 | */
|
1541 | declare class ActiveList<T> implements Observable<ActiveList<T>, ActiveListEvent<T>> {
|
1542 | /**
|
1543 | * Whether or not to inform subscribers of changes / record history.
|
1544 | * Used in the `initialize` to temporarily stop subscriptions running
|
1545 | * the initial activation, and altering the history.
|
1546 | */
|
1547 | private _isInitializing;
|
1548 | /**
|
1549 | * The `ActiveListContent` instances which the `ActiveList` holds.
|
1550 | *
|
1551 | * @since 1.0.0
|
1552 | */
|
1553 | readonly contents: ActiveListContent<T>[];
|
1554 | /**
|
1555 | * How many items can be active at the same time.
|
1556 | *
|
1557 | * When the value of `limit` is `false` there is no limit to the
|
1558 | * number of active items.
|
1559 | *
|
1560 | * Defaults to 1.
|
1561 | *
|
1562 | * @since 1.0.0
|
1563 | */
|
1564 | maxActivationLimit: number | false;
|
1565 | /**
|
1566 | * How the `maxActivationLimit` is enforced. In other words what the
|
1567 | * behavior should be when the limit is surpassed.
|
1568 | *
|
1569 | * The modes are strings which can be the following values:
|
1570 | *
|
1571 | * 1. 'circular': the first item which was added will be removed so
|
1572 | * the last item can be added without violating the limit. This
|
1573 | * basically means that the first one in is the first one out.
|
1574 | *
|
1575 | * 2. 'error': An error is thrown whenever the limit is surpassed,
|
1576 | * the error is called the `ActiveListActivationLimitReachedError`.
|
1577 | *
|
1578 | * 3. 'ignore': Nothing happens when an item is added and the limit
|
1579 | * is reached. The item is simply not added, but no error is
|
1580 | * thrown.
|
1581 | *
|
1582 | * Defaults to 'circular'.
|
1583 | *
|
1584 | * @since 1.0.0
|
1585 | */
|
1586 | maxActivationLimitBehavior: ActiveListMaxActivationLimitBehavior;
|
1587 | /**
|
1588 | * All `value` of the content which are currently considered active.
|
1589 | *
|
1590 | * @since 1.0.0
|
1591 | */
|
1592 | readonly active: T[];
|
1593 | /**
|
1594 | * All `ActiveListContent` which are currently considered active.
|
1595 | *
|
1596 | * @since 1.0.0
|
1597 | */
|
1598 | readonly activeContents: ActiveListContent<T>[];
|
1599 | /**
|
1600 | * All indexes of which are currently considered active.
|
1601 | *
|
1602 | * @since 1.0.0
|
1603 | */
|
1604 | readonly activeIndexes: number[];
|
1605 | /**
|
1606 | * Which `value` from within an `ActiveListContent` was the last
|
1607 | * value which was activated.
|
1608 | *
|
1609 | * In other words: of all active values which value was activated
|
1610 | * the last chronologically.
|
1611 | *
|
1612 | * When nothing is activated in the `ActiveList` the value of
|
1613 | * `lastActivated` will be `null`.
|
1614 | *
|
1615 | * @since 1.0.0
|
1616 | */
|
1617 | lastActivated: T | null;
|
1618 | /**
|
1619 | * Which `ActiveListContent` is the last ActiveListContent which
|
1620 | * was activated.
|
1621 | *
|
1622 | * In other words: of all active contents which content was
|
1623 | * activated the last chronologically.
|
1624 | *
|
1625 | * When nothing is activated in the `ActiveList` the value of
|
1626 | * `lastActivatedContent` will be `null`.
|
1627 | *
|
1628 | * @since 1.0.0
|
1629 | */
|
1630 | lastActivatedContent: ActiveListContent<T> | null;
|
1631 | /**
|
1632 | * Which index of the `contents` array was the last index which
|
1633 | * was activated.
|
1634 | *
|
1635 | * In other words: of all active indexes which index was activated
|
1636 | * the last chronologically.
|
1637 | *
|
1638 | * When nothing is activated in the `ActiveList` the value of
|
1639 | * `lastActivatedIndex` will be `-1`.
|
1640 | *
|
1641 | * @since 1.0.0
|
1642 | */
|
1643 | lastActivatedIndex: number;
|
1644 | /**
|
1645 | * Which `value` from within an `ActiveListContent` was the last
|
1646 | * value which was deactivated.
|
1647 | *
|
1648 | * When nothing was deactivated previously in the `ActiveList` the
|
1649 | * value of `lastDeactivated` will be `null`.
|
1650 | *
|
1651 | * @since 1.5.0
|
1652 | */
|
1653 | lastDeactivated: T | null;
|
1654 | /**
|
1655 | * Which `ActiveListContent` is the last ActiveListContent which
|
1656 | * was deactivated.
|
1657 | *
|
1658 | * When nothing was deactivated previously in the `ActiveList` the
|
1659 | * value of `lastDeactivatedContent` will be `null`.
|
1660 | *
|
1661 | * @since 1.5.0
|
1662 | */
|
1663 | lastDeactivatedContent: ActiveListContent<T> | null;
|
1664 | /**
|
1665 | * Which index of the `contents` array was the last index which
|
1666 | * was deactivated.
|
1667 | *
|
1668 | * When nothing was deactivated previously in the `ActiveList` the
|
1669 | * value of `lastDeactivatedIndex` will be `-1`.
|
1670 | *
|
1671 | * @since 1.5.0
|
1672 | */
|
1673 | lastDeactivatedIndex: number;
|
1674 | /**
|
1675 | * Whether or not the content starts back at the beginning when
|
1676 | * the end of the content is reached, and whether the content should
|
1677 | * go to the end when moving left of the start.
|
1678 | *
|
1679 | * Defaults to `false`.
|
1680 | *
|
1681 | * @since 1.0.0
|
1682 | */
|
1683 | isCircular: boolean;
|
1684 | /**
|
1685 | * The direction the `ActiveList` has previously moved to on
|
1686 | * activation or deactivation.
|
1687 | *
|
1688 | * Useful for when animating the `ActiveList` when wanting to
|
1689 | * animate differently based on the direction the content is
|
1690 | * activating towards.
|
1691 | *
|
1692 | * The direction is determined using the following rules for
|
1693 | * activation:
|
1694 | *
|
1695 | * 1. When `isCircular` is `false`:
|
1696 | *
|
1697 | * a. If the `lastActivatedIndex` is -1 the direction is always `next`.
|
1698 | * The `lastActivatedIndex` is -1 when no item is active.
|
1699 | *
|
1700 | * b. If the `lastActivatedIndex` lies before the activated index the
|
1701 | * direction is `next`.
|
1702 | *
|
1703 | * c. If the `lastActivatedIndex` lies after the activated index the
|
1704 | * direction is `previous`.
|
1705 | *
|
1706 | * 2. When `isCircular` is `true`,
|
1707 | *
|
1708 | * a. If the `lastActivatedIndex` is -1 the direction is always `next`.
|
1709 | * The `lastActivatedIndex` is -1 when no item is active.
|
1710 | *
|
1711 | * b. The direction is determined by checking which direction
|
1712 | * is the shortest path. If the shortest paths are tied, the
|
1713 | * direction will become `next`.
|
1714 | *
|
1715 | * Note: the direction is only changed upon activation and
|
1716 | * deactivation. Removing / inserting, moving and swapping do not
|
1717 | * affect the direction.
|
1718 | *
|
1719 | * Defaults to the value of the `Config` property `direction.next`.
|
1720 | *
|
1721 | * @since 1.0.0
|
1722 | */
|
1723 | direction: string;
|
1724 | /**
|
1725 | * The opposite of the `direction` property of the `ActiveList`.
|
1726 | * If the `direction` is `next` the opposite direction is always
|
1727 | * `previous` and vice versa.
|
1728 | *
|
1729 | * Defaults to the value of the `Config` property `direction.previous`.
|
1730 | *
|
1731 | * @since 1.5.0
|
1732 | */
|
1733 | oppositeDirection: string;
|
1734 | private _history;
|
1735 | /**
|
1736 | * Contains the history of the changes in the contents array.
|
1737 | *
|
1738 | * Tracks 15 types of changes:
|
1739 | *
|
1740 | * 1. INITIALIZED: fired when ActiveList is initialized.
|
1741 | *
|
1742 | * 2. INSERTED: fired when an item is added.
|
1743 | *
|
1744 | * 3. REMOVED: fired when an item is removed.
|
1745 | *
|
1746 | * 4. REMOVED_MULTIPLE: fired when multiple items are removed with a predicate.
|
1747 | *
|
1748 | * 5. ACTIVATED: fired when an item is activated.
|
1749 | *
|
1750 | * 6 ACTIVATED_MULTIPLE: fired when multiple items are activated with a predicate.
|
1751 | *
|
1752 | * 7. DEACTIVATED: fired when an item is deactivated.
|
1753 | *
|
1754 | * 8. DEACTIVATED_MULTIPLE: fired when multiple items are deactivated with a predicate.
|
1755 | *
|
1756 | * 9. SWAPPED: fired when an item is swapped.
|
1757 | *
|
1758 | * 10. MOVED: fired when an item is moved.
|
1759 | *
|
1760 | * 11. AUTO_PLAY_PLAYING: fired when play is called.
|
1761 | *
|
1762 | * 12. AUTO_PLAY_PAUSED: fired when pause is called.
|
1763 | *
|
1764 | * 13. AUTO_PLAY_STOPPED: fired when stop is called, or the autoPlay stops due to a condition.
|
1765 | *
|
1766 | * 14. COOLDOWN_STARTED: fired when ActiveList goes into cooldown state
|
1767 | *
|
1768 | * 15. COOLDOWN_ENDED: fired when ActiveList goes out of cooldown state
|
1769 | *
|
1770 | * Goes only as far back as configured in the `Config` property
|
1771 | * `keepHistoryFor`, to prevent an infinitely growing history.
|
1772 | * Note that by default no history is kept, as `keepHistoryFor`
|
1773 | * is zero by default.
|
1774 | *
|
1775 | * The last item in the `history` is the current active item. The
|
1776 | * further to the left the further in the past you go.
|
1777 | *
|
1778 | * This means that a history at index 0 is further in the past than
|
1779 | * an item at index 1.
|
1780 | *
|
1781 | * WARNING: all events store indexes, values and combinations thereof.
|
1782 | * The `index` of an item in the history may no longer be accurate, it
|
1783 | * is the index at the time of the event. Same goes for the `value`
|
1784 | * when it is an array of object, as it might have been mutated, the
|
1785 | * history items do not store copies of the values.
|
1786 | *
|
1787 | * @since 1.0.0
|
1788 | */
|
1789 | readonly history: ActiveListEvent<T>[];
|
1790 | private _observer;
|
1791 | /**
|
1792 | * Whether or not the `active` item has changed at least once.
|
1793 | * Useful when you want to know if the `ActiveList` is still
|
1794 | * in its initial state.
|
1795 | *
|
1796 | * Note: when the `initialize` method of the `Actions` is called this
|
1797 | * boolean is reset.
|
1798 | *
|
1799 | * @since 1.0.0
|
1800 | */
|
1801 | hasActiveChangedAtLeastOnce: boolean;
|
1802 | private _activationCooldownTimer;
|
1803 | /**
|
1804 | * A Cooldown is a time period in which all user made activations
|
1805 | * and deactivations are prevented / ignored. Activations and
|
1806 | * deactivations where the `isUserInteraction` is set to `false`
|
1807 | * always bypass the cooldown.
|
1808 | *
|
1809 | * The use-case is a cooldown can guarantees that animations are
|
1810 | * completed, before another is triggered.
|
1811 | *
|
1812 | * Contains whether or not the cooldown is active via `isActive` and
|
1813 | * the current duration via `duration`.
|
1814 | *
|
1815 | * @since 1.0.0
|
1816 | */
|
1817 | readonly cooldown: ActiveListCooldown;
|
1818 | private _autoPlay;
|
1819 | /**
|
1820 | * AutoPlay means that the ActiveList will move to the next content by
|
1821 | * itself after a duration.
|
1822 | *
|
1823 | * Contains whether or not the autoPlay is playing via `isPlaying`,
|
1824 | * the current duration via `duration`, and whether or not the
|
1825 | * autoPlay has been stopped before via `hasBeenStoppedBefore`
|
1826 | *
|
1827 | * @since 1.0.0
|
1828 | */
|
1829 | readonly autoPlay: ActiveListAutoPlay;
|
1830 | private _directions;
|
1831 | /**
|
1832 | * Creates an ActiveList based on the ActiveListConfig config.
|
1833 | *
|
1834 | * You can also optionally provide an subscriber so you can get
|
1835 | * informed of the changes happening to the ActiveList.
|
1836 | *
|
1837 | * @param {ActiveListConfig<T>} config The initial configuration of the ActiveList.
|
1838 | * @param {ActiveListSubscriber<T> | undefined} subscriber An optional subscriber which responds to changes in the ActiveList.
|
1839 | * @throws {ActiveListAutoPlayDurationError} autoPlay duration must be a positive number when defined
|
1840 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1841 | * @since 1.0.0
|
1842 | */
|
1843 | constructor(config?: ActiveListConfig<T>, subscriber?: ActiveListSubscriber<T>);
|
1844 | /**
|
1845 | * Subscribe to changes of the ActiveList. The function you
|
1846 | * provide will get called whenever changes occur in the
|
1847 | * ActiveList.
|
1848 | *
|
1849 | * Returns an unsubscribe function which when called will unsubscribe
|
1850 | * from the ActiveList.
|
1851 | *
|
1852 | * @param {ActiveListSubscriber<T>} subscriber The subscriber which responds to changes in the ActiveList.
|
1853 | * function which when called will unsubscribe from the ActiveList.
{UnsubscribeFunction} A |
1854 | *
|
1855 | * @since 1.0.0
|
1856 | */
|
1857 | subscribe(subscriber: ActiveListSubscriber<T>): UnsubscribeFunction;
|
1858 | /**
|
1859 | * Unsubscribe the subscriber so it no longer receives changes / updates
|
1860 | * of the state changes of the ActiveList.
|
1861 | *
|
1862 | * @param {ActiveListSubscriber<T>} subscriber The subscriber which you want to unsubscribe.
|
1863 | *
|
1864 | * @since 1.0.0
|
1865 | */
|
1866 | unsubscribe(subscriber: ActiveListSubscriber<T>): void;
|
1867 | /**
|
1868 | * Unsubscribes all subscribers at once, all subscribers will no
|
1869 | * longer receives changes / updates of the state changes of
|
1870 | * the ActiveList.
|
1871 | *
|
1872 | * @since 1.5.0
|
1873 | */
|
1874 | unsubscribeAll(): void;
|
1875 | /**
|
1876 | * Initializes the ActiveList based on the config provided. This can
|
1877 | * effectively reset the ActiveList when called, including the
|
1878 | * history, autoPlay and cooldown.
|
1879 | *
|
1880 | * @param {ActiveListConfig<T>} config The new configuration which will override the old one
|
1881 | * @throws {ActiveListAutoPlayDurationError} autoPlay duration must be a positive number when defined
|
1882 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1883 | * @since 1.0.0
|
1884 | */
|
1885 | initialize(config: ActiveListConfig<T>): void;
|
1886 | private _initializeABrokenContent;
|
1887 | /**
|
1888 | * Activates an item based on the index in the content array.
|
1889 | *
|
1890 | * If the index does not exist an error will be thrown.
|
1891 | *
|
1892 | * With the `activationOptions` you can determine the effects
|
1893 | * on `cooldown` and `autoPlay`.
|
1894 | *
|
1895 | * @param {number} index The index to activate
|
1896 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
1897 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
1898 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1899 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
1900 | *
|
1901 | * @since 1.0.0
|
1902 | */
|
1903 | activateByIndex(index: number, activationOptions?: ActiveListActivationOptions<T>): void;
|
1904 | private _doActivateByIndex;
|
1905 | /**
|
1906 | * Activates the given item based on identity by comparing the item
|
1907 | * via a `===` check. When multiple items match on `===` only the
|
1908 | * first matching item is activated.
|
1909 | *
|
1910 | * If the item does not exist in the content array it will
|
1911 | * throw an error.
|
1912 | *
|
1913 | * With the `activationOptions` you can determine the effects
|
1914 | * on `cooldown` and `autoPlay`.
|
1915 | *
|
1916 | * @param {T} item The item to activate
|
1917 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
1918 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
1919 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1920 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
1921 | *
|
1922 | * @since 1.0.0
|
1923 | */
|
1924 | activate(item: T, activationOptions?: ActiveListActivationOptions<T>): void;
|
1925 | /**
|
1926 | * Activates all items that match the predicate.
|
1927 | *
|
1928 | * If no items match the predicate nothing happens.
|
1929 | *
|
1930 | * If multiple items were activated as a result of calling
|
1931 | * `activateByPredicate` they will be activated in order of
|
1932 | * appearance in the contents array.
|
1933 | *
|
1934 | * Items can also be deactivated if the `maxActivationLimit` is set
|
1935 | * to a number and the `maxActivationLimitBehavior` is set to
|
1936 | * "circular", if space needs to be made for the new activations.
|
1937 | *
|
1938 | * When `maxActivationLimitBehavior` is set to "error", all items
|
1939 | * that can be accommodated are activated, but when the limit is
|
1940 | * exceeded the activation stops. The subscribers are then informed
|
1941 | * of which items were activated, and then the error is thrown.
|
1942 | *
|
1943 | * Even through each item is activated sequentially, only one event
|
1944 | * is emitted, and one call is made to the subscribers, even if
|
1945 | * multiple items are activated and deactivated.
|
1946 | *
|
1947 | * Within the `ActiveListActivatedMultipleEvent` only the end
|
1948 | * activate / deactivate results are reported.
|
1949 | *
|
1950 | * With the `activationOptions` you can determine the effects
|
1951 | * on `cooldown` and `autoPlay`. When the cooldown is configured
|
1952 | * as a function, the last activated content will be the parameter
|
1953 | * to the cooldown function.
|
1954 | *
|
1955 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will activate that item.
|
1956 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
1957 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1958 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
1959 | *
|
1960 | * @since 1.0.0
|
1961 | */
|
1962 | activateByPredicate(predicate: ActiveListContentPredicate<T>, activationOptions?: ActiveListActivationOptions<T>): void;
|
1963 | /**
|
1964 | * Activates the next item in the sequence based on the `lastActivated`
|
1965 | * ActiveListContent.
|
1966 | *
|
1967 | * If no `lastActivated` is present when `activateNext` is called
|
1968 | * the first element is activated.
|
1969 | *
|
1970 | * If the `contents` are empty when `activateNext` is called
|
1971 | * nothing will happen.
|
1972 | *
|
1973 | * When on the last position: if `isCircular` is `true` it will circle
|
1974 | * around and activate the first position. When `isCircular` is `false`
|
1975 | * it will stay on the last position and do nothing.
|
1976 | *
|
1977 | * With the `activationOptions` you can determine the effects
|
1978 | * on `cooldown` and `autoPlay`.
|
1979 | *
|
1980 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
1981 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
1982 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
1983 | *
|
1984 | * @since 1.0.0
|
1985 | */
|
1986 | activateNext(activationOptions?: ActiveListActivationOptions<T>): void;
|
1987 | /**
|
1988 | * Activates the previous item in the sequence based on the
|
1989 | * `lastActivated` ActiveListContent.
|
1990 | *
|
1991 | * If no `lastActivated` is present when `activatePrevious` is called
|
1992 | * the first element is activated.
|
1993 | *
|
1994 | * If the `contents` are empty when `activatePrevious` is called
|
1995 | * nothing will happen.
|
1996 | *
|
1997 | * When on the first position: if `isCircular` is `true` it will circle
|
1998 | * around and activate the last position. When `isCircular` is `false`
|
1999 | * it will stay on the first position and do nothing.
|
2000 | *
|
2001 | * With the `activationOptions` you can determine the effects
|
2002 | * on `cooldown` and `autoPlay`.
|
2003 | *
|
2004 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2005 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
2006 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2007 | *
|
2008 | * @since 1.0.0
|
2009 | */
|
2010 | activatePrevious(activationOptions?: ActiveListActivationOptions<T>): void;
|
2011 | /**
|
2012 | * Activates the first item of the contents.
|
2013 | *
|
2014 | * If the `contents` are empty when `activateFirst` is called
|
2015 | * nothing will happen.
|
2016 | *
|
2017 | * With the `activationOptions` you can determine the effects
|
2018 | * on `cooldown` and `autoPlay`.
|
2019 | *
|
2020 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2021 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
2022 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2023 | *
|
2024 | * @since 1.0.0
|
2025 | */
|
2026 | activateFirst(activationOptions?: ActiveListActivationOptions<T>): void;
|
2027 | /**
|
2028 | * Activates the last item of the contents.
|
2029 | *
|
2030 | * If the `contents` are empty when `activateLast` is called
|
2031 | * nothing will happen.
|
2032 | *
|
2033 | * With the `activationOptions` you can determine the effects
|
2034 | * on `cooldown` and `autoPlay`.
|
2035 | *
|
2036 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2037 | * @throws {ActiveListActivationLimitReachedError} thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".
|
2038 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2039 | *
|
2040 | * @since 1.0.0
|
2041 | */
|
2042 | activateLast(activationOptions?: ActiveListActivationOptions<T>): void;
|
2043 | /**
|
2044 | * Deactivates an item based on the index in the content array.
|
2045 | *
|
2046 | * If the index does not exist an error will be thrown.
|
2047 | *
|
2048 | * With the `activationOptions` you can determine the effects
|
2049 | * on `cooldown` and `autoPlay`.
|
2050 | *
|
2051 | * @param {number} index The index to deactivate
|
2052 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2053 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2054 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2055 | *
|
2056 | * @since 1.0.0
|
2057 | */
|
2058 | deactivateByIndex(index: number, activationOptions?: ActiveListActivationOptions<T>): void;
|
2059 | private _doDeactivateByIndex;
|
2060 | /**
|
2061 | * Deactivates the given item based on identity by comparing the item
|
2062 | * via a `===` check. When multiple items match on `===` only the
|
2063 | * first matching item is activated.
|
2064 | *
|
2065 | * If the item does not exist in the content array it will
|
2066 | * throw an error.
|
2067 | *
|
2068 | * With the `activationOptions` you can determine the effects
|
2069 | * on `cooldown` and `autoPlay`.
|
2070 | *
|
2071 | * @param {T} item The item to deactivate
|
2072 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2073 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2074 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2075 | *
|
2076 | * @since 1.0.0
|
2077 | */
|
2078 | deactivate(item: T, activationOptions?: ActiveListActivationOptions<T>): void;
|
2079 | /**
|
2080 | * Deactivates all items that match the predicate.
|
2081 | *
|
2082 | * If no items match the predicate nothing happens.
|
2083 | *
|
2084 | * If multiple items match they will be deactivated in order of
|
2085 | * appearance in the contents array. Only one call is made to the
|
2086 | * subscribers, even if multiple items are deactivated.
|
2087 | *
|
2088 | * With the `activationOptions` you can determine the effects
|
2089 | * on `cooldown` and `autoPlay`. When the cooldown is configured
|
2090 | * as a function, the last deactivated content will be the parameter
|
2091 | * to the cooldown function.
|
2092 | *
|
2093 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will deactivate that item.
|
2094 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2095 | * @throws {ActiveListCooldownDurationError} cooldown duration must be a positive number when defined
|
2096 | *
|
2097 | * @since 1.0.0
|
2098 | */
|
2099 | deactivateByPredicate(predicate: ActiveListContentPredicate<T>, activationOptions?: ActiveListActivationOptions<T>): void;
|
2100 | /**
|
2101 | * When calling `toggleByIndex` it will flip the `ActiveListContent`
|
2102 | * which resides on the index `isActive` state .
|
2103 | *
|
2104 | * So when `isActive` is `true` and `toggle` is called, `isActive`
|
2105 | * will become `false`. When `isActive` is `false` and `toggle` is
|
2106 | * called, `isActive` will become `true`.
|
2107 | *
|
2108 | * If the index does not exist an error will be thrown.
|
2109 | *
|
2110 | * With the `activationOptions` you can determine the effects
|
2111 | * on `cooldown` and `autoPlay`.
|
2112 | *
|
2113 | * @param {number} index The index to activate
|
2114 | * @param {ActiveListActivationOptions<T>} [activationOptions] The activation options
|
2115 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2116 | *
|
2117 | * @since 1.0.0
|
2118 | */
|
2119 | toggleByIndex(index: number, activationOptions?: ActiveListActivationOptions<T>): void;
|
2120 | /**
|
2121 | * Toggles the given item based on identity by comparing the item
|
2122 | * via a `===` check. When multiple items match on `===` only the
|
2123 | * first matching item is activated.
|
2124 | *
|
2125 | * So when `isActive` is `true` and `toggle` is called, `isActive`
|
2126 | * will become `false`. When `isActive` is `false` and `toggle` is
|
2127 | * called, `isActive` will become `true`.
|
2128 | *
|
2129 | * If the item does not exist in the content array it will
|
2130 | * throw an error.
|
2131 | *
|
2132 | * With the `activationOptions` you can determine the effects
|
2133 | * on `cooldown` and `autoPlay`.
|
2134 | *
|
2135 | * @param {T} item The item to toggle
|
2136 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2137 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2138 | *
|
2139 | * @since 1.0.0
|
2140 | */
|
2141 | toggle(item: T, activationOptions?: ActiveListActivationOptions<T>): void;
|
2142 | /**
|
2143 | * Will start playing the ActiveList based on the active
|
2144 | * autoPlayConfig. When `autoPlayConfig` is not defined nothing
|
2145 | * will happen when calling play.
|
2146 | *
|
2147 | * When there is no more content the playing will stop automatically.
|
2148 | *
|
2149 | * Note: autoPlay will only start when one or more contents are
|
2150 | * currently active. The reason for this is that the `duration`, is
|
2151 | * based on the `ActiveList` `lastActivatedContent` property.
|
2152 | * Whenever there are no more items to activate the autoPlay will
|
2153 | * stop.
|
2154 | *
|
2155 | * @throws {ActiveListAutoPlayDurationError} autoPlay duration must be a positive number when defined
|
2156 | *
|
2157 | * @since 1.0.0
|
2158 | */
|
2159 | play(): void;
|
2160 | /**
|
2161 | * When the ActiveList is playing it will pause the autoPlay.
|
2162 | *
|
2163 | * When paused, the current autoPlay duration is remember and resumed
|
2164 | * from that position, when `play` is called again.
|
2165 | *
|
2166 | * For example: when the duration is 1 second and the `pause` is
|
2167 | * called after 0.8 seconds, it will after `play` is called, take
|
2168 | * 0.2 seconds to go to the next content.
|
2169 | *
|
2170 | * Note: if the autoPlay is already paused calling `pause` again
|
2171 | * will do nothing, the time used for the remaining duration is
|
2172 | * based on the first pause.
|
2173 | *
|
2174 | * @since 1.0.0
|
2175 | */
|
2176 | pause(): void;
|
2177 | /**
|
2178 | * When the ActiveList is playing it will stop the autoPlay.
|
2179 | *
|
2180 | * By calling `play` again it is possible to restart the autoPlay.
|
2181 | * However the duration will behave in this scenario as it if was
|
2182 | * reset.
|
2183 | *
|
2184 | * For example: when the duration is 1 second and the `stop` is
|
2185 | * called after 0.8 seconds, it will after `play` is called, take
|
2186 | * 1 second to go to the next content.
|
2187 | *
|
2188 | * @since 1.0.0
|
2189 | */
|
2190 | stop(): void;
|
2191 | /**
|
2192 | * Configures the autoPlay, when the autoPlay is `null` the autoPlay
|
2193 | * is stopped.
|
2194 | *
|
2195 | * Can be used to reconfigure the speed of the autoPlay after the
|
2196 | * ActiveList has been created.
|
2197 | *
|
2198 | * Note: calling `configureAutoPlay` will not set (reset) the
|
2199 | * hasBeenStoppedBefore` to `false` when called.
|
2200 | *
|
2201 | * @param {ActiveListAutoPlayConfig<T> | null} autoPlayConfig The new autoPlay configuration
|
2202 | * @throws {ActiveListAutoPlayDurationError} autoPlay duration must be a positive number when defined
|
2203 | *
|
2204 | * @since 1.0.0
|
2205 | */
|
2206 | configureAutoPlay(autoPlayConfig: ActiveListAutoPlayConfig<T> | null): void;
|
2207 | /**
|
2208 | * Will add an item to the `contents` array, at the specified `index`.
|
2209 | *
|
2210 | * Note: `insertAtIndex` will not allow holes to be created, this
|
2211 | * means that the index can only be between `0` and `contents.length`.
|
2212 | * If you give it a larger or smaller index it will throw an error.
|
2213 | *
|
2214 | * @param {T} item The item to insert.
|
2215 | * @param {number} index The index at which to insert the item.
|
2216 | * @returns {ActiveListContent<T>} The newly inserted item wrapped in an `ActiveListContent`
|
2217 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2218 | *
|
2219 | * @since 1.0.0
|
2220 | */
|
2221 | insertAtIndex(item: T, index: number): ActiveListContent<T>;
|
2222 | /**
|
2223 | * Will add an item to the end of the `contents` array.
|
2224 | *
|
2225 | * @param {T} item The item to insert.
|
2226 | * @returns {ActiveListContent<T>} The newly inserted item wrapped in an `ActiveListContent`
|
2227 | *
|
2228 | * @since 1.0.0
|
2229 | */
|
2230 | push(item: T): ActiveListContent<T>;
|
2231 | /**
|
2232 | * Will add an item at the start of the `contents` array.
|
2233 | *
|
2234 | * @param {T} item The item to insert.
|
2235 | * @returns {ActiveListContent<T>} The newly inserted item wrapped in an `ActiveListContent`
|
2236 | *
|
2237 | * @since 1.0.0
|
2238 | */
|
2239 | unshift(item: T): ActiveListContent<T>;
|
2240 | /**
|
2241 | * Will add an item at the position in the `contents` array when when
|
2242 | * the predicate returns `true` for the `item` and `index`.
|
2243 | *
|
2244 | * If no item matches the predicate nothing is inserted and `null`
|
2245 | * will be returned.
|
2246 | *
|
2247 | * The position to where the `ActiveListContent` is inserted can be altered by
|
2248 | * providing a mode:
|
2249 | *
|
2250 | * 1. When the mode is 'at', the `ActiveListContent` is inserted to the
|
2251 | * position where the predicate matches. This is the `default`
|
2252 | * mode.
|
2253 | *
|
2254 | * 2. When the mode is 'after', the `ActiveListContent` is inserted to after
|
2255 | * the position where the predicate matches.
|
2256 | *
|
2257 | * 3. When the mode is 'before', the `ActiveListContent` is inserted to
|
2258 | * before the position where the predicate matches.
|
2259 | *
|
2260 | * @param {T} item The item to insert.
|
2261 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will move the item to that position.
|
2262 | * @param {ActiveListPredicateOptions} options The options for the predicate, when no options are provided the mode will default to "at".
|
2263 | *
|
2264 | * @since 1.0.0
|
2265 | */
|
2266 | insertByPredicate(item: T, predicate: ActiveListContentPredicate<T>, options?: ActiveListPredicateOptions): ActiveListContent<T> | null;
|
2267 | /**
|
2268 | * Will remove an item in the `contents` array, at the specified `index`.
|
2269 | *
|
2270 | * If you remove the `lastDeactivated` item it will be set to null.
|
2271 | *
|
2272 | * Throws an error if the index does not exist within the `contents`
|
2273 | * array.
|
2274 | *
|
2275 | * @param {number} index The index at which to remove the item.
|
2276 | * @returns {T} The removed value
|
2277 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2278 | *
|
2279 | * @since 1.0.0
|
2280 | */
|
2281 | removeByIndex(index: number): T;
|
2282 | private _doRemoveAtIndex;
|
2283 | /**
|
2284 | * Removes the given item based on identity by comparing the item
|
2285 | * via a `===` check. When multiple items match on `===` only the
|
2286 | * first matching item is removed.
|
2287 | *
|
2288 | * If you remove the `lastDeactivated` item it will be set to null.
|
2289 | *
|
2290 | * If the item does not exist in the content array it will
|
2291 | * throw an error.
|
2292 | *
|
2293 | * @param {T} item The item to remove
|
2294 | * @returns {T} The removed item
|
2295 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2296 | *
|
2297 | * @since 1.0.0
|
2298 | */
|
2299 | remove(item: T): T;
|
2300 | /**
|
2301 | * Removes the last item of the of the `contents` array.
|
2302 | *
|
2303 | * If you remove the `lastDeactivated` item it will be set to null.
|
2304 | *
|
2305 | * If the `contents` array at the time of the `pop` is empty
|
2306 | * `undefined` is returned.
|
2307 | *
|
2308 | * @param {ActiveListActivationOptions<T>} ActiveListActivationOptions The activation options
|
2309 | * @returns {T | undefined} The removed value, or undefined if the `contents` array is empty.
|
2310 | *
|
2311 | * @since 1.0.0
|
2312 | */
|
2313 | pop(): T | undefined;
|
2314 | /**
|
2315 | * Removes the first item of the `contents` array.
|
2316 | *
|
2317 | * If you remove the `lastDeactivated` item it will be set to null.
|
2318 | *
|
2319 | * If the `contents` array at the time of the `shift` is empty
|
2320 | * `undefined` is returned.
|
2321 | *
|
2322 | * @returns {T | undefined} The removed value, or undefined if the `contents` array is empty.
|
2323 | *
|
2324 | * @since 1.0.0
|
2325 | */
|
2326 | shift(): T | undefined;
|
2327 | /**
|
2328 | * Will remove all items from the `contents` array for which the
|
2329 | * predicate based on the `item` and `index` returns `true`.
|
2330 | *
|
2331 | * If no item matches the predicate nothing is removed and an empty
|
2332 | * array will be returned.
|
2333 | *
|
2334 | * If you remove the `lastDeactivated` item it will be set to null.
|
2335 | *
|
2336 | * @param {T} item The item to insert.
|
2337 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will remove the item.
|
2338 | * @returns {T[]} The removed items.
|
2339 | *
|
2340 | * @since 1.0.0
|
2341 | */
|
2342 | removeByPredicate(predicate: ActiveListContentPredicate<T>): T[];
|
2343 | /**
|
2344 | * Swaps the `ActiveListContent` at index a, with the `ActiveListContent` at index b.
|
2345 | *
|
2346 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
2347 | * it will only get a new position.
|
2348 | *
|
2349 | * @param {number} a The first index to swap.
|
2350 | * @param {number} b The second index to swap.
|
2351 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2352 | *
|
2353 | * @since 1.0.0
|
2354 | */
|
2355 | swapByIndex(a: number, b: number): void;
|
2356 | /**
|
2357 | * Swaps the `ActiveListContent` with item a, with the `ActiveListContent` with
|
2358 | * item b. Swaps the items based on identity by comparing the items
|
2359 | * via a `===` check. When multiple items match on `===` only the
|
2360 | * first matching item is swapped.
|
2361 | *
|
2362 | * Note: if the active `ActiveListContent` is swapped, it will stay active,
|
2363 | * it will only get a new position.
|
2364 | *
|
2365 | * @param {T} a The first item to swap.
|
2366 | * @param {T} b The second item to swap.
|
2367 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2368 | *
|
2369 | * @since 1.0.0
|
2370 | */
|
2371 | swap(a: T, b: T): void;
|
2372 | /**
|
2373 | * Moves the `ActiveListContent` at index "from", to the position at index "to".
|
2374 | *
|
2375 | * It is possible to move the `ActiveListContent` to the last place by making
|
2376 | * the "to" index the length of the `contents` array.
|
2377 | *
|
2378 | * Note: if the active `ActiveListContent` is moved it will stay active,
|
2379 | * meaning that the lastActivatedIndex will get updated.
|
2380 | *
|
2381 | * @param {number} from The "from" index which needs to be moved
|
2382 | * @param {number} to The location the `from` needs to move "to".
|
2383 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2384 | *
|
2385 | * @since 1.0.0
|
2386 | */
|
2387 | moveByIndex(from: number, to: number): void;
|
2388 | /**
|
2389 | * Moves the item, to the position at index "to".
|
2390 | *
|
2391 | * It is possible to move the `ActiveListContent` to the last place by making
|
2392 | * the "to" index the length of the `contents` array.
|
2393 | *
|
2394 | * Note: if the active `ActiveListContent` is moved it will stay active,
|
2395 | * meaning that the lastActivatedIndex will get updated.
|
2396 | *
|
2397 | * @param {T} item The item to move
|
2398 | * @param {number} to The location the `item` needs to move "to".
|
2399 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2400 | * @throws {ActiveListIndexOutOfBoundsError} index cannot be out of bounds
|
2401 | *
|
2402 | * @since 1.0.0
|
2403 | */
|
2404 | move(item: T, to: number): void;
|
2405 | /**
|
2406 | * Moves the `ActiveListContent`, at the index, to the position of the
|
2407 | * item for which the predicate returns `true`.
|
2408 | *
|
2409 | * If no item matches the predicate nothing is moved.
|
2410 | *
|
2411 | * The position to where the `ActiveListContent` moves can be altered by
|
2412 | * providing a mode:
|
2413 | *
|
2414 | * 1. When the mode is 'at', the `ActiveListContent` is moved to the position
|
2415 | * where the predicate matches. This is the `default` mode.
|
2416 | *
|
2417 | * 2. When the mode is 'after', the `ActiveListContent` is moved to after the
|
2418 | * position where the predicate matches.
|
2419 | *
|
2420 | * 3. When the mode is 'before', the `ActiveListContent` is moved to before
|
2421 | * the position where the predicate matches.
|
2422 | *
|
2423 | * @param {number} index The index to move.
|
2424 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will move the item to that position.
|
2425 | * @param {ActiveListPredicateOptions} options The options for the predicate, when no options are provided the mode will default to "at".
|
2426 | *
|
2427 | * @since 1.0.0
|
2428 | */
|
2429 | moveByIndexByPredicate(index: number, predicate: ActiveListContentPredicate<T>, options?: ActiveListPredicateOptions): void;
|
2430 | /**
|
2431 | * Moves the `ActiveListContent` which matches the value of the item based
|
2432 | * on `===` equality. To the position of the item for which
|
2433 | * the predicate returns `true`.
|
2434 | *
|
2435 | * When multiple items match on `===` only the first matching item is moved.
|
2436 | *
|
2437 | * If no item matches the predicate nothing is moved.
|
2438 | *
|
2439 | * The position to where the `ActiveListContent` moves can be altered by
|
2440 | * providing a mode:
|
2441 | *
|
2442 | * 1. When the mode is 'at', the `ActiveListContent` is moved to the position
|
2443 | * where the predicate matches. This is the `default` mode.
|
2444 | *
|
2445 | * 2. When the mode is 'after', the `ActiveListContent` is moved to after the
|
2446 | * position where the predicate matches.
|
2447 | *
|
2448 | * 3. When the mode is 'before', the `ActiveListContent` is moved to before
|
2449 | * the position where the predicate matches.
|
2450 | *
|
2451 | * @param {T} item The item to move.
|
2452 | * @param {ActiveListContentPredicate<T>} predicate A predicate function, when the predicate returns `true` it will move the item to after that position.
|
2453 | * @param {ActiveListPredicateOptions} options The options for the predicate, when no options are provided the mode will default to "at".
|
2454 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2455 | *
|
2456 | * @since 1.0.0
|
2457 | */
|
2458 | moveByPredicate(item: T, predicate: ActiveListContentPredicate<T>, options?: ActiveListPredicateOptions): void;
|
2459 | /**
|
2460 | * Gets the index for a given item.
|
2461 | *
|
2462 | * If the item does not exist in the content array it will
|
2463 | * throw an error.
|
2464 | *
|
2465 | * @param {T} item The item to get the index for.
|
2466 | * @returns {number} The index of the given item.
|
2467 | * @throws {ActiveListItemNotFoundError} item must be in the contents array based on === equality
|
2468 | *
|
2469 | * @since 1.0.0
|
2470 | */
|
2471 | getIndex(item: T): number;
|
2472 | /**
|
2473 | * Returns the final index available in the contents array.
|
2474 | *
|
2475 | * @returns {number} The last index of the contents array.
|
2476 | *
|
2477 | * @since 1.0.0
|
2478 | */
|
2479 | getLastIndex(): number;
|
2480 | _getBoundedNextIndex(index: number): number;
|
2481 | _getBoundedPreviousIndex(index: number): number;
|
2482 | _getUnboundedNextIndex(index: number): number;
|
2483 | _getUnboundedPreviousIndex(index: number): number;
|
2484 | /**
|
2485 | * Whether or not the contents is an empty array.
|
2486 | *
|
2487 | * @since 1.0.0
|
2488 | */
|
2489 | isEmpty(): boolean;
|
2490 | private _getDirectionWhenMovingToIndex;
|
2491 | private _repairContents;
|
2492 | private _repairContent;
|
2493 | private _emptyLastActives;
|
2494 | private _emptyLastDeactivated;
|
2495 | private _becameEmpty;
|
2496 | private _setLastActives;
|
2497 | private _deactivateContent;
|
2498 | private _execPred;
|
2499 | _inform(event: ActiveListEvent<T>): void;
|
2500 | private _checkIndex;
|
2501 | private _modeToMod;
|
2502 | }
|
2503 |
|
2504 | /**
|
2505 | * The configuration for the `createActiveListSubscriber` function.
|
2506 | *
|
2507 | * You should provide all methods for the events that you want to
|
2508 | * listen to, the ones you are not interested
|
2509 | *
|
2510 | * @since 1.5.0
|
2511 | */
|
2512 | type CreateActiveListSubscriberConfig<T> = {
|
2513 | /**
|
2514 | * Optionally whether or not you want to show debug logging.
|
2515 | *
|
2516 | * When `debug` is enabled whenever an event method is not provided
|
2517 | * but the event is fired, a `console.warn` message is logged. This
|
2518 | * allows you to easier detect missing methods during development.
|
2519 | *
|
2520 | * Defaults to `false`, meaning nothing will be logged to the console.
|
2521 | *
|
2522 | * @since 1.5.0
|
2523 | */
|
2524 | debug?: boolean;
|
2525 | /**
|
2526 | * Method which is called whenever an `MOVED` event is fired
|
2527 | * from within the ActiveList.
|
2528 | *
|
2529 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2530 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2531 | * @since 1.5.0
|
2532 | */
|
2533 | onMoved?: (event: ActiveListMovedEvent<T>, activeList: ActiveList<T>) => void;
|
2534 | /**
|
2535 | * Method which is called whenever an `INSERTED` event is fired
|
2536 | * from within the ActiveList.
|
2537 | *
|
2538 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2539 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2540 | * @since 1.5.0
|
2541 | */
|
2542 | onInserted?: (event: ActiveListInsertedEvent<T>, activeList: ActiveList<T>) => void;
|
2543 | /**
|
2544 | * Method which is called whenever an `INITIALIZED` event is fired
|
2545 | * from within the ActiveList.
|
2546 | *
|
2547 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2548 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2549 | * @since 1.5.0
|
2550 | */
|
2551 | onInitialized?: (event: ActiveListInitializedEvent<T>, activeList: ActiveList<T>) => void;
|
2552 | /**
|
2553 | * Method which is called whenever an `COOLDOWN_STARTED` event is
|
2554 | * fired from within the ActiveList.
|
2555 | *
|
2556 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2557 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2558 | * @since 1.5.0
|
2559 | */
|
2560 | onCooldownStarted?: (event: ActiveListCooldownStartedEvent, activeList: ActiveList<T>) => void;
|
2561 | /**
|
2562 | * Method which is called whenever an `COOLDOWN_ENDED` event is
|
2563 | * fired from within the ActiveList.
|
2564 | *
|
2565 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2566 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2567 | * @since 1.5.0
|
2568 | */
|
2569 | onCooldownEnded?: (event: ActiveListCooldownEndedEvent, activeList: ActiveList<T>) => void;
|
2570 | /**
|
2571 | * Method which is called whenever an `AUTO_PLAY_STOPPED` event is
|
2572 | * fired from within the ActiveList.
|
2573 | *
|
2574 | * @param {ActiveListMovedEvent<T>} event The event that was fired.
|
2575 | * @param {ActiveList<T>} activeList The ActiveList the event was fired from
|
2576 | * @since 1.5.0
|
2577 | */
|
2578 | onAutoPlayStopped?: (event: ActiveListAutoPlayStoppedEvent, activeList: ActiveList |