asma-ui-core 3.122.0 → 3.123.1

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.
Files changed (42) hide show
  1. package/dist/asma-ui-core.css +1 -1
  2. package/dist/components/custom/pathfinder-card/PathfinderCard.js +16 -16
  3. package/dist/index.js +66 -63
  4. package/dist/src/table/components/table-header/SortIndicator.d.ts +12 -0
  5. package/dist/src/table/custom-features/order-columns/columnLayout.d.ts +24 -0
  6. package/dist/src/table/custom-features/order-columns/columnLayout.test.d.ts +1 -0
  7. package/dist/src/table/custom-features/order-columns/types.d.ts +8 -0
  8. package/dist/src/table/custom-features/order-columns/usePersistColumnOrder.d.ts +5 -0
  9. package/dist/src/table/helpers/columnIds.d.ts +27 -0
  10. package/dist/src/table/helpers/columnIds.test.d.ts +1 -0
  11. package/dist/src/table/helpers/tableStorage.d.ts +12 -0
  12. package/dist/src/table/helpers/tableStorage.test.d.ts +1 -0
  13. package/dist/src/table/hooks/useColumnSizingPersistence.d.ts +16 -3
  14. package/dist/src/table/hooks/useColumnSizingPersistence.test.d.ts +1 -0
  15. package/dist/src/table/hooks/usePersistedSorting.d.ts +54 -0
  16. package/dist/src/table/hooks/usePersistedSorting.test.d.ts +1 -0
  17. package/dist/src/table/hooks/usePersistedStateWriter.d.ts +30 -0
  18. package/dist/src/table/hooks/useTranslations.d.ts +6 -4
  19. package/dist/src/table/index.d.ts +1 -0
  20. package/dist/src/table/types.d.ts +9 -2
  21. package/dist/table/components/StyledTable.module.js +59 -56
  22. package/dist/table/components/columns/action-column/components/HeaderActionMenu.js +61 -54
  23. package/dist/table/components/columns/action-column/components/TableActions.module.js +4 -4
  24. package/dist/table/components/table-header/SortIndicator.js +23 -0
  25. package/dist/table/components/table-header/TableHeader.js +30 -30
  26. package/dist/table/components/table-header/TableHeaderCell.js +30 -31
  27. package/dist/table/custom-features/order-columns/OrderColumnsFeature.js +7 -8
  28. package/dist/table/custom-features/order-columns/columnLayout.js +9 -0
  29. package/dist/table/custom-features/order-columns/usePersistColumnOrder.js +12 -11
  30. package/dist/table/custom-features/order-columns/usePersistedColumnOrder.js +7 -12
  31. package/dist/table/helpers/columnIds.js +28 -0
  32. package/dist/table/helpers/tableStorage.js +33 -0
  33. package/dist/table/hooks/useColumnSizingPersistence.js +16 -34
  34. package/dist/table/hooks/usePersistedPageSize.js +11 -16
  35. package/dist/table/hooks/usePersistedSorting.js +58 -0
  36. package/dist/table/hooks/usePersistedStateWriter.js +36 -0
  37. package/dist/table/hooks/useStyledTable.js +90 -60
  38. package/dist/table/hooks/useTranslations.js +13 -11
  39. package/dist/table/index.js +3 -2
  40. package/dist/table/shared-components/DropDownIcon.js +4 -2
  41. package/dist/table/shared-components/DropUpIcon.js +5 -3
  42. package/package.json +1 -1
@@ -1,58 +1,57 @@
1
- import { ACTIONS_COLUMN_ID as C, INTERNAL_COLUMN_IDS as S } from "../../types.js";
2
- import { useRootContext as G } from "../../context/RootContext.js";
1
+ import { ACTIONS_COLUMN_ID as C, INTERNAL_COLUMN_IDS as R } from "../../types.js";
2
+ import { useRootContext as A } from "../../context/RootContext.js";
3
3
  import n from "../StyledTable.module.js";
4
- import { DropUpIcon as A } from "../../shared-components/DropUpIcon.js";
5
- import { DropDownIcon as L } from "../../shared-components/DropDownIcon.js";
6
- import { getTableHeaderStyle as w } from "../../helpers/getTableHeaderStyle.js";
7
- import D from "clsx";
8
- import { useMemo as i } from "react";
9
- import { jsx as l, jsxs as F } from "react/jsx-runtime";
4
+ import { SortIndicator as F } from "./SortIndicator.js";
5
+ import { getTableHeaderStyle as L } from "../../helpers/getTableHeaderStyle.js";
6
+ import _ from "clsx";
7
+ import { useMemo as c } from "react";
8
+ import { jsx as l, jsxs as w } from "react/jsx-runtime";
10
9
  import { flexRender as M } from "@tanstack/react-table";
