@himanshu-sorathiya/react-kit 1.0.11 → 1.0.12
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 +48 -25
- package/dist/index.js +254 -159
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
-
import { RefObject } from 'react';
|
|
3
|
+
import { CSSProperties, RefObject } from 'react';
|
|
4
4
|
|
|
5
5
|
export interface ModalLayoutProps {
|
|
6
|
+
modalId: string;
|
|
6
7
|
children: React.ReactNode;
|
|
7
|
-
|
|
8
|
+
wrapperClassName?: string;
|
|
9
|
+
wrapperStyle?: CSSProperties;
|
|
10
|
+
containerClassName?: string;
|
|
11
|
+
containerStyle?: CSSProperties;
|
|
8
12
|
}
|
|
9
|
-
export declare function ModalLayout({ children,
|
|
13
|
+
export declare function ModalLayout({ modalId, children, wrapperClassName, wrapperStyle, containerClassName, containerStyle, }: ModalLayoutProps): import("react").ReactPortal | null;
|
|
10
14
|
export interface DebounceOptions {
|
|
11
15
|
maxWait?: number;
|
|
12
16
|
leading?: boolean;
|
|
@@ -120,38 +124,56 @@ declare const validKeyEventTypes: readonly [
|
|
|
120
124
|
"keypress"
|
|
121
125
|
];
|
|
122
126
|
export type KeyEventType = (typeof validKeyEventTypes)[number];
|
|
123
|
-
export interface
|
|
127
|
+
export interface BaseKeyOptions {
|
|
124
128
|
enabled?: boolean;
|
|
125
129
|
target?: RefObject<HTMLElement | null> | Window;
|
|
126
|
-
}
|
|
127
|
-
export interface KeyEventModifiers {
|
|
128
130
|
preventDefault?: boolean;
|
|
129
131
|
stopPropagation?: boolean;
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
export interface KeyChordModifiers {
|
|
132
|
+
ignoreWhenFocusedInInputs?: boolean;
|
|
133
133
|
ctrlKey?: boolean;
|
|
134
134
|
shiftKey?: boolean;
|
|
135
135
|
altKey?: boolean;
|
|
136
136
|
metaKey?: boolean;
|
|
137
137
|
}
|
|
138
|
-
export
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
export type KeyOptions = BaseKeyOptions & ({
|
|
139
|
+
eventType?: "keydown" | "keypress";
|
|
140
|
+
preventRepeat?: boolean;
|
|
141
|
+
} | {
|
|
142
|
+
eventType: "keyup";
|
|
143
|
+
preventRepeat?: never;
|
|
144
|
+
});
|
|
144
145
|
export type UseKeyReturn = void;
|
|
145
|
-
export declare function useKey(key: string,
|
|
146
|
-
export interface
|
|
146
|
+
export declare function useKey(key: string, handler: (e: KeyboardEvent) => void, { enabled, preventDefault, stopPropagation, eventType, preventRepeat, ignoreWhenFocusedInInputs, ctrlKey, shiftKey, altKey, metaKey, target, }?: KeyOptions): UseKeyReturn;
|
|
147
|
+
export interface UseModalStateReturn<TData> {
|
|
148
|
+
isOpen: boolean;
|
|
147
149
|
id: string | null;
|
|
148
150
|
data: TData | undefined;
|
|
149
|
-
openModal: <T = any>(id: string, data?: T) => void;
|
|
150
|
-
closeModal: () => void;
|
|
151
151
|
}
|
|
152
|
-
export
|
|
152
|
+
export interface UseModalActionsReturn {
|
|
153
|
+
openModal: <T = unknown>(id: string, data?: T) => void;
|
|
154
|
+
closeModal: () => void;
|
|
155
|
+
clearModal: () => void;
|
|
156
|
+
}
|
|
157
|
+
export type UseModalReturn<TData> = UseModalStateReturn<TData> & UseModalActionsReturn;
|
|
158
|
+
export declare function useModalState<TData = unknown>(): UseModalStateReturn<TData>;
|
|
159
|
+
export declare function useModalActions(): UseModalActionsReturn;
|
|
160
|
+
export declare function useModal<TData = unknown>(): UseModalReturn<TData>;
|
|
161
|
+
export interface UseOrderReturn<T> {
|
|
162
|
+
orderedItems: T[];
|
|
163
|
+
moveUp: (index: number) => void;
|
|
164
|
+
moveDown: (index: number) => void;
|
|
165
|
+
canMoveUp: (index: number) => boolean;
|
|
166
|
+
canMoveDown: (index: number) => boolean;
|
|
167
|
+
moveToTop: (index: number) => void;
|
|
168
|
+
moveToBottom: (index: number) => void;
|
|
169
|
+
move: (fromIndex: number, toIndex: number) => void;
|
|
170
|
+
swap: (indexA: number, indexB: number) => void;
|
|
171
|
+
replaceOrder: (newOrderedItems: T[]) => void;
|
|
172
|
+
resetOrder: () => void;
|
|
173
|
+
}
|
|
174
|
+
export declare function useOrder<T>(initialItems: T[]): UseOrderReturn<T>;
|
|
153
175
|
export interface UsePaginationReturn<T> {
|
|
154
|
-
|
|
176
|
+
pageItems: T[];
|
|
155
177
|
pageSize: number;
|
|
156
178
|
pageIndex: number;
|
|
157
179
|
totalPages: number;
|
|
@@ -159,12 +181,13 @@ export interface UsePaginationReturn<T> {
|
|
|
159
181
|
canNext: boolean;
|
|
160
182
|
nextPage: () => void;
|
|
161
183
|
previousPage: () => void;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
goToFirstPage: () => void;
|
|
185
|
+
goToLastPage: () => void;
|
|
186
|
+
goToPage: (newPageIndex: number) => void;
|
|
187
|
+
changePageSize: (newPageSize: number) => void;
|
|
166
188
|
resetPageIndex: () => void;
|
|
167
189
|
resetPageSize: () => void;
|
|
190
|
+
resetPagination: () => void;
|
|
168
191
|
}
|
|
169
192
|
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
170
193
|
export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,64 @@
|
|
|
1
|
-
import { createContext as e, useCallback as t, useContext as n, useEffect as r,
|
|
2
|
-
import { createPortal as
|
|
3
|
-
import { jsx as
|
|
1
|
+
import { createContext as e, useCallback as t, useContext as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
2
|
+
import { createPortal as c } from "react-dom";
|
|
3
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
4
4
|
//#region src/context/ModalContext.tsx
|
|
5
|
-
var
|
|
5
|
+
var u = e(null), d = e(null);
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/hooks/useModal.ts
|
|
8
|
-
function
|
|
9
|
-
let e = n(
|
|
10
|
-
if (!e) throw Error("
|
|
8
|
+
function f() {
|
|
9
|
+
let e = n(u);
|
|
10
|
+
if (!e) throw Error("useModalState must be used within a ModalProvider");
|
|
11
11
|
return e;
|
|
12
12
|
}
|
|
13
|
+
function p() {
|
|
14
|
+
let e = n(d);
|
|
15
|
+
if (!e) throw Error("useModalActions must be used within a ModalProvider");
|
|
16
|
+
return e;
|
|
17
|
+
}
|
|
18
|
+
function m() {
|
|
19
|
+
return {
|
|
20
|
+
...f(),
|
|
21
|
+
...p()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
13
24
|
//#endregion
|
|
14
25
|
//#region src/components/Modal.tsx
|
|
15
|
-
function
|
|
16
|
-
let { id:
|
|
26
|
+
function h({ modalId: e, children: t, wrapperClassName: n = "", wrapperStyle: i, containerClassName: a = "", containerStyle: u }) {
|
|
27
|
+
let { isOpen: d, id: m } = f(), { closeModal: h, clearModal: g } = p(), [_, v] = s(!1), y = o(null), b = m === e, x = d && b;
|
|
17
28
|
return r(() => {
|
|
18
|
-
let e =
|
|
19
|
-
e && (
|
|
20
|
-
}, [
|
|
21
|
-
ref:
|
|
29
|
+
let e = y.current;
|
|
30
|
+
e && (x && !e.open ? (v(!1), e.showModal()) : !x && e.open && v(!0));
|
|
31
|
+
}, [x]), typeof document > "u" || !b && !_ ? null : c(/* @__PURE__ */ l("dialog", {
|
|
32
|
+
ref: y,
|
|
22
33
|
onCancel: (e) => {
|
|
23
|
-
e.preventDefault(),
|
|
34
|
+
e.preventDefault(), h();
|
|
35
|
+
},
|
|
36
|
+
onClose: h,
|
|
37
|
+
onClick: (e) => {
|
|
38
|
+
let t = y.current;
|
|
39
|
+
if (!t) return;
|
|
40
|
+
let n = t.getBoundingClientRect();
|
|
41
|
+
(e.clientX < n.x || e.clientX > n.x + n.width || e.clientY < n.y || e.clientY > n.y + n.height) && h();
|
|
42
|
+
},
|
|
43
|
+
onAnimationEnd: () => {
|
|
44
|
+
if (_) {
|
|
45
|
+
let e = y.current;
|
|
46
|
+
e && e.close(), v(!1), b && g();
|
|
47
|
+
}
|
|
24
48
|
},
|
|
25
|
-
className: `universal-modal ${
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
className: `universal-modal ${n}`.trim(),
|
|
50
|
+
style: i,
|
|
51
|
+
children: /* @__PURE__ */ l("div", {
|
|
52
|
+
className: `modal-container ${a}`.trim(),
|
|
53
|
+
style: u,
|
|
54
|
+
children: t
|
|
29
55
|
})
|
|
30
56
|
}), document.body);
|
|
31
57
|
}
|
|
32
58
|
//#endregion
|
|
33
59
|
//#region src/hooks/useDebounce.ts
|
|
34
|
-
function
|
|
35
|
-
let [
|
|
60
|
+
function g(e, n, i = {}) {
|
|
61
|
+
let [a, c] = s(!1), l = i.maxWait, u = !!i.leading, d = !u && i.trailing === !1 ? !0 : i.trailing ?? !u, f = o(e), p = o(null), m = o(-1), h = o(-1), g = o(null);
|
|
36
62
|
r(() => {
|
|
37
63
|
f.current = e;
|
|
38
64
|
}, [e]);
|
|
@@ -56,22 +82,22 @@ function f(e, n, i = {}) {
|
|
|
56
82
|
]),
|
|
57
83
|
cancel: _,
|
|
58
84
|
flush: v,
|
|
59
|
-
isPending:
|
|
85
|
+
isPending: a
|
|
60
86
|
};
|
|
61
87
|
}
|
|
62
88
|
//#endregion
|
|
63
89
|
//#region src/hooks/useDebouncedValue.ts
|
|
64
|
-
function
|
|
65
|
-
let [i, a] =
|
|
90
|
+
function _(e, t, n = {}) {
|
|
91
|
+
let [i, a] = s(e), { debouncedFunc: o } = g((e) => {
|
|
66
92
|
a(e);
|
|
67
93
|
}, t, n);
|
|
68
94
|
return r(() => {
|
|
69
|
-
|
|
70
|
-
}, [e,
|
|
95
|
+
o(e);
|
|
96
|
+
}, [e, o]), i;
|
|
71
97
|
}
|
|
72
98
|
//#endregion
|
|
73
99
|
//#region src/utils/filterUtils.ts
|
|
74
|
-
var
|
|
100
|
+
var v = {
|
|
75
101
|
text: {
|
|
76
102
|
contains: (e, t, n) => e == null ? !1 : n?.caseSensitive ? String(e).includes(String(t)) : String(e).toLowerCase().includes(String(t).toLowerCase()),
|
|
77
103
|
equals: (e, t, n) => e == null ? !1 : n?.caseSensitive ? String(e) === String(t) : String(e).toLowerCase() === String(t).toLowerCase(),
|
|
@@ -128,47 +154,47 @@ var m = {
|
|
|
128
154
|
};
|
|
129
155
|
//#endregion
|
|
130
156
|
//#region src/utils/utils.ts
|
|
131
|
-
function
|
|
157
|
+
function y(e, t, n) {
|
|
132
158
|
if (typeof e != "object" || !e) return e;
|
|
133
159
|
let r = t ?? n ?? "";
|
|
134
160
|
return Array.isArray(r) ? r.reduce((e, t) => e?.[t], e) : r.includes(".") ? r.split(".").reduce((e, t) => e?.[t], e) : e?.[r];
|
|
135
161
|
}
|
|
136
162
|
//#endregion
|
|
137
163
|
//#region src/hooks/useFilter.ts
|
|
138
|
-
function
|
|
139
|
-
let [r,
|
|
164
|
+
function b(e, n = []) {
|
|
165
|
+
let [r, i] = s(n), o = a(() => {
|
|
140
166
|
let t = r.filter((e) => e.isActive !== !1).map((e) => ({
|
|
141
167
|
...e,
|
|
142
168
|
pathArray: (e.field || e.id).split(".")
|
|
143
169
|
}));
|
|
144
170
|
return e.filter((e) => t.every((t) => {
|
|
145
|
-
let { id: n, type: r, operator: i, value: a, compare: o, pathArray: s } = t, c =
|
|
171
|
+
let { id: n, type: r, operator: i, value: a, compare: o, pathArray: s } = t, c = y(e, s, n);
|
|
146
172
|
if (r === "custom") return o ? o(c, a, e) : !0;
|
|
147
|
-
let l =
|
|
173
|
+
let l = v[r];
|
|
148
174
|
if (!l) return !0;
|
|
149
175
|
let u = l[i];
|
|
150
176
|
return u ? u(c, a, t) : !0;
|
|
151
177
|
}));
|
|
152
178
|
}, [e, r]), c = t((e) => {
|
|
153
|
-
|
|
179
|
+
i((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]);
|
|
154
180
|
}, []), l = t((e) => {
|
|
155
|
-
|
|
181
|
+
i((t) => Array.isArray(e) ? t.filter((t) => !e.includes(t.id)) : t.filter((t) => t.id !== e));
|
|
156
182
|
}, []), u = t(() => {
|
|
157
|
-
|
|
183
|
+
i([]);
|
|
158
184
|
}, []), d = t(() => {
|
|
159
|
-
|
|
185
|
+
i(n);
|
|
160
186
|
}, [n]), f = t((e) => {
|
|
161
|
-
|
|
187
|
+
i(e);
|
|
162
188
|
}, []);
|
|
163
189
|
return {
|
|
164
|
-
filteredItems:
|
|
190
|
+
filteredItems: o,
|
|
165
191
|
filters: r,
|
|
166
192
|
upsertFilter: c,
|
|
167
193
|
removeFilter: l,
|
|
168
194
|
clearFilters: u,
|
|
169
195
|
resetFilters: d,
|
|
170
196
|
toggleFilter: t((e) => {
|
|
171
|
-
|
|
197
|
+
i((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? {
|
|
172
198
|
...t,
|
|
173
199
|
isActive: t.isActive === !1
|
|
174
200
|
} : t) : [...t, {
|
|
@@ -177,7 +203,7 @@ function g(e, n = []) {
|
|
|
177
203
|
}]);
|
|
178
204
|
}, []),
|
|
179
205
|
updateFilterConfig: t((e, t) => {
|
|
180
|
-
|
|
206
|
+
i((n) => n.map((n) => n.id === e ? {
|
|
181
207
|
...n,
|
|
182
208
|
...t
|
|
183
209
|
} : n));
|
|
@@ -185,7 +211,7 @@ function g(e, n = []) {
|
|
|
185
211
|
replaceFilters: f,
|
|
186
212
|
getFilterValue: t((e) => r.find((t) => t.id === e)?.value, [r]),
|
|
187
213
|
updateFilterValue: t((e, t) => {
|
|
188
|
-
|
|
214
|
+
i((n) => n.map((n) => n.id === e ? {
|
|
189
215
|
...n,
|
|
190
216
|
value: t
|
|
191
217
|
} : n));
|
|
@@ -198,7 +224,7 @@ function g(e, n = []) {
|
|
|
198
224
|
}
|
|
199
225
|
//#endregion
|
|
200
226
|
//#region src/utils/fuzzySearchUtils.ts
|
|
201
|
-
function
|
|
227
|
+
function x(e, t, n = !1) {
|
|
202
228
|
let r = e.trim(), i = t.trim(), a = r.length > 1 && r === r.toUpperCase() && /^[A-Z]+$/.test(r);
|
|
203
229
|
if (n || (r = r.toLowerCase(), i = i.toLowerCase()), r === i) return 1;
|
|
204
230
|
if (r === "" || i === "") return 0;
|
|
@@ -247,11 +273,11 @@ function _(e, t, n = !1) {
|
|
|
247
273
|
}
|
|
248
274
|
//#endregion
|
|
249
275
|
//#region src/hooks/useFuzzySearch.ts
|
|
250
|
-
function
|
|
251
|
-
let
|
|
276
|
+
function S(e, t, n, r = {}) {
|
|
277
|
+
let i = r.threshold ?? .01, o = r.caseSensitive ?? !1, s = r.matchStrategy ?? "any", c = r.exactPhraseBonus ?? !0, l = a(() => n.length === 0 || e.length === 0 ? [] : e.map((e, t) => {
|
|
252
278
|
let r = [], i = [];
|
|
253
279
|
for (let [t, a] of n) {
|
|
254
|
-
let n =
|
|
280
|
+
let n = y(e, t);
|
|
255
281
|
if (Array.isArray(n)) {
|
|
256
282
|
for (let e of n) if (e != null && e !== "" && typeof e != "object") {
|
|
257
283
|
let t = String(e);
|
|
@@ -279,12 +305,12 @@ function v(e, t, n, r = {}) {
|
|
|
279
305
|
combinedFlatText: i.join(" ")
|
|
280
306
|
};
|
|
281
307
|
}), [e, n]);
|
|
282
|
-
return
|
|
308
|
+
return a(() => {
|
|
283
309
|
let n = t.trim();
|
|
284
310
|
if (!n || l.length === 0) return e;
|
|
285
311
|
let r = n.split(/\s+/).filter((e) => e.length > 0);
|
|
286
312
|
if (r.length === 0) return e;
|
|
287
|
-
let
|
|
313
|
+
let a = [], u = .3;
|
|
288
314
|
for (let e of l) {
|
|
289
315
|
let t = 0, n = 0, l = !1;
|
|
290
316
|
for (let i of r) {
|
|
@@ -297,7 +323,7 @@ function v(e, t, n, r = {}) {
|
|
|
297
323
|
let e = Math.abs(i.length - n.length), t = Math.max(i.length, n.length);
|
|
298
324
|
if (t > 0 && (t - e) / t < u) continue;
|
|
299
325
|
}
|
|
300
|
-
let e =
|
|
326
|
+
let e = x(i, n, o) * t.weight;
|
|
301
327
|
e > r && (r = e);
|
|
302
328
|
}
|
|
303
329
|
}
|
|
@@ -309,19 +335,19 @@ function v(e, t, n, r = {}) {
|
|
|
309
335
|
let t = r.map((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("\\s+");
|
|
310
336
|
new RegExp(t, o ? "g" : "gi").test(e.combinedFlatText) && (n += .15);
|
|
311
337
|
}
|
|
312
|
-
n >=
|
|
338
|
+
n >= i && a.push({
|
|
313
339
|
item: e.item,
|
|
314
340
|
score: n,
|
|
315
341
|
index: e.index
|
|
316
342
|
});
|
|
317
343
|
}
|
|
318
344
|
}
|
|
319
|
-
return
|
|
345
|
+
return a.toSorted((e, t) => t.score === e.score ? e.index - t.index : t.score - e.score).map((e) => e.item);
|
|
320
346
|
}, [
|
|
321
347
|
l,
|
|
322
348
|
e,
|
|
323
349
|
t,
|
|
324
|
-
|
|
350
|
+
i,
|
|
325
351
|
o,
|
|
326
352
|
s,
|
|
327
353
|
c
|
|
@@ -329,42 +355,45 @@ function v(e, t, n, r = {}) {
|
|
|
329
355
|
}
|
|
330
356
|
//#endregion
|
|
331
357
|
//#region src/constants/keyConstants.ts
|
|
332
|
-
var
|
|
358
|
+
var C = [
|
|
333
359
|
"keydown",
|
|
334
360
|
"keyup",
|
|
335
361
|
"keypress"
|
|
336
362
|
];
|
|
337
363
|
//#endregion
|
|
338
364
|
//#region src/hooks/useKey.ts
|
|
339
|
-
function
|
|
340
|
-
let
|
|
341
|
-
|
|
342
|
-
|
|
365
|
+
function w(e, t, { enabled: n = !0, preventDefault: a = !0, stopPropagation: s = !0, eventType: c = "keydown", preventRepeat: l = !1, ignoreWhenFocusedInInputs: u = !0, ctrlKey: d = !1, shiftKey: f = !1, altKey: p = !1, metaKey: m = !1, target: h = window } = {}) {
|
|
366
|
+
let g = o(t), _ = o(n), v = o(!1);
|
|
367
|
+
i(() => {
|
|
368
|
+
g.current = t;
|
|
343
369
|
}, [t]), r(() => {
|
|
344
|
-
|
|
370
|
+
_.current = n;
|
|
345
371
|
}, [n]), r(() => {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
372
|
+
let t = h && "current" in h ? h.current : h;
|
|
373
|
+
if (!t) return;
|
|
374
|
+
let n = e.toLowerCase(), r = C.includes(c) ? c : "keydown", i = l && r !== "keyup";
|
|
375
|
+
function o() {
|
|
376
|
+
v.current = !1;
|
|
377
|
+
}
|
|
378
|
+
function y(e) {
|
|
379
|
+
if (!(e instanceof KeyboardEvent)) return;
|
|
380
|
+
let t = e.key.toLowerCase();
|
|
381
|
+
(t === n || d && t === "control" || f && t === "shift" || p && t === "alt" || m && t === "meta") && (v.current = !1);
|
|
352
382
|
}
|
|
353
|
-
function
|
|
354
|
-
if (!(
|
|
355
|
-
let
|
|
356
|
-
if (!(
|
|
357
|
-
if (
|
|
358
|
-
|
|
383
|
+
function b(e) {
|
|
384
|
+
if (!(e instanceof KeyboardEvent) || !_.current) return;
|
|
385
|
+
let t = e.target;
|
|
386
|
+
if (!(u && t instanceof HTMLElement && (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement || t.isContentEditable)) && e.ctrlKey === d && e.shiftKey === f && e.altKey === p && e.metaKey === m && n === e.key.toLowerCase()) {
|
|
387
|
+
if (i && v.current) return;
|
|
388
|
+
v.current = !0, g.current(e), a && e.preventDefault(), s && e.stopPropagation();
|
|
359
389
|
}
|
|
360
390
|
}
|
|
361
|
-
return
|
|
362
|
-
|
|
391
|
+
return t.addEventListener(r, b), i && (t.addEventListener("keyup", y), window.addEventListener("blur", o)), () => {
|
|
392
|
+
t.removeEventListener(r, b), i && (t.removeEventListener("keyup", y), window.removeEventListener("blur", o));
|
|
363
393
|
};
|
|
364
394
|
}, [
|
|
365
395
|
e,
|
|
366
|
-
|
|
367
|
-
o,
|
|
396
|
+
a,
|
|
368
397
|
s,
|
|
369
398
|
c,
|
|
370
399
|
l,
|
|
@@ -372,80 +401,146 @@ function b(e, t, { enabled: n = !0, preventDefault: i = !0, stopPropagation: o =
|
|
|
372
401
|
d,
|
|
373
402
|
f,
|
|
374
403
|
p,
|
|
375
|
-
|
|
404
|
+
m,
|
|
405
|
+
h
|
|
376
406
|
]);
|
|
377
407
|
}
|
|
378
408
|
//#endregion
|
|
379
|
-
//#region src/hooks/
|
|
380
|
-
function
|
|
381
|
-
let
|
|
382
|
-
c !== d && l(d);
|
|
383
|
-
let f = i(() => typeof a != "number" || a < 1 ? [] : e.slice(c * a, (c + 1) * a), [
|
|
384
|
-
c,
|
|
385
|
-
a,
|
|
386
|
-
e
|
|
387
|
-
]), p = c > 0, m = c < u - 1, h = t(() => {
|
|
388
|
-
l((e) => e < u - 1 ? e + 1 : e);
|
|
389
|
-
}, [u]), g = t(() => {
|
|
390
|
-
l((e) => e > 0 ? e - 1 : e);
|
|
391
|
-
}, []), _ = t(() => {
|
|
392
|
-
l(0);
|
|
393
|
-
}, []), v = t(() => {
|
|
394
|
-
l(u - 1);
|
|
395
|
-
}, [u]), y = t((e) => {
|
|
396
|
-
typeof e == "number" && e >= 0 && e <= u - 1 && l(e);
|
|
397
|
-
}, [u]), b = t((t) => {
|
|
398
|
-
if (typeof t == "number" && t > 0) {
|
|
399
|
-
s(t);
|
|
400
|
-
let n = Math.max(1, Math.ceil(e.length / Math.max(1, t)));
|
|
401
|
-
l((e) => Math.min(Math.max(0, e), n - 1));
|
|
402
|
-
}
|
|
403
|
-
}, [e.length]), x = t(() => {
|
|
404
|
-
l(Math.min(Math.max(0, r), u - 1));
|
|
405
|
-
}, [r, u]);
|
|
409
|
+
//#region src/hooks/useOrder.ts
|
|
410
|
+
function T(e) {
|
|
411
|
+
let n = o(e), [r, i] = s(e);
|
|
406
412
|
return {
|
|
407
|
-
|
|
408
|
-
|
|
413
|
+
orderedItems: r,
|
|
414
|
+
moveUp: t((e) => {
|
|
415
|
+
typeof e == "number" && i((t) => {
|
|
416
|
+
if (e <= 0 || e >= t.length) return t;
|
|
417
|
+
let n = [...t];
|
|
418
|
+
return [n[e], n[e - 1]] = [n[e - 1], n[e]], n;
|
|
419
|
+
});
|
|
420
|
+
}, []),
|
|
421
|
+
moveDown: t((e) => {
|
|
422
|
+
typeof e == "number" && i((t) => {
|
|
423
|
+
if (e < 0 || e >= t.length - 1) return t;
|
|
424
|
+
let n = [...t];
|
|
425
|
+
return [n[e], n[e + 1]] = [n[e + 1], n[e]], n;
|
|
426
|
+
});
|
|
427
|
+
}, []),
|
|
428
|
+
canMoveUp: t((e) => e > 0, []),
|
|
429
|
+
canMoveDown: t((e) => e < r.length - 1, [r.length]),
|
|
430
|
+
moveToTop: t((e) => {
|
|
431
|
+
typeof e == "number" && i((t) => {
|
|
432
|
+
if (e <= 0 || e >= t.length) return t;
|
|
433
|
+
let n = [...t], [r] = n.splice(e, 1);
|
|
434
|
+
return n.unshift(r), n;
|
|
435
|
+
});
|
|
436
|
+
}, []),
|
|
437
|
+
moveToBottom: t((e) => {
|
|
438
|
+
typeof e == "number" && i((t) => {
|
|
439
|
+
if (e < 0 || e >= t.length - 1) return t;
|
|
440
|
+
let n = [...t], [r] = n.splice(e, 1);
|
|
441
|
+
return n.push(r), n;
|
|
442
|
+
});
|
|
443
|
+
}, []),
|
|
444
|
+
move: t((e, t) => {
|
|
445
|
+
typeof e != "number" || typeof t != "number" || e === t || i((n) => {
|
|
446
|
+
if (e < 0 || e >= n.length || t < 0 || t >= n.length) return n;
|
|
447
|
+
let r = [...n], [i] = r.splice(e, 1);
|
|
448
|
+
return r.splice(t, 0, i), r;
|
|
449
|
+
});
|
|
450
|
+
}, []),
|
|
451
|
+
swap: t((e, t) => {
|
|
452
|
+
typeof e != "number" || typeof t != "number" || e === t || i((n) => {
|
|
453
|
+
if (e < 0 || e >= n.length || t < 0 || t >= n.length) return n;
|
|
454
|
+
let r = [...n];
|
|
455
|
+
return [r[e], r[t]] = [r[t], r[e]], r;
|
|
456
|
+
});
|
|
457
|
+
}, []),
|
|
458
|
+
replaceOrder: t((e) => {
|
|
459
|
+
i(e);
|
|
460
|
+
}, []),
|
|
461
|
+
resetOrder: t(() => {
|
|
462
|
+
i(n.current);
|
|
463
|
+
}, [])
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/hooks/usePagination.ts
|
|
468
|
+
function E(e, n, r = 0) {
|
|
469
|
+
let [i, o] = s(n), [c, l] = s(r), u = Math.max(1, Math.ceil(e.length / Math.max(1, i))), d = Math.min(Math.max(0, c), u - 1);
|
|
470
|
+
return c !== d && l(d), {
|
|
471
|
+
pageItems: a(() => typeof i != "number" || i < 1 ? [] : e.slice(c * i, (c + 1) * i), [
|
|
472
|
+
c,
|
|
473
|
+
i,
|
|
474
|
+
e
|
|
475
|
+
]),
|
|
476
|
+
pageSize: i,
|
|
409
477
|
pageIndex: c,
|
|
410
478
|
totalPages: u,
|
|
411
|
-
canPrevious:
|
|
412
|
-
canNext:
|
|
413
|
-
nextPage:
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
479
|
+
canPrevious: c > 0,
|
|
480
|
+
canNext: c < u - 1,
|
|
481
|
+
nextPage: t(() => {
|
|
482
|
+
l((e) => e < u - 1 ? e + 1 : e);
|
|
483
|
+
}, [u]),
|
|
484
|
+
previousPage: t(() => {
|
|
485
|
+
l((e) => e > 0 ? e - 1 : e);
|
|
486
|
+
}, []),
|
|
487
|
+
goToFirstPage: t(() => {
|
|
488
|
+
l(0);
|
|
489
|
+
}, []),
|
|
490
|
+
goToLastPage: t(() => {
|
|
491
|
+
l(u - 1);
|
|
492
|
+
}, [u]),
|
|
493
|
+
goToPage: t((e) => {
|
|
494
|
+
typeof e == "number" && e >= 0 && e <= u - 1 && l(e);
|
|
495
|
+
}, [u]),
|
|
496
|
+
changePageSize: t((t) => {
|
|
497
|
+
if (typeof t == "number" && t > 0) {
|
|
498
|
+
o(t);
|
|
499
|
+
let n = Math.max(1, Math.ceil(e.length / Math.max(1, t)));
|
|
500
|
+
l((e) => Math.min(Math.max(0, e), n - 1));
|
|
501
|
+
}
|
|
502
|
+
}, [e.length]),
|
|
503
|
+
resetPageIndex: t(() => {
|
|
504
|
+
l(Math.min(Math.max(0, r), u - 1));
|
|
505
|
+
}, [r, u]),
|
|
419
506
|
resetPageSize: t(() => {
|
|
420
|
-
|
|
507
|
+
o(Math.max(1, n));
|
|
421
508
|
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
422
509
|
l((e) => Math.min(Math.max(0, e), t - 1));
|
|
423
510
|
}, [n, e.length]),
|
|
424
|
-
|
|
511
|
+
resetPagination: t(() => {
|
|
512
|
+
o(Math.max(1, n));
|
|
513
|
+
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
514
|
+
l(Math.min(Math.max(0, r), t - 1));
|
|
515
|
+
}, [
|
|
516
|
+
n,
|
|
517
|
+
r,
|
|
518
|
+
e.length
|
|
519
|
+
])
|
|
425
520
|
};
|
|
426
521
|
}
|
|
427
522
|
//#endregion
|
|
428
523
|
//#region src/utils/sortUtils.ts
|
|
429
|
-
function
|
|
430
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
524
|
+
function D(e, t, n = {}) {
|
|
525
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = P(e, t, r, i);
|
|
431
526
|
if (a !== null) return a;
|
|
432
527
|
let o = !!e;
|
|
433
528
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
434
529
|
}
|
|
435
|
-
function
|
|
436
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
530
|
+
function O(e, t, n = {}) {
|
|
531
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = P(e, t, r, i);
|
|
437
532
|
if (a !== null) return a;
|
|
438
533
|
let o = Number(e), s = Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
439
|
-
return c || l ?
|
|
534
|
+
return c || l ? P(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
440
535
|
}
|
|
441
|
-
function
|
|
442
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
536
|
+
function k(e, t, n = {}) {
|
|
537
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = P(e, t, i, r);
|
|
443
538
|
if (o !== null) return o;
|
|
444
539
|
let s = String(e), c = String(t);
|
|
445
540
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
446
541
|
}
|
|
447
|
-
function
|
|
448
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
542
|
+
function A(e, t, n = {}) {
|
|
543
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = P(e, t, i, r);
|
|
449
544
|
if (o !== null) return o;
|
|
450
545
|
let s = String(e), c = String(t);
|
|
451
546
|
return s.localeCompare(c, void 0, {
|
|
@@ -453,21 +548,21 @@ function T(e, t, n = {}) {
|
|
|
453
548
|
sensitivity: a ? "variant" : "base"
|
|
454
549
|
});
|
|
455
550
|
}
|
|
456
|
-
function
|
|
457
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
551
|
+
function j(e, t, n = {}) {
|
|
552
|
+
let { desc: r = !1, sortUndefined: i } = n, a = P(e, t, i, r);
|
|
458
553
|
if (a !== null) return a;
|
|
459
554
|
let o = new Date(e).getTime(), s = new Date(t).getTime(), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
460
|
-
return (c || l) && (a =
|
|
555
|
+
return (c || l) && (a = P(c ? void 0 : o, l ? void 0 : s, i, r), a !== null) ? a : o - s;
|
|
461
556
|
}
|
|
462
|
-
function
|
|
463
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
557
|
+
function M(e, t, n = {}) {
|
|
558
|
+
let { desc: r = !1, sortUndefined: i } = n, a = P(e, t, i, r);
|
|
464
559
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
465
560
|
}
|
|
466
|
-
function
|
|
467
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
561
|
+
function N(e, t, n = {}) {
|
|
562
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = P(e, t, i, r);
|
|
468
563
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
469
564
|
}
|
|
470
|
-
function
|
|
565
|
+
function P(e, t, n = "last", r) {
|
|
471
566
|
let i = e == null || e === "", a = t == null || t === "";
|
|
472
567
|
if (i && a) return 0;
|
|
473
568
|
if (!i && !a) return null;
|
|
@@ -485,70 +580,70 @@ function k(e, t, n = "last", r) {
|
|
|
485
580
|
}
|
|
486
581
|
//#endregion
|
|
487
582
|
//#region src/hooks/useSort.ts
|
|
488
|
-
function
|
|
489
|
-
let [r,
|
|
583
|
+
function F(e, n = []) {
|
|
584
|
+
let [r, i] = s(n), o = a(() => {
|
|
490
585
|
let t = r.map((e) => ({
|
|
491
586
|
...e,
|
|
492
587
|
pathArray: (e.field || e.id).split(".")
|
|
493
588
|
}));
|
|
494
589
|
return [...e].sort((e, n) => {
|
|
495
590
|
for (let r of t) {
|
|
496
|
-
let { type: t, id: i, desc: a = !1, invertSorting: o = !1, pathArray: s } = r, c =
|
|
591
|
+
let { type: t, id: i, desc: a = !1, invertSorting: o = !1, pathArray: s } = r, c = y(e, s, i), l = y(n, s, i), u;
|
|
497
592
|
switch (t) {
|
|
498
593
|
case "numeric":
|
|
499
|
-
u =
|
|
594
|
+
u = O(c, l, r);
|
|
500
595
|
break;
|
|
501
596
|
case "alphabetical":
|
|
502
|
-
u =
|
|
597
|
+
u = k(c, l, r);
|
|
503
598
|
break;
|
|
504
599
|
case "alphanumeric":
|
|
505
|
-
u =
|
|
600
|
+
u = A(c, l, r);
|
|
506
601
|
break;
|
|
507
602
|
case "boolean":
|
|
508
|
-
u =
|
|
603
|
+
u = D(c, l, r);
|
|
509
604
|
break;
|
|
510
605
|
case "date":
|
|
511
|
-
u =
|
|
606
|
+
u = j(c, l, r);
|
|
512
607
|
break;
|
|
513
608
|
case "basic":
|
|
514
|
-
u =
|
|
609
|
+
u = M(c, l, r);
|
|
515
610
|
break;
|
|
516
611
|
case "custom":
|
|
517
|
-
u =
|
|
612
|
+
u = N(c, l, r);
|
|
518
613
|
break;
|
|
519
|
-
default: u =
|
|
614
|
+
default: u = M(c, l, r);
|
|
520
615
|
}
|
|
521
616
|
if (u !== 0) return u * (a === o ? 1 : -1);
|
|
522
617
|
}
|
|
523
618
|
return 0;
|
|
524
619
|
});
|
|
525
|
-
}, [r, e]), c = t((e) =>
|
|
526
|
-
|
|
527
|
-
}, []), u = t(() =>
|
|
528
|
-
let { multi: r = !1, ...
|
|
529
|
-
|
|
530
|
-
let
|
|
531
|
-
if (!
|
|
532
|
-
let
|
|
620
|
+
}, [r, e]), c = t((e) => i((t) => t.some((t) => t.id === e.id) ? t.map((t) => t.id === e.id ? e : t) : [...t, e]), []), l = t((e) => {
|
|
621
|
+
i((t) => Array.isArray(e) ? t.filter((t) => !e.includes(t.id)) : t.filter((t) => t.id !== e));
|
|
622
|
+
}, []), u = t(() => i([]), []), d = t(() => i(n), [n]), f = t((e) => i(e), []), p = t((e, t, n) => {
|
|
623
|
+
let { multi: r = !1, ...a } = n || {};
|
|
624
|
+
i((n) => {
|
|
625
|
+
let i = n.find((t) => t.id === e);
|
|
626
|
+
if (!i) {
|
|
627
|
+
let i = {
|
|
533
628
|
id: e,
|
|
534
629
|
type: t,
|
|
535
|
-
...
|
|
630
|
+
...a,
|
|
536
631
|
desc: !1
|
|
537
632
|
};
|
|
538
|
-
return r ? [...n,
|
|
633
|
+
return r ? [...n, i] : [i];
|
|
539
634
|
}
|
|
540
|
-
if (!
|
|
635
|
+
if (!i.desc) {
|
|
541
636
|
let t = {
|
|
542
|
-
...a,
|
|
543
637
|
...i,
|
|
638
|
+
...a,
|
|
544
639
|
desc: !0
|
|
545
640
|
};
|
|
546
641
|
return r ? n.map((n) => n.id === e ? t : n) : [t];
|
|
547
642
|
}
|
|
548
|
-
if (
|
|
643
|
+
if (i.disableSortRemoval || a.disableSortRemoval) {
|
|
549
644
|
let t = {
|
|
550
|
-
...a,
|
|
551
645
|
...i,
|
|
646
|
+
...a,
|
|
552
647
|
desc: !1
|
|
553
648
|
};
|
|
554
649
|
return r ? n.map((n) => n.id === e ? t : n) : [t];
|
|
@@ -557,7 +652,7 @@ function A(e, n = []) {
|
|
|
557
652
|
});
|
|
558
653
|
}, []);
|
|
559
654
|
return {
|
|
560
|
-
sortedItems:
|
|
655
|
+
sortedItems: o,
|
|
561
656
|
sorts: r,
|
|
562
657
|
upsertSorts: c,
|
|
563
658
|
removeSort: l,
|
|
@@ -581,8 +676,8 @@ function A(e, n = []) {
|
|
|
581
676
|
}
|
|
582
677
|
//#endregion
|
|
583
678
|
//#region src/hooks/useThrottle.ts
|
|
584
|
-
function
|
|
585
|
-
let [
|
|
679
|
+
function I(e, n, i = {}) {
|
|
680
|
+
let [a, c] = s(!1), l = i.leading ?? !0, u = i.trailing ?? !0, d = o(e), f = o(null), p = o(-1), m = o(null);
|
|
586
681
|
r(() => {
|
|
587
682
|
d.current = e;
|
|
588
683
|
}, [e]);
|
|
@@ -611,8 +706,8 @@ function j(e, n, i = {}) {
|
|
|
611
706
|
]),
|
|
612
707
|
cancel: h,
|
|
613
708
|
flush: g,
|
|
614
|
-
isPending:
|
|
709
|
+
isPending: a
|
|
615
710
|
};
|
|
616
711
|
}
|
|
617
712
|
//#endregion
|
|
618
|
-
export {
|
|
713
|
+
export { h as ModalLayout, g as useDebounce, _ as useDebouncedValue, b as useFilter, S as useFuzzySearch, w as useKey, m as useModal, p as useModalActions, f as useModalState, T as useOrder, E as usePagination, F as useSort, I as useThrottle };
|