@tristan2828/ui-foundation 4.126.0 → 4.128.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 (74) hide show
  1. package/conventions/docs/add-an-entity.md +154 -34
  2. package/conventions/docs/cell-patterns.md +88 -41
  3. package/conventions/docs/design-language.md +62 -13
  4. package/dist/api/contracts.d.ts +8 -1
  5. package/dist/api/gateway/errors.js +4 -0
  6. package/dist/api/schema.d.ts +9 -0
  7. package/dist/components/app/data-table-tools.d.ts +12 -0
  8. package/dist/components/app/data-table-tools.js +2 -2
  9. package/dist/components/app/data-table.d.ts +2 -1
  10. package/dist/components/app/data-table.js +1 -1
  11. package/dist/components/app/edit-in-place-presets.d.ts +51 -1
  12. package/dist/components/app/edit-in-place-presets.js +30 -0
  13. package/dist/components/app/edit-in-place-store.d.ts +33 -7
  14. package/dist/components/app/edit-in-place-store.js +112 -20
  15. package/dist/components/app/edit-in-place.d.ts +11 -0
  16. package/dist/components/app/editable-value.js +43 -8
  17. package/dist/components/app/entity-form.d.ts +9 -1
  18. package/dist/components/app/entity-form.js +9 -2
  19. package/dist/components/app/entity-view.js +5 -1
  20. package/dist/components/app/equal-items.d.ts +33 -6
  21. package/dist/components/app/equal-items.js +42 -7
  22. package/dist/components/app/error-state.js +1 -0
  23. package/dist/components/app/form-conflict-notice.d.ts +8 -0
  24. package/dist/components/app/form-conflict-notice.js +15 -0
  25. package/dist/components/app/form-dialog.d.ts +8 -1
  26. package/dist/components/app/form-dialog.js +9 -2
  27. package/dist/components/app/milkdown-editor.js +24 -331
  28. package/dist/components/app/notify.d.ts +18 -1
  29. package/dist/components/app/notify.js +26 -3
  30. package/dist/components/app/page-restore.js +1 -1
  31. package/dist/components/app/pill-filter.d.ts +16 -0
  32. package/dist/components/app/pill-filter.js +22 -1
  33. package/dist/components/app/rating-input.d.ts +22 -0
  34. package/dist/components/app/rating-input.js +65 -0
  35. package/dist/components/app/rating-score.d.ts +2 -1
  36. package/dist/components/app/rating-score.js +2 -6
  37. package/dist/components/app/rich-text-box-anchor.d.ts +6 -0
  38. package/dist/components/app/rich-text-box-anchor.js +8 -0
  39. package/dist/components/app/rich-text-editor.d.ts +4 -2
  40. package/dist/components/app/rich-text-editor.js +3 -2
  41. package/dist/components/app/rich-text-heading-view.d.ts +4 -0
  42. package/dist/components/app/rich-text-heading-view.js +91 -0
  43. package/dist/components/app/rich-text-keyboard-bar.js +3 -2
  44. package/dist/components/app/rich-text-link-box.d.ts +9 -0
  45. package/dist/components/app/rich-text-link-box.js +40 -0
  46. package/dist/components/app/rich-text-links.d.ts +14 -0
  47. package/dist/components/app/rich-text-links.js +92 -0
  48. package/dist/components/app/rich-text-page-box.d.ts +10 -0
  49. package/dist/components/app/rich-text-page-box.js +45 -0
  50. package/dist/components/app/rich-text-task-item-view.d.ts +4 -0
  51. package/dist/components/app/rich-text-task-item-view.js +59 -0
  52. package/dist/components/app/rich-text-toggle-heading.js +1 -1
  53. package/dist/components/app/rich-text-toolbar.js +1 -1
  54. package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
  55. package/dist/components/app/rich-text-tools-bar.js +2 -2
  56. package/dist/components/app/step-row.d.ts +15 -0
  57. package/dist/components/app/step-row.js +27 -0
  58. package/dist/components/app/step-track.d.ts +82 -0
  59. package/dist/components/app/step-track.js +98 -0
  60. package/dist/components/ui/sonner.js +1 -1
  61. package/dist/hooks/use-form-version.d.ts +101 -0
  62. package/dist/hooks/use-form-version.js +187 -0
  63. package/dist/hooks/use-record-update.d.ts +15 -8
  64. package/dist/hooks/use-record-update.js +19 -14
  65. package/dist/index.d.ts +7 -3
  66. package/dist/index.js +7 -0
  67. package/dist/lib/markdown-merge.d.ts +12 -0
  68. package/dist/lib/markdown-merge.js +90 -0
  69. package/dist/lib/rating-glyphs.d.ts +3 -0
  70. package/dist/lib/rating-glyphs.js +7 -0
  71. package/dist/lib/refusal.d.ts +9 -0
  72. package/dist/lib/refusal.js +19 -0
  73. package/openapi/foundation.yaml +12 -0
  74. package/package.json +1 -1
@@ -5,7 +5,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
5
5
  // <Markdown> renders with. Why Milkdown, and what it costs:
