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.cjs.js
CHANGED
|
@@ -9638,6 +9638,7 @@ function TableInner({
|
|
|
9638
9638
|
tableId = "default",
|
|
9639
9639
|
columns = [],
|
|
9640
9640
|
data = [],
|
|
9641
|
+
highlightRow = null,
|
|
9641
9642
|
isGrouped = false,
|
|
9642
9643
|
groupKey = "groupId",
|
|
9643
9644
|
routePath = null,
|
|
@@ -9677,6 +9678,7 @@ function TableInner({
|
|
|
9677
9678
|
customColumns = [],
|
|
9678
9679
|
groupDefaultOpen = false,
|
|
9679
9680
|
showIcons = true,
|
|
9681
|
+
timeoutLoading = 5,
|
|
9680
9682
|
t
|
|
9681
9683
|
}) {
|
|
9682
9684
|
let translate;
|
|
@@ -9817,6 +9819,117 @@ function TableInner({
|
|
|
9817
9819
|
flex: "1 1 0%"
|
|
9818
9820
|
};
|
|
9819
9821
|
}, [columnWidths, getColumnKey]);
|
|
9822
|
+
const getAccessorValue = React.useCallback((row, accessor) => {
|
|
9823
|
+
if (!row || accessor == null) return undefined;
|
|
9824
|
+
|
|
9825
|
+
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
9826
|
+
if (Array.isArray(accessor)) {
|
|
9827
|
+
for (const key of accessor) {
|
|
9828
|
+
if (row?.[key] !== undefined) return row[key];
|
|
9829
|
+
}
|
|
9830
|
+
return undefined;
|
|
9831
|
+
}
|
|
9832
|
+
return row?.[accessor];
|
|
9833
|
+
}, []);
|
|
9834
|
+
const getAccessorKey = React.useCallback((row, accessor) => {
|
|
9835
|
+
if (accessor == null) return accessor;
|
|
9836
|
+
if (Array.isArray(accessor)) {
|
|
9837
|
+
for (const key of accessor) {
|
|
9838
|
+
if (row?.[key] !== undefined) return key;
|
|
9839
|
+
}
|
|
9840
|
+
return accessor[0];
|
|
9841
|
+
}
|
|
9842
|
+
return accessor;
|
|
9843
|
+
}, []);
|
|
9844
|
+
const normalizeHighlightComparable = React.useCallback((value, compareTo) => {
|
|
9845
|
+
if (value instanceof Date || compareTo instanceof Date) {
|
|
9846
|
+
const leftTime = value == null ? NaN : new Date(value).getTime();
|
|
9847
|
+
const rightTime = compareTo == null ? NaN : new Date(compareTo).getTime();
|
|
9848
|
+
return {
|
|
9849
|
+
left: leftTime,
|
|
9850
|
+
right: rightTime,
|
|
9851
|
+
valid: !Number.isNaN(leftTime) && !Number.isNaN(rightTime)
|
|
9852
|
+
};
|
|
9853
|
+
}
|
|
9854
|
+
return {
|
|
9855
|
+
left: value,
|
|
9856
|
+
right: compareTo,
|
|
9857
|
+
valid: true
|
|
9858
|
+
};
|
|
9859
|
+
}, []);
|
|
9860
|
+
const getHighlightRowStyle = React.useCallback(row => {
|
|
9861
|
+
if (!highlightRow || !row) return null;
|
|
9862
|
+
const currentDate = new Date();
|
|
9863
|
+
if (typeof highlightRow === "function") {
|
|
9864
|
+
const result = highlightRow({
|
|
9865
|
+
row,
|
|
9866
|
+
currentDate,
|
|
9867
|
+
getValue: accessor => getAccessorValue(row, accessor)
|
|
9868
|
+
});
|
|
9869
|
+
if (result === true) return {};
|
|
9870
|
+
if (result && typeof result === "object") {
|
|
9871
|
+
return result.style && typeof result.style === "object" ? result.style : result;
|
|
9872
|
+
}
|
|
9873
|
+
return null;
|
|
9874
|
+
}
|
|
9875
|
+
const {
|
|
9876
|
+
accessor,
|
|
9877
|
+
predicate,
|
|
9878
|
+
condition,
|
|
9879
|
+
function: highlightFn,
|
|
9880
|
+
operator = "eq",
|
|
9881
|
+
compareTo,
|
|
9882
|
+
style
|
|
9883
|
+
} = highlightRow;
|
|
9884
|
+
const cellValue = accessor ? getAccessorValue(row, accessor) : row;
|
|
9885
|
+
let shouldHighlight = false;
|
|
9886
|
+
if (typeof predicate === "function") {
|
|
9887
|
+
shouldHighlight = !!predicate(cellValue, row, currentDate);
|
|
9888
|
+
} else if (typeof condition === "function") {
|
|
9889
|
+
shouldHighlight = !!condition(cellValue, row, currentDate);
|
|
9890
|
+
} else if (typeof highlightFn === "function") {
|
|
9891
|
+
shouldHighlight = !!highlightFn(cellValue, row, currentDate);
|
|
9892
|
+
} else if (compareTo !== undefined) {
|
|
9893
|
+
const resolvedCompareTo = compareTo === "currentDate" ? currentDate : compareTo;
|
|
9894
|
+
const normalized = normalizeHighlightComparable(cellValue, resolvedCompareTo);
|
|
9895
|
+
if (normalized && normalized.valid) {
|
|
9896
|
+
const {
|
|
9897
|
+
left,
|
|
9898
|
+
right
|
|
9899
|
+
} = normalized;
|
|
9900
|
+
switch (operator) {
|
|
9901
|
+
case "<":
|
|
9902
|
+
case "lt":
|
|
9903
|
+
shouldHighlight = left < right;
|
|
9904
|
+
break;
|
|
9905
|
+
case "<=":
|
|
9906
|
+
case "lte":
|
|
9907
|
+
shouldHighlight = left <= right;
|
|
9908
|
+
break;
|
|
9909
|
+
case ">":
|
|
9910
|
+
case "gt":
|
|
9911
|
+
shouldHighlight = left > right;
|
|
9912
|
+
break;
|
|
9913
|
+
case ">=":
|
|
9914
|
+
case "gte":
|
|
9915
|
+
shouldHighlight = left >= right;
|
|
9916
|
+
break;
|
|
9917
|
+
case "!=":
|
|
9918
|
+
case "!==":
|
|
9919
|
+
case "ne":
|
|
9920
|
+
shouldHighlight = left !== right;
|
|
9921
|
+
break;
|
|
9922
|
+
case "==":
|
|
9923
|
+
case "===":
|
|
9924
|
+
case "eq":
|
|
9925
|
+
default:
|
|
9926
|
+
shouldHighlight = left === right;
|
|
9927
|
+
break;
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9930
|
+
}
|
|
9931
|
+
return shouldHighlight ? style || {} : null;
|
|
9932
|
+
}, [getAccessorValue, highlightRow, normalizeHighlightComparable]);
|
|
9820
9933
|
const updateColumnWidth = React.useCallback((key, nextWidth) => {
|
|
9821
9934
|
setColumnWidths(prev => ({
|
|
9822
9935
|
...prev,
|
|
@@ -10013,28 +10126,6 @@ function TableInner({
|
|
|
10013
10126
|
return null;
|
|
10014
10127
|
});
|
|
10015
10128
|
};
|
|
10016
|
-
const getAccessorValue = React.useCallback((row, accessor) => {
|
|
10017
|
-
if (!row || accessor == null) return undefined;
|
|
10018
|
-
|
|
10019
|
-
// Support fallback accessors: ["preverjen", "Preverjen", ...]
|
|
10020
|
-
if (Array.isArray(accessor)) {
|
|
10021
|
-
for (const key of accessor) {
|
|
10022
|
-
if (row?.[key] !== undefined) return row[key];
|
|
10023
|
-
}
|
|
10024
|
-
return undefined;
|
|
10025
|
-
}
|
|
10026
|
-
return row?.[accessor];
|
|
10027
|
-
}, []);
|
|
10028
|
-
const getAccessorKey = React.useCallback((row, accessor) => {
|
|
10029
|
-
if (accessor == null) return accessor;
|
|
10030
|
-
if (Array.isArray(accessor)) {
|
|
10031
|
-
for (const key of accessor) {
|
|
10032
|
-
if (row?.[key] !== undefined) return key;
|
|
10033
|
-
}
|
|
10034
|
-
return accessor[0];
|
|
10035
|
-
}
|
|
10036
|
-
return accessor;
|
|
10037
|
-
}, []);
|
|
10038
10129
|
const isSameAccessor = React.useCallback((a, b) => {
|
|
10039
10130
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
10040
10131
|
if (a.length !== b.length) return false;
|
|
@@ -10249,6 +10340,20 @@ function TableInner({
|
|
|
10249
10340
|
return map;
|
|
10250
10341
|
}, [sortedGroupedData, groupKey]);
|
|
10251
10342
|
const [tableDataFlat, setTableDataFlat] = React.useState([]);
|
|
10343
|
+
const [loadingTimeoutReached, setLoadingTimeoutReached] = React.useState(false);
|
|
10344
|
+
React.useEffect(() => {
|
|
10345
|
+
if (tableDataFlat.length > 0) {
|
|
10346
|
+
setLoadingTimeoutReached(false);
|
|
10347
|
+
return undefined;
|
|
10348
|
+
}
|
|
10349
|
+
const timeoutSeconds = Number(timeoutLoading) && Number(timeoutLoading) >= 0 ? Number(timeoutLoading) : 5;
|
|
10350
|
+
const timerId = window.setTimeout(() => {
|
|
10351
|
+
setLoadingTimeoutReached(true);
|
|
10352
|
+
}, timeoutSeconds * 1000);
|
|
10353
|
+
return () => {
|
|
10354
|
+
window.clearTimeout(timerId);
|
|
10355
|
+
};
|
|
10356
|
+
}, [tableDataFlat.length, timeoutLoading]);
|
|
10252
10357
|
const flattened = React.useMemo(() => {
|
|
10253
10358
|
const items = [];
|
|
10254
10359
|
// Use the sortedGroupedData here so the flattened list reflects current sorting and filtering
|
|
@@ -10935,6 +11040,7 @@ function TableInner({
|
|
|
10935
11040
|
}
|
|
10936
11041
|
const row = item.row;
|
|
10937
11042
|
const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
|
|
11043
|
+
const highlightRowStyle = getHighlightRowStyle(row);
|
|
10938
11044
|
|
|
10939
11045
|
// Compose columns + custom columns
|
|
10940
11046
|
const allColumns = [...columns];
|
|
@@ -10960,7 +11066,10 @@ function TableInner({
|
|
|
10960
11066
|
};
|
|
10961
11067
|
const content = /*#__PURE__*/React.createElement("div", {
|
|
10962
11068
|
key: key,
|
|
10963
|
-
style:
|
|
11069
|
+
style: highlightRowStyle ? {
|
|
11070
|
+
...style,
|
|
11071
|
+
...highlightRowStyle
|
|
11072
|
+
} : style,
|
|
10964
11073
|
className: "table-row",
|
|
10965
11074
|
onContextMenu: e => {
|
|
10966
11075
|
if (!Array.isArray(enableMouseRightClick) || enableMouseRightClick.length === 0) return;
|
|
@@ -11078,7 +11187,7 @@ function TableInner({
|
|
|
11078
11187
|
}, content);
|
|
11079
11188
|
}
|
|
11080
11189
|
return content;
|
|
11081
|
-
}, [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]);
|
|
11190
|
+
}, [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]);
|
|
11082
11191
|
const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
|
|
11083
11192
|
const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
|
|
11084
11193
|
const rowHeightGetter = ({
|
|
@@ -11182,7 +11291,14 @@ function TableInner({
|
|
|
11182
11291
|
}, "\u2699\uFE0F") : translate("action")))), /*#__PURE__*/React.createElement("div", {
|
|
11183
11292
|
className: "main-table",
|
|
11184
11293
|
ref: listRef
|
|
11185
|
-
}, tableDataFlat.length === 0 ? /*#__PURE__*/React.createElement(DotsLoading.default, null) : /*#__PURE__*/React.createElement(
|
|
11294
|
+
}, tableDataFlat.length === 0 && !loadingTimeoutReached ? /*#__PURE__*/React.createElement(DotsLoading.default, null) : tableDataFlat.length === 0 && loadingTimeoutReached ? /*#__PURE__*/React.createElement("div", {
|
|
11295
|
+
className: "table-empty",
|
|
11296
|
+
style: {
|
|
11297
|
+
padding: 24,
|
|
11298
|
+
textAlign: 'center',
|
|
11299
|
+
color: '#666'
|
|
11300
|
+
}
|
|
11301
|
+
}, translate("noData")) : /*#__PURE__*/React.createElement(AutoSizer, null, ({
|
|
11186
11302
|
height,
|
|
11187
11303
|
width
|
|
11188
11304
|
}) => /*#__PURE__*/React.createElement(List, {
|