trotl-table 1.0.89 → 1.0.91

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
@@ -9826,28 +9826,71 @@ function TableInner({
9826
9826
  flex: "1 1 0%"
9827
9827
  };
9828
9828
  }, [columnWidths, getColumnKey]);
9829
- const getAccessorValue = React.useCallback((row, accessor) => {
9829
+ const getNestedValue = React.useCallback((row, accessor) => {
9830
9830
  if (!row || accessor == null) return undefined;
9831
-
9832
- // Support fallback accessors: ["preverjen", "Preverjen", ...]
9833
9831
  if (Array.isArray(accessor)) {
9834
9832
  for (const key of accessor) {
9835
- if (row?.[key] !== undefined) return row[key];
9833
+ const value = getNestedValue(row, key);
9834
+ if (value !== undefined) return value;
9836
9835
  }
9837
9836
  return undefined;
9838
9837
  }
9839
- return row?.[accessor];
9838
+ const path = String(accessor).split(".").filter(Boolean);
9839
+ if (path.length === 0) return undefined;
9840
+ let current = row;
9841
+ for (const key of path) {
9842
+ if (current == null || typeof current !== "object") return undefined;
9843
+ current = current[key];
9844
+ }
9845
+ return current;
9840
9846
  }, []);
9847
+ const getAccessorValue = React.useCallback((row, accessor) => {
9848
+ return getNestedValue(row, accessor);
9849
+ }, [getNestedValue]);
9841
9850
  const getAccessorKey = React.useCallback((row, accessor) => {
9842
9851
  if (accessor == null) return accessor;
9843
9852
  if (Array.isArray(accessor)) {
9844
9853
  for (const key of accessor) {
9845
- if (row?.[key] !== undefined) return key;
9854
+ if (getNestedValue(row, key) !== undefined) return key;
9846
9855
  }
9847
9856
  return accessor[0];
9848
9857
  }
9849
9858
  return accessor;
9850
- }, []);
9859
+ }, [getNestedValue]);
9860
+ const updateRowField = React.useCallback((row, accessor, value) => {
9861
+ if (row == null || typeof row !== "object") return row;
9862
+ if (Array.isArray(accessor)) {
9863
+ for (const key of accessor) {
9864
+ if (getNestedValue(row, key) !== undefined) {
9865
+ return updateRowField(row, key, value);
9866
+ }
9867
+ }
9868
+ return {
9869
+ ...row,
9870
+ [accessor[0]]: value
9871
+ };
9872
+ }
9873
+ const path = String(accessor).split(".").filter(Boolean);
9874
+ if (path.length === 0) return row;
9875
+ if (path.length === 1) return {
9876
+ ...row,
9877
+ [path[0]]: value
9878
+ };
9879
+ const nextRow = {
9880
+ ...row
9881
+ };
9882
+ let current = nextRow;
9883
+ for (let i = 0; i < path.length - 1; i += 1) {
9884
+ const key = path[i];
9885
+ const nextValue = current[key];
9886
+ current[key] = nextValue && typeof nextValue === "object" ? {
9887
+ ...nextValue
9888
+ } : {};
9889
+ current = current[key];
9890
+ }
9891
+ current[path[path.length - 1]] = value;
9892
+ return nextRow;
9893
+ }, [getNestedValue]);
9851
9894
  const normalizeHighlightComparable = React.useCallback((value, compareTo) => {
9852
9895
  if (value instanceof Date || compareTo instanceof Date) {
9853
9896
  const leftTime = value == null ? NaN : new Date(value).getTime();
@@ -10577,16 +10620,10 @@ function TableInner({
10577
10620
  if (isGrouped) {
10578
10621
  return prev.map(g => ({
10579
10622
  ...g,
10580
- rows: (g.rows || []).map(r => r.id === row.id ? {
10581
- ...r,
10582
- [accessor]: next
10583
- } : r)
10623
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10584
10624
  }));
10585
10625
  }
10586
- return (prev || []).map(r => r.id === row.id ? {
10587
- ...r,
10588
- [accessor]: next
10589
- } : r);
10626
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10590
10627
  });
10591
10628
  refreshTriggerRef.current?.();
10592
10629
  try {
@@ -10615,16 +10652,10 @@ function TableInner({
10615
10652
  if (isGrouped) {
10616
10653
  return prev.map(g => ({
10617
10654
  ...g,
10618
- rows: (g.rows || []).map(r => r.id === row.id ? {
10619
- ...r,
10620
- [accessor]: next
10621
- } : r)
10655
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10622
10656
  }));
10623
10657
  }
10624
- return (prev || []).map(r => r.id === row.id ? {
10625
- ...r,
10626
- [accessor]: next
10627
- } : r);
10658
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10628
10659
  });
10629
10660
  refreshTriggerRef.current?.();
10630
10661
  try {
@@ -10679,16 +10710,10 @@ function TableInner({
10679
10710
  if (isGrouped) {
10680
10711
  return prev.map(g => ({
10681
10712
  ...g,
10682
- rows: (g.rows || []).map(r => r.id === row.id ? {
10683
- ...r,
10684
- [accessor]: next
10685
- } : r)
10713
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10686
10714
  }));
10687
10715
  }
10688
- return (prev || []).map(r => r.id === row.id ? {
10689
- ...r,
10690
- [accessor]: next
10691
- } : r);
10716
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10692
10717
  });
10693
10718
  refreshTriggerRef.current?.();
10694
10719
  try {
@@ -10723,16 +10748,10 @@ function TableInner({
10723
10748
  if (isGrouped) {
10724
10749
  return prev.map(g => ({
10725
10750
  ...g,
10726
- rows: (g.rows || []).map(r => r.id === row.id ? {
10727
- ...r,
10728
- [accessor]: next
10729
- } : r)
10751
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10730
10752
  }));
10731
10753
  }
10732
- return (prev || []).map(r => r.id === row.id ? {
10733
- ...r,
10734
- [accessor]: next
10735
- } : r);
10754
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10736
10755
  });
10737
10756
  refreshTriggerRef.current?.();
10738
10757
  try {
@@ -11417,6 +11436,10 @@ function TableInner({
11417
11436
  showCancel: true,
11418
11437
  showConfirm: true
11419
11438
  }, /*#__PURE__*/React.createElement("p", null, translate("areYouSureYouWantToDelete"), " ", /*#__PURE__*/React.createElement("strong", null, pendingDelete ? pendingDelete[deleteLabelKey] ?? pendingDelete.name ?? pendingDelete.id : ""), "?")));
11439
+ const getContextActionLabel = (action, row, index) => {
11440
+ const label = typeof action?.label === "function" ? action.label(row, action) : action?.label;
11441
+ return label || action?.text || `Action ${index + 1}`;
11442
+ };
11420
11443
  const contextMenuMarkup = contextMenu.visible && rightClickActions.length > 0 ? /*#__PURE__*/React.createElement("div", {
11421
11444
  style: {
11422
11445
  position: "fixed",
@@ -11443,7 +11466,7 @@ function TableInner({
11443
11466
  onMouseEnter: () => setHoveredActionIndex(i),
11444
11467
  onMouseLeave: () => setHoveredActionIndex(null),
11445
11468
  onClick: () => performContextMenuAction(action, contextMenu.row)
11446
- }, action.label || action.text || `Action ${i + 1}`))) : null;
11469
+ }, getContextActionLabel(action, contextMenu.row, i)))) : null;
11447
11470
  const contextMenuModalMarkup = contextMenuModal.visible && contextMenuModal.component ? /*#__PURE__*/React.createElement(Modal.default, {
11448
11471
  isOpen: true,
11449
11472
  title: contextMenuModal.title || "",