6
6
  // docs/ARCHITECTURE.md "Decisions".
7
7
  //
8
- // What this file adds to Milkdown's own presets:
8
+ // What this file (the wiring) and the rich-text-* files beside it add to
9
+ // Milkdown's own presets:
9
10
  // - Saves go through mergeMarkdown: an untouched document, and every block
10
11
  // the person didn't change, saves back as originally written.
11
12
  // - No HTML in, ever. The preset's "preserve empty line" plugin is left
@@ -18,8 +19,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
18
19
  // <h2>. `headingLevel` moves them to where the field sits in the page's
19
20
  // outline, as it does <Markdown>'s; only the element moves, never the
20
21
  // level the Markdown is saved with (a node view draws it, from the
21
- // node's own level). They look like <Markdown>'s (prose-look.ts). A
22
- // task-list item renders a real checkbox that toggles it.
22
+ // node's own level: rich-text-heading-view.ts). They look like
23
+ // <Markdown>'s (prose-look.ts). A task-list item renders a real checkbox
24
+ // that toggles it (rich-text-task-item-view.ts).
23
25
  // - Callouts (`> [!NOTE]`, src/lib/markdown-callout.ts): a node of their
24
26
  // own, drawn as <Markdown> draws them, the icon a menu of kinds.
25
27
  // - Tables whose columns fit their words, in a box that scrolls sideways
@@ -49,7 +51,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
49
51
  // (rich-text-full-screen.ts).
50
52
  // - A click on a link opens it in a new tab, as the read view's links do,
51
53
  // so notes that are always the editor still follow their links
52
- // (followLink). Ctrl/Cmd+K adds or edits a link (a box at the caret: web
54
+ // (followLink, rich-text-links.ts). Ctrl/Cmd+K adds or edits a link (a
55
+ // box at the caret, rich-text-link-box.tsx: web
53
56
  // and email addresses only); Ctrl/Cmd+Shift+Enter ticks the task item the caret is
54
57
  // in. `[] ` at a line's start makes a task item, and Enter in one the
55
58
  // next, unticked (rich-text-tasks.ts). Ctrl/Cmd+Enter stays the field's
@@ -68,7 +71,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
68
71
  // for notes that are always editable where they're read.
69
72
  // - Images in the text show (`![alt](url)`), at most the field's width.
70
73
  // With `upload`, an image pasted, dropped or picked with the toolbar's
71
- // Image button is uploaded through it and goes in as `![](url)`
74
+ // Image button (the fixed toolbar's, the tools strip's with
75
+ // `toolbar="floating"`, the phone's row) is uploaded through it and goes in as `![](url)`
72
76
  // (rich-text-image-upload.ts); a refusal or a failed upload is a toast.
73
77
  // - Toggle headings (`## Safety {toggle="true"}`, rich-text-toggle-heading.ts):
74
78
  // a heading's `toggle` attribute, typed as `>## `, picked from the slash
@@ -79,7 +83,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
79
83
  // - `pageLink`: links the app marks as its pages drawn as page links
80
84
  // (rich-text-page-links.ts), opened in this tab; `onCreatePage`: "/page"
81
85
  // and Turn into page make one through the app and link it (a title box,
82
- // PageForm). The Markdown stays a plain link.
86
+ // rich-text-page-box.tsx). The Markdown stays a plain link.
83
87
  import { useEffect, useId, useRef, useState } from 'react';
84
88
  import { createPortal } from 'react-dom';
85
89
  import { useInRouterContext, useNavigate } from 'react-router';
@@ -93,15 +97,12 @@ import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
93
97
  import { $markSchema, $nodeSchema, $prose, $remark, getMarkdown } from '@milkdown/kit/utils';
94
98
  import { cn } from 'cn';
95
99
  import { toast } from 'sonner';
96
- import { Button } from '../ui/button.js';
97
- import { Field, FieldError, FieldLabel } from '../ui/field.js';
98
- import { Input } from '../ui/input.js';
99
- import { Popover, PopoverContent } from '../ui/popover.js';
100
+ import { Popover } from '../ui/popover.js';
100
101
  import { acceptAttribute } from '../../lib/image-file.js';
101
- import { linkHref, linkRefusal } from '../../lib/link-href.js';
102
- import { messageOf } from './edit-in-place-store.js';
102
+ import { linkHref } from '../../lib/link-href.js';
103
+ import { messageOf } from '../../lib/refusal.js';
103
104
  import { restorePage } from './page-restore.js';
104
- import { insertPageLink, pageLinkInfo, pageLinksPlugin, pendingPagePlugin, refreshPageLinks, setPendingPage, } from './rich-text-page-links.js';
105
+ import { insertPageLink, pageLinksPlugin, pendingPagePlugin, refreshPageLinks, setPendingPage, } from './rich-text-page-links.js';
105
106
  import { passEscapeThrough } from './escape-passthrough.js';
106
107
  import { calloutHandler, remarkCalloutNodes } from '../../lib/markdown-callout.js';
