@himanshu-sorathiya/react-kit 1.0.23 → 1.0.25

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
@@ -3,184 +3,6 @@
3
3
  import React$1 from 'react';
4
4
  import { CSSProperties, Key, RefObject } from 'react';
5
5
 
6
- export type DateInput = Date | number | string;
7
- export type WeekStartsOn = 0 | 1 | 2 | 3 | 4 | 5 | 6;
8
- export type DateInterval = {
9
- start: Date;
10
- end: Date;
11
- };
12
- export type DateRange = {
13
- start: Date;
14
- end: Date;
15
- };
16
- export type Duration = {
17
- years?: number;
18
- months?: number;
19
- weeks?: number;
20
- days?: number;
21
- hours?: number;
22
- minutes?: number;
23
- seconds?: number;
24
- };
25
- export declare function toDate(input: DateInput): Date;
26
- export declare function isDate(value: unknown): value is Date;
27
- export declare function isValid(date: Date): boolean;
28
- export declare function createDate(year: number, month: number, day?: number): Date;
29
- export declare function getYear(date: DateInput): number;
30
- export declare function getMonth(date: DateInput): number;
31
- export declare function getDate(date: DateInput): number;
32
- export declare function getHours(date: DateInput): number;
33
- export declare function getMinutes(date: DateInput): number;
34
- export declare function getSeconds(date: DateInput): number;
35
- export declare function getMilliseconds(date: DateInput): number;
36
- export declare function getTimestamp(date: DateInput): number;
37
- export declare function getDayOfWeek(date: DateInput): number;
38
- export declare function getDaysInMonth(date: DateInput): number;
39
- export declare function getQuarter(date: DateInput): number;
40
- export declare function getDayOfYear(date: DateInput): number;
41
- declare const TOKEN_FORMATTERS: {
42
- yyyy: (d: Date) => string;
43
- yy: (d: Date) => string;
44
- MMMM: (d: Date, loc: string) => string;
45
- MMM: (d: Date, loc: string) => string;
46
- MM: (d: Date) => string;
47
- M: (d: Date) => string;
48
- dd: (d: Date) => string;
49
- d: (d: Date) => string;
50
- EEEE: (d: Date, loc: string) => string;
51
- EEE: (d: Date, loc: string) => string;
52
- E: (d: Date, loc: string) => string;
53
- HH: (d: Date) => string;
54
- H: (d: Date) => string;
55
- hh: (d: Date) => string;
56
- h: (d: Date) => string;
57
- mm: (d: Date) => string;
58
- ss: (d: Date) => string;
59
- SSS: (d: Date) => string;
60
- a: (d: Date, loc: string) => string;
61
- Q: (d: Date) => string;
62
- w: (d: Date) => string;
63
- D: (d: Date) => string;
64
- xxx: (d: Date) => string;
65
- xx: (d: Date) => string;
66
- x: (d: Date) => string;
67
- };
68
- export type FormatToken = keyof typeof TOKEN_FORMATTERS;
69
- export declare function format(date: DateInput, formatString: string, options?: {
70
- locale?: string;
71
- }): string;
72
- export declare function formatDate(date: DateInput, locale?: string, options?: Intl.DateTimeFormatOptions): string;
73
- export declare function formatRelativeTime(date: DateInput, baseDate?: DateInput, locale?: string): string;
74
- export declare function formatISO(date: DateInput, options?: {
75
- format?: "extended" | "basic";
76
- representation?: "complete" | "date" | "time";
77
- }): string;
78
- export declare function formatRFC3339(date: DateInput, options?: {
79
- fractionDigits?: 0 | 1 | 2 | 3;
80
- }): string;
81
- export declare function formatISO9075(date: DateInput, options?: {
82
- representation?: "complete" | "date" | "time";
83
- }): string;
84
- export declare function formatRFC2822(date: DateInput): string;
85
- export declare function formatDuration(duration: Duration, options?: {
86
- format?: ReadonlyArray<keyof Duration>;
87
- zero?: boolean;
88
- delimiter?: string;
89
- locale?: string;
90
- }): string;
91
- export declare function toISOString(date: DateInput): string;
92
- export declare function parseISO(isoString: string): Date;
93
- export declare function addMilliseconds(date: DateInput, amount: number): Date;
94
- export declare function addSeconds(date: DateInput, amount: number): Date;
95
- export declare function addMinutes(date: DateInput, amount: number): Date;
96
- export declare function addHours(date: DateInput, amount: number): Date;
97
- export declare function addDays(date: DateInput, amount: number): Date;
98
- export declare function addWeeks(date: DateInput, amount: number): Date;
99
- export declare function addMonths(date: DateInput, amount: number): Date;
100
- export declare function addYears(date: DateInput, amount: number): Date;
101
- export declare function subMilliseconds(date: DateInput, amount: number): Date;
102
- export declare function subSeconds(date: DateInput, amount: number): Date;
103
- export declare function subMinutes(date: DateInput, amount: number): Date;
104
- export declare function subHours(date: DateInput, amount: number): Date;
105
- export declare function subDays(date: DateInput, amount: number): Date;
106
- export declare function subWeeks(date: DateInput, amount: number): Date;
107
- export declare function subMonths(date: DateInput, amount: number): Date;
108
- export declare function subYears(date: DateInput, amount: number): Date;
109
- export declare function setYear(date: DateInput, year: number): Date;
110
- export declare function setMonth(date: DateInput, month: number): Date;
111
- export declare function setDate(date: DateInput, day: number): Date;
112
- export declare function setHours(date: DateInput, hours: number): Date;
113
- export declare function setMinutes(date: DateInput, minutes: number): Date;
114
- export declare function setSeconds(date: DateInput, seconds: number): Date;
115
- export declare function setMilliseconds(date: DateInput, ms: number): Date;
116
- export declare function startOfDay(date: DateInput): Date;
117
- export declare function endOfDay(date: DateInput): Date;
118
- export declare function startOfHour(date: DateInput): Date;
119
- export declare function endOfHour(date: DateInput): Date;
120
- export declare function startOfMinute(date: DateInput): Date;
121
- export declare function endOfMinute(date: DateInput): Date;
122
- export declare function startOfWeek(date: DateInput, weekStartsOn?: WeekStartsOn): Date;
123
- export declare function endOfWeek(date: DateInput, weekStartsOn?: WeekStartsOn): Date;
124
- export declare function startOfMonth(date: DateInput): Date;
125
- export declare function endOfMonth(date: DateInput): Date;
126
- export declare function startOfQuarter(date: DateInput): Date;
127
- export declare function endOfQuarter(date: DateInput): Date;
128
- export declare function startOfYear(date: DateInput): Date;
129
- export declare function endOfYear(date: DateInput): Date;
130
- export declare function differenceInMilliseconds(dateLeft: DateInput, dateRight: DateInput): number;
131
- export declare function differenceInSeconds(dateLeft: DateInput, dateRight: DateInput): number;
132
- export declare function differenceInMinutes(dateLeft: DateInput, dateRight: DateInput): number;
133
- export declare function differenceInHours(dateLeft: DateInput, dateRight: DateInput): number;
134
- export declare function differenceInDays(dateLeft: DateInput, dateRight: DateInput): number;
135
- export declare function differenceInWeeks(dateLeft: DateInput, dateRight: DateInput): number;
136
- export declare function differenceInMonths(dateLeft: DateInput, dateRight: DateInput): number;
137
- export declare function differenceInYears(dateLeft: DateInput, dateRight: DateInput): number;
138
- export declare function addBusinessDays(date: DateInput, amount: number): Date;
139
- export declare function differenceInBusinessDays(dateLeft: DateInput, dateRight: DateInput): number;
140
- export declare function clampDate(date: DateInput, min: DateInput, max: DateInput): Date;
141
- export declare function min(dates: Date[]): Date | null;
142
- export declare function max(dates: Date[]): Date | null;
143
- export declare function closestTo(date: DateInput, datesArray: Date[]): Date | null;
144
- export declare function eachDayOfInterval(interval: DateInterval): Date[];
145
- export declare function eachMonthOfInterval(interval: DateInterval): Date[];
146
- export declare function eachYearOfInterval(interval: DateInterval): Date[];
147
- export declare function fromUnixTime(seconds: number): Date;
148
- export declare function toUnixTime(date: DateInput): number;
149
- export declare function roundToNearestMinutes(date: DateInput, step: number): Date;
150
- export declare function getISOWeek(date: DateInput): number;
151
- export declare function setISOWeek(date: DateInput, week: number): Date;
152
- export declare function intervalToDuration(interval: DateInterval): Duration;
153
- export declare function durationToMilliseconds(duration: Duration): number;
154
- export declare function isSameDay(dateA: DateInput, dateB: DateInput): boolean;
155
- export declare function isSameMonth(dateA: DateInput, dateB: DateInput): boolean;
156
- export declare function isSameYear(dateA: DateInput, dateB: DateInput): boolean;
157
- export declare function isSameQuarter(dateA: DateInput, dateB: DateInput): boolean;
158
- export declare function isSameWeek(dateA: DateInput, dateB: DateInput, weekStartsOn?: WeekStartsOn): boolean;
159
- export declare function isSameHour(dateA: DateInput, dateB: DateInput): boolean;
160
- export declare function isSameMinute(dateA: DateInput, dateB: DateInput): boolean;
161
- export declare function isSameSecond(dateA: DateInput, dateB: DateInput): boolean;
162
- export declare function isSameTime(dateA: DateInput, dateB: DateInput): boolean;
163
- export declare function isBefore(date: DateInput, compareDate: DateInput): boolean;
164
- export declare function isAfter(date: DateInput, compareDate: DateInput): boolean;
165
- export declare function isEqual(dateA: DateInput, dateB: DateInput): boolean;
166
- export declare function isWithinRange(date: DateInput, start: DateInput, end: DateInput): boolean;
167
- export declare function isOverlapping(rangeA: DateRange, rangeB: DateRange): boolean;
168
- export declare function isToday(date: DateInput): boolean;
169
- export declare function isYesterday(date: DateInput): boolean;
170
- export declare function isTomorrow(date: DateInput): boolean;
171
- export declare function isPast(date: DateInput): boolean;
172
- export declare function isFuture(date: DateInput): boolean;
173
- export declare function isThisWeek(date: DateInput, weekStartsOn?: WeekStartsOn): boolean;
174
- export declare function isThisMonth(date: DateInput): boolean;
175
- export declare function isThisYear(date: DateInput): boolean;
176
- export declare function isFirstDayOfMonth(date: DateInput): boolean;
177
- export declare function isLastDayOfMonth(date: DateInput): boolean;
178
- export declare function isWeekend(date: DateInput): boolean;
179
- export declare function isWeekday(date: DateInput): boolean;
180
- export declare function isAM(date: DateInput): boolean;
181
- export declare function isPM(date: DateInput): boolean;
182
- export declare function isLeapYear(yearOrDate: number | Date): boolean;
183
- export declare function isInLeapYear(date: DateInput): boolean;
184
6
  export type ClickOutsideEvent = MouseEvent | TouchEvent | PointerEvent | Event;
