@tristan2828/ui-foundation 4.71.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 (50) hide show
  1. package/conventions/docs/add-an-entity.md +45 -15
  2. package/conventions/docs/cell-patterns.md +210 -37
  3. package/conventions/docs/design-language.md +64 -24
  4. package/dist/components/app/edit-in-place-controls.d.ts +34 -0
  5. package/dist/components/app/edit-in-place-controls.js +92 -0
  6. package/dist/components/app/edit-in-place-presets.d.ts +187 -0
  7. package/dist/components/app/edit-in-place-presets.js +409 -0
  8. package/dist/components/app/edit-in-place-store.d.ts +9 -0
  9. package/dist/components/app/edit-in-place-store.js +14 -7
  10. package/dist/components/app/edit-in-place.d.ts +101 -4
  11. package/dist/components/app/editable-list.js +158 -23
  12. package/dist/components/app/editable-value.d.ts +2 -2
  13. package/dist/components/app/editable-value.js +7 -3
  14. package/dist/components/app/entity-view.d.ts +6 -2
  15. package/dist/components/app/entity-view.js +11 -2
  16. package/dist/components/app/markdown.d.ts +13 -1
  17. package/dist/components/app/markdown.js +43 -8
  18. package/dist/components/app/milkdown-editor.d.ts +1 -1
  19. package/dist/components/app/milkdown-editor.js +184 -19
  20. package/dist/components/app/page-link.d.ts +13 -0
  21. package/dist/components/app/page-link.js +44 -0
  22. package/dist/components/app/page-restore.d.ts +3 -0
  23. package/dist/components/app/page-restore.js +14 -0
  24. package/dist/components/app/page-trail.d.ts +17 -0
  25. package/dist/components/app/page-trail.js +71 -0
  26. package/dist/components/app/rich-text-editor.d.ts +22 -0
  27. package/dist/components/app/rich-text-editor.js +8 -0
  28. package/dist/components/app/rich-text-floating-toolbar.d.ts +3 -1
  29. package/dist/components/app/rich-text-floating-toolbar.js +2 -2
  30. package/dist/components/app/rich-text-page-links.d.ts +44 -0
  31. package/dist/components/app/rich-text-page-links.js +201 -0
  32. package/dist/components/app/rich-text-slash-menu.d.ts +3 -4
  33. package/dist/components/app/rich-text-slash.d.ts +12 -3
  34. package/dist/components/app/rich-text-slash.js +16 -5
  35. package/dist/components/app/rich-text-toolbar.d.ts +3 -1
  36. package/dist/components/app/rich-text-toolbar.js +10 -7
  37. package/dist/components/app/row-edit-cells.d.ts +9 -0
  38. package/dist/components/app/row-edit-cells.js +12 -16
  39. package/dist/components/ui/breadcrumb.d.ts +10 -0
  40. package/dist/components/ui/breadcrumb.js +37 -0
  41. package/dist/index.d.ts +5 -1
  42. package/dist/index.js +4 -1
  43. package/dist/lib/link-href.d.ts +28 -0
  44. package/dist/lib/link-href.js +40 -0
  45. package/dist/lib/page-link.d.ts +40 -0
  46. package/dist/lib/page-link.js +32 -0
  47. package/dist/lib/page-trail.d.ts +7 -0
  48. package/dist/lib/page-trail.js +24 -0
  49. package/package.json +1 -1
  50. package/styles/index.css +63 -0
@@ -1,4 +1,5 @@
1
1
  import type { ImageUpload } from '../../lib/image-file.js';
2
+ import type { CreatePage, PageLinkResolver } from '../../lib/page-link.js';
2
3
  import type { HeadingFrom, HeadingLevel, TableLook } from './prose-look.js';
