trotl-table 1.0.79 → 1.0.81

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,
@@ -9676,6 +9677,8 @@ function TableInner({
9676
9677
  enableMouseRightClick = null,
9677
9678
  customColumns = [],
9678
9679
  groupDefaultOpen = false,
9680
+ groupExpanded = null,
9681
+ onExpandedGroupsChange = () => {},
9679
9682
  showIcons = true,
9680
9683
  timeoutLoading = 5,
9681
9684
  t
@@ -9818,6 +9821,117 @@ function TableInner({
9818
9821
  flex: "1 1 0%"
9819
9822
  };
9820
9823
  }, [columnWidths, getColumnKey]);
9824
+ const getAccessorValue = React.useCallback((row, accessor) => {
9825
+ if (!row || accessor == null) return undefined;
9826
+
9827
+ // Support fallback accessors: ["preverjen", "Preverjen", ...]
9828
+ if (Array.isArray(accessor)) {
9829
+ for (const key of accessor) {
9830
+ if (row?.[key] !== undefined) return row[key];
9831
+ }
9832
+ return undefined;
9833
+ }
9834
+ return row?.[accessor];
9835
+ }, []);
9836
+ const getAccessorKey = React.useCallback((row, accessor) => {
9837
+ if (accessor == null) return accessor;
9838
+ if (Array.isArray(accessor)) {
9839
+ for (const key of accessor) {
9840
+ if (row?.[key] !== undefined) return key;
9841
+ }
9842
+ return accessor[0];
9843
+ }
9844
+ return accessor;
9845
+ }, []);
9846
+ const normalizeHighlightComparable = React.useCallback((value, compareTo) => {
9847
+ if (value instanceof Date || compareTo instanceof Date) {
9848
+ const leftTime = value == null ? NaN : new Date(value).getTime();
9849
+ const rightTime = compareTo == null ? NaN : new Date(compareTo).getTime();
9850
+ return {
9851
+ left: leftTime,
9852
+ right: rightTime,
9853
+ valid: !Number.isNaN(leftTime) && !Number.isNaN(rightTime)
9854
+ };
9855
+ }
9856
+ return {
9857
+ left: value,
9858
+ right: compareTo,
9859
+ valid: true
9860
+ };
9861
+ }, []);
9862
+ const getHighlightRowStyle = React.useCallback(row => {
9863
+ if (!highlightRow || !row) return null;
9864
+ const currentDate = new Date();
9865
+ if (typeof highlightRow === "function") {
9866
+ const result = highlightRow({
9867
+ row,
9868
+ currentDate,
9869
+ getValue: accessor => getAccessorValue(row, accessor)
9870
+ });
9871
+ if (result === true) return {};
9872
+ if (result && typeof result === "object") {
9873
+ return result.style && typeof result.style === "object" ? result.style : result;
9874
+ }
9875
+ return null;
9876
+ }
9877
+ const {
9878
+ accessor,
9879
+ predicate,
9880
+ condition,
9881
+ function: highlightFn,
9882
+ operator = "eq",
9883
+ compareTo,
9884
+ style
9885
+ } = highlightRow;
9886
+ const cellValue = accessor ? getAccessorValue(row, accessor) : row;
9887
+ let shouldHighlight = false;
9888
+ if (typeof predicate === "function") {
9889
+ shouldHighlight = !!predicate(cellValue, row, currentDate);
9890
+ } else if (typeof condition === "function") {
9891
+ shouldHighlight = !!condition(cellValue, row, currentDate);
9892
+ } else if (typeof highlightFn === "function") {
9893
+ shouldHighlight = !!highlightFn(cellValue, row, currentDate);
9894
+ } else if (compareTo !== undefined) {
9895
+ const resolvedCompareTo = compareTo === "currentDate" ? currentDate : compareTo;
9896
+ const normalized = normalizeHighlightComparable(cellValue, resolvedCompareTo);
9897
+ if (normalized && normalized.valid) {
9898
+ const {
9899
+ left,
9900
+ right
9901
+ } = normalized;
9902
+ switch (operator) {
9903
+ case "<":
9904
+ case "lt":
9905
+ shouldHighlight = left < right;
9906
+ break;
9907
+ case "<=":
9908
+ case "lte":
9909
+ shouldHighlight = left <= right;
9910
+ break;
9911
+ case ">":
9912
+ case "gt":
9913
+ shouldHighlight = left > right;
9914
+ break;
9915
+ case ">=":
9916
+ case "gte":
9917
+ shouldHighlight = left >= right;
9918
+ break;
9919
+ case "!=":
9920
+ case "!==":
9921
+ case "ne":
9922
+ shouldHighlight = left !== right;
9923
+ break;
9924
+ case "==":
9925
+ case "===":
9926
+ case "eq":
9927
+ default:
9928
+ shouldHighlight = left === right;
9929
+ break;
9930
+ }
9931
+ }
9932
+ }
9933
+ return shouldHighlight ? style || {} : null;
9934
+ }, [getAccessorValue, highlightRow, normalizeHighlightComparable]);
9821
9935
  const updateColumnWidth = React.useCallback((key, nextWidth) => {
9822
9936
  setColumnWidths(prev => ({
9823
9937
  ...prev,
@@ -10014,28 +10128,6 @@ function TableInner({
10014
10128
  return null;
10015
10129
  });
10016
10130
  };
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
10131
  const isSameAccessor = React.useCallback((a, b) => {
10040
10132
  if (Array.isArray(a) && Array.isArray(b)) {
10041
10133
  if (a.length !== b.length) return false;
@@ -10221,12 +10313,24 @@ function TableInner({
10221
10313
  rows: sortRows(g.rows || [])
10222
10314
  }));
10223
10315
  }, [normalizedGroups, sorting, filterRows, getAccessorValue]);
10316
+ const emitExpandedChange = React.useCallback((nextState, toggledGroupId) => {
10317
+ if (typeof onExpandedGroupsChange === "function") {
10318
+ onExpandedGroupsChange(nextState, toggledGroupId);
10319
+ }
10320
+ if (typeof groupExpanded === "function") {
10321
+ groupExpanded(nextState, toggledGroupId);
10322
+ }
10323
+ }, [onExpandedGroupsChange, groupExpanded]);
10224
10324
  const [expandedGroups, setExpandedGroups] = React.useState({});
10225
10325
  const toggleGroup = gid => {
10226
- setExpandedGroups(prev => ({
10227
- ...prev,
10228
- [gid]: !prev[gid]
10229
- }));
10326
+ setExpandedGroups(prev => {
10327
+ const next = {
10328
+ ...prev,
10329
+ [gid]: !prev[gid]
10330
+ };
10331
+ emitExpandedChange(next, gid);
10332
+ return next;
10333
+ });
10230
10334
  };
10231
10335
  React.useEffect(() => {
10232
10336
  // Pre-populate expansion state for all groups
@@ -10241,6 +10345,11 @@ function TableInner({
10241
10345
  return next;
10242
10346
  });
10243
10347
  }, [normalizedGroups, groupKey, groupDefaultOpen]);
10348
+ React.useEffect(() => {
10349
+ if (groupExpanded && typeof groupExpanded === "object") {
10350
+ setExpandedGroups(groupExpanded);
10351
+ }
10352
+ }, [groupExpanded]);
10244
10353
  const groupRowsById = React.useMemo(() => {
10245
10354
  const map = {};
10246
10355
  for (const g of sortedGroupedData) {
@@ -10950,6 +11059,7 @@ function TableInner({
10950
11059
  }
10951
11060
  const row = item.row;
10952
11061
  const visualIndex = tableDataFlat.slice(0, index).filter(i => i.type === "row").length + 1;
11062
+ const highlightRowStyle = getHighlightRowStyle(row);
10953
11063
 
10954
11064
  // Compose columns + custom columns
10955
11065
  const allColumns = [...columns];
@@ -10975,7 +11085,10 @@ function TableInner({
10975
11085
  };
10976
11086
  const content = /*#__PURE__*/React.createElement("div", {
10977
11087
  key: key,
10978
- style: style,
11088
+ style: highlightRowStyle ? {
11089
+ ...style,
11090
+ ...highlightRowStyle
11091
+ } : style,
10979
11092
  className: "table-row",
10980
11093
  onContextMenu: e => {
10981
11094
  if (!Array.isArray(enableMouseRightClick) || enableMouseRightClick.length === 0) return;
@@ -11093,7 +11206,7 @@ function TableInner({
11093
11206
  }, content);
11094
11207
  }
11095
11208
  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]);
11209
+ }, [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
11210
  const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
11098
11211
  const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
11099
11212
  const rowHeightGetter = ({