107
108
  import { formatTableWidths, remarkTableWidths } from '../../lib/markdown-table-widths.js';
@@ -111,15 +112,21 @@ import { MarkdownMergeError, markdownStyle, mergeMarkdown } from '../../lib/mark
111
112
  import { holdPendingEdit } from '../../lib/pending-edits.js';
112
113
  import { foldStore, listenForOtherTabs } from '../../hooks/fold-store.js';
113
114
  import { toggleFold } from '../../lib/markdown-fold.js';
114
- import { DEFAULT_HEADING_LEVEL, FOLD_BUTTON, FOLD_HEADING, headingBand, headingClass, headingTag } from './prose-look.js';
115
- import { foldPlugin, foldSpecOf, setFolds } from './rich-text-fold.js';
115
+ import { DEFAULT_HEADING_LEVEL } from './prose-look.js';
116
+ import { foldPlugin, setFolds } from './rich-text-fold.js';
117
+ import { headingView } from './rich-text-heading-view.js';
118
+ import { taskItemView, toggleTaskItem } from './rich-text-task-item-view.js';
119
+ import { applyLink, followLink, linkTarget } from './rich-text-links.js';
120
+ import { anchorAt } from './rich-text-box-anchor.js';
121
+ import { LinkForm } from './rich-text-link-box.js';
122
+ import { PageForm } from './rich-text-page-box.js';
116
123
  import { RichTextFloatingToolbar } from './rich-text-floating-toolbar.js';
117
124
  import { formatOn, tableAt, toggleFormat } from './rich-text-formats.js';
118
125
  import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
119
126
  import { calloutKind, calloutView, tableView } from './rich-text-node-views.js';
120
127
  import { droppedFiles, imageUploadPlugin, pastedImages, uploadImages, uploadPlaceholders } from './rich-text-image-upload.js';
121
128
  import { handleShortcut } from './rich-text-shortcuts.js';
122
- import { splitTaskItem, TASK_ROW, taskBoxHit, taskInputRule } from './rich-text-tasks.js';
129
+ import { splitTaskItem, taskInputRule } from './rich-text-tasks.js';
123
130
  import { typedInputRules } from './rich-text-input-rules.js';
124
131
  import { edges } from './rich-text-edges.js';
125
132
  import { withEmptyParagraphChildren } from './rich-text-empty-paragraph.js';
@@ -282,224 +289,6 @@ function shownKey(state) {
282
289
  return parts.join('|');
283
290
  }
284
291
  const REFUSED_EDIT = "This change can't be saved without rewriting parts of the text you didn't edit. Undo it to go on saving.";
