@himanshu-sorathiya/react-kit 1.0.5 → 1.0.6
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 +2 -2
- package/dist/index.js +71 -59
- package/package.json +1 -1
- package/dist/index.css +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
8
|
export type FilterType = "text" | "number" | "boolean" | "date" | "select" | "multiselect" | "custom";
|
|
9
9
|
export type TextOperator = "contains" | "equals" | "startsWith" | "endsWith" | "notContains";
|
|
10
10
|
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
|
|
@@ -67,12 +67,25 @@ var f = {
|
|
|
67
67
|
},
|
|
68
68
|
boolean: { equals: (e, t) => !!e == !!t },
|
|
69
69
|
date: {
|
|
70
|
-
equals: (e, t) =>
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
equals: (e, t) => {
|
|
71
|
+
if (!e || !t) return !1;
|
|
72
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
73
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n === r;
|
|
74
|
+
},
|
|
75
|
+
before: (e, t) => {
|
|
76
|
+
if (!e || !t) return !1;
|
|
77
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
78
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n < r;
|
|
79
|
+
},
|
|
80
|
+
after: (e, t) => {
|
|
81
|
+
if (!e || !t) return !1;
|
|
82
|
+
let n = new Date(e).getTime(), r = new Date(t).getTime();
|
|
83
|
+
return Number.isNaN(n) || Number.isNaN(r) ? !1 : n > r;
|
|
84
|
+
},
|
|
73
85
|
between: (e, t) => {
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
if (!e || !t?.min || !t?.max) return !1;
|
|
87
|
+
let n = new Date(e).getTime(), r = new Date(t.min).getTime(), i = new Date(t.max).getTime();
|
|
88
|
+
return Number.isNaN(n) || Number.isNaN(r) || Number.isNaN(i) ? !1 : n >= r && n <= i;
|
|
76
89
|
}
|
|
77
90
|
},
|
|
78
91
|
select: {
|
|
@@ -85,57 +98,59 @@ var f = {
|
|
|
85
98
|
intersects: (e, t) => e.some((e) => t.includes(e))
|
|
86
99
|
}
|
|
87
100
|
};
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/utils/utils.ts
|
|
88
103
|
function p(e, t, n) {
|
|
89
104
|
if (typeof e != "object" || !e) return e;
|
|
90
|
-
let r = t || n;
|
|
105
|
+
let r = (t || n) ?? "";
|
|
91
106
|
return r.includes(".") ? r.split(".").reduce((e, t) => e?.[t], e) : e?.[r];
|
|
92
107
|
}
|
|
93
108
|
//#endregion
|
|
94
109
|
//#region src/hooks/useFilter.ts
|
|
95
|
-
function m(t,
|
|
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([]);
|
|
110
|
+
function m(t, r = []) {
|
|
111
|
+
let [a, o] = i(r), s = n(() => t.filter((e) => a.every((t) => {
|
|
112
|
+
let { id: n, field: r, type: i, operator: a, value: o, compare: s } = t, c = p(e, r, n);
|
|
113
|
+
if (i === "custom" || a === "custom") return s ? s(c, o, e) : !0;
|
|
114
|
+
let l = f[i];
|
|
115
|
+
if (!l) return !0;
|
|
116
|
+
let u = l[a];
|
|
117
|
+
return u ? u(c, o, t) : !0;
|
|
118
|
+
})), [t, a]), c = e((e) => {
|
|
119
|
+
o((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]);
|
|
120
|
+
}, []), l = e((e) => {
|
|
121
|
+
o((t) => Array.isArray(e) ? t.filter((t) => !e.includes(t.id)) : t.filter((t) => t.id !== e));
|
|
109
122
|
}, []), u = e(() => {
|
|
110
|
-
|
|
111
|
-
}, [
|
|
112
|
-
|
|
113
|
-
}, []), m = e((e) =>
|
|
114
|
-
|
|
123
|
+
o([]);
|
|
124
|
+
}, []), d = e(() => {
|
|
125
|
+
o(r);
|
|
126
|
+
}, [r]), m = e((e) => {
|
|
127
|
+
o(e);
|
|
128
|
+
}, []), h = e((e) => a.find((t) => t.id === e)?.value, [a]), g = e((e, t) => {
|
|
129
|
+
o((n) => n.map((n) => n.id === e ? {
|
|
115
130
|
...n,
|
|
116
131
|
value: t
|
|
117
132
|
} : n));
|
|
118
|
-
}, []),
|
|
133
|
+
}, []), _ = e((e) => a.some((t) => t.id === e), [a]);
|
|
119
134
|
return {
|
|
120
|
-
filteredItems:
|
|
121
|
-
filters:
|
|
122
|
-
addFilter:
|
|
123
|
-
removeFilter:
|
|
124
|
-
clearFilters:
|
|
125
|
-
resetFilters:
|
|
135
|
+
filteredItems: s,
|
|
136
|
+
filters: a,
|
|
137
|
+
addFilter: c,
|
|
138
|
+
removeFilter: l,
|
|
139
|
+
clearFilters: u,
|
|
140
|
+
resetFilters: d,
|
|
126
141
|
toggleFilter: e((e) => {
|
|
127
|
-
|
|
142
|
+
o((t) => t.some((t) => t.id === e.id) ? t.filter((t) => t.id !== e.id) : [...t, e]);
|
|
128
143
|
}, []),
|
|
129
144
|
updateFilterConfig: e((e, t) => {
|
|
130
|
-
|
|
145
|
+
o((n) => n.map((n) => n.id === e ? {
|
|
131
146
|
...n,
|
|
132
147
|
...t
|
|
133
148
|
} : n));
|
|
134
149
|
}, []),
|
|
135
|
-
setFilters:
|
|
136
|
-
getFilterValue:
|
|
137
|
-
updateFilterValue:
|
|
138
|
-
isFilterActive:
|
|
150
|
+
setFilters: m,
|
|
151
|
+
getFilterValue: h,
|
|
152
|
+
updateFilterValue: g,
|
|
153
|
+
isFilterActive: _
|
|
139
154
|
};
|
|
140
155
|
}
|
|
141
156
|
//#endregion
|
|
@@ -188,23 +203,25 @@ function h(t, r, a = 0) {
|
|
|
188
203
|
//#endregion
|
|
189
204
|
//#region src/utils/sortUtils.ts
|
|
190
205
|
function g(e, t, n = {}) {
|
|
191
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
206
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = C(e, t, r, i);
|
|
192
207
|
if (a !== null) return a;
|
|
193
208
|
let o = !!e;
|
|
194
209
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
195
210
|
}
|
|
196
211
|
function _(e, t, n = {}) {
|
|
197
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
198
|
-
|
|
212
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = C(e, t, r, i);
|
|
213
|
+
if (a !== null) return a;
|
|
214
|
+
let o = e === "" || e === null ? NaN : Number(e), s = t === "" || t === null ? NaN : Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
215
|
+
return c || l ? C(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
199
216
|
}
|
|
200
217
|
function v(e, t, n = {}) {
|
|
201
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
218
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = C(e, t, i, r);
|
|
202
219
|
if (o !== null) return o;
|
|
203
220
|
let s = String(e), c = String(t);
|
|
204
221
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
205
222
|
}
|
|
206
223
|
function y(e, t, n = {}) {
|
|
207
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
224
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = C(e, t, i, r);
|
|
208
225
|
if (o !== null) return o;
|
|
209
226
|
let s = String(e), c = String(t);
|
|
210
227
|
return s.localeCompare(c, void 0, {
|
|
@@ -213,25 +230,20 @@ function y(e, t, n = {}) {
|
|
|
213
230
|
});
|
|
214
231
|
}
|
|
215
232
|
function b(e, t, n = {}) {
|
|
216
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
233
|
+
let { desc: r = !1, sortUndefined: i } = n, a = C(e, t, i, r);
|
|
217
234
|
if (a !== null) return a;
|
|
218
235
|
let o = new Date(e).getTime(), s = new Date(t).getTime();
|
|
219
236
|
return (Number.isNaN(o) ? 0 : o) - (Number.isNaN(s) ? 0 : s);
|
|
220
237
|
}
|
|
221
238
|
function x(e, t, n = {}) {
|
|
222
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
239
|
+
let { desc: r = !1, sortUndefined: i } = n, a = C(e, t, i, r);
|
|
223
240
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
224
241
|
}
|
|
225
242
|
function S(e, t, n = {}) {
|
|
226
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
243
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = C(e, t, i, r);
|
|
227
244
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
228
245
|
}
|
|
229
|
-
function C(e, t, n) {
|
|
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) {
|
|
246
|
+
function C(e, t, n = !1, r) {
|
|
235
247
|
let i = e ?? void 0, a = t ?? void 0;
|
|
236
248
|
if (i !== void 0 && a !== void 0) return null;
|
|
237
249
|
if (i === void 0 && a === void 0 || n === !1) return 0;
|
|
@@ -249,12 +261,12 @@ function w(e, t, n = !1, r) {
|
|
|
249
261
|
}
|
|
250
262
|
//#endregion
|
|
251
263
|
//#region src/hooks/useSort.ts
|
|
252
|
-
function
|
|
264
|
+
function w(t, r = []) {
|
|
253
265
|
let [a, o] = i(r);
|
|
254
266
|
return {
|
|
255
267
|
sortedItems: n(() => t.toSorted((e, t) => {
|
|
256
268
|
for (let n of a) {
|
|
257
|
-
let { type: r, field: i, id: a, desc: o = !1, invertSorting: s = !1 } = n, c =
|
|
269
|
+
let { type: r, field: i, id: a, desc: o = !1, invertSorting: s = !1 } = n, c = p(e, i, a), l = p(t, i, a), u;
|
|
258
270
|
switch (r) {
|
|
259
271
|
case "numeric":
|
|
260
272
|
u = _(c, l, n);
|
|
@@ -338,4 +350,4 @@ function T(t, r = []) {
|
|
|
338
350
|
};
|
|
339
351
|
}
|
|
340
352
|
//#endregion
|
|
341
|
-
export { d as
|
|
353
|
+
export { d as ModalLayout, m as useFilter, u as useModal, h as usePagination, w 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*/
|