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
@@ -70,6 +70,7 @@ function useResource(key, fetcher, o = {}) {
70
70
  }));
71
71
  const fetcherRef = useLatest(fetcher);
72
72
  const keyRef = useLatest(key);
73
+ const activeRef = useLatest(active);
73
74
  const keepPrevRef = useLatest(keepPrevious);
74
75
  const initialRef = useLatest(o.initialData);
75
76
  const ctlRef = useRef(null);
@@ -81,7 +82,7 @@ function useResource(key, fetcher, o = {}) {
81
82
  const load = useCallback(
82
83
  async (fresh = false) => {
83
84
  const k = keyRef.current;
84
- if (k === null) return;
85
+ if (k === null || !activeRef.current) return;
85
86
  ctlRef.current?.abort();
86
87
  const ctl = new AbortController();
87
88
  ctlRef.current = ctl;
@@ -95,7 +96,8 @@ function useResource(key, fetcher, o = {}) {
95
96
  error: void 0,
96
97
  updatedAt: keepPrevRef.current ? s.updatedAt : void 0,
97
98
  fetching: true,
98
- settled: s.settled
99
+ settled: s.settled,
100
+ loaded: false
99
101
  }
100
102
  );
101
103
  try {
@@ -104,10 +106,10 @@ function useResource(key, fetcher, o = {}) {
104
106
  if (run !== runRef.current || ctl.signal.aborted) return;
105
107
  failuresRef.current = 0;
106
108
  if (mutatedRef.current !== mutatedAtStart) {
107
- setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1 }));
109
+ setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1, loaded: true }));
108
110
  return;
109
111
  }
110
- setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1 }));
112
+ setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1, loaded: true }));
111
113
  } catch (e) {
112
114
  if (run !== runRef.current || ctl.signal.aborted) return;
113
115
  failuresRef.current++;
@@ -115,7 +117,7 @@ function useResource(key, fetcher, o = {}) {
115
117
  setState((s) => ({ ...s, key: k, error: error2, fetching: false, settled: s.settled + 1 }));
116
118
  }
117
119
  },
118
- [fetcherRef, initialRef, keepPrevRef, keyRef]
120
+ [activeRef, fetcherRef, initialRef, keepPrevRef, keyRef]
119
121
  );