285
- // A heading: the element `headingLevel` gives its level, the look its
286
- // level has. Marked as a band for PROSE_INSET (`#` and `##`).
287
- //
288
- // With `foldKey` (`onFold`), a toggle heading sits beside its fold button,
289
- // as in <Markdown>: the look on the two together, the button out of the
290
- // tab order (Ctrl/Cmd+Alt+[ and ] and NotesOutline are the keyboard's
291
- // way), kept invisible where there's nothing under the heading to fold,
292
- // or the heading isn't at the top level. A plain heading has no button
293
- // and no room for one; its fold id still marks it, for NotesOutline.
294
- function headingView(node, top, textTop, decorations, onFold) {
295
- const level = Number(node.attrs.level);
296
- const heading = document.createElement(headingTag(level, top, textTop));
297
- const sameLevel = (next) => next.type === node.type && next.attrs.level === node.attrs.level && Boolean(next.attrs.toggle) === Boolean(node.attrs.toggle);
298
- if (node.attrs.toggle)
299
- heading.dataset.toggle = '';
300
- if (!onFold || !node.attrs.toggle) {
301
- heading.className = headingClass(level);
302
- if (headingBand(level))
303
- heading.dataset.band = '';
304
- const mark = (decorations) => {
305
- const spec = onFold ? foldSpecOf(decorations) : null;
306
- if (spec)
307
- heading.dataset.foldId = spec.id;
308
- else
309
- delete heading.dataset.foldId;
310
- };
311
- mark(decorations);
312
- return {
313
- dom: heading,
314
- contentDOM: heading,
315
- update: (next, decorations) => {
316
- if (!sameLevel(next))
317
- return false;
318
- mark(decorations);
319
- return true;
320
- },
321
- };
322
- }
323
- const dom = document.createElement('div');
324
- dom.dataset.toggle = '';
325
- dom.className = cn(FOLD_HEADING, headingClass(level));
326
- if (headingBand(level))
327
- dom.dataset.band = '';
328
- heading.className = 'min-w-0 flex-1';
329
- const button = document.createElement('button');
330
- button.type = 'button';
331
- button.tabIndex = -1;
332
- button.contentEditable = 'false';
333
- button.dataset.slot = 'fold-button';
334
- const chevron = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
335
- chevron.setAttribute('viewBox', '0 0 24 24');
336
- chevron.setAttribute('aria-hidden', 'true');
337
- chevron.innerHTML =
338
- '<path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />';
339
- button.append(chevron);
340
- dom.append(button, heading);
341
- let spec = null;
342
- const render = (decorations) => {
343
- spec = foldSpecOf(decorations);
344
- button.className = cn(FOLD_BUTTON, !spec?.foldable && 'invisible');
345
- chevron.setAttribute('class', cn('size-4 transition-transform', spec?.folded && '-rotate-90'));
346
- button.setAttribute('aria-expanded', String(!spec?.folded));
347
- button.setAttribute('aria-label', spec?.label || 'Section');
348
- if (spec)
349
- dom.dataset.foldId = spec.id;
350
- else
351
- delete dom.dataset.foldId;
352
- };
353
- render(decorations);
354
- // A press keeps the caret where it is.
355
- button.addEventListener('mousedown', (event) => event.preventDefault());
356
- button.addEventListener('click', () => {
357
- if (spec?.foldable)
358
- onFold(spec.id);
359
- });
360
- return {
361
- dom,
362
- contentDOM: heading,
363
- update: (next, decorations) => {
364
- if (!sameLevel(next))
365
- return false;
366
- render(decorations);
367
- return true;
368
- },
369
- stopEvent: (event) => button.contains(event.target),
370
- ignoreMutation: (mutation) => mutation.type !== 'selection' && !heading.contains(mutation.target),
371
- };
372
- }
373
- // A task-list item: its checkbox toggles `checked`. Any other list item
374
- // renders as Milkdown's own.
375
- function taskItemView(node, view, getPos) {
376
- const dom = document.createElement('li');
377
- const box = document.createElement('input');
378
- box.type = 'checkbox';
379
- box.contentEditable = 'false';
380
- box.tabIndex = -1;
381
- box.setAttribute('aria-label', 'Done');
382
- const contentDOM = document.createElement('div');
383
- // Takes the row's width, so an empty item's caret and placeholder show.
384
- contentDOM.className = 'min-w-0 flex-1';
385
- dom.append(taskBoxHit(box), contentDOM);
386
- dom.className = TASK_ROW;
387
- dom.dataset.itemType = 'task';
388
- let current = node;
389
- const render = () => {
390
- box.checked = Boolean(current.attrs.checked);
391
- dom.dataset.checked = String(Boolean(current.attrs.checked));
392
- };
393
- render();
394
- box.addEventListener('mousedown', (event) => event.preventDefault());
395
- // The browser's own toggle is left to happen (cancelling a checkbox's
396
- // click puts its old state back after this handler), and the document
397
- // follows it.
398
- box.addEventListener('click', () => {
399
- const pos = getPos();
400
- if (pos === undefined || !view.editable)
401
- return;
402
- view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, checked: !current.attrs.checked }));
403
- });
404
- return {
405
- dom,
406
- contentDOM,
407
- update: (next) => {
408
- if (next.type !== current.type || next.attrs.checked == null)
409
- return false;
410
- current = next;
411
- render();
412
- return true;
413
- },
414
- stopEvent: (event) => event.target === box || event.target === box.parentElement,
415
- ignoreMutation: (mutation) => mutation.target === box || mutation.target === box.parentElement,
416
- };
417
- }
418
- // The task-list item the caret is in, ticked or unticked. False when the
419
- // caret isn't in one.
420
- function toggleTaskItem(view) {
421
- const { $from } = view.state.selection;
422
- for (let depth = $from.depth; depth > 0; depth--) {
423
- const node = $from.node(depth);
424
- if (node.type.name === 'list_item' && node.attrs.checked != null) {
425
- view.dispatch(view.state.tr.setNodeMarkup($from.before(depth), undefined, { ...node.attrs, checked: !node.attrs.checked }));
426
- return true;
427
- }
428
- }
429
- return false;
430
- }
431
- function linkTarget(state) {
432
- const link = state.schema.marks.link;
433
- const { from, to, empty, $from } = state.selection;
434
- if (!empty) {
435
- let href = '';
436
- state.doc.nodesBetween(from, to, (node) => {
437
- const mark = link.isInSet(node.marks);
438
- if (mark && !href)
439
- href = String(mark.attrs.href);
440
- });
441
- return { from, to, href };
442
- }
443
- const mark = link.isInSet($from.marks());
444
- if (!mark)
445
- return { from, to, href: '' };
446
- const start = $from.start();
447
- let target = { from, to, href: String(mark.attrs.href) };
448
- let runFrom = -1;
449
- $from.parent.forEach((child, offset) => {
450
- const childFrom = start + offset;
451
- const childTo = childFrom + child.nodeSize;
452
- if (!mark.isInSet(child.marks)) {
453
- runFrom = -1;
454
- return;
455
- }
456
- if (runFrom < 0)
457
- runFrom = childFrom;
458
- if (runFrom <= from && from <= childTo)
459
- target = { from: runFrom, to: childTo, href: target.href };
460
- });
461
- return target;
462
- }
463
- // A plain click (or a tap) on a link opens it in a new tab, the way the
464
- // read view's links open (markdown.tsx), so notes that are always the
465
- // editor still work as notes. Not when the click chose words (a drag ends
466
- // in a click too), extends the selection (Shift) or is Alt's; the address
467
- // goes through linkHref again, so a link that came in with the Markdown
468
- // can't run code (`javascript:`) either: that one stays text to click
469
- // into. Read-only too, where the browser would otherwise follow it in this
470
- // tab. To edit a link's words, put the caret in them from the keyboard or
471
- // drag over them; Ctrl/Cmd+K edits its address.
472
- //
473
- // A page link (`pageLink`) opens its page in this tab instead (`open`:
474
- // the router's, when there is one), and a removed page's link opens
475
- // nothing.
476
- function followLink(view, event, pages) {
477
- if (event.button !== 0 || event.shiftKey || event.altKey)
478
- return false;
479
- const anchor = event.target instanceof Element ? event.target.closest('a[href]') : null;
480
- if (!anchor || !view.dom.contains(anchor))
481
- return false;
482
- if (!view.state.selection.empty)
483
- return false;
484
- const written = anchor.getAttribute('href') ?? '';
485
- const page = pageLinkInfo(pages.resolve, written);
486
- if (page) {
487
- event.preventDefault();
488
- if (page.removed)
489
- return false;
490
- const href = linkHref(written);
491
- if (!href)
492
- return false;
493
- pages.open(href);
494
- return true;
495
- }
496
- const href = linkHref(written);
497
- if (!href)
498
- return false;
499
- event.preventDefault();
500
- window.open(href, '_blank', 'noopener,noreferrer');
501
- return true;
502
- }
503
292
  // The router's navigate, handed to the editor's callbacks: rendered only
