@tristan2828/ui-foundation 4.124.2 → 4.126.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/README.md +1 -1
- package/conventions/docs/add-an-entity.md +42 -21
- package/conventions/docs/cell-patterns.md +80 -39
- package/dist/api/transport/index.js +10 -1
- package/dist/components/app/edit-caret.d.ts +25 -0
- package/dist/components/app/edit-caret.js +118 -0
- package/dist/components/app/edit-in-place-store.d.ts +43 -4
- package/dist/components/app/edit-in-place-store.js +169 -19
- package/dist/components/app/editable-value.js +164 -22
- package/dist/components/app/entity-form.js +4 -0
- package/dist/components/app/entity-view.js +1 -1
- package/dist/components/app/form-leave-guard.js +7 -1
- package/dist/components/app/milkdown-editor.d.ts +1 -0
- package/dist/components/app/milkdown-editor.js +224 -63
- package/dist/components/app/prose-look.d.ts +1 -1
- package/dist/components/app/prose-look.js +3 -1
- package/dist/components/app/rich-text-autolink.d.ts +6 -0
- package/dist/components/app/rich-text-autolink.js +79 -0
- package/dist/components/app/rich-text-edges.d.ts +8 -0
- package/dist/components/app/rich-text-edges.js +144 -0
- package/dist/components/app/rich-text-editor.d.ts +15 -2
- package/dist/components/app/rich-text-editor.js +16 -4
- package/dist/components/app/rich-text-empty-paragraph.d.ts +14 -6
- package/dist/components/app/rich-text-empty-paragraph.js +19 -8
- package/dist/components/app/rich-text-formats.js +88 -15
- package/dist/components/app/rich-text-full-screen.d.ts +2 -0
- package/dist/components/app/rich-text-full-screen.js +78 -0
- package/dist/components/app/rich-text-highlight-menu.d.ts +3 -1
- package/dist/components/app/rich-text-highlight-menu.js +3 -2
- package/dist/components/app/rich-text-input-rules.d.ts +7 -0
- package/dist/components/app/rich-text-input-rules.js +83 -0
- package/dist/components/app/rich-text-keyboard-bar.d.ts +24 -0
- package/dist/components/app/rich-text-keyboard-bar.js +214 -0
- package/dist/components/app/rich-text-node-views.js +2 -1
- package/dist/components/app/rich-text-paste.d.ts +43 -0
- package/dist/components/app/rich-text-paste.js +355 -0
- package/dist/components/app/rich-text-shortcuts.d.ts +5 -1
- package/dist/components/app/rich-text-shortcuts.js +132 -2
- package/dist/components/app/rich-text-slash-menu.js +47 -9
- package/dist/components/app/rich-text-slash.d.ts +7 -0
- package/dist/components/app/rich-text-slash.js +27 -14
- package/dist/components/app/rich-text-table-grips.d.ts +8 -6
- package/dist/components/app/rich-text-table-grips.js +11 -12
- package/dist/components/app/rich-text-tasks.d.ts +8 -0
- package/dist/components/app/rich-text-tasks.js +20 -0
- package/dist/components/app/rich-text-toolbar.d.ts +5 -1
- package/dist/components/app/rich-text-toolbar.js +13 -5
- package/dist/components/app/rich-text-touch.d.ts +2 -0
- package/dist/components/app/rich-text-touch.js +18 -0
- package/dist/components/app/rich-text-widgets.js +1 -1
- package/dist/hooks/table-url-changes.d.ts +4 -0
- package/dist/hooks/table-url-changes.js +13 -0
- package/dist/hooks/use-table-url-state.js +14 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/lib/markdown-merge.d.ts +26 -0
- package/dist/lib/markdown-merge.js +112 -17
- package/dist/lib/page-leaving.d.ts +8 -0
- package/dist/lib/page-leaving.js +30 -0
- package/dist/lib/pending-edits.d.ts +14 -0
- package/dist/lib/pending-edits.js +51 -0
- package/dist/mocks/e2e-hooks.js +10 -0
- package/dist/mocks/override.d.ts +8 -0
- package/dist/mocks/start-worker.d.ts +24 -0
- package/dist/mocks/start-worker.js +120 -3
- package/dist/testing/index.d.ts +84 -5
- package/dist/testing/index.js +177 -10
- package/package.json +1 -1
- package/styles/index.css +7 -0
|
@@ -7,6 +7,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
// text, the selection kept. The popup is marked `data-rich-text-menu` so
|
|
8
8
|
// the floating toolbar, which this menu also sits in, knows focus in it is
|
|
9
9
|
// still the field's (milkdown-editor.tsx).
|
|
10
|
+
import { cn } from 'cn';
|
|
10
11
|
import { useRef } from 'react';
|
|
11
12
|
import { ChevronDownIcon, HighlighterIcon, RemoveFormattingIcon } from 'lucide-react';
|
|
12
13
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
@@ -19,7 +20,7 @@ const SWATCH = {
|
|
|
19
20
|
green: 'bg-highlight-green',
|
|
20
21
|
red: 'bg-highlight-red',
|
|
21
22
|
};
|
|
22
|
-
export function RichTextHighlightMenu({ state, readOnly, tabIndex, onFocus, onKeyDown, onFormat, text, ref }) {
|
|
23
|
+
export function RichTextHighlightMenu({ state, readOnly, tabIndex, onFocus, onKeyDown, onFormat, text, className, ref }) {
|
|
23
24
|
const current = state ? highlightColor(state) : null;
|
|
24
25
|
// Whether the menu is closing because an item was picked.
|
|
25
26
|
const picked = useRef(false);
|
|
@@ -34,7 +35,7 @@ export function RichTextHighlightMenu({ state, readOnly, tabIndex, onFocus, onKe
|
|
|
34
35
|
};
|
|
35
36
|
return (_jsxs(DropdownMenu, { children: [_jsxs(DropdownMenuTrigger, { ref: ref, "aria-label": "Highlight", disabled: readOnly, tabIndex: tabIndex, "data-active": current !== null || undefined,
|
|
36
37
|
// Shaped like the toolbar's toggles: on while the words are highlighted.
|
|
37
|
-
className: toggleVariants({ size: 'sm', className: 'gap-0.5 px-1.5 data-active:bg-muted data-active:text-foreground' }),
|
|
38
|
+
className: cn(toggleVariants({ size: 'sm', className: 'gap-0.5 px-1.5 data-active:bg-muted data-active:text-foreground' }), className),
|
|
38
39
|
// A mouse press keeps focus, and the selection, in the text.
|
|
39
40
|
onMouseDown: (event) => event.preventDefault(), onFocus: onFocus, onKeyDown: onKeyDown, children: [_jsx(HighlighterIcon, { "aria-hidden": "true" }), _jsx(ChevronDownIcon, { "aria-hidden": "true", className: "size-3" })] }), _jsxs(DropdownMenuContent, { className: "w-44", "data-rich-text-menu": "", finalFocus: finalFocus, children: [_jsx(DropdownMenuRadioGroup, { value: current, onValueChange: (value) => {
|
|
40
41
|
if (HIGHLIGHT_COLORS.includes(value))
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MilkdownPlugin } from '@milkdown/kit/ctx';
|
|
2
|
+
export declare const EMPHASIS_STAR: RegExp;
|
|
3
|
+
export declare const STRONG: RegExp;
|
|
4
|
+
export declare const HIGHLIGHT: RegExp;
|
|
5
|
+
export declare const DIVIDER: RegExp;
|
|
6
|
+
/** The editor's input rules: Milkdown's blocks' and marks', with the divider, emphasis and strong rules its own, and the highlight's. */
|
|
7
|
+
export declare const typedInputRules: MilkdownPlugin[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// The rich-text editor's typed Markdown: Milkdown's input rules, three of
|
|
2
|
+
// them swapped for the editor's own (4.126, the RichTextEditor review's
|
|
3
|
+
// F15, F16 and F22).
|
|
4
|
+
// - `---` (or `***`, `___` and a space) on an empty line puts in a divider
|
|
5
|
+
// the way the Divider button does: a line under it, the caret there.
|
|
6
|
+
// Milkdown's left the rule selected, and the next key replaced it.
|
|
7
|
+
// - `*words*` and `**words**` need a non-space after the opening marks and
|
|
8
|
+
// before the closing ones, as CommonMark (and Notion) do: `5 * 3 * 2`
|
|
9
|
+
// stays as typed. Milkdown's took any text between two stars.
|
|
10
|
+
// - `==words==` highlights as typed (`=={green}words==` in that colour),
|
|
11
|
+
// as the other marks do; before, it became a highlight only on a reload.
|
|
12
|
+
// Every other rule is Milkdown's own, in its order.
|
|
13
|
+
import { emphasisStarInputRule, inputRules, insertHrInputRule, markInputRules, strongInputRule } from '@milkdown/kit/preset/commonmark';
|
|
14
|
+
import { schemaCtx } from '@milkdown/kit/core';
|
|
15
|
+
import { markRule } from '@milkdown/kit/prose';
|
|
16
|
+
import { InputRule } from '@milkdown/kit/prose/inputrules';
|
|
17
|
+
import { $inputRule } from '@milkdown/kit/utils';
|
|
18
|
+
import { DEFAULT_HIGHLIGHT, isHighlightColor } from '../../lib/markdown-highlight.js';
|
|
19
|
+
import { toggleFormat } from './rich-text-formats.js';
|
|
20
|
+
// The opening `*` follows anything but a star (so it isn't half of `**`)
|
|
21
|
+
// and is followed by a non-space; the closing one, being typed, follows a
|
|
22
|
+
// non-space. The group is the words.
|
|
23
|
+
export const EMPHASIS_STAR = /(?:^|[^*])\*([^\s*](?:[^*]*[^\s*])?)\*$/;
|
|
24
|
+
// As Milkdown's: not next to a letter, a colon or a slash (a path, a URL,
|
|
25
|
+
// `a**b**c`), and now the words start and end with a non-space.
|
|
26
|
+
export const STRONG = /(?<![\w:/])(?:\*\*|__)([^\s*_](?:[^*_]*?[^\s*_])?)(?:\*\*|__)(?![\w/])$/;
|
|
27
|
+
// `==words==` or `=={colour}words==`, the way markdown-highlight.ts reads
|
|
28
|
+
// it: the opening marks follow anything but `=`, the words start and end
|
|
29
|
+
// with a non-space (and don't start with a brace, which is a colour's).
|
|
30
|
+
export const HIGHLIGHT = /(?:^|[^=])==(?:\{([a-z]+)\})?([^\s={](?:[^=]*[^\s=])?)==$/;
|
|
31
|
+
// Milkdown's divider rule's text: `---`, or `***` / `___` and a space.
|
|
32
|
+
export const DIVIDER = /^(?:---|___\s|\*\*\*\s)$/;
|
|
33
|
+
const emphasisStar = $inputRule((ctx) => markRule(EMPHASIS_STAR, ctx.get(schemaCtx).marks.emphasis, {
|
|
34
|
+
getAttr: () => ({ marker: '*' }),
|
|
35
|
+
// The character before the star is matched, not marked.
|
|
36
|
+
updateCaptured: ({ fullMatch, start }) => (!fullMatch.startsWith('*') ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {}),
|
|
37
|
+
}));
|
|
38
|
+
const strong = $inputRule((ctx) => markRule(STRONG, ctx.get(schemaCtx).marks.strong, {
|
|
39
|
+
getAttr: (match) => ({ marker: match[0].startsWith('*') ? '*' : '_' }),
|
|
40
|
+
}));
|
|
41
|
+
// Its own handler rather than markRule, which finds the words by their
|
|
42
|
+
// text and so would find "green" in the colour of `=={green}green==`.
|
|
43
|
+
// The closing `=` being typed is never put in.
|
|
44
|
+
const highlight = $inputRule((ctx) => {
|
|
45
|
+
const type = ctx.get(schemaCtx).marks.highlight;
|
|
46
|
+
return new InputRule(HIGHLIGHT, (state, match, start, end) => {
|
|
47
|
+
const [whole, colour, words] = match;
|
|
48
|
+
const open = start + (whole.startsWith('=') ? 0 : 1);
|
|
49
|
+
const textStart = open + 2 + (colour ? colour.length + 2 : 0);
|
|
50
|
+
const textEnd = textStart + words.length;
|
|
51
|
+
const tr = state.tr.delete(textEnd, end).delete(open, textStart);
|
|
52
|
+
tr.addMark(open, open + words.length, type.create({ color: isHighlightColor(colour) ? colour : DEFAULT_HIGHLIGHT }));
|
|
53
|
+
// What's typed next isn't highlighted.
|
|
54
|
+
return tr.removeStoredMark(type);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
// The Divider button's insert (rich-text-formats.ts insertBlock), on the
|
|
58
|
+
// line the marks were typed on, once they're gone: one step to undo, which
|
|
59
|
+
// brings the marks back. Nothing when the line holds more than the marks.
|
|
60
|
+
const divider = $inputRule(() => new InputRule(DIVIDER, (state, _match, start, end) => {
|
|
61
|
+
const tr = state.tr.delete(start, end);
|
|
62
|
+
if (tr.doc.resolve(start).parent.content.size > 0)
|
|
63
|
+
return null;
|
|
64
|
+
let made = null;
|
|
65
|
+
if (!toggleFormat(state.apply(tr), (next) => (made = next), 'divider'))
|
|
66
|
+
return null;
|
|
67
|
+
const done = made;
|
|
68
|
+
if (!done)
|
|
69
|
+
return null;
|
|
70
|
+
for (const step of done.steps)
|
|
71
|
+
tr.step(step);
|
|
72
|
+
return tr.setSelection(done.selection.getBookmark().resolve(tr.doc)).scrollIntoView();
|
|
73
|
+
}));
|
|
74
|
+
const REPLACED = [insertHrInputRule, emphasisStarInputRule, strongInputRule];
|
|
75
|
+
/** The editor's input rules: Milkdown's blocks' and marks', with the divider, emphasis and strong rules its own, and the highlight's. */
|
|
76
|
+
export const typedInputRules = [
|
|
77
|
+
...inputRules.filter((rule) => !REPLACED.includes(rule)),
|
|
78
|
+
divider,
|
|
79
|
+
...markInputRules.filter((rule) => !REPLACED.includes(rule)),
|
|
80
|
+
emphasisStar,
|
|
81
|
+
strong,
|
|
82
|
+
highlight,
|
|
83
|
+
];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type FocusEvent, type Ref } from 'react';
|
|
2
|
+
import type { EditorState } from '@milkdown/kit/prose/state';
|
|
3
|
+
import type { EditorView } from '@milkdown/kit/prose/view';
|
|
4
|
+
import { type FormatId } from './rich-text-formats.js';
|
|
5
|
+
export interface RichTextKeyboardBarProps {
|
|
6
|
+
view: EditorView;
|
|
7
|
+
state: EditorState | null;
|
|
8
|
+
readOnly: boolean;
|
|
9
|
+
/** The editable element's id, for `aria-controls`. */
|
|
10
|
+
controls: string;
|
|
11
|
+
onFormat: (id: FormatId) => void;
|
|
12
|
+
/** The Image button pressed (only when the editor uploads images). */
|
|
13
|
+
onImage?: () => void;
|
|
14
|
+
onFullScreen?: () => void;
|
|
15
|
+
fullScreen?: boolean;
|
|
16
|
+
text: () => HTMLElement | null;
|
|
17
|
+
/** Focus leaving one of its buttons, for the editor to tell whether it left the field. */
|
|
18
|
+
onBlur: (event: FocusEvent) => void;
|
|
19
|
+
/** A press in the text still down (the tap that focused it): the row waits for it to end. */
|
|
20
|
+
pressing?: boolean;
|
|
21
|
+
/** Its element, for Alt+F10 to reach it from the text. */
|
|
22
|
+
ref?: Ref<HTMLDivElement>;
|
|
23
|
+
}
|
|
24
|
+
export declare function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat, onImage, onFullScreen, fullScreen, text, onBlur, pressing, ref }: RichTextKeyboardBarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The rich-text editor's toolbar on a touch screen (review F11, picked
|
|
3
|
+
// 2026-11-18 as 1A and 4A): a short row pinned to the top of the phone's
|
|
4
|
+
// keyboard, in place of the rows above the text, which scroll away and
|
|
5
|
+
// take a third of what's left of the note while the keyboard is open.
|
|
6
|
+
//
|
|
7
|
+
// - Shown while the field has focus (or is full screen), on a coarse
|
|
8
|
+
// pointer only (`useCoarsePointer`); a laptop keeps the rows above the
|
|
9
|
+
// text, and the floating bar over selected words.
|
|
10
|
+
// - Pinned to the bottom of what is visible (`visualViewport`), so it sits
|
|
11
|
+
// on the keyboard and follows it as it opens, closes and resizes.
|
|
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) and
|
|
14
|
+
// Undo; with words selected, their formats first (Bold to Link), in
|
|
15
|
+
// place of the floating bar, which would land under the system's Copy
|
|
16
|
+
// bar. Hide keyboard last.
|
|
17
|
+
// - Aa swaps the keyboard for a panel of every format, by kind and named;
|
|
18
|
+
// the keyboard button in its place brings the keyboard back. Focus stays
|
|
19
|
+
// in the text the whole time (`inputmode="none"` hides the keyboard), so
|
|
20
|
+
// the selection and the caret are kept.
|
|
21
|
+
// - Its buttons are 40px (the review's floor), on semantic tokens only.
|
|
22
|
+
//
|
|
23
|
+
// Placed inside the field's element, not in a portal, like the floating
|
|
24
|
+
// toolbar (rich-text-floating-toolbar.tsx says why): `position: fixed`,
|
|
25
|
+
// offset by its containing block's own place when an ancestor is
|
|
26
|
+
// transformed (a dialog), so it still meets the keyboard.
|
|
27
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
28
|
+
import { undo } from '@milkdown/kit/prose/history';
|
|
29
|
+
import { TextSelection } from '@milkdown/kit/prose/state';
|
|
30
|
+
import { ChevronDownIcon, ImageIcon, KeyboardIcon, Maximize2Icon, Minimize2Icon, PlusIcon, Undo2Icon } from 'lucide-react';
|
|
31
|
+
import { cn } from 'cn';
|
|
32
|
+
import { Button } from '../ui/button.js';
|
|
33
|
+
import { Separator } from '../ui/separator.js';
|
|
34
|
+
import { Toggle } from '../ui/toggle.js';
|
|
35
|
+
import { FORMAT_GROUPS } from './rich-text-format-items.js';
|
|
36
|
+
import { formatOn } from './rich-text-formats.js';
|
|
37
|
+
import { FormatButtons } from './rich-text-toolbar.js';
|
|
38
|
+
// The panel's height when no keyboard has been seen yet (a phone's is
|
|
39
|
+
// about 260 to 330px).
|
|
40
|
+
const PANEL = 280;
|
|
41
|
+
// The visible area's bottom edge, followed as the keyboard opens, closes
|
|
42
|
+
// and the page zooms or scrolls under it.
|
|
43
|
+
function useVisibleEdge(probe) {
|
|
44
|
+
const [edge, setEdge] = useState(null);
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
const viewport = window.visualViewport;
|
|
47
|
+
const update = () => {
|
|
48
|
+
// Where `position: fixed` puts 0,0: the window, or a transformed ancestor.
|
|
49
|
+
const origin = probe.current?.getBoundingClientRect() ?? { top: 0, left: 0 };
|
|
50
|
+
const top = viewport?.offsetTop ?? 0;
|
|
51
|
+
const height = viewport?.height ?? window.innerHeight;
|
|
52
|
+
const next = {
|
|
53
|
+
bottom: top + height - origin.top,
|
|
54
|
+
left: (viewport?.offsetLeft ?? 0) - origin.left,
|
|
55
|
+
width: viewport?.width ?? window.innerWidth,
|
|
56
|
+
keyboard: Math.max(0, window.innerHeight - height - top),
|
|
57
|
+
};
|
|
58
|
+
setEdge((last) => {
|
|
59
|
+
const lastKeyboard = next.keyboard > 150 ? next.keyboard : (last?.lastKeyboard ?? 0);
|
|
60
|
+
if (last && last.bottom === next.bottom && last.left === next.left && last.width === next.width && last.keyboard === next.keyboard && last.lastKeyboard === lastKeyboard)
|
|
61
|
+
return last;
|
|
62
|
+
return { ...next, lastKeyboard };
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
update();
|
|
66
|
+
viewport?.addEventListener('resize', update);
|
|
67
|
+
viewport?.addEventListener('scroll', update);
|
|
68
|
+
window.addEventListener('resize', update);
|
|
69
|
+
window.addEventListener('scroll', update, true);
|
|
70
|
+
return () => {
|
|
71
|
+
viewport?.removeEventListener('resize', update);
|
|
72
|
+
viewport?.removeEventListener('scroll', update);
|
|
73
|
+
window.removeEventListener('resize', update);
|
|
74
|
+
window.removeEventListener('scroll', update, true);
|
|
75
|
+
};
|
|
76
|
+
}, [probe]);
|
|
77
|
+
return edge;
|
|
78
|
+
}
|
|
79
|
+
// The nearest ancestor that scrolls the text, or the page.
|
|
80
|
+
function scroller(element) {
|
|
81
|
+
for (let node = element.parentElement; node; node = node.parentElement) {
|
|
82
|
+
const { overflowY } = getComputedStyle(node);
|
|
83
|
+
if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight)
|
|
84
|
+
return node;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const virtualKeyboard = () => navigator.virtualKeyboard;
|
|
89
|
+
// Insert: the slash menu, on the caret's line when it's empty, else on a
|
|
90
|
+
// new line after it (made as Enter makes one, so a list item makes the
|
|
91
|
+
// next item), as a typed "/" opens it (rich-text-slash.ts).
|
|
92
|
+
function insertBlock(view) {
|
|
93
|
+
const { $from, empty } = view.state.selection;
|
|
94
|
+
if (!(empty && $from.parent.isTextblock && $from.parent.content.size === 0)) {
|
|
95
|
+
view.dispatch(view.state.tr.setSelection(TextSelection.create(view.state.doc, $from.end())));
|
|
96
|
+
const enter = new KeyboardEvent('keydown', { key: 'Enter', code: 'Enter' });
|
|
97
|
+
view.someProp('handleKeyDown', (handle) => handle(view, enter));
|
|
98
|
+
}
|
|
99
|
+
const at = view.state.selection.from;
|
|
100
|
+
const typed = view.someProp('handleTextInput', (handle) => handle(view, at, at, '/', () => view.state.tr.insertText('/', at, at)));
|
|
101
|
+
if (!typed)
|
|
102
|
+
view.dispatch(view.state.tr.insertText('/', at, at));
|
|
103
|
+
view.focus();
|
|
104
|
+
}
|
|
105
|
+
// The panel's blocks: every format that isn't about selected words, named.
|
|
106
|
+
const WORDS = ['bold', 'italic', 'strike', 'code', 'highlight', 'link'];
|
|
107
|
+
const BLOCKS = FORMAT_GROUPS.flat().filter((item) => !WORDS.includes(item.id));
|
|
108
|
+
// A block's tile in the panel: its icon over its name, two lines at most.
|
|
109
|
+
const TILE = 'h-16 w-full flex-col gap-1 rounded-lg bg-muted px-1 text-center text-xs leading-tight font-medium whitespace-normal text-foreground [&_svg]:size-5';
|
|
110
|
+
export function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat, onImage, onFullScreen, fullScreen = false, text, onBlur, pressing = false, ref }) {
|
|
111
|
+
const probe = useRef(null);
|
|
112
|
+
const row = useRef(null);
|
|
113
|
+
const edge = useVisibleEdge(probe);
|
|
114
|
+
// Shown once the tap that focused the text is over: shown at once, the
|
|
115
|
+
// row would be under a finger pressing the screen's bottom line (a link
|
|
116
|
+
// there), and the release would land on the row.
|
|
117
|
+
const [ready, setReady] = useState(!pressing);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (ready || pressing)
|
|
120
|
+
return;
|
|
121
|
+
// After the press's click, which follows its release.
|
|
122
|
+
const settle = setTimeout(() => setReady(true));
|
|
123
|
+
return () => clearTimeout(settle);
|
|
124
|
+
}, [ready, pressing]);
|
|
125
|
+
const [panel, setPanel] = useState(false);
|
|
126
|
+
const panelHeight = edge?.lastKeyboard || PANEL;
|
|
127
|
+
// The panel hides the keyboard, focus kept in the text; the keyboard
|
|
128
|
+
// comes back as it closes (or the bar goes).
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!panel)
|
|
131
|
+
return;
|
|
132
|
+
const dom = view.dom;
|
|
133
|
+
dom.setAttribute('inputmode', 'none');
|
|
134
|
+
virtualKeyboard()?.hide();
|
|
135
|
+
return () => {
|
|
136
|
+
dom.removeAttribute('inputmode');
|
|
137
|
+
};
|
|
138
|
+
}, [panel, view]);
|
|
139
|
+
// The caret stays in sight above the bar (and the panel): the browser
|
|
140
|
+
// keeps it above the keyboard only. Checked on each edit and caret move
|
|
141
|
+
// in the text itself, as `state` only follows what the bar draws (F6:
|
|
142
|
+
// typing doesn't re-render it).
|
|
143
|
+
useLayoutEffect(() => {
|
|
144
|
+
if (!edge || !ready)
|
|
145
|
+
return;
|
|
146
|
+
const keepInSight = () => {
|
|
147
|
+
if (!row.current)
|
|
148
|
+
return;
|
|
149
|
+
let caret;
|
|
150
|
+
try {
|
|
151
|
+
caret = view.coordsAtPos(view.state.selection.head);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const limit = row.current.getBoundingClientRect().top - 8;
|
|
157
|
+
const over = caret.bottom - limit;
|
|
158
|
+
if (over <= 0)
|
|
159
|
+
return;
|
|
160
|
+
const scrolling = scroller(view.dom);
|
|
161
|
+
if (scrolling)
|
|
162
|
+
scrolling.scrollTop += over;
|
|
163
|
+
else
|
|
164
|
+
window.scrollBy(0, over);
|
|
165
|
+
};
|
|
166
|
+
keepInSight();
|
|
167
|
+
let frame = 0;
|
|
168
|
+
const soon = () => {
|
|
169
|
+
cancelAnimationFrame(frame);
|
|
170
|
+
frame = requestAnimationFrame(keepInSight);
|
|
171
|
+
};
|
|
172
|
+
const dom = view.dom;
|
|
173
|
+
dom.addEventListener('input', soon);
|
|
174
|
+
document.addEventListener('selectionchange', soon);
|
|
175
|
+
return () => {
|
|
176
|
+
cancelAnimationFrame(frame);
|
|
177
|
+
dom.removeEventListener('input', soon);
|
|
178
|
+
document.removeEventListener('selectionchange', soon);
|
|
179
|
+
};
|
|
180
|
+
}, [view, edge, panel, ready]);
|
|
181
|
+
const selection = state?.selection;
|
|
182
|
+
const words = Boolean(selection && !selection.empty && !selection.$from.parent.type.spec.code);
|
|
183
|
+
const inCode = Boolean(selection?.$from.parent.type.spec.code);
|
|
184
|
+
// A press never takes focus from the text, so the selection stays.
|
|
185
|
+
const keep = (event) => event.preventDefault();
|
|
186
|
+
const press = (run) => () => {
|
|
187
|
+
run();
|
|
188
|
+
view.focus();
|
|
189
|
+
};
|
|
190
|
+
const shown = edge !== null && ready;
|
|
191
|
+
const bottom = edge ? edge.bottom - (panel ? panelHeight : 0) : 0;
|
|
192
|
+
return (_jsxs("div", { ref: ref, "data-slot": "rich-text-keyboard-bar", "data-rich-text-menu": "", onBlur: onBlur, children: [_jsx("span", { ref: probe, "aria-hidden": "true", className: "pointer-events-none fixed top-0 left-0 size-0" }), _jsxs("div", { ref: row, role: "toolbar", "aria-label": "Formatting", "aria-controls": controls, style: edge ? { top: bottom, left: edge.left, width: edge.width } : undefined, className: cn('fixed z-50 flex h-12 -translate-y-full items-center gap-0.5 border-t border-border bg-card px-1 text-card-foreground', !shown && 'invisible'), children: [_jsx(Toggle, { "aria-label": panel ? 'Keyboard' : 'All Formats', pressed: panel, disabled: readOnly, className: "size-10 min-w-10 font-serif text-base aria-pressed:bg-muted aria-pressed:text-foreground [&_svg]:size-5", onMouseDown: keep, onPressedChange: (open) => {
|
|
193
|
+
setPanel(open);
|
|
194
|
+
if (!open)
|
|
195
|
+
virtualKeyboard()?.show();
|
|
196
|
+
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
|
+
// Always on: `state` doesn't follow typing (F6), and with nothing
|
|
199
|
+
// to undo it does nothing.
|
|
200
|
+
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: () => {
|
|
201
|
+
setPanel(false);
|
|
202
|
+
view.dom.blur();
|
|
203
|
+
}, children: _jsx(ChevronDownIcon, { "aria-hidden": "true" }) })] }), panel && edge && (_jsxs("div", { role: "group", "aria-label": "All Formats", "data-slot": "rich-text-keyboard-panel", style: { top: edge.bottom - panelHeight, left: edge.left, width: edge.width, height: panelHeight }, className: "fixed z-50 flex flex-col gap-3 overflow-y-auto bg-card px-3 py-3 text-card-foreground", onMouseDown: keep, children: [_jsx("p", { className: "type-caption text-muted-foreground", children: "Words" }), _jsx("div", { role: "toolbar", "aria-label": "Format Words", className: "flex flex-wrap items-center gap-1", children: _jsx(FormatButtons, { formats: "selection", state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }) }), _jsx("p", { className: "type-caption text-muted-foreground", children: "Blocks" }), _jsxs("div", { className: "grid grid-cols-4 gap-1.5", children: [BLOCKS.map((item) => {
|
|
204
|
+
const Icon = item.icon;
|
|
205
|
+
const disabled = readOnly || (item.id === 'table' && state !== null && formatOn(state, 'table'));
|
|
206
|
+
const look = TILE;
|
|
207
|
+
if (item.action)
|
|
208
|
+
return (_jsxs(Button, { variant: "ghost", disabled: disabled, className: cn(look, 'hover:bg-muted'), onMouseDown: keep, onClick: press(() => onFormat(item.id)), children: [_jsx(Icon, { "aria-hidden": "true" }), item.label] }, item.id));
|
|
209
|
+
return (_jsxs(Toggle, { pressed: state ? formatOn(state, item.id) : false, disabled: disabled, className: cn(look, 'aria-pressed:bg-primary/15 aria-pressed:text-foreground aria-pressed:ring-1 aria-pressed:ring-primary'), onMouseDown: keep, onPressedChange: () => onFormat(item.id), children: [_jsx(Icon, { "aria-hidden": "true" }), item.label] }, item.id));
|
|
210
|
+
}), onImage && (_jsxs(Button, { variant: "ghost", disabled: readOnly, className: cn(TILE, 'hover:bg-muted'), onMouseDown: keep, onClick: onImage, children: [_jsx(ImageIcon, { "aria-hidden": "true" }), "Image"] })), onFullScreen && (_jsxs(Toggle, { pressed: fullScreen, className: cn(TILE, 'aria-pressed:bg-primary/15 aria-pressed:text-foreground aria-pressed:ring-1 aria-pressed:ring-primary'), onMouseDown: keep, onPressedChange: () => {
|
|
211
|
+
setPanel(false);
|
|
212
|
+
onFullScreen();
|
|
213
|
+
}, children: [fullScreen ? _jsx(Minimize2Icon, { "aria-hidden": "true" }) : _jsx(Maximize2Icon, { "aria-hidden": "true" }), fullScreen ? 'Leave Full Screen' : 'Full Screen'] }))] })] }))] }));
|
|
214
|
+
}
|
|
@@ -98,7 +98,8 @@ export function tableView(node, view, getPos, registry) {
|
|
|
98
98
|
const dom = document.createElement('div');
|
|
99
99
|
dom.dataset.slot = 'rich-text-table';
|
|
100
100
|
// As wide as the table (its columns fit their words), never wider than the text.
|
|
101
|
-
|
|
101
|
+
// On a touch screen, room above for the column grip's tap area (review F11).
|
|
102
|
+
dom.className = 'group/table relative grid w-fit max-w-full grid-cols-[minmax(0,auto)_auto] gap-1 pointer-coarse:pt-3';
|
|
102
103
|
const scroll = document.createElement('div');
|
|
103
104
|
// Its look: styles/index.css "Tables in written text".
|
|
104
105
|
scroll.className = cn('prose-table', TABLE_SCROLL_FOCUS);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Slice, type Node as ProseNode } from '@milkdown/kit/prose/model';
|
|
2
|
+
import type { EditorView } from '@milkdown/kit/prose/view';
|
|
3
|
+
/** What a paste says when it carries images the field can't take. */
|
|
4
|
+
export declare const NO_IMAGES_HERE = "Images can't be added here.";
|
|
5
|
+
/** The address `text` is, when it is one web or email address alone; else `null`. */
|
|
6
|
+
export declare function addressOf(text: string): string | null;
|
|
7
|
+
/** A paste's HTML, before ProseMirror reads it: Word's lists, to-dos and code languages made readable. */
|
|
8
|
+
export declare function pasteHtml(html: string): string;
|
|
9
|
+
export type PasteImages = {
|
|
10
|
+
/** Images carried in the HTML as `data:`, to upload (none when the field has no `upload`). */
|
|
11
|
+
images: File[];
|
|
12
|
+
/** How many images were left out (no `upload`, or an address that's refused). */
|
|
13
|
+
dropped: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A paste, as ProseMirror read it, made safe to save: see the file's
|
|
17
|
+
* opening. `uploads`: whether the field takes images; without it a
|
|
18
|
+
* `data:` image is dropped and counted.
|
|
19
|
+
*/
|
|
20
|
+
export declare function cleanPasted(view: EditorView, slice: Slice, uploads: boolean): {
|
|
21
|
+
slice: Slice;
|
|
22
|
+
} & PasteImages;
|
|
23
|
+
/**
|
|
24
|
+
* Lines of plain text pasted into a table cell, joined with spaces (a GFM
|
|
25
|
+
* cell is one line). Called before the table's own paste, which would
|
|
26
|
+
* spread them over the row. Returns whether it was this paste.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pasteLinesIntoCell(view: EditorView, text: string): boolean;
|
|
29
|
+
export type PlainPaste = {
|
|
30
|
+
/** The editor's Markdown parser. */
|
|
31
|
+
parse: (markdown: string) => ProseNode | string | null | undefined;
|
|
32
|
+
/** The clipboard has HTML too: only an address over selected words is this paste's. */
|
|
33
|
+
hasHtml: boolean;
|
|
34
|
+
/** Whether the field takes images (`upload`). */
|
|
35
|
+
uploads: boolean;
|
|
36
|
+
/** Images the Markdown carried as `data:`, after the paste went in (cleanPasted). */
|
|
37
|
+
onImages: (images: PasteImages) => void;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The paste of `text` (the clipboard's plain text). Returns whether it was
|
|
41
|
+
* handled; else ProseMirror's own paste goes on.
|
|
42
|
+
*/
|
|
43
|
+
export declare function pastePlainText(view: EditorView, text: string, { parse, hasHtml, uploads, onImages }: PlainPaste): boolean;
|