asma-ui-core 3.138.2 → 3.140.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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * What `StyledTable` saves under a table's `uniqueKey`, each setting in its own entry: `${uniqueKey}${suffix}`. The sorting
3
+ * (`:sorting`), column widths (`:column-sizing`), page size (`:page-size`), column order (`:column-order`) and column visibility
4
+ * (`:column-visibility`). A test pins this list to the key functions of the hooks that write them.
5
+ */
6
+ export declare const TABLE_SETTINGS_SUFFIXES: readonly [":sorting", ":column-sizing", ":page-size", ":column-order", ":column-visibility"];
7
+ /** One entry kept under a key that is not the table's `uniqueKey` plus a suffix, moved from its old key to its new one. */
8
+ export interface LegacyRawEntry {
9
+ /** The old key, named exactly. */
10
+ from: string;
11
+ /** The key that holds the entry now. */
12
+ to: string;
13
+ }
14
+ export interface LegacyTableSettings {
15
+ /** The table's `uniqueKey` now, the one the entries are copied to. Without one there is nothing to migrate to. */
16
+ newKey: string | undefined;
17
+ /**
18
+ * The old key, or the old keys, of the **current scope**: the current user, tenant and context, and the current patient or
19
+ * record where the old key held one. Name them exactly: the entries under these keys are copied to `newKey` and removed.
20
+ * When an entry exists under several, the first key listed wins; the others are removed. An empty list, or none, means the
21
+ * app has no current scope to name, and then nothing is copied and **nothing is removed**: the old entries are what the next
22
+ * visit with a scope can still carry over, and a clean-up must never run before the copy has been tried.
23
+ */
24
+ oldKeys?: string | readonly (string | undefined)[];
25
+ /**
26
+ * More old keys to remove without copying them, for entries that cannot be merged into one (another patient's, another
27
+ * record's of the same table). It is given each stored key that ends in a known suffix, **with the suffix taken off**, and
28
+ * answers whether that is an old key of this table. Match only this table's own old prefix for the current user and
29
+ * tenant, never another table's, user's or tenant's; escape every part you put in a pattern. It is asked only when
30
+ * `oldKeys` names a current scope, never about `newKey` or one of `oldKeys`, and a matcher that throws is ignored: the
31
+ * entries of `oldKeys` are still migrated.
32
+ */
33
+ matchOldKey?: (oldKey: string) => boolean;
34
+ /**
35
+ * Entries kept under keys that are **not** `newKey` plus a suffix, which the app named itself: a `persistColumnOrderKey`
36
+ * that carried a record id (`…ColumnOrder-${row.id}`), the key of an app's own visibility hook. Name them as old → new
37
+ * pairs for the current scope. The same rules as for `oldKeys`: each is copied to its `to` once, only if `to` has no entry
38
+ * of its own, and `from` is removed once that copy has been tried (not when it was refused); with no pairs, nothing is
39
+ * copied or removed. When several pairs share a `to`, the first `from` that has an entry wins.
40
+ */
41
+ rawEntries?: readonly LegacyRawEntry[];
42
+ /**
43
+ * The page size this table opens with when the user has saved none: its `pageSize` prop, or `DEFAULT_TABLE_PAGE_SIZE` when it sets
44
+ * none. It repairs what 3.138.2 and 3.139.0 wrote: a `StyledTable` with a `uniqueKey` saved its page size **when it mounted**, so a table
45
+ * that opened before its migration (no patient selected yet) already holds the default under the new key, a value the user never chose.
46
+ * The migration copies only what the new key lacks, so it would keep that default and delete the old size. With this option, **when the
47
+ * new key's `:page-size` equals it and the old entry holds a different valid page size, the old entry wins**: it is copied over the
48
+ * new one (and counted as a copy, so the revision goes up), then the old is removed as usual. A new entry that differs from the default
49
+ * is a choice the user made and is kept, and so is a new entry when the old one is not a valid page size. A user who had deliberately
50
+ * chosen the default itself under the new key cannot be told from the library's write, and gets the old size. Without this option
51
+ * nothing changes. It applies to `:page-size` only, and not to raw pairs.
52
+ */
53
+ defaultPageSize?: number;
54
+ /**
55
+ * More old raw keys to remove without copying them: another record's of the same table. It is asked about a stored key only
56
+ * if the key starts with the `to` of a pair, so it can never reach a key that does not begin with the name the table's
57
+ * settings now have; and never about a `to`, a `from`, `newKey` itself, or a table-settings entry (`newKey`, a `to` or a
58
+ * `from`, plus a suffix). Asked
59
+ * only when `rawEntries` names a current scope. Match exactly, and anchor both ends: a name that merely starts the same is
60
+ * another table's. A matcher that throws is ignored.
61
+ */
62
+ matchRawKey?: (storedKey: string) => boolean;
63
+ }
64
+ /** The scope of a migration as one string, `''` when the app names none: what the hook runs again for. */
65
+ export declare const legacyTableSettingsScope: ({ newKey, oldKeys, rawEntries, defaultPageSize }: LegacyTableSettings) => string;
66
+ /**
67
+ * Carries a table's saved settings from its old keys to its current ones (ASMA-8698). An app that changes a table's key, for
68
+ * example to take a patient id out of it, would otherwise lose every user's saved sort, widths, page size, order and
69
+ * visibility. For each of the five entries `StyledTable` saves under `newKey` (`TABLE_SETTINGS_SUFFIXES`), and for each
70
+ * old → new pair of `rawEntries` (the keys the app named itself):
71
+ *
72
+ * 1. the entry of the first old key that has one is **copied** to the new key, but only if the new key has no entry of its own
73
+ * (one exception, the page size under `defaultPageSize`: see that option): what the user saved under the new key is never
74
+ * overwritten;
75
+ * 2. then the old entries are **removed**: those of every old key named, and those the matchers accept.
76
+ *
77
+ * Nothing is removed before its copy is written: when storage is full or blocked the old entries stay, and the next call tries
78
+ * again. A call changes nothing once the old entries are gone, so it is safe to repeat (React StrictMode runs it twice). With
79
+ * nothing to migrate it only looks for the old entries (one read for each old key and suffix, one for each `from`, none for a
80
+ * new key) and writes nothing. With no current scope named (`oldKeys` empty, `rawEntries` empty) nothing is copied and nothing
81
+ * is removed, whatever a matcher would match. It never throws.
82
+ *
83
+ * **Returns the number of entries it copied** (`0` when it copied nothing: no scope, nothing to migrate, entries the new key already
84
+ * had that were only removed, or a copy that storage refused). That is how an app learns that a table which is already showing has
85
+ * new entries to read: see the `revision` {@link useLegacyTableSettingsMigration} returns.
86
+ *
87
+ * Key generation stays in the app: it builds `newKey`, `oldKeys` and the raw pairs with the same helpers that build the table's
88
+ * keys. Run it before the table first reads its storage; {@link useLegacyTableSettingsMigration} does that.
89
+ */
90
+ export declare const migrateLegacyTableSettings: (settings: LegacyTableSettings) => number;
@@ -8,6 +8,8 @@ export declare const tableStorage: {
8
8
  /** `true` when the value was written, `false` when storage refused it (quota, blocked): the setting stays in memory only. */
9
9
  set(key: string, value: string): boolean;
10
10
  remove(key: string): void;
11
+ /** A snapshot of every key in storage, safe to remove from while walking it. Empty when storage is blocked. */
12
+ keys(): string[];
11
13
  };