504
293
  // inside a router, so an editor outside one still works (a page link
505
294
  // then loads the page).
@@ -513,32 +302,6 @@ function NavigateBridge({ targetRef }) {
513
302
  }, [navigate, targetRef]);
514
303
  return null;
515
304
  }
516
- // Sets (or, with `href` empty, removes) the link on the target. With
517
- // nothing selected and no link there, the address goes in as the link's
518
- // own text.
519
- function applyLink(view, target, href) {
520
- const link = view.state.schema.marks.link;
521
- const tr = view.state.tr;
522
- if (target.from === target.to) {
523
- if (!href)
524
- return;
525
- tr.insertText(href, target.from).addMark(target.from, target.from + href.length, link.create({ href }));
526
- }
527
- else {
528
- tr.removeMark(target.from, target.to, link);
529
- if (href)
530
- tr.addMark(target.from, target.to, link.create({ href }));
531
- }
532
- view.dispatch(tr.scrollIntoView());
533
- }
534
- // A box's place: a point in the text.
535
- function anchorAt(view, pos) {
536
- const point = view.coordsAtPos(pos);
537
- return {
538
- getBoundingClientRect: () => new DOMRect(point.left, point.top, 0, point.bottom - point.top),
539
- contextElement: view.dom,
540
- };
541
- }
542
305
  export default function MilkdownEditor({ id, defaultValue, onChange, onProblem, readOnly = false, autoFocus = false, placeholder, maxLength, toolbar = true, inline = false, upload, imageAccept, imageMaxSize, headingLevel = DEFAULT_HEADING_LEVEL, headingFrom = 'hash', foldKey, tableLook = 'compact', pageLink, onCreatePage, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }) {
543
306
  const rootRef = useRef(null);
544
307
  const editorRef = useRef(null);
@@ -1461,7 +1224,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
1461
1224
  const next = event.relatedTarget;
1462
1225
  if (!editorView.dom.contains(next) && !inFloating(next))
1463
1226
  setFocused(false);
1464
- } })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
1227
+ } })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onImage: upload ? pickImages : undefined, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
1465
1228
  const next = event.relatedTarget;
1466
1229
  if (editorView && !editorView.dom.contains(next) && !inFloating(next))
1467
1230
  setFocused(false);
@@ -1477,73 +1240,3 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
1477
1240
  closeLink();
1478
1241
  } })) })] }));
1479
1242
  }