11
- function Q({ styledTableProps: R, header: o, tableCanResize: _ = !1, left: N, right: b, tableWidth: z }) {
12
- const { hideHeader: c = !1, enableResizing: r = !1, actions: I, customActionsNode: H } = R, { isResizing: a, enableResizingFlag: m, disableResizingFlag: u } = G(), d = o.column.columnDef.fixedLeft, g = !!o.column.columnDef.fixedRight, f = o.column.id === C, T = !!I || !!H, p = i(() => o.headerGroup.headers.some((e) => e.id === C), [o.headerGroup.headers]), h = i(() => o.headerGroup.headers.some((e) => !!e.column.columnDef.fixedRight), [o.headerGroup.headers]), v = i(() => o.headerGroup.headers[o.headerGroup.headers.length - (p ? 2 : 1)], [o.headerGroup.headers, p]), t = o.column.getCanSort(), x = o.column.getIsSorted(), y = t ? x === "asc" ? "ascending" : x === "desc" ? "descending" : "none" : void 0;
10
+ function J({ styledTableProps: z, header: o, tableCanResize: D = !1, left: b, right: N, tableWidth: h }) {
11
+ const { hideHeader: r = !1, enableResizing: a = !1, actions: H, customActionsNode: I } = z, { isResizing: m, enableResizingFlag: u, disableResizingFlag: d } = A(), g = o.column.columnDef.fixedLeft, f = !!o.column.columnDef.fixedRight, p = o.column.id === C, T = !!H || !!I, x = c(() => o.headerGroup.headers.some((e) => e.id === C), [o.headerGroup.headers]), v = c(() => o.headerGroup.headers.some((e) => !!e.column.columnDef.fixedRight), [o.headerGroup.headers]), y = c(() => o.headerGroup.headers[o.headerGroup.headers.length - (x ? 2 : 1)], [o.headerGroup.headers, x]), t = o.column.getCanSort(), s = o.column.getIsSorted(), G = t ? s === "asc" ? "ascending" : s === "desc" ? "descending" : "none" : void 0, S = D && (a ? !0 : o.id !== y?.id) && o.column.getCanResize() && !R.includes(o.column.id);
13
12
  return /* @__PURE__ */ l("th", {
14
13
  colSpan: o.colSpan,
15
- "aria-sort": y,
16
- className: D(n["t-cell"], !S.includes(o.column.id) && o.column.getSize() > 64 && n["data-cell"], o.column.id === "select" && n["select-cell"], c && n["hide-header"], f && n["t-cell__actions"], f && (!T || h) && n["t-cell__actions--no-shadow"], d && n["t-cell__fixed"], g && n["t-cell__fixed-right"]),
14
+ "aria-sort": G,
15
+ className: _(n["t-cell"], !R.includes(o.column.id) && o.column.getSize() > 64 && n["data-cell"], o.column.id === "select" && n["select-cell"], r && n["hide-header"], p && n["t-cell__actions"], p && (!T || v) && n["t-cell__actions--no-shadow"], g && n["t-cell__fixed"], f && n["t-cell__fixed-right"]),
17
16
  style: {
18
- ...w({
19
- enableResizing: r,
17
+ ...L({
18
+ enableResizing: a,
20
19
  header: o,
21
- tableWidth: z
20
+ tableWidth: h
22
21
  }),
23
- ...d && { left: N },
24
- ...g && { right: b }
22
+ ...g && { left: b },
23
+ ...f && { right: N }
25
24
  },
26
- children: /* @__PURE__ */ F("div", {
27
- className: D("flex items-center justify-start", c ? n["hide-table-header"] : n["show-table-header"], t && n["sortable-column"], o.column.columnDef.className),
25
+ children: /* @__PURE__ */ w("div", {
26
+ className: _("flex items-center justify-start", r ? n["hide-table-header"] : n["show-table-header"], t && n["sortable-column"], S && n["has-resize-zone"], o.column.columnDef.className),
28
27
  role: t ? "button" : void 0,
29
28
  tabIndex: t ? 0 : void 0,
30
29
  onClick: (e) => {
31
- const s = o.column.getToggleSortingHandler();
32
- !a && s && s(e), u();
30
+ const i = o.column.getToggleSortingHandler();
31
+ !m && i && i(e), d();
33
32
  },
34
33
  onKeyDown: t ? (e) => {
35
34
  if (e.key !== "Enter" && e.key !== " ") return;
36
35
  e.preventDefault();
37
- const s = o.column.getToggleSortingHandler();
38
- !a && s && s(e), u();
36
+ const i = o.column.getToggleSortingHandler();
37
+ !m && i && i(e), d();
39
38
  } : void 0,
40
39
  children: [
41
40
  /* @__PURE__ */ l("div", {
42
41
  className: n["header-content"],
43
42
  children: M(o.column.columnDef.header, o.getContext())
44
43
  }),
45
- {
46
- asc: /* @__PURE__ */ l(A, { className: n["sort-icon"] }),
47
- desc: /* @__PURE__ */ l(L, { className: n["sort-icon"] })
48
- }[o.column.getIsSorted()] ?? null,
49
- _ && (r ? !0 : o.id !== v?.id) && o.column.getCanResize() && !S.includes(o.column.id) && /* @__PURE__ */ l("div", {
44
+ t && /* @__PURE__ */ l(F, {
45
+ sorted: s,
46
+ nextDirection: s || o.column.getFirstSortDir()
47
+ }),
48
+ S && /* @__PURE__ */ l("div", {
50
49
  onDoubleClick: () => o.column.resetSize(),
51
50
  onMouseDown: (e) => {
52
- e.stopPropagation(), m(), o.getResizeHandler()(e);
51
+ e.stopPropagation(), u(), o.getResizeHandler()(e);
53
52
  },
54
53
  onTouchStart: (e) => {
55
- e.stopPropagation(), m(), o.getResizeHandler()(e);
54
+ e.stopPropagation(), u(), o.getResizeHandler()(e);
56
55
  },
57
56
  className: `${n.resizer} ${o.column.getIsResizing() ? n.isResizing : ""}`
58
57
  })
@@ -61,5 +60,5 @@ function Q({ styledTableProps: R, header: o, tableCanResize: _ = !1, left: N, ri
61
60
  }, o.id);
62
61
  }
63
62
  export {
64
- Q as TableHeaderCell
63
+ J as TableHeaderCell
65
64
  };
@@ -1,20 +1,19 @@
1
- import { functionalUpdate as u, makeStateUpdater as d } from "@tanstack/react-table";
2
- var a = {
1
+ import { functionalUpdate as o, makeStateUpdater as u } from "@tanstack/react-table";
2
+ var d = {
3
3
  getInitialState: (r) => ({
4
4
  ...r,
5
5
  columnOrder: r?.columnOrder ?? []
6
6
  }),
7
- getDefaultOptions: (r) => ({ onColumnOrderChange: d("columnOrder", r) }),
7
+ getDefaultOptions: (r) => ({ onColumnOrderChange: u("columnOrder", r) }),
8
8
  createTable: (r) => {
9
- const n = r.getAllLeafColumns().map((e) => e.id);
10
9
  r.setColumnOrder = (e) => {
11
- const o = (t) => u(e, t);
12
- return r.options.onColumnOrderChange?.(o);
10
+ const n = (t) => o(e, t);
11
+ return r.options.onColumnOrderChange?.(n);
13
12
  }, r.resetColumnOrder = () => {
14
- r.setColumnOrder(n);
13
+ r.setColumnOrder([]);
15
14
  };
16
15
  }
17
16
  };
18
17
  export {
19
- a as OrderColumnsFeature
18
+ d as OrderColumnsFeature
20
19
  };
@@ -0,0 +1,9 @@
1
+ import { INTERNAL_COLUMN_IDS as l } from "../../types.js";
2
+ var s = (e) => e.flatMap((r) => r.columns.length ? s(r.columns) : [r.id]), a = (e) => s(e.getAllColumns()), i = (e) => e.getAllLeafColumns().map((r) => r.id), o = (e, r) => e.length === r.length && e.every((n, d) => n === r[d]), f = (e) => o(i(e), a(e)), t = (e) => !l.includes(e.id) && !!e.columnDef.header, m = (e) => {
3
+ const r = new Set(e.getAllLeafColumns().filter(t).map((n) => n.id));
4
+ return !o(i(e).filter((n) => r.has(n)), a(e).filter((n) => r.has(n)));
5
+ }, u = (e) => e.getAllLeafColumns().some((r) => r.getCanHide() && !r.getIsVisible() && !l.includes(r.id)), v = (e) => u(e) || m(e);
6
+ export {
7
+ v as hasChangedColumnLayout,
8
+ f as isDefaultColumnOrder
9
+ };
@@ -1,15 +1,16 @@
1
- import { useEffect as c } from "react";
2
- function s(e, r) {
3
- const t = e.getState().columnOrder;
4
- c(() => {
5
- if (!(!r || !t))
6
- try {
7
- localStorage.setItem(r, JSON.stringify(t));
8
- } catch (o) {
9
- console.error(o);
10
- }
1
+ import { tableStorage as u } from "../../helpers/tableStorage.js";
2
+ import { isDefaultColumnOrder as i } from "./columnLayout.js";
3
+ import { useEffect as m, useRef as f } from "react";
4
+ function d(n, r) {
5
+ const o = n.getState().columnOrder, t = JSON.stringify(o ?? []), c = !o?.length || i(n), s = f(r), e = f(t);
6
+ m(() => {
7
+ if (s.current !== r) {
8
+ s.current = r, e.current = t;
9
+ return;
10
+ }
11
+ !r || t === e.current || (e.current = t, c ? u.remove(r) : u.set(r, t));
11
12
  }, [t, r]);
12
13
  }
13
14
  export {
14
- s as usePersistColumnOrder
15
+ d as usePersistColumnOrder
15
16
  };
@@ -1,15 +1,10 @@
1
- import { useMemo as o } from "react";
2
- var i = (r) => o(() => {
3
- if (r)
4
- try {
5
- const t = localStorage.getItem(r);
6
- if (!t) return;
7
- const e = JSON.parse(t);
8
- return Array.isArray(e) ? e : void 0;
9
- } catch {
10
- return;
11
- }
1
+ import { readJson as e } from "../../helpers/tableStorage.js";
2
+ import { useMemo as i } from "react";
3
+ var n = (r) => i(() => {
4
+ if (!r) return;
5
+ const o = e(r);
6
+ return Array.isArray(o) ? o.filter((t) => typeof t == "string") : void 0;
12
7
  }, [r]);
13
8
  export {
14
- i as usePersistedColumnOrder
9
+ n as usePersistedColumnOrder
15
10
  };
@@ -0,0 +1,28 @@
1
+ var i = (e) => {
2
+ const o = e.id ?? (typeof e.accessorKey == "string" && e.accessorKey ? e.accessorKey.replaceAll(".", "_") : void 0) ?? (typeof e.header == "string" ? e.header : void 0);
3
+ return o === void 0 || o === "" ? void 0 : o;
4
+ }, u = (e, o = {}) => {
5
+ const t = [], s = (l) => {
6
+ for (const r of l) {
7
+ if (r.columns?.length) {
8
+ s(r.columns);
9
+ continue;
10
+ }
11
+ const n = {
12
+ ...o.defaultColumn,
13
+ ...r
14
+ }, c = i(n);
15
+ if (c === void 0) continue;
16
+ const a = !!n.accessorFn || !!n.accessorKey;
17
+ t.push({
18
+ id: c,
19
+ canSort: (n.enableSorting ?? !0) && (o.enableSorting ?? !0) && a,
20
+ canMultiSort: n.enableMultiSort ?? o.enableMultiSort ?? a
21
+ });
22
+ }
23
+ };
24
+ return s(e), t;
25
+ };
26
+ export {
27
+ u as getLeafColumnInfos
28
+ };
@@ -0,0 +1,33 @@
1
+ var e = {
2
+ get(t) {
3
+ try {
4
+ return localStorage.getItem(t);
5
+ } catch {
6
+ return null;
7
+ }
8
+ },
9
+ set(t, r) {
10
+ try {
11
+ localStorage.setItem(t, r);
12
+ } catch {
13
+ }
14
+ },
15
+ remove(t) {
16
+ try {
17
+ localStorage.removeItem(t);
18
+ } catch {
19
+ }
20
+ }
21
+ }, a = (t) => {
22
+ const r = e.get(t);
23
+ if (r)
24
+ try {
25
+ return JSON.parse(r);
26
+ } catch {
27
+ return;
28
+ }
29
+ };
30
+ export {
31
+ a as readJson,
32
+ e as tableStorage
33
+ };
@@ -1,36 +1,18 @@
1
- import { useEffect as s, useMemo as c } from "react";
2
- var a = ":column-sizing", g = (t) => {
3
- if (t)
4
- try {
5
- const r = JSON.parse(t);
6
- return !r || typeof r != "object" || Array.isArray(r) ? void 0 : Object.fromEntries(Object.entries(r).filter((e) => typeof e[1] == "number" && Number.isFinite(e[1]) && e[1] > 0));
7
- } catch {
8
- return;
9
- }
10
- }, o = (t) => t ? `${t}${a}` : void 0, m = (t) => c(() => {
11
- const r = o(t);
12
- if (!(!r || !t))
13
- try {
14
- return g(localStorage.getItem(r));
15
- } catch {
16
- return;
17
- }
18
- }, [t]), S = (t, r) => {
19
- const e = o(r), i = t.getState().columnSizing, n = !!t.getState().columnSizingInfo.isResizingColumn;
20
- s(() => {
21
- if (!(!e || n))
22
- try {
23
- localStorage.setItem(e, JSON.stringify(i));
24
- } catch {
25
- return;
26
- }
27
- }, [
28
- i,
29
- n,
30
- e
31
- ]);
32
- };
1
+ import { readJson as n } from "../helpers/tableStorage.js";
2
+ import { useMemo as t } from "react";
3
+ var s = ":column-sizing", m = (i) => i ? `${i}${s}` : void 0, a = (i) => {
4
+ if (!(typeof i != "object" || i === null || Array.isArray(i)))
5
+ return Object.fromEntries(Object.entries(i).filter((r) => typeof r[1] == "number" && Number.isFinite(r[1]) && r[1] > 0));
6
+ }, S = (i, r) => t(() => {
7
+ const e = m(i), o = e ? a(n(e)) : void 0;
8
+ return o && {
9
+ ...r,
10
+ ...o
11
+ };
12
+ }, [i]), v = (i) => JSON.stringify(Object.entries(i).sort(([r], [e]) => r < e ? -1 : r > e ? 1 : 0)), l = (i) => JSON.stringify(i);
33
13
  export {
34
- S as usePersistColumnSizing,
35
- m as usePersistedColumnSizing
14
+ v as columnSizingSignature,
15
+ m as getColumnSizingStorageKey,
16
+ l as serializeColumnSizing,
17
+ S as usePersistedColumnSizing
36
18
  };
@@ -1,20 +1,15 @@
1
- import { useMemo as a } from "react";
2
- var i = ":page-size", s = (e) => {
1
+ import { readJson as o } from "../helpers/tableStorage.js";
2
+ import { useMemo as i } from "react";
3
+ var s = ":page-size", a = (e) => {
3
4
  if (e)
4
- return `${e}${i}`;
5
- }, n = (e) => a(() => {
6
- const t = s(e);
7
- if (t)
8
- try {
9
- const o = localStorage.getItem(t);
10
- if (!o) return;
11
- const r = JSON.parse(o);
12
- return typeof r == "number" && Number.isInteger(r) && r > 0 ? r : void 0;
13
- } catch {
14
- return;
15
- }
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;
16
11
  }, [e]);
17
12
  export {
18
- s as getPersistedPageSizeKey,
19
- n as usePersistedPageSize
13
+ a as getPersistedPageSizeKey,
14
+ d as usePersistedPageSize
20
15
  };
@@ -0,0 +1,58 @@
1
+ import { readJson as l } from "../helpers/tableStorage.js";
2
+ import { useCallback as f, useState as m } from "react";
3
+ import { functionalUpdate as v } from "@tanstack/react-table";
4
+ var p = ":sorting", S = 1, u = [], y = (t) => t ? `${t}${p}` : void 0, d = (t) => typeof t == "object" && t !== null && !Array.isArray(t), O = (t, r) => {
5
+ if (!d(t) || t.v !== S || !Array.isArray(t.sorting)) return;
6
+ const o = t.sorting;
7
+ if (o.length === 0) return [];
8
+ const s = new Map(r.sortableColumns.map((n) => [n.id, n])), a = /* @__PURE__ */ new Set(), e = [];
9
+ for (const n of o) {
10
+ if (!d(n) || typeof n.id != "string" || typeof n.desc != "boolean") continue;
11
+ const g = s.get(n.id);
12
+ !g || a.has(n.id) || e.length > 0 && (r.enableMultiSort === !1 || !g.canMultiSort) || (a.add(n.id), e.push({
13
+ id: n.id,
14
+ desc: n.desc
15
+ }));
16
+ }
17
+ const i = r.maxMultiSortColCount, c = i !== void 0 && Number.isFinite(i) && i >= 1 ? e.slice(0, Math.floor(i)) : e;
18
+ return c.length > 0 ? c : void 0;
19
+ }, R = (t) => JSON.stringify({
20
+ v: S,
21
+ sorting: t.map(({ id: r, desc: o }) => ({
22
+ id: r,
23
+ desc: o
24
+ }))
25
+ }), A = (t) => JSON.stringify(t.map(({ id: r, desc: o }) => [r, o])), N = (t, r) => {
26
+ const o = y(t);
27
+ return o ? O(l(o), r) : void 0;
28
+ }, b = ({ sortableColumnIds: t, enableMultiSort: r, maxMultiSortColCount: o }) => ({
29
+ sortableColumns: t.map((s) => ({
30
+ id: s,
31
+ canMultiSort: !0
32
+ })),
33
+ enableMultiSort: r,
34
+ maxMultiSortColCount: o
35
+ }), h = (t, r) => N(t, b(r)), I = ({ uniqueKey: t, defaultSorting: r = u, ...o }) => {
36
+ const s = () => ({
37
+ key: t,
38
+ sorting: h(t, o) ?? r
39
+ }), [a, e] = m(s);
40
+ let i = a;
41
+ a.key !== t && (i = s(), e(i));
42
+ const c = f((n) => e((g) => ({
43
+ ...g,
44
+ sorting: v(n, g.sorting)
45
+ })), []);
46
+ return {
47
+ sorting: i.sorting,
48
+ onSortingChange: c
49
+ };
50
+ };
51
+ export {
52
+ y as getSortingStorageKey,
53
+ h as readPersistedSorting,
54
+ N as readSortingFromStorage,
55
+ R as serializeSorting,
56
+ A as sortingSignature,
57
+ I as usePersistedSorting
58
+ };
@@ -0,0 +1,36 @@
1
+ import { tableStorage as y } from "../helpers/tableStorage.js";
2
+ import { useEffect as b, useLayoutEffect as v, useRef as s } from "react";
3
+ var K = (a) => {
4
+ const { storageKey: t, state: l, defaultValue: c, saved: p, settled: f = !0, controlled: i = !1 } = a, { toSignature: o, toStorage: R, applyState: d } = a, e = o(l), g = o(c), S = s(t), u = s(e), n = s(null);
5
+ v(() => {
6
+ if (S.current === t) return;
7
+ if (S.current = t, n.current = null, u.current = e, !t) {
8
+ !i && e !== g && d(c);
9
+ return;
10
+ }
11
+ const r = p ?? c, m = o(r);
12
+ n.current = {
13
+ stale: e,
14
+ loaded: m
15
+ }, !i && m !== e && d(r);
16
+ }, [t]), b(() => {
17
+ if (!t || !f) return;
18
+ const r = n.current;
19
+ if (r) {
20
+ if (e === r.loaded) {
21
+ n.current = null, u.current = e;
22
+ return;
23
+ }
24
+ if (e === r.stale) return;
25
+ n.current = null;
26
+ }
27
+ e !== u.current && (u.current = e, e === g ? y.remove(t) : y.set(t, R(l)));
28
+ }, [
29
+ e,
30
+ t,
31
+ f
32
+ ]);
33
+ };
34
+ export {
35
+ K as usePersistedStateWriter
36
+ };
@@ -1,80 +1,110 @@
1
- import { SELECT_COLUMN_ID as y } from "../types.js";
2
- import { ExpandedRowsFeature as E } from "../custom-features/expand-rows/ExpandRowsFeature.js";
3
- import { FocusedRowsFeature as I } from "../custom-features/focus-rows/FocusRowsFeature.js";
4
- import { OrderColumnsFeature as b } from "../custom-features/order-columns/OrderColumnsFeature.js";
5
- import { usePersistColumnOrder as F } from "../custom-features/order-columns/usePersistColumnOrder.js";
6
- import { usePersistedColumnOrder as O } from "../custom-features/order-columns/usePersistedColumnOrder.js";
7
- import { getPersistedPageSizeKey as _, usePersistedPageSize as x } from "./usePersistedPageSize.js";
8
- import { usePersistColumnSizing as v, usePersistedColumnSizing as K } from "./useColumnSizingPersistence.js";
9
- import { RowSelectionTooltipFeature as L } from "../custom-features/row-selection-tooltip/RowSelectionTooltipFeature.js";
10
- import { useEffect as p, useRef as T } from "react";
11
- import { getCoreRowModel as N, getExpandedRowModel as U, getFilteredRowModel as h, getPaginationRowModel as A, getSortedRowModel as D, useReactTable as V } from "@tanstack/react-table";
12
- var Z = 100, ee = (n) => {
13
- const { columns: z, data: C, initialState: a, pageSize: w, enableRowSelection: M, tableInstanceRef: d, locale: P, persistColumnOrderKey: u, uniqueKey: l, defaultColumn: g, ...m } = n, S = O(u), c = n.enableColumnResizing ? l : void 0, f = K(c), t = x(l) ?? w ?? 50, e = V({
1
+ import { SELECT_COLUMN_ID as N } from "../types.js";
2
+ import { ExpandedRowsFeature as L } from "../custom-features/expand-rows/ExpandRowsFeature.js";
3
+ import { FocusedRowsFeature as T } from "../custom-features/focus-rows/FocusRowsFeature.js";
4
+ import { OrderColumnsFeature as U } from "../custom-features/order-columns/OrderColumnsFeature.js";
5
+ import { tableStorage as w } from "../helpers/tableStorage.js";
6
+ import { usePersistColumnOrder as V } from "../custom-features/order-columns/usePersistColumnOrder.js";
7
+ import { usePersistedColumnOrder as D } from "../custom-features/order-columns/usePersistedColumnOrder.js";
8
+ import { getPersistedPageSizeKey as Z, usePersistedPageSize as A } from "./usePersistedPageSize.js";
9
+ import { columnSizingSignature as G, getColumnSizingStorageKey as h, serializeColumnSizing as j, usePersistedColumnSizing as q } from "./useColumnSizingPersistence.js";
10
+ import { getSortingStorageKey as B, readSortingFromStorage as J, serializeSorting as W, sortingSignature as k } from "./usePersistedSorting.js";
11
+ import { usePersistedStateWriter as I } from "./usePersistedStateWriter.js";
12
+ import { RowSelectionTooltipFeature as H } from "../custom-features/row-selection-tooltip/RowSelectionTooltipFeature.js";
13
+ import { getLeafColumnInfos as Q } from "../helpers/columnIds.js";
14
+ import { useEffect as K, useMemo as X, useRef as Y } from "react";
15
+ import { getCoreRowModel as $, getExpandedRowModel as ee, getFilteredRowModel as te, getPaginationRowModel as oe, getSortedRowModel as ie, useReactTable as ne } from "@tanstack/react-table";
16
+ var re = 100, ae = [], le = {}, we = (g) => {
17
+ const { columns: c, data: O, initialState: l, pageSize: P, enableRowSelection: _, tableInstanceRef: C, locale: E, persistColumnOrderKey: u, uniqueKey: r, persistSorting: x, defaultColumn: p, ...o } = g, z = l?.sorting ?? ae, S = l?.columnSizing ?? le, R = g.enableColumnResizing ? {
18
+ minSize: re,
19
+ ...p
20
+ } : p, F = Q(c, {
21
+ defaultColumn: R,
22
+ enableSorting: o.enableSorting,
23
+ enableMultiSort: o.enableMultiSort
24
+ }), y = D(u), M = g.enableColumnResizing ? r : void 0, v = h(M), m = q(M, S), a = x ? B(r) : void 0, d = X(() => a ? J(r, {
25
+ sortableColumns: F.filter((t) => t.canSort),
26
+ maxMultiSortColCount: o.maxMultiSortColCount
27
+ }) : void 0, [a]), i = A(r) ?? P ?? 50, e = ne({
14
28
  _features: [
15
- E,
16
- I,
17
- b,
18
- L
29
+ L,
30
+ T,
31
+ U,
32
+ H
19
33
  ],
20
- columns: z,
21
- data: C,
22
- meta: { locale: P ?? "en" },
34
+ columns: c,
35
+ data: O,
36
+ meta: { locale: E ?? "en" },
23
37
  initialState: {
24
38
  pagination: {
25
39
  pageIndex: 0,
26
- pageSize: t
40
+ pageSize: i
27
41
  },
28
42
  columnVisibility: {
29
- ...a?.columnVisibility,
30
- [y]: !1
43
+ ...l?.columnVisibility,
44
+ [N]: !1
31
45
  },
32
- ...S && { columnOrder: S },
33
- ...a,
34
- ...f && { columnSizing: {
35
- ...a?.columnSizing,
36
- ...f
37
- } }
46
+ ...y && { columnOrder: y },
47
+ ...l,
48
+ ...m && { columnSizing: m },
49
+ ...d !== void 0 && { sorting: d }
38
50
  },
39
- enableRowSelection: M,
40
- getCoreRowModel: N(),
41
- getExpandedRowModel: U(),
42
- getFilteredRowModel: h(),
43
- getSortedRowModel: D(),
44
- getPaginationRowModel: A(),
45
- getRowId: m.getRowId ?? ((r, j, R) => R ? [R.id, r.id].join(".") : r.id.toString()),
46
- defaultColumn: n.enableColumnResizing ? {
47
- minSize: Z,
48
- ...g
49
- } : g,
50
- ...m
51
+ enableRowSelection: _,
52
+ getCoreRowModel: $(),
53
+ getExpandedRowModel: ee(),
54
+ getFilteredRowModel: te(),
55
+ getSortedRowModel: ie(),
56
+ getPaginationRowModel: oe(),
57
+ getRowId: o.getRowId ?? ((t, se, b) => b ? [b.id, t.id].join(".") : t.id.toString()),
58
+ defaultColumn: R,
59
+ ...o
51
60
  });
52
- d && (d.current = e), F(e, u), v(e, c);
53
- const o = _(l), i = e.getState().pagination?.pageSize, s = T(void 0);
54
- return p(() => {
55
- s.current = void 0, e.getState().pagination?.pageSize !== t && (e.setPageIndex(0), e.setPageSize(t));
61
+ C && (C.current = e), V(e, u), I({
62
+ storageKey: a,
63
+ state: e.getState().sorting,
64
+ defaultValue: z,
65
+ saved: d,
66
+ controlled: o.state?.sorting !== void 0,
67
+ toSignature: k,
68
+ toStorage: W,
69
+ applyState: (t) => e.setSorting(t)
70
+ }), I({
71
+ storageKey: v,
72
+ state: e.getState().columnSizing,
73
+ defaultValue: S,
74
+ saved: m,
75
+ settled: !e.getState().columnSizingInfo.isResizingColumn,
76
+ toSignature: G,
77
+ toStorage: j,
78
+ applyState: (t) => e.setColumnSizing(t)
79
+ }), e.resetColumnSettings = () => {
80
+ e.setColumnOrder([]), e.setColumnSizing(S), a && e.setSorting(z);
81
+ for (const t of [
82
+ a,
83
+ v,
84
+ u
85
+ ]) t && w.remove(t);
86
+ };
87
+ const n = Z(r), s = e.getState().pagination?.pageSize, f = Y(void 0);
88
+ return K(() => {
89
+ f.current = void 0, e.getState().pagination?.pageSize !== i && (e.setPageIndex(0), e.setPageSize(i));
56
90
  }, [
57
- t,
58
- o,
91
+ i,
92
+ n,
59
93
  e
60
- ]), p(() => {
61
- if (!(!o || i == null)) {
62
- if (s.current !== o) {
63
- if (i !== t) return;
64
- s.current = o;
65
- }
66
- try {
67
- localStorage.setItem(o, JSON.stringify(i));
68
- } catch (r) {
69
- console.error(r);
94
+ ]), K(() => {
95
+ if (!(!n || s == null)) {
96
+ if (f.current !== n) {
97
+ if (s !== i) return;
98
+ f.current = n;
70
99
  }
100
+ w.set(n, JSON.stringify(s));
71
101
  }
72
102
  }, [
103
+ s,
73
104
  i,
74
- t,
75
- o
105
+ n
76
106
  ]), { table: e };
77
107
  };
78
108
  export {
79
- ee as useStyledTable
109
+ we as useStyledTable
80
110
  };
@@ -1,25 +1,27 @@
1
- import { useMemo as r } from "react";
2
- var n = {
1
+ import { useMemo as o } from "react";
2
+ var e = {
3
3
  en: {
4
4
  column_reorder: "This column is fixed and can’t be reordered.",
5
5
  column_hidden: "This column is fixed and can’t be hidden.",
6
6
  column_reorder_and_hidden: "This column is fixed and can’t be reordered or hidden.",
7
- reset_order: "Reset order",
8
- column_order_reset: "Column order reset",
9
- column_settings: "Column settings"
7
+ reset_columns: "Reset columns",
8
+ columns_reset: "Columns reset",
9
+ column_settings: "Column settings",
10
+ column_settings_changed: "Column settings, changed"
10
11
  },
11
12
  no: {
12
13
  column_reorder: "Denne kolonnen er fast og kan ikke flyttes.",
13
14
  column_hidden: "Denne kolonnen er fast og kan ikke skjules.",
14
15
  column_reorder_and_hidden: "Denne kolonnen er fast og kan ikke flyttes eller skjules.",
15
- reset_order: "Tilbakestill rekkefølge",
16
- column_order_reset: "Kolonnerekkefølgen er tilbakestilt",
17
- column_settings: "Kolonneinnstillinger"
16
+ reset_columns: "Tilbakestill kolonner",
17
+ columns_reset: "Kolonnene er tilbakestilt",
18
+ column_settings: "Kolonneinnstillinger",
19
+ column_settings_changed: "Kolonneinnstillinger, endret"
18
20
  }
19
21
  };
20
- function s(e = "en") {
21
- return r(() => n[e] ?? n.en, [e]);
22
+ function l(n = "en") {
23
+ return o(() => e[n] ?? e.en, [n]);
22
24
  }
23
25
  export {
24
- s as useTranslations
26
+ l as useTranslations
25
27
  };