nish-ui 2.2.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 +10 -6
- package/dist/chart.d.ts +8 -3
- package/dist/chart.js +2 -417
- package/dist/elements-all.js +81 -80
- 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/accordion.js +3 -2
- package/dist/esm/components/app-shell.js +3 -2
- package/dist/esm/components/avatar.js +6 -5
- package/dist/esm/components/breadcrumbs.js +3 -2
- package/dist/esm/components/calendar-base.js +4 -3
- package/dist/esm/components/canvas/legend.js +7 -6
- package/dist/esm/components/canvas/node.js +3 -2
- package/dist/esm/components/canvas/system-canvas.js +27 -3
- package/dist/esm/components/carousel.js +24 -5
- package/dist/esm/components/charts.js +29 -20
- package/dist/esm/components/combobox.js +4 -3
- package/dist/esm/components/command.js +4 -3
- package/dist/esm/components/context-menu.js +3 -2
- package/dist/esm/components/data-classes.js +5 -4
- package/dist/esm/components/data.js +5 -8
- package/dist/esm/components/date-picker.js +5 -3
- package/dist/esm/components/date-range-picker.js +5 -3
- package/dist/esm/components/display.js +10 -9
- package/dist/esm/components/drawer.js +3 -2
- package/dist/esm/components/error-boundary.js +4 -2
- package/dist/esm/components/feedback.js +7 -6
- package/dist/esm/components/file-dropzone.js +24 -3
- package/dist/esm/components/filters.js +7 -4
- package/dist/esm/components/flow.js +17 -15
- package/dist/esm/components/forms.js +37 -10
- package/dist/esm/components/hooks.js +22 -19
- package/dist/esm/components/hover-card.js +2 -2
- package/dist/esm/components/inbox.js +12 -8
- package/dist/esm/components/layout-vars.js +10 -7
- package/dist/esm/components/layout.js +5 -4
- package/dist/esm/components/media.js +3 -2
- package/dist/esm/components/menu.js +12 -8
- package/dist/esm/components/modal.js +4 -3
- package/dist/esm/components/more-sheet.js +3 -2
- package/dist/esm/components/multi-select.js +10 -6
- package/dist/esm/components/nav-items.js +4 -3
- package/dist/esm/components/nav.js +5 -4
- package/dist/esm/components/overlay-core.js +31 -10
- package/dist/esm/components/overlay-dialog.js +20 -4
- package/dist/esm/components/pagination.js +7 -3
- package/dist/esm/components/popover.js +17 -11
- package/dist/esm/components/portal.js +2 -2
- package/dist/esm/components/primitives.js +1 -1
- package/dist/esm/components/progress.js +5 -2
- package/dist/esm/components/provider.js +34 -5
- package/dist/esm/components/range-calendar.js +4 -3
- package/dist/esm/components/resource-classes.js +34 -16
- package/dist/esm/components/resource.js +5 -4
- package/dist/esm/components/service-tokens.js +4 -3
- package/dist/esm/components/settings.js +8 -5
- package/dist/esm/components/slider.js +4 -2
- package/dist/esm/components/split.js +4 -3
- package/dist/esm/components/strings.js +182 -65
- package/dist/esm/components/tag-input.js +18 -9
- package/dist/esm/components/theme-toggle.js +3 -2
- package/dist/esm/components/time-field-classes.js +5 -2
- package/dist/esm/components/time-field.js +19 -10
- package/dist/esm/components/toast-card.js +155 -0
- package/dist/esm/components/toast-store.js +136 -0
- package/dist/esm/components/toast.js +38 -241
- package/dist/esm/components/tooltip.js +3 -3
- package/dist/esm/components/url-state.js +1 -0
- package/dist/esm/components/virtual-table.js +11 -4
- package/dist/esm/components/virtual.js +16 -2
- package/dist/esm/format.js +17 -14
- package/dist/esm/index.js +0 -20
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/server/inbox/client.js +1 -1
- package/dist/esm/system-canvas.js +4 -0
- package/dist/esm/theme.js +73 -13
- package/dist/format.js +18 -15
- package/dist/inbox-client.js +1 -1
- package/dist/index.d.ts +43 -21
- 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 +179 -2
- package/dist/theme.d.ts +23 -5
- package/dist/theme.global.js +87 -151
- package/dist/theme.js +87 -151
- package/package.json +1 -1
- package/dist/system-canvas-BLuWd69H.d.ts +0 -183
|
@@ -1,11 +1,12 @@
|
|
|
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";
|
|
8
|
-
import {
|
|
8
|
+
import { useStrings } from "./provider.js";
|
|
9
|
+
import { FILE_STRINGS } from "./strings.js";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
function matchesAccept(file, accept) {
|
|
11
12
|
const tokens = (accept ?? "").split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
|
|
@@ -53,12 +54,32 @@ function FileDropzone({
|
|
|
53
54
|
"aria-invalid": ariaInvalid,
|
|
54
55
|
...rest
|
|
55
56
|
}) {
|
|
56
|
-
const strings =
|
|
57
|
+
const strings = useStrings(FILE_STRINGS);
|
|
57
58
|
const input = useRef(null);
|
|
58
59
|
const depth = useRef(0);
|
|
59
60
|
const [files, setFiles] = useState([]);
|
|
60
61
|
const [dragging, setDragging] = useState(false);
|
|
61
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
|
+
}, []);
|
|
62
83
|
const take = (incoming) => {
|
|
63
84
|
const rejected = [];
|
|
64
85
|
const list = multiple ? [...files] : [];
|
|
@@ -7,7 +7,8 @@ import { SearchInput } from "./forms.js";
|
|
|
7
7
|
import { NARROW_QUERY, useMediaQuery } from "./hooks.js";
|
|
8
8
|
import { Drawer } from "./drawer.js";
|
|
9
9
|
import { Badge, Button } from "./primitives.js";
|
|
10
|
-
import {
|
|
10
|
+
import { useStrings } from "./provider.js";
|
|
11
|
+
import { FILTER_STRINGS, FIELD_STRINGS } from "./strings.js";
|
|
11
12
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
13
|
var LG_QUERY = "(max-width: 1023.98px)";
|
|
13
14
|
function FunnelIcon({ size = 16, ...rest }) {
|
|
@@ -30,7 +31,7 @@ function FunnelIcon({ size = 16, ...rest }) {
|
|
|
30
31
|
);
|
|
31
32
|
}
|
|
32
33
|
function FilterSheet({ open, onClose, title, children, onClear, activeCount, resultLabel }) {
|
|
33
|
-
const strings =
|
|
34
|
+
const strings = useStrings(FILTER_STRINGS, FIELD_STRINGS);
|
|
34
35
|
if (!open) return null;
|
|
35
36
|
return /* @__PURE__ */ jsx(
|
|
36
37
|
Drawer,
|
|
@@ -61,9 +62,11 @@ function FilterBar({
|
|
|
61
62
|
ref,
|
|
62
63
|
...rest
|
|
63
64
|
}) {
|
|
64
|
-
const strings =
|
|
65
|
+
const strings = useStrings(FILTER_STRINGS, FIELD_STRINGS);
|
|
65
66
|
const compact = useMediaQuery(sheetBelow === "lg" ? LG_QUERY : NARROW_QUERY);
|
|
66
|
-
const [
|
|
67
|
+
const [openState, setOpen] = useState(false);
|
|
68
|
+
const open = openState && compact;
|
|
69
|
+
if (!compact && openState) setOpen(false);
|
|
67
70
|
const hasChildren = children != null && children !== false;
|
|
68
71
|
const searchBox = search ? /* @__PURE__ */ jsx(
|
|
69
72
|
SearchInput,
|
|
@@ -14,7 +14,8 @@ 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 {
|
|
17
|
+
import { useNishContext, useStrings } from "./provider.js";
|
|
18
|
+
import { PROGRESS_STRINGS, FLOW_STRINGS } from "./strings.js";
|
|
18
19
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
20
|
var EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
20
21
|
function usePrefersReducedMotion() {
|
|
@@ -119,7 +120,6 @@ var NODE_STATUS = {
|
|
|
119
120
|
done: "bg-th-ok-fill text-th-on-ok forced-colors:border-2 forced-colors:border-[color:Highlight]",
|
|
120
121
|
failed: "bg-th-loss-fill text-th-on-loss forced-colors:border-2 forced-colors:border-dashed forced-colors:border-[color:CanvasText]"
|
|
121
122
|
};
|
|
122
|
-
var STEP_SR_DEFAULT = { done: ", done", failed: ", failed" };
|
|
123
123
|
function pickStepFx(from, to) {
|
|
124
124
|
if (to === "done") return "done";
|
|
125
125
|
if (to === "failed") return "failed";
|
|
@@ -203,7 +203,7 @@ function StepRow({
|
|
|
203
203
|
);
|
|
204
204
|
}
|
|
205
205
|
function FlowSteps({ steps, orientation = "auto", label, statusLabels, className, ref, ...rest }) {
|
|
206
|
-
const s =
|
|
206
|
+
const s = useStrings(PROGRESS_STRINGS, FLOW_STRINGS);
|
|
207
207
|
const allDone = steps.length > 0 && steps.every((s2) => s2.status === "done");
|
|
208
208
|
const prevAll = useRef(null);
|
|
209
209
|
const [sweeping, setSweeping] = useState(false);
|
|
@@ -228,13 +228,13 @@ function FlowSteps({ steps, orientation = "auto", label, statusLabels, className
|
|
|
228
228
|
index: i,
|
|
229
229
|
last: i === steps.length - 1,
|
|
230
230
|
sweeping,
|
|
231
|
-
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
|
|
232
232
|
},
|
|
233
233
|
step.id
|
|
234
234
|
)) }) });
|
|
235
235
|
}
|
|
236
236
|
function StepBar({ total, done, active = false, label, className, ref, ...rest }) {
|
|
237
|
-
const s =
|
|
237
|
+
const s = useStrings(PROGRESS_STRINGS, FLOW_STRINGS);
|
|
238
238
|
const t = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0;
|
|
239
239
|
const d = Number.isFinite(done) ? Math.min(t, Math.max(0, Math.floor(done))) : 0;
|
|
240
240
|
const props = {
|
|
@@ -297,12 +297,6 @@ function TickerText({ text, as = "span", className, ref, ...rest }) {
|
|
|
297
297
|
/* @__PURE__ */ jsx("span", { className: animating ? "nish-flow-ticker-in" : void 0, children: cur.text }, cur.text)
|
|
298
298
|
] });
|
|
299
299
|
}
|
|
300
|
-
var STATE_WORD = {
|
|
301
|
-
queued: "Queued",
|
|
302
|
-
running: "Running",
|
|
303
|
-
done: "Done",
|
|
304
|
-
failed: "Failed"
|
|
305
|
-
};
|
|
306
300
|
var AGENT_STATE = {
|
|
307
301
|
queued: "border-dashed border-th-line opacity-70",
|
|
308
302
|
running: "border-th-accent",
|
|
@@ -348,7 +342,14 @@ function AgentNode({ label, state, model, activity, meta, onClick, stateLabels,
|
|
|
348
342
|
const own = useRef(null);
|
|
349
343
|
const ref = useMergedRef(own, refProp);
|
|
350
344
|
useTransitionFx(state, own, pickAgentFx);
|
|
351
|
-
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]}`;
|
|
352
353
|
const classes = cn(
|
|
353
354
|
"nish-flow-agent block min-h-16 w-full min-w-0 rounded-xl border bg-th-surface p-3 text-start",
|
|
354
355
|
AGENT_STATE[state],
|
|
@@ -397,7 +398,7 @@ function PhaseConnector({ flowing }) {
|
|
|
397
398
|
] });
|
|
398
399
|
}
|
|
399
400
|
function WorkflowBoard({ phases, agents, label, otherLabel, waitingLabel, className, ref, ...rest }) {
|
|
400
|
-
const s =
|
|
401
|
+
const s = useStrings(PROGRESS_STRINGS, FLOW_STRINGS);
|
|
401
402
|
const otherTitle = otherLabel ?? s.other;
|
|
402
403
|
const fresh = useFreshIds(
|
|
403
404
|
agents.map((a) => a.id),
|
|
@@ -507,7 +508,8 @@ var FEED_DOT = {
|
|
|
507
508
|
};
|
|
508
509
|
var FEED_DOT_FORCED = "forced-colors:bg-[color:CanvasText]";
|
|
509
510
|
function ActivityFeed({ items, max = 50, now, label, empty, className, ref, ...rest }) {
|
|
510
|
-
const s =
|
|
511
|
+
const s = useStrings(PROGRESS_STRINGS, FLOW_STRINGS);
|
|
512
|
+
const { locale } = useNishContext();
|
|
511
513
|
const internalNow = useNow(15e3);
|
|
512
514
|
const clock = now ?? internalNow;
|
|
513
515
|
const shown = useMemo(() => [...items].sort((a, b) => b.at - a.at).slice(0, Math.max(0, max)), [items, max]);
|
|
@@ -524,7 +526,7 @@ function ActivityFeed({ items, max = 50, now, label, empty, className, ref, ...r
|
|
|
524
526
|
/* @__PURE__ */ jsx("div", { className: "break-words text-sm text-th-hi2", children: item.text }),
|
|
525
527
|
item.source != null ? /* @__PURE__ */ jsx("div", { className: "break-words text-xs text-th-hi3", children: item.source }) : null
|
|
526
528
|
] }),
|
|
527
|
-
/* @__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 }) })
|
|
528
530
|
] }) }) }, item.id)) });
|
|
529
531
|
}
|
|
530
532
|
var ENTER_MS = 400;
|
|
@@ -15,7 +15,9 @@ import { cn } from "../cn.js";
|
|
|
15
15
|
import { FIELD, IconButton, Input } from "./primitives.js";
|
|
16
16
|
import { XIcon } from "./icons.js";
|
|
17
17
|
import { isRtl, useIsoLayoutEffect } from "./client.js";
|
|
18
|
-
import {
|
|
18
|
+
import { useStrings } from "./provider.js";
|
|
19
|
+
import { FIELD_STRINGS } from "./strings.js";
|
|
20
|
+
import { warnDev } from "./display-classes.js";
|
|
19
21
|
import { chipClass, setRef } from "./forms-classes.js";
|
|
20
22
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
23
|
function Svg({ size = 16, children, ...rest }) {
|
|
@@ -67,6 +69,28 @@ function Textarea({ ref, invalid, size = "md", autoGrow = false, className, rows
|
|
|
67
69
|
useIsoLayoutEffect(() => {
|
|
68
70
|
resize();
|
|
69
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]);
|
|
70
94
|
return /* @__PURE__ */ jsx(
|
|
71
95
|
"textarea",
|
|
72
96
|
{
|
|
@@ -180,7 +204,6 @@ function Switch({
|
|
|
180
204
|
ref,
|
|
181
205
|
checked: checkedProp,
|
|
182
206
|
defaultChecked = false,
|
|
183
|
-
onChange,
|
|
184
207
|
onCheckedChange,
|
|
185
208
|
name,
|
|
186
209
|
value = "on",
|
|
@@ -194,8 +217,13 @@ function Switch({
|
|
|
194
217
|
className,
|
|
195
218
|
id,
|
|
196
219
|
onClick,
|
|
197
|
-
...
|
|
220
|
+
...allRest
|
|
198
221
|
}) {
|
|
222
|
+
const { onChange: removedOnChange, ...rest } = allRest;
|
|
223
|
+
const removed = removedOnChange !== void 0;
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (removed) warnDev("Switch: onChange was removed in nish-ui 3.0. Use onCheckedChange(checked).");
|
|
226
|
+
}, [removed]);
|
|
199
227
|
const auto = useId();
|
|
200
228
|
const btnId = id ?? `${auto}-switch`;
|
|
201
229
|
const labelId = `${auto}-label`;
|
|
@@ -219,8 +247,8 @@ function Switch({
|
|
|
219
247
|
role: "switch",
|
|
220
248
|
"aria-checked": checked,
|
|
221
249
|
"aria-required": required || void 0,
|
|
222
|
-
"aria-labelledby": label != null ? labelId : rest["aria-labelledby"],
|
|
223
|
-
"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,
|
|
224
252
|
"data-state": state,
|
|
225
253
|
"data-disabled": disabled ? "" : void 0,
|
|
226
254
|
disabled,
|
|
@@ -229,7 +257,6 @@ function Switch({
|
|
|
229
257
|
if (e.defaultPrevented) return;
|
|
230
258
|
const next = !checked;
|
|
231
259
|
if (!controlled) setInner(next);
|
|
232
|
-
onChange?.(next, e);
|
|
233
260
|
onCheckedChange?.(next);
|
|
234
261
|
},
|
|
235
262
|
className: cn(
|
|
@@ -327,7 +354,7 @@ function Field({
|
|
|
327
354
|
...rest
|
|
328
355
|
}) {
|
|
329
356
|
const auto = useId();
|
|
330
|
-
const strings =
|
|
357
|
+
const strings = useStrings(FIELD_STRINGS);
|
|
331
358
|
const only = Children.count(children) === 1 && isValidElement(children) ? children : null;
|
|
332
359
|
const childId = only && typeof only.props.id === "string" ? only.props.id : void 0;
|
|
333
360
|
const controlId = htmlFor ?? childId ?? `${auto}-control`;
|
|
@@ -385,7 +412,7 @@ function Field({
|
|
|
385
412
|
}
|
|
386
413
|
function FieldGroup({ ref, label, hint, error, optional = false, className, children, ...rest }) {
|
|
387
414
|
const auto = useId();
|
|
388
|
-
const strings =
|
|
415
|
+
const strings = useStrings(FIELD_STRINGS);
|
|
389
416
|
const hasError = error != null && error !== false && error !== "";
|
|
390
417
|
const hintId = `${auto}-hint`;
|
|
391
418
|
const errorId = `${auto}-error`;
|
|
@@ -420,7 +447,7 @@ function SearchInput({
|
|
|
420
447
|
disabled,
|
|
421
448
|
...rest
|
|
422
449
|
}) {
|
|
423
|
-
const strings =
|
|
450
|
+
const strings = useStrings(FIELD_STRINGS);
|
|
424
451
|
const inner = useRef(null);
|
|
425
452
|
const [own, setOwn] = useState(defaultValue);
|
|
426
453
|
const controlled = valueProp !== void 0;
|
|
@@ -494,7 +521,7 @@ function SearchInput({
|
|
|
494
521
|
] });
|
|
495
522
|
}
|
|
496
523
|
function Chip({ ref, variant = "toggle", pressed, onRemove, removeLabel, icon, trailing, size = "md", className, children, type = "button", ...rest }) {
|
|
497
|
-
const strings =
|
|
524
|
+
const strings = useStrings(FIELD_STRINGS);
|
|
498
525
|
if (variant === "tag") {
|
|
499
526
|
const name = removeLabel ?? (typeof children === "string" ? strings.removeNamed(children) : strings.remove);
|
|
500
527
|
const spanProps = rest;
|
|
@@ -11,7 +11,8 @@ 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 {
|
|
14
|
+
import { shared } from "../runtime.js";
|
|
15
|
+
import { useNishContext } from "./provider.js";
|
|
15
16
|
import { jsx } from "react/jsx-runtime";
|
|
16
17
|
var queries = /* @__PURE__ */ new Map();
|
|
17
18
|
function hasMatchMedia() {
|
|
@@ -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
|
},
|
|
@@ -215,7 +218,7 @@ function RelativeTime({
|
|
|
215
218
|
...rest
|
|
216
219
|
}) {
|
|
217
220
|
const now = useNow(refreshMs);
|
|
218
|
-
const config =
|
|
221
|
+
const config = useNishContext();
|
|
219
222
|
const loc = locale ?? config.locale;
|
|
220
223
|
const d = new Date(value);
|
|
221
224
|
const iso = Number.isNaN(d.getTime()) ? void 0 : d.toISOString();
|
|
@@ -20,7 +20,7 @@ import { mergeRefs, warnOnce } from "./data-classes.js";
|
|
|
20
20
|
import { useLatest } from "./latest.js";
|
|
21
21
|
import { place } from "./overlay-position.js";
|
|
22
22
|
import { keyboardFocused, touchTracker } from "./overlay-classes.js";
|
|
23
|
-
import {
|
|
23
|
+
import { useNishContext } from "./provider.js";
|
|
24
24
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
25
25
|
var openCard = () => shared("hoverCard", () => ({ close: null }));
|
|
26
26
|
function useCardPosition(anchor, card, open, side, align) {
|
|
@@ -74,7 +74,7 @@ function HoverCard({
|
|
|
74
74
|
}) {
|
|
75
75
|
const [openState, setOpenState] = useState(defaultOpen ?? false);
|
|
76
76
|
const open = openProp ?? openState;
|
|
77
|
-
const config =
|
|
77
|
+
const config = useNishContext();
|
|
78
78
|
const isClient = useIsClient();
|
|
79
79
|
const autoId = useId();
|
|
80
80
|
const id = rest.id ?? autoId;
|
|
@@ -9,16 +9,18 @@ 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 {
|
|
17
|
+
import { useNishContext, useStrings } from "./provider.js";
|
|
18
|
+
import { INBOX_STRINGS, SHELL_STRINGS, STATUS_STRINGS, OVERLAY_STRINGS } from "./strings.js";
|
|
18
19
|
import { Tabs } from "./tabs.js";
|
|
19
20
|
import { DEFAULT_INBOX_LABELS } from "./inbox-classes.js";
|
|
20
21
|
import { DEFAULT_INBOX_LABELS as DEFAULT_INBOX_LABELS2 } from "./inbox-classes.js";
|
|
21
22
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
var useInboxStrings = () => useStrings(INBOX_STRINGS, SHELL_STRINGS, STATUS_STRINGS, OVERLAY_STRINGS);
|
|
22
24
|
var DOT_TONE = {
|
|
23
25
|
urgent: "loss",
|
|
24
26
|
normal: "accent",
|
|
@@ -40,15 +42,17 @@ var SNOOZE_OPTIONS = [
|
|
|
40
42
|
function looksClamped(body) {
|
|
41
43
|
return body.length > 100 || body.split("\n").length > 3;
|
|
42
44
|
}
|
|
43
|
-
function lastActionText(result, item, labels) {
|
|
45
|
+
function lastActionText(result, item, labels, now, locale) {
|
|
44
46
|
const label = item.actions?.find((a) => a.id === result.actionId)?.label ?? result.actionId;
|
|
45
47
|
const ms = Date.parse(result.at);
|
|
46
|
-
const at = new Date(ms).toDateString() ===
|
|
48
|
+
const at = new Date(ms).toDateString() === new Date(now).toDateString() ? time(ms, { locale }) : dateTime(ms, { locale });
|
|
47
49
|
if (result.ok) return labels.actionRan(label, at);
|
|
48
50
|
const why = result.error ?? (result.status != null ? `HTTP ${result.status}` : null);
|
|
49
51
|
return labels.actionFailed(label, at, why);
|
|
50
52
|
}
|
|
51
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();
|
|
52
56
|
const severity = item.severity in DOT_TONE ? item.severity : "normal";
|
|
53
57
|
const dot = { tone: DOT_TONE[severity], label: labels[severity] };
|
|
54
58
|
const long = item.body != null && looksClamped(item.body);
|
|
@@ -90,10 +94,10 @@ function Row({ item, view, label, wide, selected, expanded, domId, onToggle, onH
|
|
|
90
94
|
},
|
|
91
95
|
a.id
|
|
92
96
|
)) }) : null,
|
|
93
|
-
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,
|
|
94
|
-
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,
|
|
95
99
|
view === "handled" && item.handledAt ? /* @__PURE__ */ jsxs("p", { className: "m-0 mt-0.5 text-xs text-th-hi3", children: [
|
|
96
|
-
labels.handledAgo(ago(item.handledAt)),
|
|
100
|
+
labels.handledAgo(ago(item.handledAt, { now: clock, locale })),
|
|
97
101
|
item.handledBy === "source" ? labels.handledByApp : item.handledBy === "expired" ? labels.handledAutomatically : ""
|
|
98
102
|
] }) : null
|
|
99
103
|
] }),
|
|
@@ -142,7 +146,7 @@ function Inbox({
|
|
|
142
146
|
ref,
|
|
143
147
|
...rest
|
|
144
148
|
}) {
|
|
145
|
-
const strings =
|
|
149
|
+
const strings = useInboxStrings();
|
|
146
150
|
const labels = { ...DEFAULT_INBOX_LABELS, ...labelOverrides };
|
|
147
151
|
const idBase = useId().replace(/:/g, "");
|
|
148
152
|
const wide = useMediaQuery("(min-width: 480px)");
|
|
@@ -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 });
|
|
@@ -13,7 +13,8 @@ import { mergeRefs } from "./data-classes.js";
|
|
|
13
13
|
import { Callout } from "./display.js";
|
|
14
14
|
import { useHeightVar, useStuck } from "./layout-vars.js";
|
|
15
15
|
import { Button } from "./primitives.js";
|
|
16
|
-
import {
|
|
16
|
+
import { useStrings } from "./provider.js";
|
|
17
|
+
import { STATUS_STRINGS } from "./strings.js";
|
|
17
18
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
18
19
|
function StickyBar({
|
|
19
20
|
children,
|
|
@@ -55,7 +56,7 @@ function StickyActionBar({
|
|
|
55
56
|
ref: refProp,
|
|
56
57
|
...rest
|
|
57
58
|
}) {
|
|
58
|
-
const strings =
|
|
59
|
+
const strings = useStrings(STATUS_STRINGS);
|
|
59
60
|
const ref = useRef(null);
|
|
60
61
|
useHeightVar(ref, "--nish-bottom-bar-h", open);
|
|
61
62
|
if (!open) return null;
|
|
@@ -97,7 +98,7 @@ function LoadingBar({
|
|
|
97
98
|
ref,
|
|
98
99
|
...rest
|
|
99
100
|
}) {
|
|
100
|
-
const strings =
|
|
101
|
+
const strings = useStrings(STATUS_STRINGS);
|
|
101
102
|
const [shown, setShown] = useState(false);
|
|
102
103
|
useEffect(() => {
|
|
103
104
|
if (!active) {
|
|
@@ -185,7 +186,7 @@ function ConnectionBanner({
|
|
|
185
186
|
onRetry,
|
|
186
187
|
...rest
|
|
187
188
|
}) {
|
|
188
|
-
const strings =
|
|
189
|
+
const strings = useStrings(STATUS_STRINGS);
|
|
189
190
|
const online = useOnline();
|
|
190
191
|
const [reachable, setReachable] = useState(true);
|
|
191
192
|
const [retrying, setRetrying] = useState(false);
|
|
@@ -6,7 +6,8 @@ import { cn } from "../cn.js";
|
|
|
6
6
|
import { safeUrl } from "../url.js";
|
|
7
7
|
import { ListRow } from "./data.js";
|
|
8
8
|
import { Badge } from "./primitives.js";
|
|
9
|
-
import {
|
|
9
|
+
import { useStrings } from "./provider.js";
|
|
10
|
+
import { MEDIA_STRINGS } from "./strings.js";
|
|
10
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
var THUMB_BOX = {
|
|
12
13
|
wide: {
|
|
@@ -61,7 +62,7 @@ function MediaRow({
|
|
|
61
62
|
ref,
|
|
62
63
|
...rest
|
|
63
64
|
}) {
|
|
64
|
-
const t =
|
|
65
|
+
const t = useStrings(MEDIA_STRINGS);
|
|
65
66
|
const small = dense || compact;
|
|
66
67
|
const size = thumbSize ?? (small ? "sm" : "md");
|
|
67
68
|
const badgeSize = small ? "xs" : "sm";
|
|
@@ -8,11 +8,13 @@ import { isRtl } from "./client.js";
|
|
|
8
8
|
import { useMediaQuery } from "./hooks.js";
|
|
9
9
|
import { useLatest } from "./latest.js";
|
|
10
10
|
import { lazyModule, useLazyModule } from "./lazy-module.js";
|
|
11
|
-
import {
|
|
11
|
+
import { useStrings, useNishContext } from "./provider.js";
|
|
12
|
+
import { OVERLAY_STRINGS } from "./strings.js";
|
|
12
13
|
import { MENU_ROW, PHONE_QUERY, menuItemClass } from "./overlay-classes.js";
|
|
13
14
|
import { layerHost, setRef, useMergedRef } from "./overlay-core.js";
|
|
14
15
|
import { useAnchoredPosition, floatingStyle, useDismiss, useReturnFocus } from "./overlay-position.js";
|
|
15
16
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var InlineMenuItemContext = /* @__PURE__ */ createContext(false);
|
|
16
18
|
var MenuContext = /* @__PURE__ */ createContext(null);
|
|
17
19
|
var drawerModule = /* @__PURE__ */ lazyModule(() => import("./drawer.js"));
|
|
18
20
|
var ITEM_SELECTOR = '[role="menuitem"]:not([aria-disabled="true"])';
|
|
@@ -43,8 +45,8 @@ function DropdownMenu({
|
|
|
43
45
|
onKeyDown: userKeyDown,
|
|
44
46
|
...rest
|
|
45
47
|
}) {
|
|
46
|
-
const strings =
|
|
47
|
-
const config =
|
|
48
|
+
const strings = useStrings(OVERLAY_STRINGS);
|
|
49
|
+
const config = useNishContext();
|
|
48
50
|
const [openState, setOpenState] = useState(defaultOpen);
|
|
49
51
|
const open = openProp ?? openState;
|
|
50
52
|
const triggerRef = useRef(null);
|
|
@@ -227,6 +229,7 @@ function MenuItem({
|
|
|
227
229
|
...rest
|
|
228
230
|
}) {
|
|
229
231
|
const ctx = useContext(MenuContext);
|
|
232
|
+
const inline = useContext(InlineMenuItemContext);
|
|
230
233
|
function select() {
|
|
231
234
|
if (disabled) return;
|
|
232
235
|
const ev = new Event("nish-menu-select", { cancelable: true });
|
|
@@ -239,8 +242,8 @@ function MenuItem({
|
|
|
239
242
|
...rest,
|
|
240
243
|
ref,
|
|
241
244
|
type: "button",
|
|
242
|
-
role: "menuitem",
|
|
243
|
-
tabIndex: -1,
|
|
245
|
+
role: inline ? void 0 : "menuitem",
|
|
246
|
+
tabIndex: inline ? void 0 : -1,
|
|
244
247
|
"aria-disabled": disabled || void 0,
|
|
245
248
|
"aria-current": active || void 0,
|
|
246
249
|
"data-disabled": disabled ? "" : void 0,
|
|
@@ -250,13 +253,13 @@ function MenuItem({
|
|
|
250
253
|
},
|
|
251
254
|
onMouseMove: (e) => {
|
|
252
255
|
onMouseMove?.(e);
|
|
253
|
-
if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
|
|
256
|
+
if (!inline && !disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
|
|
254
257
|
},
|
|
255
258
|
className: menuItemClass({
|
|
256
259
|
active,
|
|
257
260
|
danger,
|
|
258
261
|
disabled,
|
|
259
|
-
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)
|
|
260
263
|
}),
|
|
261
264
|
children: [
|
|
262
265
|
icon ? /* @__PURE__ */ jsx("span", { className: cn("inline-flex shrink-0", danger || disabled ? "" : "text-th-hi3"), children: icon }) : null,
|
|
@@ -291,7 +294,7 @@ function MenuSeparator({
|
|
|
291
294
|
return /* @__PURE__ */ jsx("div", { ...rest, ref, role: "separator", className: cn("my-1 h-px bg-th-line forced-colors:bg-[CanvasText]", className) });
|
|
292
295
|
}
|
|
293
296
|
function MenuSubHeader({ onBack, children, className, ref, onKeyDown, ...rest }) {
|
|
294
|
-
const strings =
|
|
297
|
+
const strings = useStrings(OVERLAY_STRINGS);
|
|
295
298
|
return /* @__PURE__ */ jsxs(
|
|
296
299
|
"button",
|
|
297
300
|
{
|
|
@@ -335,6 +338,7 @@ function MenuSubHeader({ onBack, children, className, ref, onKeyDown, ...rest })
|
|
|
335
338
|
export {
|
|
336
339
|
DropdownMenu,
|
|
337
340
|
ITEM_SELECTOR,
|
|
341
|
+
InlineMenuItemContext,
|
|
338
342
|
MenuContext,
|
|
339
343
|
MenuItem,
|
|
340
344
|
MenuLabel,
|