1480
- // The link box: the address, Apply, and Remove link for an existing one.
1481
- // Enter (Ctrl/Cmd+Enter too) applies the link and stays its own: editing
1482
- // in place listens for Ctrl/Cmd+Enter through the portal, and would save
1483
- // the field without it. Esc is the popover's: it closes the box only.
1484
- function LinkForm({ box, onApply }) {
1485
- const [typed, setTyped] = useState(box.href);
1486
- const [error, setError] = useState(null);
1487
- const inputRef = useRef(null);
1488
- const inputId = useId();
1489
- const errorId = `${inputId}-error`;
1490
- const apply = () => {
1491
- const href = linkHref(typed);
1492
- if (href === null) {
1493
- setError(linkRefusal(typed) === 'whitespace'
1494
- ? 'An address has no spaces. Remove them, or write each as %20.'
1495
- : 'Enter a web or email address, like https://example.com.');
1496
- return;
1497
- }
1498
- onApply(href);
1499
- };
1500
- const onKeyDown = (event) => {
1501
- if (event.key === 'Enter' && event.target === inputRef.current) {
1502
- event.preventDefault();
1503
- event.stopPropagation();
1504
- apply();
1505
- }
1506
- };
1507
- return (_jsxs(PopoverContent, { anchor: box.anchor, align: "start", "aria-label": box.href ? 'Edit Link' : 'Add Link', initialFocus: inputRef, finalFocus: false, className: "w-80", onKeyDown: onKeyDown, children: [_jsxs(Field, { "data-invalid": error ? true : undefined, children: [_jsx(FieldLabel, { htmlFor: inputId, children: "Link Address" }), _jsx(Input, { ref: inputRef, id: inputId, value: typed, placeholder: "https://", autoComplete: "off", "aria-invalid": error ? true : undefined, "aria-describedby": error ? errorId : undefined, onChange: (event) => {
1508
- setTyped(event.target.value);
1509
- setError(null);
1510
- } }), error && _jsx(FieldError, { id: errorId, children: error })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { size: "sm", onClick: apply, children: "Apply" }), box.href && (_jsx(Button, { size: "sm", variant: "outline", onClick: () => onApply(''), children: "Remove Link" }))] })] }));
1511
- }
1512
- // The new page's title box: the title (the selected words to start with),
1513
- // and Create page. While the app makes the page it waits, its controls
1514
- // held; a refusal shows under the title, in the gateway's words, and the
1515
- // text is left as it was. Enter creates; Esc is the popover's, and closes
1516
- // it (not while the app is still working).
1517
- function PageForm({ box, busy, onCreate }) {
1518
- const [typed, setTyped] = useState(box.title);
1519
- const [error, setError] = useState(null);
1520
- const inputRef = useRef(null);
1521
- const inputId = useId();
1522
- const errorId = `${inputId}-error`;
1523
- const create = () => {
1524
- const title = typed.replace(/\s+/g, ' ').trim();
1525
- if (!title) {
1526
- setError('Give the page a title.');
1527
- return;
1528
- }
1529
- setError(null);
1530
- void onCreate(title).then((refused) => {
1531
- if (refused) {
1532
- setError(refused);
1533
- inputRef.current?.focus();
1534
- }
1535
- });
1536
- };
1537
- const onKeyDown = (event) => {
1538
- if (event.key === 'Enter' && event.target === inputRef.current) {
1539
- event.preventDefault();
1540
- event.stopPropagation();
1541
- if (!busy)
1542
- create();
1543
- }
1544
- };
1545
- return (_jsxs(PopoverContent, { anchor: box.anchor, align: "start", "aria-label": "New Page", initialFocus: inputRef, finalFocus: false, className: "w-80", "data-rich-text-menu": "", "data-slot": "page-form", onKeyDown: onKeyDown, children: [_jsxs(Field, { "data-invalid": error ? true : undefined, children: [_jsx(FieldLabel, { htmlFor: inputId, children: "Page Title" }), _jsx(Input, { ref: inputRef, id: inputId, value: typed, autoComplete: "off", readOnly: busy, "aria-invalid": error ? true : undefined, "aria-describedby": error ? errorId : undefined, onChange: (event) => {
1546
- setTyped(event.target.value);
1547
- setError(null);
1548
- } }), error && _jsx(FieldError, { id: errorId, children: error })] }), _jsx("div", { className: "flex gap-2", children: _jsx(Button, { size: "sm", onClick: create, disabled: busy, children: busy ? 'Creating…' : 'Create Page' }) })] }));
1549
- }
@@ -1,15 +1,32 @@
1
+ import { type To } from 'react-router';
2
+ /** Where Open goes: a path, or `{ to, label }` to change its word ("View"). */
3
+ export type NotifyOpen = To | {
4
+ to: To;
5
+ label?: string;
6
+ };
1
7
  export type NotifyDoneOptions = {
2
8
  /** Undo's action: restores what was done. Undo shows only when it's given. */
3
9
  undo?: () => unknown;
4
10
  /** The verb once Undo has worked: "Restored" unless set ("Unarchived"). */
5
11
  undone?: string;
12
+ /**
13
+ * An Open link to the record the toast names: a path, or `{ to, label }`.
14
+ * For a record made where the person stays. With Undo too, both
15
+ * show, Open first.
16
+ */
17
+ open?: NotifyOpen;
6
18
  };
7
19
  /** "Deleted The Long Walk": the verb, then the name. */
8
20
  export declare function doneMessage(verb: string, name: string): string;
9
21
  /** "Retire" → "Retired", "Archive" → "Archived", "Remove" → "Removed". */
10
22
  export declare function pastTense(verb: string): string;
11
23
  declare function failed(message: string): string | number;
