@himanshu-sorathiya/react-kit 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +156 -0
- package/dist/index.js +5 -5
- package/dist/performance.d.ts +156 -0
- package/dist/performance.js +2 -2
- package/dist/performance2.js +254 -167
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -417,6 +417,162 @@ export type UseKeyReturn = () => void;
|
|
|
417
417
|
* ```
|
|
418
418
|
*/
|
|
419
419
|
export declare function useKey(key: string, handler: (event: KeyboardEvent) => void, options?: UseKeyOptions): UseKeyReturn;
|
|
420
|
+
/**
|
|
421
|
+
* Configuration for `useBatcher`.
|
|
422
|
+
*
|
|
423
|
+
* All three flush triggers (`maxSize`, `maxWait`, `quietPeriod`) are
|
|
424
|
+
* optional and independent — configure any combination, and whichever
|
|
425
|
+
* condition is met first triggers the flush. If none are configured, the
|
|
426
|
+
* batch only ever flushes when `flush()` is called manually.
|
|
427
|
+
*/
|
|
428
|
+
export interface BatchOptions<Item> {
|
|
429
|
+
/**
|
|
430
|
+
* Flushes the batch immediately once it reaches this many items.
|
|
431
|
+
* Checked on every `add()` call, before either timer-based trigger is
|
|
432
|
+
* considered.
|
|
433
|
+
*
|
|
434
|
+
* Invalid input (not a positive number) is ignored — not clamped to a
|
|
435
|
+
* fallback — with a dev-mode warning, since there's no sensible
|
|
436
|
+
* default size to fall back to.
|
|
437
|
+
*
|
|
438
|
+
* @defaultValue `undefined` (no size ceiling)
|
|
439
|
+
*/
|
|
440
|
+
maxSize?: number;
|
|
441
|
+
/**
|
|
442
|
+
* A hard ceiling, in milliseconds, on how long a batch can sit before
|
|
443
|
+
* flushing — measured from the moment the *first* item of the current
|
|
444
|
+
* batch was added, not the most recent one. Guarantees a maximum
|
|
445
|
+
* latency per item regardless of how long the batch keeps growing.
|
|
446
|
+
*
|
|
447
|
+
* Invalid input (not a non-negative number) is ignored with a dev-mode
|
|
448
|
+
* warning.
|
|
449
|
+
*
|
|
450
|
+
* @defaultValue `undefined` (no time ceiling)
|
|
451
|
+
*/
|
|
452
|
+
maxWait?: number;
|
|
453
|
+
/**
|
|
454
|
+
* Flushes the batch once this many milliseconds pass with no further
|
|
455
|
+
* items added — resets on every `add()` call, unlike `maxWait`. Use
|
|
456
|
+
* this when you want to wait for activity to genuinely settle before
|
|
457
|
+
* flushing, rather than enforcing a hard per-item latency ceiling.
|
|
458
|
+
*
|
|
459
|
+
* If both `maxWait` and `quietPeriod` are configured and `quietPeriod`
|
|
460
|
+
* is not shorter than `maxWait`, `maxWait` will almost always win the
|
|
461
|
+
* race — a dev-mode warning flags this combination.
|
|
462
|
+
*
|
|
463
|
+
* Invalid input (not a non-negative number) is ignored with a dev-mode
|
|
464
|
+
* warning.
|
|
465
|
+
*
|
|
466
|
+
* @defaultValue `undefined` (no quiet-period trigger)
|
|
467
|
+
*/
|
|
468
|
+
quietPeriod?: number;
|
|
469
|
+
/**
|
|
470
|
+
* Called with a snapshot of the current batch contents every time it
|
|
471
|
+
* changes — after every `add()`, and after every flush or `cancel()`
|
|
472
|
+
* (with an empty array). This is the mechanism for getting live,
|
|
473
|
+
* reactive access to what's currently queued (e.g. a "3 items
|
|
474
|
+
* queued…" indicator) without `useBatcher` itself needing to hold the
|
|
475
|
+
* full item list in React state.
|
|
476
|
+
*
|
|
477
|
+
* Safe to pass a fresh inline function on every render — it's captured
|
|
478
|
+
* in a ref and refreshed via effect, same as `onFlush`.
|
|
479
|
+
*
|
|
480
|
+
* @defaultValue `undefined`
|
|
481
|
+
*/
|
|
482
|
+
onItemsChange?: (items: readonly Item[]) => void;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The object returned by `useBatcher`.
|
|
486
|
+
*/
|
|
487
|
+
export interface UseBatcherReturn<Item> {
|
|
488
|
+
/**
|
|
489
|
+
* Adds `item` to the current batch. Never rejected, never deferred to
|
|
490
|
+
* a future call — the item is always accepted immediately. Depending
|
|
491
|
+
* on the configured triggers, this may also cause an immediate flush
|
|
492
|
+
* (e.g. if `maxSize` is now reached).
|
|
493
|
+
*/
|
|
494
|
+
add: (item: Item) => void;
|
|
495
|
+
/**
|
|
496
|
+
* Immediately flushes whatever is currently batched, bypassing
|
|
497
|
+
* `maxWait`/`quietPeriod` entirely. A no-op if the batch is empty —
|
|
498
|
+
* `onFlush` is never called with zero items.
|
|
499
|
+
*/
|
|
500
|
+
flush: () => void;
|
|
501
|
+
/**
|
|
502
|
+
* Discards the current batch entirely, without ever calling
|
|
503
|
+
* `onFlush`. Clears any pending timers.
|
|
504
|
+
*/
|
|
505
|
+
cancel: () => void;
|
|
506
|
+
/**
|
|
507
|
+
* Suspends all automatic flush triggers (`maxSize`, `maxWait`,
|
|
508
|
+
* `quietPeriod`). Items added via `add()` while paused still
|
|
509
|
+
* accumulate normally — pausing stops the flushing machinery, not the
|
|
510
|
+
* accumulation. The only way to flush while paused is a manual
|
|
511
|
+
* `flush()` call.
|
|
512
|
+
*/
|
|
513
|
+
pause: () => void;
|
|
514
|
+
/**
|
|
515
|
+
* Resumes automatic flushing. If the batch already meets `maxSize`
|
|
516
|
+
* (because items kept arriving while paused), flushes immediately.
|
|
517
|
+
* Otherwise, re-arms `maxWait`/`quietPeriod` timers from scratch —
|
|
518
|
+
* pausing does not preserve partial progress toward either deadline;
|
|
519
|
+
* resuming starts a fresh clock for whatever's still batched.
|
|
520
|
+
*/
|
|
521
|
+
resume: () => void;
|
|
522
|
+
/** The number of items currently in the batch. */
|
|
523
|
+
size: number;
|
|
524
|
+
/** `true` whenever `size > 0`. */
|
|
525
|
+
isPending: boolean;
|
|
526
|
+
/** `true` after `pause()`, until the next `resume()`. */
|
|
527
|
+
isPaused: boolean;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Groups rapid, individual `add()` calls into batches, flushing the whole
|
|
531
|
+
* accumulated group to `onFlush` at once — instead of debouncing,
|
|
532
|
+
* throttling, or rate-limiting, all of which discard some calls along the
|
|
533
|
+
* way. Nothing added to a `useBatcher` is ever dropped; it's only ever
|
|
534
|
+
* grouped.
|
|
535
|
+
*
|
|
536
|
+
* A batch flushes when any configured trigger fires first: reaching
|
|
537
|
+
* `maxSize` items, `maxWait` milliseconds since the batch's first item,
|
|
538
|
+
* or `quietPeriod` milliseconds of no new items. All three are optional
|
|
539
|
+
* and can be combined freely. If none are configured, only a manual
|
|
540
|
+
* `flush()` call ever empties the batch.
|
|
541
|
+
*
|
|
542
|
+
* Unlike the debounce/throttle/rate-limit hook families, there's no
|
|
543
|
+
* separate `Callback`/`State`/`Value` wrapper — `onFlush` is a single
|
|
544
|
+
* fixed handler (captured in a ref and always current, so a fresh inline
|
|
545
|
+
* function on every render is safe), and live access to the current batch
|
|
546
|
+
* contents is available via the `onItemsChange` option instead of a
|
|
547
|
+
* dedicated hook.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```tsx
|
|
551
|
+
* function AnalyticsProvider({ children }: { children: React.ReactNode }) {
|
|
552
|
+
* const { add } = useBatcher<AnalyticsEvent>(
|
|
553
|
+
* (events) => sendAnalyticsBatch(events),
|
|
554
|
+
* { maxSize: 20, maxWait: 5000 },
|
|
555
|
+
* );
|
|
556
|
+
*
|
|
557
|
+
* // `track` can be called as often as needed — events are grouped and
|
|
558
|
+
* // sent in batches of up to 20, at least once every 5 seconds.
|
|
559
|
+
* const track = (event: AnalyticsEvent) => add(event);
|
|
560
|
+
*
|
|
561
|
+
* return (
|
|
562
|
+
* <AnalyticsContext.Provider value={{ track }}>
|
|
563
|
+
* {children}
|
|
564
|
+
* </AnalyticsContext.Provider>
|
|
565
|
+
* );
|
|
566
|
+
* }
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* @param onFlush - Called with every item accumulated since the last
|
|
570
|
+
* flush, as a snapshot array. Safe to pass a fresh inline function on
|
|
571
|
+
* every render.
|
|
572
|
+
* @param options - See {@link BatchOptions}.
|
|
573
|
+
* @returns See {@link UseBatcherReturn}.
|
|
574
|
+
*/
|
|
575
|
+
export declare function useBatcher<Item>(onFlush: (items: readonly Item[]) => void, options?: BatchOptions<Item>): UseBatcherReturn<Item>;
|
|
420
576
|
/**
|
|
421
577
|
* Adds an optional custom equality comparator to any hook that manages a
|
|
422
578
|
* value and needs to decide whether a "new" value is actually different
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as e } from "./useEventListener.js";
|
|
2
2
|
import { n as t, t as n } from "./events2.js";
|
|
3
|
-
import { a as r, c as i, d as a, f as o,
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
import { a as
|
|
7
|
-
export {
|
|
3
|
+
import { a as r, c as i, d as a, f as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _ } from "./performance2.js";
|
|
4
|
+
import { a as v, c as y, i as b, n as x, o as S, r as C, s as w, t as T } from "./state2.js";
|
|
5
|
+
import { a as E, i as D, n as O, o as k, r as A, s as j, t as M } from "./storage2.js";
|
|
6
|
+
import { a as N, c as P, i as F, n as I, o as L, r as R, s as z, t as B } from "./ui2.js";
|
|
7
|
+
export { P as FuzzyHighlighter, F as ModalLayout, A as bigIntSerializer, D as dateSerializer, E as defaultSerializer, k as mapSerializer, j as setSerializer, s as useBatcher, t as useClickOutside, p as useDebouncedCallback, o as useDebouncedState, a as useDebouncedValue, u as useDebouncer, e as useEventListener, R as useExpansion, y as useFilter, w as useFuzzySearch, S as useGrouping, n as useKey, O as useLocalStorage, N as useModal, L as useModalActions, z as useModalState, v as useMultipleSelection, b as useOrder, C as usePagination, I as usePin, l as useRateLimitedCallback, i as useRateLimitedState, h as useRateLimitedValue, _ as useRateLimiter, M as useSessionStorage, x as useSingleSelection, T as useSort, r as useThrottledCallback, c as useThrottledState, m as useThrottledValue, f as useThrottler, d as useVirtualGrid, g as useVirtualList, B as useVisibility };
|
package/dist/performance.d.ts
CHANGED
|
@@ -2,6 +2,162 @@
|
|
|
2
2
|
|
|
3
3
|
import { Key } from 'react';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for `useBatcher`.
|
|
7
|
+
*
|
|
8
|
+
* All three flush triggers (`maxSize`, `maxWait`, `quietPeriod`) are
|
|
9
|
+
* optional and independent — configure any combination, and whichever
|
|
10
|
+
* condition is met first triggers the flush. If none are configured, the
|
|
11
|
+
* batch only ever flushes when `flush()` is called manually.
|
|
12
|
+
*/
|
|
13
|
+
export interface BatchOptions<Item> {
|
|
14
|
+
/**
|
|
15
|
+
* Flushes the batch immediately once it reaches this many items.
|
|
16
|
+
* Checked on every `add()` call, before either timer-based trigger is
|
|
17
|
+
* considered.
|
|
18
|
+
*
|
|
19
|
+
* Invalid input (not a positive number) is ignored — not clamped to a
|
|
20
|
+
* fallback — with a dev-mode warning, since there's no sensible
|
|
21
|
+
* default size to fall back to.
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue `undefined` (no size ceiling)
|
|
24
|
+
*/
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
/**
|
|
27
|
+
* A hard ceiling, in milliseconds, on how long a batch can sit before
|
|
28
|
+
* flushing — measured from the moment the *first* item of the current
|
|
29
|
+
* batch was added, not the most recent one. Guarantees a maximum
|
|
30
|
+
* latency per item regardless of how long the batch keeps growing.
|
|
31
|
+
*
|
|
32
|
+
* Invalid input (not a non-negative number) is ignored with a dev-mode
|
|
33
|
+
* warning.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue `undefined` (no time ceiling)
|
|
36
|
+
*/
|
|
37
|
+
maxWait?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Flushes the batch once this many milliseconds pass with no further
|
|
40
|
+
* items added — resets on every `add()` call, unlike `maxWait`. Use
|
|
41
|
+
* this when you want to wait for activity to genuinely settle before
|
|
42
|
+
* flushing, rather than enforcing a hard per-item latency ceiling.
|
|
43
|
+
*
|
|
44
|
+
* If both `maxWait` and `quietPeriod` are configured and `quietPeriod`
|
|
45
|
+
* is not shorter than `maxWait`, `maxWait` will almost always win the
|
|
46
|
+
* race — a dev-mode warning flags this combination.
|
|
47
|
+
*
|
|
48
|
+
* Invalid input (not a non-negative number) is ignored with a dev-mode
|
|
49
|
+
* warning.
|
|
50
|
+
*
|
|
51
|
+
* @defaultValue `undefined` (no quiet-period trigger)
|
|
52
|
+
*/
|
|
53
|
+
quietPeriod?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Called with a snapshot of the current batch contents every time it
|
|
56
|
+
* changes — after every `add()`, and after every flush or `cancel()`
|
|
57
|
+
* (with an empty array). This is the mechanism for getting live,
|
|
58
|
+
* reactive access to what's currently queued (e.g. a "3 items
|
|
59
|
+
* queued…" indicator) without `useBatcher` itself needing to hold the
|
|
60
|
+
* full item list in React state.
|
|
61
|
+
*
|
|
62
|
+
* Safe to pass a fresh inline function on every render — it's captured
|
|
63
|
+
* in a ref and refreshed via effect, same as `onFlush`.
|
|
64
|
+
*
|
|
65
|
+
* @defaultValue `undefined`
|
|
66
|
+
*/
|
|
67
|
+
onItemsChange?: (items: readonly Item[]) => void;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The object returned by `useBatcher`.
|
|
71
|
+
*/
|
|
72
|
+
export interface UseBatcherReturn<Item> {
|
|
73
|
+
/**
|
|
74
|
+
* Adds `item` to the current batch. Never rejected, never deferred to
|
|
75
|
+
* a future call — the item is always accepted immediately. Depending
|
|
76
|
+
* on the configured triggers, this may also cause an immediate flush
|
|
77
|
+
* (e.g. if `maxSize` is now reached).
|
|
78
|
+
*/
|
|
79
|
+
add: (item: Item) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Immediately flushes whatever is currently batched, bypassing
|
|
82
|
+
* `maxWait`/`quietPeriod` entirely. A no-op if the batch is empty —
|
|
83
|
+
* `onFlush` is never called with zero items.
|
|
84
|
+
*/
|
|
85
|
+
flush: () => void;
|
|
86
|
+
/**
|
|
87
|
+
* Discards the current batch entirely, without ever calling
|
|
88
|
+
* `onFlush`. Clears any pending timers.
|
|
89
|
+
*/
|
|
90
|
+
cancel: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Suspends all automatic flush triggers (`maxSize`, `maxWait`,
|
|
93
|
+
* `quietPeriod`). Items added via `add()` while paused still
|
|
94
|
+
* accumulate normally — pausing stops the flushing machinery, not the
|
|
95
|
+
* accumulation. The only way to flush while paused is a manual
|
|
96
|
+
* `flush()` call.
|
|
97
|
+
*/
|
|
98
|
+
pause: () => void;
|
|
99
|
+
/**
|
|
100
|
+
* Resumes automatic flushing. If the batch already meets `maxSize`
|
|
101
|
+
* (because items kept arriving while paused), flushes immediately.
|
|
102
|
+
* Otherwise, re-arms `maxWait`/`quietPeriod` timers from scratch —
|
|
103
|
+
* pausing does not preserve partial progress toward either deadline;
|
|
104
|
+
* resuming starts a fresh clock for whatever's still batched.
|
|
105
|
+
*/
|
|
106
|
+
resume: () => void;
|
|
107
|
+
/** The number of items currently in the batch. */
|
|
108
|
+
size: number;
|
|
109
|
+
/** `true` whenever `size > 0`. */
|
|
110
|
+
isPending: boolean;
|
|
111
|
+
/** `true` after `pause()`, until the next `resume()`. */
|
|
112
|
+
isPaused: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Groups rapid, individual `add()` calls into batches, flushing the whole
|
|
116
|
+
* accumulated group to `onFlush` at once — instead of debouncing,
|
|
117
|
+
* throttling, or rate-limiting, all of which discard some calls along the
|
|
118
|
+
* way. Nothing added to a `useBatcher` is ever dropped; it's only ever
|
|
119
|
+
* grouped.
|
|
120
|
+
*
|
|
121
|
+
* A batch flushes when any configured trigger fires first: reaching
|
|
122
|
+
* `maxSize` items, `maxWait` milliseconds since the batch's first item,
|
|
123
|
+
* or `quietPeriod` milliseconds of no new items. All three are optional
|
|
124
|
+
* and can be combined freely. If none are configured, only a manual
|
|
125
|
+
* `flush()` call ever empties the batch.
|
|
126
|
+
*
|
|
127
|
+
* Unlike the debounce/throttle/rate-limit hook families, there's no
|
|
128
|
+
* separate `Callback`/`State`/`Value` wrapper — `onFlush` is a single
|
|
129
|
+
* fixed handler (captured in a ref and always current, so a fresh inline
|
|
130
|
+
* function on every render is safe), and live access to the current batch
|
|
131
|
+
* contents is available via the `onItemsChange` option instead of a
|
|
132
|
+
* dedicated hook.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```tsx
|
|
136
|
+
* function AnalyticsProvider({ children }: { children: React.ReactNode }) {
|
|
137
|
+
* const { add } = useBatcher<AnalyticsEvent>(
|
|
138
|
+
* (events) => sendAnalyticsBatch(events),
|
|
139
|
+
* { maxSize: 20, maxWait: 5000 },
|
|
140
|
+
* );
|
|
141
|
+
*
|
|
142
|
+
* // `track` can be called as often as needed — events are grouped and
|
|
143
|
+
* // sent in batches of up to 20, at least once every 5 seconds.
|
|
144
|
+
* const track = (event: AnalyticsEvent) => add(event);
|
|
145
|
+
*
|
|
146
|
+
* return (
|
|
147
|
+
* <AnalyticsContext.Provider value={{ track }}>
|
|
148
|
+
* {children}
|
|
149
|
+
* </AnalyticsContext.Provider>
|
|
150
|
+
* );
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @param onFlush - Called with every item accumulated since the last
|
|
155
|
+
* flush, as a snapshot array. Safe to pass a fresh inline function on
|
|
156
|
+
* every render.
|
|
157
|
+
* @param options - See {@link BatchOptions}.
|
|
158
|
+
* @returns See {@link UseBatcherReturn}.
|
|
159
|
+
*/
|
|
160
|
+
export declare function useBatcher<Item>(onFlush: (items: readonly Item[]) => void, options?: BatchOptions<Item>): UseBatcherReturn<Item>;
|
|
5
161
|
/**
|
|
6
162
|
* Adds an optional custom equality comparator to any hook that manages a
|
|
7
163
|
* value and needs to decide whether a "new" value is actually different
|
package/dist/performance.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i,
|
|
2
|
-
export {
|
|
1
|
+
import { a as e, c as t, d as n, f as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m } from "./performance2.js";
|
|
2
|
+
export { i as useBatcher, u as useDebouncedCallback, r as useDebouncedState, n as useDebouncedValue, s as useDebouncer, o as useRateLimitedCallback, t as useRateLimitedState, f as useRateLimitedValue, m as useRateLimiter, e as useThrottledCallback, a as useThrottledState, d as useThrottledValue, l as useThrottler, c as useVirtualGrid, p as useVirtualList };
|
package/dist/performance2.js
CHANGED
|
@@ -1,41 +1,128 @@
|
|
|
1
1
|
import { t as e } from "./useEventListener.js";
|
|
2
2
|
import { t } from "./utils.js";
|
|
3
3
|
import { useCallback as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
4
|
+
//#region src/performance/useBatcher/utils.ts
|
|
5
|
+
function c(e) {
|
|
6
|
+
if (e === void 0) return;
|
|
7
|
+
let t = Math.floor(Number(e));
|
|
8
|
+
return Number.isFinite(t) && t >= 1 ? t : void 0;
|
|
9
|
+
}
|
|
10
|
+
function l(e) {
|
|
11
|
+
if (e === void 0) return;
|
|
12
|
+
let t = Number(e);
|
|
13
|
+
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/performance/useBatcher/useBatcher.ts
|
|
17
|
+
var u = globalThis.process?.env?.NODE_ENV !== "production";
|
|
18
|
+
function d(e, t = {}) {
|
|
19
|
+
u && typeof e != "function" && console.warn(`[useBatcher] Expected \`onFlush\` to be a function, received ${typeof e}.`);
|
|
20
|
+
let i = c(t?.maxSize), a = l(t?.maxWait), d = l(t?.quietPeriod);
|
|
21
|
+
u && t?.maxSize !== void 0 && i === void 0 && console.warn(`[useBatcher] \`maxSize\` (${String(t.maxSize)}) must be a positive integer — ignoring it.`), u && t?.maxWait !== void 0 && a === void 0 && console.warn(`[useBatcher] \`maxWait\` (${String(t.maxWait)}) must be a non-negative number — ignoring it.`), u && t?.quietPeriod !== void 0 && d === void 0 && console.warn(`[useBatcher] \`quietPeriod\` (${String(t.quietPeriod)}) must be a non-negative number — ignoring it.`), u && i === void 0 && a === void 0 && d === void 0 && console.warn("[useBatcher] No `maxSize`, `maxWait`, or `quietPeriod` configured — items will only flush when `flush()` is called manually."), u && a !== void 0 && d !== void 0 && d >= a && console.warn(`[useBatcher] \`quietPeriod\` (${d}ms) is not shorter than \`maxWait\` (${a}ms) — \`maxWait\` will almost always fire first, making \`quietPeriod\` unreachable in practice.`), u && t?.onItemsChange !== void 0 && typeof t.onItemsChange != "function" && console.warn("[useBatcher] `onItemsChange` must be a function — ignoring the provided value.");
|
|
22
|
+
let [f, p] = s(0), [m, h] = s(!1), g = o([]), _ = o(!1), v = o(null), y = o(null), b = o(e), x = o(typeof t?.onItemsChange == "function" ? t.onItemsChange : void 0);
|
|
23
|
+
r(() => {
|
|
24
|
+
b.current = e;
|
|
25
|
+
}, [e]), r(() => {
|
|
26
|
+
x.current = typeof t?.onItemsChange == "function" ? t.onItemsChange : void 0;
|
|
27
|
+
}, [t?.onItemsChange]);
|
|
28
|
+
let S = n(() => {
|
|
29
|
+
x.current?.([...g.current]);
|
|
30
|
+
}, []), C = n(() => {
|
|
31
|
+
v.current !== null && (clearTimeout(v.current), v.current = null), y.current !== null && (clearTimeout(y.current), y.current = null);
|
|
32
|
+
}, []);
|
|
33
|
+
r(() => C, [C]);
|
|
34
|
+
let w = n(() => {
|
|
35
|
+
if (C(), g.current.length === 0) return;
|
|
36
|
+
let e = g.current;
|
|
37
|
+
g.current = [], p(0), S(), b.current(e);
|
|
38
|
+
}, [C, S]), T = n(() => {
|
|
39
|
+
C(), g.current = [], p(0), S();
|
|
40
|
+
}, [C, S]), E = n(() => {
|
|
41
|
+
_.current = !0, C(), h(!0);
|
|
42
|
+
}, [C]), D = n(() => {
|
|
43
|
+
if (_.current = !1, h(!1), g.current.length !== 0) {
|
|
44
|
+
if (i !== void 0 && g.current.length >= i) {
|
|
45
|
+
w();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
a !== void 0 && (v.current = setTimeout(() => {
|
|
49
|
+
v.current = null, w();
|
|
50
|
+
}, a)), d !== void 0 && (y.current = setTimeout(() => {
|
|
51
|
+
y.current = null, w();
|
|
52
|
+
}, d));
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
i,
|
|
56
|
+
a,
|
|
57
|
+
d,
|
|
58
|
+
w
|
|
59
|
+
]);
|
|
60
|
+
return {
|
|
61
|
+
add: n((e) => {
|
|
62
|
+
let t = g.current.length === 0;
|
|
63
|
+
if (g.current.push(e), p(g.current.length), S(), !_.current) {
|
|
64
|
+
if (i !== void 0 && g.current.length >= i) {
|
|
65
|
+
w();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
t && a !== void 0 && (v.current = setTimeout(() => {
|
|
69
|
+
v.current = null, w();
|
|
70
|
+
}, a)), d !== void 0 && (y.current !== null && clearTimeout(y.current), y.current = setTimeout(() => {
|
|
71
|
+
y.current = null, w();
|
|
72
|
+
}, d));
|
|
73
|
+
}
|
|
74
|
+
}, [
|
|
75
|
+
i,
|
|
76
|
+
a,
|
|
77
|
+
d,
|
|
78
|
+
w,
|
|
79
|
+
S
|
|
80
|
+
]),
|
|
81
|
+
flush: w,
|
|
82
|
+
cancel: T,
|
|
83
|
+
pause: E,
|
|
84
|
+
resume: D,
|
|
85
|
+
size: f,
|
|
86
|
+
isPending: f > 0,
|
|
87
|
+
isPaused: m
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
4
91
|
//#region src/performance/useDebouncer/useDebouncer.ts
|
|
5
|
-
var
|
|
6
|
-
function
|
|
92
|
+
var f = globalThis.process?.env?.NODE_ENV !== "production";
|
|
93
|
+
function p(e, t = {}) {
|
|
7
94
|
let i = Math.max(0, Number(e) || 0);
|
|
8
|
-
|
|
9
|
-
let [a,
|
|
10
|
-
|
|
95
|
+
f && (typeof e != "number" || !Number.isFinite(e) || e < 0) && console.warn(`[useDebouncer] Received an invalid \`delay\` (${String(e)}) — falling back to ${i}ms.`);
|
|
96
|
+
let [a, c] = s(!1), l = t?.maxWait, u = !!t?.leading, d = t?.trailing ?? !0;
|
|
97
|
+
f && !u && !d && console.warn("[useDebouncer] Both `leading` and `trailing` are false — the debounced function will never be invoked."), f && l !== void 0 && l < i && console.warn(`[useDebouncer] \`maxWait\` (${l}ms) is smaller than \`delay\` (${i}ms) — the function will fire on almost every call.`);
|
|
11
98
|
let p = o(null), m = o(null), h = o(null), g = o(-1), _ = n(() => {
|
|
12
|
-
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null,
|
|
99
|
+
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null, c(!1);
|
|
13
100
|
}, []), v = n(() => {
|
|
14
101
|
let e = p.current, t = m.current;
|
|
15
|
-
h.current === null || e === null || t === null || (clearTimeout(h.current), h.current = null, g.current = -1, m.current = null, p.current = null,
|
|
102
|
+
h.current === null || e === null || t === null || (clearTimeout(h.current), h.current = null, g.current = -1, m.current = null, p.current = null, c(!1), e(...t));
|
|
16
103
|
}, []);
|
|
17
104
|
return r(() => _, [_]), {
|
|
18
105
|
run: n((e, ...t) => {
|
|
19
106
|
let n = Date.now();
|
|
20
|
-
if (p.current = e, m.current = t, g.current === -1 && (g.current = n,
|
|
107
|
+
if (p.current = e, m.current = t, g.current === -1 && (g.current = n, u)) {
|
|
21
108
|
let e = p.current, t = m.current;
|
|
22
109
|
m.current = null, e(...t);
|
|
23
110
|
}
|
|
24
111
|
let r = p.current, a = m.current;
|
|
25
|
-
if (
|
|
26
|
-
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null,
|
|
112
|
+
if (l !== void 0 && r !== null && a !== null && n - g.current >= l) {
|
|
113
|
+
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null, c(!1), r(...a);
|
|
27
114
|
return;
|
|
28
115
|
}
|
|
29
116
|
h.current !== null && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
30
117
|
h.current = null;
|
|
31
118
|
let e = p.current, t = m.current;
|
|
32
|
-
g.current = -1, m.current = null, p.current = null,
|
|
33
|
-
}, i),
|
|
119
|
+
g.current = -1, m.current = null, p.current = null, c(!1), d && e !== null && t !== null && e(...t);
|
|
120
|
+
}, i), c(d);
|
|
34
121
|
}, [
|
|
35
122
|
i,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
123
|
+
l,
|
|
124
|
+
d,
|
|
125
|
+
u
|
|
39
126
|
]),
|
|
40
127
|
cancel: _,
|
|
41
128
|
flush: v,
|
|
@@ -44,79 +131,79 @@ function l(e, t = {}) {
|
|
|
44
131
|
}
|
|
45
132
|
//#endregion
|
|
46
133
|
//#region src/performance/useDebouncer/useDebouncedCallback.ts
|
|
47
|
-
var
|
|
48
|
-
function
|
|
49
|
-
|
|
134
|
+
var m = globalThis.process?.env?.NODE_ENV !== "production";
|
|
135
|
+
function h(e, t, i = {}) {
|
|
136
|
+
m && typeof e != "function" && console.warn(`[useDebouncedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
50
137
|
let a = o(e);
|
|
51
138
|
r(() => {
|
|
52
139
|
a.current = e;
|
|
53
140
|
}, [e]);
|
|
54
|
-
let { run: s, cancel: c, flush:
|
|
141
|
+
let { run: s, cancel: c, flush: l, isPending: u } = p(t, i);
|
|
55
142
|
return {
|
|
56
143
|
debouncedFunc: n((...e) => {
|
|
57
144
|
s(a.current, ...e);
|
|
58
145
|
}, [s]),
|
|
59
146
|
cancel: c,
|
|
60
|
-
flush:
|
|
61
|
-
isPending:
|
|
147
|
+
flush: l,
|
|
148
|
+
isPending: u
|
|
62
149
|
};
|
|
63
150
|
}
|
|
64
151
|
//#endregion
|
|
65
152
|
//#region src/shared/rateControlShared/utils.ts
|
|
66
|
-
function
|
|
153
|
+
function g(e) {
|
|
67
154
|
return typeof e == "function";
|
|
68
155
|
}
|
|
69
156
|
//#endregion
|
|
70
157
|
//#region src/performance/useDebouncer/useDebouncedState.ts
|
|
71
|
-
var
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { debouncedFunc: u, cancel:
|
|
158
|
+
var _ = globalThis.process?.env?.NODE_ENV !== "production";
|
|
159
|
+
function v(e, t, r = {}) {
|
|
160
|
+
_ && r.equalityFn !== void 0 && typeof r.equalityFn != "function" && console.warn("[useDebouncedState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
161
|
+
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { debouncedFunc: u, cancel: d, flush: f, isPending: p } = h(n((e) => {
|
|
75
162
|
c((t) => i(t, e) ? t : e);
|
|
76
163
|
}, [i]), t, r);
|
|
77
164
|
return [
|
|
78
165
|
a,
|
|
79
166
|
n((e) => {
|
|
80
|
-
let t =
|
|
167
|
+
let t = g(e) ? e(l.current) : e;
|
|
81
168
|
l.current = t, u(t);
|
|
82
169
|
}, [u]),
|
|
83
170
|
{
|
|
84
|
-
isPending:
|
|
171
|
+
isPending: p,
|
|
85
172
|
cancel: n(() => {
|
|
86
|
-
|
|
87
|
-
}, [
|
|
88
|
-
flush:
|
|
173
|
+
d(), c((e) => (l.current = e, e));
|
|
174
|
+
}, [d]),
|
|
175
|
+
flush: f,
|
|
89
176
|
forceSetValue: n((e) => {
|
|
90
|
-
|
|
91
|
-
let n =
|
|
177
|
+
d(), c((t) => {
|
|
178
|
+
let n = g(e) ? e(t) : e;
|
|
92
179
|
return l.current = n, n;
|
|
93
180
|
});
|
|
94
|
-
}, [
|
|
181
|
+
}, [d])
|
|
95
182
|
}
|
|
96
183
|
];
|
|
97
184
|
}
|
|
98
185
|
//#endregion
|
|
99
186
|
//#region src/performance/useDebouncer/useDebouncedValue.ts
|
|
100
|
-
var
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { debouncedFunc: c, cancel: l, flush: u, isPending:
|
|
187
|
+
var y = globalThis.process?.env?.NODE_ENV !== "production";
|
|
188
|
+
function b(e, t, n = {}) {
|
|
189
|
+
y && n.equalityFn !== void 0 && typeof n.equalityFn != "function" && console.warn("[useDebouncedValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
190
|
+
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { debouncedFunc: c, cancel: l, flush: u, isPending: d } = h((e) => {
|
|
104
191
|
o((t) => i(t, e) ? t : e);
|
|
105
192
|
}, t, n);
|
|
106
193
|
return r(() => {
|
|
107
194
|
c(e);
|
|
108
195
|
}, [e, c]), [a, {
|
|
109
|
-
isPending:
|
|
196
|
+
isPending: d,
|
|
110
197
|
cancel: l,
|
|
111
198
|
flush: u
|
|
112
199
|
}];
|
|
113
200
|
}
|
|
114
201
|
//#endregion
|
|
115
202
|
//#region src/performance/useRateLimiter/useRateLimiter.ts
|
|
116
|
-
var
|
|
117
|
-
function
|
|
203
|
+
var x = globalThis.process?.env?.NODE_ENV !== "production";
|
|
204
|
+
function S(e, t, i) {
|
|
118
205
|
let a = Math.max(1, Math.floor(Number(e) || 1)), c = Math.max(0, Number(t) || 0);
|
|
119
|
-
|
|
206
|
+
x && (typeof e != "number" || !Number.isFinite(e) || e < 1) && console.warn(`[useRateLimiter] Received an invalid \`limit\` (${String(e)}) — falling back to ${a}.`), x && (typeof t != "number" || !Number.isFinite(t) || t < 0) && console.warn(`[useRateLimiter] Received an invalid \`windowMs\` (${String(t)}) — falling back to ${c}ms.`), x && c === 0 && console.warn("[useRateLimiter] `windowMs` is 0 — rate limiting is effectively disabled; every call will be allowed."), x && i?.refillStrategy !== void 0 && i.refillStrategy !== "burst" && i.refillStrategy !== "gradual" && console.warn(`[useRateLimiter] \`refillStrategy\` must be "burst" or "gradual", received "${String(i.refillStrategy)}" — falling back to "burst".`), x && i?.onRateLimitReached !== void 0 && typeof i.onRateLimitReached != "function" && console.warn("[useRateLimiter] `onRateLimitReached` must be a function — ignoring the provided value.");
|
|
120
207
|
let [l, u] = s(a), d = i?.refillStrategy === "gradual" ? "gradual" : "burst", f = o(typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0);
|
|
121
208
|
r(() => {
|
|
122
209
|
f.current = typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0;
|
|
@@ -141,7 +228,7 @@ function v(e, t, i) {
|
|
|
141
228
|
d,
|
|
142
229
|
c,
|
|
143
230
|
a
|
|
144
|
-
]),
|
|
231
|
+
]), _ = n(function e() {
|
|
145
232
|
if (h.current !== null && (clearTimeout(h.current), h.current = null), p.current >= a || c === 0) return;
|
|
146
233
|
let t = c / a, n = Date.now() - m.current, r = d === "burst" ? c - n : t - n;
|
|
147
234
|
h.current = setTimeout(() => {
|
|
@@ -152,26 +239,26 @@ function v(e, t, i) {
|
|
|
152
239
|
c,
|
|
153
240
|
d,
|
|
154
241
|
g
|
|
155
|
-
]),
|
|
242
|
+
]), v = n(() => {
|
|
156
243
|
h.current !== null && (clearTimeout(h.current), h.current = null), p.current = a, m.current = Date.now(), u(a);
|
|
157
244
|
}, [a]);
|
|
158
245
|
return {
|
|
159
|
-
run: n((e, ...t) => (g(), p.current > 0 ? (--p.current, u(p.current),
|
|
160
|
-
reset:
|
|
246
|
+
run: n((e, ...t) => (g(), p.current > 0 ? (--p.current, u(p.current), _(), e(...t), !0) : (f.current?.(), _(), !1)), [g, _]),
|
|
247
|
+
reset: v,
|
|
161
248
|
remaining: l,
|
|
162
249
|
isRateLimited: l === 0
|
|
163
250
|
};
|
|
164
251
|
}
|
|
165
252
|
//#endregion
|
|
166
253
|
//#region src/performance/useRateLimiter/useRateLimitedCallback.ts
|
|
167
|
-
var
|
|
168
|
-
function
|
|
169
|
-
|
|
254
|
+
var C = globalThis.process?.env?.NODE_ENV !== "production";
|
|
255
|
+
function w(e, t, i, a) {
|
|
256
|
+
C && typeof e != "function" && console.warn(`[useRateLimitedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
170
257
|
let s = o(e);
|
|
171
258
|
r(() => {
|
|
172
259
|
s.current = e;
|
|
173
260
|
}, [e]);
|
|
174
|
-
let { run: c, reset: l, remaining: u, isRateLimited: d } =
|
|
261
|
+
let { run: c, reset: l, remaining: u, isRateLimited: d } = S(t, i, a);
|
|
175
262
|
return {
|
|
176
263
|
rateLimitedFunc: n((...e) => c(s.current, ...e), [c]),
|
|
177
264
|
reset: l,
|
|
@@ -181,21 +268,21 @@ function b(e, t, i, a) {
|
|
|
181
268
|
}
|
|
182
269
|
//#endregion
|
|
183
270
|
//#region src/performance/useRateLimiter/useRateLimitedState.ts
|
|
184
|
-
var
|
|
185
|
-
function
|
|
186
|
-
|
|
271
|
+
var T = globalThis.process?.env?.NODE_ENV !== "production";
|
|
272
|
+
function E(e, t, r, i = {}) {
|
|
273
|
+
T && i.equalityFn !== void 0 && typeof i.equalityFn != "function" && console.warn("[useRateLimitedState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
187
274
|
let a = typeof i.equalityFn == "function" ? i.equalityFn : Object.is, [o, c] = s(e), l = n((e) => {
|
|
188
275
|
c((t) => {
|
|
189
|
-
let n =
|
|
276
|
+
let n = g(e) ? e(t) : e;
|
|
190
277
|
return a(t, n) ? t : n;
|
|
191
278
|
});
|
|
192
|
-
}, [a]), { rateLimitedFunc: u, reset: d, remaining:
|
|
279
|
+
}, [a]), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = w(l, t, r, i);
|
|
193
280
|
return [
|
|
194
281
|
o,
|
|
195
282
|
n((e) => u(e), [u]),
|
|
196
283
|
{
|
|
197
|
-
remaining:
|
|
198
|
-
isRateLimited:
|
|
284
|
+
remaining: f,
|
|
285
|
+
isRateLimited: p,
|
|
199
286
|
reset: d,
|
|
200
287
|
forceSetValue: n((e) => {
|
|
201
288
|
l(e);
|
|
@@ -205,10 +292,10 @@ function S(e, t, r, i = {}) {
|
|
|
205
292
|
}
|
|
206
293
|
//#endregion
|
|
207
294
|
//#region src/performance/useRateLimiter/useRateLimitedValue.ts
|
|
208
|
-
var
|
|
209
|
-
function
|
|
210
|
-
|
|
211
|
-
let a = typeof i.equalityFn == "function" ? i.equalityFn : Object.is, [c, l] = s(e), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } =
|
|
295
|
+
var D = globalThis.process?.env?.NODE_ENV !== "production";
|
|
296
|
+
function O(e, t, n, i = {}) {
|
|
297
|
+
D && i.equalityFn !== void 0 && typeof i.equalityFn != "function" && console.warn("[useRateLimitedValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
298
|
+
let a = typeof i.equalityFn == "function" ? i.equalityFn : Object.is, [c, l] = s(e), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = w((e) => {
|
|
212
299
|
l((t) => a(t, e) ? t : e);
|
|
213
300
|
}, t, n, i), m = o(!0);
|
|
214
301
|
return r(() => {
|
|
@@ -225,12 +312,12 @@ function w(e, t, n, i = {}) {
|
|
|
225
312
|
}
|
|
226
313
|
//#endregion
|
|
227
314
|
//#region src/performance/useThrottler/useThrottler.ts
|
|
228
|
-
var
|
|
229
|
-
function
|
|
315
|
+
var k = globalThis.process?.env?.NODE_ENV !== "production";
|
|
316
|
+
function A(e, t = {}) {
|
|
230
317
|
let i = Math.max(0, Number(e) || 0);
|
|
231
|
-
|
|
318
|
+
k && (typeof e != "number" || !Number.isFinite(e) || e < 0) && console.warn(`[useThrottler] Received an invalid \`delay\` (${String(e)}) — falling back to ${i}ms.`);
|
|
232
319
|
let [a, c] = s(!1), l = t?.leading ?? !0, u = t?.trailing ?? !0;
|
|
233
|
-
|
|
320
|
+
k && !l && !u && console.warn("[useThrottler] Both `leading` and `trailing` are false — the throttled function will never be invoked.");
|
|
234
321
|
let d = o(null), f = o(null), p = o(null), m = o(-1), h = n(() => {
|
|
235
322
|
p.current !== null && (clearTimeout(p.current), p.current = null), m.current = -1, f.current = null, d.current = null, c(!1);
|
|
236
323
|
}, []), g = n(() => {
|
|
@@ -268,14 +355,14 @@ function E(e, t = {}) {
|
|
|
268
355
|
}
|
|
269
356
|
//#endregion
|
|
270
357
|
//#region src/performance/useThrottler/useThrottledCallback.ts
|
|
271
|
-
var
|
|
272
|
-
function
|
|
273
|
-
|
|
358
|
+
var j = globalThis.process?.env?.NODE_ENV !== "production";
|
|
359
|
+
function M(e, t, i = {}) {
|
|
360
|
+
j && typeof e != "function" && console.warn(`[useThrottledCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
274
361
|
let a = o(e);
|
|
275
362
|
r(() => {
|
|
276
363
|
a.current = e;
|
|
277
364
|
}, [e]);
|
|
278
|
-
let { run: s, cancel: c, flush: l, isPending: u } =
|
|
365
|
+
let { run: s, cancel: c, flush: l, isPending: u } = A(t, i);
|
|
279
366
|
return {
|
|
280
367
|
throttledFunc: n((...e) => {
|
|
281
368
|
s(a.current, ...e);
|
|
@@ -287,27 +374,27 @@ function O(e, t, i = {}) {
|
|
|
287
374
|
}
|
|
288
375
|
//#endregion
|
|
289
376
|
//#region src/performance/useThrottler/useThrottledState.ts
|
|
290
|
-
var
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { throttledFunc: u, cancel: d, flush:
|
|
377
|
+
var N = globalThis.process?.env?.NODE_ENV !== "production";
|
|
378
|
+
function P(e, t, r = {}) {
|
|
379
|
+
N && r.equalityFn !== void 0 && typeof r.equalityFn != "function" && console.warn("[useThrottledState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
380
|
+
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { throttledFunc: u, cancel: d, flush: f, isPending: p } = M(n((e) => {
|
|
294
381
|
c((t) => i(t, e) ? t : e);
|
|
295
382
|
}, [i]), t, r);
|
|
296
383
|
return [
|
|
297
384
|
a,
|
|
298
385
|
n((e) => {
|
|
299
|
-
let t =
|
|
386
|
+
let t = g(e) ? e(l.current) : e;
|
|
300
387
|
l.current = t, u(t);
|
|
301
388
|
}, [u]),
|
|
302
389
|
{
|
|
303
|
-
isPending:
|
|
390
|
+
isPending: p,
|
|
304
391
|
cancel: n(() => {
|
|
305
392
|
d(), c((e) => (l.current = e, e));
|
|
306
393
|
}, [d]),
|
|
307
|
-
flush:
|
|
394
|
+
flush: f,
|
|
308
395
|
forceSetValue: n((e) => {
|
|
309
396
|
d(), c((t) => {
|
|
310
|
-
let n =
|
|
397
|
+
let n = g(e) ? e(t) : e;
|
|
311
398
|
return l.current = n, n;
|
|
312
399
|
});
|
|
313
400
|
}, [d])
|
|
@@ -316,10 +403,10 @@ function A(e, t, r = {}) {
|
|
|
316
403
|
}
|
|
317
404
|
//#endregion
|
|
318
405
|
//#region src/performance/useThrottler/useThrottledValue.ts
|
|
319
|
-
var
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { throttledFunc: c, cancel: l, flush: u, isPending: d } =
|
|
406
|
+
var F = globalThis.process?.env?.NODE_ENV !== "production";
|
|
407
|
+
function I(e, t, n = {}) {
|
|
408
|
+
F && n.equalityFn !== void 0 && typeof n.equalityFn != "function" && console.warn("[useThrottledValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
409
|
+
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { throttledFunc: c, cancel: l, flush: u, isPending: d } = M((e) => {
|
|
323
410
|
o((t) => i(t, e) ? t : e);
|
|
324
411
|
}, t, n);
|
|
325
412
|
return r(() => {
|
|
@@ -332,7 +419,7 @@ function M(e, t, n = {}) {
|
|
|
332
419
|
}
|
|
333
420
|
//#endregion
|
|
334
421
|
//#region src/shared/virtualShared/offsetCache.ts
|
|
335
|
-
var
|
|
422
|
+
var L = class {
|
|
336
423
|
_offsets = /* @__PURE__ */ new Float64Array();
|
|
337
424
|
_count = 0;
|
|
338
425
|
initializeOffsets(e, t) {
|
|
@@ -401,42 +488,42 @@ var N = class {
|
|
|
401
488
|
};
|
|
402
489
|
//#endregion
|
|
403
490
|
//#region src/shared/virtualShared/utils.ts
|
|
404
|
-
function
|
|
491
|
+
function R(e, t) {
|
|
405
492
|
let n = typeof t == "function" ? t(e) : t, r = Number(n);
|
|
406
493
|
return Number.isFinite(r) && r >= 0 ? r : 0;
|
|
407
494
|
}
|
|
408
|
-
function
|
|
495
|
+
function z(e, t, n) {
|
|
409
496
|
if (e <= 0) return 0;
|
|
410
497
|
if (typeof t == "number") return e * Math.max(0, t);
|
|
411
498
|
if (n) return n.getItemStartOffset(e);
|
|
412
499
|
let r = 0;
|
|
413
|
-
for (let n = 0; n < e; n++) r +=
|
|
500
|
+
for (let n = 0; n < e; n++) r += R(n, t);
|
|
414
501
|
return r;
|
|
415
502
|
}
|
|
416
|
-
function
|
|
503
|
+
function B(e, t, n) {
|
|
417
504
|
if (e <= 0) return 0;
|
|
418
505
|
if (typeof t == "number") return e * Math.max(0, t);
|
|
419
506
|
if (n) return n.getTotalSize();
|
|
420
507
|
let r = 0;
|
|
421
|
-
for (let n = 0; n < e; n++) r +=
|
|
508
|
+
for (let n = 0; n < e; n++) r += R(n, t);
|
|
422
509
|
return r;
|
|
423
510
|
}
|
|
424
|
-
function
|
|
511
|
+
function V(e, t) {
|
|
425
512
|
if (!e) return 0;
|
|
426
513
|
let n = t === "vertical";
|
|
427
514
|
return e instanceof Window ? n ? document.documentElement.clientHeight : document.documentElement.clientWidth : e instanceof Document ? n ? e.documentElement.clientHeight : e.documentElement.clientWidth : n ? e.clientHeight : e.clientWidth;
|
|
428
515
|
}
|
|
429
|
-
function
|
|
516
|
+
function H(e, t) {
|
|
430
517
|
if (!e) return 0;
|
|
431
518
|
let n = t === "vertical";
|
|
432
519
|
return e instanceof Window ? n ? e.scrollY : e.scrollX : e instanceof Document ? n ? e.documentElement.scrollTop : e.documentElement.scrollLeft : n ? e.scrollTop : e.scrollLeft;
|
|
433
520
|
}
|
|
434
|
-
function
|
|
521
|
+
function U(e) {
|
|
435
522
|
return e ? e instanceof Window ? document.documentElement : e instanceof Document ? e.scrollingElement ?? e.documentElement : e : null;
|
|
436
523
|
}
|
|
437
524
|
//#endregion
|
|
438
525
|
//#region src/performance/useVirtualGrid/utils.ts
|
|
439
|
-
function
|
|
526
|
+
function W(e, t, n, r, i, a) {
|
|
440
527
|
if (n <= 0 || t <= 0) return {
|
|
441
528
|
startIndex: 0,
|
|
442
529
|
endIndex: -1
|
|
@@ -452,7 +539,7 @@ function B(e, t, n, r, i, a) {
|
|
|
452
539
|
o = 0, s = -1;
|
|
453
540
|
let i = 0, a = !1;
|
|
454
541
|
for (let c = 0; c < n; c++) {
|
|
455
|
-
let n =
|
|
542
|
+
let n = R(c, r), l = i + n;
|
|
456
543
|
if (!a && l > e && (o = c, a = !0), a) if (i < e + t) s = c;
|
|
457
544
|
else break;
|
|
458
545
|
i += n;
|
|
@@ -464,8 +551,8 @@ function B(e, t, n, r, i, a) {
|
|
|
464
551
|
endIndex: s
|
|
465
552
|
};
|
|
466
553
|
}
|
|
467
|
-
function
|
|
468
|
-
let s = o ? o.getItemSize(e) :
|
|
554
|
+
function G(e, t, n, r, i, a, o) {
|
|
555
|
+
let s = o ? o.getItemSize(e) : R(e, a), c = z(e, a, o), l = c + s, u = Math.max(0, r - n), d;
|
|
469
556
|
switch (t) {
|
|
470
557
|
case "start":
|
|
471
558
|
d = c;
|
|
@@ -485,71 +572,71 @@ function V(e, t, n, r, i, a, o) {
|
|
|
485
572
|
}
|
|
486
573
|
//#endregion
|
|
487
574
|
//#region src/performance/useVirtualGrid/useVirtualGrid.ts
|
|
488
|
-
function
|
|
489
|
-
let { rowCount: c, colCount: l, estimateRowHeight: u, estimateColumnWidth:
|
|
575
|
+
function K(t) {
|
|
576
|
+
let { rowCount: c, colCount: l, estimateRowHeight: u, estimateColumnWidth: d, getScrollElement: f, overscanRows: p = 3, overscanCols: m = 3, scrollingDelay: g = 150, initialViewportHeight: _ = 0, initialViewportWidth: v = 0, initialScrollTop: y, initialScrollLeft: b, initialScrollRow: x, initialScrollCol: S, itemKey: C } = t, w = Math.max(0, Math.trunc(Number(c)) || 0), T = Math.max(0, Math.trunc(Number(l)) || 0), E = Math.max(0, Math.trunc(Number(p)) || 0), D = Math.max(0, Math.trunc(Number(m)) || 0), O = o(t);
|
|
490
577
|
i(() => {
|
|
491
578
|
O.current = t;
|
|
492
579
|
});
|
|
493
580
|
let k = a(() => {
|
|
494
581
|
if (typeof u != "function") return;
|
|
495
|
-
let e = new
|
|
582
|
+
let e = new L();
|
|
496
583
|
return e.initializeOffsets(w, u), e;
|
|
497
584
|
}, [w, u]), A = a(() => {
|
|
498
|
-
if (typeof
|
|
499
|
-
let e = new
|
|
500
|
-
return e.initializeOffsets(T,
|
|
501
|
-
}, [T,
|
|
585
|
+
if (typeof d != "function") return;
|
|
586
|
+
let e = new L();
|
|
587
|
+
return e.initializeOffsets(T, d), e;
|
|
588
|
+
}, [T, d]), j = o(k), M = o(A);
|
|
502
589
|
i(() => {
|
|
503
590
|
j.current = k;
|
|
504
591
|
}, [k]), i(() => {
|
|
505
592
|
M.current = A;
|
|
506
593
|
}, [A]);
|
|
507
|
-
let [
|
|
594
|
+
let [N, P] = s(() => {
|
|
508
595
|
if (typeof y == "number") return Math.max(0, y);
|
|
509
596
|
if (typeof x == "number" && w > 0) {
|
|
510
597
|
let e = Math.max(0, Math.min(Math.trunc(Number(x)) || 0, w - 1));
|
|
511
|
-
return k ? k.getItemStartOffset(e) :
|
|
598
|
+
return k ? k.getItemStartOffset(e) : z(e, u);
|
|
512
599
|
}
|
|
513
600
|
return 0;
|
|
514
|
-
}), [
|
|
601
|
+
}), [F, I] = s(() => {
|
|
515
602
|
if (typeof b == "number") return Math.max(0, b);
|
|
516
603
|
if (typeof S == "number" && T > 0) {
|
|
517
604
|
let e = Math.max(0, Math.min(Math.trunc(Number(S)) || 0, T - 1));
|
|
518
|
-
return A ? A.getItemStartOffset(e) :
|
|
605
|
+
return A ? A.getItemStartOffset(e) : z(e, d);
|
|
519
606
|
}
|
|
520
607
|
return 0;
|
|
521
|
-
}), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } =
|
|
608
|
+
}), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } = h(() => q(!1), g), Z = f();
|
|
522
609
|
r(() => {
|
|
523
610
|
if (!Z) return;
|
|
524
611
|
if (!Y.current) {
|
|
525
612
|
Y.current = !0;
|
|
526
613
|
let e = typeof y == "number" || typeof x == "number", t = typeof b == "number" || typeof S == "number";
|
|
527
614
|
if (e || t) {
|
|
528
|
-
let n =
|
|
615
|
+
let n = U(Z);
|
|
529
616
|
n && n.scrollTo({
|
|
530
|
-
...e && { top:
|
|
531
|
-
...t && { left:
|
|
617
|
+
...e && { top: N },
|
|
618
|
+
...t && { left: F },
|
|
532
619
|
behavior: "auto"
|
|
533
620
|
});
|
|
534
621
|
return;
|
|
535
622
|
}
|
|
536
623
|
}
|
|
537
|
-
let e =
|
|
538
|
-
|
|
624
|
+
let e = H(Z, "vertical"), t = H(Z, "horizontal");
|
|
625
|
+
P((t) => t === e ? t : e), I((e) => e === t ? e : t);
|
|
539
626
|
}, [
|
|
540
627
|
Z,
|
|
541
628
|
y,
|
|
542
629
|
b,
|
|
543
630
|
x,
|
|
544
631
|
S,
|
|
545
|
-
|
|
546
|
-
|
|
632
|
+
N,
|
|
633
|
+
F
|
|
547
634
|
]);
|
|
548
635
|
function ee() {
|
|
549
636
|
let { getScrollElement: e, scrollingDelay: t } = O.current, n = e();
|
|
550
637
|
if (!n) return;
|
|
551
|
-
let r =
|
|
552
|
-
|
|
638
|
+
let r = H(n, "vertical"), i = H(n, "horizontal");
|
|
639
|
+
P(r), I(i), (t ?? 150) > 0 && (q(!0), X());
|
|
553
640
|
}
|
|
554
641
|
e("scroll", ee, {
|
|
555
642
|
target: Z,
|
|
@@ -561,13 +648,13 @@ function H(t) {
|
|
|
561
648
|
let t = new ResizeObserver(e), n = Z instanceof Document ? Z.documentElement : Z;
|
|
562
649
|
return t.observe(n), () => t.disconnect();
|
|
563
650
|
}, [Z]);
|
|
564
|
-
let te =
|
|
651
|
+
let te = V(Z, "vertical") || _, ne = V(Z, "horizontal") || v, re = B(w, u, k), ie = B(T, d, A), { startIndex: Q, endIndex: ae } = W(N, te, w, u, E, k), { startIndex: $, endIndex: oe } = W(F, ne, T, d, D, A), se = [];
|
|
565
652
|
if (Q <= ae && $ <= oe) {
|
|
566
|
-
let e = k ? k.getItemStartOffset(Q) :
|
|
653
|
+
let e = k ? k.getItemStartOffset(Q) : z(Q, u);
|
|
567
654
|
for (let t = Q; t <= ae; t++) {
|
|
568
|
-
let n = k ? k.getItemSize(t) :
|
|
655
|
+
let n = k ? k.getItemSize(t) : R(t, u), r = A ? A.getItemStartOffset($) : z($, d);
|
|
569
656
|
for (let i = $; i <= oe; i++) {
|
|
570
|
-
let a = A ? A.getItemSize(i) :
|
|
657
|
+
let a = A ? A.getItemSize(i) : R(i, d), o = C ? C(t, i) : `${t}:${i}`;
|
|
571
658
|
se.push({
|
|
572
659
|
key: o,
|
|
573
660
|
rowIndex: t,
|
|
@@ -589,7 +676,7 @@ function H(t) {
|
|
|
589
676
|
scrollToOffset: n((e, t) => {
|
|
590
677
|
let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } = O.current, a = n();
|
|
591
678
|
if (!a) return;
|
|
592
|
-
let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } = O.current, u = Math.max(0, Math.trunc(Number(o)) || 0), d = Math.max(0, Math.trunc(Number(s)) || 0), f =
|
|
679
|
+
let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } = O.current, u = Math.max(0, Math.trunc(Number(o)) || 0), d = Math.max(0, Math.trunc(Number(s)) || 0), f = B(u, c, j.current), p = B(d, l, M.current), m = V(a, "vertical") || r || 0, h = V(a, "horizontal") || i || 0, g = Math.max(0, Math.min(e.top, Math.max(0, f - m))), _ = Math.max(0, Math.min(e.left, Math.max(0, p - h))), v = U(a);
|
|
593
680
|
v && v.scrollTo({
|
|
594
681
|
top: g,
|
|
595
682
|
left: _,
|
|
@@ -601,7 +688,7 @@ function H(t) {
|
|
|
601
688
|
if (!o) return;
|
|
602
689
|
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
603
690
|
if (s === 0) return;
|
|
604
|
-
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l =
|
|
691
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = V(o, "vertical") || a || 0, u = B(s, i, j.current), d = H(o, "vertical"), f = G(c, t?.align ?? "auto", l, u, d, i, j.current), p = U(o);
|
|
605
692
|
p && p.scrollTo({
|
|
606
693
|
top: f,
|
|
607
694
|
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
@@ -612,7 +699,7 @@ function H(t) {
|
|
|
612
699
|
if (!o) return;
|
|
613
700
|
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
614
701
|
if (s === 0) return;
|
|
615
|
-
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l =
|
|
702
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = V(o, "horizontal") || a || 0, u = B(s, i, M.current), d = H(o, "horizontal"), f = G(c, t?.align ?? "auto", l, u, d, i, M.current), p = U(o);
|
|
616
703
|
p && p.scrollTo({
|
|
617
704
|
left: f,
|
|
618
705
|
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
@@ -623,7 +710,7 @@ function H(t) {
|
|
|
623
710
|
if (!u) return;
|
|
624
711
|
let d = Math.max(0, Math.trunc(Number(i)) || 0), f = Math.max(0, Math.trunc(Number(a)) || 0);
|
|
625
712
|
if (d === 0 || f === 0) return;
|
|
626
|
-
let p = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, d - 1)), m = Math.max(0, Math.min(Math.trunc(Number(t)) || 0, f - 1)), h =
|
|
713
|
+
let p = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, d - 1)), m = Math.max(0, Math.min(Math.trunc(Number(t)) || 0, f - 1)), h = V(u, "vertical") || c || 0, g = V(u, "horizontal") || l || 0, _ = B(d, o, j.current), v = B(f, s, M.current), y = H(u, "vertical"), b = H(u, "horizontal"), x = G(p, n?.rowAlign ?? "auto", h, _, y, o, j.current), S = G(m, n?.colAlign ?? "auto", g, v, b, s, M.current), C = U(u);
|
|
627
714
|
C && C.scrollTo({
|
|
628
715
|
top: x,
|
|
629
716
|
left: S,
|
|
@@ -634,13 +721,13 @@ function H(t) {
|
|
|
634
721
|
}
|
|
635
722
|
//#endregion
|
|
636
723
|
//#region src/performance/useVirtualList/utils.ts
|
|
637
|
-
function
|
|
638
|
-
return
|
|
724
|
+
function q(e, t) {
|
|
725
|
+
return V(e, t ? "horizontal" : "vertical");
|
|
639
726
|
}
|
|
640
|
-
function
|
|
641
|
-
return
|
|
727
|
+
function J(e, t) {
|
|
728
|
+
return H(e, t ? "horizontal" : "vertical");
|
|
642
729
|
}
|
|
643
|
-
function
|
|
730
|
+
function Y(e, t, n, r, i, a, o, s) {
|
|
644
731
|
if (r <= 0 || t <= 0) return {
|
|
645
732
|
startIndex: 0,
|
|
646
733
|
endIndex: -1
|
|
@@ -660,7 +747,7 @@ function G(e, t, n, r, i, a, o, s) {
|
|
|
660
747
|
c = r, l = -1;
|
|
661
748
|
let a = 0;
|
|
662
749
|
for (let o = 0; o < r; o++) {
|
|
663
|
-
let r =
|
|
750
|
+
let r = R(o, i), s = n - a - r;
|
|
664
751
|
if (n - a <= e) break;
|
|
665
752
|
s < e + t && (o < c && (c = o), l = o), a += r;
|
|
666
753
|
}
|
|
@@ -669,7 +756,7 @@ function G(e, t, n, r, i, a, o, s) {
|
|
|
669
756
|
c = 0, l = -1;
|
|
670
757
|
let n = 0, a = !1;
|
|
671
758
|
for (let o = 0; o < r; o++) {
|
|
672
|
-
let r =
|
|
759
|
+
let r = R(o, i), s = n + r;
|
|
673
760
|
if (!a && s > e && (c = o, a = !0), a) if (n < e + t) l = o;
|
|
674
761
|
else break;
|
|
675
762
|
n += r;
|
|
@@ -681,8 +768,8 @@ function G(e, t, n, r, i, a, o, s) {
|
|
|
681
768
|
endIndex: l
|
|
682
769
|
};
|
|
683
770
|
}
|
|
684
|
-
function
|
|
685
|
-
let c = s ? s.getItemSize(e) :
|
|
771
|
+
function X(e, t, n, r, i, a, o, s) {
|
|
772
|
+
let c = s ? s.getItemSize(e) : R(e, a), l = z(e, a, s), u = o ? r - l - c : l, d = u + c, f = Math.max(0, r - n), p;
|
|
686
773
|
switch (t) {
|
|
687
774
|
case "start":
|
|
688
775
|
p = o ? Math.max(0, d - n) : u;
|
|
@@ -702,14 +789,14 @@ function K(e, t, n, r, i, a, o, s) {
|
|
|
702
789
|
}
|
|
703
790
|
//#endregion
|
|
704
791
|
//#region src/performance/useVirtualList/useVirtualList.ts
|
|
705
|
-
function
|
|
706
|
-
let { count: l, estimateSize: u, getScrollElement:
|
|
792
|
+
function Z(c) {
|
|
793
|
+
let { count: l, estimateSize: u, getScrollElement: d, overscan: f = 3, horizontal: p = !1, reverse: m = !1, scrollingDelay: g = 150, initialViewportSize: _ = 0, data: v, itemKey: y, initialOffset: b, initialScrollIndex: x } = c, S = Math.max(0, Math.trunc(Number(l)) || 0), C = Math.max(0, Math.trunc(Number(f)) || 0), w = o(c);
|
|
707
794
|
i(() => {
|
|
708
795
|
w.current = c;
|
|
709
796
|
});
|
|
710
797
|
let T = a(() => {
|
|
711
798
|
if (typeof u != "function") return;
|
|
712
|
-
let e = new
|
|
799
|
+
let e = new L();
|
|
713
800
|
return e.initializeOffsets(S, u), e;
|
|
714
801
|
}, [S, u]), E = o(T);
|
|
715
802
|
i(() => {
|
|
@@ -718,55 +805,55 @@ function q(c) {
|
|
|
718
805
|
let [D, O] = s(() => {
|
|
719
806
|
if (typeof b == "number") return Math.max(0, b);
|
|
720
807
|
if (typeof x == "number" && S > 0) {
|
|
721
|
-
let e = Math.max(0, Math.min(Math.trunc(Number(x)) || 0, S - 1)), t = T ? T.getItemStartOffset(e) :
|
|
722
|
-
if (
|
|
723
|
-
let n = T ? T.getItemSize(e) :
|
|
808
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(x)) || 0, S - 1)), t = T ? T.getItemStartOffset(e) : z(e, u);
|
|
809
|
+
if (m) {
|
|
810
|
+
let n = T ? T.getItemSize(e) : R(e, u), r = B(S, u, T);
|
|
724
811
|
return Math.max(0, r - t - n);
|
|
725
812
|
}
|
|
726
813
|
return t;
|
|
727
814
|
}
|
|
728
815
|
return 0;
|
|
729
|
-
}), [k, A] = s(!1), [, j] = s({}), M = o(!1), { debouncedFunc:
|
|
816
|
+
}), [k, A] = s(!1), [, j] = s({}), M = o(!1), { debouncedFunc: N } = h(() => A(!1), g), P = d();
|
|
730
817
|
r(() => {
|
|
731
|
-
if (!
|
|
818
|
+
if (!P) return;
|
|
732
819
|
if (!M.current && (M.current = !0, typeof b == "number" || typeof x == "number")) {
|
|
733
|
-
let e =
|
|
820
|
+
let e = U(P);
|
|
734
821
|
e && e.scrollTo({
|
|
735
|
-
[
|
|
822
|
+
[p ? "left" : "top"]: D,
|
|
736
823
|
behavior: "auto"
|
|
737
824
|
});
|
|
738
825
|
return;
|
|
739
826
|
}
|
|
740
|
-
let e =
|
|
827
|
+
let e = J(P, p);
|
|
741
828
|
O((t) => t === e ? t : e);
|
|
742
829
|
}, [
|
|
743
|
-
|
|
744
|
-
|
|
830
|
+
P,
|
|
831
|
+
p,
|
|
745
832
|
b,
|
|
746
833
|
x,
|
|
747
834
|
D
|
|
748
835
|
]);
|
|
749
|
-
function
|
|
836
|
+
function F() {
|
|
750
837
|
let { getScrollElement: e, horizontal: t } = w.current, n = e();
|
|
751
838
|
if (!n) return;
|
|
752
|
-
let r =
|
|
753
|
-
O(r), (w.current.scrollingDelay ?? 150) > 0 && (A(!0),
|
|
839
|
+
let r = J(n, t ?? !1);
|
|
840
|
+
O(r), (w.current.scrollingDelay ?? 150) > 0 && (A(!0), N());
|
|
754
841
|
}
|
|
755
|
-
e("scroll",
|
|
756
|
-
target:
|
|
842
|
+
e("scroll", F, {
|
|
843
|
+
target: P,
|
|
757
844
|
passive: !0
|
|
758
845
|
}), r(() => {
|
|
759
|
-
if (!
|
|
846
|
+
if (!P) return;
|
|
760
847
|
let e = () => j({});
|
|
761
|
-
if (
|
|
762
|
-
let t = new ResizeObserver(e), n =
|
|
848
|
+
if (P instanceof Window) return P.addEventListener("resize", e), () => P.removeEventListener("resize", e);
|
|
849
|
+
let t = new ResizeObserver(e), n = P instanceof Document ? P.documentElement : P;
|
|
763
850
|
return t.observe(n), () => t.disconnect();
|
|
764
|
-
}, [
|
|
765
|
-
let
|
|
766
|
-
if (
|
|
767
|
-
let e = T ? T.getItemStartOffset(
|
|
768
|
-
for (let n =
|
|
769
|
-
let r = T ? T.getItemSize(n) :
|
|
851
|
+
}, [P]);
|
|
852
|
+
let I = q(P, p) || _, V = B(S, u, T), { startIndex: H, endIndex: W } = Y(D, I, V, S, u, C, m, T), G = [];
|
|
853
|
+
if (H <= W) {
|
|
854
|
+
let e = T ? T.getItemStartOffset(H) : z(H, u);
|
|
855
|
+
for (let n = H; n <= W; n++) {
|
|
856
|
+
let r = T ? T.getItemSize(n) : R(n, u), i = m ? V - e - r : e, a = n;
|
|
770
857
|
if (y) {
|
|
771
858
|
if (typeof y == "function") a = y(n, v?.[n]);
|
|
772
859
|
else if (v && v[n] !== void 0 && v[n] !== null) {
|
|
@@ -774,7 +861,7 @@ function q(c) {
|
|
|
774
861
|
(typeof e == "string" || typeof e == "number") && (a = e);
|
|
775
862
|
}
|
|
776
863
|
}
|
|
777
|
-
|
|
864
|
+
G.push({
|
|
778
865
|
key: a,
|
|
779
866
|
index: n,
|
|
780
867
|
size: r,
|
|
@@ -782,30 +869,30 @@ function q(c) {
|
|
|
782
869
|
}), e += r;
|
|
783
870
|
}
|
|
784
871
|
}
|
|
785
|
-
let
|
|
872
|
+
let K = n((e, t) => {
|
|
786
873
|
let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } = w.current, o = n();
|
|
787
874
|
if (!o) return;
|
|
788
|
-
let s = r ?? !1, c =
|
|
875
|
+
let s = r ?? !1, c = q(o, s) || w.current.initialViewportSize || 0, l = E.current, u = B(Math.max(0, Math.trunc(Number(i)) || 0), a, l), d = Math.max(0, Math.min(e, Math.max(0, u - c))), f = U(o);
|
|
789
876
|
if (!f) return;
|
|
790
877
|
let p = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
791
878
|
s ? p.left = d : p.top = d, f.scrollTo(p);
|
|
792
879
|
}, []);
|
|
793
880
|
return {
|
|
794
|
-
virtualItems:
|
|
795
|
-
totalSize:
|
|
881
|
+
virtualItems: G,
|
|
882
|
+
totalSize: V,
|
|
796
883
|
isScrolling: k,
|
|
797
884
|
scrollToIndex: n((e, t) => {
|
|
798
885
|
let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } = w.current, s = n();
|
|
799
886
|
if (!s) return;
|
|
800
887
|
let c = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
801
888
|
if (c === 0) return;
|
|
802
|
-
let l = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, c - 1)), u = t?.align ?? "auto", d = a ?? !1, f = o ?? !1, p = E.current, m =
|
|
889
|
+
let l = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, c - 1)), u = t?.align ?? "auto", d = a ?? !1, f = o ?? !1, p = E.current, m = X(l, u, q(s, d) || w.current.initialViewportSize || 0, B(c, i, p), J(s, d), i, f, p), h = U(s);
|
|
803
890
|
if (!h) return;
|
|
804
891
|
let g = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
805
892
|
d ? g.left = m : g.top = m, h.scrollTo(g);
|
|
806
893
|
}, []),
|
|
807
|
-
scrollToOffset:
|
|
894
|
+
scrollToOffset: K
|
|
808
895
|
};
|
|
809
896
|
}
|
|
810
897
|
//#endregion
|
|
811
|
-
export {
|
|
898
|
+
export { M as a, E as c, b as d, v as f, d as h, P as i, w as l, p as m, K as n, A as o, h as p, I as r, O as s, Z as t, S as u };
|