twico-ui 1.28.0 → 1.29.0

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/index.d.cts CHANGED
@@ -1949,6 +1949,13 @@ interface DatatableProps<T = any> extends Omit<React.HTMLAttributes<HTMLDivEleme
1949
1949
  selectionMode?: "none" | "row" | "cell";
1950
1950
  /** Fired when a row is clicked in "row" selection mode: (row, key). */
1951
1951
  onRowClick?: (row: T, key: string | number) => void;
1952
+ /** #324: controlled highlighted row key for `selectionMode="row"`. When provided, the grid highlights THIS
1953
+ * row (not its internal state) and reports clicks via `onRowClick` so you update the prop — the same
1954
+ * controlled/uncontrolled split as `page`. Pass `null` to clear. Lets an external selection (a graph, a
1955
+ * master/detail pane) drive the row highlight, with scroll-into-view. */
1956
+ activeRowId?: string | number | null;
1957
+ /** #324: scroll the controlled active row into view when `activeRowId` changes. @default true */
1958
+ scrollActiveRowIntoView?: boolean;
1952
1959
  /** Fired when a cell is clicked in "cell" selection mode: (value, row, field). */
1953
1960
  onCellClick?: (value: any, row: T, field: string) => void;
1954
1961
  /** Fired when the active cell changes: ({ key, field } | null). */
package/dist/index.d.ts CHANGED
@@ -1949,6 +1949,13 @@ interface DatatableProps<T = any> extends Omit<React.HTMLAttributes<HTMLDivEleme
1949
1949
  selectionMode?: "none" | "row" | "cell";
1950
1950
  /** Fired when a row is clicked in "row" selection mode: (row, key). */
1951
1951
  onRowClick?: (row: T, key: string | number) => void;
1952
+ /** #324: controlled highlighted row key for `selectionMode="row"`. When provided, the grid highlights THIS
1953
+ * row (not its internal state) and reports clicks via `onRowClick` so you update the prop — the same
1954
+ * controlled/uncontrolled split as `page`. Pass `null` to clear. Lets an external selection (a graph, a
1955
+ * master/detail pane) drive the row highlight, with scroll-into-view. */
1956
+ activeRowId?: string | number | null;
1957
+ /** #324: scroll the controlled active row into view when `activeRowId` changes. @default true */
1958
+ scrollActiveRowIntoView?: boolean;
1952
1959
  /** Fired when a cell is clicked in "cell" selection mode: (value, row, field). */
1953
1960
  onCellClick?: (value: any, row: T, field: string) => void;
1954
1961
  /** Fired when the active cell changes: ({ key, field } | null). */
package/dist/index.mjs CHANGED
@@ -9162,6 +9162,8 @@ function Datatable({
9162
9162
  onCellClick,
9163
9163
  onActiveCellChange,
9164
9164
  onCellSelectionChange,
9165
+ activeRowId,
9166
+ scrollActiveRowIntoView = true,
9165
9167
  enableClipboard = false,
9166
9168
  onCellsCopy,
9167
9169
  onCellsPaste,
@@ -9294,6 +9296,8 @@ function Datatable({
9294
9296
  };
9295
9297
  const [selected, setSelected] = React51__default.useState(() => /* @__PURE__ */ new Set());
9296
9298
  const [activeRow, setActiveRow] = React51__default.useState(null);
9299
+ const activeRowControlled = activeRowId !== void 0;
9300
+ const activeRowVal = activeRowControlled ? activeRowId : activeRow;
9297
9301
  const [activeCell, setActiveCell] = React51__default.useState(null);
9298
9302
  const [anchorCell, setAnchorCell] = React51__default.useState(null);
9299
9303
  const gridId = React51__default.useId();
@@ -10281,7 +10285,7 @@ function Datatable({
10281
10285
  if (selectionMode === "none") return;
10282
10286
  if (e.target.closest("button, a, input, select, .twc-dt__check, .twc-dt__editor-wrap")) return;
10283
10287
  if (selectionMode === "row") {
10284
- setActiveRow(k);
10288
+ if (!activeRowControlled) setActiveRow(k);
10285
10289
  onRowClick?.(row, k);
10286
10290
  onActiveCellChange?.(null);
10287
10291
  }
@@ -10360,8 +10364,9 @@ function Datatable({
10360
10364
  }
10361
10365
  if (selectionMode === "row") {
10362
10366
  e.preventDefault();
10363
- setActiveRow(keyOf(leafRows[r2], r2));
10364
- onRowClick?.(leafRows[r2], keyOf(leafRows[r2], r2));
10367
+ const rk = keyOf(leafRows[r2], r2);
10368
+ if (!activeRowControlled) setActiveRow(rk);
10369
+ onRowClick?.(leafRows[r2], rk);
10365
10370
  return;
10366
10371
  }
10367
10372
  handled = false;
@@ -10402,6 +10407,11 @@ function Datatable({
10402
10407
  prevRowSelSigRef.current = sig;
10403
10408
  cb(selKeys, selectedRows);
10404
10409
  }, [selKeys, selectedRows]);
10410
+ React51__default.useEffect(() => {
10411
+ if (!activeRowControlled || !scrollActiveRowIntoView || activeRowId == null) return;
10412
+ const el = gridRef.current && gridRef.current.querySelector('.twc-dt__row[data-active="true"]');
10413
+ if (el && el.scrollIntoView) el.scrollIntoView({ block: "nearest" });
10414
+ }, [activeRowId, activeRowControlled, scrollActiveRowIntoView]);
10405
10415
  function clearSelection() {
10406
10416
  setSelected(/* @__PURE__ */ new Set());
10407
10417
  }
@@ -11119,7 +11129,7 @@ function Datatable({
11119
11129
  function renderLeaf(row, ri, pinSide, midIdx) {
11120
11130
  const k = keyOf(row, ri);
11121
11131
  const sel = selected.has(k);
11122
- const rowActive = selectionMode === "row" && activeRow === k;
11132
+ const rowActive = selectionMode === "row" && activeRowVal === k;
11123
11133
  const stickyStyle = pinSide === "top" ? { position: "sticky", top: headH, zIndex: 5 } : pinSide === "bottom" ? { position: "sticky", bottom: 0, zIndex: 5 } : void 0;
11124
11134
  const h = rowHeights[k];
11125
11135
  const rowStyle = { ...stickyStyle || {}, ...h ? { height: h } : {} };