@himanshu-sorathiya/react-kit 1.0.21 → 1.0.23
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/events.d.ts +30 -0
- package/dist/events.js +3 -2
- package/dist/events2.js +44 -31
- package/dist/index.d.ts +121 -1
- package/dist/index.js +6 -5
- package/dist/performance.d.ts +92 -0
- package/dist/performance.js +2 -2
- package/dist/performance2.js +571 -92
- package/dist/useEventListener.js +32 -0
- package/package.json +1 -1
package/dist/events.d.ts
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
import { RefObject } from 'react';
|
|
4
4
|
|
|
5
|
+
export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent | Event;
|
|
6
|
+
export type ClickOutsideTarget = HTMLElement | null;
|
|
7
|
+
export type ClickOutsideTargetRef = RefObject<ClickOutsideTarget> | ClickOutsideTarget;
|
|
8
|
+
export interface UseClickOutsideOptions {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
eventType?: string | string[];
|
|
11
|
+
}
|
|
12
|
+
export type UseClickOutsideReturn = void;
|
|
13
|
+
export declare function useClickOutside(target: ClickOutsideTargetRef | ClickOutsideTargetRef[], handler: (event: ClickOutsideEvent) => void, options?: UseClickOutsideOptions): UseClickOutsideReturn;
|
|
14
|
+
export type TargetType = EventTarget;
|
|
15
|
+
export type TargetRef<T extends TargetType> = RefObject<T | null> | T | null;
|
|
16
|
+
export interface UseEventListenerOptions<T extends TargetType> extends AddEventListenerOptions {
|
|
17
|
+
target?: TargetRef<T>;
|
|
18
|
+
}
|
|
19
|
+
export type UseEventListenerReturn = void;
|
|
20
|
+
export declare function useEventListener<K extends keyof WindowEventMap>(eventName: K | K[], handler: (event: WindowEventMap[K]) => void, options?: UseEventListenerOptions<Window> & {
|
|
21
|
+
target?: Window | null | undefined;
|
|
22
|
+
}): UseEventListenerReturn;
|
|
23
|
+
export declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K | K[], handler: (event: DocumentEventMap[K]) => void, options: UseEventListenerOptions<Document> & {
|
|
24
|
+
target: Document | RefObject<Document | null> | null;
|
|
25
|
+
}): UseEventListenerReturn;
|
|
26
|
+
export declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLElement>(eventName: K | K[], handler: (event: HTMLElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
27
|
+
target: T | RefObject<T | null> | null;
|
|
28
|
+
}): UseEventListenerReturn;
|
|
29
|
+
export declare function useEventListener<K extends keyof SVGElementEventMap, T extends SVGElement = SVGElement>(eventName: K | K[], handler: (event: SVGElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
30
|
+
target: T | RefObject<T | null> | null;
|
|
31
|
+
}): UseEventListenerReturn;
|
|
32
|
+
export declare function useEventListener<K extends string, T extends TargetType = TargetType>(eventName: K | K[], handler: (event: Event) => void, options: UseEventListenerOptions<T> & {
|
|
33
|
+
target: T | RefObject<T | null> | null;
|
|
34
|
+
}): UseEventListenerReturn;
|
|
5
35
|
declare const validKeyEventTypes: readonly [
|
|
6
36
|
"keydown",
|
|
7
37
|
"keyup",
|
package/dist/events.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { t as e } from "./
|
|
2
|
-
|
|
1
|
+
import { t as e } from "./useEventListener.js";
|
|
2
|
+
import { n as t, t as n } from "./events2.js";
|
|
3
|
+
export { t as useClickOutside, e as useEventListener, n as useKey };
|
package/dist/events2.js
CHANGED
|
@@ -1,44 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as e } from "./useEventListener.js";
|
|
2
|
+
import { useEffect as t, useLayoutEffect as n, useRef as r } from "react";
|
|
3
|
+
//#region src/events/useClickOutside/useClickOutside.ts
|
|
4
|
+
var i = typeof window < "u" ? n : t;
|
|
5
|
+
function a(t, n, a = {}) {
|
|
6
|
+
let { enabled: o = !0, eventType: s = ["mousedown", "touchstart"] } = a, c = r(n);
|
|
7
|
+
i(() => {
|
|
8
|
+
c.current = n;
|
|
9
|
+
}, [n]), e(s, (e) => {
|
|
10
|
+
o && (Array.isArray(t) ? t : [t]).every((t) => {
|
|
11
|
+
let n = t && "current" in t ? t.current : t;
|
|
12
|
+
return n && !n.contains(e.target);
|
|
13
|
+
}) && c.current(e);
|
|
14
|
+
}, { target: typeof document > "u" ? null : document });
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
2
17
|
//#region src/events/useKey/constants.ts
|
|
3
|
-
var
|
|
18
|
+
var o = [
|
|
4
19
|
"keydown",
|
|
5
20
|
"keyup",
|
|
6
21
|
"keypress"
|
|
7
|
-
];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
t(() => {
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function o() {
|
|
21
|
-
y.current = !1;
|
|
22
|
+
], s = typeof window < "u" ? n : t;
|
|
23
|
+
function c(e, n, { enabled: i = !0, preventDefault: a = !0, stopPropagation: c = !0, eventType: l = "keydown", preventRepeat: u = !1, ignoreWhenFocusedInInputs: d = !0, ctrlKey: f = !1, shiftKey: p = !1, altKey: m = !1, metaKey: h = !1, target: g } = {}) {
|
|
24
|
+
let _ = g === void 0 ? typeof window > "u" ? null : window : g, v = r(n), y = r(i), b = r(!1);
|
|
25
|
+
s(() => {
|
|
26
|
+
v.current = n;
|
|
27
|
+
}, [n]), t(() => {
|
|
28
|
+
y.current = i;
|
|
29
|
+
}, [i]), t(() => {
|
|
30
|
+
let t = _ && "current" in _ ? _.current : _;
|
|
31
|
+
if (!t) return;
|
|
32
|
+
let n = String(e || "").toLowerCase(), r = o.includes(l) ? l : "keydown", i = u && r !== "keyup";
|
|
33
|
+
function s() {
|
|
34
|
+
b.current = !1;
|
|
22
35
|
}
|
|
23
|
-
function
|
|
36
|
+
function g(e) {
|
|
24
37
|
if (!(e instanceof KeyboardEvent)) return;
|
|
25
|
-
let
|
|
26
|
-
(
|
|
38
|
+
let t = e.key.toLowerCase();
|
|
39
|
+
(t === n || f && t === "control" || p && t === "shift" || m && t === "alt" || h && t === "meta") && (b.current = !1);
|
|
27
40
|
}
|
|
28
41
|
function x(e) {
|
|
29
|
-
if (!(e instanceof KeyboardEvent) || !
|
|
30
|
-
let
|
|
31
|
-
if (!(d &&
|
|
32
|
-
if (
|
|
33
|
-
|
|
42
|
+
if (!(e instanceof KeyboardEvent) || !y.current) return;
|
|
43
|
+
let t = e.target;
|
|
44
|
+
if (!(d && t instanceof HTMLElement && (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement || t.isContentEditable)) && e.ctrlKey === f && e.shiftKey === p && e.altKey === m && e.metaKey === h && n === e.key.toLowerCase()) {
|
|
45
|
+
if (i && b.current) return;
|
|
46
|
+
b.current = !0, v.current(e), a && e.preventDefault(), c && e.stopPropagation();
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
|
-
return
|
|
37
|
-
|
|
49
|
+
return t.addEventListener(r, x), i && (t.addEventListener("keyup", g), window.addEventListener("blur", s)), () => {
|
|
50
|
+
t.removeEventListener(r, x), i && (t.removeEventListener("keyup", g), window.removeEventListener("blur", s));
|
|
38
51
|
};
|
|
39
52
|
}, [
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
e,
|
|
54
|
+
a,
|
|
42
55
|
c,
|
|
43
56
|
l,
|
|
44
57
|
u,
|
|
@@ -47,8 +60,8 @@ function i(i, a, { enabled: o = !0, preventDefault: s = !0, stopPropagation: c =
|
|
|
47
60
|
p,
|
|
48
61
|
m,
|
|
49
62
|
h,
|
|
50
|
-
|
|
63
|
+
_
|
|
51
64
|
]);
|
|
52
65
|
}
|
|
53
66
|
//#endregion
|
|
54
|
-
export {
|
|
67
|
+
export { a as n, c as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
3
|
import React$1 from 'react';
|
|
4
|
-
import { CSSProperties, RefObject } from 'react';
|
|
4
|
+
import { CSSProperties, Key, RefObject } from 'react';
|
|
5
5
|
|
|
6
6
|
export type DateInput = Date | number | string;
|
|
7
7
|
export type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
@@ -181,6 +181,36 @@ export declare function isAM(date: DateInput): boolean;
|
|
|
181
181
|
export declare function isPM(date: DateInput): boolean;
|
|
182
182
|
export declare function isLeapYear(yearOrDate: number | Date): boolean;
|
|
183
183
|
export declare function isInLeapYear(date: DateInput): boolean;
|
|
184
|
+
export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent | Event;
|
|
185
|
+
export type ClickOutsideTarget = HTMLElement | null;
|
|
186
|
+
export type ClickOutsideTargetRef = React$1.RefObject<ClickOutsideTarget> | ClickOutsideTarget;
|
|
187
|
+
export interface UseClickOutsideOptions {
|
|
188
|
+
enabled?: boolean;
|
|
189
|
+
eventType?: string | string[];
|
|
190
|
+
}
|
|
191
|
+
export type UseClickOutsideReturn = void;
|
|
192
|
+
export declare function useClickOutside(target: ClickOutsideTargetRef | ClickOutsideTargetRef[], handler: (event: ClickOutsideEvent) => void, options?: UseClickOutsideOptions): UseClickOutsideReturn;
|
|
193
|
+
export type TargetType = EventTarget;
|
|
194
|
+
export type TargetRef<T extends TargetType> = React$1.RefObject<T | null> | T | null;
|
|
195
|
+
export interface UseEventListenerOptions<T extends TargetType> extends AddEventListenerOptions {
|
|
196
|
+
target?: TargetRef<T>;
|
|
197
|
+
}
|
|
198
|
+
export type UseEventListenerReturn = void;
|
|
199
|
+
export declare function useEventListener<K extends keyof WindowEventMap>(eventName: K | K[], handler: (event: WindowEventMap[K]) => void, options?: UseEventListenerOptions<Window> & {
|
|
200
|
+
target?: Window | null | undefined;
|
|
201
|
+
}): UseEventListenerReturn;
|
|
202
|
+
export declare function useEventListener<K extends keyof DocumentEventMap>(eventName: K | K[], handler: (event: DocumentEventMap[K]) => void, options: UseEventListenerOptions<Document> & {
|
|
203
|
+
target: Document | React$1.RefObject<Document | null> | null;
|
|
204
|
+
}): UseEventListenerReturn;
|
|
205
|
+
export declare function useEventListener<K extends keyof HTMLElementEventMap, T extends HTMLElement = HTMLElement>(eventName: K | K[], handler: (event: HTMLElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
206
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
207
|
+
}): UseEventListenerReturn;
|
|
208
|
+
export declare function useEventListener<K extends keyof SVGElementEventMap, T extends SVGElement = SVGElement>(eventName: K | K[], handler: (event: SVGElementEventMap[K]) => void, options: UseEventListenerOptions<T> & {
|
|
209
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
210
|
+
}): UseEventListenerReturn;
|
|
211
|
+
export declare function useEventListener<K extends string, T extends TargetType = TargetType>(eventName: K | K[], handler: (event: Event) => void, options: UseEventListenerOptions<T> & {
|
|
212
|
+
target: T | React$1.RefObject<T | null> | null;
|
|
213
|
+
}): UseEventListenerReturn;
|
|
184
214
|
declare const validKeyEventTypes: readonly [
|
|
185
215
|
"keydown",
|
|
186
216
|
"keyup",
|
|
@@ -286,6 +316,96 @@ export type UseThrottledStateReturn<T> = [
|
|
|
286
316
|
export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: ThrottleOptions): UseThrottledStateReturn<T>;
|
|
287
317
|
export type UseThrottledValueReturn<T> = T;
|
|
288
318
|
export declare function useThrottledValue<T>(value: T, delay: number, options?: ThrottleOptions): UseThrottledValueReturn<T>;
|
|
319
|
+
export type ScrollAlign = "start" | "center" | "end" | "auto";
|
|
320
|
+
export type Axis = "vertical" | "horizontal";
|
|
321
|
+
export interface ScrollToOffsetOptions {
|
|
322
|
+
smooth?: boolean;
|
|
323
|
+
}
|
|
324
|
+
export interface ScrollToCellOptions {
|
|
325
|
+
rowAlign?: ScrollAlign;
|
|
326
|
+
colAlign?: ScrollAlign;
|
|
327
|
+
smooth?: boolean;
|
|
328
|
+
}
|
|
329
|
+
export interface ScrollToRowOptions {
|
|
330
|
+
align?: ScrollAlign;
|
|
331
|
+
smooth?: boolean;
|
|
332
|
+
}
|
|
333
|
+
export interface ScrollToColumnOptions {
|
|
334
|
+
align?: ScrollAlign;
|
|
335
|
+
smooth?: boolean;
|
|
336
|
+
}
|
|
337
|
+
export interface VirtualCell {
|
|
338
|
+
key: React$1.Key;
|
|
339
|
+
rowIndex: number;
|
|
340
|
+
colIndex: number;
|
|
341
|
+
height: number;
|
|
342
|
+
width: number;
|
|
343
|
+
top: number;
|
|
344
|
+
left: number;
|
|
345
|
+
}
|
|
346
|
+
export interface UseVirtualGridOptions {
|
|
347
|
+
rowCount: number;
|
|
348
|
+
colCount: number;
|
|
349
|
+
estimateRowHeight: number | ((rowIndex: number) => number);
|
|
350
|
+
estimateColumnWidth: number | ((colIndex: number) => number);
|
|
351
|
+
getScrollElement: () => HTMLElement | Window | Document | null;
|
|
352
|
+
overscanRows?: number;
|
|
353
|
+
overscanCols?: number;
|
|
354
|
+
scrollingDelay?: number;
|
|
355
|
+
initialViewportHeight?: number;
|
|
356
|
+
initialViewportWidth?: number;
|
|
357
|
+
initialScrollTop?: number;
|
|
358
|
+
initialScrollLeft?: number;
|
|
359
|
+
initialScrollRow?: number;
|
|
360
|
+
initialScrollCol?: number;
|
|
361
|
+
itemKey?: (rowIndex: number, colIndex: number) => React$1.Key;
|
|
362
|
+
}
|
|
363
|
+
export interface UseVirtualGridReturn {
|
|
364
|
+
virtualCells: VirtualCell[];
|
|
365
|
+
totalHeight: number;
|
|
366
|
+
totalWidth: number;
|
|
367
|
+
isScrolling: boolean;
|
|
368
|
+
scrollToCell: (rowIndex: number, colIndex: number, options?: ScrollToCellOptions) => void;
|
|
369
|
+
scrollToOffset: (offsets: {
|
|
370
|
+
top: number;
|
|
371
|
+
left: number;
|
|
372
|
+
}, options?: ScrollToOffsetOptions) => void;
|
|
373
|
+
scrollToRow: (rowIndex: number, options?: ScrollToRowOptions) => void;
|
|
374
|
+
scrollToColumn: (colIndex: number, options?: ScrollToColumnOptions) => void;
|
|
375
|
+
}
|
|
376
|
+
export declare function useVirtualGrid(options: UseVirtualGridOptions): UseVirtualGridReturn;
|
|
377
|
+
export interface ScrollToIndexOptions {
|
|
378
|
+
align?: ScrollAlign;
|
|
379
|
+
smooth?: boolean;
|
|
380
|
+
}
|
|
381
|
+
export interface VirtualItem {
|
|
382
|
+
key: React$1.Key;
|
|
383
|
+
index: number;
|
|
384
|
+
size: number;
|
|
385
|
+
start: number;
|
|
386
|
+
}
|
|
387
|
+
export interface UseVirtualListOptions<T = unknown> {
|
|
388
|
+
count: number;
|
|
389
|
+
estimateSize: number | ((index: number) => number);
|
|
390
|
+
getScrollElement: () => HTMLElement | Window | Document | null;
|
|
391
|
+
overscan?: number;
|
|
392
|
+
horizontal?: boolean;
|
|
393
|
+
reverse?: boolean;
|
|
394
|
+
scrollingDelay?: number;
|
|
395
|
+
initialViewportSize?: number;
|
|
396
|
+
initialOffset?: number;
|
|
397
|
+
initialScrollIndex?: number;
|
|
398
|
+
data?: T[];
|
|
399
|
+
itemKey?: string | string[] | ((index: number, item?: T) => React$1.Key);
|
|
400
|
+
}
|
|
401
|
+
export interface UseVirtualListReturn {
|
|
402
|
+
virtualItems: VirtualItem[];
|
|
403
|
+
totalSize: number;
|
|
404
|
+
isScrolling: boolean;
|
|
405
|
+
scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void;
|
|
406
|
+
scrollToOffset: (offset: number, options?: ScrollToOffsetOptions) => void;
|
|
407
|
+
}
|
|
408
|
+
export declare function useVirtualList<T = unknown>(options: UseVirtualListOptions<T>): UseVirtualListReturn;
|
|
289
409
|
export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
|
|
290
410
|
export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
|
|
291
411
|
export type NumberOperator = "equals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addBusinessDays as e, addDays as t, addHours as n, addMilliseconds as r, addMinutes as i, addMonths as a, addSeconds as o, addWeeks as s, addYears as c, clampDate as l, closestTo as u, createDate as d, differenceInBusinessDays as f, differenceInDays as p, differenceInHours as m, differenceInMilliseconds as h, differenceInMinutes as g, differenceInMonths as _, differenceInSeconds as v, differenceInWeeks as y, differenceInYears as b, durationToMilliseconds as x, eachDayOfInterval as S, eachMonthOfInterval as C, eachYearOfInterval as w, endOfDay as T, endOfHour as E, endOfMinute as D, endOfMonth as O, endOfQuarter as k, endOfWeek as A, endOfYear as j, format as M, formatDate as N, formatDuration as P, formatISO as F, formatISO9075 as I, formatRFC2822 as L, formatRFC3339 as R, formatRelativeTime as z, fromUnixTime as B, getDate as V, getDayOfWeek as H, getDayOfYear as U, getDaysInMonth as W, getHours as G, getISOWeek as K, getMilliseconds as q, getMinutes as J, getMonth as Y, getQuarter as X, getSeconds as Z, getTimestamp as Q, getYear as $, intervalToDuration as ee, isAM as te, isAfter as ne, isBefore as re, isDate as ie, isEqual as ae, isFirstDayOfMonth as oe, isFuture as se, isInLeapYear as ce, isLastDayOfMonth as le, isLeapYear as ue, isOverlapping as de, isPM as fe, isPast as pe, isSameDay as me, isSameHour as he, isSameMinute as ge, isSameMonth as _e, isSameQuarter as ve, isSameSecond as ye, isSameTime as be, isSameWeek as xe, isSameYear as Se, isThisMonth as Ce, isThisWeek as we, isThisYear as Te, isToday as Ee, isTomorrow as De, isValid as Oe, isWeekday as ke, isWeekend as Ae, isWithinRange as je, isYesterday as Me, max as Ne, min as Pe, parseISO as Fe, roundToNearestMinutes as Ie, setDate as Le, setHours as Re, setISOWeek as ze, setMilliseconds as Be, setMinutes as Ve, setMonth as He, setSeconds as Ue, setYear as We, startOfDay as Ge, startOfHour as Ke, startOfMinute as qe, startOfMonth as Je, startOfQuarter as Ye, startOfWeek as Xe, startOfYear as Ze, subDays as Qe, subHours as $e, subMilliseconds as et, subMinutes as tt, subMonths as nt, subSeconds as rt, subWeeks as it, subYears as at, toDate as ot, toISOString as st, toUnixTime as ct } from "./datetime.js";
|
|
2
|
-
import { t as lt } from "./
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
|
|
2
|
+
import { t as lt } from "./useEventListener.js";
|
|
3
|
+
import { n as ut, t as dt } from "./events2.js";
|
|
4
|
+
import { a as ft, c as pt, d as mt, f as ht, i as gt, l as _t, n as vt, o as yt, r as bt, s as xt, t as St, u as Ct } from "./performance2.js";
|
|
5
|
+
import { a as wt, c as Tt, i as Et, n as Dt, o as Ot, r as kt, s as At, t as jt } from "./state2.js";
|
|
6
|
+
import { a as Mt, c as Nt, i as Pt, n as Ft, o as It, r as Lt, s as Rt, t as zt } from "./ui2.js";
|
|
7
|
+
export { Nt as FuzzyHighlighter, Pt as ModalLayout, e as addBusinessDays, t as addDays, n as addHours, r as addMilliseconds, i as addMinutes, a as addMonths, o as addSeconds, s as addWeeks, c as addYears, l as clampDate, u as closestTo, d as createDate, f as differenceInBusinessDays, p as differenceInDays, m as differenceInHours, h as differenceInMilliseconds, g as differenceInMinutes, _ as differenceInMonths, v as differenceInSeconds, y as differenceInWeeks, b as differenceInYears, x as durationToMilliseconds, S as eachDayOfInterval, C as eachMonthOfInterval, w as eachYearOfInterval, T as endOfDay, E as endOfHour, D as endOfMinute, O as endOfMonth, k as endOfQuarter, A as endOfWeek, j as endOfYear, M as format, N as formatDate, P as formatDuration, F as formatISO, I as formatISO9075, L as formatRFC2822, R as formatRFC3339, z as formatRelativeTime, B as fromUnixTime, V as getDate, H as getDayOfWeek, U as getDayOfYear, W as getDaysInMonth, G as getHours, K as getISOWeek, q as getMilliseconds, J as getMinutes, Y as getMonth, X as getQuarter, Z as getSeconds, Q as getTimestamp, $ as getYear, ee as intervalToDuration, te as isAM, ne as isAfter, re as isBefore, ie as isDate, ae as isEqual, oe as isFirstDayOfMonth, se as isFuture, ce as isInLeapYear, le as isLastDayOfMonth, ue as isLeapYear, de as isOverlapping, fe as isPM, pe as isPast, me as isSameDay, he as isSameHour, ge as isSameMinute, _e as isSameMonth, ve as isSameQuarter, ye as isSameSecond, be as isSameTime, xe as isSameWeek, Se as isSameYear, Ce as isThisMonth, we as isThisWeek, Te as isThisYear, Ee as isToday, De as isTomorrow, Oe as isValid, ke as isWeekday, Ae as isWeekend, je as isWithinRange, Me as isYesterday, Ne as max, Pe as min, Fe as parseISO, Ie as roundToNearestMinutes, Le as setDate, Re as setHours, ze as setISOWeek, Be as setMilliseconds, Ve as setMinutes, He as setMonth, Ue as setSeconds, We as setYear, Ge as startOfDay, Ke as startOfHour, qe as startOfMinute, Je as startOfMonth, Ye as startOfQuarter, Xe as startOfWeek, Ze as startOfYear, Qe as subDays, $e as subHours, et as subMilliseconds, tt as subMinutes, nt as subMonths, rt as subSeconds, it as subWeeks, at as subYears, ot as toDate, st as toISOString, ct as toUnixTime, ut as useClickOutside, ht as useDebounce, mt as useDebouncedCallback, Ct as useDebouncedState, _t as useDebouncedValue, lt as useEventListener, Lt as useExpansion, Tt as useFilter, At as useFuzzySearch, Ot as useGrouping, dt as useKey, Mt as useModal, It as useModalActions, Rt as useModalState, wt as useMultipleSelection, Et as useOrder, kt as usePagination, Ft as usePin, pt as useRateLimit, xt as useRateLimitedCallback, Dt as useSingleSelection, jt as useSort, yt as useThrottle, ft as useThrottledCallback, gt as useThrottledState, bt as useThrottledValue, vt as useVirtualGrid, St as useVirtualList, zt as useVisibility };
|
package/dist/performance.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
import { Key } from 'react';
|
|
4
|
+
|
|
3
5
|
export interface DebounceOptions {
|
|
4
6
|
maxWait?: number;
|
|
5
7
|
leading?: boolean;
|
|
@@ -79,5 +81,95 @@ export type UseThrottledStateReturn<T> = [
|
|
|
79
81
|
export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: ThrottleOptions): UseThrottledStateReturn<T>;
|
|
80
82
|
export type UseThrottledValueReturn<T> = T;
|
|
81
83
|
export declare function useThrottledValue<T>(value: T, delay: number, options?: ThrottleOptions): UseThrottledValueReturn<T>;
|
|
84
|
+
export type ScrollAlign = "start" | "center" | "end" | "auto";
|
|
85
|
+
export type Axis = "vertical" | "horizontal";
|
|
86
|
+
export interface ScrollToOffsetOptions {
|
|
87
|
+
smooth?: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface ScrollToCellOptions {
|
|
90
|
+
rowAlign?: ScrollAlign;
|
|
91
|
+
colAlign?: ScrollAlign;
|
|
92
|
+
smooth?: boolean;
|
|
93
|
+
}
|
|
94
|
+
export interface ScrollToRowOptions {
|
|
95
|
+
align?: ScrollAlign;
|
|
96
|
+
smooth?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface ScrollToColumnOptions {
|
|
99
|
+
align?: ScrollAlign;
|
|
100
|
+
smooth?: boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface VirtualCell {
|
|
103
|
+
key: Key;
|
|
104
|
+
rowIndex: number;
|
|
105
|
+
colIndex: number;
|
|
106
|
+
height: number;
|
|
107
|
+
width: number;
|
|
108
|
+
top: number;
|
|
109
|
+
left: number;
|
|
110
|
+
}
|
|
111
|
+
export interface UseVirtualGridOptions {
|
|
112
|
+
rowCount: number;
|
|
113
|
+
colCount: number;
|
|
114
|
+
estimateRowHeight: number | ((rowIndex: number) => number);
|
|
115
|
+
estimateColumnWidth: number | ((colIndex: number) => number);
|
|
116
|
+
getScrollElement: () => HTMLElement | Window | Document | null;
|
|
117
|
+
overscanRows?: number;
|
|
118
|
+
overscanCols?: number;
|
|
119
|
+
scrollingDelay?: number;
|
|
120
|
+
initialViewportHeight?: number;
|
|
121
|
+
initialViewportWidth?: number;
|
|
122
|
+
initialScrollTop?: number;
|
|
123
|
+
initialScrollLeft?: number;
|
|
124
|
+
initialScrollRow?: number;
|
|
125
|
+
initialScrollCol?: number;
|
|
126
|
+
itemKey?: (rowIndex: number, colIndex: number) => Key;
|
|
127
|
+
}
|
|
128
|
+
export interface UseVirtualGridReturn {
|
|
129
|
+
virtualCells: VirtualCell[];
|
|
130
|
+
totalHeight: number;
|
|
131
|
+
totalWidth: number;
|
|
132
|
+
isScrolling: boolean;
|
|
133
|
+
scrollToCell: (rowIndex: number, colIndex: number, options?: ScrollToCellOptions) => void;
|
|
134
|
+
scrollToOffset: (offsets: {
|
|
135
|
+
top: number;
|
|
136
|
+
left: number;
|
|
137
|
+
}, options?: ScrollToOffsetOptions) => void;
|
|
138
|
+
scrollToRow: (rowIndex: number, options?: ScrollToRowOptions) => void;
|
|
139
|
+
scrollToColumn: (colIndex: number, options?: ScrollToColumnOptions) => void;
|
|
140
|
+
}
|
|
141
|
+
export declare function useVirtualGrid(options: UseVirtualGridOptions): UseVirtualGridReturn;
|
|
142
|
+
export interface ScrollToIndexOptions {
|
|
143
|
+
align?: ScrollAlign;
|
|
144
|
+
smooth?: boolean;
|
|
145
|
+
}
|
|
146
|
+
export interface VirtualItem {
|
|
147
|
+
key: Key;
|
|
148
|
+
index: number;
|
|
149
|
+
size: number;
|
|
150
|
+
start: number;
|
|
151
|
+
}
|
|
152
|
+
export interface UseVirtualListOptions<T = unknown> {
|
|
153
|
+
count: number;
|
|
154
|
+
estimateSize: number | ((index: number) => number);
|
|
155
|
+
getScrollElement: () => HTMLElement | Window | Document | null;
|
|
156
|
+
overscan?: number;
|
|
157
|
+
horizontal?: boolean;
|
|
158
|
+
reverse?: boolean;
|
|
159
|
+
scrollingDelay?: number;
|
|
160
|
+
initialViewportSize?: number;
|
|
161
|
+
initialOffset?: number;
|
|
162
|
+
initialScrollIndex?: number;
|
|
163
|
+
data?: T[];
|
|
164
|
+
itemKey?: string | string[] | ((index: number, item?: T) => Key);
|
|
165
|
+
}
|
|
166
|
+
export interface UseVirtualListReturn {
|
|
167
|
+
virtualItems: VirtualItem[];
|
|
168
|
+
totalSize: number;
|
|
169
|
+
isScrolling: boolean;
|
|
170
|
+
scrollToIndex: (index: number, options?: ScrollToIndexOptions) => void;
|
|
171
|
+
scrollToOffset: (offset: number, options?: ScrollToOffsetOptions) => void;
|
|
172
|
+
}
|
|
173
|
+
export declare function useVirtualList<T = unknown>(options: UseVirtualListOptions<T>): UseVirtualListReturn;
|
|
82
174
|
|
|
83
175
|
export {};
|
package/dist/performance.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, c as t,
|
|
2
|
-
export {
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "./performance2.js";
|
|
2
|
+
export { r as useDebounce, n as useDebouncedCallback, d as useDebouncedState, a as useDebouncedValue, t as useRateLimit, l as useRateLimitedCallback, s as useThrottle, e as useThrottledCallback, i as useThrottledState, c as useThrottledValue, o as useVirtualGrid, u as useVirtualList };
|
package/dist/performance2.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as e } from "./useEventListener.js";
|
|
2
|
+
import { t } from "./utils.js";
|
|
3
|
+
import { useCallback as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
2
4
|
//#region src/performance/useDebounce/useDebounce.ts
|
|
3
|
-
function
|
|
4
|
-
let
|
|
5
|
+
function c(e, t = {}) {
|
|
6
|
+
let i = Math.max(0, Number(e) || 0), [a, c] = s(!1), l = t?.maxWait, u = !!t?.leading, d = !u && t?.trailing === !1 ? !0 : t?.trailing ?? !u, f = o(null), p = o(null), m = o(null), h = o(-1), g = o(-1), _ = n(() => {
|
|
5
7
|
m.current &&= (clearTimeout(m.current), null), h.current = -1, g.current = -1, p.current = null, f.current = null, c(!1);
|
|
6
|
-
}, []), v =
|
|
8
|
+
}, []), v = n(() => {
|
|
7
9
|
m.current && f.current && p.current && (clearTimeout(m.current), m.current = null, f.current(...p.current), h.current = Date.now(), g.current = -1, p.current = null, f.current = null, c(!1));
|
|
8
10
|
}, []);
|
|
9
|
-
return
|
|
11
|
+
return r(() => () => {
|
|
10
12
|
_();
|
|
11
13
|
}, [_]), {
|
|
12
|
-
run:
|
|
14
|
+
run: n((e, ...t) => {
|
|
13
15
|
c(!0), g.current = Date.now(), p.current = t, f.current = e, h.current === -1 && (h.current = Date.now(), u === !0 && f.current(...t)), l !== void 0 && Date.now() - h.current >= l ? (m.current && clearTimeout(m.current), f.current && f.current(...t), h.current = -1, c(!1)) : (m.current && clearTimeout(m.current), m.current = setTimeout(() => {
|
|
14
16
|
g.current !== h.current && d !== !1 && f.current && p.current && f.current(...p.current), h.current = -1, c(!1);
|
|
15
|
-
},
|
|
17
|
+
}, i));
|
|
16
18
|
}, [
|
|
17
|
-
|
|
19
|
+
i,
|
|
18
20
|
l,
|
|
19
21
|
d,
|
|
20
22
|
u
|
|
21
23
|
]),
|
|
22
24
|
cancel: _,
|
|
23
25
|
flush: v,
|
|
24
|
-
isPending:
|
|
26
|
+
isPending: a
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
29
|
//#endregion
|
|
28
30
|
//#region src/performance/useDebounce/useDebouncedCallback.ts
|
|
29
|
-
function
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, [
|
|
34
|
-
let { run:
|
|
31
|
+
function l(e, t, i = {}) {
|
|
32
|
+
let a = o(e);
|
|
33
|
+
r(() => {
|
|
34
|
+
a.current = e;
|
|
35
|
+
}, [e]);
|
|
36
|
+
let { run: s, cancel: l, flush: u, isPending: d } = c(t, i);
|
|
35
37
|
return {
|
|
36
|
-
debouncedFunc:
|
|
37
|
-
|
|
38
|
-
}, [
|
|
38
|
+
debouncedFunc: n((...e) => {
|
|
39
|
+
s(a.current, ...e);
|
|
40
|
+
}, [s]),
|
|
39
41
|
cancel: l,
|
|
40
42
|
flush: u,
|
|
41
43
|
isPending: d
|
|
@@ -43,57 +45,57 @@ function a(r, a, o = {}) {
|
|
|
43
45
|
}
|
|
44
46
|
//#endregion
|
|
45
47
|
//#region src/performance/useDebounce/useDebouncedState.ts
|
|
46
|
-
function
|
|
47
|
-
let [
|
|
48
|
-
|
|
48
|
+
function u(e, t, n = {}) {
|
|
49
|
+
let [r, i] = s(e), { debouncedFunc: a, cancel: o, flush: c, isPending: u } = l((e) => {
|
|
50
|
+
i(e);
|
|
49
51
|
}, t, n);
|
|
50
52
|
return [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
r,
|
|
54
|
+
a,
|
|
53
55
|
{
|
|
54
56
|
isPending: u,
|
|
55
|
-
cancel:
|
|
56
|
-
flush:
|
|
57
|
-
forceSetValue:
|
|
57
|
+
cancel: o,
|
|
58
|
+
flush: c,
|
|
59
|
+
forceSetValue: i
|
|
58
60
|
}
|
|
59
61
|
];
|
|
60
62
|
}
|
|
61
63
|
//#endregion
|
|
62
64
|
//#region src/performance/useDebounce/useDebouncedValue.ts
|
|
63
|
-
function
|
|
64
|
-
let [
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
}, [e,
|
|
65
|
+
function d(e, t, n = {}) {
|
|
66
|
+
let [i, a] = s(e), { debouncedFunc: o } = l((e) => {
|
|
67
|
+
a(e);
|
|
68
|
+
}, t, n);
|
|
69
|
+
return r(() => {
|
|
70
|
+
o(e);
|
|
71
|
+
}, [e, o]), i;
|
|
70
72
|
}
|
|
71
73
|
//#endregion
|
|
72
74
|
//#region src/performance/useRateLimit/useRateLimit.ts
|
|
73
|
-
function
|
|
74
|
-
let
|
|
75
|
-
|
|
76
|
-
f.current =
|
|
77
|
-
}, [
|
|
78
|
-
let p =
|
|
79
|
-
return
|
|
75
|
+
function f(e, t, i) {
|
|
76
|
+
let a = Math.max(1, Number(e) || 1), c = Math.max(0, Number(t) || 0), [l, u] = s(a), d = i?.refillStrategy ?? "burst", f = o(i?.onRateLimitReached);
|
|
77
|
+
r(() => {
|
|
78
|
+
f.current = i?.onRateLimitReached;
|
|
79
|
+
}, [i?.onRateLimitReached]);
|
|
80
|
+
let p = o(a), [m] = s(() => Date.now()), h = o(m), g = o(null);
|
|
81
|
+
return r(() => () => {
|
|
80
82
|
g.current && clearTimeout(g.current);
|
|
81
83
|
}, []), {
|
|
82
|
-
run:
|
|
84
|
+
run: n((e, ...t) => {
|
|
83
85
|
let n = Date.now(), r = n - h.current;
|
|
84
|
-
if (d === "burst") r >= c && (p.current =
|
|
86
|
+
if (d === "burst") r >= c && (p.current = a, h.current = n);
|
|
85
87
|
else {
|
|
86
|
-
let e = c /
|
|
87
|
-
t > 0 && (p.current = Math.min(
|
|
88
|
+
let e = c / a, t = Math.floor(r / e);
|
|
89
|
+
t > 0 && (p.current = Math.min(a, p.current + t), h.current += t * e);
|
|
88
90
|
}
|
|
89
|
-
if (p.current > 0 ? (--p.current, u(p.current), e(...t)) : f.current && f.current(), g.current && clearTimeout(g.current), p.current <
|
|
90
|
-
let e = c /
|
|
91
|
+
if (p.current > 0 ? (--p.current, u(p.current), e(...t)) : f.current && f.current(), g.current && clearTimeout(g.current), p.current < a) {
|
|
92
|
+
let e = c / a, t = d === "burst" ? c - (Date.now() - h.current) : e - (Date.now() - h.current);
|
|
91
93
|
g.current = setTimeout(() => {
|
|
92
|
-
u((e) => Math.min(
|
|
94
|
+
u((e) => Math.min(a, e + 1)), h.current = Date.now(), p.current = Math.min(a, p.current + 1);
|
|
93
95
|
}, Math.max(0, t));
|
|
94
96
|
}
|
|
95
97
|
}, [
|
|
96
|
-
|
|
98
|
+
a,
|
|
97
99
|
c,
|
|
98
100
|
d
|
|
99
101
|
]),
|
|
@@ -103,96 +105,573 @@ function c(i, a, o) {
|
|
|
103
105
|
}
|
|
104
106
|
//#endregion
|
|
105
107
|
//#region src/performance/useRateLimit/useRateLimitedCallback.ts
|
|
106
|
-
function
|
|
107
|
-
let s =
|
|
108
|
-
|
|
109
|
-
s.current =
|
|
110
|
-
}, [
|
|
111
|
-
let { run:
|
|
108
|
+
function p(e, t, i, a) {
|
|
109
|
+
let s = o(e);
|
|
110
|
+
r(() => {
|
|
111
|
+
s.current = e;
|
|
112
|
+
}, [e]);
|
|
113
|
+
let { run: c, remaining: l, isRateLimited: u } = f(t, i, a);
|
|
112
114
|
return {
|
|
113
|
-
rateLimitedFunc:
|
|
114
|
-
|
|
115
|
-
}, [
|
|
116
|
-
remaining:
|
|
117
|
-
isRateLimited:
|
|
115
|
+
rateLimitedFunc: n((...e) => {
|
|
116
|
+
c(s.current, ...e);
|
|
117
|
+
}, [c]),
|
|
118
|
+
remaining: l,
|
|
119
|
+
isRateLimited: u
|
|
118
120
|
};
|
|
119
121
|
}
|
|
120
122
|
//#endregion
|
|
121
123
|
//#region src/performance/useThrottle/useThrottle.ts
|
|
122
|
-
function
|
|
123
|
-
let
|
|
124
|
+
function m(e, t = {}) {
|
|
125
|
+
let i = Math.max(0, Number(e) || 0), [a, c] = s(!1), l = t?.leading ?? !0, u = t?.trailing ?? !0;
|
|
124
126
|
l === !1 && u === !1 && (l = !0, u = !0);
|
|
125
|
-
let d =
|
|
127
|
+
let d = o(null), f = o(null), p = o(null), m = o(-1), h = n(() => {
|
|
126
128
|
p.current &&= (clearTimeout(p.current), null), m.current = -1, f.current = null, d.current = null, c(!1);
|
|
127
|
-
}, []), g =
|
|
129
|
+
}, []), g = n(() => {
|
|
128
130
|
f.current && d.current && (p.current &&= (clearTimeout(p.current), null), d.current(...f.current), m.current = l ? Date.now() : -1, f.current = null, d.current = null, c(!1));
|
|
129
131
|
}, [l]);
|
|
130
|
-
return
|
|
132
|
+
return r(() => () => {
|
|
131
133
|
h();
|
|
132
134
|
}, [h]), {
|
|
133
|
-
run:
|
|
135
|
+
run: n((e, ...t) => {
|
|
134
136
|
c(!0);
|
|
135
137
|
let n = Date.now();
|
|
136
|
-
if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >=
|
|
138
|
+
if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= i) p.current &&= (clearTimeout(p.current), null), d.current(...t), m.current = n, f.current = null, c(!1);
|
|
137
139
|
else if (!p.current) {
|
|
138
|
-
let e = m.current === -1 ? 0 : n - m.current, t =
|
|
140
|
+
let e = m.current === -1 ? 0 : n - m.current, t = i - e;
|
|
139
141
|
p.current = setTimeout(() => {
|
|
140
142
|
u && f.current && d.current ? (d.current(...f.current), m.current = l ? Date.now() : -1) : m.current = -1, f.current = null, d.current = null, p.current = null, c(!1);
|
|
141
143
|
}, t);
|
|
142
144
|
}
|
|
143
145
|
}, [
|
|
144
|
-
|
|
146
|
+
i,
|
|
145
147
|
l,
|
|
146
148
|
u
|
|
147
149
|
]),
|
|
148
150
|
cancel: h,
|
|
149
151
|
flush: g,
|
|
150
|
-
isPending:
|
|
152
|
+
isPending: a
|
|
151
153
|
};
|
|
152
154
|
}
|
|
153
155
|
//#endregion
|
|
154
156
|
//#region src/performance/useThrottle/useThrottledCallback.ts
|
|
155
|
-
function
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}, [
|
|
160
|
-
let { run: s, cancel: c, flush: l, isPending:
|
|
157
|
+
function h(e, t, i = {}) {
|
|
158
|
+
let a = o(e);
|
|
159
|
+
r(() => {
|
|
160
|
+
a.current = e;
|
|
161
|
+
}, [e]);
|
|
162
|
+
let { run: s, cancel: c, flush: l, isPending: u } = m(t, i);
|
|
161
163
|
return {
|
|
162
|
-
throttledFunc:
|
|
163
|
-
s(
|
|
164
|
+
throttledFunc: n((...e) => {
|
|
165
|
+
s(a.current, ...e);
|
|
164
166
|
}, [s]),
|
|
165
167
|
cancel: c,
|
|
166
168
|
flush: l,
|
|
167
|
-
isPending:
|
|
169
|
+
isPending: u
|
|
168
170
|
};
|
|
169
171
|
}
|
|
170
172
|
//#endregion
|
|
171
173
|
//#region src/performance/useThrottle/useThrottledState.ts
|
|
172
|
-
function
|
|
173
|
-
let [
|
|
174
|
-
|
|
174
|
+
function g(e, t, n = {}) {
|
|
175
|
+
let [r, i] = s(e), { throttledFunc: a, isPending: o, cancel: c, flush: l } = h((e) => {
|
|
176
|
+
i(e);
|
|
175
177
|
}, t, n);
|
|
176
178
|
return [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
r,
|
|
180
|
+
a,
|
|
179
181
|
{
|
|
180
|
-
isPending:
|
|
182
|
+
isPending: o,
|
|
181
183
|
cancel: c,
|
|
182
184
|
flush: l,
|
|
183
|
-
forceSetValue:
|
|
185
|
+
forceSetValue: i
|
|
184
186
|
}
|
|
185
187
|
];
|
|
186
188
|
}
|
|
187
189
|
//#endregion
|
|
188
190
|
//#region src/performance/useThrottle/useThrottledValue.ts
|
|
189
|
-
function
|
|
190
|
-
let [
|
|
191
|
+
function _(e, t, n = {}) {
|
|
192
|
+
let [i, a] = s(e), { throttledFunc: o } = h((e) => {
|
|
193
|
+
a(e);
|
|
194
|
+
}, t, n);
|
|
195
|
+
return r(() => {
|
|
191
196
|
o(e);
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
}, [e, o]), i;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/performance/virtualShared/offsetCache.ts
|
|
201
|
+
var v = class {
|
|
202
|
+
_offsets = /* @__PURE__ */ new Float64Array();
|
|
203
|
+
_count = 0;
|
|
204
|
+
initializeOffsets(e, t) {
|
|
205
|
+
this._count = e, this._offsets = new Float64Array(e + 1);
|
|
206
|
+
let n = 0;
|
|
207
|
+
for (let r = 0; r < e; r++) {
|
|
208
|
+
this._offsets[r] = n;
|
|
209
|
+
let e = t(r);
|
|
210
|
+
n += Number.isFinite(e) && e >= 0 ? e : 0;
|
|
211
|
+
}
|
|
212
|
+
this._offsets[e] = n;
|
|
213
|
+
}
|
|
214
|
+
getItemStartOffset(e) {
|
|
215
|
+
return e <= 0 ? 0 : e >= this._count ? this._offsets[this._count] ?? 0 : this._offsets[e] ?? 0;
|
|
216
|
+
}
|
|
217
|
+
getItemSize(e) {
|
|
218
|
+
return e < 0 || e >= this._count ? 0 : (this._offsets[e + 1] ?? 0) - (this._offsets[e] ?? 0);
|
|
219
|
+
}
|
|
220
|
+
getTotalSize() {
|
|
221
|
+
return this._offsets[this._count] ?? 0;
|
|
222
|
+
}
|
|
223
|
+
updateItemSize(e, t) {
|
|
224
|
+
if (e < 0 || e >= this._count) return;
|
|
225
|
+
let n = (Number.isFinite(t) && t >= 0 ? t : 0) - this.getItemSize(e);
|
|
226
|
+
if (n !== 0) for (let t = e + 1; t <= this._count; t++) this._offsets[t] = (this._offsets[t] ?? 0) + n;
|
|
227
|
+
}
|
|
228
|
+
findStartIndex(e) {
|
|
229
|
+
if (this._count === 0) return 0;
|
|
230
|
+
let t = 0, n = this._count - 1;
|
|
231
|
+
for (; t < n;) {
|
|
232
|
+
let r = t + n >>> 1;
|
|
233
|
+
(this._offsets[r + 1] ?? 0) <= e ? t = r + 1 : n = r;
|
|
234
|
+
}
|
|
235
|
+
return t;
|
|
236
|
+
}
|
|
237
|
+
findEndIndex(e) {
|
|
238
|
+
if (this._count === 0) return -1;
|
|
239
|
+
let t = 0, n = this._count - 1;
|
|
240
|
+
for (; t < n;) {
|
|
241
|
+
let r = (t + n >>> 1) + 1;
|
|
242
|
+
(this._offsets[r] ?? 0) < e ? t = r : n = r - 1;
|
|
243
|
+
}
|
|
244
|
+
return t;
|
|
245
|
+
}
|
|
246
|
+
getPhysicalStartReverse(e, t) {
|
|
247
|
+
return t - (this._offsets[e + 1] ?? 0);
|
|
248
|
+
}
|
|
249
|
+
findStartIndexReverse(e, t) {
|
|
250
|
+
if (this._count === 0) return 0;
|
|
251
|
+
let n = t - e, r = 0, i = this._count - 1;
|
|
252
|
+
for (; r < i;) {
|
|
253
|
+
let e = (r + i >>> 1) + 1;
|
|
254
|
+
(this._offsets[e] ?? 0) < n ? r = e : i = e - 1;
|
|
255
|
+
}
|
|
256
|
+
return (this._offsets[r] ?? 0) >= n ? 0 : r;
|
|
257
|
+
}
|
|
258
|
+
findEndIndexReverse(e, t) {
|
|
259
|
+
if (this._count === 0) return -1;
|
|
260
|
+
let n = t - e, r = 0, i = this._count - 1;
|
|
261
|
+
for (; r < i;) {
|
|
262
|
+
let e = r + i >>> 1;
|
|
263
|
+
(this._offsets[e + 1] ?? 0) > n ? i = e : r = e + 1;
|
|
264
|
+
}
|
|
265
|
+
return (this._offsets[r + 1] ?? 0) <= n ? -1 : r;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/performance/virtualShared/utils.ts
|
|
270
|
+
function y(e, t) {
|
|
271
|
+
let n = typeof t == "function" ? t(e) : t, r = Number(n);
|
|
272
|
+
return Number.isFinite(r) && r >= 0 ? r : 0;
|
|
273
|
+
}
|
|
274
|
+
function b(e, t, n) {
|
|
275
|
+
if (e <= 0) return 0;
|
|
276
|
+
if (typeof t == "number") return e * Math.max(0, t);
|
|
277
|
+
if (n) return n.getItemStartOffset(e);
|
|
278
|
+
let r = 0;
|
|
279
|
+
for (let n = 0; n < e; n++) r += y(n, t);
|
|
280
|
+
return r;
|
|
281
|
+
}
|
|
282
|
+
function x(e, t, n) {
|
|
283
|
+
if (e <= 0) return 0;
|
|
284
|
+
if (typeof t == "number") return e * Math.max(0, t);
|
|
285
|
+
if (n) return n.getTotalSize();
|
|
286
|
+
let r = 0;
|
|
287
|
+
for (let n = 0; n < e; n++) r += y(n, t);
|
|
288
|
+
return r;
|
|
289
|
+
}
|
|
290
|
+
function S(e, t) {
|
|
291
|
+
if (!e) return 0;
|
|
292
|
+
let n = t === "vertical";
|
|
293
|
+
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;
|
|
294
|
+
}
|
|
295
|
+
function C(e, t) {
|
|
296
|
+
if (!e) return 0;
|
|
297
|
+
let n = t === "vertical";
|
|
298
|
+
return e instanceof Window ? n ? e.scrollY : e.scrollX : e instanceof Document ? n ? e.documentElement.scrollTop : e.documentElement.scrollLeft : n ? e.scrollTop : e.scrollLeft;
|
|
299
|
+
}
|
|
300
|
+
function w(e) {
|
|
301
|
+
return e ? e instanceof Window ? document.documentElement : e instanceof Document ? e.scrollingElement ?? e.documentElement : e : null;
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/performance/useVirtualGrid/utils.ts
|
|
305
|
+
function T(e, t, n, r, i, a) {
|
|
306
|
+
if (n <= 0 || t <= 0) return {
|
|
307
|
+
startIndex: 0,
|
|
308
|
+
endIndex: -1
|
|
309
|
+
};
|
|
310
|
+
let o, s;
|
|
311
|
+
if (typeof r == "number") {
|
|
312
|
+
let i = Math.max(0, r);
|
|
313
|
+
i === 0 ? (o = 0, s = n - 1) : (o = Math.max(0, Math.floor(e / i)), s = Math.min(n - 1, Math.ceil((e + t) / i) - 1));
|
|
314
|
+
} else if (a) {
|
|
315
|
+
let n = e + t;
|
|
316
|
+
o = a.findStartIndex(e), s = a.findEndIndex(n);
|
|
317
|
+
} else {
|
|
318
|
+
o = 0, s = -1;
|
|
319
|
+
let i = 0, a = !1;
|
|
320
|
+
for (let c = 0; c < n; c++) {
|
|
321
|
+
let n = y(c, r), l = i + n;
|
|
322
|
+
if (!a && l > e && (o = c, a = !0), a) if (i < e + t) s = c;
|
|
323
|
+
else break;
|
|
324
|
+
i += n;
|
|
325
|
+
}
|
|
326
|
+
a || (o = 0, s = -1);
|
|
327
|
+
}
|
|
328
|
+
return o = Math.max(0, o - i), s = Math.min(n - 1, s + i), {
|
|
329
|
+
startIndex: o,
|
|
330
|
+
endIndex: s
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function E(e, t, n, r, i, a, o) {
|
|
334
|
+
let s = o ? o.getItemSize(e) : y(e, a), c = b(e, a, o), l = c + s, u = Math.max(0, r - n), d;
|
|
335
|
+
switch (t) {
|
|
336
|
+
case "start":
|
|
337
|
+
d = c;
|
|
338
|
+
break;
|
|
339
|
+
case "end":
|
|
340
|
+
d = Math.max(0, l - n);
|
|
341
|
+
break;
|
|
342
|
+
case "center":
|
|
343
|
+
d = Math.max(0, c + s / 2 - n / 2);
|
|
344
|
+
break;
|
|
345
|
+
default:
|
|
346
|
+
if (c >= i && l <= i + n) return i;
|
|
347
|
+
d = c < i ? c : Math.max(0, l - n);
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
return Math.max(0, Math.min(d, u));
|
|
351
|
+
}
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/performance/useVirtualGrid/useVirtualGrid.ts
|
|
354
|
+
function D(t) {
|
|
355
|
+
let { rowCount: c, colCount: u, estimateRowHeight: d, estimateColumnWidth: f, getScrollElement: p, overscanRows: m = 3, overscanCols: h = 3, scrollingDelay: g = 150, initialViewportHeight: _ = 0, initialViewportWidth: D = 0, initialScrollTop: O, initialScrollLeft: k, initialScrollRow: A, initialScrollCol: j, itemKey: M } = t, N = Math.max(0, Math.trunc(Number(c)) || 0), P = Math.max(0, Math.trunc(Number(u)) || 0), F = Math.max(0, Math.trunc(Number(m)) || 0), I = Math.max(0, Math.trunc(Number(h)) || 0), L = o(t);
|
|
356
|
+
i(() => {
|
|
357
|
+
L.current = t;
|
|
358
|
+
});
|
|
359
|
+
let R = a(() => {
|
|
360
|
+
if (typeof d != "function") return;
|
|
361
|
+
let e = new v();
|
|
362
|
+
return e.initializeOffsets(N, d), e;
|
|
363
|
+
}, [N, d]), z = a(() => {
|
|
364
|
+
if (typeof f != "function") return;
|
|
365
|
+
let e = new v();
|
|
366
|
+
return e.initializeOffsets(P, f), e;
|
|
367
|
+
}, [P, f]), B = o(R), V = o(z);
|
|
368
|
+
i(() => {
|
|
369
|
+
B.current = R;
|
|
370
|
+
}, [R]), i(() => {
|
|
371
|
+
V.current = z;
|
|
372
|
+
}, [z]);
|
|
373
|
+
let [H, U] = s(() => {
|
|
374
|
+
if (typeof O == "number") return Math.max(0, O);
|
|
375
|
+
if (typeof A == "number" && N > 0) {
|
|
376
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(A)) || 0, N - 1));
|
|
377
|
+
return R ? R.getItemStartOffset(e) : b(e, d);
|
|
378
|
+
}
|
|
379
|
+
return 0;
|
|
380
|
+
}), [W, G] = s(() => {
|
|
381
|
+
if (typeof k == "number") return Math.max(0, k);
|
|
382
|
+
if (typeof j == "number" && P > 0) {
|
|
383
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(j)) || 0, P - 1));
|
|
384
|
+
return z ? z.getItemStartOffset(e) : b(e, f);
|
|
385
|
+
}
|
|
386
|
+
return 0;
|
|
387
|
+
}), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } = l(() => q(!1), g), Z = p();
|
|
388
|
+
r(() => {
|
|
389
|
+
if (!Z) return;
|
|
390
|
+
if (!Y.current) {
|
|
391
|
+
Y.current = !0;
|
|
392
|
+
let e = typeof O == "number" || typeof A == "number", t = typeof k == "number" || typeof j == "number";
|
|
393
|
+
if (e || t) {
|
|
394
|
+
let n = w(Z);
|
|
395
|
+
n && n.scrollTo({
|
|
396
|
+
...e && { top: H },
|
|
397
|
+
...t && { left: W },
|
|
398
|
+
behavior: "auto"
|
|
399
|
+
});
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
let e = C(Z, "vertical"), t = C(Z, "horizontal");
|
|
404
|
+
U((t) => t === e ? t : e), G((e) => e === t ? e : t);
|
|
405
|
+
}, [
|
|
406
|
+
Z,
|
|
407
|
+
O,
|
|
408
|
+
k,
|
|
409
|
+
A,
|
|
410
|
+
j,
|
|
411
|
+
H,
|
|
412
|
+
W
|
|
413
|
+
]);
|
|
414
|
+
function ee() {
|
|
415
|
+
let { getScrollElement: e, scrollingDelay: t } = L.current, n = e();
|
|
416
|
+
if (!n) return;
|
|
417
|
+
let r = C(n, "vertical"), i = C(n, "horizontal");
|
|
418
|
+
U(r), G(i), (t ?? 150) > 0 && (q(!0), X());
|
|
419
|
+
}
|
|
420
|
+
e("scroll", ee, {
|
|
421
|
+
target: Z,
|
|
422
|
+
passive: !0
|
|
423
|
+
}), r(() => {
|
|
424
|
+
if (!Z) return;
|
|
425
|
+
let e = () => J({});
|
|
426
|
+
if (Z instanceof Window) return Z.addEventListener("resize", e), () => Z.removeEventListener("resize", e);
|
|
427
|
+
let t = new ResizeObserver(e), n = Z instanceof Document ? Z.documentElement : Z;
|
|
428
|
+
return t.observe(n), () => t.disconnect();
|
|
429
|
+
}, [Z]);
|
|
430
|
+
let te = S(Z, "vertical") || _, ne = S(Z, "horizontal") || D, re = x(N, d, R), ie = x(P, f, z), { startIndex: Q, endIndex: ae } = T(H, te, N, d, F, R), { startIndex: $, endIndex: oe } = T(W, ne, P, f, I, z), se = [];
|
|
431
|
+
if (Q <= ae && $ <= oe) {
|
|
432
|
+
let e = R ? R.getItemStartOffset(Q) : b(Q, d);
|
|
433
|
+
for (let t = Q; t <= ae; t++) {
|
|
434
|
+
let n = R ? R.getItemSize(t) : y(t, d), r = z ? z.getItemStartOffset($) : b($, f);
|
|
435
|
+
for (let i = $; i <= oe; i++) {
|
|
436
|
+
let a = z ? z.getItemSize(i) : y(i, f), o = M ? M(t, i) : `${t}:${i}`;
|
|
437
|
+
se.push({
|
|
438
|
+
key: o,
|
|
439
|
+
rowIndex: t,
|
|
440
|
+
colIndex: i,
|
|
441
|
+
height: n,
|
|
442
|
+
width: a,
|
|
443
|
+
top: e,
|
|
444
|
+
left: r
|
|
445
|
+
}), r += a;
|
|
446
|
+
}
|
|
447
|
+
e += n;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return {
|
|
451
|
+
virtualCells: se,
|
|
452
|
+
totalHeight: re,
|
|
453
|
+
totalWidth: ie,
|
|
454
|
+
isScrolling: K,
|
|
455
|
+
scrollToOffset: n((e, t) => {
|
|
456
|
+
let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } = L.current, a = n();
|
|
457
|
+
if (!a) return;
|
|
458
|
+
let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } = L.current, u = Math.max(0, Math.trunc(Number(o)) || 0), d = Math.max(0, Math.trunc(Number(s)) || 0), f = x(u, c, B.current), p = x(d, l, V.current), m = S(a, "vertical") || r || 0, h = S(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 = w(a);
|
|
459
|
+
v && v.scrollTo({
|
|
460
|
+
top: g,
|
|
461
|
+
left: _,
|
|
462
|
+
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
463
|
+
});
|
|
464
|
+
}, []),
|
|
465
|
+
scrollToRow: n((e, t) => {
|
|
466
|
+
let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a } = L.current, o = n();
|
|
467
|
+
if (!o) return;
|
|
468
|
+
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
469
|
+
if (s === 0) return;
|
|
470
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = S(o, "vertical") || a || 0, u = x(s, i, B.current), d = C(o, "vertical"), f = E(c, t?.align ?? "auto", l, u, d, i, B.current), p = w(o);
|
|
471
|
+
p && p.scrollTo({
|
|
472
|
+
top: f,
|
|
473
|
+
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
474
|
+
});
|
|
475
|
+
}, []),
|
|
476
|
+
scrollToColumn: n((e, t) => {
|
|
477
|
+
let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a } = L.current, o = n();
|
|
478
|
+
if (!o) return;
|
|
479
|
+
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
480
|
+
if (s === 0) return;
|
|
481
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = S(o, "horizontal") || a || 0, u = x(s, i, V.current), d = C(o, "horizontal"), f = E(c, t?.align ?? "auto", l, u, d, i, V.current), p = w(o);
|
|
482
|
+
p && p.scrollTo({
|
|
483
|
+
left: f,
|
|
484
|
+
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
485
|
+
});
|
|
486
|
+
}, []),
|
|
487
|
+
scrollToCell: n((e, t, n) => {
|
|
488
|
+
let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l } = L.current, u = r();
|
|
489
|
+
if (!u) return;
|
|
490
|
+
let d = Math.max(0, Math.trunc(Number(i)) || 0), f = Math.max(0, Math.trunc(Number(a)) || 0);
|
|
491
|
+
if (d === 0 || f === 0) return;
|
|
492
|
+
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 = S(u, "vertical") || c || 0, g = S(u, "horizontal") || l || 0, _ = x(d, o, B.current), v = x(f, s, V.current), y = C(u, "vertical"), b = C(u, "horizontal"), T = E(p, n?.rowAlign ?? "auto", h, _, y, o, B.current), D = E(m, n?.colAlign ?? "auto", g, v, b, s, V.current), O = w(u);
|
|
493
|
+
O && O.scrollTo({
|
|
494
|
+
top: T,
|
|
495
|
+
left: D,
|
|
496
|
+
behavior: n?.smooth === !0 ? "smooth" : "auto"
|
|
497
|
+
});
|
|
498
|
+
}, [])
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/performance/useVirtualList/utils.ts
|
|
503
|
+
function O(e, t) {
|
|
504
|
+
return S(e, t ? "horizontal" : "vertical");
|
|
505
|
+
}
|
|
506
|
+
function k(e, t) {
|
|
507
|
+
return C(e, t ? "horizontal" : "vertical");
|
|
508
|
+
}
|
|
509
|
+
function A(e, t, n, r, i, a, o, s) {
|
|
510
|
+
if (r <= 0 || t <= 0) return {
|
|
511
|
+
startIndex: 0,
|
|
512
|
+
endIndex: -1
|
|
513
|
+
};
|
|
514
|
+
let c, l;
|
|
515
|
+
if (typeof i == "number") {
|
|
516
|
+
let a = Math.max(0, i);
|
|
517
|
+
a === 0 ? (c = 0, l = r - 1) : o ? (c = Math.max(0, Math.floor((n - e - t) / a)), l = Math.min(r - 1, Math.ceil((n - e) / a) - 1)) : (c = Math.max(0, Math.floor(e / a)), l = Math.min(r - 1, Math.ceil((e + t) / a) - 1));
|
|
518
|
+
} else if (s) if (o) {
|
|
519
|
+
let r = e + t;
|
|
520
|
+
c = s.findStartIndexReverse(e, n), l = s.findEndIndexReverse(r, n);
|
|
521
|
+
} else {
|
|
522
|
+
let n = e + t;
|
|
523
|
+
c = s.findStartIndex(e), l = s.findEndIndex(n);
|
|
524
|
+
}
|
|
525
|
+
else if (o) {
|
|
526
|
+
c = r, l = -1;
|
|
527
|
+
let a = 0;
|
|
528
|
+
for (let o = 0; o < r; o++) {
|
|
529
|
+
let r = y(o, i), s = n - a - r;
|
|
530
|
+
if (n - a <= e) break;
|
|
531
|
+
s < e + t && (o < c && (c = o), l = o), a += r;
|
|
532
|
+
}
|
|
533
|
+
c === r && (c = 0, l = -1);
|
|
534
|
+
} else {
|
|
535
|
+
c = 0, l = -1;
|
|
536
|
+
let n = 0, a = !1;
|
|
537
|
+
for (let o = 0; o < r; o++) {
|
|
538
|
+
let r = y(o, i), s = n + r;
|
|
539
|
+
if (!a && s > e && (c = o, a = !0), a) if (n < e + t) l = o;
|
|
540
|
+
else break;
|
|
541
|
+
n += r;
|
|
542
|
+
}
|
|
543
|
+
a || (c = 0, l = -1);
|
|
544
|
+
}
|
|
545
|
+
return c = Math.max(0, c - a), l = Math.min(r - 1, l + a), {
|
|
546
|
+
startIndex: c,
|
|
547
|
+
endIndex: l
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function j(e, t, n, r, i, a, o, s) {
|
|
551
|
+
let c = s ? s.getItemSize(e) : y(e, a), l = b(e, a, s), u = o ? r - l - c : l, d = u + c, f = Math.max(0, r - n), p;
|
|
552
|
+
switch (t) {
|
|
553
|
+
case "start":
|
|
554
|
+
p = o ? Math.max(0, d - n) : u;
|
|
555
|
+
break;
|
|
556
|
+
case "end":
|
|
557
|
+
p = o ? u : Math.max(0, d - n);
|
|
558
|
+
break;
|
|
559
|
+
case "center":
|
|
560
|
+
p = Math.max(0, u + c / 2 - n / 2);
|
|
561
|
+
break;
|
|
562
|
+
default:
|
|
563
|
+
if (u >= i && d <= i + n) return i;
|
|
564
|
+
p = u < i ? o ? Math.max(0, d - n) : u : o ? u : Math.max(0, d - n);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
return Math.max(0, Math.min(p, f));
|
|
568
|
+
}
|
|
569
|
+
//#endregion
|
|
570
|
+
//#region src/performance/useVirtualList/useVirtualList.ts
|
|
571
|
+
function M(c) {
|
|
572
|
+
let { count: u, estimateSize: d, getScrollElement: f, overscan: p = 3, horizontal: m = !1, reverse: h = !1, scrollingDelay: g = 150, initialViewportSize: _ = 0, data: S, itemKey: C, initialOffset: T, initialScrollIndex: E } = c, D = Math.max(0, Math.trunc(Number(u)) || 0), M = Math.max(0, Math.trunc(Number(p)) || 0), N = o(c);
|
|
573
|
+
i(() => {
|
|
574
|
+
N.current = c;
|
|
575
|
+
});
|
|
576
|
+
let P = a(() => {
|
|
577
|
+
if (typeof d != "function") return;
|
|
578
|
+
let e = new v();
|
|
579
|
+
return e.initializeOffsets(D, d), e;
|
|
580
|
+
}, [D, d]), F = o(P);
|
|
581
|
+
i(() => {
|
|
582
|
+
F.current = P;
|
|
583
|
+
}, [P]);
|
|
584
|
+
let [I, L] = s(() => {
|
|
585
|
+
if (typeof T == "number") return Math.max(0, T);
|
|
586
|
+
if (typeof E == "number" && D > 0) {
|
|
587
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(E)) || 0, D - 1)), t = P ? P.getItemStartOffset(e) : b(e, d);
|
|
588
|
+
if (h) {
|
|
589
|
+
let n = P ? P.getItemSize(e) : y(e, d), r = x(D, d, P);
|
|
590
|
+
return Math.max(0, r - t - n);
|
|
591
|
+
}
|
|
592
|
+
return t;
|
|
593
|
+
}
|
|
594
|
+
return 0;
|
|
595
|
+
}), [R, z] = s(!1), [, B] = s({}), V = o(!1), { debouncedFunc: H } = l(() => z(!1), g), U = f();
|
|
596
|
+
r(() => {
|
|
597
|
+
if (!U) return;
|
|
598
|
+
if (!V.current && (V.current = !0, typeof T == "number" || typeof E == "number")) {
|
|
599
|
+
let e = w(U);
|
|
600
|
+
e && e.scrollTo({
|
|
601
|
+
[m ? "left" : "top"]: I,
|
|
602
|
+
behavior: "auto"
|
|
603
|
+
});
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
let e = k(U, m);
|
|
607
|
+
L((t) => t === e ? t : e);
|
|
608
|
+
}, [
|
|
609
|
+
U,
|
|
610
|
+
m,
|
|
611
|
+
T,
|
|
612
|
+
E,
|
|
613
|
+
I
|
|
614
|
+
]);
|
|
615
|
+
function W() {
|
|
616
|
+
let { getScrollElement: e, horizontal: t } = N.current, n = e();
|
|
617
|
+
if (!n) return;
|
|
618
|
+
let r = k(n, t ?? !1);
|
|
619
|
+
L(r), (N.current.scrollingDelay ?? 150) > 0 && (z(!0), H());
|
|
620
|
+
}
|
|
621
|
+
e("scroll", W, {
|
|
622
|
+
target: U,
|
|
623
|
+
passive: !0
|
|
624
|
+
}), r(() => {
|
|
625
|
+
if (!U) return;
|
|
626
|
+
let e = () => B({});
|
|
627
|
+
if (U instanceof Window) return U.addEventListener("resize", e), () => U.removeEventListener("resize", e);
|
|
628
|
+
let t = new ResizeObserver(e), n = U instanceof Document ? U.documentElement : U;
|
|
629
|
+
return t.observe(n), () => t.disconnect();
|
|
630
|
+
}, [U]);
|
|
631
|
+
let G = O(U, m) || _, K = x(D, d, P), { startIndex: q, endIndex: J } = A(I, G, K, D, d, M, h, P), Y = [];
|
|
632
|
+
if (q <= J) {
|
|
633
|
+
let e = P ? P.getItemStartOffset(q) : b(q, d);
|
|
634
|
+
for (let n = q; n <= J; n++) {
|
|
635
|
+
let r = P ? P.getItemSize(n) : y(n, d), i = h ? K - e - r : e, a = n;
|
|
636
|
+
if (C) {
|
|
637
|
+
if (typeof C == "function") a = C(n, S?.[n]);
|
|
638
|
+
else if (S && S[n] !== void 0 && S[n] !== null) {
|
|
639
|
+
let e = t(S[n], C);
|
|
640
|
+
(typeof e == "string" || typeof e == "number") && (a = e);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
Y.push({
|
|
644
|
+
key: a,
|
|
645
|
+
index: n,
|
|
646
|
+
size: r,
|
|
647
|
+
start: i
|
|
648
|
+
}), e += r;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
let X = n((e, t) => {
|
|
652
|
+
let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } = N.current, o = n();
|
|
653
|
+
if (!o) return;
|
|
654
|
+
let s = r ?? !1, c = O(o, s) || N.current.initialViewportSize || 0, l = F.current, u = x(Math.max(0, Math.trunc(Number(i)) || 0), a, l), d = Math.max(0, Math.min(e, Math.max(0, u - c))), f = w(o);
|
|
655
|
+
if (!f) return;
|
|
656
|
+
let p = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
657
|
+
s ? p.left = d : p.top = d, f.scrollTo(p);
|
|
658
|
+
}, []);
|
|
659
|
+
return {
|
|
660
|
+
virtualItems: Y,
|
|
661
|
+
totalSize: K,
|
|
662
|
+
isScrolling: R,
|
|
663
|
+
scrollToIndex: n((e, t) => {
|
|
664
|
+
let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } = N.current, s = n();
|
|
665
|
+
if (!s) return;
|
|
666
|
+
let c = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
667
|
+
if (c === 0) return;
|
|
668
|
+
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 = F.current, m = j(l, u, O(s, d) || N.current.initialViewportSize || 0, x(c, i, p), k(s, d), i, f, p), h = w(s);
|
|
669
|
+
if (!h) return;
|
|
670
|
+
let g = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
671
|
+
d ? g.left = m : g.top = m, h.scrollTo(g);
|
|
672
|
+
}, []),
|
|
673
|
+
scrollToOffset: X
|
|
674
|
+
};
|
|
196
675
|
}
|
|
197
676
|
//#endregion
|
|
198
|
-
export {
|
|
677
|
+
export { h as a, f as c, l as d, c as f, g as i, d as l, D as n, m as o, _ as r, p as s, M as t, u };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useEffect as e, useLayoutEffect as t, useRef as n } from "react";
|
|
2
|
+
//#region src/events/useEventListener/useEventListener.ts
|
|
3
|
+
var r = typeof window < "u" ? t : e;
|
|
4
|
+
function i(t, i, a = {}) {
|
|
5
|
+
let { target: o, capture: s = !1, passive: c = !1, once: l = !1 } = a, u = o === void 0 ? typeof window > "u" ? null : window : o, d = n(i);
|
|
6
|
+
r(() => {
|
|
7
|
+
d.current = i;
|
|
8
|
+
}, [i]), e(() => {
|
|
9
|
+
let e = u && "current" in u ? u.current : u;
|
|
10
|
+
if (!e?.addEventListener) return;
|
|
11
|
+
let n = Array.isArray(t) ? t : [t], r = (e) => d.current(e);
|
|
12
|
+
return n.forEach((t) => {
|
|
13
|
+
e.addEventListener(t, r, {
|
|
14
|
+
capture: s,
|
|
15
|
+
passive: c,
|
|
16
|
+
once: l
|
|
17
|
+
});
|
|
18
|
+
}), () => {
|
|
19
|
+
n.forEach((t) => {
|
|
20
|
+
e.removeEventListener(t, r, { capture: s });
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}, [
|
|
24
|
+
Array.isArray(t) ? t.join(",") : t,
|
|
25
|
+
u,
|
|
26
|
+
s,
|
|
27
|
+
c,
|
|
28
|
+
l
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { i as t };
|