@tristan2828/ui-foundation 4.72.0 → 4.74.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 (34) hide show
  1. package/conventions/docs/add-an-entity.md +38 -14
  2. package/conventions/docs/design-language.md +103 -26
  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 +73 -0
  34. package/styles/theme.css +55 -1
@@ -0,0 +1,201 @@
1
+ import { Plugin, PluginKey, TextSelection } from '@milkdown/kit/prose/state';
2
+ import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
3
+ import { buttonVariants } from '../ui/button.js';
4
+ import { PAGE_ICON_PATHS, pageLinkSignature, pageName } from '../../lib/page-link.js';
5
+ // Every link in the text, as runs of text under one link mark.
6
+ function linkRuns(doc) {
7
+ const runs = [];
8
+ doc.descendants((node, pos) => {
9
+ if (!node.isTextblock)
10
+ return true;
11
+ let run = null;
12
+ node.forEach((child, offset) => {
13
+ const start = pos + 1 + offset;
14
+ const mark = child.marks.find((candidate) => candidate.type.name === 'link');
15
+ if (mark && run && run.mark.eq(mark) && run.to === start) {
16
+ run.to = start + child.nodeSize;
17
+ run.words += child.text ?? '';
18
+ return;
19
+ }
20
+ if (run)
21
+ runs.push(run);
22
+ const href = mark ? String(mark.attrs.href ?? '') : '';
23
+ run = mark && href ? { from: start, to: start + child.nodeSize, mark, href, words: child.text ?? '', parent: node, parentPos: pos } : null;
24
+ });
25
+ if (run)
26
+ runs.push(run);
27
+ return false;
28
+ });
29
+ return runs;
30
+ }
31
+ function pageIcon() {
32
+ const box = document.createElement('span');
33
+ box.setAttribute('aria-hidden', 'true');
34
+ const svgNs = 'http://www.w3.org/2000/svg';
35
+ const svg = document.createElementNS(svgNs, 'svg');
36
+ for (const [name, value] of Object.entries({
37
+ viewBox: '0 0 24 24',
38
+ fill: 'none',
39
+ stroke: 'currentColor',
40
+ 'stroke-width': '2',
41
+ 'stroke-linecap': 'round',
42
+ 'stroke-linejoin': 'round',
43
+ class: 'page-link-icon',
44
+ }))
45
+ svg.setAttribute(name, value);
46
+ for (const d of PAGE_ICON_PATHS) {
47
+ const path = document.createElementNS(svgNs, 'path');
48
+ path.setAttribute('d', d);
49
+ svg.appendChild(path);
50
+ }
51
+ box.appendChild(svg);
52
+ return box;
53
+ }
54
+ const pageLinksKey = new PluginKey('rich-text-page-links');
55
+ function draw(doc, options) {
56
+ const resolve = options.resolve();
57
+ if (!resolve)
58
+ return { decorations: DecorationSet.empty, signature: '' };
59
+ const decorations = [];
60
+ const signature = [];
61
+ for (const run of linkRuns(doc)) {
62
+ const info = resolve(run.href);
63
+ signature.push(`${run.href}:${pageLinkSignature(info)}`);
64
+ if (!info)
65
+ continue;
66
+ const removed = Boolean(info.removed);
67
+ decorations.push(
68
+ // The icon inside the link (its marks), so a click on it is one on the link.
69
+ Decoration.widget(run.from, pageIcon, { side: -1, marks: [run.mark], key: 'page-icon', ignoreSelection: true }), Decoration.inline(run.from, run.to, { class: 'page-link-text', 'data-page-link': '', ...(removed ? { 'data-removed': '' } : {}) }));
70
+ if (run.parent.type.name === 'paragraph' && run.from === run.parentPos + 1 && run.to === run.parentPos + 1 + run.parent.content.size)
71
+ decorations.push(Decoration.node(run.parentPos, run.parentPos + run.parent.nodeSize, { class: 'page-line', 'data-page-line': '' }));
72
+ if (removed) {
73
+ const name = pageName(info, run.words);
74
+ const restorable = Boolean(info.onRestore) && options.editable();
75
+ decorations.push(Decoration.widget(run.to, () => removedNote(info, name, restorable, options), {
76
+ side: 1,
77
+ key: `page-removed:${restorable}:${name}`,
78
+ ignoreSelection: true,
79
+ // The button's own events: ProseMirror leaves them alone.
80
+ stopEvent: () => true,
81
+ }));
82
+ }
83
+ }
84
+ return { decorations: DecorationSet.create(doc, decorations), signature: signature.join('\n') };
85
+ }
86
+ // "Page removed", and Restore when the app gives one.
87
+ function removedNote(info, name, restorable, options) {
88
+ const box = document.createElement('span');
89
+ box.className = 'page-removed';
90
+ box.dataset.slot = 'page-removed';
91
+ const note = document.createElement('span');
92
+ note.className = 'page-removed-note';
93
+ note.textContent = 'Page removed';
94
+ box.appendChild(note);
95
+ if (!restorable)
96
+ return box;
97
+ const button = document.createElement('button');
98
+ button.type = 'button';
99
+ button.className = buttonVariants({ variant: 'outline', size: 'xs' });
100
+ button.dataset.slot = 'page-restore';
101
+ button.setAttribute('aria-label', `Restore ${name}`);
102
+ button.textContent = 'Restore';
103
+ // A press never moves the caret.
104
+ button.addEventListener('mousedown', (event) => event.preventDefault());
105
+ button.addEventListener('click', (event) => {
106
+ event.preventDefault();
107
+ event.stopPropagation();
108
+ button.disabled = true;
109
+ button.textContent = 'Restoring…';
110
+ void options.restore(info, name).then(() => {
111
+ button.disabled = false;
112
+ button.textContent = 'Restore';
113
+ });
114
+ });
115
+ box.appendChild(button);
116
+ return box;
117
+ }
118
+ /** The plugin: the page links' look, drawn again when the text changes or `refreshPageLinks` asks. */
119
+ export function pageLinksPlugin(options) {
120
+ return new Plugin({
121
+ key: pageLinksKey,
122
+ state: {
123
+ init: (_config, state) => draw(state.doc, options),
124
+ apply: (tr, value, _previous, next) => (tr.docChanged || tr.getMeta(pageLinksKey) ? draw(next.doc, options) : value),
125
+ },
126
+ props: {
127
+ decorations: (state) => pageLinksKey.getState(state)?.decorations,
128
+ },
129
+ });
130
+ }
131
+ /**
132
+ * Redraws the page links if what the app answers for them has changed
133
+ * (a title, removed or restored, Restore offered or not, read-only or
134
+ * not). Cheap to call after every render: it dispatches only on a change.
135
+ */
136
+ export function refreshPageLinks(view, resolve, editable) {
137
+ const current = pageLinksKey.getState(view.state);
138
+ if (!current)
139
+ return;
140
+ const signature = resolve
141
+ ? linkRuns(view.state.doc)
142
+ .map((run) => `${run.href}:${pageLinkSignature(resolve(run.href))}`)
143
+ .join('\n')
144
+ : '';
145
+ const key = `${editable}|${signature}`;
146
+ if (key === refreshed.get(view))
147
+ return;
148
+ refreshed.set(view, key);
149
+ view.dispatch(view.state.tr.setMeta(pageLinksKey, true).setMeta('addToHistory', false));
150
+ }
151
+ const refreshed = new WeakMap();
152
+ /** What the app says of the page a link points to, if it's one. */
153
+ export function pageLinkInfo(resolve, href) {
154
+ return resolve?.(href) ?? null;
155
+ }
156
+ const pendingKey = new PluginKey('rich-text-pending-page');
157
+ /** Keeps the span a page being made will replace in step with edits made meanwhile. */
158
+ export function pendingPagePlugin() {
159
+ return new Plugin({
160
+ key: pendingKey,
161
+ state: {
162
+ init: () => null,
163
+ apply: (tr, value) => {
164
+ const meta = tr.getMeta(pendingKey);
165
+ if (meta !== undefined)
166
+ return meta;
167
+ if (!value)
168
+ return null;
169
+ const from = tr.mapping.map(value.from, 1);
170
+ const to = Math.max(from, tr.mapping.map(value.to, -1));
171
+ return { from, to };
172
+ },
173
+ },
174
+ });
175
+ }
176
+ /** Marks (or, with null, forgets) the span the page being made will go in. */
177
+ export function setPendingPage(tr, span) {
178
+ return tr.setMeta(pendingKey, span);
179
+ }
180
+ /** The span the page being made will go in, if one is. */
181
+ export function pendingPage(state) {
182
+ return pendingKey.getState(state) ?? null;
183
+ }
184
+ /**
185
+ * Puts the new page's link in its span: the title as the link's words,
186
+ * linked to `href`, in one transaction (one undo step). The caret goes
187
+ * after it, and what's typed next isn't part of the link. False when
188
+ * there's no span any more.
189
+ */
190
+ export function insertPageLink(view, title, href) {
191
+ const span = pendingPage(view.state);
192
+ if (!span || span.to > view.state.doc.content.size)
193
+ return false;
194
+ const { schema } = view.state;
195
+ const link = schema.marks.link.create({ href });
196
+ const tr = setPendingPage(view.state.tr.replaceWith(span.from, span.to, schema.text(title, [link])), null);
197
+ tr.setSelection(TextSelection.create(tr.doc, span.from + title.length));
198
+ tr.removeStoredMark(schema.marks.link);
199
+ view.dispatch(tr.scrollIntoView());
200
+ return true;
201
+ }
@@ -1,6 +1,5 @@
1
1
  import type { EditorView } from '@milkdown/kit/prose/view';
