trotl-table 1.0.71 → 1.0.73
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/Table.cjs.js +108 -29
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +108 -29
- package/dist/Table.esm.js.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/package.json +1 -1
package/dist/Table.cjs.js
CHANGED
|
@@ -9787,6 +9787,82 @@ function TableInner({
|
|
|
9787
9787
|
|
|
9788
9788
|
// Local selection & sorting state (removed TableContext dependency)
|
|
9789
9789
|
const [selectedRows, setSelectedRows] = React.useState(() => resolvedInitialSelectedRows);
|
|
9790
|
+
const [columnWidths, setColumnWidths] = React.useState(() => ({}));
|
|
9791
|
+
const columnResizeRef = React.useRef(null);
|
|
9792
|
+
const getColumnKey = React.useCallback((col, index) => {
|
|
9793
|
+
if (col?.key != null) return `col-${String(col.key)}`;
|
|
9794
|
+
if (col?.accessor != null && (typeof col.accessor === "string" || typeof col.accessor === "number")) {
|
|
9795
|
+
return `col-${String(col.accessor)}`;
|
|
9796
|
+
}
|
|
9797
|
+
return `col-${index}`;
|
|
9798
|
+
}, []);
|
|
9799
|
+
const getCellStyle = React.useCallback((col, index) => {
|
|
9800
|
+
const key = getColumnKey(col, index);
|
|
9801
|
+
const width = columnWidths[key] ?? col?.style?.width;
|
|
9802
|
+
const baseStyle = col?.style ? {
|
|
9803
|
+
...col.style
|
|
9804
|
+
} : {};
|
|
9805
|
+
if (width) {
|
|
9806
|
+
return {
|
|
9807
|
+
...baseStyle,
|
|
9808
|
+
flex: "0 0 auto",
|
|
9809
|
+
width,
|
|
9810
|
+
minWidth: width,
|
|
9811
|
+
maxWidth: width
|
|
9812
|
+
};
|
|
9813
|
+
}
|
|
9814
|
+
return {
|
|
9815
|
+
...baseStyle,
|
|
9816
|
+
flex: "1 1 0%"
|
|
9817
|
+
};
|
|
9818
|
+
}, [columnWidths, getColumnKey]);
|
|
9819
|
+
const updateColumnWidth = React.useCallback((key, nextWidth) => {
|
|
9820
|
+
setColumnWidths(prev => ({
|
|
9821
|
+
...prev,
|
|
9822
|
+
[key]: `${Math.max(60, Math.round(nextWidth))}px`
|
|
9823
|
+
}));
|
|
9824
|
+
}, []);
|
|
9825
|
+
const handleDocumentMouseMove = React.useCallback(event => {
|
|
9826
|
+
const state = columnResizeRef.current;
|
|
9827
|
+
if (!state) return;
|
|
9828
|
+
const delta = event.clientX - state.startX;
|
|
9829
|
+
updateColumnWidth(state.key, state.startWidth + delta);
|
|
9830
|
+
}, [updateColumnWidth]);
|
|
9831
|
+
const stopColumnResize = React.useCallback(() => {
|
|
9832
|
+
if (!columnResizeRef.current) return;
|
|
9833
|
+
columnResizeRef.current = null;
|
|
9834
|
+
document.removeEventListener("mousemove", handleDocumentMouseMove);
|
|
9835
|
+
document.removeEventListener("mouseup", stopColumnResize);
|
|
9836
|
+
document.body.style.cursor = "";
|
|
9837
|
+
document.body.style.userSelect = "";
|
|
9838
|
+
}, [handleDocumentMouseMove]);
|
|
9839
|
+
const startColumnResize = React.useCallback((event, col, index) => {
|
|
9840
|
+
event.preventDefault();
|
|
9841
|
+
event.stopPropagation();
|
|
9842
|
+
const key = getColumnKey(col, index);
|
|
9843
|
+
const headerCell = event.currentTarget.parentElement;
|
|
9844
|
+
const startWidth = headerCell?.getBoundingClientRect().width || 120;
|
|
9845
|
+
columnResizeRef.current = {
|
|
9846
|
+
key,
|
|
9847
|
+
startX: event.clientX,
|
|
9848
|
+
startWidth
|
|
9849
|
+
};
|
|
9850
|
+
document.addEventListener("mousemove", handleDocumentMouseMove);
|
|
9851
|
+
document.addEventListener("mouseup", stopColumnResize);
|
|
9852
|
+
document.body.style.cursor = "col-resize";
|
|
9853
|
+
document.body.style.userSelect = "none";
|
|
9854
|
+
}, [getColumnKey, handleDocumentMouseMove, stopColumnResize]);
|
|
9855
|
+
React.useEffect(() => {
|
|
9856
|
+
return () => {
|
|
9857
|
+
if (columnResizeRef.current) {
|
|
9858
|
+
document.removeEventListener("mousemove", handleDocumentMouseMove);
|
|
9859
|
+
document.removeEventListener("mouseup", stopColumnResize);
|
|
9860
|
+
document.body.style.cursor = "";
|
|
9861
|
+
document.body.style.userSelect = "";
|
|
9862
|
+
columnResizeRef.current = null;
|
|
9863
|
+
}
|
|
9864
|
+
};
|
|
9865
|
+
}, [handleDocumentMouseMove, stopColumnResize]);
|
|
9790
9866
|
const [sorting, setSorting] = React.useState(null);
|
|
9791
9867
|
|
|
9792
9868
|
// Initialize localData early so it's available for the sync effect below
|
|
@@ -10337,11 +10413,12 @@ function TableInner({
|
|
|
10337
10413
|
}
|
|
10338
10414
|
}, [getAccessorKey, getAccessorValue]);
|
|
10339
10415
|
const renderCell = React.useCallback((v, accessor, row, col) => {
|
|
10340
|
-
const
|
|
10416
|
+
const isUndefinedLike = v === undefined || typeof v === "string" && v.trim().toLowerCase() === "undefined";
|
|
10417
|
+
const isNoData = isUndefinedLike;
|
|
10341
10418
|
|
|
10342
10419
|
// Checkbox column type (editable in-table)
|
|
10343
10420
|
if (col && col.type === 'checkbox') {
|
|
10344
|
-
const checked = !!v;
|
|
10421
|
+
const checked = isUndefinedLike ? false : !!v;
|
|
10345
10422
|
return /*#__PURE__*/React.createElement("input", {
|
|
10346
10423
|
type: "checkbox",
|
|
10347
10424
|
checked: checked,
|
|
@@ -10379,7 +10456,7 @@ function TableInner({
|
|
|
10379
10456
|
|
|
10380
10457
|
// Switch column type (uses internal Switch component)
|
|
10381
10458
|
if (col && col.type === 'switch') {
|
|
10382
|
-
const checked = !!v;
|
|
10459
|
+
const checked = isUndefinedLike ? false : !!v;
|
|
10383
10460
|
return /*#__PURE__*/React.createElement("div", {
|
|
10384
10461
|
title: isNoData ? translate("noData") : undefined,
|
|
10385
10462
|
onClick: e => {
|
|
@@ -10417,8 +10494,8 @@ function TableInner({
|
|
|
10417
10494
|
|
|
10418
10495
|
// Color column type (display color swatch background)
|
|
10419
10496
|
if (col && col.type === 'color') {
|
|
10420
|
-
const colorVal = v || "transparent";
|
|
10421
|
-
const text = String(colorVal) ;
|
|
10497
|
+
const colorVal = isUndefinedLike ? "transparent" : v || "transparent";
|
|
10498
|
+
const text = isUndefinedLike ? "..." : String(colorVal) ;
|
|
10422
10499
|
return /*#__PURE__*/React.createElement("div", {
|
|
10423
10500
|
style: {
|
|
10424
10501
|
width: '100%',
|
|
@@ -10560,6 +10637,23 @@ function TableInner({
|
|
|
10560
10637
|
minute: "2-digit"
|
|
10561
10638
|
}) : "-";
|
|
10562
10639
|
}
|
|
10640
|
+
if (isUndefinedLike) {
|
|
10641
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
10642
|
+
title: translate("noData")
|
|
10643
|
+
}, "...");
|
|
10644
|
+
}
|
|
10645
|
+
if (typeof v === "boolean") {
|
|
10646
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
10647
|
+
title: String(v),
|
|
10648
|
+
style: {
|
|
10649
|
+
color: v ? "#1a7f37" : "#b42318",
|
|
10650
|
+
fontWeight: 700,
|
|
10651
|
+
display: "inline-block",
|
|
10652
|
+
minWidth: "1ch",
|
|
10653
|
+
textAlign: "center"
|
|
10654
|
+
}
|
|
10655
|
+
}, v ? "✓" : "✗");
|
|
10656
|
+
}
|
|
10563
10657
|
// existing highlight logic for other fields
|
|
10564
10658
|
return highlight(String(v));
|
|
10565
10659
|
}, [highlight, isGrouped, triggerCellCallback, translate, formatArrayValue]);
|
|
@@ -10912,15 +11006,7 @@ function TableInner({
|
|
|
10912
11006
|
}, visualIndex), allColumns.map((col, i) => {
|
|
10913
11007
|
const resolvedAccessor = getAccessorKey(row, col.accessor);
|
|
10914
11008
|
const cellValue = getAccessorValue(row, col.accessor);
|
|
10915
|
-
|
|
10916
|
-
...col.style
|
|
10917
|
-
} : undefined;
|
|
10918
|
-
if (col.style && col.style.width) {
|
|
10919
|
-
cellStyle = cellStyle || {};
|
|
10920
|
-
cellStyle.minWidth = col.style.width;
|
|
10921
|
-
cellStyle.maxWidth = col.style.width;
|
|
10922
|
-
cellStyle.width = col.style.width;
|
|
10923
|
-
}
|
|
11009
|
+
const cellStyle = getCellStyle(col, i);
|
|
10924
11010
|
return /*#__PURE__*/React.createElement("div", {
|
|
10925
11011
|
key: i,
|
|
10926
11012
|
className: "table-cell",
|
|
@@ -11000,7 +11086,7 @@ function TableInner({
|
|
|
11000
11086
|
}, content);
|
|
11001
11087
|
}
|
|
11002
11088
|
return content;
|
|
11003
|
-
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, translate, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns, doubleClickEnable, keyWidth, actionColumnStyle, showDuplicate, showDownload, showIcons, showShare, triggerCellCallback, getAccessorKey, getAccessorValue]);
|
|
11089
|
+
}, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, getCellStyle, showActions, showDelete, showEdit, showKey, showView, translate, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns, doubleClickEnable, keyWidth, actionColumnStyle, showDuplicate, showDownload, showIcons, showShare, triggerCellCallback, getAccessorKey, getAccessorValue]);
|
|
11004
11090
|
const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
|
|
11005
11091
|
const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
|
|
11006
11092
|
const rowHeightGetter = ({
|
|
@@ -11081,27 +11167,20 @@ function TableInner({
|
|
|
11081
11167
|
maxWidth: keyWidth
|
|
11082
11168
|
} : undefined
|
|
11083
11169
|
}, "#"), allColumns.map((col, i) => {
|
|
11084
|
-
|
|
11085
|
-
...col.style,
|
|
11086
|
-
cursor: col.isCustom ? undefined : "pointer"
|
|
11087
|
-
} : {
|
|
11088
|
-
cursor: col.isCustom ? undefined : "pointer"
|
|
11089
|
-
};
|
|
11090
|
-
if (col.style && col.style.width) {
|
|
11091
|
-
cellStyle.minWidth = col.style.width;
|
|
11092
|
-
cellStyle.maxWidth = col.style.width;
|
|
11093
|
-
cellStyle.width = col.style.width;
|
|
11094
|
-
}
|
|
11170
|
+
const cellStyle = getCellStyle(col, i);
|
|
11095
11171
|
const translatedHeader = typeof col.header === "string" ? translate(col.header) : col.header;
|
|
11096
|
-
// Keep tooltip text in sync with rendered header when it's a string.
|
|
11097
11172
|
const headerTitle = typeof translatedHeader === "string" ? translatedHeader : undefined;
|
|
11098
11173
|
return /*#__PURE__*/React.createElement("div", {
|
|
11099
11174
|
key: i,
|
|
11100
|
-
className: "table-cell",
|
|
11175
|
+
className: "table-cell header-cell",
|
|
11101
11176
|
style: cellStyle,
|
|
11102
11177
|
title: headerTitle,
|
|
11103
11178
|
onClick: col.isCustom ? undefined : () => setSort(col.accessor)
|
|
11104
|
-
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓")
|
|
11179
|
+
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"), /*#__PURE__*/React.createElement("div", {
|
|
11180
|
+
className: "column-resizer",
|
|
11181
|
+
onMouseDown: event => startColumnResize(event, col, i),
|
|
11182
|
+
onClick: event => event.stopPropagation()
|
|
11183
|
+
}));
|
|
11105
11184
|
}), showActions && /*#__PURE__*/React.createElement("div", {
|
|
11106
11185
|
className: "table-cell action-cell",
|
|
11107
11186
|
style: actionColumnStyle,
|