@himanshu-sorathiya/react-kit 1.0.20 → 1.0.22
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 +2 -2
- package/dist/events2.js +72 -30
- package/dist/index.d.ts +43 -13
- package/dist/index.js +5 -5
- package/dist/performance2.js +55 -55
- package/dist/state.d.ts +8 -8
- package/dist/state2.js +193 -191
- package/dist/ui.d.ts +5 -5
- package/dist/ui2.js +177 -177
- 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,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as useKey };
|
|
1
|
+
import { n as e, r as t, t as n } from "./events2.js";
|
|
2
|
+
export { e as useClickOutside, t as useEventListener, n as useKey };
|
package/dist/events2.js
CHANGED
|
@@ -1,45 +1,87 @@
|
|
|
1
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
|
+
//#region src/events/useClickOutside/useClickOutside.ts
|
|
33
|
+
var a = typeof window < "u" ? t : e;
|
|
34
|
+
function o(e, t, r = {}) {
|
|
35
|
+
let { enabled: o = !0, eventType: s = ["mousedown", "touchstart"] } = r, c = n(t);
|
|
36
|
+
a(() => {
|
|
37
|
+
c.current = t;
|
|
38
|
+
}, [t]), i(s, (t) => {
|
|
39
|
+
o && (Array.isArray(e) ? e : [e]).every((e) => {
|
|
40
|
+
let n = e && "current" in e ? e.current : e;
|
|
41
|
+
return n && !n.contains(t.target);
|
|
42
|
+
}) && c.current(t);
|
|
43
|
+
}, { target: typeof document > "u" ? null : document });
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
2
46
|
//#region src/events/useKey/constants.ts
|
|
3
|
-
var
|
|
47
|
+
var s = [
|
|
4
48
|
"keydown",
|
|
5
49
|
"keyup",
|
|
6
50
|
"keypress"
|
|
7
|
-
];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, [
|
|
15
|
-
|
|
16
|
-
}, [o]), e(() => {
|
|
17
|
-
let e = g && "current" in g ? g.current : g;
|
|
51
|
+
], c = typeof window < "u" ? t : e;
|
|
52
|
+
function l(t, r, { enabled: i = !0, preventDefault: a = !0, stopPropagation: o = !0, eventType: l = "keydown", preventRepeat: u = !1, ignoreWhenFocusedInInputs: d = !0, ctrlKey: f = !1, shiftKey: p = !1, altKey: m = !1, metaKey: h = !1, target: g } = {}) {
|
|
53
|
+
let _ = g === void 0 ? typeof window > "u" ? null : window : g, v = n(r), y = n(i), b = n(!1);
|
|
54
|
+
c(() => {
|
|
55
|
+
v.current = r;
|
|
56
|
+
}, [r]), e(() => {
|
|
57
|
+
y.current = i;
|
|
58
|
+
}, [i]), e(() => {
|
|
59
|
+
let e = _ && "current" in _ ? _.current : _;
|
|
18
60
|
if (!e) return;
|
|
19
|
-
let
|
|
20
|
-
function
|
|
21
|
-
|
|
61
|
+
let n = String(t || "").toLowerCase(), r = s.includes(l) ? l : "keydown", i = u && r !== "keyup";
|
|
62
|
+
function c() {
|
|
63
|
+
b.current = !1;
|
|
22
64
|
}
|
|
23
|
-
function
|
|
65
|
+
function g(e) {
|
|
24
66
|
if (!(e instanceof KeyboardEvent)) return;
|
|
25
|
-
let
|
|
26
|
-
(
|
|
67
|
+
let t = e.key.toLowerCase();
|
|
68
|
+
(t === n || f && t === "control" || p && t === "shift" || m && t === "alt" || h && t === "meta") && (b.current = !1);
|
|
27
69
|
}
|
|
28
70
|
function x(e) {
|
|
29
|
-
if (!(e instanceof KeyboardEvent) || !
|
|
30
|
-
let
|
|
31
|
-
if (!(d &&
|
|
32
|
-
if (
|
|
33
|
-
|
|
71
|
+
if (!(e instanceof KeyboardEvent) || !y.current) return;
|
|
72
|
+
let t = e.target;
|
|
73
|
+
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()) {
|
|
74
|
+
if (i && b.current) return;
|
|
75
|
+
b.current = !0, v.current(e), a && e.preventDefault(), o && e.stopPropagation();
|
|
34
76
|
}
|
|
35
77
|
}
|
|
36
|
-
return e.addEventListener(
|
|
37
|
-
e.removeEventListener(
|
|
78
|
+
return e.addEventListener(r, x), i && (e.addEventListener("keyup", g), window.addEventListener("blur", c)), () => {
|
|
79
|
+
e.removeEventListener(r, x), i && (e.removeEventListener("keyup", g), window.removeEventListener("blur", c));
|
|
38
80
|
};
|
|
39
81
|
}, [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
82
|
+
t,
|
|
83
|
+
a,
|
|
84
|
+
o,
|
|
43
85
|
l,
|
|
44
86
|
u,
|
|
45
87
|
d,
|
|
@@ -47,8 +89,8 @@ function i(i, a, { enabled: o = !0, preventDefault: s = !0, stopPropagation: c =
|
|
|
47
89
|
p,
|
|
48
90
|
m,
|
|
49
91
|
h,
|
|
50
|
-
|
|
92
|
+
_
|
|
51
93
|
]);
|
|
52
94
|
}
|
|
53
95
|
//#endregion
|
|
54
|
-
export { i as t };
|
|
96
|
+
export { o as n, i as r, l as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -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",
|
|
@@ -361,7 +391,7 @@ export interface UseFilterReturn<T> {
|
|
|
361
391
|
updateFilterValue: (id: string, value: unknown) => void;
|
|
362
392
|
isFilterActive: (id: string) => boolean;
|
|
363
393
|
}
|
|
364
|
-
export declare function useFilter<T>(data
|
|
394
|
+
export declare function useFilter<T>(data?: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
|
|
365
395
|
export interface FuzzySearchOptions {
|
|
366
396
|
threshold?: number;
|
|
367
397
|
caseSensitive?: boolean;
|
|
@@ -404,8 +434,8 @@ export interface UseGroupingReturn<T> {
|
|
|
404
434
|
resetGrouping: () => void;
|
|
405
435
|
getGroupItems: (groupKey: string) => T[];
|
|
406
436
|
}
|
|
407
|
-
export declare function useGrouping<T = unknown>(
|
|
408
|
-
items
|
|
437
|
+
export declare function useGrouping<T = unknown>(options?: {
|
|
438
|
+
items?: T[];
|
|
409
439
|
initialGroupBy?: string;
|
|
410
440
|
}): UseGroupingReturn<T>;
|
|
411
441
|
export type SelectionId = string | number;
|
|
@@ -428,8 +458,8 @@ export interface UseMultipleSelectionReturn<T> {
|
|
|
428
458
|
deselectMultiple: (itemsToRemove: SelectionId[] | T[]) => void;
|
|
429
459
|
retainOnly: (itemsToRetain: SelectionId[] | T[]) => void;
|
|
430
460
|
}
|
|
431
|
-
export declare function useMultipleSelection<T = unknown>(
|
|
432
|
-
items
|
|
461
|
+
export declare function useMultipleSelection<T = unknown>(options?: {
|
|
462
|
+
items?: T[];
|
|
433
463
|
field?: string;
|
|
434
464
|
initialSelectedIds?: SelectionId[];
|
|
435
465
|
}): UseMultipleSelectionReturn<T>;
|
|
@@ -446,7 +476,7 @@ export interface UseOrderReturn<T> {
|
|
|
446
476
|
resetOrder: () => void;
|
|
447
477
|
replaceOrder: (newOrderedItems: T[]) => void;
|
|
448
478
|
}
|
|
449
|
-
export declare function useOrder<T>(initialItems
|
|
479
|
+
export declare function useOrder<T>(initialItems?: T[]): UseOrderReturn<T>;
|
|
450
480
|
export interface UsePaginationReturn<T> {
|
|
451
481
|
pageItems: T[];
|
|
452
482
|
pageSize: number;
|
|
@@ -464,7 +494,7 @@ export interface UsePaginationReturn<T> {
|
|
|
464
494
|
resetPageSize: () => void;
|
|
465
495
|
resetPagination: () => void;
|
|
466
496
|
}
|
|
467
|
-
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
497
|
+
export declare function usePagination<T>(data: T[] | undefined, initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
468
498
|
type SelectionId$1 = string | number;
|
|
469
499
|
export interface UseSingleSelectionReturn {
|
|
470
500
|
selectedId: SelectionId$1 | undefined;
|
|
@@ -516,7 +546,7 @@ export interface UseSortReturn<T> {
|
|
|
516
546
|
getNextSortingOrder: (id: string) => "asc" | "desc" | "none";
|
|
517
547
|
getSortIndex: (id: string) => number | undefined;
|
|
518
548
|
}
|
|
519
|
-
export declare function useSort<T>(data
|
|
549
|
+
export declare function useSort<T>(data?: T[], initialSorts?: SortState): UseSortReturn<T>;
|
|
520
550
|
export interface FuzzyHighlighterProps {
|
|
521
551
|
text: string;
|
|
522
552
|
query: string;
|
|
@@ -546,7 +576,7 @@ export interface UseExpansionReturn<T> {
|
|
|
546
576
|
resetExpansion: () => void;
|
|
547
577
|
replaceExpansion: (newExpandedItems: ExpansionId[] | T[]) => void;
|
|
548
578
|
}
|
|
549
|
-
export declare function useExpansion<T = unknown>(
|
|
579
|
+
export declare function useExpansion<T = unknown>(options?: {
|
|
550
580
|
items?: T[];
|
|
551
581
|
field?: string;
|
|
552
582
|
initialExpandedIds?: ExpansionId[];
|
|
@@ -584,8 +614,8 @@ export interface UsePinReturn<T> {
|
|
|
584
614
|
pinMultiple: (newItems: PinId[] | T[]) => void;
|
|
585
615
|
unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
|
|
586
616
|
}
|
|
587
|
-
export declare function usePin<T = unknown>(
|
|
588
|
-
items
|
|
617
|
+
export declare function usePin<T = unknown>(options?: {
|
|
618
|
+
items?: T[];
|
|
589
619
|
field?: string;
|
|
590
620
|
initialPinnedIds?: PinId[];
|
|
591
621
|
maxPins?: number;
|
|
@@ -605,8 +635,8 @@ export interface UseVisibilityReturn<T> {
|
|
|
605
635
|
resetVisibility: () => void;
|
|
606
636
|
replaceVisibility: (newVisibleItems: VisibilityId[] | T[]) => void;
|
|
607
637
|
}
|
|
608
|
-
export declare function useVisibility<T = unknown>(
|
|
609
|
-
items
|
|
638
|
+
export declare function useVisibility<T = unknown>(options?: {
|
|
639
|
+
items?: T[];
|
|
610
640
|
field?: string;
|
|
611
641
|
initialVisibleIds?: VisibilityId[];
|
|
612
642
|
}): UseVisibilityReturn<T>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
export {
|
|
2
|
+
import { n as lt, r as ut, t as dt } from "./events2.js";
|
|
3
|
+
import { a as ft, c as pt, i as mt, l as ht, n as gt, o as _t, r as vt, s as yt, t as bt, u as xt } from "./performance2.js";
|
|
4
|
+
import { a as St, c as Ct, i as wt, n as Tt, o as Et, r as Dt, s as Ot, t as kt } from "./state2.js";
|
|
5
|
+
import { a as At, c as jt, i as Mt, n as Nt, o as Pt, r as Ft, s as It, t as Lt } from "./ui2.js";
|
|
6
|
+
export { jt as FuzzyHighlighter, Mt 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, lt as useClickOutside, xt as useDebounce, ht as useDebouncedCallback, pt as useDebouncedState, yt as useDebouncedValue, ut as useEventListener, Ft as useExpansion, Ct as useFilter, Ot as useFuzzySearch, Et as useGrouping, dt as useKey, At as useModal, Pt as useModalActions, It as useModalState, St as useMultipleSelection, wt as useOrder, Dt as usePagination, Nt as usePin, _t as useRateLimit, ft as useRateLimitedCallback, Tt as useSingleSelection, kt as useSort, mt as useThrottle, vt as useThrottledCallback, gt as useThrottledState, bt as useThrottledValue, Lt as useVisibility };
|
package/dist/performance2.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
|
|
2
2
|
//#region src/performance/useDebounce/useDebounce.ts
|
|
3
3
|
function i(i, a = {}) {
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
}, []),
|
|
7
|
-
|
|
4
|
+
let o = Math.max(0, Number(i) || 0), [s, c] = r(!1), l = a?.maxWait, u = !!a?.leading, d = !u && a?.trailing === !1 ? !0 : a?.trailing ?? !u, f = n(null), p = n(null), m = n(null), h = n(-1), g = n(-1), _ = e(() => {
|
|
5
|
+
m.current &&= (clearTimeout(m.current), null), h.current = -1, g.current = -1, p.current = null, f.current = null, c(!1);
|
|
6
|
+
}, []), v = e(() => {
|
|
7
|
+
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
8
|
}, []);
|
|
9
9
|
return t(() => () => {
|
|
10
|
-
|
|
11
|
-
}, [
|
|
10
|
+
_();
|
|
11
|
+
}, [_]), {
|
|
12
12
|
run: e((e, ...t) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
},
|
|
13
|
+
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
|
+
g.current !== h.current && d !== !1 && f.current && p.current && f.current(...p.current), h.current = -1, c(!1);
|
|
15
|
+
}, o));
|
|
16
16
|
}, [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
o,
|
|
18
|
+
l,
|
|
19
|
+
d,
|
|
20
|
+
u
|
|
21
21
|
]),
|
|
22
|
-
cancel:
|
|
23
|
-
flush:
|
|
24
|
-
isPending:
|
|
22
|
+
cancel: _,
|
|
23
|
+
flush: v,
|
|
24
|
+
isPending: s
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
//#endregion
|
|
@@ -71,34 +71,34 @@ function s(e, n, i = {}) {
|
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region src/performance/useRateLimit/useRateLimit.ts
|
|
73
73
|
function c(i, a, o) {
|
|
74
|
-
let
|
|
74
|
+
let s = Math.max(1, Number(i) || 1), c = Math.max(0, Number(a) || 0), [l, u] = r(s), d = o?.refillStrategy ?? "burst", f = n(o?.onRateLimitReached);
|
|
75
75
|
t(() => {
|
|
76
|
-
|
|
76
|
+
f.current = o?.onRateLimitReached;
|
|
77
77
|
}, [o?.onRateLimitReached]);
|
|
78
|
-
let
|
|
78
|
+
let p = n(s), [m] = r(() => Date.now()), h = n(m), g = n(null);
|
|
79
79
|
return t(() => () => {
|
|
80
|
-
|
|
80
|
+
g.current && clearTimeout(g.current);
|
|
81
81
|
}, []), {
|
|
82
82
|
run: e((e, ...t) => {
|
|
83
|
-
let n = Date.now(), r = n -
|
|
84
|
-
if (
|
|
83
|
+
let n = Date.now(), r = n - h.current;
|
|
84
|
+
if (d === "burst") r >= c && (p.current = s, h.current = n);
|
|
85
85
|
else {
|
|
86
|
-
let e =
|
|
87
|
-
t > 0 && (
|
|
86
|
+
let e = c / s, t = Math.floor(r / e);
|
|
87
|
+
t > 0 && (p.current = Math.min(s, p.current + t), h.current += t * e);
|
|
88
88
|
}
|
|
89
|
-
if (
|
|
90
|
-
let e =
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
if (p.current > 0 ? (--p.current, u(p.current), e(...t)) : f.current && f.current(), g.current && clearTimeout(g.current), p.current < s) {
|
|
90
|
+
let e = c / s, t = d === "burst" ? c - (Date.now() - h.current) : e - (Date.now() - h.current);
|
|
91
|
+
g.current = setTimeout(() => {
|
|
92
|
+
u((e) => Math.min(s, e + 1)), h.current = Date.now(), p.current = Math.min(s, p.current + 1);
|
|
93
93
|
}, Math.max(0, t));
|
|
94
94
|
}
|
|
95
95
|
}, [
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
s,
|
|
97
|
+
c,
|
|
98
|
+
d
|
|
99
99
|
]),
|
|
100
|
-
remaining:
|
|
101
|
-
isRateLimited:
|
|
100
|
+
remaining: l,
|
|
101
|
+
isRateLimited: l === 0
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
//#endregion
|
|
@@ -120,34 +120,34 @@ function l(r, i, a, o) {
|
|
|
120
120
|
//#endregion
|
|
121
121
|
//#region src/performance/useThrottle/useThrottle.ts
|
|
122
122
|
function u(i, a = {}) {
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
}, []),
|
|
128
|
-
|
|
129
|
-
}, [
|
|
123
|
+
let o = Math.max(0, Number(i) || 0), [s, c] = r(!1), l = a?.leading ?? !0, u = a?.trailing ?? !0;
|
|
124
|
+
l === !1 && u === !1 && (l = !0, u = !0);
|
|
125
|
+
let d = n(null), f = n(null), p = n(null), m = n(-1), h = e(() => {
|
|
126
|
+
p.current &&= (clearTimeout(p.current), null), m.current = -1, f.current = null, d.current = null, c(!1);
|
|
127
|
+
}, []), g = e(() => {
|
|
128
|
+
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
|
+
}, [l]);
|
|
130
130
|
return t(() => () => {
|
|
131
|
-
|
|
132
|
-
}, [
|
|
131
|
+
h();
|
|
132
|
+
}, [h]), {
|
|
133
133
|
run: e((e, ...t) => {
|
|
134
|
-
|
|
134
|
+
c(!0);
|
|
135
135
|
let n = Date.now();
|
|
136
|
-
if (
|
|
137
|
-
else if (!
|
|
138
|
-
let e =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
},
|
|
136
|
+
if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= o) p.current &&= (clearTimeout(p.current), null), d.current(...t), m.current = n, f.current = null, c(!1);
|
|
137
|
+
else if (!p.current) {
|
|
138
|
+
let e = m.current === -1 ? 0 : n - m.current, t = o - e;
|
|
139
|
+
p.current = setTimeout(() => {
|
|
140
|
+
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
|
+
}, t);
|
|
142
142
|
}
|
|
143
143
|
}, [
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
o,
|
|
145
|
+
l,
|
|
146
|
+
u
|
|
147
147
|
]),
|
|
148
|
-
cancel:
|
|
149
|
-
flush:
|
|
150
|
-
isPending:
|
|
148
|
+
cancel: h,
|
|
149
|
+
flush: g,
|
|
150
|
+
isPending: s
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
package/dist/state.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface UseFilterReturn<T> {
|
|
|
75
75
|
updateFilterValue: (id: string, value: unknown) => void;
|
|
76
76
|
isFilterActive: (id: string) => boolean;
|
|
77
77
|
}
|
|
78
|
-
export declare function useFilter<T>(data
|
|
78
|
+
export declare function useFilter<T>(data?: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
|
|
79
79
|
export interface FuzzySearchOptions {
|
|
80
80
|
threshold?: number;
|
|
81
81
|
caseSensitive?: boolean;
|
|
@@ -118,8 +118,8 @@ export interface UseGroupingReturn<T> {
|
|
|
118
118
|
resetGrouping: () => void;
|
|
119
119
|
getGroupItems: (groupKey: string) => T[];
|
|
120
120
|
}
|
|
121
|
-
export declare function useGrouping<T = unknown>(
|
|
122
|
-
items
|
|
121
|
+
export declare function useGrouping<T = unknown>(options?: {
|
|
122
|
+
items?: T[];
|
|
123
123
|
initialGroupBy?: string;
|
|
124
124
|
}): UseGroupingReturn<T>;
|
|
125
125
|
export type SelectionId = string | number;
|
|
@@ -142,8 +142,8 @@ export interface UseMultipleSelectionReturn<T> {
|
|
|
142
142
|
deselectMultiple: (itemsToRemove: SelectionId[] | T[]) => void;
|
|
143
143
|
retainOnly: (itemsToRetain: SelectionId[] | T[]) => void;
|
|
144
144
|
}
|
|
145
|
-
export declare function useMultipleSelection<T = unknown>(
|
|
146
|
-
items
|
|
145
|
+
export declare function useMultipleSelection<T = unknown>(options?: {
|
|
146
|
+
items?: T[];
|
|
147
147
|
field?: string;
|
|
148
148
|
initialSelectedIds?: SelectionId[];
|
|
149
149
|
}): UseMultipleSelectionReturn<T>;
|
|
@@ -160,7 +160,7 @@ export interface UseOrderReturn<T> {
|
|
|
160
160
|
resetOrder: () => void;
|
|
161
161
|
replaceOrder: (newOrderedItems: T[]) => void;
|
|
162
162
|
}
|
|
163
|
-
export declare function useOrder<T>(initialItems
|
|
163
|
+
export declare function useOrder<T>(initialItems?: T[]): UseOrderReturn<T>;
|
|
164
164
|
export interface UsePaginationReturn<T> {
|
|
165
165
|
pageItems: T[];
|
|
166
166
|
pageSize: number;
|
|
@@ -178,7 +178,7 @@ export interface UsePaginationReturn<T> {
|
|
|
178
178
|
resetPageSize: () => void;
|
|
179
179
|
resetPagination: () => void;
|
|
180
180
|
}
|
|
181
|
-
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
181
|
+
export declare function usePagination<T>(data: T[] | undefined, initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
182
182
|
type SelectionId$1 = string | number;
|
|
183
183
|
export interface UseSingleSelectionReturn {
|
|
184
184
|
selectedId: SelectionId$1 | undefined;
|
|
@@ -230,6 +230,6 @@ export interface UseSortReturn<T> {
|
|
|
230
230
|
getNextSortingOrder: (id: string) => "asc" | "desc" | "none";
|
|
231
231
|
getSortIndex: (id: string) => number | undefined;
|
|
232
232
|
}
|
|
233
|
-
export declare function useSort<T>(data
|
|
233
|
+
export declare function useSort<T>(data?: T[], initialSorts?: SortState): UseSortReturn<T>;
|
|
234
234
|
|
|
235
235
|
export {};
|