@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.
- package/conventions/docs/add-an-entity.md +154 -34
- package/conventions/docs/cell-patterns.md +88 -41
- package/conventions/docs/design-language.md +62 -13
- package/dist/api/contracts.d.ts +8 -1
- package/dist/api/gateway/errors.js +4 -0
- package/dist/api/schema.d.ts +9 -0
- package/dist/components/app/data-table-tools.d.ts +12 -0
- package/dist/components/app/data-table-tools.js +2 -2
- package/dist/components/app/data-table.d.ts +2 -1
- package/dist/components/app/data-table.js +1 -1
- package/dist/components/app/edit-in-place-presets.d.ts +51 -1
- package/dist/components/app/edit-in-place-presets.js +30 -0
- package/dist/components/app/edit-in-place-store.d.ts +33 -7
- package/dist/components/app/edit-in-place-store.js +112 -20
- package/dist/components/app/edit-in-place.d.ts +11 -0
- package/dist/components/app/editable-value.js +43 -8
- package/dist/components/app/entity-form.d.ts +9 -1
- package/dist/components/app/entity-form.js +9 -2
- package/dist/components/app/entity-view.js +5 -1
- package/dist/components/app/equal-items.d.ts +33 -6
- package/dist/components/app/equal-items.js +42 -7
- package/dist/components/app/error-state.js +1 -0
- 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 +24 -331
- 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/pill-filter.d.ts +16 -0
- package/dist/components/app/pill-filter.js +22 -1
- package/dist/components/app/rating-input.d.ts +22 -0
- package/dist/components/app/rating-input.js +65 -0
- package/dist/components/app/rating-score.d.ts +2 -1
- package/dist/components/app/rating-score.js +2 -6
- 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-editor.d.ts +4 -2
- package/dist/components/app/rich-text-editor.js +3 -2
- 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-keyboard-bar.js +3 -2
- 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/rich-text-toolbar.js +1 -1
- package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
- package/dist/components/app/rich-text-tools-bar.js +2 -2
- 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 +15 -8
- package/dist/hooks/use-record-update.js +19 -14
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -0
- package/dist/lib/markdown-merge.d.ts +12 -0
- package/dist/lib/markdown-merge.js +90 -0
- package/dist/lib/rating-glyphs.d.ts +3 -0
- package/dist/lib/rating-glyphs.js +7 -0
- package/dist/lib/refusal.d.ts +9 -0
- package/dist/lib/refusal.js +19 -0
- package/openapi/foundation.yaml +12 -0
- package/package.json +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A score out of a few, set by clicking a star (cell pattern 9, 4.127):
|
|
3
|
+
// RatingScore's glyphs and tokens, as a control. "My Rating" as ★★★★☆,
|
|
4
|
+
// where a click on the second star makes it 2.
|
|
5
|
+
//
|
|
6
|
+
// - One radio group named by `label` (shadcn's RadioGroup on Base UI): one
|
|
7
|
+
// tab stop, the arrow keys move along the stars and set the value, Space
|
|
8
|
+
// or a click sets the star it's on. Each star is a radio named "2 of 5".
|
|
9
|
+
// - Pressing the star that's already set clears it (`null`): a click, or
|
|
10
|
+
// Space on it. Nothing else can clear it, so a slip of the arrow keys
|
|
11
|
+
// never empties a score.
|
|
12
|
+
// - Hovering previews: the stars up to the pointer fill as they would on a
|
|
13
|
+
// click, and leaving puts the value back. A mouse's only: a finger has
|
|
14
|
+
// no hover, and a tap's preview would stick.
|
|
15
|
+
// - Drawn as RatingScore draws: the filled glyphs in `foreground`, the
|
|
16
|
+
// rest outlines in `muted-foreground` (3:1 on the page in both themes),
|
|
17
|
+
// so the count carries the value and survives greyscale.
|
|
18
|
+
// - Compact on a mouse's screen (24px targets, the glyphs RatingScore's
|
|
19
|
+
// 16px), 44px targets on a touch screen (`pointer-coarse`), the glyphs
|
|
20
|
+
// 20px. Fixed-size: as wide at 1 as at 5, so setting it moves nothing.
|
|
21
|
+
// - `onChange`'s second argument says how it was set: `pointer` (a click
|
|
22
|
+
// or a tap, a deliberate pick) or `keyboard` (an arrow, which may be one
|
|
23
|
+
// of several on the way). `inPlace.rating` saves a pick at once and an
|
|
24
|
+
// arrow's value a pause after the last one.
|
|
25
|
+
import { Radio } from '@base-ui/react/radio';
|
|
26
|
+
import { useRef, useState } from 'react';
|
|
27
|
+
import { cn } from 'cn';
|
|
28
|
+
import { RadioGroup } from '../ui/radio-group.js';
|
|
29
|
+
import { RATING_GLYPH_PATHS } from '../../lib/rating-glyphs.js';
|
|
30
|
+
const clamp = (value, max) => (value == null ? null : Math.min(Math.max(0, Math.round(value)), max) || null);
|
|
31
|
+
export function RatingInput({ value, max = 5, glyph = 'star', onChange, label, disabled = false, invalid = false, id, className, 'aria-describedby': describedBy, }) {
|
|
32
|
+
const set = clamp(value, max);
|
|
33
|
+
const [preview, setPreview] = useState(null);
|
|
34
|
+
// What started the change Base UI reports: a key (an arrow, Space) or a pointer.
|
|
35
|
+
const source = useRef('pointer');
|
|
36
|
+
const filled = disabled ? (set ?? 0) : (preview ?? set ?? 0);
|
|
37
|
+
const path = RATING_GLYPH_PATHS[glyph];
|
|
38
|
+
const onKeyDown = () => {
|
|
39
|
+
source.current = 'keyboard';
|
|
40
|
+
};
|
|
41
|
+
const onPointerDown = () => {
|
|
42
|
+
source.current = 'pointer';
|
|
43
|
+
};
|
|
44
|
+
const hover = (star) => (event) => {
|
|
45
|
+
if (event.pointerType === 'mouse')
|
|
46
|
+
setPreview(star);
|
|
47
|
+
};
|
|
48
|
+
return (_jsx(RadioGroup, { id: id, "data-slot": "rating-input", "data-value": set ?? undefined, "data-glyph": glyph, "aria-label": label, "aria-describedby": describedBy, "aria-invalid": invalid || undefined, value: set, onValueChange: (next) => {
|
|
49
|
+
if (next != null && next !== set)
|
|
50
|
+
onChange(next, source.current);
|
|
51
|
+
}, disabled: disabled, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerLeave: hover(null), className: cn('inline-flex w-fit shrink-0 items-center gap-0 align-middle text-foreground', invalid && 'rounded-md ring-3 ring-destructive/20 dark:ring-destructive/40', className), children: Array.from({ length: max }, (_, at) => {
|
|
52
|
+
const star = at + 1;
|
|
53
|
+
const on = star <= filled;
|
|
54
|
+
return (_jsx(Radio.Root, { value: star, "data-star": star, "aria-label": `${star} of ${max}`, onPointerEnter: hover(star),
|
|
55
|
+
// Pressing the set star again clears it (a click, a tap or
|
|
56
|
+
// Space, which Base UI turns into a click). Base UI reports no
|
|
57
|
+
// change for it. The arrow keys check a radio by focusing it,
|
|
58
|
+
// never by a click, so they never clear.
|
|
59
|
+
onClick: () => {
|
|
60
|
+
if (disabled || star !== set)
|
|
61
|
+
return;
|
|
62
|
+
onChange(null, source.current);
|
|
63
|
+
}, className: cn('inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-sm outline-none', 'focus-visible:ring-3 focus-visible:ring-ring/50', 'pointer-coarse:size-11', 'data-disabled:cursor-not-allowed data-disabled:opacity-50'), children: _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", "data-filled": on ? '' : undefined, className: cn('size-4 shrink-0 pointer-coarse:size-5', on ? 'text-current' : 'text-muted-foreground'), children: _jsx("path", { d: path, className: on ? 'fill-current stroke-current' : 'fill-none stroke-current', strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }, star));
|
|
64
|
+
}) }));
|
|
65
|
+
}
|
|
@@ -12,11 +12,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
// Fixed-size glyphs: the score is as wide at 1 as at 5, so a value edited
|
|
13
13
|
// in place never moves what's beside it.
|
|
14
14
|
import { cn } from 'cn';
|
|
15
|
-
|
|
16
|
-
const PATHS = {
|
|
17
|
-
star: 'M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z',
|
|
18
|
-
heart: 'M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5',
|
|
19
|
-
};
|
|
15
|
+
import { RATING_GLYPH_PATHS } from '../../lib/rating-glyphs.js';
|
|
20
16
|
/** A score's spoken words: "4 of 5", or "Loved, 4 of 5" with a word. */
|
|
21
17
|
function ratingScoreName(value, max = 5, word) {
|
|
22
18
|
const filled = Math.min(Math.max(0, Math.round(value)), max);
|
|
@@ -24,6 +20,6 @@ function ratingScoreName(value, max = 5, word) {
|
|
|
24
20
|
}
|
|
25
21
|
export function RatingScore({ value, max = 5, glyph = 'star', word, label, className }) {
|
|
26
22
|
const filled = Math.min(Math.max(0, Math.round(value)), max);
|
|
27
|
-
const path =
|
|
23
|
+
const path = RATING_GLYPH_PATHS[glyph];
|
|
28
24
|
return (_jsxs("span", { role: "img", "aria-label": label ?? ratingScoreName(filled, max, word), "data-slot": "rating-score", "data-value": filled, "data-glyph": glyph, className: cn('inline-flex shrink-0 items-center gap-1.5 align-middle text-foreground', className), children: [_jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0 items-center gap-0.5", children: Array.from({ length: max }, (_, at) => (_jsx("svg", { viewBox: "0 0 24 24", "data-filled": at < filled ? '' : undefined, className: cn('size-4 shrink-0', at < filled ? 'text-current' : 'text-muted-foreground'), children: _jsx("path", { d: path, className: at < filled ? 'fill-current stroke-current' : 'fill-none stroke-current', strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }, at))) }), word && (_jsx("span", { "aria-hidden": "true", className: "text-muted-foreground", children: word }))] }));
|
|
29
25
|
}
|
|
@@ -58,8 +58,10 @@ export type RichTextEditorProps = {
|
|
|
58
58
|
inline?: boolean;
|
|
59
59
|
/**
|
|
60
60
|
* Images uploaded into the text: pasted, dropped, or picked with an
|
|
61
|
-
* Image button on the fixed toolbar
|
|
62
|
-
*
|
|
61
|
+
* Image button (on the fixed toolbar; with `toolbar="floating"`, on the
|
|
62
|
+
* "Editor tools" strip shown while the field has focus; on a phone, in
|
|
63
|
+
* the row pinned to the keyboard) or the slash menu's Image ("/image",
|
|
64
|
+
* 4.123). Each file goes through this (the
|
|
63
65
|
* app's own storage: the package knows no endpoint) and goes in as
|
|
64
66
|
* ``, from the result's `url`, else its `thumbUrl`. A
|
|
65
67
|
* placeholder shows where it will go while it uploads (it isn't saved);
|
|
@@ -23,8 +23,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
23
23
|
// keys scroll.
|
|
24
24
|
//
|
|
25
25
|
// Images in the text (``) show, at most the field's width.
|
|
26
|
-
// With `upload`, an image pasted, dropped or picked with
|
|
27
|
-
//
|
|
26
|
+
// With `upload`, an image pasted, dropped or picked with an Image button
|
|
27
|
+
// (the fixed toolbar's, or the tools strip's with `toolbar="floating"`) is
|
|
28
|
+
// uploaded through the app's own storage and goes in as
|
|
28
29
|
// ``; while it uploads, a placeholder shows where it will go.
|
|
29
30
|
//
|
|
30
31
|
// A table's columns fit their words. Grips on its column and row (or a
|
|
@@ -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
|
+
}
|
|
@@ -10,7 +10,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
10
10
|
// - Pinned to the bottom of what is visible (`visualViewport`), so it sits
|
|
11
11
|
// on the keyboard and follows it as it opens, closes and resizes.
|
|
12
12
|
// - The row: Aa, then the list buttons used while typing (Task, Bulleted,
|
|
13
|
-
// Outdent, Indent), Insert (opens the slash menu on a new line)
|
|
13
|
+
// Outdent, Indent), Insert (opens the slash menu on a new line), Image
|
|
14
|
+
// when the editor uploads images (the fixed toolbar's file picker), and
|
|
14
15
|
// Undo; with words selected, their formats first (Bold to Link), in
|
|
15
16
|
// place of the floating bar, which would land under the system's Copy
|
|
16
17
|
// bar. Hide keyboard last.
|
|
@@ -194,7 +195,7 @@ export function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat,
|
|
|
194
195
|
if (!open)
|
|
195
196
|
virtualKeyboard()?.show();
|
|
196
197
|
view.focus();
|
|
197
|
-
}, children: panel ? _jsx(KeyboardIcon, { "aria-hidden": "true" }) : 'Aa' }), _jsx(Separator, { orientation: "vertical", className: "mx-1 h-6 data-vertical:self-center" }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto [scrollbar-width:none]", children: [_jsx(FormatButtons, { formats: words ? 'keyboardWords' : 'keyboard', state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }), !words && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Insert Block", disabled: readOnly || inCode, className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => insertBlock(view), children: _jsx(PlusIcon, { "aria-hidden": "true" }) }), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Undo",
|
|
198
|
+
}, children: panel ? _jsx(KeyboardIcon, { "aria-hidden": "true" }) : 'Aa' }), _jsx(Separator, { orientation: "vertical", className: "mx-1 h-6 data-vertical:self-center" }), _jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto [scrollbar-width:none]", children: [_jsx(FormatButtons, { formats: words ? 'keyboardWords' : 'keyboard', state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }), !words && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Insert Block", disabled: readOnly || inCode, className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => insertBlock(view), children: _jsx(PlusIcon, { "aria-hidden": "true" }) }), onImage && (_jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Image", disabled: readOnly, className: "[&_svg]:size-5", onMouseDown: keep, onClick: onImage, children: _jsx(ImageIcon, { "aria-hidden": "true" }) })), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Undo",
|
|
198
199
|
// Always on: `state` doesn't follow typing (F6), and with nothing
|
|
199
200
|
// to undo it does nothing.
|
|
200
201
|
disabled: readOnly, className: "[&_svg]:size-5", onMouseDown: keep, onClick: press(() => undo(view.state, view.dispatch)), children: _jsx(Undo2Icon, { "aria-hidden": "true" }) })] }))] }), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Hide Keyboard", className: "[&_svg]:size-5", onMouseDown: keep, onClick: () => {
|
|
@@ -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;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The editor's link box (Ctrl/Cmd+K, milkdown-editor.tsx).
|
|
3
|
+
import { useId, useRef, useState } from 'react';
|
|
4
|
+
import { Button } from '../ui/button.js';
|
|
5
|
+
import { Field, FieldError, FieldLabel } from '../ui/field.js';
|
|
6
|
+
import { Input } from '../ui/input.js';
|
|
7
|
+
import { PopoverContent } from '../ui/popover.js';
|
|
8
|
+
import { linkHref, linkRefusal } from '../../lib/link-href.js';
|
|
9
|
+
// The link box: the address, Apply, and Remove link for an existing one.
|
|
10
|
+
// Enter (Ctrl/Cmd+Enter too) applies the link and stays its own: editing
|
|
11
|
+
// in place listens for Ctrl/Cmd+Enter through the portal, and would save
|
|
12
|
+
// the field without it. Esc is the popover's: it closes the box only.
|
|
13
|
+
export function LinkForm({ box, onApply }) {
|
|
14
|
+
const [typed, setTyped] = useState(box.href);
|
|
15
|
+
const [error, setError] = useState(null);
|
|
16
|
+
const inputRef = useRef(null);
|
|
17
|
+
const inputId = useId();
|
|
18
|
+
const errorId = `${inputId}-error`;
|
|
19
|
+
const apply = () => {
|
|
20
|
+
const href = linkHref(typed);
|
|
21
|
+
if (href === null) {
|
|
22
|
+
setError(linkRefusal(typed) === 'whitespace'
|
|
23
|
+
? 'An address has no spaces. Remove them, or write each as %20.'
|
|
24
|
+
: 'Enter a web or email address, like https://example.com.');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
onApply(href);
|
|
28
|
+
};
|
|
29
|
+
const onKeyDown = (event) => {
|
|
30
|
+
if (event.key === 'Enter' && event.target === inputRef.current) {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
apply();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
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) => {
|
|
37
|
+
setTyped(event.target.value);
|
|
38
|
+
setError(null);
|
|
39
|
+
} }), 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" }))] })] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EditorState } from '@milkdown/kit/prose/state';
|
|
2
|
+
import type { EditorView } from '@milkdown/kit/prose/view';
|
|
3
|
+
import type { PageLinkResolver } from '../../lib/page-link.js';
|
|
4
|
+
export type LinkTarget = {
|
|
5
|
+
from: number;
|
|
6
|
+
to: number;
|
|
7
|
+
href: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function linkTarget(state: EditorState): LinkTarget;
|
|
10
|
+
export declare function followLink(view: EditorView, event: MouseEvent, pages: {
|
|
11
|
+
resolve: PageLinkResolver | undefined;
|
|
12
|
+
open: (href: string) => void;
|
|
13
|
+
}): boolean;
|
|
14
|
+
export declare function applyLink(view: EditorView, target: LinkTarget, href: string): void;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { linkHref } from '../../lib/link-href.js';
|
|
2
|
+
import { pageLinkInfo } from './rich-text-page-links.js';
|
|
3
|
+
export function linkTarget(state) {
|
|
4
|
+
const link = state.schema.marks.link;
|
|
5
|
+
const { from, to, empty, $from } = state.selection;
|
|
6
|
+
if (!empty) {
|
|
7
|
+
let href = '';
|
|
8
|
+
state.doc.nodesBetween(from, to, (node) => {
|
|
9
|
+
const mark = link.isInSet(node.marks);
|
|
10
|
+
if (mark && !href)
|
|
11
|
+
href = String(mark.attrs.href);
|
|
12
|
+
});
|
|
13
|
+
return { from, to, href };
|
|
14
|
+
}
|
|
15
|
+
const mark = link.isInSet($from.marks());
|
|
16
|
+
if (!mark)
|
|
17
|
+
return { from, to, href: '' };
|
|
18
|
+
const start = $from.start();
|
|
19
|
+
let target = { from, to, href: String(mark.attrs.href) };
|
|
20
|
+
let runFrom = -1;
|
|
21
|
+
$from.parent.forEach((child, offset) => {
|
|
22
|
+
const childFrom = start + offset;
|
|
23
|
+
const childTo = childFrom + child.nodeSize;
|
|
24
|
+
if (!mark.isInSet(child.marks)) {
|
|
25
|
+
runFrom = -1;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (runFrom < 0)
|
|
29
|
+
runFrom = childFrom;
|
|
30
|
+
if (runFrom <= from && from <= childTo)
|
|
31
|
+
target = { from: runFrom, to: childTo, href: target.href };
|
|
32
|
+
});
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
35
|
+
// A plain click (or a tap) on a link opens it in a new tab, the way the
|
|
36
|
+
// read view's links open (markdown.tsx), so notes that are always the
|
|
37
|
+
// editor still work as notes. Not when the click chose words (a drag ends
|
|
38
|
+
// in a click too), extends the selection (Shift) or is Alt's; the address
|
|
39
|
+
// goes through linkHref again, so a link that came in with the Markdown
|
|
40
|
+
// can't run code (`javascript:`) either: that one stays text to click
|
|
41
|
+
// into. Read-only too, where the browser would otherwise follow it in this
|
|
42
|
+
// tab. To edit a link's words, put the caret in them from the keyboard or
|
|
43
|
+
// drag over them; Ctrl/Cmd+K edits its address.
|
|
44
|
+
//
|
|
45
|
+
// A page link (`pageLink`) opens its page in this tab instead (`open`:
|
|
46
|
+
// the router's, when there is one), and a removed page's link opens
|
|
47
|
+
// nothing.
|
|
48
|
+
export function followLink(view, event, pages) {
|
|
49
|
+
if (event.button !== 0 || event.shiftKey || event.altKey)
|
|
50
|
+
return false;
|
|
51
|
+
const anchor = event.target instanceof Element ? event.target.closest('a[href]') : null;
|
|
52
|
+
if (!anchor || !view.dom.contains(anchor))
|
|
53
|
+
return false;
|
|
54
|
+
if (!view.state.selection.empty)
|
|
55
|
+
return false;
|
|
56
|
+
const written = anchor.getAttribute('href') ?? '';
|
|
57
|
+
const page = pageLinkInfo(pages.resolve, written);
|
|
58
|
+
if (page) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
if (page.removed)
|
|
61
|
+
return false;
|
|
62
|
+
const href = linkHref(written);
|
|
63
|
+
if (!href)
|
|
64
|
+
return false;
|
|
65
|
+
pages.open(href);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const href = linkHref(written);
|
|
69
|
+
if (!href)
|
|
70
|
+
return false;
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
window.open(href, '_blank', 'noopener,noreferrer');
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
// Sets (or, with `href` empty, removes) the link on the target. With
|
|
76
|
+
// nothing selected and no link there, the address goes in as the link's
|
|
77
|
+
// own text.
|
|
78
|
+
export function applyLink(view, target, href) {
|
|
79
|
+
const link = view.state.schema.marks.link;
|
|
80
|
+
const tr = view.state.tr;
|
|
81
|
+
if (target.from === target.to) {
|
|
82
|
+
if (!href)
|
|
83
|
+
return;
|
|
84
|
+
tr.insertText(href, target.from).addMark(target.from, target.from + href.length, link.create({ href }));
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
tr.removeMark(target.from, target.to, link);
|
|
88
|
+
if (href)
|
|
89
|
+
tr.addMark(target.from, target.to, link.create({ href }));
|
|
90
|
+
}
|
|
91
|
+
view.dispatch(tr.scrollIntoView());
|
|
92
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BoxAnchor } from './rich-text-box-anchor.js';
|
|
2
|
+
export type PageBox = {
|
|
3
|
+
title: string;
|
|
4
|
+
anchor: BoxAnchor;
|
|
5
|
+
};
|
|
6
|
+
export declare function PageForm({ box, busy, onCreate }: {
|
|
7
|
+
box: PageBox;
|
|
8
|
+
busy: boolean;
|
|
9
|
+
onCreate: (title: string) => Promise<string | null>;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The editor's new-page box ("/page" and Turn into page, milkdown-editor.tsx).
|
|
3
|
+
import { useId, useRef, useState } from 'react';
|
|
4
|
+
import { Button } from '../ui/button.js';
|
|
5
|
+
import { Field, FieldError, FieldLabel } from '../ui/field.js';
|
|
6
|
+
import { Input } from '../ui/input.js';
|
|
7
|
+
import { PopoverContent } from '../ui/popover.js';
|
|
8
|
+
// The new page's title box: the title (the selected words to start with),
|
|
9
|
+
// and Create page. While the app makes the page it waits, its controls
|
|
10
|
+
// held; a refusal shows under the title, in the gateway's words, and the
|
|
11
|
+
// text is left as it was. Enter creates; Esc is the popover's, and closes
|
|
12
|
+
// it (not while the app is still working).
|
|
13
|
+
export function PageForm({ box, busy, onCreate }) {
|
|
14
|
+
const [typed, setTyped] = useState(box.title);
|
|
15
|
+
const [error, setError] = useState(null);
|
|
16
|
+
const inputRef = useRef(null);
|
|
17
|
+
const inputId = useId();
|
|
18
|
+
const errorId = `${inputId}-error`;
|
|
19
|
+
const create = () => {
|
|
20
|
+
const title = typed.replace(/\s+/g, ' ').trim();
|
|
21
|
+
if (!title) {
|
|
22
|
+
setError('Give the page a title.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setError(null);
|
|
26
|
+
void onCreate(title).then((refused) => {
|
|
27
|
+
if (refused) {
|
|
28
|
+
setError(refused);
|
|
29
|
+
inputRef.current?.focus();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const onKeyDown = (event) => {
|
|
34
|
+
if (event.key === 'Enter' && event.target === inputRef.current) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
if (!busy)
|
|
38
|
+
create();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
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) => {
|
|
42
|
+
setTyped(event.target.value);
|
|
43
|
+
setError(null);
|
|
44
|
+
} }), 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' }) })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Node as ProseNode } from '@milkdown/kit/prose/model';
|
|
2
|
+
import type { EditorView, NodeView } from '@milkdown/kit/prose/view';
|
|
3
|
+
export declare function taskItemView(node: ProseNode, view: EditorView, getPos: () => number | undefined): NodeView;
|
|
4
|
+
export declare function toggleTaskItem(view: EditorView): boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TASK_ROW, taskBoxHit } from './rich-text-tasks.js';
|
|
2
|
+
// A task-list item: its checkbox toggles `checked`. Any other list item
|
|
3
|
+
// renders as Milkdown's own.
|
|
4
|
+
export function taskItemView(node, view, getPos) {
|
|
5
|
+
const dom = document.createElement('li');
|
|
6
|
+
const box = document.createElement('input');
|
|
7
|
+
box.type = 'checkbox';
|
|
8
|
+
box.contentEditable = 'false';
|
|
9
|
+
box.tabIndex = -1;
|
|
10
|
+
box.setAttribute('aria-label', 'Done');
|
|
11
|
+
const contentDOM = document.createElement('div');
|
|
12
|
+
// Takes the row's width, so an empty item's caret and placeholder show.
|
|
13
|
+
contentDOM.className = 'min-w-0 flex-1';
|
|
14
|
+
dom.append(taskBoxHit(box), contentDOM);
|
|
15
|
+
dom.className = TASK_ROW;
|
|
16
|
+
dom.dataset.itemType = 'task';
|
|
17
|
+
let current = node;
|
|
18
|
+
const render = () => {
|
|
19
|
+
box.checked = Boolean(current.attrs.checked);
|
|
20
|
+
dom.dataset.checked = String(Boolean(current.attrs.checked));
|
|
21
|
+
};
|
|
22
|
+
render();
|
|
23
|
+
box.addEventListener('mousedown', (event) => event.preventDefault());
|
|
24
|
+
// The browser's own toggle is left to happen (cancelling a checkbox's
|
|
25
|
+
// click puts its old state back after this handler), and the document
|
|
26
|
+
// follows it.
|
|
27
|
+
box.addEventListener('click', () => {
|
|
28
|
+
const pos = getPos();
|
|
29
|
+
if (pos === undefined || !view.editable)
|
|
30
|
+
return;
|
|
31
|
+
view.dispatch(view.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, checked: !current.attrs.checked }));
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
dom,
|
|
35
|
+
contentDOM,
|
|
36
|
+
update: (next) => {
|
|
37
|
+
if (next.type !== current.type || next.attrs.checked == null)
|
|
38
|
+
return false;
|
|
39
|
+
current = next;
|
|
40
|
+
render();
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
stopEvent: (event) => event.target === box || event.target === box.parentElement,
|
|
44
|
+
ignoreMutation: (mutation) => mutation.target === box || mutation.target === box.parentElement,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// The task-list item the caret is in, ticked or unticked. False when the
|
|
48
|
+
// caret isn't in one.
|
|
49
|
+
export function toggleTaskItem(view) {
|
|
50
|
+
const { $from } = view.state.selection;
|
|
51
|
+
for (let depth = $from.depth; depth > 0; depth--) {
|
|
52
|
+
const node = $from.node(depth);
|
|
53
|
+
if (node.type.name === 'list_item' && node.attrs.checked != null) {
|
|
54
|
+
view.dispatch(view.state.tr.setNodeMarkup($from.before(depth), undefined, { ...node.attrs, checked: !node.attrs.checked }));
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// - Picked: the slash menu's Toggle heading 1 to 3, and the toolbar's
|
|
11
11
|
// Toggle heading (rich-text-formats.ts).
|
|
12
12
|
// Only a toggle heading folds, and only it has a fold button
|
|
13
|
-
// (
|
|
13
|
+
// (rich-text-heading-view.ts, rich-text-fold.ts).
|
|
14
14
|
import { headingSchema } from '@milkdown/kit/preset/commonmark';
|
|
15
15
|
import { textblockTypeInputRule } from '@milkdown/kit/prose/inputrules';
|
|
16
16
|
import { $inputRule, $remark } from '@milkdown/kit/utils';
|
|
@@ -117,7 +117,7 @@ export function FormatButtons({ formats, state, readOnly, onFormat, onPage, onIm
|
|
|
117
117
|
onMouseDown: (event) => event.preventDefault(), onFocus: () => setCurrent(index), onKeyDown: onKeyDown, onPressedChange: () => onFormat(item.id) }), children: _jsx(Icon, {}) }), _jsx(TooltipContent, { children: tip })] }, item.id));
|
|
118
118
|
})] }, 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) => {
|
|
119
119
|
buttons.current[pageIndex] = element;
|
|
120
|
-
}, 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) => {
|
|
120
|
+
}, 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: [(items.length > 0 || onPage) && _jsx(Separator, { orientation: "vertical", className: "mx-1 h-5 self-center" }), _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ref: (element) => {
|
|
121
121
|
buttons.current[imageIndex] = element;
|
|
122
122
|
}, 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) => {
|
|
123
123
|
buttons.current[fullScreenIndex] = element;
|
|
@@ -8,6 +8,8 @@ export interface RichTextToolsBarProps {
|
|
|
8
8
|
/** The editable element's id, for `aria-controls`. */
|
|
9
9
|
controls: string;
|
|
10
10
|
onFormat: (id: FormatId) => void;
|
|
11
|
+
/** The Image button pressed: pick images to upload. No button without it (the editor has no `upload`). */
|
|
12
|
+
onImage?: () => void;
|
|
11
13
|
onFullScreen: () => void;
|
|
12
14
|
/** Esc: focus back to the text. */
|
|
13
15
|
onReturn: () => void;
|
|
@@ -15,4 +17,4 @@ export interface RichTextToolsBarProps {
|
|
|
15
17
|
onBlur: (event: FocusEvent) => void;
|
|
16
18
|
ref?: Ref<HTMLDivElement>;
|
|
17
19
|
}
|
|
18
|
-
export declare function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onFullScreen, onReturn, onBlur, ref }: RichTextToolsBarProps): import("react").JSX.Element;
|
|
20
|
+
export declare function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onImage, onFullScreen, onReturn, onBlur, ref }: RichTextToolsBarProps): import("react").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from 'cn';
|
|
3
3
|
import { FormatButtons } from './rich-text-toolbar.js';
|
|
4
|
-
export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onFullScreen, onReturn, onBlur, ref }) {
|
|
4
|
+
export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onFormat, onImage, onFullScreen, onReturn, onBlur, ref }) {
|
|
5
5
|
const onKeyDown = (event) => {
|
|
6
6
|
// Full screen's Esc is the field's (milkdown-editor.tsx); otherwise it
|
|
7
7
|
// gives focus back to the text.
|
|
@@ -13,5 +13,5 @@ export function RichTextToolsBar({ state, readOnly, fullScreen, controls, onForm
|
|
|
13
13
|
};
|
|
14
14
|
return (_jsx("div", { ref: ref, role: "toolbar", "aria-label": "Editor tools", "aria-controls": controls, "data-slot": "rich-text-tools-bar", className: cn('absolute right-0 z-40 flex items-center gap-0.5 rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10',
|
|
15
15
|
// Above the field, or inside its corner once it fills the window.
|
|
16
|
-
fullScreen ? 'top-2 right-2' : 'bottom-full mb-1'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "tools", state: state, readOnly: readOnly, onFormat: onFormat, onFullScreen: onFullScreen, fullScreen: fullScreen }) }));
|
|
16
|
+
fullScreen ? 'top-2 right-2' : 'bottom-full mb-1'), onKeyDown: onKeyDown, onBlur: onBlur, children: _jsx(FormatButtons, { formats: "tools", state: state, readOnly: readOnly, onFormat: onFormat, onImage: onImage, onFullScreen: onFullScreen, fullScreen: fullScreen }) }));
|
|
17
17
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/** Where a step is in a sequence (StepTrackState). */
|
|
3
|
+
type StepState = 'done' | 'current' | 'upcoming';
|
|
4
|
+
/** A step's box: at least 4.5rem wide and 44px tall, sharing the row. */
|
|
5
|
+
export declare const STEP_CELL = "group/step relative flex min-h-11 min-w-18 flex-1 basis-0 flex-col items-center gap-1 rounded-md px-1 pt-1 pb-1.5 text-center text-xs text-muted-foreground";
|
|
6
|
+
/** The line from the step before, under the marks: the primary up to the current one. */
|
|
7
|
+
export declare const stepLine: (step: StepState) => string;
|
|
8
|
+
/** The row's scroll box: sideways in its own box, never the page. */
|
|
9
|
+
export declare const STEP_ROW = "relative flex max-w-full overflow-x-auto overflow-y-hidden [scrollbar-width:thin]";
|
|
10
|
+
/**
|
|
11
|
+
* Keeps the step `selector` finds in the row's view when the row scrolls
|
|
12
|
+
* sideways: the row only, never the page. Runs again when `key` changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useKeepStepInView(rowRef: RefObject<HTMLElement | null>, selector: string, key: string | undefined): void;
|
|
15
|
+
export {};
|