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
|
@@ -7,7 +7,8 @@ import { XIcon } from "./icons.js";
|
|
|
7
7
|
import { Button } from "./primitives.js";
|
|
8
8
|
import { useLatest } from "./latest.js";
|
|
9
9
|
import { Portal } from "./portal.js";
|
|
10
|
-
import {
|
|
10
|
+
import { useStrings } from "./provider.js";
|
|
11
|
+
import { OVERLAY_STRINGS } from "./strings.js";
|
|
11
12
|
import { CLOSE_BUTTON, MODAL_SIZE, SHEET_HEIGHT_CLASS } from "./overlay-classes.js";
|
|
12
13
|
import { isPhoneViewport, closeVetoes, warnDev, useMergedRef, useScrollable } from "./overlay-core.js";
|
|
13
14
|
import { useDialog, useSheetExit, useSheetSwipe, SheetHandle } from "./overlay-dialog.js";
|
|
@@ -38,7 +39,7 @@ function ModalPanel({
|
|
|
38
39
|
ref,
|
|
39
40
|
...rest
|
|
40
41
|
}) {
|
|
41
|
-
const strings =
|
|
42
|
+
const strings = useStrings(OVERLAY_STRINGS);
|
|
42
43
|
const titleId = useId();
|
|
43
44
|
const [panelRef, setPanelRef] = useMergedRef(ref);
|
|
44
45
|
const scrimRef = useRef(null);
|
|
@@ -132,7 +133,7 @@ function ConfirmDialog({
|
|
|
132
133
|
open,
|
|
133
134
|
onOpenChange
|
|
134
135
|
}) {
|
|
135
|
-
const strings =
|
|
136
|
+
const strings = useStrings(OVERLAY_STRINGS);
|
|
136
137
|
const bodyId = useId();
|
|
137
138
|
const pendingRef = useLatest(pending);
|
|
138
139
|
const onOpenChangeRef = useLatest(onOpenChange);
|
|
@@ -5,11 +5,12 @@ import { cn } from "../cn.js";
|
|
|
5
5
|
import { FORCED_MARK } from "./display-classes.js";
|
|
6
6
|
import { Drawer } from "./drawer.js";
|
|
7
7
|
import { FOCUS, NavBadge, renderItem, visibleNavItems } from "./nav-items.js";
|
|
8
|
-
import {
|
|
8
|
+
import { useStrings } from "./provider.js";
|
|
9
|
+
import { SHELL_STRINGS, THEME_STRINGS } from "./strings.js";
|
|
9
10
|
import { ThemeToggle } from "./theme-toggle.js";
|
|
10
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
function MoreSheet({ open, onClose, items, title, footer, renderLink }) {
|
|
12
|
-
const strings =
|
|
13
|
+
const strings = useStrings(SHELL_STRINGS, THEME_STRINGS);
|
|
13
14
|
if (!open) return null;
|
|
14
15
|
const shown = visibleNavItems(items);
|
|
15
16
|
const row = (active) => cn(
|
|
@@ -1,13 +1,14 @@
|
|
|
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";
|
|
8
8
|
import { Chip } from "./forms.js";
|
|
9
9
|
import { fieldClass } from "./primitives.js";
|
|
10
|
-
import {
|
|
10
|
+
import { useStrings } from "./provider.js";
|
|
11
|
+
import { FIELD_STRINGS, MULTI_SELECT_STRINGS } from "./strings.js";
|
|
11
12
|
import { indexComboboxOptions, setRef } from "./forms-classes.js";
|
|
12
13
|
import { COMBOBOX_DEBOUNCE_MS, COMBOBOX_MAX_SHOWN } from "../combobox-filter.js";
|
|
13
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -42,7 +43,7 @@ function MultiSelect({
|
|
|
42
43
|
className,
|
|
43
44
|
...rest
|
|
44
45
|
}) {
|
|
45
|
-
const strings =
|
|
46
|
+
const strings = useStrings(FIELD_STRINGS, MULTI_SELECT_STRINGS);
|
|
46
47
|
const autoId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
47
48
|
const inputId = id ?? `nish-ms-${autoId}`;
|
|
48
49
|
const listId = `nish-ms-list-${autoId}`;
|
|
@@ -113,11 +114,11 @@ function MultiSelect({
|
|
|
113
114
|
}, [open, current]);
|
|
114
115
|
const toOption = (v) => options.find((o) => o.value === v) ?? seen[v] ?? { value: v, label: v };
|
|
115
116
|
const labelOf = (v) => toOption(v).label;
|
|
116
|
-
const close =
|
|
117
|
+
const close = () => {
|
|
117
118
|
setOpen(false);
|
|
118
119
|
setActive(-1);
|
|
119
120
|
setArmed(false);
|
|
120
|
-
}
|
|
121
|
+
};
|
|
121
122
|
const queryChanged = (q) => {
|
|
122
123
|
if (!onQueryChange) return;
|
|
123
124
|
window.clearTimeout(debounceRef.current);
|
|
@@ -267,7 +268,10 @@ function MultiSelect({
|
|
|
267
268
|
rest.onBlur?.(e);
|
|
268
269
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
269
270
|
close();
|
|
270
|
-
|
|
271
|
+
if (text !== "") {
|
|
272
|
+
setText("");
|
|
273
|
+
queryChanged("");
|
|
274
|
+
}
|
|
271
275
|
}
|
|
272
276
|
},
|
|
273
277
|
className: cn("relative w-full min-w-0", className),
|
|
@@ -6,10 +6,11 @@ import { safeUrl } from "../url.js";
|
|
|
6
6
|
import { isRtl, useIsoLayoutEffect } from "./client.js";
|
|
7
7
|
import { navigateFromLayer } from "./navigate.js";
|
|
8
8
|
import { warnDev } from "./display-classes.js";
|
|
9
|
-
import {
|
|
9
|
+
import { useStrings, useNishContext } from "./provider.js";
|
|
10
|
+
import { SHELL_STRINGS } from "./strings.js";
|
|
10
11
|
import { jsx } from "react/jsx-runtime";
|
|
11
12
|
function useEndSide(ref) {
|
|
12
|
-
const dir =
|
|
13
|
+
const dir = useNishContext().dir;
|
|
13
14
|
const [rtl, setRtl] = useState(dir === "rtl");
|
|
14
15
|
useIsoLayoutEffect(() => {
|
|
15
16
|
setRtl(dir ? dir === "rtl" : isRtl(ref.current));
|
|
@@ -17,7 +18,7 @@ function useEndSide(ref) {
|
|
|
17
18
|
return rtl ? "left" : "right";
|
|
18
19
|
}
|
|
19
20
|
function NavBadge({ value }) {
|
|
20
|
-
const strings =
|
|
21
|
+
const strings = useStrings(SHELL_STRINGS);
|
|
21
22
|
if (value === void 0 || value === false || value === 0) return null;
|
|
22
23
|
if (value === true) {
|
|
23
24
|
return /* @__PURE__ */ jsx(
|
|
@@ -16,7 +16,8 @@ import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "./icons.js";
|
|
|
16
16
|
import { useHeightVar, useScrollEdges } from "./layout-vars.js";
|
|
17
17
|
import { NavBadge, FOCUS, renderItem, useEndSide, visibleNavItems } from "./nav-items.js";
|
|
18
18
|
import { IconButton } from "./primitives.js";
|
|
19
|
-
import {
|
|
19
|
+
import { useStrings } from "./provider.js";
|
|
20
|
+
import { SHELL_STRINGS } from "./strings.js";
|
|
20
21
|
import { Tooltip } from "./tooltip.js";
|
|
21
22
|
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
22
23
|
var MAX_QUERY = {
|
|
@@ -44,7 +45,7 @@ function BottomNav({
|
|
|
44
45
|
ref: refProp,
|
|
45
46
|
...rest
|
|
46
47
|
}) {
|
|
47
|
-
const strings =
|
|
48
|
+
const strings = useStrings(SHELL_STRINGS);
|
|
48
49
|
const ref = useRef(null);
|
|
49
50
|
const visible = useMediaQuery(MAX_QUERY[hideFrom]);
|
|
50
51
|
useHeightVar(ref, "--nish-bottom-nav-h", visible);
|
|
@@ -115,7 +116,7 @@ function NavRail({
|
|
|
115
116
|
ref: refProp,
|
|
116
117
|
...rest
|
|
117
118
|
}) {
|
|
118
|
-
const strings =
|
|
119
|
+
const strings = useStrings(SHELL_STRINGS);
|
|
119
120
|
const ref = useRef(null);
|
|
120
121
|
const side = useEndSide(ref);
|
|
121
122
|
const shown = visibleNavItems(items);
|
|
@@ -179,7 +180,7 @@ function NavSidebar({
|
|
|
179
180
|
ref: refProp,
|
|
180
181
|
...rest
|
|
181
182
|
}) {
|
|
182
|
-
const strings =
|
|
183
|
+
const strings = useStrings(SHELL_STRINGS);
|
|
183
184
|
const ref = useRef(null);
|
|
184
185
|
const side = useEndSide(ref);
|
|
185
186
|
const shown = visibleNavItems(items);
|
|
@@ -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();
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { useLatest } from "./latest.js";
|
|
7
|
-
import {
|
|
7
|
+
import { useStrings } from "./provider.js";
|
|
8
|
+
import { OVERLAY_STRINGS } from "./strings.js";
|
|
8
9
|
import { SHEET_EXIT_MS } from "./overlay-classes.js";
|
|
9
10
|
import { ov, isTop, syncLayerAttr, pushInert, popInert, acquireGuard, releaseGuard, prefersReducedMotion, closeVetoes, focusables, lockScroll, queueHistoryPush, cancelHistoryPush } from "./overlay-core.js";
|
|
10
11
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -136,7 +137,11 @@ function useSheetExit(onClose, canClose, onOpenChange) {
|
|
|
136
137
|
fire();
|
|
137
138
|
}, [fire]);
|
|
138
139
|
const isClosing = useCallback(() => closingRef.current, []);
|
|
139
|
-
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]);
|
|
140
145
|
return { closing, requestClose, closeNow, isClosing, allowClose };
|
|
141
146
|
}
|
|
142
147
|
function useSheetSwipe(panelRef, scrimRef, enabled, onDismiss, allow = () => true) {
|
|
@@ -201,7 +206,18 @@ function useSheetSwipe(panelRef, scrimRef, enabled, onDismiss, allow = () => tru
|
|
|
201
206
|
if (dismiss) {
|
|
202
207
|
panel.style.transform = "translateY(100%)";
|
|
203
208
|
if (scrim) scrim.style.opacity = "0";
|
|
204
|
-
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);
|
|
205
221
|
} else {
|
|
206
222
|
panel.style.transform = "translateY(0)";
|
|
207
223
|
if (scrim) scrim.style.opacity = "1";
|
|
@@ -225,7 +241,7 @@ function useSheetSwipe(panelRef, scrimRef, enabled, onDismiss, allow = () => tru
|
|
|
225
241
|
};
|
|
226
242
|
}
|
|
227
243
|
function SheetHandle({ onClose, swipe, className }) {
|
|
228
|
-
const strings =
|
|
244
|
+
const strings = useStrings(OVERLAY_STRINGS);
|
|
229
245
|
return /* @__PURE__ */ jsx(
|
|
230
246
|
"div",
|
|
231
247
|
{
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { useCallback, useRef, useState } from "react";
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { useIsoLayoutEffect } from "./client.js";
|
|
7
|
-
import {
|
|
7
|
+
import { useStrings } from "./provider.js";
|
|
8
|
+
import { PAGING_STRINGS } from "./strings.js";
|
|
8
9
|
import { paginationRange } from "./pagination-classes.js";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
11
|
var SIZE = { sm: "h-8 min-w-8 text-xs", md: "h-9 min-w-9 text-sm" };
|
|
@@ -60,7 +61,7 @@ function Pagination({
|
|
|
60
61
|
ref,
|
|
61
62
|
...rest
|
|
62
63
|
}) {
|
|
63
|
-
const strings =
|
|
64
|
+
const strings = useStrings(PAGING_STRINGS);
|
|
64
65
|
const [pageState, setPageState] = useState(defaultPage);
|
|
65
66
|
const navRef = useRef(null);
|
|
66
67
|
const [narrow, setNarrow] = useState(false);
|
|
@@ -108,7 +109,10 @@ function Pagination({
|
|
|
108
109
|
"aria-current": current ? "page" : void 0,
|
|
109
110
|
"data-state": state,
|
|
110
111
|
children,
|
|
111
|
-
onClick: () =>
|
|
112
|
+
onClick: (event) => {
|
|
113
|
+
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
114
|
+
go(target);
|
|
115
|
+
}
|
|
112
116
|
};
|
|
113
117
|
return /* @__PURE__ */ jsx("li", { children: renderLink(target, props) }, key);
|
|
114
118
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
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
|
-
import {
|
|
9
|
+
import { useNishContext } from "./provider.js";
|
|
10
10
|
import { focusables, layerHost, useMergedRef } from "./overlay-core.js";
|
|
11
11
|
import { useAnchoredPosition, floatingStyle, useDismiss, useReturnFocus } from "./overlay-position.js";
|
|
12
12
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -26,26 +26,32 @@ function Popover({
|
|
|
26
26
|
onKeyDown: userKeyDown,
|
|
27
27
|
...rest
|
|
28
28
|
}) {
|
|
29
|
-
const config =
|
|
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 {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// src/components/portal.tsx
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { useIsClient } from "./client.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useNishContext } from "./provider.js";
|
|
7
7
|
function Portal({ children, container }) {
|
|
8
8
|
const isClient = useIsClient();
|
|
9
|
-
const config =
|
|
9
|
+
const config = useNishContext();
|
|
10
10
|
if (!isClient) return null;
|
|
11
11
|
const target = container ?? config.portalContainer ?? document.body;
|
|
12
12
|
return createPortal(children, target);
|
|
@@ -212,7 +212,7 @@ function Input({ invalid, size = "md", leading, trailing, wrapperClassName, clas
|
|
|
212
212
|
{
|
|
213
213
|
ref,
|
|
214
214
|
"aria-invalid": invalid || void 0,
|
|
215
|
-
className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8", className) }),
|
|
215
|
+
className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8 pointer-coarse:pe-12", className) }),
|
|
216
216
|
...rest
|
|
217
217
|
}
|
|
218
218
|
);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
// src/components/progress.tsx
|
|
2
4
|
import { useId } from "react";
|
|
3
5
|
import { cn } from "../cn.js";
|
|
4
|
-
import {
|
|
6
|
+
import { useStrings } from "./provider.js";
|
|
7
|
+
import { PROGRESS_STRINGS } from "./strings.js";
|
|
5
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
9
|
var FILL = {
|
|
7
10
|
accent: "bg-th-accent",
|
|
@@ -27,7 +30,7 @@ function Progress({
|
|
|
27
30
|
"aria-labelledby": ariaLabelledBy,
|
|
28
31
|
...rest
|
|
29
32
|
}) {
|
|
30
|
-
const strings =
|
|
33
|
+
const strings = useStrings(PROGRESS_STRINGS);
|
|
31
34
|
const labelId = useId();
|
|
32
35
|
const indeterminate = value == null || Number.isNaN(value);
|
|
33
36
|
const clamped = indeterminate ? 0 : Math.min(Math.max(value, 0), max);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { createContext, useContext, useMemo } from "react";
|
|
5
5
|
import { DEFAULT_STRINGS } from "./strings.js";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
var
|
|
8
|
-
var NishContext = /* @__PURE__ */ createContext(
|
|
7
|
+
var EMPTY = {};
|
|
8
|
+
var NishContext = /* @__PURE__ */ createContext({ strings: EMPTY });
|
|
9
9
|
function NishProvider({ strings, locale, dir, portalContainer, children }) {
|
|
10
10
|
const outer = useContext(NishContext);
|
|
11
11
|
const value = useMemo(
|
|
@@ -19,14 +19,43 @@ function NishProvider({ strings, locale, dir, portalContainer, children }) {
|
|
|
19
19
|
);
|
|
20
20
|
return /* @__PURE__ */ jsx(NishContext.Provider, { value, children });
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function useNishContext() {
|
|
23
23
|
return useContext(NishContext);
|
|
24
24
|
}
|
|
25
|
+
function pick(o, groups) {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const key of Object.keys(o)) {
|
|
28
|
+
for (const g of groups) {
|
|
29
|
+
if (g && Object.hasOwn(g, key)) {
|
|
30
|
+
out[key] = o[key];
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
function useStrings(a, b, c, d) {
|
|
38
|
+
const o = useContext(NishContext).strings;
|
|
39
|
+
return useMemo(
|
|
40
|
+
() => o === EMPTY && !b ? a : Object.assign({}, a, b, c, d, pick(o, [a, b, c, d])),
|
|
41
|
+
[a, b, c, d, o]
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
function useNishConfig() {
|
|
45
|
+
const ctx = useContext(NishContext);
|
|
46
|
+
return useMemo(
|
|
47
|
+
() => ({ ...ctx, strings: ctx.strings === EMPTY ? DEFAULT_STRINGS : { ...DEFAULT_STRINGS, ...ctx.strings } }),
|
|
48
|
+
[ctx]
|
|
49
|
+
);
|
|
50
|
+
}
|
|
25
51
|
function useNishStrings() {
|
|
26
|
-
|
|
52
|
+
const o = useContext(NishContext).strings;
|
|
53
|
+
return useMemo(() => o === EMPTY ? DEFAULT_STRINGS : { ...DEFAULT_STRINGS, ...o }, [o]);
|
|
27
54
|
}
|
|
28
55
|
export {
|
|
29
56
|
NishProvider,
|
|
30
57
|
useNishConfig,
|
|
31
|
-
|
|
58
|
+
useNishContext,
|
|
59
|
+
useNishStrings,
|
|
60
|
+
useStrings
|
|
32
61
|
};
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
toRange
|
|
15
15
|
} from "./calendar-classes.js";
|
|
16
16
|
import { CalendarBase } from "./calendar-base.js";
|
|
17
|
-
import {
|
|
17
|
+
import { useStrings, useNishContext } from "./provider.js";
|
|
18
|
+
import { PICKER_STRINGS } from "./strings.js";
|
|
18
19
|
import { jsx } from "react/jsx-runtime";
|
|
19
20
|
var warned = /* @__PURE__ */ new Set();
|
|
20
21
|
var OUTSIDE = { filled: false, band: null, ariaSelected: false };
|
|
@@ -40,8 +41,8 @@ function RangeCalendar({
|
|
|
40
41
|
allowDisabledInRange = false,
|
|
41
42
|
...shared
|
|
42
43
|
}) {
|
|
43
|
-
const strings =
|
|
44
|
-
const config =
|
|
44
|
+
const strings = useStrings(PICKER_STRINGS);
|
|
45
|
+
const config = useNishContext();
|
|
45
46
|
const loc = resolveLocale(shared.locale ?? config.locale ?? getDefaultLocale());
|
|
46
47
|
const { min: minProp, max: maxProp, isDateDisabled } = shared;
|
|
47
48
|
const min = minProp != null && parseIso(minProp) ? minProp : null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/components/resource-classes.ts
|
|
2
|
+
import { shared } from "../runtime.js";
|
|
2
3
|
var ApiError = class extends Error {
|
|
3
4
|
/** HTTP status; 0 = network failure or abort-by-timeout. */
|
|
4
5
|
status;
|
|
@@ -17,9 +18,9 @@ var ApiError = class extends Error {
|
|
|
17
18
|
return this.status === 0 || this.status >= 500;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
var
|
|
21
|
+
var store = shared("api", () => ({ config: {} }));
|
|
21
22
|
function configureApi(c) {
|
|
22
|
-
config = { ...config, ...c };
|
|
23
|
+
store.config = { ...store.config, ...c };
|
|
23
24
|
}
|
|
24
25
|
function isRawBody(b) {
|
|
25
26
|
return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
|
|
@@ -44,24 +45,41 @@ function excerpt(text, max = 120) {
|
|
|
44
45
|
}
|
|
45
46
|
var SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
46
47
|
function isTrustedOrigin(url) {
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const bases = [];
|
|
49
|
+
if (typeof document !== "undefined" && document.baseURI) bases.push(document.baseURI);
|
|
50
|
+
if (typeof location !== "undefined" && location.href) bases.push(location.href);
|
|
51
|
+
for (const here of bases) {
|
|
52
|
+
try {
|
|
53
|
+
const target = new URL(url, here);
|
|
54
|
+
if (target.origin !== "null" && target.origin === new URL(here).origin) return true;
|
|
55
|
+
if (store.config.baseUrl && SCHEME.test(store.config.baseUrl) && target.origin === new URL(store.config.baseUrl).origin) return true;
|
|
56
|
+
return false;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
|
-
return
|
|
60
|
+
return isRelativePath(url);
|
|
61
|
+
}
|
|
62
|
+
function isRelativePath(url) {
|
|
63
|
+
let i = 0;
|
|
64
|
+
while (i < url.length && (url[i] === " " || url[i] === " ")) i++;
|
|
65
|
+
const rest = url.slice(i);
|
|
66
|
+
if (SCHEME.test(rest)) return false;
|
|
67
|
+
const a = rest[0];
|
|
68
|
+
const b = rest[1];
|
|
69
|
+
const isSlash = (c) => c === "/" || c === "\\";
|
|
70
|
+
if (a === "\\") return false;
|
|
71
|
+
if (a === "/" && isSlash(b)) return false;
|
|
72
|
+
const squeezed = rest.replace(/[\t\n\r]/g, "");
|
|
73
|
+
if (isSlash(squeezed[0]) && isSlash(squeezed[1])) return false;
|
|
74
|
+
if (SCHEME.test(squeezed)) return false;
|
|
75
|
+
return true;
|
|
58
76
|
}
|
|
59
77
|
async function apiFetch(path, o = {}) {
|
|
60
78
|
const { body, timeoutMs = 15e3, nullOn404, signal: callerSignal, headers: extraHeaders, ...init } = o;
|
|
61
|
-
const url = path.startsWith("/") && config.baseUrl ? config.baseUrl + path : path;
|
|
79
|
+
const url = path.startsWith("/") && store.config.baseUrl ? store.config.baseUrl + path : path;
|
|
62
80
|
const headers = new Headers({ accept: "application/json" });
|
|
63
|
-
if (config.headers && (isTrustedOrigin(url) || config.headersFor?.(url) === true)) {
|
|
64
|
-
for (const [k, v] of Object.entries(config.headers())) headers.set(k, v);
|
|
81
|
+
if (store.config.headers && (isTrustedOrigin(url) || store.config.headersFor?.(url) === true)) {
|
|
82
|
+
for (const [k, v] of Object.entries(store.config.headers())) headers.set(k, v);
|
|
65
83
|
}
|
|
66
84
|
if (extraHeaders) new Headers(extraHeaders).forEach((v, k) => headers.set(k, v));
|
|
67
85
|
let payload;
|
|
@@ -108,7 +126,7 @@ async function apiFetch(path, o = {}) {
|
|
|
108
126
|
if (!res.ok) {
|
|
109
127
|
if (res.status === 404 && nullOn404) return null;
|
|
110
128
|
const err = new ApiError(errorMessage(parsed, res.status), { status: res.status, body: parsed, url });
|
|
111
|
-
if (res.status === 401) config.onUnauthorized?.(err);
|
|
129
|
+
if (res.status === 401) store.config.onUnauthorized?.(err);
|
|
112
130
|
throw err;
|
|
113
131
|
}
|
|
114
132
|
if (res.status === 204 || text === "") return void 0;
|
|
@@ -95,7 +95,8 @@ function useResource(key, fetcher, o = {}) {
|
|
|
95
95
|
error: void 0,
|
|
96
96
|
updatedAt: keepPrevRef.current ? s.updatedAt : void 0,
|
|
97
97
|
fetching: true,
|
|
98
|
-
settled: s.settled
|
|
98
|
+
settled: s.settled,
|
|
99
|
+
loaded: false
|
|
99
100
|
}
|
|
100
101
|
);
|
|
101
102
|
try {
|
|
@@ -104,10 +105,10 @@ function useResource(key, fetcher, o = {}) {
|
|
|
104
105
|
if (run !== runRef.current || ctl.signal.aborted) return;
|
|
105
106
|
failuresRef.current = 0;
|
|
106
107
|
if (mutatedRef.current !== mutatedAtStart) {
|
|
107
|
-
setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1 }));
|
|
108
|
+
setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1, loaded: true }));
|
|
108
109
|
return;
|
|
109
110
|
}
|
|
110
|
-
setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1 }));
|
|
111
|
+
setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1, loaded: true }));
|
|
111
112
|
} catch (e) {
|
|
112
113
|
if (run !== runRef.current || ctl.signal.aborted) return;
|
|
113
114
|
failuresRef.current++;
|
|
@@ -193,7 +194,7 @@ function useResource(key, fetcher, o = {}) {
|
|
|
193
194
|
return {
|
|
194
195
|
data,
|
|
195
196
|
error,
|
|
196
|
-
loading: active && data === void 0 && error === void 0,
|
|
197
|
+
loading: active && data === void 0 && error === void 0 && !(sameKey && state.loaded),
|
|
197
198
|
refreshing: state.fetching || active && !sameKey,
|
|
198
199
|
updatedAt,
|
|
199
200
|
stale,
|
|
@@ -14,11 +14,12 @@ import { ErrorState, SkeletonRows } from "./feedback.js";
|
|
|
14
14
|
import { ConfirmDialog } from "./overlay.js";
|
|
15
15
|
import { Badge, Button } from "./primitives.js";
|
|
16
16
|
import { apiFetch } from "./resource.js";
|
|
17
|
-
import {
|
|
17
|
+
import { useStrings } from "./provider.js";
|
|
18
|
+
import { TOKEN_STRINGS, STATUS_STRINGS, ERROR_STRINGS, OVERLAY_STRINGS } from "./strings.js";
|
|
18
19
|
import { SettingRow, SettingsSection } from "./settings.js";
|
|
19
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
20
21
|
function useServiceTokens(url = "/api/service-tokens") {
|
|
21
|
-
const strings =
|
|
22
|
+
const strings = useStrings(TOKEN_STRINGS, STATUS_STRINGS, ERROR_STRINGS, OVERLAY_STRINGS);
|
|
22
23
|
const [tokens, setTokens] = useState(
|
|
23
24
|
void 0
|
|
24
25
|
);
|
|
@@ -88,7 +89,7 @@ function ServiceTokensSection({
|
|
|
88
89
|
envSourceLabel = "from SERVICE_TOKENS",
|
|
89
90
|
...rest
|
|
90
91
|
}) {
|
|
91
|
-
const strings =
|
|
92
|
+
const strings = useStrings(TOKEN_STRINGS, STATUS_STRINGS, ERROR_STRINGS, OVERLAY_STRINGS);
|
|
92
93
|
const title = titleProp ?? strings.serviceTokens;
|
|
93
94
|
const description = descriptionProp ?? strings.serviceTokensIntro;
|
|
94
95
|
const [target, setTarget] = useState(null);
|