@himanshu-sorathiya/react-kit 1.0.13 → 1.0.14
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 +34 -0
- package/dist/index.js +124 -30
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -173,6 +173,30 @@ export type UseModalReturn<TData> = UseModalStateReturn<TData> & UseModalActions
|
|
|
173
173
|
export declare function useModalState<TData = unknown>(): UseModalStateReturn<TData>;
|
|
174
174
|
export declare function useModalActions(): UseModalActionsReturn;
|
|
175
175
|
export declare function useModal<TData = unknown>(): UseModalReturn<TData>;
|
|
176
|
+
export interface UseMultipleSelectionReturn<T> {
|
|
177
|
+
selectedIds: (string | number)[];
|
|
178
|
+
selectedCount: number;
|
|
179
|
+
selectedItems: T[];
|
|
180
|
+
isEmpty: boolean;
|
|
181
|
+
select: (item: string | number | T) => void;
|
|
182
|
+
deselect: (item: string | number | T) => void;
|
|
183
|
+
toggle: (item: string | number | T) => void;
|
|
184
|
+
isSelected: (item: string | number | T) => boolean;
|
|
185
|
+
replaceSelection: (newSelectedItems: (string | number)[] | T[]) => void;
|
|
186
|
+
resetSelection: () => void;
|
|
187
|
+
selectAll: () => void;
|
|
188
|
+
deselectAll: () => void;
|
|
189
|
+
toggleAll: () => void;
|
|
190
|
+
invertSelection: () => void;
|
|
191
|
+
selectMultiple: (newItems: (string | number)[] | T[]) => void;
|
|
192
|
+
deselectMultiple: (itemsToRemove: (string | number)[] | T[]) => void;
|
|
193
|
+
retainOnly: (itemsToRetain: (string | number)[] | T[]) => void;
|
|
194
|
+
}
|
|
195
|
+
export declare function useMultipleSelection<T = unknown>({ items, field, initialSelectedIds, }: {
|
|
196
|
+
items: T[];
|
|
197
|
+
field?: string;
|
|
198
|
+
initialSelectedIds?: (number | string)[];
|
|
199
|
+
}): UseMultipleSelectionReturn<T>;
|
|
176
200
|
export interface UseOrderReturn<T> {
|
|
177
201
|
orderedItems: T[];
|
|
178
202
|
moveUp: (index: number) => void;
|
|
@@ -205,6 +229,16 @@ export interface UsePaginationReturn<T> {
|
|
|
205
229
|
resetPagination: () => void;
|
|
206
230
|
}
|
|
207
231
|
export declare function usePagination<T>(data: T[], initialPageSize: number, initialPageIndex?: number): UsePaginationReturn<T>;
|
|
232
|
+
export interface UseSingleSelectionReturn {
|
|
233
|
+
selectedId: string | number | undefined;
|
|
234
|
+
hasSelection: boolean;
|
|
235
|
+
select: (id: string | number) => void;
|
|
236
|
+
deselect: () => void;
|
|
237
|
+
toggle: (id: string | number) => void;
|
|
238
|
+
isSelected: (id: string | number) => boolean;
|
|
239
|
+
resetSelection: () => void;
|
|
240
|
+
}
|
|
241
|
+
export declare function useSingleSelection(initialSelectedId?: number | string): UseSingleSelectionReturn;
|
|
208
242
|
export type SortType = "numeric" | "alphabetical" | "alphanumeric" | "boolean" | "date" | "basic" | "custom";
|
|
209
243
|
export interface BaseSortOptions {
|
|
210
244
|
desc?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -406,8 +406,88 @@ function w(e, t, { enabled: n = !0, preventDefault: a = !0, stopPropagation: s =
|
|
|
406
406
|
]);
|
|
407
407
|
}
|
|
408
408
|
//#endregion
|
|
409
|
+
//#region src/hooks/useMultipleSelection.ts
|
|
410
|
+
function T({ items: e, field: n, initialSelectedIds: r = [] }) {
|
|
411
|
+
let [i, o] = s(new Set(r)), c = t((e) => {
|
|
412
|
+
o((t) => {
|
|
413
|
+
let r = new Set(t), i = y(e, n);
|
|
414
|
+
return r.add(i), r;
|
|
415
|
+
});
|
|
416
|
+
}, [n]), l = t((e) => {
|
|
417
|
+
o((t) => {
|
|
418
|
+
let r = new Set(t), i = y(e, n);
|
|
419
|
+
return r.delete(i), r;
|
|
420
|
+
});
|
|
421
|
+
}, [n]), u = t((e) => {
|
|
422
|
+
o((t) => {
|
|
423
|
+
let r = new Set(t), i = y(e, n);
|
|
424
|
+
return r.has(i) ? r.delete(i) : r.add(i), r;
|
|
425
|
+
});
|
|
426
|
+
}, [n]), d = t((e) => {
|
|
427
|
+
let t = y(e, n);
|
|
428
|
+
return i.has(t);
|
|
429
|
+
}, [i, n]), f = t((e) => {
|
|
430
|
+
let t = e.map((e) => y(e, n));
|
|
431
|
+
o(new Set(t));
|
|
432
|
+
}, [n]), p = t(() => o(new Set(r)), [r]), m = t(() => {
|
|
433
|
+
let t = e.map((e) => y(e, n));
|
|
434
|
+
o(new Set(t));
|
|
435
|
+
}, [e, n]), h = t(() => {
|
|
436
|
+
o(/* @__PURE__ */ new Set());
|
|
437
|
+
}, []), g = t(() => o((t) => {
|
|
438
|
+
if (t.size === e.length) return /* @__PURE__ */ new Set();
|
|
439
|
+
let r = e.map((e) => y(e, n));
|
|
440
|
+
return new Set(r);
|
|
441
|
+
}), [e, n]), _ = t(() => o((t) => {
|
|
442
|
+
if (t.size === e.length) return /* @__PURE__ */ new Set();
|
|
443
|
+
let r = e.filter((e) => !t.has(y(e, n))).map((e) => y(e, n));
|
|
444
|
+
return new Set(r);
|
|
445
|
+
}), [e, n]), v = t((e) => {
|
|
446
|
+
o((t) => {
|
|
447
|
+
let r = new Set(t);
|
|
448
|
+
return e.map((e) => y(e, n)).forEach((e) => r.add(e)), r;
|
|
449
|
+
});
|
|
450
|
+
}, [n]), b = t((e) => {
|
|
451
|
+
o((t) => {
|
|
452
|
+
let r = new Set(t);
|
|
453
|
+
return e.map((e) => y(e, n)).forEach((e) => r.delete(e)), r;
|
|
454
|
+
});
|
|
455
|
+
}, [n]), x = t((e) => {
|
|
456
|
+
o((t) => {
|
|
457
|
+
let r = /* @__PURE__ */ new Set();
|
|
458
|
+
return e.map((e) => y(e, n)).forEach((e) => t.has(e) && r.add(e)), r;
|
|
459
|
+
});
|
|
460
|
+
}, [n]), S = a(() => e.filter((e) => {
|
|
461
|
+
let t = y(e, n);
|
|
462
|
+
return i.has(t);
|
|
463
|
+
}), [
|
|
464
|
+
e,
|
|
465
|
+
n,
|
|
466
|
+
i
|
|
467
|
+
]);
|
|
468
|
+
return {
|
|
469
|
+
selectedIds: [...i],
|
|
470
|
+
selectedCount: i.size,
|
|
471
|
+
selectedItems: S,
|
|
472
|
+
isEmpty: i.size === 0,
|
|
473
|
+
select: c,
|
|
474
|
+
deselect: l,
|
|
475
|
+
toggle: u,
|
|
476
|
+
isSelected: d,
|
|
477
|
+
replaceSelection: f,
|
|
478
|
+
resetSelection: p,
|
|
479
|
+
selectAll: m,
|
|
480
|
+
deselectAll: h,
|
|
481
|
+
toggleAll: g,
|
|
482
|
+
invertSelection: _,
|
|
483
|
+
selectMultiple: v,
|
|
484
|
+
deselectMultiple: b,
|
|
485
|
+
retainOnly: x
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
//#endregion
|
|
409
489
|
//#region src/hooks/useOrder.ts
|
|
410
|
-
function
|
|
490
|
+
function E(e) {
|
|
411
491
|
let n = o(e), [r, i] = s(e);
|
|
412
492
|
return {
|
|
413
493
|
orderedItems: r,
|
|
@@ -465,7 +545,7 @@ function T(e) {
|
|
|
465
545
|
}
|
|
466
546
|
//#endregion
|
|
467
547
|
//#region src/hooks/usePagination.ts
|
|
468
|
-
function
|
|
548
|
+
function D(e, n, r = 0) {
|
|
469
549
|
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
550
|
return c !== d && l(d), {
|
|
471
551
|
pageItems: a(() => typeof i != "number" || i < 1 ? [] : e.slice(c * i, (c + 1) * i), [
|
|
@@ -520,27 +600,41 @@ function E(e, n, r = 0) {
|
|
|
520
600
|
};
|
|
521
601
|
}
|
|
522
602
|
//#endregion
|
|
603
|
+
//#region src/hooks/useSingleSelection.ts
|
|
604
|
+
function O(e) {
|
|
605
|
+
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]);
|
|
606
|
+
return {
|
|
607
|
+
selectedId: n,
|
|
608
|
+
hasSelection: !!n,
|
|
609
|
+
select: i,
|
|
610
|
+
deselect: a,
|
|
611
|
+
toggle: o,
|
|
612
|
+
isSelected: c,
|
|
613
|
+
resetSelection: l
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
//#endregion
|
|
523
617
|
//#region src/utils/sortUtils.ts
|
|
524
|
-
function
|
|
525
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
618
|
+
function k(e, t, n = {}) {
|
|
619
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = I(e, t, r, i);
|
|
526
620
|
if (a !== null) return a;
|
|
527
621
|
let o = !!e;
|
|
528
622
|
return o === !!t ? 0 : o ? 1 : -1;
|
|
529
623
|
}
|
|
530
|
-
function
|
|
531
|
-
let { sortUndefined: r, desc: i = !1 } = n, a =
|
|
624
|
+
function A(e, t, n = {}) {
|
|
625
|
+
let { sortUndefined: r, desc: i = !1 } = n, a = I(e, t, r, i);
|
|
532
626
|
if (a !== null) return a;
|
|
533
627
|
let o = Number(e), s = Number(t), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
534
|
-
return c || l ?
|
|
628
|
+
return c || l ? I(c ? void 0 : o, l ? void 0 : s, r, i) ?? 0 : o - s;
|
|
535
629
|
}
|
|
536
|
-
function
|
|
537
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
630
|
+
function j(e, t, n = {}) {
|
|
631
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = I(e, t, i, r);
|
|
538
632
|
if (o !== null) return o;
|
|
539
633
|
let s = String(e), c = String(t);
|
|
540
634
|
return s.localeCompare(c, void 0, { sensitivity: a ? "variant" : "base" });
|
|
541
635
|
}
|
|
542
|
-
function
|
|
543
|
-
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o =
|
|
636
|
+
function M(e, t, n = {}) {
|
|
637
|
+
let { desc: r = !1, sortUndefined: i, caseSensitive: a = !1 } = n, o = I(e, t, i, r);
|
|
544
638
|
if (o !== null) return o;
|
|
545
639
|
let s = String(e), c = String(t);
|
|
546
640
|
return s.localeCompare(c, void 0, {
|
|
@@ -548,21 +642,21 @@ function A(e, t, n = {}) {
|
|
|
548
642
|
sensitivity: a ? "variant" : "base"
|
|
549
643
|
});
|
|
550
644
|
}
|
|
551
|
-
function
|
|
552
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
645
|
+
function N(e, t, n = {}) {
|
|
646
|
+
let { desc: r = !1, sortUndefined: i } = n, a = I(e, t, i, r);
|
|
553
647
|
if (a !== null) return a;
|
|
554
648
|
let o = new Date(e).getTime(), s = new Date(t).getTime(), c = Number.isNaN(o), l = Number.isNaN(s);
|
|
555
|
-
return (c || l) && (a =
|
|
649
|
+
return (c || l) && (a = I(c ? void 0 : o, l ? void 0 : s, i, r), a !== null) ? a : o - s;
|
|
556
650
|
}
|
|
557
|
-
function
|
|
558
|
-
let { desc: r = !1, sortUndefined: i } = n, a =
|
|
651
|
+
function P(e, t, n = {}) {
|
|
652
|
+
let { desc: r = !1, sortUndefined: i } = n, a = I(e, t, i, r);
|
|
559
653
|
return a === null ? e < t ? -1 : +(e > t) : a;
|
|
560
654
|
}
|
|
561
|
-
function
|
|
562
|
-
let { desc: r = !1, sortUndefined: i, compare: a } = n, o =
|
|
655
|
+
function F(e, t, n = {}) {
|
|
656
|
+
let { desc: r = !1, sortUndefined: i, compare: a } = n, o = I(e, t, i, r);
|
|
563
657
|
return o === null ? typeof a == "function" ? a(e, t) : e < t ? -1 : +(e > t) : o;
|
|
564
658
|
}
|
|
565
|
-
function
|
|
659
|
+
function I(e, t, n = "last", r) {
|
|
566
660
|
let i = e == null || e === "", a = t == null || t === "";
|
|
567
661
|
if (i && a) return 0;
|
|
568
662
|
if (!i && !a) return null;
|
|
@@ -580,7 +674,7 @@ function P(e, t, n = "last", r) {
|
|
|
580
674
|
}
|
|
581
675
|
//#endregion
|
|
582
676
|
//#region src/hooks/useSort.ts
|
|
583
|
-
function
|
|
677
|
+
function L(e, n = []) {
|
|
584
678
|
let [r, i] = s(n), o = a(() => {
|
|
585
679
|
let t = r.map((e) => ({
|
|
586
680
|
...e,
|
|
@@ -591,27 +685,27 @@ function F(e, n = []) {
|
|
|
591
685
|
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;
|
|
592
686
|
switch (t) {
|
|
593
687
|
case "numeric":
|
|
594
|
-
u =
|
|
688
|
+
u = A(c, l, r);
|
|
595
689
|
break;
|
|
596
690
|
case "alphabetical":
|
|
597
|
-
u =
|
|
691
|
+
u = j(c, l, r);
|
|
598
692
|
break;
|
|
599
693
|
case "alphanumeric":
|
|
600
|
-
u =
|
|
694
|
+
u = M(c, l, r);
|
|
601
695
|
break;
|
|
602
696
|
case "boolean":
|
|
603
|
-
u =
|
|
697
|
+
u = k(c, l, r);
|
|
604
698
|
break;
|
|
605
699
|
case "date":
|
|
606
|
-
u =
|
|
700
|
+
u = N(c, l, r);
|
|
607
701
|
break;
|
|
608
702
|
case "basic":
|
|
609
|
-
u =
|
|
703
|
+
u = P(c, l, r);
|
|
610
704
|
break;
|
|
611
705
|
case "custom":
|
|
612
|
-
u =
|
|
706
|
+
u = F(c, l, r);
|
|
613
707
|
break;
|
|
614
|
-
default: u =
|
|
708
|
+
default: u = P(c, l, r);
|
|
615
709
|
}
|
|
616
710
|
if (u !== 0) return u * (a === o ? 1 : -1);
|
|
617
711
|
}
|
|
@@ -676,7 +770,7 @@ function F(e, n = []) {
|
|
|
676
770
|
}
|
|
677
771
|
//#endregion
|
|
678
772
|
//#region src/hooks/useThrottle.ts
|
|
679
|
-
function
|
|
773
|
+
function R(e, n, i = {}) {
|
|
680
774
|
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);
|
|
681
775
|
r(() => {
|
|
682
776
|
d.current = e;
|
|
@@ -710,4 +804,4 @@ function I(e, n, i = {}) {
|
|
|
710
804
|
};
|
|
711
805
|
}
|
|
712
806
|
//#endregion
|
|
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
|
|
807
|
+
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 useMultipleSelection, E as useOrder, D as usePagination, O as useSingleSelection, L as useSort, R as useThrottle };
|