12
14
  /** Parses a saved value; anything that is not valid JSON counts as nothing saved. */
13
15
  export declare const readJson: (key: string) => unknown;
@@ -2,6 +2,20 @@ import { ColumnOrderState, Table, VisibilityState } from '@tanstack/react-table'
2
2
  import { LeafColumnInfo } from '../helpers/columnIds';
3
3
  export declare const getColumnOrderStorageKey: (uniqueKey?: string) => string | undefined;
4
4
  export declare const getColumnVisibilityStorageKey: (uniqueKey?: string) => string | undefined;
5
+ /**
6
+ * Whether a parsed `:column-order` value has the shape of an entry, **even one with nothing in it** (`{"v":1,"order":[]}`): the
7
+ * right version and a list. That tells a well-formed entry (which confirms the user's own layout, empty or equal to the default
8
+ * included) from a malformed one (which confirms nothing), where `sanitizeColumnOrder` answers `undefined` for both.
9
+ */
10
+ export declare const isColumnOrderEntry: (raw: unknown) => raw is {
11
+ v: number;
12
+ order: unknown[];
13
+ };
14
+ /** The same for a parsed `:column-visibility` value: the right version and a map (`{"v":1,"visibility":{}}` is well formed). */
15
+ export declare const isColumnVisibilityEntry: (raw: unknown) => raw is {
16
+ v: number;
17
+ visibility: Record<string, unknown>;
18
+ };
5
19
  /**
6
20
  * Checks a parsed `:column-order` value. Ids that no column has are kept: an order saved for columns that are not there at
7
21
  * the moment survives, and TanStack ignores them (ASMA-8597, DEC-W). `undefined` means nothing usable is saved.
@@ -0,0 +1,55 @@
1
+ import { LegacyTableSettings } from '../helpers/migrateLegacyTableSettings';
2
+ /**
3
+ * Runs {@link migrateLegacyTableSettings} while the component renders, so it has run before the `StyledTable` it renders reads
4
+ * its storage for the first time (a parent renders before its children), and again whenever the current scope changes: `newKey`
5
+ * or `oldKeys`, which carry the user, tenant, context and patient or record. With no scope (`oldKeys` empty or missing, or no
6
+ * `newKey`) it does nothing, and it does nothing again for the same scope.
7
+ *
8
+ * `matchOldKey` is read at the moment the scope changes and is not a dependency: whatever it depends on must also be in
9
+ * `oldKeys`, so that a change of it changes the scope. The migration is idempotent, so StrictMode and a re-render that runs
10
+ * it again change nothing.
11
+ *
12
+ * **Returns a `revision`: a number that goes up by one each time a migration copied something, and only then** (an entry the new
13
+ * key already had, or a copy that storage refused, does not raise it). A `StyledTable` reads its saved settings (widths, page size,
14
+ * sorting, order, visibility) when it **mounts**, and again only when its `uniqueKey` changes. A table that is already showing when
15
+ * a deferred migration copies (it opened with no patient selected, and a patient was selected later: the table's `uniqueKey` does not
16
+ * hold the patient, so it did not change) would keep its defaults, and its next resize or page size change would write over what was
17
+ * migrated. Use the revision as the table's React `key`, so that it reads its storage again once, after the copy:
18
+ *
19
+ * ```tsx
20
+ * const revision = useLegacyTableSettingsMigration({
21
+ * newKey: tableKey,
22
+ * oldKeys: patientId ? [oldKeyFor(patientId)] : undefined,
23
+ * })
24
+ * <StyledTable key={revision} uniqueKey={tableKey} … />
25
+ * ```
26
+ *
27
+ * That remounts the table once (its row selection, expanded rows and scroll position start again), only when something was copied,
28
+ * and the React `key` is not persisted, so no patient id reaches a storage key. A migration that copies before the table mounts
29
+ * (a patient already selected on the first render) raises the revision before the table exists, so it costs no remount.
30
+ *
31
+ * Why a key and not a prop that makes a mounted `StyledTable` read its storage again: the key reuses the table's one read-at-mount path
32
+ * for every setting, where a re-read prop would need a second path for each of the five, each with its own rule about what beats
33
+ * what (saved values over the app's, initial state over state). It is the smaller change, and it cannot leave one setting stale.
34
+ *
35
+ * The number is per table (its `newKey`, or the first `to` of a raw pair when there is no `newKey`) and counts for the page's life,
36
+ * so only a change of it means anything; do not compare it with a fixed number.
37
+ *
38
+ * **Several mounted instances that share one `newKey`** (the tables of sub-rows, each opened from its own row) **share the revision**:
39
+ * a copy made for one raises it for all, so the others remount too, on their next render. That is harmless, and cheap, since a
40
+ * remount only reads their storage again. **To combine the revision with a key the table already has**, put both in it:
41
+ *
42
+ * ```tsx
43
+ * <StyledTable key={`${tab}-${revision}`} uniqueKey={tableKey} … />
44
+ * ```
45
+ *
46
+ * **The page size.** A `StyledTable` saves its page size when it **changes** after mounting, never when it mounts. That includes a change
47
+ * the app makes itself with `table.setPageSize()` after mount, which is saved as if the user had made it. 3.138.2 and 3.139.0 saved it
48
+ * on mount, so a browser that ran them may already hold the table's default under the new key; pass `defaultPageSize` (the table's
49
+ * `pageSize` prop, or `DEFAULT_TABLE_PAGE_SIZE` when it sets none) and the migration lets the old size replace that default, and counts it
50
+ * as a copy, so the revision goes up and the table reads it. A new page size that is not the default is the user's and is kept.
51
+ *
52
+ * **What an app has to do:** its migration wrapper must **return** the revision, the table must use it in its `key`, and the app passes
53
+ * `defaultPageSize`.
54
+ */
55
+ export declare const useLegacyTableSettingsMigration: (migration: LegacyTableSettings) => number;
@@ -1,2 +1,6 @@
1
+ /** The page size a `StyledTable` opens with when it is given no `pageSize` and the user has saved none. */
2
+ export declare const DEFAULT_TABLE_PAGE_SIZE = 50;
3
+ /** A saved page size: a positive whole number, as `${uniqueKey}:page-size` holds it. Anything else is not a page size. */
4
+ export declare const parseSavedPageSize: (raw: string | null) => number | undefined;
1
5
  export declare const getPersistedPageSizeKey: (uniqueKey?: string) => string | undefined;