2
- import type { FormatItem } from './rich-text-format-items.js';
3
- import type { FormatId } from './rich-text-formats.js';
2
+ import { type SlashItem } from './rich-text-slash.js';
4
3
  export interface RichTextSlashMenuProps {
5
4
  /** The list's id, for the text's `aria-controls`. */
6
5
  id: string;
@@ -9,10 +8,10 @@ export interface RichTextSlashMenuProps {
9
8
  at: number;
10
9
  /** The field's element it's placed against (positioned: `relative`). */
11
10
  field: HTMLElement | null;
12
- items: FormatItem[];
11
+ items: SlashItem[];
13
12
  /** The highlighted item: Enter picks it. */
14
13
  active: number;
15
14
  onHighlight: (index: number) => void;
16
- onPick: (id: FormatId) => void;
15
+ onPick: (id: SlashItem['id']) => void;
17
16
  }
18
17
  export declare function RichTextSlashMenu({ id, view, at, field, items, active, onHighlight, onPick }: RichTextSlashMenuProps): import("react").JSX.Element;
@@ -14,14 +14,23 @@ export type SlashQuery = {
14
14
  };
15
15
  /** The open menu's span and query, or null when it's closed. */
16
16
  export declare function slashQuery(state: EditorState): SlashQuery | null;
17
- /** The transaction that closes the menu, leaving what was typed as text (Esc). */
17
+ /** The transaction that closes the menu, leaving what was typed as text (Esc, or the page's title box opening). */
18
18
  export declare function closeSlash(state: EditorState): Transaction;
19
19
  /** The id of the menu's item at `index`, for the text's `aria-activedescendant`. */
20
20
  export declare function slashOptionId(listId: string, index: number): string;
21
21
  /** The plugin: opens on a typed "/", follows the text, closes once the span stops qualifying. */
22
22
  export declare function slashPlugin(): Plugin<SlashState>;
23
- /** The blocks matching what's typed after the "/": in the name, or the start of a keyword. */
24
- export declare function slashItems(query: string): FormatItem[];
23
+ /** A slash menu item: a block, or the new page (only with the app's `onCreatePage`). */
24
+ export type SlashItem = Omit<FormatItem, 'id'> & {
25
+ id: FormatId | 'page';
26
+ };
27
+ /**
28
+ * The blocks matching what's typed after the "/": in the name, or the
29
+ * start of a keyword. With `page`, the new page too.
30
+ */
31
+ export declare function slashItems(query: string, options?: {
32
+ page?: boolean;
33
+ }): SlashItem[];
25
34
  /**
26
35
  * Picks an item: the "/…" goes and the paragraph becomes that block, in one
27
36
  * transaction (one undo step, which brings the "/…" back).
@@ -8,6 +8,7 @@
8
8
  // `/usr/bin`) never does, and neither does a "/" mid-line or inside a
9
9
  // list, a quote or a code block.
10
10
  import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
11
+ import { FileTextIcon } from 'lucide-react';
11
12
  import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
12
13
  import { toggleFormat } from './rich-text-formats.js';
13
14
  const slashKey = new PluginKey('rich-text-slash');
@@ -43,7 +44,7 @@ export function slashQuery(state) {
43
44
  const open = slashKey.getState(state);
44
45
  return open ? queryAt(state, open.from) : null;
45
46
  }
46
- /** The transaction that closes the menu, leaving what was typed as text (Esc). */
47
+ /** The transaction that closes the menu, leaving what was typed as text (Esc, or the page's title box opening). */
47
48
  export function closeSlash(state) {
48
49
  return state.tr.setMeta(slashKey, 'close');
49
50
  }
@@ -108,15 +109,25 @@ const KEYWORDS = {
108
109
  // once something's typed ("/warn"), so the list "/" opens with stays short.
109
110
  const BLOCKS = FORMAT_GROUPS.flat().filter((item) => KEYWORDS[item.id]);
110
111
  BLOCKS.splice(BLOCKS.findIndex((item) => item.id === 'heading3') + 1, 0, ...TOGGLE_HEADING_VARIANTS);
111
- /** The blocks matching what's typed after the "/": in the name, or the start of a keyword. */
112
- export function slashItems(query) {
112
+ // A page of its own, linked from here (src/lib/page-link.ts): last, since
113
+ // it's the only item that leaves the editor (a title box, then the app).
114
+ const PAGE_ITEM = { id: 'page', label: 'Page', icon: FileTextIcon };
115
+ const PAGE_KEYWORDS = ['page', 'subpage', 'child', 'link', 'new'];
116
+ /**
117
+ * The blocks matching what's typed after the "/": in the name, or the
118
+ * start of a keyword. With `page`, the new page too.
119
+ */
120
+ export function slashItems(query, options = {}) {
113
121
  const typed = query.trim().toLowerCase();
122
+ const page = options.page && (!typed || 'page'.includes(typed) || PAGE_KEYWORDS.some((word) => word.startsWith(typed))) ? [PAGE_ITEM] : [];
114
123
  if (!typed)
115
- return BLOCKS;
124
+ return [...BLOCKS, ...page];
116
125
  const blocks = [...BLOCKS];
117
126
  blocks.splice(BLOCKS.findIndex((item) => item.id === 'callout') + 1, 0, ...CALLOUT_VARIANTS);
118
127
  blocks.push(...HIGHLIGHT_VARIANTS);
119
- return blocks.filter((item) => item.label.toLowerCase().includes(typed) || KEYWORDS[item.id].some((word) => word.startsWith(typed)));
128
+ const matches = blocks.filter((item) => item.label.toLowerCase().includes(typed) || KEYWORDS[item.id].some((word) => word.startsWith(typed)));
129
+ // "/page" puts the page first: it's what was asked for by name.
130
+ return typed.length >= 2 && 'page'.startsWith(typed) ? [...page, ...matches] : [...matches, ...page];
120
131
  }
121
132
  /**
122
133
  * Picks an item: the "/…" goes and the paragraph becomes that block, in one
@@ -15,6 +15,8 @@ export type FormatButtonsProps = {
15
15
  readOnly: boolean;
16
16
  /** A button pressed: run the format on the editor and give it focus back. */
17
17
  onFormat: (id: FormatId) => void;
18
+ /** The Page button pressed: the selected words become a new page's link. No button without it. */
19
+ onPage?: () => void;
18
20
  /** The Image button pressed: pick images to upload. No button without it. */
19
21
  onImage?: () => void;
20
22
  /** The Full screen button pressed. No button without it. */
@@ -24,7 +26,7 @@ export type FormatButtonsProps = {
24
26
  /** The editable element, for the Highlight menu to give focus back to. */
25
27
  text?: () => HTMLElement | null;
26
28
  };
27
- export declare function FormatButtons({ formats, state, readOnly, onFormat, onImage, onFullScreen, fullScreen, text }: FormatButtonsProps): import("react").JSX.Element;
29
+ export declare function FormatButtons({ formats, state, readOnly, onFormat, onPage, onImage, onFullScreen, fullScreen, text }: FormatButtonsProps): import("react").JSX.Element;
28
30
  export interface RichTextToolbarProps {
29
31
  /** The editor's state now, to show which formats are on. Null until it's made. */
30
32
  state: EditorState | null;
@@ -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.74.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
@@ -79,6 +79,16 @@
79
79
  --color-category-10: var(--category-10);
80
80
  --color-category-11: var(--category-11);
81
81
  --color-category-12: var(--category-12);
82
+ --color-heat-1: var(--heat-1);
83
+ --color-heat-1-foreground: var(--heat-1-foreground);
84
+ --color-heat-2: var(--heat-2);
85
+ --color-heat-2-foreground: var(--heat-2-foreground);
86
+ --color-heat-3: var(--heat-3);
87
+ --color-heat-3-foreground: var(--heat-3-foreground);
88
+ --color-heat-4: var(--heat-4);
89
+ --color-heat-4-foreground: var(--heat-4-foreground);
90
+ --color-heat-5: var(--heat-5);
91
+ --color-heat-5-foreground: var(--heat-5-foreground);
82
92
  --color-accent-foreground: var(--accent-foreground);
83
93
  --color-accent: var(--accent);
84
94
  --color-muted-foreground: var(--muted-foreground);
@@ -395,3 +405,66 @@
395
405
  padding-bottom: 0;
396
406
  }
397
407
  }
408
+
409
+ /* Page links in written text (<Markdown> and the rich-text editor): a
410
+ link the app marks as one of its pages (`pageLink`,
411
+ src/lib/page-link.ts). The page icon, then the title in the text's own
412
+ colour, medium weight, still underlined (so it's told from the words
413
+ around it without colour: axe's link-in-text-block). A paragraph that
414
+ holds only one is a page line, a row that tints on hover. A removed
415
+ page is muted and struck through, "Page removed" beside it. <Markdown>
416
+ draws `.page-link` itself; in the editor the link is Milkdown's <a>,
417
+ its words wrapped in a `.page-link-text` decoration. Unlayered, so the
418
+ editor's utility classes on every <a> don't outrank it. */
419
+ .page-link,
420
+ .ProseMirror a:has(> .page-link-text) {
421
+ color: var(--foreground);
422
+ font-weight: 500;
423
+ text-decoration-line: underline;
424
+ text-decoration-color: var(--muted-foreground);
425
+ text-underline-offset: 4px;
426
+ }
427
+ .page-link:hover,
428
+ .ProseMirror a:has(> .page-link-text):hover {
429
+ text-decoration-color: currentColor;
430
+ }
431
+ .page-link-icon {
432
+ display: inline-block;
433
+ width: 1rem;
434
+ height: 1rem;
435
+ margin-right: 0.25rem;
436
+ vertical-align: -0.1875rem;
437
+ color: var(--muted-foreground);
438
+ }
439
+ .page-line {
440
+ margin-inline: -0.375rem;
441
+ padding: 0.125rem 0.375rem;
442
+ border-radius: calc(var(--radius) - 2px);
443
+ }
444
+ .page-line:hover {
445
+ background-color: var(--muted);
446
+ }
447
+ .page-link-removed,
448
+ .ProseMirror a:has(> .page-link-text[data-removed]) {
449
+ color: var(--muted-foreground);
450
+ text-decoration-line: none;
451
+ }
452
+ .page-link-removed .page-link-title,
453
+ .page-link-text[data-removed] {
454
+ text-decoration-line: line-through;
455
+ }
456
+ .page-removed-note {
457
+ margin-inline: 0.5rem;
458
+ color: var(--muted-foreground);
459
+ font-size: 0.75rem;
460
+ }
461
+ .page-removed {
462
+ display: inline-flex;
463
+ align-items: center;
464
+ gap: 0.5rem;
465
+ margin-inline-start: 0.5rem;
466
+ vertical-align: middle;
467
+ }
468
+ .page-removed .page-removed-note {
469
+ margin-inline: 0;
470
+ }