12
- declare function done(verb: string, name: string, { undo, undone }?: NotifyDoneOptions): string | number;
24
+ /** `open` as a link and its word: "Open" unless `{ label }` says otherwise. */
25
+ export declare function openTarget(open: NotifyOpen): {
26
+ to: To;
27
+ label: string;
28
+ };
29
+ declare function done(verb: string, name: string, { undo, undone, open }?: NotifyDoneOptions): string | number;
13
30
  export declare const notify: {
14
31
  done: typeof done;
15
32
  failed: typeof failed;
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // The words and the lifetimes of the app's toasts (4.90, the dialogs and
2
3
  // feedback standard D5, D6). A toast is for what happened out of sight: a
3
4
  // delete (with Undo), a record made somewhere else, a job that finished
@@ -8,11 +9,18 @@
8
9
  // Walk", the verb first, the same way everywhere, for 4 seconds. With
9
10
  // `undo`, an Undo button that runs it, then "Restored The Long Walk"; an
10
11
  // Undo that fails is a toast that stays.
12
+ // - `notify.done("Added", "The Long Walk", { open: "/books/7" })`: the same
13
+ // toast with an Open link to the new record, for a record made from a
14
+ // page that stays put (a dialog over a page of tiles). A real link (the
15
+ // router's `Link`), named "Open The Long Walk", reached by Tab once the
16
+ // toaster has focus (Alt+T); it closes the toast as it goes. Same 4
17
+ // seconds. `{ to, label: "View" }` changes its word.
11
18
  // - `notify.failed("Couldn't save The Long Walk: the server didn't
12
19
  // answer.")`: an error toast that stays until it's closed. Only as the
13
20
  // fallback, when what failed is no longer on screen (useAction does
14
21
  // this); an action whose button is still there shows its error beside
15
22
  // it (ActionError).
23
+ import { Link } from 'react-router';
16
24
  import { toast } from 'sonner';
17
25
  import { messageOf } from './edit-in-place-store.js';
18
26
  /** "Deleted The Long Walk": the verb, then the name. */
@@ -26,8 +34,22 @@ export function pastTense(verb) {
26
34
  function failed(message) {
27
35
  return toast.error(message, { duration: Number.POSITIVE_INFINITY, closeButton: true });
28
36
  }
29
- function done(verb, name, { undo, undone = 'Restored' } = {}) {
30
- return toast.success(doneMessage(verb, name), {
37
+ /** `open` as a link and its word: "Open" unless `{ label }` says otherwise. */
38
+ export function openTarget(open) {
39
+ if (typeof open === 'object' && 'to' in open)
40
+ return { to: open.to, label: open.label ?? 'Open' };
41
+ return { to: open, label: 'Open' };
42
+ }
43
+ function done(verb, name, { undo, undone = 'Restored', open } = {}) {
44
+ let id = undefined;
45
+ const target = open === undefined ? undefined : openTarget(open);
46
+ // A link, not a button that navigates: the router's Link inside the
47
+ // shell's Toaster (it sits under the router), so it can be opened in a
48
+ // new tab too. `data-button` takes sonner's own action look, Undo's.
49
+ const link = target && (_jsx(Link, { to: target.to, "data-button": "", "data-action": "", "aria-label": `${target.label} ${name}`, onClick: () => toast.dismiss(id), children: target.label }));
50
+ id = toast.success(doneMessage(verb, name), {
51
+ // With Undo as the action, Open takes the slot before it.
52
+ cancel: undo ? link : undefined,
31
53
  action: undo
32
54
  ? {
33
55
  label: 'Undo',
@@ -40,7 +62,8 @@ function done(verb, name, { undo, undone = 'Restored' } = {}) {
40
62
  .then(() => toast.success(doneMessage(undone, name)), (error) => failed(`Couldn't undo: ${messageOf(error)}`));
41
63
  },
42
64
  }
43
- : undefined,
65
+ : link,
44
66
  });
67
+ return id;
45
68
  }
46
69
  export const notify = { done, failed };
@@ -2,7 +2,7 @@
2
2
  // and the editor's (rich-text-page-links.ts): the app's `onRestore`, its
3
3
  // refusal toasted in the gateway's words (messageOf).
4
4
  import { toast } from 'sonner';
5
- import { messageOf } from './edit-in-place-store.js';
5
+ import { messageOf } from '../../lib/refusal.js';
6
6
  /** Runs the app's restore, toasting a refusal. Resolves either way. */
7
7
  export async function restorePage(info, name) {
8
8
  try {
@@ -15,3 +15,19 @@ export type PillFilterProps = {
15
15
  className?: string;
16
16
  };
17
17
  export declare function PillFilter({ label, options, value, onValueChange, allLabel, className }: PillFilterProps): import("react").JSX.Element;
18
+ /**
19
+ * One pill as PillGroup draws it: a PillFilterOption, and for DataTable's
20
+ * views (4.127) a count after the label, "Needs a Look · 3".
21
+ */
22
+ export type PillGroupOption = PillFilterOption & {
23
+ /** The number shown after the label; null, undefined or 0 shows none, past 99 "99+". */
24
+ count?: number | null;
25
+ /**
26
+ * The pill keeps room for a two-digit count from its first render, so
27
+ * a count that arrives later (or never) moves no pill.
28
+ */
29
+ counted?: boolean;
30
+ };
31
+ export declare function PillGroup({ label, options, value, onValueChange, allLabel, className, }: Omit<PillFilterProps, 'options'> & {
32
+ options: readonly PillGroupOption[];
33
+ }): import("react").JSX.Element;
@@ -12,6 +12,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
12
12
  // button with aria-pressed.
13
13
  import { cn } from 'cn';
14
14
  import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
15
+ import { navCountText } from './app-shell-nav.js';
15
16
  // The All pill's value inside the group: Base UI's toggles need one that
16
17
  // isn't empty, and '' is what the app's filter calls All.
17
18
  const ALL = '__all__';
@@ -20,6 +21,16 @@ const ALL = '__all__';
20
21
  const PILL_CLASS = 'rounded-full px-3 aria-pressed:border-primary aria-pressed:bg-primary aria-pressed:text-primary-foreground ' +
21
22
  'aria-pressed:hover:bg-primary/90 aria-pressed:hover:text-primary-foreground';
22
23
  export function PillFilter({ label, options, value, onValueChange, allLabel = 'All', className }) {
24
+ return (_jsx(PillGroup, { label: label, options: options, value: value, onValueChange: onValueChange, allLabel: allLabel, className: className }));
25
+ }
26
+ // The count as drawn: navCountText's rules (nothing at 0 or while loading,
27
+ // "99+" past 99), shared with the sidebar's counts.
28
+ function countText(count) {
29
+ return navCountText(count ?? undefined);
30
+ }
31
+ // PillFilter's pills, with an optional count per pill. Internal: DataTable's
32
+ // views draw theirs with it (data-table-tools.tsx's ViewPills).
33
+ export function PillGroup({ label, options, value, onValueChange, allLabel = 'All', className, }) {
23
34
  const pills = allLabel === null ? options : [{ value: ALL, label: allLabel }, ...options];
24
35
  const pressed = value === '' && allLabel !== null ? ALL : value;
25
36
  return (_jsx(ToggleGroup, { "aria-label": label, variant: "outline", size: "sm", spacing: 1, className: cn('flex-wrap', className), value: [pressed], onValueChange: (next) => {
@@ -28,5 +39,15 @@ export function PillFilter({ label, options, value, onValueChange, allLabel = 'A
28
39
  if (chosen === undefined || chosen === pressed)
29
40
  return;
30
41
  onValueChange(chosen === ALL ? '' : chosen);
31
- }, children: pills.map((option) => (_jsx(ToggleGroupItem, { value: option.value, className: PILL_CLASS, children: option.label }, option.value))) }));
42
+ }, children: pills.map((option) => {
43
+ const count = countText(option.count);
44
+ return (_jsx(ToggleGroupItem, { value: option.value, "aria-label": count !== undefined ? `${option.label}, ${count}` : undefined, className: PILL_CLASS, children: option.counted || count !== undefined ? _jsx(CountedLabel, { label: option.label, count: count, counted: option.counted }) : option.label }, option.value));
45
+ }) }));
46
+ }
47
+ // "Needs a Look · 3". A hidden copy with a two-digit count (::after, not in
48
+ // the DOM's text or the name) holds the pill at that width while the count
49
+ // loads, is 0 or is one digit, the way EntityView's tab names hold their
50
+ // bold width; the label sits centred in it.
51
+ function CountedLabel({ label, count, counted }) {
52
+ return (_jsx("span", { "data-slot": "pill-label", "data-reserve": counted ? `${label} · 00` : undefined, className: "inline-grid after:invisible after:col-start-1 after:row-start-1 after:h-0 after:tabular-nums after:content-[attr(data-reserve)]", children: _jsx("span", { "data-slot": "pill-text", className: "col-start-1 row-start-1 justify-self-center tabular-nums", children: count !== undefined ? `${label} · ${count}` : label }) }));
32
53
  }
@@ -0,0 +1,22 @@
1
+ import type { RatingScoreGlyph } from './rating-score.js';
2
+ /** How a RatingInput's value was set: a click or tap, or the keyboard. */
3
+ export type RatingInputSource = 'pointer' | 'keyboard';
4
+ export type RatingInputProps = {
5
+ /** How many stars are set, 1…max, or `null` for none (rounded, clamped). */
6
+ value: number | null;
7
+ /** How many stars it has. Defaults to 5. */
8
+ max?: number;
9
+ /** Stars (the default) or hearts. */
10
+ glyph?: RatingScoreGlyph;
11
+ /** The new value: a star's number, or `null` when the set one was pressed again. */
12
+ onChange: (value: number | null, source: RatingInputSource) => void;
13
+ /** The group's accessible name: the field's label ("My Rating"). */
14
+ label: string;
15
+ disabled?: boolean;
16
+ /** The line describing it (a field's error or hint). */
17
+ 'aria-describedby'?: string;
18
+ invalid?: boolean;
19
+ id?: string;
20
+ className?: string;
21
+ };
22
+ export declare function RatingInput({ value, max, glyph, onChange, label, disabled, invalid, id, className, 'aria-describedby': describedBy, }: RatingInputProps): import("react").JSX.Element;