2
6
  export declare const usePersistedPageSize: (uniqueKey?: string) => number | undefined;
@@ -2,4 +2,7 @@ export * from './types';
2
2
  export * from './components/StyledTableIndex';
3
3
  export { RowDragHandleCell } from './components/columns/dndHandleColumn';
4
4
  export { readPersistedSorting, usePersistedSorting, type PersistedSortingOptions, } from './hooks/usePersistedSorting';
5
+ export { migrateLegacyTableSettings, type LegacyRawEntry, type LegacyTableSettings, } from './helpers/migrateLegacyTableSettings';
6
+ export { useLegacyTableSettingsMigration } from './hooks/useLegacyTableSettingsMigration';
7
+ export { DEFAULT_TABLE_PAGE_SIZE } from './hooks/usePersistedPageSize';
5
8
  export { createColumnHelper, type Table, type Row, type ColumnDef, type CellContext } from '@tanstack/react-table';
@@ -0,0 +1,93 @@
1
+ import { tableStorage as a } from "./tableStorage.js";
2
+ import { parseSavedPageSize as $ } from "../hooks/usePersistedPageSize.js";
3
+ var m = [
4
+ ":sorting",
5
+ ":column-sizing",
6
+ ":page-size",
7
+ ":column-order",
8
+ ":column-visibility"
9
+ ], d = (e) => (typeof e == "string" ? [e] : [...e ?? []]).filter((i) => !!i), S = (e) => (e ?? []).filter(({ from: i, to: n }) => !!i && !!n && i !== n), y = ({ newKey: e, oldKeys: i, rawEntries: n, defaultPageSize: g }) => {
10
+ const u = d(i), f = e && u.length > 0 ? `${[e, ...u].join("\0")}${String(g ?? "")}` : "", l = S(n).map(({ from: o, to: s }) => `${o}\0${s}`).join("");
11
+ return f || l ? `${f}${l}` : "";
12
+ }, b = (e, i, n) => {
13
+ if (n === void 0 || !Number.isInteger(n) || n <= 0) return !1;
14
+ const g = $(i);
15
+ return $(e) === n && g !== void 0 && g !== n;
16
+ }, E = ({ newKey: e, oldKeys: i, matchOldKey: n, defaultPageSize: g }, u) => {
17
+ const f = d(i).filter((o) => o !== e);
18
+ if (!e || f.length === 0) return;
19
+ const l = /* @__PURE__ */ new Map();
20
+ if (n) try {
21
+ for (const o of a.keys()) {
22
+ const s = m.find((c) => o.endsWith(c));
23
+ if (s === void 0) continue;
24
+ const t = o.slice(0, o.length - s.length);
25
+ t === e || f.includes(t) || !n(t) || l.set(s, [...l.get(s) ?? [], o]);
26
+ }
27
+ } catch {
28
+ l.clear();
29
+ }
30
+ for (const o of m) {
31
+ let s = null;
32
+ const t = [];
33
+ for (const r of f) {
34
+ const p = a.get(`${r}${o}`);
35
+ p !== null && (t.push(`${r}${o}`), s ??= p);
36
+ }
37
+ const c = l.get(o) ?? [];
38
+ if (!(t.length === 0 && c.length === 0)) {
39
+ if (s !== null) {
40
+ const r = a.get(`${e}${o}`);
41
+ if (r === null || o === ":page-size" && b(r, s, g)) {
42
+ if (!a.set(`${e}${o}`, s)) continue;
43
+ u.copied += 1;
44
+ }
45
+ }
46
+ for (const r of [...t, ...c]) a.remove(r);
47
+ }
48
+ }
49
+ }, T = ({ newKey: e, rawEntries: i, matchRawKey: n }, g) => {
50
+ const u = S(i);
51
+ if (u.length === 0) return;
52
+ const f = [...new Set(u.map(({ to: t }) => t))], l = new Set(u.map(({ from: t }) => t)), o = (t) => f.includes(t) || l.has(t) || t === e || [
53
+ e,
54
+ ...f,
55
+ ...l
56
+ ].some((c) => !!c && m.some((r) => t === `${c}${r}`)), s = /* @__PURE__ */ new Map();
57
+ if (n) try {
58
+ for (const t of a.keys()) {
59
+ const c = f.filter((r) => t.startsWith(r)).sort((r, p) => p.length - r.length)[0];
60
+ c === void 0 || o(t) || !n(t) || s.set(c, [...s.get(c) ?? [], t]);
61
+ }
62
+ } catch {
63
+ s.clear();
64
+ }
65
+ for (const t of f) {
66
+ let c = null;
67
+ const r = [];
68
+ for (const h of u) {
69
+ if (h.to !== t) continue;
70
+ const v = a.get(h.from);
71
+ v !== null && (r.push(h.from), c ??= v);
72
+ }
73
+ const p = s.get(t) ?? [];
74
+ if (!(r.length === 0 && p.length === 0)) {
75
+ if (c !== null && a.get(t) === null) {
76
+ if (!a.set(t, c)) continue;
77
+ g.copied += 1;
78
+ }
79
+ for (const h of [...r, ...p]) a.remove(h);
80
+ }
81
+ }
82
+ }, L = (e) => {
83
+ const i = { copied: 0 };
84
+ for (const n of [E, T]) try {
85
+ n(e, i);
86
+ } catch {
87
+ }
88
+ return i.copied;
89
+ };
90
+ export {
91
+ y as legacyTableSettingsScope,
92
+ L as migrateLegacyTableSettings
93
+ };
@@ -18,6 +18,13 @@ var e = {
18
18
  localStorage.removeItem(r);
19
19
  } catch {
20
20
  }