185
7
  export type ClickOutsideTarget = HTMLElement | null;
186
8
  export type ClickOutsideTargetRef = React$1.RefObject<ClickOutsideTarget> | ClickOutsideTarget;
@@ -585,17 +407,16 @@ export interface UsePaginationReturn<T> {
585
407
  resetPagination: () => void;
586
408
  }
587
409
  export declare function usePagination<T>(data: T[] | undefined, initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
588
- type SelectionId$1 = string | number;
589
410
  export interface UseSingleSelectionReturn {
590
- selectedId: SelectionId$1 | undefined;
411
+ selectedId: SelectionId | undefined;
591
412
  hasSelection: boolean;
592
- select: (id: SelectionId$1) => void;
413
+ select: (id: SelectionId) => void;
593
414
  deselect: () => void;
594
- toggle: (id: SelectionId$1) => void;
595
- isSelected: (id: SelectionId$1) => boolean;
415
+ toggle: (id: SelectionId) => void;
416
+ isSelected: (id: SelectionId) => boolean;
596
417
  resetSelection: () => void;
597
418
  }
598
- export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
419
+ export declare function useSingleSelection(initialSelectedId?: SelectionId): UseSingleSelectionReturn;
599
420
  export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
600
421
  export interface BaseSortOptions {
601
422
  desc?: boolean;
@@ -637,6 +458,44 @@ export interface UseSortReturn<T> {
637
458
  getSortIndex: (id: string) => number | undefined;
638
459
  }
639
460
  export declare function useSort<T>(data?: T[], initialSorts?: SortState): UseSortReturn<T>;
461
+ export interface StorageSerializer<T> {
462
+ serialize: (value: T) => string;
463
+ deserialize: (raw: string) => T;
464
+ }
465
+ export interface BaseStorageOptions<T> {
466
+ serializer?: StorageSerializer<T>;
467
+ initializeWithValue?: boolean;
468
+ sameInstanceSync?: boolean;
469
+ }
470
+ export interface StorageCustomEventDetail {
471
+ value: string | null;
472
+ instanceId: symbol;
473
+ }
474
+ export interface UseLocalStorageOptions<T> extends BaseStorageOptions<T> {
475
+ crossInstanceSync?: boolean;
476
+ }
477
+ export interface UseLocalStorageReturn<T> {
478
+ value: T | undefined;
479
+ setValue: (valueOrUpdater: T | ((prev: T | undefined) => T)) => void;
480
+ removeValue: () => void;
481
+ isHydrated: boolean;
482
+ error: Error | null;
483
+ }
484
+ export declare function useLocalStorage<T = unknown>(key: string, initialValue?: T, options?: UseLocalStorageOptions<T>): UseLocalStorageReturn<T>;
485
+ export type UseSessionStorageOptions<T> = BaseStorageOptions<T>;
486
+ export interface UseSessionStorageReturn<T> {
487
+ value: T | undefined;
488
+ setValue: (valueOrUpdater: T | ((prev: T | undefined) => T)) => void;
489
+ removeValue: () => void;
490
+ isHydrated: boolean;
491
+ error: Error | null;
492
+ }
493
+ export declare function useSessionStorage<T = unknown>(key: string, initialValue?: T, options?: UseSessionStorageOptions<T>): UseSessionStorageReturn<T>;
494
+ export declare const defaultSerializer: StorageSerializer<unknown>;
495
+ export declare function mapSerializer<K, V>(): StorageSerializer<Map<K, V>>;
496
+ export declare function setSerializer<V>(): StorageSerializer<Set<V>>;
497
+ export declare const dateSerializer: StorageSerializer<Date>;
498
+ export declare const bigIntSerializer: StorageSerializer<bigint>;
640
499
  export interface FuzzyHighlighterProps {
641
500
  text: string;
642
501
  query: string;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
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 "./useEventListener.js";
3
- import { n as ut, t as dt } from "./events2.js";
4
- import { a as ft, c as pt, d as mt, f as ht, i as gt, l as _t, n as vt, o as yt, r as bt, s as xt, t as St, u as Ct } from "./performance2.js";
5
- import { a as wt, c as Tt, i as Et, n as Dt, o as Ot, r as kt, s as At, t as jt } from "./state2.js";
6
- import { a as Mt, c as Nt, i as Pt, n as Ft, o as It, r as Lt, s as Rt, t as zt } from "./ui2.js";
7
- export { Nt as FuzzyHighlighter, Pt as ModalLayout, e as addBusinessDays, t as addDays, n as addHours, r as addMilliseconds, i as addMinutes, a as addMonths, o as addSeconds, s as addWeeks, c as addYears, l as clampDate, u as closestTo, d as createDate, f as differenceInBusinessDays, p as differenceInDays, m as differenceInHours, h as differenceInMilliseconds, g as differenceInMinutes, _ as differenceInMonths, v as differenceInSeconds, y as differenceInWeeks, b as differenceInYears, x as durationToMilliseconds, S as eachDayOfInterval, C as eachMonthOfInterval, w as eachYearOfInterval, T as endOfDay, E as endOfHour, D as endOfMinute, O as endOfMonth, k as endOfQuarter, A as endOfWeek, j as endOfYear, M as format, N as formatDate, P as formatDuration, F as formatISO, I as formatISO9075, L as formatRFC2822, R as formatRFC3339, z as formatRelativeTime, B as fromUnixTime, V as getDate, H as getDayOfWeek, U as getDayOfYear, W as getDaysInMonth, G as getHours, K as getISOWeek, q as getMilliseconds, J as getMinutes, Y as getMonth, X as getQuarter, Z as getSeconds, Q as getTimestamp, $ as getYear, ee as intervalToDuration, te as isAM, ne as isAfter, re as isBefore, ie as isDate, ae as isEqual, oe as isFirstDayOfMonth, se as isFuture, ce as isInLeapYear, le as isLastDayOfMonth, ue as isLeapYear, de as isOverlapping, fe as isPM, pe as isPast, me as isSameDay, he as isSameHour, ge as isSameMinute, _e as isSameMonth, ve as isSameQuarter, ye as isSameSecond, be as isSameTime, xe as isSameWeek, Se as isSameYear, Ce as isThisMonth, we as isThisWeek, Te as isThisYear, Ee as isToday, De as isTomorrow, Oe as isValid, ke as isWeekday, Ae as isWeekend, je as isWithinRange, Me as isYesterday, Ne as max, Pe as min, Fe as parseISO, Ie as roundToNearestMinutes, Le as setDate, Re as setHours, ze as setISOWeek, Be as setMilliseconds, Ve as setMinutes, He as setMonth, Ue as setSeconds, We as setYear, Ge as startOfDay, Ke as startOfHour, qe as startOfMinute, Je as startOfMonth, Ye as startOfQuarter, Xe as startOfWeek, Ze as startOfYear, Qe as subDays, $e as subHours, et as subMilliseconds, tt as subMinutes, nt as subMonths, rt as subSeconds, it as subWeeks, at as subYears, ot as toDate, st as toISOString, ct as toUnixTime, ut as useClickOutside, ht as useDebounce, mt as useDebouncedCallback, Ct as useDebouncedState, _t as useDebouncedValue, lt as useEventListener, Lt as useExpansion, Tt as useFilter, At as useFuzzySearch, Ot as useGrouping, dt as useKey, Mt as useModal, It as useModalActions, Rt as useModalState, wt as useMultipleSelection, Et as useOrder, kt as usePagination, Ft as usePin, pt as useRateLimit, xt as useRateLimitedCallback, Dt as useSingleSelection, jt as useSort, yt as useThrottle, ft as useThrottledCallback, gt as useThrottledState, bt as useThrottledValue, vt as useVirtualGrid, St as useVirtualList, zt as useVisibility };
1
+ import { t as e } from "./useEventListener.js";
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, n as l, o as u, r as d, s as f, t as p, u as m } from "./performance2.js";
4
+ import { a as h, c as g, i as _, n as v, o as y, r as b, s as x, t as S } from "./state2.js";
5
+ import { a as C, i as w, n as T, o as E, r as D, s as O, t as k } from "./storage2.js";
6
+ import { a as A, c as j, i as M, n as N, o as P, r as F, s as I, t as L } from "./ui2.js";
7
+ export { j as FuzzyHighlighter, M as ModalLayout, D as bigIntSerializer, w as dateSerializer, C as defaultSerializer, E as mapSerializer, O as setSerializer, t as useClickOutside, o as useDebounce, a as useDebouncedCallback, m as useDebouncedState, c as useDebouncedValue, e as useEventListener, F as useExpansion, g as useFilter, x as useFuzzySearch, y as useGrouping, n as useKey, T as useLocalStorage, A as useModal, P as useModalActions, I as useModalState, h as useMultipleSelection, _ as useOrder, b as usePagination, N as usePin, i as useRateLimit, f as useRateLimitedCallback, k as useSessionStorage, v as useSingleSelection, S as useSort, u as useThrottle, r as useThrottledCallback, s as useThrottledState, d as useThrottledValue, l as useVirtualGrid, p as useVirtualList, L as useVisibility };
@@ -197,7 +197,7 @@ function _(e, t, n = {}) {
197
197
  }, [e, o]), i;
198
198
  }
