trotl-table 1.0.90 → 1.0.92

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
@@ -9663,8 +9663,6 @@ function TableInner({
9663
9663
  onCellChange = () => {},
9664
9664
  // callback for any cell click
9665
9665
  cellCallback = () => {},
9666
- // when true, skip the integrated confirmation modal and delete immediately
9667
- disableDeleteModal = false,
9668
9666
  deleteLabelKey = "name",
9669
9667
  buttons = ["view", "edit", "delete", "share", "duplicate"],
9670
9668
  enableDragRow = false,
@@ -9717,6 +9715,9 @@ function TableInner({
9717
9715
  return translations[key] || key;
9718
9716
  };
9719
9717
  }
9718
+
9719
+ // normalize delete modal flag early (handles string 'false' etc)
9720
+
9720
9721
  // Use refs for callbacks to prevent infinite loops from dependency changes
9721
9722
  const selectedRowsCallbackRef = React.useRef(selectedRowsCallback);
9722
9723
  const refreshTriggerRef = React.useRef(refreshTrigger);
@@ -9826,28 +9827,71 @@ function TableInner({
9826
9827
  flex: "1 1 0%"
9827
9828
  };
9828
9829
  }, [columnWidths, getColumnKey]);
9829
- const getAccessorValue = React.useCallback((row, accessor) => {
9830
+ const getNestedValue = React.useCallback((row, accessor) => {
9830
9831
  if (!row || accessor == null) return undefined;
9831
-
9832
- // Support fallback accessors: ["preverjen", "Preverjen", ...]
9833
9832
  if (Array.isArray(accessor)) {
9834
9833
  for (const key of accessor) {
9835
- if (row?.[key] !== undefined) return row[key];
9834
+ const value = getNestedValue(row, key);
9835
+ if (value !== undefined) return value;
9836
9836
  }
9837
9837
  return undefined;
9838
9838
  }
9839
- return row?.[accessor];
9839
+ const path = String(accessor).split(".").filter(Boolean);
9840
+ if (path.length === 0) return undefined;
9841
+ let current = row;
9842
+ for (const key of path) {
9843
+ if (current == null || typeof current !== "object") return undefined;
9844
+ current = current[key];
9845
+ }
9846
+ return current;
9840
9847
  }, []);
9848
+ const getAccessorValue = React.useCallback((row, accessor) => {
9849
+ return getNestedValue(row, accessor);
9850
+ }, [getNestedValue]);
9841
9851
  const getAccessorKey = React.useCallback((row, accessor) => {
9842
9852
  if (accessor == null) return accessor;
9843
9853
  if (Array.isArray(accessor)) {
9844
9854
  for (const key of accessor) {
9845
- if (row?.[key] !== undefined) return key;
9855
+ if (getNestedValue(row, key) !== undefined) return key;
9846
9856
  }
9847
9857
  return accessor[0];
9848
9858
  }
9849
9859
  return accessor;
9850
- }, []);
9860
+ }, [getNestedValue]);
9861
+ const updateRowField = React.useCallback((row, accessor, value) => {
9862
+ if (row == null || typeof row !== "object") return row;
9863
+ if (Array.isArray(accessor)) {
9864
+ for (const key of accessor) {
9865
+ if (getNestedValue(row, key) !== undefined) {
9866
+ return updateRowField(row, key, value);
9867
+ }
9868
+ }
9869
+ return {
9870
+ ...row,
9871
+ [accessor[0]]: value
9872
+ };
9873
+ }
9874
+ const path = String(accessor).split(".").filter(Boolean);
9875
+ if (path.length === 0) return row;
9876
+ if (path.length === 1) return {
9877
+ ...row,
9878
+ [path[0]]: value
9879
+ };
9880
+ const nextRow = {
9881
+ ...row
9882
+ };
9883
+ let current = nextRow;
9884
+ for (let i = 0; i < path.length - 1; i += 1) {
9885
+ const key = path[i];
9886
+ const nextValue = current[key];
9887
+ current[key] = nextValue && typeof nextValue === "object" ? {
9888
+ ...nextValue
9889
+ } : {};
9890
+ current = current[key];
9891
+ }
9892
+ current[path[path.length - 1]] = value;
9893
+ return nextRow;
9894
+ }, [getNestedValue]);
9851
9895
  const normalizeHighlightComparable = React.useCallback((value, compareTo) => {
9852
9896
  if (value instanceof Date || compareTo instanceof Date) {
9853
9897
  const leftTime = value == null ? NaN : new Date(value).getTime();
@@ -10141,17 +10185,25 @@ function TableInner({
10141
10185
  return a === b;
10142
10186
  }, []);
10143
10187
  const formatArrayValue = React.useCallback((value, col) => {
10144
- if (!Array.isArray(value)) return value;
10188
+ if (!Array.isArray(value)) return "";
10145
10189
  const objectKey = col?.objectKey;
10146
10190
  const parts = value.map(item => {
10147
10191
  if (item == null) return "";
10192
+
10193
+ // When objectKey is configured, only use that field. This prevents
10194
+ // objects without a label from displaying their key or JSON value.
10195
+ if (objectKey) {
10196
+ if (typeof item !== "object" || typeof item[objectKey] !== "string") {
10197
+ return "";
10198
+ }
10199
+ return item[objectKey].trim();
10200
+ }
10148
10201
  if (typeof item !== "object") return String(item);
10149
- if (objectKey && item?.[objectKey] !== undefined) return String(item[objectKey]);
10150
10202
  if (item.label !== undefined) return String(item.label);
10151
10203
  if (item.value !== undefined) return String(item.value);
10152
10204
  return JSON.stringify(item);
10153
- }).filter(item => item !== "");
10154
- return parts.join(", ");
10205
+ }).filter(Boolean);
10206
+ return [...new Set(parts)].join(", ");
10155
10207
  }, []);
10156
10208
 
10157
10209
  // console.log(extraSearchTerm)
@@ -10577,16 +10629,10 @@ function TableInner({
10577
10629
  if (isGrouped) {
10578
10630
  return prev.map(g => ({
10579
10631
  ...g,
10580
- rows: (g.rows || []).map(r => r.id === row.id ? {
10581
- ...r,
10582
- [accessor]: next
10583
- } : r)
10632
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10584
10633
  }));
10585
10634
  }
10586
- return (prev || []).map(r => r.id === row.id ? {
10587
- ...r,
10588
- [accessor]: next
10589
- } : r);
10635
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10590
10636
  });
10591
10637
  refreshTriggerRef.current?.();
10592
10638
  try {
@@ -10615,16 +10661,10 @@ function TableInner({
10615
10661
  if (isGrouped) {
10616
10662
  return prev.map(g => ({
10617
10663
  ...g,
10618
- rows: (g.rows || []).map(r => r.id === row.id ? {
10619
- ...r,
10620
- [accessor]: next
10621
- } : r)
10664
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10622
10665
  }));
10623
10666
  }
10624
- return (prev || []).map(r => r.id === row.id ? {
10625
- ...r,
10626
- [accessor]: next
10627
- } : r);
10667
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10628
10668
  });
10629
10669
  refreshTriggerRef.current?.();
10630
10670
  try {
@@ -10679,16 +10719,10 @@ function TableInner({
10679
10719
  if (isGrouped) {
10680
10720
  return prev.map(g => ({
10681
10721
  ...g,
10682
- rows: (g.rows || []).map(r => r.id === row.id ? {
10683
- ...r,
10684
- [accessor]: next
10685
- } : r)
10722
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10686
10723
  }));
10687
10724
  }
10688
- return (prev || []).map(r => r.id === row.id ? {
10689
- ...r,
10690
- [accessor]: next
10691
- } : r);
10725
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10692
10726
  });
10693
10727
  refreshTriggerRef.current?.();
10694
10728
  try {
@@ -10723,16 +10757,10 @@ function TableInner({
10723
10757
  if (isGrouped) {
10724
10758
  return prev.map(g => ({
10725
10759
  ...g,
10726
- rows: (g.rows || []).map(r => r.id === row.id ? {
10727
- ...r,
10728
- [accessor]: next
10729
- } : r)
10760
+ rows: (g.rows || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r)
10730
10761
  }));
10731
10762
  }
10732
- return (prev || []).map(r => r.id === row.id ? {
10733
- ...r,
10734
- [accessor]: next
10735
- } : r);
10763
+ return (prev || []).map(r => r.id === row.id ? updateRowField(r, accessor, next) : r);
10736
10764
  });
10737
10765
  refreshTriggerRef.current?.();
10738
10766
  try {
@@ -10774,10 +10802,8 @@ function TableInner({
10774
10802
  }, formatted);
10775
10803
  }
10776
10804
  if (col && col.type === "array") {
10777
- const arr = Array.isArray(v) ? v : [];
10778
- const list = formatArrayValue(arr, col);
10779
- const count = arr.length;
10780
- const display = count > 0 ? `${count}: ${list}` : "...";
10805
+ const list = formatArrayValue(v, col);
10806
+ const display = list || "...";
10781
10807
  return /*#__PURE__*/React.createElement("span", {
10782
10808
  title: list || translate("noData")
10783
10809
  }, display);
@@ -10961,50 +10987,6 @@ function TableInner({
10961
10987
  });
10962
10988
  }, [tableDataFlat, isGrouped, groupKey]);
10963
10989
 
10964
- // DUPLICATE
10965
- React.useCallback(row => {
10966
- if (!row) return;
10967
- // try user callback first; if it returns an object with newRow use that
10968
- let newRow = null;
10969
- if (duplicateCallbackRef.current) {
10970
- try {
10971
- const res = duplicateCallbackRef.current(row);
10972
- if (res && res.newRow) {
10973
- newRow = res.newRow;
10974
- }
10975
- } catch (err) {
10976
- console.error("duplicateCallback threw", err);
10977
- }
10978
- }
10979
- // fallback simple clone if callback didn't provide newRow
10980
- if (!newRow) {
10981
- newRow = {
10982
- ...row
10983
- };
10984
- // give it a distinct id if possible
10985
- if (newRow.id != null) {
10986
- newRow.id = `${newRow.id}-dup-${Date.now()}`;
10987
- }
10988
- }
10989
- setLocalData(prev => {
10990
- if (isGrouped) {
10991
- return prev.map(g => {
10992
- const gid = g[groupKey] ?? g.groupId ?? g.groupName;
10993
- // insert into same group as original row
10994
- if (row[groupKey] === gid || g.rows.some(r => r.id === row.id)) {
10995
- return {
10996
- ...g,
10997
- rows: [...(g.rows || []), newRow]
10998
- };
10999
- }
11000
- return g;
11001
- });
11002
- }
11003
- return [...(prev || []), newRow];
11004
- });
11005
- refreshTriggerRef.current?.();
11006
- }, [duplicateCallbackRef, isGrouped, groupKey, refreshTriggerRef]);
11007
-
11008
10990
  // ROW RENDERER
11009
10991
  const rowRenderer = React.useCallback(({
11010
10992
  index,