@tristan2828/ui-foundation 4.72.0 → 4.73.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.
Files changed (33) hide show
  1. package/conventions/docs/add-an-entity.md +38 -14
  2. package/conventions/docs/design-language.md +27 -15
  3. package/dist/components/app/markdown.d.ts +13 -1
  4. package/dist/components/app/markdown.js +43 -8
  5. package/dist/components/app/milkdown-editor.d.ts +1 -1
  6. package/dist/components/app/milkdown-editor.js +184 -19
  7. package/dist/components/app/page-link.d.ts +13 -0
  8. package/dist/components/app/page-link.js +44 -0
  9. package/dist/components/app/page-restore.d.ts +3 -0
  10. package/dist/components/app/page-restore.js +14 -0
  11. package/dist/components/app/page-trail.d.ts +17 -0
  12. package/dist/components/app/page-trail.js +71 -0
  13. package/dist/components/app/rich-text-editor.d.ts +22 -0
  14. package/dist/components/app/rich-text-editor.js +8 -0
  15. package/dist/components/app/rich-text-floating-toolbar.d.ts +3 -1
  16. package/dist/components/app/rich-text-floating-toolbar.js +2 -2
  17. package/dist/components/app/rich-text-page-links.d.ts +44 -0
  18. package/dist/components/app/rich-text-page-links.js +201 -0
  19. package/dist/components/app/rich-text-slash-menu.d.ts +3 -4
  20. package/dist/components/app/rich-text-slash.d.ts +12 -3
  21. package/dist/components/app/rich-text-slash.js +16 -5
  22. package/dist/components/app/rich-text-toolbar.d.ts +3 -1
  23. package/dist/components/app/rich-text-toolbar.js +10 -7
  24. package/dist/components/ui/breadcrumb.d.ts +10 -0
  25. package/dist/components/ui/breadcrumb.js +37 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +1 -0
  28. package/dist/lib/page-link.d.ts +40 -0
  29. package/dist/lib/page-link.js +32 -0
  30. package/dist/lib/page-trail.d.ts +7 -0
  31. package/dist/lib/page-trail.js +24 -0
  32. package/package.json +1 -1
  33. package/styles/index.css +63 -0
@@ -16,7 +16,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
16
16
  // - Alt+F10 in the text reaches it (the floating toolbar first, when it's
17
17
  // showing: rich-text-floating-toolbar.tsx).
18
18
  import { Fragment, useEffect, useRef, useState } from 'react';
19
- import { ImageIcon, Maximize2Icon, Minimize2Icon } from 'lucide-react';
19
+ import { FileTextIcon, ImageIcon, Maximize2Icon, Minimize2Icon } from 'lucide-react';
20
20
  import { Button } from '../ui/button.js';
21
21
  import { Separator } from '../ui/separator.js';
22
22
  import { Toggle } from '../ui/toggle.js';