3
4
  export type RichTextEditorProps = {
4
5
  /** The editable element's id, for a label's `htmlFor` or a test. */
@@ -98,6 +99,27 @@ export type RichTextEditorProps = {
98
99
  * zebra rows. The same on <Markdown>. Either way columns fit their words.
99
100
  */
100
101
  tableLook?: TableLook;
102
+ /**
103
+ * Which links are the app's own pages, as on `<Markdown>`
104
+ * (src/lib/page-link.ts): each link's address in, what the app knows of
105
+ * the page (title, removed, `onRestore`) or `null` out. A page link
106
+ * shows the page icon and its words in the page-link look, a row of its
107
+ * own when alone in a paragraph; a click opens it in this tab (through
108
+ * the router when there is one). A removed page is struck through, with
109
+ * "Page removed" and, given `onRestore`, Restore. The Markdown is never
110
+ * changed. Called again on each render, so pass the app's latest data.
111
+ */
112
+ pageLink?: PageLinkResolver;
113
+ /**
114
+ * Lets the text make pages: "/page" in the slash menu, and Turn into
115
+ * page on selected words, ask for a title (the selected words to start
116
+ * with), call this with it, and once it resolves to the new page's
117
+ * address put `[title](href)` where the "/page" or the words were. While
118
+ * it's pending the title box waits; a rejection is shown in the box in
119
+ * the gateway's words and the text is left as it was. Where the page
120
+ * lives (under this record, or under a page, any depth) is the app's.
121
+ */
122
+ onCreatePage?: CreatePage;
101
123
  className?: string;
102
124
  /** The field's label. A rich-text area must have one: this, or `aria-labelledby`. */
103
125
  'aria-label'?: string;
@@ -35,6 +35,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
35
35
  // from the slash menu (Toggle heading 1 to 3) or made from the heading the
36
36
  // caret is in with the toolbar's Toggle heading. Plain is the default.
37
37
  //
38
+ // With `pageLink`, links the app marks as its pages (src/lib/page-link.ts)
39
+ // draw as page links, as on <Markdown>: the page icon, a row of their own
40
+ // when alone in a paragraph, "Page removed" with Restore. A click opens the
41
+ // page in this tab. With `onCreatePage`, "/page" (or Turn into page on
42
+ // selected words) asks for a title, has the app make the page, and puts
43
+ // in `[title](href)`. Pages may nest to any depth: a page's own note takes
44
+ // the same props. The Markdown stays plain links.
45
+ //
38
46
  // `defaultValue` is read when it mounts, then followed: a new value the
39
47
  // editor didn't report itself (a form's loaded record arriving after the
40
48
  // editor, a reset) replaces the text, as if it opened with it. Its own
@@ -13,6 +13,8 @@ export interface RichTextFloatingToolbarProps {
13
13
  controls: string;
14
14
  /** A button pressed: run the format on the editor and give it focus back. */
15
15
  onFormat: (id: FormatId) => void;
16
+ /** The Page button pressed (the words become a new page's link). No button without it. */
17
+ onPage?: () => void;
16
18
  /** Esc: hide it until the selection changes. */
17
19
  onDismiss: () => void;
18
20
  /** Esc or Tab: focus back to the text. */
@@ -22,4 +24,4 @@ export interface RichTextFloatingToolbarProps {
22
24
  /** Its element, for Alt+F10 to reach it and for the editor's own blur. */
23
25
  ref?: Ref<HTMLDivElement>;
24
26
  }
25
- export declare function RichTextFloatingToolbar({ view, state, field, controls, onFormat, onDismiss, onReturn, onBlur, ref, }: RichTextFloatingToolbarProps): import("react").JSX.Element;
27
+ export declare function RichTextFloatingToolbar({ view, state, field, controls, onFormat, onPage, onDismiss, onReturn, onBlur, ref, }: RichTextFloatingToolbarProps): import("react").JSX.Element;
@@ -53,7 +53,7 @@ function place(view, from, to, field, bar) {
53
53
  const left = Math.max(0, Math.min(centre - box.left, box.width - width));
54
54
  return { top: top - box.top, left, side: above ? 'top' : 'bottom' };
55
55
  }
56
- export function RichTextFloatingToolbar({ view, state, field, controls, onFormat, onDismiss, onReturn, onBlur, ref, }) {
56
+ export function RichTextFloatingToolbar({ view, state, field, controls, onFormat, onPage, onDismiss, onReturn, onBlur, ref, }) {
57
57
  const [bar, setBar] = useState(null);
58
58
  const [placement, setPlacement] = useState(null);
59
59
  const { from, to } = state.selection;
@@ -88,5 +88,5 @@ export function RichTextFloatingToolbar({ view, state, field, controls, onFormat
88
88
  ref.current = element;
89
89
  }, role: "toolbar", "aria-label": "Format selection", "aria-controls": controls, "data-slot": "rich-text-floating-toolbar", "data-side": placement?.side, style: placement ? { top: placement.top, left: placement.left } : undefined, className: cn('absolute z-50 flex items-center gap-0.5 rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10', 'animate-in fade-in-0 zoom-in-95 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2',
90
90
  // Measured before it's seen, so it never shows in the wrong place.
91
- !placement && 'invisible'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "selection", state: state, readOnly: false, onFormat: onFormat }) }));
91
+ !placement && 'invisible'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "selection", state: state, readOnly: false, onFormat: onFormat, onPage: onPage }) }));
92
92
  }
