twico-ui 1.22.1 → 1.22.3

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
@@ -1953,7 +1953,10 @@ interface DatatableProps<T = any> extends Omit<React.HTMLAttributes<HTMLDivEleme
1953
1953
  rowReorder?: boolean;
1954
1954
  /** Enable drag-to-resize row height (handle on the row's bottom edge). @default false */
1955
1955
  rowResize?: boolean;
1956
- /** Called with the new array of row keys after a drag-reorder. */
1956
+ /** Called with the new array of row keys after a drag-reorder. In `serverMode` the drag order is
1957
+ * an optimistic overlay: persist the keys, then hand back a new `rows` prop — the overlay clears on
1958
+ * any `rows` change, so a rejected reorder reverts (reload the authoritative order) and a
1959
+ * server-corrected order reflects, both without remounting. */
1957
1960
  onRowOrderChange?: (keys: Array<string | number>) => void;
1958
1961
  /** Initial pivot model (seeds the toolbar **Pivot** panel, which the user can edit live): aggregate `values` across `rows` (row groups) × `columns` (nested column groups). */
1959
1962
  pivot?: {
package/dist/index.d.ts CHANGED
@@ -1953,7 +1953,10 @@ interface DatatableProps<T = any> extends Omit<React.HTMLAttributes<HTMLDivEleme
1953
1953
  rowReorder?: boolean;
1954
1954
  /** Enable drag-to-resize row height (handle on the row's bottom edge). @default false */
1955
1955
  rowResize?: boolean;
1956
- /** Called with the new array of row keys after a drag-reorder. */
1956
+ /** Called with the new array of row keys after a drag-reorder. In `serverMode` the drag order is
1957
+ * an optimistic overlay: persist the keys, then hand back a new `rows` prop — the overlay clears on
1958
+ * any `rows` change, so a rejected reorder reverts (reload the authoritative order) and a
1959
+ * server-corrected order reflects, both without remounting. */
1957
1960
  onRowOrderChange?: (keys: Array<string | number>) => void;
1958
1961
  /** Initial pivot model (seeds the toolbar **Pivot** panel, which the user can edit live): aggregate `values` across `rows` (row groups) × `columns` (nested column groups). */
1959
1962
  pivot?: {
package/dist/index.mjs CHANGED
@@ -9278,6 +9278,9 @@ function Datatable({
9278
9278
  const [headH, setHeadH] = React51__default.useState(41);
9279
9279
  const theadRef = React51__default.useRef(null);
9280
9280
  const [rowOrder, setRowOrder] = React51__default.useState(null);
9281
+ React51__default.useEffect(() => {
9282
+ if (serverMode) setRowOrder(null);
9283
+ }, [rows, serverMode]);
9281
9284
  const [rowHeights, setRowHeights] = React51__default.useState({});
9282
9285
  const [rowDrag, setRowDrag] = React51__default.useState({ from: null, over: null, after: false });
9283
9286
  const [rowGrab, setRowGrab] = React51__default.useState(null);
@@ -9337,6 +9340,7 @@ function Datatable({
9337
9340
  }
9338
9341
  };
9339
9342
  const stateReadyRef = React51__default.useRef(false);
9343
+ const stateRestoredRef = React51__default.useRef(false);
9340
9344
  const onStateChangeRef = React51__default.useRef(onStateChange);
9341
9345
  onStateChangeRef.current = onStateChange;
9342
9346
  React51__default.useEffect(() => {
@@ -9352,7 +9356,7 @@ function Datatable({
9352
9356
  }
9353
9357
  return void 0;
9354
9358
  }, [filters, sort, quick, pageVal, sizeVal, order, widths, hidden, pins, density, fWidths, fPanelSize, stateKey]);
9355
- React51__default.useEffect(() => {
9359
+ const restoreState = () => {
9356
9360
  let saved = null;
9357
9361
  if (stateKey) {
9358
9362
  try {
@@ -9363,8 +9367,22 @@ function Datatable({
9363
9367
  }
9364
9368
  if (!saved && initialState) saved = initialState;
9365
9369
  if (saved) applyState(saved);
9366
- stateReadyRef.current = true;
9370
+ stateRestoredRef.current = true;
9371
+ };
9372
+ React51__default.useEffect(() => {
9373
+ if (columns.length) {
9374
+ restoreState();
9375
+ stateReadyRef.current = true;
9376
+ }
9377
+ return () => {
9378
+ stateReadyRef.current = false;
9379
+ };
9367
9380
  }, []);
9381
+ React51__default.useEffect(() => {
9382
+ if (stateRestoredRef.current || !columns.length) return;
9383
+ restoreState();
9384
+ stateReadyRef.current = true;
9385
+ }, [columns.length]);
9368
9386
  const rootRef = React51__default.useRef(null);
9369
9387
  const [compact, setCompact] = React51__default.useState(false);
9370
9388
  React51__default.useEffect(() => {
@@ -9437,20 +9455,19 @@ function Datatable({
9437
9455
  React51__default.useEffect(() => {
9438
9456
  setOrder((prev) => mergeColOrder(prev, columns.map((c) => c.field).filter(Boolean)));
9439
9457
  }, [columns]);
9440
- const densitySyncedRef = React51__default.useRef(false);
9458
+ const densityPropRef = React51__default.useRef(densityProp);
9441
9459
  React51__default.useEffect(() => {
9442
- if (densitySyncedRef.current) setDensity(densityProp);
9443
- else densitySyncedRef.current = true;
9460
+ if (densityPropRef.current === densityProp) return;
9461
+ densityPropRef.current = densityProp;
9462
+ setDensity(densityProp);
9444
9463
  }, [densityProp]);
9445
9464
  React51__default.useEffect(() => {
9446
9465
  setAggOn(showAggregation);
9447
9466
  }, [showAggregation]);
9448
- const pageSizeSyncedRef = React51__default.useRef(false);
9467
+ const pageSizePropRef = React51__default.useRef(pageSize);
9449
9468
  React51__default.useEffect(() => {
9450
- if (!pageSizeSyncedRef.current) {
9451
- pageSizeSyncedRef.current = true;
9452
- return;
9453
- }
9469
+ if (pageSizePropRef.current === pageSize) return;
9470
+ pageSizePropRef.current = pageSize;
9454
9471
  if (pageSizeControlled) return;
9455
9472
  setInternalRpp(pageSize > 0 ? pageSize : 10);
9456
9473
  setInternalPage(0);