@@ -51,15 +51,16 @@ function useCompact() {
51
51
  // A toolbar's row of buttons: one tab stop, the last one used (ARIA's
52
52
  // toolbar pattern); the arrow keys, Home and End move along the row. The
53
53
  // toolbar's element (`role="toolbar"`, its name) is the caller's.
54
- export function FormatButtons({ formats, state, readOnly, onFormat, onImage, onFullScreen, fullScreen = false, text = () => null }) {
54
+ export function FormatButtons({ formats, state, readOnly, onFormat, onPage, onImage, onFullScreen, fullScreen = false, text = () => null }) {
55
55
  const apple = isApple();
56
56
  const compact = useCompact();
57
57
  const groups = SETS[formats].map((group) => group.filter((item) => compact || !item.touch)).filter((group) => group.length > 0);
58
58
  const items = groups.flat();
59
- // The Image and Full screen buttons, last in the row, after the formats.
60
- const imageIndex = onImage ? items.length : -1;
61
- const fullScreenIndex = onFullScreen ? items.length + (onImage ? 1 : 0) : -1;
62
- const count = items.length + (onImage ? 1 : 0) + (onFullScreen ? 1 : 0);
59
+ // The Page, Image and Full screen buttons, last in the row, after the formats.
60
+ const pageIndex = onPage ? items.length : -1;
61
+ const imageIndex = onImage ? items.length + (onPage ? 1 : 0) : -1;
62
+ const fullScreenIndex = onFullScreen ? items.length + (onPage ? 1 : 0) + (onImage ? 1 : 0) : -1;
63
+ const count = items.length + (onPage ? 1 : 0) + (onImage ? 1 : 0) + (onFullScreen ? 1 : 0);
63
64
  const buttons = useRef([]);
64
65
  // The one button Tab reaches: the last one used.
65
66
  const [current, setCurrent] = useState(0);
@@ -106,7 +107,9 @@ export function FormatButtons({ formats, state, readOnly, onFormat, onImage, onF
106
107
  }, size: "icon-sm", "aria-label": item.label, "aria-keyshortcuts": item.keys ? ariaKeys(item.keys, apple) : undefined, pressed: state ? formatOn(state, item.id) : false, disabled: readOnly, tabIndex: index === current ? 0 : -1, className: "aria-pressed:bg-muted aria-pressed:text-foreground",
107
108
  // A mouse press keeps focus, and the selection, in the text.
108
109
  onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(index), onKeyDown: onKeyDown, onPressedChange: () => onFormat(item.id) }), children: _jsx(Icon, {}) }), _jsx(TooltipContent, { children: tip })] }, item.id));
109
- })] }, groupIndex))), onImage && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
110
+ })] }, groupIndex))), onPage && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
111
+ buttons.current[pageIndex] = element;
112
+ }, variant: "ghost", size: "icon-sm", "aria-label": "Turn into page", disabled: readOnly, tabIndex: pageIndex === current ? 0 : -1, onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(pageIndex), onKeyDown: onKeyDown, onClick: onPage }), children: _jsx(FileTextIcon, {}) }), _jsx(TooltipContent, { children: "Turn into page \u00B7 a new page named for the words, linked here" })] })] })), onImage && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
110
113
  buttons.current[imageIndex] = element;
