nish-ui 2.0.1 → 2.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 +18 -8
- package/dist/chart.js +1 -1
- package/dist/elements-all.js +13 -13
- package/dist/elements-charts.js +1 -1
- package/dist/elements-data.js +1 -1
- package/dist/elements-forms.js +1 -1
- package/dist/elements.js +3 -3
- package/dist/esm/components/app-shell.js +145 -45
- package/dist/esm/components/breadcrumbs.js +1 -1
- package/dist/esm/components/calendar-classes.js +325 -0
- package/dist/esm/components/calendar.js +263 -0
- package/dist/esm/components/canvas/route.js +56 -20
- package/dist/esm/components/carousel-classes.js +27 -0
- package/dist/esm/components/carousel.js +317 -0
- package/dist/esm/components/command.js +2 -27
- package/dist/esm/components/context-menu.js +199 -0
- package/dist/esm/components/date-picker.js +208 -0
- package/dist/esm/components/display-classes.js +10 -13
- package/dist/esm/components/display.js +22 -19
- package/dist/esm/components/drawer.js +139 -0
- package/dist/esm/components/filters.js +1 -1
- package/dist/esm/components/flow.js +1 -1
- package/dist/esm/components/hooks.js +17 -6
- package/dist/esm/components/hover-card.js +221 -0
- package/dist/esm/components/icons.js +17 -0
- package/dist/esm/components/inbox.js +2 -1
- package/dist/esm/components/lazy-module.js +53 -0
- package/dist/esm/components/menu.js +344 -0
- package/dist/esm/components/modal.js +173 -0
- package/dist/esm/components/more-sheet.js +52 -0
- package/dist/esm/components/multi-select.js +420 -0
- package/dist/esm/components/nav-items.js +138 -0
- package/dist/esm/components/nav.js +13 -174
- package/dist/esm/components/navigate.js +33 -0
- package/dist/esm/components/overlay-core.js +221 -0
- package/dist/esm/components/overlay-dialog.js +255 -0
- package/dist/esm/components/overlay-position.js +163 -0
- package/dist/esm/components/overlay.js +7 -1441
- package/dist/esm/components/popover.js +92 -0
- package/dist/esm/components/segmented.js +2 -1
- package/dist/esm/components/split.js +1 -1
- package/dist/esm/components/strings.js +25 -0
- package/dist/esm/components/tooltip.js +177 -0
- package/dist/esm/components/tree-view-classes.js +57 -0
- package/dist/esm/components/tree-view.js +319 -0
- package/dist/esm/components/virtual-table.js +245 -0
- package/dist/esm/components/virtual.js +291 -0
- package/dist/esm/inbox.js +12 -0
- package/dist/esm/index.js +61 -2
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/service-tokens.js +6 -0
- package/dist/esm/theme.js +2 -2
- package/dist/esm/virtual-range.js +73 -0
- package/dist/format.js +1 -1
- package/dist/inbox.d.ts +238 -0
- package/dist/index.d.ts +1032 -778
- package/dist/nish-components.css +2 -0
- package/dist/nish-components.min.css +1 -1
- package/dist/service-tokens.d.ts +60 -0
- package/dist/theme.d.ts +50 -0
- package/dist/theme.global.js +28 -3
- package/dist/theme.js +28 -3
- package/package.json +17 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/nav-items.tsx
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { safeUrl } from "../url.js";
|
|
6
|
+
import { isRtl, useIsoLayoutEffect } from "./client.js";
|
|
7
|
+
import { navigateFromLayer } from "./navigate.js";
|
|
8
|
+
import { warnDev } from "./display-classes.js";
|
|
9
|
+
import { useNishConfig, useNishStrings } from "./provider.js";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
function useEndSide(ref) {
|
|
12
|
+
const dir = useNishConfig().dir;
|
|
13
|
+
const [rtl, setRtl] = useState(dir === "rtl");
|
|
14
|
+
useIsoLayoutEffect(() => {
|
|
15
|
+
setRtl(dir ? dir === "rtl" : isRtl(ref.current));
|
|
16
|
+
}, [dir, ref]);
|
|
17
|
+
return rtl ? "left" : "right";
|
|
18
|
+
}
|
|
19
|
+
function NavBadge({ value }) {
|
|
20
|
+
const strings = useNishStrings();
|
|
21
|
+
if (value === void 0 || value === false || value === 0) return null;
|
|
22
|
+
if (value === true) {
|
|
23
|
+
return /* @__PURE__ */ jsx(
|
|
24
|
+
"span",
|
|
25
|
+
{
|
|
26
|
+
"aria-hidden": "true",
|
|
27
|
+
className: "absolute -end-0.5 -top-0.5 size-2 rounded-full bg-th-loss ring-2 ring-th-surface forced-colors:forced-color-adjust-none forced-colors:bg-[Highlight]"
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
"span",
|
|
33
|
+
{
|
|
34
|
+
"aria-label": strings.newCount(value),
|
|
35
|
+
className: "absolute -end-2.5 -top-1.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-th-loss px-1 text-3xs font-semibold leading-none tabular-nums text-th-on-loss ring-2 ring-th-surface forced-colors:border forced-colors:border-[CanvasText]",
|
|
36
|
+
children: value > 99 ? "99+" : value
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
var layerOf = () => history.state?.nishLayer;
|
|
41
|
+
function closeAfterRouterLink(onAfter) {
|
|
42
|
+
const layer = layerOf();
|
|
43
|
+
if (typeof window === "undefined" || !layer) {
|
|
44
|
+
onAfter();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
let decided = false;
|
|
48
|
+
const decide = (routerTookIt) => {
|
|
49
|
+
if (decided) return;
|
|
50
|
+
decided = true;
|
|
51
|
+
window.removeEventListener("click", onWindowClick);
|
|
52
|
+
if (!routerTookIt) {
|
|
53
|
+
onAfter();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const t0 = Date.now();
|
|
57
|
+
const wait = () => {
|
|
58
|
+
if (layerOf() !== layer || Date.now() - t0 > 3e3) onAfter();
|
|
59
|
+
else window.setTimeout(wait, 16);
|
|
60
|
+
};
|
|
61
|
+
wait();
|
|
62
|
+
};
|
|
63
|
+
const onWindowClick = (e) => decide(e.defaultPrevented);
|
|
64
|
+
window.addEventListener("click", onWindowClick);
|
|
65
|
+
window.setTimeout(() => decide(true), 0);
|
|
66
|
+
}
|
|
67
|
+
function renderItem(item, className, children, renderLink, onAfter) {
|
|
68
|
+
const current = item.active ? "page" : void 0;
|
|
69
|
+
const state = item.active ? "active" : "inactive";
|
|
70
|
+
if (item.href != null) {
|
|
71
|
+
const href = safeUrl(item.href);
|
|
72
|
+
if (href === null) return null;
|
|
73
|
+
if (renderLink) {
|
|
74
|
+
return renderLink(item, {
|
|
75
|
+
className,
|
|
76
|
+
children,
|
|
77
|
+
"aria-current": current,
|
|
78
|
+
"data-state": state,
|
|
79
|
+
...onAfter ? { replace: true } : {},
|
|
80
|
+
onClick: () => {
|
|
81
|
+
item.onSelect?.();
|
|
82
|
+
if (onAfter) closeAfterRouterLink(onAfter);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return /* @__PURE__ */ jsx(
|
|
87
|
+
"a",
|
|
88
|
+
{
|
|
89
|
+
href,
|
|
90
|
+
className,
|
|
91
|
+
"aria-current": current,
|
|
92
|
+
"data-state": state,
|
|
93
|
+
onClick: (e) => {
|
|
94
|
+
item.onSelect?.();
|
|
95
|
+
const inLayer = !!history.state?.nishLayer;
|
|
96
|
+
const plain = e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.defaultPrevented;
|
|
97
|
+
if (onAfter && inLayer && plain) {
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
onAfter();
|
|
100
|
+
navigateFromLayer(href);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
onAfter?.();
|
|
104
|
+
},
|
|
105
|
+
children
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return /* @__PURE__ */ jsx(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
type: "button",
|
|
113
|
+
className,
|
|
114
|
+
"aria-current": current,
|
|
115
|
+
"data-state": state,
|
|
116
|
+
onClick: () => {
|
|
117
|
+
item.onSelect?.();
|
|
118
|
+
onAfter?.();
|
|
119
|
+
},
|
|
120
|
+
children
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
var FOCUS = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent";
|
|
125
|
+
function visibleNavItems(items) {
|
|
126
|
+
return items.filter((item) => {
|
|
127
|
+
if (item.href == null || safeUrl(item.href) !== null) return true;
|
|
128
|
+
warnDev(`nish-ui: nav item "${item.key}" was not rendered because its href is not safe (${item.href.slice(0, 40)}).`);
|
|
129
|
+
return false;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
FOCUS,
|
|
134
|
+
NavBadge,
|
|
135
|
+
renderItem,
|
|
136
|
+
useEndSide,
|
|
137
|
+
visibleNavItems
|
|
138
|
+
};
|
|
@@ -8,19 +8,16 @@ import {
|
|
|
8
8
|
useState
|
|
9
9
|
} from "react";
|
|
10
10
|
import { cn } from "../cn.js";
|
|
11
|
-
import { safeUrl } from "../url.js";
|
|
12
|
-
import { isRtl, useIsoLayoutEffect } from "./client.js";
|
|
13
|
-
import { navigateFromLayer } from "./command.js";
|
|
14
11
|
import { mergeRefs } from "./data-classes.js";
|
|
15
|
-
import { FORCED_MARK
|
|
12
|
+
import { FORCED_MARK } from "./display-classes.js";
|
|
16
13
|
import { chipClass } from "./forms.js";
|
|
17
14
|
import { useMediaQuery } from "./hooks.js";
|
|
18
15
|
import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "./icons.js";
|
|
19
16
|
import { useHeightVar, useScrollEdges } from "./layout-vars.js";
|
|
20
|
-
import {
|
|
17
|
+
import { NavBadge, FOCUS, renderItem, useEndSide, visibleNavItems } from "./nav-items.js";
|
|
21
18
|
import { IconButton } from "./primitives.js";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
19
|
+
import { useNishStrings } from "./provider.js";
|
|
20
|
+
import { Tooltip } from "./tooltip.js";
|
|
24
21
|
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
25
22
|
var MAX_QUERY = {
|
|
26
23
|
md: "(max-width: 767px)",
|
|
@@ -29,127 +26,6 @@ var MAX_QUERY = {
|
|
|
29
26
|
var HIDE_FROM = { md: "md:hidden", lg: "lg:hidden" };
|
|
30
27
|
var RAIL_SHOW = { sm: "sm:flex", md: "md:flex", lg: "lg:flex" };
|
|
31
28
|
var RAIL_HIDE = { md: "md:hidden", lg: "lg:hidden", xl: "xl:hidden" };
|
|
32
|
-
function visibleNavItems(items) {
|
|
33
|
-
return items.filter((item) => {
|
|
34
|
-
if (item.href == null || safeUrl(item.href) !== null) return true;
|
|
35
|
-
warnDev(`nish-ui: nav item "${item.key}" was not rendered because its href is not safe (${item.href.slice(0, 40)}).`);
|
|
36
|
-
return false;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function useEndSide(ref) {
|
|
40
|
-
const dir = useNishConfig().dir;
|
|
41
|
-
const [rtl, setRtl] = useState(dir === "rtl");
|
|
42
|
-
useIsoLayoutEffect(() => {
|
|
43
|
-
setRtl(dir ? dir === "rtl" : isRtl(ref.current));
|
|
44
|
-
}, [dir, ref]);
|
|
45
|
-
return rtl ? "left" : "right";
|
|
46
|
-
}
|
|
47
|
-
function CountBadge({ value }) {
|
|
48
|
-
const strings = useNishStrings();
|
|
49
|
-
if (value === void 0 || value === false || value === 0) return null;
|
|
50
|
-
if (value === true) {
|
|
51
|
-
return /* @__PURE__ */ jsx(
|
|
52
|
-
"span",
|
|
53
|
-
{
|
|
54
|
-
"aria-hidden": "true",
|
|
55
|
-
className: "absolute -end-0.5 -top-0.5 size-2 rounded-full bg-th-loss ring-2 ring-th-surface forced-colors:forced-color-adjust-none forced-colors:bg-[Highlight]"
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
return /* @__PURE__ */ jsx(
|
|
60
|
-
"span",
|
|
61
|
-
{
|
|
62
|
-
"aria-label": strings.newCount(value),
|
|
63
|
-
className: "absolute -end-2.5 -top-1.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-th-loss px-1 text-3xs font-semibold leading-none tabular-nums text-th-on-loss ring-2 ring-th-surface forced-colors:border forced-colors:border-[CanvasText]",
|
|
64
|
-
children: value > 99 ? "99+" : value
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
var layerOf = () => history.state?.nishLayer;
|
|
69
|
-
function closeAfterRouterLink(onAfter) {
|
|
70
|
-
const layer = layerOf();
|
|
71
|
-
if (typeof window === "undefined" || !layer) {
|
|
72
|
-
onAfter();
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
let decided = false;
|
|
76
|
-
const decide = (routerTookIt) => {
|
|
77
|
-
if (decided) return;
|
|
78
|
-
decided = true;
|
|
79
|
-
window.removeEventListener("click", onWindowClick);
|
|
80
|
-
if (!routerTookIt) {
|
|
81
|
-
onAfter();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const t0 = Date.now();
|
|
85
|
-
const wait = () => {
|
|
86
|
-
if (layerOf() !== layer || Date.now() - t0 > 3e3) onAfter();
|
|
87
|
-
else window.setTimeout(wait, 16);
|
|
88
|
-
};
|
|
89
|
-
wait();
|
|
90
|
-
};
|
|
91
|
-
const onWindowClick = (e) => decide(e.defaultPrevented);
|
|
92
|
-
window.addEventListener("click", onWindowClick);
|
|
93
|
-
window.setTimeout(() => decide(true), 0);
|
|
94
|
-
}
|
|
95
|
-
function renderItem(item, className, children, renderLink, onAfter) {
|
|
96
|
-
const current = item.active ? "page" : void 0;
|
|
97
|
-
const state = item.active ? "active" : "inactive";
|
|
98
|
-
if (item.href != null) {
|
|
99
|
-
const href = safeUrl(item.href);
|
|
100
|
-
if (href === null) return null;
|
|
101
|
-
if (renderLink) {
|
|
102
|
-
return renderLink(item, {
|
|
103
|
-
className,
|
|
104
|
-
children,
|
|
105
|
-
"aria-current": current,
|
|
106
|
-
"data-state": state,
|
|
107
|
-
...onAfter ? { replace: true } : {},
|
|
108
|
-
onClick: () => {
|
|
109
|
-
item.onSelect?.();
|
|
110
|
-
if (onAfter) closeAfterRouterLink(onAfter);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return /* @__PURE__ */ jsx(
|
|
115
|
-
"a",
|
|
116
|
-
{
|
|
117
|
-
href,
|
|
118
|
-
className,
|
|
119
|
-
"aria-current": current,
|
|
120
|
-
"data-state": state,
|
|
121
|
-
onClick: (e) => {
|
|
122
|
-
item.onSelect?.();
|
|
123
|
-
const inLayer = !!history.state?.nishLayer;
|
|
124
|
-
const plain = e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.defaultPrevented;
|
|
125
|
-
if (onAfter && inLayer && plain) {
|
|
126
|
-
e.preventDefault();
|
|
127
|
-
onAfter();
|
|
128
|
-
navigateFromLayer(href);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
onAfter?.();
|
|
132
|
-
},
|
|
133
|
-
children
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return /* @__PURE__ */ jsx(
|
|
138
|
-
"button",
|
|
139
|
-
{
|
|
140
|
-
type: "button",
|
|
141
|
-
className,
|
|
142
|
-
"aria-current": current,
|
|
143
|
-
"data-state": state,
|
|
144
|
-
onClick: () => {
|
|
145
|
-
item.onSelect?.();
|
|
146
|
-
onAfter?.();
|
|
147
|
-
},
|
|
148
|
-
children
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
var FOCUS = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent";
|
|
153
29
|
function MoreDots() {
|
|
154
30
|
return /* @__PURE__ */ jsxs("svg", { width: 22, height: 22, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: [
|
|
155
31
|
/* @__PURE__ */ jsx("circle", { cx: "5", cy: "12", r: "1.8" }),
|
|
@@ -198,9 +74,9 @@ function BottomNav({
|
|
|
198
74
|
/* @__PURE__ */ jsxs("span", { className: pill(!!item.active), children: [
|
|
199
75
|
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-6 items-center justify-center", children: [
|
|
200
76
|
item.icon,
|
|
201
|
-
/* @__PURE__ */ jsx(
|
|
77
|
+
/* @__PURE__ */ jsx(NavBadge, { value: item.badge })
|
|
202
78
|
] }),
|
|
203
|
-
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.label })
|
|
79
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.shortLabel ?? item.label })
|
|
204
80
|
] }),
|
|
205
81
|
renderLink
|
|
206
82
|
) }, item.key)),
|
|
@@ -227,45 +103,6 @@ function BottomNav({
|
|
|
227
103
|
}
|
|
228
104
|
);
|
|
229
105
|
}
|
|
230
|
-
function MoreSheet({ open, onClose, items, title, footer, renderLink }) {
|
|
231
|
-
const strings = useNishStrings();
|
|
232
|
-
if (!open) return null;
|
|
233
|
-
const shown = visibleNavItems(items);
|
|
234
|
-
const row = (active) => cn(
|
|
235
|
-
"flex min-h-[52px] w-full items-center gap-3 rounded-lg px-3 text-start transition-colors",
|
|
236
|
-
active ? cn("bg-th-accent-soft text-th-accent", FORCED_MARK) : "text-th-hi hover:bg-th-elevated",
|
|
237
|
-
FOCUS
|
|
238
|
-
);
|
|
239
|
-
return /* @__PURE__ */ jsx(
|
|
240
|
-
Drawer,
|
|
241
|
-
{
|
|
242
|
-
side: "bottom",
|
|
243
|
-
title: title ?? strings.more,
|
|
244
|
-
onClose,
|
|
245
|
-
bottomOffset: "var(--nish-bottom-nav-h, 0px)",
|
|
246
|
-
footer: footer ?? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-5 py-3", children: [
|
|
247
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-th-hi", children: strings.theme }),
|
|
248
|
-
/* @__PURE__ */ jsx(ThemeToggle, { phone: "segmented" })
|
|
249
|
-
] }),
|
|
250
|
-
children: /* @__PURE__ */ jsx("ul", { className: "m-0 list-none p-2", children: shown.map((item) => /* @__PURE__ */ jsx("li", { children: renderItem(
|
|
251
|
-
item,
|
|
252
|
-
row(!!item.active),
|
|
253
|
-
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
254
|
-
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-6 shrink-0 items-center justify-center", children: [
|
|
255
|
-
item.icon,
|
|
256
|
-
/* @__PURE__ */ jsx(CountBadge, { value: item.badge })
|
|
257
|
-
] }),
|
|
258
|
-
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
259
|
-
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: item.label }),
|
|
260
|
-
item.hint ? /* @__PURE__ */ jsx("span", { className: cn("block truncate text-xs", item.active ? "text-th-accent/80" : "text-th-hi3"), children: item.hint }) : null
|
|
261
|
-
] })
|
|
262
|
-
] }),
|
|
263
|
-
renderLink,
|
|
264
|
-
onClose
|
|
265
|
-
) }, item.key)) })
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
106
|
function NavRail({
|
|
270
107
|
items,
|
|
271
108
|
tools,
|
|
@@ -309,15 +146,16 @@ function NavRail({
|
|
|
309
146
|
),
|
|
310
147
|
children: [
|
|
311
148
|
item.icon,
|
|
312
|
-
/* @__PURE__ */ jsx(
|
|
149
|
+
/* @__PURE__ */ jsx(NavBadge, { value: item.badge })
|
|
313
150
|
]
|
|
314
151
|
}
|
|
315
152
|
),
|
|
316
|
-
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.label })
|
|
153
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.shortLabel ?? item.label })
|
|
317
154
|
] }),
|
|
318
155
|
renderLink
|
|
319
156
|
);
|
|
320
|
-
|
|
157
|
+
const tip = item.hint ?? (item.shortLabel != null && item.shortLabel !== item.label ? item.label : void 0);
|
|
158
|
+
return tip ? /* @__PURE__ */ jsx(Tooltip, { tip, side, focusable: false, className: "block w-full", children: node }, item.key) : /* @__PURE__ */ jsx("span", { className: "block w-full", children: node }, item.key);
|
|
321
159
|
}),
|
|
322
160
|
tools ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
323
161
|
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "my-1 h-px w-8 bg-th-line" }),
|
|
@@ -334,6 +172,7 @@ function NavSidebar({
|
|
|
334
172
|
onCollapsedChange,
|
|
335
173
|
tools,
|
|
336
174
|
footer,
|
|
175
|
+
header,
|
|
337
176
|
label,
|
|
338
177
|
renderLink,
|
|
339
178
|
className,
|
|
@@ -357,6 +196,7 @@ function NavSidebar({
|
|
|
357
196
|
className
|
|
358
197
|
),
|
|
359
198
|
children: [
|
|
199
|
+
header != null && !collapsed ? /* @__PURE__ */ jsx("div", { className: "mb-3 flex flex-col items-start gap-2 px-3", children: header }) : null,
|
|
360
200
|
tools ? /* @__PURE__ */ jsx("div", { className: cn("mb-2 flex gap-1 border-b border-th-line pb-2", collapsed ? "flex-col items-center" : "flex-wrap px-3"), children: tools }) : null,
|
|
361
201
|
/* @__PURE__ */ jsx("nav", { "aria-label": label ?? strings.sections, className: cn("flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto", collapsed ? "items-center px-2" : "px-3"), children: shown.map((item) => {
|
|
362
202
|
const node = renderItem(
|
|
@@ -370,7 +210,7 @@ function NavSidebar({
|
|
|
370
210
|
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
371
211
|
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-5 shrink-0 items-center justify-center [&>svg]:size-5", children: [
|
|
372
212
|
item.icon,
|
|
373
|
-
/* @__PURE__ */ jsx(
|
|
213
|
+
/* @__PURE__ */ jsx(NavBadge, { value: item.badge })
|
|
374
214
|
] }),
|
|
375
215
|
/* @__PURE__ */ jsx("span", { className: collapsed ? "sr-only" : "min-w-0 truncate", children: item.label })
|
|
376
216
|
] }),
|
|
@@ -602,7 +442,6 @@ function SectionNav({
|
|
|
602
442
|
}
|
|
603
443
|
export {
|
|
604
444
|
BottomNav,
|
|
605
|
-
MoreSheet,
|
|
606
445
|
NavRail,
|
|
607
446
|
NavSidebar,
|
|
608
447
|
ScrollRow,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/components/navigate.ts
|
|
2
|
+
import { safeUrl } from "../url.js";
|
|
3
|
+
import { whenHistorySettled } from "./overlay-core.js";
|
|
4
|
+
function warnUnsafe(href) {
|
|
5
|
+
try {
|
|
6
|
+
if (process.env.NODE_ENV !== "production") console.warn(`CommandPalette: ignored an unsafe href (${href.slice(0, 40)}).`);
|
|
7
|
+
} catch {
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function navigateFromLayer(rawHref) {
|
|
11
|
+
const href = safeUrl(rawHref);
|
|
12
|
+
if (href === null) {
|
|
13
|
+
warnUnsafe(rawHref);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const inLayer = !!history.state?.nishLayer;
|
|
17
|
+
if (!inLayer) {
|
|
18
|
+
window.location.assign(href);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let done = false;
|
|
22
|
+
const go = () => {
|
|
23
|
+
if (done) return;
|
|
24
|
+
done = true;
|
|
25
|
+
window.location.assign(href);
|
|
26
|
+
};
|
|
27
|
+
window.setTimeout(() => whenHistorySettled(go), 0);
|
|
28
|
+
window.setTimeout(go, 400);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
navigateFromLayer,
|
|
32
|
+
warnUnsafe
|
|
33
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/overlay-core.ts
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { shared } from "../runtime.js";
|
|
6
|
+
import { PHONE_QUERY } from "./overlay-classes.js";
|
|
7
|
+
function createState() {
|
|
8
|
+
const s = {
|
|
9
|
+
layerStack: [],
|
|
10
|
+
dialogCount: 0,
|
|
11
|
+
dialogPortals: [],
|
|
12
|
+
inerted: /* @__PURE__ */ new Set(),
|
|
13
|
+
lockCount: 0,
|
|
14
|
+
savedOverflow: null,
|
|
15
|
+
pendingBacks: 0,
|
|
16
|
+
queuedPushes: [],
|
|
17
|
+
layerSeq: 0,
|
|
18
|
+
backDialogs: 0,
|
|
19
|
+
guardOn: false,
|
|
20
|
+
guard: () => {
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
s.guard = (e) => {
|
|
24
|
+
if (s.pendingBacks <= 0) return;
|
|
25
|
+
s.pendingBacks--;
|
|
26
|
+
e.stopImmediatePropagation();
|
|
27
|
+
if (s.pendingBacks === 0) {
|
|
28
|
+
for (const push of s.queuedPushes.splice(0)) push();
|
|
29
|
+
removeGuardIfIdle(s);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
var cachedState;
|
|
35
|
+
function ov() {
|
|
36
|
+
return cachedState ??= shared("overlay", createState);
|
|
37
|
+
}
|
|
38
|
+
function removeGuardIfIdle(s) {
|
|
39
|
+
if (s.guardOn && s.backDialogs === 0 && s.pendingBacks === 0) {
|
|
40
|
+
window.removeEventListener("popstate", s.guard, true);
|
|
41
|
+
s.guardOn = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function acquireGuard() {
|
|
45
|
+
const s = ov();
|
|
46
|
+
s.backDialogs++;
|
|
47
|
+
if (!s.guardOn) {
|
|
48
|
+
window.addEventListener("popstate", s.guard, true);
|
|
49
|
+
s.guardOn = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function releaseGuard() {
|
|
53
|
+
const s = ov();
|
|
54
|
+
s.backDialogs--;
|
|
55
|
+
removeGuardIfIdle(s);
|
|
56
|
+
}
|
|
57
|
+
var isTop = (self) => {
|
|
58
|
+
const stack = ov().layerStack;
|
|
59
|
+
return stack[stack.length - 1] === self;
|
|
60
|
+
};
|
|
61
|
+
function syncLayerAttr() {
|
|
62
|
+
if (typeof document === "undefined") return;
|
|
63
|
+
const html = document.documentElement;
|
|
64
|
+
if (ov().dialogCount > 0) html.setAttribute("data-nish-layer-open", "");
|
|
65
|
+
else html.removeAttribute("data-nish-layer-open");
|
|
66
|
+
}
|
|
67
|
+
function syncInert() {
|
|
68
|
+
if (typeof document === "undefined") return;
|
|
69
|
+
const { dialogPortals, inerted } = ov();
|
|
70
|
+
for (let i = dialogPortals.length - 1; i >= 0; i--) if (!dialogPortals[i].isConnected) dialogPortals.splice(i, 1);
|
|
71
|
+
const top = dialogPortals[dialogPortals.length - 1];
|
|
72
|
+
if (!top) {
|
|
73
|
+
inerted.forEach((el) => {
|
|
74
|
+
el.inert = false;
|
|
75
|
+
el.removeAttribute("inert");
|
|
76
|
+
});
|
|
77
|
+
inerted.clear();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
for (const el of Array.from(document.body.children)) {
|
|
81
|
+
const skip = el === top || el.contains(top) || el.hasAttribute("data-nish-keep-active");
|
|
82
|
+
if (skip) {
|
|
83
|
+
if (inerted.has(el)) {
|
|
84
|
+
el.inert = false;
|
|
85
|
+
el.removeAttribute("inert");
|
|
86
|
+
inerted.delete(el);
|
|
87
|
+
}
|
|
88
|
+
} else if (!el.inert) {
|
|
89
|
+
el.inert = true;
|
|
90
|
+
el.setAttribute("inert", "");
|
|
91
|
+
inerted.add(el);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function pushInert(scrim) {
|
|
96
|
+
const { dialogPortals } = ov();
|
|
97
|
+
if (!dialogPortals.includes(scrim)) dialogPortals.push(scrim);
|
|
98
|
+
syncInert();
|
|
99
|
+
}
|
|
100
|
+
function popInert(scrim) {
|
|
101
|
+
const { dialogPortals } = ov();
|
|
102
|
+
const i = dialogPortals.indexOf(scrim);
|
|
103
|
+
if (i >= 0) dialogPortals.splice(i, 1);
|
|
104
|
+
syncInert();
|
|
105
|
+
}
|
|
106
|
+
function isPhoneViewport() {
|
|
107
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(PHONE_QUERY).matches;
|
|
108
|
+
}
|
|
109
|
+
function prefersReducedMotion() {
|
|
110
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
111
|
+
}
|
|
112
|
+
var closeVetoes = /* @__PURE__ */ new WeakMap();
|
|
113
|
+
var FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
114
|
+
function focusables(root) {
|
|
115
|
+
return Array.from(root.querySelectorAll(FOCUSABLE)).filter((n) => n.offsetParent !== null);
|
|
116
|
+
}
|
|
117
|
+
function lockScroll() {
|
|
118
|
+
const s = ov();
|
|
119
|
+
if (s.lockCount++ === 0) {
|
|
120
|
+
const html = document.documentElement;
|
|
121
|
+
s.savedOverflow = {
|
|
122
|
+
html: html.style.overflow,
|
|
123
|
+
body: document.body.style.overflow
|
|
124
|
+
};
|
|
125
|
+
html.style.overflow = "hidden";
|
|
126
|
+
document.body.style.overflow = "hidden";
|
|
127
|
+
}
|
|
128
|
+
let released = false;
|
|
129
|
+
return () => {
|
|
130
|
+
if (released) return;
|
|
131
|
+
released = true;
|
|
132
|
+
if (--s.lockCount === 0 && s.savedOverflow) {
|
|
133
|
+
document.documentElement.style.overflow = s.savedOverflow.html;
|
|
134
|
+
document.body.style.overflow = s.savedOverflow.body;
|
|
135
|
+
s.savedOverflow = null;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function layerHost(anchor, container) {
|
|
140
|
+
return anchor?.closest("[data-nish-layer]") ?? container ?? document.body;
|
|
141
|
+
}
|
|
142
|
+
function queueHistoryPush(push) {
|
|
143
|
+
const s = ov();
|
|
144
|
+
if (s.pendingBacks > 0) s.queuedPushes.push(push);
|
|
145
|
+
else push();
|
|
146
|
+
}
|
|
147
|
+
function whenHistorySettled(cb) {
|
|
148
|
+
queueHistoryPush(cb);
|
|
149
|
+
}
|
|
150
|
+
function cancelHistoryPush(push) {
|
|
151
|
+
const q = ov().queuedPushes;
|
|
152
|
+
const i = q.indexOf(push);
|
|
153
|
+
if (i >= 0) q.splice(i, 1);
|
|
154
|
+
}
|
|
155
|
+
var warnedDev = /* @__PURE__ */ new Set();
|
|
156
|
+
function warnDev(message) {
|
|
157
|
+
if (warnedDev.has(message)) return;
|
|
158
|
+
try {
|
|
159
|
+
if (process.env.NODE_ENV !== "production") {
|
|
160
|
+
warnedDev.add(message);
|
|
161
|
+
console.warn(message);
|
|
162
|
+
}
|
|
163
|
+
} catch {
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function setRef(ref, value) {
|
|
167
|
+
if (typeof ref === "function") ref(value);
|
|
168
|
+
else if (ref) ref.current = value;
|
|
169
|
+
}
|
|
170
|
+
function useMergedRef(external) {
|
|
171
|
+
const internalRef = useRef(null);
|
|
172
|
+
const callbackRef = useCallback(
|
|
173
|
+
(node) => {
|
|
174
|
+
internalRef.current = node;
|
|
175
|
+
setRef(external, node);
|
|
176
|
+
},
|
|
177
|
+
[external]
|
|
178
|
+
);
|
|
179
|
+
return [internalRef, callbackRef];
|
|
180
|
+
}
|
|
181
|
+
function useScrollable(ref) {
|
|
182
|
+
const [scrollable, setScrollable] = useState(false);
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
const el = ref.current;
|
|
185
|
+
if (!el) return;
|
|
186
|
+
const check = () => setScrollable(el.scrollHeight > el.clientHeight + 1);
|
|
187
|
+
check();
|
|
188
|
+
const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(check);
|
|
189
|
+
ro?.observe(el);
|
|
190
|
+
const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(check);
|
|
191
|
+
mo?.observe(el, { childList: true, subtree: true, characterData: true });
|
|
192
|
+
return () => {
|
|
193
|
+
ro?.disconnect();
|
|
194
|
+
mo?.disconnect();
|
|
195
|
+
};
|
|
196
|
+
}, [ref]);
|
|
197
|
+
return scrollable;
|
|
198
|
+
}
|
|
199
|
+
export {
|
|
200
|
+
FOCUSABLE,
|
|
201
|
+
acquireGuard,
|
|
202
|
+
cancelHistoryPush,
|
|
203
|
+
closeVetoes,
|
|
204
|
+
focusables,
|
|
205
|
+
isPhoneViewport,
|
|
206
|
+
isTop,
|
|
207
|
+
layerHost,
|
|
208
|
+
lockScroll,
|
|
209
|
+
ov,
|
|
210
|
+
popInert,
|
|
211
|
+
prefersReducedMotion,
|
|
212
|
+
pushInert,
|
|
213
|
+
queueHistoryPush,
|
|
214
|
+
releaseGuard,
|
|
215
|
+
setRef,
|
|
216
|
+
syncLayerAttr,
|
|
217
|
+
useMergedRef,
|
|
218
|
+
useScrollable,
|
|
219
|
+
warnDev,
|
|
220
|
+
whenHistorySettled
|
|
221
|
+
};
|