@@ -0,0 +1,44 @@
1
+ import { Plugin, type EditorState, type Transaction } from '@milkdown/kit/prose/state';
2
+ import { DecorationSet, type EditorView } from '@milkdown/kit/prose/view';
3
+ import { type PageLinkInfo, type PageLinkResolver } from '../../lib/page-link.js';
4
+ export type PageLinksOptions = {
5
+ /** The app's `pageLink` now (it may change between renders). */
6
+ resolve: () => PageLinkResolver | undefined;
7
+ /** A Restore button pressed: resolves once the app's restore settles. */
8
+ restore: (info: PageLinkInfo, name: string) => Promise<void>;
9
+ /** Whether the text can be edited now (no Restore while it can't). */
10
+ editable: () => boolean;
11
+ };
12
+ type PageLinksState = {
13
+ decorations: DecorationSet;
14
+ signature: string;
15
+ };
16
+ /** The plugin: the page links' look, drawn again when the text changes or `refreshPageLinks` asks. */
17
+ export declare function pageLinksPlugin(options: PageLinksOptions): Plugin<PageLinksState>;
18
+ /**
19
+ * Redraws the page links if what the app answers for them has changed
20
+ * (a title, removed or restored, Restore offered or not, read-only or
21
+ * not). Cheap to call after every render: it dispatches only on a change.
22
+ */
23
+ export declare function refreshPageLinks(view: EditorView, resolve: PageLinkResolver | undefined, editable: boolean): void;
24
+ /** What the app says of the page a link points to, if it's one. */
25
+ export declare function pageLinkInfo(resolve: PageLinkResolver | undefined, href: string): PageLinkInfo | null;
26
+ /** Where the new page's link goes: what was typed ("/page") or selected. */
27
+ export type PageSpan = {
28
+ from: number;
29
+ to: number;
30
+ };
31
+ /** Keeps the span a page being made will replace in step with edits made meanwhile. */
32
+ export declare function pendingPagePlugin(): Plugin<PageSpan | null>;
33
+ /** Marks (or, with null, forgets) the span the page being made will go in. */
34
+ export declare function setPendingPage(tr: Transaction, span: PageSpan | null): Transaction;
35
+ /** The span the page being made will go in, if one is. */
36
+ export declare function pendingPage(state: EditorState): PageSpan | null;
37
+ /**
38
+ * Puts the new page's link in its span: the title as the link's words,
39
+ * linked to `href`, in one transaction (one undo step). The caret goes
40
+ * after it, and what's typed next isn't part of the link. False when
41
+ * there's no span any more.
42
+ */
43
+ export declare function insertPageLink(view: EditorView, title: string, href: string): boolean;
44
+ export {};
@@ -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;
@@ -47,6 +47,15 @@ export type LinkCellProps = {
47
47
  /** The input's width class. Defaults to `w-64`. */
48
48
  inputClassName?: string;
49
49
  };
