@himanshu-sorathiya/react-kit 1.0.5 → 1.0.7
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 +21 -2
- package/dist/index.js +129 -77
- package/package.json +1 -1
- package/dist/index.css +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface ModalLayoutProps {
|
|
4
4
|
children: React.ReactNode;
|
|
5
5
|
className?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function ModalLayout({ children, className }: ModalLayoutProps): import("react").ReactPortal;
|
|
8
|
+
export interface DebounceOptions {
|
|
9
|
+
maxWait?: number;
|
|
10
|
+
leading?: boolean;
|
|
11
|
+
trailing?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface UseDebounceReturn<Args extends any[]> {
|
|
14
|
+
debouncedFunc: (...args: Args) => void;
|
|
15
|
+
cancel: () => void;
|
|
16
|
+
flush: () => void;
|
|
17
|
+
isPending: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function useDebounce<Args extends any[]>(func: (...args: Args) => void, delay: number, options?: DebounceOptions): UseDebounceReturn<Args>;
|
|
20
|
+
export interface DebouncedValueOptions {
|
|
21
|
+
maxWait?: number;
|
|
22
|
+
leading?: boolean;
|
|
23
|
+
trailing?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type UseDebouncedValueReturn<T> = T;
|
|
26
|
+
export declare function useDebouncedValue<T>(value: T, delay: number, options?: DebouncedValueOptions): UseDebouncedValueReturn<T>;
|
|
8
27
|
export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
|
|
9
28
|
export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
|
|
10
29
|
export type NumberOperator = "equals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "between";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useCallback as e, useState as i, useMemo as n, useRef as r, useEffect as t } from "react";
|
|
1
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
3
2
|
import { createPortal as a } from "react-dom";
|
|
3
|
+
import { createStore as o, useSelector as s } from "@tanstack/react-store";
|
|
4
4
|
import { jsx as c } from "react/jsx-runtime";
|
|
5
5
|
//#region src/store/modalStore.ts
|
|
6
6
|
var l = o({
|
|
@@ -30,7 +30,7 @@ function u() {
|
|
|
30
30
|
}
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region src/components/Modal.tsx
|
|
33
|
-
function d({ children: e, className: n
|
|
33
|
+
function d({ children: e, className: n }) {
|
|
34
34
|
let { id: i, closeModal: o } = u(), s = r(null);
|
|
35
35
|
return t(() => {
|
|
36
36
|
let e = s.current;
|
|
@@ -40,7 +40,7 @@ function d({ children: e, className: n = "" }) {
|
|
|
40
40
|
onCancel: (e) => {
|
|
41
41
|
e.preventDefault(), o();
|
|
42
42
|
},
|
|
43
|
-
className: `universal-modal ${n
|
|
43
|
+
className: `universal-modal ${n}`,
|
|
44
44
|
children: /* @__PURE__ */ c("div", {
|
|
45
45
|
className: "modal-container",
|
|
46
46
|
children: e
|
|
@@ -48,8 +48,48 @@ function d({ children: e, className: n = "" }) {
|
|
|
48
48
|
}), document.body);
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
|
+
//#region src/hooks/useDebounce.ts
|
|
52
|
+
function f(n, a, o = {}) {
|
|
53
|
+
let [s, c] = i(!1), l = o.maxWait, u = !!o.leading, d = !u && o.trailing === !1 ? !0 : o.trailing ?? !u, f = r(n), p = r(null), m = r(-1), h = r(-1), g = r(null);
|
|
54
|
+
t(() => {
|
|
55
|
+
f.current = n;
|
|
56
|
+
}, [n]);
|
|
57
|
+
let _ = e(() => {
|
|
58
|
+
p.current &&= (clearTimeout(p.current), null), m.current = -1, h.current = -1, g.current = null, c(!1);
|
|
59
|
+
}, []), v = e(() => {
|
|
60
|
+
p.current && g.current && (clearTimeout(p.current), p.current = null, f.current(...g.current), m.current = Date.now(), h.current = -1, g.current = null, c(!1));
|
|
61
|
+
}, []);
|
|
62
|
+
return t(() => () => {
|
|
63
|
+
_();
|
|
64
|
+
}, [_]), {
|
|
65
|
+
debouncedFunc: e((...e) => {
|
|
66
|
+
c(!0), h.current = Date.now(), g.current = e, m.current === -1 && (m.current = Date.now(), u === !0 && f.current(...e)), l !== void 0 && Date.now() - m.current >= l ? (p.current && clearTimeout(p.current), f.current(...e), m.current = -1, c(!1)) : (p.current && clearTimeout(p.current), p.current = setTimeout(() => {
|
|
67
|
+
h.current !== m.current && d !== !1 && f.current(...e), m.current = -1, c(!1);
|
|
68
|
+
}, a));
|
|
69
|
+
}, [
|
|
70
|
+
a,
|
|
71
|
+
l,
|
|
72
|
+
d,
|
|
73
|
+
u
|
|
74
|
+
]),
|
|
75
|
+
cancel: _,
|
|
76
|
+
flush: v,
|
|
77
|
+
isPending: s
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/hooks/useDebouncedValue.ts
|
|
82
|
+
function p(e, n, r = {}) {
|
|
83
|
+
let [a, o] = i(e), { debouncedFunc: s } = f((e) => {
|
|
84
|
+
o(e);
|
|
85
|
+
}, n, r);
|
|
86
|
+
return t(() => {
|
|
87
|
+
s(e);
|
|
88
|
+
}, [e, s]), a;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
51
91
|
//#region src/utils/filterUtils.ts
|
|
52
|
-
var
|
|
92
|
+
var m = {
|
|
53
93
|
text: {
|
|
54
94
|
contains: (e, t, n) => n?.caseSensitive ? String(e).includes(String(t)) : String(e).toLowerCase().includes(String(t).toLowerCase()),
|
|
55
95
|
equals: (e, t, n) => n?.caseSensitive ? String(e) === String(t) : String(e).toLowerCase() === String(t).toLowerCase(),
|
|
@@ -67,12 +107,25 @@ var f = {
|
|
|
67
107
|
},
|
|
68
108
|
boolean: { equals: (e, t) => !!e == !!t },
|
|
69
109
|
date: {
|
|
70
|
-
equals: (e, t) =>
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
equals: (e, t) => {
|
|
111
|
+
if (!e || !t) return !1;
|
|
112
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
113
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n === r;
|
|
114
|
+
},
|
|
115
|
+
before: (e, t) => {
|
|
116
|
+
if (!e || !t) return !1;
|
|
117
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
118
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n < r;
|
|
119
|
+
},
|
|
120
|
+
after: (e, t) => {
|
|
121
|
+
if (!e || !t) return !1;
|
|
122
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
123
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n > r;
|
|
124
|
+
},
|
|
73
125
|
between: (e, t) => {
|
|
74
|
-
|
|
75
|
-
|
|
126
|
+
if (!e || !t?.min || !t?.max) return !1;
|
|
127
|
+
let n = new Date(e).getTime(), r = new Date(t.min).getTime(), i = new Date(t.max).getTime();
|
|
128
|
+
return Number.isNaN(n) || Number.isNaN(r) || Number.isNaN(i) ? !1 : n >= r && n <= i;
|
|
76
129
|
}
|
|
77
130
|
},
|
|
78
131
|
select: {
|
|
@@ -85,62 +138,64 @@ var f = {
|
|
|
85
138
|
intersects: (e, t) => e.some((e) => t.includes(e))
|
|
86
139
|
}
|
|
87
140
|
};
|
|
88
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/utils/utils.ts
|
|
143
|
+
function h(e, t, n) {
|
|
89
144
|
if (typeof e != "object" || !e) return e;
|
|
90
|
-
let r = t || n;
|
|
145
|
+
let r = (t || n) ?? "";
|
|
91
146
|
return r.includes(".") ? r.split(".").reduce((e, t) => e?.[t], e) : e?.[r];
|
|
92
147
|
}
|
|
93
148
|
//#endregion
|
|
94
149
|
//#region src/hooks/useFilter.ts
|
|
95
|
-
function
|
|
96
|
-
let [
|
|
97
|
-
let { id: n, field: r, type: i, operator: a, value: o, compare: s
|
|
98
|
-
if (i === "custom" || a === "custom") return s ? s(
|
|
99
|
-
let
|
|
100
|
-
if (!
|
|
101
|
-
let
|
|
102
|
-
return
|
|
103
|
-
})),
|
|
104
|
-
|
|
105
|
-
}, []),
|
|
106
|
-
|
|
107
|
-
}, []), l = e(() => {
|
|
108
|
-
a([]);
|
|
150
|
+
function g(t, r = []) {
|
|
151
|
+
let [a, o] = i(r), s = n(() => t.filter((e) => a.every((t) => {
|
|
152
|
+
let { id: n, field: r, type: i, operator: a, value: o, compare: s } = t, c = h(e, r, n);
|
|
153
|
+
if (i === "custom" || a === "custom") return s ? s(c, o, e) : !0;
|
|
154
|
+
let l = m[i];
|
|
155
|
+
if (!l) return !0;
|
|
156
|
+
let u = l[a];
|
|
157
|
+
return u ? u(c, o, t) : !0;
|
|
158
|
+
})), [t, a]), c = e((e) => {
|
|
159
|
+
o((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]);
|
|
160
|
+
}, []), l = e((e) => {
|
|
161
|
+
o((t) => Array.isArray(e) ? t.filter((t) => !e.includes(t.id)) : t.filter((t) => t.id !== e));
|
|
109
162
|
}, []), u = e(() => {
|
|
110
|
-
|
|
111
|
-
}, [
|
|
112
|
-
|
|
113
|
-
}, [
|
|
114
|
-
|
|
163
|
+
o([]);
|
|
164
|
+
}, []), d = e(() => {
|
|
165
|
+
o(r);
|
|
166
|
+
}, [r]), f = e((e) => {
|
|
167
|
+
o(e);
|
|
168
|
+
}, []), p = e((e) => a.find((t) => t.id === e)?.value, [a]), g = e((e, t) => {
|
|
169
|
+
o((n) => n.map((n) => n.id === e ? {
|
|
115
170
|
...n,
|
|
116
171
|
value: t
|
|
117
172
|
} : n));
|
|
118
|
-
}, []),
|
|
173
|
+
}, []), _ = e((e) => a.some((t) => t.id === e), [a]);
|
|
119
174
|
return {
|
|
120
|
-
filteredItems:
|
|
121
|
-
filters:
|
|
122
|
-
addFilter:
|
|
123
|
-
removeFilter:
|
|
124
|
-
clearFilters:
|
|
125
|
-
resetFilters:
|
|
175
|
+
filteredItems: s,
|
|
176
|
+
filters: a,
|
|
177
|
+
addFilter: c,
|
|
178
|
+
removeFilter: l,
|
|
179
|
+
clearFilters: u,
|
|
180
|
+
resetFilters: d,
|
|
126
181
|
toggleFilter: e((e) => {
|
|
127
|
-
|
|
182
|
+
o((t) => t.some((t) => t.id === e.id) ? t.filter((t) => t.id !== e.id) : [...t, e]);
|
|
128
183
|
}, []),
|
|
129
184
|
updateFilterConfig: e((e, t) => {
|
|
130
|
-
|
|
185
|
+
o((n) => n.map((n) => n.id === e ? {
|
|
131
186
|
...n,
|
|
132
187
|
...t
|
|
133
188
|
} : n));
|
|
134
189
|
}, []),
|
|
135
|
-
setFilters:
|
|
136
|
-
getFilterValue:
|
|
137
|
-
updateFilterValue:
|
|
138
|
-
isFilterActive:
|
|
190
|
+
setFilters: f,
|
|
191
|
+
getFilterValue: p,
|
|
192
|
+
updateFilterValue: g,
|
|
193
|
+
isFilterActive: _
|
|
139
194
|
};
|
|
140
195
|
}
|
|
141
196
|
//#endregion
|
|
142
197
|
//#region src/hooks/usePagination.ts
|
|
143
|
-
function
|
|
198
|
+
function _(t, r, a = 0) {
|
|
144
199
|
let [o, s] = i(r), [c, l] = i(a), u = Math.max(1, Math.ceil(t.length / Math.max(1, o))), d = Math.min(Math.max(0, c), u - 1);
|
|
145
200
|
return c !== d && l(d), {
|
|
146
201
|
currentItems: n(() => typeof o != "number" || o < 1 ? [] : t.slice(c * o, (c + 1) * o), [
|
|
@@ -187,24 +242,26 @@ function h(t, r, a = 0) {
|
|
|
187
242
|
}
|
|
188
243
|
//#endregion
|
|
189
244
|
//#region src/utils/sortUtils.ts
|
|
190
|
-
function
|
|
191
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
245
|
+
function v(e, t, n = {}) {
|
|
246
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = T(e, t, r, i);
|
|
192
247
|
if (a !== null) return a;
|
|
193
248
|
let o = !!e;
|
|
194
249
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
195
250
|
}
|
|
196
|
-
function
|
|
197
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
198
|
-
|
|
251
|
+
function y(e, t, n = {}) {
|
|
252
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = T(e, t, r, i);
|
|
253
|
+
if (a !== null) return a;
|
|
254
|
+
let o = e === "" || e === null ? NaN : Number(e), s = t === "" || t === null ? NaN : Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
255
|
+
return c || l ? T(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
199
256
|
}
|
|
200
|
-
function
|
|
201
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
257
|
+
function b(e, t, n = {}) {
|
|
258
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = T(e, t, i, r);
|
|
202
259
|
if (o !== null) return o;
|
|
203
260
|
let s = String(e), c = String(t);
|
|
204
261
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
205
262
|
}
|
|
206
|
-
function
|
|
207
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
263
|
+
function x(e, t, n = {}) {
|
|
264
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = T(e, t, i, r);
|
|
208
265
|
if (o !== null) return o;
|
|
209
266
|
let s = String(e), c = String(t);
|
|
210
267
|
return s.localeCompare(c, void 0, {
|
|
@@ -212,26 +269,21 @@ function y(e, t, n = {}) {
|
|
|
212
269
|
sensitivity: a ? "variant" : "base"
|
|
213
270
|
});
|
|
214
271
|
}
|
|
215
|
-
function
|
|
216
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
272
|
+
function S(e, t, n = {}) {
|
|
273
|
+
let { desc: r = !1, sortUndefined: i } = n, a = T(e, t, i, r);
|
|
217
274
|
if (a !== null) return a;
|
|
218
275
|
let o = new Date(e).getTime(), s = new Date(t).getTime();
|
|
219
276
|
return (Number.isNaN(o) ? 0 : o) - (Number.isNaN(s) ? 0 : s);
|
|
220
277
|
}
|
|
221
|
-
function
|
|
222
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
278
|
+
function C(e, t, n = {}) {
|
|
279
|
+
let { desc: r = !1, sortUndefined: i } = n, a = T(e, t, i, r);
|
|
223
280
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
224
281
|
}
|
|
225
|
-
function
|
|
226
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
282
|
+
function w(e, t, n = {}) {
|
|
283
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = T(e, t, i, r);
|
|
227
284
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
228
285
|
}
|
|
229
|
-
function
|
|
230
|
-
if (typeof e != "object" || !e) return e;
|
|
231
|
-
let r = t || n;
|
|
232
|
-
return r.includes(".") ? r.split(".").reduce((e, t) => e?.[t], e) : e?.[r];
|
|
233
|
-
}
|
|
234
|
-
function w(e, t, n = !1, r) {
|
|
286
|
+
function T(e, t, n = !1, r) {
|
|
235
287
|
let i = e ?? void 0, a = t ?? void 0;
|
|
236
288
|
if (i !== void 0 && a !== void 0) return null;
|
|
237
289
|
if (i === void 0 && a === void 0 || n === !1) return 0;
|
|
@@ -249,35 +301,35 @@ function w(e, t, n = !1, r) {
|
|
|
249
301
|
}
|
|
250
302
|
//#endregion
|
|
251
303
|
//#region src/hooks/useSort.ts
|
|
252
|
-
function
|
|
304
|
+
function E(t, r = []) {
|
|
253
305
|
let [a, o] = i(r);
|
|
254
306
|
return {
|
|
255
307
|
sortedItems: n(() => t.toSorted((e, t) => {
|
|
256
308
|
for (let n of a) {
|
|
257
|
-
let { type: r, field: i, id: a, desc: o = !1, invertSorting: s = !1 } = n, c =
|
|
309
|
+
let { type: r, field: i, id: a, desc: o = !1, invertSorting: s = !1 } = n, c = h(e, i, a), l = h(t, i, a), u;
|
|
258
310
|
switch (r) {
|
|
259
311
|
case "numeric":
|
|
260
|
-
u =
|
|
312
|
+
u = y(c, l, n);
|
|
261
313
|
break;
|
|
262
314
|
case "alphabetical":
|
|
263
|
-
u =
|
|
315
|
+
u = b(c, l, n);
|
|
264
316
|
break;
|
|
265
317
|
case "alphanumeric":
|
|
266
|
-
u =
|
|
318
|
+
u = x(c, l, n);
|
|
267
319
|
break;
|
|
268
320
|
case "boolean":
|
|
269
|
-
u =
|
|
321
|
+
u = v(c, l, n);
|
|
270
322
|
break;
|
|
271
323
|
case "date":
|
|
272
|
-
u =
|
|
324
|
+
u = S(c, l, n);
|
|
273
325
|
break;
|
|
274
326
|
case "basic":
|
|
275
|
-
u =
|
|
327
|
+
u = C(c, l, n);
|
|
276
328
|
break;
|
|
277
329
|
case "custom":
|
|
278
|
-
u =
|
|
330
|
+
u = w(c, l, n);
|
|
279
331
|
break;
|
|
280
|
-
default: u =
|
|
332
|
+
default: u = C(c, l, n);
|
|
281
333
|
}
|
|
282
334
|
if (u !== 0) return u * (o === s ? 1 : -1);
|
|
283
335
|
}
|
|
@@ -338,4 +390,4 @@ function T(t, r = []) {
|
|
|
338
390
|
};
|
|
339
391
|
}
|
|
340
392
|
//#endregion
|
|
341
|
-
export { d as
|
|
393
|
+
export { d as ModalLayout, f as useDebounce, p as useDebouncedValue, g as useFilter, u as useModal, _ as usePagination, E as useSort };
|
package/package.json
CHANGED
package/dist/index.css
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
:where(html){scrollbar-gutter:stable both}:where(body:has(dialog[open])){overflow:hidden}:where(dialog.universal-modal){box-sizing:border-box;max-width:var(--modal-max-width,500px);background:0 0;border:none;width:calc(100% - 2rem);padding:0}:where(dialog.universal-modal .modal-container){box-sizing:border-box;padding:var(--modal-padding,24px);background-color:var(--modal-bg,#fff);border-radius:var(--modal-radius,8px);box-shadow:var(--modal-shadow,0 4px 12px #00000026)}dialog.universal-modal::backdrop{background-color:var(--modal-backdrop-bg,#00000080);-webkit-backdrop-filter:blur(var(--modal-backdrop-blur,none));backdrop-filter:blur(var(--modal-backdrop-blur,none))}:where(dialog.universal-modal[open]){animation:.2s ease-out modal-fade-in}@keyframes modal-fade-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}
|
|
2
|
-
/*$vite$:1*/
|