@himanshu-sorathiya/react-kit 1.0.19 → 1.0.21
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/events2.js +1 -1
- package/dist/index.d.ts +71 -17
- package/dist/index.js +4 -4
- package/dist/performance.d.ts +58 -4
- package/dist/performance.js +2 -2
- package/dist/performance2.js +155 -34
- 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/events2.js
CHANGED
|
@@ -16,7 +16,7 @@ function i(i, a, { enabled: o = !0, preventDefault: s = !0, stopPropagation: c =
|
|
|
16
16
|
}, [o]), e(() => {
|
|
17
17
|
let e = g && "current" in g ? g.current : g;
|
|
18
18
|
if (!e) return;
|
|
19
|
-
let t = i.toLowerCase(), n = r.includes(l) ? l : "keydown", a = u && n !== "keyup";
|
|
19
|
+
let t = String(i || "").toLowerCase(), n = r.includes(l) ? l : "keydown", a = u && n !== "keyup";
|
|
20
20
|
function o() {
|
|
21
21
|
y.current = !1;
|
|
22
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -212,26 +212,80 @@ export interface DebounceOptions {
|
|
|
212
212
|
leading?: boolean;
|
|
213
213
|
trailing?: boolean;
|
|
214
214
|
}
|
|
215
|
-
export interface UseDebounceReturn
|
|
215
|
+
export interface UseDebounceReturn {
|
|
216
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
217
|
+
cancel: () => void;
|
|
218
|
+
flush: () => void;
|
|
219
|
+
isPending: boolean;
|
|
220
|
+
}
|
|
221
|
+
export declare function useDebounce(delay: number, options?: DebounceOptions): UseDebounceReturn;
|
|
222
|
+
export interface UseDebouncedCallbackReturn<Args extends unknown[]> {
|
|
216
223
|
debouncedFunc: (...args: Args) => void;
|
|
217
224
|
cancel: () => void;
|
|
218
225
|
flush: () => void;
|
|
219
226
|
isPending: boolean;
|
|
220
227
|
}
|
|
221
|
-
export declare function
|
|
228
|
+
export declare function useDebouncedCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebouncedCallbackReturn<Args>;
|
|
229
|
+
export type UseDebouncedStateReturn<T> = [
|
|
230
|
+
T,
|
|
231
|
+
(value: T) => void,
|
|
232
|
+
{
|
|
233
|
+
isPending: boolean;
|
|
234
|
+
cancel: () => void;
|
|
235
|
+
flush: () => void;
|
|
236
|
+
forceSetValue: (value: T) => void;
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
export declare function useDebouncedState<T>(initialValue: T | (() => T), delay: number, options?: DebounceOptions): UseDebouncedStateReturn<T>;
|
|
222
240
|
export type UseDebouncedValueReturn<T> = T;
|
|
223
241
|
export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
|
|
242
|
+
export interface RateLimitOptions {
|
|
243
|
+
onRateLimitReached?: () => void;
|
|
244
|
+
refillStrategy?: "burst" | "gradual";
|
|
245
|
+
}
|
|
246
|
+
export interface UseRateLimitReturn {
|
|
247
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
248
|
+
remaining: number;
|
|
249
|
+
isRateLimited: boolean;
|
|
250
|
+
}
|
|
251
|
+
export declare function useRateLimit(limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitReturn;
|
|
252
|
+
export interface UseRateLimitedCallbackReturn<Args extends unknown[]> {
|
|
253
|
+
rateLimitedFunc: (...args: Args) => void;
|
|
254
|
+
remaining: number;
|
|
255
|
+
isRateLimited: boolean;
|
|
256
|
+
}
|
|
257
|
+
export declare function useRateLimitedCallback<Args extends unknown[]>(func: (...args: Args) => void, limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitedCallbackReturn<Args>;
|
|
224
258
|
export interface ThrottleOptions {
|
|
225
259
|
leading?: boolean;
|
|
226
260
|
trailing?: boolean;
|
|
227
261
|
}
|
|
228
|
-
export interface UseThrottleReturn
|
|
262
|
+
export interface UseThrottleReturn {
|
|
263
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
264
|
+
cancel: () => void;
|
|
265
|
+
flush: () => void;
|
|
266
|
+
isPending: boolean;
|
|
267
|
+
}
|
|
268
|
+
export declare function useThrottle(delay: number, options?: ThrottleOptions): UseThrottleReturn;
|
|
269
|
+
export interface UseThrottledCallbackReturn<Args extends unknown[]> {
|
|
229
270
|
throttledFunc: (...args: Args) => void;
|
|
230
271
|
cancel: () => void;
|
|
231
272
|
flush: () => void;
|
|
232
273
|
isPending: boolean;
|
|
233
274
|
}
|
|
234
|
-
export declare function
|
|
275
|
+
export declare function useThrottledCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottledCallbackReturn<Args>;
|
|
276
|
+
export type UseThrottledStateReturn<T> = [
|
|
277
|
+
T,
|
|
278
|
+
(value: T) => void,
|
|
279
|
+
{
|
|
280
|
+
isPending: boolean;
|
|
281
|
+
cancel: () => void;
|
|
282
|
+
flush: () => void;
|
|
283
|
+
forceSetValue: (value: T) => void;
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: ThrottleOptions): UseThrottledStateReturn<T>;
|
|
287
|
+
export type UseThrottledValueReturn<T> = T;
|
|
288
|
+
export declare function useThrottledValue<T>(value: T, delay: number, options?: ThrottleOptions): UseThrottledValueReturn<T>;
|
|
235
289
|
export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
|
|
236
290
|
export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
|
|
237
291
|
export type NumberOperator = "equals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between";
|
|
@@ -307,7 +361,7 @@ export interface UseFilterReturn<T> {
|
|
|
307
361
|
updateFilterValue: (id: string, value: unknown) => void;
|
|
308
362
|
isFilterActive: (id: string) => boolean;
|
|
309
363
|
}
|
|
310
|
-
export declare function useFilter<T>(data
|
|
364
|
+
export declare function useFilter<T>(data?: T[], initialFilters?: FilterState<T>): UseFilterReturn<T>;
|
|
311
365
|
export interface FuzzySearchOptions {
|
|
312
366
|
threshold?: number;
|
|
313
367
|
caseSensitive?: boolean;
|
|
@@ -350,8 +404,8 @@ export interface UseGroupingReturn<T> {
|
|
|
350
404
|
resetGrouping: () => void;
|
|
351
405
|
getGroupItems: (groupKey: string) => T[];
|
|
352
406
|
}
|
|
353
|
-
export declare function useGrouping<T = unknown>(
|
|
354
|
-
items
|
|
407
|
+
export declare function useGrouping<T = unknown>(options?: {
|
|
408
|
+
items?: T[];
|
|
355
409
|
initialGroupBy?: string;
|
|
356
410
|
}): UseGroupingReturn<T>;
|
|
357
411
|
export type SelectionId = string | number;
|
|
@@ -374,8 +428,8 @@ export interface UseMultipleSelectionReturn<T> {
|
|
|
374
428
|
deselectMultiple: (itemsToRemove: SelectionId[] | T[]) => void;
|
|
375
429
|
retainOnly: (itemsToRetain: SelectionId[] | T[]) => void;
|
|
376
430
|
}
|
|
377
|
-
export declare function useMultipleSelection<T = unknown>(
|
|
378
|
-
items
|
|
431
|
+
export declare function useMultipleSelection<T = unknown>(options?: {
|
|
432
|
+
items?: T[];
|
|
379
433
|
field?: string;
|
|
380
434
|
initialSelectedIds?: SelectionId[];
|
|
381
435
|
}): UseMultipleSelectionReturn<T>;
|
|
@@ -392,7 +446,7 @@ export interface UseOrderReturn<T> {
|
|
|
392
446
|
resetOrder: () => void;
|
|
393
447
|
replaceOrder: (newOrderedItems: T[]) => void;
|
|
394
448
|
}
|
|
395
|
-
export declare function useOrder<T>(initialItems
|
|
449
|
+
export declare function useOrder<T>(initialItems?: T[]): UseOrderReturn<T>;
|
|
396
450
|
export interface UsePaginationReturn<T> {
|
|
397
451
|
pageItems: T[];
|
|
398
452
|
pageSize: number;
|
|
@@ -410,7 +464,7 @@ export interface UsePaginationReturn<T> {
|
|
|
410
464
|
resetPageSize: () => void;
|
|
411
465
|
resetPagination: () => void;
|
|
412
466
|
}
|
|
413
|
-
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
467
|
+
export declare function usePagination<T>(data: T[] | undefined, initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
414
468
|
type SelectionId$1 = string | number;
|
|
415
469
|
export interface UseSingleSelectionReturn {
|
|
416
470
|
selectedId: SelectionId$1 | undefined;
|
|
@@ -462,7 +516,7 @@ export interface UseSortReturn<T> {
|
|
|
462
516
|
getNextSortingOrder: (id: string) => "asc" | "desc" | "none";
|
|
463
517
|
getSortIndex: (id: string) => number | undefined;
|
|
464
518
|
}
|
|
465
|
-
export declare function useSort<T>(data
|
|
519
|
+
export declare function useSort<T>(data?: T[], initialSorts?: SortState): UseSortReturn<T>;
|
|
466
520
|
export interface FuzzyHighlighterProps {
|
|
467
521
|
text: string;
|
|
468
522
|
query: string;
|
|
@@ -492,7 +546,7 @@ export interface UseExpansionReturn<T> {
|
|
|
492
546
|
resetExpansion: () => void;
|
|
493
547
|
replaceExpansion: (newExpandedItems: ExpansionId[] | T[]) => void;
|
|
494
548
|
}
|
|
495
|
-
export declare function useExpansion<T = unknown>(
|
|
549
|
+
export declare function useExpansion<T = unknown>(options?: {
|
|
496
550
|
items?: T[];
|
|
497
551
|
field?: string;
|
|
498
552
|
initialExpandedIds?: ExpansionId[];
|
|
@@ -530,8 +584,8 @@ export interface UsePinReturn<T> {
|
|
|
530
584
|
pinMultiple: (newItems: PinId[] | T[]) => void;
|
|
531
585
|
unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
|
|
532
586
|
}
|
|
533
|
-
export declare function usePin<T = unknown>(
|
|
534
|
-
items
|
|
587
|
+
export declare function usePin<T = unknown>(options?: {
|
|
588
|
+
items?: T[];
|
|
535
589
|
field?: string;
|
|
536
590
|
initialPinnedIds?: PinId[];
|
|
537
591
|
maxPins?: number;
|
|
@@ -551,8 +605,8 @@ export interface UseVisibilityReturn<T> {
|
|
|
551
605
|
resetVisibility: () => void;
|
|
552
606
|
replaceVisibility: (newVisibleItems: VisibilityId[] | T[]) => void;
|
|
553
607
|
}
|
|
554
|
-
export declare function useVisibility<T = unknown>(
|
|
555
|
-
items
|
|
608
|
+
export declare function useVisibility<T = unknown>(options?: {
|
|
609
|
+
items?: T[];
|
|
556
610
|
field?: string;
|
|
557
611
|
initialVisibleIds?: VisibilityId[];
|
|
558
612
|
}): 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
2
|
import { t as lt } from "./events2.js";
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import { a as
|
|
6
|
-
export {
|
|
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 };
|
package/dist/performance.d.ts
CHANGED
|
@@ -5,25 +5,79 @@ export interface DebounceOptions {
|
|
|
5
5
|
leading?: boolean;
|
|
6
6
|
trailing?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export interface UseDebounceReturn
|
|
8
|
+
export interface UseDebounceReturn {
|
|
9
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
10
|
+
cancel: () => void;
|
|
11
|
+
flush: () => void;
|
|
12
|
+
isPending: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function useDebounce(delay: number, options?: DebounceOptions): UseDebounceReturn;
|
|
15
|
+
export interface UseDebouncedCallbackReturn<Args extends unknown[]> {
|
|
9
16
|
debouncedFunc: (...args: Args) => void;
|
|
10
17
|
cancel: () => void;
|
|
11
18
|
flush: () => void;
|
|
12
19
|
isPending: boolean;
|
|
13
20
|
}
|
|
14
|
-
export declare function
|
|
21
|
+
export declare function useDebouncedCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebouncedCallbackReturn<Args>;
|
|
22
|
+
export type UseDebouncedStateReturn<T> = [
|
|
23
|
+
T,
|
|
24
|
+
(value: T) => void,
|
|
25
|
+
{
|
|
26
|
+
isPending: boolean;
|
|
27
|
+
cancel: () => void;
|
|
28
|
+
flush: () => void;
|
|
29
|
+
forceSetValue: (value: T) => void;
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
export declare function useDebouncedState<T>(initialValue: T | (() => T), delay: number, options?: DebounceOptions): UseDebouncedStateReturn<T>;
|
|
15
33
|
export type UseDebouncedValueReturn<T> = T;
|
|
16
34
|
export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebounceOptions): UseDebouncedValueReturn<T>;
|
|
35
|
+
export interface RateLimitOptions {
|
|
36
|
+
onRateLimitReached?: () => void;
|
|
37
|
+
refillStrategy?: "burst" | "gradual";
|
|
38
|
+
}
|
|
39
|
+
export interface UseRateLimitReturn {
|
|
40
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
41
|
+
remaining: number;
|
|
42
|
+
isRateLimited: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function useRateLimit(limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitReturn;
|
|
45
|
+
export interface UseRateLimitedCallbackReturn<Args extends unknown[]> {
|
|
46
|
+
rateLimitedFunc: (...args: Args) => void;
|
|
47
|
+
remaining: number;
|
|
48
|
+
isRateLimited: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare function useRateLimitedCallback<Args extends unknown[]>(func: (...args: Args) => void, limit: number, windowMs: number, options?: RateLimitOptions): UseRateLimitedCallbackReturn<Args>;
|
|
17
51
|
export interface ThrottleOptions {
|
|
18
52
|
leading?: boolean;
|
|
19
53
|
trailing?: boolean;
|
|
20
54
|
}
|
|
21
|
-
export interface UseThrottleReturn
|
|
55
|
+
export interface UseThrottleReturn {
|
|
56
|
+
run: <Args extends unknown[]>(func: (...args: Args) => void, ...args: Args) => void;
|
|
57
|
+
cancel: () => void;
|
|
58
|
+
flush: () => void;
|
|
59
|
+
isPending: boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare function useThrottle(delay: number, options?: ThrottleOptions): UseThrottleReturn;
|
|
62
|
+
export interface UseThrottledCallbackReturn<Args extends unknown[]> {
|
|
22
63
|
throttledFunc: (...args: Args) => void;
|
|
23
64
|
cancel: () => void;
|
|
24
65
|
flush: () => void;
|
|
25
66
|
isPending: boolean;
|
|
26
67
|
}
|
|
27
|
-
export declare function
|
|
68
|
+
export declare function useThrottledCallback<Args extends unknown[]>(func: (...args: Args) => void, delay: number, options?: ThrottleOptions): UseThrottledCallbackReturn<Args>;
|
|
69
|
+
export type UseThrottledStateReturn<T> = [
|
|
70
|
+
T,
|
|
71
|
+
(value: T) => void,
|
|
72
|
+
{
|
|
73
|
+
isPending: boolean;
|
|
74
|
+
cancel: () => void;
|
|
75
|
+
flush: () => void;
|
|
76
|
+
forceSetValue: (value: T) => void;
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
export declare function useThrottledState<T>(initialValue: T | (() => T), delay: number, options?: ThrottleOptions): UseThrottledStateReturn<T>;
|
|
80
|
+
export type UseThrottledValueReturn<T> = T;
|
|
81
|
+
export declare function useThrottledValue<T>(value: T, delay: number, options?: ThrottleOptions): UseThrottledValueReturn<T>;
|
|
28
82
|
|
|
29
83
|
export {};
|
package/dist/performance.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./performance2.js";
|
|
2
|
+
export { l as useDebounce, r as useDebouncedCallback, t as useDebouncedState, s as useDebouncedValue, a as useRateLimit, e as useRateLimitedCallback, n as useThrottle, o as useThrottledCallback, i as useThrottledState, c as useThrottledValue };
|
package/dist/performance2.js
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
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
|
-
function i(i, a
|
|
4
|
-
let [s, c] = r(!1), l =
|
|
5
|
-
|
|
6
|
-
f.current = i;
|
|
7
|
-
}, [i]);
|
|
8
|
-
let _ = e(() => {
|
|
9
|
-
p.current &&= (clearTimeout(p.current), null), m.current = -1, h.current = -1, g.current = null, c(!1);
|
|
3
|
+
function i(i, a = {}) {
|
|
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);
|
|
10
6
|
}, []), v = e(() => {
|
|
11
|
-
|
|
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));
|
|
12
8
|
}, []);
|
|
13
9
|
return t(() => () => {
|
|
14
10
|
_();
|
|
15
11
|
}, [_]), {
|
|
16
|
-
|
|
17
|
-
c(!0),
|
|
18
|
-
|
|
19
|
-
},
|
|
12
|
+
run: e((e, ...t) => {
|
|
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));
|
|
20
16
|
}, [
|
|
21
|
-
|
|
17
|
+
o,
|
|
22
18
|
l,
|
|
23
19
|
d,
|
|
24
20
|
u
|
|
@@ -29,42 +25,123 @@ function i(i, a, o = {}) {
|
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
27
|
//#endregion
|
|
28
|
+
//#region src/performance/useDebounce/useDebouncedCallback.ts
|
|
29
|
+
function a(r, a, o = {}) {
|
|
30
|
+
let s = n(r);
|
|
31
|
+
t(() => {
|
|
32
|
+
s.current = r;
|
|
33
|
+
}, [r]);
|
|
34
|
+
let { run: c, cancel: l, flush: u, isPending: d } = i(a, o);
|
|
35
|
+
return {
|
|
36
|
+
debouncedFunc: e((...e) => {
|
|
37
|
+
c(s.current, ...e);
|
|
38
|
+
}, [c]),
|
|
39
|
+
cancel: l,
|
|
40
|
+
flush: u,
|
|
41
|
+
isPending: d
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/performance/useDebounce/useDebouncedState.ts
|
|
46
|
+
function o(e, t, n = {}) {
|
|
47
|
+
let [i, o] = r(e), { debouncedFunc: s, cancel: c, flush: l, isPending: u } = a((e) => {
|
|
48
|
+
o(e);
|
|
49
|
+
}, t, n);
|
|
50
|
+
return [
|
|
51
|
+
i,
|
|
52
|
+
s,
|
|
53
|
+
{
|
|
54
|
+
isPending: u,
|
|
55
|
+
cancel: c,
|
|
56
|
+
flush: l,
|
|
57
|
+
forceSetValue: o
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
32
62
|
//#region src/performance/useDebounce/useDebouncedValue.ts
|
|
33
|
-
function
|
|
34
|
-
let [o, s] = r(e), { debouncedFunc: c } =
|
|
63
|
+
function s(e, n, i = {}) {
|
|
64
|
+
let [o, s] = r(e), { debouncedFunc: c } = a((e) => {
|
|
35
65
|
s(e);
|
|
36
|
-
}, n,
|
|
66
|
+
}, n, i);
|
|
37
67
|
return t(() => {
|
|
38
68
|
c(e);
|
|
39
69
|
}, [e, c]), o;
|
|
40
70
|
}
|
|
41
71
|
//#endregion
|
|
42
|
-
//#region src/performance/
|
|
43
|
-
function
|
|
44
|
-
let
|
|
72
|
+
//#region src/performance/useRateLimit/useRateLimit.ts
|
|
73
|
+
function c(i, a, o) {
|
|
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);
|
|
45
75
|
t(() => {
|
|
46
|
-
|
|
47
|
-
}, [
|
|
48
|
-
let
|
|
49
|
-
|
|
76
|
+
f.current = o?.onRateLimitReached;
|
|
77
|
+
}, [o?.onRateLimitReached]);
|
|
78
|
+
let p = n(s), [m] = r(() => Date.now()), h = n(m), g = n(null);
|
|
79
|
+
return t(() => () => {
|
|
80
|
+
g.current && clearTimeout(g.current);
|
|
81
|
+
}, []), {
|
|
82
|
+
run: e((e, ...t) => {
|
|
83
|
+
let n = Date.now(), r = n - h.current;
|
|
84
|
+
if (d === "burst") r >= c && (p.current = s, h.current = n);
|
|
85
|
+
else {
|
|
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
|
+
}
|
|
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
|
+
}, Math.max(0, t));
|
|
94
|
+
}
|
|
95
|
+
}, [
|
|
96
|
+
s,
|
|
97
|
+
c,
|
|
98
|
+
d
|
|
99
|
+
]),
|
|
100
|
+
remaining: l,
|
|
101
|
+
isRateLimited: l === 0
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/performance/useRateLimit/useRateLimitedCallback.ts
|
|
106
|
+
function l(r, i, a, o) {
|
|
107
|
+
let s = n(r);
|
|
108
|
+
t(() => {
|
|
109
|
+
s.current = r;
|
|
110
|
+
}, [r]);
|
|
111
|
+
let { run: l, remaining: u, isRateLimited: d } = c(i, a, o);
|
|
112
|
+
return {
|
|
113
|
+
rateLimitedFunc: e((...e) => {
|
|
114
|
+
l(s.current, ...e);
|
|
115
|
+
}, [l]),
|
|
116
|
+
remaining: u,
|
|
117
|
+
isRateLimited: d
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/performance/useThrottle/useThrottle.ts
|
|
122
|
+
function u(i, a = {}) {
|
|
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);
|
|
50
127
|
}, []), g = e(() => {
|
|
51
|
-
|
|
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));
|
|
52
129
|
}, [l]);
|
|
53
130
|
return t(() => () => {
|
|
54
131
|
h();
|
|
55
132
|
}, [h]), {
|
|
56
|
-
|
|
133
|
+
run: e((e, ...t) => {
|
|
57
134
|
c(!0);
|
|
58
|
-
let
|
|
59
|
-
if (
|
|
60
|
-
else if (!
|
|
61
|
-
let e =
|
|
62
|
-
|
|
63
|
-
u &&
|
|
64
|
-
},
|
|
135
|
+
let n = Date.now();
|
|
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);
|
|
65
142
|
}
|
|
66
143
|
}, [
|
|
67
|
-
|
|
144
|
+
o,
|
|
68
145
|
l,
|
|
69
146
|
u
|
|
70
147
|
]),
|
|
@@ -74,4 +151,48 @@ function o(i, a, o = {}) {
|
|
|
74
151
|
};
|
|
75
152
|
}
|
|
76
153
|
//#endregion
|
|
77
|
-
|
|
154
|
+
//#region src/performance/useThrottle/useThrottledCallback.ts
|
|
155
|
+
function d(r, i, a = {}) {
|
|
156
|
+
let o = n(r);
|
|
157
|
+
t(() => {
|
|
158
|
+
o.current = r;
|
|
159
|
+
}, [r]);
|
|
160
|
+
let { run: s, cancel: c, flush: l, isPending: d } = u(i, a);
|
|
161
|
+
return {
|
|
162
|
+
throttledFunc: e((...e) => {
|
|
163
|
+
s(o.current, ...e);
|
|
164
|
+
}, [s]),
|
|
165
|
+
cancel: c,
|
|
166
|
+
flush: l,
|
|
167
|
+
isPending: d
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/performance/useThrottle/useThrottledState.ts
|
|
172
|
+
function f(e, t, n = {}) {
|
|
173
|
+
let [i, a] = r(e), { throttledFunc: o, isPending: s, cancel: c, flush: l } = d((e) => {
|
|
174
|
+
a(e);
|
|
175
|
+
}, t, n);
|
|
176
|
+
return [
|
|
177
|
+
i,
|
|
178
|
+
o,
|
|
179
|
+
{
|
|
180
|
+
isPending: s,
|
|
181
|
+
cancel: c,
|
|
182
|
+
flush: l,
|
|
183
|
+
forceSetValue: a
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/performance/useThrottle/useThrottledValue.ts
|
|
189
|
+
function p(e, n, i = {}) {
|
|
190
|
+
let [a, o] = r(e), { throttledFunc: s } = d((e) => {
|
|
191
|
+
o(e);
|
|
192
|
+
}, n, i);
|
|
193
|
+
return t(() => {
|
|
194
|
+
s(e);
|
|
195
|
+
}, [e, s]), a;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
export { l as a, o as c, u as i, a as l, f as n, c as o, d as r, s, p as t, i as u };
|
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 {};
|