asma-ui-core 3.137.2 → 3.138.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/src/table/custom-features/order-columns/types.d.ts +1 -1
- package/dist/src/table/custom-features/order-columns/usePersistColumnOrder.d.ts +2 -1
- package/dist/src/table/hooks/usePersistedSorting.d.ts +25 -3
- package/dist/src/table/hooks/usePersistedStateWriter.d.ts +4 -0
- package/dist/src/table/types.d.ts +15 -4
- package/dist/table/custom-features/order-columns/usePersistColumnOrder.js +10 -10
- package/dist/table/hooks/useColumnLayoutPersistence.js +37 -37
- package/dist/table/hooks/usePersistedSorting.js +21 -20
- package/dist/table/hooks/usePersistedStateWriter.js +18 -18
- package/dist/table/hooks/useStyledTable.js +113 -108
- package/package.json +1 -1
|
@@ -21,7 +21,7 @@ export interface ColumnLayoutDefaults {
|
|
|
21
21
|
export interface ColumnSettingsInstance {
|
|
22
22
|
/**
|
|
23
23
|
* Reset columns (ASMA-8597): puts the column order and the widths back to the table's defaults, and the
|
|
24
|
-
* sorting too when the table
|
|
24
|
+
* sorting too when the table saves it (a `uniqueKey`, unless `persistSorting={false}` or the app owns the sorting). It removes the saved entries of what it resets. On a table
|
|
25
25
|
* with `persistColumnLayout` (ASMA-8695, OQ-02) it also puts the visibility back to the default, unhiding what
|
|
26
26
|
* the user hid and hiding what is hidden by default; any other table never touches visibility. Set by
|
|
27
27
|
* `StyledTable`, which knows the defaults.
|
|
@@ -2,6 +2,7 @@ import { Table } from '@tanstack/react-table';
|
|
|
2
2
|
/**
|
|
3
3
|
* Saves the column order under `key` when it changes. An order that is `[]` or that matches the live
|
|
4
4
|
* definition order removes the entry instead (ASMA-8597, REQ-004), so a table the user has put back to its
|
|
5
|
-
* defaults stores nothing. Mounting never writes.
|
|
5
|
+
* defaults stores nothing. Mounting never writes. A table with no key does no work per render (ASMA-8698), and whether the
|
|
6
|
+
* order is the default is worked out only when it is about to be saved.
|
|
6
7
|
*/
|
|
7
8
|
export declare function usePersistColumnOrder<TData = unknown>(table: Table<TData>, key?: string | null): void;
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { OnChangeFn, SortingState } from '@tanstack/react-table';
|
|
2
2
|
export declare const getSortingStorageKey: (uniqueKey?: string) => string | undefined;
|
|
3
|
+
/** What decides whether `StyledTable` saves a table's sorting: the props that matter, read from the table's own. */
|
|
4
|
+
export interface SortingPersistenceInput {
|
|
5
|
+
uniqueKey?: string;
|
|
6
|
+
/** The `persistSorting` prop as the app wrote it; `undefined` when it did not. */
|
|
7
|
+
persistSorting?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The app owns the sorting state: it passes `state.sorting`, or `onSortingChange`. TanStack hands every change to that
|
|
10
|
+
* handler instead of updating the table's own state, so a handler alone is as much the app's state as `state.sorting`.
|
|
11
|
+
*/
|
|
12
|
+
controlled: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Whether `StyledTable` reads and writes the sorting under `${uniqueKey}:sorting` (ASMA-8698, DEC-8698-OPTOUT).
|
|
16
|
+
*
|
|
17
|
+
* - No `uniqueKey`: never.
|
|
18
|
+
* - `persistSorting={false}`: never, the opt-out for tables whose order is the user's own (drag and drop).
|
|
19
|
+
* - `persistSorting={true}`: yes, even when the app owns the sorting state. That is how such an app lets `StyledTable` be the
|
|
20
|
+
* only writer of the sort it reads back with `usePersistedSorting`.
|
|
21
|
+
* - Not written: yes, unless the app owns the sorting state. A saved sort could not be applied to a state the table does not
|
|
22
|
+
* own, and an app that persists its own sort would have two writers fighting over it.
|
|
23
|
+
*/
|
|
24
|
+
export declare const savesSorting: ({ uniqueKey, persistSorting, controlled }: SortingPersistenceInput) => boolean;
|
|
3
25
|
/** What a saved sort is checked against: the columns that can sort, and the multi-sort rules. */
|
|
4
26
|
export interface SortingRules {
|
|
5
27
|
sortableColumns: readonly {
|
|
@@ -27,7 +49,7 @@ export interface PersistedSortingOptions {
|
|
|
27
49
|
maxMultiSortColCount?: number;
|
|
28
50
|
}
|
|
29
51
|
/**
|
|
30
|
-
* Reads the sorting `StyledTable` saved for `uniqueKey
|
|
52
|
+
* Reads the sorting `StyledTable` saved for `uniqueKey`, checked against the columns
|
|
31
53
|
* the caller can sort by. Synchronous and pure, so a table that owns its sorting state (for example because
|
|
32
54
|
* the server sorts) can use the saved sort for its first request. Returns `undefined` when nothing valid is
|
|
33
55
|
* saved, and `[]` when the user turned sorting off.
|
|
@@ -36,8 +58,8 @@ export declare const readPersistedSorting: (uniqueKey: string | undefined, optio
|
|
|
36
58
|
/**
|
|
37
59
|
* Sorting state for a table that owns `state.sorting`: the saved sort on the first render (before the first
|
|
38
60
|
* request), `defaultSorting` when nothing valid is saved, and the new key's sort after `uniqueKey` changes.
|
|
39
|
-
* It never writes: `StyledTable`
|
|
40
|
-
* from `initialState.sorting`, which Reset columns restores.
|
|
61
|
+
* It never writes: `StyledTable` is the only writer, and it saves a sort the app owns only with `persistSorting` written
|
|
62
|
+
* on the table (see `savesSorting`). It takes the same default from `initialState.sorting`, which Reset columns restores.
|
|
41
63
|
*
|
|
42
64
|
* ```tsx
|
|
43
65
|
* const { sorting, onSortingChange } = usePersistedSorting({ uniqueKey, defaultSorting, sortableColumnIds })
|
|
@@ -25,6 +25,10 @@ interface PersistedStateWriterOptions<T> {
|
|
|
25
25
|
* entry is never touched, so the old value can't be copied over the new key.
|
|
26
26
|
* - When the key goes away (`undefined`), the table goes back to the app's defaults and writes nothing, so
|
|
27
27
|
* one user's values are not left on screen for whoever is shown next.
|
|
28
|
+
*
|
|
29
|
+
* It costs a table that does not save the setting nothing per render (ASMA-8698): the value's signature is computed only
|
|
30
|
+
* while there is a key (the render that loses the key reads it in the layout effect), and the default's only when a write
|
|
31
|
+
* or a reset needs it.
|
|
28
32
|
*/
|
|
29
33
|
export declare const usePersistedStateWriter: <T>(options: PersistedStateWriterOptions<T>) => void;
|
|
30
34
|
export {};
|
|
@@ -158,10 +158,21 @@ export type StyledTableProps<TData, TCustomData> = {
|
|
|
158
158
|
*/
|
|
159
159
|
uniqueKey?: string;
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
161
|
+
* Whether the table saves and restores its sorting under `${uniqueKey}:sorting`, and lets Reset columns reset it
|
|
162
|
+
* (ASMA-8698). It does by default: a table with a `uniqueKey` remembers each user's sort, like their column widths. Without
|
|
163
|
+
* `uniqueKey` nothing is saved.
|
|
164
|
+
*
|
|
165
|
+
* - `false` is the opt-out, for a table whose order is the user's own (drag and drop rows) or that must always open as the
|
|
166
|
+
* app declares it. Nothing is read or written for sorting then.
|
|
167
|
+
* - Leaving it out, or `true`, saves a sort that `StyledTable` owns. `true` is the default spelled out: nothing changes
|
|
168
|
+
* for a table that has it (it will not be removed before the next major version).
|
|
169
|
+
* - A table whose app owns the sorting state (`state.sorting`, or `onSortingChange`, which TanStack calls instead of
|
|
170
|
+
* updating the table's own state) is **not** saved by default: the saved sort could not be applied to a state the table
|
|
171
|
+
* does not own, and an app with its own persistence would have two writers. Such a table that wants it saved writes
|
|
172
|
+
* `persistSorting` (`true`), makes `StyledTable` the only writer, and reads the sort back with `usePersistedSorting`.
|
|
173
|
+
*
|
|
174
|
+
* A saved sort of a column that is gone or cannot sort is ignored, and so is storage that is corrupt, full or blocked: the
|
|
175
|
+
* table opens with its `initialState.sorting`, which Reset columns also returns to.
|
|
165
176
|
*/
|
|
166
177
|
persistSorting?: boolean;
|
|
167
178
|
/**
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { tableStorage as
|
|
2
|
-
import { isDefaultColumnOrder as
|
|
3
|
-
import { useEffect as
|
|
4
|
-
function
|
|
5
|
-
const o = n.getState().columnOrder, t = JSON.stringify(o ?? [])
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
|
|
1
|
+
import { tableStorage as s } from "../../helpers/tableStorage.js";
|
|
2
|
+
import { isDefaultColumnOrder as c } from "./columnLayout.js";
|
|
3
|
+
import { useEffect as i, useRef as f } from "react";
|
|
4
|
+
function g(n, r) {
|
|
5
|
+
const o = n.getState().columnOrder, t = r ? JSON.stringify(o ?? []) : "", u = f(r), e = f(t);
|
|
6
|
+
i(() => {
|
|
7
|
+
if (u.current !== r) {
|
|
8
|
+
u.current = r, e.current = t;
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
!r || t === e.current || (e.current = t, c ?
|
|
11
|
+
!r || t === e.current || (e.current = t, !o?.length || c(n) ? s.remove(r) : s.set(r, t));
|
|
12
12
|
}, [t, r]);
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
g as usePersistColumnOrder
|
|
16
16
|
};
|
|
@@ -16,30 +16,30 @@ var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${
|
|
|
16
16
|
const i = C(e);
|
|
17
17
|
return i.length > 0 ? i : void 0;
|
|
18
18
|
}, T = (e, i, t) => {
|
|
19
|
-
if (!S(e) || !Object.values(e).every((
|
|
20
|
-
const r = K(Object.fromEntries(Object.entries(e).filter(([
|
|
19
|
+
if (!S(e) || !Object.values(e).every((s) => typeof s == "boolean")) return;
|
|
20
|
+
const r = K(Object.fromEntries(Object.entries(e).filter(([s]) => p(s, i))), t);
|
|
21
21
|
return Object.keys(r).length > 0 ? r : void 0;
|
|
22
22
|
}, U = (e) => {
|
|
23
|
-
const { enabled: i, uniqueKey: t, legacyOrderKey: r, legacyVisibilityKey:
|
|
23
|
+
const { enabled: i, uniqueKey: t, legacyOrderKey: r, legacyVisibilityKey: s, columns: o, defaultOrder: g, defaultVisibility: n } = e, d = i ? k(t) : void 0, a = i ? E(t) : void 0, l = o.map((y) => y.id), c = [];
|
|
24
24
|
let b, u;
|
|
25
|
-
if (
|
|
26
|
-
if (v.get(
|
|
25
|
+
if (d) {
|
|
26
|
+
if (v.get(d) !== null) b = D(O(d));
|
|
27
27
|
else if (r && v.get(r) !== null) {
|
|
28
|
-
const
|
|
29
|
-
|
|
28
|
+
const y = x(O(r)), I = y === void 0 || m(j(y, l), l).join() === m(g, l).join();
|
|
29
|
+
y && !I && (b = y), c.push({
|
|
30
30
|
legacyKey: r,
|
|
31
|
-
...
|
|
32
|
-
key:
|
|
31
|
+
...y && !I && { write: {
|
|
32
|
+
key: d,
|
|
33
33
|
value: JSON.stringify({
|
|
34
34
|
v: f,
|
|
35
|
-
order:
|
|
35
|
+
order: y
|
|
36
36
|
})
|
|
37
37
|
} }
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
return a && (v.get(a) !== null ? u = $(O(a),
|
|
42
|
-
legacyKey:
|
|
41
|
+
return a && (v.get(a) !== null ? u = $(O(a), o) : s && v.get(s) !== null && (u = T(O(s), o, n), c.push({
|
|
42
|
+
legacyKey: s,
|
|
43
43
|
...u && { write: {
|
|
44
44
|
key: a,
|
|
45
45
|
value: JSON.stringify({
|
|
@@ -48,18 +48,18 @@ var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${
|
|
|
48
48
|
})
|
|
49
49
|
} }
|
|
50
50
|
}))), {
|
|
51
|
-
orderKey:
|
|
51
|
+
orderKey: d,
|
|
52
52
|
visibilityKey: a,
|
|
53
53
|
order: b,
|
|
54
54
|
visibility: u,
|
|
55
55
|
migration: c
|
|
56
56
|
};
|
|
57
57
|
}, W = (e, i, t) => {
|
|
58
|
-
const r = e.visibility && Object.fromEntries(Object.entries(e.visibility).filter(([
|
|
58
|
+
const r = e.visibility && Object.fromEntries(Object.entries(e.visibility).filter(([s]) => p(s, i)));
|
|
59
59
|
return {
|
|
60
60
|
orderKey: e.orderKey,
|
|
61
61
|
visibilityKey: e.visibilityKey,
|
|
62
|
-
order: e.order && j(e.order, i.map((
|
|
62
|
+
order: e.order && j(e.order, i.map((s) => s.id)),
|
|
63
63
|
visibility: r && Object.keys(r).length > 0 ? {
|
|
64
64
|
...t,
|
|
65
65
|
...r
|
|
@@ -77,41 +77,41 @@ var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${
|
|
|
77
77
|
r && !v.set(r.key, r.value) || v.remove(t);
|
|
78
78
|
}, [i]), W(i, e.columns, e.defaultVisibility);
|
|
79
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:
|
|
81
|
-
signature: JSON.stringify([
|
|
80
|
+
const { enabled: t, definitionIds: r, defaultOrder: s, defaultVisibility: o, controlledVisibility: g } = i, n = {
|
|
81
|
+
signature: t ? JSON.stringify([
|
|
82
82
|
r,
|
|
83
|
-
|
|
84
|
-
Object.entries(
|
|
85
|
-
]),
|
|
83
|
+
s,
|
|
84
|
+
Object.entries(o).sort()
|
|
85
|
+
]) : "",
|
|
86
86
|
definitionIds: r,
|
|
87
|
-
defaultOrder:
|
|
88
|
-
defaultVisibility:
|
|
89
|
-
},
|
|
87
|
+
defaultOrder: s,
|
|
88
|
+
defaultVisibility: o
|
|
89
|
+
}, d = V.get(e) ?? n, a = t && d.signature !== "" && d.signature !== n.signature;
|
|
90
90
|
return R(() => {
|
|
91
|
-
const
|
|
92
|
-
if (V.set(e,
|
|
93
|
-
const c = e.getState().columnOrder, b = m(c,
|
|
91
|
+
const l = V.get(e);
|
|
92
|
+
if (V.set(e, n), !t || !l || l.signature === "" || l.signature === n.signature) return;
|
|
93
|
+
const c = e.getState().columnOrder, b = m(c, l.definitionIds).join() === m(l.defaultOrder, l.definitionIds).join() ? s : j(c, r);
|
|
94
94
|
if (e.setColumnOrder(b), !g) {
|
|
95
|
-
const u = e.getState().columnVisibility,
|
|
96
|
-
...
|
|
97
|
-
...K(u,
|
|
95
|
+
const u = e.getState().columnVisibility, y = {
|
|
96
|
+
...o,
|
|
97
|
+
...K(u, l.defaultVisibility)
|
|
98
98
|
};
|
|
99
|
-
Y(
|
|
99
|
+
Y(y, u) || e.setColumnVisibility(y);
|
|
100
100
|
}
|
|
101
101
|
}, [
|
|
102
102
|
e,
|
|
103
103
|
t,
|
|
104
|
-
|
|
104
|
+
n.signature
|
|
105
105
|
]), a;
|
|
106
106
|
}, Q = (e, i) => {
|
|
107
|
-
const { saved: t, reconciling: r, defaultOrder:
|
|
107
|
+
const { saved: t, reconciling: r, defaultOrder: s, defaultVisibility: o, controlledVisibility: g } = i;
|
|
108
108
|
L({
|
|
109
109
|
storageKey: t.orderKey,
|
|
110
110
|
state: e.getState().columnOrder,
|
|
111
|
-
defaultValue:
|
|
111
|
+
defaultValue: s,
|
|
112
112
|
saved: t.order,
|
|
113
113
|
settled: !r,
|
|
114
|
-
toSignature: (n) => JSON.stringify(m(n,
|
|
114
|
+
toSignature: (n) => JSON.stringify(m(n, A(e))),
|
|
115
115
|
toStorage: (n) => JSON.stringify({
|
|
116
116
|
v: f,
|
|
117
117
|
order: C(n)
|
|
@@ -120,14 +120,14 @@ var F = ":column-order", M = ":column-visibility", f = 1, k = (e) => e ? `${e}${
|
|
|
120
120
|
}), L({
|
|
121
121
|
storageKey: t.visibilityKey,
|
|
122
122
|
state: e.getState().columnVisibility,
|
|
123
|
-
defaultValue:
|
|
123
|
+
defaultValue: o,
|
|
124
124
|
saved: t.visibility,
|
|
125
125
|
settled: !r,
|
|
126
126
|
controlled: g,
|
|
127
|
-
toSignature: (n) => h(n,
|
|
127
|
+
toSignature: (n) => h(n, o),
|
|
128
128
|
toStorage: (n) => JSON.stringify({
|
|
129
129
|
v: f,
|
|
130
|
-
visibility: K(n,
|
|
130
|
+
visibility: K(n, o)
|
|
131
131
|
}),
|
|
132
132
|
applyState: (n) => e.setColumnVisibility(n)
|
|
133
133
|
});
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { readJson as
|
|
2
|
-
import { useCallback as f, useState as
|
|
1
|
+
import { readJson as S } from "../helpers/tableStorage.js";
|
|
2
|
+
import { useCallback as f, useState as u } from "react";
|
|
3
3
|
import { functionalUpdate as v } from "@tanstack/react-table";
|
|
4
|
-
var
|
|
5
|
-
if (!d(t) || t.v !==
|
|
4
|
+
var m = ":sorting", l = 1, p = [], y = (t) => t ? `${t}${m}` : void 0, R = ({ uniqueKey: t, persistSorting: r, controlled: o }) => !t || r === !1 ? !1 : r === !0 || !o, d = (t) => typeof t == "object" && t !== null && !Array.isArray(t), O = (t, r) => {
|
|
5
|
+
if (!d(t) || t.v !== l || !Array.isArray(t.sorting)) return;
|
|
6
6
|
const o = t.sorting;
|
|
7
7
|
if (o.length === 0) return [];
|
|
8
|
-
const s = new Map(r.sortableColumns.map((n) => [n.id, n])), a = /* @__PURE__ */ new Set(),
|
|
8
|
+
const s = new Map(r.sortableColumns.map((n) => [n.id, n])), a = /* @__PURE__ */ new Set(), i = [];
|
|
9
9
|
for (const n of o) {
|
|
10
10
|
if (!d(n) || typeof n.id != "string" || typeof n.desc != "boolean") continue;
|
|
11
11
|
const g = s.get(n.id);
|
|
12
|
-
!g || a.has(n.id) ||
|
|
12
|
+
!g || a.has(n.id) || i.length > 0 && (r.enableMultiSort === !1 || !g.canMultiSort) || (a.add(n.id), i.push({
|
|
13
13
|
id: n.id,
|
|
14
14
|
desc: n.desc
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const e = r.maxMultiSortColCount, c = e !== void 0 && Number.isFinite(e) && e >= 1 ? i.slice(0, Math.floor(e)) : i;
|
|
18
18
|
return c.length > 0 ? c : void 0;
|
|
19
|
-
},
|
|
20
|
-
v:
|
|
19
|
+
}, A = (t) => JSON.stringify({
|
|
20
|
+
v: l,
|
|
21
21
|
sorting: t.map(({ id: r, desc: o }) => ({
|
|
22
22
|
id: r,
|
|
23
23
|
desc: o
|
|
24
24
|
}))
|
|
25
|
-
}),
|
|
25
|
+
}), I = (t) => JSON.stringify(t.map(({ id: r, desc: o }) => [r, o])), N = (t, r) => {
|
|
26
26
|
const o = y(t);
|
|
27
|
-
return o ? O(
|
|
27
|
+
return o ? O(S(o), r) : void 0;
|
|
28
28
|
}, b = ({ sortableColumnIds: t, enableMultiSort: r, maxMultiSortColCount: o }) => ({
|
|
29
29
|
sortableColumns: t.map((s) => ({
|
|
30
30
|
id: s,
|
|
@@ -32,19 +32,19 @@ var p = ":sorting", S = 1, u = [], y = (t) => t ? `${t}${p}` : void 0, d = (t) =
|
|
|
32
32
|
})),
|
|
33
33
|
enableMultiSort: r,
|
|
34
34
|
maxMultiSortColCount: o
|
|
35
|
-
}), h = (t, r) => N(t, b(r)),
|
|
35
|
+
}), h = (t, r) => N(t, b(r)), _ = ({ uniqueKey: t, defaultSorting: r = p, ...o }) => {
|
|
36
36
|
const s = () => ({
|
|
37
37
|
key: t,
|
|
38
38
|
sorting: h(t, o) ?? r
|
|
39
|
-
}), [a,
|
|
40
|
-
let
|
|
41
|
-
a.key !== t && (
|
|
42
|
-
const c = f((n) =>
|
|
39
|
+
}), [a, i] = u(s);
|
|
40
|
+
let e = a;
|
|
41
|
+
a.key !== t && (e = s(), i(e));
|
|
42
|
+
const c = f((n) => i((g) => ({
|
|
43
43
|
...g,
|
|
44
44
|
sorting: v(n, g.sorting)
|
|
45
45
|
})), []);
|
|
46
46
|
return {
|
|
47
|
-
sorting:
|
|
47
|
+
sorting: e.sorting,
|
|
48
48
|
onSortingChange: c
|
|
49
49
|
};
|
|
50
50
|
};
|
|
@@ -52,7 +52,8 @@ export {
|
|
|
52
52
|
y as getSortingStorageKey,
|
|
53
53
|
h as readPersistedSorting,
|
|
54
54
|
N as readSortingFromStorage,
|
|
55
|
-
R as
|
|
56
|
-
A as
|
|
57
|
-
I as
|
|
55
|
+
R as savesSorting,
|
|
56
|
+
A as serializeSorting,
|
|
57
|
+
I as sortingSignature,
|
|
58
|
+
_ as usePersistedSorting
|
|
58
59
|
};
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { tableStorage as
|
|
2
|
-
import { useEffect as
|
|
3
|
-
var
|
|
4
|
-
const { storageKey: t, state:
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
if (
|
|
8
|
-
!i &&
|
|
1
|
+
import { tableStorage as m } from "../helpers/tableStorage.js";
|
|
2
|
+
import { useEffect as v, useLayoutEffect as R, useRef as l } from "react";
|
|
3
|
+
var E = (a) => {
|
|
4
|
+
const { storageKey: t, state: s, defaultValue: o, saved: y, settled: f = !0, controlled: i = !1 } = a, { toSignature: n, toStorage: p, applyState: d } = a, e = t !== void 0 ? n(s) : "", g = l(t), c = l(e), u = l(null);
|
|
5
|
+
R(() => {
|
|
6
|
+
if (g.current === t) return;
|
|
7
|
+
if (g.current = t, u.current = null, c.current = e, !t) {
|
|
8
|
+
!i && n(s) !== n(o) && d(o);
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const r =
|
|
12
|
-
|
|
11
|
+
const r = y ?? o, S = n(r);
|
|
12
|
+
u.current = {
|
|
13
13
|
stale: e,
|
|
14
|
-
loaded:
|
|
15
|
-
}, !i &&
|
|
16
|
-
}, [t]),
|
|
14
|
+
loaded: S
|
|
15
|
+
}, !i && S !== e && d(r);
|
|
16
|
+
}, [t]), v(() => {
|
|
17
17
|
if (!t || !f) return;
|
|
18
|
-
const r =
|
|
18
|
+
const r = u.current;
|
|
19
19
|
if (r) {
|
|
20
20
|
if (e === r.loaded) {
|
|
21
|
-
|
|
21
|
+
u.current = null, c.current = e;
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
if (e === r.stale) return;
|
|
25
|
-
|
|
25
|
+
u.current = null;
|
|
26
26
|
}
|
|
27
|
-
e !==
|
|
27
|
+
e !== c.current && (c.current = e, e === n(o) ? m.remove(t) : m.set(t, p(s)));
|
|
28
28
|
}, [
|
|
29
29
|
e,
|
|
30
30
|
t,
|
|
@@ -32,5 +32,5 @@ var K = (a) => {
|
|
|
32
32
|
]);
|
|
33
33
|
};
|
|
34
34
|
export {
|
|
35
|
-
|
|
35
|
+
E as usePersistedStateWriter
|
|
36
36
|
};
|
|
@@ -1,170 +1,175 @@
|
|
|
1
|
-
import { SELECT_COLUMN_ID as
|
|
2
|
-
import { ExpandedRowsFeature as
|
|
3
|
-
import { FocusedRowsFeature as
|
|
4
|
-
import { OrderColumnsFeature as
|
|
5
|
-
import { tableStorage as
|
|
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:
|
|
22
|
-
defaultColumn:
|
|
1
|
+
import { SELECT_COLUMN_ID as W } from "../types.js";
|
|
2
|
+
import { ExpandedRowsFeature as $ } from "../custom-features/expand-rows/ExpandRowsFeature.js";
|
|
3
|
+
import { FocusedRowsFeature as ee } from "../custom-features/focus-rows/FocusRowsFeature.js";
|
|
4
|
+
import { OrderColumnsFeature as te } from "../custom-features/order-columns/OrderColumnsFeature.js";
|
|
5
|
+
import { tableStorage as H } from "../helpers/tableStorage.js";
|
|
6
|
+
import { normalizeDefaultColumnOrder as oe } from "../custom-features/order-columns/columnLayout.js";
|
|
7
|
+
import { usePersistColumnOrder as ie } from "../custom-features/order-columns/usePersistColumnOrder.js";
|
|
8
|
+
import { usePersistedColumnOrder as ne } from "../custom-features/order-columns/usePersistedColumnOrder.js";
|
|
9
|
+
import { getPersistedPageSizeKey as re, usePersistedPageSize as le } from "./usePersistedPageSize.js";
|
|
10
|
+
import { columnSizingSignature as se, getColumnSizingStorageKey as ae, serializeColumnSizing as ue, usePersistedColumnSizing as de } from "./useColumnSizingPersistence.js";
|
|
11
|
+
import { getSortingStorageKey as ge, readSortingFromStorage as me, savesSorting as ce, serializeSorting as Se, sortingSignature as fe } from "./usePersistedSorting.js";
|
|
12
|
+
import { usePersistedStateWriter as G } from "./usePersistedStateWriter.js";
|
|
13
|
+
import { useColumnLayoutReconcile as ye, useColumnLayoutWriter as Ce, useSavedColumnLayout as be } from "./useColumnLayoutPersistence.js";
|
|
14
|
+
import { RowSelectionTooltipFeature as pe } from "../custom-features/row-selection-tooltip/RowSelectionTooltipFeature.js";
|
|
15
|
+
import { getLeafColumnInfos as ve } from "../helpers/columnIds.js";
|
|
16
|
+
import { resolveColumnSizingDefaults as ze } from "../helpers/columnSizingDefaults.js";
|
|
17
|
+
import { STYLED_DEFAULT_SORTING_FN as Re, createStyledDefaultSortingFn as Oe, resolveSortUndefinedDefaults as Ke } from "../helpers/defaultSortingFn.js";
|
|
18
|
+
import { useEffect as C, useMemo as b, useRef as p } from "react";
|
|
19
|
+
import { getCoreRowModel as Ve, getExpandedRowModel as Me, getFilteredRowModel as Ie, getPaginationRowModel as Le, getSortedRowModel as Fe, useReactTable as we } from "@tanstack/react-table";
|
|
20
|
+
var Pe = [], _e = {}, De = [], Ne = { [W]: !1 }, et = (v) => {
|
|
21
|
+
const { columns: z, data: A, initialState: u, pageSize: B, enableRowSelection: Y, tableInstanceRef: F, locale: j, persistColumnOrderKey: m, uniqueKey: r, persistSorting: q, persistColumnLayout: J, legacyColumnVisibilityKey: w, defaultColumn: l, ...t } = v, P = u?.sorting ?? Pe, R = u?.columnSizing ?? _e, O = v.enableColumnResizing ?? !0, Z = v.enableColumnResizing === !0, k = b(() => Ke(ze(z, {
|
|
22
|
+
defaultColumn: l,
|
|
23
23
|
enableSorting: t.enableSorting,
|
|
24
|
-
canResize:
|
|
25
|
-
}),
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
canResize: O
|
|
25
|
+
}), l), [
|
|
26
|
+
z,
|
|
27
|
+
l,
|
|
28
28
|
t.enableSorting,
|
|
29
|
-
|
|
30
|
-
]),
|
|
31
|
-
defaultColumn:
|
|
29
|
+
O
|
|
30
|
+
]), K = ve(z, {
|
|
31
|
+
defaultColumn: l,
|
|
32
32
|
enableSorting: t.enableSorting,
|
|
33
33
|
enableMultiSort: t.enableMultiSort,
|
|
34
34
|
enableHiding: t.enableHiding
|
|
35
|
-
}), i =
|
|
35
|
+
}), i = J === !0, _ = K.map((o) => o.id), s = oe(u?.columnOrder ?? De, _), c = u?.columnVisibility ?? Ne, n = be({
|
|
36
36
|
enabled: i,
|
|
37
|
-
uniqueKey:
|
|
38
|
-
legacyOrderKey:
|
|
39
|
-
legacyVisibilityKey:
|
|
40
|
-
columns:
|
|
41
|
-
defaultOrder:
|
|
42
|
-
defaultVisibility:
|
|
43
|
-
}), D =
|
|
44
|
-
|
|
37
|
+
uniqueKey: r,
|
|
38
|
+
legacyOrderKey: m,
|
|
39
|
+
legacyVisibilityKey: w,
|
|
40
|
+
columns: K,
|
|
41
|
+
defaultOrder: s,
|
|
42
|
+
defaultVisibility: c
|
|
43
|
+
}), D = ne(i ? void 0 : m), N = Z ? r : void 0, T = ae(N), V = de(N, R), E = t.state?.sorting !== void 0 || t.onSortingChange !== void 0, S = ce({
|
|
44
|
+
uniqueKey: r,
|
|
45
|
+
persistSorting: q,
|
|
46
|
+
controlled: E
|
|
47
|
+
}) ? ge(r) : void 0, M = b(() => S ? me(r, {
|
|
48
|
+
sortableColumns: K.filter((o) => o.canSort),
|
|
45
49
|
maxMultiSortColCount: t.maxMultiSortColCount
|
|
46
|
-
}) : void 0, [S]),
|
|
47
|
-
...
|
|
48
|
-
sortingFn:
|
|
49
|
-
}), [
|
|
50
|
+
}) : void 0, [S]), d = le(r) ?? B ?? 50, x = p(void 0), Q = b(() => Oe(() => x.current), []), X = b(() => ({
|
|
51
|
+
...l,
|
|
52
|
+
sortingFn: l?.sortingFn ?? "styledDefault"
|
|
53
|
+
}), [l]), e = we({
|
|
50
54
|
_features: [
|
|
51
|
-
Q,
|
|
52
|
-
X,
|
|
53
55
|
$,
|
|
54
|
-
|
|
56
|
+
ee,
|
|
57
|
+
te,
|
|
58
|
+
pe
|
|
55
59
|
],
|
|
56
|
-
columns:
|
|
57
|
-
data:
|
|
60
|
+
columns: k,
|
|
61
|
+
data: A,
|
|
58
62
|
meta: {
|
|
59
|
-
locale:
|
|
63
|
+
locale: j ?? "en",
|
|
60
64
|
hideHeader: !!t.hideHeader
|
|
61
65
|
},
|
|
62
66
|
initialState: {
|
|
63
67
|
pagination: {
|
|
64
68
|
pageIndex: 0,
|
|
65
|
-
pageSize:
|
|
69
|
+
pageSize: d
|
|
66
70
|
},
|
|
67
71
|
columnVisibility: {
|
|
68
|
-
...
|
|
69
|
-
[
|
|
72
|
+
...u?.columnVisibility,
|
|
73
|
+
[W]: !1
|
|
70
74
|
},
|
|
71
75
|
...D && { columnOrder: D },
|
|
72
|
-
...
|
|
73
|
-
...i &&
|
|
76
|
+
...u,
|
|
77
|
+
...i && s.length > 0 && { columnOrder: s },
|
|
74
78
|
...n.order && { columnOrder: n.order },
|
|
75
79
|
...n.visibility && { columnVisibility: n.visibility },
|
|
76
|
-
...
|
|
77
|
-
...
|
|
80
|
+
...V && { columnSizing: V },
|
|
81
|
+
...M !== void 0 && { sorting: M }
|
|
78
82
|
},
|
|
79
|
-
enableRowSelection:
|
|
80
|
-
getCoreRowModel:
|
|
81
|
-
getExpandedRowModel:
|
|
82
|
-
getFilteredRowModel:
|
|
83
|
-
getSortedRowModel:
|
|
84
|
-
getPaginationRowModel:
|
|
85
|
-
getRowId: t.getRowId ?? ((o,
|
|
86
|
-
defaultColumn:
|
|
83
|
+
enableRowSelection: Y,
|
|
84
|
+
getCoreRowModel: Ve(),
|
|
85
|
+
getExpandedRowModel: Me(),
|
|
86
|
+
getFilteredRowModel: Ie(),
|
|
87
|
+
getSortedRowModel: Fe(),
|
|
88
|
+
getPaginationRowModel: Le(),
|
|
89
|
+
getRowId: t.getRowId ?? ((o, U, f) => f ? [f.id, o.id].join(".") : o.id.toString()),
|
|
90
|
+
defaultColumn: X,
|
|
87
91
|
...t,
|
|
88
|
-
enableColumnResizing:
|
|
92
|
+
enableColumnResizing: O,
|
|
89
93
|
sortingFns: {
|
|
90
|
-
[
|
|
94
|
+
[Re]: Q,
|
|
91
95
|
...t.sortingFns
|
|
92
96
|
}
|
|
93
97
|
});
|
|
94
|
-
|
|
95
|
-
const
|
|
98
|
+
x.current = e;
|
|
99
|
+
const y = e.options.meta?.locale, h = p(y);
|
|
96
100
|
C(() => {
|
|
97
|
-
|
|
98
|
-
}, [
|
|
101
|
+
h.current !== y && (h.current = y, e.getState().sorting.length > 0 && e.setSorting((o) => [...o]));
|
|
102
|
+
}, [y, e]), F && (F.current = e), ie(e, i ? void 0 : m), Ce(e, {
|
|
99
103
|
saved: n,
|
|
100
|
-
reconciling:
|
|
104
|
+
reconciling: ye(e, {
|
|
101
105
|
enabled: i,
|
|
102
106
|
definitionIds: _,
|
|
103
|
-
defaultOrder:
|
|
104
|
-
defaultVisibility:
|
|
107
|
+
defaultOrder: s,
|
|
108
|
+
defaultVisibility: c,
|
|
105
109
|
controlledVisibility: t.state?.columnVisibility !== void 0
|
|
106
110
|
}),
|
|
107
|
-
defaultOrder:
|
|
108
|
-
defaultVisibility:
|
|
111
|
+
defaultOrder: s,
|
|
112
|
+
defaultVisibility: c,
|
|
109
113
|
controlledVisibility: t.state?.columnVisibility !== void 0
|
|
110
114
|
}), C(() => {
|
|
111
|
-
}, [i, t.state?.columnVisibility !== void 0 || t.onColumnVisibilityChange !== void 0]),
|
|
115
|
+
}, [i, t.state?.columnVisibility !== void 0 || t.onColumnVisibilityChange !== void 0]), G({
|
|
112
116
|
storageKey: S,
|
|
113
117
|
state: e.getState().sorting,
|
|
114
|
-
defaultValue:
|
|
115
|
-
saved:
|
|
116
|
-
controlled:
|
|
117
|
-
toSignature:
|
|
118
|
-
toStorage:
|
|
118
|
+
defaultValue: P,
|
|
119
|
+
saved: M,
|
|
120
|
+
controlled: E,
|
|
121
|
+
toSignature: fe,
|
|
122
|
+
toStorage: Se,
|
|
119
123
|
applyState: (o) => e.setSorting(o)
|
|
120
|
-
}),
|
|
121
|
-
storageKey:
|
|
124
|
+
}), G({
|
|
125
|
+
storageKey: T,
|
|
122
126
|
state: e.getState().columnSizing,
|
|
123
|
-
defaultValue:
|
|
124
|
-
saved:
|
|
127
|
+
defaultValue: R,
|
|
128
|
+
saved: V,
|
|
125
129
|
settled: !e.getState().columnSizingInfo.isResizingColumn,
|
|
126
|
-
toSignature:
|
|
127
|
-
toStorage:
|
|
130
|
+
toSignature: se,
|
|
131
|
+
toStorage: ue,
|
|
128
132
|
applyState: (o) => e.setColumnSizing(o)
|
|
129
133
|
}), e.columnLayoutDefaults = i ? {
|
|
130
|
-
order:
|
|
131
|
-
visibility:
|
|
134
|
+
order: s,
|
|
135
|
+
visibility: c
|
|
132
136
|
} : void 0, e.resetColumnSettings = () => {
|
|
133
|
-
e.setColumnOrder(i ?
|
|
137
|
+
e.setColumnOrder(i ? s : []), e.setColumnSizing(R), i && e.setColumnVisibility(c), S && e.setSorting(P);
|
|
134
138
|
const o = i && n.orderKey !== void 0 ? [
|
|
135
139
|
n.orderKey,
|
|
136
140
|
n.visibilityKey,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
] : [],
|
|
140
|
-
for (const
|
|
141
|
+
m,
|
|
142
|
+
w
|
|
143
|
+
] : [], U = i ? void 0 : m;
|
|
144
|
+
for (const f of [
|
|
141
145
|
S,
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
T,
|
|
147
|
+
U,
|
|
144
148
|
...o
|
|
145
|
-
])
|
|
149
|
+
]) f && H.remove(f);
|
|
146
150
|
};
|
|
147
|
-
const
|
|
151
|
+
const g = re(r), a = e.getState().pagination?.pageSize, I = p(void 0), L = p(void 0);
|
|
148
152
|
return C(() => {
|
|
149
|
-
|
|
153
|
+
I.current = void 0, e.getState().pagination?.pageSize !== d && (e.setPageIndex(0), e.setPageSize(d));
|
|
150
154
|
}, [
|
|
151
|
-
u,
|
|
152
155
|
d,
|
|
156
|
+
g,
|
|
153
157
|
e
|
|
154
158
|
]), C(() => {
|
|
155
|
-
if (!(!
|
|
156
|
-
if (
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
+
if (!(!g || a == null)) {
|
|
160
|
+
if (I.current !== g) {
|
|
161
|
+
if (a !== d) return;
|
|
162
|
+
I.current = g, L.current = a;
|
|
163
|
+
return;
|
|
159
164
|
}
|
|
160
|
-
|
|
165
|
+
a !== L.current && (L.current = a, H.set(g, JSON.stringify(a)));
|
|
161
166
|
}
|
|
162
167
|
}, [
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
a,
|
|
169
|
+
d,
|
|
170
|
+
g
|
|
166
171
|
]), { table: e };
|
|
167
172
|
};
|
|
168
173
|
export {
|
|
169
|
-
|
|
174
|
+
et as useStyledTable
|
|
170
175
|
};
|