nish-ui 3.0.0 → 3.2.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.
Files changed (89) hide show
  1. package/README.md +11 -8
  2. package/dist/chart.d.ts +8 -3
  3. package/dist/chart.js +4 -419
  4. package/dist/elements-all.js +70 -69
  5. package/dist/elements-charts.d.ts +8 -2
  6. package/dist/elements-charts.js +23 -23
  7. package/dist/elements-data.d.ts +7 -1
  8. package/dist/elements-data.js +5 -5
  9. package/dist/elements-forms.d.ts +7 -1
  10. package/dist/elements-forms.js +20 -19
  11. package/dist/elements.d.ts +7 -1
  12. package/dist/elements.js +4 -4
  13. package/dist/esm/chart-values.js +2 -1
  14. package/dist/esm/combobox-filter.js +6 -5
  15. package/dist/esm/command-filter.js +32 -0
  16. package/dist/esm/components/accordion.js +2 -1
  17. package/dist/esm/components/app-shell.js +1 -1
  18. package/dist/esm/components/avatar.js +2 -2
  19. package/dist/esm/components/breadcrumbs.js +1 -1
  20. package/dist/esm/components/calendar-base.js +1 -1
  21. package/dist/esm/components/canvas/legend.js +4 -4
  22. package/dist/esm/components/canvas/system-canvas.js +24 -1
  23. package/dist/esm/components/carousel.js +21 -3
  24. package/dist/esm/components/charts.js +21 -13
  25. package/dist/esm/components/combobox.js +3 -3
  26. package/dist/esm/components/command.js +5 -5
  27. package/dist/esm/components/data-classes.js +23 -8
  28. package/dist/esm/components/data.js +1 -5
  29. package/dist/esm/components/date-picker.js +1 -0
  30. package/dist/esm/components/date-range-picker.js +1 -0
  31. package/dist/esm/components/display.js +7 -7
  32. package/dist/esm/components/feedback.js +1 -1
  33. package/dist/esm/components/file-dropzone.js +44 -2
  34. package/dist/esm/components/filters.js +3 -1
  35. package/dist/esm/components/flow.js +16 -15
  36. package/dist/esm/components/forms-classes.js +1 -1
  37. package/dist/esm/components/forms.js +30 -6
  38. package/dist/esm/components/hooks.js +20 -17
  39. package/dist/esm/components/inbox.js +13 -8
  40. package/dist/esm/components/layout-vars.js +10 -7
  41. package/dist/esm/components/menu.js +11 -4
  42. package/dist/esm/components/multi-select.js +9 -6
  43. package/dist/esm/components/nav-classes.js +9 -0
  44. package/dist/esm/components/nav.js +2 -1
  45. package/dist/esm/components/overlay-core.js +31 -10
  46. package/dist/esm/components/overlay-dialog.js +17 -2
  47. package/dist/esm/components/pagination.js +4 -1
  48. package/dist/esm/components/popover.js +15 -9
  49. package/dist/esm/components/primitives-classes.js +4 -4
  50. package/dist/esm/components/primitives.js +2 -2
  51. package/dist/esm/components/progress.js +2 -0
  52. package/dist/esm/components/radio-group.js +1 -1
  53. package/dist/esm/components/resource-classes.js +41 -19
  54. package/dist/esm/components/resource.js +8 -6
  55. package/dist/esm/components/settings.js +9 -3
  56. package/dist/esm/components/slider.js +1 -0
  57. package/dist/esm/components/strings.js +9 -1
  58. package/dist/esm/components/tabs.js +3 -2
  59. package/dist/esm/components/tag-input.js +15 -7
  60. package/dist/esm/components/time-field-classes.js +5 -2
  61. package/dist/esm/components/time-field.js +15 -7
  62. package/dist/esm/components/toast-store.js +16 -4
  63. package/dist/esm/components/tooltip.js +1 -1
  64. package/dist/esm/components/url-state.js +3 -1
  65. package/dist/esm/components/virtual-table.js +8 -2
  66. package/dist/esm/components/virtual.js +16 -2
  67. package/dist/esm/format.js +41 -16
  68. package/dist/esm/runtime.js +9 -2
  69. package/dist/esm/server/inbox/client.js +1 -1
  70. package/dist/esm/split-layout.js +2 -1
  71. package/dist/esm/theme.js +66 -6
  72. package/dist/format.js +50 -19
  73. package/dist/inbox-client.d.ts +5 -1
  74. package/dist/inbox-client.js +1 -2
  75. package/dist/index.d.ts +39 -11
  76. package/dist/nish-components.css +52 -3
  77. package/dist/nish-components.min.css +1 -1
  78. package/dist/node/th-check.js +12 -3
  79. package/dist/server/hono.d.ts +2 -2
  80. package/dist/server/hono.js +111 -8
  81. package/dist/server/index.d.ts +20 -12
  82. package/dist/server/index.js +136 -32
  83. package/dist/{spa-BLlMc0eI.d.ts → spa-BfRDo38r.d.ts} +35 -6
  84. package/dist/split-layout.js +2 -2
  85. package/dist/system-canvas.d.ts +0 -4
  86. package/dist/theme.d.ts +20 -2
  87. package/dist/theme.global.js +75 -10
  88. package/dist/theme.js +75 -9
  89. package/package.json +1 -1
