@trackunit/react-table 2.11.9 → 2.11.10-alpha-e1e6a0f33ce.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/index.cjs.js +305 -324
- package/index.esm.js +306 -325
- package/migrations/entry.js.map +1 -0
- package/package.json +10 -10
- package/src/hooks/useTablePersistence/useTablePersistence.d.ts +41 -44
- package/src/hooks/useTablePersistence/utils/tableUrlValue.d.ts +27 -0
- package/src/useTable.d.ts +6 -0
- package/src/hooks/useTablePersistence/utils/useCompactTableUrl.d.ts +0 -24
package/index.cjs.js
CHANGED
|
@@ -365,142 +365,88 @@ const ActionSheet = ({ actions, dropdownActions, moreActions = [], selections, r
|
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
368
|
+
* The URL projection of table state: everything except `expanded`.
|
|
369
|
+
*
|
|
370
|
+
* Row expansion is per-session, per-user detail and would make a shared link
|
|
371
|
+
* open rows the recipient has no interest in, so it lives only in
|
|
372
|
+
* localStorage. `usePersistedState`'s `mergeWithStorageOnRead` restores it on
|
|
373
|
+
* load. The remaining fields are written as-is; the gzip step in
|
|
374
|
+
* `useCustomEncoding` handles the size, and a value that reads back to the
|
|
375
|
+
* same shape it was written from cannot drift from storage.
|
|
373
376
|
*/
|
|
374
|
-
const
|
|
375
|
-
columnOrder: "co",
|
|
376
|
-
columnVisibility: "cv",
|
|
377
|
-
sorting: "s",
|
|
378
|
-
columnPinning: "cp",
|
|
379
|
-
columnSizing: "cs",
|
|
380
|
-
};
|
|
381
|
-
const REVERSE_URL_KEY_MAP = Object.fromEntries(Object.entries(URL_KEY_MAP).map(([full, short]) => [short, full]));
|
|
382
|
-
const compactPinningSchema = zod.z.object({
|
|
383
|
-
l: zod.z.array(zod.z.string()).optional(),
|
|
384
|
-
r: zod.z.array(zod.z.string()).optional(),
|
|
385
|
-
left: zod.z.array(zod.z.string()).optional(),
|
|
386
|
-
right: zod.z.array(zod.z.string()).optional(),
|
|
387
|
-
});
|
|
377
|
+
const toTableUrlValue = ({ expanded: _expanded, ...shareable }) => shareable;
|
|
388
378
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* - Stores columnOrder as visible-column order when columnVisibility is available
|
|
393
|
-
* - Drops empty pinning arrays
|
|
394
|
-
* - Excludes `expanded` (not shareable)
|
|
379
|
+
* Short keys used by the compact URL format that was written before the hash
|
|
380
|
+
* carried the full state. Links and bookmarks with that format still exist,
|
|
381
|
+
* so reads keep accepting it.
|
|
395
382
|
*/
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const visibleColumnSet = new Set(visibleColumns);
|
|
403
|
-
const hasColumnVisibility = (columnVisibilityEntries?.length ?? 0) > 0;
|
|
404
|
-
if (hasColumnVisibility) {
|
|
405
|
-
compact[URL_KEY_MAP.columnVisibility] = visibleColumns;
|
|
406
|
-
}
|
|
407
|
-
if (state.columnOrder && state.columnOrder.length > 0) {
|
|
408
|
-
compact[URL_KEY_MAP.columnOrder] = hasColumnVisibility
|
|
409
|
-
? [
|
|
410
|
-
...state.columnOrder.filter(columnId => visibleColumnSet.has(columnId)),
|
|
411
|
-
...visibleColumns.filter(columnId => !state.columnOrder?.includes(columnId)),
|
|
412
|
-
]
|
|
413
|
-
: state.columnOrder;
|
|
414
|
-
}
|
|
415
|
-
if (state.sorting && state.sorting.length > 0) {
|
|
416
|
-
compact[URL_KEY_MAP.sorting] = state.sorting;
|
|
417
|
-
}
|
|
418
|
-
if (state.columnSizing && Object.keys(state.columnSizing).length > 0) {
|
|
419
|
-
compact[URL_KEY_MAP.columnSizing] = state.columnSizing;
|
|
420
|
-
}
|
|
421
|
-
if (state.columnPinning) {
|
|
422
|
-
const pinning = {};
|
|
423
|
-
if (state.columnPinning.left && state.columnPinning.left.length > 0) {
|
|
424
|
-
pinning.l = state.columnPinning.left;
|
|
425
|
-
}
|
|
426
|
-
if (state.columnPinning.right && state.columnPinning.right.length > 0) {
|
|
427
|
-
pinning.r = state.columnPinning.right;
|
|
428
|
-
}
|
|
429
|
-
if (Object.keys(pinning).length > 0) {
|
|
430
|
-
compact[URL_KEY_MAP.columnPinning] = pinning;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
return compact;
|
|
383
|
+
const LEGACY_URL_KEY_MAP = {
|
|
384
|
+
co: "columnOrder",
|
|
385
|
+
cv: "columnVisibility",
|
|
386
|
+
s: "sorting",
|
|
387
|
+
cp: "columnPinning",
|
|
388
|
+
cs: "columnSizing",
|
|
434
389
|
};
|
|
435
|
-
const
|
|
436
|
-
const
|
|
437
|
-
const
|
|
390
|
+
const recordSchema = zod.z.record(zod.z.string(), zod.z.unknown());
|
|
391
|
+
const legacyVisibleListSchema = zod.z.array(zod.z.string());
|
|
392
|
+
const legacyVisibilitySchema = zod.z
|
|
438
393
|
.object({
|
|
439
394
|
v: zod.z.array(zod.z.string()).optional(),
|
|
440
395
|
h: zod.z.array(zod.z.string()).optional(),
|
|
441
396
|
})
|
|
442
397
|
.strict();
|
|
398
|
+
const legacyPinningSchema = zod.z.object({
|
|
399
|
+
l: zod.z.array(zod.z.string()).optional(),
|
|
400
|
+
r: zod.z.array(zod.z.string()).optional(),
|
|
401
|
+
left: zod.z.array(zod.z.string()).optional(),
|
|
402
|
+
right: zod.z.array(zod.z.string()).optional(),
|
|
403
|
+
});
|
|
443
404
|
/**
|
|
444
|
-
*
|
|
405
|
+
* Normalises a decoded URL value into the full `TableColumnOptions` shape.
|
|
406
|
+
*
|
|
407
|
+
* A value written by {@link toTableUrlValue} passes through unchanged, except
|
|
408
|
+
* that a `columnPinning` with one side missing gets the other side filled in
|
|
409
|
+
* as `[]`. Values in the legacy compact format are expanded:
|
|
410
|
+
* - short keys (`co`, `cv`, `s`, `cp`, `cs`) become full names;
|
|
411
|
+
* - a `columnVisibility` array of visible column IDs becomes a visible-only
|
|
412
|
+
* map (see `VISIBLE_ONLY_COLUMN_VISIBILITY_KEY`);
|
|
413
|
+
* - a `columnVisibility` `{ v, h }` pair becomes explicit booleans;
|
|
414
|
+
* - `columnPinning` `{ l, r }` becomes `{ left, right }`.
|
|
415
|
+
*
|
|
416
|
+
* Non-object input is returned as-is so validation can reject it.
|
|
445
417
|
*/
|
|
446
|
-
const
|
|
447
|
-
const parsed =
|
|
418
|
+
const fromTableUrlValue = (decoded) => {
|
|
419
|
+
const parsed = recordSchema.safeParse(decoded);
|
|
448
420
|
if (!parsed.success) {
|
|
449
421
|
return decoded;
|
|
450
422
|
}
|
|
451
423
|
const expanded = {};
|
|
452
424
|
for (const [key, value] of Object.entries(parsed.data)) {
|
|
453
|
-
|
|
454
|
-
expanded[fullKey] = value;
|
|
425
|
+
expanded[LEGACY_URL_KEY_MAP[key] ?? key] = value;
|
|
455
426
|
}
|
|
456
|
-
const
|
|
457
|
-
if (
|
|
427
|
+
const visibleList = legacyVisibleListSchema.safeParse(expanded.columnVisibility);
|
|
428
|
+
if (visibleList.success) {
|
|
458
429
|
expanded.columnVisibility = Object.fromEntries([
|
|
459
430
|
[sharedUtils.VISIBLE_ONLY_COLUMN_VISIBILITY_KEY, true],
|
|
460
|
-
...
|
|
431
|
+
...visibleList.data.map(col => [col, true]),
|
|
461
432
|
]);
|
|
462
433
|
}
|
|
463
|
-
const
|
|
464
|
-
if (
|
|
434
|
+
const legacyVisibility = legacyVisibilitySchema.safeParse(expanded.columnVisibility);
|
|
435
|
+
if (legacyVisibility.success) {
|
|
465
436
|
expanded.columnVisibility = Object.fromEntries([
|
|
466
|
-
...(
|
|
467
|
-
...(
|
|
437
|
+
...(legacyVisibility.data.v ?? []).map(col => [col, true]),
|
|
438
|
+
...(legacyVisibility.data.h ?? []).map(col => [col, false]),
|
|
468
439
|
]);
|
|
469
440
|
}
|
|
470
|
-
const
|
|
471
|
-
if (
|
|
441
|
+
const legacyPinning = legacyPinningSchema.safeParse(expanded.columnPinning);
|
|
442
|
+
if (legacyPinning.success) {
|
|
472
443
|
expanded.columnPinning = {
|
|
473
|
-
left:
|
|
474
|
-
right:
|
|
444
|
+
left: legacyPinning.data.l ?? legacyPinning.data.left ?? [],
|
|
445
|
+
right: legacyPinning.data.r ?? legacyPinning.data.right ?? [],
|
|
475
446
|
};
|
|
476
447
|
}
|
|
477
448
|
return expanded;
|
|
478
449
|
};
|
|
479
|
-
/**
|
|
480
|
-
* Provides transform functions for compacting table state before URL encoding
|
|
481
|
-
* and expanding it back after URL decoding.
|
|
482
|
-
*
|
|
483
|
-
* The compaction strategy:
|
|
484
|
-
* - Short property keys (columnOrder → co, columnVisibility → cv, etc.)
|
|
485
|
-
* - columnVisibility stored as an array of visible column names only
|
|
486
|
-
* - columnOrder stored as visible-column order when visibility is available
|
|
487
|
-
* - columnSizing stored under a short key (`cs`)
|
|
488
|
-
* - `expanded` is excluded from the URL and restored from localStorage via
|
|
489
|
-
* `usePersistedState`'s `mergeWithStorageOnRead`
|
|
490
|
-
* - Empty pinning arrays are excluded
|
|
491
|
-
*
|
|
492
|
-
* These transforms are designed to plug into {@link usePersistedState}'s
|
|
493
|
-
* `toUrlValue` and `fromUrlValue` options.
|
|
494
|
-
*/
|
|
495
|
-
const useCompactTableUrl = () => {
|
|
496
|
-
const toUrlValue = react.useCallback((state) => {
|
|
497
|
-
return compactForUrl(state);
|
|
498
|
-
}, []);
|
|
499
|
-
const fromUrlValue = react.useCallback((decoded) => {
|
|
500
|
-
return expandFromUrl(decoded);
|
|
501
|
-
}, []);
|
|
502
|
-
return react.useMemo(() => ({ toUrlValue, fromUrlValue }), [toUrlValue, fromUrlValue]);
|
|
503
|
-
};
|
|
504
450
|
|
|
505
451
|
const PERSISTENCE_KEY_MAX_LENGTH = 15;
|
|
506
452
|
const camelCaseRegex = /^[a-z][a-zA-Z0-9]*$/;
|
|
@@ -531,69 +477,96 @@ const validateTableState = (raw) => {
|
|
|
531
477
|
const result = tableStateSchema.safeParse(raw);
|
|
532
478
|
return result.success ? result.data : undefined;
|
|
533
479
|
};
|
|
480
|
+
/**
|
|
481
|
+
* Drops fields that hold nothing (empty arrays, empty maps, pinning with no
|
|
482
|
+
* side) so a reset column is removed from storage rather than stored as empty.
|
|
483
|
+
*/
|
|
484
|
+
const pruneEmptyFields = (state) => {
|
|
485
|
+
const { columnOrder, columnSizing, columnVisibility, sorting, columnPinning, expanded } = state;
|
|
486
|
+
const pruned = {};
|
|
487
|
+
if (columnOrder && columnOrder.length > 0) {
|
|
488
|
+
pruned.columnOrder = columnOrder;
|
|
489
|
+
}
|
|
490
|
+
if (columnSizing && sharedUtils.objectKeys(columnSizing).length > 0) {
|
|
491
|
+
pruned.columnSizing = columnSizing;
|
|
492
|
+
}
|
|
493
|
+
if (columnVisibility && sharedUtils.objectKeys(columnVisibility).length > 0) {
|
|
494
|
+
pruned.columnVisibility = columnVisibility;
|
|
495
|
+
}
|
|
496
|
+
if (sorting && sorting.length > 0) {
|
|
497
|
+
pruned.sorting = sorting;
|
|
498
|
+
}
|
|
499
|
+
if (columnPinning && ((columnPinning.left?.length ?? 0) > 0 || (columnPinning.right?.length ?? 0) > 0)) {
|
|
500
|
+
pruned.columnPinning = columnPinning;
|
|
501
|
+
}
|
|
502
|
+
if (expanded === true || (typeof expanded === "object" && sharedUtils.objectKeys(expanded).length > 0)) {
|
|
503
|
+
pruned.expanded = expanded;
|
|
504
|
+
}
|
|
505
|
+
return pruned;
|
|
506
|
+
};
|
|
507
|
+
const URL_WRITE_DEBOUNCE_MS = 300;
|
|
534
508
|
/**
|
|
535
509
|
* Changes reported before `clientSideUserId` resolves carry no owner — the user
|
|
536
510
|
* was already editing while their id was in flight — so the identity that
|
|
537
511
|
* resolves adopts them. Once a defined identity owns the reported state it must
|
|
538
|
-
* not be adopted by a later identity, including a
|
|
539
|
-
*
|
|
540
|
-
*
|
|
512
|
+
* not be adopted by a later identity, including through a gap where the current
|
|
513
|
+
* id is unset: treating that gap as unowned would copy one person's layout into
|
|
514
|
+
* the next user's scoped storage.
|
|
541
515
|
*/
|
|
542
|
-
const
|
|
516
|
+
const isOwnedBy = (ownerId, clientSideUserId) => ownerId === undefined || ownerId === clientSideUserId;
|
|
517
|
+
/** Whether anything of `state` would reach the URL; a layout of only `expanded` has nothing to share. */
|
|
518
|
+
const hasShareableFields = (state) => sharedUtils.objectKeys(toTableUrlValue(state)).length > 0;
|
|
543
519
|
/**
|
|
544
520
|
* Persists and restores table column state (order, sizing, visibility, sorting, pinning, expanded) using
|
|
545
|
-
* the URL **hash fragment
|
|
521
|
+
* localStorage and the URL **hash fragment**.
|
|
546
522
|
*
|
|
547
523
|
* Storage scope:
|
|
548
|
-
* -
|
|
549
|
-
* -
|
|
524
|
+
* - localStorage: everything, scoped to the current user.
|
|
525
|
+
* - URL hash (shareable): everything except `expanded`.
|
|
550
526
|
*
|
|
551
527
|
* The hash slot is used instead of search params because some deployments
|
|
552
528
|
* route through AWS WAF, whose `SizeRestrictions_QUERYSTRING` managed rule
|
|
553
529
|
* caps the query string at ~5000 bytes — easily breached by wide tables.
|
|
554
530
|
* The fragment is client-only and bypasses that cap entirely (subject to a
|
|
555
|
-
* 64 KiB soft limit enforced by
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* one-
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
* wrote it; the stamp is read only by the login redirect, which drops a hash
|
|
595
|
-
* left behind by a *different* account that also uses this browser so
|
|
596
|
-
* accounts sharing a PC do not hand their layouts to each other (GLU-2396).
|
|
531
|
+
* 64 KiB soft limit enforced by the URL sync).
|
|
532
|
+
*
|
|
533
|
+
* On load the hash wins, so a link or bookmark renders the same layout for
|
|
534
|
+
* whoever opens it, and localStorage fills in what the hash omits (`expanded`).
|
|
535
|
+
* Opening a URL that carries a layout saves it for the account that loaded the
|
|
536
|
+
* page, so a pasted link sticks without a further edit. A layout that exists
|
|
537
|
+
* only in localStorage is never copied into the hash on load: doing that put
|
|
538
|
+
* the current layout into every history entry, so a later visit via history,
|
|
539
|
+
* a bookmark, or a login redirect replayed an older layout and saved it over
|
|
540
|
+
* the current one (GLU-2396).
|
|
541
|
+
*
|
|
542
|
+
* `onTableStateChange` takes a *partial* state and merges it into whatever was
|
|
543
|
+
* reported earlier in the session, so a consumer can report a single slice
|
|
544
|
+
* (e.g. only `expanded`) without the omitted fields falling back to their
|
|
545
|
+
* mount-time values. A field reported empty is dropped from the stored state,
|
|
546
|
+
* and once every field is empty the entry is removed altogether.
|
|
547
|
+
*
|
|
548
|
+
* Each change is written to localStorage as soon as it is reported, so
|
|
549
|
+
* navigating away right after an edit cannot lose it. The hash is written
|
|
550
|
+
* after a {@link URL_WRITE_DEBOUNCE_MS} quiet period, replacing the current
|
|
551
|
+
* history entry: a drag or a run of toggles leaves one entry, not one per step.
|
|
552
|
+
*
|
|
553
|
+
* Every hash write is stamped with the identity that wrote it. The stamp is
|
|
554
|
+
* read only by the login redirect, which drops a hash left behind by another
|
|
555
|
+
* account that also uses this browser, so accounts sharing a PC do not hand
|
|
556
|
+
* their layouts to each other (GLU-2396).
|
|
557
|
+
*
|
|
558
|
+
* Changes reported before `clientSideUserId` resolves are held in React state
|
|
559
|
+
* and written to the user's scoped storage and stamped into the hash once it
|
|
560
|
+
* does. The id can also change while the table is mounted: releasing an
|
|
561
|
+
* impersonated identity renews the token, and the new claims are published
|
|
562
|
+
* before the page navigates away. Reported state is therefore tagged with the
|
|
563
|
+
* identity that produced it and persisted only while that identity is current,
|
|
564
|
+
* and the layout read on load is committed to storage only for the account
|
|
565
|
+
* that opened the page, so a layout never crosses from one account into
|
|
566
|
+
* another's scoped storage or into their hash on its own. An identity that
|
|
567
|
+
* takes over and then edits saves what it sees on screen — the opener's hash
|
|
568
|
+
* over its own stored layout — under its own key, the same as editing an
|
|
569
|
+
* opened link.
|
|
597
570
|
*
|
|
598
571
|
* @param persistenceKey - Unique key used to store and retrieve the table state.
|
|
599
572
|
* Must be camelCase and at most 15 characters (e.g. "userTable", "assetList").
|
|
@@ -603,145 +576,104 @@ const isOwnedByCurrentUser = (ownerId, clientSideUserId) => ownerId === undefine
|
|
|
603
576
|
* @throws {Error} If persistenceKey is not camelCase or exceeds 15 characters.
|
|
604
577
|
*/
|
|
605
578
|
const useTablePersistence = (persistenceKey) => {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
579
|
+
// The key is a constant per table; validate it once rather than every render.
|
|
580
|
+
react.useMemo(() => {
|
|
581
|
+
const parseResult = persistenceKeySchema.safeParse(persistenceKey);
|
|
582
|
+
if (!parseResult.success) {
|
|
583
|
+
throw new Error(parseResult.error.errors.map(e => e.message).join(", "));
|
|
584
|
+
}
|
|
585
|
+
}, [persistenceKey]);
|
|
610
586
|
const { clientSideUserId } = reactCoreHooks.useCurrentUser();
|
|
611
587
|
const localStorageEnabled = clientSideUserId !== undefined;
|
|
612
|
-
const {
|
|
613
|
-
const { initialState, persistState, clearState, commitHydratedState } = reactComponents.usePersistedState({
|
|
588
|
+
const { initialState, persistToStorage, persistToUrl } = reactComponents.usePersistedState({
|
|
614
589
|
key: `${persistenceKey}Tp`,
|
|
615
590
|
validate: validateTableState,
|
|
616
|
-
toUrlValue,
|
|
617
|
-
fromUrlValue,
|
|
591
|
+
toUrlValue: toTableUrlValue,
|
|
592
|
+
fromUrlValue: fromTableUrlValue,
|
|
618
593
|
// Replace, so a second edit updates this visit's history entry. A push
|
|
619
594
|
// per column change left older layouts in history, and a later full load
|
|
620
595
|
// of one of them saved that layout over the newer one (GLU-2396).
|
|
621
596
|
replace: true,
|
|
622
597
|
clientSideUserId,
|
|
623
598
|
localStorageEnabled,
|
|
624
|
-
// `
|
|
625
|
-
//
|
|
626
|
-
// survive reloads.
|
|
599
|
+
// `expanded` is kept out of the URL; the merge restores it from
|
|
600
|
+
// localStorage on read so it survives reloads.
|
|
627
601
|
mergeWithStorageOnRead: true,
|
|
628
|
-
// Move the persisted blob into the URL hash so it bypasses the AWS WAF
|
|
629
|
-
// query-string cap. `usePersistedState` also migrates any legacy
|
|
630
|
-
// `?<key>=...` search param into the hash on first load.
|
|
631
602
|
urlLocation: "hash",
|
|
632
|
-
// The hash outlives the session that wrote it and is carried through the
|
|
633
|
-
// login redirect to the next account on the same browser. Stamp it with
|
|
634
|
-
// the writing identity so the redirect can drop another account's layout
|
|
635
|
-
// (GLU-2396). Reads are unaffected: the URL still wins for everyone.
|
|
636
603
|
stampUrlWithIdentity: true,
|
|
637
604
|
});
|
|
638
|
-
//
|
|
639
|
-
|
|
640
|
-
//
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
//
|
|
605
|
+
// Opening a shared URL saves its layout for the account that opened it: the
|
|
606
|
+
// first identity to resolve while the table is mounted. `persistToStorage`
|
|
607
|
+
// dedupes against what storage held, so this writes only when the hash
|
|
608
|
+
// changed something; a reload of the account's own link, or a layout that
|
|
609
|
+
// came from storage alone, writes nothing. `initialState` is re-read in the
|
|
610
|
+
// render where `clientSideUserId` resolves, so the write sees the merge for
|
|
611
|
+
// the resolved account. An identity that takes over later does not commit:
|
|
612
|
+
// the hash on screen is the opener's layout, not theirs.
|
|
644
613
|
const openingUserIdRef = react.useRef(undefined);
|
|
645
614
|
react.useEffect(() => {
|
|
646
|
-
if (clientSideUserId === undefined
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
if (!commitHydratedState()) {
|
|
615
|
+
if (clientSideUserId === undefined) {
|
|
650
616
|
return;
|
|
651
617
|
}
|
|
652
|
-
openingUserIdRef.current = clientSideUserId;
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const debouncedPending = reactComponents.useDebounce(pendingState, { delay: 300 });
|
|
656
|
-
const hasReportedChange = debouncedPending !== null;
|
|
657
|
-
const currentState = react.useMemo(() => {
|
|
658
|
-
if (!debouncedPending && !initialState) {
|
|
659
|
-
return undefined;
|
|
660
|
-
}
|
|
661
|
-
const columnOrder = debouncedPending?.state.columnOrder ?? initialState?.columnOrder;
|
|
662
|
-
const columnSizing = debouncedPending?.state.columnSizing ?? initialState?.columnSizing;
|
|
663
|
-
const columnVisibility = debouncedPending?.state.columnVisibility ?? initialState?.columnVisibility;
|
|
664
|
-
const sorting = debouncedPending?.state.sorting ?? initialState?.sorting;
|
|
665
|
-
const columnPinning = debouncedPending?.state.columnPinning ?? initialState?.columnPinning;
|
|
666
|
-
const expanded = debouncedPending?.state.expanded ?? initialState?.expanded;
|
|
667
|
-
const state = {};
|
|
668
|
-
if (columnOrder && columnOrder.length > 0) {
|
|
669
|
-
state.columnOrder = columnOrder;
|
|
670
|
-
}
|
|
671
|
-
if (columnSizing && sharedUtils.objectKeys(columnSizing).length > 0) {
|
|
672
|
-
state.columnSizing = columnSizing;
|
|
618
|
+
openingUserIdRef.current ?? (openingUserIdRef.current = clientSideUserId);
|
|
619
|
+
if (initialState !== undefined && openingUserIdRef.current === clientSideUserId) {
|
|
620
|
+
persistToStorage(initialState);
|
|
673
621
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
state.columnPinning = columnPinning;
|
|
682
|
-
}
|
|
683
|
-
if (expanded === true || (typeof expanded === "object" && sharedUtils.objectKeys(expanded).length > 0)) {
|
|
684
|
-
state.expanded = expanded;
|
|
685
|
-
}
|
|
686
|
-
return sharedUtils.objectKeys(state).length > 0 || hasReportedChange ? state : undefined;
|
|
687
|
-
}, [debouncedPending, hasReportedChange, initialState]);
|
|
622
|
+
}, [clientSideUserId, initialState, persistToStorage]);
|
|
623
|
+
// Everything reported in this session, merged, with the identity it belongs
|
|
624
|
+
// to. `null` until the first report so a mount with no edits writes nothing.
|
|
625
|
+
// Reports merge into whatever is held, whoever holds it; which identity that
|
|
626
|
+
// is gets settled in render below, where `clientSideUserId` is current. The
|
|
627
|
+
// callback stays stable so consumers can hold on to it.
|
|
628
|
+
const [reported, setReported] = react.useState(null);
|
|
688
629
|
const onTableStateChange = react.useCallback((newTableState) => {
|
|
689
630
|
if (!newTableState) {
|
|
690
631
|
return;
|
|
691
632
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
633
|
+
setReported(previous => ({ ownerId: previous?.ownerId, state: { ...previous?.state, ...newTableState } }));
|
|
634
|
+
}, []);
|
|
635
|
+
// Settle ownership in the render where an identity is current: reports made
|
|
636
|
+
// while no identity was resolved belong to the one that resolves; reports
|
|
637
|
+
// owned by a different identity are discarded so the current one starts
|
|
638
|
+
// over from what it sees on screen. While the id is unset nothing is
|
|
639
|
+
// settled, so edits in the gap stay with their owner and are kept if that
|
|
640
|
+
// owner comes back.
|
|
641
|
+
if (reported !== null && clientSideUserId !== undefined && reported.ownerId !== clientSideUserId) {
|
|
642
|
+
setReported(previous => {
|
|
643
|
+
if (previous === null || previous.ownerId === clientSideUserId) {
|
|
644
|
+
return previous;
|
|
697
645
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
646
|
+
return previous.ownerId === undefined ? { ...previous, ownerId: clientSideUserId } : null;
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
// `undefined` before any report or while the report belongs to another
|
|
650
|
+
// identity; afterwards the full layout to persist, `{}` meaning "remove the
|
|
651
|
+
// entry", tagged with the identity it is persisted for.
|
|
652
|
+
const currentState = react.useMemo(() => {
|
|
653
|
+
if (reported === null || !isOwnedBy(reported.ownerId, clientSideUserId)) {
|
|
654
|
+
return undefined;
|
|
706
655
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
state: { ...previousState?.state, ...newTableState },
|
|
710
|
-
}));
|
|
711
|
-
}, [clientSideUserId]);
|
|
656
|
+
return { ownerId: clientSideUserId, state: pruneEmptyFields({ ...initialState, ...reported.state }) };
|
|
657
|
+
}, [clientSideUserId, initialState, reported]);
|
|
712
658
|
react.useEffect(() => {
|
|
713
|
-
|
|
714
|
-
// storage on its own, via `commitHydratedState`, and must not be echoed
|
|
715
|
-
// through here — `persistState` treats the hydrated value as already saved.
|
|
716
|
-
if (!hasReportedChange || !currentState) {
|
|
659
|
+
if (currentState === undefined) {
|
|
717
660
|
return;
|
|
718
661
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
// State reported before identity resolution is adopted by the first
|
|
731
|
-
// identity that resolves. Hydration-only runs cannot reach this branch.
|
|
732
|
-
if (debouncedOwnerId === undefined && clientSideUserId !== undefined) {
|
|
733
|
-
pendingOwnerIdRef.current = clientSideUserId;
|
|
734
|
-
}
|
|
735
|
-
if (sharedUtils.objectKeys(currentState).length === 0) {
|
|
736
|
-
clearState();
|
|
662
|
+
persistToStorage(sharedUtils.objectKeys(currentState.state).length > 0 ? currentState.state : undefined);
|
|
663
|
+
}, [currentState, persistToStorage]);
|
|
664
|
+
// The debounced value carries the identity it was computed for, so a change
|
|
665
|
+
// of identity during the quiet period discards the pending write instead of
|
|
666
|
+
// stamping the previous identity's layout into the new one's hash. A layout
|
|
667
|
+
// whose shareable part is empty removes the hash entry even when a
|
|
668
|
+
// storage-only field such as `expanded` remains.
|
|
669
|
+
const debouncedState = reactComponents.useDebounce(currentState, { delay: URL_WRITE_DEBOUNCE_MS });
|
|
670
|
+
react.useEffect(() => {
|
|
671
|
+
if (debouncedState === undefined || !isOwnedBy(debouncedState.ownerId, clientSideUserId)) {
|
|
737
672
|
return;
|
|
738
673
|
}
|
|
739
|
-
|
|
740
|
-
}, [
|
|
741
|
-
return react.useMemo(() => ({
|
|
742
|
-
onTableStateChange,
|
|
743
|
-
initialState,
|
|
744
|
-
}), [initialState, onTableStateChange]);
|
|
674
|
+
persistToUrl(hasShareableFields(debouncedState.state) ? debouncedState.state : undefined);
|
|
675
|
+
}, [clientSideUserId, debouncedState, persistToUrl]);
|
|
676
|
+
return react.useMemo(() => ({ onTableStateChange, initialState }), [initialState, onTableStateChange]);
|
|
745
677
|
};
|
|
746
678
|
|
|
747
679
|
const cvaColumnFilterGrabbable = cssClassVarianceUtilities.cva({
|
|
@@ -1782,6 +1714,8 @@ const useColumnHelper = () => {
|
|
|
1782
1714
|
}, []);
|
|
1783
1715
|
};
|
|
1784
1716
|
|
|
1717
|
+
const areSameSequence = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
|
|
1718
|
+
const isSamePinning = (left, right) => areSameSequence(left.left ?? [], right.left ?? []) && areSameSequence(left.right ?? [], right.right ?? []);
|
|
1785
1719
|
const computeMergedPinning = (initialPinning, columnConfigPinning) => {
|
|
1786
1720
|
const leftPinning = initialPinning?.left;
|
|
1787
1721
|
const mergedLeft = leftPinning !== undefined && leftPinning.length > 0 ? [...leftPinning] : [...(columnConfigPinning.left ?? [])];
|
|
@@ -1810,6 +1744,12 @@ const computeMergedPinning = (initialPinning, columnConfigPinning) => {
|
|
|
1810
1744
|
*
|
|
1811
1745
|
* `onTableStateChange` is called with the field that changed, not the whole state, so anything
|
|
1812
1746
|
* storing it has to merge each report into what it already holds. `useTablePersistence` does.
|
|
1747
|
+
* Within that field only what differs from the column definitions is reported — visibility
|
|
1748
|
+
* entries equal to `meta.hiddenByDefault`, sizes equal to `size`, an order equal to the
|
|
1749
|
+
* definition order, a pinning equal to `meta.pinned` — and an emptied field is reported empty.
|
|
1750
|
+
* Defaults therefore belong on the column definitions; a value in `initialState` is read as
|
|
1751
|
+
* saved state, not as a default. Columns without an explicit `id` take no part in the
|
|
1752
|
+
* defaults (as before), so they are always reported once they are in the state.
|
|
1813
1753
|
*
|
|
1814
1754
|
* @template TData - The type representing the data model associated with the table.
|
|
1815
1755
|
* @param {TableOptionsProps<TData>} props - The props object containing configuration options.
|
|
@@ -1844,42 +1784,52 @@ const computeMergedPinning = (initialPinning, columnConfigPinning) => {
|
|
|
1844
1784
|
*/
|
|
1845
1785
|
const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProps }) => {
|
|
1846
1786
|
const stableColumns = react.useMemo(() => JSON.stringify(columns), [columns]);
|
|
1847
|
-
|
|
1787
|
+
// The column definitions are the single source of defaults: `meta.hiddenByDefault`, definition
|
|
1788
|
+
// order, `meta.pinned`, and `size`. They seed the state when `initialState` says nothing, and
|
|
1789
|
+
// they are the baseline for what `onTableStateChange` reports (see `persistTableState`).
|
|
1790
|
+
// Consumers that want a different default should set it on the column, not in `initialState`:
|
|
1791
|
+
// a value in `initialState` is treated as saved state.
|
|
1792
|
+
const columnDefaults = react.useMemo(() => {
|
|
1848
1793
|
const columnsList = JSON.parse(stableColumns);
|
|
1794
|
+
const visibilityById = {};
|
|
1795
|
+
const lockedVisibleIds = new Set();
|
|
1796
|
+
const order = [];
|
|
1797
|
+
columnsList.forEach(column => {
|
|
1798
|
+
if (column.id === undefined) {
|
|
1799
|
+
return;
|
|
1800
|
+
}
|
|
1801
|
+
order.push(column.id);
|
|
1802
|
+
const columnCannotHide = reactTableProps.enableHiding === false || column.enableHiding === false;
|
|
1803
|
+
if (columnCannotHide) {
|
|
1804
|
+
lockedVisibleIds.add(column.id);
|
|
1805
|
+
}
|
|
1806
|
+
visibilityById[column.id] = columnCannotHide ? true : column.meta?.hiddenByDefault !== true;
|
|
1807
|
+
});
|
|
1808
|
+
return { visibilityById, lockedVisibleIds, order };
|
|
1809
|
+
}, [stableColumns, reactTableProps.enableHiding]);
|
|
1810
|
+
const updatedInitialColumnVisibility = react.useMemo(() => {
|
|
1849
1811
|
const initialStateColumnVisibility = initialState?.columnVisibility;
|
|
1850
1812
|
const shouldHideColumnsMissingFromInitialVisibility = initialStateColumnVisibility?.[sharedUtils.VISIBLE_ONLY_COLUMN_VISIBILITY_KEY] === true;
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
if (column.id && initialStateColumnVisibility[column.id] !== undefined) {
|
|
1855
|
-
const columnCannotHide = reactTableProps.enableHiding === false || column.enableHiding === false;
|
|
1856
|
-
return [column.id, columnCannotHide ? true : initialStateColumnVisibility[column.id]];
|
|
1857
|
-
}
|
|
1858
|
-
return null;
|
|
1859
|
-
})
|
|
1860
|
-
.filter(sharedUtils.nonNullable))
|
|
1861
|
-
: {};
|
|
1862
|
-
columnsList.forEach((column) => {
|
|
1863
|
-
if (column.id && resultFromInitialState[column.id] === undefined) {
|
|
1864
|
-
const columnCannotHide = reactTableProps.enableHiding === false || column.enableHiding === false;
|
|
1865
|
-
resultFromInitialState[column.id] = columnCannotHide
|
|
1866
|
-
? true
|
|
1867
|
-
: shouldHideColumnsMissingFromInitialVisibility
|
|
1868
|
-
? false
|
|
1869
|
-
: column.meta?.hiddenByDefault !== true;
|
|
1813
|
+
return Object.fromEntries(sharedUtils.objectEntries(columnDefaults.visibilityById).map(([columnId, visibleByDefault]) => {
|
|
1814
|
+
if (columnDefaults.lockedVisibleIds.has(columnId)) {
|
|
1815
|
+
return [columnId, true];
|
|
1870
1816
|
}
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1817
|
+
const savedVisibility = initialStateColumnVisibility?.[columnId];
|
|
1818
|
+
if (savedVisibility !== undefined) {
|
|
1819
|
+
return [columnId, savedVisibility];
|
|
1820
|
+
}
|
|
1821
|
+
return [columnId, shouldHideColumnsMissingFromInitialVisibility ? false : visibleByDefault];
|
|
1822
|
+
}));
|
|
1823
|
+
}, [columnDefaults, initialState?.columnVisibility]);
|
|
1874
1824
|
const updatedInitialColumnOrder = react.useMemo(() => {
|
|
1875
1825
|
const resultFromInitialState = initialState?.columnOrder ? [...initialState.columnOrder] : [];
|
|
1876
|
-
|
|
1877
|
-
if (
|
|
1878
|
-
resultFromInitialState.push(
|
|
1826
|
+
columnDefaults.order.forEach(columnId => {
|
|
1827
|
+
if (!resultFromInitialState.includes(columnId)) {
|
|
1828
|
+
resultFromInitialState.push(columnId);
|
|
1879
1829
|
}
|
|
1880
1830
|
});
|
|
1881
1831
|
return resultFromInitialState;
|
|
1882
|
-
}, [
|
|
1832
|
+
}, [columnDefaults, initialState?.columnOrder]);
|
|
1883
1833
|
const stableUpdatedInitialColumnPinning = react.useMemo(() => {
|
|
1884
1834
|
const pinningState = { left: [], right: [] };
|
|
1885
1835
|
JSON.parse(stableColumns).forEach((column) => {
|
|
@@ -1937,23 +1887,51 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
1937
1887
|
// A ref exposes the latest derived state to the change callbacks without making them depend on
|
|
1938
1888
|
// it (callbacks run on user events, outside render). Every managed key on `state` is always
|
|
1939
1889
|
// defined — it originates from `baseState` — so the callbacks read it directly.
|
|
1890
|
+
//
|
|
1891
|
+
// `applyUpdate` resolves a TanStack updater against that ref and advances the ref at once, so
|
|
1892
|
+
// several updaters fired from one event (the column menu's Reset toggles every column that
|
|
1893
|
+
// differs from its default in a single click) build on each other instead of each starting
|
|
1894
|
+
// from the state as of the last render.
|
|
1940
1895
|
const stateRef = react.useRef(state);
|
|
1941
1896
|
stateRef.current = state;
|
|
1897
|
+
const applyUpdate = (key, value) => {
|
|
1898
|
+
const current = stateRef.current[key];
|
|
1899
|
+
const next = typeof value === "function" ? value(current) : value;
|
|
1900
|
+
stateRef.current = { ...stateRef.current, [key]: next };
|
|
1901
|
+
setUserEdits(prev => ({ ...prev, [key]: next }));
|
|
1902
|
+
return next;
|
|
1903
|
+
};
|
|
1942
1904
|
// Reports only the field that changed — `useTablePersistence` merges partial reports — so a
|
|
1943
|
-
// change can never store another field's unsettled or transient value.
|
|
1944
|
-
//
|
|
1905
|
+
// change can never store another field's unsettled or transient value. Within a field, only
|
|
1906
|
+
// what differs from the column defaults is reported: visibility entries equal to
|
|
1907
|
+
// `hiddenByDefault`, sizes equal to the default size, an order equal to the definition order and
|
|
1908
|
+
// a pinning equal to `meta.pinned` all read back the same when absent, so storing them would only
|
|
1909
|
+
// freeze today's defaults under the user's layout and bloat what is shared. A field with nothing
|
|
1910
|
+
// left is reported empty so the store can drop it.
|
|
1945
1911
|
const persistTableState = react.useCallback((nextState) => {
|
|
1946
1912
|
if (!onTableStateChange) {
|
|
1947
1913
|
return;
|
|
1948
1914
|
}
|
|
1949
|
-
const
|
|
1950
|
-
if (
|
|
1951
|
-
|
|
1952
|
-
|
|
1915
|
+
const reported = { ...nextState };
|
|
1916
|
+
if (nextState.columnVisibility) {
|
|
1917
|
+
reported.columnVisibility = Object.fromEntries(sharedUtils.objectEntries(nextState.columnVisibility).filter(([columnId, visible]) => columnDefaults.visibilityById[columnId] !== visible));
|
|
1918
|
+
}
|
|
1919
|
+
if (nextState.columnSizing) {
|
|
1920
|
+
reported.columnSizing = Object.fromEntries(sharedUtils.objectEntries(nextState.columnSizing).filter(([columnId, size]) => defaultColumnSizingById[columnId] !== size));
|
|
1921
|
+
}
|
|
1922
|
+
if (nextState.columnOrder && areSameSequence(nextState.columnOrder, columnDefaults.order)) {
|
|
1923
|
+
reported.columnOrder = [];
|
|
1953
1924
|
}
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1925
|
+
if (nextState.columnPinning && isSamePinning(nextState.columnPinning, stableUpdatedInitialColumnPinning)) {
|
|
1926
|
+
reported.columnPinning = { left: [], right: [] };
|
|
1927
|
+
}
|
|
1928
|
+
onTableStateChange(reported);
|
|
1929
|
+
}, [onTableStateChange, columnDefaults, defaultColumnSizingById, stableUpdatedInitialColumnPinning]);
|
|
1930
|
+
// Whether a column-resize drag is in progress, as of the last render (TanStack
|
|
1931
|
+
// flags it at pointer-down, before the first move arrives), and whether a
|
|
1932
|
+
// sizing change was held back during one.
|
|
1933
|
+
const isResizingColumnRef = react.useRef(false);
|
|
1934
|
+
const sizingReportPendingRef = react.useRef(false);
|
|
1957
1935
|
const table = reactTable.useReactTable({
|
|
1958
1936
|
manualSorting: true,
|
|
1959
1937
|
enableSortingRemoval: true,
|
|
@@ -1962,44 +1940,37 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
1962
1940
|
getCoreRowModel: reactTable.getCoreRowModel(),
|
|
1963
1941
|
...reactTableProps,
|
|
1964
1942
|
onColumnVisibilityChange: value => {
|
|
1965
|
-
|
|
1966
|
-
const next = typeof value === "function" ? value(current) : value;
|
|
1967
|
-
setUserEdits(prev => ({ ...prev, columnVisibility: next }));
|
|
1968
|
-
persistTableState({ columnVisibility: next });
|
|
1943
|
+
persistTableState({ columnVisibility: applyUpdate("columnVisibility", value) });
|
|
1969
1944
|
reactTableProps.onColumnVisibilityChange?.(value);
|
|
1970
1945
|
},
|
|
1971
1946
|
onColumnSizingChange: value => {
|
|
1972
|
-
const
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1947
|
+
const next = applyUpdate("columnSizing", value);
|
|
1948
|
+
// A drag updates the sizing on every pointer move (`columnResizeMode:
|
|
1949
|
+
// "onChange"`); the store would write every move. The report waits for
|
|
1950
|
+
// the drag to end (see the effect below). Anything else — `resetSize`,
|
|
1951
|
+
// `setColumnSizing` — is reported at once.
|
|
1952
|
+
if (isResizingColumnRef.current) {
|
|
1953
|
+
sizingReportPendingRef.current = true;
|
|
1954
|
+
}
|
|
1955
|
+
else {
|
|
1956
|
+
persistTableState({ columnSizing: next });
|
|
1957
|
+
}
|
|
1976
1958
|
reactTableProps.onColumnSizingChange?.(value);
|
|
1977
1959
|
},
|
|
1978
1960
|
onColumnOrderChange: value => {
|
|
1979
|
-
|
|
1980
|
-
const next = typeof value === "function" ? value(current) : value;
|
|
1981
|
-
setUserEdits(prev => ({ ...prev, columnOrder: next }));
|
|
1982
|
-
persistTableState({ columnOrder: next });
|
|
1961
|
+
persistTableState({ columnOrder: applyUpdate("columnOrder", value) });
|
|
1983
1962
|
reactTableProps.onColumnOrderChange?.(value);
|
|
1984
1963
|
},
|
|
1985
1964
|
onSortingChange: value => {
|
|
1986
|
-
|
|
1987
|
-
const next = typeof value === "function" ? value(current) : value;
|
|
1988
|
-
setUserEdits(prev => ({ ...prev, sorting: next }));
|
|
1989
|
-
persistTableState({ sorting: next });
|
|
1965
|
+
persistTableState({ sorting: applyUpdate("sorting", value) });
|
|
1990
1966
|
reactTableProps.onSortingChange?.(value);
|
|
1991
1967
|
},
|
|
1992
1968
|
onColumnPinningChange: value => {
|
|
1993
|
-
|
|
1994
|
-
const next = typeof value === "function" ? value(current) : value;
|
|
1995
|
-
setUserEdits(prev => ({ ...prev, columnPinning: next }));
|
|
1996
|
-
persistTableState({ columnPinning: next });
|
|
1969
|
+
persistTableState({ columnPinning: applyUpdate("columnPinning", value) });
|
|
1997
1970
|
reactTableProps.onColumnPinningChange?.(value);
|
|
1998
1971
|
},
|
|
1999
1972
|
onExpandedChange: value => {
|
|
2000
|
-
const
|
|
2001
|
-
const next = typeof value === "function" ? value(current) : value;
|
|
2002
|
-
setUserEdits(prev => ({ ...prev, expanded: next }));
|
|
1973
|
+
const next = applyUpdate("expanded", value);
|
|
2003
1974
|
if (reactTableProps.state?.expanded === undefined) {
|
|
2004
1975
|
persistTableState({ expanded: next });
|
|
2005
1976
|
}
|
|
@@ -2008,6 +1979,16 @@ const useTable = ({ onTableStateChange, initialState, columns, ...reactTableProp
|
|
|
2008
1979
|
columns,
|
|
2009
1980
|
state,
|
|
2010
1981
|
});
|
|
1982
|
+
const isResizingColumn = table.getState().columnSizingInfo.isResizingColumn !== false;
|
|
1983
|
+
isResizingColumnRef.current = isResizingColumn;
|
|
1984
|
+
// The drag has ended: report the sizing it left behind, once. TanStack
|
|
1985
|
+
// applies the final size before it clears the flag, so the ref holds it.
|
|
1986
|
+
react.useEffect(() => {
|
|
1987
|
+
if (!isResizingColumn && sizingReportPendingRef.current) {
|
|
1988
|
+
sizingReportPendingRef.current = false;
|
|
1989
|
+
persistTableState({ columnSizing: stateRef.current.columnSizing });
|
|
1990
|
+
}
|
|
1991
|
+
}, [isResizingColumn, persistTableState]);
|
|
2011
1992
|
return react.useMemo(() => {
|
|
2012
1993
|
return { table };
|
|
2013
1994
|
}, [table]);
|