trotl-table 1.0.62 → 1.0.63

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
@@ -9657,6 +9657,8 @@ function TableInner({
9657
9657
  downloadCallback = () => {},
9658
9658
  // callback for cell edits: (row, accessor, newValue)
9659
9659
  onCellChange = () => {},
9660
+ // callback for any cell click
9661
+ cellCallback = () => {},
9660
9662
  // when true, skip the integrated confirmation modal and delete immediately
9661
9663
  disableDeleteModal = false,
9662
9664
  deleteLabelKey = "name",
@@ -9714,6 +9716,7 @@ function TableInner({
9714
9716
  const duplicateCallbackRef = React.useRef(duplicateCallback);
9715
9717
  const downloadCallbackRef = React.useRef(downloadCallback);
9716
9718
  const onCellChangeRef = React.useRef(onCellChange);
9719
+ const cellCallbackRef = React.useRef(cellCallback);
9717
9720
 
9718
9721
  // Update refs when callbacks change (using useLayoutEffect to update before render)
9719
9722
  React.useLayoutEffect(() => {
@@ -9723,6 +9726,7 @@ function TableInner({
9723
9726
  editCallbackRef.current = editCallback;
9724
9727
  deleteCallbackRef.current = deleteCallback;
9725
9728
  onCellChangeRef.current = onCellChange;
9729
+ cellCallbackRef.current = cellCallback;
9726
9730
  });
9727
9731
  React.useEffect(() => {
9728
9732
  shareCallbackRef.current = shareCallback;
@@ -10179,6 +10183,28 @@ function TableInner({
10179
10183
  title: text
10180
10184
  }, text.slice(idx + query.length)));
10181
10185
  }, [searchTerm]);
10186
+ const triggerCellCallback = React.useCallback((row, col, explicitValue) => {
10187
+ const accessor = col?.accessor ?? null;
10188
+ const value = explicitValue !== undefined ? explicitValue : accessor != null ? row?.[accessor] : undefined;
10189
+ const type = col?.type ?? (col?.isCustom ? "custom" : "text");
10190
+ try {
10191
+ const callback = cellCallbackRef.current;
10192
+ if (typeof callback !== "function") return;
10193
+ if (callback.length >= 2) {
10194
+ callback(row, accessor, value, col);
10195
+ return;
10196
+ }
10197
+ callback({
10198
+ type,
10199
+ accessor,
10200
+ value,
10201
+ row,
10202
+ column: col
10203
+ });
10204
+ } catch (err) {
10205
+ console.error("cellCallback error", err);
10206
+ }
10207
+ }, []);
10182
10208
  const renderCell = React.useCallback((v, accessor, row, col) => {
10183
10209
  // Checkbox column type (editable in-table)
10184
10210
  if (col && col.type === 'checkbox') {
@@ -10186,7 +10212,10 @@ function TableInner({
10186
10212
  return /*#__PURE__*/React.createElement("input", {
10187
10213
  type: "checkbox",
10188
10214
  checked: checked,
10189
- onClick: e => e.stopPropagation(),
10215
+ onClick: e => {
10216
+ e.stopPropagation();
10217
+ triggerCellCallback(row, col, checked);
10218
+ },
10190
10219
  onChange: e => {
10191
10220
  const next = !!e.target.checked;
10192
10221
  setLocalData(prev => {
@@ -10218,7 +10247,10 @@ function TableInner({
10218
10247
  if (col && col.type === 'switch') {
10219
10248
  const checked = !!v;
10220
10249
  return /*#__PURE__*/React.createElement("div", {
10221
- onClick: e => e.stopPropagation()
10250
+ onClick: e => {
10251
+ e.stopPropagation();
10252
+ triggerCellCallback(row, col, checked);
10253
+ }
10222
10254
  }, /*#__PURE__*/React.createElement(Switch.default, {
10223
10255
  checked: checked,
10224
10256
  onChange: valOrEvent => {
@@ -10255,7 +10287,10 @@ function TableInner({
10255
10287
  type: "text",
10256
10288
  className: "table-cell-input",
10257
10289
  value: text,
10258
- onClick: e => e.stopPropagation(),
10290
+ onClick: e => {
10291
+ e.stopPropagation();
10292
+ triggerCellCallback(row, col, text);
10293
+ },
10259
10294
  onChange: e => {
10260
10295
  const next = e.target.value;
10261
10296
  setLocalData(prev => {
@@ -10331,7 +10366,7 @@ function TableInner({
10331
10366
  }
10332
10367
  // existing highlight logic for other fields
10333
10368
  return highlight(String(v));
10334
- }, [highlight, isGrouped]);
10369
+ }, [highlight, isGrouped, triggerCellCallback]);
10335
10370
  const showView = buttons.includes("view");
10336
10371
  const showEdit = buttons.includes("edit");
10337
10372
  // show delete only when view is also shown (per request)
@@ -10680,7 +10715,8 @@ function TableInner({
10680
10715
  return /*#__PURE__*/React.createElement("div", {
10681
10716
  key: i,
10682
10717
  className: "table-cell",
10683
- style: cellStyle
10718
+ style: cellStyle,
10719
+ onClick: () => triggerCellCallback(row, col)
10684
10720
  }, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(row[col.accessor], col.accessor, row, col));
10685
10721
  })), showActions && /*#__PURE__*/React.createElement("div", {
10686
10722
  className: "table-cell action-cell",
@@ -10755,7 +10791,7 @@ function TableInner({
10755
10791
  }, content);
10756
10792
  }
10757
10793
  return content;
10758
- }, [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]);
10794
+ }, [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]);
10759
10795
  const rowHeightGetter = ({
10760
10796
  index
10761
10797
  }) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;