baaz-custom-components 5.2.1 → 5.2.2
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.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +216 -156
- package/dist/index.mjs +199 -140
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -148,8 +148,8 @@ interface SelectionAction {
|
|
|
148
148
|
icon?: React__default.ReactNode;
|
|
149
149
|
}
|
|
150
150
|
interface GridSelectionProps {
|
|
151
|
-
getSelectedIds: () => RowId[];
|
|
152
151
|
selectionEnabled?: boolean;
|
|
152
|
+
selectedIds?: RowId[];
|
|
153
153
|
onRowSelectionChange?: (id: RowId, rowData: AnyRow, checked: boolean) => void;
|
|
154
154
|
onSelectAllPage?: (pageData: AnyRow[], checked: boolean) => void;
|
|
155
155
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -148,8 +148,8 @@ interface SelectionAction {
|
|
|
148
148
|
icon?: React__default.ReactNode;
|
|
149
149
|
}
|
|
150
150
|
interface GridSelectionProps {
|
|
151
|
-
getSelectedIds: () => RowId[];
|
|
152
151
|
selectionEnabled?: boolean;
|
|
152
|
+
selectedIds?: RowId[];
|
|
153
153
|
onRowSelectionChange?: (id: RowId, rowData: AnyRow, checked: boolean) => void;
|
|
154
154
|
onSelectAllPage?: (pageData: AnyRow[], checked: boolean) => void;
|
|
155
155
|
}
|
package/dist/index.js
CHANGED
|
@@ -1947,7 +1947,7 @@ var CustomBreadcrumb = ({
|
|
|
1947
1947
|
var breadcrumb_default = CustomBreadcrumb;
|
|
1948
1948
|
|
|
1949
1949
|
// src/components/custom/grid/index.tsx
|
|
1950
|
-
var
|
|
1950
|
+
var import_react10 = __toESM(require("react"));
|
|
1951
1951
|
var import_react_grid = require("@svar-ui/react-grid");
|
|
1952
1952
|
|
|
1953
1953
|
// src/utils/exportPdf.ts
|
|
@@ -2039,13 +2039,13 @@ var Filters = ({
|
|
|
2039
2039
|
}
|
|
2040
2040
|
]);
|
|
2041
2041
|
};
|
|
2042
|
-
const updateCondition = (
|
|
2042
|
+
const updateCondition = (id3, next) => {
|
|
2043
2043
|
setConditions(
|
|
2044
|
-
(prev) => prev.map((c) => c.id ===
|
|
2044
|
+
(prev) => prev.map((c) => c.id === id3 ? __spreadValues(__spreadValues({}, c), next) : c)
|
|
2045
2045
|
);
|
|
2046
2046
|
};
|
|
2047
|
-
const deleteCondition = (
|
|
2048
|
-
const updatedConditions = conditions.filter((c) => c.id !==
|
|
2047
|
+
const deleteCondition = (id3) => {
|
|
2048
|
+
const updatedConditions = conditions.filter((c) => c.id !== id3);
|
|
2049
2049
|
setConditions(updatedConditions);
|
|
2050
2050
|
if (updatedConditions.length === 0) {
|
|
2051
2051
|
setFilterMenu(false);
|
|
@@ -2526,32 +2526,62 @@ function GridHeader({
|
|
|
2526
2526
|
var gridHeader_default = import_react6.default.memo(GridHeader);
|
|
2527
2527
|
|
|
2528
2528
|
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2529
|
-
var
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2529
|
+
var import_react8 = __toESM(require("react"));
|
|
2530
|
+
|
|
2531
|
+
// node_modules/@svar-ui/lib-react/dist/index.js
|
|
2532
|
+
var import_react7 = require("react");
|
|
2533
|
+
|
|
2534
|
+
// node_modules/@svar-ui/lib-dom/dist/index.js
|
|
2535
|
+
function getEnv() {
|
|
2536
|
+
return {
|
|
2537
|
+
detect: () => true,
|
|
2538
|
+
addEvent: function(node, event, handler) {
|
|
2539
|
+
node.addEventListener(event, handler);
|
|
2540
|
+
return () => node.removeEventListener(event, handler);
|
|
2541
|
+
},
|
|
2542
|
+
addGlobalEvent: function(event, handler) {
|
|
2543
|
+
document.addEventListener(event, handler);
|
|
2544
|
+
return () => document.removeEventListener(event, handler);
|
|
2545
|
+
},
|
|
2546
|
+
getTopNode: function() {
|
|
2547
|
+
return window.document.body;
|
|
2536
2548
|
}
|
|
2537
|
-
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
var env = getEnv();
|
|
2552
|
+
var id2 = (/* @__PURE__ */ new Date()).valueOf();
|
|
2553
|
+
|
|
2554
|
+
// node_modules/@svar-ui/lib-react/dist/index.js
|
|
2555
|
+
function useWritable(writable2, initialValue, name) {
|
|
2556
|
+
const [state, setState] = (0, import_react7.useState)(() => initialValue);
|
|
2557
|
+
if (!writable2) console.warn(`Writable ${name} is not defined`);
|
|
2538
2558
|
(0, import_react7.useEffect)(() => {
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
setIsSelected(
|
|
2543
|
-
((_a = api.getState().selectedRows) != null ? _a : []).includes(row.id)
|
|
2544
|
-
);
|
|
2545
|
-
}
|
|
2559
|
+
if (!writable2) return;
|
|
2560
|
+
const unsubscribe = writable2.subscribe((newValue) => {
|
|
2561
|
+
setState(() => newValue);
|
|
2546
2562
|
});
|
|
2547
|
-
return
|
|
2548
|
-
}, [
|
|
2563
|
+
return unsubscribe;
|
|
2564
|
+
}, [writable2]);
|
|
2565
|
+
return state;
|
|
2566
|
+
}
|
|
2567
|
+
function useStore(store, name) {
|
|
2568
|
+
const s = store.getState();
|
|
2569
|
+
const r = store.getReactiveState();
|
|
2570
|
+
return useWritable(r[name], s[name], name);
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2574
|
+
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2575
|
+
var CheckboxCell = ({ row, api, column }) => {
|
|
2576
|
+
console.log("CheckboxCell rendered");
|
|
2577
|
+
const selectedRows = useStore(api, "selectedRows");
|
|
2578
|
+
const isSelected = selectedRows.includes(row.id);
|
|
2549
2579
|
const handleChange = (e) => {
|
|
2550
2580
|
var _a, _b;
|
|
2551
2581
|
e.stopPropagation();
|
|
2552
|
-
const
|
|
2553
|
-
api.exec("select-row", { id: row.id, mode:
|
|
2554
|
-
(_b = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.onSelectionChange) == null ? void 0 : _b.call(_a, row.id, row,
|
|
2582
|
+
const isChecked = e.target.checked;
|
|
2583
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2584
|
+
(_b = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.onSelectionChange) == null ? void 0 : _b.call(_a, row.id, row, isChecked);
|
|
2555
2585
|
};
|
|
2556
2586
|
return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
|
|
2557
2587
|
"div",
|
|
@@ -2571,37 +2601,57 @@ var CheckboxCell = ({ row, api, column }) => {
|
|
|
2571
2601
|
}
|
|
2572
2602
|
);
|
|
2573
2603
|
};
|
|
2574
|
-
var checkBoxCell_default =
|
|
2604
|
+
var checkBoxCell_default = import_react8.default.memo(CheckboxCell, (prev, next) => {
|
|
2605
|
+
return prev.row.id !== next.row.id;
|
|
2606
|
+
});
|
|
2575
2607
|
|
|
2576
2608
|
// src/components/custom/grid/checkboxCell/headerCheckBox.tsx
|
|
2577
|
-
var
|
|
2609
|
+
var import_react9 = __toESM(require("react"));
|
|
2578
2610
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
2579
2611
|
var HeaderCheckbox = ({ api, column }) => {
|
|
2580
|
-
var _a
|
|
2581
|
-
const checkboxRef = (0,
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
const
|
|
2585
|
-
|
|
2612
|
+
var _a;
|
|
2613
|
+
const checkboxRef = (0, import_react9.useRef)(null);
|
|
2614
|
+
const computeState = () => {
|
|
2615
|
+
var _a2, _b, _c;
|
|
2616
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2617
|
+
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2618
|
+
const selectedOnPage = pageData.filter(
|
|
2619
|
+
(r) => selectedRows.includes(r.id)
|
|
2620
|
+
).length;
|
|
2621
|
+
return {
|
|
2622
|
+
allSelected: pageData.length > 0 && selectedOnPage === pageData.length,
|
|
2623
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < pageData.length
|
|
2624
|
+
};
|
|
2625
|
+
};
|
|
2626
|
+
const [, forceUpdate] = (0, import_react9.useReducer)((x) => x + 1, 0);
|
|
2627
|
+
(0, import_react9.useEffect)(() => {
|
|
2628
|
+
const unsub = api.on("select-row", () => {
|
|
2629
|
+
forceUpdate();
|
|
2630
|
+
});
|
|
2631
|
+
return () => {
|
|
2632
|
+
if (typeof unsub === "function") unsub();
|
|
2633
|
+
};
|
|
2586
2634
|
}, [api]);
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
(
|
|
2591
|
-
).
|
|
2592
|
-
const
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2635
|
+
(0, import_react9.useEffect)(() => {
|
|
2636
|
+
var _a2;
|
|
2637
|
+
(_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.clearToken;
|
|
2638
|
+
forceUpdate();
|
|
2639
|
+
}, [(_a = column == null ? void 0 : column.config) == null ? void 0 : _a.clearToken]);
|
|
2640
|
+
const state = computeState();
|
|
2641
|
+
(0, import_react9.useEffect)(() => {
|
|
2642
|
+
if (checkboxRef.current) {
|
|
2643
|
+
checkboxRef.current.indeterminate = state.someSelected;
|
|
2644
|
+
}
|
|
2645
|
+
}, [state.someSelected]);
|
|
2597
2646
|
const handleChange = (e) => {
|
|
2598
|
-
var _a2,
|
|
2647
|
+
var _a2, _b, _c, _d;
|
|
2599
2648
|
e.stopPropagation();
|
|
2600
|
-
const
|
|
2601
|
-
pageData.
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2649
|
+
const isChecked = e.target.checked;
|
|
2650
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2651
|
+
pageData.forEach((row) => {
|
|
2652
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2653
|
+
});
|
|
2654
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, pageData, isChecked);
|
|
2605
2655
|
};
|
|
2606
2656
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2607
2657
|
"div",
|
|
@@ -2614,7 +2664,7 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2614
2664
|
{
|
|
2615
2665
|
ref: checkboxRef,
|
|
2616
2666
|
type: "checkbox",
|
|
2617
|
-
checked: allSelected,
|
|
2667
|
+
checked: state.allSelected,
|
|
2618
2668
|
onChange: handleChange,
|
|
2619
2669
|
className: "w-4 h-4 rounded border border-border bg-background accent-primary cursor-pointer focus:outline-none focus:ring-1 focus:ring-primary"
|
|
2620
2670
|
}
|
|
@@ -2622,21 +2672,27 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2622
2672
|
}
|
|
2623
2673
|
);
|
|
2624
2674
|
};
|
|
2625
|
-
var headerCheckBox_default =
|
|
2675
|
+
var headerCheckBox_default = import_react9.default.memo(HeaderCheckbox);
|
|
2626
2676
|
|
|
2627
2677
|
// src/components/custom/grid/utils/buildCheckboxColumn.tsx
|
|
2628
2678
|
function buildCheckboxColumn({
|
|
2629
2679
|
getPageData,
|
|
2630
2680
|
onSelectionChange,
|
|
2631
|
-
onSelectAllPage
|
|
2681
|
+
onSelectAllPage,
|
|
2682
|
+
clearToken
|
|
2632
2683
|
}) {
|
|
2633
|
-
const
|
|
2684
|
+
const configRef = {
|
|
2685
|
+
getPageData,
|
|
2686
|
+
onSelectionChange,
|
|
2687
|
+
onSelectAllPage,
|
|
2688
|
+
clearToken
|
|
2689
|
+
};
|
|
2634
2690
|
return {
|
|
2635
2691
|
id: "__selection__",
|
|
2636
2692
|
width: 58,
|
|
2637
2693
|
sortable: false,
|
|
2638
2694
|
resize: false,
|
|
2639
|
-
config,
|
|
2695
|
+
config: configRef,
|
|
2640
2696
|
header: { cell: headerCheckBox_default },
|
|
2641
2697
|
cell: checkBoxCell_default
|
|
2642
2698
|
};
|
|
@@ -2644,7 +2700,7 @@ function buildCheckboxColumn({
|
|
|
2644
2700
|
|
|
2645
2701
|
// src/components/custom/grid/index.tsx
|
|
2646
2702
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2647
|
-
var Grid = (0,
|
|
2703
|
+
var Grid = (0, import_react10.forwardRef)(
|
|
2648
2704
|
(_a, ref) => {
|
|
2649
2705
|
var _b = _a, {
|
|
2650
2706
|
data,
|
|
@@ -2662,9 +2718,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2662
2718
|
children,
|
|
2663
2719
|
onFocusCell = () => false,
|
|
2664
2720
|
selectionEnabled = false,
|
|
2665
|
-
|
|
2721
|
+
selectedIds = [],
|
|
2666
2722
|
onRowSelectionChange,
|
|
2667
2723
|
onSelectAllPage,
|
|
2724
|
+
selectedCount,
|
|
2725
|
+
selectedData,
|
|
2668
2726
|
selectionActions,
|
|
2669
2727
|
onSelectionAction,
|
|
2670
2728
|
onClearSelection
|
|
@@ -2684,139 +2742,140 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2684
2742
|
"children",
|
|
2685
2743
|
"onFocusCell",
|
|
2686
2744
|
"selectionEnabled",
|
|
2687
|
-
"
|
|
2745
|
+
"selectedIds",
|
|
2688
2746
|
"onRowSelectionChange",
|
|
2689
2747
|
"onSelectAllPage",
|
|
2748
|
+
"selectedCount",
|
|
2749
|
+
"selectedData",
|
|
2690
2750
|
"selectionActions",
|
|
2691
2751
|
"onSelectionAction",
|
|
2692
2752
|
"onClearSelection"
|
|
2693
2753
|
]);
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const
|
|
2697
|
-
const
|
|
2698
|
-
(0,
|
|
2754
|
+
var _a2;
|
|
2755
|
+
console.log("Grid rendered");
|
|
2756
|
+
const apiRef = (0, import_react10.useRef)(null);
|
|
2757
|
+
const containerRef = (0, import_react10.useRef)(null);
|
|
2758
|
+
const dataRef = (0, import_react10.useRef)(data);
|
|
2759
|
+
(0, import_react10.useEffect)(() => {
|
|
2699
2760
|
dataRef.current = data;
|
|
2700
2761
|
}, [data]);
|
|
2701
|
-
const onRowSelectionChangeRef = (0,
|
|
2702
|
-
(0,
|
|
2762
|
+
const onRowSelectionChangeRef = (0, import_react10.useRef)(onRowSelectionChange);
|
|
2763
|
+
(0, import_react10.useEffect)(() => {
|
|
2703
2764
|
onRowSelectionChangeRef.current = onRowSelectionChange;
|
|
2704
2765
|
}, [onRowSelectionChange]);
|
|
2705
|
-
const onSelectAllPageRef = (0,
|
|
2706
|
-
(0,
|
|
2766
|
+
const onSelectAllPageRef = (0, import_react10.useRef)(onSelectAllPage);
|
|
2767
|
+
(0, import_react10.useEffect)(() => {
|
|
2707
2768
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2708
2769
|
}, [onSelectAllPage]);
|
|
2709
|
-
(0,
|
|
2710
|
-
const
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2770
|
+
(0, import_react10.useImperativeHandle)(ref, () => apiRef.current, []);
|
|
2771
|
+
const clearTokenRef = (0, import_react10.useRef)(0);
|
|
2772
|
+
const prevSelectedCountRef = (0, import_react10.useRef)(selectedCount != null ? selectedCount : 0);
|
|
2773
|
+
if (((_a2 = prevSelectedCountRef.current) != null ? _a2 : 0) > 0 && (selectedCount != null ? selectedCount : 0) === 0) {
|
|
2774
|
+
clearTokenRef.current += 1;
|
|
2775
|
+
}
|
|
2776
|
+
prevSelectedCountRef.current = selectedCount != null ? selectedCount : 0;
|
|
2777
|
+
const resolvedColumns = (0, import_react10.useMemo)(() => {
|
|
2778
|
+
if (!selectionEnabled) return columns;
|
|
2779
|
+
if (columns.length === 0) return columns;
|
|
2717
2780
|
const checkboxCol = buildCheckboxColumn({
|
|
2718
2781
|
getPageData: () => {
|
|
2719
|
-
var
|
|
2720
|
-
return (
|
|
2782
|
+
var _a3;
|
|
2783
|
+
return (_a3 = dataRef.current) != null ? _a3 : [];
|
|
2721
2784
|
},
|
|
2722
|
-
onSelectionChange: (
|
|
2723
|
-
var
|
|
2724
|
-
(
|
|
2785
|
+
onSelectionChange: (id3, rowData, checked) => {
|
|
2786
|
+
var _a3;
|
|
2787
|
+
(_a3 = onRowSelectionChangeRef.current) == null ? void 0 : _a3.call(onRowSelectionChangeRef, id3, rowData, checked);
|
|
2725
2788
|
},
|
|
2726
2789
|
onSelectAllPage: (pageData, checked) => {
|
|
2727
|
-
var
|
|
2728
|
-
(
|
|
2729
|
-
}
|
|
2790
|
+
var _a3;
|
|
2791
|
+
(_a3 = onSelectAllPageRef.current) == null ? void 0 : _a3.call(onSelectAllPageRef, pageData, checked);
|
|
2792
|
+
},
|
|
2793
|
+
clearToken: clearTokenRef.current
|
|
2730
2794
|
});
|
|
2731
2795
|
return [checkboxCol, ...columns];
|
|
2732
|
-
}, [selectionEnabled, columns]);
|
|
2733
|
-
const resizeColumns = (0,
|
|
2796
|
+
}, [selectionEnabled, columns, clearTokenRef.current]);
|
|
2797
|
+
const resizeColumns = (0, import_react10.useCallback)(() => {
|
|
2734
2798
|
const api = apiRef.current;
|
|
2735
2799
|
const container = containerRef.current;
|
|
2736
2800
|
if (!api || !container) return;
|
|
2737
2801
|
const gridWidth = container.clientWidth;
|
|
2738
|
-
const
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2802
|
+
const isFixedColumn = (col) => col.id === "__selection__";
|
|
2803
|
+
const resizableColumns = resolvedColumns.filter(
|
|
2804
|
+
(col) => !isFixedColumn(col)
|
|
2805
|
+
);
|
|
2806
|
+
const fixedColumns = resolvedColumns.filter(
|
|
2807
|
+
(col) => isFixedColumn(col)
|
|
2808
|
+
);
|
|
2809
|
+
const totalFixedWidth = fixedColumns.reduce((sum, col) => {
|
|
2810
|
+
var _a3, _b2;
|
|
2811
|
+
const column = api.getColumn(col.id);
|
|
2812
|
+
const width = (_b2 = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : col.width) != null ? _b2 : 0;
|
|
2813
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2745
2814
|
}, 0);
|
|
2746
|
-
const
|
|
2815
|
+
const availableWidth = Math.max(gridWidth - totalFixedWidth, 0);
|
|
2747
2816
|
if (data && data.length > 0) {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
);
|
|
2751
|
-
const
|
|
2752
|
-
var
|
|
2753
|
-
const
|
|
2754
|
-
|
|
2817
|
+
resizableColumns.forEach((col) => {
|
|
2818
|
+
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2819
|
+
});
|
|
2820
|
+
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2821
|
+
var _a3;
|
|
2822
|
+
const column = api.getColumn(col.id);
|
|
2823
|
+
const width = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2824
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2755
2825
|
}, 0);
|
|
2756
|
-
if (
|
|
2757
|
-
const extra = (
|
|
2758
|
-
|
|
2759
|
-
var
|
|
2760
|
-
const
|
|
2761
|
-
|
|
2762
|
-
|
|
2826
|
+
if (totalAutoWidth < availableWidth && resizableColumns.length > 0) {
|
|
2827
|
+
const extra = (availableWidth - totalAutoWidth) / resizableColumns.length;
|
|
2828
|
+
resizableColumns.forEach((col) => {
|
|
2829
|
+
var _a3;
|
|
2830
|
+
const column = api.getColumn(col.id);
|
|
2831
|
+
const currentWidth = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2832
|
+
if (!isNaN(currentWidth)) {
|
|
2833
|
+
api.exec("resize-column", {
|
|
2834
|
+
id: col.id,
|
|
2835
|
+
width: currentWidth + extra
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2763
2838
|
});
|
|
2764
2839
|
}
|
|
2765
2840
|
} else {
|
|
2766
|
-
const
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2841
|
+
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2842
|
+
resizableColumns.forEach((col) => {
|
|
2843
|
+
api.exec("resize-column", {
|
|
2844
|
+
id: col.id,
|
|
2845
|
+
width: equalWidth
|
|
2846
|
+
});
|
|
2847
|
+
});
|
|
2770
2848
|
}
|
|
2771
2849
|
}, [resolvedColumns, data]);
|
|
2772
|
-
|
|
2850
|
+
(0, import_react10.useEffect)(() => {
|
|
2851
|
+
if (!containerRef.current) return;
|
|
2852
|
+
const observer = new ResizeObserver(() => resizeColumns());
|
|
2853
|
+
observer.observe(containerRef.current);
|
|
2854
|
+
return () => observer.disconnect();
|
|
2855
|
+
}, [resizeColumns]);
|
|
2856
|
+
const init = (0, import_react10.useCallback)(
|
|
2773
2857
|
(api) => {
|
|
2774
2858
|
apiRef.current = api;
|
|
2775
2859
|
resizeColumns();
|
|
2776
2860
|
api.intercept("focus-cell", onFocusCell);
|
|
2777
|
-
if (selectionEnabled) {
|
|
2778
|
-
api.on("select-row", () => {
|
|
2779
|
-
var _a2;
|
|
2780
|
-
setInternalSelectedCount(
|
|
2781
|
-
((_a2 = api.getState().selectedRows) != null ? _a2 : []).length
|
|
2782
|
-
);
|
|
2783
|
-
});
|
|
2784
|
-
}
|
|
2785
2861
|
},
|
|
2786
|
-
[resizeColumns, onFocusCell
|
|
2862
|
+
[resizeColumns, onFocusCell]
|
|
2787
2863
|
);
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
const
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
(0, import_react9.useEffect)(() => {
|
|
2795
|
-
if (!selectionEnabled || !getSelectedIds || !apiRef.current) return;
|
|
2796
|
-
const pageIds = new Set((data != null ? data : []).map((r) => r.id));
|
|
2797
|
-
const toRestore = getSelectedIds().filter((id) => pageIds.has(id));
|
|
2798
|
-
toRestore.forEach(
|
|
2799
|
-
(id) => apiRef.current.exec("select-row", { id, mode: true })
|
|
2800
|
-
);
|
|
2801
|
-
}, [data, selectionEnabled, getSelectedIds]);
|
|
2802
|
-
const handleClearSelection = (0, import_react9.useCallback)(() => {
|
|
2803
|
-
var _a2;
|
|
2804
|
-
const api = apiRef.current;
|
|
2805
|
-
if (!api) return;
|
|
2806
|
-
const ids = [...(_a2 = api.getState().selectedRows) != null ? _a2 : []];
|
|
2807
|
-
ids.forEach((id) => api.exec("select-row", { id, mode: false }));
|
|
2808
|
-
onClearSelection == null ? void 0 : onClearSelection();
|
|
2809
|
-
}, [onClearSelection]);
|
|
2810
|
-
const handleExportPdf = (0, import_react9.useCallback)(() => {
|
|
2864
|
+
const getSelectedData = () => {
|
|
2865
|
+
var _a3, _b2;
|
|
2866
|
+
const selected = (_b2 = (_a3 = apiRef.current) == null ? void 0 : _a3.getState().selectedRows) != null ? _b2 : [];
|
|
2867
|
+
return data.filter((row) => selected.includes(row.id));
|
|
2868
|
+
};
|
|
2869
|
+
const handleExportPdf = (0, import_react10.useCallback)(() => {
|
|
2811
2870
|
const selected = getSelectedData();
|
|
2812
2871
|
if (selected.length) exportPdf(selected, fileName);
|
|
2813
2872
|
else onExportPdf == null ? void 0 : onExportPdf();
|
|
2814
|
-
}, [
|
|
2815
|
-
const handleExportExcel = (0,
|
|
2873
|
+
}, [data, fileName, onExportPdf]);
|
|
2874
|
+
const handleExportExcel = (0, import_react10.useCallback)(() => {
|
|
2816
2875
|
const selected = getSelectedData();
|
|
2817
2876
|
if (selected.length) exportExcel(selected, fileName);
|
|
2818
2877
|
else onExportExcel == null ? void 0 : onExportExcel();
|
|
2819
|
-
}, [
|
|
2878
|
+
}, [data, fileName, onExportExcel]);
|
|
2820
2879
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "w-full h-full flex flex-col overflow-hidden", children: [
|
|
2821
2880
|
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2822
2881
|
gridHeader_default,
|
|
@@ -2831,11 +2890,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2831
2890
|
filterList: rest.filterList,
|
|
2832
2891
|
onFilterChange,
|
|
2833
2892
|
initialFilters,
|
|
2834
|
-
selectedCount
|
|
2835
|
-
selectedData
|
|
2893
|
+
selectedCount,
|
|
2894
|
+
selectedData,
|
|
2836
2895
|
selectionActions,
|
|
2837
2896
|
onSelectionAction,
|
|
2838
|
-
onClearSelection
|
|
2897
|
+
onClearSelection,
|
|
2839
2898
|
children
|
|
2840
2899
|
}
|
|
2841
2900
|
),
|
|
@@ -2850,6 +2909,7 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2850
2909
|
data,
|
|
2851
2910
|
columns: resolvedColumns,
|
|
2852
2911
|
init,
|
|
2912
|
+
selectedRows: selectionEnabled ? selectedIds : void 0,
|
|
2853
2913
|
select: selectionEnabled ? false : rest.select
|
|
2854
2914
|
})
|
|
2855
2915
|
) }) })
|
|
@@ -2858,11 +2918,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2858
2918
|
] });
|
|
2859
2919
|
}
|
|
2860
2920
|
);
|
|
2861
|
-
var grid_default =
|
|
2921
|
+
var grid_default = import_react10.default.memo(Grid);
|
|
2862
2922
|
|
|
2863
2923
|
// src/components/custom/grid/sortableHeaderCell.tsx
|
|
2864
2924
|
var import_lucide_react15 = require("lucide-react");
|
|
2865
|
-
var
|
|
2925
|
+
var import_react11 = __toESM(require("react"));
|
|
2866
2926
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
2867
2927
|
var SortableHeaderCell = ({ cell, sortKey, sortOrder, onSortChange }) => {
|
|
2868
2928
|
if (!(cell == null ? void 0 : cell.id)) return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { children: cell == null ? void 0 : cell.text });
|
|
@@ -2892,7 +2952,7 @@ var SortableHeaderCell = ({ cell, sortKey, sortOrder, onSortChange }) => {
|
|
|
2892
2952
|
}
|
|
2893
2953
|
);
|
|
2894
2954
|
};
|
|
2895
|
-
var sortableHeaderCell_default =
|
|
2955
|
+
var sortableHeaderCell_default = import_react11.default.memo(SortableHeaderCell, (prev, next) => {
|
|
2896
2956
|
var _a, _b, _c, _d;
|
|
2897
2957
|
if (((_a = prev.cell) == null ? void 0 : _a.id) !== ((_b = next.cell) == null ? void 0 : _b.id)) return false;
|
|
2898
2958
|
if (((_c = prev.cell) == null ? void 0 : _c.text) !== ((_d = next.cell) == null ? void 0 : _d.text)) return false;
|
|
@@ -3019,7 +3079,7 @@ var pagination_default = Pagination;
|
|
|
3019
3079
|
|
|
3020
3080
|
// src/components/custom/toolbar/index.tsx
|
|
3021
3081
|
var import_lucide_react17 = require("lucide-react");
|
|
3022
|
-
var
|
|
3082
|
+
var import_react12 = require("react");
|
|
3023
3083
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
3024
3084
|
var SlideToolbar = ({
|
|
3025
3085
|
items,
|
|
@@ -3032,9 +3092,9 @@ var SlideToolbar = ({
|
|
|
3032
3092
|
className = ""
|
|
3033
3093
|
}) => {
|
|
3034
3094
|
const resolvedItems = items != null ? items : children ? void 0 : [];
|
|
3035
|
-
const [open, setOpen] = (0,
|
|
3036
|
-
const panelRef = (0,
|
|
3037
|
-
(0,
|
|
3095
|
+
const [open, setOpen] = (0, import_react12.useState)(false);
|
|
3096
|
+
const panelRef = (0, import_react12.useRef)(null);
|
|
3097
|
+
(0, import_react12.useEffect)(() => {
|
|
3038
3098
|
if (!open || !closeOnBackdrop) return;
|
|
3039
3099
|
const handlePointerDown = (e) => {
|
|
3040
3100
|
if (panelRef.current && !panelRef.current.contains(e.target)) {
|
package/dist/index.mjs
CHANGED
|
@@ -1911,12 +1911,11 @@ var breadcrumb_default = CustomBreadcrumb;
|
|
|
1911
1911
|
// src/components/custom/grid/index.tsx
|
|
1912
1912
|
import React6, {
|
|
1913
1913
|
useCallback as useCallback2,
|
|
1914
|
-
useRef as
|
|
1914
|
+
useRef as useRef5,
|
|
1915
1915
|
useImperativeHandle,
|
|
1916
1916
|
forwardRef,
|
|
1917
1917
|
useEffect as useEffect9,
|
|
1918
|
-
useMemo as useMemo4
|
|
1919
|
-
useState as useState9
|
|
1918
|
+
useMemo as useMemo4
|
|
1920
1919
|
} from "react";
|
|
1921
1920
|
import { Grid as SvarGrid, WillowDark } from "@svar-ui/react-grid";
|
|
1922
1921
|
|
|
@@ -2009,13 +2008,13 @@ var Filters = ({
|
|
|
2009
2008
|
}
|
|
2010
2009
|
]);
|
|
2011
2010
|
};
|
|
2012
|
-
const updateCondition = (
|
|
2011
|
+
const updateCondition = (id3, next) => {
|
|
2013
2012
|
setConditions(
|
|
2014
|
-
(prev) => prev.map((c) => c.id ===
|
|
2013
|
+
(prev) => prev.map((c) => c.id === id3 ? __spreadValues(__spreadValues({}, c), next) : c)
|
|
2015
2014
|
);
|
|
2016
2015
|
};
|
|
2017
|
-
const deleteCondition = (
|
|
2018
|
-
const updatedConditions = conditions.filter((c) => c.id !==
|
|
2016
|
+
const deleteCondition = (id3) => {
|
|
2017
|
+
const updatedConditions = conditions.filter((c) => c.id !== id3);
|
|
2019
2018
|
setConditions(updatedConditions);
|
|
2020
2019
|
if (updatedConditions.length === 0) {
|
|
2021
2020
|
setFilterMenu(false);
|
|
@@ -2496,32 +2495,62 @@ function GridHeader({
|
|
|
2496
2495
|
var gridHeader_default = React3.memo(GridHeader);
|
|
2497
2496
|
|
|
2498
2497
|
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2499
|
-
import React4
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2498
|
+
import React4 from "react";
|
|
2499
|
+
|
|
2500
|
+
// node_modules/@svar-ui/lib-react/dist/index.js
|
|
2501
|
+
import { useState as useState8, useRef as useRef3, useEffect as useEffect7 } from "react";
|
|
2502
|
+
|
|
2503
|
+
// node_modules/@svar-ui/lib-dom/dist/index.js
|
|
2504
|
+
function getEnv() {
|
|
2505
|
+
return {
|
|
2506
|
+
detect: () => true,
|
|
2507
|
+
addEvent: function(node, event, handler) {
|
|
2508
|
+
node.addEventListener(event, handler);
|
|
2509
|
+
return () => node.removeEventListener(event, handler);
|
|
2510
|
+
},
|
|
2511
|
+
addGlobalEvent: function(event, handler) {
|
|
2512
|
+
document.addEventListener(event, handler);
|
|
2513
|
+
return () => document.removeEventListener(event, handler);
|
|
2514
|
+
},
|
|
2515
|
+
getTopNode: function() {
|
|
2516
|
+
return window.document.body;
|
|
2506
2517
|
}
|
|
2507
|
-
|
|
2518
|
+
};
|
|
2519
|
+
}
|
|
2520
|
+
var env = getEnv();
|
|
2521
|
+
var id2 = (/* @__PURE__ */ new Date()).valueOf();
|
|
2522
|
+
|
|
2523
|
+
// node_modules/@svar-ui/lib-react/dist/index.js
|
|
2524
|
+
function useWritable(writable2, initialValue, name) {
|
|
2525
|
+
const [state, setState] = useState8(() => initialValue);
|
|
2526
|
+
if (!writable2) console.warn(`Writable ${name} is not defined`);
|
|
2508
2527
|
useEffect7(() => {
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
setIsSelected(
|
|
2513
|
-
((_a = api.getState().selectedRows) != null ? _a : []).includes(row.id)
|
|
2514
|
-
);
|
|
2515
|
-
}
|
|
2528
|
+
if (!writable2) return;
|
|
2529
|
+
const unsubscribe = writable2.subscribe((newValue) => {
|
|
2530
|
+
setState(() => newValue);
|
|
2516
2531
|
});
|
|
2517
|
-
return
|
|
2518
|
-
}, [
|
|
2532
|
+
return unsubscribe;
|
|
2533
|
+
}, [writable2]);
|
|
2534
|
+
return state;
|
|
2535
|
+
}
|
|
2536
|
+
function useStore(store, name) {
|
|
2537
|
+
const s = store.getState();
|
|
2538
|
+
const r = store.getReactiveState();
|
|
2539
|
+
return useWritable(r[name], s[name], name);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2543
|
+
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
2544
|
+
var CheckboxCell = ({ row, api, column }) => {
|
|
2545
|
+
console.log("CheckboxCell rendered");
|
|
2546
|
+
const selectedRows = useStore(api, "selectedRows");
|
|
2547
|
+
const isSelected = selectedRows.includes(row.id);
|
|
2519
2548
|
const handleChange = (e) => {
|
|
2520
2549
|
var _a, _b;
|
|
2521
2550
|
e.stopPropagation();
|
|
2522
|
-
const
|
|
2523
|
-
api.exec("select-row", { id: row.id, mode:
|
|
2524
|
-
(_b = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.onSelectionChange) == null ? void 0 : _b.call(_a, row.id, row,
|
|
2551
|
+
const isChecked = e.target.checked;
|
|
2552
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2553
|
+
(_b = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.onSelectionChange) == null ? void 0 : _b.call(_a, row.id, row, isChecked);
|
|
2525
2554
|
};
|
|
2526
2555
|
return /* @__PURE__ */ jsx26(
|
|
2527
2556
|
"div",
|
|
@@ -2541,37 +2570,57 @@ var CheckboxCell = ({ row, api, column }) => {
|
|
|
2541
2570
|
}
|
|
2542
2571
|
);
|
|
2543
2572
|
};
|
|
2544
|
-
var checkBoxCell_default = React4.memo(CheckboxCell)
|
|
2573
|
+
var checkBoxCell_default = React4.memo(CheckboxCell, (prev, next) => {
|
|
2574
|
+
return prev.row.id !== next.row.id;
|
|
2575
|
+
});
|
|
2545
2576
|
|
|
2546
2577
|
// src/components/custom/grid/checkboxCell/headerCheckBox.tsx
|
|
2547
|
-
import React5, { useEffect as useEffect8, useRef as
|
|
2578
|
+
import React5, { useEffect as useEffect8, useRef as useRef4, useReducer } from "react";
|
|
2548
2579
|
import { jsx as jsx27 } from "react/jsx-runtime";
|
|
2549
2580
|
var HeaderCheckbox = ({ api, column }) => {
|
|
2550
|
-
var _a
|
|
2551
|
-
const checkboxRef =
|
|
2581
|
+
var _a;
|
|
2582
|
+
const checkboxRef = useRef4(null);
|
|
2583
|
+
const computeState = () => {
|
|
2584
|
+
var _a2, _b, _c;
|
|
2585
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2586
|
+
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2587
|
+
const selectedOnPage = pageData.filter(
|
|
2588
|
+
(r) => selectedRows.includes(r.id)
|
|
2589
|
+
).length;
|
|
2590
|
+
return {
|
|
2591
|
+
allSelected: pageData.length > 0 && selectedOnPage === pageData.length,
|
|
2592
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < pageData.length
|
|
2593
|
+
};
|
|
2594
|
+
};
|
|
2552
2595
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2553
2596
|
useEffect8(() => {
|
|
2554
|
-
const unsub = api.on("select-row", () =>
|
|
2555
|
-
|
|
2597
|
+
const unsub = api.on("select-row", () => {
|
|
2598
|
+
forceUpdate();
|
|
2599
|
+
});
|
|
2600
|
+
return () => {
|
|
2601
|
+
if (typeof unsub === "function") unsub();
|
|
2602
|
+
};
|
|
2556
2603
|
}, [api]);
|
|
2557
|
-
const pageData = (_b = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.getPageData()) != null ? _b : [];
|
|
2558
|
-
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2559
|
-
const selectedOnPage = pageData.filter(
|
|
2560
|
-
(r) => selectedRows.includes(r.id)
|
|
2561
|
-
).length;
|
|
2562
|
-
const allSelected = pageData.length > 0 && selectedOnPage === pageData.length;
|
|
2563
|
-
const someSelected = selectedOnPage > 0 && selectedOnPage < pageData.length;
|
|
2564
2604
|
useEffect8(() => {
|
|
2565
|
-
|
|
2566
|
-
|
|
2605
|
+
var _a2;
|
|
2606
|
+
(_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.clearToken;
|
|
2607
|
+
forceUpdate();
|
|
2608
|
+
}, [(_a = column == null ? void 0 : column.config) == null ? void 0 : _a.clearToken]);
|
|
2609
|
+
const state = computeState();
|
|
2610
|
+
useEffect8(() => {
|
|
2611
|
+
if (checkboxRef.current) {
|
|
2612
|
+
checkboxRef.current.indeterminate = state.someSelected;
|
|
2613
|
+
}
|
|
2614
|
+
}, [state.someSelected]);
|
|
2567
2615
|
const handleChange = (e) => {
|
|
2568
|
-
var _a2,
|
|
2616
|
+
var _a2, _b, _c, _d;
|
|
2569
2617
|
e.stopPropagation();
|
|
2570
|
-
const
|
|
2571
|
-
pageData.
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2618
|
+
const isChecked = e.target.checked;
|
|
2619
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2620
|
+
pageData.forEach((row) => {
|
|
2621
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2622
|
+
});
|
|
2623
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, pageData, isChecked);
|
|
2575
2624
|
};
|
|
2576
2625
|
return /* @__PURE__ */ jsx27(
|
|
2577
2626
|
"div",
|
|
@@ -2584,7 +2633,7 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2584
2633
|
{
|
|
2585
2634
|
ref: checkboxRef,
|
|
2586
2635
|
type: "checkbox",
|
|
2587
|
-
checked: allSelected,
|
|
2636
|
+
checked: state.allSelected,
|
|
2588
2637
|
onChange: handleChange,
|
|
2589
2638
|
className: "w-4 h-4 rounded border border-border bg-background accent-primary cursor-pointer focus:outline-none focus:ring-1 focus:ring-primary"
|
|
2590
2639
|
}
|
|
@@ -2598,15 +2647,21 @@ var headerCheckBox_default = React5.memo(HeaderCheckbox);
|
|
|
2598
2647
|
function buildCheckboxColumn({
|
|
2599
2648
|
getPageData,
|
|
2600
2649
|
onSelectionChange,
|
|
2601
|
-
onSelectAllPage
|
|
2650
|
+
onSelectAllPage,
|
|
2651
|
+
clearToken
|
|
2602
2652
|
}) {
|
|
2603
|
-
const
|
|
2653
|
+
const configRef = {
|
|
2654
|
+
getPageData,
|
|
2655
|
+
onSelectionChange,
|
|
2656
|
+
onSelectAllPage,
|
|
2657
|
+
clearToken
|
|
2658
|
+
};
|
|
2604
2659
|
return {
|
|
2605
2660
|
id: "__selection__",
|
|
2606
2661
|
width: 58,
|
|
2607
2662
|
sortable: false,
|
|
2608
2663
|
resize: false,
|
|
2609
|
-
config,
|
|
2664
|
+
config: configRef,
|
|
2610
2665
|
header: { cell: headerCheckBox_default },
|
|
2611
2666
|
cell: checkBoxCell_default
|
|
2612
2667
|
};
|
|
@@ -2632,9 +2687,11 @@ var Grid = forwardRef(
|
|
|
2632
2687
|
children,
|
|
2633
2688
|
onFocusCell = () => false,
|
|
2634
2689
|
selectionEnabled = false,
|
|
2635
|
-
|
|
2690
|
+
selectedIds = [],
|
|
2636
2691
|
onRowSelectionChange,
|
|
2637
2692
|
onSelectAllPage,
|
|
2693
|
+
selectedCount,
|
|
2694
|
+
selectedData,
|
|
2638
2695
|
selectionActions,
|
|
2639
2696
|
onSelectionAction,
|
|
2640
2697
|
onClearSelection
|
|
@@ -2654,139 +2711,140 @@ var Grid = forwardRef(
|
|
|
2654
2711
|
"children",
|
|
2655
2712
|
"onFocusCell",
|
|
2656
2713
|
"selectionEnabled",
|
|
2657
|
-
"
|
|
2714
|
+
"selectedIds",
|
|
2658
2715
|
"onRowSelectionChange",
|
|
2659
2716
|
"onSelectAllPage",
|
|
2717
|
+
"selectedCount",
|
|
2718
|
+
"selectedData",
|
|
2660
2719
|
"selectionActions",
|
|
2661
2720
|
"onSelectionAction",
|
|
2662
2721
|
"onClearSelection"
|
|
2663
2722
|
]);
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
const
|
|
2667
|
-
const
|
|
2723
|
+
var _a2;
|
|
2724
|
+
console.log("Grid rendered");
|
|
2725
|
+
const apiRef = useRef5(null);
|
|
2726
|
+
const containerRef = useRef5(null);
|
|
2727
|
+
const dataRef = useRef5(data);
|
|
2668
2728
|
useEffect9(() => {
|
|
2669
2729
|
dataRef.current = data;
|
|
2670
2730
|
}, [data]);
|
|
2671
|
-
const onRowSelectionChangeRef =
|
|
2731
|
+
const onRowSelectionChangeRef = useRef5(onRowSelectionChange);
|
|
2672
2732
|
useEffect9(() => {
|
|
2673
2733
|
onRowSelectionChangeRef.current = onRowSelectionChange;
|
|
2674
2734
|
}, [onRowSelectionChange]);
|
|
2675
|
-
const onSelectAllPageRef =
|
|
2735
|
+
const onSelectAllPageRef = useRef5(onSelectAllPage);
|
|
2676
2736
|
useEffect9(() => {
|
|
2677
2737
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2678
2738
|
}, [onSelectAllPage]);
|
|
2679
2739
|
useImperativeHandle(ref, () => apiRef.current, []);
|
|
2680
|
-
const
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
}
|
|
2740
|
+
const clearTokenRef = useRef5(0);
|
|
2741
|
+
const prevSelectedCountRef = useRef5(selectedCount != null ? selectedCount : 0);
|
|
2742
|
+
if (((_a2 = prevSelectedCountRef.current) != null ? _a2 : 0) > 0 && (selectedCount != null ? selectedCount : 0) === 0) {
|
|
2743
|
+
clearTokenRef.current += 1;
|
|
2744
|
+
}
|
|
2745
|
+
prevSelectedCountRef.current = selectedCount != null ? selectedCount : 0;
|
|
2685
2746
|
const resolvedColumns = useMemo4(() => {
|
|
2686
|
-
if (!selectionEnabled
|
|
2747
|
+
if (!selectionEnabled) return columns;
|
|
2748
|
+
if (columns.length === 0) return columns;
|
|
2687
2749
|
const checkboxCol = buildCheckboxColumn({
|
|
2688
2750
|
getPageData: () => {
|
|
2689
|
-
var
|
|
2690
|
-
return (
|
|
2751
|
+
var _a3;
|
|
2752
|
+
return (_a3 = dataRef.current) != null ? _a3 : [];
|
|
2691
2753
|
},
|
|
2692
|
-
onSelectionChange: (
|
|
2693
|
-
var
|
|
2694
|
-
(
|
|
2754
|
+
onSelectionChange: (id3, rowData, checked) => {
|
|
2755
|
+
var _a3;
|
|
2756
|
+
(_a3 = onRowSelectionChangeRef.current) == null ? void 0 : _a3.call(onRowSelectionChangeRef, id3, rowData, checked);
|
|
2695
2757
|
},
|
|
2696
2758
|
onSelectAllPage: (pageData, checked) => {
|
|
2697
|
-
var
|
|
2698
|
-
(
|
|
2699
|
-
}
|
|
2759
|
+
var _a3;
|
|
2760
|
+
(_a3 = onSelectAllPageRef.current) == null ? void 0 : _a3.call(onSelectAllPageRef, pageData, checked);
|
|
2761
|
+
},
|
|
2762
|
+
clearToken: clearTokenRef.current
|
|
2700
2763
|
});
|
|
2701
2764
|
return [checkboxCol, ...columns];
|
|
2702
|
-
}, [selectionEnabled, columns]);
|
|
2765
|
+
}, [selectionEnabled, columns, clearTokenRef.current]);
|
|
2703
2766
|
const resizeColumns = useCallback2(() => {
|
|
2704
2767
|
const api = apiRef.current;
|
|
2705
2768
|
const container = containerRef.current;
|
|
2706
2769
|
if (!api || !container) return;
|
|
2707
2770
|
const gridWidth = container.clientWidth;
|
|
2708
|
-
const
|
|
2709
|
-
const
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2771
|
+
const isFixedColumn = (col) => col.id === "__selection__";
|
|
2772
|
+
const resizableColumns = resolvedColumns.filter(
|
|
2773
|
+
(col) => !isFixedColumn(col)
|
|
2774
|
+
);
|
|
2775
|
+
const fixedColumns = resolvedColumns.filter(
|
|
2776
|
+
(col) => isFixedColumn(col)
|
|
2777
|
+
);
|
|
2778
|
+
const totalFixedWidth = fixedColumns.reduce((sum, col) => {
|
|
2779
|
+
var _a3, _b2;
|
|
2780
|
+
const column = api.getColumn(col.id);
|
|
2781
|
+
const width = (_b2 = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : col.width) != null ? _b2 : 0;
|
|
2782
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2715
2783
|
}, 0);
|
|
2716
|
-
const
|
|
2784
|
+
const availableWidth = Math.max(gridWidth - totalFixedWidth, 0);
|
|
2717
2785
|
if (data && data.length > 0) {
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
);
|
|
2721
|
-
const
|
|
2722
|
-
var
|
|
2723
|
-
const
|
|
2724
|
-
|
|
2786
|
+
resizableColumns.forEach((col) => {
|
|
2787
|
+
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2788
|
+
});
|
|
2789
|
+
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2790
|
+
var _a3;
|
|
2791
|
+
const column = api.getColumn(col.id);
|
|
2792
|
+
const width = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2793
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2725
2794
|
}, 0);
|
|
2726
|
-
if (
|
|
2727
|
-
const extra = (
|
|
2728
|
-
|
|
2729
|
-
var
|
|
2730
|
-
const
|
|
2731
|
-
|
|
2732
|
-
|
|
2795
|
+
if (totalAutoWidth < availableWidth && resizableColumns.length > 0) {
|
|
2796
|
+
const extra = (availableWidth - totalAutoWidth) / resizableColumns.length;
|
|
2797
|
+
resizableColumns.forEach((col) => {
|
|
2798
|
+
var _a3;
|
|
2799
|
+
const column = api.getColumn(col.id);
|
|
2800
|
+
const currentWidth = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2801
|
+
if (!isNaN(currentWidth)) {
|
|
2802
|
+
api.exec("resize-column", {
|
|
2803
|
+
id: col.id,
|
|
2804
|
+
width: currentWidth + extra
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2733
2807
|
});
|
|
2734
2808
|
}
|
|
2735
2809
|
} else {
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2810
|
+
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2811
|
+
resizableColumns.forEach((col) => {
|
|
2812
|
+
api.exec("resize-column", {
|
|
2813
|
+
id: col.id,
|
|
2814
|
+
width: equalWidth
|
|
2815
|
+
});
|
|
2816
|
+
});
|
|
2740
2817
|
}
|
|
2741
2818
|
}, [resolvedColumns, data]);
|
|
2819
|
+
useEffect9(() => {
|
|
2820
|
+
if (!containerRef.current) return;
|
|
2821
|
+
const observer = new ResizeObserver(() => resizeColumns());
|
|
2822
|
+
observer.observe(containerRef.current);
|
|
2823
|
+
return () => observer.disconnect();
|
|
2824
|
+
}, [resizeColumns]);
|
|
2742
2825
|
const init = useCallback2(
|
|
2743
2826
|
(api) => {
|
|
2744
2827
|
apiRef.current = api;
|
|
2745
2828
|
resizeColumns();
|
|
2746
2829
|
api.intercept("focus-cell", onFocusCell);
|
|
2747
|
-
if (selectionEnabled) {
|
|
2748
|
-
api.on("select-row", () => {
|
|
2749
|
-
var _a2;
|
|
2750
|
-
setInternalSelectedCount(
|
|
2751
|
-
((_a2 = api.getState().selectedRows) != null ? _a2 : []).length
|
|
2752
|
-
);
|
|
2753
|
-
});
|
|
2754
|
-
}
|
|
2755
2830
|
},
|
|
2756
|
-
[resizeColumns, onFocusCell
|
|
2831
|
+
[resizeColumns, onFocusCell]
|
|
2757
2832
|
);
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
const
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
}, [resizeColumns]);
|
|
2764
|
-
useEffect9(() => {
|
|
2765
|
-
if (!selectionEnabled || !getSelectedIds || !apiRef.current) return;
|
|
2766
|
-
const pageIds = new Set((data != null ? data : []).map((r) => r.id));
|
|
2767
|
-
const toRestore = getSelectedIds().filter((id) => pageIds.has(id));
|
|
2768
|
-
toRestore.forEach(
|
|
2769
|
-
(id) => apiRef.current.exec("select-row", { id, mode: true })
|
|
2770
|
-
);
|
|
2771
|
-
}, [data, selectionEnabled, getSelectedIds]);
|
|
2772
|
-
const handleClearSelection = useCallback2(() => {
|
|
2773
|
-
var _a2;
|
|
2774
|
-
const api = apiRef.current;
|
|
2775
|
-
if (!api) return;
|
|
2776
|
-
const ids = [...(_a2 = api.getState().selectedRows) != null ? _a2 : []];
|
|
2777
|
-
ids.forEach((id) => api.exec("select-row", { id, mode: false }));
|
|
2778
|
-
onClearSelection == null ? void 0 : onClearSelection();
|
|
2779
|
-
}, [onClearSelection]);
|
|
2833
|
+
const getSelectedData = () => {
|
|
2834
|
+
var _a3, _b2;
|
|
2835
|
+
const selected = (_b2 = (_a3 = apiRef.current) == null ? void 0 : _a3.getState().selectedRows) != null ? _b2 : [];
|
|
2836
|
+
return data.filter((row) => selected.includes(row.id));
|
|
2837
|
+
};
|
|
2780
2838
|
const handleExportPdf = useCallback2(() => {
|
|
2781
2839
|
const selected = getSelectedData();
|
|
2782
2840
|
if (selected.length) exportPdf(selected, fileName);
|
|
2783
2841
|
else onExportPdf == null ? void 0 : onExportPdf();
|
|
2784
|
-
}, [
|
|
2842
|
+
}, [data, fileName, onExportPdf]);
|
|
2785
2843
|
const handleExportExcel = useCallback2(() => {
|
|
2786
2844
|
const selected = getSelectedData();
|
|
2787
2845
|
if (selected.length) exportExcel(selected, fileName);
|
|
2788
2846
|
else onExportExcel == null ? void 0 : onExportExcel();
|
|
2789
|
-
}, [
|
|
2847
|
+
}, [data, fileName, onExportExcel]);
|
|
2790
2848
|
return /* @__PURE__ */ jsxs20("div", { className: "w-full h-full flex flex-col overflow-hidden", children: [
|
|
2791
2849
|
/* @__PURE__ */ jsx28(
|
|
2792
2850
|
gridHeader_default,
|
|
@@ -2801,11 +2859,11 @@ var Grid = forwardRef(
|
|
|
2801
2859
|
filterList: rest.filterList,
|
|
2802
2860
|
onFilterChange,
|
|
2803
2861
|
initialFilters,
|
|
2804
|
-
selectedCount
|
|
2805
|
-
selectedData
|
|
2862
|
+
selectedCount,
|
|
2863
|
+
selectedData,
|
|
2806
2864
|
selectionActions,
|
|
2807
2865
|
onSelectionAction,
|
|
2808
|
-
onClearSelection
|
|
2866
|
+
onClearSelection,
|
|
2809
2867
|
children
|
|
2810
2868
|
}
|
|
2811
2869
|
),
|
|
@@ -2820,6 +2878,7 @@ var Grid = forwardRef(
|
|
|
2820
2878
|
data,
|
|
2821
2879
|
columns: resolvedColumns,
|
|
2822
2880
|
init,
|
|
2881
|
+
selectedRows: selectionEnabled ? selectedIds : void 0,
|
|
2823
2882
|
select: selectionEnabled ? false : rest.select
|
|
2824
2883
|
})
|
|
2825
2884
|
) }) })
|
|
@@ -2989,7 +3048,7 @@ var pagination_default = Pagination;
|
|
|
2989
3048
|
|
|
2990
3049
|
// src/components/custom/toolbar/index.tsx
|
|
2991
3050
|
import { ChevronRight as ChevronRight4, X as X5 } from "lucide-react";
|
|
2992
|
-
import { useState as
|
|
3051
|
+
import { useState as useState9, useRef as useRef6, useEffect as useEffect10 } from "react";
|
|
2993
3052
|
import { Fragment as Fragment4, jsx as jsx31, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
2994
3053
|
var SlideToolbar = ({
|
|
2995
3054
|
items,
|
|
@@ -3002,8 +3061,8 @@ var SlideToolbar = ({
|
|
|
3002
3061
|
className = ""
|
|
3003
3062
|
}) => {
|
|
3004
3063
|
const resolvedItems = items != null ? items : children ? void 0 : [];
|
|
3005
|
-
const [open, setOpen] =
|
|
3006
|
-
const panelRef =
|
|
3064
|
+
const [open, setOpen] = useState9(false);
|
|
3065
|
+
const panelRef = useRef6(null);
|
|
3007
3066
|
useEffect10(() => {
|
|
3008
3067
|
if (!open || !closeOnBackdrop) return;
|
|
3009
3068
|
const handlePointerDown = (e) => {
|