50
+ /**
51
+ * A link out of the app as LinkCell shows one at rest: the link tone,
52
+ * underlined, an external-link mark, opening in a new tab (said to a
53
+ * screen reader). `href` must be one `linkHref` returned.
54
+ */
55
+ export declare function LinkOut({ href, children }: {
56
+ href: string;
57
+ children: ReactNode;
58
+ }): import("react").JSX.Element;
50
59
  /** An optional link: shown as a link out (or the not-set label), edited as one line; blank clears it. */
51
60
  export declare function LinkCell({ label, value, save, linkText, emptyLabel, inputClassName }: LinkCellProps): import("react").JSX.Element;
52
61
  export {};
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ExternalLinkIcon } from 'lucide-react';
3
3
  import { Input } from '../ui/input.js';
4
4
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
5
- import { linkHref, linkRefusal } from '../../lib/link-href.js';
5
+ import { linkHref, linkRule } from '../../lib/link-href.js';
6
6
  import { editInPlace } from './edit-in-place.js';
7
7
  import { EditableValue } from './editable-value.js';
8
8
  /** A name in one line: Enter saves, the form's rule runs first, a taken name's 422 shows in the cell. */
@@ -32,20 +32,16 @@ export function ChoiceCell({ label, value, options, render, save, triggerClassNa
32
32
  }
33
33
  // A web or email address (`example.com` gains https://), blank for none.
34
34
  // Another scheme (`javascript:`) or a space inside the address is refused
35
- // before anything is sent.
36
- const LINK_RULE = {
37
- safeParse: (value) => {
38
- const typed = String(value ?? '');
39
- const href = linkHref(typed);
40
- if (href === '')
41
- return { success: true, data: null };
42
- if (href === null) {
43
- const message = linkRefusal(typed) === 'whitespace' ? 'An address has no spaces' : 'Use a web or email address';
44
- return { success: false, error: { issues: [{ message }] } };
45
- }
46
- return { success: true, data: href };
47
- },
48
- };
35
+ // before anything is sent: `linkRule`, shared with `inPlace.link`.
36
+ const LINK_RULE = linkRule;
37
+ /**
38
+ * A link out of the app as LinkCell shows one at rest: the link tone,
39
+ * underlined, an external-link mark, opening in a new tab (said to a
40
+ * screen reader). `href` must be one `linkHref` returned.
41
+ */
42
+ export function LinkOut({ href, children }) {
43
+ return (_jsxs("a", { href: href, target: "_blank", rel: "noopener noreferrer", className: "rounded-sm text-link underline underline-offset-4 outline-none focus-visible:ring-3 focus-visible:ring-ring/50", children: [children, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] }));
44
+ }
49
45
  function shownLinkText(href, linkText) {
50
46
  if (typeof linkText === 'function')
51
47
  return linkText(href);
@@ -62,5 +58,5 @@ export function LinkCell({ label, value, save, linkText, emptyLabel = 'Not set',
62
58
  schema: LINK_RULE,
63
59
  save,
64
60
  control: (props) => (_jsx(Input, { id: props.id, type: "url", inputMode: "url", className: inputClassName, value: props.value, placeholder: "https://", readOnly: props.disabled, "aria-invalid": props.invalid || undefined, "aria-label": props.label, "aria-describedby": props.describedBy, onChange: (event) => props.onChange(event.target.value) })),
65
- }), children: !value ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel })) : href ? (_jsxs("a", { href: href, target: "_blank", rel: "noreferrer", className: "rounded-sm text-link underline underline-offset-4 outline-none focus-visible:ring-3 focus-visible:ring-ring/50", children: [shownLinkText(href, linkText), _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })) : (value) }));
61
+ }), children: !value ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel })) : href ? (_jsx(LinkOut, { href: href, children: shownLinkText(href, linkText) })) : (value) }));
66
62
  }
@@ -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, };