111
114
  }, variant: "ghost", size: "icon-sm", "aria-label": "Image", disabled: readOnly, tabIndex: imageIndex === current ? 0 : -1, onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(imageIndex), onKeyDown: onKeyDown, onClick: onImage }), children: _jsx(ImageIcon, {}) }), _jsx(TooltipContent, { children: "Image \u00B7 or paste or drop one" })] })] })), onFullScreen && (_jsxs(_Fragment, { children: [_jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Toggle, { ref: (element) => {
112
115
  buttons.current[fullScreenIndex] = element;
@@ -0,0 +1,10 @@
1
+ import * as React from "react";
2
+ import { useRender } from "@base-ui/react/use-render";
3
+ declare function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">): React.JSX.Element;
4
+ declare function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">): React.JSX.Element;
5
+ declare function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">): React.JSX.Element;
6
+ declare function BreadcrumbLink({ className, render, ...props }: useRender.ComponentProps<"a">): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
7
+ declare function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
8
+ declare function BreadcrumbSeparator({ children, className, ...props }: React.ComponentProps<"li">): React.JSX.Element;
9
+ declare function BreadcrumbEllipsis({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
10
+ export { Breadcrumb, BreadcrumbList, BreadcrumbItem, BreadcrumbLink, BreadcrumbPage, BreadcrumbSeparator, BreadcrumbEllipsis, };
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { mergeProps } from "@base-ui/react/merge-props";
4
+ import { useRender } from "@base-ui/react/use-render";
5
+ import { cn } from "cn";
6
+ import { ChevronRightIcon, MoreHorizontalIcon } from "lucide-react";
7
+ function Breadcrumb({ className, ...props }) {
8
+ return (_jsx("nav", { "aria-label": "breadcrumb", "data-slot": "breadcrumb", className: cn(className), ...props }));
9
+ }
10
+ function BreadcrumbList({ className, ...props }) {
11
+ return (_jsx("ol", { "data-slot": "breadcrumb-list", className: cn("flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground", className), ...props }));
12
+ }
13
+ function BreadcrumbItem({ className, ...props }) {
14
+ return (_jsx("li", { "data-slot": "breadcrumb-item", className: cn("inline-flex items-center gap-1", className), ...props }));
15
+ }
16
+ function BreadcrumbLink({ className, render, ...props }) {
17
+ return useRender({
18
+ defaultTagName: "a",
19
+ props: mergeProps({
20
+ className: cn("transition-colors hover:text-foreground", className),
21
+ }, props),
22
+ render,
23
+ state: {
24
+ slot: "breadcrumb-link",
25
+ },
26
+ });
27
+ }
28
+ function BreadcrumbPage({ className, ...props }) {
29
+ return (_jsx("span", { "data-slot": "breadcrumb-page", role: "link", "aria-disabled": "true", "aria-current": "page", className: cn("font-normal text-foreground", className), ...props }));
30
+ }
31
+ function BreadcrumbSeparator({ children, className, ...props }) {
32
+ return (_jsx("li", { "data-slot": "breadcrumb-separator", role: "presentation", "aria-hidden": "true", className: cn("[&>svg]:size-3.5", className), ...props, children: children ?? (_jsx(ChevronRightIcon, {})) }));
33
+ }
34
+ function BreadcrumbEllipsis({ className, ...props }) {
35
+ return (_jsxs("span", { "data-slot": "breadcrumb-ellipsis", role: "presentation", "aria-hidden": "true", className: cn("flex size-5 items-center justify-center [&>svg]:size-4", className), ...props, children: [_jsx(MoreHorizontalIcon, {}), _jsx("span", { className: "sr-only", children: "More" })] }));
36
+ }
37
+ export { Breadcrumb, BreadcrumbList, BreadcrumbItem, BreadcrumbLink, BreadcrumbPage, BreadcrumbSeparator, BreadcrumbEllipsis, };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,8 @@ export { ErrorState } from './components/app/error-state.js';
27
27
  export { InlineCreate, type InlineCreateProps } from './components/app/inline-create.js';
28
28
  export { FoundationProviders } from './components/app/foundation-providers.js';
29
29
  export { Markdown, type MarkdownProps } from './components/app/markdown.js';
30
+ export { PageTrail, type PageCrumb, type PageTrailProps } from './components/app/page-trail.js';
31
+ export type { CreatePage, PageLinkInfo, PageLinkResolver } from './lib/page-link.js';
30
32
  export { countTasks, toggleTaskAt, type TaskCount } from './lib/markdown-tasks.js';
31
33
  export { NotesOutline, type NotesOutlineProps } from './components/app/notes-outline.js';
32
34
  export type { HeadingFrom, HeadingLevel, TableLook } from './components/app/prose-look.js';
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ export { ErrorState } from './components/app/error-state.js';
31
31
  export { InlineCreate } from './components/app/inline-create.js';
32
32
  export { FoundationProviders } from './components/app/foundation-providers.js';
33
33
  export { Markdown } from './components/app/markdown.js';
34
+ export { PageTrail } from './components/app/page-trail.js';
34
35
  export { countTasks, toggleTaskAt } from './lib/markdown-tasks.js';
35
36
  export { NotesOutline } from './components/app/notes-outline.js';
36
37
  export { MockModeBanner } from './components/app/mock-mode-banner.js';
@@ -0,0 +1,40 @@
1
+ /** What the app knows about a page a link points to. */
2
+ export type PageLinkInfo = {
3
+ /**
4
+ * The page's title now, shown in place of the link's own words where
5
+ * the text is read (`<Markdown>`), so a renamed page reads as renamed.
6
+ * The editor shows the words as written, since they're what's saved.
7
+ */
8
+ title?: string;
9
+ /** The page is gone (deleted, in the app's bin): drawn as "Page removed". */
10
+ removed?: boolean;
11
+ /**
12
+ * Brings a removed page back: a Restore button beside "Page removed".
13
+ * Return the request's promise: while it's pending the button waits,
14
+ * and a rejection is shown as a toast in the gateway's words.
15
+ */
16
+ onRestore?: () => void | Promise<unknown>;
17
+ };
18
+ /**
19
+ * Says whether a link's address is one of the app's pages, and what it
20
+ * knows about it; `null` (or `undefined`) for any other link, which stays
21
+ * an ordinary link.
22
+ */
23
+ export type PageLinkResolver = (href: string) => PageLinkInfo | null | undefined;
24
+ /**
25
+ * Makes a page with this title, wherever the app keeps them (under the
26
+ * record or page whose note this is), and resolves to its address, which
27
+ * goes into the note as `[title](href)`. A rejection leaves the note as it
28
+ * was and shows why.
29
+ */
30
+ export type CreatePage = (title: string) => Promise<string>;
31
+ /**
32
+ * The page icon's shape (lucide's `file-text`, 24×24, stroked): drawn as
33
+ * the React icon in <Markdown> and as plain SVG in the editor's widget,
34
+ * so the two match.
35
+ */
36
+ export declare const PAGE_ICON_PATHS: readonly ["M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z", "M14 2v5a1 1 0 0 0 1 1h5", "M10 9H8", "M16 13H8", "M16 17H8"];
37
+ /** A page's name for buttons and screen readers: its title, else the link's words, else "Untitled". */
38
+ export declare function pageName(info: PageLinkInfo, words: string): string;
39
+ /** What the page-link look depends on, to tell when it must be drawn again. */
40
+ export declare function pageLinkSignature(info: PageLinkInfo | null | undefined): string;
@@ -0,0 +1,32 @@
1
+ // Page links: a link in a note that the app says is one of its own pages
2
+ // (a child page of a record, or of another page, to any depth). The
3
+ // package never knows where pages live or how they nest: the app answers
4
+ // `pageLink(href)` for each link's address, and only it can make one
5
+ // (`onCreatePage`). The Markdown is never changed by any of this: a page
6
+ // link is an ordinary Markdown link, `[Getting Started](/notes/12/pages/3)`.
7
+ //
8
+ // Drawn by <Markdown> (markdown.tsx) and the rich-text editor
9
+ // (rich-text-page-links.ts), in the same look (styles/index.css "Page
10
+ // links in written text").
11
+ /**
12
+ * The page icon's shape (lucide's `file-text`, 24×24, stroked): drawn as
13
+ * the React icon in <Markdown> and as plain SVG in the editor's widget,
14
+ * so the two match.
15
+ */
16
+ export const PAGE_ICON_PATHS = [
17
+ 'M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z',
18
+ 'M14 2v5a1 1 0 0 0 1 1h5',
19
+ 'M10 9H8',
20
+ 'M16 13H8',
21
+ 'M16 17H8',
22
+ ];
23
+ /** A page's name for buttons and screen readers: its title, else the link's words, else "Untitled". */
24
+ export function pageName(info, words) {
25
+ return info.title?.trim() || words.trim() || 'Untitled';
26
+ }
27
+ /** What the page-link look depends on, to tell when it must be drawn again. */
28
+ export function pageLinkSignature(info) {
29
+ if (!info)
30
+ return '-';
31
+ return JSON.stringify([info.title ?? null, Boolean(info.removed), Boolean(info.onRestore)]);
32
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * How many crumbs after the first to fold into the "…" menu so the trail
3
+ * fits `available`: 0 when it all fits, at most all but the first and the
4
+ * last. `widths` are each crumb's, `separator` the gap a separator takes
5
+ * (with its spacing), `ellipsis` the menu button's.
6
+ */
7
+ export declare function crumbsToFold(widths: readonly number[], separator: number, ellipsis: number, available: number): number;
@@ -0,0 +1,24 @@
1
+ // PageTrail's fitting (src/components/app/page-trail.tsx): how many
2
+ // crumbs fold into its "…" menu so the trail fits on one line.
3
+ /**
4
+ * How many crumbs after the first to fold into the "…" menu so the trail
5
+ * fits `available`: 0 when it all fits, at most all but the first and the
6
+ * last. `widths` are each crumb's, `separator` the gap a separator takes
7
+ * (with its spacing), `ellipsis` the menu button's.
8
+ */
9
+ export function crumbsToFold(widths, separator, ellipsis, available) {
10
+ const count = widths.length;
11
+ if (count <= 2)
12
+ return 0;
13
+ const sum = (from) => widths.slice(from).reduce((total, width) => total + width, 0);
14
+ if (sum(0) + separator * (count - 1) <= available)
15
+ return 0;
16
+ for (let folded = 1; folded < count - 1; folded++) {
17
+ // The first, the menu, then every crumb after the folded ones.
18
+ const shown = count - 1 - folded;
19
+ const width = widths[0] + ellipsis + sum(folded + 1) + separator * (shown + 1);
20
+ if (width <= available)
21
+ return folded;
22
+ }
23
+ return count - 2;
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.72.0",
3
+ "version": "4.73.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/styles/index.css CHANGED
@@ -395,3 +395,66 @@
395
395
  padding-bottom: 0;
396
396
  }
397
397
  }
398
+
399
+ /* Page links in written text (<Markdown> and the rich-text editor): a
400
+ link the app marks as one of its pages (`pageLink`,
401
+ src/lib/page-link.ts). The page icon, then the title in the text's own
402
+ colour, medium weight, still underlined (so it's told from the words
403
+ around it without colour: axe's link-in-text-block). A paragraph that
404
+ holds only one is a page line, a row that tints on hover. A removed
405
+ page is muted and struck through, "Page removed" beside it. <Markdown>
406
+ draws `.page-link` itself; in the editor the link is Milkdown's <a>,
407
+ its words wrapped in a `.page-link-text` decoration. Unlayered, so the
408
+ editor's utility classes on every <a> don't outrank it. */
409
+ .page-link,
410
+ .ProseMirror a:has(> .page-link-text) {
411
+ color: var(--foreground);
412
+ font-weight: 500;
413
+ text-decoration-line: underline;
414
+ text-decoration-color: var(--muted-foreground);
415
+ text-underline-offset: 4px;
416
+ }
417
+ .page-link:hover,
418
+ .ProseMirror a:has(> .page-link-text):hover {
419
+ text-decoration-color: currentColor;
420
+ }
421
+ .page-link-icon {
422
+ display: inline-block;
423
+ width: 1rem;
424
+ height: 1rem;
425
+ margin-right: 0.25rem;
426
+ vertical-align: -0.1875rem;
427
+ color: var(--muted-foreground);
428
+ }
429
+ .page-line {
430
+ margin-inline: -0.375rem;
431
+ padding: 0.125rem 0.375rem;
432
+ border-radius: calc(var(--radius) - 2px);
433
+ }
434
+ .page-line:hover {
435
+ background-color: var(--muted);
436
+ }
437
+ .page-link-removed,
438
+ .ProseMirror a:has(> .page-link-text[data-removed]) {
439
+ color: var(--muted-foreground);
440
+ text-decoration-line: none;
441
+ }
442
+ .page-link-removed .page-link-title,
443
+ .page-link-text[data-removed] {
444
+ text-decoration-line: line-through;
445
+ }
446
+ .page-removed-note {
447
+ margin-inline: 0.5rem;
448
+ color: var(--muted-foreground);
449
+ font-size: 0.75rem;
450
+ }
451
+ .page-removed {
452
+ display: inline-flex;
453
+ align-items: center;
454
+ gap: 0.5rem;
455
+ margin-inline-start: 0.5rem;
456
+ vertical-align: middle;
457
+ }
458
+ .page-removed .page-removed-note {
459
+ margin-inline: 0;
460
+ }