@tristan2828/ui-foundation 4.127.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.
- package/conventions/docs/add-an-entity.md +52 -16
- package/conventions/docs/design-language.md +25 -8
- package/dist/components/app/edit-in-place-store.d.ts +2 -3
- package/dist/components/app/edit-in-place-store.js +53 -9
- package/dist/components/app/entity-form.d.ts +9 -1
- package/dist/components/app/entity-form.js +9 -2
- package/dist/components/app/equal-items.d.ts +2 -1
- package/dist/components/app/equal-items.js +9 -25
- package/dist/components/app/form-conflict-notice.d.ts +8 -0
- package/dist/components/app/form-conflict-notice.js +15 -0
- package/dist/components/app/form-dialog.d.ts +8 -1
- package/dist/components/app/form-dialog.js +9 -2
- package/dist/components/app/milkdown-editor.js +21 -329
- package/dist/components/app/notify.d.ts +18 -1
- package/dist/components/app/notify.js +26 -3
- package/dist/components/app/page-restore.js +1 -1
- package/dist/components/app/rich-text-box-anchor.d.ts +6 -0
- package/dist/components/app/rich-text-box-anchor.js +8 -0
- package/dist/components/app/rich-text-heading-view.d.ts +4 -0
- package/dist/components/app/rich-text-heading-view.js +91 -0
- package/dist/components/app/rich-text-link-box.d.ts +9 -0
- package/dist/components/app/rich-text-link-box.js +40 -0
- package/dist/components/app/rich-text-links.d.ts +14 -0
- package/dist/components/app/rich-text-links.js +92 -0
- package/dist/components/app/rich-text-page-box.d.ts +10 -0
- package/dist/components/app/rich-text-page-box.js +45 -0
- package/dist/components/app/rich-text-task-item-view.d.ts +4 -0
- package/dist/components/app/rich-text-task-item-view.js +59 -0
- package/dist/components/app/rich-text-toggle-heading.js +1 -1
- package/dist/components/app/step-row.d.ts +15 -0
- package/dist/components/app/step-row.js +27 -0
- package/dist/components/app/step-track.d.ts +82 -0
- package/dist/components/app/step-track.js +98 -0
- package/dist/components/ui/sonner.js +1 -1
- package/dist/hooks/use-form-version.d.ts +101 -0
- package/dist/hooks/use-form-version.js +187 -0
- package/dist/hooks/use-record-update.d.ts +2 -7
- package/dist/hooks/use-record-update.js +2 -11
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/lib/refusal.d.ts +9 -0
- package/dist/lib/refusal.js +19 -0
- 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
|
|
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
|
|
22
|
-
// task-list item renders a real checkbox
|
|
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
|
|
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
|
|
@@ -80,7 +83,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
80
83
|
// - `pageLink`: links the app marks as its pages drawn as page links
|
|
81
84
|
// (rich-text-page-links.ts), opened in this tab; `onCreatePage`: "/page"
|
|
82
85
|
// and Turn into page make one through the app and link it (a title box,
|
|
83
|
-
//
|
|
86
|
+
// rich-text-page-box.tsx). The Markdown stays a plain link.
|
|
84
87
|
import { useEffect, useId, useRef, useState } from 'react';
|
|
85
88
|
import { createPortal } from 'react-dom';
|
|
86
89
|
import { useInRouterContext, useNavigate } from 'react-router';
|
|
@@ -94,15 +97,12 @@ import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
|
|
|
94
97
|
import { $markSchema, $nodeSchema, $prose, $remark, getMarkdown } from '@milkdown/kit/utils';
|
|
95
98
|
import { cn } from 'cn';
|
|
96
99
|
import { toast } from 'sonner';
|
|
97
|
-
import {
|
|
98
|
-
import { Field, FieldError, FieldLabel } from '../ui/field.js';
|
|
99
|
-
import { Input } from '../ui/input.js';
|
|
100
|
-
import { Popover, PopoverContent } from '../ui/popover.js';
|
|
100
|
+
import { Popover } from '../ui/popover.js';
|
|
101
101
|
import { acceptAttribute } from '../../lib/image-file.js';
|
|
102
|
-
import { linkHref
|
|
103
|
-
import { messageOf } from '
|
|
102
|
+
import { linkHref } from '../../lib/link-href.js';
|
|
103
|
+
import { messageOf } from '../../lib/refusal.js';
|
|
104
104
|
import { restorePage } from './page-restore.js';
|
|
105
|
-
import { insertPageLink,
|
|
105
|
+
import { insertPageLink, pageLinksPlugin, pendingPagePlugin, refreshPageLinks, setPendingPage, } from './rich-text-page-links.js';
|
|
106
106
|
import { passEscapeThrough } from './escape-passthrough.js';
|
|
107
107
|
import { calloutHandler, remarkCalloutNodes } from '../../lib/markdown-callout.js';
|
|
108
108
|
import { formatTableWidths, remarkTableWidths } from '../../lib/markdown-table-widths.js';
|
|
@@ -112,15 +112,21 @@ import { MarkdownMergeError, markdownStyle, mergeMarkdown } from '../../lib/mark
|
|
|
112
112
|
import { holdPendingEdit } from '../../lib/pending-edits.js';
|
|
113
113
|
import { foldStore, listenForOtherTabs } from '../../hooks/fold-store.js';
|
|
114
114
|
import { toggleFold } from '../../lib/markdown-fold.js';
|
|
115
|
-
import { DEFAULT_HEADING_LEVEL
|
|
116
|
-
import { foldPlugin,
|
|
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';
|
|
117
123
|
import { RichTextFloatingToolbar } from './rich-text-floating-toolbar.js';
|
|
118
124
|
import { formatOn, tableAt, toggleFormat } from './rich-text-formats.js';
|
|
119
125
|
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
|
|
120
126
|
import { calloutKind, calloutView, tableView } from './rich-text-node-views.js';
|
|
121
127
|
import { droppedFiles, imageUploadPlugin, pastedImages, uploadImages, uploadPlaceholders } from './rich-text-image-upload.js';
|
|
122
128
|
import { handleShortcut } from './rich-text-shortcuts.js';
|
|
123
|
-
import { splitTaskItem,
|
|
129
|
+
import { splitTaskItem, taskInputRule } from './rich-text-tasks.js';
|
|
124
130
|
import { typedInputRules } from './rich-text-input-rules.js';
|
|
125
131
|
import { edges } from './rich-text-edges.js';
|
|
126
132
|
import { withEmptyParagraphChildren } from './rich-text-empty-paragraph.js';
|
|
@@ -283,224 +289,6 @@ function shownKey(state) {
|
|
|
283
289
|
return parts.join('|');
|
|
284
290
|
}
|
|
285
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.";
|
|
286
|
-
// A heading: the element `headingLevel` gives its level, the look its
|
|
287
|
-
// level has. Marked as a band for PROSE_INSET (`#` and `##`).
|
|
288
|
-
//
|
|
289
|
-
// With `foldKey` (`onFold`), a toggle heading sits beside its fold button,
|
|
290
|
-
// as in <Markdown>: the look on the two together, the button out of the
|
|
291
|
-
// tab order (Ctrl/Cmd+Alt+[ and ] and NotesOutline are the keyboard's
|
|
292
|
-
// way), kept invisible where there's nothing under the heading to fold,
|
|
293
|
-
// or the heading isn't at the top level. A plain heading has no button
|
|
294
|
-
// and no room for one; its fold id still marks it, for NotesOutline.
|
|
295
|
-
function headingView(node, top, textTop, decorations, onFold) {
|
|
296
|
-
const level = Number(node.attrs.level);
|
|
297
|
-
const heading = document.createElement(headingTag(level, top, textTop));
|
|
298
|
-
const sameLevel = (next) => next.type === node.type && next.attrs.level === node.attrs.level && Boolean(next.attrs.toggle) === Boolean(node.attrs.toggle);
|
|
299
|
-
if (node.attrs.toggle)
|
|
300
|
-
heading.dataset.toggle = '';
|
|
301
|
-
if (!onFold || !node.attrs.toggle) {
|
|
302
|
-
heading.className = headingClass(level);
|
|
303
|
-
if (headingBand(level))
|
|
304
|
-
heading.dataset.band = '';
|
|
305
|
-
const mark = (decorations) => {
|
|
306
|
-
const spec = onFold ? foldSpecOf(decorations) : null;
|
|
307
|
-
if (spec)
|
|
308
|
-
heading.dataset.foldId = spec.id;
|
|
309
|
-
else
|
|
310
|
-
delete heading.dataset.foldId;
|
|
311
|
-
};
|
|
312
|
-
mark(decorations);
|
|
313
|
-
return {
|
|
314
|
-
dom: heading,
|
|
315
|
-
contentDOM: heading,
|
|
316
|
-
update: (next, decorations) => {
|
|
317
|
-
if (!sameLevel(next))
|
|
318
|
-
return false;
|
|
319
|
-
mark(decorations);
|
|
320
|
-
return true;
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
const dom = document.createElement('div');
|
|
325
|
-
dom.dataset.toggle = '';
|
|
326
|
-
dom.className = cn(FOLD_HEADING, headingClass(level));
|
|
327
|
-
if (headingBand(level))
|
|
328
|
-
dom.dataset.band = '';
|
|
329
|
-
heading.className = 'min-w-0 flex-1';
|
|
330
|
-
const button = document.createElement('button');
|
|
331
|
-
button.type = 'button';
|
|
332
|
-
button.tabIndex = -1;
|
|
333
|
-
button.contentEditable = 'false';
|
|
334
|
-
button.dataset.slot = 'fold-button';
|
|
335
|
-
const chevron = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
336
|
-
chevron.setAttribute('viewBox', '0 0 24 24');
|
|
337
|
-
chevron.setAttribute('aria-hidden', 'true');
|
|
338
|
-
chevron.innerHTML =
|
|
339
|
-
'<path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />';
|
|
340
|
-
button.append(chevron);
|
|
341
|
-
dom.append(button, heading);
|
|
342
|
-
let spec = null;
|
|
343
|
-
const render = (decorations) => {
|
|
344
|
-
spec = foldSpecOf(decorations);
|
|
345
|
-
button.className = cn(FOLD_BUTTON, !spec?.foldable && 'invisible');
|
|
346
|
-
chevron.setAttribute('class', cn('size-4 transition-transform', spec?.folded && '-rotate-90'));
|
|
347
|
-
button.setAttribute('aria-expanded', String(!spec?.folded));
|
|
348
|
-
button.setAttribute('aria-label', spec?.label || 'Section');
|
|
349
|
-
if (spec)
|
|
350
|
-
dom.dataset.foldId = spec.id;
|
|
351
|
-
else
|
|
352
|
-
delete dom.dataset.foldId;
|
|
353
|
-
};
|
|
354
|
-
render(decorations);
|
|
355
|
-
// A press keeps the caret where it is.
|
|
356
|
-
button.addEventListener('mousedown', (event) => event.preventDefault());
|
|
357
|
-
button.addEventListener('click', () => {
|
|
358
|
-
if (spec?.foldable)
|
|
359
|
-
onFold(spec.id);
|
|
360
|
-
});
|
|
361
|
-
return {
|
|
362
|
-
dom,
|
|
363
|
-
contentDOM: heading,
|
|
364
|
-
update: (next, decorations) => {
|
|
365
|
-
if (!sameLevel(next))
|
|
366
|
-
return false;
|
|
367
|
-
render(decorations);
|
|
368
|
-
return true;
|
|
369
|
-
},
|
|
370
|
-
stopEvent: (event) => button.contains(event.target),
|
|
371
|
-
ignoreMutation: (mutation) => mutation.type !== 'selection' && !heading.contains(mutation.target),
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
// A task-list item: its checkbox toggles `checked`. Any other list item
|
|
375
|
-
// renders as Milkdown's own.
|
|
376
|
-
function taskItemView(node, view, getPos) {
|
|
377
|
-
const dom = document.createElement('li');
|
|
378
|
-
const box = document.createElement('input');
|
|
379
|
-
box.type = 'checkbox';
|
|
380
|
-
box.contentEditable = 'false';
|
|
381
|
-
box.tabIndex = -1;
|
|
382
|
-
box.setAttribute('aria-label', 'Done');
|
|
383
|
-
const contentDOM = document.createElement('div');
|
|
384
|
-
// Takes the row's width, so an empty item's caret and placeholder show.
|
|
385
|
-
contentDOM.className = 'min-w-0 flex-1';
|
|
386
|
-
dom.append(taskBoxHit(box), contentDOM);
|
|
387
|
-
dom.className = TASK_ROW;
|
|
388
|
-
dom.dataset.itemType = 'task';
|
|
389
|
-
let current = node;
|
|
390
|
-
const render = () => {
|
|
391
|
-
box.checked = Boolean(current.attrs.checked);
|
|
392
|
-
dom.dataset.checked = String(Boolean(current.attrs.checked));
|
|
393
|
-
};
|
|
394
|
-
render();
|
|
395
|
-
box.addEventListener('mousedown', (event) => event.preventDefault());
|
|
396
|
-
// The browser's own toggle is left to happen (cancelling a checkbox's
|
|
397
|
-
// click puts its old state back after this handler), and the document
|
|
398
|
-
// follows it.
|
|
399
|
-
box.addEventListener('click', () => {
|
|
400
|
-
const pos = getPos();
|
|
401
|
-
if (pos === undefined || !view.editable)
|
|
402
|
-
return;
|
|
403
|
-
view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, checked: !current.attrs.checked }));
|
|
404
|
-
});
|
|
405
|
-
return {
|
|
406
|
-
dom,
|
|
407
|
-
contentDOM,
|
|
408
|
-
update: (next) => {
|
|
409
|
-
if (next.type !== current.type || next.attrs.checked == null)
|
|
410
|
-
return false;
|
|
411
|
-
current = next;
|
|
412
|
-
render();
|
|
413
|
-
return true;
|
|
414
|
-
},
|
|
415
|
-
stopEvent: (event) => event.target === box || event.target === box.parentElement,
|
|
416
|
-
ignoreMutation: (mutation) => mutation.target === box || mutation.target === box.parentElement,
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
// The task-list item the caret is in, ticked or unticked. False when the
|
|
420
|
-
// caret isn't in one.
|
|
421
|
-
function toggleTaskItem(view) {
|
|
422
|
-
const { $from } = view.state.selection;
|
|
423
|
-
for (let depth = $from.depth; depth > 0; depth--) {
|
|
424
|
-
const node = $from.node(depth);
|
|
425
|
-
if (node.type.name === 'list_item' && node.attrs.checked != null) {
|
|
426
|
-
view.dispatch(view.state.tr.setNodeMarkup($from.before(depth), undefined, { ...node.attrs, checked: !node.attrs.checked }));
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
function linkTarget(state) {
|
|
433
|
-
const link = state.schema.marks.link;
|
|
434
|
-
const { from, to, empty, $from } = state.selection;
|
|
435
|
-
if (!empty) {
|
|
436
|
-
let href = '';
|
|
437
|
-
state.doc.nodesBetween(from, to, (node) => {
|
|
438
|
-
const mark = link.isInSet(node.marks);
|
|
439
|
-
if (mark && !href)
|
|
440
|
-
href = String(mark.attrs.href);
|
|
441
|
-
});
|
|
442
|
-
return { from, to, href };
|
|
443
|
-
}
|
|
444
|
-
const mark = link.isInSet($from.marks());
|
|
445
|
-
if (!mark)
|
|
446
|
-
return { from, to, href: '' };
|
|
447
|
-
const start = $from.start();
|
|
448
|
-
let target = { from, to, href: String(mark.attrs.href) };
|
|
449
|
-
let runFrom = -1;
|
|
450
|
-
$from.parent.forEach((child, offset) => {
|
|
451
|
-
const childFrom = start + offset;
|
|
452
|
-
const childTo = childFrom + child.nodeSize;
|
|
453
|
-
if (!mark.isInSet(child.marks)) {
|
|
454
|
-
runFrom = -1;
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
if (runFrom < 0)
|
|
458
|
-
runFrom = childFrom;
|
|
459
|
-
if (runFrom <= from && from <= childTo)
|
|
460
|
-
target = { from: runFrom, to: childTo, href: target.href };
|
|
461
|
-
});
|
|
462
|
-
return target;
|
|
463
|
-
}
|
|
464
|
-
// A plain click (or a tap) on a link opens it in a new tab, the way the
|
|
465
|
-
// read view's links open (markdown.tsx), so notes that are always the
|
|
466
|
-
// editor still work as notes. Not when the click chose words (a drag ends
|
|
467
|
-
// in a click too), extends the selection (Shift) or is Alt's; the address
|
|
468
|
-
// goes through linkHref again, so a link that came in with the Markdown
|
|
469
|
-
// can't run code (`javascript:`) either: that one stays text to click
|
|
470
|
-
// into. Read-only too, where the browser would otherwise follow it in this
|
|
471
|
-
// tab. To edit a link's words, put the caret in them from the keyboard or
|
|
472
|
-
// drag over them; Ctrl/Cmd+K edits its address.
|
|
473
|
-
//
|
|
474
|
-
// A page link (`pageLink`) opens its page in this tab instead (`open`:
|
|
475
|
-
// the router's, when there is one), and a removed page's link opens
|
|
476
|
-
// nothing.
|
|
477
|
-
function followLink(view, event, pages) {
|
|
478
|
-
if (event.button !== 0 || event.shiftKey || event.altKey)
|
|
479
|
-
return false;
|
|
480
|
-
const anchor = event.target instanceof Element ? event.target.closest('a[href]') : null;
|
|
481
|
-
if (!anchor || !view.dom.contains(anchor))
|
|
482
|
-
return false;
|
|
483
|
-
if (!view.state.selection.empty)
|
|
484
|
-
return false;
|
|
485
|
-
const written = anchor.getAttribute('href') ?? '';
|
|
486
|
-
const page = pageLinkInfo(pages.resolve, written);
|
|
487
|
-
if (page) {
|
|
488
|
-
event.preventDefault();
|
|
489
|
-
if (page.removed)
|
|
490
|
-
return false;
|
|
491
|
-
const href = linkHref(written);
|
|
492
|
-
if (!href)
|
|
493
|
-
return false;
|
|
494
|
-
pages.open(href);
|
|
495
|
-
return true;
|
|
496
|
-
}
|
|
497
|
-
const href = linkHref(written);
|
|
498
|
-
if (!href)
|
|
499
|
-
return false;
|
|
500
|
-
event.preventDefault();
|
|
501
|
-
window.open(href, '_blank', 'noopener,noreferrer');
|
|
502
|
-
return true;
|
|
503
|
-
}
|
|
504
292
|
// The router's navigate, handed to the editor's callbacks: rendered only
|
|
505
293
|
// inside a router, so an editor outside one still works (a page link
|
|
506
294
|
// then loads the page).
|
|
@@ -514,32 +302,6 @@ function NavigateBridge({ targetRef }) {
|
|
|
514
302
|
}, [navigate, targetRef]);
|
|
515
303
|
return null;
|
|
516
304
|
}
|
|
517
|
-
// Sets (or, with `href` empty, removes) the link on the target. With
|
|
518
|
-
// nothing selected and no link there, the address goes in as the link's
|
|
519
|
-
// own text.
|
|
520
|
-
function applyLink(view, target, href) {
|
|
521
|
-
const link = view.state.schema.marks.link;
|
|
522
|
-
const tr = view.state.tr;
|
|
523
|
-
if (target.from === target.to) {
|
|
524
|
-
if (!href)
|
|
525
|
-
return;
|
|
526
|
-
tr.insertText(href, target.from).addMark(target.from, target.from + href.length, link.create({ href }));
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
tr.removeMark(target.from, target.to, link);
|
|
530
|
-
if (href)
|
|
531
|
-
tr.addMark(target.from, target.to, link.create({ href }));
|
|
532
|
-
}
|
|
533
|
-
view.dispatch(tr.scrollIntoView());
|
|
534
|
-
}
|
|
535
|
-
// A box's place: a point in the text.
|
|
536
|
-
function anchorAt(view, pos) {
|
|
537
|
-
const point = view.coordsAtPos(pos);
|
|
538
|
-
return {
|
|
539
|
-
getBoundingClientRect: () => new DOMRect(point.left, point.top, 0, point.bottom - point.top),
|
|
540
|
-
contextElement: view.dom,
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
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, }) {
|
|
544
306
|
const rootRef = useRef(null);
|
|
545
307
|
const editorRef = useRef(null);
|
|
@@ -1478,73 +1240,3 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1478
1240
|
closeLink();
|
|
1479
1241
|
} })) })] }));
|
|
1480
1242
|
}
|
|
1481
|
-
// The link box: the address, Apply, and Remove link for an existing one.
|
|
1482
|
-
// Enter (Ctrl/Cmd+Enter too) applies the link and stays its own: editing
|
|
1483
|
-
// in place listens for Ctrl/Cmd+Enter through the portal, and would save
|
|
1484
|
-
// the field without it. Esc is the popover's: it closes the box only.
|
|
1485
|
-
function LinkForm({ box, onApply }) {
|
|
1486
|
-
const [typed, setTyped] = useState(box.href);
|
|
1487
|
-
const [error, setError] = useState(null);
|
|
1488
|
-
const inputRef = useRef(null);
|
|
1489
|
-
const inputId = useId();
|
|
1490
|
-
const errorId = `${inputId}-error`;
|
|
1491
|
-
const apply = () => {
|
|
1492
|
-
const href = linkHref(typed);
|
|
1493
|
-
if (href === null) {
|
|
1494
|
-
setError(linkRefusal(typed) === 'whitespace'
|
|
1495
|
-
? 'An address has no spaces. Remove them, or write each as %20.'
|
|
1496
|
-
: 'Enter a web or email address, like https://example.com.');
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
onApply(href);
|
|
1500
|
-
};
|
|
1501
|
-
const onKeyDown = (event) => {
|
|
1502
|
-
if (event.key === 'Enter' && event.target === inputRef.current) {
|
|
1503
|
-
event.preventDefault();
|
|
1504
|
-
event.stopPropagation();
|
|
1505
|
-
apply();
|
|
1506
|
-
}
|
|
1507
|
-
};
|
|
1508
|
-
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) => {
|
|
1509
|
-
setTyped(event.target.value);
|
|
1510
|
-
setError(null);
|
|
1511
|
-
} }), 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" }))] })] }));
|
|
1512
|
-
}
|
|
1513
|
-
// The new page's title box: the title (the selected words to start with),
|
|
1514
|
-
// and Create page. While the app makes the page it waits, its controls
|
|
1515
|
-
// held; a refusal shows under the title, in the gateway's words, and the
|
|
1516
|
-
// text is left as it was. Enter creates; Esc is the popover's, and closes
|
|
1517
|
-
// it (not while the app is still working).
|
|
1518
|
-
function PageForm({ box, busy, onCreate }) {
|
|
1519
|
-
const [typed, setTyped] = useState(box.title);
|
|
1520
|
-
const [error, setError] = useState(null);
|
|
1521
|
-
const inputRef = useRef(null);
|
|
1522
|
-
const inputId = useId();
|
|
1523
|
-
const errorId = `${inputId}-error`;
|
|
1524
|
-
const create = () => {
|
|
1525
|
-
const title = typed.replace(/\s+/g, ' ').trim();
|
|
1526
|
-
if (!title) {
|
|
1527
|
-
setError('Give the page a title.');
|
|
1528
|
-
return;
|
|
1529
|
-
}
|
|
1530
|
-
setError(null);
|
|
1531
|
-
void onCreate(title).then((refused) => {
|
|
1532
|
-
if (refused) {
|
|
1533
|
-
setError(refused);
|
|
1534
|
-
inputRef.current?.focus();
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
1537
|
-
};
|
|
1538
|
-
const onKeyDown = (event) => {
|
|
1539
|
-
if (event.key === 'Enter' && event.target === inputRef.current) {
|
|
1540
|
-
event.preventDefault();
|
|
1541
|
-
event.stopPropagation();
|
|
1542
|
-
if (!busy)
|
|
1543
|
-
create();
|
|
1544
|
-
}
|
|
1545
|
-
};
|
|
1546
|
-
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) => {
|
|
1547
|
-
setTyped(event.target.value);
|
|
1548
|
-
setError(null);
|
|
1549
|
-
} }), 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' }) })] }));
|
|
1550
|
-
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
:
|
|
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 '
|
|
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 {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as ProseNode } from '@milkdown/kit/prose/model';
|
|
2
|
+
import type { Decoration, NodeView } from '@milkdown/kit/prose/view';
|
|
3
|
+
import { type HeadingLevel } from './prose-look.js';
|
|
4
|
+
export declare function headingView(node: ProseNode, top: HeadingLevel, textTop: number, decorations: readonly Decoration[], onFold?: (id: string) => void): NodeView;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { cn } from 'cn';
|
|
2
|
+
import { FOLD_BUTTON, FOLD_HEADING, headingBand, headingClass, headingTag } from './prose-look.js';
|
|
3
|
+
import { foldSpecOf } from './rich-text-fold.js';
|
|
4
|
+
// A heading: the element `headingLevel` gives its level, the look its
|
|
5
|
+
// level has. Marked as a band for PROSE_INSET (`#` and `##`).
|
|
6
|
+
//
|
|
7
|
+
// With `foldKey` (`onFold`), a toggle heading sits beside its fold button,
|
|
8
|
+
// as in <Markdown>: the look on the two together, the button out of the
|
|
9
|
+
// tab order (Ctrl/Cmd+Alt+[ and ] and NotesOutline are the keyboard's
|
|
10
|
+
// way), kept invisible where there's nothing under the heading to fold,
|
|
11
|
+
// or the heading isn't at the top level. A plain heading has no button
|
|
12
|
+
// and no room for one; its fold id still marks it, for NotesOutline.
|
|
13
|
+
export function headingView(node, top, textTop, decorations, onFold) {
|
|
14
|
+
const level = Number(node.attrs.level);
|
|
15
|
+
const heading = document.createElement(headingTag(level, top, textTop));
|
|
16
|
+
const sameLevel = (next) => next.type === node.type && next.attrs.level === node.attrs.level && Boolean(next.attrs.toggle) === Boolean(node.attrs.toggle);
|
|
17
|
+
if (node.attrs.toggle)
|
|
18
|
+
heading.dataset.toggle = '';
|
|
19
|
+
if (!onFold || !node.attrs.toggle) {
|
|
20
|
+
heading.className = headingClass(level);
|
|
21
|
+
if (headingBand(level))
|
|
22
|
+
heading.dataset.band = '';
|
|
23
|
+
const mark = (decorations) => {
|
|
24
|
+
const spec = onFold ? foldSpecOf(decorations) : null;
|
|
25
|
+
if (spec)
|
|
26
|
+
heading.dataset.foldId = spec.id;
|
|
27
|
+
else
|
|
28
|
+
delete heading.dataset.foldId;
|
|
29
|
+
};
|
|
30
|
+
mark(decorations);
|
|
31
|
+
return {
|
|
32
|
+
dom: heading,
|
|
33
|
+
contentDOM: heading,
|
|
34
|
+
update: (next, decorations) => {
|
|
35
|
+
if (!sameLevel(next))
|
|
36
|
+
return false;
|
|
37
|
+
mark(decorations);
|
|
38
|
+
return true;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const dom = document.createElement('div');
|
|
43
|
+
dom.dataset.toggle = '';
|
|
44
|
+
dom.className = cn(FOLD_HEADING, headingClass(level));
|
|
45
|
+
if (headingBand(level))
|
|
46
|
+
dom.dataset.band = '';
|
|
47
|
+
heading.className = 'min-w-0 flex-1';
|
|
48
|
+
const button = document.createElement('button');
|
|
49
|
+
button.type = 'button';
|
|
50
|
+
button.tabIndex = -1;
|
|
51
|
+
button.contentEditable = 'false';
|
|
52
|
+
button.dataset.slot = 'fold-button';
|
|
53
|
+
const chevron = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
54
|
+
chevron.setAttribute('viewBox', '0 0 24 24');
|
|
55
|
+
chevron.setAttribute('aria-hidden', 'true');
|
|
56
|
+
chevron.innerHTML =
|
|
57
|
+
'<path d="m6 9 6 6 6-6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />';
|
|
58
|
+
button.append(chevron);
|
|
59
|
+
dom.append(button, heading);
|
|
60
|
+
let spec = null;
|
|
61
|
+
const render = (decorations) => {
|
|
62
|
+
spec = foldSpecOf(decorations);
|
|
63
|
+
button.className = cn(FOLD_BUTTON, !spec?.foldable && 'invisible');
|
|
64
|
+
chevron.setAttribute('class', cn('size-4 transition-transform', spec?.folded && '-rotate-90'));
|
|
65
|
+
button.setAttribute('aria-expanded', String(!spec?.folded));
|
|
66
|
+
button.setAttribute('aria-label', spec?.label || 'Section');
|
|
67
|
+
if (spec)
|
|
68
|
+
dom.dataset.foldId = spec.id;
|
|
69
|
+
else
|
|
70
|
+
delete dom.dataset.foldId;
|
|
71
|
+
};
|
|
72
|
+
render(decorations);
|
|
73
|
+
// A press keeps the caret where it is.
|
|
74
|
+
button.addEventListener('mousedown', (event) => event.preventDefault());
|
|
75
|
+
button.addEventListener('click', () => {
|
|
76
|
+
if (spec?.foldable)
|
|
77
|
+
onFold(spec.id);
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
dom,
|
|
81
|
+
contentDOM: heading,
|
|
82
|
+
update: (next, decorations) => {
|
|
83
|
+
if (!sameLevel(next))
|
|
84
|
+
return false;
|
|
85
|
+
render(decorations);
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
stopEvent: (event) => button.contains(event.target),
|
|
89
|
+
ignoreMutation: (mutation) => mutation.type !== 'selection' && !heading.contains(mutation.target),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BoxAnchor } from './rich-text-box-anchor.js';
|
|
2
|
+
import type { LinkTarget } from './rich-text-links.js';
|
|
3
|
+
export type LinkBox = LinkTarget & {
|
|
4
|
+
anchor: BoxAnchor;
|
|
5
|
+
};
|
|
6
|
+
export declare function LinkForm({ box, onApply }: {
|
|
7
|
+
box: LinkBox;
|
|
8
|
+
onApply: (href: string) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|