baaz-custom-components 5.2.1 → 5.2.3
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 +218 -156
- package/dist/index.mjs +201 -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,59 @@ 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 dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2618
|
+
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2619
|
+
const selectedOnPage = dataArray.filter(
|
|
2620
|
+
(r) => selectedRows.includes(r.id)
|
|
2621
|
+
).length;
|
|
2622
|
+
return {
|
|
2623
|
+
allSelected: dataArray.length > 0 && selectedOnPage === dataArray.length,
|
|
2624
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < dataArray.length
|
|
2625
|
+
};
|
|
2626
|
+
};
|
|
2627
|
+
const [, forceUpdate] = (0, import_react9.useReducer)((x) => x + 1, 0);
|
|
2628
|
+
(0, import_react9.useEffect)(() => {
|
|
2629
|
+
const unsub = api.on("select-row", () => {
|
|
2630
|
+
forceUpdate();
|
|
2631
|
+
});
|
|
2632
|
+
return () => {
|
|
2633
|
+
if (typeof unsub === "function") unsub();
|
|
2634
|
+
};
|
|
2586
2635
|
}, [api]);
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
(
|
|
2591
|
-
).
|
|
2592
|
-
const
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2636
|
+
(0, import_react9.useEffect)(() => {
|
|
2637
|
+
var _a2;
|
|
2638
|
+
(_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.clearToken;
|
|
2639
|
+
forceUpdate();
|
|
2640
|
+
}, [(_a = column == null ? void 0 : column.config) == null ? void 0 : _a.clearToken]);
|
|
2641
|
+
const state = computeState();
|
|
2642
|
+
(0, import_react9.useEffect)(() => {
|
|
2643
|
+
if (checkboxRef.current) {
|
|
2644
|
+
checkboxRef.current.indeterminate = state.someSelected;
|
|
2645
|
+
}
|
|
2646
|
+
}, [state.someSelected]);
|
|
2597
2647
|
const handleChange = (e) => {
|
|
2598
|
-
var _a2,
|
|
2648
|
+
var _a2, _b, _c, _d;
|
|
2599
2649
|
e.stopPropagation();
|
|
2600
|
-
const
|
|
2601
|
-
pageData.
|
|
2602
|
-
|
|
2603
|
-
)
|
|
2604
|
-
|
|
2650
|
+
const isChecked = e.target.checked;
|
|
2651
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2652
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2653
|
+
dataArray.forEach((row) => {
|
|
2654
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2655
|
+
});
|
|
2656
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, dataArray, isChecked);
|
|
2605
2657
|
};
|
|
2606
2658
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2607
2659
|
"div",
|
|
@@ -2614,7 +2666,7 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2614
2666
|
{
|
|
2615
2667
|
ref: checkboxRef,
|
|
2616
2668
|
type: "checkbox",
|
|
2617
|
-
checked: allSelected,
|
|
2669
|
+
checked: state.allSelected,
|
|
2618
2670
|
onChange: handleChange,
|
|
2619
2671
|
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
2672
|
}
|
|
@@ -2622,21 +2674,27 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2622
2674
|
}
|
|
2623
2675
|
);
|
|
2624
2676
|
};
|
|
2625
|
-
var headerCheckBox_default =
|
|
2677
|
+
var headerCheckBox_default = import_react9.default.memo(HeaderCheckbox);
|
|
2626
2678
|
|
|
2627
2679
|
// src/components/custom/grid/utils/buildCheckboxColumn.tsx
|
|
2628
2680
|
function buildCheckboxColumn({
|
|
2629
2681
|
getPageData,
|
|
2630
2682
|
onSelectionChange,
|
|
2631
|
-
onSelectAllPage
|
|
2683
|
+
onSelectAllPage,
|
|
2684
|
+
clearToken
|
|
2632
2685
|
}) {
|
|
2633
|
-
const
|
|
2686
|
+
const configRef = {
|
|
2687
|
+
getPageData,
|
|
2688
|
+
onSelectionChange,
|
|
2689
|
+
onSelectAllPage,
|
|
2690
|
+
clearToken
|
|
2691
|
+
};
|
|
2634
2692
|
return {
|
|
2635
2693
|
id: "__selection__",
|
|
2636
2694
|
width: 58,
|
|
2637
2695
|
sortable: false,
|
|
2638
2696
|
resize: false,
|
|
2639
|
-
config,
|
|
2697
|
+
config: configRef,
|
|
2640
2698
|
header: { cell: headerCheckBox_default },
|
|
2641
2699
|
cell: checkBoxCell_default
|
|
2642
2700
|
};
|
|
@@ -2644,7 +2702,7 @@ function buildCheckboxColumn({
|
|
|
2644
2702
|
|
|
2645
2703
|
// src/components/custom/grid/index.tsx
|
|
2646
2704
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2647
|
-
var Grid = (0,
|
|
2705
|
+
var Grid = (0, import_react10.forwardRef)(
|
|
2648
2706
|
(_a, ref) => {
|
|
2649
2707
|
var _b = _a, {
|
|
2650
2708
|
data,
|
|
@@ -2662,9 +2720,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2662
2720
|
children,
|
|
2663
2721
|
onFocusCell = () => false,
|
|
2664
2722
|
selectionEnabled = false,
|
|
2665
|
-
|
|
2723
|
+
selectedIds = [],
|
|
2666
2724
|
onRowSelectionChange,
|
|
2667
2725
|
onSelectAllPage,
|
|
2726
|
+
selectedCount,
|
|
2727
|
+
selectedData,
|
|
2668
2728
|
selectionActions,
|
|
2669
2729
|
onSelectionAction,
|
|
2670
2730
|
onClearSelection
|
|
@@ -2684,139 +2744,140 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2684
2744
|
"children",
|
|
2685
2745
|
"onFocusCell",
|
|
2686
2746
|
"selectionEnabled",
|
|
2687
|
-
"
|
|
2747
|
+
"selectedIds",
|
|
2688
2748
|
"onRowSelectionChange",
|
|
2689
2749
|
"onSelectAllPage",
|
|
2750
|
+
"selectedCount",
|
|
2751
|
+
"selectedData",
|
|
2690
2752
|
"selectionActions",
|
|
2691
2753
|
"onSelectionAction",
|
|
2692
2754
|
"onClearSelection"
|
|
2693
2755
|
]);
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const
|
|
2697
|
-
const
|
|
2698
|
-
(0,
|
|
2756
|
+
var _a2;
|
|
2757
|
+
console.log("Grid rendered");
|
|
2758
|
+
const apiRef = (0, import_react10.useRef)(null);
|
|
2759
|
+
const containerRef = (0, import_react10.useRef)(null);
|
|
2760
|
+
const dataRef = (0, import_react10.useRef)(data);
|
|
2761
|
+
(0, import_react10.useEffect)(() => {
|
|
2699
2762
|
dataRef.current = data;
|
|
2700
2763
|
}, [data]);
|
|
2701
|
-
const onRowSelectionChangeRef = (0,
|
|
2702
|
-
(0,
|
|
2764
|
+
const onRowSelectionChangeRef = (0, import_react10.useRef)(onRowSelectionChange);
|
|
2765
|
+
(0, import_react10.useEffect)(() => {
|
|
2703
2766
|
onRowSelectionChangeRef.current = onRowSelectionChange;
|
|
2704
2767
|
}, [onRowSelectionChange]);
|
|
2705
|
-
const onSelectAllPageRef = (0,
|
|
2706
|
-
(0,
|
|
2768
|
+
const onSelectAllPageRef = (0, import_react10.useRef)(onSelectAllPage);
|
|
2769
|
+
(0, import_react10.useEffect)(() => {
|
|
2707
2770
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2708
2771
|
}, [onSelectAllPage]);
|
|
2709
|
-
(0,
|
|
2710
|
-
const
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2772
|
+
(0, import_react10.useImperativeHandle)(ref, () => apiRef.current, []);
|
|
2773
|
+
const clearTokenRef = (0, import_react10.useRef)(0);
|
|
2774
|
+
const prevSelectedCountRef = (0, import_react10.useRef)(selectedCount != null ? selectedCount : 0);
|
|
2775
|
+
if (((_a2 = prevSelectedCountRef.current) != null ? _a2 : 0) > 0 && (selectedCount != null ? selectedCount : 0) === 0) {
|
|
2776
|
+
clearTokenRef.current += 1;
|
|
2777
|
+
}
|
|
2778
|
+
prevSelectedCountRef.current = selectedCount != null ? selectedCount : 0;
|
|
2779
|
+
const resolvedColumns = (0, import_react10.useMemo)(() => {
|
|
2780
|
+
if (!selectionEnabled) return columns;
|
|
2781
|
+
if (columns.length === 0) return columns;
|
|
2717
2782
|
const checkboxCol = buildCheckboxColumn({
|
|
2718
2783
|
getPageData: () => {
|
|
2719
|
-
var
|
|
2720
|
-
return (
|
|
2784
|
+
var _a3;
|
|
2785
|
+
return (_a3 = dataRef.current) != null ? _a3 : [];
|
|
2721
2786
|
},
|
|
2722
|
-
onSelectionChange: (
|
|
2723
|
-
var
|
|
2724
|
-
(
|
|
2787
|
+
onSelectionChange: (id3, rowData, checked) => {
|
|
2788
|
+
var _a3;
|
|
2789
|
+
(_a3 = onRowSelectionChangeRef.current) == null ? void 0 : _a3.call(onRowSelectionChangeRef, id3, rowData, checked);
|
|
2725
2790
|
},
|
|
2726
2791
|
onSelectAllPage: (pageData, checked) => {
|
|
2727
|
-
var
|
|
2728
|
-
(
|
|
2729
|
-
}
|
|
2792
|
+
var _a3;
|
|
2793
|
+
(_a3 = onSelectAllPageRef.current) == null ? void 0 : _a3.call(onSelectAllPageRef, pageData, checked);
|
|
2794
|
+
},
|
|
2795
|
+
clearToken: clearTokenRef.current
|
|
2730
2796
|
});
|
|
2731
2797
|
return [checkboxCol, ...columns];
|
|
2732
|
-
}, [selectionEnabled, columns]);
|
|
2733
|
-
const resizeColumns = (0,
|
|
2798
|
+
}, [selectionEnabled, columns, clearTokenRef.current]);
|
|
2799
|
+
const resizeColumns = (0, import_react10.useCallback)(() => {
|
|
2734
2800
|
const api = apiRef.current;
|
|
2735
2801
|
const container = containerRef.current;
|
|
2736
2802
|
if (!api || !container) return;
|
|
2737
2803
|
const gridWidth = container.clientWidth;
|
|
2738
|
-
const
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2804
|
+
const isFixedColumn = (col) => col.id === "__selection__";
|
|
2805
|
+
const resizableColumns = resolvedColumns.filter(
|
|
2806
|
+
(col) => !isFixedColumn(col)
|
|
2807
|
+
);
|
|
2808
|
+
const fixedColumns = resolvedColumns.filter(
|
|
2809
|
+
(col) => isFixedColumn(col)
|
|
2810
|
+
);
|
|
2811
|
+
const totalFixedWidth = fixedColumns.reduce((sum, col) => {
|
|
2812
|
+
var _a3, _b2;
|
|
2813
|
+
const column = api.getColumn(col.id);
|
|
2814
|
+
const width = (_b2 = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : col.width) != null ? _b2 : 0;
|
|
2815
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2745
2816
|
}, 0);
|
|
2746
|
-
const
|
|
2817
|
+
const availableWidth = Math.max(gridWidth - totalFixedWidth, 0);
|
|
2747
2818
|
if (data && data.length > 0) {
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
);
|
|
2751
|
-
const
|
|
2752
|
-
var
|
|
2753
|
-
const
|
|
2754
|
-
|
|
2819
|
+
resizableColumns.forEach((col) => {
|
|
2820
|
+
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2821
|
+
});
|
|
2822
|
+
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2823
|
+
var _a3;
|
|
2824
|
+
const column = api.getColumn(col.id);
|
|
2825
|
+
const width = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2826
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2755
2827
|
}, 0);
|
|
2756
|
-
if (
|
|
2757
|
-
const extra = (
|
|
2758
|
-
|
|
2759
|
-
var
|
|
2760
|
-
const
|
|
2761
|
-
|
|
2762
|
-
|
|
2828
|
+
if (totalAutoWidth < availableWidth && resizableColumns.length > 0) {
|
|
2829
|
+
const extra = (availableWidth - totalAutoWidth) / resizableColumns.length;
|
|
2830
|
+
resizableColumns.forEach((col) => {
|
|
2831
|
+
var _a3;
|
|
2832
|
+
const column = api.getColumn(col.id);
|
|
2833
|
+
const currentWidth = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2834
|
+
if (!isNaN(currentWidth)) {
|
|
2835
|
+
api.exec("resize-column", {
|
|
2836
|
+
id: col.id,
|
|
2837
|
+
width: currentWidth + extra
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2763
2840
|
});
|
|
2764
2841
|
}
|
|
2765
2842
|
} else {
|
|
2766
|
-
const
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2843
|
+
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2844
|
+
resizableColumns.forEach((col) => {
|
|
2845
|
+
api.exec("resize-column", {
|
|
2846
|
+
id: col.id,
|
|
2847
|
+
width: equalWidth
|
|
2848
|
+
});
|
|
2849
|
+
});
|
|
2770
2850
|
}
|
|
2771
2851
|
}, [resolvedColumns, data]);
|
|
2772
|
-
|
|
2852
|
+
(0, import_react10.useEffect)(() => {
|
|
2853
|
+
if (!containerRef.current) return;
|
|
2854
|
+
const observer = new ResizeObserver(() => resizeColumns());
|
|
2855
|
+
observer.observe(containerRef.current);
|
|
2856
|
+
return () => observer.disconnect();
|
|
2857
|
+
}, [resizeColumns]);
|
|
2858
|
+
const init = (0, import_react10.useCallback)(
|
|
2773
2859
|
(api) => {
|
|
2774
2860
|
apiRef.current = api;
|
|
2775
2861
|
resizeColumns();
|
|
2776
2862
|
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
2863
|
},
|
|
2786
|
-
[resizeColumns, onFocusCell
|
|
2864
|
+
[resizeColumns, onFocusCell]
|
|
2787
2865
|
);
|
|
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)(() => {
|
|
2866
|
+
const getSelectedData = () => {
|
|
2867
|
+
var _a3, _b2;
|
|
2868
|
+
const selected = (_b2 = (_a3 = apiRef.current) == null ? void 0 : _a3.getState().selectedRows) != null ? _b2 : [];
|
|
2869
|
+
return data.filter((row) => selected.includes(row.id));
|
|
2870
|
+
};
|
|
2871
|
+
const handleExportPdf = (0, import_react10.useCallback)(() => {
|
|
2811
2872
|
const selected = getSelectedData();
|
|
2812
2873
|
if (selected.length) exportPdf(selected, fileName);
|
|
2813
2874
|
else onExportPdf == null ? void 0 : onExportPdf();
|
|
2814
|
-
}, [
|
|
2815
|
-
const handleExportExcel = (0,
|
|
2875
|
+
}, [data, fileName, onExportPdf]);
|
|
2876
|
+
const handleExportExcel = (0, import_react10.useCallback)(() => {
|
|
2816
2877
|
const selected = getSelectedData();
|
|
2817
2878
|
if (selected.length) exportExcel(selected, fileName);
|
|
2818
2879
|
else onExportExcel == null ? void 0 : onExportExcel();
|
|
2819
|
-
}, [
|
|
2880
|
+
}, [data, fileName, onExportExcel]);
|
|
2820
2881
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: "w-full h-full flex flex-col overflow-hidden", children: [
|
|
2821
2882
|
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2822
2883
|
gridHeader_default,
|
|
@@ -2831,11 +2892,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2831
2892
|
filterList: rest.filterList,
|
|
2832
2893
|
onFilterChange,
|
|
2833
2894
|
initialFilters,
|
|
2834
|
-
selectedCount
|
|
2835
|
-
selectedData
|
|
2895
|
+
selectedCount,
|
|
2896
|
+
selectedData,
|
|
2836
2897
|
selectionActions,
|
|
2837
2898
|
onSelectionAction,
|
|
2838
|
-
onClearSelection
|
|
2899
|
+
onClearSelection,
|
|
2839
2900
|
children
|
|
2840
2901
|
}
|
|
2841
2902
|
),
|
|
@@ -2850,6 +2911,7 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2850
2911
|
data,
|
|
2851
2912
|
columns: resolvedColumns,
|
|
2852
2913
|
init,
|
|
2914
|
+
selectedRows: selectionEnabled ? selectedIds : void 0,
|
|
2853
2915
|
select: selectionEnabled ? false : rest.select
|
|
2854
2916
|
})
|
|
2855
2917
|
) }) })
|
|
@@ -2858,11 +2920,11 @@ var Grid = (0, import_react9.forwardRef)(
|
|
|
2858
2920
|
] });
|
|
2859
2921
|
}
|
|
2860
2922
|
);
|
|
2861
|
-
var grid_default =
|
|
2923
|
+
var grid_default = import_react10.default.memo(Grid);
|
|
2862
2924
|
|
|
2863
2925
|
// src/components/custom/grid/sortableHeaderCell.tsx
|
|
2864
2926
|
var import_lucide_react15 = require("lucide-react");
|
|
2865
|
-
var
|
|
2927
|
+
var import_react11 = __toESM(require("react"));
|
|
2866
2928
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
2867
2929
|
var SortableHeaderCell = ({ cell, sortKey, sortOrder, onSortChange }) => {
|
|
2868
2930
|
if (!(cell == null ? void 0 : cell.id)) return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("span", { children: cell == null ? void 0 : cell.text });
|
|
@@ -2892,7 +2954,7 @@ var SortableHeaderCell = ({ cell, sortKey, sortOrder, onSortChange }) => {
|
|
|
2892
2954
|
}
|
|
2893
2955
|
);
|
|
2894
2956
|
};
|
|
2895
|
-
var sortableHeaderCell_default =
|
|
2957
|
+
var sortableHeaderCell_default = import_react11.default.memo(SortableHeaderCell, (prev, next) => {
|
|
2896
2958
|
var _a, _b, _c, _d;
|
|
2897
2959
|
if (((_a = prev.cell) == null ? void 0 : _a.id) !== ((_b = next.cell) == null ? void 0 : _b.id)) return false;
|
|
2898
2960
|
if (((_c = prev.cell) == null ? void 0 : _c.text) !== ((_d = next.cell) == null ? void 0 : _d.text)) return false;
|
|
@@ -3019,7 +3081,7 @@ var pagination_default = Pagination;
|
|
|
3019
3081
|
|
|
3020
3082
|
// src/components/custom/toolbar/index.tsx
|
|
3021
3083
|
var import_lucide_react17 = require("lucide-react");
|
|
3022
|
-
var
|
|
3084
|
+
var import_react12 = require("react");
|
|
3023
3085
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
3024
3086
|
var SlideToolbar = ({
|
|
3025
3087
|
items,
|
|
@@ -3032,9 +3094,9 @@ var SlideToolbar = ({
|
|
|
3032
3094
|
className = ""
|
|
3033
3095
|
}) => {
|
|
3034
3096
|
const resolvedItems = items != null ? items : children ? void 0 : [];
|
|
3035
|
-
const [open, setOpen] = (0,
|
|
3036
|
-
const panelRef = (0,
|
|
3037
|
-
(0,
|
|
3097
|
+
const [open, setOpen] = (0, import_react12.useState)(false);
|
|
3098
|
+
const panelRef = (0, import_react12.useRef)(null);
|
|
3099
|
+
(0, import_react12.useEffect)(() => {
|
|
3038
3100
|
if (!open || !closeOnBackdrop) return;
|
|
3039
3101
|
const handlePointerDown = (e) => {
|
|
3040
3102
|
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,59 @@ 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 dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2587
|
+
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2588
|
+
const selectedOnPage = dataArray.filter(
|
|
2589
|
+
(r) => selectedRows.includes(r.id)
|
|
2590
|
+
).length;
|
|
2591
|
+
return {
|
|
2592
|
+
allSelected: dataArray.length > 0 && selectedOnPage === dataArray.length,
|
|
2593
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < dataArray.length
|
|
2594
|
+
};
|
|
2595
|
+
};
|
|
2552
2596
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2553
2597
|
useEffect8(() => {
|
|
2554
|
-
const unsub = api.on("select-row", () =>
|
|
2555
|
-
|
|
2598
|
+
const unsub = api.on("select-row", () => {
|
|
2599
|
+
forceUpdate();
|
|
2600
|
+
});
|
|
2601
|
+
return () => {
|
|
2602
|
+
if (typeof unsub === "function") unsub();
|
|
2603
|
+
};
|
|
2556
2604
|
}, [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
2605
|
useEffect8(() => {
|
|
2565
|
-
|
|
2566
|
-
|
|
2606
|
+
var _a2;
|
|
2607
|
+
(_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.clearToken;
|
|
2608
|
+
forceUpdate();
|
|
2609
|
+
}, [(_a = column == null ? void 0 : column.config) == null ? void 0 : _a.clearToken]);
|
|
2610
|
+
const state = computeState();
|
|
2611
|
+
useEffect8(() => {
|
|
2612
|
+
if (checkboxRef.current) {
|
|
2613
|
+
checkboxRef.current.indeterminate = state.someSelected;
|
|
2614
|
+
}
|
|
2615
|
+
}, [state.someSelected]);
|
|
2567
2616
|
const handleChange = (e) => {
|
|
2568
|
-
var _a2,
|
|
2617
|
+
var _a2, _b, _c, _d;
|
|
2569
2618
|
e.stopPropagation();
|
|
2570
|
-
const
|
|
2571
|
-
pageData.
|
|
2572
|
-
|
|
2573
|
-
)
|
|
2574
|
-
|
|
2619
|
+
const isChecked = e.target.checked;
|
|
2620
|
+
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2621
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2622
|
+
dataArray.forEach((row) => {
|
|
2623
|
+
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2624
|
+
});
|
|
2625
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, dataArray, isChecked);
|
|
2575
2626
|
};
|
|
2576
2627
|
return /* @__PURE__ */ jsx27(
|
|
2577
2628
|
"div",
|
|
@@ -2584,7 +2635,7 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2584
2635
|
{
|
|
2585
2636
|
ref: checkboxRef,
|
|
2586
2637
|
type: "checkbox",
|
|
2587
|
-
checked: allSelected,
|
|
2638
|
+
checked: state.allSelected,
|
|
2588
2639
|
onChange: handleChange,
|
|
2589
2640
|
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
2641
|
}
|
|
@@ -2598,15 +2649,21 @@ var headerCheckBox_default = React5.memo(HeaderCheckbox);
|
|
|
2598
2649
|
function buildCheckboxColumn({
|
|
2599
2650
|
getPageData,
|
|
2600
2651
|
onSelectionChange,
|
|
2601
|
-
onSelectAllPage
|
|
2652
|
+
onSelectAllPage,
|
|
2653
|
+
clearToken
|
|
2602
2654
|
}) {
|
|
2603
|
-
const
|
|
2655
|
+
const configRef = {
|
|
2656
|
+
getPageData,
|
|
2657
|
+
onSelectionChange,
|
|
2658
|
+
onSelectAllPage,
|
|
2659
|
+
clearToken
|
|
2660
|
+
};
|
|
2604
2661
|
return {
|
|
2605
2662
|
id: "__selection__",
|
|
2606
2663
|
width: 58,
|
|
2607
2664
|
sortable: false,
|
|
2608
2665
|
resize: false,
|
|
2609
|
-
config,
|
|
2666
|
+
config: configRef,
|
|
2610
2667
|
header: { cell: headerCheckBox_default },
|
|
2611
2668
|
cell: checkBoxCell_default
|
|
2612
2669
|
};
|
|
@@ -2632,9 +2689,11 @@ var Grid = forwardRef(
|
|
|
2632
2689
|
children,
|
|
2633
2690
|
onFocusCell = () => false,
|
|
2634
2691
|
selectionEnabled = false,
|
|
2635
|
-
|
|
2692
|
+
selectedIds = [],
|
|
2636
2693
|
onRowSelectionChange,
|
|
2637
2694
|
onSelectAllPage,
|
|
2695
|
+
selectedCount,
|
|
2696
|
+
selectedData,
|
|
2638
2697
|
selectionActions,
|
|
2639
2698
|
onSelectionAction,
|
|
2640
2699
|
onClearSelection
|
|
@@ -2654,139 +2713,140 @@ var Grid = forwardRef(
|
|
|
2654
2713
|
"children",
|
|
2655
2714
|
"onFocusCell",
|
|
2656
2715
|
"selectionEnabled",
|
|
2657
|
-
"
|
|
2716
|
+
"selectedIds",
|
|
2658
2717
|
"onRowSelectionChange",
|
|
2659
2718
|
"onSelectAllPage",
|
|
2719
|
+
"selectedCount",
|
|
2720
|
+
"selectedData",
|
|
2660
2721
|
"selectionActions",
|
|
2661
2722
|
"onSelectionAction",
|
|
2662
2723
|
"onClearSelection"
|
|
2663
2724
|
]);
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
const
|
|
2667
|
-
const
|
|
2725
|
+
var _a2;
|
|
2726
|
+
console.log("Grid rendered");
|
|
2727
|
+
const apiRef = useRef5(null);
|
|
2728
|
+
const containerRef = useRef5(null);
|
|
2729
|
+
const dataRef = useRef5(data);
|
|
2668
2730
|
useEffect9(() => {
|
|
2669
2731
|
dataRef.current = data;
|
|
2670
2732
|
}, [data]);
|
|
2671
|
-
const onRowSelectionChangeRef =
|
|
2733
|
+
const onRowSelectionChangeRef = useRef5(onRowSelectionChange);
|
|
2672
2734
|
useEffect9(() => {
|
|
2673
2735
|
onRowSelectionChangeRef.current = onRowSelectionChange;
|
|
2674
2736
|
}, [onRowSelectionChange]);
|
|
2675
|
-
const onSelectAllPageRef =
|
|
2737
|
+
const onSelectAllPageRef = useRef5(onSelectAllPage);
|
|
2676
2738
|
useEffect9(() => {
|
|
2677
2739
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2678
2740
|
}, [onSelectAllPage]);
|
|
2679
2741
|
useImperativeHandle(ref, () => apiRef.current, []);
|
|
2680
|
-
const
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
}
|
|
2742
|
+
const clearTokenRef = useRef5(0);
|
|
2743
|
+
const prevSelectedCountRef = useRef5(selectedCount != null ? selectedCount : 0);
|
|
2744
|
+
if (((_a2 = prevSelectedCountRef.current) != null ? _a2 : 0) > 0 && (selectedCount != null ? selectedCount : 0) === 0) {
|
|
2745
|
+
clearTokenRef.current += 1;
|
|
2746
|
+
}
|
|
2747
|
+
prevSelectedCountRef.current = selectedCount != null ? selectedCount : 0;
|
|
2685
2748
|
const resolvedColumns = useMemo4(() => {
|
|
2686
|
-
if (!selectionEnabled
|
|
2749
|
+
if (!selectionEnabled) return columns;
|
|
2750
|
+
if (columns.length === 0) return columns;
|
|
2687
2751
|
const checkboxCol = buildCheckboxColumn({
|
|
2688
2752
|
getPageData: () => {
|
|
2689
|
-
var
|
|
2690
|
-
return (
|
|
2753
|
+
var _a3;
|
|
2754
|
+
return (_a3 = dataRef.current) != null ? _a3 : [];
|
|
2691
2755
|
},
|
|
2692
|
-
onSelectionChange: (
|
|
2693
|
-
var
|
|
2694
|
-
(
|
|
2756
|
+
onSelectionChange: (id3, rowData, checked) => {
|
|
2757
|
+
var _a3;
|
|
2758
|
+
(_a3 = onRowSelectionChangeRef.current) == null ? void 0 : _a3.call(onRowSelectionChangeRef, id3, rowData, checked);
|
|
2695
2759
|
},
|
|
2696
2760
|
onSelectAllPage: (pageData, checked) => {
|
|
2697
|
-
var
|
|
2698
|
-
(
|
|
2699
|
-
}
|
|
2761
|
+
var _a3;
|
|
2762
|
+
(_a3 = onSelectAllPageRef.current) == null ? void 0 : _a3.call(onSelectAllPageRef, pageData, checked);
|
|
2763
|
+
},
|
|
2764
|
+
clearToken: clearTokenRef.current
|
|
2700
2765
|
});
|
|
2701
2766
|
return [checkboxCol, ...columns];
|
|
2702
|
-
}, [selectionEnabled, columns]);
|
|
2767
|
+
}, [selectionEnabled, columns, clearTokenRef.current]);
|
|
2703
2768
|
const resizeColumns = useCallback2(() => {
|
|
2704
2769
|
const api = apiRef.current;
|
|
2705
2770
|
const container = containerRef.current;
|
|
2706
2771
|
if (!api || !container) return;
|
|
2707
2772
|
const gridWidth = container.clientWidth;
|
|
2708
|
-
const
|
|
2709
|
-
const
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2773
|
+
const isFixedColumn = (col) => col.id === "__selection__";
|
|
2774
|
+
const resizableColumns = resolvedColumns.filter(
|
|
2775
|
+
(col) => !isFixedColumn(col)
|
|
2776
|
+
);
|
|
2777
|
+
const fixedColumns = resolvedColumns.filter(
|
|
2778
|
+
(col) => isFixedColumn(col)
|
|
2779
|
+
);
|
|
2780
|
+
const totalFixedWidth = fixedColumns.reduce((sum, col) => {
|
|
2781
|
+
var _a3, _b2;
|
|
2782
|
+
const column = api.getColumn(col.id);
|
|
2783
|
+
const width = (_b2 = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : col.width) != null ? _b2 : 0;
|
|
2784
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2715
2785
|
}, 0);
|
|
2716
|
-
const
|
|
2786
|
+
const availableWidth = Math.max(gridWidth - totalFixedWidth, 0);
|
|
2717
2787
|
if (data && data.length > 0) {
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
);
|
|
2721
|
-
const
|
|
2722
|
-
var
|
|
2723
|
-
const
|
|
2724
|
-
|
|
2788
|
+
resizableColumns.forEach((col) => {
|
|
2789
|
+
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2790
|
+
});
|
|
2791
|
+
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2792
|
+
var _a3;
|
|
2793
|
+
const column = api.getColumn(col.id);
|
|
2794
|
+
const width = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2795
|
+
return sum + (isNaN(width) ? 0 : width);
|
|
2725
2796
|
}, 0);
|
|
2726
|
-
if (
|
|
2727
|
-
const extra = (
|
|
2728
|
-
|
|
2729
|
-
var
|
|
2730
|
-
const
|
|
2731
|
-
|
|
2732
|
-
|
|
2797
|
+
if (totalAutoWidth < availableWidth && resizableColumns.length > 0) {
|
|
2798
|
+
const extra = (availableWidth - totalAutoWidth) / resizableColumns.length;
|
|
2799
|
+
resizableColumns.forEach((col) => {
|
|
2800
|
+
var _a3;
|
|
2801
|
+
const column = api.getColumn(col.id);
|
|
2802
|
+
const currentWidth = (_a3 = column == null ? void 0 : column.width) != null ? _a3 : 0;
|
|
2803
|
+
if (!isNaN(currentWidth)) {
|
|
2804
|
+
api.exec("resize-column", {
|
|
2805
|
+
id: col.id,
|
|
2806
|
+
width: currentWidth + extra
|
|
2807
|
+
});
|
|
2808
|
+
}
|
|
2733
2809
|
});
|
|
2734
2810
|
}
|
|
2735
2811
|
} else {
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2812
|
+
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2813
|
+
resizableColumns.forEach((col) => {
|
|
2814
|
+
api.exec("resize-column", {
|
|
2815
|
+
id: col.id,
|
|
2816
|
+
width: equalWidth
|
|
2817
|
+
});
|
|
2818
|
+
});
|
|
2740
2819
|
}
|
|
2741
2820
|
}, [resolvedColumns, data]);
|
|
2821
|
+
useEffect9(() => {
|
|
2822
|
+
if (!containerRef.current) return;
|
|
2823
|
+
const observer = new ResizeObserver(() => resizeColumns());
|
|
2824
|
+
observer.observe(containerRef.current);
|
|
2825
|
+
return () => observer.disconnect();
|
|
2826
|
+
}, [resizeColumns]);
|
|
2742
2827
|
const init = useCallback2(
|
|
2743
2828
|
(api) => {
|
|
2744
2829
|
apiRef.current = api;
|
|
2745
2830
|
resizeColumns();
|
|
2746
2831
|
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
2832
|
},
|
|
2756
|
-
[resizeColumns, onFocusCell
|
|
2833
|
+
[resizeColumns, onFocusCell]
|
|
2757
2834
|
);
|
|
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]);
|
|
2835
|
+
const getSelectedData = () => {
|
|
2836
|
+
var _a3, _b2;
|
|
2837
|
+
const selected = (_b2 = (_a3 = apiRef.current) == null ? void 0 : _a3.getState().selectedRows) != null ? _b2 : [];
|
|
2838
|
+
return data.filter((row) => selected.includes(row.id));
|
|
2839
|
+
};
|
|
2780
2840
|
const handleExportPdf = useCallback2(() => {
|
|
2781
2841
|
const selected = getSelectedData();
|
|
2782
2842
|
if (selected.length) exportPdf(selected, fileName);
|
|
2783
2843
|
else onExportPdf == null ? void 0 : onExportPdf();
|
|
2784
|
-
}, [
|
|
2844
|
+
}, [data, fileName, onExportPdf]);
|
|
2785
2845
|
const handleExportExcel = useCallback2(() => {
|
|
2786
2846
|
const selected = getSelectedData();
|
|
2787
2847
|
if (selected.length) exportExcel(selected, fileName);
|
|
2788
2848
|
else onExportExcel == null ? void 0 : onExportExcel();
|
|
2789
|
-
}, [
|
|
2849
|
+
}, [data, fileName, onExportExcel]);
|
|
2790
2850
|
return /* @__PURE__ */ jsxs20("div", { className: "w-full h-full flex flex-col overflow-hidden", children: [
|
|
2791
2851
|
/* @__PURE__ */ jsx28(
|
|
2792
2852
|
gridHeader_default,
|
|
@@ -2801,11 +2861,11 @@ var Grid = forwardRef(
|
|
|
2801
2861
|
filterList: rest.filterList,
|
|
2802
2862
|
onFilterChange,
|
|
2803
2863
|
initialFilters,
|
|
2804
|
-
selectedCount
|
|
2805
|
-
selectedData
|
|
2864
|
+
selectedCount,
|
|
2865
|
+
selectedData,
|
|
2806
2866
|
selectionActions,
|
|
2807
2867
|
onSelectionAction,
|
|
2808
|
-
onClearSelection
|
|
2868
|
+
onClearSelection,
|
|
2809
2869
|
children
|
|
2810
2870
|
}
|
|
2811
2871
|
),
|
|
@@ -2820,6 +2880,7 @@ var Grid = forwardRef(
|
|
|
2820
2880
|
data,
|
|
2821
2881
|
columns: resolvedColumns,
|
|
2822
2882
|
init,
|
|
2883
|
+
selectedRows: selectionEnabled ? selectedIds : void 0,
|
|
2823
2884
|
select: selectionEnabled ? false : rest.select
|
|
2824
2885
|
})
|
|
2825
2886
|
) }) })
|
|
@@ -2989,7 +3050,7 @@ var pagination_default = Pagination;
|
|
|
2989
3050
|
|
|
2990
3051
|
// src/components/custom/toolbar/index.tsx
|
|
2991
3052
|
import { ChevronRight as ChevronRight4, X as X5 } from "lucide-react";
|
|
2992
|
-
import { useState as
|
|
3053
|
+
import { useState as useState9, useRef as useRef6, useEffect as useEffect10 } from "react";
|
|
2993
3054
|
import { Fragment as Fragment4, jsx as jsx31, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
2994
3055
|
var SlideToolbar = ({
|
|
2995
3056
|
items,
|
|
@@ -3002,8 +3063,8 @@ var SlideToolbar = ({
|
|
|
3002
3063
|
className = ""
|
|
3003
3064
|
}) => {
|
|
3004
3065
|
const resolvedItems = items != null ? items : children ? void 0 : [];
|
|
3005
|
-
const [open, setOpen] =
|
|
3006
|
-
const panelRef =
|
|
3066
|
+
const [open, setOpen] = useState9(false);
|
|
3067
|
+
const panelRef = useRef6(null);
|
|
3007
3068
|
useEffect10(() => {
|
|
3008
3069
|
if (!open || !closeOnBackdrop) return;
|
|
3009
3070
|
const handlePointerDown = (e) => {
|