asma-ui-core 3.133.0 → 3.134.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/asma-ui-core.css +1 -1
- package/dist/components/utils/popover/PopoverSheet.js +168 -151
- package/dist/src/table/helpers/defaultSortingFn.d.ts +48 -0
- package/dist/src/table/helpers/defaultSortingFn.test.d.ts +1 -0
- package/dist/src/table/types.d.ts +13 -0
- package/dist/table/helpers/defaultSortingFn.js +60 -0
- package/dist/table/hooks/useStyledTable.js +124 -112
- package/package.json +1 -1
|
@@ -1,227 +1,244 @@
|
|
|
1
|
-
import { cn as
|
|
2
|
-
import { firstTabbable as
|
|
3
|
-
import { TOP_LAYER_PROPS as
|
|
1
|
+
import { cn as Me } from "../../../helpers/cn.js";
|
|
2
|
+
import { firstTabbable as re } from "../../../helpers/focusable.js";
|
|
3
|
+
import { TOP_LAYER_PROPS as Se, TOP_LAYER_RESET_STYLE as Ce, getOpenModalDialogAncestor as Ie, shouldUsePopoverTopLayer as _e, useTopLayerRef as We } from "../../../hooks/useTopLayer.hook.js";
|
|
4
4
|
import { StyledButton as ke } from "../../inputs/button/StyledButton.js";
|
|
5
|
-
import { OverlayBackOwnerContext as He, requestCloseTopOverlayBack as
|
|
6
|
-
import { isKeyboardModality as
|
|
7
|
-
import { useDebouncedValue as
|
|
8
|
-
import { useFocusTrap as
|
|
9
|
-
import { useMobileMediaQuery as
|
|
10
|
-
import { SHEET_TEXT as
|
|
11
|
-
import { formatResultsLabel as
|
|
12
|
-
import { StyledBottomSheet as
|
|
13
|
-
import { PopoverAnatomy as
|
|
14
|
-
import { useCallback as
|
|
15
|
-
import { Fragment as
|
|
16
|
-
import { FloatingPortal as
|
|
17
|
-
var
|
|
5
|
+
import { OverlayBackOwnerContext as He, requestCloseTopOverlayBack as Be, useBackCloses as De } from "../../../hooks/useBackCloses.hook.js";
|
|
6
|
+
import { isKeyboardModality as qe, trackInputModality as Xe } from "../../inputs/full-screen-picker/inputModality.js";
|
|
7
|
+
import { useDebouncedValue as $e } from "../../../hooks/useDebouncedValue.hook.js";
|
|
8
|
+
import { useFocusTrap as Ke } from "../../../hooks/useFocusTrap.hook.js";
|
|
9
|
+
import { useMobileMediaQuery as Ne } from "../../../hooks/useMediaQuery.hook.js";
|
|
10
|
+
import { SHEET_TEXT as je } from "../bottom-sheet/sheetCopy.js";
|
|
11
|
+
import { formatResultsLabel as Ue } from "../bottom-sheet/formatResultsLabel.js";
|
|
12
|
+
import { StyledBottomSheet as Ve } from "../bottom-sheet/StyledBottomSheet.js";
|
|
13
|
+
import { PopoverAnatomy as Ye } from "./PopoverAnatomy.js";
|
|
14
|
+
import { useCallback as p, useEffect as b, useId as ze, useRef as g, useState as l } from "react";
|
|
15
|
+
import { Fragment as ie, jsx as h, jsxs as se } from "react/jsx-runtime";
|
|
16
|
+
import { FloatingPortal as Ge, autoUpdate as Qe, flip as Je, offset as Ze, shift as et, size as tt, useDismiss as ot, useFloating as nt, useInteractions as rt, useMergeRefs as it } from "@floating-ui/react";
|
|
17
|
+
var H = 240, st = {
|
|
18
18
|
info: 472,
|
|
19
19
|
action: 472
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
}, ae = 0.6, ce = "calc(100vw - 32px)", at = () => {
|
|
21
|
+
let o;
|
|
22
|
+
return {
|
|
23
|
+
name: "holdAlignedEdge",
|
|
24
|
+
fn: ({ x: v, rects: w, placement: f }) => {
|
|
25
|
+
const u = f.endsWith("-end"), E = w.floating.width, { x, width: R } = w.reference;
|
|
26
|
+
return !(o !== void 0 && o.x >= x - 1 && o.x <= x + R + 1) || o?.atEnd !== u || o.viewportWidth !== window.innerWidth ? (o = {
|
|
27
|
+
x: u ? v + E : v,
|
|
28
|
+
atEnd: u,
|
|
29
|
+
viewportWidth: window.innerWidth
|
|
30
|
+
}, {}) : { x: u ? o.x - E : o.x };
|
|
31
|
+
},
|
|
32
|
+
release: () => {
|
|
33
|
+
o = void 0;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}, Tt = ({ dataTest: o, renderTrigger: v, variant: w = "info", title: f, children: u, viewResultsAction: E, resetAction: x, footerActions: R, resultCount: O, locale: M = "en", closeLabel: B = je[M].close, ariaLabel: D, onOpenChange: q, className: X, align: $ = "auto", ignoreOutside: K }) => {
|
|
37
|
+
const y = ze(), N = `${y}-title`, [n, le] = l(!1), [j, de] = l(), [ue, U] = l(), [fe, me] = l("start"), [S, V] = l(), [pe, Y] = l(H), [z] = l(at), m = Ne(), r = w === "action", ge = m && !r, A = m && r, T = p((e) => {
|
|
38
|
+
le(e), q?.(e);
|
|
39
|
+
}, [q]), { refs: C, floatingStyles: he, context: ve, placement: G, isPositioned: we } = nt({
|
|
40
|
+
open: n,
|
|
41
|
+
onOpenChange: T,
|
|
42
|
+
placement: `${S ?? "bottom"}-${fe}`,
|
|
27
43
|
strategy: "fixed",
|
|
28
|
-
whileElementsMounted:
|
|
44
|
+
whileElementsMounted: Qe,
|
|
29
45
|
middleware: [
|
|
30
|
-
|
|
31
|
-
...
|
|
46
|
+
Ze(8),
|
|
47
|
+
...ge || S ? [] : [Je({
|
|
32
48
|
padding: 8,
|
|
33
49
|
crossAxis: !1,
|
|
34
50
|
flipAlignment: !1
|
|
35
51
|
})],
|
|
36
|
-
|
|
37
|
-
et({
|
|
52
|
+
z,
|
|
53
|
+
et({ padding: 8 }),
|
|
54
|
+
tt({
|
|
38
55
|
padding: 8,
|
|
39
56
|
apply({ availableHeight: e, rects: t }) {
|
|
40
|
-
U(Math.min(e, Math.round(window.innerHeight *
|
|
57
|
+
U(Math.min(e, Math.round(window.innerHeight * ae))), m || Y((c) => Math.max(c, t.floating.width));
|
|
41
58
|
}
|
|
42
59
|
})
|
|
43
60
|
]
|
|
44
61
|
});
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
}, []),
|
|
49
|
-
|
|
50
|
-
}, [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, [
|
|
54
|
-
const
|
|
62
|
+
n && we && !S && V(G.startsWith("top") ? "top" : "bottom");
|
|
63
|
+
const I = _e(j), d = g(null), [i, Ee] = l(null), xe = p((e) => {
|
|
64
|
+
d.current = e, Ee(e);
|
|
65
|
+
}, []), ye = it([We(C.setFloating, I), xe]), F = g(null), Pe = p((e) => {
|
|
66
|
+
F.current = e, C.setReference(e);
|
|
67
|
+
}, [C]), Q = g(null), _ = K?.length ? K.join(",") : void 0, J = g(_);
|
|
68
|
+
b(() => {
|
|
69
|
+
J.current = _;
|
|
70
|
+
}, [_]);
|
|
71
|
+
const P = p((e) => {
|
|
55
72
|
if (!(e instanceof Element)) return !1;
|
|
56
|
-
if (
|
|
57
|
-
const t =
|
|
73
|
+
if (d.current?.contains(e) || F.current?.contains(e) || Q.current === e) return !0;
|
|
74
|
+
const t = J.current;
|
|
58
75
|
return t !== void 0 && e.closest(t) !== null;
|
|
59
|
-
}, []),
|
|
60
|
-
|
|
61
|
-
}, []), { getFloatingProps:
|
|
62
|
-
enabled: !
|
|
76
|
+
}, []), Z = g(null), be = p((e) => {
|
|
77
|
+
Q.current = e.target, e.target instanceof HTMLElement && d.current?.contains(e.target) && (Z.current = e.target);
|
|
78
|
+
}, []), { getFloatingProps: Re } = rt([ot(ve, {
|
|
79
|
+
enabled: !A,
|
|
63
80
|
escapeKey: !1,
|
|
64
81
|
outsidePress: (e) => {
|
|
65
82
|
const t = e.target;
|
|
66
83
|
if (!(t instanceof Element)) return !0;
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
return !
|
|
84
|
+
if (P(t) || t.closest("[data-floating-ui-portal]")) return !1;
|
|
85
|
+
const c = t.closest('dialog[open], [role="dialog"]');
|
|
86
|
+
return !c || c.contains(d.current);
|
|
70
87
|
}
|
|
71
|
-
})]),
|
|
72
|
-
|
|
73
|
-
}, [
|
|
74
|
-
|
|
75
|
-
active:
|
|
76
|
-
requestClose:
|
|
77
|
-
ownerRef:
|
|
78
|
-
}),
|
|
79
|
-
if (!
|
|
88
|
+
})]), a = p(() => {
|
|
89
|
+
T(!1);
|
|
90
|
+
}, [T]);
|
|
91
|
+
De({
|
|
92
|
+
active: n,
|
|
93
|
+
requestClose: a,
|
|
94
|
+
ownerRef: d
|
|
95
|
+
}), b(() => {
|
|
96
|
+
if (!n || A) return;
|
|
80
97
|
const e = (t) => {
|
|
81
|
-
t.key !== "Escape" || t.defaultPrevented || t.isComposing || (t.preventDefault(), t.stopImmediatePropagation(),
|
|
98
|
+
t.key !== "Escape" || t.defaultPrevented || t.isComposing || (t.preventDefault(), t.stopImmediatePropagation(), Be(t));
|
|
82
99
|
};
|
|
83
100
|
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
84
|
-
}, [
|
|
85
|
-
const [
|
|
86
|
-
|
|
87
|
-
if (!
|
|
101
|
+
}, [n, A]), Ke(n && r && i !== null, d);
|
|
102
|
+
const [ee, Ae] = l(!1);
|
|
103
|
+
b(() => {
|
|
104
|
+
if (!i || r && !ee) return;
|
|
88
105
|
const e = requestAnimationFrame(() => {
|
|
89
|
-
(
|
|
106
|
+
(r ? re(i) : i)?.focus({ preventScroll: !0 });
|
|
90
107
|
});
|
|
91
108
|
return () => {
|
|
92
109
|
cancelAnimationFrame(e);
|
|
93
110
|
};
|
|
94
111
|
}, [
|
|
112
|
+
i,
|
|
95
113
|
r,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!r) return;
|
|
114
|
+
ee
|
|
115
|
+
]), b(() => {
|
|
116
|
+
if (!i) return;
|
|
100
117
|
let e = 0;
|
|
101
118
|
const t = () => {
|
|
102
119
|
cancelAnimationFrame(e), e = requestAnimationFrame(() => {
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
105
|
-
const
|
|
106
|
-
(
|
|
120
|
+
const s = document.activeElement;
|
|
121
|
+
if (!i.isConnected || s && s !== document.body && P(s)) return;
|
|
122
|
+
const k = Z.current;
|
|
123
|
+
(k?.isConnected && i.contains(k) ? k : re(i) ?? i).focus({ preventScroll: !0 });
|
|
107
124
|
});
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
},
|
|
113
|
-
!
|
|
125
|
+
}, c = (s) => {
|
|
126
|
+
s.relatedTarget === null && a();
|
|
127
|
+
}, oe = (s) => {
|
|
128
|
+
s.relatedTarget === null && P(s.target) && t();
|
|
129
|
+
}, ne = (s) => {
|
|
130
|
+
!i.isConnected || P(s.target) || (r ? t() : a());
|
|
114
131
|
};
|
|
115
|
-
return
|
|
116
|
-
cancelAnimationFrame(e), document.removeEventListener("focusout",
|
|
132
|
+
return r ? document.addEventListener("focusout", oe) : i.addEventListener("focusout", c), document.addEventListener("focusin", ne), () => {
|
|
133
|
+
cancelAnimationFrame(e), document.removeEventListener("focusout", oe), i.removeEventListener("focusout", c), document.removeEventListener("focusin", ne);
|
|
117
134
|
};
|
|
118
135
|
}, [
|
|
136
|
+
i,
|
|
119
137
|
r,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
h
|
|
138
|
+
a,
|
|
139
|
+
P
|
|
123
140
|
]);
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
141
|
+
const W = g(!1);
|
|
142
|
+
b(() => {
|
|
143
|
+
if (n) {
|
|
144
|
+
Xe(), W.current = !0;
|
|
128
145
|
return;
|
|
129
146
|
}
|
|
130
|
-
if (!
|
|
131
|
-
|
|
132
|
-
const e =
|
|
147
|
+
if (!W.current) return;
|
|
148
|
+
W.current = !1;
|
|
149
|
+
const e = F.current;
|
|
133
150
|
if (!e) return;
|
|
134
151
|
const t = requestAnimationFrame(() => {
|
|
135
|
-
document.activeElement === document.body && e.focus({ focusVisible:
|
|
152
|
+
document.activeElement === document.body && e.focus({ focusVisible: qe() });
|
|
136
153
|
});
|
|
137
154
|
return () => {
|
|
138
155
|
cancelAnimationFrame(t);
|
|
139
156
|
};
|
|
140
|
-
}, [
|
|
141
|
-
const
|
|
157
|
+
}, [n]);
|
|
158
|
+
const te = {
|
|
142
159
|
ref: Pe,
|
|
143
|
-
isOpen:
|
|
160
|
+
isOpen: n,
|
|
144
161
|
triggerProps: {
|
|
145
162
|
onClick: (e) => {
|
|
146
|
-
if (
|
|
147
|
-
|
|
163
|
+
if (n) {
|
|
164
|
+
a();
|
|
148
165
|
return;
|
|
149
166
|
}
|
|
150
|
-
|
|
151
|
-
const t = e.currentTarget.getBoundingClientRect(),
|
|
152
|
-
|
|
167
|
+
de(Ie(e.currentTarget));
|
|
168
|
+
const t = e.currentTarget.getBoundingClientRect(), c = t.left + t.width / 2 > window.innerWidth / 2;
|
|
169
|
+
me($ === "auto" ? c ? "end" : "start" : $), V(void 0), z.release(), Y(H), U(Math.round(window.innerHeight * ae)), Ae(e.detail === 0), T(!0);
|
|
153
170
|
},
|
|
154
|
-
"aria-expanded":
|
|
155
|
-
"aria-controls":
|
|
156
|
-
"aria-haspopup":
|
|
157
|
-
"aria-describedby": !
|
|
171
|
+
"aria-expanded": n,
|
|
172
|
+
"aria-controls": n ? y : void 0,
|
|
173
|
+
"aria-haspopup": r ? "dialog" : void 0,
|
|
174
|
+
"aria-describedby": !r && n ? y : void 0
|
|
158
175
|
}
|
|
159
|
-
},
|
|
160
|
-
dataTest: `${
|
|
176
|
+
}, L = (e) => typeof e == "function" ? e({ close: a }) : e, Te = $e(O, 500), Fe = E ?? (O === void 0 ? void 0 : /* @__PURE__ */ h(ke, {
|
|
177
|
+
dataTest: `${o}-view-results`,
|
|
161
178
|
type: "button",
|
|
162
179
|
variant: "text",
|
|
163
|
-
onClick:
|
|
164
|
-
children:
|
|
165
|
-
})),
|
|
166
|
-
return
|
|
167
|
-
id:
|
|
168
|
-
dataTest:
|
|
169
|
-
open:
|
|
170
|
-
onClose:
|
|
180
|
+
onClick: a,
|
|
181
|
+
children: Ue(Te, M)
|
|
182
|
+
})), Le = m ? ce : st[w], Oe = m ? ce : void 0;
|
|
183
|
+
return A ? /* @__PURE__ */ se(ie, { children: [v(te), /* @__PURE__ */ h(Ve, {
|
|
184
|
+
id: y,
|
|
185
|
+
dataTest: o,
|
|
186
|
+
open: n,
|
|
187
|
+
onClose: a,
|
|
171
188
|
registerBackClose: !1,
|
|
172
|
-
ownerRef:
|
|
173
|
-
triggerRef:
|
|
174
|
-
title:
|
|
189
|
+
ownerRef: d,
|
|
190
|
+
triggerRef: F,
|
|
191
|
+
title: f,
|
|
175
192
|
ariaLabel: D,
|
|
176
|
-
viewResultsAction:
|
|
177
|
-
resetAction:
|
|
178
|
-
footerActions:
|
|
179
|
-
resultCount:
|
|
180
|
-
locale:
|
|
193
|
+
viewResultsAction: E,
|
|
194
|
+
resetAction: x,
|
|
195
|
+
footerActions: R,
|
|
196
|
+
resultCount: O,
|
|
197
|
+
locale: M,
|
|
181
198
|
closeLabel: B,
|
|
182
199
|
className: X,
|
|
183
|
-
children:
|
|
184
|
-
})] }) : /* @__PURE__ */ ie
|
|
200
|
+
children: u
|
|
201
|
+
})] }) : /* @__PURE__ */ se(ie, { children: [v(te), n && /* @__PURE__ */ h(Ge, {
|
|
185
202
|
root: j,
|
|
186
|
-
children: /* @__PURE__ */
|
|
187
|
-
...
|
|
188
|
-
onFocusCapture:
|
|
189
|
-
ref:
|
|
190
|
-
id:
|
|
191
|
-
"data-placement":
|
|
192
|
-
"data-test":
|
|
193
|
-
"data-testid":
|
|
194
|
-
role:
|
|
195
|
-
"aria-labelledby":
|
|
196
|
-
"aria-label":
|
|
197
|
-
tabIndex:
|
|
198
|
-
...
|
|
203
|
+
children: /* @__PURE__ */ h("div", {
|
|
204
|
+
...Re(),
|
|
205
|
+
onFocusCapture: be,
|
|
206
|
+
ref: ye,
|
|
207
|
+
id: y,
|
|
208
|
+
"data-placement": G,
|
|
209
|
+
"data-test": o,
|
|
210
|
+
"data-testid": o,
|
|
211
|
+
role: r ? "dialog" : void 0,
|
|
212
|
+
"aria-labelledby": r && f ? N : void 0,
|
|
213
|
+
"aria-label": r && !f ? D : void 0,
|
|
214
|
+
tabIndex: r ? void 0 : -1,
|
|
215
|
+
...I ? Se : {},
|
|
199
216
|
style: {
|
|
200
|
-
...
|
|
201
|
-
...
|
|
202
|
-
minWidth:
|
|
217
|
+
...I ? Ce : {},
|
|
218
|
+
...he,
|
|
219
|
+
minWidth: m ? H : pe,
|
|
203
220
|
width: Oe,
|
|
204
|
-
maxWidth:
|
|
221
|
+
maxWidth: Le,
|
|
205
222
|
maxHeight: ue
|
|
206
223
|
},
|
|
207
|
-
className:
|
|
208
|
-
children: /* @__PURE__ */
|
|
209
|
-
value:
|
|
210
|
-
children: /* @__PURE__ */
|
|
211
|
-
dataTest:
|
|
212
|
-
title:
|
|
224
|
+
className: Me("z-[1300]", "box-border flex flex-col overflow-hidden rounded-lg bg-white text-delta-700 outline-none shadow-[0px_4px_40px_0px_#22213366]", X),
|
|
225
|
+
children: /* @__PURE__ */ h(He.Provider, {
|
|
226
|
+
value: d,
|
|
227
|
+
children: /* @__PURE__ */ h(Ye, {
|
|
228
|
+
dataTest: o,
|
|
229
|
+
title: f,
|
|
213
230
|
titleId: N,
|
|
214
|
-
viewResultsAction:
|
|
215
|
-
resetAction: x
|
|
216
|
-
footerActions:
|
|
231
|
+
viewResultsAction: L(Fe),
|
|
232
|
+
resetAction: L(x),
|
|
233
|
+
footerActions: L(R),
|
|
217
234
|
closeLabel: B,
|
|
218
|
-
onClose:
|
|
219
|
-
children:
|
|
235
|
+
onClose: a,
|
|
236
|
+
children: L(u)
|
|
220
237
|
})
|
|
221
238
|
})
|
|
222
239
|
})
|
|
223
240
|
})] });
|
|
224
241
|
};
|
|
225
242
|
export {
|
|
226
|
-
|
|
243
|
+
Tt as PopoverSheet
|
|
227
244
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BuiltInSortingFn, SortingFn, Table } from '@tanstack/react-table';
|
|
2
|
+
/**
|
|
3
|
+
* The comparison every `StyledTable` column uses unless the column, or the app's `defaultColumn`, names its own `sortingFn`
|
|
4
|
+
* (ASMA-8597, P2f, DEC-SORTFN). It is registered as `sortingFns.styledDefault`.
|
|
5
|
+
*
|
|
6
|
+
* - Empty cells (`undefined`, `null`, `''`, whitespace only, `NaN`, an invalid `Date`) go last in both directions. Two empty
|
|
7
|
+
* cells tie.
|
|
8
|
+
* - Numbers, `Date`s and booleans compare by value; two ISO 8601 date strings compare by time.
|
|
9
|
+
* - Any other two strings, and two values of different types, compare as text in the table locale: case and accents are
|
|
10
|
+
* ignored and digit runs compare as numbers (`svc-9` before `svc-10`).
|
|
11
|
+
* - Ties return 0, so TanStack keeps the data order.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The name the comparison is registered under in the table's `sortingFns`. It is typed as a built-in name because TanStack's
|
|
15
|
+
* `SortingFns` interface, which would let `'styledDefault'` type-check, turns `sortingFns` into a required prop of every
|
|
16
|
+
* `StyledTable` once it is augmented; the table registers the function itself, so no app needs to.
|
|
17
|
+
*/
|
|
18
|
+
export declare const STYLED_DEFAULT_SORTING_FN: BuiltInSortingFn;
|
|
19
|
+
/** One collator per locale: building one is the expensive part of a text comparison. */
|
|
20
|
+
export declare const getSortCollator: (locale?: string) => Intl.Collator;
|
|
21
|
+
/** Whether a cell has no value to sort on: such cells always go last. */
|
|
22
|
+
export declare const isEmptySortValue: (value: unknown) => boolean;
|
|
23
|
+
/** Compares two cells that are not empty, ascending. A tie is exactly 0. */
|
|
24
|
+
export declare const compareSortValues: (a: unknown, b: unknown, collator: Intl.Collator) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Builds the comparison. TanStack hands a sorting function only `(rowA, rowB, columnId)` and flips its result afterwards
|
|
27
|
+
* for a descending sort and for `invertSorting`, so an empty cell would swap ends with the direction. To keep it last the
|
|
28
|
+
* comparison reads the column's direction and `invertSorting` live from the table (`getTable` returns the table of the
|
|
29
|
+
* render that sorts) and returns the sign that comes out "after" once TanStack has applied both flips.
|
|
30
|
+
*/
|
|
31
|
+
export declare const createStyledDefaultSortingFn: <TData>(getTable: () => Table<TData> | undefined) => SortingFn<TData>;
|
|
32
|
+
/** The parts of a column definition that decide whether the default comparison applies to it. */
|
|
33
|
+
interface SortUndefinedColumnDef {
|
|
34
|
+
sortingFn?: unknown;
|
|
35
|
+
sortUndefined?: unknown;
|
|
36
|
+
columns?: readonly SortUndefinedColumnDef[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gives `sortUndefined: false` to the leaf columns that sort with `styledDefault`, and to no other (DeepSeek's audit of
|
|
40
|
+
* #340, round 1). The setting lets `undefined` reach the comparison so that it can put it last. A column with its own
|
|
41
|
+
* `sortingFn` would then receive `undefined` in its own comparator, which was written for TanStack's handling and may not
|
|
42
|
+
* expect it, so it keeps TanStack's default.
|
|
43
|
+
*
|
|
44
|
+
* A leaf gets it only when it sorts with `styledDefault` (neither it nor the app's `defaultColumn` names another
|
|
45
|
+
* `sortingFn`) and neither it nor the app's `defaultColumn` sets `sortUndefined`. Group columns are walked into.
|
|
46
|
+
*/
|
|
47
|
+
export declare const resolveSortUndefinedDefaults: <TColumn extends SortUndefinedColumnDef>(columns: readonly TColumn[], defaultColumn?: SortUndefinedColumnDef) => TColumn[];
|
|
48
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -73,6 +73,19 @@ export type RowActionsState = {
|
|
|
73
73
|
state: 'enabled';
|
|
74
74
|
};
|
|
75
75
|
export type StyledTableProps<TData, TCustomData> = {
|
|
76
|
+
/**
|
|
77
|
+
* The table's language. It sets the labels, and also the text order of the default sort: names compare in this locale,
|
|
78
|
+
* ignoring case and accents, with digit runs as numbers (`'no'` puts æ, ø and å after z).
|
|
79
|
+
*
|
|
80
|
+
* **Default sort.** Unless a column sets its own `sortingFn` (or the table's `defaultColumn` does), the column sorts with
|
|
81
|
+
* `sortingFns.styledDefault` (ASMA-8597, P2f): numbers, dates and booleans by value, ISO date strings by time, other
|
|
82
|
+
* text in the table locale, ties in the data order. Empty cells (`undefined`, `null`, `''`, whitespace, `NaN`, an invalid
|
|
83
|
+
* `Date`) always go last, in both directions. A column with its own `sortingFn`, or one that `defaultColumn: { sortingFn }`
|
|
84
|
+
* covers, is not touched: its comparator, and TanStack's handling of `undefined` before it, stay as they were. A column's own
|
|
85
|
+
* `sortUndefined` only decides where `undefined` goes (TanStack handles it before the comparison); `null`, `''`,
|
|
86
|
+
* whitespace, `NaN` and an invalid `Date` still go last through `styledDefault`. The table's own `sortingFns` are kept
|
|
87
|
+
* beside `styledDefault`.
|
|
88
|
+
*/
|
|
76
89
|
locale?: 'no' | 'en';
|
|
77
90
|
height?: string | number;
|
|
78
91
|
actions?: (row: Row<TData>) => (IAction<TData> | ICustomAction<TData>)[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var E = "styledDefault", v = (e) => e === "no" ? "nb" : e ?? "en", p = /* @__PURE__ */ new Map(), S = (e) => {
|
|
2
|
+
const t = v(e);
|
|
3
|
+
let r = p.get(t);
|
|
4
|
+
return r || (r = new Intl.Collator(t, {
|
|
5
|
+
numeric: !0,
|
|
6
|
+
sensitivity: "base"
|
|
7
|
+
}), p.set(t, r)), r;
|
|
8
|
+
}, D = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?(?:Z|[+-]\d{2}(?::?\d{2})?)?)?$/, y = [
|
|
9
|
+
31,
|
|
10
|
+
28,
|
|
11
|
+
31,
|
|
12
|
+
30,
|
|
13
|
+
31,
|
|
14
|
+
30,
|
|
15
|
+
31,
|
|
16
|
+
31,
|
|
17
|
+
30,
|
|
18
|
+
31,
|
|
19
|
+
30,
|
|
20
|
+
31
|
|
21
|
+
], T = (e) => e % 4 === 0 && e % 100 !== 0 || e % 400 === 0, b = (e, t, r) => t >= 1 && t <= 12 && r >= 1 && r <= (t === 2 && T(e) ? 29 : y[t - 1]), l = (e) => {
|
|
22
|
+
if (!D.test(e) || !b(Number(e.slice(0, 4)), Number(e.slice(5, 7)), Number(e.slice(8, 10)))) return;
|
|
23
|
+
const t = Date.parse(e.replace(" ", "T").replace(",", "."));
|
|
24
|
+
return Number.isNaN(t) ? void 0 : t;
|
|
25
|
+
}, u = (e) => e == null || typeof e == "string" && e.trim() === "" || typeof e == "number" && Number.isNaN(e) || e instanceof Date && Number.isNaN(e.getTime()), f = (e, t) => e < t ? -1 : e > t ? 1 : 0, F = (e, t, r) => {
|
|
26
|
+
if (typeof e == "number" && typeof t == "number") return f(e, t);
|
|
27
|
+
if (e instanceof Date && t instanceof Date) return f(e.getTime(), t.getTime());
|
|
28
|
+
if (typeof e == "boolean" && typeof t == "boolean") return f(Number(e), Number(t));
|
|
29
|
+
if (typeof e == "string" && typeof t == "string") {
|
|
30
|
+
const i = l(e), o = l(t);
|
|
31
|
+
return i !== void 0 && o !== void 0 ? f(i, o) : r.compare(e, t) || 0;
|
|
32
|
+
}
|
|
33
|
+
return r.compare(String(e), String(t)) || 0;
|
|
34
|
+
}, U = (e) => (t, r, i) => {
|
|
35
|
+
const o = t.getValue(i), n = r.getValue(i), s = u(o), a = u(n), d = e();
|
|
36
|
+
if (s || a) {
|
|
37
|
+
if (s && a) return 0;
|
|
38
|
+
const m = d?.getState().sorting.find((N) => N.id === i)?.desc ?? !1, g = d?.getColumn(i)?.columnDef.invertSorting ?? !1, c = (m ? -1 : 1) * (g ? -1 : 1);
|
|
39
|
+
return s ? c : -c;
|
|
40
|
+
}
|
|
41
|
+
return F(o, n, S(d?.options.meta?.locale));
|
|
42
|
+
}, _ = (e, t) => {
|
|
43
|
+
const r = t?.sortingFn, i = t?.sortUndefined !== void 0, o = (n) => {
|
|
44
|
+
if (n.columns?.length) return {
|
|
45
|
+
...n,
|
|
46
|
+
columns: n.columns.map((a) => o(a))
|
|
47
|
+
};
|
|
48
|
+
const s = n.sortingFn ?? r;
|
|
49
|
+
return !(s == null || s === "styledDefault") || n.sortUndefined !== void 0 || i ? n : {
|
|
50
|
+
...n,
|
|
51
|
+
sortUndefined: !1
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
return e.map(o);
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
E as STYLED_DEFAULT_SORTING_FN,
|
|
58
|
+
U as createStyledDefaultSortingFn,
|
|
59
|
+
_ as resolveSortUndefinedDefaults
|
|
60
|
+
};
|