asma-ui-core 3.130.5 → 3.131.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,41 @@
1
+ import { ColumnDefLike } from './columnIds';
2
+ /** UX round 4 (D16): the room a sortable column's triangle needs, in px. */
3
+ export declare const SORTABLE_EXTRA_WIDTH = 20;
4
+ /** ui-core's own minimum width of a resizable column. It does not grow with D16. */
5
+ export declare const RESIZABLE_MIN_SIZE = 100;
6
+ /** The parts of a column definition that decide its default width. */
7
+ export interface SizableColumnDef extends ColumnDefLike {
8
+ size?: number;
9
+ minSize?: number;
10
+ maxSize?: number;
11
+ }
12
+ interface ColumnSizingDefaultsOptions {
13
+ /** The table's own `defaultColumn`, which each column definition is merged over. */
14
+ defaultColumn?: SizableColumnDef;
15
+ /** The table's `enableSorting`. */
16
+ enableSorting?: boolean;
17
+ /** Whether the table can resize its columns (D15): only then does a column get ui-core's minimum width. */
18
+ canResize: boolean;
19
+ }
20
+ /**
21
+ * Resolves the default `size`, `minSize` and `maxSize` of every leaf column before TanStack sees the definitions
22
+ * (ASMA-8597, UX round 4, P2e). It changes defaults only: a width the user saved, an app's `initialState.columnSizing`
23
+ * and a controlled `state.columnSizing` are applied on top by TanStack as given (DEC-D16).
24
+ *
25
+ * - **D16, +20 px for a sortable column.** A data column that can sort (the rule `getLeafColumnInfos` already uses, which is
26
+ * TanStack's `getCanSort()` for a leaf) gets `size` + 20, where `size` is its own, else the table's `defaultColumn.size`,
27
+ * else TanStack's 150. Its `minSize` and `maxSize` grow by 20 when the column or `defaultColumn` sets them. A sortable
28
+ * column that opts out of resizing grows too (DEC-D16-OPTOUTS): it keeps no handle, and a `minSize === maxSize` column
29
+ * stays fixed, at the new width. Columns that cannot sort, group headers and ui-core's own columns are left as they are.
30
+ * - **DEC-NARROW, the minimum of a resizable column.** A column that sets no `minSize` gets the smaller of 100 px and its
31
+ * default width (its `size` after D16) as its minimum, so turning resizing on never widens a column past its default
32
+ * width. A column with no `size` at all keeps the 100 px minimum. A column that sets its own `minSize` keeps it.
33
+ * ui-core's own columns keep the 100 px minimum they have always had.
34
+ */
35
+ export declare const resolveColumnSizingDefaults: <TDef extends SizableColumnDef>(columns: readonly TDef[], options: ColumnSizingDefaultsOptions) => TDef[];
36
+ /**
37
+ * Whether a column has a fixed width: it sets `maxSize` equal to `minSize`. Such a column has no resize handle (OQ-15,
38
+ * the apps' own decision), however resizing came to be on. Reads the resolved definition (`column.columnDef`).
39
+ */
40
+ export declare const hasFixedWidth: (columnDef: Pick<SizableColumnDef, "minSize" | "maxSize">) => boolean;
41
+ export {};
@@ -139,6 +139,22 @@ export type StyledTableProps<TData, TCustomData> = {
139
139
  * makes `uniqueKey` alone enough and retires this prop (follow-up ASMA-8698).
140
140
  */
141
141
  persistSorting?: boolean;
142
+ /**
143
+ * Whether the table's columns can be resized with the pointer. **On by default** (ASMA-8597, UX round 4, D15): every data
144
+ * column has a handle, except ui-core's own columns (select, expand, actions, drag handle, show full text), a column that
145
+ * opts out with `enableResizing: false` or has a fixed width (`minSize` equal to `maxSize`), and the last data column,
146
+ * which keeps filling the remaining width (unless the table sets `enableResizing`). `enableColumnResizing={false}` turns
147
+ * resizing off for the table.
148
+ *
149
+ * Saving the widths is a separate opt-in (D17): widths are read and written under `${uniqueKey}:column-sizing` only when
150
+ * a table sets `enableColumnResizing` itself, as `true`. A table that gets resizing from the default resizes in memory only.
151
+ * Give it a per-user `uniqueKey` (`getTableSettingsKey` of asma-core-helpers) and write `enableColumnResizing` to save.
152
+ *
153
+ * A column without a `minSize` gets the smaller of 100 px and its default width as its minimum. Every sortable data column
154
+ * is 20 px wider by default (so its sort triangle fits), and so are its `minSize` and `maxSize` when set; widths a user
155
+ * saved and the app's `initialState.columnSizing` are applied as given.
156
+ */
157
+ enableColumnResizing?: boolean;
142
158
  } & Omit<TTableOptions<TData>, 'getCoreRowModel' | 'getExpandedRowModel' | 'getFilteredRowModel' | 'getSortedRowModel'> & TFooter<TData>;
