trotl-table 1.0.78 → 1.0.80
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 +141 -25
- package/dist/Table.cjs.js.map +1 -1
- package/dist/Table.esm.js +141 -25
- package/dist/Table.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/Table.esm.js
CHANGED
|
@@ -9616,6 +9616,7 @@ function TableInner({
|
|
|
9616
9616
|
tableId = "default",
|
|
9617
9617
|
columns = [],
|
|
9618
9618
|
data = [],
|
|
9619
|
+
highlightRow = null,
|
|
9619
9620
|
isGrouped = false,
|
|
9620
9621
|
groupKey = "groupId",
|
|
9621
9622
|
routePath = null,
|
|
@@ -9655,6 +9656,7 @@ function TableInner({
|
|
|
9655
9656
|
customColumns = [],
|
|
9656
9657
|
groupDefaultOpen = false,
|
|
9657
9658
|
showIcons = true,
|
|
9659
|
+
timeoutLoading = 5,
|
|
9658
9660
|
t
|
|
9659
9661
|
}) {
|
|
9660
9662
|
let translate;
|
|
@@ -9795,6 +9797,117 @@ function TableInner({
|
|
|
9795
9797
|
flex: "1 1 0%"
|
|
9796
9798
|
};
|
|
9797
9799
|
}, [columnWidths, getColumnKey]);
|
|
9800
|
+
const getAccessorValue = useCallback((row, accessor) => {
|
|
9801
|
+
if (!row || accessor == null) return undefined;
|
|
9802
|
+
|
|
9803
|
+
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
9804
|
+
if (Array.isArray(accessor)) {
|
|
9805
|
+
for (const key of accessor) {
|
|
9806
|
+
if (row?.[key] !== undefined) return row[key];
|
|
9807
|
+
}
|
|
9808
|
+
return undefined;
|
|
9809
|
+
}
|
|
9810
|
+
return row?.[accessor];
|
|
9811
|
+
}, []);
|
|
9812
|
+
const getAccessorKey = useCallback((row, accessor) => {
|
|
9813
|
+
if (accessor == null) return accessor;
|
|
9814
|
+
if (Array.isArray(accessor)) {
|
|
9815
|
+
for (const key of accessor) {
|
|
9816
|
+
if (row?.[key] !== undefined) return key;
|
|
9817
|
+
}
|
|
9818
|
+
return accessor[0];
|
|
9819
|
+
}
|
|
9820
|
+
return accessor;
|
|
9821
|
+
}, []);
|
|
9822
|
+
const normalizeHighlightComparable = useCallback((value, compareTo) => {
|
|
9823
|
+
if (value instanceof Date || compareTo instanceof Date) {
|
|
9824
|
+
const leftTime = value == null ? NaN : new Date(value).getTime();
|
|
9825
|
+
const rightTime = compareTo == null ? NaN : new Date(compareTo).getTime();
|
|
9826
|
+
return {
|
|
9827
|
+
left: leftTime,
|
|
9828
|
+
right: rightTime,
|
|
9829
|
+
valid: !Number.isNaN(leftTime) && !Number.isNaN(rightTime)
|
|
9830
|
+
};
|
|
9831
|
+
}
|
|
9832
|
+
return {
|
|
9833
|
+
left: value,
|
|
9834
|
+
right: compareTo,
|
|
9835
|
+
valid: true
|
|
9836
|
+
};
|
|
9837
|
+
}, []);
|
|
9838
|
+
const getHighlightRowStyle = useCallback(row => {
|
|
9839
|
+
if (!highlightRow || !row) return null;
|
|
9840
|
+
const currentDate = new Date();
|
|
9841
|
+
if (typeof highlightRow === "function") {
|
|
9842
|
+
const result = highlightRow({
|
|
9843
|
+
row,
|
|
9844
|
+
currentDate,
|
|
9845
|
+
getValue: accessor => getAccessorValue(row, accessor)
|
|
9846
|
+
});
|
|
9847
|
+
if (result === true) return {};
|
|
9848
|
+
if (result && typeof result === "object") {
|
|
9849
|
+
return result.style && typeof result.style === "object" ? result.style : result;
|
|
9850
|
+
}
|
|
9851
|
+
return null;
|
|
9852
|
+
}
|
|
9853
|
+
const {
|
|
9854
|
+
accessor,
|
|
9855
|
+
predicate,
|
|
9856
|
+
condition,
|
|
9857
|
+
function: highlightFn,
|
|
9858
|
+
operator = "eq",
|
|
9859
|
+
compareTo,
|
|
9860
|
+
style
|
|
9861
|
+
} = highlightRow;
|
|
9862
|
+
const cellValue = accessor ? getAccessorValue(row, accessor) : row;
|
|
9863
|
+
let shouldHighlight = false;
|
|
9864
|
+
if (typeof predicate === "function") {
|
|
9865
|
+
shouldHighlight = !!predicate(cellValue, row, currentDate);
|
|
9866
|
+
} else if (typeof condition === "function") {
|
|
9867
|
+
shouldHighlight = !!condition(cellValue, row, currentDate);
|
|
9868
|
+
} else if (typeof highlightFn === "function") {
|
|
9869
|
+
shouldHighlight = !!highlightFn(cellValue, row, currentDate);
|
|
9870
|
+
} else if (compareTo !== undefined) {
|
|
9871
|
+
const resolvedCompareTo = compareTo === "currentDate" ? currentDate : compareTo;
|
|
9872
|
+
const normalized = normalizeHighlightComparable(cellValue, resolvedCompareTo);
|
|
9873
|
+
if (normalized && normalized.valid) {
|
|
9874
|
+
const {
|
|
9875
|
+
left,
|
|
9876
|
+
right
|
|
9877
|
+
} = normalized;
|
|
9878
|
+
switch (operator) {
|
|
9879
|
+
case "<":
|
|
9880
|
+
case "lt":
|
|
9881
|
+
shouldHighlight = left < right;
|
|
9882
|
+
break;
|
|
9883
|
+
case "<=":
|
|
9884
|
+
case "lte":
|
|
9885
|
+
shouldHighlight = left <= right;
|
|
9886
|
+
break;
|
|
9887
|
+
case ">":
|
|
9888
|
+
case "gt":
|
|
9889
|
+
shouldHighlight = left > right;
|
|
9890
|
+
break;
|
|
9891
|
+
case ">=":
|
|
9892
|
+
case "gte":
|
|
9893
|
+
shouldHighlight = left >= right;
|
|
9894
|
+
break;
|
|
9895
|
+
case "!=":
|
|
9896
|
+
case "!==":
|
|
9897
|
+
case "ne":
|
|
9898
|
+
shouldHighlight = left !== right;
|
|
9899
|
+
break;
|
|
9900
|
+
case "==":
|
|
9901
|
+
case "===":
|
|
9902
|
+
case "eq":
|
|
9903
|
+
default:
|
|
9904
|
+
shouldHighlight = left === right;
|
|
9905
|
+
break;
|
|
9906
|
+
}
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
return shouldHighlight ? style || {} : null;
|
|
9910
|
+
}, [getAccessorValue, highlightRow, normalizeHighlightComparable]);
|
|
9798
9911
|
const updateColumnWidth = useCallback((key, nextWidth) => {
|
|
9799
9912
|
setColumnWidths(prev => ({
|
|
9800
9913
|
...prev,
|
|
@@ -9991,28 +10104,6 @@ function TableInner({
|
|
|
9991
10104
|
return null;
|
|
9992
10105
|
});
|
|
9993
10106
|
};
|
|
9994
|
-
const getAccessorValue = useCallback((row, accessor) => {
|
|
9995
|
-
if (!row || accessor == null) return undefined;
|
|
9996
|
-
|
|
9997
|
-
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
9998
|
-
if (Array.isArray(accessor)) {
|
|
9999
|
-
for (const key of accessor) {
|
|
10000
|
-
if (row?.[key] !== undefined) return row[key];
|
|
10001
|
-
}
|
|
10002
|
-
return undefined;
|
|
10003
|
-
}
|
|
10004
|
-
return row?.[accessor];
|
|
10005
|
-
}, []);
|
|
10006
|
-
const getAccessorKey = useCallback((row, accessor) => {
|
|
10007
|
-
if (accessor == null) return accessor;
|
|
10008
|
-
if (Array.isArray(accessor)) {
|
|
10009
|
-
for (const key of accessor) {
|
|
10010
|
-
if (row?.[key] !== undefined) return key;
|
|
10011
|
-
}
|
|
10012
|
-
return accessor[0];
|
|
10013
|
-
}
|
|
10014
|
-
return accessor;
|
|
10015
|
-
}, []);
|
|
10016
10107
|
const isSameAccessor = useCallback((a, b) => {
|
|
10017
10108
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
10018
10109
|
if (a.length !== b.length) return false;
|
|
@@ -10227,6 +10318,20 @@ function TableInner({
|
|
|
10227
10318
|
return map;
|
|
10228
10319
|
}, [sortedGroupedData, groupKey]);
|
|
10229
10320
|
const [tableDataFlat, setTableDataFlat] = useState([]);
|
|
10321
|
+
const [loadingTimeoutReached, setLoadingTimeoutReached] = useState(false);
|
|
10322
|
+
useEffect(() => {
|
|
10323
|
+
if (tableDataFlat.length > 0) {
|
|
10324
|
+
setLoadingTimeoutReached(false);
|
|
10325
|
+
return undefined;
|
|
10326
|
+
}
|
|
10327
|
+
const timeoutSeconds = Number(timeoutLoading) && Number(timeoutLoading) >= 0 ? Number(timeoutLoading) : 5;
|
|
10328
|
+
const timerId = window.setTimeout(() => {
|
|
10329
|
+
setLoadingTimeoutReached(true);
|
|
10330
|
+
}, timeoutSeconds * 1000);
|
|
10331
|
+
return () => {
|
|
10332
|
+
window.clearTimeout(timerId);
|
|
10333
|
+
};
|
|
10334
|
+
}, [tableDataFlat.length, timeoutLoading]);
|
|
10230
10335
|
const flattened = useMemo(() => {
|
|
10231
10336
|
const items = [];
|
|
10232
10337
|
// Use the sortedGroupedData here so the flattened list reflects current sorting and filtering
|
|
@@ -10913,6 +11018,7 @@ function TableInner({
|
|
|
10913
11018
|
}
|
|
10914
11019
|
const row = item.row;
|
|
10915
11020
|
const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
|
|
11021
|
+
const highlightRowStyle = getHighlightRowStyle(row);
|
|
10916
11022
|
|
|
10917
11023
|
// Compose columns + custom columns
|
|
10918
11024
|
const allColumns = [...columns];
|
|
@@ -10938,7 +11044,10 @@ function TableInner({
|
|
|
10938
11044
|
};
|
|
10939
11045
|
const content = /*#__PURE__*/React__default.createElement("div", {
|
|
10940
11046
|
key: key,
|
|
10941
|
-
style:
|
|
11047
|
+
style: highlightRowStyle ? {
|
|
11048
|
+
...style,
|
|
11049
|
+
...highlightRowStyle
|
|
11050
|
+
} : style,
|
|
10942
11051
|
className: "table-row",
|
|
10943
11052
|
onContextMenu: e => {
|
|
10944
11053
|
if (!Array.isArray(enableMouseRightClick) || enableMouseRightClick.length === 0) return;
|
|
@@ -11056,7 +11165,7 @@ function TableInner({
|
|
|
11056
11165
|
}, content);
|
|
11057
11166
|
}
|
|
11058
11167
|
return content;
|
|
11059
|
-
}, [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]);
|
|
11168
|
+
}, [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, getHighlightRowStyle, triggerCellCallback, getAccessorKey, getAccessorValue]);
|
|
11060
11169
|
const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
|
|
11061
11170
|
const [hoveredActionIndex, setHoveredActionIndex] = useState(null);
|
|
11062
11171
|
const rowHeightGetter = ({
|
|
@@ -11160,7 +11269,14 @@ function TableInner({
|
|
|
11160
11269
|
}, "\u2699\uFE0F") : translate("action")))), /*#__PURE__*/React__default.createElement("div", {
|
|
11161
11270
|
className: "main-table",
|
|
11162
11271
|
ref: listRef
|
|
11163
|
-
}, tableDataFlat.length === 0 ? /*#__PURE__*/React__default.createElement(DotsLoading, null) : /*#__PURE__*/React__default.createElement(
|
|
11272
|
+
}, tableDataFlat.length === 0 && !loadingTimeoutReached ? /*#__PURE__*/React__default.createElement(DotsLoading, null) : tableDataFlat.length === 0 && loadingTimeoutReached ? /*#__PURE__*/React__default.createElement("div", {
|
|
11273
|
+
className: "table-empty",
|
|
11274
|
+
style: {
|
|
11275
|
+
padding: 24,
|
|
11276
|
+
textAlign: 'center',
|
|
11277
|
+
color: '#666'
|
|
11278
|
+
}
|
|
11279
|
+
}, translate("noData")) : /*#__PURE__*/React__default.createElement(AutoSizer, null, ({
|
|
11164
11280
|
height,
|
|
11165
11281
|
width
|
|
11166
11282
|
}) => /*#__PURE__*/React__default.createElement(List, {
|