@meldgrove/ui 0.1.1 → 0.1.2

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 CHANGED
@@ -48,7 +48,7 @@ components it uses imports `@meldgrove/ui/theme.css` instead and adds
48
48
  `@source` lines for those files in `node_modules/@meldgrove/ui/dist/components`.
49
49
 
50
50
  `SidebarInset` renders a `<div>`; the app's page content brings its own
51
- `<main>`.
51
+ `<main>`. Apps with the [app frame](#app-frame) get both from it.
52
52
 
53
53
  ### Language
54
54
 
@@ -69,6 +69,141 @@ toaster once; it follows the class `dark` on `<html>`:
69
69
  import { Toaster } from "@meldgrove/ui/sonner";
70
70
  ```
71
71
 
72
+ ## App frame
73
+
74
+ Every Meldgrove app shows its pages in the same frame. Changing it here
75
+ changes every app.
76
+
77
+ - **Sidebar:** the app's name at the top, then the search, the navigation as
78
+ text (no icons) and the person at the bottom. ⌘B or Ctrl+B, or a click on
79
+ its edge, hides it completely. On phones it is a sheet that closes once a
80
+ page is chosen.
81
+ - **Header:** the breadcrumbs (at most three steps; on phones only "‹ back")
82
+ and, at the right, `headerEnd`: the update button for admins.
83
+ - **User menu:** Appearance (light, dark, device setting), Settings, Keyboard
84
+ shortcuts and Sign out.
85
+ - **Keys:** ⌘K or Ctrl+K and "/" open the search. "G then a letter" opens a
86
+ main page. Ctrl+/ lists every shortcut (Ctrl on a Mac too). Shortcuts with
87
+ single letters can be turned off on the settings page (WCAG 2.1.4).
88
+
89
+ ```tsx
90
+ import { AppFrame, type FrameLink, type NavGroup } from "@meldgrove/ui/app-frame";
91
+ import { useThemePreference } from "@meldgrove/ui/theme";
92
+ import { UpdateButton } from "@meldgrove/ui/updates";
93
+
94
+ const nav: NavGroup[] = [
95
+ {
96
+ items: [
97
+ { label: "Overview", href: "/", shortcut: "o" },
98
+ { label: "Requests", href: "/requests", shortcut: "r", badge: openCount },
99
+ ],
100
+ },
101
+ { label: "Admin", items: [{ label: "Forms", href: "/admin/forms" }] },
102
+ ];
103
+
104
+ const [theme, setTheme] = useThemePreference();
105
+
106
+ <AppFrame
107
+ app={{ name: "Helpdesk", icon: <LifeBuoy />, description: organizationName }}
108
+ nav={nav}
109
+ pathname={pathname}
110
+ link={AppLink}
111
+ navigate={(href) => router.navigate({ to: href })}
112
+ user={{ name, email, detail: roleLabel, image }}
113
+ theme={theme}
114
+ onThemeChange={setTheme}
115
+ settingsHref="/settings"
116
+ onSignOut={signOut}
117
+ breadcrumbs={[{ label: "Requests", href: "/requests" }, { label: "REQ-142" }]}
118
+ headerEnd={isAdmin ? <UpdateButton /> : null}
119
+ search={{ find: (query, signal) => api.search(query, { signal }) }}
120
+ >
121
+ <Outlet />
122
+ </AppFrame>;
123
+ ```
124
+
125
+ - **`link`:** the router's link. Next.js passes its `Link` as it is. Other
126
+ routers use a small adapter that passes every other prop on to the `<a>`:
127
+ `const AppLink: FrameLink = ({ href, ...props }) => <Link to={href} {...props} />;`
128
+ - **`nav`:** the app filters it by role before it passes it in. The item
129
+ whose `href` the path starts with is marked (the longest one; "/" and
130
+ `exact` items only on themselves; `match` adds paths that belong to an
131
+ item, such as `["/e"]` for entries of a timeline at "/"). `shortcut` is for the main pages only,
132
+ each letter once (the console says so otherwise); "o" is the start page in
133
+ every app.
134
+ - **`breadcrumbs`:** from the sidebar section to the page, without the app.
135
+ A record appears by its short number where it has one (REQ-142), else by
136
+ its name; long labels are cut.
137
+ - **`search`:** without `find`, the search offers the app's pages.
138
+ `find(query, signal)` adds records (`href`, `title`, optional `reference`
139
+ and `kind`); `allResultsHref(query)` adds "Show all results".
140
+ - **`theme`:** `useThemePreference()` keeps the choice in the browser and
141
+ sets the class `dark`. An app that saves it with the person passes its own
142
+ value. To avoid a light flash on load, the app sets the class in a small
143
+ script before React starts.
144
+ - **`shortcuts`:** default: the person's choice in this browser
145
+ (`useShortcutsPreference`). An app that saves it with the person passes it.
146
+ - **Next.js:** the frame takes functions and a component (`link`,
147
+ `navigate`, `onSignOut`), which cannot cross from a server component. Put
148
+ it in a client component of the app; the server layout passes data only,
149
+ with `defaultSidebarOpen` from the cookie `sidebar_state`. Vite apps leave
150
+ that out; the frame reads the cookie.
151
+ - `SidebarInset` is inside the frame; the page brings its `Page` (below), not
152
+ another `<main>`.
153
+
154
+ ### Pages
155
+
156
+ `Page` is the content area (centred, at most 80 rem; `wide` for full width),
157
+ `PageHeader` the title with description and actions:
158
+
159
+ ```tsx
160
+ import { Page, PageHeader } from "@meldgrove/ui/page";
161
+
162
+ <Page>
163
+ <PageHeader
164
+ title="Requests"
165
+ description="Every request, newest first."
166
+ actions={<Button>New request</Button>}
167
+ />
168
+ …
169
+ </Page>;
170
+ ```
171
+
172
+ The main action of a page sits in its header; the frame has no button for it.
173
+
174
+ ### Sign-in page
175
+
176
+ ```tsx
177
+ import { SignInPage } from "@meldgrove/ui/sign-in-page";
178
+
179
+ <SignInPage
180
+ app={{ name: "Helpdesk", icon: <LifeBuoy /> }}
181
+ tagline="Send requests and follow them up."
182
+ organization={organizationName}
183
+ repositoryUrl="https://github.com/meldgrove/helpdesk"
184
+ >
185
+ <Button onClick={signIn}>Sign in with your organization account</Button>
186
+ </SignInPage>;
187
+ ```
188
+
189
+ What the app is for sits on the left on wide screens, the sign-in on the
190
+ right, and below it "Helpdesk is part of Meldgrove" with a link to the
191
+ repository. The app's buttons and messages go in `children`.
192
+
193
+ ### Settings page
194
+
195
+ ```tsx
196
+ import { AboutCard, AppearanceCard, KeyboardShortcutsCard } from "@meldgrove/ui/settings-cards";
197
+
198
+ <AppearanceCard value={theme} onChange={setTheme} />
199
+ <KeyboardShortcutsCard />
200
+ <AboutCard appName="Helpdesk" repositoryUrl="https://github.com/meldgrove/helpdesk" />
201
+ ```
202
+
203
+ `KeyboardShortcutsCard` without props keeps the choice in the browser, and
204
+ the frame follows it. A private repository (CRM) links to
205
+ `https://github.com/meldgrove` instead.
206
+
72
207
  ## Colors
73
208
 
74
209
  Every component uses the semantic tokens of shadcn/ui (`--primary`,
@@ -205,7 +340,8 @@ sets that class from `prefers-color-scheme` in a small script.
205
340
 
206
341
  ## Development
207
342
 
208
- See [CONTRIBUTING.md](CONTRIBUTING.md). `npm run dev` opens a demo page with
343
+ See [CONTRIBUTING.md](CONTRIBUTING.md). `npm run dev:templates` opens the
344
+ app frame with fake content of three apps. `npm run dev` opens a demo page with
209
345
  every component in light and dark, English and German, and with an app
210
346
  accent.
211
347
 
@@ -0,0 +1,82 @@
1
+ import { type ComponentProps, type ComponentType, type ReactNode } from "react";
2
+ import { type ThemePreference } from "../lib/theme.ts";
3
+ import { type Crumb } from "../frame/crumbs.tsx";
4
+ import { type AppSearchOptions } from "../frame/search.tsx";
5
+ export type { Crumb } from "../frame/crumbs.tsx";
6
+ export type { AppSearchOptions, SearchResult } from "../frame/search.tsx";
7
+ export { useShortcutsPreference } from "../frame/shortcuts.tsx";
8
+ /**
9
+ * The app's link: Next.js's `Link` as it is, or a small adapter for another
10
+ * router. It must pass every other prop (class, `aria-current`, `ref`, …)
11
+ * on to its `<a>`.
12
+ */
13
+ export type FrameLinkProps = Omit<ComponentProps<"a">, "href"> & {
14
+ href: string;
15
+ };
16
+ export type FrameLink = ComponentType<FrameLinkProps>;
17
+ export type NavItem = {
18
+ label: string;
19
+ href: string;
20
+ /** A count or marker at the right, e.g. open tasks. */
21
+ badge?: ReactNode;
22
+ /**
23
+ * "G then this letter" opens the page. Only for the app's main pages, each
24
+ * letter once; "o" is the start page in every app.
25
+ */
26
+ shortcut?: string;
27
+ /** Active only on the page itself, not on its sub-pages. "/" is always exact. */
28
+ exact?: boolean;
29
+ /** More paths whose pages belong to this item, with their sub-pages: ["/e"] for entries of a timeline at "/". */
30
+ match?: string[];
31
+ };
32
+ export type NavGroup = {
33
+ label?: string;
34
+ items: NavItem[];
35
+ };
36
+ export type AppFrameProps = {
37
+ /** At the top of the sidebar, a link to the start page. */
38
+ app: {
39
+ name: string;
40
+ icon: ReactNode;
41
+ description?: string;
42
+ href?: string;
43
+ };
44
+ nav: NavGroup[];
45
+ /** More sidebar content after the groups, e.g. a list of spaces. */
46
+ sidebarContent?: ReactNode;
47
+ /** The current path; the matching item is marked. */
48
+ pathname: string;
49
+ link: FrameLink;
50
+ /** For shortcuts and search results: go to a path of the app. */
51
+ navigate: (href: string) => void;
52
+ user: {
53
+ name: string;
54
+ email?: string | null;
55
+ detail?: string;
56
+ image?: string | null;
57
+ };
58
+ /** "Appearance" in the user menu; `useThemePreference` from `@meldgrove/ui/theme` keeps one in the browser. */
59
+ theme: ThemePreference;
60
+ onThemeChange: (theme: ThemePreference) => void;
61
+ /** The person's settings page: in the user menu and in the shortcuts overview. */
62
+ settingsHref?: string;
63
+ onSignOut: () => void;
64
+ /** Where the page sits in the app, from the sidebar section to the page; at most three show. */
65
+ breadcrumbs?: Crumb[];
66
+ /** At the right of the header, e.g. the update button. */
67
+ headerEnd?: ReactNode;
68
+ search?: AppSearchOptions;
69
+ /** Single-letter shortcuts ("G then a letter", "/"). Default: the person's choice in this browser. */
70
+ shortcuts?: boolean;
71
+ /** Next.js: the cookie `sidebar_state`, read on the server. Default: that cookie, read in the browser. */
72
+ defaultSidebarOpen?: boolean;
73
+ children: ReactNode;
74
+ };
75
+ /**
76
+ * The frame of a Meldgrove app: the sidebar with the search at the top, the
77
+ * navigation as text and the user menu at the bottom; the header with the
78
+ * breadcrumbs and, at the right, `headerEnd` (the update button); the page.
79
+ * Keys: ⌘K or Ctrl+K and "/" search, "G then a letter" opens a page, Ctrl+/
80
+ * lists the shortcuts, ⌘B or Ctrl+B shows or hides the sidebar.
81
+ */
82
+ export declare function AppFrame(props: AppFrameProps): import("react").JSX.Element;
@@ -0,0 +1,129 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useMemo, useState, } from "react";
4
+ import { ChevronsUpDown, Keyboard, LogOut, PanelLeft, Settings, SunMoon } from "lucide-react";
5
+ import { Avatar, AvatarFallback, AvatarImage } from "./avatar.js";
6
+ import { Button } from "./button.js";
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "./dropdown-menu.js";
8
+ import { Separator } from "./separator.js";
9
+ import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarRail, useSidebar, } from "./sidebar.js";
10
+ import { useT } from "../lib/i18n.js";
11
+ import { THEME_PREFERENCES } from "../lib/theme.js";
12
+ import { FrameCrumbs } from "../frame/crumbs.js";
13
+ import { shortcutClashes } from "../frame/keyboard.js";
14
+ import { activeHref } from "../frame/nav.js";
15
+ import { frameMessages } from "../frame/messages.js";
16
+ import { SearchButton, SearchDialog, useSearchKeys } from "../frame/search.js";
17
+ import { GoHint, ShortcutsDialog, useGoShortcuts, useShortcutsPreference, } from "../frame/shortcuts.js";
18
+ export { useShortcutsPreference } from "../frame/shortcuts.js";
19
+ const SIDEBAR_COOKIE = "sidebar_state";
20
+ function sidebarCookie() {
21
+ if (typeof document === "undefined")
22
+ return true;
23
+ return !document.cookie.split("; ").includes(`${SIDEBAR_COOKIE}=false`);
24
+ }
25
+ function initials(name) {
26
+ const words = name.trim().split(/\s+/).filter(Boolean);
27
+ const letters = words.length > 1 ? [words[0], words.at(-1)] : words;
28
+ return letters.map((word) => word[0].toUpperCase()).join("") || "?";
29
+ }
30
+ function UserMenu(props) {
31
+ const t = useT(frameMessages);
32
+ const { isMobile } = useSidebar();
33
+ const { user } = props;
34
+ const Link = props.link;
35
+ const person = (_jsxs(_Fragment, { children: [_jsxs(Avatar, { className: "size-8 rounded-lg", children: [user.image ? _jsx(AvatarImage, { src: user.image, alt: "" }) : null, _jsx(AvatarFallback, { className: "rounded-lg", children: initials(user.name) })] }), _jsxs("span", { className: "grid flex-1 text-left text-sm leading-tight", children: [_jsx("span", { className: "truncate font-medium", children: user.name }), user.email ? _jsx("span", { className: "text-muted-foreground truncate text-xs", children: user.email }) : null] })] }));
36
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsxs(SidebarMenuButton, { size: "lg", "aria-label": t("account", { name: user.name }), className: "data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground", children: [person, _jsx(ChevronsUpDown, { className: "ml-auto size-4", "aria-hidden": "true" })] }) }), _jsxs(DropdownMenuContent, { className: "w-(--radix-dropdown-menu-trigger-width) min-w-60 rounded-lg", side: isMobile ? "top" : "right", align: "end", sideOffset: 4, children: [_jsxs(DropdownMenuLabel, { className: "font-normal", children: [_jsx("div", { className: "truncate text-sm font-medium", children: user.name }), user.email || user.detail ? (_jsx("div", { className: "text-muted-foreground truncate text-xs", children: [user.email, user.detail].filter(Boolean).join(" · ") })) : null] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuSub, { children: [_jsxs(DropdownMenuSubTrigger, { children: [_jsx(SunMoon, {}), t("appearance")] }), _jsx(DropdownMenuSubContent, { children: _jsx(DropdownMenuRadioGroup, { value: props.theme, onValueChange: (value) => props.onThemeChange(value), children: THEME_PREFERENCES.map((option) => (_jsx(DropdownMenuRadioItem, { value: option, children: t(option) }, option))) }) })] }), props.settingsHref ? (_jsx(DropdownMenuItem, { asChild: true, children: _jsxs(Link, { href: props.settingsHref, onClick: props.onNavigate, children: [_jsx(Settings, {}), t("settings")] }) })) : null, _jsxs(DropdownMenuItem, { onSelect: props.onShortcuts, children: [_jsx(Keyboard, {}), t("shortcuts"), _jsxs(DropdownMenuShortcut, { children: [t("ctrl"), " /"] })] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onSelect: props.onSignOut, children: [_jsx(LogOut, {}), t("signOut")] })] })] }));
37
+ }
38
+ function FrameSidebar(props) {
39
+ const t = useT(frameMessages);
40
+ const { isMobile, setOpenMobile, state } = useSidebar();
41
+ const Link = props.link;
42
+ const items = props.nav.flatMap((group) => group.items);
43
+ // Collapsed on a wide screen, the sidebar is off screen: keep its contents out of the tab
44
+ // order. Not on the whole sidebar, so that its edge (the rail) still opens it.
45
+ const hidden = !isMobile && state === "collapsed";
46
+ const active = activeHref(props.pathname, items);
47
+ // On phones the sidebar is a sheet: it closes once a page is chosen.
48
+ const close = () => {
49
+ if (isMobile)
50
+ setOpenMobile(false);
51
+ };
52
+ return (_jsxs(Sidebar, { variant: "floating", collapsible: "offcanvas", children: [_jsx(SidebarHeader, { inert: hidden, children: _jsxs(SidebarMenu, { children: [_jsx(SidebarMenuItem, { children: _jsx(SidebarMenuButton, { size: "lg", asChild: true, children: _jsxs(Link, { href: props.app.href ?? "/", onClick: close, children: [_jsx("span", { className: "bg-primary text-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg [&_svg]:size-4", children: props.app.icon }), _jsxs("span", { className: "grid flex-1 text-left leading-tight", children: [_jsx("span", { className: "truncate font-semibold", children: props.app.name }), props.app.description ? (_jsx("span", { className: "text-muted-foreground truncate text-xs", children: props.app.description })) : null] })] }) }) }), _jsx(SidebarMenuItem, { className: "mt-1", children: _jsx(SearchButton, { onClick: () => {
53
+ close();
54
+ props.onSearch();
55
+ } }) })] }) }), _jsxs(SidebarContent, { inert: hidden, children: [_jsx("nav", { "aria-label": t("navigation"), className: "contents", children: props.nav.map((group, index) => (_jsxs(SidebarGroup, { children: [group.label ? _jsx(SidebarGroupLabel, { children: group.label }) : null, _jsx(SidebarGroupContent, { children: _jsx(SidebarMenu, { children: group.items.map((item) => {
56
+ const current = item.href === active;
57
+ return (_jsxs(SidebarMenuItem, { children: [_jsx(SidebarMenuButton, { asChild: true, isActive: current, children: _jsx(Link, { href: item.href, onClick: close, "aria-current": current ? "page" : undefined, children: _jsx("span", { className: "truncate", children: item.label }) }) }), item.badge !== undefined && item.badge !== null ? (_jsx(SidebarMenuBadge, { children: item.badge })) : null] }, item.href));
58
+ }) }) })] }, group.label ?? index))) }), props.sidebarContent] }), _jsx(SidebarFooter, { inert: hidden, children: _jsx(SidebarMenu, { children: _jsx(SidebarMenuItem, { children: _jsx(UserMenu, { user: props.user, link: props.link, theme: props.theme, onThemeChange: props.onThemeChange, settingsHref: props.settingsHref, onSignOut: props.onSignOut, onShortcuts: props.onShortcuts, onNavigate: close }) }) }) }), _jsx(SidebarRail, {})] }));
59
+ }
60
+ function FrameHeader(props) {
61
+ const t = useT(frameMessages);
62
+ const { isMobile, toggleSidebar } = useSidebar();
63
+ return (_jsxs("header", { className: "bg-background/95 sticky top-0 z-20 flex h-14 shrink-0 items-center gap-2 border-b px-4 backdrop-blur md:rounded-t-[inherit]", children: [_jsx(Button, { variant: "ghost", size: "icon", className: "-ml-1 size-7", "aria-label": t("toggleSidebar"), title: t("toggleSidebar"), onClick: toggleSidebar, children: _jsx(PanelLeft, {}) }), _jsx(Separator, { orientation: "vertical", className: "mr-2 data-[orientation=vertical]:h-4" }), _jsx(FrameCrumbs, { crumbs: props.crumbs, link: props.link, compact: isMobile }), props.end ? _jsx("div", { className: "ml-auto flex shrink-0 items-center gap-1", children: props.end }) : null] }));
64
+ }
65
+ /**
66
+ * The frame of a Meldgrove app: the sidebar with the search at the top, the
67
+ * navigation as text and the user menu at the bottom; the header with the
68
+ * breadcrumbs and, at the right, `headerEnd` (the update button); the page.
69
+ * Keys: ⌘K or Ctrl+K and "/" search, "G then a letter" opens a page, Ctrl+/
70
+ * lists the shortcuts, ⌘B or Ctrl+B shows or hides the sidebar.
71
+ */
72
+ export function AppFrame(props) {
73
+ const t = useT(frameMessages);
74
+ const [savedShortcuts] = useShortcutsPreference();
75
+ const singleKeys = props.shortcuts ?? savedShortcuts;
76
+ const [defaultOpen] = useState(() => props.defaultSidebarOpen ?? sidebarCookie());
77
+ const [searchOpen, setSearchOpen] = useState(false);
78
+ const [shortcutsOpen, setShortcutsOpen] = useState(false);
79
+ const openSearch = useCallback(() => setSearchOpen(true), []);
80
+ const openShortcuts = useCallback(() => setShortcutsOpen(true), []);
81
+ const items = props.nav.flatMap((group) => group.items);
82
+ const signature = JSON.stringify(items.map((item) => [item.shortcut ?? "", item.label, item.href]));
83
+ const targets = useMemo(() => props.nav
84
+ .flatMap((group) => group.items)
85
+ .filter((item) => item.shortcut)
86
+ .map((item) => ({ key: item.shortcut.toLowerCase(), label: item.label, href: item.href })),
87
+ // The items' content, not the array: apps often build `nav` on every render.
88
+ // eslint-disable-next-line react-hooks/exhaustive-deps
89
+ [signature]);
90
+ useEffect(() => {
91
+ for (const [key, labels] of shortcutClashes(items)) {
92
+ // A mistake in the app's navigation; its developers see it in the console.
93
+ // eslint-disable-next-line no-console
94
+ console.error(`@meldgrove/ui AppFrame: "G then ${key.toUpperCase()}" is set for ${labels.join(", ")}; each letter may open one page.`);
95
+ }
96
+ // eslint-disable-next-line react-hooks/exhaustive-deps
97
+ }, [signature]);
98
+ return (_jsxs(SidebarProvider, { defaultOpen: defaultOpen, children: [_jsx("a", { href: "#main", onClick: (event) => {
99
+ // Focus only: the address stays as it is.
100
+ event.preventDefault();
101
+ document.getElementById("main")?.focus();
102
+ }, className: "bg-background sr-only z-50 rounded-md px-3 py-2 focus:not-sr-only focus:fixed focus:top-2 focus:left-2", children: t("skip") }), _jsx(FrameSidebar, { ...props, onSearch: openSearch, onShortcuts: openShortcuts }), _jsxs(SidebarInset, { className: "min-w-0", children: [_jsx(FrameHeader, { crumbs: props.breadcrumbs ?? [], link: props.link, end: props.headerEnd }), _jsx("main", { id: "main", tabIndex: -1, className: "flex-1 outline-none", children: props.children })] }), _jsx(FrameLayers, { ...props, pages: items.map((item) => ({ label: item.label, href: item.href, shortcut: item.shortcut })), targets: targets, singleKeys: singleKeys, searchOpen: searchOpen, setSearchOpen: setSearchOpen, shortcutsOpen: shortcutsOpen, setShortcutsOpen: setShortcutsOpen })] }));
103
+ }
104
+ /** The search, the shortcuts overview and the keys; inside the sidebar's provider, to close its sheet on phones. */
105
+ function FrameLayers(props) {
106
+ const t = useT(frameMessages);
107
+ const { setOpenMobile } = useSidebar();
108
+ const { setSearchOpen, setShortcutsOpen } = props;
109
+ const Link = props.link;
110
+ const appNavigate = props.navigate;
111
+ const navigate = useCallback((href) => {
112
+ setOpenMobile(false);
113
+ appNavigate(href);
114
+ }, [setOpenMobile, appNavigate]);
115
+ const openSearch = useCallback(() => setSearchOpen(true), [setSearchOpen]);
116
+ const openShortcuts = useCallback(() => setShortcutsOpen(true), [setShortcutsOpen]);
117
+ useSearchKeys({ open: props.searchOpen, slash: props.singleKeys, onOpen: openSearch });
118
+ const waiting = useGoShortcuts({
119
+ targets: props.targets,
120
+ enabled: props.singleKeys,
121
+ navigate,
122
+ onOverview: openShortcuts,
123
+ });
124
+ const settingsLink = props.settingsHref ? (_jsx(Link, { href: props.settingsHref, onClick: () => {
125
+ setShortcutsOpen(false);
126
+ setOpenMobile(false);
127
+ }, className: "text-foreground underline underline-offset-4", children: t("openSettings") })) : null;
128
+ return (_jsxs(_Fragment, { children: [_jsx(SearchDialog, { appName: props.app.name, open: props.searchOpen, onOpenChange: setSearchOpen, pages: props.pages, options: props.search, singleKeys: props.singleKeys, navigate: navigate, onShortcuts: openShortcuts }), _jsx(ShortcutsDialog, { targets: props.targets, enabled: props.singleKeys, open: props.shortcutsOpen, onOpenChange: setShortcutsOpen, settings: settingsLink }), waiting ? _jsx(GoHint, { targets: waiting }) : null] }));
129
+ }
@@ -3,7 +3,7 @@ import { type VariantProps } from "class-variance-authority";
3
3
  import { Button } from "./button.tsx";
