trotl-table 1.0.71 → 1.0.72

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 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
@@ -10912,15 +10988,7 @@ function TableInner({
10912
10988
  }, visualIndex), allColumns.map((col, i) => {
10913
10989
  const resolvedAccessor = getAccessorKey(row, col.accessor);
10914
10990
  const cellValue = getAccessorValue(row, col.accessor);
10915
- let cellStyle = col.style ? {
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
- }
10991
+ const cellStyle = getCellStyle(col, i);
10924
10992
  return /*#__PURE__*/React.createElement("div", {
10925
10993
  key: i,
10926
10994
  className: "table-cell",
@@ -11000,7 +11068,7 @@ function TableInner({
11000
11068
  }, content);
11001
11069
  }
11002
11070
  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]);
11071
+ }, [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
11072
  const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
11005
11073
  const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
11006
11074
  const rowHeightGetter = ({
@@ -11081,27 +11149,20 @@ function TableInner({
11081
11149
  maxWidth: keyWidth
11082
11150
  } : undefined
11083
11151
  }, "#"), allColumns.map((col, i) => {
11084
- let cellStyle = col.style ? {
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
- }
11152
+ const cellStyle = getCellStyle(col, i);
11095
11153
  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
11154
  const headerTitle = typeof translatedHeader === "string" ? translatedHeader : undefined;
11098
11155
  return /*#__PURE__*/React.createElement("div", {
11099
11156
  key: i,
11100
- className: "table-cell",
11157
+ className: "table-cell header-cell",
11101
11158
  style: cellStyle,
11102
11159
  title: headerTitle,
11103
11160
  onClick: col.isCustom ? undefined : () => setSort(col.accessor)
11104
- }, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"));
11161
+ }, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"), /*#__PURE__*/React.createElement("div", {
11162
+ className: "column-resizer",
11163
+ onMouseDown: event => startColumnResize(event, col, i),
11164
+ onClick: event => event.stopPropagation()
11165
+ }));
11105
11166
  }), showActions && /*#__PURE__*/React.createElement("div", {
11106
11167
  className: "table-cell action-cell",
11107
11168
  style: actionColumnStyle,