nish-ui 3.2.0 → 3.3.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/README.md +7 -3
- package/dist/base-tailwind.css +30 -15
- package/dist/base.css +30 -15
- package/dist/elements-all.js +78 -78
- package/dist/elements-charts.js +39 -38
- package/dist/elements-data.d.ts +10 -0
- package/dist/elements-data.js +4 -5
- package/dist/elements-forms.js +5 -5
- package/dist/elements.d.ts +1 -0
- package/dist/elements.js +4 -4
- package/dist/esm/command-filter.js +55 -4
- package/dist/esm/components/accordion.js +3 -2
- package/dist/esm/components/app-shell.js +8 -4
- package/dist/esm/components/breadcrumbs.js +7 -3
- package/dist/esm/components/calendar-base.js +32 -5
- package/dist/esm/components/calendar-classes.js +14 -2
- package/dist/esm/components/canvas/follow-caption.js +31 -21
- package/dist/esm/components/canvas/follow.js +5 -6
- package/dist/esm/components/canvas/minimap.js +3 -3
- package/dist/esm/components/canvas/system-canvas.js +3 -1
- package/dist/esm/components/canvas/view.js +0 -2
- package/dist/esm/components/carousel.js +2 -3
- package/dist/esm/components/charts.js +18 -7
- package/dist/esm/components/combobox.js +18 -7
- package/dist/esm/components/command.js +23 -61
- package/dist/esm/components/context-menu.js +2 -1
- package/dist/esm/components/data-classes.js +5 -4
- package/dist/esm/components/data.js +19 -10
- package/dist/esm/components/display.js +20 -11
- package/dist/esm/components/drawer.js +17 -4
- package/dist/esm/components/error-boundary.js +3 -3
- package/dist/esm/components/feedback.js +3 -3
- package/dist/esm/components/file-dropzone.js +16 -6
- package/dist/esm/components/filters.js +42 -1
- package/dist/esm/components/flow.js +8 -5
- package/dist/esm/components/forms-classes.js +2 -0
- package/dist/esm/components/forms.js +2 -2
- package/dist/esm/components/hooks.js +47 -13
- package/dist/esm/components/hover-card.js +2 -1
- package/dist/esm/components/inbox.js +5 -1
- package/dist/esm/components/latest.js +4 -2
- package/dist/esm/components/layout.js +7 -4
- package/dist/esm/components/menu.js +10 -1
- package/dist/esm/components/modal.js +17 -4
- package/dist/esm/components/multi-select.js +5 -5
- package/dist/esm/components/nav.js +30 -11
- package/dist/esm/components/navigate.js +1 -1
- package/dist/esm/components/overlay-dialog.js +35 -1
- package/dist/esm/components/pagination.js +1 -1
- package/dist/esm/components/primitives.js +17 -4
- package/dist/esm/components/progress.js +2 -1
- package/dist/esm/components/resource.js +14 -4
- package/dist/esm/components/segmented.js +2 -0
- package/dist/esm/components/separator.js +6 -1
- package/dist/esm/components/service-tokens.js +18 -7
- package/dist/esm/components/settings.js +16 -0
- package/dist/esm/components/slider.js +5 -1
- package/dist/esm/components/split.js +4 -2
- package/dist/esm/components/strings.js +17 -4
- package/dist/esm/components/table.js +15 -3
- package/dist/esm/components/tag-input.js +5 -1
- package/dist/esm/components/time-field.js +15 -7
- package/dist/esm/components/toast-card.js +5 -3
- package/dist/esm/components/toast.js +4 -1
- package/dist/esm/components/tooltip.js +3 -2
- package/dist/esm/components/url-state.js +3 -1
- package/dist/esm/components/virtual-table.js +2 -2
- package/dist/esm/components/virtual.js +8 -4
- package/dist/esm/format.js +3 -2
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/server/inbox/client.js +4 -0
- package/dist/esm/theme.js +38 -15
- package/dist/esm/tokens.mjs +1 -1
- package/dist/format.d.ts +5 -3
- package/dist/format.js +4 -3
- package/dist/inbox-client.d.ts +1 -1
- package/dist/inbox-client.js +4 -0
- package/dist/index.d.ts +61 -29
- package/dist/nish-components.css +59 -21
- package/dist/nish-components.min.css +1 -1
- package/dist/nish.css +30 -15
- package/dist/nish.min.css +1 -1
- package/dist/node/vite.js +1 -1
- package/dist/server/hono.d.ts +9 -2
- package/dist/server/hono.js +17 -4
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +7 -2
- package/dist/service-tokens.d.ts +4 -4
- package/dist/{spa-BfRDo38r.d.ts → spa-FwS7yZ8p.d.ts} +4 -3
- package/dist/system-canvas.d.ts +11 -10
- package/dist/theme.d.ts +30 -2
- package/dist/theme.global.js +45 -18
- package/dist/theme.js +45 -18
- package/package.json +3 -2
- package/dist/tokens.js +0 -425
|
@@ -40,9 +40,21 @@ function TableWrap({
|
|
|
40
40
|
update();
|
|
41
41
|
if (typeof ResizeObserver === "undefined") return;
|
|
42
42
|
const ro = new ResizeObserver(update);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const watch = () => {
|
|
44
|
+
ro.disconnect();
|
|
45
|
+
ro.observe(el);
|
|
46
|
+
for (const c of Array.from(el.children)) ro.observe(c);
|
|
47
|
+
};
|
|
48
|
+
watch();
|
|
49
|
+
const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(() => {
|
|
50
|
+
watch();
|
|
51
|
+
update();
|
|
52
|
+
});
|
|
53
|
+
mo?.observe(el, { childList: true });
|
|
54
|
+
return () => {
|
|
55
|
+
ro.disconnect();
|
|
56
|
+
mo?.disconnect();
|
|
57
|
+
};
|
|
46
58
|
}, []);
|
|
47
59
|
const name = label ?? rest["aria-label"];
|
|
48
60
|
const css = {
|
|
@@ -143,7 +143,11 @@ function TagInput({
|
|
|
143
143
|
if (!SPLIT.test(pasted)) return;
|
|
144
144
|
e.preventDefault();
|
|
145
145
|
const parts = pasted.split(SPLIT);
|
|
146
|
-
|
|
146
|
+
const el = e.currentTarget;
|
|
147
|
+
const start = Math.min(el.selectionStart ?? text.length, text.length);
|
|
148
|
+
const end = Math.min(el.selectionEnd ?? start, text.length);
|
|
149
|
+
parts[0] = text.slice(0, start) + parts[0];
|
|
150
|
+
parts[parts.length - 1] += text.slice(end);
|
|
147
151
|
const { error: err, refused } = add(parts);
|
|
148
152
|
setText(err ? refused.join(", ") : "");
|
|
149
153
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/components/time-field.tsx
|
|
4
|
-
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { getDefaultLocale } from "../format.js";
|
|
7
7
|
import { resolveLocale } from "./calendar-classes.js";
|
|
@@ -109,6 +109,13 @@ function TimeField({
|
|
|
109
109
|
const [own, setOwn] = useState(() => okProp("defaultValue", defaultValue));
|
|
110
110
|
const value = controlled ? okProp("value", valueProp) : own;
|
|
111
111
|
const hourRef = useRef(null);
|
|
112
|
+
const setHourNode = useCallback(
|
|
113
|
+
(node) => {
|
|
114
|
+
hourRef.current = node;
|
|
115
|
+
setRef(ref, node);
|
|
116
|
+
},
|
|
117
|
+
[ref]
|
|
118
|
+
);
|
|
112
119
|
const minuteRef = useRef(null);
|
|
113
120
|
const [draftState, setDraft] = useState(null);
|
|
114
121
|
const [bad, setBad] = useState(false);
|
|
@@ -188,10 +195,14 @@ function TimeField({
|
|
|
188
195
|
}
|
|
189
196
|
} else if (key === "Home") {
|
|
190
197
|
e.preventDefault();
|
|
191
|
-
update(
|
|
198
|
+
update(
|
|
199
|
+
which === "h" ? cycle === 12 ? { ...shown, h: "1" } : { ...shown, h: hourText(0, cycle), pm: false } : { ...shown, m: "00" }
|
|
200
|
+
);
|
|
192
201
|
} else if (key === "End") {
|
|
193
202
|
e.preventDefault();
|
|
194
|
-
update(
|
|
203
|
+
update(
|
|
204
|
+
which === "h" ? cycle === 12 ? { ...shown, h: "12" } : { ...shown, h: hourText(23, cycle), pm: true } : { ...shown, m: pad2(lastMinute(st)) }
|
|
205
|
+
);
|
|
195
206
|
} else if (cycle === 12 && (key === "a" || key === "A" || key === "p" || key === "P")) {
|
|
196
207
|
e.preventDefault();
|
|
197
208
|
update({ ...shown, pm: key === "p" || key === "P" });
|
|
@@ -258,10 +269,7 @@ function TimeField({
|
|
|
258
269
|
"input",
|
|
259
270
|
{
|
|
260
271
|
...common,
|
|
261
|
-
ref:
|
|
262
|
-
hourRef.current = node;
|
|
263
|
-
setRef(ref, node);
|
|
264
|
-
},
|
|
272
|
+
ref: setHourNode,
|
|
265
273
|
id: inputId,
|
|
266
274
|
value: shown.h,
|
|
267
275
|
"aria-labelledby": names(hId),
|
|
@@ -40,7 +40,7 @@ function ToastCard({ t }) {
|
|
|
40
40
|
el.style.opacity = dx === 0 ? "" : String(Math.max(0, 1 - Math.abs(dx) / width));
|
|
41
41
|
};
|
|
42
42
|
const onDown = (e) => {
|
|
43
|
-
if (e.pointerType === "mouse") return;
|
|
43
|
+
if (e.pointerType === "mouse" || drag.current) return;
|
|
44
44
|
drag.current = {
|
|
45
45
|
pointerId: e.pointerId,
|
|
46
46
|
startX: e.clientX,
|
|
@@ -71,8 +71,9 @@ function ToastCard({ t }) {
|
|
|
71
71
|
const onUp = (e) => {
|
|
72
72
|
const d = drag.current;
|
|
73
73
|
const el = ref.current;
|
|
74
|
+
if (d && d.pointerId !== e.pointerId) return;
|
|
74
75
|
drag.current = null;
|
|
75
|
-
if (!d || !el ||
|
|
76
|
+
if (!d || !el || !d.active) return;
|
|
76
77
|
const dx = e.clientX - d.startX;
|
|
77
78
|
const width = el.offsetWidth;
|
|
78
79
|
const flung = Math.abs(d.velocity) > SWIPE_DISMISS_VELOCITY && Math.sign(d.velocity) === Math.sign(dx);
|
|
@@ -89,8 +90,9 @@ function ToastCard({ t }) {
|
|
|
89
90
|
};
|
|
90
91
|
const onCancel = (e) => {
|
|
91
92
|
const d = drag.current;
|
|
93
|
+
if (d && d.pointerId !== e.pointerId) return;
|
|
92
94
|
drag.current = null;
|
|
93
|
-
if (!d?.active
|
|
95
|
+
if (!d?.active) return;
|
|
94
96
|
setOffset(0, ref.current?.offsetWidth || 1);
|
|
95
97
|
resumeTimer(t.id);
|
|
96
98
|
};
|
|
@@ -116,7 +116,10 @@ function ToastFallback({ t, focusedRef }) {
|
|
|
116
116
|
"div",
|
|
117
117
|
{
|
|
118
118
|
"data-nish-toast-fallback": "",
|
|
119
|
-
|
|
119
|
+
onBlur: (e) => {
|
|
120
|
+
if (!e.currentTarget.contains(e.relatedTarget)) focusedRef.current = null;
|
|
121
|
+
},
|
|
122
|
+
className: `pointer-events-auto flex w-full max-w-md items-start gap-2.5 rounded-xl border ${{ success: "border-th-ok/35", error: "border-th-loss/40", warn: "border-th-warn/40", info: "border-th-line-strong" }[t.tone]} bg-th-elevated px-3.5 py-3 shadow-pop animate-[nish-rise-in_160ms_var(--nish-ease-out)]`,
|
|
120
123
|
children: [
|
|
121
124
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
122
125
|
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
|
|
@@ -100,9 +100,10 @@ function Tooltip({ tip, children, className, side = "top", as = "span", focusabl
|
|
|
100
100
|
if (!over) graceTimer.current = window.setTimeout(() => setOpen(false), TIP_GRACE_MS);
|
|
101
101
|
}, []);
|
|
102
102
|
const wrapperFocusable = focusable ?? !inner;
|
|
103
|
+
const own = rest ?? {};
|
|
103
104
|
const a11y = {
|
|
104
|
-
tabIndex: wrapperFocusable ? 0 : void 0,
|
|
105
|
-
"aria-describedby": open && !inner ? id : void 0,
|
|
105
|
+
tabIndex: own.tabIndex ?? (wrapperFocusable ? 0 : void 0),
|
|
106
|
+
"aria-describedby": [own["aria-describedby"], open && !inner ? id : void 0].filter(Boolean).join(" ") || void 0,
|
|
106
107
|
"data-state": open ? "open" : "closed"
|
|
107
108
|
};
|
|
108
109
|
const hint = variant === "hint" && "cursor-help underline decoration-th-hi3 decoration-dotted underline-offset-2";
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// src/components/url-state.ts
|
|
4
4
|
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
5
|
-
var
|
|
5
|
+
var URL_STATE_EVENT = "nish:urlstate";
|
|
6
|
+
var EVENT = URL_STATE_EVENT;
|
|
6
7
|
var locationAdapter = {
|
|
7
8
|
get() {
|
|
8
9
|
if (typeof location === "undefined") return new URLSearchParams();
|
|
@@ -115,6 +116,7 @@ function useUrlState(defaults, o = {}) {
|
|
|
115
116
|
return [state, patch, reset];
|
|
116
117
|
}
|
|
117
118
|
export {
|
|
119
|
+
URL_STATE_EVENT,
|
|
118
120
|
locationAdapter,
|
|
119
121
|
useUrlState
|
|
120
122
|
};
|
|
@@ -11,14 +11,14 @@ import {
|
|
|
11
11
|
} from "react";
|
|
12
12
|
import { cn } from "../cn.js";
|
|
13
13
|
import { useIsoLayoutEffect } from "./client.js";
|
|
14
|
-
import { sortRows } from "./data-classes.js";
|
|
14
|
+
import { sortRows, tableInternals } from "./data-classes.js";
|
|
15
15
|
import { useStrings } from "./provider.js";
|
|
16
16
|
import { TABLE_STRINGS, STATUS_STRINGS } from "./strings.js";
|
|
17
17
|
import { useLatest } from "./latest.js";
|
|
18
18
|
import { Table, TableWrap, Td, Th, Tr } from "./table.js";
|
|
19
19
|
import { useVirtualRows } from "./virtual.js";
|
|
20
20
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
-
var
|
|
21
|
+
var { HIDE_BELOW } = tableInternals;
|
|
22
22
|
var ROW_FOCUS = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-th-accent";
|
|
23
23
|
var INTERACTIVE_CHILD = 'a,button,input,select,textarea,label,summary,[role="button"],[role="link"]';
|
|
24
24
|
function VirtualTable({
|
|
@@ -46,12 +46,12 @@ function useVirtualRows(options) {
|
|
|
46
46
|
const offsets = useMemo(
|
|
47
47
|
() => buildOffsets(
|
|
48
48
|
count,
|
|
49
|
-
(i) => (measured.size === 0 ? void 0 : measured.get(getKey(i))) ?? (typeof itemSize === "number" ? itemSize : itemSize(i)),
|
|
49
|
+
(i) => (!measure || measured.size === 0 ? void 0 : measured.get(getKey(i))) ?? (typeof itemSize === "number" ? itemSize : itemSize(i)),
|
|
50
50
|
gap
|
|
51
51
|
),
|
|
52
52
|
// getKey only matters once something is measured, so an unstable getKey must not rebuild fixed-size offsets
|
|
53
53
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
-
[count, itemSize, measure ? getKey : null, gap, measured]
|
|
54
|
+
[count, itemSize, measure, measure ? getKey : null, gap, measured]
|
|
55
55
|
);
|
|
56
56
|
const total = offsets[count];
|
|
57
57
|
const offsetOf = useCallback((i) => offsets[i], [offsets]);
|
|
@@ -179,7 +179,8 @@ function useVirtualRows(options) {
|
|
|
179
179
|
const pin = useCallback((index) => setPinned(index), []);
|
|
180
180
|
const scrollToIndex = useCallback(
|
|
181
181
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization -- reads the latest-value ref on purpose; the callback must stay stable
|
|
182
|
-
(index, { align = "auto", behavior = "auto" } = {}) => {
|
|
182
|
+
(index, { align = "auto", behavior: wanted = "auto" } = {}) => {
|
|
183
|
+
const behavior = wanted === "smooth" && typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : wanted;
|
|
183
184
|
const jump = (minMove) => {
|
|
184
185
|
const { offsets: o, count: n, gap: g } = latest.current;
|
|
185
186
|
if (n === 0) return;
|
|
@@ -261,7 +262,10 @@ function VirtualList({
|
|
|
261
262
|
...rest,
|
|
262
263
|
ref: mergeRefs(ref, rootRef),
|
|
263
264
|
style: rootStyle,
|
|
264
|
-
tabIndex: self ? count > 0 ? 0 : void 0 : rest.tabIndex,
|
|
265
|
+
tabIndex: self ? rest.tabIndex ?? (count > 0 ? 0 : void 0) : rest.tabIndex,
|
|
266
|
+
role: self && labelled && count > 0 && rest.role === void 0 ? "region" : rest.role,
|
|
267
|
+
"aria-label": self && labelled && count > 0 && !ariaLabelledBy ? ariaLabel : void 0,
|
|
268
|
+
"aria-labelledby": self && labelled && count > 0 ? ariaLabelledBy : void 0,
|
|
265
269
|
className: cn("relative", self && "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent", className),
|
|
266
270
|
children: count === 0 && empty != null ? empty : /* @__PURE__ */ jsx(
|
|
267
271
|
"div",
|
package/dist/esm/format.js
CHANGED
|
@@ -134,7 +134,7 @@ function money(v, o = {}) {
|
|
|
134
134
|
}
|
|
135
135
|
function signedMoney(v, o = {}) {
|
|
136
136
|
if (!finite(v)) return DASH;
|
|
137
|
-
if (Math.abs(v) < 5e-3) return "No change";
|
|
137
|
+
if (Math.abs(v) < 5e-3) return o.zero ?? "No change";
|
|
138
138
|
return (v < 0 ? MINUS : "+") + moneyAbs(Math.abs(v), o, loc(o));
|
|
139
139
|
}
|
|
140
140
|
function pct(v, o = {}) {
|
|
@@ -172,7 +172,8 @@ function bytes(v, o = {}) {
|
|
|
172
172
|
i++;
|
|
173
173
|
}
|
|
174
174
|
const text = i === 0 || abs >= 100 ? fixed(abs, 0, 0, locale) : fixed(abs, 0, 1, locale);
|
|
175
|
-
|
|
175
|
+
const zero = Number(text.replace(/[^0-9]/g, "")) === 0;
|
|
176
|
+
return (v < 0 && !zero ? MINUS : "") + text + " " + BYTE_UNITS[i];
|
|
176
177
|
}
|
|
177
178
|
var DURATION_PARTS = [
|
|
178
179
|
[86400, "d", "day"],
|
package/dist/esm/runtime.js
CHANGED
|
@@ -236,6 +236,10 @@ function createInboxClient(options) {
|
|
|
236
236
|
}
|
|
237
237
|
if (queue[0] === head) queue.shift();
|
|
238
238
|
if (result.kind === "ok") sentSinceDown++;
|
|
239
|
+
else if (!loggedInvalid.has(result.error)) {
|
|
240
|
+
loggedInvalid.add(result.error);
|
|
241
|
+
log(`queued event dropped: ${result.error}`);
|
|
242
|
+
}
|
|
239
243
|
}
|
|
240
244
|
retryStep = 0;
|
|
241
245
|
if (down) {
|
package/dist/esm/theme.js
CHANGED
|
@@ -25,7 +25,10 @@ function storageKey() {
|
|
|
25
25
|
return k && /^[A-Za-z0-9_-]+$/.test(k) ? k : DEFAULT_KEY;
|
|
26
26
|
}
|
|
27
27
|
function registerThemes(themes) {
|
|
28
|
-
Object.
|
|
28
|
+
for (const [name, scheme] of Object.entries(themes)) {
|
|
29
|
+
if (/^[a-z0-9-]+$/.test(name)) state().extra[name] = scheme;
|
|
30
|
+
else console.warn(`[nish-ui] registerThemes: skipped "${name}" (use lowercase letters, digits and hyphens)`);
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
var has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
31
34
|
function isThemeName(v) {
|
|
@@ -34,7 +37,7 @@ function isThemeName(v) {
|
|
|
34
37
|
function readCookie() {
|
|
35
38
|
if (typeof document === "undefined") return null;
|
|
36
39
|
try {
|
|
37
|
-
const m = document.cookie.match(new RegExp(`(?:^|;\\s*)${storageKey()}=([a-z0-9-]+)`));
|
|
40
|
+
const m = document.cookie.match(new RegExp(`(?:^|;\\s*)${storageKey()}=([a-z0-9-]+)(?:;|$)`));
|
|
38
41
|
return m ? m[1] : null;
|
|
39
42
|
} catch {
|
|
40
43
|
return null;
|
|
@@ -238,7 +241,7 @@ function mountThemeToggle(button, opts = {}) {
|
|
|
238
241
|
if (svg.getAttribute("data-icon") === icon) svg.removeAttribute("display");
|
|
239
242
|
else svg.setAttribute("display", "none");
|
|
240
243
|
});
|
|
241
|
-
const elsewhere = TOGGLE_ORDER.includes(choice) ? "" : ` (${elsewhereWords})`;
|
|
244
|
+
const elsewhere = TOGGLE_ORDER.includes(choice) || has(state().extra, choice) ? "" : ` (${elsewhereWords})`;
|
|
242
245
|
const label = sentence(`${themeLabel(choice, words)}${elsewhere}`, themeLabel(nextChoice(choice), words));
|
|
243
246
|
button.setAttribute("aria-label", label);
|
|
244
247
|
button.setAttribute("title", label);
|
|
@@ -278,7 +281,8 @@ var toastRegion = null;
|
|
|
278
281
|
var hideCurrent = null;
|
|
279
282
|
function showToast(content, opts = {}) {
|
|
280
283
|
hideCurrent?.();
|
|
281
|
-
if (!toastRegion || !toastRegion.isConnected)
|
|
284
|
+
if (!toastRegion || !toastRegion.isConnected) toastRegion = document.querySelector(".nish-toast-region");
|
|
285
|
+
if (!toastRegion) {
|
|
282
286
|
toastRegion = document.createElement("div");
|
|
283
287
|
toastRegion.setAttribute("role", "status");
|
|
284
288
|
toastRegion.setAttribute("aria-live", "polite");
|
|
@@ -301,10 +305,13 @@ function showToast(content, opts = {}) {
|
|
|
301
305
|
let remaining = opts.duration === "sticky" ? Infinity : opts.duration ?? TOAST_MS;
|
|
302
306
|
let started = 0;
|
|
303
307
|
let holds = 0;
|
|
308
|
+
let returnTo = null;
|
|
304
309
|
const hide = () => {
|
|
305
310
|
if (timer != null) clearTimeout(timer);
|
|
306
311
|
timer = null;
|
|
312
|
+
const hadFocus = box.contains(document.activeElement);
|
|
307
313
|
box.remove();
|
|
314
|
+
if (hadFocus && returnTo?.isConnected) returnTo.focus();
|
|
308
315
|
if (hideCurrent === hide) hideCurrent = null;
|
|
309
316
|
};
|
|
310
317
|
const run = (ms) => {
|
|
@@ -347,7 +354,11 @@ function showToast(content, opts = {}) {
|
|
|
347
354
|
box.append(close);
|
|
348
355
|
box.addEventListener("pointerenter", (e) => e.pointerType === "mouse" && pause());
|
|
349
356
|
box.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && resume());
|
|
350
|
-
box.addEventListener("focusin", (e) =>
|
|
357
|
+
box.addEventListener("focusin", (e) => {
|
|
358
|
+
if (box.contains(e.relatedTarget)) return;
|
|
359
|
+
if (e.relatedTarget instanceof HTMLElement) returnTo = e.relatedTarget;
|
|
360
|
+
pause();
|
|
361
|
+
});
|
|
351
362
|
box.addEventListener("focusout", (e) => !box.contains(e.relatedTarget) && resume());
|
|
352
363
|
box.addEventListener("keydown", (e) => {
|
|
353
364
|
if (e.key === "Escape") hide();
|
|
@@ -361,6 +372,11 @@ function showToast(content, opts = {}) {
|
|
|
361
372
|
return hide;
|
|
362
373
|
}
|
|
363
374
|
var dialogSeq = 0;
|
|
375
|
+
function onBackdrop(dialog, e) {
|
|
376
|
+
if (e.target !== dialog) return false;
|
|
377
|
+
const r = dialog.getBoundingClientRect();
|
|
378
|
+
return !(e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom);
|
|
379
|
+
}
|
|
364
380
|
function confirmDialog(opts) {
|
|
365
381
|
if (typeof document === "undefined") return Promise.resolve(false);
|
|
366
382
|
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
@@ -416,11 +432,12 @@ function confirmDialog(opts) {
|
|
|
416
432
|
finish(false);
|
|
417
433
|
});
|
|
418
434
|
dialog.addEventListener("close", () => finish(false));
|
|
435
|
+
let pressedOnBackdrop = null;
|
|
436
|
+
dialog.addEventListener("pointerdown", (e) => pressedOnBackdrop = onBackdrop(dialog, e));
|
|
419
437
|
dialog.addEventListener("click", (e) => {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (!inside) finish(false);
|
|
438
|
+
const down = pressedOnBackdrop;
|
|
439
|
+
pressedOnBackdrop = null;
|
|
440
|
+
if (down !== false && onBackdrop(dialog, e)) finish(false);
|
|
424
441
|
});
|
|
425
442
|
document.body.append(dialog);
|
|
426
443
|
dialog.showModal();
|
|
@@ -497,11 +514,15 @@ function openSheet(dialog) {
|
|
|
497
514
|
const onKey = (e) => {
|
|
498
515
|
if (e.key === "Escape") e.stopPropagation();
|
|
499
516
|
};
|
|
517
|
+
let pressedOnBackdrop = null;
|
|
518
|
+
const onPress = (e) => {
|
|
519
|
+
pressedOnBackdrop = onBackdrop(dialog, e);
|
|
520
|
+
};
|
|
500
521
|
const onClick = (e) => {
|
|
501
522
|
if (e.target === dialog) {
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
if (
|
|
523
|
+
const down = pressedOnBackdrop;
|
|
524
|
+
pressedOnBackdrop = null;
|
|
525
|
+
if (down !== false && onBackdrop(dialog, e)) closeNow();
|
|
505
526
|
return;
|
|
506
527
|
}
|
|
507
528
|
if (e.target instanceof Element && e.target.closest("[data-sheet-close]")) closeNow();
|
|
@@ -516,7 +537,7 @@ function openSheet(dialog) {
|
|
|
516
537
|
if (typeof matchMedia !== "undefined" && matchMedia("(min-width: 640px)").matches) return;
|
|
517
538
|
const r = dialog.getBoundingClientRect();
|
|
518
539
|
const onHeader = e.target instanceof Element && e.target.closest(".nish-sheet-header") != null;
|
|
519
|
-
if (!onHeader && e.clientY - r.top >
|
|
540
|
+
if (!onHeader && e.clientY - r.top > 44) return;
|
|
520
541
|
dragging = true;
|
|
521
542
|
startY = lastY = e.clientY;
|
|
522
543
|
lastT = e.timeStamp;
|
|
@@ -553,6 +574,7 @@ function openSheet(dialog) {
|
|
|
553
574
|
dialog.removeEventListener("cancel", onCancel);
|
|
554
575
|
dialog.removeEventListener("keydown", onKey);
|
|
555
576
|
dialog.removeEventListener("click", onClick);
|
|
577
|
+
dialog.removeEventListener("pointerdown", onPress);
|
|
556
578
|
dialog.removeEventListener("pointerdown", onDown);
|
|
557
579
|
dialog.removeEventListener("pointermove", onMove);
|
|
558
580
|
dialog.removeEventListener("pointerup", onUp);
|
|
@@ -563,6 +585,7 @@ function openSheet(dialog) {
|
|
|
563
585
|
dialog.addEventListener("cancel", onCancel);
|
|
564
586
|
dialog.addEventListener("keydown", onKey);
|
|
565
587
|
dialog.addEventListener("click", onClick);
|
|
588
|
+
dialog.addEventListener("pointerdown", onPress);
|
|
566
589
|
dialog.addEventListener("pointerdown", onDown);
|
|
567
590
|
dialog.addEventListener("pointermove", onMove);
|
|
568
591
|
dialog.addEventListener("pointerup", onUp);
|
|
@@ -792,7 +815,7 @@ function mountScrollspy(nav, o = {}) {
|
|
|
792
815
|
};
|
|
793
816
|
return Object.assign(stop, { lock });
|
|
794
817
|
}
|
|
795
|
-
function mountChecklist(list) {
|
|
818
|
+
function mountChecklist(list, opts = {}) {
|
|
796
819
|
if (typeof document === "undefined") return () => void 0;
|
|
797
820
|
const key = list.dataset.store || null;
|
|
798
821
|
const boxes = () => Array.from(list.querySelectorAll('li[data-id] input[type="checkbox"]'));
|
|
@@ -816,7 +839,7 @@ function mountChecklist(list) {
|
|
|
816
839
|
const all = boxes();
|
|
817
840
|
const done = all.filter((b) => b.checked).length;
|
|
818
841
|
if (progress) {
|
|
819
|
-
progress.textContent = `${done} of ${all.length}`;
|
|
842
|
+
progress.textContent = opts.format ? opts.format(done, all.length) : `${done} of ${all.length}`;
|
|
820
843
|
progress.style.setProperty("--p", `${all.length ? done / all.length * 100 : 0}%`);
|
|
821
844
|
}
|
|
822
845
|
};
|
package/dist/esm/tokens.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The one source of truth for every design token. scripts/build.mjs turns this into
|
|
2
2
|
// dist/tokens.css (--nish-* custom properties), tools/contrast.mjs checks it, and
|
|
3
|
-
// src/theme.ts
|
|
3
|
+
// src/theme.ts builds PRESETS from THEMES. Edit values here, never in generated CSS.
|
|
4
4
|
//
|
|
5
5
|
// Colors are plain hex so static pages can use them as-is; Tailwind opacity
|
|
6
6
|
// modifiers (bg-th-surface/50) work through color-mix in Tailwind 4.
|
package/dist/format.d.ts
CHANGED
|
@@ -22,8 +22,10 @@ interface MoneyOptions extends LocaleOptions {
|
|
|
22
22
|
}
|
|
23
23
|
/** Money: 1234.56 → "$1,234.56"; negatives use a true minus sign. The symbol always comes first. */
|
|
24
24
|
declare function money(v: number | null | undefined, o?: MoneyOptions): string;
|
|
25
|
-
/** Signed money: "+$12.30", "−$4.00", and "No change" when |v| < 0.005. */
|
|
26
|
-
declare function signedMoney(v: number | null | undefined, o?: MoneyOptions
|
|
25
|
+
/** Signed money: "+$12.30", "−$4.00", and "No change" when |v| < 0.005. Pass `zero` for another language. */
|
|
26
|
+
declare function signedMoney(v: number | null | undefined, o?: MoneyOptions & {
|
|
27
|
+
zero?: string;
|
|
28
|
+
}): string;
|
|
27
29
|
interface PctOptions extends LocaleOptions {
|
|
28
30
|
/** Fraction digits. Default 1. */
|
|
29
31
|
digits?: number;
|
|
@@ -35,7 +37,7 @@ interface PctOptions extends LocaleOptions {
|
|
|
35
37
|
/** Percent: 0.123 → "12.3%". */
|
|
36
38
|
declare function pct(v: number | null | undefined, o?: PctOptions): string;
|
|
37
39
|
interface NumOptions extends LocaleOptions {
|
|
38
|
-
/** Fixed fraction digits. Default: up to 2, trailing zeros trimmed (1 when compact). */
|
|
40
|
+
/** Fixed fraction digits. Default: up to 2, trailing zeros trimmed (1 when compact). With `compact`, digits is a maximum: 12000 gives "12k", not "12.00k". */
|
|
39
41
|
digits?: number;
|
|
40
42
|
/** Short form: 12.3k, 4.5M. */
|
|
41
43
|
compact?: boolean;
|
package/dist/format.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/runtime.ts
|
|
2
|
-
var version = true ? "3.
|
|
2
|
+
var version = true ? "3.3.0" : "dev";
|
|
3
3
|
var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
|
|
4
4
|
function runtime() {
|
|
5
5
|
const g = globalThis;
|
|
@@ -167,7 +167,7 @@ function money(v, o = {}) {
|
|
|
167
167
|
}
|
|
168
168
|
function signedMoney(v, o = {}) {
|
|
169
169
|
if (!finite(v)) return DASH;
|
|
170
|
-
if (Math.abs(v) < 5e-3) return "No change";
|
|
170
|
+
if (Math.abs(v) < 5e-3) return o.zero ?? "No change";
|
|
171
171
|
return (v < 0 ? MINUS : "+") + moneyAbs(Math.abs(v), o, loc(o));
|
|
172
172
|
}
|
|
173
173
|
function pct(v, o = {}) {
|
|
@@ -205,7 +205,8 @@ function bytes(v, o = {}) {
|
|
|
205
205
|
i++;
|
|
206
206
|
}
|
|
207
207
|
const text = i === 0 || abs >= 100 ? fixed(abs, 0, 0, locale) : fixed(abs, 0, 1, locale);
|
|
208
|
-
|
|
208
|
+
const zero = Number(text.replace(/[^0-9]/g, "")) === 0;
|
|
209
|
+
return (v < 0 && !zero ? MINUS : "") + text + " " + BYTE_UNITS[i];
|
|
209
210
|
}
|
|
210
211
|
var DURATION_PARTS = [
|
|
211
212
|
[86400, "d", "day"],
|
package/dist/inbox-client.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ interface InboxEventInput {
|
|
|
57
57
|
kind: string;
|
|
58
58
|
/** Headline, trimmed, 1-140 characters. Longer text is cut to 139 plus an ellipsis. */
|
|
59
59
|
title: string;
|
|
60
|
-
/** Details, trimmed, up to 2000 characters. Longer text is cut to 1999 plus an ellipsis; an empty string becomes
|
|
60
|
+
/** Details, trimmed, up to 2000 characters. Longer text is cut to 1999 plus an ellipsis; an empty string becomes null. */
|
|
61
61
|
body?: string;
|
|
62
62
|
/** Link opened when the notification or item is tapped. http: or https:, up to 2000 characters. */
|
|
63
63
|
url?: string;
|
package/dist/inbox-client.js
CHANGED
|
@@ -254,6 +254,10 @@ function createInboxClient(options) {
|
|
|
254
254
|
}
|
|
255
255
|
if (queue[0] === head) queue.shift();
|
|
256
256
|
if (result.kind === "ok") sentSinceDown++;
|
|
257
|
+
else if (!loggedInvalid.has(result.error)) {
|
|
258
|
+
loggedInvalid.add(result.error);
|
|
259
|
+
log(`queued event dropped: ${result.error}`);
|
|
260
|
+
}
|
|
257
261
|
}
|
|
258
262
|
retryStep = 0;
|
|
259
263
|
if (down) {
|