@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
|
@@ -356,7 +356,7 @@ function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop
|
|
|
356
356
|
return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx("div", { ref: setMarker, "aria-hidden": "true", "data-slot": "entity-view-tabs-marker", className: "h-px -mb-6" }), _jsxs("div", { ref: setBar, "data-slot": "entity-view-tab-bar", "data-stuck": stuck ? '' : undefined,
|
|
357
357
|
// A record dialog's body sets --entity-view-sticky-top to minus its
|
|
358
358
|
// padding, so the bar sits at the body's own top edge there.
|
|
359
|
-
style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: cn('sticky z-10 -mx-1 flex min-w-0 flex-col gap-1 bg-background px-1 pt-0 data-[stuck]:pt-2 data-[stuck]:shadow-[0_8px_12px_-10px_var(--color-foreground)]', aside !== undefined && FACTS_RAIL.barBeside), children: [stuck && title && (_jsx("p", { "data-slot": "entity-view-tab-bar-title", "aria-hidden": "true", className: "truncate type-label font-semibold text-foreground", children: title })), _jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-0 overflow-x-auto overflow-y-hidden border-b border-border p-0 md:gap-1 [scrollbar-width:thin]", children: tabs.map((tab) => {
|
|
359
|
+
style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: cn('sticky z-10 -mx-1 flex min-w-0 flex-col gap-1 bg-background px-1 pt-0 data-[stuck]:pt-2 data-[stuck]:mb-[calc(-1*(var(--type-label-leading)+--spacing(3)))] data-[stuck]:shadow-[0_8px_12px_-10px_var(--color-foreground)]', aside !== undefined && FACTS_RAIL.barBeside), children: [stuck && title && (_jsx("p", { "data-slot": "entity-view-tab-bar-title", "aria-hidden": "true", className: "h-(--type-label-leading) truncate type-label font-semibold text-foreground", children: title })), _jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-0 overflow-x-auto overflow-y-hidden border-b border-border p-0 md:gap-1 [scrollbar-width:thin]", children: tabs.map((tab) => {
|
|
360
360
|
const count = countOf(tab);
|
|
361
361
|
return (_jsxs(TabsTrigger, { value: tab.slug, className: "h-11 flex-none gap-1.5 rounded-b-none px-2.5 text-sm font-semibold text-muted-foreground group-data-horizontal/tabs:after:bottom-0 group-data-horizontal/tabs:after:h-[3px] after:bg-primary data-active:font-bold! data-active:text-primary-text md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-primary-text", children: [_jsx("span", { "data-slot": "entity-view-tab-name", "data-text": tab.name, className: "inline-grid after:invisible after:col-start-1 after:row-start-1 after:h-0 after:font-bold after:content-[attr(data-text)]", children: _jsx("span", { className: "col-start-1 row-start-1", children: tab.name }) }), count > 0 && (_jsx("span", { "data-slot": "entity-view-tab-count", className: "rounded-full bg-muted px-1.5 text-xs leading-[1.0625rem] font-medium tabular-nums text-foreground", children: count }))] }, tab.slug));
|
|
362
362
|
}) })] }), aside === undefined ? (panels) : (_jsxs("div", { "data-slot": "entity-view-with-facts", className: FACTS_RAIL.columns, children: [panels, aside] }))] }));
|
|
@@ -15,12 +15,18 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
15
15
|
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
16
16
|
import { useBlocker } from 'react-router';
|
|
17
17
|
import { DiscardChangesDialog } from '../ui/dialog.js';
|
|
18
|
+
import { flushPendingEdits } from '../../lib/pending-edits.js';
|
|
18
19
|
export function FormLeaveGuard({ dirty, letThrough }) {
|
|
19
20
|
const latest = useRef({ dirty, letThrough });
|
|
20
21
|
useLayoutEffect(() => {
|
|
21
22
|
latest.current = { dirty, letThrough };
|
|
22
23
|
});
|
|
23
|
-
|
|
24
|
+
// Typing a rich-text field holds back (F6) is reported first; the form
|
|
25
|
+
// marks itself dirty from it as it does from any change.
|
|
26
|
+
const blocker = useBlocker(({ currentLocation, nextLocation }) => {
|
|
27
|
+
flushPendingEdits();
|
|
28
|
+
return latest.current.dirty && !latest.current.letThrough() && currentLocation.pathname !== nextLocation.pathname;
|
|
29
|
+
});
|
|
24
30
|
useEffect(() => {
|
|
25
31
|
if (!dirty)
|
|
26
32
|
return;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { RichTextEditorProps } from './rich-text-editor.js';
|
|
2
|
+
export declare const MERGE_PAUSE_MS = 300;
|
|
2
3
|
export default function MilkdownEditor({ id, defaultValue, onChange, onProblem, readOnly, autoFocus, placeholder, maxLength, toolbar, inline, upload, imageAccept, imageMaxSize, headingLevel, headingFrom, foldKey, tableLook, pageLink, onCreatePage, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }: RichTextEditorProps): import("react").JSX.Element;
|
|
@@ -37,7 +37,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
37
37
|
// Markdown writes them (src/lib/markdown-table.ts).
|
|
38
38
|
// - Edited blocks are written in the document's own bullet and rule marks.
|
|
39
39
|
// - Markdown pasted as plain text arrives formatted (still no HTML), and a
|
|
40
|
-
// copy out of the editor is Markdown.
|
|
40
|
+
// copy out of the editor is Markdown. A paste keeps its lines, Word's
|
|
41
|
+
// and Notion's lists and to-dos, and code's language; an address pasted
|
|
42
|
+
// or typed becomes a link; a paste can't bring in a link that runs code
|
|
43
|
+
// or an image as `data:` (rich-text-paste.ts, rich-text-autolink.ts).
|
|
44
|
+
// - An edit the merge refuses is never saved quietly: the field is marked
|
|
45
|
+
// invalid, and says why in itself when the app gives no `onProblem`
|
|
46
|
+
// (with one, the app shows it: a form's field error, editing in
|
|
47
|
+
// place's line).
|
|
48
|
+
// - Full screen holds focus: the page behind it is inert until it ends
|
|
49
|
+
// (rich-text-full-screen.ts).
|
|
41
50
|
// - A click on a link opens it in a new tab, as the read view's links do,
|
|
42
51
|
// so notes that are always the editor still follow their links
|
|
43
52
|
// (followLink). Ctrl/Cmd+K adds or edits a link (a box at the caret: web
|
|
@@ -76,11 +85,10 @@ import { createPortal } from 'react-dom';
|
|
|
76
85
|
import { useInRouterContext, useNavigate } from 'react-router';
|
|
77
86
|
import { defaultValueCtx, Editor, editorViewCtx, editorViewOptionsCtx, parserCtx, remarkStringifyOptionsCtx, rootCtx, schemaCtx, serializerCtx, } from '@milkdown/kit/core';
|
|
78
87
|
import { history } from '@milkdown/kit/plugin/history';
|
|
79
|
-
import { commands, headingSchema, paragraphSchema,
|
|
88
|
+
import { commands, headingSchema, paragraphSchema, keymap, plugins, remarkPreserveEmptyLinePlugin, schema, } from '@milkdown/kit/preset/commonmark';
|
|
80
89
|
import { gfm, tableCellSchema, tableHeaderSchema, tableSchema } from '@milkdown/kit/preset/gfm';
|
|
81
|
-
import { Fragment, Slice } from '@milkdown/kit/prose/model';
|
|
82
90
|
import { NodeSelection, Plugin, TextSelection } from '@milkdown/kit/prose/state';
|
|
83
|
-
import { isInTable, TableMap } from '@milkdown/kit/prose/tables';
|
|
91
|
+
import { isInTable, selectedRect, TableMap } from '@milkdown/kit/prose/tables';
|
|
84
92
|
import { Decoration, DecorationSet } from '@milkdown/kit/prose/view';
|
|
85
93
|
import { $markSchema, $nodeSchema, $prose, $remark, getMarkdown } from '@milkdown/kit/utils';
|
|
86
94
|
import { cn } from 'cn';
|
|
@@ -100,16 +108,20 @@ import { formatTableWidths, remarkTableWidths } from '../../lib/markdown-table-w
|
|
|
100
108
|
import { DEFAULT_HIGHLIGHT, highlightHandler, isHighlightColor, remarkHighlightNodes } from '../../lib/markdown-highlight.js';
|
|
101
109
|
import { textTopHeading } from '../../lib/markdown-top-heading.js';
|
|
102
110
|
import { MarkdownMergeError, markdownStyle, mergeMarkdown } from '../../lib/markdown-merge.js';
|
|
111
|
+
import { holdPendingEdit } from '../../lib/pending-edits.js';
|
|
103
112
|
import { foldStore, listenForOtherTabs } from '../../hooks/fold-store.js';
|
|
104
113
|
import { toggleFold } from '../../lib/markdown-fold.js';
|
|
105
114
|
import { DEFAULT_HEADING_LEVEL, FOLD_BUTTON, FOLD_HEADING, headingBand, headingClass, headingTag } from './prose-look.js';
|
|
106
115
|
import { foldPlugin, foldSpecOf, setFolds } from './rich-text-fold.js';
|
|
107
116
|
import { RichTextFloatingToolbar } from './rich-text-floating-toolbar.js';
|
|
108
|
-
import { tableAt, toggleFormat } from './rich-text-formats.js';
|
|
117
|
+
import { formatOn, tableAt, toggleFormat } from './rich-text-formats.js';
|
|
118
|
+
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
|
|
109
119
|
import { calloutKind, calloutView, tableView } from './rich-text-node-views.js';
|
|
110
120
|
import { droppedFiles, imageUploadPlugin, pastedImages, uploadImages, uploadPlaceholders } from './rich-text-image-upload.js';
|
|
111
121
|
import { handleShortcut } from './rich-text-shortcuts.js';
|
|
112
|
-
import { splitTaskItem, taskInputRule } from './rich-text-tasks.js';
|
|
122
|
+
import { splitTaskItem, TASK_ROW, taskBoxHit, taskInputRule } from './rich-text-tasks.js';
|
|
123
|
+
import { typedInputRules } from './rich-text-input-rules.js';
|
|
124
|
+
import { edges } from './rich-text-edges.js';
|
|
113
125
|
import { withEmptyParagraphChildren } from './rich-text-empty-paragraph.js';
|
|
114
126
|
import { toggleHeadingInputRule, toggleHeadingRemark, withToggle } from './rich-text-toggle-heading.js';
|
|
115
127
|
import { addRowAtEnd, colorTableCells, fitAllColumns, handleTableKey, previewColumnWidth, runTableAction, setColumnWidth, tableLook as tableLookPlugin, tableWidthsOf } from './rich-text-table.js';
|
|
@@ -118,14 +130,18 @@ import { applySlash, clearSlash, closeSlash, slashItems, slashOptionId, slashPlu
|
|
|
118
130
|
import { RichTextSlashMenu } from './rich-text-slash-menu.js';
|
|
119
131
|
import { RichTextToolbar } from './rich-text-toolbar.js';
|
|
120
132
|
import { RichTextToolsBar } from './rich-text-tools-bar.js';
|
|
133
|
+
import { RichTextKeyboardBar } from './rich-text-keyboard-bar.js';
|
|
134
|
+
import { useCoarsePointer } from './rich-text-touch.js';
|
|
135
|
+
import { autolinkPlugin, linkWordBefore } from './rich-text-autolink.js';
|
|
136
|
+
import { useHoldFocus } from './rich-text-full-screen.js';
|
|
137
|
+
import { cleanPasted, NO_IMAGES_HERE, pasteHtml, pasteLinesIntoCell, pastePlainText } from './rich-text-paste.js';
|
|
121
138
|
import { CalloutKindMenu, TableBar } from './rich-text-widgets.js';
|
|
122
139
|
// The commonmark preset, minus the plugin that writes `<br />`. A $remark
|
|
123
140
|
// plugin is a pair (its options and the plugin), spread into `plugins`.
|
|
124
141
|
const LEFT_OUT = remarkPreserveEmptyLinePlugin;
|
|
125
142
|
const COMMONMARK = [
|
|
126
143
|
...schema,
|
|
127
|
-
...
|
|
128
|
-
...markInputRules,
|
|
144
|
+
...typedInputRules,
|
|
129
145
|
...commands,
|
|
130
146
|
...keymap,
|
|
131
147
|
...plugins.filter((plugin) => !LEFT_OUT.includes(plugin)),
|
|
@@ -230,22 +246,42 @@ function emptyImageTitles(node) {
|
|
|
230
246
|
node.children?.forEach(emptyImageTitles);
|
|
231
247
|
}
|
|
232
248
|
const imageTitles = $remark('imageTitles', () => () => (tree) => emptyImageTitles(tree));
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
249
|
+
// What the field says when the merge refuses an edit (markdown-merge.ts):
|
|
250
|
+
// to the app's `onProblem`, and in the field itself.
|
|
251
|
+
// How long typing has to stop before the edit is turned back into
|
|
252
|
+
// Markdown (mergeMarkdown) and reported through onChange (F6).
|
|
253
|
+
export const MERGE_PAUSE_MS = 300;
|
|
254
|
+
// Every format a toolbar can show as on.
|
|
255
|
+
const SHOWN_FORMATS = [
|
|
256
|
+
...new Set([...FORMAT_GROUPS.flat(), ...TOGGLE_HEADING_VARIANTS, ...CALLOUT_VARIANTS, ...HIGHLIGHT_VARIANTS].map((item) => item.id)),
|
|
257
|
+
];
|
|
258
|
+
// What the editor's React parts draw from its state, as one string: the
|
|
259
|
+
// formats on, the selection (where only when there is one: a caret's
|
|
260
|
+
// place matters to nothing drawn but the slash menu and a table's grips),
|
|
261
|
+
// the slash menu's query, a table's caret cell and the uploads. A key
|
|
262
|
+
// that doesn't change it re-renders nothing (F6).
|
|
263
|
+
function shownKey(state) {
|
|
264
|
+
const { selection } = state;
|
|
265
|
+
const parts = [selection.empty ? 'caret' : `${selection.from}-${selection.to}`];
|
|
266
|
+
if (selection instanceof NodeSelection)
|
|
267
|
+
parts.push('node');
|
|
268
|
+
if (selection.$from.parent.type.spec.code)
|
|
269
|
+
parts.push('code');
|
|
270
|
+
if (!selection.empty && selection.$from.sameParent(selection.$to))
|
|
271
|
+
parts.push('one-block');
|
|
272
|
+
parts.push(SHOWN_FORMATS.filter((id) => formatOn(state, id)).join(','));
|
|
273
|
+
const slash = slashQuery(state);
|
|
274
|
+
if (slash)
|
|
275
|
+
parts.push(`slash:${slash.from}:${slash.to}:${slash.query}`);
|
|
276
|
+
const table = tableAt(state);
|
|
277
|
+
if (table && isInTable(state)) {
|
|
278
|
+
const { top, left } = selectedRect(state);
|
|
279
|
+
parts.push(`table:${table.pos}:${top}:${left}`);
|
|
280
|
+
}
|
|
281
|
+
parts.push(`uploads:${uploadPlaceholders(state).length}`);
|
|
282
|
+
return parts.join('|');
|
|
248
283
|
}
|
|
284
|
+
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.";
|
|
249
285
|
// A heading: the element `headingLevel` gives its level, the look its
|
|
250
286
|
// level has. Marked as a band for PROSE_INSET (`#` and `##`).
|
|
251
287
|
//
|
|
@@ -346,7 +382,8 @@ function taskItemView(node, view, getPos) {
|
|
|
346
382
|
const contentDOM = document.createElement('div');
|
|
347
383
|
// Takes the row's width, so an empty item's caret and placeholder show.
|
|
348
384
|
contentDOM.className = 'min-w-0 flex-1';
|
|
349
|
-
dom.append(box, contentDOM);
|
|
385
|
+
dom.append(taskBoxHit(box), contentDOM);
|
|
386
|
+
dom.className = TASK_ROW;
|
|
350
387
|
dom.dataset.itemType = 'task';
|
|
351
388
|
let current = node;
|
|
352
389
|
const render = () => {
|
|
@@ -374,8 +411,8 @@ function taskItemView(node, view, getPos) {
|
|
|
374
411
|
render();
|
|
375
412
|
return true;
|
|
376
413
|
},
|
|
377
|
-
stopEvent: (event) => event.target === box,
|
|
378
|
-
ignoreMutation: (mutation) => mutation.target === box,
|
|
414
|
+
stopEvent: (event) => event.target === box || event.target === box.parentElement,
|
|
415
|
+
ignoreMutation: (mutation) => mutation.target === box || mutation.target === box.parentElement,
|
|
379
416
|
};
|
|
380
417
|
}
|
|
381
418
|
// The task-list item the caret is in, ticked or unticked. False when the
|
|
@@ -516,6 +553,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
516
553
|
const navigateRef = useRef(null);
|
|
517
554
|
const inRouter = useInRouterContext();
|
|
518
555
|
const [length, setLength] = useState(defaultValue.length);
|
|
556
|
+
// Why the last edit can't be saved, shown in the field (REFUSED_EDIT).
|
|
557
|
+
const [refused, setRefused] = useState(null);
|
|
519
558
|
// The editor's state after each change, for the toolbar's pressed buttons.
|
|
520
559
|
const [editorState, setEditorState] = useState(null);
|
|
521
560
|
const [editorView, setEditorView] = useState(null);
|
|
@@ -523,7 +562,16 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
523
562
|
// toolbar), the mouse is down choosing words, and the selection Esc hid
|
|
524
563
|
// it for.
|
|
525
564
|
const [focused, setFocused] = useState(false);
|
|
526
|
-
const [selecting,
|
|
565
|
+
const [selecting, setSelectingState] = useState(false);
|
|
566
|
+
// Set only when it changes: a key sets it false, and React would draw
|
|
567
|
+
// the whole editor again for the first key after a click (F6).
|
|
568
|
+
const selectingRef = useRef(false);
|
|
569
|
+
const setSelecting = (next) => {
|
|
570
|
+
if (selectingRef.current === next)
|
|
571
|
+
return;
|
|
572
|
+
selectingRef.current = next;
|
|
573
|
+
setSelectingState(next);
|
|
574
|
+
};
|
|
527
575
|
const [dismissed, setDismissed] = useState(null);
|
|
528
576
|
const toolbarRef = useRef(null);
|
|
529
577
|
const floatingRef = useRef(null);
|
|
@@ -564,20 +612,29 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
564
612
|
document.body.style.overflow = overflow;
|
|
565
613
|
};
|
|
566
614
|
}, [fullScreen]);
|
|
615
|
+
// The page behind full screen is inert meanwhile (rich-text-full-screen.ts).
|
|
616
|
+
useHoldFocus(field, fullScreen);
|
|
567
617
|
// The toolbar's Image button opens this file picker.
|
|
568
618
|
const imageInputRef = useRef(null);
|
|
569
619
|
// The fixed bar above the text, and the menus over it (the floating
|
|
570
620
|
// toolbar and the slash menu), which `'floating'` keeps on their own.
|
|
571
|
-
|
|
621
|
+
// On a touch screen, the bar pinned to the keyboard in their place
|
|
622
|
+
// (rich-text-keyboard-bar.tsx).
|
|
623
|
+
const coarse = useCoarsePointer();
|
|
624
|
+
const fixedToolbar = toolbar === true && !coarse;
|
|
572
625
|
const menus = toolbar !== false;
|
|
573
626
|
const ids = useId();
|
|
574
627
|
const counterId = `${ids}-count`;
|
|
628
|
+
const problemId = `${ids}-problem`;
|
|
575
629
|
// The editable element's id: the app's, or one of its own, so the
|
|
576
630
|
// toolbar can name what it controls.
|
|
577
631
|
const editableId = id ?? `${ids}-text`;
|
|
578
632
|
// The count shows from 80% of the limit: below that it's noise.
|
|
579
633
|
const showCount = maxLength !== undefined && length >= maxLength * 0.8;
|
|
580
|
-
|
|
634
|
+
// The field says it itself when the app hears of it through no
|
|
635
|
+
// `onProblem` (a form that passes none would save the old text quietly).
|
|
636
|
+
const ownProblem = onProblem ? null : refused;
|
|
637
|
+
const describedBy = [ariaDescribedBy, ownProblem ? problemId : undefined, showCount ? counterId : undefined].filter(Boolean).join(' ');
|
|
581
638
|
const attributes = {
|
|
582
639
|
'aria-multiline': 'true',
|
|
583
640
|
'aria-readonly': String(readOnly),
|
|
@@ -590,7 +647,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
590
647
|
attributes['aria-labelledby'] = ariaLabelledBy;
|
|
591
648
|
if (describedBy)
|
|
592
649
|
attributes['aria-describedby'] = describedBy;
|
|
593
|
-
if (ariaInvalid)
|
|
650
|
+
if (ariaInvalid || refused)
|
|
594
651
|
attributes['aria-invalid'] = 'true';
|
|
595
652
|
if (placeholder)
|
|
596
653
|
attributes['aria-placeholder'] = placeholder;
|
|
@@ -599,7 +656,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
599
656
|
// The slash menu: open while a "/" typed at a line's start is followed
|
|
600
657
|
// by something some block answers to, and the field has focus.
|
|
601
658
|
const slash = menus && !readOnly && focused && editorState ? slashQuery(editorState) : null;
|
|
602
|
-
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage), image: Boolean(upload) }) : [];
|
|
659
|
+
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage), image: Boolean(upload), at: editorState ? { state: editorState, span: slash } : undefined }) : [];
|
|
603
660
|
const slashOpen = slash !== null && slashMatches.length > 0;
|
|
604
661
|
const slashMenuKey = slash ? `${slash.from}:${slash.query}` : '';
|
|
605
662
|
const slashIndex = slashActive.key === slashMenuKey ? Math.min(slashActive.index, slashMatches.length - 1) : 0;
|
|
@@ -622,13 +679,35 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
622
679
|
const textTop = headingFrom === 'text' ? textTopHeading(original) : 1;
|
|
623
680
|
let baseline = null;
|
|
624
681
|
let cancelled = false;
|
|
682
|
+
// The last shownKey React drew.
|
|
683
|
+
let shown = '';
|
|
684
|
+
// The merge runs a pause after typing stops (MERGE_PAUSE_MS), not on
|
|
685
|
+
// every key: its cost grows with the note (F6). Anything about to read
|
|
686
|
+
// the value first asks for it (flushPendingEdits, src/lib/pending-edits.ts),
|
|
687
|
+
// and leaving the text, Esc, Ctrl/Cmd+Enter, hiding the page and
|
|
688
|
+
// unmounting report it at once.
|
|
689
|
+
let pause;
|
|
690
|
+
let release = null;
|
|
691
|
+
const editedSoon = () => {
|
|
692
|
+
clearTimeout(pause);
|
|
693
|
+
pause = setTimeout(emit, MERGE_PAUSE_MS);
|
|
694
|
+
if (!release)
|
|
695
|
+
release = holdPendingEdit(emit);
|
|
696
|
+
};
|
|
625
697
|
const emit = () => {
|
|
698
|
+
clearTimeout(pause);
|
|
699
|
+
pause = undefined;
|
|
700
|
+
if (!release)
|
|
701
|
+
return;
|
|
702
|
+
release();
|
|
703
|
+
release = null;
|
|
626
704
|
const editor = editorRef.current;
|
|
627
705
|
if (!editor || baseline === null)
|
|
628
706
|
return;
|
|
629
707
|
const current = editor.action(getMarkdown());
|
|
630
708
|
try {
|
|
631
709
|
const merged = mergeMarkdown(original, baseline, current);
|
|
710
|
+
setRefused(null);
|
|
632
711
|
latest.current.onProblem?.(null);
|
|
633
712
|
latest.current.onChange(merged);
|
|
634
713
|
setLength(merged.length);
|
|
@@ -636,7 +715,10 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
636
715
|
catch (error) {
|
|
637
716
|
if (!(error instanceof MarkdownMergeError))
|
|
638
717
|
throw error;
|
|
639
|
-
|
|
718
|
+
// onChange isn't called: the app keeps the last text that could
|
|
719
|
+
// be saved, and the field says why it stopped.
|
|
720
|
+
setRefused(REFUSED_EDIT);
|
|
721
|
+
latest.current.onProblem?.(REFUSED_EDIT);
|
|
640
722
|
}
|
|
641
723
|
};
|
|
642
724
|
const changes = $prose(() => new Plugin({
|
|
@@ -644,16 +726,31 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
644
726
|
update: (view, previous) => {
|
|
645
727
|
if (cancelled)
|
|
646
728
|
return;
|
|
647
|
-
|
|
648
|
-
//
|
|
649
|
-
|
|
650
|
-
|
|
729
|
+
// React hears of the state only when something it draws
|
|
730
|
+
// from it changed (shownKey): most keys re-render nothing.
|
|
731
|
+
const key = shownKey(view.state);
|
|
732
|
+
if (key !== shown) {
|
|
733
|
+
shown = key;
|
|
734
|
+
setEditorState(view.state);
|
|
735
|
+
// Esc hides the floating toolbar for one selection only.
|
|
736
|
+
if (view.state.selection.empty)
|
|
737
|
+
setDismissed(null);
|
|
738
|
+
}
|
|
651
739
|
if (!view.state.doc.eq(previous.doc))
|
|
652
|
-
|
|
740
|
+
editedSoon();
|
|
653
741
|
},
|
|
654
742
|
}),
|
|
655
743
|
props: {
|
|
656
|
-
|
|
744
|
+
// Word's lists, to-dos and code languages, before the HTML is read.
|
|
745
|
+
transformPastedHTML: (html) => pasteHtml(html),
|
|
746
|
+
// No HTML, no link that runs code, no image as `data:`; in a
|
|
747
|
+
// cell, one line (rich-text-paste.ts).
|
|
748
|
+
transformPasted: (slice, view) => {
|
|
749
|
+
const { slice: cleaned, images, dropped } = cleanPasted(view, slice, Boolean(latest.current.upload));
|
|
750
|
+
if (images.length > 0 || dropped > 0)
|
|
751
|
+
setTimeout(() => pastedImagesLanded(view, { images, dropped }), 0);
|
|
752
|
+
return cleaned;
|
|
753
|
+
},
|
|
657
754
|
},
|
|
658
755
|
}));
|
|
659
756
|
// The node views' slots, by slot; React hears of a change once per
|
|
@@ -704,6 +801,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
704
801
|
// made will be linked.
|
|
705
802
|
const pageLinks = $prose(() => pageLinksPlugin({ resolve: () => latest.current.pageLink, restore: restorePage, editable: () => !latest.current.readOnly }));
|
|
706
803
|
const pendingPages = $prose(() => pendingPagePlugin());
|
|
804
|
+
// An address typed and ended with a space becomes a link.
|
|
805
|
+
const autolink = $prose(() => autolinkPlugin());
|
|
707
806
|
// Images pasted or dropped, uploaded through the app's `upload`; with
|
|
708
807
|
// none given, a paste or drop is left to the handlers after this one,
|
|
709
808
|
// as if this weren't here.
|
|
@@ -715,26 +814,49 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
715
814
|
uploadImages(view, files, at, { upload: send, accept, maxSize, onError: (message) => toast.error(message) });
|
|
716
815
|
return true;
|
|
717
816
|
};
|
|
817
|
+
// Images a paste carried as `data:`: uploaded at the caret once the
|
|
818
|
+
// paste is in, or, with no `upload`, said no to.
|
|
819
|
+
const pastedImagesLanded = (view, { images, dropped }) => {
|
|
820
|
+
if (cancelled || view.isDestroyed)
|
|
821
|
+
return;
|
|
822
|
+
if (images.length > 0)
|
|
823
|
+
startUploads(view, images, null);
|
|
824
|
+
if (dropped > 0)
|
|
825
|
+
toast.error(NO_IMAGES_HERE);
|
|
826
|
+
};
|
|
718
827
|
const imageInput = $prose(() => new Plugin({
|
|
719
828
|
props: {
|
|
829
|
+
// Without `upload`, an image file pasted or dropped says it
|
|
830
|
+
// can't go in (any words with it still paste).
|
|
720
831
|
handlePaste: (view, event) => {
|
|
721
|
-
if (!
|
|
832
|
+
if (!view.editable)
|
|
722
833
|
return false;
|
|
723
834
|
const files = pastedImages(event.clipboardData);
|
|
724
835
|
if (files.length === 0)
|
|
725
836
|
return false;
|
|
837
|
+
if (!latest.current.upload) {
|
|
838
|
+
toast.error(NO_IMAGES_HERE);
|
|
839
|
+
if (event.clipboardData?.getData('text/plain'))
|
|
840
|
+
return false;
|
|
841
|
+
event.preventDefault();
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
726
844
|
event.preventDefault();
|
|
727
845
|
return startUploads(view, files, null);
|
|
728
846
|
},
|
|
729
847
|
// Files from outside (a text or an image moved within the
|
|
730
848
|
// editor carries none).
|
|
731
849
|
handleDrop: (view, event, _slice, moved) => {
|
|
732
|
-
if (moved || !
|
|
850
|
+
if (moved || !view.editable)
|
|
733
851
|
return false;
|
|
734
852
|
const files = droppedFiles(event.dataTransfer);
|
|
735
853
|
if (files.length === 0)
|
|
736
854
|
return false;
|
|
737
855
|
event.preventDefault();
|
|
856
|
+
if (!latest.current.upload) {
|
|
857
|
+
toast.error(NO_IMAGES_HERE);
|
|
858
|
+
return true;
|
|
859
|
+
}
|
|
738
860
|
const at = view.posAtCoords({ left: event.clientX, top: event.clientY })?.pos ?? view.state.selection.from;
|
|
739
861
|
return startUploads(view, files, at);
|
|
740
862
|
},
|
|
@@ -745,26 +867,19 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
745
867
|
// Plain text is read as Markdown, so `## Notes` or `**bold**`
|
|
746
868
|
// copied from another app arrives formatted; raw HTML in it
|
|
747
869
|
// still arrives as text. A paste with HTML of its own (from a
|
|
748
|
-
// web page) is ProseMirror's, through transformPasted above
|
|
870
|
+
// web page) is ProseMirror's, through transformPasted above,
|
|
871
|
+
// but for an address pasted over words, which links them
|
|
872
|
+
// (rich-text-paste.ts).
|
|
749
873
|
handlePaste: (view, event) => {
|
|
750
874
|
const data = event.clipboardData;
|
|
751
|
-
if (!data || !view.editable
|
|
752
|
-
return false;
|
|
753
|
-
const text = data.getData('text/plain');
|
|
754
|
-
if (!text || view.state.selection.$from.parent.type.spec.code)
|
|
755
|
-
return false;
|
|
756
|
-
const parsed = ctx.get(parserCtx)(text);
|
|
757
|
-
if (!parsed || typeof parsed === 'string')
|
|
875
|
+
if (!data || !view.editable)
|
|
758
876
|
return false;
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
}
|
|
766
|
-
view.dispatch(view.state.tr.replaceSelection(Slice.maxOpen(htmlToText(parsed.content))).scrollIntoView());
|
|
767
|
-
return true;
|
|
877
|
+
return pastePlainText(view, data.getData('text/plain'), {
|
|
878
|
+
parse: (markdown) => ctx.get(parserCtx)(markdown),
|
|
879
|
+
hasHtml: Boolean(data.getData('text/html')),
|
|
880
|
+
uploads: Boolean(latest.current.upload),
|
|
881
|
+
onImages: (images) => pastedImagesLanded(view, images),
|
|
882
|
+
});
|
|
768
883
|
},
|
|
769
884
|
// A copy is Markdown, so it pastes into a plain text field
|
|
770
885
|
// (or another Markdown editor) as written.
|
|
@@ -780,7 +895,9 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
780
895
|
return false;
|
|
781
896
|
},
|
|
782
897
|
// Moving to the floating toolbar keeps it showing.
|
|
898
|
+
// Leaving the text reports what was typed (F6).
|
|
783
899
|
blur: (_view, event) => {
|
|
900
|
+
emit();
|
|
784
901
|
if (!inFloating(event.relatedTarget))
|
|
785
902
|
setFocused(false);
|
|
786
903
|
return false;
|
|
@@ -803,6 +920,10 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
803
920
|
},
|
|
804
921
|
handleKeyDown: (view, event) => {
|
|
805
922
|
setSelecting(false);
|
|
923
|
+
// Esc and Ctrl/Cmd+Enter are the field's (save, close): what
|
|
924
|
+
// was typed is reported before they reach it (F6).
|
|
925
|
+
if (event.key === 'Escape' || (event.key === 'Enter' && (event.metaKey || event.ctrlKey)))
|
|
926
|
+
emit();
|
|
806
927
|
// Alt+F10: to the floating toolbar when it shows, else the
|
|
807
928
|
// fixed one (the convention editors share).
|
|
808
929
|
if (event.altKey && event.key === 'F10') {
|
|
@@ -880,6 +1001,14 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
880
1001
|
...options,
|
|
881
1002
|
editable: () => !latest.current.readOnly,
|
|
882
1003
|
attributes,
|
|
1004
|
+
// Lines pasted into a table cell: one line, before the table's
|
|
1005
|
+
// own paste spreads them over the row (rich-text-paste.ts).
|
|
1006
|
+
handlePaste: (view, event) => {
|
|
1007
|
+
const data = event.clipboardData;
|
|
1008
|
+
if (!data || !view.editable || data.getData('text/html'))
|
|
1009
|
+
return false;
|
|
1010
|
+
return pasteLinesIntoCell(view, data.getData('text/plain'));
|
|
1011
|
+
},
|
|
883
1012
|
// The slash menu's keys, the editor's own shortcuts and its table
|
|
884
1013
|
// keys, as view props: before Milkdown's own keymap, whose Enter
|
|
885
1014
|
// would split the line (or leave a table).
|
|
@@ -929,6 +1058,9 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
929
1058
|
return true;
|
|
930
1059
|
}
|
|
931
1060
|
}
|
|
1061
|
+
// Enter after a typed address links it first (rich-text-autolink.ts).
|
|
1062
|
+
if (event.key === 'Enter' && !event.isComposing && !event.metaKey && !event.ctrlKey)
|
|
1063
|
+
linkWordBefore(view);
|
|
932
1064
|
// Enter in a task item: the next one, unticked (rich-text-tasks.ts).
|
|
933
1065
|
if (event.key === 'Enter' && plain && !event.isComposing && splitTaskItem(view.state, view.dispatch))
|
|
934
1066
|
return true;
|
|
@@ -947,6 +1079,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
947
1079
|
},
|
|
948
1080
|
}));
|
|
949
1081
|
})
|
|
1082
|
+
.use(edges)
|
|
950
1083
|
.use(COMMONMARK)
|
|
951
1084
|
.use(gfm)
|
|
952
1085
|
.use(taskInputRule)
|
|
@@ -970,6 +1103,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
970
1103
|
.use(imageUploads)
|
|
971
1104
|
.use(imageInput)
|
|
972
1105
|
.use(input)
|
|
1106
|
+
.use(autolink)
|
|
973
1107
|
.use(folds);
|
|
974
1108
|
void make.create().then((editor) => {
|
|
975
1109
|
if (cancelled) {
|
|
@@ -980,6 +1114,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
980
1114
|
baseline = editor.action(getMarkdown());
|
|
981
1115
|
const view = editor.action((ctx) => ctx.get(editorViewCtx));
|
|
982
1116
|
setEditorView(view);
|
|
1117
|
+
shown = shownKey(view.state);
|
|
983
1118
|
setEditorState(view.state);
|
|
984
1119
|
if (autoFocus)
|
|
985
1120
|
editor.action((ctx) => ctx.get(editorViewCtx).focus());
|
|
@@ -988,7 +1123,19 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
988
1123
|
stopFolds = foldStore.subscribe(foldKey, () => view.dispatch(setFolds(view.state, foldStore.get(foldKey))));
|
|
989
1124
|
}
|
|
990
1125
|
});
|
|
1126
|
+
// Hiding the page (another tab, a phone's home screen) reports what
|
|
1127
|
+
// was typed: the page may not come back.
|
|
1128
|
+
const onHidden = () => {
|
|
1129
|
+
if (document.visibilityState === 'hidden')
|
|
1130
|
+
emit();
|
|
1131
|
+
};
|
|
1132
|
+
document.addEventListener('visibilitychange', onHidden);
|
|
1133
|
+
window.addEventListener('pagehide', emit);
|
|
991
1134
|
return () => {
|
|
1135
|
+
document.removeEventListener('visibilitychange', onHidden);
|
|
1136
|
+
window.removeEventListener('pagehide', emit);
|
|
1137
|
+
// Unmounting reports what was typed since the last pause.
|
|
1138
|
+
emit();
|
|
992
1139
|
cancelled = true;
|
|
993
1140
|
stopFolds();
|
|
994
1141
|
setEditorState(null);
|
|
@@ -1144,10 +1291,18 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1144
1291
|
editorView.focus();
|
|
1145
1292
|
};
|
|
1146
1293
|
const caretTable = editorState ? tableAt(editorState)?.pos : undefined;
|
|
1294
|
+
// The caret's cell, for its table's grips: only while the text has focus.
|
|
1295
|
+
const caretCell = (() => {
|
|
1296
|
+
if (!focused || !editorState || caretTable === undefined || !isInTable(editorState))
|
|
1297
|
+
return null;
|
|
1298
|
+
const { top, left } = selectedRect(editorState);
|
|
1299
|
+
return { row: top, column: left };
|
|
1300
|
+
})();
|
|
1147
1301
|
// The floating toolbar: words selected, focus in the field, the mouse up,
|
|
1148
1302
|
// and nothing else open over the text.
|
|
1149
1303
|
const selection = editorState?.selection;
|
|
1150
1304
|
const floatingOpen = Boolean(menus &&
|
|
1305
|
+
!coarse &&
|
|
1151
1306
|
!readOnly &&
|
|
1152
1307
|
editorView &&
|
|
1153
1308
|
focused &&
|
|
@@ -1164,7 +1319,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1164
1319
|
});
|
|
1165
1320
|
const returnToText = () => editorView?.focus();
|
|
1166
1321
|
// The tools strip of a field with only the floating toolbar.
|
|
1167
|
-
const toolsOpen = Boolean(toolbar === 'floating' && editorView && (focused || fullScreen));
|
|
1322
|
+
const toolsOpen = Boolean(toolbar === 'floating' && !coarse && editorView && (focused || fullScreen));
|
|
1168
1323
|
const toggleFullScreen = () => {
|
|
1169
1324
|
setFullScreen((on) => !on);
|
|
1170
1325
|
editorView?.focus();
|
|
@@ -1248,7 +1403,9 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1248
1403
|
setLinkBox(null);
|
|
1249
1404
|
editorRef.current?.action((ctx) => ctx.get(editorViewCtx).focus());
|
|
1250
1405
|
};
|
|
1251
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { ref: setField, "data-slot": "rich-text-editor", "data-table-look": tableLook, "data-full-screen": fullScreen || undefined,
|
|
1406
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ref: setField, "data-slot": "rich-text-editor", "data-table-look": tableLook, "data-full-screen": fullScreen || undefined,
|
|
1407
|
+
// Full screen is a dialog over the page, named as the field is.
|
|
1408
|
+
role: fullScreen ? 'dialog' : undefined, "aria-modal": fullScreen || undefined, "aria-labelledby": fullScreen ? ariaLabelledBy : undefined, "aria-label": fullScreen && !ariaLabelledBy ? (ariaLabel ?? 'Text') : undefined, onKeyDown: leaveFullScreen, className: cn(fullScreen ? 'fixed inset-0 z-50 h-dvh rounded-none! border-0! bg-background! ring-0!' : 'relative', 'flex w-full min-w-0 flex-col bg-transparent type-body text-foreground break-words',
|
|
1252
1409
|
// Inline, it's the text itself: the caret shows where it's
|
|
1253
1410
|
// edited, and a refusal's reason under it says what's wrong.
|
|
1254
1411
|
!inline &&
|
|
@@ -1275,7 +1432,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1275
1432
|
// as typed, so one at the end of a line isn't kept as .
|
|
1276
1433
|
'[&_.ProseMirror]:whitespace-pre-wrap [&_.ProseMirror]:break-words', '[&_ul]:flex [&_ul]:list-disc [&_ul]:flex-col [&_ul]:gap-1 [&_ul]:pl-6', '[&_ol]:flex [&_ol]:list-decimal [&_ol]:flex-col [&_ol]:gap-1 [&_ol]:pl-6', '[&_li[data-item-type=task]]:-ml-6 [&_li[data-item-type=task]]:flex [&_li[data-item-type=task]]:list-none [&_li[data-item-type=task]]:items-start [&_li[data-item-type=task]]:gap-2',
|
|
1277
1434
|
// Highlighted words: the colour's wash, the text's own colour on it.
|
|
1278
|
-
'[&_mark]:rounded-sm [&_mark]:text-foreground [&_mark[data-color=amber]]:bg-highlight-amber [&_mark[data-color=yellow]]:bg-highlight-yellow [&_mark[data-color=green]]:bg-highlight-green [&_mark[data-color=red]]:bg-highlight-red',
|
|
1435
|
+
'[&_mark]:rounded-sm [&_mark]:text-foreground [&_mark[data-color=amber]]:bg-highlight-amber [&_mark[data-color=yellow]]:bg-highlight-yellow [&_mark[data-color=green]]:bg-highlight-green [&_mark[data-color=red]]:bg-highlight-red',
|
|
1279
1436
|
// Headings, callouts and tables are drawn by their node views;
|
|
1280
1437
|
// these are the elements Milkdown draws itself.
|
|
1281
1438
|
'[&_a]:cursor-pointer [&_a]:text-link [&_a]:underline [&_a]:decoration-link/40 [&_a]:underline-offset-4', '[&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:text-muted-foreground', '[&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:font-mono', '[&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:font-mono', '[&_hr]:my-2 [&_hr]:h-0.5 [&_hr]:rounded-full [&_hr]:border-0 [&_hr]:bg-rule', '[&_hr.ProseMirror-selectednode]:outline-2 [&_hr.ProseMirror-selectednode]:outline-offset-4 [&_hr.ProseMirror-selectednode]:outline-ring',
|
|
@@ -1286,7 +1443,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1286
1443
|
// Raw HTML from the text: shown as its characters, never as markup.
|
|
1287
1444
|
'[&_span[data-type=html]]:rounded [&_span[data-type=html]]:bg-muted [&_span[data-type=html]]:px-1 [&_span[data-type=html]]:font-mono [&_span[data-type=html]]:text-foreground',
|
|
1288
1445
|
// The placeholder, in an empty document only (a decoration).
|
|
1289
|
-
'[&_p[data-placeholder]]:before:pointer-events-none [&_p[data-placeholder]]:before:float-left [&_p[data-placeholder]]:before:h-0 [&_p[data-placeholder]]:before:text-muted-foreground [&_p[data-placeholder]]:before:content-[attr(data-placeholder)]') }), widgets.map((widget) => {
|
|
1446
|
+
'[&_p[data-placeholder]]:before:pointer-events-none [&_p[data-placeholder]]:before:float-left [&_p[data-placeholder]]:before:h-0 [&_p[data-placeholder]]:before:text-muted-foreground [&_p[data-placeholder]]:before:content-[attr(data-placeholder)]') }), ownProblem && (_jsx("p", { id: problemId, role: "alert", "data-slot": "rich-text-editor-problem", className: cn('type-caption text-destructive-text', inline ? 'pt-1' : 'border-t border-border px-2.5 py-1.5', fullScreen && 'px-4 md:px-8'), children: ownProblem })), widgets.map((widget) => {
|
|
1290
1447
|
if (widget.type === 'callout')
|
|
1291
1448
|
return createPortal(_jsx(CalloutKindMenu, { kind: widget.kind, readOnly: readOnly, onPick: (kind) => changeCallout(widget.getPos, kind), onRemove: () => changeCallout(widget.getPos, null), text: textElement }), widget.slot, widget.key);
|
|
1292
1449
|
const active = caretTable !== undefined && caretTable === widget.getPos();
|
|
@@ -1294,13 +1451,17 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1294
1451
|
createPortal(_jsx(TableBar, { side: "row", active: active, readOnly: readOnly, onAdd: () => addToTable(widget.getPos, 'row') }), widget.slot, `${widget.key}-row`),
|
|
1295
1452
|
createPortal(_jsx(TableBar, { side: "column", active: active, readOnly: readOnly, onAdd: () => addToTable(widget.getPos, 'column') }), widget.column, `${widget.key}-column`),
|
|
1296
1453
|
editorView &&
|
|
1297
|
-
createPortal(_jsx(TableGrips, { view: editorView,
|
|
1454
|
+
createPortal(_jsx(TableGrips, { view: editorView, caret: active ? caretCell : null, getPos: widget.getPos, frame: widget.frame, box: widget.box, table: widget.table, readOnly: readOnly, onAction: (cell, action) => runTableAt(widget.getPos, cell, action), onColor: (cell, scope, color) => colorTableAt(widget.getPos, cell, scope, color), onWidth: (column, width) => widthTableAt(widget.getPos, column, width), onPreviewWidth: (column, width) => previewTableWidth(widget.getPos, column, width), text: textElement }), widget.grips, `${widget.key}-grips`),
|
|
1298
1455
|
];
|
|
1299
1456
|
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) => item === 'page'
|
|
1300
1457
|
? startPage(editorView, slash, '')
|
|
1301
1458
|
: item === 'image'
|
|
1302
1459
|
? pickSlashImage(editorView, slash)
|
|
1303
|
-
: applySlash(editorView, slash, item) })),
|
|
1460
|
+
: applySlash(editorView, slash, item) })), coarse && menus && editorView && (focused || fullScreen) && (_jsx(RichTextKeyboardBar, { ref: toolbarRef, pressing: selecting, view: editorView, state: editorState, readOnly: readOnly, controls: editableId, onFormat: runFormat, onImage: upload ? pickImages : undefined, onFullScreen: toggleFullScreen, fullScreen: fullScreen, text: textElement, onBlur: (event) => {
|
|
1461
|
+
const next = event.relatedTarget;
|
|
1462
|
+
if (!editorView.dom.contains(next) && !inFloating(next))
|
|
1463
|
+
setFocused(false);
|
|
1464
|
+
} })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1304
1465
|
const next = event.relatedTarget;
|
|
1305
1466
|
if (editorView && !editorView.dom.contains(next) && !inFloating(next))
|
|
1306
1467
|
setFocused(false);
|
|
@@ -31,7 +31,7 @@ export declare const PROSE: {
|
|
|
31
31
|
* so it sits on the first line of a heading that wraps. Its chevron points
|
|
32
32
|
* down while the section shows and right while it's folded.
|
|
33
33
|
*/
|
|
34
|
-
export declare const FOLD_BUTTON
|
|
34
|
+
export declare const FOLD_BUTTON: string;
|
|
35
35
|
/** A heading with a fold button: the button and the words side by side, the look on both. */
|
|
36
36
|
export declare const FOLD_HEADING = "flex items-start gap-1";
|
|
37
37
|
/**
|