nish-ui 1.9.0 → 2.0.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 +218 -58
- package/dist/base-tailwind.css +1757 -0
- package/dist/base.css +1590 -1445
- package/dist/chart.d.ts +4 -1
- package/dist/chart.js +122 -49
- package/dist/elements-all.d.ts +8 -0
- package/dist/elements-all.js +178 -0
- package/dist/elements-charts.d.ts +71 -0
- package/dist/elements-charts.js +56 -57
- package/dist/elements-data.d.ts +71 -0
- package/dist/elements-data.js +5 -6
- package/dist/elements-forms.d.ts +71 -0
- package/dist/elements-forms.js +24 -25
- package/dist/elements.d.ts +71 -0
- package/dist/elements.js +4 -5
- package/dist/esm/chart-values.js +58 -0
- package/dist/esm/chart.js +10 -0
- package/dist/esm/cn.js +19 -0
- package/dist/esm/combobox-filter.js +13 -0
- package/dist/esm/components/accordion.js +166 -0
- package/dist/esm/components/app-shell.js +198 -0
- package/dist/esm/components/avatar-classes.js +28 -0
- package/dist/esm/components/avatar.js +113 -0
- package/dist/esm/components/breadcrumbs.js +154 -0
- package/dist/esm/components/canvas/follow-caption.js +32 -0
- package/dist/esm/components/canvas/follow.js +119 -0
- package/dist/esm/components/canvas/icons.js +70 -0
- package/dist/esm/components/canvas/index.js +10 -0
- package/dist/esm/components/canvas/layout.js +258 -0
- package/dist/esm/components/canvas/legend.js +93 -0
- package/dist/esm/components/canvas/minimap.js +127 -0
- package/dist/esm/components/canvas/node.js +87 -0
- package/dist/esm/components/canvas/route.js +262 -0
- package/dist/esm/components/canvas/system-canvas.js +837 -0
- package/dist/esm/components/canvas/types.js +10 -0
- package/dist/esm/components/canvas/view.js +47 -0
- package/dist/esm/components/chart-hooks.js +19 -0
- package/dist/esm/components/charts.js +467 -0
- package/dist/esm/components/client.js +24 -0
- package/dist/esm/components/combobox.js +343 -0
- package/dist/esm/components/command.js +403 -0
- package/dist/esm/components/data-classes.js +159 -0
- package/dist/esm/components/data.js +517 -0
- package/dist/esm/components/display-classes.js +130 -0
- package/dist/esm/components/display.js +755 -0
- package/dist/esm/components/error-boundary.js +64 -0
- package/dist/esm/components/feedback.js +136 -0
- package/dist/esm/components/file-dropzone.js +184 -0
- package/dist/esm/components/filters.js +108 -0
- package/dist/esm/components/flow.js +746 -0
- package/dist/esm/components/forms-classes.js +43 -0
- package/dist/esm/components/forms.js +581 -0
- package/dist/esm/components/hooks-classes.js +9 -0
- package/dist/esm/components/hooks.js +236 -0
- package/dist/esm/components/icons.js +96 -0
- package/dist/esm/components/inbox-classes.js +29 -0
- package/dist/esm/components/inbox.js +257 -0
- package/dist/esm/components/latest.js +13 -0
- package/dist/esm/components/layout-vars.js +96 -0
- package/dist/esm/components/layout.js +272 -0
- package/dist/esm/components/media.js +143 -0
- package/dist/esm/components/nav.js +614 -0
- package/dist/esm/components/overlay-classes.js +66 -0
- package/dist/esm/components/overlay.js +1447 -0
- package/dist/esm/components/pagination-classes.js +29 -0
- package/dist/esm/components/pagination.js +154 -0
- package/dist/esm/components/portal.js +16 -0
- package/dist/esm/components/primitives-classes.js +198 -0
- package/dist/esm/components/primitives.js +268 -0
- package/dist/esm/components/progress.js +77 -0
- package/dist/esm/components/provider.js +32 -0
- package/dist/esm/components/radio-group.js +186 -0
- package/dist/esm/components/resource-classes.js +133 -0
- package/dist/esm/components/resource.js +209 -0
- package/dist/esm/components/segmented.js +178 -0
- package/dist/esm/components/separator.js +38 -0
- package/dist/esm/components/service-tokens.js +221 -0
- package/dist/esm/components/settings.js +301 -0
- package/dist/esm/components/slider.js +262 -0
- package/dist/esm/components/split-classes.js +8 -0
- package/dist/esm/components/split.js +411 -0
- package/dist/esm/components/strings.js +119 -0
- package/dist/esm/components/table.js +144 -0
- package/dist/esm/components/tabs-classes.js +21 -0
- package/dist/esm/components/tabs.js +201 -0
- package/dist/esm/components/tag-input.js +257 -0
- package/dist/esm/components/theme-toggle.js +177 -0
- package/dist/esm/components/toast.js +361 -0
- package/dist/esm/components/url-state.js +118 -0
- package/dist/esm/components/visually-hidden.js +20 -0
- package/dist/esm/format.js +320 -0
- package/dist/esm/inbox-client.js +2 -0
- package/dist/esm/inbox-types.js +2 -0
- package/dist/esm/index.js +320 -0
- package/dist/esm/runtime.js +37 -0
- package/dist/esm/server/inbox/client.js +297 -0
- package/dist/esm/server/inbox/types.js +24 -0
- package/dist/esm/sparkline-path.js +59 -0
- package/dist/esm/split-layout.js +419 -0
- package/dist/esm/system-canvas.js +2 -0
- package/dist/esm/theme.js +804 -0
- package/dist/esm/tokens.mjs +425 -0
- package/dist/esm/url.js +20 -0
- package/dist/files.json +5 -1
- package/dist/fonts/LICENSE-Inter.txt +93 -0
- package/dist/format.d.ts +32 -18
- package/dist/format.js +227 -82
- package/dist/inbox-client.js +3 -1
- package/dist/index.d.ts +1686 -667
- package/dist/nish-components.css +4649 -4506
- package/dist/nish-components.min.css +1 -0
- package/dist/nish.css +1603 -1450
- package/dist/nish.min.css +1 -0
- package/dist/node/eslint.js +29 -14
- package/dist/node/th-check.js +29 -14
- package/dist/node/vite.d.ts +12 -0
- package/dist/node/vite.js +12 -2
- package/dist/server/hono.d.ts +15 -6
- package/dist/server/hono.js +30 -25
- package/dist/server/index.d.ts +3 -10
- package/dist/server/index.js +71 -38
- package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
- package/dist/system-canvas-BLuWd69H.d.ts +183 -0
- package/dist/system-canvas.d.ts +2 -168
- package/dist/tailwind-core.css +114 -0
- package/dist/tailwind.css +3 -7
- package/dist/theme-init.js +23 -9
- package/dist/theme-init.sha256 +1 -0
- package/dist/theme.d.ts +243 -4
- package/dist/theme.global.js +356 -89
- package/dist/theme.js +337 -67
- package/dist/tokens.css +14 -6
- package/dist/tokens.dtcg.json +1513 -0
- package/dist/tokens.js +29 -14
- package/dist/tokens.json +512 -0
- package/package.json +51 -13
- package/dist/chart.js.map +0 -1
- package/dist/elements-charts.js.map +0 -1
- package/dist/elements-data.js.map +0 -1
- package/dist/elements-forms.js.map +0 -1
- package/dist/elements.js.map +0 -1
- package/dist/format.js.map +0 -1
- package/dist/inbox-client.js.map +0 -1
- package/dist/index.js +0 -10260
- package/dist/index.js.map +0 -1
- package/dist/server/hono.js.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/split-layout.js.map +0 -1
- package/dist/system-canvas.js +0 -2204
- package/dist/system-canvas.js.map +0 -1
- package/dist/theme.global.js.map +0 -1
- package/dist/theme.js.map +0 -1
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/app-shell.tsx
|
|
4
|
+
import { Fragment, useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useLocalStorage } from "./hooks.js";
|
|
6
|
+
import { useHeightVar } from "./layout-vars.js";
|
|
7
|
+
import { cn } from "../cn.js";
|
|
8
|
+
import { safeUrl } from "../url.js";
|
|
9
|
+
import { ConnectionBanner, LoadingBar, PageContainer } from "./layout.js";
|
|
10
|
+
import { AppErrorBoundary } from "./error-boundary.js";
|
|
11
|
+
import { AppHeader } from "./display.js";
|
|
12
|
+
import { MoreIcon } from "./icons.js";
|
|
13
|
+
import { BottomNav, MoreSheet, NavRail, NavSidebar, visibleNavItems } from "./nav.js";
|
|
14
|
+
import { DropdownMenu, MenuItem } from "./overlay.js";
|
|
15
|
+
import { IconButton } from "./primitives.js";
|
|
16
|
+
import { useNishStrings } from "./provider.js";
|
|
17
|
+
import { tabClass } from "./tabs-classes.js";
|
|
18
|
+
import { ThemeToggle } from "./theme-toggle.js";
|
|
19
|
+
import { Toaster } from "./toast.js";
|
|
20
|
+
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
var MAIN_ID = "nish-main";
|
|
22
|
+
function AppShell({
|
|
23
|
+
name,
|
|
24
|
+
icon,
|
|
25
|
+
brand,
|
|
26
|
+
homeHref = "/",
|
|
27
|
+
hub = false,
|
|
28
|
+
nav: navProp = [],
|
|
29
|
+
primary = 4,
|
|
30
|
+
moreItems: moreItemsProp = [],
|
|
31
|
+
renderLink,
|
|
32
|
+
navLabel: navLabelProp,
|
|
33
|
+
mainId = MAIN_ID,
|
|
34
|
+
actions,
|
|
35
|
+
themeToggle,
|
|
36
|
+
railFooter,
|
|
37
|
+
loading = false,
|
|
38
|
+
connection = {},
|
|
39
|
+
banner,
|
|
40
|
+
sidebar = false,
|
|
41
|
+
container = "default",
|
|
42
|
+
toaster = {},
|
|
43
|
+
errorBoundary = true,
|
|
44
|
+
resetKey,
|
|
45
|
+
children
|
|
46
|
+
}) {
|
|
47
|
+
const strings = useNishStrings();
|
|
48
|
+
const navLabel = navLabelProp ?? strings.sections;
|
|
49
|
+
const nav = visibleNavItems(navProp);
|
|
50
|
+
const moreItems = visibleNavItems(moreItemsProp);
|
|
51
|
+
const [sheet, setSheet] = useState(false);
|
|
52
|
+
const firstKey = useRef(true);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (firstKey.current) {
|
|
55
|
+
firstKey.current = false;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
setSheet(false);
|
|
59
|
+
}, [resetKey]);
|
|
60
|
+
const side = sidebar === false ? null : sidebar === true ? {} : sidebar;
|
|
61
|
+
const storageKey = side?.storageKey === false ? null : side?.storageKey ?? "nish-sidebar-collapsed";
|
|
62
|
+
const [storedCollapsed, setStoredCollapsed] = useLocalStorage(storageKey ?? "nish-sidebar-collapsed", side?.defaultCollapsed ?? false);
|
|
63
|
+
const [memoryCollapsed, setMemoryCollapsed] = useState(side?.defaultCollapsed ?? false);
|
|
64
|
+
const collapsed = side?.collapsed ?? (storageKey ? storedCollapsed : memoryCollapsed);
|
|
65
|
+
const setCollapsed = (next) => {
|
|
66
|
+
if (side?.collapsed === void 0) (storageKey ? setStoredCollapsed : setMemoryCollapsed)(next);
|
|
67
|
+
side?.onCollapsedChange?.(next);
|
|
68
|
+
};
|
|
69
|
+
const bannersRef = useRef(null);
|
|
70
|
+
useHeightVar(bannersRef, "--nish-banners-h");
|
|
71
|
+
const hasNav = nav.length > 0;
|
|
72
|
+
const n = nav.length <= 5 ? nav.length : Math.max(0, primary);
|
|
73
|
+
const bottomItems = nav.slice(0, n);
|
|
74
|
+
const overflow = nav.slice(n);
|
|
75
|
+
const sheetItems = hasNav ? [...overflow, ...moreItems] : [];
|
|
76
|
+
const hasSheet = sheetItems.length > 0;
|
|
77
|
+
const moreActive = sheetItems.some((i) => i.active);
|
|
78
|
+
const stickTop = "sticky top-[calc(var(--nish-header-h,0px)+var(--nish-banners-h,0px))] h-[calc(100dvh-var(--nish-header-h,0px)-var(--nish-banners-h,0px))] self-start";
|
|
79
|
+
const toggle = themeToggle === false ? false : hasSheet ? /* @__PURE__ */ jsx("span", { className: "max-md:hidden", children: themeToggle ?? /* @__PURE__ */ jsx(ThemeToggle, {}) }) : themeToggle;
|
|
80
|
+
const desktopNav = /* @__PURE__ */ jsx(Fragment2, { children: nav.map((item) => {
|
|
81
|
+
const className = cn(tabClass({ active: !!item.active }), "inline-flex");
|
|
82
|
+
const current = item.active ? "page" : void 0;
|
|
83
|
+
if (renderLink && item.href != null) {
|
|
84
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderLink(item, { className, children: item.label, "aria-current": current, onClick: item.onSelect }) }, item.key);
|
|
85
|
+
}
|
|
86
|
+
return item.href != null ? /* @__PURE__ */ jsx("a", { href: item.href, className, "aria-current": current, onClick: item.onSelect, children: item.label }, item.key) : /* @__PURE__ */ jsx("button", { type: "button", className, "aria-current": current, onClick: item.onSelect, children: item.label }, item.key);
|
|
87
|
+
}) });
|
|
88
|
+
const moreMenu = moreItems.length > 0 ? (
|
|
89
|
+
// With nav, under 768px these items live in the MoreSheet; signed out there is no sheet.
|
|
90
|
+
/* @__PURE__ */ jsx("div", { className: hasNav ? "hidden md:inline-flex" : "inline-flex", children: /* @__PURE__ */ jsx(
|
|
91
|
+
DropdownMenu,
|
|
92
|
+
{
|
|
93
|
+
align: "end",
|
|
94
|
+
trigger: /* @__PURE__ */ jsx(IconButton, { label: strings.more, children: /* @__PURE__ */ jsx(MoreIcon, { size: 20 }) }),
|
|
95
|
+
children: moreItems.map((item) => /* @__PURE__ */ jsx(
|
|
96
|
+
MenuItem,
|
|
97
|
+
{
|
|
98
|
+
icon: item.icon,
|
|
99
|
+
active: item.active,
|
|
100
|
+
onSelect: () => {
|
|
101
|
+
if (item.onSelect) item.onSelect();
|
|
102
|
+
else if (item.href != null) {
|
|
103
|
+
const href = safeUrl(item.href);
|
|
104
|
+
if (href !== null) window.location.assign(href);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
children: item.label
|
|
108
|
+
},
|
|
109
|
+
item.key
|
|
110
|
+
))
|
|
111
|
+
}
|
|
112
|
+
) })
|
|
113
|
+
) : null;
|
|
114
|
+
const page = errorBoundary ? /* @__PURE__ */ jsx(AppErrorBoundary, { resetKeys: [resetKey], children }) : children;
|
|
115
|
+
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
116
|
+
/* @__PURE__ */ jsx(
|
|
117
|
+
"a",
|
|
118
|
+
{
|
|
119
|
+
href: `#${mainId}`,
|
|
120
|
+
className: "nish-skip-link",
|
|
121
|
+
onClick: (e) => {
|
|
122
|
+
const main = document.getElementById(mainId);
|
|
123
|
+
if (!main) return;
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
main.focus();
|
|
126
|
+
main.scrollIntoView?.();
|
|
127
|
+
},
|
|
128
|
+
children: strings.skipToContent
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
/* @__PURE__ */ jsx(
|
|
132
|
+
AppHeader,
|
|
133
|
+
{
|
|
134
|
+
name,
|
|
135
|
+
icon,
|
|
136
|
+
brand,
|
|
137
|
+
homeHref,
|
|
138
|
+
hub,
|
|
139
|
+
hideNameBelow: icon != null ? "sm" : void 0,
|
|
140
|
+
compactPill: true,
|
|
141
|
+
actions: /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
142
|
+
hasNav && side?.tools != null ? /* @__PURE__ */ jsx("span", { className: "flex items-center gap-2 lg:hidden", children: side.tools }) : null,
|
|
143
|
+
actions,
|
|
144
|
+
moreMenu
|
|
145
|
+
] }),
|
|
146
|
+
themeToggle: toggle,
|
|
147
|
+
className: "max-lg:[&>nav]:hidden",
|
|
148
|
+
nav: hasNav && !side ? desktopNav : void 0,
|
|
149
|
+
navLabel
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
/* @__PURE__ */ jsx(LoadingBar, { active: loading }),
|
|
153
|
+
/* @__PURE__ */ jsxs(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
ref: bannersRef,
|
|
157
|
+
"data-nish-bar": "",
|
|
158
|
+
className: "sticky top-[var(--nish-header-h,0px)] z-[var(--nish-z-sticky,20)] empty:hidden",
|
|
159
|
+
children: [
|
|
160
|
+
connection !== false ? /* @__PURE__ */ jsx(ConnectionBanner, { ...connection }) : null,
|
|
161
|
+
banner
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
/* @__PURE__ */ jsxs("div", { className: "md:flex", children: [
|
|
166
|
+
hasNav ? /* @__PURE__ */ jsx("div", { className: cn(stickTop, "hidden md:block lg:hidden"), children: /* @__PURE__ */ jsx(NavRail, { items: nav, showFrom: "md", hideFrom: "lg", footer: railFooter, renderLink, label: navLabel, className: "h-full" }) }) : null,
|
|
167
|
+
hasNav && side ? /* @__PURE__ */ jsx("div", { className: cn(stickTop, "hidden lg:block"), children: /* @__PURE__ */ jsx(
|
|
168
|
+
NavSidebar,
|
|
169
|
+
{
|
|
170
|
+
items: nav,
|
|
171
|
+
collapsed,
|
|
172
|
+
onCollapsedChange: setCollapsed,
|
|
173
|
+
tools: side.tools,
|
|
174
|
+
footer: side.footer,
|
|
175
|
+
renderLink,
|
|
176
|
+
label: navLabel
|
|
177
|
+
}
|
|
178
|
+
) }) : null,
|
|
179
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx("main", { id: mainId, tabIndex: -1, className: "focus:outline-none", children: container === false ? page : /* @__PURE__ */ jsx(PageContainer, { as: "div", size: container, children: page }) }) })
|
|
180
|
+
] }),
|
|
181
|
+
hasNav ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
182
|
+
/* @__PURE__ */ jsx(
|
|
183
|
+
BottomNav,
|
|
184
|
+
{
|
|
185
|
+
items: bottomItems,
|
|
186
|
+
more: hasSheet ? { active: moreActive, expanded: sheet, onToggle: () => setSheet((s) => !s) } : void 0,
|
|
187
|
+
renderLink,
|
|
188
|
+
label: navLabel
|
|
189
|
+
}
|
|
190
|
+
),
|
|
191
|
+
/* @__PURE__ */ jsx(MoreSheet, { open: sheet, onClose: () => setSheet(false), items: sheetItems, renderLink })
|
|
192
|
+
] }) : null,
|
|
193
|
+
toaster !== false ? /* @__PURE__ */ jsx(Toaster, { ...toaster }) : null
|
|
194
|
+
] });
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
AppShell
|
|
198
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/components/avatar-classes.ts
|
|
2
|
+
var HUES = [
|
|
3
|
+
"bg-th-emerald-soft text-th-hi",
|
|
4
|
+
"bg-th-indigo-soft text-th-hi",
|
|
5
|
+
"bg-th-amber-soft text-th-hi",
|
|
6
|
+
"bg-th-lime-soft text-th-hi",
|
|
7
|
+
"bg-th-rose-soft text-th-hi",
|
|
8
|
+
"bg-th-sky-soft text-th-hi",
|
|
9
|
+
"bg-th-violet-soft text-th-hi",
|
|
10
|
+
"bg-th-teal-soft text-th-hi"
|
|
11
|
+
];
|
|
12
|
+
function avatarHueIndex(name) {
|
|
13
|
+
let h = 5381;
|
|
14
|
+
for (let i = 0; i < name.length; i++) h = (h << 5) + h + name.charCodeAt(i) >>> 0;
|
|
15
|
+
return h % HUES.length;
|
|
16
|
+
}
|
|
17
|
+
function avatarInitials(name) {
|
|
18
|
+
const words = name.trim().split(/\s+/).filter(Boolean);
|
|
19
|
+
if (!words.length) return "";
|
|
20
|
+
const first = Array.from(words[0])[0] ?? "";
|
|
21
|
+
const last = words.length > 1 ? Array.from(words[words.length - 1])[0] ?? "" : "";
|
|
22
|
+
return (first + last).toUpperCase();
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
HUES,
|
|
26
|
+
avatarHueIndex,
|
|
27
|
+
avatarInitials
|
|
28
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/avatar.tsx
|
|
4
|
+
import {
|
|
5
|
+
Children,
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
useState
|
|
9
|
+
} from "react";
|
|
10
|
+
import { cn } from "../cn.js";
|
|
11
|
+
import { safeUrl } from "../url.js";
|
|
12
|
+
import { StatusDot } from "./display.js";
|
|
13
|
+
import { useNishStrings } from "./provider.js";
|
|
14
|
+
import { HUES, avatarHueIndex, avatarInitials } from "./avatar-classes.js";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var SIZE = {
|
|
17
|
+
xs: "size-6 text-3xs",
|
|
18
|
+
sm: "size-8 text-xs",
|
|
19
|
+
md: "size-10 text-sm",
|
|
20
|
+
lg: "size-12 text-base",
|
|
21
|
+
xl: "size-16 text-xl"
|
|
22
|
+
};
|
|
23
|
+
var DOT_SIZE = { xs: "xs", sm: "xs", md: "sm", lg: "sm", xl: "md" };
|
|
24
|
+
var GroupContext = /* @__PURE__ */ createContext(null);
|
|
25
|
+
function Avatar({ src, name, alt, size, shape, status, className, ref, ...rest }) {
|
|
26
|
+
const group = useContext(GroupContext);
|
|
27
|
+
const strings = useNishStrings();
|
|
28
|
+
const resolvedSize = size ?? group?.size ?? "md";
|
|
29
|
+
const resolvedShape = shape ?? group?.shape ?? "circle";
|
|
30
|
+
const url = src ? safeUrl(src) : null;
|
|
31
|
+
const [failed, setFailed] = useState(null);
|
|
32
|
+
const showImage = url != null && failed !== url;
|
|
33
|
+
const label = alt ?? name ?? strings.avatar;
|
|
34
|
+
const decorative = alt === "";
|
|
35
|
+
const initials = name ? avatarInitials(name) : "";
|
|
36
|
+
const rounded = resolvedShape === "circle" ? "rounded-full" : "rounded-lg";
|
|
37
|
+
return /* @__PURE__ */ jsxs(
|
|
38
|
+
"span",
|
|
39
|
+
{
|
|
40
|
+
ref,
|
|
41
|
+
className: cn("relative inline-flex shrink-0 align-middle", SIZE[resolvedSize].split(" ")[0], className),
|
|
42
|
+
...rest,
|
|
43
|
+
children: [
|
|
44
|
+
showImage ? /* @__PURE__ */ jsx(
|
|
45
|
+
"img",
|
|
46
|
+
{
|
|
47
|
+
src: url,
|
|
48
|
+
alt: label,
|
|
49
|
+
onError: () => setFailed(url),
|
|
50
|
+
className: cn("size-full object-cover", rounded)
|
|
51
|
+
}
|
|
52
|
+
) : /* @__PURE__ */ jsx(
|
|
53
|
+
"span",
|
|
54
|
+
{
|
|
55
|
+
role: decorative ? void 0 : "img",
|
|
56
|
+
"aria-label": decorative ? void 0 : label,
|
|
57
|
+
"aria-hidden": decorative ? true : void 0,
|
|
58
|
+
className: cn(
|
|
59
|
+
"inline-flex size-full select-none items-center justify-center overflow-hidden font-semibold",
|
|
60
|
+
"forced-colors:border forced-colors:border-[ButtonText]",
|
|
61
|
+
rounded,
|
|
62
|
+
SIZE[resolvedSize].split(" ")[1],
|
|
63
|
+
name ? HUES[avatarHueIndex(name)] : "bg-th-elevated text-th-hi2"
|
|
64
|
+
),
|
|
65
|
+
children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials })
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
status ? /* @__PURE__ */ jsx(
|
|
69
|
+
StatusDot,
|
|
70
|
+
{
|
|
71
|
+
tone: status,
|
|
72
|
+
size: DOT_SIZE[resolvedSize],
|
|
73
|
+
label: status,
|
|
74
|
+
className: "absolute bottom-0 end-0 ring-2 ring-th-surface forced-colors:border forced-colors:border-[ButtonText]"
|
|
75
|
+
}
|
|
76
|
+
) : null
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function AvatarGroup({ max, size = "md", shape = "circle", children, className, ref, ...rest }) {
|
|
82
|
+
const strings = useNishStrings();
|
|
83
|
+
const items = Children.toArray(children);
|
|
84
|
+
const limit = max != null && max >= 0 ? Math.floor(max) : items.length;
|
|
85
|
+
const shown = items.slice(0, limit);
|
|
86
|
+
const extra = items.length - shown.length;
|
|
87
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, { value: { size, shape }, children: /* @__PURE__ */ jsxs("div", { ref, role: "group", className: cn("flex items-center", className), ...rest, children: [
|
|
88
|
+
shown.map((child, i) => /* @__PURE__ */ jsx("span", { className: cn("inline-flex ring-2 ring-th-surface", shape === "circle" ? "rounded-full" : "rounded-lg", i > 0 && "-ms-2"), children: child }, i)),
|
|
89
|
+
extra > 0 ? /* @__PURE__ */ jsx(
|
|
90
|
+
"span",
|
|
91
|
+
{
|
|
92
|
+
role: "img",
|
|
93
|
+
"aria-label": strings.avatarMore(extra),
|
|
94
|
+
className: cn(
|
|
95
|
+
"-ms-2 inline-flex shrink-0 items-center justify-center bg-th-overlay font-semibold tabular-nums text-th-hi2 ring-2 ring-th-surface",
|
|
96
|
+
"forced-colors:border forced-colors:border-[ButtonText]",
|
|
97
|
+
shape === "circle" ? "rounded-full" : "rounded-lg",
|
|
98
|
+
SIZE[size]
|
|
99
|
+
),
|
|
100
|
+
children: /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", children: [
|
|
101
|
+
"+",
|
|
102
|
+
extra
|
|
103
|
+
] })
|
|
104
|
+
}
|
|
105
|
+
) : null
|
|
106
|
+
] }) });
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
Avatar,
|
|
110
|
+
AvatarGroup,
|
|
111
|
+
avatarHueIndex,
|
|
112
|
+
avatarInitials
|
|
113
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/breadcrumbs.tsx
|
|
4
|
+
import { Children, Fragment, cloneElement, isValidElement, useCallback, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { safeUrl } from "../url.js";
|
|
7
|
+
import { useIsoLayoutEffect } from "./client.js";
|
|
8
|
+
import { DropdownMenu, MenuItem } from "./overlay.js";
|
|
9
|
+
import { useNishStrings } from "./provider.js";
|
|
10
|
+
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var LINK = cn(
|
|
12
|
+
"inline-flex items-center rounded text-th-hi3 transition-colors duration-150 hover:text-th-hi hover:underline",
|
|
13
|
+
"pointer-coarse:min-h-11"
|
|
14
|
+
);
|
|
15
|
+
var CURRENT = "inline-flex items-center font-medium text-th-hi pointer-coarse:min-h-11";
|
|
16
|
+
function Chevron() {
|
|
17
|
+
return /* @__PURE__ */ jsx(
|
|
18
|
+
"svg",
|
|
19
|
+
{
|
|
20
|
+
width: 14,
|
|
21
|
+
height: 14,
|
|
22
|
+
viewBox: "0 0 24 24",
|
|
23
|
+
fill: "none",
|
|
24
|
+
stroke: "currentColor",
|
|
25
|
+
strokeWidth: 2,
|
|
26
|
+
strokeLinecap: "round",
|
|
27
|
+
strokeLinejoin: "round",
|
|
28
|
+
"aria-hidden": "true",
|
|
29
|
+
focusable: "false",
|
|
30
|
+
className: "shrink-0 text-th-ghost rtl:-scale-x-100",
|
|
31
|
+
children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" })
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
function Crumb({
|
|
36
|
+
item,
|
|
37
|
+
current,
|
|
38
|
+
renderLink
|
|
39
|
+
}) {
|
|
40
|
+
const href = item.href !== void 0 ? safeUrl(item.href) : null;
|
|
41
|
+
if (current) {
|
|
42
|
+
return /* @__PURE__ */ jsx("span", { "aria-current": "page", className: cn(CURRENT, "min-w-0 truncate"), children: item.label });
|
|
43
|
+
}
|
|
44
|
+
if (href !== null) {
|
|
45
|
+
const props = { className: cn(LINK, "min-w-0"), href, children: item.label, onClick: item.onClick };
|
|
46
|
+
if (renderLink) return /* @__PURE__ */ jsx(Fragment2, { children: renderLink(item, props) });
|
|
47
|
+
return /* @__PURE__ */ jsx("a", { ...props });
|
|
48
|
+
}
|
|
49
|
+
if (item.onClick) {
|
|
50
|
+
return /* @__PURE__ */ jsx("button", { type: "button", className: cn(LINK, "min-w-0"), onClick: item.onClick, children: item.label });
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsx("span", { className: "inline-flex min-w-0 items-center text-th-hi3 pointer-coarse:min-h-11", children: item.label });
|
|
53
|
+
}
|
|
54
|
+
function Breadcrumbs({
|
|
55
|
+
items,
|
|
56
|
+
children,
|
|
57
|
+
renderLink,
|
|
58
|
+
separator,
|
|
59
|
+
maxItems = 4,
|
|
60
|
+
collapse = "auto",
|
|
61
|
+
label,
|
|
62
|
+
moreLabel,
|
|
63
|
+
className,
|
|
64
|
+
ref,
|
|
65
|
+
...rest
|
|
66
|
+
}) {
|
|
67
|
+
const strings = useNishStrings();
|
|
68
|
+
const navRef = useRef(null);
|
|
69
|
+
const [narrow, setNarrow] = useState(false);
|
|
70
|
+
const setRefs = useCallback(
|
|
71
|
+
(node) => {
|
|
72
|
+
navRef.current = node;
|
|
73
|
+
if (typeof ref === "function") ref(node);
|
|
74
|
+
else if (ref) ref.current = node;
|
|
75
|
+
},
|
|
76
|
+
[ref]
|
|
77
|
+
);
|
|
78
|
+
useIsoLayoutEffect(() => {
|
|
79
|
+
const el = navRef.current;
|
|
80
|
+
if (collapse !== "auto" || !el || typeof ResizeObserver === "undefined") return;
|
|
81
|
+
const measure = (w) => setNarrow(w > 0 && w < 640);
|
|
82
|
+
measure(el.getBoundingClientRect().width);
|
|
83
|
+
const ro = new ResizeObserver((entries) => {
|
|
84
|
+
const w = entries[0]?.contentRect.width;
|
|
85
|
+
if (w !== void 0) measure(w);
|
|
86
|
+
});
|
|
87
|
+
ro.observe(el);
|
|
88
|
+
return () => ro.disconnect();
|
|
89
|
+
}, [collapse]);
|
|
90
|
+
const sep = separator ?? /* @__PURE__ */ jsx(Chevron, {});
|
|
91
|
+
const nodes = [];
|
|
92
|
+
if (items) {
|
|
93
|
+
const limit = Math.max(2, Math.floor(maxItems));
|
|
94
|
+
const shouldCollapse = items.length > limit && (collapse === "always" || collapse === "auto" && narrow);
|
|
95
|
+
const tail = Math.max(1, limit - 2);
|
|
96
|
+
const hidden = shouldCollapse ? items.slice(1, items.length - tail) : [];
|
|
97
|
+
const shown = shouldCollapse ? [items[0], null, ...items.slice(items.length - tail)] : items;
|
|
98
|
+
shown.forEach((item, i) => {
|
|
99
|
+
if (item === null) {
|
|
100
|
+
nodes.push(
|
|
101
|
+
/* @__PURE__ */ jsx(
|
|
102
|
+
DropdownMenu,
|
|
103
|
+
{
|
|
104
|
+
"aria-label": moreLabel ?? strings.more,
|
|
105
|
+
trigger: /* @__PURE__ */ jsx(
|
|
106
|
+
"button",
|
|
107
|
+
{
|
|
108
|
+
type: "button",
|
|
109
|
+
"aria-label": moreLabel ?? strings.more,
|
|
110
|
+
className: cn(LINK, "min-h-8 min-w-8 justify-center px-1 pointer-coarse:min-w-11"),
|
|
111
|
+
children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\u2026" })
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
children: hidden.map((h, j) => /* @__PURE__ */ jsx(
|
|
115
|
+
MenuItem,
|
|
116
|
+
{
|
|
117
|
+
onSelect: (e) => {
|
|
118
|
+
if (h.onClick) h.onClick(e);
|
|
119
|
+
else {
|
|
120
|
+
const href = h.href !== void 0 ? safeUrl(h.href) : null;
|
|
121
|
+
if (href !== null && typeof window !== "undefined") window.location.assign(href);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
children: h.label
|
|
125
|
+
},
|
|
126
|
+
j
|
|
127
|
+
))
|
|
128
|
+
},
|
|
129
|
+
"more"
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
} else {
|
|
133
|
+
nodes.push(/* @__PURE__ */ jsx(Crumb, { item, current: i === shown.length - 1, renderLink }, `i${i}`));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
const kids = Children.toArray(children);
|
|
138
|
+
kids.forEach((k, i) => {
|
|
139
|
+
const last = i === kids.length - 1;
|
|
140
|
+
let node = k;
|
|
141
|
+
if (last) {
|
|
142
|
+
node = isValidElement(k) ? cloneElement(k, { "aria-current": "page" }) : /* @__PURE__ */ jsx("span", { "aria-current": "page", className: CURRENT, children: k });
|
|
143
|
+
}
|
|
144
|
+
nodes.push(/* @__PURE__ */ jsx(Fragment, { children: node }, i));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return /* @__PURE__ */ jsx("nav", { "aria-label": label ?? strings.breadcrumbs, ...rest, ref: setRefs, className: cn("min-w-0 text-sm", className), children: /* @__PURE__ */ jsx("ol", { className: "flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5", children: nodes.map((node, i) => /* @__PURE__ */ jsxs("li", { className: "flex min-w-0 items-center gap-1.5", children: [
|
|
148
|
+
i > 0 && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", "data-separator": "", className: "flex shrink-0 items-center text-th-ghost", children: sep }),
|
|
149
|
+
node
|
|
150
|
+
] }, i)) }) });
|
|
151
|
+
}
|
|
152
|
+
export {
|
|
153
|
+
Breadcrumbs
|
|
154
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/canvas/follow-caption.tsx
|
|
4
|
+
import { memo } from "react";
|
|
5
|
+
import { StatusDot } from "../display.js";
|
|
6
|
+
import { TickerText } from "../flow.js";
|
|
7
|
+
import { DEFAULT_CANVAS_LABELS } from "./types.js";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var FollowCaption = memo(function FollowCaption2({ step, labels = DEFAULT_CANVAS_LABELS }) {
|
|
10
|
+
if (!step) return null;
|
|
11
|
+
const only = step.targets.length === 1 ? step.targets[0] : null;
|
|
12
|
+
const text = step.mode === "idle" ? labels.followIdle : only ? labels.followOne(only.group, only.label) : labels.followMany(step.targets.length);
|
|
13
|
+
return /* @__PURE__ */ jsxs(
|
|
14
|
+
"div",
|
|
15
|
+
{
|
|
16
|
+
"data-canvas-ui": true,
|
|
17
|
+
role: "status",
|
|
18
|
+
"aria-live": "polite",
|
|
19
|
+
className: "absolute bottom-[68px] start-3 z-10 flex max-w-[min(420px,calc(100%-24px))] items-center gap-2 rounded-xl border border-th-line bg-th-surface px-3 py-2 text-xs text-th-hi shadow-card min-[600px]:bottom-3",
|
|
20
|
+
children: [
|
|
21
|
+
/* @__PURE__ */ jsx(StatusDot, { tone: "accent", pulse: step.mode !== "idle" }),
|
|
22
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
23
|
+
/* @__PURE__ */ jsx("div", { className: "truncate", children: text }),
|
|
24
|
+
only?.note ? /* @__PURE__ */ jsx(TickerText, { as: "div", text: only.note, className: "truncate text-th-hi3" }) : null
|
|
25
|
+
] })
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
export {
|
|
31
|
+
FollowCaption
|
|
32
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/canvas/follow.ts
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { centerOn, clampK } from "./view.js";
|
|
6
|
+
var CYCLE_MS = 6e3;
|
|
7
|
+
var BBOX_PAD = 80;
|
|
8
|
+
var VIEW_PAD = 96;
|
|
9
|
+
var PHONE_W = 600;
|
|
10
|
+
var PHONE_TOP = 0.45;
|
|
11
|
+
function followTargets(groups, layout) {
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const g of groups) {
|
|
14
|
+
for (const n of g.nodes) {
|
|
15
|
+
const box = layout.nodes[n.id];
|
|
16
|
+
if (!n.active || !box) continue;
|
|
17
|
+
out.push({ id: n.id, label: n.label, group: g.title, note: n.note, box, groupBox: layout.groups[g.id], at: n.activeAt ?? 0 });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return out.sort((a, b) => b.at - a.at);
|
|
21
|
+
}
|
|
22
|
+
function place(w, h, k, box, groupBox, top = 0) {
|
|
23
|
+
const v = centerOn(w, h, k, box);
|
|
24
|
+
if (w >= PHONE_W) return v;
|
|
25
|
+
const y = Math.max(h * PHONE_TOP / 2, top + box.h * k / 2) - (box.y + box.h / 2) * k;
|
|
26
|
+
if (groupBox && groupBox.w * k <= w - 24) return { ...v, x: w / 2 - (groupBox.x + groupBox.w / 2) * k, y };
|
|
27
|
+
return { ...v, y };
|
|
28
|
+
}
|
|
29
|
+
function followStep(targets, i, w, h, fit, top = 0) {
|
|
30
|
+
if (targets.length === 0) return { mode: "idle", view: fit, targets: [] };
|
|
31
|
+
const phone = w < PHONE_W;
|
|
32
|
+
const single = phone ? 0.8 : 1;
|
|
33
|
+
if (targets.length === 1) {
|
|
34
|
+
return { mode: "all", targets, view: place(w, h, single, targets[0].box, targets[0].groupBox, top) };
|
|
35
|
+
}
|
|
36
|
+
let x0 = Infinity;
|
|
37
|
+
let y0 = Infinity;
|
|
38
|
+
let x1 = -Infinity;
|
|
39
|
+
let y1 = -Infinity;
|
|
40
|
+
for (const t of targets) {
|
|
41
|
+
x0 = Math.min(x0, t.box.x);
|
|
42
|
+
y0 = Math.min(y0, t.box.y);
|
|
43
|
+
x1 = Math.max(x1, t.box.x + t.box.w);
|
|
44
|
+
y1 = Math.max(y1, t.box.y + t.box.h);
|
|
45
|
+
}
|
|
46
|
+
const bbox = { x: x0 - BBOX_PAD, y: y0 - BBOX_PAD, w: x1 - x0 + 2 * BBOX_PAD, h: y1 - y0 + 2 * BBOX_PAD };
|
|
47
|
+
const kAll = Math.min((w - VIEW_PAD) / bbox.w, (h - VIEW_PAD) / bbox.h, 1.1);
|
|
48
|
+
if (kAll >= (phone ? 0.55 : 0.75)) {
|
|
49
|
+
return { mode: "all", targets, view: place(w, h, clampK(kAll), bbox, void 0, top) };
|
|
50
|
+
}
|
|
51
|
+
const target = targets[(i % targets.length + targets.length) % targets.length];
|
|
52
|
+
return { mode: "one", targets: [target], view: place(w, h, single, target.box, target.groupBox, top) };
|
|
53
|
+
}
|
|
54
|
+
var followSignature = (targets) => targets.map((t) => t.id).sort().join("|");
|
|
55
|
+
var captionKey = (targets) => targets.map((t) => `${t.id}:${t.label}:${t.group}:${t.note ?? ""}`).join("|");
|
|
56
|
+
function useFollow(o) {
|
|
57
|
+
const { on, groups, layout, size } = o;
|
|
58
|
+
const latest = useRef(o);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
latest.current = o;
|
|
61
|
+
});
|
|
62
|
+
const index = useRef(0);
|
|
63
|
+
const visiting = useRef(null);
|
|
64
|
+
const [step, setStep] = useState(null);
|
|
65
|
+
const targets = on ? followTargets(groups, layout) : [];
|
|
66
|
+
const sig = followSignature(targets);
|
|
67
|
+
const caption = captionKey(targets);
|
|
68
|
+
const indexKey = useRef("");
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!on) {
|
|
71
|
+
indexKey.current = "";
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const key = sig;
|
|
75
|
+
if (indexKey.current !== key) {
|
|
76
|
+
indexKey.current = key;
|
|
77
|
+
index.current = 0;
|
|
78
|
+
visiting.current = null;
|
|
79
|
+
}
|
|
80
|
+
let timer;
|
|
81
|
+
const run = (advance) => {
|
|
82
|
+
const cur = latest.current;
|
|
83
|
+
const ts = followTargets(cur.groups, cur.layout);
|
|
84
|
+
const at = visiting.current ? ts.findIndex((t) => t.id === visiting.current) : -1;
|
|
85
|
+
index.current = at < 0 ? 0 : advance ? at + 1 : at;
|
|
86
|
+
const next = followStep(ts, index.current, cur.size.w, cur.size.h, cur.fit(), cur.inset ?? 0);
|
|
87
|
+
visiting.current = next.mode === "one" ? next.targets[0]?.id ?? null : null;
|
|
88
|
+
setStep(next);
|
|
89
|
+
cur.fly(next.view);
|
|
90
|
+
if (next.mode === "one" && timer === void 0) timer = setInterval(() => run(true), CYCLE_MS);
|
|
91
|
+
if (next.mode !== "one" && timer !== void 0) {
|
|
92
|
+
clearInterval(timer);
|
|
93
|
+
timer = void 0;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
run(false);
|
|
97
|
+
return () => {
|
|
98
|
+
if (timer !== void 0) clearInterval(timer);
|
|
99
|
+
};
|
|
100
|
+
}, [on, sig, layout, size.w, size.h]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (!on) return;
|
|
103
|
+
const cur = latest.current;
|
|
104
|
+
const ts = followTargets(cur.groups, cur.layout);
|
|
105
|
+
setStep((prev) => {
|
|
106
|
+
if (!prev || prev.mode === "idle") return prev;
|
|
107
|
+
const fresh = prev.mode === "one" ? ts.filter((t) => t.id === visiting.current) : ts;
|
|
108
|
+
if (fresh.length === 0 || captionKey(prev.targets) === captionKey(fresh)) return prev;
|
|
109
|
+
return { ...prev, targets: fresh };
|
|
110
|
+
});
|
|
111
|
+
}, [on, caption]);
|
|
112
|
+
return { step: on ? step : null };
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
followSignature,
|
|
116
|
+
followStep,
|
|
117
|
+
followTargets,
|
|
118
|
+
useFollow
|
|
119
|
+
};
|