199
199
  //#endregion
200
- //#region src/performance/virtualShared/offsetCache.ts
200
+ //#region src/shared/virtualShared/offsetCache.ts
201
201
  var v = class {
202
202
  _offsets = /* @__PURE__ */ new Float64Array();
203
203
  _count = 0;
@@ -266,7 +266,7 @@ var v = class {
266
266
  }
267
267
  };
268
268
  //#endregion
269
- //#region src/performance/virtualShared/utils.ts
269
+ //#region src/shared/virtualShared/utils.ts
270
270
  function y(e, t) {
271
271
  let n = typeof t == "function" ? t(e) : t, r = Number(n);
272
272
  return Number.isFinite(r) && r >= 0 ? r : 0;
package/dist/state.d.ts CHANGED
@@ -179,17 +179,16 @@ export interface UsePaginationReturn<T> {
179
179
  resetPagination: () => void;
180
180
  }
181
181
  export declare function usePagination<T>(data: T[] | undefined, initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
182
- type SelectionId$1 = string | number;
183
182
  export interface UseSingleSelectionReturn {
184
- selectedId: SelectionId$1 | undefined;
183
+ selectedId: SelectionId | undefined;
185
184
  hasSelection: boolean;
186
- select: (id: SelectionId$1) => void;
185
+ select: (id: SelectionId) => void;
187
186
  deselect: () => void;
188
- toggle: (id: SelectionId$1) => void;
189
- isSelected: (id: SelectionId$1) => boolean;
187
+ toggle: (id: SelectionId) => void;
188
+ isSelected: (id: SelectionId) => boolean;
190
189
  resetSelection: () => void;
191
190
  }
192
- export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
191
+ export declare function useSingleSelection(initialSelectedId?: SelectionId): UseSingleSelectionReturn;
193
192
  export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
194
193
  export interface BaseSortOptions {
195
194
  desc?: boolean;
@@ -0,0 +1,42 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export interface StorageSerializer<T> {
4
+ serialize: (value: T) => string;
5
+ deserialize: (raw: string) => T;
6
+ }
7
+ export interface BaseStorageOptions<T> {
8
+ serializer?: StorageSerializer<T>;
9
+ initializeWithValue?: boolean;
10
+ sameInstanceSync?: boolean;
11
+ }
12
+ export interface StorageCustomEventDetail {
13
+ value: string | null;
14
+ instanceId: symbol;
15
+ }
16
+ export interface UseLocalStorageOptions<T> extends BaseStorageOptions<T> {
17
+ crossInstanceSync?: boolean;
18
+ }
19
+ export interface UseLocalStorageReturn<T> {
20
+ value: T | undefined;
21
+ setValue: (valueOrUpdater: T | ((prev: T | undefined) => T)) => void;
22
+ removeValue: () => void;
23
+ isHydrated: boolean;
24
+ error: Error | null;
25
+ }
26
+ export declare function useLocalStorage<T = unknown>(key: string, initialValue?: T, options?: UseLocalStorageOptions<T>): UseLocalStorageReturn<T>;
27
+ export type UseSessionStorageOptions<T> = BaseStorageOptions<T>;
28
+ export interface UseSessionStorageReturn<T> {
29
+ value: T | undefined;
30
+ setValue: (valueOrUpdater: T | ((prev: T | undefined) => T)) => void;
31
+ removeValue: () => void;
32
+ isHydrated: boolean;
33
+ error: Error | null;
34
+ }
35
+ export declare function useSessionStorage<T = unknown>(key: string, initialValue?: T, options?: UseSessionStorageOptions<T>): UseSessionStorageReturn<T>;
36
+ export declare const defaultSerializer: StorageSerializer<unknown>;
37
+ export declare function mapSerializer<K, V>(): StorageSerializer<Map<K, V>>;
38
+ export declare function setSerializer<V>(): StorageSerializer<Set<V>>;
39
+ export declare const dateSerializer: StorageSerializer<Date>;
40
+ export declare const bigIntSerializer: StorageSerializer<bigint>;
41
+
42
+ export {};
@@ -0,0 +1,2 @@
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./storage2.js";
2
+ export { i as bigIntSerializer, t as dateSerializer, e as defaultSerializer, r as mapSerializer, a as setSerializer, n as useLocalStorage, o as useSessionStorage };
@@ -0,0 +1,261 @@
1
+ import { t as e } from "./useEventListener.js";
2
+ import { useCallback as t, useEffect as n, useRef as r, useState as i } from "react";
3
+ //#region src/shared/storageShared/serializers.ts
4
+ var a = {
5
+ serialize: (e) => JSON.stringify(e),
6
+ deserialize: (e) => JSON.parse(e)
7
+ };
8
+ function o() {
9
+ return {
10
+ serialize: (e) => JSON.stringify(Array.from(e.entries())),
11
+ deserialize: (e) => new Map(JSON.parse(e))
12
+ };
13
+ }
14
+ function s() {
15
+ return {
16
+ serialize: (e) => JSON.stringify(Array.from(e.values())),
17
+ deserialize: (e) => new Set(JSON.parse(e))
18
+ };
19
+ }
20
+ var c = {
21
+ serialize: (e) => e.toISOString(),
22
+ deserialize: (e) => {
23
+ let t = new Date(e);
24
+ if (isNaN(t.getTime())) throw Error(`[react-kit] dateSerializer: invalid date string "${e}"`);
25
+ return t;
26
+ }
27
+ }, l = {
28
+ serialize: (e) => e.toString(),
29
+ deserialize: (e) => {
30
+ try {
31
+ return BigInt(e);
32
+ } catch {
33
+ throw Error(`[react-kit] bigIntSerializer: cannot convert "${e}" to bigint`);
34
+ }
35
+ }
36
+ }, u = "react-kit:use-local-storage";
37
+ //#endregion
38
+ //#region src/storage/useLocalStorage/utils.ts
39
+ function d() {
40
+ if (typeof window > "u") return null;
41
+ try {
42
+ return window.localStorage;
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+ function f(e, t, n, r) {
48
+ try {
49
+ let i = e.getItem(t);
50
+ return i === null ? {
51
+ value: n,
52
+ error: null
53
+ } : {
54
+ value: r.deserialize(i),
55
+ error: null
56
+ };
57
+ } catch (e) {
58
+ return {
59
+ value: n,
60
+ error: e instanceof Error ? e : Error(String(e))
61
+ };
62
+ }
63
+ }
64
+ function p(e, t, n) {
65
+ let r = {
66
+ value: t,
67
+ instanceId: n
68
+ }, i = new CustomEvent(`${u}:${e}`, { detail: r });
69
+ window.dispatchEvent(i);
70
+ }
71
+ //#endregion
72
+ //#region src/storage/useLocalStorage/useLocalStorage.ts
73
+ function m(o, s, c = {}) {
74
+ let { serializer: l = a, initializeWithValue: m = !0, sameInstanceSync: h = !0, crossInstanceSync: g = !0 } = c, [_] = i(() => o), v = r(_), y = o !== _, b = `${u}:${_}`, x = r(Symbol()), S = r(l);
75
+ n(() => {
76
+ S.current = l;
77
+ }, [l]);
78
+ let [C, w] = i(() => {
79
+ if (!m) return;
80
+ let e = d();
81
+ if (!e) return s;
82
+ let { value: t } = f(e, o, s, l);
83
+ return t;
84
+ }), T = r(C);
85
+ n(() => {
86
+ T.current = C;
87
+ }, [C]);
88
+ let [E, D] = i(m && typeof window < "u"), [O, k] = i(null);
89
+ n(() => {
90
+ if (!y) return;
91
+ let e = /* @__PURE__ */ Error(`[react-kit:use-local-storage] Changing the storage key at runtime is not supported. Still using original key: "${v.current}". Received new key: "${o}".`);
92
+ console.warn(e.message), k(e);
93
+ }, [o, y]), n(() => {
94
+ if (m) return;
95
+ let e = d(), { value: t, error: n } = e === null ? {
96
+ value: s,
97
+ error: null
98
+ } : f(e, v.current, s, S.current);
99
+ n && (console.warn(`[react-kit:use-local-storage] Failed to read key "${v.current}" from localStorage:`, n.message), k(n)), w(t), D(!0);
100
+ }, [m]);
101
+ let A = t((e) => {
102
+ let t = d();
103
+ if (!t) return;
104
+ let n = T.current, r = typeof e == "function" ? e(n) : e;
105
+ try {
106
+ let e = S.current.serialize(r);
107
+ t.setItem(v.current, e), w(r), k(null), h && p(v.current, e, x.current);
108
+ } catch (e) {
109
+ let t = e instanceof Error ? e : Error(String(e));
110
+ console.warn(`[react-kit:use-local-storage] Failed to write key "${v.current}" to localStorage:`, t.message), k(t);
111
+ }
112
+ }, [h]), j = t(() => {
113
+ let e = d();
114
+ e && (e.removeItem(v.current), w(s), k(null), h && p(v.current, null, x.current));
115
+ }, [h]);
116
+ return e("storage", (e) => {
117
+ if (g && e.storageArea === d() && e.key === v.current) {
118
+ if (e.newValue === null) {
119
+ w(s), k(null);
120
+ return;
121
+ }
122
+ try {
123
+ let t = S.current.deserialize(e.newValue);
124
+ w(t), k(null);
125
+ } catch (e) {
126
+ let t = e instanceof Error ? e : Error(String(e));
127
+ console.warn(`[react-kit:use-local-storage] Failed to deserialize cross-tab update for key "${v.current}":`, t.message), w(s), k(t);
128
+ }
129
+ }
130
+ }), e(b, (e) => {
131
+ if (!h) return;
132
+ let t = e.detail;
133
+ if (t.instanceId !== x.current) {
134
+ if (t.value === null) {
135
+ w(s), k(null);
136
+ return;
137
+ }
138
+ try {
139
+ let e = S.current.deserialize(t.value);
140
+ w(e), k(null);
141
+ } catch (e) {
142
+ let t = e instanceof Error ? e : Error(String(e));
143
+ console.warn(`[react-kit:use-local-storage] Failed to deserialize same-tab update for key "${v.current}":`, t.message), w(s), k(t);
144
+ }
145
+ }
146
+ }, { target: typeof window > "u" ? null : window }), {
147
+ value: C,
148
+ setValue: A,
149
+ removeValue: j,
150
+ isHydrated: E,
151
+ error: O
152
+ };
153
+ }
154
+ //#endregion
155
+ //#region src/storage/useSessionStorage/constants.ts
156
+ var h = "react-kit:use-session-storage";
157
+ //#endregion
158
+ //#region src/storage/useSessionStorage/utils.ts
159
+ function g() {
160
+ if (typeof window > "u") return null;
161
+ try {
162
+ return window.sessionStorage;
163
+ } catch {
164
+ return null;
165
+ }
166
+ }
167
+ function _(e, t, n, r) {
168
+ try {
169
+ let i = e.getItem(t);
170
+ return i === null ? {
171
+ value: n,
172
+ error: null
173
+ } : {
174
+ value: r.deserialize(i),
175
+ error: null
176
+ };
177
+ } catch (e) {
178
+ return {
179
+ value: n,
180
+ error: e instanceof Error ? e : Error(String(e))
181
+ };
182
+ }
183
+ }
184
+ function v(e, t, n) {
185
+ let r = {
186
+ value: t,
187
+ instanceId: n
188
+ }, i = new CustomEvent(`${h}:${e}`, { detail: r });
189
+ window.dispatchEvent(i);
190
+ }
191
+ //#endregion
192
+ //#region src/storage/useSessionStorage/useSessionStorage.ts
193
+ function y(o, s, c = {}) {
194
+ let { serializer: l = a, initializeWithValue: u = !0, sameInstanceSync: d = !0 } = c, [f] = i(() => o), p = r(f), m = o !== f, y = `${h}:${f}`, b = r(Symbol()), x = r(l);
195
+ n(() => {
196
+ x.current = l;
197
+ }, [l]);
198
+ let [S, C] = i(() => {
199
+ if (!u) return;
200
+ let e = g();
201
+ if (!e) return s;
202
+ let { value: t } = _(e, o, s, l);
203
+ return t;
204
+ }), w = r(S);
205
+ n(() => {
206
+ w.current = S;
207
+ }, [S]);
208
+ let [T, E] = i(u && typeof window < "u"), [D, O] = i(null);
209
+ n(() => {
210
+ if (!m) return;
211
+ let e = /* @__PURE__ */ Error(`[react-kit:use-session-storage] Changing the storage key at runtime is not supported. Still using original key: "${p.current}". Received new key: "${o}".`);
212
+ console.warn(e.message), O(e);
213
+ }, [o, m]), n(() => {
214
+ if (u) return;
215
+ let e = g(), { value: t, error: n } = e === null ? {
216
+ value: s,
217
+ error: null
218
+ } : _(e, p.current, s, x.current);
219
+ n && (console.warn(`[react-kit:use-session-storage] Failed to read key "${p.current}" from sessionStorage:`, n.message), O(n)), C(t), E(!0);
220
+ }, [u]);
221
+ let k = t((e) => {
222
+ let t = g();
223
+ if (!t) return;
224
+ let n = w.current, r = typeof e == "function" ? e(n) : e;
225
+ try {
226
+ let e = x.current.serialize(r);
227
+ t.setItem(p.current, e), C(r), O(null), d && v(p.current, e, b.current);
228
+ } catch (e) {
229
+ let t = e instanceof Error ? e : Error(String(e));
230
+ console.warn(`[react-kit:use-session-storage] Failed to write key "${p.current}" to sessionStorage:`, t.message), O(t);
231
+ }
232
+ }, [d]), A = t(() => {
233
+ let e = g();
234
+ e && (e.removeItem(p.current), C(s), O(null), d && v(p.current, null, b.current));
235
+ }, [d]);
236
+ return e(y, (e) => {
237
+ if (!d) return;
238
+ let t = e.detail;
239
+ if (t.instanceId !== b.current) {
240
+ if (t.value === null) {
241
+ C(s), O(null);
242
+ return;
243
+ }
244
+ try {
245
+ let e = x.current.deserialize(t.value);
246
+ C(e), O(null);
247
+ } catch (e) {
248
+ let t = e instanceof Error ? e : Error(String(e));
249
+ console.warn(`[react-kit:use-session-storage] Failed to deserialize same-tab update for key "${p.current}":`, t.message), C(s), O(t);
250
+ }
251
+ }
252
+ }, { target: typeof window > "u" ? null : window }), {
253
+ value: S,
254
+ setValue: k,
255
+ removeValue: A,
256
+ isHydrated: T,
257
+ error: D
258
+ };
259
+ }
260
+ //#endregion
261
+ export { a, c as i, m as n, o, l as r, s, y as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@himanshu-sorathiya/react-kit",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "An opinionated collection of react hooks, and reusable UI components.",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -29,15 +29,15 @@
29
29
  "types": "./dist/events.d.ts",
30
30
  "import": "./dist/events.js"
31
31
  },
32
- "./datetime": {
33
- "types": "./dist/datetime.d.ts",
34
- "import": "./dist/datetime.js"
32
+ "./storage": {
33
+ "types": "./dist/storage.d.ts",
34
+ "import": "./dist/storage.js"
35
35
  },
36
36
  "./styles.css": "./dist/index.css"
37
37
  },
38
38
  "scripts": {
39
39
  "dev": "vite",
40
- "build": "vite build && dts-bundle-generator --project tsconfig.app.json -o dist/index.d.ts src/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/ui.d.ts src/ui/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/state.d.ts src/state/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/performance.d.ts src/performance/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/events.d.ts src/events/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/datetime.d.ts src/datetime/index.ts",
40
+ "build": "vite build && dts-bundle-generator --project tsconfig.app.json -o dist/index.d.ts src/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/ui.d.ts src/ui/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/state.d.ts src/state/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/performance.d.ts src/performance/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/events.d.ts src/events/index.ts && dts-bundle-generator --project tsconfig.app.json -o dist/storage.d.ts src/storage/index.ts",
41
41
  "lint": "eslint .",
42
42
  "preview": "vite preview",
43
43
  "format": "prettier . --write"