21
+ },
22
+ keys() {
23
+ try {
24
+ return Array.from({ length: localStorage.length }, (r, t) => localStorage.key(t)).filter((r) => r !== null);
25
+ } catch {
26
+ return [];
27
+ }
21
28
  }
22
29
  }, a = (r) => {
23
30
  const t = e.get(r);
@@ -1,139 +1,146 @@
1
- import { INTERNAL_COLUMN_IDS as N } from "../types.js";
2
- import { readJson as O, tableStorage as v } from "../helpers/tableStorage.js";
3
- import { columnVisibilitySignature as h, diffColumnVisibility as K, effectiveColumnOrder as m, getDefinitionColumnOrder as A, insertMissingColumns as j } from "../custom-features/order-columns/columnLayout.js";
4
- import { usePersistedStateWriter as L } from "./usePersistedStateWriter.js";
5
- import { useEffect as J, useLayoutEffect as R, useMemo as _ } from "react";
6
- var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${F}` : void 0, E = (e) => e ? `${e}${M}` : void 0, S = (e) => typeof e == "object" && e !== null && !Array.isArray(e), C = (e) => [...new Set(e.filter((i) => typeof i == "string"))], D = (e) => {
7
- if (!S(e) || e.v !== f || !Array.isArray(e.order)) return;
8
- const i = C(e.order);
1
+ import { INTERNAL_COLUMN_IDS as A } from "../types.js";
2
+ import { readJson as O, tableStorage as c } from "../helpers/tableStorage.js";
3
+ import { columnVisibilitySignature as J, diffColumnVisibility as K, effectiveColumnOrder as m, getDefinitionColumnOrder as R, insertMissingColumns as C } from "../custom-features/order-columns/columnLayout.js";
4
+ import { usePersistedStateWriter as E } from "./usePersistedStateWriter.js";
5
+ import { useEffect as _, useLayoutEffect as F, useMemo as M } from "react";
6
+ var D = ":column-order", $ = ":column-visibility", f = 1, L = (e) => e ? `${e}${D}` : void 0, h = (e) => e ? `${e}${$}` : void 0, S = (e) => typeof e == "object" && e !== null && !Array.isArray(e), j = (e) => [...new Set(e.filter((i) => typeof i == "string"))], k = (e) => S(e) && e.v === f && Array.isArray(e.order), N = (e) => S(e) && e.v === f && S(e.visibility), x = (e) => {
7
+ if (!k(e)) return;
8
+ const i = j(e.order);
9
9
  return i.length > 0 ? i : void 0;
10
- }, p = (e, i) => !N.includes(e) && i.find((t) => t.id === e)?.canHide !== !1, $ = (e, i) => {
11
- if (!S(e) || e.v !== f || !S(e.visibility)) return;
12
- const t = Object.fromEntries(Object.entries(e.visibility).filter((r) => typeof r[1] == "boolean" && p(r[0], i)));
13
- return Object.keys(t).length > 0 ? t : void 0;
14
- }, x = (e) => {
15
- if (!Array.isArray(e)) return;
16
- const i = C(e);
17
- return i.length > 0 ? i : void 0;
18
- }, T = (e, i, t) => {
19
- if (!S(e) || !Object.values(e).every((o) => typeof o == "boolean")) return;
20
- const r = K(Object.fromEntries(Object.entries(e).filter(([o]) => p(o, i))), t);
10
+ }, p = (e, i) => !A.includes(e) && i.find((r) => r.id === e)?.canHide !== !1, T = (e, i) => {
11
+ if (!N(e)) return;
12
+ const r = Object.fromEntries(Object.entries(e.visibility).filter((t) => typeof t[1] == "boolean" && p(t[0], i)));
21
13
  return Object.keys(r).length > 0 ? r : void 0;
22
14
  }, U = (e) => {
23
- const { enabled: i, uniqueKey: t, legacyOrderKey: r, legacyVisibilityKey: o, columns: s, defaultOrder: g, defaultVisibility: d } = e, n = i ? k(t) : void 0, a = i ? E(t) : void 0, y = s.map((l) => l.id), c = [];
24
- let b, u;
25
- if (n) {
26
- if (v.get(n) !== null) b = D(O(n));
27
- else if (r && v.get(r) !== null) {
28
- const l = x(O(r)), I = l === void 0 || m(j(l, y), y).join() === m(g, y).join();
29
- l && !I && (b = l), c.push({
30
- legacyKey: r,
31
- ...l && !I && { write: {
32
- key: n,
15
+ if (!Array.isArray(e)) return;
16
+ const i = j(e);
17
+ return i.length > 0 ? i : void 0;
18
+ }, W = (e, i, r) => {
19
+ if (!S(e) || !Object.values(e).every((n) => typeof n == "boolean")) return;
20
+ const t = K(Object.fromEntries(Object.entries(e).filter(([n]) => p(n, i))), r);
21
+ return Object.keys(t).length > 0 ? t : void 0;
22
+ }, Y = (e) => {
23
+ const { enabled: i, uniqueKey: r, legacyOrderKey: t, legacyVisibilityKey: n, columns: l, defaultOrder: g, defaultVisibility: u } = e, s = i ? L(r) : void 0, v = i ? h(r) : void 0, y = l.map((o) => o.id), d = [];
24
+ let b, a;
25
+ if (s) {
26
+ if (c.get(s) !== null) {
27
+ const o = O(s);
28
+ b = x(o), k(o) && t && c.get(t) !== null && d.push({ legacyKey: t });
29
+ } else if (t && c.get(t) !== null) {
30
+ const o = U(O(t)), I = o === void 0 || m(C(o, y), y).join() === m(g, y).join();
31
+ o && !I && (b = o), d.push({
32
+ legacyKey: t,
33
+ ...o && !I && { write: {
34
+ key: s,
33
35
  value: JSON.stringify({
34
36
  v: f,
35
- order: l
37
+ order: o
36
38
  })
37
39
  } }
38
40
  });
39
41
  }
40
42
  }
41
- return a && (v.get(a) !== null ? u = $(O(a), s) : o && v.get(o) !== null && (u = T(O(o), s, d), c.push({
42
- legacyKey: o,
43
- ...u && { write: {
44
- key: a,
45
- value: JSON.stringify({
46
- v: f,
47
- visibility: u
48
- })
49
- } }
50
- }))), {
51
- orderKey: n,
52
- visibilityKey: a,
43
+ if (v)
44
+ if (c.get(v) !== null) {
45
+ const o = O(v);
46
+ a = T(o, l), N(o) && n && c.get(n) !== null && d.push({ legacyKey: n });
47
+ } else n && c.get(n) !== null && (a = W(O(n), l, u), d.push({
48
+ legacyKey: n,
49
+ ...a && { write: {
50
+ key: v,
51
+ value: JSON.stringify({
52
+ v: f,
53
+ visibility: a
54
+ })
55
+ } }
56
+ }));
57
+ return {
58
+ orderKey: s,
59
+ visibilityKey: v,
53
60
  order: b,
54
- visibility: u,
55
- migration: c
61
+ visibility: a,
62
+ migration: d
56
63
  };
57
- }, W = (e, i, t) => {
58
- const r = e.visibility && Object.fromEntries(Object.entries(e.visibility).filter(([o]) => p(o, i)));
64
+ }, q = (e, i, r) => {
65
+ const t = e.visibility && Object.fromEntries(Object.entries(e.visibility).filter(([n]) => p(n, i)));
59
66
  return {
60
67
  orderKey: e.orderKey,
61
68
  visibilityKey: e.visibilityKey,
62
- order: e.order && j(e.order, i.map((o) => o.id)),
63
- visibility: r && Object.keys(r).length > 0 ? {
64
- ...t,
65
- ...r
69
+ order: e.order && C(e.order, i.map((n) => n.id)),
70
+ visibility: t && Object.keys(t).length > 0 ? {
71
+ ...r,
72
+ ...t
66
73
  } : void 0
67
74
  };
68
- }, P = (e) => {
69
- const i = _(() => U(e), [
70
- e.enabled ? k(e.uniqueKey) : void 0,
71
- e.enabled ? E(e.uniqueKey) : void 0,
75
+ }, Q = (e) => {
76
+ const i = M(() => Y(e), [
77
+ e.enabled ? L(e.uniqueKey) : void 0,
78
+ e.enabled ? h(e.uniqueKey) : void 0,
72
79
  e.legacyOrderKey,
73
80
  e.legacyVisibilityKey
74
81
  ]);
75
- return J(() => {
76
- for (const { legacyKey: t, write: r } of i.migration)
77
- r && !v.set(r.key, r.value) || v.remove(t);
78
- }, [i]), W(i, e.columns, e.defaultVisibility);
79
- }, V = /* @__PURE__ */ new WeakMap(), Y = (e, i) => [.../* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(i)])].every((t) => (e[t] ?? !0) === (i[t] ?? !0)), G = (e, i) => {
80
- const { enabled: t, definitionIds: r, defaultOrder: o, defaultVisibility: s, controlledVisibility: g } = i, d = {
82
+ return _(() => {
83
+ for (const { legacyKey: r, write: t } of i.migration)
84
+ t && !c.set(t.key, t.value) || c.remove(r);
85
+ }, [i]), q(i, e.columns, e.defaultVisibility);
86
+ }, V = /* @__PURE__ */ new WeakMap(), z = (e, i) => [.../* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(i)])].every((r) => (e[r] ?? !0) === (i[r] ?? !0)), Z = (e, i) => {
87
+ const { enabled: r, definitionIds: t, defaultOrder: n, defaultVisibility: l, controlledVisibility: g } = i, u = {
81
88
  signature: JSON.stringify([
82
- r,
83
- o,
84
- Object.entries(s).sort()
89
+ t,
90
+ n,
91
+ Object.entries(l).sort()
85
92
  ]),
86
- definitionIds: r,
87
- defaultOrder: o,
88
- defaultVisibility: s
89
- }, n = V.get(e) ?? d, a = t && n.signature !== d.signature;
90
- return R(() => {
93
+ definitionIds: t,
94
+ defaultOrder: n,
95
+ defaultVisibility: l
96
+ }, s = V.get(e) ?? u, v = r && s.signature !== u.signature;
97
+ return F(() => {
91
98
  const y = V.get(e);
92
- if (V.set(e, d), !t || !y || y.signature === d.signature) return;
93
- const c = e.getState().columnOrder, b = m(c, y.definitionIds).join() === m(y.defaultOrder, y.definitionIds).join() ? o : j(c, r);
99
+ if (V.set(e, u), !r || !y || y.signature === u.signature) return;
100
+ const d = e.getState().columnOrder, b = m(d, y.definitionIds).join() === m(y.defaultOrder, y.definitionIds).join() ? n : C(d, t);
94
101
  if (e.setColumnOrder(b), !g) {
95
- const u = e.getState().columnVisibility, l = {
96
- ...s,
97
- ...K(u, y.defaultVisibility)
102
+ const a = e.getState().columnVisibility, o = {
103
+ ...l,
104
+ ...K(a, y.defaultVisibility)
98
105
  };
99
- Y(l, u) || e.setColumnVisibility(l);
106
+ z(o, a) || e.setColumnVisibility(o);
100
107
  }
101
108
  }, [
102
109
  e,
103
- t,
104
- d.signature
105
- ]), a;
106
- }, Q = (e, i) => {
107
- const { saved: t, reconciling: r, defaultOrder: o, defaultVisibility: s, controlledVisibility: g } = i, d = A(e);
108
- L({
109
- storageKey: t.orderKey,
110
+ r,
111
+ u.signature
112
+ ]), v;
113
+ }, w = (e, i) => {
114
+ const { saved: r, reconciling: t, defaultOrder: n, defaultVisibility: l, controlledVisibility: g } = i, u = R(e);
115
+ E({
116
+ storageKey: r.orderKey,
110
117
  state: e.getState().columnOrder,
111
- defaultValue: o,
112
- saved: t.order,
113
- settled: !r,
114
- toSignature: (n) => JSON.stringify(m(n, d)),
115
- toStorage: (n) => JSON.stringify({
118
+ defaultValue: n,
119
+ saved: r.order,
120
+ settled: !t,
121
+ toSignature: (s) => JSON.stringify(m(s, u)),
122
+ toStorage: (s) => JSON.stringify({
116
123
  v: f,
117
- order: C(n)
124
+ order: j(s)
118
125
  }),
119
- applyState: (n) => e.setColumnOrder(n)
120
- }), L({
121
- storageKey: t.visibilityKey,
126
+ applyState: (s) => e.setColumnOrder(s)
127
+ }), E({
128
+ storageKey: r.visibilityKey,
122
129
  state: e.getState().columnVisibility,
123
- defaultValue: s,
124
- saved: t.visibility,
125
- settled: !r,
130
+ defaultValue: l,
131
+ saved: r.visibility,
132
+ settled: !t,
126
133
  controlled: g,
127
- toSignature: (n) => h(n, s),
128
- toStorage: (n) => JSON.stringify({
134
+ toSignature: (s) => J(s, l),
135
+ toStorage: (s) => JSON.stringify({
129
136
  v: f,
130
- visibility: K(n, s)
137
+ visibility: K(s, l)
131
138
  }),
132
- applyState: (n) => e.setColumnVisibility(n)
139
+ applyState: (s) => e.setColumnVisibility(s)
133
140
  });
134
141
  };
135
142
  export {
136
- G as useColumnLayoutReconcile,
137
- Q as useColumnLayoutWriter,
138
- P as useSavedColumnLayout
143
+ Z as useColumnLayoutReconcile,
144
+ w as useColumnLayoutWriter,
145
+ Q as useSavedColumnLayout
139
146
  };
@@ -0,0 +1,11 @@
1
+ import { legacyTableSettingsScope as r, migrateLegacyTableSettings as s } from "../helpers/migrateLegacyTableSettings.js";
2
+ import { useMemo as g } from "react";
3
+ var o = /* @__PURE__ */ new Map(), i = ({ newKey: e, rawEntries: a }) => e ?? a?.find(({ to: t }) => !!t)?.to ?? "", l = (e) => {
4
+ const a = r(e), t = i(e);
5
+ return g(() => {
6
+ s(e) > 0 && o.set(t, (o.get(t) ?? 0) + 1);
7
+ }, [a]), o.get(t) ?? 0;
8
+ };
9
+ export {
10
+ l as useLegacyTableSettingsMigration
11
+ };
@@ -1,15 +1,24 @@
1
- import { readJson as o } from "../helpers/tableStorage.js";
2
- import { useMemo as i } from "react";
3
- var s = ":page-size", a = (e) => {
1
+ import { tableStorage as t } from "../helpers/tableStorage.js";
2
+ import { useMemo as a } from "react";
3
+ var i = ":page-size", v = 50, o = (e) => {
4
4
  if (e)
5
- return `${e}${s}`;
6
- }, d = (e) => i(() => {
7
- const t = a(e);
8
- if (!t) return;
9
- const r = o(t);
10
- return typeof r == "number" && Number.isInteger(r) && r > 0 ? r : void 0;
5
+ try {
6
+ const r = JSON.parse(e);
7
+ return typeof r == "number" && Number.isInteger(r) && r > 0 ? r : void 0;
8
+ } catch {
9
+ return;
10
+ }
11
+ }, s = (e) => {
12
+ if (e)
13
+ return `${e}${i}`;
14
+ }, S = (e) => a(() => {
15
+ const r = s(e);
16
+ if (r)
17
+ return o(t.get(r));
11
18
  }, [e]);
12
19
  export {
13
- a as getPersistedPageSizeKey,
14
- d as usePersistedPageSize
20
+ v as DEFAULT_TABLE_PAGE_SIZE,
21
+ s as getPersistedPageSizeKey,
22
+ o as parseSavedPageSize,
23
+ S as usePersistedPageSize
15
24
  };