143
159
  export declare const SELECT_COLUMN_ID = "select";
144
160
  export declare const EXPAND_COLUMN_ID = "expand-column-id";
@@ -106,7 +106,7 @@ var Ve = (l) => {
106
106
  children: [/* @__PURE__ */ t(se, {
107
107
  table: a,
108
108
  styledTableProps: o,
109
- tableCanResize: !!o.enableColumnResizing,
109
+ tableCanResize: o.enableColumnResizing ?? !0,
110
110
  tableWidth: null,
111
111
  columnWindow: j
112
112
  }), /* @__PURE__ */ t(ie, {
@@ -1,26 +1,27 @@
1
1
  import { ACTIONS_COLUMN_ID as D, INTERNAL_COLUMN_IDS as R } from "../../types.js";
2
2
  import { useRootContext as L } from "../../context/RootContext.js";
3
+ import { hasFixedWidth as A } from "../../helpers/columnSizingDefaults.js";
3
4
  import e from "../StyledTable.module.js";
4
- import { SortIndicator as A } from "./SortIndicator.js";
5
- import { getTableHeaderStyle as O } from "../../helpers/getTableHeaderStyle.js";
6
- import { getSortPreview as E } from "../../helpers/sortPreview.js";
5
+ import { SortIndicator as O } from "./SortIndicator.js";
6
+ import { getTableHeaderStyle as E } from "../../helpers/getTableHeaderStyle.js";
7
+ import { getSortPreview as M } from "../../helpers/sortPreview.js";
7
8
  import _ from "clsx";
8
9
  import { useMemo as c } from "react";
9
- import { jsx as l, jsxs as M } from "react/jsx-runtime";
10
- import { flexRender as k } from "@tanstack/react-table";
11
- function X({ styledTableProps: z, header: o, tableCanResize: b = !1, left: N, right: v, tableWidth: H }) {
12
- const { hideHeader: r = !1, enableResizing: m = !1, actions: I, customActionsNode: T } = z, { isResizing: a, enableResizingFlag: u, disableResizingFlag: d } = L(), g = o.column.columnDef.fixedLeft, f = !!o.column.columnDef.fixedRight, p = o.column.id === D, w = !!I || !!T, S = c(() => o.headerGroup.headers.some((t) => t.id === D), [o.headerGroup.headers]), y = c(() => o.headerGroup.headers.some((t) => !!t.column.columnDef.fixedRight), [o.headerGroup.headers]), h = c(() => o.headerGroup.headers[o.headerGroup.headers.length - (S ? 2 : 1)], [o.headerGroup.headers, S]), n = o.column.getCanSort(), s = o.column.getIsSorted(), x = o.getContext().table.getState().sorting, F = E({
10
+ import { jsx as l, jsxs as k } from "react/jsx-runtime";
11
+ import { flexRender as B } from "@tanstack/react-table";
12
+ function Z({ styledTableProps: z, header: o, tableCanResize: b = !1, left: N, right: v, tableWidth: H }) {
13
+ const { hideHeader: r = !1, enableResizing: m = !1, actions: I, customActionsNode: T } = z, { isResizing: a, enableResizingFlag: u, disableResizingFlag: d } = L(), g = o.column.columnDef.fixedLeft, f = !!o.column.columnDef.fixedRight, p = o.column.id === D, h = !!I || !!T, S = c(() => o.headerGroup.headers.some((t) => t.id === D), [o.headerGroup.headers]), w = c(() => o.headerGroup.headers.some((t) => !!t.column.columnDef.fixedRight), [o.headerGroup.headers]), y = c(() => o.headerGroup.headers[o.headerGroup.headers.length - (S ? 2 : 1)], [o.headerGroup.headers, S]), n = o.column.getCanSort(), s = o.column.getIsSorted(), x = o.getContext().table.getState().sorting, F = M({
13
14
  sorted: s,
14
15
  firstDirection: o.column.getFirstSortDir(),
15
16
  nextOrder: o.column.getNextSortingOrder(),
16
17
  isLastSortEntry: x[x.length - 1]?.id === o.column.id
17
- }), G = n ? s === "asc" ? "ascending" : s === "desc" ? "descending" : "none" : void 0, C = b && (m ? !0 : o.id !== h?.id) && o.column.getCanResize() && !R.includes(o.column.id);
18
+ }), G = n ? s === "asc" ? "ascending" : s === "desc" ? "descending" : "none" : void 0, C = b && (m ? !0 : o.id !== y?.id) && o.column.getCanResize() && !A(o.column.columnDef) && !R.includes(o.column.id);
18
19
  return /* @__PURE__ */ l("th", {
19
20
  colSpan: o.colSpan,
20
21
  "aria-sort": G,
21
- className: _(e["t-cell"], !R.includes(o.column.id) && o.column.getSize() > 64 && e["data-cell"], o.column.id === "select" && e["select-cell"], r && e["hide-header"], p && e["t-cell__actions"], p && (!w || y) && e["t-cell__actions--no-shadow"], g && e["t-cell__fixed"], f && e["t-cell__fixed-right"]),
22
+ className: _(e["t-cell"], !R.includes(o.column.id) && o.column.getSize() > 64 && e["data-cell"], o.column.id === "select" && e["select-cell"], r && e["hide-header"], p && e["t-cell__actions"], p && (!h || w) && e["t-cell__actions--no-shadow"], g && e["t-cell__fixed"], f && e["t-cell__fixed-right"]),
22
23
  style: {
23
- ...O({
24
+ ...E({
24
25
  enableResizing: m,
25
26
  header: o,
26
27
  tableWidth: H
@@ -28,7 +29,7 @@ function X({ styledTableProps: z, header: o, tableCanResize: b = !1, left: N, ri
28
29
  ...g && { left: N },
29
30
  ...f && { right: v }
30
31
  },
31
- children: /* @__PURE__ */ M("div", {
32
+ children: /* @__PURE__ */ k("div", {
32
33
  className: _("flex items-center justify-start", r ? e["hide-table-header"] : e["show-table-header"], n && e["sortable-column"], C && e["has-resize-zone"], o.column.columnDef.className),
33
34
  role: n ? "button" : void 0,
34
35
  tabIndex: n ? 0 : void 0,
@@ -45,9 +46,9 @@ function X({ styledTableProps: z, header: o, tableCanResize: b = !1, left: N, ri
45
46
  children: [
46
47
  /* @__PURE__ */ l("div", {
47
48
  className: e["header-content"],
48
- children: k(o.column.columnDef.header, o.getContext())
49
+ children: B(o.column.columnDef.header, o.getContext())
49
50
  }),
50
- n && /* @__PURE__ */ l(A, {
51
+ n && /* @__PURE__ */ l(O, {
51
52
  sorted: s,
52
53
  firstDirection: o.column.getFirstSortDir(),
53
54
  preview: F
@@ -67,5 +68,5 @@ function X({ styledTableProps: z, header: o, tableCanResize: b = !1, left: N, ri
67
68
  }, o.id);
68
69
  }
69
70
  export {
70
- X as TableHeaderCell
71
+ Z as TableHeaderCell
71
72
  };
@@ -0,0 +1,29 @@
1
+ import { INTERNAL_COLUMN_IDS as x } from "../types.js";
2
+ import { getLeafColumnInfos as I } from "./columnIds.js";
3
+ var E = 150;
4
+ var g = (n, m) => {
5
+ const { defaultColumn: S, canResize: v } = m, z = (e) => {
6
+ if (e.columns?.length) return {
7
+ ...e,
8
+ columns: e.columns.map((u) => z(u))
9
+ };
10
+ const a = I([e], {
11
+ defaultColumn: S,
12
+ enableSorting: m.enableSorting
13
+ })[0];
14
+ if (!a) return e;
15
+ const i = {
16
+ ...S,
17
+ ...e
18
+ }, l = x.includes(a.id), t = a.canSort && !l, r = t ? (i.size ?? E) + 20 : i.size;
19
+ let o = i.minSize;
20
+ o !== void 0 ? t && (o += 20) : v && (o = l || r === void 0 ? 100 : Math.min(100, r));
21
+ const c = t && i.maxSize !== void 0 ? i.maxSize + 20 : i.maxSize, s = { ...e };
22
+ return r !== i.size && (s.size = r), o !== i.minSize && (s.minSize = o), c !== i.maxSize && (s.maxSize = c), s;
23
+ };
24
+ return n.map(z);
25
+ }, A = (n) => n.maxSize !== void 0 && n.minSize === n.maxSize;
26
+ export {
27
+ A as hasFixedWidth,
28
+ g as resolveColumnSizingDefaults
29
+ };
@@ -1,110 +1,118 @@
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";
1
+ import { SELECT_COLUMN_ID as V } from "../types.js";
2
+ import { ExpandedRowsFeature as h } from "../custom-features/expand-rows/ExpandRowsFeature.js";
3
+ import { FocusedRowsFeature as D } from "../custom-features/focus-rows/FocusRowsFeature.js";
4
+ import { OrderColumnsFeature as G } from "../custom-features/order-columns/OrderColumnsFeature.js";
5
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,
6
+ import { usePersistColumnOrder as U } from "../custom-features/order-columns/usePersistColumnOrder.js";
7
+ import { usePersistedColumnOrder as W } from "../custom-features/order-columns/usePersistedColumnOrder.js";
8
+ import { getPersistedPageSizeKey as j, usePersistedPageSize as q } from "./usePersistedPageSize.js";
9
+ import { columnSizingSignature as J, getColumnSizingStorageKey as Z, serializeColumnSizing as k, usePersistedColumnSizing as A } from "./useColumnSizingPersistence.js";
10
+ import { getSortingStorageKey as B, readSortingFromStorage as H, serializeSorting as Q, sortingSignature as X } from "./usePersistedSorting.js";
11
+ import { usePersistedStateWriter as K } from "./usePersistedStateWriter.js";
12
+ import { RowSelectionTooltipFeature as Y } from "../custom-features/row-selection-tooltip/RowSelectionTooltipFeature.js";
13
+ import { getLeafColumnInfos as $ } from "../helpers/columnIds.js";
14
+ import { resolveColumnSizingDefaults as ee } from "../helpers/columnSizingDefaults.js";
15
+ import { useEffect as P, useMemo as O, useRef as te } from "react";
16
+ import { getCoreRowModel as oe, getExpandedRowModel as ie, getFilteredRowModel as ne, getPaginationRowModel as re, getSortedRowModel as ae, useReactTable as se } from "@tanstack/react-table";
17
+ var le = [], ge = {}, Oe = (u) => {
18
+ const { columns: S, data: I, initialState: s, pageSize: x, enableRowSelection: F, tableInstanceRef: C, locale: N, persistColumnOrderKey: m, uniqueKey: r, persistSorting: _, defaultColumn: l, ...o } = u, R = s?.sorting ?? le, d = s?.columnSizing ?? ge, c = u.enableColumnResizing ?? !0, E = u.enableColumnResizing === !0, T = O(() => ee(S, {
19
+ defaultColumn: l,
20
+ enableSorting: o.enableSorting,
21
+ canResize: c
22
+ }), [
23
+ S,
24
+ l,
25
+ o.enableSorting,
26
+ c
27
+ ]), L = $(S, {
28
+ defaultColumn: l,
22
29
  enableSorting: o.enableSorting,
23
30
  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),
31
+ }), y = W(m), b = E ? r : void 0, M = Z(b), f = A(b, d), a = _ ? B(r) : void 0, p = O(() => a ? H(r, {
32
+ sortableColumns: L.filter((t) => t.canSort),
26
33
  maxMultiSortColCount: o.maxMultiSortColCount
27
- }) : void 0, [a]), i = A(r) ?? P ?? 50, e = ne({
34
+ }) : void 0, [a]), i = q(r) ?? x ?? 50, e = se({
28
35
  _features: [
29
- L,
30
- T,
31
- U,
32
- H
36
+ h,
37
+ D,
38
+ G,
39
+ Y
33
40
  ],
34
- columns: c,
35
- data: O,
36
- meta: { locale: E ?? "en" },
41
+ columns: T,
42
+ data: I,
43
+ meta: { locale: N ?? "en" },
37
44
  initialState: {
38
45
  pagination: {
39
46
  pageIndex: 0,
40
47
  pageSize: i
41
48
  },
42
49
  columnVisibility: {
43
- ...l?.columnVisibility,
44
- [N]: !1
50
+ ...s?.columnVisibility,
51
+ [V]: !1
45
52
  },
46
53
  ...y && { columnOrder: y },
47
- ...l,
48
- ...m && { columnSizing: m },
49
- ...d !== void 0 && { sorting: d }
54
+ ...s,
55
+ ...f && { columnSizing: f },
56
+ ...p !== void 0 && { sorting: p }
50
57
  },
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
58
+ enableRowSelection: F,
59
+ getCoreRowModel: oe(),
60
+ getExpandedRowModel: ie(),
61
+ getFilteredRowModel: ne(),
62
+ getSortedRowModel: ae(),
63
+ getPaginationRowModel: re(),
64
+ getRowId: o.getRowId ?? ((t, ue, v) => v ? [v.id, t.id].join(".") : t.id.toString()),
65
+ defaultColumn: l,
66
+ ...o,
67
+ enableColumnResizing: c
60
68
  });
61
- C && (C.current = e), V(e, u), I({
69
+ C && (C.current = e), U(e, m), K({
62
70
  storageKey: a,
63
71
  state: e.getState().sorting,
64
- defaultValue: z,
65
- saved: d,
72
+ defaultValue: R,
73
+ saved: p,
66
74
  controlled: o.state?.sorting !== void 0,
67
- toSignature: k,
68
- toStorage: W,
75
+ toSignature: X,
76
+ toStorage: Q,
69
77
  applyState: (t) => e.setSorting(t)
70
- }), I({
71
- storageKey: v,
78
+ }), K({
79
+ storageKey: M,
72
80
  state: e.getState().columnSizing,
73
- defaultValue: S,
74
- saved: m,
81
+ defaultValue: d,
82
+ saved: f,
75
83
  settled: !e.getState().columnSizingInfo.isResizingColumn,
76
- toSignature: G,
77
- toStorage: j,
84
+ toSignature: J,
85
+ toStorage: k,
78
86
  applyState: (t) => e.setColumnSizing(t)
79
87
  }), e.resetColumnSettings = () => {
80
- e.setColumnOrder([]), e.setColumnSizing(S), a && e.setSorting(z);
88
+ e.setColumnOrder([]), e.setColumnSizing(d), a && e.setSorting(R);
81
89
  for (const t of [
82
90
  a,
83
- v,
84
- u
91
+ M,
92
+ m
85
93
  ]) t && w.remove(t);
86
94
  };
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));
95
+ const n = j(r), g = e.getState().pagination?.pageSize, z = te(void 0);
96
+ return P(() => {
97
+ z.current = void 0, e.getState().pagination?.pageSize !== i && (e.setPageIndex(0), e.setPageSize(i));
90
98
  }, [
91
99
  i,
92
100
  n,
93
101
  e
94
- ]), K(() => {
95
- if (!(!n || s == null)) {
96
- if (f.current !== n) {
97
- if (s !== i) return;
98
- f.current = n;
102
+ ]), P(() => {
103
+ if (!(!n || g == null)) {
104
+ if (z.current !== n) {
105
+ if (g !== i) return;
106
+ z.current = n;
99
107
  }
100
- w.set(n, JSON.stringify(s));
108
+ w.set(n, JSON.stringify(g));
101
109
  }
102
110
  }, [
103
- s,
111
+ g,
104
112
  i,
105
113
  n
106
114
  ]), { table: e };
107
115
  };
108
116
  export {
109
- we as useStyledTable
117
+ Oe as useStyledTable
110
118
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "3.130.5",
6
+ "version": "3.131.0",
7
7
  "type": "module",
8
8
  "sideEffects": [
9
9
  "**/*.css",