@himanshu-sorathiya/react-kit 1.0.16 → 1.0.17
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 +71 -52
- package/dist/index.js +260 -202
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -141,24 +141,6 @@ export declare function useGrouping<T = unknown>({ items, initialGroupBy, }: {
|
|
|
141
141
|
items: T[];
|
|
142
142
|
initialGroupBy?: string;
|
|
143
143
|
}): UseGroupingReturn<T>;
|
|
144
|
-
export interface UsePaginationReturn<T> {
|
|
145
|
-
pageItems: T[];
|
|
146
|
-
pageSize: number;
|
|
147
|
-
pageIndex: number;
|
|
148
|
-
totalPages: number;
|
|
149
|
-
canPrevious: boolean;
|
|
150
|
-
canNext: boolean;
|
|
151
|
-
nextPage: () => void;
|
|
152
|
-
previousPage: () => void;
|
|
153
|
-
goToFirstPage: () => void;
|
|
154
|
-
goToLastPage: () => void;
|
|
155
|
-
goToPage: (newPageIndex: number) => void;
|
|
156
|
-
changePageSize: (newPageSize: number) => void;
|
|
157
|
-
resetPageIndex: () => void;
|
|
158
|
-
resetPageSize: () => void;
|
|
159
|
-
resetPagination: () => void;
|
|
160
|
-
}
|
|
161
|
-
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
162
144
|
export type SelectionId = string | number;
|
|
163
145
|
export interface UseMultipleSelectionReturn<T> {
|
|
164
146
|
selectedIds: SelectionId[];
|
|
@@ -184,17 +166,6 @@ export declare function useMultipleSelection<T = unknown>({ items, field, initia
|
|
|
184
166
|
field?: string;
|
|
185
167
|
initialSelectedIds?: SelectionId[];
|
|
186
168
|
}): UseMultipleSelectionReturn<T>;
|
|
187
|
-
type SelectionId$1 = string | number;
|
|
188
|
-
export interface UseSingleSelectionReturn {
|
|
189
|
-
selectedId: SelectionId$1 | undefined;
|
|
190
|
-
hasSelection: boolean;
|
|
191
|
-
select: (id: SelectionId$1) => void;
|
|
192
|
-
deselect: () => void;
|
|
193
|
-
toggle: (id: SelectionId$1) => void;
|
|
194
|
-
isSelected: (id: SelectionId$1) => boolean;
|
|
195
|
-
resetSelection: () => void;
|
|
196
|
-
}
|
|
197
|
-
export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
|
|
198
169
|
export interface UseOrderReturn<T> {
|
|
199
170
|
orderedItems: T[];
|
|
200
171
|
moveUp: (index: number) => void;
|
|
@@ -209,30 +180,35 @@ export interface UseOrderReturn<T> {
|
|
|
209
180
|
replaceOrder: (newOrderedItems: T[]) => void;
|
|
210
181
|
}
|
|
211
182
|
export declare function useOrder<T>(initialItems: T[]): UseOrderReturn<T>;
|
|
212
|
-
export
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
|
|
183
|
+
export interface UsePaginationReturn<T> {
|
|
184
|
+
pageItems: T[];
|
|
185
|
+
pageSize: number;
|
|
186
|
+
pageIndex: number;
|
|
187
|
+
totalPages: number;
|
|
188
|
+
canPrevious: boolean;
|
|
189
|
+
canNext: boolean;
|
|
190
|
+
nextPage: () => void;
|
|
191
|
+
previousPage: () => void;
|
|
192
|
+
goToFirstPage: () => void;
|
|
193
|
+
goToLastPage: () => void;
|
|
194
|
+
goToPage: (newPageIndex: number) => void;
|
|
195
|
+
changePageSize: (newPageSize: number) => void;
|
|
196
|
+
resetPageIndex: () => void;
|
|
197
|
+
resetPageSize: () => void;
|
|
198
|
+
resetPagination: () => void;
|
|
229
199
|
}
|
|
230
|
-
export declare function
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
200
|
+
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
201
|
+
type SelectionId$1 = string | number;
|
|
202
|
+
export interface UseSingleSelectionReturn {
|
|
203
|
+
selectedId: SelectionId$1 | undefined;
|
|
204
|
+
hasSelection: boolean;
|
|
205
|
+
select: (id: SelectionId$1) => void;
|
|
206
|
+
deselect: () => void;
|
|
207
|
+
toggle: (id: SelectionId$1) => void;
|
|
208
|
+
isSelected: (id: SelectionId$1) => boolean;
|
|
209
|
+
resetSelection: () => void;
|
|
210
|
+
}
|
|
211
|
+
export declare function useSingleSelection(initialSelectedId?: SelectionId$1): UseSingleSelectionReturn;
|
|
236
212
|
export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
|
|
237
213
|
export interface BaseSortOptions {
|
|
238
214
|
desc?: boolean;
|
|
@@ -274,6 +250,25 @@ export interface UseSortReturn<T> {
|
|
|
274
250
|
getSortIndex: (id: string) => number | undefined;
|
|
275
251
|
}
|
|
276
252
|
export declare function useSort<T>(data: T[], initialSorts?: SortState): UseSortReturn<T>;
|
|
253
|
+
export type ExpansionId = string | number;
|
|
254
|
+
export interface UseExpansionReturn<T> {
|
|
255
|
+
expandedIds: ExpansionId[];
|
|
256
|
+
expandedItems: T[];
|
|
257
|
+
isExpanded: (itemOrId: ExpansionId | T) => boolean;
|
|
258
|
+
expand: (itemOrId: ExpansionId | T) => void;
|
|
259
|
+
collapse: (itemOrId: ExpansionId | T) => void;
|
|
260
|
+
toggle: (itemOrId: ExpansionId | T) => void;
|
|
261
|
+
expandAll: () => void;
|
|
262
|
+
collapseAll: () => void;
|
|
263
|
+
resetExpansion: () => void;
|
|
264
|
+
replaceExpansion: (newExpandedItems: ExpansionId[] | T[]) => void;
|
|
265
|
+
}
|
|
266
|
+
export declare function useExpansion<T = unknown>({ items, field, initialExpandedIds, multiple, }?: {
|
|
267
|
+
items?: T[];
|
|
268
|
+
field?: string;
|
|
269
|
+
initialExpandedIds?: ExpansionId[];
|
|
270
|
+
multiple?: boolean;
|
|
271
|
+
}): UseExpansionReturn<T>;
|
|
277
272
|
export interface UseModalStateReturn<TData> {
|
|
278
273
|
isOpen: boolean;
|
|
279
274
|
id: string | null;
|
|
@@ -288,6 +283,30 @@ export type UseModalReturn<TData> = UseModalStateReturn<TData> & UseModalActions
|
|
|
288
283
|
export declare function useModalState<TData = unknown>(): UseModalStateReturn<TData>;
|
|
289
284
|
export declare function useModalActions(): UseModalActionsReturn;
|
|
290
285
|
export declare function useModal<TData = unknown>(): UseModalReturn<TData>;
|
|
286
|
+
export type PinId = string | number;
|
|
287
|
+
export interface UsePinReturn<T> {
|
|
288
|
+
pinnedIds: PinId[];
|
|
289
|
+
pinnedItems: T[];
|
|
290
|
+
unpinnedItems: T[];
|
|
291
|
+
pinnedCount: number;
|
|
292
|
+
hasPins: boolean;
|
|
293
|
+
isAtMaxLimit: boolean;
|
|
294
|
+
pin: (itemOrId: PinId | T) => void;
|
|
295
|
+
unpin: (itemOrId: PinId | T) => void;
|
|
296
|
+
togglePin: (itemOrId: PinId | T) => void;
|
|
297
|
+
isPinned: (itemOrId: PinId | T) => boolean;
|
|
298
|
+
clearPins: () => void;
|
|
299
|
+
resetPins: () => void;
|
|
300
|
+
replacePins: (newPinnedItems: PinId[] | T[]) => void;
|
|
301
|
+
pinMultiple: (newItems: PinId[] | T[]) => void;
|
|
302
|
+
unpinMultiple: (itemsToRemove: PinId[] | T[]) => void;
|
|
303
|
+
}
|
|
304
|
+
export declare function usePin<T = unknown>({ items, field, initialPinnedIds, maxPins, }: {
|
|
305
|
+
items: T[];
|
|
306
|
+
field?: string;
|
|
307
|
+
initialPinnedIds?: PinId[];
|
|
308
|
+
maxPins?: number;
|
|
309
|
+
}): UsePinReturn<T>;
|
|
291
310
|
export type VisibilityId = number | string;
|
|
292
311
|
export interface UseVisibilityReturn<T> {
|
|
293
312
|
visibleIds: VisibilityId[];
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
import { Fragment as c, jsx as l } from "react/jsx-runtime";
|
|
3
3
|
import { createPortal as u } from "react-dom";
|
|
4
|
-
//#region src/ui/
|
|
4
|
+
//#region src/ui/FuzzyHighlighter/FuzzyHighlighter.tsx
|
|
5
5
|
function d({ text: e, query: t, className: n = "", caseSensitive: r = !1 }) {
|
|
6
6
|
let i = t.trim();
|
|
7
7
|
if (!i || !e) return /* @__PURE__ */ l(c, { children: e });
|
|
@@ -23,10 +23,10 @@ function d({ text: e, query: t, className: n = "", caseSensitive: r = !1 }) {
|
|
|
23
23
|
}, t) : e) });
|
|
24
24
|
}
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region src/ui/
|
|
26
|
+
//#region src/ui/useModal/ModalContext.tsx
|
|
27
27
|
var f = e(null), p = e(null);
|
|
28
28
|
//#endregion
|
|
29
|
-
//#region src/ui/
|
|
29
|
+
//#region src/ui/useModal/useModal.ts
|
|
30
30
|
function m() {
|
|
31
31
|
let e = n(f);
|
|
32
32
|
if (!e) throw Error("useModalState must be used within a ModalProvider");
|
|
@@ -44,13 +44,13 @@ function g() {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
//#endregion
|
|
47
|
-
//#region src/ui/
|
|
47
|
+
//#region src/ui/useModal/ModalLayout.tsx
|
|
48
48
|
function _({ modalId: e, children: t, wrapperClassName: n = "", wrapperStyle: i, containerClassName: a = "", containerStyle: c }) {
|
|
49
|
-
let { isOpen: d, id: f } = m(), { closeModal: p, clearModal: g } = h(), [_, v] = s(!1), y = o(null), b = f === e,
|
|
49
|
+
let { isOpen: d, id: f } = m(), { closeModal: p, clearModal: g } = h(), [_, v] = s(!1), y = o(null), b = o(null), x = f === e, S = d && x;
|
|
50
50
|
return r(() => {
|
|
51
51
|
let e = y.current;
|
|
52
|
-
e && (
|
|
53
|
-
}, [
|
|
52
|
+
e && (S && !e.open ? (document.activeElement && (b.current = document.activeElement), v(!1), e.showModal()) : !S && e.open && v(!0));
|
|
53
|
+
}, [S]), typeof document > "u" || !x && !_ ? null : u(/* @__PURE__ */ l("dialog", {
|
|
54
54
|
ref: y,
|
|
55
55
|
onCancel: (e) => {
|
|
56
56
|
e.preventDefault(), p();
|
|
@@ -65,7 +65,7 @@ function _({ modalId: e, children: t, wrapperClassName: n = "", wrapperStyle: i,
|
|
|
65
65
|
onAnimationEnd: () => {
|
|
66
66
|
if (_) {
|
|
67
67
|
let e = y.current;
|
|
68
|
-
e && e.close(), v(!1),
|
|
68
|
+
e && e.close(), v(!1), x && g(), b.current &&= (b.current.focus(), null);
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
className: `universal-modal ${n}`.trim(),
|
|
@@ -85,7 +85,7 @@ function v(e, t, n) {
|
|
|
85
85
|
return Array.isArray(r) ? r.reduce((e, t) => e?.[t], e) : r.includes(".") ? r.split(".").reduce((e, t) => e?.[t], e) : e?.[r];
|
|
86
86
|
}
|
|
87
87
|
//#endregion
|
|
88
|
-
//#region src/state/
|
|
88
|
+
//#region src/state/useFilter/utils.ts
|
|
89
89
|
var y = {
|
|
90
90
|
text: {
|
|
91
91
|
contains: (e, t, n) => e == null ? !1 : n?.caseSensitive ? String(e).includes(String(t)) : String(e).toLowerCase().includes(String(t).toLowerCase()),
|
|
@@ -142,7 +142,7 @@ var y = {
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
//#endregion
|
|
145
|
-
//#region src/state/
|
|
145
|
+
//#region src/state/useFilter/useFilter.ts
|
|
146
146
|
function b(e, n = []) {
|
|
147
147
|
let r = o(n), [i, c] = s(() => n), l = a(() => {
|
|
148
148
|
let t = i.filter((e) => e.isActive !== !1).map((e) => ({
|
|
@@ -205,7 +205,7 @@ function b(e, n = []) {
|
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
//#endregion
|
|
208
|
-
//#region src/state/
|
|
208
|
+
//#region src/state/useFuzzySearch/utils.ts
|
|
209
209
|
function x(e, t, n = !1) {
|
|
210
210
|
let r = e.trim(), i = t.trim(), a = r.length > 1 && r === r.toUpperCase() && /^[A-Z]+$/.test(r);
|
|
211
211
|
if (n || (r = r.toLowerCase(), i = i.toLowerCase()), r === i) return 1;
|
|
@@ -254,7 +254,7 @@ function x(e, t, n = !1) {
|
|
|
254
254
|
return Math.max(0, _ * .45);
|
|
255
255
|
}
|
|
256
256
|
//#endregion
|
|
257
|
-
//#region src/state/
|
|
257
|
+
//#region src/state/useFuzzySearch/useFuzzySearch.ts
|
|
258
258
|
function S(e, t, n, r = {}) {
|
|
259
259
|
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) => {
|
|
260
260
|
let r = [], i = [];
|
|
@@ -336,7 +336,7 @@ function S(e, t, n, r = {}) {
|
|
|
336
336
|
]);
|
|
337
337
|
}
|
|
338
338
|
//#endregion
|
|
339
|
-
//#region src/state/
|
|
339
|
+
//#region src/state/useGrouping/useGrouping.ts
|
|
340
340
|
function C({ items: e, initialGroupBy: n }) {
|
|
341
341
|
let [r, i] = s(n), o = a(() => r ? e.reduce((e, t) => {
|
|
342
342
|
let n = v(t, r), i = n == null ? "Unknown" : String(n);
|
|
@@ -364,64 +364,8 @@ function C({ items: e, initialGroupBy: n }) {
|
|
|
364
364
|
};
|
|
365
365
|
}
|
|
366
366
|
//#endregion
|
|
367
|
-
//#region src/state/
|
|
368
|
-
function w(e, n, r =
|
|
369
|
-
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);
|
|
370
|
-
return c !== d && l(d), {
|
|
371
|
-
pageItems: a(() => typeof i != "number" || i < 1 ? [] : e.slice(c * i, (c + 1) * i), [
|
|
372
|
-
c,
|
|
373
|
-
i,
|
|
374
|
-
e
|
|
375
|
-
]),
|
|
376
|
-
pageSize: i,
|
|
377
|
-
pageIndex: c,
|
|
378
|
-
totalPages: u,
|
|
379
|
-
canPrevious: c > 0,
|
|
380
|
-
canNext: c < u - 1,
|
|
381
|
-
nextPage: t(() => {
|
|
382
|
-
l((e) => e < u - 1 ? e + 1 : e);
|
|
383
|
-
}, [u]),
|
|
384
|
-
previousPage: t(() => {
|
|
385
|
-
l((e) => e > 0 ? e - 1 : e);
|
|
386
|
-
}, []),
|
|
387
|
-
goToFirstPage: t(() => {
|
|
388
|
-
l(0);
|
|
389
|
-
}, []),
|
|
390
|
-
goToLastPage: t(() => {
|
|
391
|
-
l(u - 1);
|
|
392
|
-
}, [u]),
|
|
393
|
-
goToPage: t((e) => {
|
|
394
|
-
typeof e == "number" && e >= 0 && e <= u - 1 && l(e);
|
|
395
|
-
}, [u]),
|
|
396
|
-
changePageSize: t((t) => {
|
|
397
|
-
if (typeof t == "number" && t > 0) {
|
|
398
|
-
o(t);
|
|
399
|
-
let n = Math.max(1, Math.ceil(e.length / Math.max(1, t)));
|
|
400
|
-
l((e) => Math.min(Math.max(0, e), n - 1));
|
|
401
|
-
}
|
|
402
|
-
}, [e.length]),
|
|
403
|
-
resetPageIndex: t(() => {
|
|
404
|
-
l(Math.min(Math.max(0, r), u - 1));
|
|
405
|
-
}, [r, u]),
|
|
406
|
-
resetPageSize: t(() => {
|
|
407
|
-
o(Math.max(1, n));
|
|
408
|
-
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
409
|
-
l((e) => Math.min(Math.max(0, e), t - 1));
|
|
410
|
-
}, [n, e.length]),
|
|
411
|
-
resetPagination: t(() => {
|
|
412
|
-
o(Math.max(1, n));
|
|
413
|
-
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
414
|
-
l(Math.min(Math.max(0, r), t - 1));
|
|
415
|
-
}, [
|
|
416
|
-
n,
|
|
417
|
-
r,
|
|
418
|
-
e.length
|
|
419
|
-
])
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region src/state/selection/useMultipleSelection.ts
|
|
424
|
-
function T({ items: e, field: n, initialSelectedIds: r = [] }) {
|
|
367
|
+
//#region src/state/useMultipleSelection/useMultipleSelection.ts
|
|
368
|
+
function w({ items: e, field: n, initialSelectedIds: r = [] }) {
|
|
425
369
|
let i = o(r), [c, l] = s(() => new Set(r)), u = t((e) => {
|
|
426
370
|
l((t) => {
|
|
427
371
|
let r = new Set(t), i = v(e, n);
|
|
@@ -500,22 +444,8 @@ function T({ items: e, field: n, initialSelectedIds: r = [] }) {
|
|
|
500
444
|
};
|
|
501
445
|
}
|
|
502
446
|
//#endregion
|
|
503
|
-
//#region src/state/
|
|
504
|
-
function
|
|
505
|
-
let [n, r] = s(e), i = t((e) => r(e), []), a = t(() => r(void 0), []), o = t((e) => r((t) => t === e ? void 0 : e), []), c = t((e) => n === e, [n]), l = t(() => r(e), [e]);
|
|
506
|
-
return {
|
|
507
|
-
selectedId: n,
|
|
508
|
-
hasSelection: !!n,
|
|
509
|
-
select: i,
|
|
510
|
-
deselect: a,
|
|
511
|
-
toggle: o,
|
|
512
|
-
isSelected: c,
|
|
513
|
-
resetSelection: l
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
//#endregion
|
|
517
|
-
//#region src/state/sort/useOrder.ts
|
|
518
|
-
function D(e) {
|
|
447
|
+
//#region src/state/useOrder/useOrder.ts
|
|
448
|
+
function T(e) {
|
|
519
449
|
let n = o(e), [r, i] = s(() => e), a = t((e) => {
|
|
520
450
|
typeof e == "number" && i((t) => {
|
|
521
451
|
if (e <= 0 || e >= t.length) return t;
|
|
@@ -572,104 +502,97 @@ function D(e) {
|
|
|
572
502
|
};
|
|
573
503
|
}
|
|
574
504
|
//#endregion
|
|
575
|
-
//#region src/state/
|
|
576
|
-
function
|
|
577
|
-
let
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
})
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
r.add(e);
|
|
505
|
+
//#region src/state/usePagination/usePagination.ts
|
|
506
|
+
function E(e, n, r = 0) {
|
|
507
|
+
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);
|
|
508
|
+
return c !== d && l(d), {
|
|
509
|
+
pageItems: a(() => typeof i != "number" || i < 1 ? [] : e.slice(c * i, (c + 1) * i), [
|
|
510
|
+
c,
|
|
511
|
+
i,
|
|
512
|
+
e
|
|
513
|
+
]),
|
|
514
|
+
pageSize: i,
|
|
515
|
+
pageIndex: c,
|
|
516
|
+
totalPages: u,
|
|
517
|
+
canPrevious: c > 0,
|
|
518
|
+
canNext: c < u - 1,
|
|
519
|
+
nextPage: t(() => {
|
|
520
|
+
l((e) => e < u - 1 ? e + 1 : e);
|
|
521
|
+
}, [u]),
|
|
522
|
+
previousPage: t(() => {
|
|
523
|
+
l((e) => e > 0 ? e - 1 : e);
|
|
524
|
+
}, []),
|
|
525
|
+
goToFirstPage: t(() => {
|
|
526
|
+
l(0);
|
|
527
|
+
}, []),
|
|
528
|
+
goToLastPage: t(() => {
|
|
529
|
+
l(u - 1);
|
|
530
|
+
}, [u]),
|
|
531
|
+
goToPage: t((e) => {
|
|
532
|
+
typeof e == "number" && e >= 0 && e <= u - 1 && l(e);
|
|
533
|
+
}, [u]),
|
|
534
|
+
changePageSize: t((t) => {
|
|
535
|
+
if (typeof t == "number" && t > 0) {
|
|
536
|
+
o(t);
|
|
537
|
+
let n = Math.max(1, Math.ceil(e.length / Math.max(1, t)));
|
|
538
|
+
l((e) => Math.min(Math.max(0, e), n - 1));
|
|
610
539
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
u
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
540
|
+
}, [e.length]),
|
|
541
|
+
resetPageIndex: t(() => {
|
|
542
|
+
l(Math.min(Math.max(0, r), u - 1));
|
|
543
|
+
}, [r, u]),
|
|
544
|
+
resetPageSize: t(() => {
|
|
545
|
+
o(Math.max(1, n));
|
|
546
|
+
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
547
|
+
l((e) => Math.min(Math.max(0, e), t - 1));
|
|
548
|
+
}, [n, e.length]),
|
|
549
|
+
resetPagination: t(() => {
|
|
550
|
+
o(Math.max(1, n));
|
|
551
|
+
let t = Math.max(1, Math.ceil(e.length / Math.max(1, n)));
|
|
552
|
+
l(Math.min(Math.max(0, r), t - 1));
|
|
553
|
+
}, [
|
|
554
|
+
n,
|
|
555
|
+
r,
|
|
556
|
+
e.length
|
|
557
|
+
])
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/state/useSingleSelection/useSingleSelection.ts
|
|
562
|
+
function D(e) {
|
|
563
|
+
let [n, r] = s(e), i = t((e) => r(e), []), a = t(() => r(void 0), []), o = t((e) => r((t) => t === e ? void 0 : e), []), c = t((e) => n === e, [n]), l = t(() => r(e), [e]);
|
|
633
564
|
return {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
unpin: f,
|
|
642
|
-
togglePin: p,
|
|
643
|
-
isPinned: m,
|
|
644
|
-
clearPins: h,
|
|
645
|
-
resetPins: g,
|
|
646
|
-
replacePins: _,
|
|
647
|
-
pinMultiple: y,
|
|
648
|
-
unpinMultiple: b
|
|
565
|
+
selectedId: n,
|
|
566
|
+
hasSelection: !!n,
|
|
567
|
+
select: i,
|
|
568
|
+
deselect: a,
|
|
569
|
+
toggle: o,
|
|
570
|
+
isSelected: c,
|
|
571
|
+
resetSelection: l
|
|
649
572
|
};
|
|
650
573
|
}
|
|
651
574
|
//#endregion
|
|
652
|
-
//#region src/state/
|
|
653
|
-
function
|
|
654
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
575
|
+
//#region src/state/useSort/utils.ts
|
|
576
|
+
function O(e, t, n = {}) {
|
|
577
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = F(e, t, r, i);
|
|
655
578
|
if (a !== null) return a;
|
|
656
579
|
let o = !!e;
|
|
657
580
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
658
581
|
}
|
|
659
|
-
function
|
|
660
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
582
|
+
function k(e, t, n = {}) {
|
|
583
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = F(e, t, r, i);
|
|
661
584
|
if (a !== null) return a;
|
|
662
585
|
let o = Number(e), s = Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
663
|
-
return c || l ?
|
|
586
|
+
return c || l ? F(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
664
587
|
}
|
|
665
|
-
function
|
|
666
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
588
|
+
function A(e, t, n = {}) {
|
|
589
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = F(e, t, i, r);
|
|
667
590
|
if (o !== null) return o;
|
|
668
591
|
let s = String(e), c = String(t);
|
|
669
592
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
670
593
|
}
|
|
671
|
-
function
|
|
672
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
594
|
+
function j(e, t, n = {}) {
|
|
595
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = F(e, t, i, r);
|
|
673
596
|
if (o !== null) return o;
|
|
674
597
|
let s = String(e), c = String(t);
|
|
675
598
|
return s.localeCompare(c, void 0, {
|
|
@@ -677,21 +600,21 @@ function M(e, t, n = {}) {
|
|
|
677
600
|
sensitivity: a ? "variant" : "base"
|
|
678
601
|
});
|
|
679
602
|
}
|
|
680
|
-
function
|
|
681
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
603
|
+
function M(e, t, n = {}) {
|
|
604
|
+
let { desc: r = !1, sortUndefined: i } = n, a = F(e, t, i, r);
|
|
682
605
|
if (a !== null) return a;
|
|
683
606
|
let o = new Date(e).getTime(), s = new Date(t).getTime(), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
684
|
-
return (c || l) && (a =
|
|
607
|
+
return (c || l) && (a = F(c ? void 0 : o, l ? void 0 : s, i, r), a !== null) ? a : o - s;
|
|
685
608
|
}
|
|
686
|
-
function
|
|
687
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
609
|
+
function N(e, t, n = {}) {
|
|
610
|
+
let { desc: r = !1, sortUndefined: i } = n, a = F(e, t, i, r);
|
|
688
611
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
689
612
|
}
|
|
690
|
-
function
|
|
691
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
613
|
+
function P(e, t, n = {}) {
|
|
614
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = F(e, t, i, r);
|
|
692
615
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
693
616
|
}
|
|
694
|
-
function
|
|
617
|
+
function F(e, t, n = "last", r) {
|
|
695
618
|
let i = e == null || e === "", a = t == null || t === "";
|
|
696
619
|
if (i && a) return 0;
|
|
697
620
|
if (!i && !a) return null;
|
|
@@ -708,8 +631,8 @@ function I(e, t, n = "last", r) {
|
|
|
708
631
|
return null;
|
|
709
632
|
}
|
|
710
633
|
//#endregion
|
|
711
|
-
//#region src/state/
|
|
712
|
-
function
|
|
634
|
+
//#region src/state/useSort/useSort.ts
|
|
635
|
+
function I(e, n = []) {
|
|
713
636
|
let r = o(n), [i, c] = s(() => n), l = a(() => {
|
|
714
637
|
let t = i.map((e) => ({
|
|
715
638
|
...e,
|
|
@@ -720,27 +643,27 @@ function L(e, n = []) {
|
|
|
720
643
|
let { type: t, id: i, desc: a = !1, invertSorting: o = !1, pathArray: s } = r, c = v(e, s, i), l = v(n, s, i), u;
|
|
721
644
|
switch (t) {
|
|
722
645
|
case "numeric":
|
|
723
|
-
u =
|
|
646
|
+
u = k(c, l, r);
|
|
724
647
|
break;
|
|
725
648
|
case "alphabetical":
|
|
726
|
-
u =
|
|
649
|
+
u = A(c, l, r);
|
|
727
650
|
break;
|
|
728
651
|
case "alphanumeric":
|
|
729
|
-
u =
|
|
652
|
+
u = j(c, l, r);
|
|
730
653
|
break;
|
|
731
654
|
case "boolean":
|
|
732
|
-
u =
|
|
655
|
+
u = O(c, l, r);
|
|
733
656
|
break;
|
|
734
657
|
case "date":
|
|
735
|
-
u =
|
|
658
|
+
u = M(c, l, r);
|
|
736
659
|
break;
|
|
737
660
|
case "basic":
|
|
738
|
-
u =
|
|
661
|
+
u = N(c, l, r);
|
|
739
662
|
break;
|
|
740
663
|
case "custom":
|
|
741
|
-
u =
|
|
664
|
+
u = P(c, l, r);
|
|
742
665
|
break;
|
|
743
|
-
default: u =
|
|
666
|
+
default: u = N(c, l, r);
|
|
744
667
|
}
|
|
745
668
|
if (u !== 0) return u * (a === o ? 1 : -1);
|
|
746
669
|
}
|
|
@@ -804,8 +727,143 @@ function L(e, n = []) {
|
|
|
804
727
|
};
|
|
805
728
|
}
|
|
806
729
|
//#endregion
|
|
807
|
-
//#region src/ui/
|
|
808
|
-
function
|
|
730
|
+
//#region src/ui/useExpansion/useExpansion.ts
|
|
731
|
+
function L({ items: e = [], field: n, initialExpandedIds: r = [], multiple: i = !1 } = {}) {
|
|
732
|
+
let c = o(r), [l, u] = s(() => new Set(r)), d = t((e) => {
|
|
733
|
+
let t = v(e, n);
|
|
734
|
+
return l.has(t);
|
|
735
|
+
}, [l, n]), f = t((e) => {
|
|
736
|
+
u((t) => {
|
|
737
|
+
let r = v(e, n);
|
|
738
|
+
if (t.has(r)) return t;
|
|
739
|
+
let a = i ? new Set(t) : /* @__PURE__ */ new Set();
|
|
740
|
+
return a.add(r), a;
|
|
741
|
+
});
|
|
742
|
+
}, [n, i]), p = t((e) => {
|
|
743
|
+
u((t) => {
|
|
744
|
+
let r = v(e, n);
|
|
745
|
+
if (!t.has(r)) return t;
|
|
746
|
+
let i = new Set(t);
|
|
747
|
+
return i.delete(r), i;
|
|
748
|
+
});
|
|
749
|
+
}, [n]), m = t((e) => {
|
|
750
|
+
u((t) => {
|
|
751
|
+
let r = v(e, n), a = i ? new Set(t) : /* @__PURE__ */ new Set();
|
|
752
|
+
return t.has(r) ? i && a.delete(r) : a.add(r), a;
|
|
753
|
+
});
|
|
754
|
+
}, [n, i]), h = t(() => {
|
|
755
|
+
if (!i) return;
|
|
756
|
+
let t = e.map((e) => v(e, n));
|
|
757
|
+
u(new Set(t));
|
|
758
|
+
}, [
|
|
759
|
+
e,
|
|
760
|
+
n,
|
|
761
|
+
i
|
|
762
|
+
]), g = t(() => {
|
|
763
|
+
u(/* @__PURE__ */ new Set());
|
|
764
|
+
}, []), _ = t(() => {
|
|
765
|
+
u(new Set(c.current));
|
|
766
|
+
}, []), y = t((e) => {
|
|
767
|
+
let t = e.map((e) => v(e, n));
|
|
768
|
+
u(new Set(t));
|
|
769
|
+
}, [n]), b = a(() => e.filter((e) => l.has(v(e, n))), [
|
|
770
|
+
e,
|
|
771
|
+
n,
|
|
772
|
+
l
|
|
773
|
+
]);
|
|
774
|
+
return {
|
|
775
|
+
expandedIds: [...l],
|
|
776
|
+
expandedItems: b,
|
|
777
|
+
isExpanded: d,
|
|
778
|
+
expand: f,
|
|
779
|
+
collapse: p,
|
|
780
|
+
toggle: m,
|
|
781
|
+
expandAll: h,
|
|
782
|
+
collapseAll: g,
|
|
783
|
+
resetExpansion: _,
|
|
784
|
+
replaceExpansion: y
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/ui/usePin/usePin.ts
|
|
789
|
+
function R({ items: e, field: n, initialPinnedIds: r = [], maxPins: i = 2 ** 53 - 1 }) {
|
|
790
|
+
let c = o(r), [l, u] = s(() => new Set(r)), d = t((e) => {
|
|
791
|
+
u((t) => {
|
|
792
|
+
if (t.size >= i) return t;
|
|
793
|
+
let r = new Set(t), a = v(e, n);
|
|
794
|
+
return r.add(a), r;
|
|
795
|
+
});
|
|
796
|
+
}, [n, i]), f = t((e) => {
|
|
797
|
+
u((t) => {
|
|
798
|
+
let r = new Set(t), i = v(e, n);
|
|
799
|
+
return r.delete(i), r;
|
|
800
|
+
});
|
|
801
|
+
}, [n]), p = t((e) => {
|
|
802
|
+
u((t) => {
|
|
803
|
+
let r = new Set(t), a = v(e, n);
|
|
804
|
+
if (r.has(a)) r.delete(a);
|
|
805
|
+
else {
|
|
806
|
+
if (r.size >= i) return t;
|
|
807
|
+
r.add(a);
|
|
808
|
+
}
|
|
809
|
+
return r;
|
|
810
|
+
});
|
|
811
|
+
}, [n, i]), m = t((e) => {
|
|
812
|
+
let t = v(e, n);
|
|
813
|
+
return l.has(t);
|
|
814
|
+
}, [l, n]), h = t(() => u(/* @__PURE__ */ new Set()), []), g = t(() => u(new Set(c.current)), [c]), _ = t((e) => {
|
|
815
|
+
let t = e.map((e) => v(e, n));
|
|
816
|
+
u(new Set(t.slice(0, i)));
|
|
817
|
+
}, [n, i]), y = t((e) => {
|
|
818
|
+
u((t) => {
|
|
819
|
+
let r = new Set(t), a = e.map((e) => v(e, n));
|
|
820
|
+
for (let e of a) {
|
|
821
|
+
if (r.size >= i && !r.has(e)) break;
|
|
822
|
+
r.add(e);
|
|
823
|
+
}
|
|
824
|
+
return r;
|
|
825
|
+
});
|
|
826
|
+
}, [n, i]), b = t((e) => {
|
|
827
|
+
u((t) => {
|
|
828
|
+
let r = new Set(t);
|
|
829
|
+
return e.map((e) => v(e, n)).forEach((e) => r.delete(e)), r;
|
|
830
|
+
});
|
|
831
|
+
}, [n]), x = a(() => e.filter((e) => {
|
|
832
|
+
let t = v(e, n);
|
|
833
|
+
return l.has(t);
|
|
834
|
+
}), [
|
|
835
|
+
e,
|
|
836
|
+
n,
|
|
837
|
+
l
|
|
838
|
+
]), S = a(() => e.filter((e) => {
|
|
839
|
+
let t = v(e, n);
|
|
840
|
+
return !l.has(t);
|
|
841
|
+
}), [
|
|
842
|
+
e,
|
|
843
|
+
n,
|
|
844
|
+
l
|
|
845
|
+
]);
|
|
846
|
+
return {
|
|
847
|
+
pinnedIds: [...l],
|
|
848
|
+
pinnedItems: x,
|
|
849
|
+
unpinnedItems: S,
|
|
850
|
+
pinnedCount: l.size,
|
|
851
|
+
hasPins: l.size > 0,
|
|
852
|
+
isAtMaxLimit: l.size >= i,
|
|
853
|
+
pin: d,
|
|
854
|
+
unpin: f,
|
|
855
|
+
togglePin: p,
|
|
856
|
+
isPinned: m,
|
|
857
|
+
clearPins: h,
|
|
858
|
+
resetPins: g,
|
|
859
|
+
replacePins: _,
|
|
860
|
+
pinMultiple: y,
|
|
861
|
+
unpinMultiple: b
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
//#endregion
|
|
865
|
+
//#region src/ui/useVisibility/useVisibility.ts
|
|
866
|
+
function z({ items: e, field: n, initialVisibleIds: r = [] }) {
|
|
809
867
|
let i = o(r), [c, l] = s(() => new Set(r)), u = t((e) => {
|
|
810
868
|
let t = v(e, n);
|
|
811
869
|
return c.has(t);
|
|
@@ -874,8 +932,8 @@ function R({ items: e, field: n, initialVisibleIds: r = [] }) {
|
|
|
874
932
|
};
|
|
875
933
|
}
|
|
876
934
|
//#endregion
|
|
877
|
-
//#region src/performance/
|
|
878
|
-
function
|
|
935
|
+
//#region src/performance/useDebounce/useDebounce.ts
|
|
936
|
+
function B(e, n, i = {}) {
|
|
879
937
|
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);
|
|
880
938
|
r(() => {
|
|
881
939
|
f.current = e;
|
|
@@ -904,9 +962,9 @@ function z(e, n, i = {}) {
|
|
|
904
962
|
};
|
|
905
963
|
}
|
|
906
964
|
//#endregion
|
|
907
|
-
//#region src/performance/
|
|
908
|
-
function
|
|
909
|
-
let [i, a] = s(e), { debouncedFunc: o } =
|
|
965
|
+
//#region src/performance/useDebounce/useDebouncedValue.ts
|
|
966
|
+
function V(e, t, n = {}) {
|
|
967
|
+
let [i, a] = s(e), { debouncedFunc: o } = B((e) => {
|
|
910
968
|
a(e);
|
|
911
969
|
}, t, n);
|
|
912
970
|
return r(() => {
|
|
@@ -914,8 +972,8 @@ function B(e, t, n = {}) {
|
|
|
914
972
|
}, [e, o]), i;
|
|
915
973
|
}
|
|
916
974
|
//#endregion
|
|
917
|
-
//#region src/performance/
|
|
918
|
-
function
|
|
975
|
+
//#region src/performance/useThrottle/useThrottle.ts
|
|
976
|
+
function H(e, n, i = {}) {
|
|
919
977
|
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);
|
|
920
978
|
r(() => {
|
|
921
979
|
d.current = e;
|
|
@@ -949,15 +1007,15 @@ function V(e, n, i = {}) {
|
|
|
949
1007
|
};
|
|
950
1008
|
}
|
|
951
1009
|
//#endregion
|
|
952
|
-
//#region src/events/
|
|
953
|
-
var
|
|
1010
|
+
//#region src/events/useKey/constants.ts
|
|
1011
|
+
var U = [
|
|
954
1012
|
"keydown",
|
|
955
1013
|
"keyup",
|
|
956
1014
|
"keypress"
|
|
957
1015
|
];
|
|
958
1016
|
//#endregion
|
|
959
|
-
//#region src/events/
|
|
960
|
-
function
|
|
1017
|
+
//#region src/events/useKey/useKey.ts
|
|
1018
|
+
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 } = {}) {
|
|
961
1019
|
let g = o(t), _ = o(n), v = o(!1);
|
|
962
1020
|
i(() => {
|
|
963
1021
|
g.current = t;
|
|
@@ -966,7 +1024,7 @@ function U(e, t, { enabled: n = !0, preventDefault: a = !0, stopPropagation: s =
|
|
|
966
1024
|
}, [n]), r(() => {
|
|
967
1025
|
let t = h && "current" in h ? h.current : h;
|
|
968
1026
|
if (!t) return;
|
|
969
|
-
let n = e.toLowerCase(), r =
|
|
1027
|
+
let n = e.toLowerCase(), r = U.includes(c) ? c : "keydown", i = l && r !== "keyup";
|
|
970
1028
|
function o() {
|
|
971
1029
|
v.current = !1;
|
|
972
1030
|
}
|
|
@@ -1001,4 +1059,4 @@ function U(e, t, { enabled: n = !0, preventDefault: a = !0, stopPropagation: s =
|
|
|
1001
1059
|
]);
|
|
1002
1060
|
}
|
|
1003
1061
|
//#endregion
|
|
1004
|
-
export { d as FuzzyHighlighter, _ as ModalLayout,
|
|
1062
|
+
export { d as FuzzyHighlighter, _ as ModalLayout, B as useDebounce, V as useDebouncedValue, L as useExpansion, b as useFilter, S as useFuzzySearch, C as useGrouping, W as useKey, g as useModal, h as useModalActions, m as useModalState, w as useMultipleSelection, T as useOrder, E as usePagination, R as usePin, D as useSingleSelection, I as useSort, H as useThrottle, z as useVisibility };
|