@@ -11,6 +11,7 @@ import {
11
11
  import { cn } from "../cn.js";
12
12
  import { ago, dateTime } from "../format.js";
13
13
  import { BREAKPOINTS, NARROW_QUERY, PHONE_QUERY } from "./hooks-classes.js";
14
+ import { shared } from "../runtime.js";
14
15
  import { useNishContext } from "./provider.js";
15
16
  import { jsx } from "react/jsx-runtime";
16
17
  var queries = /* @__PURE__ */ new Map();
@@ -126,41 +127,43 @@ function useNow(intervalMs = 3e4) {
126
127
  }, [intervalMs]);
127
128
  return now;
128
129
  }
129
- var storeSubs = /* @__PURE__ */ new Map();
130
- var memory = /* @__PURE__ */ new Map();
130
+ var local = () => shared("localStorage", () => ({
131
+ subs: /* @__PURE__ */ new Map(),
132
+ memory: /* @__PURE__ */ new Map(),
133
+ listening: false
134
+ }));
131
135
  var warned = /* @__PURE__ */ new Set();
132
- var storageListening = false;
133
136
  function notify(key) {
134
- if (key === null) storeSubs.forEach((set) => set.forEach((fn) => fn()));
135
- else storeSubs.get(key)?.forEach((fn) => fn());
137
+ if (key === null) local().subs.forEach((set) => set.forEach((fn) => fn()));
138
+ else local().subs.get(key)?.forEach((fn) => fn());
136
139
  }
137
140
  function onStorageEvent(e) {
138
- if (e.key !== null) memory.delete(e.key);
139
- else memory.clear();
141
+ if (e.key !== null) local().memory.delete(e.key);
142
+ else local().memory.clear();
140
143
  notify(e.key);
141
144
  }