120
122
  useEffect(() => {
121
123
  if (!active) return;
@@ -193,7 +195,7 @@ function useResource(key, fetcher, o = {}) {
193
195
  return {
194
196
  data,
195
197
  error,
196
- loading: active && data === void 0 && error === void 0,
198
+ loading: active && data === void 0 && error === void 0 && !(sameKey && state.loaded),
197
199
  refreshing: state.fetching || active && !sameKey,
198
200
  updatedAt,
199
201
  stale,
@@ -124,7 +124,11 @@ function useSaveStatus() {
124
124
  const tone = status === "saved" ? "ok" : status === "error" ? "error" : "muted";
125
125
  return { status, error, label, tone, run };
126
126
  }
127
- var parseDraft = (text) => Number(text.trim().replace(/,/g, "").replace(/\u2212/g, "-"));
127
+ var parseDraft = (text) => {
128
+ const t = text.trim().replace(/,/g, "").replace(/\u2212/g, "-");
129
+ const n = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/.test(t) ? Number(t) : NaN;
130
+ return Number.isFinite(n) ? n : NaN;
131
+ };
128
132
  var fmt = (v) => v == null ? "" : String(v);
129
133
  var decimals = (n) => String(n).split(".")[1]?.length ?? 0;
130
134
  function NumberField({
@@ -153,6 +157,7 @@ function NumberField({
153
157
  const [pending, setPending] = useState(false);
154
158
  const draftRef = useRef(draft);
155
159
  const lastSent = useRef(null);
160
+ const seq = useRef(0);
156
161
  const mounted = useRef(true);
157
162
  const skipCommit = useRef(false);
158
163
  const setDraft = (next) => {
@@ -205,6 +210,7 @@ function NumberField({
205
210
  if (lastSent.current && lastSent.current.v === next) return;
206
211
  setError(null);
207
212
  lastSent.current = { v: next };
213
+ const mine = ++seq.current;
208
214
  let result;
209
215
  try {
210
216
  result = onCommit(next);
@@ -216,10 +222,10 @@ function NumberField({
216
222
  setPending(true);
217
223
  result.then(
218
224
  () => {
219
- if (mounted.current) setPending(false);
225
+ if (mounted.current && mine === seq.current) setPending(false);
220
226
  },
221
227
  (e) => {
222
- if (!mounted.current) return;
228
+ if (!mounted.current || mine !== seq.current) return;
223
229
  setPending(false);
224
230
  fail(e);
225
231
  }
@@ -114,6 +114,7 @@ function Slider({
114
114
  const handlePointerDown = (e) => {
115
115
  onPointerDown?.(e);
116
116
  if (e.defaultPrevented || disabled || e.button !== 0) return;
117
+ e.preventDefault();
117
118
  const v = valueAt(e.clientX);
118
119
  const cur = live.current;
119
120
  let i = 0;
@@ -63,7 +63,8 @@ var FIELD_STRINGS = {
63
63
  clear: "Clear",
64
64
  noMatches: "No matches",
65
65
  searching: "Searching\u2026",
66
- removeTag: (tag) => `Remove ${tag}`
66
+ removeTag: (tag) => `Remove ${tag}`,
67
+ maxTags: (max) => `You can add up to ${max}`
67
68
  };
68
69
  var FILTER_STRINGS = {
69
70
  filters: "Filters",
@@ -113,6 +114,7 @@ var COMMAND_STRINGS = {
113
114
  var TABLE_STRINGS = {
114
115
  sortAnnounce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
115
116
  sortBy: "Sort by",
117
+ sortToggle: (dir) => dir === "desc" ? "Sorted descending, switch to ascending" : "Sorted ascending, switch to descending",
116
118
  sortDefault: "Default"
117
119
  };
118
120
  var SETTINGS_STRINGS = {
@@ -135,6 +137,12 @@ var PROGRESS_STRINGS = {
135
137
  progressIndeterminate: "Loading"
136
138
  };
137
139
  var FLOW_STRINGS = {
140
+ agentQueued: "Queued",
141
+ agentRunning: "Running",
142
+ agentDone: "Done",
143
+ agentFailed: "Failed",
144
+ stepDone: ", done",
145
+ stepFailed: ", failed",
138
146
  workflow: "Workflow",
139
147
  activity: "Activity",
140
148
  other: "Other",
@@ -53,8 +53,9 @@ function ScrollingList({
53
53
  return /* @__PURE__ */ jsx("div", { ref: setRef, ...rest, children });
54
54
  }
55
55
  var Ctx = /* @__PURE__ */ createContext(null);
56
- var tabId = (base, v) => `${base}-tab-${v}`;
57
- var panelId = (base, v) => `${base}-panel-${v}`;
56
+ var idPart = (v) => v.replace(/[^A-Za-z0-9_-]/g, (c) => "_" + c.charCodeAt(0).toString(16));
57
+ var tabId = (base, v) => `${base}-tab-${idPart(v)}`;
58
+ var panelId = (base, v) => `${base}-panel-${idPart(v)}`;
58
59
  function Tabs({
59
60
  value: valueProp,
60
61
  defaultValue,
@@ -69,23 +69,29 @@ function TagInput({
69
69
  const add = (raw) => {
70
70
  let next = tags;
71
71
  let err = null;
72
+ const refused = [];
72
73
  for (const r of raw) {
73
74
  const t = r.trim();
74
75
  if (!t || next.includes(t)) continue;
75
- if (maxTags !== void 0 && next.length >= maxTags) break;
76
+ if (maxTags !== void 0 && next.length >= maxTags) {
77
+ err ??= strings.maxTags(maxTags);
78
+ refused.push(t);
79
+ continue;
80
+ }
76
81
  const message = validate?.(t) ?? null;
77
82
  if (message) {
78
83
  err ??= message;
84
+ refused.push(t);
79
85
  continue;
80
86
  }
81
87
  next = [...next, t];
82
88
  }
83
89
  if (next !== tags) setTags(next);
84
90
  setError(err);
85
- return err;
91
+ return { error: err, refused };
86
92
  };
87
93
  const commitText = (raw) => {
88
- if (!add([raw])) {
94
+ if (!add([raw]).error) {
89
95
  setText("");
90
96
  setActive(-1);
91
97
  }
@@ -98,9 +104,10 @@ function TagInput({
98
104
  const handleKeyDown = (e) => {
99
105
  if (e.nativeEvent.isComposing) return;
100
106
  if (e.key === "Enter") {
101
- if (listOpen && active >= 0) {
107
+ const pick = listOpen && active >= 0 ? filtered[active] : void 0;
108
+ if (pick !== void 0) {
102
109
  e.preventDefault();
103
- commitText(filtered[active]);
110
+ commitText(pick);
104
111
  } else if (text.trim()) {
105
112
  e.preventDefault();
106
113
  commitText(text);
@@ -137,7 +144,8 @@ function TagInput({
137
144
  e.preventDefault();
138
145
  const parts = pasted.split(SPLIT);
139
146
  parts[0] = text + parts[0];
140
- if (!add(parts)) setText("");
147
+ const { error: err, refused } = add(parts);
148
+ setText(err ? refused.join(", ") : "");
141
149
  };
142
150
  const handleBlur = (e) => {
143
151
  onBlur?.(e);
@@ -201,7 +209,7 @@ function TagInput({
201
209
  "aria-expanded": hasSuggestions ? listOpen : void 0,
202
210
  "aria-controls": listOpen ? listId : void 0,
203
211
  "aria-autocomplete": hasSuggestions ? "list" : void 0,
204
- "aria-activedescendant": listOpen && active >= 0 ? `${auto}-opt-${active}` : void 0,
212
+ "aria-activedescendant": listOpen && active >= 0 && active < filtered.length ? `${auto}-opt-${active}` : void 0,
205
213
  "aria-label": ariaLabel,
206
214
  "aria-labelledby": ariaLabelledBy,
207
215
  "aria-describedby": [ariaDescribedBy, error ? errorId : null].filter(Boolean).join(" ") || void 0,
@@ -11,8 +11,11 @@ function toTime(h, m) {
11
11
  return `${pad2(h)}:${pad2(m)}`;
12
12
  }
13
13
  function inTimeRange(t, min, max) {
14
- if (parseTime(min) && t < min) return false;
15
- if (parseTime(max) && t > max) return false;
14
+ const lo = parseTime(min) ? min : null;
15
+ const hi = parseTime(max) ? max : null;
16
+ if (lo !== null && hi !== null && lo > hi) return t >= lo || t <= hi;
17
+ if (lo !== null && t < lo) return false;
18
+ if (hi !== null && t > hi) return false;
16
19
  return true;
17
20
  }
18
21
  var cycles = /* @__PURE__ */ new Map();
@@ -108,15 +108,17 @@ function TimeField({
108
108
  };
109
109
  const [own, setOwn] = useState(() => okProp("defaultValue", defaultValue));
110
110
  const value = controlled ? okProp("value", valueProp) : own;
111
+ const hourRef = useRef(null);
112
+ const minuteRef = useRef(null);
111
113
  const [draftState, setDraft] = useState(null);
112
114
  const [bad, setBad] = useState(false);
113
- if (draftState !== null && draftState.base !== value) {
115
+ const [focusInside, setFocusInside] = useState(false);
116
+ const draftKept = draftState !== null && (draftState.base === value || focusInside && draftState.prev === value);
117
+ if (draftState !== null && !draftKept) {
114
118
  setDraft(null);
115
119
  setBad(false);
116
120
  }
117
- const draft = draftState !== null && draftState.base === value ? draftState.d : null;
118
- const hourRef = useRef(null);
119
- const minuteRef = useRef(null);
121
+ const draft = draftState !== null && draftKept ? draftState.d : null;
120
122
  const shown = draft ?? draftFromTime(value, cycle);
121
123
  const draftBad = () => {
122
124
  if (draft === null) return false;
@@ -147,14 +149,14 @@ function TimeField({
147
149
  const t = draftTime(next, cycle);
148
150
  if (t === null) {
149
151
  if (value !== null) commit(null);
150
- setDraft({ d: next, base: null });
152
+ setDraft({ d: next, base: null, prev: value });
151
153
  setBad(false);
152
154
  } else if (typeof t === "string" && inTimeRange(t, minT, maxT)) {
153
155
  if (t !== value) commit(t);
154
- setDraft({ d: next, base: t });
156
+ setDraft({ d: next, base: t, prev: value });
155
157
  setBad(false);
156
158
  } else {
157
- setDraft({ d: next, base: value });
159
+ setDraft({ d: next, base: value, prev: value });
158
160
  }
159
161
  };
160
162
  const focusMinute = () => {
@@ -164,6 +166,7 @@ function TimeField({
164
166
  const onKey = (which) => (e) => {
165
167
  if (disabled) return;
166
168
  const key = e.key;
169
+ if (e.ctrlKey || e.metaKey || e.altKey) return;
167
170
  if (key === "Enter") {
168
171
  if (draftBad()) {
169
172
  e.preventDefault();
@@ -233,9 +236,14 @@ function TimeField({
233
236
  "aria-labelledby": src,
234
237
  "data-disabled": disabled ? "" : void 0,
235
238
  className: cn("inline-flex items-center gap-2", className),
239
+ onFocus: (e) => {
240
+ rest.onFocus?.(e);
241
+ setFocusInside(true);
242
+ },
236
243
  onBlur: (e) => {
237
244
  rest.onBlur?.(e);
238
245
  if (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)) return;
246
+ setFocusInside(false);
239
247
  const isBad = draftBad();
240
248
  setBad(isBad);
241
249
  if (!isBad) setDraft(null);
@@ -61,8 +61,8 @@ function push(tone, title, bodyOrOptions) {
61
61
  const o = typeof bodyOrOptions === "string" ? { body: bodyOrOptions } : bodyOrOptions ?? {};
62
62
  const s = store();
63
63
  const id = s.nextId++;
64
- const asked = o.duration === Infinity ? "sticky" : o.duration;
65
- const duration = asked ?? (tone === "error" ? "sticky" : AUTO_DISMISS_MS);
64
+ const asked = o.duration;
65
+ const duration = asked === "sticky" ? "sticky" : typeof asked === "number" && asked > 0 ? asked >= 2 ** 31 - 1 ? "sticky" : asked : tone === "error" ? "sticky" : AUTO_DISMISS_MS;
66
66
  const item = {
67
67
  id,
68
68
  tone,
@@ -103,10 +103,22 @@ var toast = /* @__PURE__ */ Object.assign((title, o) => push("info", title, o),
103
103
  push("info", messages.loading, { duration: "sticky", id: slot });
104
104
  promise.then(
105
105
  (value) => {
106
- push("success", typeof messages.success === "function" ? messages.success(value) : messages.success, { id: slot });
106
+ let m;
107
+ try {
108
+ m = typeof messages.success === "function" ? messages.success(value) : messages.success;
109
+ } catch (e) {
110
+ return void push("error", String(e), { id: slot });
111
+ }
112
+ push("success", m, { id: slot });
107
113
  },
108
114
  (error) => {
109
- push("error", typeof messages.error === "function" ? messages.error(error) : messages.error, { id: slot });
115
+ let m;
116
+ try {
117
+ m = typeof messages.error === "function" ? messages.error(error) : messages.error;
118
+ } catch (e) {
119
+ m = String(e);
120
+ }
121
+ push("error", m, { id: slot });
110
122
  }
111
123
  );
112
124
  return promise;
@@ -25,7 +25,7 @@ function Tooltip({ tip, children, className, side = "top", as = "span", focusabl
25
25
  const [measuredInner, setMeasuredInner] = useState(false);
26
26
  useIsoLayoutEffect(() => {
27
27
  const el = triggerRef.current;
28
- const found = only !== null && !!el && el.querySelector(FOCUSABLE) !== null;
28
+ const found = only !== null && !!el && !!el.firstElementChild?.matches(FOCUSABLE);
29
29
  setMeasuredInner(found);
30
30
  });
31
31
  const inner = only !== null && (staticInner || measuredInner);
@@ -69,8 +69,9 @@ function useUrlState(defaults, o = {}) {
69
69
  const comma = useMemo(() => JSON.parse(commaKey), [commaKey]);
70
70
  const defaultsKey = JSON.stringify(defaults);
71
71
  const stableDefaults = useMemo(() => JSON.parse(defaultsKey), [defaultsKey]);
72
+ const subscribe = useCallback((cb) => adapter.subscribe(cb), [adapter]);
72
73
  const search = useSyncExternalStore(
73
- adapter.subscribe,
74
+ subscribe,
74
75
  () => adapter.get().toString(),
75
76
  () => ""
76
77
  );
@@ -84,6 +85,7 @@ function useUrlState(defaults, o = {}) {
84
85
  const name = prefix + key;
85
86
  const value = next[key];
86
87
  params.delete(name);
88
+ if (value === void 0 || value === null) continue;
87
89
  if (same(value, d[key])) continue;
88
90
  if (Array.isArray(value)) {
89
91
  if (value.length === 0) params.append(name, "");
@@ -20,7 +20,7 @@ import { useVirtualRows } from "./virtual.js";
20
20
  import { jsx, jsxs } from "react/jsx-runtime";
21
21
  var HIDE_BELOW = { sm: "hidden sm:table-cell", md: "hidden md:table-cell", lg: "hidden lg:table-cell" };
22
22
  var ROW_FOCUS = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-th-accent";
23
- var INTERACTIVE_CHILD = "a,button,input,select,textarea,[role=button]";
23
+ var INTERACTIVE_CHILD = 'a,button,input,select,textarea,label,summary,[role="button"],[role="link"]';
24
24
  function VirtualTable({
25
25
  rows,
26
26
  columns,
@@ -100,10 +100,15 @@ function VirtualTable({
100
100
  const topSpace = indices.length > 0 ? offsetOf(first) : 0;
101
101
  const bottomSpace = Math.max(0, total - (last >= 0 ? offsetOf(last) + sizeOf(last) : 0));
102
102
  const interactive = !!onRowClick;
103
- const tabbable = indices.includes(focusIndex) ? focusIndex : first;
103
+ const firstInView = virtual.range.start === 0 ? first : indices.find((i) => i >= virtual.range.start + overscan) ?? first;
104
+ const tabbable = indices.includes(focusIndex) ? focusIndex : firstInView;
104
105
  useEffect(() => {
105
106
  if (count > 0 && focusIndex > count - 1) setFocusIndex(count - 1);
106
107
  }, [count, focusIndex]);
108
+ useIsoLayoutEffect(() => {
109
+ const h = headRef.current?.offsetHeight ?? 0;
110
+ if (scrollRef.current) scrollRef.current.style.scrollPaddingTop = h ? `${h}px` : "";
111
+ });
107
112
  useIsoLayoutEffect(() => {
108
113
  const body = bodyRef.current;
109
114
  if (pendingFocus.current !== null) {
@@ -127,6 +132,7 @@ function VirtualTable({
127
132
  };
128
133
  const onBodyBlur = (e) => {
129
134
  const next = e.relatedTarget;
135
+ if (!next && (!document.hasFocus() || document.activeElement === e.target)) return;
130
136
  if (next ? !bodyRef.current?.contains(next) : e.target.isConnected) {
131
137
  hadFocus.current = false;
132
138
  pin(null);
@@ -24,6 +24,18 @@ import { mergeRefs, warnOnce } from "./data-classes.js";
24
24
  import { useLatest } from "./latest.js";
25
25
  import { jsx } from "react/jsx-runtime";
26
26
  var PIN_REACH = 100;
27
+ function rootPx(style, name) {
28
+ const n = parseFloat(style.getPropertyValue(name));
29
+ return Number.isFinite(n) ? n : 0;
30
+ }
31
+ function windowInsets() {
32
+ if (typeof document === "undefined" || typeof getComputedStyle === "undefined") return { top: 0, bottom: 0 };
33
+ const style = getComputedStyle(document.documentElement);
34
+ const top = rootPx(style, "--nish-header-h") + rootPx(style, "--nish-sticky-extra");
35
+ const raw = style.getPropertyValue("--nish-bottom-inset");
36
+ const bottom = Number.isFinite(parseFloat(raw)) ? parseFloat(raw) : rootPx(style, "--nish-bottom-nav-h") + rootPx(style, "--nish-bottom-bar-h");
37
+ return { top, bottom };
38
+ }
27
39
  var byIndex = (i) => i;
28
40
  function useVirtualRows(options) {
29
41
  const { count, itemSize, getKey, measure, gap, overscan, initialCount, scrollRef, listRef, coverTop, pinMode, onRangeChange } = options;
@@ -59,8 +71,9 @@ function useVirtualRows(options) {
59
71
  viewTop = top + cover;
60
72
  viewBottom = top + scroller.clientHeight;
61
73
  } else {
62
- viewTop = cover;
63
- viewBottom = window.innerHeight;
74
+ const inset = windowInsets();
75
+ viewTop = latest.current.coverTop ? cover : inset.top;
76
+ viewBottom = window.innerHeight - inset.bottom;
64
77
  }
65
78
  return { top: viewTop - listTop, bottom: viewBottom - listTop, listTop, viewTop, viewBottom };
66
79
  }, [listRef, scrollRef, latest]);
@@ -238,6 +251,7 @@ function VirtualList({
238
251
  };
239
252
  const onBlur = (e) => {
240
253
  const next = e.relatedTarget;
254
+ if (!next && (!document.hasFocus() || document.activeElement === e.target)) return;
241
255
  if (!next || !listRef.current?.contains(next)) pin(null);
242
256
  };
243
257
  const rootStyle = self ? { ...style, height, overflowY: "auto", overflowAnchor: "none", overscrollBehavior: "contain" } : style;
@@ -47,7 +47,24 @@ function nf(locale, min, max) {
47
47
  () => new Intl.NumberFormat(locale, { minimumFractionDigits: min, maximumFractionDigits: max })
48
48
  );
49
49
  }
50
- function dtf(locale, key, options, timeZone) {
50
+ var zoneOk = /* @__PURE__ */ new Map();
51
+ function safeZone(timeZone) {
52
+ if (!timeZone) return void 0;
53
+ let ok = zoneOk.get(timeZone);
54
+ if (ok === void 0) {
55
+ try {
56
+ new Intl.DateTimeFormat("en-US", { timeZone });
57
+ ok = true;
58
+ } catch {
59
+ ok = false;
60
+ }
61
+ if (zoneOk.size >= 64) zoneOk.clear();
62
+ zoneOk.set(timeZone, ok);
63
+ }
64
+ return ok ? timeZone : void 0;
65
+ }
66
+ function dtf(locale, key, options, zone2) {
67
+ const timeZone = safeZone(zone2);
51
68
  return cached(
52
69
  `d|${locale}|${key}|${timeZone ?? ""}`,
53
70
  () => new Intl.DateTimeFormat(locale, timeZone ? { ...options, timeZone } : options)
@@ -80,32 +97,35 @@ function compactAbs(abs, digits, locale) {
80
97
  function isZeroAfterRounding(v, digits) {
81
98
  return Number(Math.abs(v).toFixed(digits)) === 0;
82
99
  }
83
- var symbols = /* @__PURE__ */ new Map();
84
- function currencySymbol(currency, locale) {
100
+ var currencies = /* @__PURE__ */ new Map();
101
+ function currencyInfo(currency, locale) {
85
102
  const key = `${locale}|${currency}`;
86
- let s = symbols.get(key);
87
- if (s === void 0) {
103
+ let info = currencies.get(key);
104
+ if (info === void 0) {
88
105
  try {
89
- const parts = new Intl.NumberFormat(locale, {
106
+ const nf2 = new Intl.NumberFormat(locale, {
90
107
  style: "currency",
91
108
  currency,
92
109
  currencyDisplay: "narrowSymbol"
93
- }).formatToParts(0);
94
- s = parts.find((p) => p.type === "currency")?.value ?? currency;
110
+ });
111
+ let s = nf2.formatToParts(0).find((p) => p.type === "currency")?.value ?? currency;
112
+ if (/\p{L}$/u.test(s)) s += "\xA0";
113
+ info = { symbol: s, digits: nf2.resolvedOptions().maximumFractionDigits ?? 2 };
95
114
  } catch {
96
- s = currency + " ";
115
+ info = { symbol: currency + " ", digits: 2 };
97
116
  }
98
- symbols.set(key, s);
117
+ currencies.set(key, info);
99
118
  }
100
- return s;
119
+ return info;
101
120
  }
102
121
  function moneyAbs(abs, o, locale) {
103
- const symbol = currencySymbol(o.currency ?? "USD", locale);
122
+ const { symbol, digits } = currencyInfo(o.currency ?? "USD", locale);
104
123
  if (o.compact && abs >= 1e3) return symbol + compactAbs(abs, 1, locale);
105
124
  const cents = o.cents ?? "auto";
106
- const hasCents = Math.round(abs * 100) % 100 !== 0;
107
- const showCents = cents === "always" || cents === "auto" && (abs < 1e3 || hasCents);
108
- return symbol + (showCents ? fixed(abs, 2, 2, locale) : fixed(abs, 0, 0, locale));
125
+ const unit = 10 ** digits;
126
+ const hasCents = Math.round(abs * unit) % unit !== 0;
127
+ const showCents = digits > 0 && (cents === "always" || cents === "auto" && (abs < 1e3 || hasCents));
128
+ return symbol + (showCents ? fixed(abs, digits, digits, locale) : fixed(abs, 0, 0, locale));
109
129
  }
110
130
  function money(v, o = {}) {
111
131
  if (!finite(v)) return DASH;
@@ -229,7 +249,12 @@ function ago(t, o = {}) {
229
249
  if (abs < 45) return english ? "just now" : rtf(locale, long ? "long" : "narrow").format(0, "second");
230
250
  let pick = AGO_UNITS[0];
231
251
  for (const u of AGO_UNITS) if (abs >= u[0]) pick = u;
232
- const n = Math.max(1, Math.round(abs / pick[0]));
252
+ let n = Math.max(1, Math.round(abs / pick[0]));
253
+ const next = AGO_UNITS[AGO_UNITS.indexOf(pick) + 1];
254
+ if (next && (n * pick[0] >= next[0] || pick[1] === "month" && n >= 12)) {
255
+ pick = next;
256
+ n = Math.max(1, Math.round(abs / pick[0]));
257
+ }
233
258
  const past = diff < 0;
234
259
  if (!english) return rtf(locale, long ? "long" : "narrow").format(past ? -n : n, pick[1]);
235
260
  if (long) return rtf(locale, "long").format(past ? -n : n, pick[1]);
@@ -1,14 +1,21 @@
1
1
  // src/runtime.ts
2
- var version = true ? "3.0.0" : "dev";
2
+ var version = true ? "3.2.0" : "dev";
3
3
  var VERSION = version;
4
4
  var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
5
5
  function runtime() {
6
6
  const g = globalThis;
7
7
  return g[KEY] ??= { versions: /* @__PURE__ */ new Set(), slots: {} };
8
8
  }
9
+ function isDevelopment() {
10
+ try {
11
+ return process.env.NODE_ENV !== "production";
12
+ } catch {
13
+ return false;
14
+ }
15
+ }
9
16
  function register(rt) {
10
17
  rt.versions.add(version);
11
- if (rt.versions.size > 1 && !rt.warned && globalThis.process?.env?.NODE_ENV !== "production") {
18
+ if (rt.versions.size > 1 && !rt.warned && isDevelopment()) {
12
19
  rt.warned = true;
13
20
  console.warn(
14
21
  `nish-ui: two versions are loaded on this page (${[...rt.versions].join(", ")}). Overlays, toasts and theme state are shared, but mixing versions is unsupported.`
@@ -265,7 +265,7 @@ function createInboxClient(options) {
265
265
  if (disabled) return { ok: false, error: "disabled", queued: false };
266
266
  if (queue.length > 0) {
267
267
  enqueue(parsed.value);
268
- void flush();
268
+ if (timer === null) void flush();
269
269
  return { ok: false, error: "queued behind earlier events", queued: true };
270
270
  }
271
271
  const result = await attempt(parsed.value);
@@ -361,7 +361,8 @@ function swapSlots(slots, a, b) {
361
361
  function narrowLayout(count, n, aspect) {
362
362
  if (count === 1) return leaf(0);
363
363
  const dir = n.dir === "auto" ? aspect >= 1.2 ? "row" : "col" : n.dir;
364
- const split = Math.min(0.8, Math.max(0.2, n.split));
364
+ const s = Number.isFinite(n.split) ? n.split : 0.5;
365
+ const split = Math.min(0.8, Math.max(0.2, s));
365
366
  return {
366
367
  type: "split",
367
368
  dir,