@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 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 { t as e } from "./events2.js";
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 r = [
47
+ var s = [
4
48
  "keydown",
5
49
  "keyup",
6
50
  "keypress"
7
- ];
8
- //#endregion
9
- //#region src/events/useKey/useKey.ts
10
- function i(i, a, { enabled: o = !0, preventDefault: s = !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 = window } = {}) {
11
- let _ = n(a), v = n(o), y = n(!1);
12
- t(() => {
13
- _.current = a;
14
- }, [a]), e(() => {
15
- v.current = o;
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 t = i.toLowerCase(), n = r.includes(l) ? l : "keydown", a = u && n !== "keyup";
20
- function o() {
21
- y.current = !1;
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 b(e) {
65
+ function g(e) {
24
66
  if (!(e instanceof KeyboardEvent)) return;
25
- let n = e.key.toLowerCase();
26
- (n === t || f && n === "control" || p && n === "shift" || m && n === "alt" || h && n === "meta") && (y.current = !1);
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) || !v.current) return;
30
- let n = e.target;
31
- if (!(d && n instanceof HTMLElement && (n instanceof HTMLInputElement || n instanceof HTMLTextAreaElement || n instanceof HTMLSelectElement || n.isContentEditable)) && e.ctrlKey === f && e.shiftKey === p && e.altKey === m && e.metaKey === h && t === e.key.toLowerCase()) {
32
- if (a && y.current) return;
33
- y.current = !0, _.current(e), s && e.preventDefault(), c && e.stopPropagation();
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(n, x), a && (e.addEventListener("keyup", b), window.addEventListener("blur", o)), () => {
37
- e.removeEventListener(n, x), a && (e.removeEventListener("keyup", b), window.removeEventListener("blur", o));
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
- i,
41
- s,
42
- c,
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
- g
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: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
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>({ items, initialGroupBy, }: {
408
- items: T[];
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>({ items, field, initialSelectedIds, }: {
432
- items: T[];
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: T[]): UseOrderReturn<T>;
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: T[], initialSorts?: SortState): UseSortReturn<T>;
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>({ items, field, initialExpandedIds, multiple, }?: {
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>({ items, field, initialPinnedIds, maxPins, }: {
588
- items: T[];
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>({ items, field, initialVisibleIds, }: {
609
- items: T[];
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 { t as lt } from "./events2.js";
3
- import { a as ut, c as dt, i as ft, l as pt, n as mt, o as ht, r as gt, s as _t, t as vt, u as yt } from "./performance2.js";
4
- import { a as bt, c as xt, i as St, n as Ct, o as wt, r as Tt, s as Et, t as Dt } from "./state2.js";
5
- import { a as Ot, c as kt, i as At, n as jt, o as Mt, r as Nt, s as Pt, t as Ft } from "./ui2.js";
6
- export { kt as FuzzyHighlighter, At 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, yt as useDebounce, pt as useDebouncedCallback, dt as useDebouncedState, _t as useDebouncedValue, Nt as useExpansion, xt as useFilter, Et as useFuzzySearch, wt as useGrouping, lt as useKey, Ot as useModal, Mt as useModalActions, Pt as useModalState, bt as useMultipleSelection, St as useOrder, Tt as usePagination, jt as usePin, ht as useRateLimit, ut as useRateLimitedCallback, Ct as useSingleSelection, Dt as useSort, ft as useThrottle, gt as useThrottledCallback, mt as useThrottledState, vt as useThrottledValue, Ft as useVisibility };
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 };
@@ -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 [o, s] = r(!1), c = a.maxWait, l = !!a.leading, u = !l && a.trailing === !1 ? !0 : a.trailing ?? !l, d = n(null), f = n(null), p = n(null), m = n(-1), h = n(-1), g = e(() => {
5
- p.current &&= (clearTimeout(p.current), null), m.current = -1, h.current = -1, f.current = null, d.current = null, s(!1);
6
- }, []), _ = e(() => {
7
- p.current && d.current && f.current && (clearTimeout(p.current), p.current = null, d.current(...f.current), m.current = Date.now(), h.current = -1, f.current = null, d.current = null, s(!1));
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
- g();
11
- }, [g]), {
10
+ _();
11
+ }, [_]), {
12
12
  run: e((e, ...t) => {
13
- s(!0), h.current = Date.now(), f.current = t, d.current = e, m.current === -1 && (m.current = Date.now(), l === !0 && d.current(...t)), c !== void 0 && Date.now() - m.current >= c ? (p.current && clearTimeout(p.current), d.current && d.current(...t), m.current = -1, s(!1)) : (p.current && clearTimeout(p.current), p.current = setTimeout(() => {
14
- h.current !== m.current && u !== !1 && d.current && f.current && d.current(...f.current), m.current = -1, s(!1);
15
- }, i));
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
- i,
18
- c,
19
- u,
20
- l
17
+ o,
18
+ l,
19
+ d,
20
+ u
21
21
  ]),
22
- cancel: g,
23
- flush: _,
24
- isPending: o
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 [s, c] = r(i), l = o?.refillStrategy ?? "burst", u = n(o?.onRateLimitReached);
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
- u.current = o?.onRateLimitReached;
76
+ f.current = o?.onRateLimitReached;
77
77
  }, [o?.onRateLimitReached]);
78
- let d = n(i), [f] = r(() => Date.now()), p = n(f), m = n(null);
78
+ let p = n(s), [m] = r(() => Date.now()), h = n(m), g = n(null);
79
79
  return t(() => () => {
80
- m.current && clearTimeout(m.current);
80
+ g.current && clearTimeout(g.current);
81
81
  }, []), {
82
82
  run: e((e, ...t) => {
83
- let n = Date.now(), r = n - p.current;
84
- if (l === "burst") r >= a && (d.current = i, p.current = n);
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 = a / i, t = Math.floor(r / e);
87
- t > 0 && (d.current = Math.min(i, d.current + t), p.current += t * e);
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 (d.current > 0 ? (--d.current, c(d.current), e(...t)) : u.current && u.current(), m.current && clearTimeout(m.current), d.current < i) {
90
- let e = a / i, t = l === "burst" ? a - (Date.now() - p.current) : e - (Date.now() - p.current);
91
- m.current = setTimeout(() => {
92
- c((e) => Math.min(i, e + 1)), p.current = Date.now(), d.current = Math.min(i, d.current + 1);
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
- i,
97
- a,
98
- l
96
+ s,
97
+ c,
98
+ d
99
99
  ]),
100
- remaining: s,
101
- isRateLimited: s === 0
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 [o, s] = r(!1), c = a.leading ?? !0, l = a.trailing ?? !0;
124
- c === !1 && l === !1 && (c = !0, l = !0);
125
- let u = n(null), d = n(null), f = n(null), p = n(-1), m = e(() => {
126
- f.current &&= (clearTimeout(f.current), null), p.current = -1, d.current = null, u.current = null, s(!1);
127
- }, []), h = e(() => {
128
- d.current && u.current && (f.current &&= (clearTimeout(f.current), null), u.current(...d.current), p.current = c ? Date.now() : -1, d.current = null, u.current = null, s(!1));
129
- }, [c]);
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
- m();
132
- }, [m]), {
131
+ h();
132
+ }, [h]), {
133
133
  run: e((e, ...t) => {
134
- s(!0);
134
+ c(!0);
135
135
  let n = Date.now();
136
- if (d.current = t, u.current = e, p.current === -1 ? c : n - p.current >= i) f.current &&= (clearTimeout(f.current), null), u.current(...t), p.current = n, d.current = null, s(!1);
137
- else if (!f.current) {
138
- let e = i - (p.current === -1 ? 0 : n - p.current);
139
- f.current = setTimeout(() => {
140
- l && d.current && u.current ? (u.current(...d.current), p.current = c ? Date.now() : -1) : p.current = -1, d.current = null, u.current = null, f.current = null, s(!1);
141
- }, e);
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
- i,
145
- c,
146
- l
144
+ o,
145
+ l,
146
+ u
147
147
  ]),
148
- cancel: m,
149
- flush: h,
150
- isPending: o
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: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
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>({ items, initialGroupBy, }: {
122
- items: T[];
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>({ items, field, initialSelectedIds, }: {
146
- items: T[];
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: T[]): UseOrderReturn<T>;
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: T[], initialSorts?: SortState): UseSortReturn<T>;
233
+ export declare function useSort<T>(data?: T[], initialSorts?: SortState): UseSortReturn<T>;
234
234
 
235
235
  export {};