142
145
  function subscribeKey(key, cb) {
143
146
  if (typeof window === "undefined") return () => {
144
147
  };
145
- let set = storeSubs.get(key);
146
- if (!set) storeSubs.set(key, set = /* @__PURE__ */ new Set());
148
+ let set = local().subs.get(key);
149
+ if (!set) local().subs.set(key, set = /* @__PURE__ */ new Set());
147
150
  const subs = set;
148
151
  subs.add(cb);
149
- if (!storageListening) {
150
- storageListening = true;
152
+ if (!local().listening) {
153
+ local().listening = true;
151
154
  window.addEventListener("storage", onStorageEvent);
152
155
  }
153
156
  return () => {
154
157
  subs.delete(cb);
155
- if (subs.size === 0 && storeSubs.get(key) === subs) storeSubs.delete(key);
156
- if (storeSubs.size === 0 && storageListening) {
157
- storageListening = false;
158
+ if (subs.size === 0 && local().subs.get(key) === subs) local().subs.delete(key);
159
+ if (local().subs.size === 0 && local().listening) {
160
+ local().listening = false;
158
161
  window.removeEventListener("storage", onStorageEvent);
159
162
  }
160
163
  };
161
164
  }
162
165
  function readText(key) {
163
- const kept = memory.get(key);
166
+ const kept = local().memory.get(key);
164
167
  if (kept !== void 0) return kept;
165
168
  try {
166
169
  return window.localStorage.getItem(key);
@@ -195,9 +198,9 @@ function useLocalStorage(key, initial, o = {}) {
195
198
  const out = raw ? String(resolved) : JSON.stringify(resolved);
196
199
  try {
197
200
  window.localStorage.setItem(key, out);
198
- memory.delete(key);
201
+ local().memory.delete(key);
199
202
  } catch {
200
- memory.set(key, out);
203
+ local().memory.set(key, out);
201
204
  }
202
205
  notify(key);
203
206
  },
@@ -9,12 +9,12 @@ import { safeUrl } from "../url.js";
9
9
  import { ChipGroup, Chip } from "./forms.js";
10
10
  import { StatusDot } from "./display.js";
11
11
  import { EmptyState, ErrorState, SkeletonRows } from "./feedback.js";
12
- import { RelativeTime, useMediaQuery } from "./hooks.js";
12
+ import { RelativeTime, useMediaQuery, useNow } from "./hooks.js";
13
13
  import { CheckIcon, ClockIcon, MoreIcon } from "./icons.js";
14
14
  import { DropdownMenu, MenuItem, MenuLabel, MenuSeparator } from "./menu.js";
15
15
  import { ConfirmDialog } from "./modal.js";
16
16
  import { Button, Card, IconButton } from "./primitives.js";
17
- import { useStrings } from "./provider.js";
17
+ import { useNishContext, useStrings } from "./provider.js";
18
18
  import { INBOX_STRINGS, SHELL_STRINGS, STATUS_STRINGS, OVERLAY_STRINGS } from "./strings.js";
19
19
  import { Tabs } from "./tabs.js";
20
20
  import { DEFAULT_INBOX_LABELS } from "./inbox-classes.js";
@@ -42,15 +42,17 @@ var SNOOZE_OPTIONS = [
42
42
  function looksClamped(body) {
43
43
  return body.length > 100 || body.split("\n").length > 3;
44
44
  }
45
- function lastActionText(result, item, labels) {
45
+ function lastActionText(result, item, labels, now, locale) {
46
46
  const label = item.actions?.find((a) => a.id === result.actionId)?.label ?? result.actionId;
47
47
  const ms = Date.parse(result.at);
48
- const at = new Date(ms).toDateString() === (/* @__PURE__ */ new Date()).toDateString() ? time(ms) : dateTime(ms);
48
+ const at = new Date(ms).toDateString() === new Date(now).toDateString() ? time(ms, { locale }) : dateTime(ms, { locale });
49
49
  if (result.ok) return labels.actionRan(label, at);
50
50
  const why = result.error ?? (result.status != null ? `HTTP ${result.status}` : null);
51
51
  return labels.actionFailed(label, at, why);
52
52
  }
53
53
  function Row({ item, view, label, wide, selected, expanded, domId, onToggle, onHandle, onUnhandle, onSnooze, onUnsnooze, running, onAction, labels, strings }) {
54
+ const { locale } = useNishContext();
55
+ const clock = useNow();
54
56
  const severity = item.severity in DOT_TONE ? item.severity : "normal";
55
57
  const dot = { tone: DOT_TONE[severity], label: labels[severity] };
56
58
  const long = item.body != null && looksClamped(item.body);
@@ -92,10 +94,10 @@ function Row({ item, view, label, wide, selected, expanded, domId, onToggle, onH
92
94
  },
93
95
  a.id
94
96
  )) }) : null,
95
- last && (actions.length > 0 || view === "handled") ? /* @__PURE__ */ jsx("p", { className: cn("m-0 mt-1 text-xs", last.ok ? "text-th-hi3" : "text-th-loss"), children: lastActionText(last, item, labels) }) : null,
96
- view === "snoozed" && item.snoozedUntil ? /* @__PURE__ */ jsx("p", { className: "m-0 mt-0.5 text-xs text-th-hi3", children: labels.until(dateTime(item.snoozedUntil)) }) : null,
97
+ last && (actions.length > 0 || view === "handled") ? /* @__PURE__ */ jsx("p", { className: cn("m-0 mt-1 text-xs", last.ok ? "text-th-hi3" : "text-th-loss"), children: lastActionText(last, item, labels, clock, locale) }) : null,
98
+ view === "snoozed" && item.snoozedUntil ? /* @__PURE__ */ jsx("p", { className: "m-0 mt-0.5 text-xs text-th-hi3", children: labels.until(dateTime(item.snoozedUntil, { locale })) }) : null,
97
99
  view === "handled" && item.handledAt ? /* @__PURE__ */ jsxs("p", { className: "m-0 mt-0.5 text-xs text-th-hi3", children: [
98
- labels.handledAgo(ago(item.handledAt)),
100
+ labels.handledAgo(ago(item.handledAt, { now: clock, locale })),
99
101
  item.handledBy === "source" ? labels.handledByApp : item.handledBy === "expired" ? labels.handledAutomatically : ""
100
102
  ] }) : null
101
103
  ] }),
@@ -145,7 +147,10 @@ function Inbox({
145
147
  ...rest
146
148
  }) {
147
149
  const strings = useInboxStrings();
148
- const labels = { ...DEFAULT_INBOX_LABELS, ...labelOverrides };
150
+ const labels = {
151
+ ...DEFAULT_INBOX_LABELS,
152
+ ...Object.fromEntries(Object.entries(labelOverrides ?? {}).filter(([, v]) => v !== void 0))
153
+ };
149
154
  const idBase = useId().replace(/:/g, "");
150
155
  const wide = useMediaQuery("(min-width: 480px)");
151
156
  const [expanded, setExpanded] = useState(() => /* @__PURE__ */ new Set());
@@ -2,10 +2,11 @@
2
2
 
3
3
  // src/components/layout-vars.ts
4
4
  import { useEffect, useState } from "react";
5
+ import { shared } from "../runtime.js";
5
6
  import { mountStuck } from "../theme.js";
6
- var heightOwners = /* @__PURE__ */ new Map();
7
+ var heightOwnersMap = () => shared("heightVars", () => /* @__PURE__ */ new Map());
7
8
  function applyHeightVar(name) {
8
- const owners = heightOwners.get(name);
9
+ const owners = heightOwnersMap().get(name);
9
10
  const root = document.documentElement;
10
11
  const max = owners ? Math.max(0, ...owners.values()) : 0;
11
12
  if (max > 0) root.style.setProperty(name, `${max}px`);
@@ -16,8 +17,8 @@ function useHeightVar(ref, name, enabled = true) {
16
17
  const el = ref.current;
17
18
  if (!enabled || !el || typeof document === "undefined") return;
18
19
  const owner = {};
19
- let owners = heightOwners.get(name);
20
- if (!owners) heightOwners.set(name, owners = /* @__PURE__ */ new Map());
20
+ let owners = heightOwnersMap().get(name);
21
+ if (!owners) heightOwnersMap().set(name, owners = /* @__PURE__ */ new Map());
21
22
  const write = () => {
22
23
  owners.set(owner, el.offsetHeight);
23
24
  applyHeightVar(name);
@@ -34,7 +35,7 @@ function useHeightVar(ref, name, enabled = true) {
34
35
  ro?.disconnect();
35
36
  window.removeEventListener("resize", write);
36
37
  owners.delete(owner);
37
- if (owners.size === 0) heightOwners.delete(name);
38
+ if (owners.size === 0) heightOwnersMap().delete(name);
38
39
  applyHeightVar(name);
39
40
  };
40
41
  }, [ref, name, enabled]);
@@ -58,8 +59,10 @@ function useScrollEdges(ref) {
58
59
  if (!el) return;
59
60
  const update = () => {
60
61
  const max = el.scrollWidth - el.clientWidth;
61
- el.dataset.atStart = String(el.scrollLeft <= 1);
62
- el.dataset.atEnd = String(max <= 1 || el.scrollLeft >= max - 1);
62
+ const rtl = getComputedStyle(el).direction === "rtl";
63
+ const left = rtl ? el.scrollLeft + max : el.scrollLeft;
64
+ el.dataset.atStart = String(left <= 1);
65
+ el.dataset.atEnd = String(max <= 1 || left >= max - 1);
63
66
  };
64
67
  update();
65
68
  el.addEventListener("scroll", update, { passive: true });
@@ -14,6 +14,7 @@ import { MENU_ROW, PHONE_QUERY, menuItemClass } from "./overlay-classes.js";
14
14
  import { layerHost, setRef, useMergedRef } from "./overlay-core.js";
15
15
  import { useAnchoredPosition, floatingStyle, useDismiss, useReturnFocus } from "./overlay-position.js";
16
16
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
17
+ var InlineMenuItemContext = /* @__PURE__ */ createContext(false);
17
18
  var MenuContext = /* @__PURE__ */ createContext(null);
18
19
  var drawerModule = /* @__PURE__ */ lazyModule(() => import("./drawer.js"));
19
20
  var ITEM_SELECTOR = '[role="menuitem"]:not([aria-disabled="true"])';
@@ -228,6 +229,7 @@ function MenuItem({
228
229
  ...rest
229
230
  }) {
230
231
  const ctx = useContext(MenuContext);
232
+ const inline = useContext(InlineMenuItemContext);
231
233
  function select() {
232
234
  if (disabled) return;
233
235
  const ev = new Event("nish-menu-select", { cancelable: true });
@@ -240,24 +242,28 @@ function MenuItem({
240
242
  ...rest,
241
243
  ref,
242
244
  type: "button",
243
- role: "menuitem",
244
- tabIndex: -1,
245
+ role: inline ? void 0 : "menuitem",
246
+ tabIndex: inline ? void 0 : -1,
245
247
  "aria-disabled": disabled || void 0,
246
248
  "aria-current": active || void 0,
247
249
  "data-disabled": disabled ? "" : void 0,
248
250
  onClick: (e) => {
251
+ if (disabled) {
252
+ e.preventDefault();
253
+ return;
254
+ }
249
255
  onClick?.(e);
250
256
  if (!e.defaultPrevented) select();
251
257
  },
252
258
  onMouseMove: (e) => {
253
259
  onMouseMove?.(e);
254
- if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
260
+ if (!inline && !disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
255
261
  },
256
262
  className: menuItemClass({
257
263
  active,
258
264
  danger,
259
265
  disabled,
260
- className: cn(!disabled && (danger ? "focus:bg-th-loss-soft" : "focus:bg-th-overlay focus:text-th-hi"), className)
266
+ className: cn(!inline && !disabled && (danger ? "focus:bg-th-loss-soft" : "focus:bg-th-overlay focus:text-th-hi"), className)
261
267
  }),
262
268
  children: [
263
269
  icon ? /* @__PURE__ */ jsx("span", { className: cn("inline-flex shrink-0", danger || disabled ? "" : "text-th-hi3"), children: icon }) : null,
@@ -336,6 +342,7 @@ function MenuSubHeader({ onBack, children, className, ref, onKeyDown, ...rest })
336
342
  export {
337
343
  DropdownMenu,
338
344
  ITEM_SELECTOR,
345
+ InlineMenuItemContext,
339
346
  MenuContext,
340
347
  MenuItem,
341
348
  MenuLabel,
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/multi-select.tsx
4
- import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
4
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
5
5
  import { cn } from "../cn.js";
6
6
  import { CheckIcon, XIcon } from "./icons.js";
7
7
  import { Spinner } from "./feedback.js";
@@ -10,7 +10,7 @@ import { fieldClass } from "./primitives.js";
10
10
  import { useStrings } from "./provider.js";
11
11
  import { FIELD_STRINGS, MULTI_SELECT_STRINGS } from "./strings.js";
12
12
  import { indexComboboxOptions, setRef } from "./forms-classes.js";
13
- import { COMBOBOX_DEBOUNCE_MS, COMBOBOX_MAX_SHOWN } from "../combobox-filter.js";
13
+ import { COMBOBOX_DEBOUNCE_MS, COMBOBOX_MAX_SHOWN, matchesComboboxNeedle } from "../combobox-filter.js";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
15
15
  var defaultResultsText = (n) => `${n} ${n === 1 ? "result" : "results"}`;
16
16
  function MultiSelect({
@@ -86,7 +86,7 @@ function MultiSelect({
86
86
  if (needle && !serverFiltered) {
87
87
  if (filter) {
88
88
  if (!filter(it.option, text)) continue;
89
- } else if (!it.label.includes(needle) && !(it.hint?.includes(needle) ?? false)) continue;
89
+ } else if (!matchesComboboxNeedle(it.label, it.hint, needle)) continue;
90
90
  }
91
91
  out.push(it.option);
92
92
  }
@@ -114,11 +114,11 @@ function MultiSelect({
114
114
  }, [open, current]);
115
115
  const toOption = (v) => options.find((o) => o.value === v) ?? seen[v] ?? { value: v, label: v };
116
116
  const labelOf = (v) => toOption(v).label;
117
- const close = useCallback(() => {
117
+ const close = () => {
118
118
  setOpen(false);
119
119
  setActive(-1);
120
120
  setArmed(false);
121
- }, []);
121
+ };
122
122
  const queryChanged = (q) => {
123
123
  if (!onQueryChange) return;
124
124
  window.clearTimeout(debounceRef.current);
@@ -268,7 +268,10 @@ function MultiSelect({
268
268
  rest.onBlur?.(e);
269
269
  if (!e.currentTarget.contains(e.relatedTarget)) {
270
270
  close();
271
- setText("");
271
+ if (text !== "") {
272
+ setText("");
273
+ queryChanged("");
274
+ }
272
275
  }
273
276
  },
274
277
  className: cn("relative w-full min-w-0", className),
@@ -0,0 +1,9 @@
1
+ // src/components/nav-classes.ts
2
+ import { cn } from "../cn.js";
3
+ import { FOCUS } from "./nav-items.js";
4
+ function navRailItemClass(active) {
5
+ return cn("group flex min-h-14 w-full flex-col items-center justify-center gap-0.5 text-2xs leading-tight", FOCUS, active ? "font-medium text-th-accent" : "text-th-hi3 hover:text-th-hi");
6
+ }
7
+ export {
8
+ navRailItemClass
9
+ };
@@ -14,6 +14,7 @@ import { chipClass } from "./forms.js";
14
14
  import { useMediaQuery } from "./hooks.js";
15
15
  import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "./icons.js";
16
16
  import { useHeightVar, useScrollEdges } from "./layout-vars.js";
17
+ import { navRailItemClass } from "./nav-classes.js";
17
18
  import { NavBadge, FOCUS, renderItem, useEndSide, visibleNavItems } from "./nav-items.js";
18
19
  import { IconButton } from "./primitives.js";
19
20
  import { useStrings } from "./provider.js";
@@ -136,7 +137,7 @@ function NavRail({
136
137
  shown.map((item) => {
137
138
  const node = renderItem(
138
139
  item,
139
- cn("group flex min-h-14 w-full flex-col items-center justify-center gap-0.5 text-2xs leading-tight", FOCUS, item.active ? "font-medium text-th-accent" : "text-th-hi3 hover:text-th-hi"),
140
+ navRailItemClass(!!item.active),
140
141
  /* @__PURE__ */ jsxs(Fragment2, { children: [
141
142
  /* @__PURE__ */ jsxs(
142
143
  "span",
@@ -77,20 +77,27 @@ function syncInert() {
77
77
  inerted.clear();
78
78
  return;
79
79
  }
80
- for (const el of Array.from(document.body.children)) {
81
- const skip = el === top || el.contains(top) || el.hasAttribute("data-nish-keep-active");
82
- if (skip) {
83
- if (inerted.has(el)) {
84
- el.inert = false;
85
- el.removeAttribute("inert");
86
- inerted.delete(el);
87
- }
80
+ const keeps = top.style.bottom !== "" ? Array.from(document.querySelectorAll("[data-nish-bar]")).filter((b) => !top.contains(b) && !b.contains(top)) : [];
81
+ const release = (el) => {
82
+ if (inerted.has(el)) {
83
+ el.inert = false;
84
+ el.removeAttribute("inert");
85
+ inerted.delete(el);
86
+ }
87
+ };
88
+ const visit = (el) => {
89
+ if (el === top || el.contains(top) || el.hasAttribute("data-nish-keep-active") || keeps.includes(el)) {
90
+ release(el);
91
+ } else if (keeps.some((k) => el.contains(k))) {
92
+ release(el);
93
+ for (const child of Array.from(el.children)) visit(child);
88
94
  } else if (!el.inert) {
89
95
  el.inert = true;
90
96
  el.setAttribute("inert", "");
91
97
  inerted.add(el);
92
98
  }
93
- }
99
+ };
100
+ for (const el of Array.from(document.body.children)) visit(el);
94
101
  }
95
102
  function pushInert(scrim) {
96
103
  const { dialogPortals } = ov();
@@ -112,7 +119,21 @@ function prefersReducedMotion() {
112
119
  var closeVetoes = /* @__PURE__ */ new WeakMap();
113
120
  var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
114
121
  function focusables(root) {
115
- return Array.from(root.querySelectorAll(FOCUSABLE)).filter((n) => n.offsetParent !== null);
122
+ const all = Array.from(root.querySelectorAll(FOCUSABLE));
123
+ const radios = (n) => Array.from((n.form ?? root).querySelectorAll('input[type="radio"]')).filter((r) => r.name === n.name && !r.disabled);
124
+ return all.filter((n) => {
125
+ if (n.offsetParent === null) return false;
126
+ const ti = n.getAttribute("tabindex");
127
+ if (ti !== null && Number.parseInt(ti, 10) < 0) return false;
128
+ if (n.closest("[inert]")) return false;
129
+ if (typeof n.checkVisibility === "function" && !n.checkVisibility({ visibilityProperty: true })) return false;
130
+ if (n instanceof HTMLInputElement && n.type === "radio" && n.name) {
131
+ const group = radios(n);
132
+ const checked = group.find((r) => r.checked);
133
+ return checked ? n === checked : n === group[0];
134
+ }
135
+ return true;
136
+ });
116
137
  }
117
138
  function lockScroll() {
118
139
  const s = ov();
@@ -137,7 +137,11 @@ function useSheetExit(onClose, canClose, onOpenChange) {
137
137
  fire();
138
138
  }, [fire]);
139
139
  const isClosing = useCallback(() => closingRef.current, []);
140
- const allowClose = useCallback(() => !canCloseRef.current || canCloseRef.current(), [canCloseRef]);
140
+ const allowClose = useCallback(() => {
141
+ const handler = onCloseRef.current;
142
+ if (handler && closeVetoes.get(handler)?.()) return false;
143
+ return !canCloseRef.current || canCloseRef.current();
144
+ }, [canCloseRef, onCloseRef]);
141
145
  return { closing, requestClose, closeNow, isClosing, allowClose };
142
146
  }
143
147
  function useSheetSwipe(panelRef, scrimRef, enabled, onDismiss, allow = () => true) {
@@ -202,7 +206,18 @@ function useSheetSwipe(panelRef, scrimRef, enabled, onDismiss, allow = () => tru
202
206
  if (dismiss) {
203
207
  panel.style.transform = "translateY(100%)";
204
208
  if (scrim) scrim.style.opacity = "0";
205
- timer.current = window.setTimeout(() => dismissRef.current(), ms);
209
+ timer.current = window.setTimeout(() => {
210
+ dismissRef.current();
211
+ timer.current = window.setTimeout(() => {
212
+ if (!panel.isConnected) return;
213
+ panel.style.transform = "";
214
+ panel.style.transition = "";
215
+ if (scrim) {
216
+ scrim.style.opacity = "";
217
+ scrim.style.transition = "";
218
+ }
219
+ }, 100);
220
+ }, ms);
206
221
  } else {
207
222
  panel.style.transform = "translateY(0)";
208
223
  if (scrim) scrim.style.opacity = "1";
@@ -109,7 +109,10 @@ function Pagination({
109
109
  "aria-current": current ? "page" : void 0,
110
110
  "data-state": state,
111
111
  children,
112
- onClick: () => go(target)
112
+ onClick: (event) => {
113
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
114
+ go(target);
115
+ }
113
116
  };
114
117
  return /* @__PURE__ */ jsx("li", { children: renderLink(target, props) }, key);
115
118
  }
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/popover.tsx
4
- import { useEffect } from "react";
4
+ import { useEffect, useState } from "react";
5
5
  import { createPortal } from "react-dom";
6
6
  import { cn } from "../cn.js";
7
- import { useIsClient } from "./client.js";
7
+ import { useIsClient, useIsoLayoutEffect } from "./client.js";
8
8
  import { useLatest } from "./latest.js";
9
9
  import { useNishContext } from "./provider.js";
10
10
  import { focusables, layerHost, useMergedRef } from "./overlay-core.js";
@@ -29,23 +29,29 @@ function Popover({
29
29
  const config = useNishContext();
30
30
  const isClient = useIsClient();
31
31
  const [panelRef, setPanelRef] = useMergedRef(ref);
32
- const pos = useAnchoredPosition(anchor, panelRef, open, side, align);
32
+ const [host, setHost] = useState(null);
33
+ useIsoLayoutEffect(() => {
34
+ const next = open ? layerHost(anchor.current, config.portalContainer) : null;
35
+ setHost((prev) => prev === next ? prev : next);
36
+ }, [open, anchor, config.portalContainer]);
37
+ const shown = open && host != null;
38
+ const pos = useAnchoredPosition(anchor, panelRef, shown, side, align);
33
39
  const onOpenChangeRef = useLatest(onOpenChange);
34
40
  const outsideRef = useLatest(dismissOnOutside);
35
- useDismiss(open, panelRef, anchor, (reason) => {
41
+ useDismiss(shown, panelRef, anchor, (reason) => {
36
42
  if (reason === "outside" && !outsideRef.current) return;
37
43
  onOpenChangeRef.current(false, reason);
38
44
  });
39
- useReturnFocus(open, panelRef, anchor);
45
+ useReturnFocus(shown, panelRef, anchor);
40
46
  useEffect(() => {
41
- if (!open) return;
47
+ if (!shown) return;
42
48
  const t = window.setTimeout(() => {
43
49
  const p = panelRef.current;
44
50
  if (p && !p.contains(document.activeElement)) (p.querySelector("[data-autofocus],[autofocus]") ?? p).focus();
45
51
  }, 0);
46
52
  return () => window.clearTimeout(t);
47
- }, [open, panelRef]);
48
- if (!open || !isClient) return null;
53
+ }, [shown, panelRef]);
54
+ if (!open || !isClient || !host) return null;
49
55
  function onKeyDown(e) {
50
56
  userKeyDown?.(e);
51
57
  if (e.key !== "Tab" || !panelRef.current) return;
@@ -84,7 +90,7 @@ function Popover({
84
90
  children
85
91
  }
86
92
  ),
87
- layerHost(anchor.current, config.portalContainer)
93
+ host
88
94
  );
89
95
  }
90
96
  export {
@@ -10,9 +10,9 @@ var BUTTON_VARIANT = {
10
10
  link: "h-auto p-0 font-medium text-th-accent underline-offset-2 hover:underline"
11
11
  };
12
12
  var BUTTON_SIZE = {
13
- xs: "h-6 gap-1 px-2 text-2xs pointer-coarse:min-h-11",
14
- sm: "h-7 gap-1.5 px-2.5 text-xs pointer-coarse:min-h-11",
15
- md: "h-9 gap-2 px-3.5 text-sm pointer-coarse:min-h-11",
13
+ xs: "h-6 gap-1 px-2 text-2xs pointer-coarse:min-h-11 pointer-coarse:min-w-11",
14
+ sm: "h-7 gap-1.5 px-2.5 text-xs pointer-coarse:min-h-11 pointer-coarse:min-w-11",
15
+ md: "h-9 gap-2 px-3.5 text-sm pointer-coarse:min-h-11 pointer-coarse:min-w-11",
16
16
  lg: "h-11 gap-2 px-5 text-base"
17
17
  };
18
18
  var LINK_SIZE = {
@@ -24,7 +24,7 @@ var LINK_SIZE = {
24
24
  var BUTTON_BASE = "inline-flex shrink-0 select-none items-center justify-center whitespace-nowrap rounded-lg font-medium transition-[color,background-color,border-color,transform] duration-150";
25
25
  var BUTTON_FORCED = "forced-colors:border forced-colors:border-[ButtonText]";
26
26
  var PRESS = "pointer-coarse:not-disabled:active:scale-[0.97]";
27
- var LINK_HIT = "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-2 pointer-coarse:after:-inset-y-3 pointer-coarse:after:content-['']";
27
+ var LINK_HIT = "pointer-coarse:relative pointer-coarse:after:absolute pointer-coarse:after:-inset-x-2 pointer-coarse:after:-inset-y-3.5 pointer-coarse:after:content-['']";
28
28
  var BUTTON_DISABLED = "disabled:pointer-events-none disabled:border disabled:border-th-line disabled:bg-th-elevated disabled:text-th-ghost disabled:shadow-none forced-colors:disabled:border-[GrayText] forced-colors:disabled:text-[GrayText]";
29
29
  var LINK_DISABLED = "disabled:pointer-events-none disabled:text-th-ghost disabled:no-underline forced-colors:disabled:text-[GrayText]";
30
30
  function buttonClass({ variant = "secondary", size = "md", inline = false, className } = {}) {
@@ -104,7 +104,7 @@ function IconButton({
104
104
  disabled,
105
105
  "aria-label": label,
106
106
  title: label,
107
- "aria-pressed": pressed || void 0,
107
+ "aria-pressed": active === void 0 ? void 0 : pressed,
108
108
  "data-state": active === void 0 ? void 0 : pressed ? "active" : "inactive",
109
109
  "data-disabled": disabled ? "" : void 0,
110
110
  className: iconButtonClass({ size, variant, tone, active: pressed, className }),
@@ -212,7 +212,7 @@ function Input({ invalid, size = "md", leading, trailing, wrapperClassName, clas
212
212
  {
213
213
  ref,
214
214
  "aria-invalid": invalid || void 0,
215
- className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8", className) }),
215
+ className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8 pointer-coarse:pe-12", className) }),
216
216
  ...rest
217
217
  }
218
218
  );
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  // src/components/progress.tsx
2
4
  import { useId } from "react";
3
5
  import { cn } from "../cn.js";
@@ -148,7 +148,7 @@ function Radio({ value, label, description, className, disabled, required, name,
148
148
  name: name ?? ctx?.name,
149
149
  disabled: off,
150
150
  required: required ?? ctx?.required,
151
- "aria-describedby": description != null ? descId : rest["aria-describedby"],
151
+ "aria-describedby": [description != null ? descId : null, rest["aria-describedby"]].filter(Boolean).join(" ") || void 0,
152
152
  onChange: (e) => {
153
153
  onChange?.(e);
154
154
  if (e.target.checked) ctx?.select(value);
@@ -1,4 +1,5 @@
1
1
  // src/components/resource-classes.ts
2
+ import { shared } from "../runtime.js";
2
3
  var ApiError = class extends Error {
3
4
  /** HTTP status; 0 = network failure or abort-by-timeout. */
4
5
  status;
@@ -17,12 +18,12 @@ var ApiError = class extends Error {
17
18
  return this.status === 0 || this.status >= 500;
18
19
  }
19
20
  };
20
- var config = {};
21
+ var store = shared("api", () => ({ config: {} }));
21
22
  function configureApi(c) {
22
- config = { ...config, ...c };
23
+ store.config = { ...store.config, ...c };
23
24
  }
24
25
  function isRawBody(b) {
25
- return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
26
+ return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || typeof ReadableStream !== "undefined" && b instanceof ReadableStream || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
26
27
  }
27
28
  var ERROR_CODE = /^[a-z0-9_]+$/;
28
29
  function errorMessage(body, status) {
@@ -44,30 +45,51 @@ function excerpt(text, max = 120) {
44
45
  }
45
46
  var SCHEME = /^[a-z][a-z0-9+.-]*:/i;
46
47
  function isTrustedOrigin(url) {
47
- const relative = !SCHEME.test(url) && !url.startsWith("//");
48
- if (relative) return true;
49
- const here = typeof location !== "undefined" ? location.href : void 0;
50
- try {
51
- const target = new URL(url, here);
52
- if (here && target.origin === new URL(here).origin) return true;
53
- if (config.baseUrl && SCHEME.test(config.baseUrl) && target.origin === new URL(config.baseUrl).origin) return true;
54
- } catch {
55
- return false;
48
+ const bases = [];
49
+ if (typeof document !== "undefined" && document.baseURI) bases.push(document.baseURI);
50
+ if (typeof location !== "undefined" && location.href) bases.push(location.href);
51
+ for (const here of bases) {
52
+ try {
53
+ const target = new URL(url, here);
54
+ if (target.origin !== "null" && target.origin === new URL(here).origin) return true;
55
+ if (store.config.baseUrl && SCHEME.test(store.config.baseUrl) && target.origin === new URL(store.config.baseUrl).origin) return true;
56
+ return false;
57
+ } catch {
58
+ }
56
59
  }
57
- return false;
60
+ return isRelativePath(url);
61
+ }
62
+ function isRelativePath(url) {
63
+ let i = 0;
64
+ while (i < url.length && (url[i] === " " || url[i] === " ")) i++;
65
+ const rest = url.slice(i);
66
+ if (SCHEME.test(rest)) return false;
67
+ const a = rest[0];
68
+ const b = rest[1];
69
+ const isSlash = (c) => c === "/" || c === "\\";
70
+ if (a === "\\") return false;
71
+ if (a === "/" && isSlash(b)) return false;
72
+ const squeezed = rest.replace(/[\t\n\r]/g, "");
73
+ if (isSlash(squeezed[0]) && isSlash(squeezed[1])) return false;
74
+ if (SCHEME.test(squeezed)) return false;
75
+ return true;
58
76
  }
59
77
  async function apiFetch(path, o = {}) {
60
78
  const { body, timeoutMs = 15e3, nullOn404, signal: callerSignal, headers: extraHeaders, ...init } = o;
61
- const url = path.startsWith("/") && config.baseUrl ? config.baseUrl + path : path;
79
+ const url = path.startsWith("/") && store.config.baseUrl ? store.config.baseUrl + path : path;
62
80
  const headers = new Headers({ accept: "application/json" });
63
- if (config.headers && (isTrustedOrigin(url) || config.headersFor?.(url) === true)) {
64
- for (const [k, v] of Object.entries(config.headers())) headers.set(k, v);
81
+ if (store.config.headers && (isTrustedOrigin(url) || store.config.headersFor?.(url) === true)) {
82
+ for (const [k, v] of Object.entries(store.config.headers())) headers.set(k, v);
65
83
  }
66
84
  if (extraHeaders) new Headers(extraHeaders).forEach((v, k) => headers.set(k, v));
67
85
  let payload;
68
86
  if (body !== void 0) {
69
- if (isRawBody(body)) payload = body;
70
- else {
87
+ if (isRawBody(body)) {
88
+ payload = body;
89
+ if (typeof ReadableStream !== "undefined" && body instanceof ReadableStream && !("duplex" in init)) {
90
+ init.duplex = "half";
91
+ }
92
+ } else {
71
93
  payload = JSON.stringify(body);
72
94
  if (!headers.has("content-type")) headers.set("content-type", "application/json");
73
95
  }
@@ -108,7 +130,7 @@ async function apiFetch(path, o = {}) {
108
130
  if (!res.ok) {
109
131
  if (res.status === 404 && nullOn404) return null;
110
132
  const err = new ApiError(errorMessage(parsed, res.status), { status: res.status, body: parsed, url });
111
- if (res.status === 401) config.onUnauthorized?.(err);
133
+ if (res.status === 401) store.config.onUnauthorized?.(err);
112
134
  throw err;
113
135
  }
114
136
  if (res.status === 204 || text === "") return void 0;