@himanshu-sorathiya/react-kit 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
3
  import React$1 from 'react';
4
- import { CSSProperties, Key, RefObject } from 'react';
4
+ import { Key, RefObject } from 'react';
5
5
 
6
6
  /**
7
7
  * The native event that triggered a `useClickOutside` handler. Determined
@@ -417,6 +417,162 @@ export type UseKeyReturn = () => void;
417
417
  * ```
418
418
  */
419
419
  export declare function useKey(key: string, handler: (event: KeyboardEvent) => void, options?: UseKeyOptions): UseKeyReturn;
420
+ /**
421
+ * Configuration for `useBatcher`.
422
+ *
423
+ * All three flush triggers (`maxSize`, `maxWait`, `quietPeriod`) are
424
+ * optional and independent — configure any combination, and whichever
425
+ * condition is met first triggers the flush. If none are configured, the
426
+ * batch only ever flushes when `flush()` is called manually.
427
+ */
428
+ export interface BatchOptions<Item> {
429
+ /**
430
+ * Flushes the batch immediately once it reaches this many items.
431
+ * Checked on every `add()` call, before either timer-based trigger is
432
+ * considered.
433
+ *
434
+ * Invalid input (not a positive number) is ignored — not clamped to a
435
+ * fallback — with a dev-mode warning, since there's no sensible
436
+ * default size to fall back to.
437
+ *
438
+ * @defaultValue `undefined` (no size ceiling)
439
+ */
440
+ maxSize?: number;
441
+ /**
442
+ * A hard ceiling, in milliseconds, on how long a batch can sit before
443
+ * flushing — measured from the moment the *first* item of the current
444
+ * batch was added, not the most recent one. Guarantees a maximum
445
+ * latency per item regardless of how long the batch keeps growing.
446
+ *
447
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
448
+ * warning.
449
+ *
450
+ * @defaultValue `undefined` (no time ceiling)
451
+ */
452
+ maxWait?: number;
453
+ /**
454
+ * Flushes the batch once this many milliseconds pass with no further
455
+ * items added — resets on every `add()` call, unlike `maxWait`. Use
456
+ * this when you want to wait for activity to genuinely settle before
457
+ * flushing, rather than enforcing a hard per-item latency ceiling.
458
+ *
459
+ * If both `maxWait` and `quietPeriod` are configured and `quietPeriod`
460
+ * is not shorter than `maxWait`, `maxWait` will almost always win the
461
+ * race — a dev-mode warning flags this combination.
462
+ *
463
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
464
+ * warning.
465
+ *
466
+ * @defaultValue `undefined` (no quiet-period trigger)
467
+ */
468
+ quietPeriod?: number;
469
+ /**
470
+ * Called with a snapshot of the current batch contents every time it
471
+ * changes — after every `add()`, and after every flush or `cancel()`
472
+ * (with an empty array). This is the mechanism for getting live,
473
+ * reactive access to what's currently queued (e.g. a "3 items
474
+ * queued…" indicator) without `useBatcher` itself needing to hold the
475
+ * full item list in React state.
476
+ *
477
+ * Safe to pass a fresh inline function on every render — it's captured
478
+ * in a ref and refreshed via effect, same as `onFlush`.
479
+ *
480
+ * @defaultValue `undefined`
481
+ */
482
+ onItemsChange?: (items: readonly Item[]) => void;
483
+ }
484
+ /**
485
+ * The object returned by `useBatcher`.
486
+ */
487
+ export interface UseBatcherReturn<Item> {
488
+ /**
489
+ * Adds `item` to the current batch. Never rejected, never deferred to
490
+ * a future call — the item is always accepted immediately. Depending
491
+ * on the configured triggers, this may also cause an immediate flush
492
+ * (e.g. if `maxSize` is now reached).
493
+ */
494
+ add: (item: Item) => void;
495
+ /**
496
+ * Immediately flushes whatever is currently batched, bypassing
497
+ * `maxWait`/`quietPeriod` entirely. A no-op if the batch is empty —
498
+ * `onFlush` is never called with zero items.
499
+ */
500
+ flush: () => void;
501
+ /**
502
+ * Discards the current batch entirely, without ever calling
503
+ * `onFlush`. Clears any pending timers.
504
+ */
505
+ cancel: () => void;
506
+ /**
507
+ * Suspends all automatic flush triggers (`maxSize`, `maxWait`,
508
+ * `quietPeriod`). Items added via `add()` while paused still
509
+ * accumulate normally — pausing stops the flushing machinery, not the
510
+ * accumulation. The only way to flush while paused is a manual
511
+ * `flush()` call.
512
+ */
513
+ pause: () => void;
514
+ /**
515
+ * Resumes automatic flushing. If the batch already meets `maxSize`
516
+ * (because items kept arriving while paused), flushes immediately.
517
+ * Otherwise, re-arms `maxWait`/`quietPeriod` timers from scratch —
518
+ * pausing does not preserve partial progress toward either deadline;
519
+ * resuming starts a fresh clock for whatever's still batched.
520
+ */
521
+ resume: () => void;
522
+ /** The number of items currently in the batch. */
523
+ size: number;
524
+ /** `true` whenever `size > 0`. */
525
+ isPending: boolean;
526
+ /** `true` after `pause()`, until the next `resume()`. */
527
+ isPaused: boolean;
528
+ }
529
+ /**
530
+ * Groups rapid, individual `add()` calls into batches, flushing the whole
531
+ * accumulated group to `onFlush` at once — instead of debouncing,
532
+ * throttling, or rate-limiting, all of which discard some calls along the
533
+ * way. Nothing added to a `useBatcher` is ever dropped; it's only ever
534
+ * grouped.
535
+ *
536
+ * A batch flushes when any configured trigger fires first: reaching
537
+ * `maxSize` items, `maxWait` milliseconds since the batch's first item,
538
+ * or `quietPeriod` milliseconds of no new items. All three are optional
539
+ * and can be combined freely. If none are configured, only a manual
540
+ * `flush()` call ever empties the batch.
541
+ *
542
+ * Unlike the debounce/throttle/rate-limit hook families, there's no
543
+ * separate `Callback`/`State`/`Value` wrapper — `onFlush` is a single
544
+ * fixed handler (captured in a ref and always current, so a fresh inline
545
+ * function on every render is safe), and live access to the current batch
546
+ * contents is available via the `onItemsChange` option instead of a
547
+ * dedicated hook.
548
+ *
549
+ * @example
550
+ * ```tsx
551
+ * function AnalyticsProvider({ children }: { children: React.ReactNode }) {
552
+ * const { add } = useBatcher<AnalyticsEvent>(
553
+ * (events) => sendAnalyticsBatch(events),
554
+ * { maxSize: 20, maxWait: 5000 },
555
+ * );
556
+ *
557
+ * // `track` can be called as often as needed — events are grouped and
558
+ * // sent in batches of up to 20, at least once every 5 seconds.
559
+ * const track = (event: AnalyticsEvent) => add(event);
560
+ *
561
+ * return (
562
+ * <AnalyticsContext.Provider value={{ track }}>
563
+ * {children}
564
+ * </AnalyticsContext.Provider>
565
+ * );
566
+ * }
567
+ * ```
568
+ *
569
+ * @param onFlush - Called with every item accumulated since the last
570
+ * flush, as a snapshot array. Safe to pass a fresh inline function on
571
+ * every render.
572
+ * @param options - See {@link BatchOptions}.
573
+ * @returns See {@link UseBatcherReturn}.
574
+ */
575
+ export declare function useBatcher<Item>(onFlush: (items: readonly Item[]) => void, options?: BatchOptions<Item>): UseBatcherReturn<Item>;
420
576
  /**
421
577
  * Adds an optional custom equality comparator to any hook that manages a
422
578
  * value and needs to decide whether a "new" value is actually different
@@ -1966,15 +2122,6 @@ export interface FuzzyHighlighterProps {
1966
2122
  caseSensitive?: boolean;
1967
2123
  }
1968
2124
  export declare function FuzzyHighlighter({ text, query, className, caseSensitive, }: FuzzyHighlighterProps): React$1.JSX.Element;
1969
- export interface ModalLayoutProps {
1970
- modalId: string;
1971
- children: React$1.ReactNode;
1972
- wrapperClassName?: string;
1973
- wrapperStyle?: React$1.CSSProperties;
1974
- containerClassName?: string;
1975
- containerStyle?: React$1.CSSProperties;
1976
- }
1977
- export declare function ModalLayout({ modalId, children, wrapperClassName, wrapperStyle, containerClassName, containerStyle, }: ModalLayoutProps): import("react").ReactPortal | null;
1978
2125
  export type ExpansionId = string | number;
1979
2126
  export interface UseExpansionReturn<T> {
1980
2127
  expandedIds: ExpansionId[];
@@ -1994,20 +2141,6 @@ export declare function useExpansion<T = unknown>(options?: {
1994
2141
  initialExpandedIds?: ExpansionId[];
1995
2142
  multiple?: boolean;
1996
2143
  }): UseExpansionReturn<T>;
1997
- export interface UseModalStateReturn<TData> {
1998
- isOpen: boolean;
1999
- id: string | null;
2000
- data: TData | undefined;
2001
- }
2002
- export interface UseModalActionsReturn {
2003
- openModal: <T = unknown>(id: string, data?: T) => void;
2004
- closeModal: () => void;
2005
- clearModal: () => void;
2006
- }
2007
- export type UseModalReturn<TData> = UseModalStateReturn<TData> & UseModalActionsReturn;
2008
- export declare function useModalState<TData = unknown>(): UseModalStateReturn<TData>;
2009
- export declare function useModalActions(): UseModalActionsReturn;
2010
- export declare function useModal<TData = unknown>(): UseModalReturn<TData>;
2011
2144
  export type PinId = string | number;
2012
2145
  export interface UsePinReturn<T> {
2013
2146
  pinnedIds: PinId[];
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { t as e } from "./useEventListener.js";
2
2
  import { n as t, t as n } from "./events2.js";
3
- import { a as r, c as i, d as a, f as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g } from "./performance2.js";
4
- import { a as _, c as v, i as y, n as b, o as x, r as S, s as C, t as w } from "./state2.js";
5
- import { a as T, i as E, n as D, o as O, r as k, s as A, t as j } from "./storage2.js";
6
- import { a as M, c as N, i as P, n as F, o as I, r as L, s as R, t as z } from "./ui2.js";
7
- export { N as FuzzyHighlighter, P as ModalLayout, k as bigIntSerializer, E as dateSerializer, T as defaultSerializer, O as mapSerializer, A as setSerializer, t as useClickOutside, f as useDebouncedCallback, o as useDebouncedState, a as useDebouncedValue, l as useDebouncer, e as useEventListener, L as useExpansion, v as useFilter, C as useFuzzySearch, x as useGrouping, n as useKey, D as useLocalStorage, M as useModal, I as useModalActions, R as useModalState, _ as useMultipleSelection, y as useOrder, S as usePagination, F as usePin, c as useRateLimitedCallback, i as useRateLimitedState, m as useRateLimitedValue, g as useRateLimiter, j as useSessionStorage, b as useSingleSelection, w as useSort, r as useThrottledCallback, s as useThrottledState, p as useThrottledValue, d as useThrottler, u as useVirtualGrid, h as useVirtualList, z as useVisibility };
3
+ import { a as r, c as i, d as a, f as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _ } from "./performance2.js";
4
+ import { a as v, c as y, i as b, n as x, o as S, r as C, s as w, t as T } from "./state2.js";
5
+ import { a as E, i as D, n as O, o as k, r as A, s as j, t as M } from "./storage2.js";
6
+ import { i as N, n as P, r as F, t as I } from "./ui2.js";
7
+ export { N as FuzzyHighlighter, A as bigIntSerializer, D as dateSerializer, E as defaultSerializer, k as mapSerializer, j as setSerializer, s as useBatcher, t as useClickOutside, p as useDebouncedCallback, o as useDebouncedState, a as useDebouncedValue, u as useDebouncer, e as useEventListener, F as useExpansion, y as useFilter, w as useFuzzySearch, S as useGrouping, n as useKey, O as useLocalStorage, v as useMultipleSelection, b as useOrder, C as usePagination, P as usePin, l as useRateLimitedCallback, i as useRateLimitedState, h as useRateLimitedValue, _ as useRateLimiter, M as useSessionStorage, x as useSingleSelection, T as useSort, r as useThrottledCallback, c as useThrottledState, m as useThrottledValue, f as useThrottler, d as useVirtualGrid, g as useVirtualList, I as useVisibility };
@@ -2,6 +2,162 @@
2
2
 
3
3
  import { Key } from 'react';
4
4
 
5
+ /**
6
+ * Configuration for `useBatcher`.
7
+ *
8
+ * All three flush triggers (`maxSize`, `maxWait`, `quietPeriod`) are
9
+ * optional and independent — configure any combination, and whichever
10
+ * condition is met first triggers the flush. If none are configured, the
11
+ * batch only ever flushes when `flush()` is called manually.
12
+ */
13
+ export interface BatchOptions<Item> {
14
+ /**
15
+ * Flushes the batch immediately once it reaches this many items.
16
+ * Checked on every `add()` call, before either timer-based trigger is
17
+ * considered.
18
+ *
19
+ * Invalid input (not a positive number) is ignored — not clamped to a
20
+ * fallback — with a dev-mode warning, since there's no sensible
21
+ * default size to fall back to.
22
+ *
23
+ * @defaultValue `undefined` (no size ceiling)
24
+ */
25
+ maxSize?: number;
26
+ /**
27
+ * A hard ceiling, in milliseconds, on how long a batch can sit before
28
+ * flushing — measured from the moment the *first* item of the current
29
+ * batch was added, not the most recent one. Guarantees a maximum
30
+ * latency per item regardless of how long the batch keeps growing.
31
+ *
32
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
33
+ * warning.
34
+ *
35
+ * @defaultValue `undefined` (no time ceiling)
36
+ */
37
+ maxWait?: number;
38
+ /**
39
+ * Flushes the batch once this many milliseconds pass with no further
40
+ * items added — resets on every `add()` call, unlike `maxWait`. Use
41
+ * this when you want to wait for activity to genuinely settle before
42
+ * flushing, rather than enforcing a hard per-item latency ceiling.
43
+ *
44
+ * If both `maxWait` and `quietPeriod` are configured and `quietPeriod`
45
+ * is not shorter than `maxWait`, `maxWait` will almost always win the
46
+ * race — a dev-mode warning flags this combination.
47
+ *
48
+ * Invalid input (not a non-negative number) is ignored with a dev-mode
49
+ * warning.
50
+ *
51
+ * @defaultValue `undefined` (no quiet-period trigger)
52
+ */
53
+ quietPeriod?: number;
54
+ /**
55
+ * Called with a snapshot of the current batch contents every time it
56
+ * changes — after every `add()`, and after every flush or `cancel()`
57
+ * (with an empty array). This is the mechanism for getting live,
58
+ * reactive access to what's currently queued (e.g. a "3 items
59
+ * queued…" indicator) without `useBatcher` itself needing to hold the
60
+ * full item list in React state.
61
+ *
62
+ * Safe to pass a fresh inline function on every render — it's captured
63
+ * in a ref and refreshed via effect, same as `onFlush`.
64
+ *
65
+ * @defaultValue `undefined`
66
+ */
67
+ onItemsChange?: (items: readonly Item[]) => void;
68
+ }
69
+ /**
70
+ * The object returned by `useBatcher`.
71
+ */
72
+ export interface UseBatcherReturn<Item> {
73
+ /**
74
+ * Adds `item` to the current batch. Never rejected, never deferred to
75
+ * a future call — the item is always accepted immediately. Depending
76
+ * on the configured triggers, this may also cause an immediate flush
77
+ * (e.g. if `maxSize` is now reached).
78
+ */
79
+ add: (item: Item) => void;
80
+ /**
81
+ * Immediately flushes whatever is currently batched, bypassing
82
+ * `maxWait`/`quietPeriod` entirely. A no-op if the batch is empty —
83
+ * `onFlush` is never called with zero items.
84
+ */
85
+ flush: () => void;
86
+ /**
87
+ * Discards the current batch entirely, without ever calling
88
+ * `onFlush`. Clears any pending timers.
89
+ */
90
+ cancel: () => void;
91
+ /**
92
+ * Suspends all automatic flush triggers (`maxSize`, `maxWait`,
93
+ * `quietPeriod`). Items added via `add()` while paused still
94
+ * accumulate normally — pausing stops the flushing machinery, not the
95
+ * accumulation. The only way to flush while paused is a manual
96
+ * `flush()` call.
97
+ */
98
+ pause: () => void;
99
+ /**
100
+ * Resumes automatic flushing. If the batch already meets `maxSize`
101
+ * (because items kept arriving while paused), flushes immediately.
102
+ * Otherwise, re-arms `maxWait`/`quietPeriod` timers from scratch —
103
+ * pausing does not preserve partial progress toward either deadline;
104
+ * resuming starts a fresh clock for whatever's still batched.
105
+ */
106
+ resume: () => void;
107
+ /** The number of items currently in the batch. */
108
+ size: number;
109
+ /** `true` whenever `size > 0`. */
110
+ isPending: boolean;
111
+ /** `true` after `pause()`, until the next `resume()`. */
112
+ isPaused: boolean;
113
+ }
114
+ /**
115
+ * Groups rapid, individual `add()` calls into batches, flushing the whole
116
+ * accumulated group to `onFlush` at once — instead of debouncing,
117
+ * throttling, or rate-limiting, all of which discard some calls along the
118
+ * way. Nothing added to a `useBatcher` is ever dropped; it's only ever
119
+ * grouped.
120
+ *
121
+ * A batch flushes when any configured trigger fires first: reaching
122
+ * `maxSize` items, `maxWait` milliseconds since the batch's first item,
123
+ * or `quietPeriod` milliseconds of no new items. All three are optional
124
+ * and can be combined freely. If none are configured, only a manual
125
+ * `flush()` call ever empties the batch.
126
+ *
127
+ * Unlike the debounce/throttle/rate-limit hook families, there's no
128
+ * separate `Callback`/`State`/`Value` wrapper — `onFlush` is a single
129
+ * fixed handler (captured in a ref and always current, so a fresh inline
130
+ * function on every render is safe), and live access to the current batch
131
+ * contents is available via the `onItemsChange` option instead of a
132
+ * dedicated hook.
133
+ *
134
+ * @example
135
+ * ```tsx
136
+ * function AnalyticsProvider({ children }: { children: React.ReactNode }) {
137
+ * const { add } = useBatcher<AnalyticsEvent>(
138
+ * (events) => sendAnalyticsBatch(events),
139
+ * { maxSize: 20, maxWait: 5000 },
140
+ * );
141
+ *
142
+ * // `track` can be called as often as needed — events are grouped and
143
+ * // sent in batches of up to 20, at least once every 5 seconds.
144
+ * const track = (event: AnalyticsEvent) => add(event);
145
+ *
146
+ * return (
147
+ * <AnalyticsContext.Provider value={{ track }}>
148
+ * {children}
149
+ * </AnalyticsContext.Provider>
150
+ * );
151
+ * }
152
+ * ```
153
+ *
154
+ * @param onFlush - Called with every item accumulated since the last
155
+ * flush, as a snapshot array. Safe to pass a fresh inline function on
156
+ * every render.
157
+ * @param options - See {@link BatchOptions}.
158
+ * @returns See {@link UseBatcherReturn}.
159
+ */
160
+ export declare function useBatcher<Item>(onFlush: (items: readonly Item[]) => void, options?: BatchOptions<Item>): UseBatcherReturn<Item>;
5
161
  /**
6
162
  * Adds an optional custom equality comparator to any hook that manages a
7
163
  * value and needs to decide whether a "new" value is actually different
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, m as o, n as s, o as c, p as l, r as u, s as d, t as f, u as p } from "./performance2.js";
2
- export { l as useDebouncedCallback, r as useDebouncedState, n as useDebouncedValue, o as useDebouncer, a as useRateLimitedCallback, t as useRateLimitedState, d as useRateLimitedValue, p as useRateLimiter, e as useThrottledCallback, i as useThrottledState, u as useThrottledValue, c as useThrottler, s as useVirtualGrid, f as useVirtualList };
1
+ import { a as e, c as t, d as n, f as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m } from "./performance2.js";
2
+ export { i as useBatcher, u as useDebouncedCallback, r as useDebouncedState, n as useDebouncedValue, s as useDebouncer, o as useRateLimitedCallback, t as useRateLimitedState, f as useRateLimitedValue, m as useRateLimiter, e as useThrottledCallback, a as useThrottledState, d as useThrottledValue, l as useThrottler, c as useVirtualGrid, p as useVirtualList };