trotl-table 1.0.79 → 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 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,
@@ -9818,6 +9819,117 @@ function TableInner({
9818
9819
  flex: "1 1 0%"
9819
9820
  };
9820
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]);
9821
9933
  const updateColumnWidth = React.useCallback((key, nextWidth) => {
9822
9934
  setColumnWidths(prev => ({
9823
9935
  ...prev,
@@ -10014,28 +10126,6 @@ function TableInner({
10014
10126
  return null;
10015
10127
  });
10016
10128
  };
10017
- const getAccessorValue = React.useCallback((row, accessor) => {
10018
- if (!row || accessor == null) return undefined;
10019
-
10020
- // Support fallback accessors: ["preverjen", "Preverjen", ...]
10021
- if (Array.isArray(accessor)) {
10022
- for (const key of accessor) {
10023
- if (row?.[key] !== undefined) return row[key];
10024
- }
10025
- return undefined;
10026
- }
10027
- return row?.[accessor];
10028
- }, []);
10029
- const getAccessorKey = React.useCallback((row, accessor) => {
10030
- if (accessor == null) return accessor;
10031
- if (Array.isArray(accessor)) {
10032
- for (const key of accessor) {
10033
- if (row?.[key] !== undefined) return key;
10034
- }
10035
- return accessor[0];
10036
- }
10037
- return accessor;
10038
- }, []);
10039
10129
  const isSameAccessor = React.useCallback((a, b) => {
10040
10130
  if (Array.isArray(a) && Array.isArray(b)) {
10041
10131
  if (a.length !== b.length) return false;
@@ -10950,6 +11040,7 @@ function TableInner({
10950
11040
  }
10951
11041
  const row = item.row;
10952
11042
  const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
11043
+ const highlightRowStyle = getHighlightRowStyle(row);
10953
11044
 
10954
11045
  // Compose columns + custom columns
10955
11046
  const allColumns = [...columns];
@@ -10975,7 +11066,10 @@ function TableInner({
10975
11066
  };
10976
11067
  const content = /*#__PURE__*/React.createElement("div", {
10977
11068
  key: key,
10978
- style: style,
11069
+ style: highlightRowStyle ? {
11070
+ ...style,
11071
+ ...highlightRowStyle
11072
+ } : style,
10979
11073
  className: "table-row",
10980
11074
  onContextMenu: e => {
10981
11075
  if (!Array.isArray(enableMouseRightClick) || enableMouseRightClick.length === 0) return;
@@ -11093,7 +11187,7 @@ function TableInner({
11093
11187
  }, content);
11094
11188
  }
11095
11189
  return content;
11096
- }, [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]);
11097
11191
  const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
11098
11192
  const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
11099
11193
  const rowHeightGetter = ({