asma-ui-core 3.139.0 → 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.
- package/dist/index.js +209 -207
- package/dist/src/table/helpers/migrateLegacyTableSettings.d.ts +21 -4
- package/dist/src/table/hooks/useLegacyTableSettingsMigration.d.ts +41 -3
- package/dist/src/table/hooks/usePersistedPageSize.d.ts +4 -0
- package/dist/src/table/index.d.ts +1 -0
- package/dist/table/helpers/migrateLegacyTableSettings.js +69 -49
- package/dist/table/hooks/useLegacyTableSettingsMigration.js +7 -4
- package/dist/table/hooks/usePersistedPageSize.js +20 -11
- package/dist/table/hooks/useStyledTable.js +93 -92
- package/dist/table/index.js +3 -2
- package/package.json +1 -1
|
@@ -39,6 +39,18 @@ export interface LegacyTableSettings {
|
|
|
39
39
|
* copied or removed. When several pairs share a `to`, the first `from` that has an entry wins.
|
|
40
40
|
*/
|
|
41
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;
|
|
42
54
|
/**
|
|
43
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
|
|
44
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
|
|
@@ -50,15 +62,16 @@ export interface LegacyTableSettings {
|
|
|
50
62
|
matchRawKey?: (storedKey: string) => boolean;
|
|
51
63
|
}
|
|
52
64
|
/** The scope of a migration as one string, `''` when the app names none: what the hook runs again for. */
|
|
53
|
-
export declare const legacyTableSettingsScope: ({ newKey, oldKeys, rawEntries }: LegacyTableSettings) => string;
|
|
65
|
+
export declare const legacyTableSettingsScope: ({ newKey, oldKeys, rawEntries, defaultPageSize }: LegacyTableSettings) => string;
|
|
54
66
|
/**
|
|
55
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
|
|
56
68
|
* example to take a patient id out of it, would otherwise lose every user's saved sort, widths, page size, order and
|
|
57
69
|
* visibility. For each of the five entries `StyledTable` saves under `newKey` (`TABLE_SETTINGS_SUFFIXES`), and for each
|
|
58
70
|
* old → new pair of `rawEntries` (the keys the app named itself):
|
|
59
71
|
*
|
|
60
|
-
* 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
|
|
61
|
-
* what the user saved under the new key is never
|
|
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;
|
|
62
75
|
* 2. then the old entries are **removed**: those of every old key named, and those the matchers accept.
|
|
63
76
|
*
|
|
64
77
|
* Nothing is removed before its copy is written: when storage is full or blocked the old entries stay, and the next call tries
|
|
@@ -67,7 +80,11 @@ export declare const legacyTableSettingsScope: ({ newKey, oldKeys, rawEntries }:
|
|
|
67
80
|
* new key) and writes nothing. With no current scope named (`oldKeys` empty, `rawEntries` empty) nothing is copied and nothing
|
|
68
81
|
* is removed, whatever a matcher would match. It never throws.
|
|
69
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
|
+
*
|
|
70
87
|
* Key generation stays in the app: it builds `newKey`, `oldKeys` and the raw pairs with the same helpers that build the table's
|
|
71
88
|
* keys. Run it before the table first reads its storage; {@link useLegacyTableSettingsMigration} does that.
|
|
72
89
|
*/
|
|
73
|
-
export declare const migrateLegacyTableSettings: (settings: LegacyTableSettings) =>
|
|
90
|
+
export declare const migrateLegacyTableSettings: (settings: LegacyTableSettings) => number;
|
|
@@ -9,9 +9,47 @@ import { LegacyTableSettings } from '../helpers/migrateLegacyTableSettings';
|
|
|
9
9
|
* `oldKeys`, so that a change of it changes the scope. The migration is idempotent, so StrictMode and a re-render that runs
|
|
10
10
|
* it again change nothing.
|
|
11
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
|
+
*
|
|
12
42
|
* ```tsx
|
|
13
|
-
*
|
|
14
|
-
* <StyledTable uniqueKey={tableKey} … />
|
|
43
|
+
* <StyledTable key={`${tab}-${revision}`} uniqueKey={tableKey} … />
|
|
15
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`.
|
|
16
54
|
*/
|
|
17
|
-
export declare const useLegacyTableSettingsMigration: (migration: LegacyTableSettings) =>
|
|
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;
|
|
@@ -4,4 +4,5 @@ export { RowDragHandleCell } from './components/columns/dndHandleColumn';
|
|
|
4
4
|
export { readPersistedSorting, usePersistedSorting, type PersistedSortingOptions, } from './hooks/usePersistedSorting';
|
|
5
5
|
export { migrateLegacyTableSettings, type LegacyRawEntry, type LegacyTableSettings, } from './helpers/migrateLegacyTableSettings';
|
|
6
6
|
export { useLegacyTableSettingsMigration } from './hooks/useLegacyTableSettingsMigration';
|
|
7
|
+
export { DEFAULT_TABLE_PAGE_SIZE } from './hooks/usePersistedPageSize';
|
|
7
8
|
export { createColumnHelper, type Table, type Row, type ColumnDef, type CellContext } from '@tanstack/react-table';
|
|
@@ -1,73 +1,93 @@
|
|
|
1
|
-
import { tableStorage as
|
|
1
|
+
import { tableStorage as a } from "./tableStorage.js";
|
|
2
|
+
import { parseSavedPageSize as $ } from "../hooks/usePersistedPageSize.js";
|
|
2
3
|
var m = [
|
|
3
4
|
":sorting",
|
|
4
5
|
":column-sizing",
|
|
5
6
|
":page-size",
|
|
6
7
|
":column-order",
|
|
7
8
|
":column-visibility"
|
|
8
|
-
],
|
|
9
|
-
const
|
|
10
|
-
return
|
|
11
|
-
},
|
|
12
|
-
|
|
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);
|
|
13
18
|
if (!e || f.length === 0) return;
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
for (const
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
const
|
|
20
|
-
|
|
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]);
|
|
21
26
|
}
|
|
22
27
|
} catch {
|
|
23
|
-
|
|
28
|
+
l.clear();
|
|
24
29
|
}
|
|
25
|
-
for (const
|
|
26
|
-
let
|
|
27
|
-
const
|
|
28
|
-
for (const
|
|
29
|
-
const
|
|
30
|
-
|
|
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);
|
|
31
47
|
}
|
|
32
|
-
const t = i.get(n) ?? [];
|
|
33
|
-
if (!(s.length === 0 && t.length === 0) && !(c !== null && u.get(`${e}${n}`) === null && !u.set(`${e}${n}`, c)))
|
|
34
|
-
for (const o of [...s, ...t]) u.remove(o);
|
|
35
48
|
}
|
|
36
|
-
},
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
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 || [
|
|
40
53
|
e,
|
|
41
|
-
...
|
|
42
|
-
...
|
|
43
|
-
].some((
|
|
44
|
-
if (
|
|
45
|
-
for (const t of
|
|
46
|
-
const
|
|
47
|
-
|
|
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]);
|
|
48
61
|
}
|
|
49
62
|
} catch {
|
|
50
63
|
s.clear();
|
|
51
64
|
}
|
|
52
|
-
for (const t of
|
|
53
|
-
let
|
|
54
|
-
const
|
|
55
|
-
for (const
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
|
|
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);
|
|
59
80
|
}
|
|
60
|
-
const h = s.get(t) ?? [];
|
|
61
|
-
if (!(l.length === 0 && h.length === 0) && !(o !== null && u.get(t) === null && !u.set(t, o)))
|
|
62
|
-
for (const g of [...l, ...h]) u.remove(g);
|
|
63
81
|
}
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
}, L = (e) => {
|
|
83
|
+
const i = { copied: 0 };
|
|
84
|
+
for (const n of [E, T]) try {
|
|
85
|
+
n(e, i);
|
|
67
86
|
} catch {
|
|
68
87
|
}
|
|
88
|
+
return i.copied;
|
|
69
89
|
};
|
|
70
90
|
export {
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
y as legacyTableSettingsScope,
|
|
92
|
+
L as migrateLegacyTableSettings
|
|
73
93
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { legacyTableSettingsScope as
|
|
1
|
+
import { legacyTableSettingsScope as r, migrateLegacyTableSettings as s } from "../helpers/migrateLegacyTableSettings.js";
|
|
2
2
|
import { useMemo as g } from "react";
|
|
3
|
-
var i = (e) => {
|
|
4
|
-
|
|
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;
|
|
5
8
|
};
|
|
6
9
|
export {
|
|
7
|
-
|
|
10
|
+
l as useLegacyTableSettingsMigration
|
|
8
11
|
};
|
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo as
|
|
3
|
-
var
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
20
|
+
v as DEFAULT_TABLE_PAGE_SIZE,
|
|
21
|
+
s as getPersistedPageSizeKey,
|
|
22
|
+
o as parseSavedPageSize,
|
|
23
|
+
S as usePersistedPageSize
|
|
15
24
|
};
|
|
@@ -1,170 +1,171 @@
|
|
|
1
|
-
import { SELECT_COLUMN_ID as
|
|
2
|
-
import { ExpandedRowsFeature as
|
|
3
|
-
import { FocusedRowsFeature as
|
|
4
|
-
import { OrderColumnsFeature as
|
|
1
|
+
import { SELECT_COLUMN_ID as G } from "../types.js";
|
|
2
|
+
import { ExpandedRowsFeature as X } from "../custom-features/expand-rows/ExpandRowsFeature.js";
|
|
3
|
+
import { FocusedRowsFeature as $ } from "../custom-features/focus-rows/FocusRowsFeature.js";
|
|
4
|
+
import { OrderColumnsFeature as ee } from "../custom-features/order-columns/OrderColumnsFeature.js";
|
|
5
5
|
import { tableStorage as h } from "../helpers/tableStorage.js";
|
|
6
|
-
import { normalizeDefaultColumnOrder as
|
|
7
|
-
import { usePersistColumnOrder as
|
|
8
|
-
import { usePersistedColumnOrder as
|
|
9
|
-
import { getPersistedPageSizeKey as
|
|
10
|
-
import { columnSizingSignature as
|
|
11
|
-
import { getSortingStorageKey as
|
|
12
|
-
import { usePersistedStateWriter as
|
|
13
|
-
import { useColumnLayoutReconcile as
|
|
14
|
-
import { RowSelectionTooltipFeature as
|
|
15
|
-
import { getLeafColumnInfos as
|
|
16
|
-
import { resolveColumnSizingDefaults as
|
|
17
|
-
import { STYLED_DEFAULT_SORTING_FN as
|
|
18
|
-
import { useEffect as C, useMemo as b, useRef as
|
|
19
|
-
import { getCoreRowModel as
|
|
20
|
-
var
|
|
21
|
-
const { columns:
|
|
6
|
+
import { normalizeDefaultColumnOrder as te } from "../custom-features/order-columns/columnLayout.js";
|
|
7
|
+
import { usePersistColumnOrder as oe } from "../custom-features/order-columns/usePersistColumnOrder.js";
|
|
8
|
+
import { usePersistedColumnOrder as ie } from "../custom-features/order-columns/usePersistedColumnOrder.js";
|
|
9
|
+
import { getPersistedPageSizeKey as ne, usePersistedPageSize as re } from "./usePersistedPageSize.js";
|
|
10
|
+
import { columnSizingSignature as le, getColumnSizingStorageKey as se, serializeColumnSizing as ae, usePersistedColumnSizing as ue } from "./useColumnSizingPersistence.js";
|
|
11
|
+
import { getSortingStorageKey as de, readSortingFromStorage as ge, serializeSorting as me, sortingSignature as Se } from "./usePersistedSorting.js";
|
|
12
|
+
import { usePersistedStateWriter as A } from "./usePersistedStateWriter.js";
|
|
13
|
+
import { useColumnLayoutReconcile as ce, useColumnLayoutWriter as fe, useSavedColumnLayout as ye } from "./useColumnLayoutPersistence.js";
|
|
14
|
+
import { RowSelectionTooltipFeature as Ce } from "../custom-features/row-selection-tooltip/RowSelectionTooltipFeature.js";
|
|
15
|
+
import { getLeafColumnInfos as be } from "../helpers/columnIds.js";
|
|
16
|
+
import { resolveColumnSizingDefaults as pe } from "../helpers/columnSizingDefaults.js";
|
|
17
|
+
import { STYLED_DEFAULT_SORTING_FN as ve, createStyledDefaultSortingFn as ze, resolveSortUndefinedDefaults as Re } from "../helpers/defaultSortingFn.js";
|
|
18
|
+
import { useEffect as C, useMemo as b, useRef as p } from "react";
|
|
19
|
+
import { getCoreRowModel as Oe, getExpandedRowModel as Ke, getFilteredRowModel as Le, getPaginationRowModel as Ve, getSortedRowModel as Ie, useReactTable as Me } from "@tanstack/react-table";
|
|
20
|
+
var Fe = [], _e = {}, we = [], Pe = { [G]: !1 }, $e = (v) => {
|
|
21
|
+
const { columns: z, data: H, initialState: a, pageSize: B, enableRowSelection: W, tableInstanceRef: F, locale: Y, persistColumnOrderKey: m, uniqueKey: u, persistSorting: Z, persistColumnLayout: j, legacyColumnVisibilityKey: _, defaultColumn: r, ...t } = v, w = a?.sorting ?? Fe, R = a?.columnSizing ?? _e, O = v.enableColumnResizing ?? !0, q = v.enableColumnResizing === !0, J = b(() => Re(pe(z, {
|
|
22
22
|
defaultColumn: r,
|
|
23
23
|
enableSorting: t.enableSorting,
|
|
24
|
-
canResize:
|
|
24
|
+
canResize: O
|
|
25
25
|
}), r), [
|
|
26
|
-
|
|
26
|
+
z,
|
|
27
27
|
r,
|
|
28
28
|
t.enableSorting,
|
|
29
|
-
|
|
30
|
-
]),
|
|
29
|
+
O
|
|
30
|
+
]), K = be(z, {
|
|
31
31
|
defaultColumn: r,
|
|
32
32
|
enableSorting: t.enableSorting,
|
|
33
33
|
enableMultiSort: t.enableMultiSort,
|
|
34
34
|
enableHiding: t.enableHiding
|
|
35
|
-
}), i = j === !0,
|
|
35
|
+
}), i = j === !0, P = K.map((o) => o.id), l = te(a?.columnOrder ?? we, P), S = a?.columnVisibility ?? Pe, n = ye({
|
|
36
36
|
enabled: i,
|
|
37
|
-
uniqueKey:
|
|
38
|
-
legacyOrderKey:
|
|
39
|
-
legacyVisibilityKey:
|
|
40
|
-
columns:
|
|
37
|
+
uniqueKey: u,
|
|
38
|
+
legacyOrderKey: m,
|
|
39
|
+
legacyVisibilityKey: _,
|
|
40
|
+
columns: K,
|
|
41
41
|
defaultOrder: l,
|
|
42
|
-
defaultVisibility:
|
|
43
|
-
}), D =
|
|
44
|
-
sortableColumns:
|
|
42
|
+
defaultVisibility: S
|
|
43
|
+
}), D = ie(i ? void 0 : m), E = q ? u : void 0, T = se(E), L = ue(E, R), c = Z ? de(u) : void 0, V = b(() => c ? ge(u, {
|
|
44
|
+
sortableColumns: K.filter((o) => o.canSort),
|
|
45
45
|
maxMultiSortColCount: t.maxMultiSortColCount
|
|
46
|
-
}) : void 0, [
|
|
46
|
+
}) : void 0, [c]), d = re(u) ?? B ?? 50, N = p(void 0), k = b(() => ze(() => N.current), []), Q = b(() => ({
|
|
47
47
|
...r,
|
|
48
48
|
sortingFn: r?.sortingFn ?? "styledDefault"
|
|
49
|
-
}), [r]), e =
|
|
49
|
+
}), [r]), e = Me({
|
|
50
50
|
_features: [
|
|
51
|
-
Q,
|
|
52
51
|
X,
|
|
53
52
|
$,
|
|
54
|
-
|
|
53
|
+
ee,
|
|
54
|
+
Ce
|
|
55
55
|
],
|
|
56
56
|
columns: J,
|
|
57
|
-
data:
|
|
57
|
+
data: H,
|
|
58
58
|
meta: {
|
|
59
|
-
locale:
|
|
59
|
+
locale: Y ?? "en",
|
|
60
60
|
hideHeader: !!t.hideHeader
|
|
61
61
|
},
|
|
62
62
|
initialState: {
|
|
63
63
|
pagination: {
|
|
64
64
|
pageIndex: 0,
|
|
65
|
-
pageSize:
|
|
65
|
+
pageSize: d
|
|
66
66
|
},
|
|
67
67
|
columnVisibility: {
|
|
68
|
-
...
|
|
69
|
-
[
|
|
68
|
+
...a?.columnVisibility,
|
|
69
|
+
[G]: !1
|
|
70
70
|
},
|
|
71
71
|
...D && { columnOrder: D },
|
|
72
|
-
...
|
|
72
|
+
...a,
|
|
73
73
|
...i && l.length > 0 && { columnOrder: l },
|
|
74
74
|
...n.order && { columnOrder: n.order },
|
|
75
75
|
...n.visibility && { columnVisibility: n.visibility },
|
|
76
|
-
...
|
|
76
|
+
...L && { columnSizing: L },
|
|
77
77
|
...V !== void 0 && { sorting: V }
|
|
78
78
|
},
|
|
79
|
-
enableRowSelection:
|
|
80
|
-
getCoreRowModel:
|
|
81
|
-
getExpandedRowModel:
|
|
82
|
-
getFilteredRowModel:
|
|
83
|
-
getSortedRowModel:
|
|
79
|
+
enableRowSelection: W,
|
|
80
|
+
getCoreRowModel: Oe(),
|
|
81
|
+
getExpandedRowModel: Ke(),
|
|
82
|
+
getFilteredRowModel: Le(),
|
|
83
|
+
getSortedRowModel: Ie(),
|
|
84
84
|
getPaginationRowModel: Ve(),
|
|
85
|
-
getRowId: t.getRowId ?? ((o,
|
|
86
|
-
defaultColumn:
|
|
85
|
+
getRowId: t.getRowId ?? ((o, U, f) => f ? [f.id, o.id].join(".") : o.id.toString()),
|
|
86
|
+
defaultColumn: Q,
|
|
87
87
|
...t,
|
|
88
|
-
enableColumnResizing:
|
|
88
|
+
enableColumnResizing: O,
|
|
89
89
|
sortingFns: {
|
|
90
|
-
[
|
|
90
|
+
[ve]: k,
|
|
91
91
|
...t.sortingFns
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
-
|
|
95
|
-
const
|
|
94
|
+
N.current = e;
|
|
95
|
+
const y = e.options.meta?.locale, x = p(y);
|
|
96
96
|
C(() => {
|
|
97
|
-
|
|
98
|
-
}, [
|
|
97
|
+
x.current !== y && (x.current = y, e.getState().sorting.length > 0 && e.setSorting((o) => [...o]));
|
|
98
|
+
}, [y, e]), F && (F.current = e), oe(e, i ? void 0 : m), fe(e, {
|
|
99
99
|
saved: n,
|
|
100
|
-
reconciling:
|
|
100
|
+
reconciling: ce(e, {
|
|
101
101
|
enabled: i,
|
|
102
|
-
definitionIds:
|
|
102
|
+
definitionIds: P,
|
|
103
103
|
defaultOrder: l,
|
|
104
|
-
defaultVisibility:
|
|
104
|
+
defaultVisibility: S,
|
|
105
105
|
controlledVisibility: t.state?.columnVisibility !== void 0
|
|
106
106
|
}),
|
|
107
107
|
defaultOrder: l,
|
|
108
|
-
defaultVisibility:
|
|
108
|
+
defaultVisibility: S,
|
|
109
109
|
controlledVisibility: t.state?.columnVisibility !== void 0
|
|
110
110
|
}), C(() => {
|
|
111
|
-
}, [i, t.state?.columnVisibility !== void 0 || t.onColumnVisibilityChange !== void 0]),
|
|
112
|
-
storageKey:
|
|
111
|
+
}, [i, t.state?.columnVisibility !== void 0 || t.onColumnVisibilityChange !== void 0]), A({
|
|
112
|
+
storageKey: c,
|
|
113
113
|
state: e.getState().sorting,
|
|
114
114
|
defaultValue: w,
|
|
115
115
|
saved: V,
|
|
116
116
|
controlled: t.state?.sorting !== void 0,
|
|
117
|
-
toSignature:
|
|
118
|
-
toStorage:
|
|
117
|
+
toSignature: Se,
|
|
118
|
+
toStorage: me,
|
|
119
119
|
applyState: (o) => e.setSorting(o)
|
|
120
|
-
}),
|
|
121
|
-
storageKey:
|
|
120
|
+
}), A({
|
|
121
|
+
storageKey: T,
|
|
122
122
|
state: e.getState().columnSizing,
|
|
123
|
-
defaultValue:
|
|
124
|
-
saved:
|
|
123
|
+
defaultValue: R,
|
|
124
|
+
saved: L,
|
|
125
125
|
settled: !e.getState().columnSizingInfo.isResizingColumn,
|
|
126
|
-
toSignature:
|
|
127
|
-
toStorage:
|
|
126
|
+
toSignature: le,
|
|
127
|
+
toStorage: ae,
|
|
128
128
|
applyState: (o) => e.setColumnSizing(o)
|
|
129
129
|
}), e.columnLayoutDefaults = i ? {
|
|
130
130
|
order: l,
|
|
131
|
-
visibility:
|
|
131
|
+
visibility: S
|
|
132
132
|
} : void 0, e.resetColumnSettings = () => {
|
|
133
|
-
e.setColumnOrder(i ? l : []), e.setColumnSizing(
|
|
133
|
+
e.setColumnOrder(i ? l : []), e.setColumnSizing(R), i && e.setColumnVisibility(S), c && e.setSorting(w);
|
|
134
134
|
const o = i && n.orderKey !== void 0 ? [
|
|
135
135
|
n.orderKey,
|
|
136
136
|
n.visibilityKey,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
] : [],
|
|
140
|
-
for (const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
m,
|
|
138
|
+
_
|
|
139
|
+
] : [], U = i ? void 0 : m;
|
|
140
|
+
for (const f of [
|
|
141
|
+
c,
|
|
142
|
+
T,
|
|
143
|
+
U,
|
|
144
144
|
...o
|
|
145
|
-
])
|
|
145
|
+
]) f && h.remove(f);
|
|
146
146
|
};
|
|
147
|
-
const
|
|
147
|
+
const g = ne(u), s = e.getState().pagination?.pageSize, I = p(void 0), M = p(void 0);
|
|
148
148
|
return C(() => {
|
|
149
|
-
|
|
149
|
+
I.current = void 0, e.getState().pagination?.pageSize !== d && (e.setPageIndex(0), e.setPageSize(d));
|
|
150
150
|
}, [
|
|
151
|
-
u,
|
|
152
151
|
d,
|
|
152
|
+
g,
|
|
153
153
|
e
|
|
154
154
|
]), C(() => {
|
|
155
|
-
if (!(!
|
|
156
|
-
if (
|
|
157
|
-
if (
|
|
158
|
-
M.current =
|
|
155
|
+
if (!(!g || s == null)) {
|
|
156
|
+
if (I.current !== g) {
|
|
157
|
+
if (s !== d) return;
|
|
158
|
+
I.current = g, M.current = s;
|
|
159
|
+
return;
|
|
159
160
|
}
|
|
160
|
-
h.set(
|
|
161
|
+
s !== M.current && (M.current = s, h.set(g, JSON.stringify(s)));
|
|
161
162
|
}
|
|
162
163
|
}, [
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
s,
|
|
165
|
+
d,
|
|
166
|
+
g
|
|
166
167
|
]), { table: e };
|
|
167
168
|
};
|
|
168
169
|
export {
|
|
169
|
-
|
|
170
|
+
$e as useStyledTable
|
|
170
171
|
};
|
package/dist/table/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "./types.js";
|
|
2
|
+
import "./hooks/usePersistedPageSize.js";
|
|
2
3
|
import "./hooks/usePersistedSorting.js";
|
|
3
4
|
import "./components/columns/dndHandleColumn.js";
|
|
4
5
|
import "./components/StyledTableIndex.js";
|
|
5
6
|
import "./helpers/migrateLegacyTableSettings.js";
|
|
6
7
|
import "./hooks/useLegacyTableSettingsMigration.js";
|
|
7
|
-
import { createColumnHelper as
|
|
8
|
+
import { createColumnHelper as A } from "@tanstack/react-table";
|
|
8
9
|
export {
|
|
9
|
-
|
|
10
|
+
A as createColumnHelper
|
|
10
11
|
};
|