nish-ui 3.0.0 → 3.1.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 +5 -5
- package/dist/chart.d.ts +8 -3
- package/dist/chart.js +2 -417
- package/dist/elements-all.js +71 -70
- package/dist/elements-charts.d.ts +7 -1
- package/dist/elements-charts.js +16 -16
- package/dist/elements-data.d.ts +7 -1
- package/dist/elements-data.js +5 -5
- package/dist/elements-forms.d.ts +7 -1
- package/dist/elements-forms.js +18 -17
- package/dist/elements.d.ts +7 -1
- package/dist/elements.js +4 -4
- package/dist/esm/components/avatar.js +2 -2
- package/dist/esm/components/canvas/legend.js +4 -4
- package/dist/esm/components/canvas/system-canvas.js +24 -1
- package/dist/esm/components/carousel.js +21 -3
- package/dist/esm/components/charts.js +21 -13
- package/dist/esm/components/combobox.js +1 -1
- package/dist/esm/components/data-classes.js +5 -4
- package/dist/esm/components/data.js +1 -5
- package/dist/esm/components/date-picker.js +1 -0
- package/dist/esm/components/date-range-picker.js +1 -0
- package/dist/esm/components/display.js +3 -3
- package/dist/esm/components/file-dropzone.js +21 -1
- package/dist/esm/components/filters.js +3 -1
- package/dist/esm/components/flow.js +12 -11
- package/dist/esm/components/forms.js +24 -2
- package/dist/esm/components/hooks.js +20 -17
- package/dist/esm/components/inbox.js +9 -7
- package/dist/esm/components/layout-vars.js +10 -7
- package/dist/esm/components/menu.js +7 -4
- package/dist/esm/components/multi-select.js +7 -4
- package/dist/esm/components/overlay-core.js +31 -10
- package/dist/esm/components/overlay-dialog.js +17 -2
- package/dist/esm/components/pagination.js +4 -1
- package/dist/esm/components/popover.js +15 -9
- package/dist/esm/components/primitives.js +1 -1
- package/dist/esm/components/progress.js +2 -0
- package/dist/esm/components/resource-classes.js +34 -16
- package/dist/esm/components/resource.js +5 -4
- package/dist/esm/components/settings.js +4 -2
- package/dist/esm/components/slider.js +1 -0
- package/dist/esm/components/strings.js +9 -1
- package/dist/esm/components/tag-input.js +15 -7
- package/dist/esm/components/time-field-classes.js +5 -2
- package/dist/esm/components/time-field.js +15 -7
- package/dist/esm/components/tooltip.js +1 -1
- package/dist/esm/components/url-state.js +1 -0
- package/dist/esm/components/virtual-table.js +8 -2
- package/dist/esm/components/virtual.js +16 -2
- package/dist/esm/format.js +17 -14
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/server/inbox/client.js +1 -1
- package/dist/esm/theme.js +66 -6
- package/dist/format.js +18 -15
- package/dist/inbox-client.js +1 -1
- package/dist/index.d.ts +32 -7
- package/dist/nish-components.css +41 -1
- package/dist/nish-components.min.css +1 -1
- package/dist/node/th-check.js +12 -3
- package/dist/server/hono.d.ts +1 -1
- package/dist/server/hono.js +20 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +19 -5
- package/dist/{spa-BLlMc0eI.d.ts → spa-7myD4xvA.d.ts} +3 -2
- package/dist/system-canvas.d.ts +0 -4
- package/dist/theme.d.ts +20 -2
- package/dist/theme.global.js +67 -7
- package/dist/theme.js +67 -7
- package/package.json +1 -1
|
@@ -71,10 +71,6 @@ var TONE_EDGE = {
|
|
|
71
71
|
warn: "border-s-[3px] border-s-[var(--nish-warn-fill)]",
|
|
72
72
|
loss: "border-s-[3px] border-s-[var(--nish-loss-fill)]"
|
|
73
73
|
};
|
|
74
|
-
var DEFAULT_SORT_TEXT = {
|
|
75
|
-
announce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
|
|
76
|
-
toggle: (dir) => dir === "desc" ? "Sorted descending, switch to ascending" : "Sorted ascending, switch to descending"
|
|
77
|
-
};
|
|
78
74
|
var BodyRow = /* @__PURE__ */ memo(function BodyRow2({ row, columns, tone, interactive, onGo }) {
|
|
79
75
|
return /* @__PURE__ */ jsx(
|
|
80
76
|
Tr,
|
|
@@ -122,7 +118,7 @@ function ResponsiveTable({
|
|
|
122
118
|
...rest
|
|
123
119
|
}) {
|
|
124
120
|
const t = useStrings(STATUS_STRINGS, TABLE_STRINGS);
|
|
125
|
-
const text = {
|
|
121
|
+
const text = { announce: sortText?.announce ?? t.sortAnnounce, toggle: sortText?.toggle ?? t.sortToggle };
|
|
126
122
|
const [innerSort, setInnerSort] = useState(null);
|
|
127
123
|
const [announcement, setAnnouncement] = useState("");
|
|
128
124
|
const sortId = useId();
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import { Skeleton } from "./feedback.js";
|
|
37
37
|
import { AlertTriangleIcon, CheckCircleIcon, ChevronDownIcon, InfoIcon, XIcon } from "./icons.js";
|
|
38
38
|
import { useHeightVar, useStuck } from "./layout-vars.js";
|
|
39
|
-
import { DropdownMenu } from "./menu.js";
|
|
39
|
+
import { DropdownMenu, InlineMenuItemContext } from "./menu.js";
|
|
40
40
|
import { Tooltip } from "./tooltip.js";
|
|
41
41
|
import { Badge, Button, Card, IconButton } from "./primitives.js";
|
|
42
42
|
import { useStrings } from "./provider.js";
|
|
@@ -115,7 +115,7 @@ function Callout({
|
|
|
115
115
|
const dismissEl = onDismiss ? /* @__PURE__ */ jsx(IconButton, { label: dismissLabel ?? strings.dismiss, size: "xs", onClick: onDismiss, className: "-my-0.5 -me-1", children: /* @__PURE__ */ jsx(XIcon, { size: 14 }) }) : null;
|
|
116
116
|
const chevron = /* @__PURE__ */ jsx(ChevronDownIcon, { size: 16, className: "-rotate-90 shrink-0 self-center text-th-hi3 rtl:rotate-90" });
|
|
117
117
|
const hit = cn(
|
|
118
|
-
"flex min-h-11 min-w-0 flex-1 items-start text-start outline-none focus-visible:ring-2 focus-visible:ring-th-accent/40",
|
|
118
|
+
"flex min-h-11 min-w-0 flex-1 items-start text-start outline-none focus-visible:ring-2 focus-visible:ring-th-accent/40 forced-colors:focus-visible:outline-2 forced-colors:focus-visible:outline-solid forced-colors:focus-visible:outline-[Highlight]",
|
|
119
119
|
compact ? "gap-2" : "gap-3",
|
|
120
120
|
// Pull the padding of the row into the link so the whole row is the target.
|
|
121
121
|
compact ? "-my-2 py-2" : "-my-3 py-3"
|
|
@@ -648,7 +648,7 @@ function AppHeader({
|
|
|
648
648
|
/* @__PURE__ */ jsxs("div", { className: "ms-auto flex shrink-0 items-center gap-2", children: [
|
|
649
649
|
actions,
|
|
650
650
|
overflowActions ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
651
|
-
/* @__PURE__ */ jsx("div", { ref: inlineActionsRef, className: "hidden items-center gap-2 sm:flex [&>button]:w-auto", children: overflowActions }),
|
|
651
|
+
/* @__PURE__ */ jsx("div", { ref: inlineActionsRef, className: "hidden items-center gap-2 sm:flex [&>button]:w-auto", children: /* @__PURE__ */ jsx(InlineMenuItemContext.Provider, { value: true, children: overflowActions }) }),
|
|
652
652
|
/* @__PURE__ */ jsx("div", { className: "sm:hidden", children: /* @__PURE__ */ jsx(
|
|
653
653
|
DropdownMenu,
|
|
654
654
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/components/file-dropzone.tsx
|
|
4
|
-
import { useRef, useState } from "react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { XIcon } from "./icons.js";
|
|
7
7
|
import { IconButton } from "./primitives.js";
|
|
@@ -60,6 +60,26 @@ function FileDropzone({
|
|
|
60
60
|
const [files, setFiles] = useState([]);
|
|
61
61
|
const [dragging, setDragging] = useState(false);
|
|
62
62
|
const isInvalid = invalid || ariaInvalid === true || ariaInvalid === "true";
|
|
63
|
+
const latestChange = useRef(onFilesChange);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
latestChange.current = onFilesChange;
|
|
66
|
+
});
|
|
67
|
+
const hasFiles = useRef(false);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
hasFiles.current = files.length > 0;
|
|
70
|
+
}, [files]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const form = input.current?.form;
|
|
73
|
+
if (!form) return;
|
|
74
|
+
const onReset = () => {
|
|
75
|
+
depth.current = 0;
|
|
76
|
+
setDragging(false);
|
|
77
|
+
setFiles([]);
|
|
78
|
+
if (hasFiles.current) latestChange.current?.([], []);
|
|
79
|
+
};
|
|
80
|
+
form.addEventListener("reset", onReset);
|
|
81
|
+
return () => form.removeEventListener("reset", onReset);
|
|
82
|
+
}, []);
|
|
63
83
|
const take = (incoming) => {
|
|
64
84
|
const rejected = [];
|
|
65
85
|
const list = multiple ? [...files] : [];
|
|
@@ -64,7 +64,9 @@ function FilterBar({
|
|
|
64
64
|
}) {
|
|
65
65
|
const strings = useStrings(FILTER_STRINGS, FIELD_STRINGS);
|
|
66
66
|
const compact = useMediaQuery(sheetBelow === "lg" ? LG_QUERY : NARROW_QUERY);
|
|
67
|
-
const [
|
|
67
|
+
const [openState, setOpen] = useState(false);
|
|
68
|
+
const open = openState && compact;
|
|
69
|
+
if (!compact && openState) setOpen(false);
|
|
68
70
|
const hasChildren = children != null && children !== false;
|
|
69
71
|
const searchBox = search ? /* @__PURE__ */ jsx(
|
|
70
72
|
SearchInput,
|
|
@@ -14,7 +14,7 @@ import { useIsoLayoutEffect } from "./client.js";
|
|
|
14
14
|
import { useMediaQuery, useNow } from "./hooks.js";
|
|
15
15
|
import { Tooltip } from "./tooltip.js";
|
|
16
16
|
import { Badge } from "./primitives.js";
|
|
17
|
-
import { useStrings } from "./provider.js";
|
|
17
|
+
import { useNishContext, useStrings } from "./provider.js";
|
|
18
18
|
import { PROGRESS_STRINGS, FLOW_STRINGS } from "./strings.js";
|
|
19
19
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
20
20
|
var EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
@@ -120,7 +120,6 @@ var NODE_STATUS = {
|
|
|
120
120
|
done: "bg-th-ok-fill text-th-on-ok forced-colors:border-2 forced-colors:border-[color:Highlight]",
|
|
121
121
|
failed: "bg-th-loss-fill text-th-on-loss forced-colors:border-2 forced-colors:border-dashed forced-colors:border-[color:CanvasText]"
|
|
122
122
|
};
|
|
123
|
-
var STEP_SR_DEFAULT = { done: ", done", failed: ", failed" };
|
|
124
123
|
function pickStepFx(from, to) {
|
|
125
124
|
if (to === "done") return "done";
|
|
126
125
|
if (to === "failed") return "failed";
|
|
@@ -229,7 +228,7 @@ function FlowSteps({ steps, orientation = "auto", label, statusLabels, className
|
|
|
229
228
|
index: i,
|
|
230
229
|
last: i === steps.length - 1,
|
|
231
230
|
sweeping,
|
|
232
|
-
statusWord: step.status === "done" || step.status === "failed" ? statusLabels?.[step.status] ??
|
|
231
|
+
statusWord: step.status === "done" || step.status === "failed" ? statusLabels?.[step.status] ?? (step.status === "done" ? s.stepDone : s.stepFailed) : void 0
|
|
233
232
|
},
|
|
234
233
|
step.id
|
|
235
234
|
)) }) });
|
|
@@ -298,12 +297,6 @@ function TickerText({ text, as = "span", className, ref, ...rest }) {
|
|
|
298
297
|
/* @__PURE__ */ jsx("span", { className: animating ? "nish-flow-ticker-in" : void 0, children: cur.text }, cur.text)
|
|
299
298
|
] });
|
|
300
299
|
}
|
|
301
|
-
var STATE_WORD = {
|
|
302
|
-
queued: "Queued",
|
|
303
|
-
running: "Running",
|
|
304
|
-
done: "Done",
|
|
305
|
-
failed: "Failed"
|
|
306
|
-
};
|
|
307
300
|
var AGENT_STATE = {
|
|
308
301
|
queued: "border-dashed border-th-line opacity-70",
|
|
309
302
|
running: "border-th-accent",
|
|
@@ -349,7 +342,14 @@ function AgentNode({ label, state, model, activity, meta, onClick, stateLabels,
|
|
|
349
342
|
const own = useRef(null);
|
|
350
343
|
const ref = useMergedRef(own, refProp);
|
|
351
344
|
useTransitionFx(state, own, pickAgentFx);
|
|
352
|
-
const
|
|
345
|
+
const s = useStrings(FLOW_STRINGS);
|
|
346
|
+
const stateWord = {
|
|
347
|
+
queued: s.agentQueued,
|
|
348
|
+
running: s.agentRunning,
|
|
349
|
+
done: s.agentDone,
|
|
350
|
+
failed: s.agentFailed
|
|
351
|
+
};
|
|
352
|
+
const aria = `${label}: ${stateLabels?.[state] ?? stateWord[state]}`;
|
|
353
353
|
const classes = cn(
|
|
354
354
|
"nish-flow-agent block min-h-16 w-full min-w-0 rounded-xl border bg-th-surface p-3 text-start",
|
|
355
355
|
AGENT_STATE[state],
|
|
@@ -509,6 +509,7 @@ var FEED_DOT = {
|
|
|
509
509
|
var FEED_DOT_FORCED = "forced-colors:bg-[color:CanvasText]";
|
|
510
510
|
function ActivityFeed({ items, max = 50, now, label, empty, className, ref, ...rest }) {
|
|
511
511
|
const s = useStrings(PROGRESS_STRINGS, FLOW_STRINGS);
|
|
512
|
+
const { locale } = useNishContext();
|
|
512
513
|
const internalNow = useNow(15e3);
|
|
513
514
|
const clock = now ?? internalNow;
|
|
514
515
|
const shown = useMemo(() => [...items].sort((a, b) => b.at - a.at).slice(0, Math.max(0, max)), [items, max]);
|
|
@@ -525,7 +526,7 @@ function ActivityFeed({ items, max = 50, now, label, empty, className, ref, ...r
|
|
|
525
526
|
/* @__PURE__ */ jsx("div", { className: "break-words text-sm text-th-hi2", children: item.text }),
|
|
526
527
|
item.source != null ? /* @__PURE__ */ jsx("div", { className: "break-words text-xs text-th-hi3", children: item.source }) : null
|
|
527
528
|
] }),
|
|
528
|
-
/* @__PURE__ */ jsx("span", { className: "pt-0.5 text-end text-xs tabular-nums text-th-hi3", children: ago(item.at, { now: clock, style: "short" }) })
|
|
529
|
+
/* @__PURE__ */ jsx("span", { className: "pt-0.5 text-end text-xs tabular-nums text-th-hi3", children: ago(item.at, { now: clock, style: "short", locale }) })
|
|
529
530
|
] }) }) }, item.id)) });
|
|
530
531
|
}
|
|
531
532
|
var ENTER_MS = 400;
|
|
@@ -69,6 +69,28 @@ function Textarea({ ref, invalid, size = "md", autoGrow = false, className, rows
|
|
|
69
69
|
useIsoLayoutEffect(() => {
|
|
70
70
|
resize();
|
|
71
71
|
}, [resize, value]);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const el = inner.current;
|
|
74
|
+
if (!grow || !el) return;
|
|
75
|
+
let lastWidth = el.clientWidth;
|
|
76
|
+
let ro;
|
|
77
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
78
|
+
ro = new ResizeObserver(() => {
|
|
79
|
+
const w = el.clientWidth;
|
|
80
|
+
if (w === lastWidth) return;
|
|
81
|
+
lastWidth = w;
|
|
82
|
+
resize();
|
|
83
|
+
});
|
|
84
|
+
ro.observe(el);
|
|
85
|
+
}
|
|
86
|
+
const form = el.form;
|
|
87
|
+
const onReset = () => queueMicrotask(resize);
|
|
88
|
+
form?.addEventListener("reset", onReset);
|
|
89
|
+
return () => {
|
|
90
|
+
ro?.disconnect();
|
|
91
|
+
form?.removeEventListener("reset", onReset);
|
|
92
|
+
};
|
|
93
|
+
}, [grow, resize]);
|
|
72
94
|
return /* @__PURE__ */ jsx(
|
|
73
95
|
"textarea",
|
|
74
96
|
{
|
|
@@ -225,8 +247,8 @@ function Switch({
|
|
|
225
247
|
role: "switch",
|
|
226
248
|
"aria-checked": checked,
|
|
227
249
|
"aria-required": required || void 0,
|
|
228
|
-
"aria-labelledby": label != null ? labelId : rest["aria-labelledby"],
|
|
229
|
-
"aria-describedby": description != null ? descId :
|
|
250
|
+
"aria-labelledby": [label != null ? labelId : void 0, rest["aria-labelledby"]].filter(Boolean).join(" ") || void 0,
|
|
251
|
+
"aria-describedby": [rest["aria-describedby"], description != null ? descId : void 0].filter(Boolean).join(" ") || void 0,
|
|
230
252
|
"data-state": state,
|
|
231
253
|
"data-disabled": disabled ? "" : void 0,
|
|
232
254
|
disabled,
|
|
@@ -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
|
|
130
|
-
|
|
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)
|
|
135
|
-
else
|
|
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 =
|
|
146
|
-
if (!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 (!
|
|
150
|
-
|
|
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 &&
|
|
156
|
-
if (
|
|
157
|
-
|
|
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() ===
|
|
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
|
] }),
|
|
@@ -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
|
|
7
|
+
var heightOwnersMap = () => shared("heightVars", () => /* @__PURE__ */ new Map());
|
|
7
8
|
function applyHeightVar(name) {
|
|
8
|
-
const owners =
|
|
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 =
|
|
20
|
-
if (!owners)
|
|
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)
|
|
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
|
-
|
|
62
|
-
|
|
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,8 +242,8 @@ 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,
|
|
@@ -251,13 +253,13 @@ function MenuItem({
|
|
|
251
253
|
},
|
|
252
254
|
onMouseMove: (e) => {
|
|
253
255
|
onMouseMove?.(e);
|
|
254
|
-
if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
|
|
256
|
+
if (!inline && !disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
|
|
255
257
|
},
|
|
256
258
|
className: menuItemClass({
|
|
257
259
|
active,
|
|
258
260
|
danger,
|
|
259
261
|
disabled,
|
|
260
|
-
className: cn(!disabled && (danger ? "focus:bg-th-loss-soft" : "focus:bg-th-overlay focus:text-th-hi"), className)
|
|
262
|
+
className: cn(!inline && !disabled && (danger ? "focus:bg-th-loss-soft" : "focus:bg-th-overlay focus:text-th-hi"), className)
|
|
261
263
|
}),
|
|
262
264
|
children: [
|
|
263
265
|
icon ? /* @__PURE__ */ jsx("span", { className: cn("inline-flex shrink-0", danger || disabled ? "" : "text-th-hi3"), children: icon }) : null,
|
|
@@ -336,6 +338,7 @@ function MenuSubHeader({ onBack, children, className, ref, onKeyDown, ...rest })
|
|
|
336
338
|
export {
|
|
337
339
|
DropdownMenu,
|
|
338
340
|
ITEM_SELECTOR,
|
|
341
|
+
InlineMenuItemContext,
|
|
339
342
|
MenuContext,
|
|
340
343
|
MenuItem,
|
|
341
344
|
MenuLabel,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/components/multi-select.tsx
|
|
4
|
-
import {
|
|
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";
|
|
@@ -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 =
|
|
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
|
-
|
|
271
|
+
if (text !== "") {
|
|
272
|
+
setText("");
|
|
273
|
+
queryChanged("");
|
|
274
|
+
}
|
|
272
275
|
}
|
|
273
276
|
},
|
|
274
277
|
className: cn("relative w-full min-w-0", className),
|
|
@@ -77,20 +77,27 @@ function syncInert() {
|
|
|
77
77
|
inerted.clear();
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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(() =>
|
|
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(() =>
|
|
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: () =>
|
|
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
|
|
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(
|
|
41
|
+
useDismiss(shown, panelRef, anchor, (reason) => {
|
|
36
42
|
if (reason === "outside" && !outsideRef.current) return;
|
|
37
43
|
onOpenChangeRef.current(false, reason);
|
|
38
44
|
});
|
|
39
|
-
useReturnFocus(
|
|
45
|
+
useReturnFocus(shown, panelRef, anchor);
|
|
40
46
|
useEffect(() => {
|
|
41
|
-
if (!
|
|
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
|
-
}, [
|
|
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
|
-
|
|
93
|
+
host
|
|
88
94
|
);
|
|
89
95
|
}
|
|
90
96
|
export {
|