baaz-custom-components 5.2.2 → 5.2.4
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 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +46 -13
- package/dist/index.mjs +46 -13
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -105,6 +105,7 @@ type GridProps = {
|
|
|
105
105
|
filterList: Filters[];
|
|
106
106
|
initialFilters?: any[];
|
|
107
107
|
children?: React.ReactNode;
|
|
108
|
+
onRowClick?: (row: AnyRow) => void;
|
|
108
109
|
onSortChange?: (key: string, order: SortOrder) => void;
|
|
109
110
|
onExportPdf?: () => void;
|
|
110
111
|
onExportExcel?: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ type GridProps = {
|
|
|
105
105
|
filterList: Filters[];
|
|
106
106
|
initialFilters?: any[];
|
|
107
107
|
children?: React.ReactNode;
|
|
108
|
+
onRowClick?: (row: AnyRow) => void;
|
|
108
109
|
onSortChange?: (key: string, order: SortOrder) => void;
|
|
109
110
|
onExportPdf?: () => void;
|
|
110
111
|
onExportExcel?: () => void;
|
package/dist/index.js
CHANGED
|
@@ -2412,7 +2412,6 @@ function GridHeader({
|
|
|
2412
2412
|
onSelectionAction,
|
|
2413
2413
|
onClearSelection
|
|
2414
2414
|
}) {
|
|
2415
|
-
console.log("GridHeader rendered");
|
|
2416
2415
|
const [downloadMenu, setDownloadMenu] = (0, import_react6.useState)(false);
|
|
2417
2416
|
const [searchOpen, setSearchOpen] = (0, import_react6.useState)(false);
|
|
2418
2417
|
const downloadRef = (0, import_react6.useRef)(null);
|
|
@@ -2573,7 +2572,6 @@ function useStore(store, name) {
|
|
|
2573
2572
|
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2574
2573
|
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2575
2574
|
var CheckboxCell = ({ row, api, column }) => {
|
|
2576
|
-
console.log("CheckboxCell rendered");
|
|
2577
2575
|
const selectedRows = useStore(api, "selectedRows");
|
|
2578
2576
|
const isSelected = selectedRows.includes(row.id);
|
|
2579
2577
|
const handleChange = (e) => {
|
|
@@ -2614,13 +2612,14 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2614
2612
|
const computeState = () => {
|
|
2615
2613
|
var _a2, _b, _c;
|
|
2616
2614
|
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2615
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2617
2616
|
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2618
|
-
const selectedOnPage =
|
|
2617
|
+
const selectedOnPage = dataArray.filter(
|
|
2619
2618
|
(r) => selectedRows.includes(r.id)
|
|
2620
2619
|
).length;
|
|
2621
2620
|
return {
|
|
2622
|
-
allSelected:
|
|
2623
|
-
someSelected: selectedOnPage > 0 && selectedOnPage <
|
|
2621
|
+
allSelected: dataArray.length > 0 && selectedOnPage === dataArray.length,
|
|
2622
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < dataArray.length
|
|
2624
2623
|
};
|
|
2625
2624
|
};
|
|
2626
2625
|
const [, forceUpdate] = (0, import_react9.useReducer)((x) => x + 1, 0);
|
|
@@ -2648,10 +2647,11 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2648
2647
|
e.stopPropagation();
|
|
2649
2648
|
const isChecked = e.target.checked;
|
|
2650
2649
|
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2651
|
-
|
|
2650
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2651
|
+
dataArray.forEach((row) => {
|
|
2652
2652
|
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2653
2653
|
});
|
|
2654
|
-
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c,
|
|
2654
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, dataArray, isChecked);
|
|
2655
2655
|
};
|
|
2656
2656
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2657
2657
|
"div",
|
|
@@ -2700,6 +2700,15 @@ function buildCheckboxColumn({
|
|
|
2700
2700
|
|
|
2701
2701
|
// src/components/custom/grid/index.tsx
|
|
2702
2702
|
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2703
|
+
var _measureCanvas = typeof window !== "undefined" ? document.createElement("canvas") : null;
|
|
2704
|
+
function measureHeaderTextWidth(text) {
|
|
2705
|
+
if (!_measureCanvas) return 0;
|
|
2706
|
+
const ctx = _measureCanvas.getContext("2d");
|
|
2707
|
+
if (!ctx) return 0;
|
|
2708
|
+
ctx.font = "500 13px Inter, ui-sans-serif, system-ui, sans-serif";
|
|
2709
|
+
const textWidth = ctx.measureText(text).width;
|
|
2710
|
+
return Math.ceil(textWidth) + 64;
|
|
2711
|
+
}
|
|
2703
2712
|
var Grid = (0, import_react10.forwardRef)(
|
|
2704
2713
|
(_a, ref) => {
|
|
2705
2714
|
var _b = _a, {
|
|
@@ -2725,7 +2734,8 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2725
2734
|
selectedData,
|
|
2726
2735
|
selectionActions,
|
|
2727
2736
|
onSelectionAction,
|
|
2728
|
-
onClearSelection
|
|
2737
|
+
onClearSelection,
|
|
2738
|
+
onRowClick
|
|
2729
2739
|
} = _b, rest = __objRest(_b, [
|
|
2730
2740
|
"data",
|
|
2731
2741
|
"columns",
|
|
@@ -2749,10 +2759,10 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2749
2759
|
"selectedData",
|
|
2750
2760
|
"selectionActions",
|
|
2751
2761
|
"onSelectionAction",
|
|
2752
|
-
"onClearSelection"
|
|
2762
|
+
"onClearSelection",
|
|
2763
|
+
"onRowClick"
|
|
2753
2764
|
]);
|
|
2754
2765
|
var _a2;
|
|
2755
|
-
console.log("Grid rendered");
|
|
2756
2766
|
const apiRef = (0, import_react10.useRef)(null);
|
|
2757
2767
|
const containerRef = (0, import_react10.useRef)(null);
|
|
2758
2768
|
const dataRef = (0, import_react10.useRef)(data);
|
|
@@ -2767,6 +2777,10 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2767
2777
|
(0, import_react10.useEffect)(() => {
|
|
2768
2778
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2769
2779
|
}, [onSelectAllPage]);
|
|
2780
|
+
const onRowClickRef = (0, import_react10.useRef)(onRowClick);
|
|
2781
|
+
(0, import_react10.useEffect)(() => {
|
|
2782
|
+
onRowClickRef.current = onRowClick;
|
|
2783
|
+
}, [onRowClick]);
|
|
2770
2784
|
(0, import_react10.useImperativeHandle)(ref, () => apiRef.current, []);
|
|
2771
2785
|
const clearTokenRef = (0, import_react10.useRef)(0);
|
|
2772
2786
|
const prevSelectedCountRef = (0, import_react10.useRef)(selectedCount != null ? selectedCount : 0);
|
|
@@ -2817,6 +2831,17 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2817
2831
|
resizableColumns.forEach((col) => {
|
|
2818
2832
|
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2819
2833
|
});
|
|
2834
|
+
resizableColumns.forEach((col) => {
|
|
2835
|
+
var _a3, _b2, _c, _d, _e, _f, _g;
|
|
2836
|
+
const headerText = (_f = (_e = (_d = (_a3 = col == null ? void 0 : col.header) == null ? void 0 : _a3.text) != null ? _d : (_c = (_b2 = col == null ? void 0 : col.header) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) != null ? _e : col == null ? void 0 : col.text) != null ? _f : "";
|
|
2837
|
+
if (!headerText) return;
|
|
2838
|
+
const minWidth = measureHeaderTextWidth(headerText);
|
|
2839
|
+
const column = api.getColumn(col.id);
|
|
2840
|
+
const currentWidth = (_g = column == null ? void 0 : column.width) != null ? _g : 0;
|
|
2841
|
+
if (!isNaN(currentWidth) && currentWidth < minWidth) {
|
|
2842
|
+
api.exec("resize-column", { id: col.id, width: minWidth });
|
|
2843
|
+
}
|
|
2844
|
+
});
|
|
2820
2845
|
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2821
2846
|
var _a3;
|
|
2822
2847
|
const column = api.getColumn(col.id);
|
|
@@ -2840,9 +2865,12 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2840
2865
|
} else {
|
|
2841
2866
|
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2842
2867
|
resizableColumns.forEach((col) => {
|
|
2868
|
+
var _a3, _b2, _c, _d, _e, _f;
|
|
2869
|
+
const headerText = (_f = (_e = (_d = (_a3 = col == null ? void 0 : col.header) == null ? void 0 : _a3.text) != null ? _d : (_c = (_b2 = col == null ? void 0 : col.header) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) != null ? _e : col == null ? void 0 : col.text) != null ? _f : "";
|
|
2870
|
+
const minWidth = headerText ? measureHeaderTextWidth(headerText) : 0;
|
|
2843
2871
|
api.exec("resize-column", {
|
|
2844
2872
|
id: col.id,
|
|
2845
|
-
width: equalWidth
|
|
2873
|
+
width: Math.max(equalWidth, minWidth)
|
|
2846
2874
|
});
|
|
2847
2875
|
});
|
|
2848
2876
|
}
|
|
@@ -2858,6 +2886,12 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2858
2886
|
apiRef.current = api;
|
|
2859
2887
|
resizeColumns();
|
|
2860
2888
|
api.intercept("focus-cell", onFocusCell);
|
|
2889
|
+
api.on("select-row", (ev) => {
|
|
2890
|
+
const handler = onRowClickRef.current;
|
|
2891
|
+
if (!handler) return;
|
|
2892
|
+
const row = api.getRow(ev.id);
|
|
2893
|
+
handler(row);
|
|
2894
|
+
});
|
|
2861
2895
|
},
|
|
2862
2896
|
[resizeColumns, onFocusCell]
|
|
2863
2897
|
);
|
|
@@ -2909,8 +2943,7 @@ var Grid = (0, import_react10.forwardRef)(
|
|
|
2909
2943
|
data,
|
|
2910
2944
|
columns: resolvedColumns,
|
|
2911
2945
|
init,
|
|
2912
|
-
selectedRows: selectionEnabled ? selectedIds : void 0
|
|
2913
|
-
select: selectionEnabled ? false : rest.select
|
|
2946
|
+
selectedRows: selectionEnabled ? selectedIds : void 0
|
|
2914
2947
|
})
|
|
2915
2948
|
) }) })
|
|
2916
2949
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -2381,7 +2381,6 @@ function GridHeader({
|
|
|
2381
2381
|
onSelectionAction,
|
|
2382
2382
|
onClearSelection
|
|
2383
2383
|
}) {
|
|
2384
|
-
console.log("GridHeader rendered");
|
|
2385
2384
|
const [downloadMenu, setDownloadMenu] = useState7(false);
|
|
2386
2385
|
const [searchOpen, setSearchOpen] = useState7(false);
|
|
2387
2386
|
const downloadRef = useRef2(null);
|
|
@@ -2542,7 +2541,6 @@ function useStore(store, name) {
|
|
|
2542
2541
|
// src/components/custom/grid/checkboxCell/checkBoxCell.tsx
|
|
2543
2542
|
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
2544
2543
|
var CheckboxCell = ({ row, api, column }) => {
|
|
2545
|
-
console.log("CheckboxCell rendered");
|
|
2546
2544
|
const selectedRows = useStore(api, "selectedRows");
|
|
2547
2545
|
const isSelected = selectedRows.includes(row.id);
|
|
2548
2546
|
const handleChange = (e) => {
|
|
@@ -2583,13 +2581,14 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2583
2581
|
const computeState = () => {
|
|
2584
2582
|
var _a2, _b, _c;
|
|
2585
2583
|
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2584
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2586
2585
|
const selectedRows = (_c = api.getState().selectedRows) != null ? _c : [];
|
|
2587
|
-
const selectedOnPage =
|
|
2586
|
+
const selectedOnPage = dataArray.filter(
|
|
2588
2587
|
(r) => selectedRows.includes(r.id)
|
|
2589
2588
|
).length;
|
|
2590
2589
|
return {
|
|
2591
|
-
allSelected:
|
|
2592
|
-
someSelected: selectedOnPage > 0 && selectedOnPage <
|
|
2590
|
+
allSelected: dataArray.length > 0 && selectedOnPage === dataArray.length,
|
|
2591
|
+
someSelected: selectedOnPage > 0 && selectedOnPage < dataArray.length
|
|
2593
2592
|
};
|
|
2594
2593
|
};
|
|
2595
2594
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
@@ -2617,10 +2616,11 @@ var HeaderCheckbox = ({ api, column }) => {
|
|
|
2617
2616
|
e.stopPropagation();
|
|
2618
2617
|
const isChecked = e.target.checked;
|
|
2619
2618
|
const pageData = (_b = (_a2 = column == null ? void 0 : column.config) == null ? void 0 : _a2.getPageData()) != null ? _b : [];
|
|
2620
|
-
|
|
2619
|
+
const dataArray = Array.isArray(pageData) ? pageData : [];
|
|
2620
|
+
dataArray.forEach((row) => {
|
|
2621
2621
|
api.exec("select-row", { id: row.id, mode: isChecked, toggle: true });
|
|
2622
2622
|
});
|
|
2623
|
-
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c,
|
|
2623
|
+
(_d = (_c = column == null ? void 0 : column.config) == null ? void 0 : _c.onSelectAllPage) == null ? void 0 : _d.call(_c, dataArray, isChecked);
|
|
2624
2624
|
};
|
|
2625
2625
|
return /* @__PURE__ */ jsx27(
|
|
2626
2626
|
"div",
|
|
@@ -2669,6 +2669,15 @@ function buildCheckboxColumn({
|
|
|
2669
2669
|
|
|
2670
2670
|
// src/components/custom/grid/index.tsx
|
|
2671
2671
|
import { jsx as jsx28, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
2672
|
+
var _measureCanvas = typeof window !== "undefined" ? document.createElement("canvas") : null;
|
|
2673
|
+
function measureHeaderTextWidth(text) {
|
|
2674
|
+
if (!_measureCanvas) return 0;
|
|
2675
|
+
const ctx = _measureCanvas.getContext("2d");
|
|
2676
|
+
if (!ctx) return 0;
|
|
2677
|
+
ctx.font = "500 13px Inter, ui-sans-serif, system-ui, sans-serif";
|
|
2678
|
+
const textWidth = ctx.measureText(text).width;
|
|
2679
|
+
return Math.ceil(textWidth) + 64;
|
|
2680
|
+
}
|
|
2672
2681
|
var Grid = forwardRef(
|
|
2673
2682
|
(_a, ref) => {
|
|
2674
2683
|
var _b = _a, {
|
|
@@ -2694,7 +2703,8 @@ var Grid = forwardRef(
|
|
|
2694
2703
|
selectedData,
|
|
2695
2704
|
selectionActions,
|
|
2696
2705
|
onSelectionAction,
|
|
2697
|
-
onClearSelection
|
|
2706
|
+
onClearSelection,
|
|
2707
|
+
onRowClick
|
|
2698
2708
|
} = _b, rest = __objRest(_b, [
|
|
2699
2709
|
"data",
|
|
2700
2710
|
"columns",
|
|
@@ -2718,10 +2728,10 @@ var Grid = forwardRef(
|
|
|
2718
2728
|
"selectedData",
|
|
2719
2729
|
"selectionActions",
|
|
2720
2730
|
"onSelectionAction",
|
|
2721
|
-
"onClearSelection"
|
|
2731
|
+
"onClearSelection",
|
|
2732
|
+
"onRowClick"
|
|
2722
2733
|
]);
|
|
2723
2734
|
var _a2;
|
|
2724
|
-
console.log("Grid rendered");
|
|
2725
2735
|
const apiRef = useRef5(null);
|
|
2726
2736
|
const containerRef = useRef5(null);
|
|
2727
2737
|
const dataRef = useRef5(data);
|
|
@@ -2736,6 +2746,10 @@ var Grid = forwardRef(
|
|
|
2736
2746
|
useEffect9(() => {
|
|
2737
2747
|
onSelectAllPageRef.current = onSelectAllPage;
|
|
2738
2748
|
}, [onSelectAllPage]);
|
|
2749
|
+
const onRowClickRef = useRef5(onRowClick);
|
|
2750
|
+
useEffect9(() => {
|
|
2751
|
+
onRowClickRef.current = onRowClick;
|
|
2752
|
+
}, [onRowClick]);
|
|
2739
2753
|
useImperativeHandle(ref, () => apiRef.current, []);
|
|
2740
2754
|
const clearTokenRef = useRef5(0);
|
|
2741
2755
|
const prevSelectedCountRef = useRef5(selectedCount != null ? selectedCount : 0);
|
|
@@ -2786,6 +2800,17 @@ var Grid = forwardRef(
|
|
|
2786
2800
|
resizableColumns.forEach((col) => {
|
|
2787
2801
|
api.exec("resize-column", { id: col.id, auto: "data" });
|
|
2788
2802
|
});
|
|
2803
|
+
resizableColumns.forEach((col) => {
|
|
2804
|
+
var _a3, _b2, _c, _d, _e, _f, _g;
|
|
2805
|
+
const headerText = (_f = (_e = (_d = (_a3 = col == null ? void 0 : col.header) == null ? void 0 : _a3.text) != null ? _d : (_c = (_b2 = col == null ? void 0 : col.header) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) != null ? _e : col == null ? void 0 : col.text) != null ? _f : "";
|
|
2806
|
+
if (!headerText) return;
|
|
2807
|
+
const minWidth = measureHeaderTextWidth(headerText);
|
|
2808
|
+
const column = api.getColumn(col.id);
|
|
2809
|
+
const currentWidth = (_g = column == null ? void 0 : column.width) != null ? _g : 0;
|
|
2810
|
+
if (!isNaN(currentWidth) && currentWidth < minWidth) {
|
|
2811
|
+
api.exec("resize-column", { id: col.id, width: minWidth });
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2789
2814
|
const totalAutoWidth = resizableColumns.reduce((sum, col) => {
|
|
2790
2815
|
var _a3;
|
|
2791
2816
|
const column = api.getColumn(col.id);
|
|
@@ -2809,9 +2834,12 @@ var Grid = forwardRef(
|
|
|
2809
2834
|
} else {
|
|
2810
2835
|
const equalWidth = resizableColumns.length > 0 ? availableWidth / resizableColumns.length : 0;
|
|
2811
2836
|
resizableColumns.forEach((col) => {
|
|
2837
|
+
var _a3, _b2, _c, _d, _e, _f;
|
|
2838
|
+
const headerText = (_f = (_e = (_d = (_a3 = col == null ? void 0 : col.header) == null ? void 0 : _a3.text) != null ? _d : (_c = (_b2 = col == null ? void 0 : col.header) == null ? void 0 : _b2[0]) == null ? void 0 : _c.text) != null ? _e : col == null ? void 0 : col.text) != null ? _f : "";
|
|
2839
|
+
const minWidth = headerText ? measureHeaderTextWidth(headerText) : 0;
|
|
2812
2840
|
api.exec("resize-column", {
|
|
2813
2841
|
id: col.id,
|
|
2814
|
-
width: equalWidth
|
|
2842
|
+
width: Math.max(equalWidth, minWidth)
|
|
2815
2843
|
});
|
|
2816
2844
|
});
|
|
2817
2845
|
}
|
|
@@ -2827,6 +2855,12 @@ var Grid = forwardRef(
|
|
|
2827
2855
|
apiRef.current = api;
|
|
2828
2856
|
resizeColumns();
|
|
2829
2857
|
api.intercept("focus-cell", onFocusCell);
|
|
2858
|
+
api.on("select-row", (ev) => {
|
|
2859
|
+
const handler = onRowClickRef.current;
|
|
2860
|
+
if (!handler) return;
|
|
2861
|
+
const row = api.getRow(ev.id);
|
|
2862
|
+
handler(row);
|
|
2863
|
+
});
|
|
2830
2864
|
},
|
|
2831
2865
|
[resizeColumns, onFocusCell]
|
|
2832
2866
|
);
|
|
@@ -2878,8 +2912,7 @@ var Grid = forwardRef(
|
|
|
2878
2912
|
data,
|
|
2879
2913
|
columns: resolvedColumns,
|
|
2880
2914
|
init,
|
|
2881
|
-
selectedRows: selectionEnabled ? selectedIds : void 0
|
|
2882
|
-
select: selectionEnabled ? false : rest.select
|
|
2915
|
+
selectedRows: selectionEnabled ? selectedIds : void 0
|
|
2883
2916
|
})
|
|
2884
2917
|
) }) })
|
|
2885
2918
|
}
|