4
4
  declare function InputGroup({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
5
5
  declare const inputGroupAddonVariants: (props?: ({
6
- align?: "inline-start" | "inline-end" | "block-start" | "block-end" | null | undefined;
6
+ align?: "inline-end" | "inline-start" | "block-end" | "block-start" | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  declare function InputGroupAddon({ className, align, ...props }: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>): React.JSX.Element;
9
9
  declare const inputGroupButtonVariants: (props?: ({
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+ /** The header of a page: title, optional description, and actions on the right. */
3
+ export declare function PageHeader(props: {
4
+ title: ReactNode;
5
+ description?: ReactNode;
6
+ actions?: ReactNode;
7
+ className?: string;
8
+ }): import("react").JSX.Element;
9
+ /** The content area of a page: centred, at most 80 rem wide unless `wide`. */
10
+ export declare function Page(props: {
11
+ children: ReactNode;
12
+ className?: string;
13
+ wide?: boolean;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from "../lib/utils.js";
3
+ /** The header of a page: title, optional description, and actions on the right. */
4
+ export function PageHeader(props) {
5
+ return (_jsxs("div", { className: cn("flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", props.className), children: [_jsxs("div", { className: "min-w-0 space-y-1", children: [_jsx("h1", { className: "truncate text-2xl font-semibold tracking-tight", children: props.title }), props.description ? _jsx("p", { className: "text-muted-foreground text-sm", children: props.description }) : null] }), props.actions ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: props.actions }) : null] }));
6
+ }
7
+ /** The content area of a page: centred, at most 80 rem wide unless `wide`. */
8
+ export function Page(props) {
9
+ return (_jsx("div", { className: cn("mx-auto flex w-full flex-col gap-6 p-4 md:p-6", props.wide ? "max-w-none" : "max-w-7xl", props.className), children: props.children }));
10
+ }
@@ -0,0 +1,19 @@
1
+ import { type ThemePreference } from "../lib/theme.ts";
2
+ /** "Appearance" for the person's settings page: the same choice as in the user menu. */
3
+ export declare function AppearanceCard(props: {
4
+ value: ThemePreference;
5
+ onChange: (value: ThemePreference) => void;
6
+ }): import("react").JSX.Element;
7
+ /**
8
+ * Turns shortcuts with single letters on and off (WCAG 2.1.4). Without
9
+ * props, the choice is kept in this browser and the frame follows it.
10
+ */
11
+ export declare function KeyboardShortcutsCard(props: {
12
+ enabled?: boolean;
13
+ onEnabledChange?: (enabled: boolean) => void;
14
+ }): import("react").JSX.Element;
15
+ /** "About" for the settings page: the app is part of Meldgrove, with a link to its repository. */
16
+ export declare function AboutCard(props: {
17
+ appName: string;
18
+ repositoryUrl: string;
19
+ }): import("react").JSX.Element;
@@ -0,0 +1,62 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId } from "react";
4
+ import { ArrowUpRight } from "lucide-react";
5
+ import { Button } from "./button.js";
6
+ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "./card.js";
7
+ import { Label } from "./label.js";
8
+ import { RadioGroup, RadioGroupItem } from "./radio-group.js";
9
+ import { Switch } from "./switch.js";
10
+ import { defineMessages, useT } from "../lib/i18n.js";
11
+ import { THEME_PREFERENCES } from "../lib/theme.js";
12
+ import { useShortcutsPreference } from "../frame/shortcuts.js";
13
+ const messages = defineMessages({
14
+ en: {
15
+ appearance: "Appearance",
16
+ appearanceDescription: "Light, dark, or as your device is set.",
17
+ light: "Light",
18
+ dark: "Dark",
19
+ system: "Device setting",
20
+ shortcuts: "Keyboard shortcuts",
21
+ shortcutsDescription: "Ctrl / shows every shortcut. Ctrl K and Ctrl / always work.",
22
+ singleKeys: "Shortcuts with single letters: G then a letter, and /",
23
+ about: "About",
24
+ aboutText: "{app} is part of Meldgrove: open-source apps for nonprofits and small teams.",
25
+ onGitHub: "Meldgrove on GitHub",
26
+ },
27
+ de: {
28
+ appearance: "Darstellung",
29
+ appearanceDescription: "Hell, dunkel oder wie dein Gerät eingestellt ist.",
30
+ light: "Hell",
31
+ dark: "Dunkel",
32
+ system: "Wie das Gerät",
33
+ shortcuts: "Tastenkürzel",
34
+ shortcutsDescription: "Strg / zeigt alle Tastenkürzel. Strg K und Strg / gelten immer.",
35
+ singleKeys: "Tastenkürzel mit einzelnen Buchstaben: G und dann ein Buchstabe, und /",
36
+ about: "Über",
37
+ aboutText: "{app} gehört zu Meldgrove: Open-Source-Apps für gemeinnützige Organisationen und kleine Teams.",
38
+ onGitHub: "Meldgrove auf GitHub",
39
+ },
40
+ });
41
+ /** "Appearance" for the person's settings page: the same choice as in the user menu. */
42
+ export function AppearanceCard(props) {
43
+ const t = useT(messages);
44
+ const id = useId();
45
+ return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("appearance") }), _jsx(CardDescription, { children: t("appearanceDescription") })] }), _jsx(CardContent, { children: _jsx(RadioGroup, { value: props.value, onValueChange: (value) => props.onChange(value), "aria-label": t("appearance"), className: "gap-3", children: THEME_PREFERENCES.map((option) => (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(RadioGroupItem, { value: option, id: `${id}-${option}` }), _jsx(Label, { htmlFor: `${id}-${option}`, className: "font-normal", children: t(option) })] }, option))) }) })] }));
46
+ }
47
+ /**
48
+ * Turns shortcuts with single letters on and off (WCAG 2.1.4). Without
49
+ * props, the choice is kept in this browser and the frame follows it.
50
+ */
51
+ export function KeyboardShortcutsCard(props) {
52
+ const t = useT(messages);
53
+ const id = useId();
54
+ const [saved, setSaved] = useShortcutsPreference();
55
+ const enabled = props.enabled ?? saved;
56
+ return (_jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: t("shortcuts") }), _jsx(CardDescription, { children: t("shortcutsDescription") })] }), _jsxs(CardContent, { className: "flex items-center justify-between gap-4", children: [_jsx(Label, { htmlFor: id, className: "font-normal", children: t("singleKeys") }), _jsx(Switch, { id: id, checked: enabled, onCheckedChange: props.onEnabledChange ?? setSaved })] })] }));
57
+ }
58
+ /** "About" for the settings page: the app is part of Meldgrove, with a link to its repository. */
59
+ export function AboutCard(props) {
60
+ const t = useT(messages);
61
+ return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: t("about") }) }), _jsx(CardContent, { className: "text-muted-foreground text-sm", children: t("aboutText", { app: props.appName }) }), _jsx(CardFooter, { children: _jsx(Button, { variant: "outline", size: "sm", asChild: true, children: _jsxs("a", { href: props.repositoryUrl, target: "_blank", rel: "noreferrer", children: [t("onGitHub"), _jsx(ArrowUpRight, {})] }) }) })] }));
62
+ }
@@ -51,6 +51,9 @@ function SidebarProvider({ defaultOpen = true, open: openProp, onOpenChange: set
51
51
  // Adds a keyboard shortcut to toggle the sidebar.
52
52
  React.useEffect(() => {
53
53
  const handleKeyDown = (event) => {
54
+ // Not in shadcn/ui: a key an editor already handled (Ctrl+B for bold) stays the editor's.
55
+ if (event.defaultPrevented)
56
+ return;
54
57
  if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
55
58
  event.preventDefault();
56
59
  toggleSidebar();
@@ -0,0 +1,23 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * The sign-in page of a Meldgrove app, outside the frame: what the app is
4
+ * for on the left (on wide screens), the sign-in on the right, and the
5
+ * Meldgrove line. The app puts its buttons and messages in `children`.
6
+ */
7
+ export declare function SignInPage(props: {
8
+ app: {
9
+ name: string;
10
+ icon: ReactNode;
11
+ };
12
+ /** What the app is for, in one sentence; the large text on the left. */
13
+ tagline: string;
14
+ /** The organization that runs this installation, if known. */
15
+ organization?: string;
16
+ /** The app's repository, for the "Meldgrove" link. */
17
+ repositoryUrl: string;
18
+ /** Default: "Sign in". */
19
+ title?: ReactNode;
20
+ /** Default: "With the account of <organization>." when it is known. */
21
+ description?: ReactNode;
22
+ children: ReactNode;
23
+ }): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { defineMessages, useT } from "../lib/i18n.js";
4
+ import { PartOfMeldgrove } from "../frame/part-of-meldgrove.js";
5
+ const messages = defineMessages({
6
+ en: {
7
+ signIn: "Sign in",
8
+ withAccount: "With the account of {organization}.",
9
+ forPeople: "For the people of {organization}.",
10
+ },
11
+ de: {
12
+ signIn: "Anmelden",
13
+ withAccount: "Mit dem Konto von {organization}.",
14
+ forPeople: "Für die Menschen bei {organization}.",
15
+ },
16
+ });
17
+ function AppMark(props) {
18
+ return (_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("span", { className: "bg-primary text-primary-foreground flex size-9 items-center justify-center rounded-lg [&_svg]:size-5", children: props.icon }), _jsx("span", { className: "font-semibold", children: props.name })] }));
19
+ }
20
+ /**
21
+ * The sign-in page of a Meldgrove app, outside the frame: what the app is
22
+ * for on the left (on wide screens), the sign-in on the right, and the
23
+ * Meldgrove line. The app puts its buttons and messages in `children`.
24
+ */
25
+ export function SignInPage(props) {
26
+ const t = useT(messages);
27
+ const organization = props.organization;
28
+ const description = props.description ?? (organization ? t("withAccount", { organization }) : undefined);
29
+ const footer = _jsx(PartOfMeldgrove, { appName: props.app.name, repositoryUrl: props.repositoryUrl });
30
+ return (_jsxs("main", { className: "grid min-h-svh lg:grid-cols-2", children: [_jsxs("section", { className: "bg-muted/60 hidden flex-col justify-between p-10 lg:flex", children: [_jsx(AppMark, { name: props.app.name, icon: props.app.icon }), _jsxs("div", { className: "max-w-md space-y-3", children: [_jsx("p", { className: "text-3xl font-semibold tracking-tight", children: props.tagline }), organization ? _jsx("p", { className: "text-muted-foreground", children: t("forPeople", { organization }) }) : null] }), _jsx("p", { className: "text-muted-foreground text-xs", children: footer })] }), _jsxs("section", { className: "flex flex-col items-center justify-center gap-8 p-6", children: [_jsxs("div", { className: "flex w-full max-w-sm flex-col gap-6", children: [_jsx("div", { className: "lg:hidden", children: _jsx(AppMark, { name: props.app.name, icon: props.app.icon }) }), _jsxs("div", { className: "space-y-1", children: [_jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: props.title ?? t("signIn") }), description ? _jsx("p", { className: "text-muted-foreground text-sm", children: description }) : null] }), props.children] }), _jsx("p", { className: "text-muted-foreground max-w-sm text-center text-xs lg:hidden", children: footer })] })] }));
31
+ }
@@ -0,0 +1,5 @@
1
+ /** The Meldgrove line of the sign-in page and the About card. */
2
+ export declare const aboutMessages: import("../lib/i18n-core.ts").Messages<{
3
+ partOf: string;
4
+ newTab: string;
5
+ }>;
@@ -0,0 +1,12 @@
1
+ import { defineMessages } from "../lib/i18n-core.js";
2
+ /** The Meldgrove line of the sign-in page and the About card. */
3
+ export const aboutMessages = defineMessages({
4
+ en: {
5
+ partOf: "{app} is part of {meldgrove}, open-source apps for nonprofits and small teams.",
6
+ newTab: "(GitHub, opens in a new tab)",
7
+ },
8
+ de: {
9
+ partOf: "{app} gehört zu {meldgrove}, Open-Source-Apps für gemeinnützige Organisationen und kleine Teams.",
10
+ newTab: "(GitHub, öffnet in einem neuen Tab)",
11
+ },
12
+ });
@@ -0,0 +1,18 @@
1
+ import type { FrameLink } from "../components/app-frame.tsx";
2
+ /** One step of the path to the current page; the last one is the page itself. */
3
+ export type Crumb = {
4
+ label: string;
5
+ href?: string;
6
+ };
7
+ /** At most three items: deeper paths keep the first step and the last two, with "…" between. */
8
+ export declare function visibleCrumbs(crumbs: Crumb[]): (Crumb | "more")[];
9
+ /**
10
+ * Where the page sits in the app, in the header: short, cut when long (the
11
+ * full label shows on hover), the current page as text. On phones only the
12
+ * way back: "‹ parent".
13
+ */
14
+ export declare function FrameCrumbs(props: {
15
+ crumbs: Crumb[];
16
+ link: FrameLink;
17
+ compact: boolean;
18
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Fragment } from "react";
4
+ import { ChevronLeft } from "lucide-react";
5
+ import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "../components/breadcrumb.js";
6
+ import { Button } from "../components/button.js";
7
+ import { useT } from "../lib/i18n.js";
8
+ import { frameMessages } from "./messages.js";
9
+ /** At most three items: deeper paths keep the first step and the last two, with "…" between. */
10
+ export function visibleCrumbs(crumbs) {
11
+ return crumbs.length > 3 ? [crumbs[0], "more", ...crumbs.slice(-2)] : crumbs;
12
+ }
13
+ /**
14
+ * Where the page sits in the app, in the header: short, cut when long (the
15
+ * full label shows on hover), the current page as text. On phones only the
16
+ * way back: "‹ parent".
17
+ */
18
+ export function FrameCrumbs(props) {
19
+ const t = useT(frameMessages);
20
+ const { crumbs, compact } = props;
21
+ const Link = props.link;
22
+ if (crumbs.length === 0)
23
+ return null;
24
+ const parent = crumbs.length > 1 ? crumbs.at(-2) : undefined;
25
+ if (compact && parent?.href) {
26
+ return (_jsx(Button, { variant: "ghost", size: "sm", asChild: true, className: "text-muted-foreground -ml-2 min-w-0 gap-1 px-2", children: _jsxs(Link, { href: parent.href, "aria-label": t("back", { page: parent.label }), children: [_jsx(ChevronLeft, { "aria-hidden": "true" }), _jsx("span", { className: "truncate", children: parent.label })] }) }));
27
+ }
28
+ const shown = visibleCrumbs(crumbs);
29
+ return (_jsx(Breadcrumb, { "aria-label": t("breadcrumbs"), className: "min-w-0", children: _jsx(BreadcrumbList, { className: "flex-nowrap", children: shown.map((crumb, index) => {
30
+ const last = index === shown.length - 1;
31
+ return (_jsxs(Fragment, { children: [index > 0 ? _jsx(BreadcrumbSeparator, {}) : null, _jsx(BreadcrumbItem, { className: "min-w-0", children: crumb === "more" ? (_jsx(BreadcrumbEllipsis, { className: "size-5" })) : last || !crumb.href ? (_jsx(BreadcrumbPage, { className: "block max-w-64 truncate", title: crumb.label, children: crumb.label })) : (_jsx(BreadcrumbLink, { asChild: true, children: _jsx(Link, { href: crumb.href, className: "block max-w-40 truncate", title: crumb.label, children: crumb.label }) })) })] }, crumb === "more" ? "more" : `${index}-${crumb.label}`));
32
+ }) }) }));
33
+ }