trotl-table 1.0.62 → 1.0.64
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 +80 -12
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +80 -12
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -9847,6 +9851,35 @@ function TableInner({
|
|
|
9847
9851
|
return null;
|
|
9848
9852
|
});
|
|
9849
9853
|
};
|
|
9854
|
+
const getAccessorValue = React.useCallback((row, accessor) => {
|
|
9855
|
+
if (!row || accessor == null) return undefined;
|
|
9856
|
+
|
|
9857
|
+
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
9858
|
+
if (Array.isArray(accessor)) {
|
|
9859
|
+
for (const key of accessor) {
|
|
9860
|
+
if (row?.[key] !== undefined) return row[key];
|
|
9861
|
+
}
|
|
9862
|
+
return undefined;
|
|
9863
|
+
}
|
|
9864
|
+
return row?.[accessor];
|
|
9865
|
+
}, []);
|
|
9866
|
+
const getAccessorKey = React.useCallback((row, accessor) => {
|
|
9867
|
+
if (accessor == null) return accessor;
|
|
9868
|
+
if (Array.isArray(accessor)) {
|
|
9869
|
+
for (const key of accessor) {
|
|
9870
|
+
if (row?.[key] !== undefined) return key;
|
|
9871
|
+
}
|
|
9872
|
+
return accessor[0];
|
|
9873
|
+
}
|
|
9874
|
+
return accessor;
|
|
9875
|
+
}, []);
|
|
9876
|
+
const isSameAccessor = React.useCallback((a, b) => {
|
|
9877
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9878
|
+
if (a.length !== b.length) return false;
|
|
9879
|
+
return a.every((item, idx) => item === b[idx]);
|
|
9880
|
+
}
|
|
9881
|
+
return a === b;
|
|
9882
|
+
}, []);
|
|
9850
9883
|
|
|
9851
9884
|
// console.log(extraSearchTerm)
|
|
9852
9885
|
|
|
@@ -9932,11 +9965,11 @@ function TableInner({
|
|
|
9932
9965
|
if (!searchTerm) return dateFiltered;
|
|
9933
9966
|
const query = searchTerm.toLowerCase();
|
|
9934
9967
|
return dateFiltered.filter(row => columns.some(col => {
|
|
9935
|
-
const val = row
|
|
9968
|
+
const val = getAccessorValue(row, col.accessor);
|
|
9936
9969
|
if (val == null) return false;
|
|
9937
9970
|
return String(val).toLowerCase().includes(query);
|
|
9938
9971
|
}));
|
|
9939
|
-
}, [searchTerm, columns, urlSearchString]);
|
|
9972
|
+
}, [searchTerm, columns, urlSearchString, getAccessorValue]);
|
|
9940
9973
|
|
|
9941
9974
|
// Natural-ish comparator: handles nulls, numbers, strings, ISO dates
|
|
9942
9975
|
const compare = (x, y, dir = "asc") => {
|
|
@@ -10001,14 +10034,14 @@ function TableInner({
|
|
|
10001
10034
|
const sortRows = rows => {
|
|
10002
10035
|
const arr = [...rows];
|
|
10003
10036
|
if (!sortKey) return filterRows(arr); // fallback to drag order
|
|
10004
|
-
arr.sort((a, b) => compare(a
|
|
10037
|
+
arr.sort((a, b) => compare(getAccessorValue(a, sortKey), getAccessorValue(b, sortKey), direction));
|
|
10005
10038
|
return filterRows(arr);
|
|
10006
10039
|
};
|
|
10007
10040
|
return normalizedGroups.map(g => ({
|
|
10008
10041
|
...g,
|
|
10009
10042
|
rows: sortRows(g.rows || [])
|
|
10010
10043
|
}));
|
|
10011
|
-
}, [normalizedGroups, sorting, filterRows]);
|
|
10044
|
+
}, [normalizedGroups, sorting, filterRows, getAccessorValue]);
|
|
10012
10045
|
const [expandedGroups, setExpandedGroups] = React.useState({});
|
|
10013
10046
|
const toggleGroup = gid => {
|
|
10014
10047
|
setExpandedGroups(prev => ({
|
|
@@ -10179,6 +10212,29 @@ function TableInner({
|
|
|
10179
10212
|
title: text
|
|
10180
10213
|
}, text.slice(idx + query.length)));
|
|
10181
10214
|
}, [searchTerm]);
|
|
10215
|
+
const triggerCellCallback = React.useCallback((row, col, explicitValue) => {
|
|
10216
|
+
const accessor = col?.accessor ?? null;
|
|
10217
|
+
const resolvedAccessor = getAccessorKey(row, accessor);
|
|
10218
|
+
const value = explicitValue !== undefined ? explicitValue : getAccessorValue(row, accessor);
|
|
10219
|
+
const type = col?.type ?? (col?.isCustom ? "custom" : "text");
|
|
10220
|
+
try {
|
|
10221
|
+
const callback = cellCallbackRef.current;
|
|
10222
|
+
if (typeof callback !== "function") return;
|
|
10223
|
+
if (callback.length >= 2) {
|
|
10224
|
+
callback(row, resolvedAccessor, value, col);
|
|
10225
|
+
return;
|
|
10226
|
+
}
|
|
10227
|
+
callback({
|
|
10228
|
+
type,
|
|
10229
|
+
accessor: resolvedAccessor,
|
|
10230
|
+
value,
|
|
10231
|
+
row,
|
|
10232
|
+
column: col
|
|
10233
|
+
});
|
|
10234
|
+
} catch (err) {
|
|
10235
|
+
console.error("cellCallback error", err);
|
|
10236
|
+
}
|
|
10237
|
+
}, [getAccessorKey, getAccessorValue]);
|
|
10182
10238
|
const renderCell = React.useCallback((v, accessor, row, col) => {
|
|
10183
10239
|
// Checkbox column type (editable in-table)
|
|
10184
10240
|
if (col && col.type === 'checkbox') {
|
|
@@ -10186,7 +10242,10 @@ function TableInner({
|
|
|
10186
10242
|
return /*#__PURE__*/React.createElement("input", {
|
|
10187
10243
|
type: "checkbox",
|
|
10188
10244
|
checked: checked,
|
|
10189
|
-
onClick: e =>
|
|
10245
|
+
onClick: e => {
|
|
10246
|
+
e.stopPropagation();
|
|
10247
|
+
triggerCellCallback(row, col, checked);
|
|
10248
|
+
},
|
|
10190
10249
|
onChange: e => {
|
|
10191
10250
|
const next = !!e.target.checked;
|
|
10192
10251
|
setLocalData(prev => {
|
|
@@ -10218,7 +10277,10 @@ function TableInner({
|
|
|
10218
10277
|
if (col && col.type === 'switch') {
|
|
10219
10278
|
const checked = !!v;
|
|
10220
10279
|
return /*#__PURE__*/React.createElement("div", {
|
|
10221
|
-
onClick: e =>
|
|
10280
|
+
onClick: e => {
|
|
10281
|
+
e.stopPropagation();
|
|
10282
|
+
triggerCellCallback(row, col, checked);
|
|
10283
|
+
}
|
|
10222
10284
|
}, /*#__PURE__*/React.createElement(Switch.default, {
|
|
10223
10285
|
checked: checked,
|
|
10224
10286
|
onChange: valOrEvent => {
|
|
@@ -10255,7 +10317,10 @@ function TableInner({
|
|
|
10255
10317
|
type: "text",
|
|
10256
10318
|
className: "table-cell-input",
|
|
10257
10319
|
value: text,
|
|
10258
|
-
onClick: e =>
|
|
10320
|
+
onClick: e => {
|
|
10321
|
+
e.stopPropagation();
|
|
10322
|
+
triggerCellCallback(row, col, text);
|
|
10323
|
+
},
|
|
10259
10324
|
onChange: e => {
|
|
10260
10325
|
const next = e.target.value;
|
|
10261
10326
|
setLocalData(prev => {
|
|
@@ -10331,7 +10396,7 @@ function TableInner({
|
|
|
10331
10396
|
}
|
|
10332
10397
|
// existing highlight logic for other fields
|
|
10333
10398
|
return highlight(String(v));
|
|
10334
|
-
}, [highlight, isGrouped]);
|
|
10399
|
+
}, [highlight, isGrouped, triggerCellCallback]);
|
|
10335
10400
|
const showView = buttons.includes("view");
|
|
10336
10401
|
const showEdit = buttons.includes("edit");
|
|
10337
10402
|
// show delete only when view is also shown (per request)
|
|
@@ -10668,6 +10733,8 @@ function TableInner({
|
|
|
10668
10733
|
maxWidth: keyWidth
|
|
10669
10734
|
} : undefined
|
|
10670
10735
|
}, visualIndex), allColumns.map((col, i) => {
|
|
10736
|
+
const resolvedAccessor = getAccessorKey(row, col.accessor);
|
|
10737
|
+
const cellValue = getAccessorValue(row, col.accessor);
|
|
10671
10738
|
let cellStyle = col.style ? {
|
|
10672
10739
|
...col.style
|
|
10673
10740
|
} : undefined;
|
|
@@ -10680,8 +10747,9 @@ function TableInner({
|
|
|
10680
10747
|
return /*#__PURE__*/React.createElement("div", {
|
|
10681
10748
|
key: i,
|
|
10682
10749
|
className: "table-cell",
|
|
10683
|
-
style: cellStyle
|
|
10684
|
-
|
|
10750
|
+
style: cellStyle,
|
|
10751
|
+
onClick: () => triggerCellCallback(row, col)
|
|
10752
|
+
}, col.isCustom ? typeof col.render === 'function' ? col.render(row, i) : col.render : renderCell(cellValue, resolvedAccessor, row, col));
|
|
10685
10753
|
})), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10686
10754
|
className: "table-cell action-cell",
|
|
10687
10755
|
style: actionColumnStyle
|
|
@@ -10755,7 +10823,7 @@ function TableInner({
|
|
|
10755
10823
|
}, content);
|
|
10756
10824
|
}
|
|
10757
10825
|
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]);
|
|
10826
|
+
}, [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]);
|
|
10759
10827
|
const rowHeightGetter = ({
|
|
10760
10828
|
index
|
|
10761
10829
|
}) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
|
|
@@ -10854,7 +10922,7 @@ function TableInner({
|
|
|
10854
10922
|
style: cellStyle,
|
|
10855
10923
|
title: headerTitle,
|
|
10856
10924
|
onClick: col.isCustom ? undefined : () => setSort(col.accessor)
|
|
10857
|
-
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && sorting?.column
|
|
10925
|
+
}, col.isCustom ? translatedHeader ?? "" : translatedHeader, !col.isCustom && isSameAccessor(sorting?.column, col.accessor) && (sorting.direction === "asc" ? " ↑" : " ↓"));
|
|
10858
10926
|
}), showActions && /*#__PURE__*/React.createElement("div", {
|
|
10859
10927
|
className: "table-cell action-cell",
|
|
10860
10928
|
style: actionColumnStyle,
|