@tristan2828/ui-foundation 4.64.0 → 4.66.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 +99 -47
- package/conventions/docs/cell-patterns.md +1 -1
- package/conventions/docs/entity-plan-template.md +11 -4
- package/dist/components/app/data-table.d.ts +32 -1
- package/dist/components/app/data-table.js +59 -13
- package/dist/components/app/markdown.d.ts +4 -3
- package/dist/components/app/markdown.js +15 -8
- package/dist/components/app/milkdown-editor.js +39 -10
- package/dist/components/app/notes-outline.js +3 -2
- package/dist/components/app/record-dialog.d.ts +8 -1
- package/dist/components/app/record-dialog.js +16 -4
- package/dist/components/app/rich-text-editor.d.ts +4 -3
- package/dist/components/app/rich-text-editor.js +5 -2
- package/dist/components/app/rich-text-fold.js +1 -1
- package/dist/components/app/rich-text-format-items.d.ts +6 -0
- package/dist/components/app/rich-text-format-items.js +13 -1
- package/dist/components/app/rich-text-formats.d.ts +6 -1
- package/dist/components/app/rich-text-formats.js +22 -5
- package/dist/components/app/rich-text-slash-menu.js +1 -1
- package/dist/components/app/rich-text-slash.js +9 -5
- package/dist/components/app/rich-text-toggle-heading.d.ts +8 -0
- package/dist/components/app/rich-text-toggle-heading.js +55 -0
- package/dist/index.d.ts +1 -1
- package/dist/lib/markdown-fold.d.ts +5 -2
- package/dist/lib/markdown-fold.js +24 -10
- package/dist/lib/markdown-toggle.d.ts +29 -0
- package/dist/lib/markdown-toggle.js +69 -0
- package/eslint/index.d.ts +6 -1
- package/eslint/index.js +18 -2
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
// A long text's headings as a list to jump with, beside <Markdown> or the
|
|
3
3
|
// rich-text editor given the same `foldKey`: each heading a button that
|
|
4
4
|
// opens its section (and any it sits under) and brings it into view, with
|
|
5
|
-
// Fold all and Open all above
|
|
5
|
+
// Fold all and Open all above (when a toggle heading has something to
|
|
6
|
+
// fold). Every top-level heading is listed, plain or toggle, as folding
|
|
6
7
|
// sees them (src/lib/markdown-fold.ts); the deepest levels are left out
|
|
7
8
|
// (`depth`), so a long text's outline stays a list of its parts.
|
|
8
9
|
//
|
|
@@ -53,7 +54,7 @@ export function NotesOutline({ markdown, foldKey, depth = 2, minHeadings = 2, 'a
|
|
|
53
54
|
button.focus({ preventScroll: true });
|
|
54
55
|
});
|
|
55
56
|
};
|
|
56
|
-
return (_jsxs("nav", { "aria-label": ariaLabel, "data-slot": "notes-outline", className: cn('flex min-w-0 flex-col gap-2', className), children: [_jsxs("div", { className: "flex flex-wrap gap-1", children: [_jsx(Button, { size: "xs", variant: "outline", disabled: allFolded, onClick: () => setFolded(foldable), children: "Fold all" }), _jsx(Button, { size: "xs", variant: "outline", disabled: !anyFolded, onClick: () => setFolded(new Set()), children: "Open all" })] }), _jsx("ul", { className: "flex flex-col", children: listed.map((heading) => {
|
|
57
|
+
return (_jsxs("nav", { "aria-label": ariaLabel, "data-slot": "notes-outline", className: cn('flex min-w-0 flex-col gap-2', className), children: [foldable.size > 0 && (_jsxs("div", { className: "flex flex-wrap gap-1", children: [_jsx(Button, { size: "xs", variant: "outline", disabled: allFolded, onClick: () => setFolded(foldable), children: "Fold all" }), _jsx(Button, { size: "xs", variant: "outline", disabled: !anyFolded, onClick: () => setFolded(new Set()), children: "Open all" })] })), _jsx("ul", { className: "flex flex-col", children: listed.map((heading) => {
|
|
57
58
|
const isFolded = heading.foldable && folded.has(heading.id);
|
|
58
59
|
return (_jsx("li", { children: _jsxs("button", { type: "button", onClick: () => jump(heading.id), className: cn('flex w-full min-w-0 items-center gap-1 rounded-md py-1 pr-2 text-left type-body text-foreground outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50', INDENT[Math.min(heading.level - top, INDENT.length - 1)], heading.level > top && 'text-muted-foreground hover:text-foreground'), children: [_jsx("span", { className: "min-w-0 flex-1 truncate", children: heading.text || 'Untitled section' }), isFolded && (_jsxs(_Fragment, { children: [_jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-3.5 shrink-0 text-muted-foreground" }), _jsx("span", { className: "sr-only", children: " (folded)" })] }))] }) }, heading.id));
|
|
59
60
|
}) })] }));
|
|
@@ -10,8 +10,15 @@ export type RecordDialogRouteProps = {
|
|
|
10
10
|
label: string;
|
|
11
11
|
/** Extra classes on the dialog's popup (its width, say: `sm:max-w-5xl`). */
|
|
12
12
|
className?: string;
|
|
13
|
+
/**
|
|
14
|
+
* False: the record has no full page, only this dialog (DataTable's
|
|
15
|
+
* `opens` kind `dialog-only`). No Open full page, and its address opened
|
|
16
|
+
* any other way (a deep link, a link from another page) is the dialog
|
|
17
|
+
* over the list. True by default.
|
|
18
|
+
*/
|
|
19
|
+
fullPage?: boolean;
|
|
13
20
|
};
|
|
14
|
-
export declare function RecordDialogRoute({ list, label, className }: RecordDialogRouteProps): import("react").JSX.Element;
|
|
21
|
+
export declare function RecordDialogRoute({ list, label, className, fullPage }: RecordDialogRouteProps): import("react").JSX.Element;
|
|
15
22
|
export type RecordLinkProps = Omit<ComponentProps<typeof Link>, 'state'>;
|
|
16
23
|
/**
|
|
17
24
|
* A link to a record that opens it over the current list (a board's card,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// A record opened in a centered dialog over its list, instead of going to
|
|
3
|
-
// the record's page (add-an-entity.md "
|
|
3
|
+
// the record's page (add-an-entity.md "How a list opens a record").
|
|
4
4
|
//
|
|
5
5
|
// RecordDialogRoute is the list route's element, and the record's route is
|
|
6
6
|
// its child:
|
|
@@ -22,6 +22,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
22
22
|
// full page, as is a record opened over a list other than its own
|
|
23
23
|
// (a link on the home page).
|
|
24
24
|
//
|
|
25
|
+
// `fullPage={false}` is a record with no page of its own (a dialog only:
|
|
26
|
+
// a small record with no notes, where a page would only repeat the
|
|
27
|
+
// dialog). There's no Open full page, and a deep link or a link from
|
|
28
|
+
// another page opens the dialog over its own list, at the list's plain
|
|
29
|
+
// address.
|
|
30
|
+
//
|
|
25
31
|
// Inside, the record's route renders as it always does. EntityView sees
|
|
26
32
|
// the dialog (useRecordDialog): its heading names the dialog, its back link
|
|
27
33
|
// gives way to the dialog's own bar, and not found's way out closes the
|
|
@@ -34,7 +40,7 @@ import { Button, buttonVariants } from '../ui/button.js';
|
|
|
34
40
|
import { Dialog, DialogClose, DialogContent } from '../ui/dialog.js';
|
|
35
41
|
import { escapePassedThrough } from './escape-passthrough.js';
|
|
36
42
|
import { backgroundOf, recordDialogState, RecordDialogContext } from './record-dialog-context.js';
|
|
37
|
-
export function RecordDialogRoute({ list, label, className }) {
|
|
43
|
+
export function RecordDialogRoute({ list, label, className, fullPage = true }) {
|
|
38
44
|
const location = useLocation();
|
|
39
45
|
const navigationType = useNavigationType();
|
|
40
46
|
const navigate = useNavigate();
|
|
@@ -44,7 +50,13 @@ export function RecordDialogRoute({ list, label, className }) {
|
|
|
44
50
|
const opened = backgroundOf(location.state);
|
|
45
51
|
// Over its own list only: opened from anywhere else, the list under it
|
|
46
52
|
// would be a page the user wasn't on.
|
|
47
|
-
|
|
53
|
+
// With no full page, a record opened any other way is the dialog over
|
|
54
|
+
// the list's plain address, with nothing to go back over.
|
|
55
|
+
const background = opened && opened.pathname === listPath
|
|
56
|
+
? opened
|
|
57
|
+
: !fullPage && outlet !== null
|
|
58
|
+
? { pathname: listPath, search: '', hash: '', depth: 0 }
|
|
59
|
+
: null;
|
|
48
60
|
const open = outlet !== null && background !== null;
|
|
49
61
|
// The list sees the address it was opened from, not the record's, so
|
|
50
62
|
// its URL state (filters, sort, page) stays as it was under the dialog.
|
|
@@ -78,7 +90,7 @@ export function RecordDialogRoute({ list, label, className }) {
|
|
|
78
90
|
return;
|
|
79
91
|
}
|
|
80
92
|
close();
|
|
81
|
-
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", className: cn('flex max-h-[calc(100dvh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl data-closed:hidden', className), children: [_jsxs("div", { className:
|
|
93
|
+
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", className: cn('flex max-h-[calc(100dvh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl data-closed:hidden', className), children: [_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open full page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] }), _jsx("div", { "data-slot": "record-dialog-body", className: "min-h-0 overflow-y-auto p-4 sm:p-6", children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
84
96
|
* A link to a record that opens it over the current list (a board's card,
|
|
@@ -74,9 +74,10 @@ export type RichTextEditorProps = {
|
|
|
74
74
|
*/
|
|
75
75
|
headingFrom?: HeadingFrom;
|
|
76
76
|
/**
|
|
77
|
-
* Folds the text by its headings, as `<Markdown>`'s `foldKey`
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* Folds the text by its toggle headings, as `<Markdown>`'s `foldKey`
|
|
78
|
+
* does: each toggle heading (`## Safety {toggle="true"}`) at the text's
|
|
79
|
+
* top level has a button that folds what's under it (a plain heading
|
|
80
|
+
* never folds), Ctrl/Cmd+Alt+[ folds the section the caret is in and
|
|
80
81
|
* Ctrl/Cmd+Alt+] opens the heading it's on, and the caret moving into a
|
|
81
82
|
* folded section opens it. Remembered on this device under this key,
|
|
82
83
|
* and shared with `<Markdown>` and NotesOutline given the same one.
|
|
@@ -29,8 +29,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
29
29
|
// kept as Markdown already writes them (src/lib/markdown-table.ts).
|
|
30
30
|
// `tableLook` picks compact (the default) or boxed, as on <Markdown>.
|
|
31
31
|
//
|
|
32
|
-
// With `foldKey`, the text folds by its headings (NotesOutline
|
|
33
|
-
// beside it), the Markdown untouched.
|
|
32
|
+
// With `foldKey`, the text folds by its toggle headings (NotesOutline
|
|
33
|
+
// lists every heading beside it), the Markdown untouched. A toggle heading
|
|
34
|
+
// is `## Safety {toggle="true"}` in the Markdown: typed as `>## `, picked
|
|
35
|
+
// from the slash menu (Toggle heading 1 to 3) or made from the heading the
|
|
36
|
+
// caret is in with the toolbar's Toggle heading. Plain is the default.
|
|
34
37
|
//
|
|
35
38
|
// `defaultValue` is read when it mounts, then followed: a new value the
|
|
36
39
|
// editor didn't report itself (a form's loaded record arriving after the
|
|
@@ -5,7 +5,7 @@ export const foldPluginKey = new PluginKey('fold');
|
|
|
5
5
|
/** The fold plan of a document's top-level blocks. */
|
|
6
6
|
export function docFoldPlan(doc, folded) {
|
|
7
7
|
const blocks = [];
|
|
8
|
-
doc.forEach((node) => blocks.push(node.type.name === 'heading' ? { level: Number(node.attrs.level), text: node.textContent } : null));
|
|
8
|
+
doc.forEach((node) => blocks.push(node.type.name === 'heading' ? { level: Number(node.attrs.level), text: node.textContent, toggle: Boolean(node.attrs.toggle) } : null));
|
|
9
9
|
return foldPlan(blocks, folded);
|
|
10
10
|
}
|
|
11
11
|
function build(doc, folded) {
|
|
@@ -19,6 +19,12 @@ export type FormatItem = {
|
|
|
19
19
|
export declare const FORMAT_GROUPS: FormatItem[][];
|
|
20
20
|
/** Every format by its id. */
|
|
21
21
|
export declare const FORMAT_ITEMS: Map<FormatId, FormatItem>;
|
|
22
|
+
/**
|
|
23
|
+
* A toggle heading of each level, for the slash menu, beside the plain
|
|
24
|
+
* headings: "Toggle heading 2". On the toolbar, Toggle heading turns the
|
|
25
|
+
* caret's heading into one.
|
|
26
|
+
*/
|
|
27
|
+
export declare const TOGGLE_HEADING_VARIANTS: FormatItem[];
|
|
22
28
|
/**
|
|
23
29
|
* A callout of each kind but the default, for the slash menu: "Warning
|
|
24
30
|
* callout". Not on the toolbar (its Callout makes a note).
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// blocks (Cmd+Option on a Mac, where Cmd+Shift+3 to 5 take screenshots),
|
|
8
8
|
// written `Block+…` here; Mod+Shift+S strikes through. Milkdown's own
|
|
9
9
|
// (Ctrl+Alt+1, Mod+Alt+X, Mod+Shift+B, …) still work.
|
|
10
|
-
import { BoldIcon, CodeIcon, Heading1Icon, Heading2Icon, Heading3Icon, HighlighterIcon, IndentDecreaseIcon, IndentIncreaseIcon, ItalicIcon, LinkIcon, ListChecksIcon, ListIcon, ListOrderedIcon, MinusIcon, SquareCodeIcon, StrikethroughIcon, TableIcon, TextQuoteIcon, } from 'lucide-react';
|
|
10
|
+
import { BoldIcon, CodeIcon, Heading1Icon, Heading2Icon, Heading3Icon, HighlighterIcon, IndentDecreaseIcon, IndentIncreaseIcon, ItalicIcon, LinkIcon, ListChecksIcon, ListCollapseIcon, ListIcon, ListOrderedIcon, MinusIcon, SquareCodeIcon, StrikethroughIcon, TableIcon, TextQuoteIcon, } from 'lucide-react';
|
|
11
11
|
import { CALLOUT_KINDS } from '../../lib/markdown-callout.js';
|
|
12
12
|
import { CALLOUT_LOOK } from './prose-look.js';
|
|
13
13
|
import { HIGHLIGHT_COLORS } from '../../lib/markdown-highlight.js';
|
|
@@ -23,6 +23,7 @@ export const FORMAT_GROUPS = [
|
|
|
23
23
|
{ id: 'heading1', label: 'Heading 1', icon: Heading1Icon, keys: 'Block+1' },
|
|
24
24
|
{ id: 'heading2', label: 'Heading 2', icon: Heading2Icon, keys: 'Block+2' },
|
|
25
25
|
{ id: 'heading3', label: 'Heading 3', icon: Heading3Icon, keys: 'Block+3' },
|
|
26
|
+
{ id: 'toggleHeading', label: 'Toggle heading', icon: ListCollapseIcon, hint: 'folds what is under it; or type >## ' },
|
|
26
27
|
],
|
|
27
28
|
[
|
|
28
29
|
{ id: 'tasks', label: 'Task list', icon: ListChecksIcon, keys: 'Block+4', hint: 'tick an item: Mod+Shift+Enter' },
|
|
@@ -42,6 +43,17 @@ export const FORMAT_GROUPS = [
|
|
|
42
43
|
];
|
|
43
44
|
/** Every format by its id. */
|
|
44
45
|
export const FORMAT_ITEMS = new Map(FORMAT_GROUPS.flat().map((item) => [item.id, item]));
|
|
46
|
+
/**
|
|
47
|
+
* A toggle heading of each level, for the slash menu, beside the plain
|
|
48
|
+
* headings: "Toggle heading 2". On the toolbar, Toggle heading turns the
|
|
49
|
+
* caret's heading into one.
|
|
50
|
+
*/
|
|
51
|
+
export const TOGGLE_HEADING_VARIANTS = [1, 2, 3].map((level) => ({
|
|
52
|
+
id: `toggleHeading${level}`,
|
|
53
|
+
label: `Toggle heading ${level}`,
|
|
54
|
+
icon: [Heading1Icon, Heading2Icon, Heading3Icon][level - 1],
|
|
55
|
+
hint: `or type >${'#'.repeat(level)} `,
|
|
56
|
+
}));
|
|
45
57
|
/**
|
|
46
58
|
* A callout of each kind but the default, for the slash menu: "Warning
|
|
47
59
|
* callout". Not on the toolbar (its Callout makes a note).
|
|
@@ -2,7 +2,12 @@ import { type Node as ProseNode, type Schema } from '@milkdown/kit/prose/model';
|
|
|
2
2
|
import { type EditorState, type Transaction } from '@milkdown/kit/prose/state';
|
|
3
3
|
import type { CalloutKind } from '../../lib/markdown-callout.js';
|
|
4
4
|
import { type HighlightColor } from '../../lib/markdown-highlight.js';
|
|
5
|
-
export type FormatId = 'bold' | 'italic' | 'strike' | 'code' | 'highlight' | HighlightFormat | 'highlight-off' | 'indent' | 'outdent' | 'text' | 'heading1' | 'heading2' | 'heading3' | 'bullets' | 'numbers' | 'tasks' | 'quote' | CalloutFormat | 'codeBlock' | 'divider' | 'table' | 'link';
|
|
5
|
+
export type FormatId = 'bold' | 'italic' | 'strike' | 'code' | 'highlight' | HighlightFormat | 'highlight-off' | 'indent' | 'outdent' | 'text' | 'heading1' | 'heading2' | 'heading3' | ToggleHeadingFormat | 'toggleHeading' | 'bullets' | 'numbers' | 'tasks' | 'quote' | CalloutFormat | 'codeBlock' | 'divider' | 'table' | 'link';
|
|
6
|
+
/**
|
|
7
|
+
* A toggle heading of each level (the slash menu's). `toggleHeading`, the
|
|
8
|
+
* toolbar's, turns the heading the caret is in into a toggle one or back.
|
|
9
|
+
*/
|
|
10
|
+
export type ToggleHeadingFormat = 'toggleHeading1' | 'toggleHeading2' | 'toggleHeading3';
|
|
6
11
|
/** Words highlighted in each colour. `highlight` is the toolbar's menu of them. */
|
|
7
12
|
export type HighlightFormat = `highlight-${HighlightColor}`;
|
|
8
13
|
/** The colour a highlight format puts on, or null when it isn't one. */
|
|
@@ -20,6 +20,12 @@ export function calloutKindOf(id) {
|
|
|
20
20
|
return id.startsWith('callout-') ? id.slice('callout-'.length) : null;
|
|
21
21
|
}
|
|
22
22
|
const HEADING_LEVEL = { heading1: 1, heading2: 2, heading3: 3 };
|
|
23
|
+
const TOGGLE_LEVEL = { toggleHeading1: 1, toggleHeading2: 2, toggleHeading3: 3 };
|
|
24
|
+
// The heading the caret's line is, if it's one, and whether it's a toggle.
|
|
25
|
+
function headingHere(state) {
|
|
26
|
+
const parent = state.selection.$from.parent;
|
|
27
|
+
return parent.type.name === 'heading' ? { level: Number(parent.attrs.level), toggle: Boolean(parent.attrs.toggle) } : null;
|
|
28
|
+
}
|
|
23
29
|
const MARKS = {
|
|
24
30
|
bold: 'strong',
|
|
25
31
|
italic: 'emphasis',
|
|
@@ -95,9 +101,11 @@ export function formatOn(state, id) {
|
|
|
95
101
|
if (mark)
|
|
96
102
|
return markOn(state, schema.marks[mark]);
|
|
97
103
|
const parent = state.selection.$from.parent;
|
|
98
|
-
const level = HEADING_LEVEL[id];
|
|
104
|
+
const level = HEADING_LEVEL[id] ?? TOGGLE_LEVEL[id];
|
|
99
105
|
if (level)
|
|
100
|
-
return parent.type.name === 'heading' && parent.attrs.level === level;
|
|
106
|
+
return parent.type.name === 'heading' && parent.attrs.level === level && Boolean(parent.attrs.toggle) === (id in TOGGLE_LEVEL);
|
|
107
|
+
if (id === 'toggleHeading')
|
|
108
|
+
return Boolean(headingHere(state)?.toggle);
|
|
101
109
|
if (id === 'highlight')
|
|
102
110
|
return highlightColor(state) !== null;
|
|
103
111
|
const color = highlightColorOf(id);
|
|
@@ -178,9 +186,18 @@ export function toggleFormat(state, dispatch, id) {
|
|
|
178
186
|
return liftListItem(schema.nodes.list_item)(state, dispatch);
|
|
179
187
|
const on = formatOn(state, id);
|
|
180
188
|
const paragraph = schema.nodes.paragraph;
|
|
181
|
-
const level = HEADING_LEVEL[id];
|
|
182
|
-
if (level)
|
|
183
|
-
|
|
189
|
+
const level = HEADING_LEVEL[id] ?? TOGGLE_LEVEL[id];
|
|
190
|
+
if (level) {
|
|
191
|
+
if (on)
|
|
192
|
+
return setBlockType(paragraph)(state, dispatch);
|
|
193
|
+
return setBlockType(schema.nodes.heading, { level, toggle: id in TOGGLE_LEVEL })(state, dispatch);
|
|
194
|
+
}
|
|
195
|
+
// The toolbar's Toggle heading: a heading turned toggle or plain, its
|
|
196
|
+
// level kept; any other line a toggle `##`.
|
|
197
|
+
if (id === 'toggleHeading') {
|
|
198
|
+
const here = headingHere(state);
|
|
199
|
+
return setBlockType(schema.nodes.heading, { level: here?.level ?? 2, toggle: !here?.toggle })(state, dispatch);
|
|
200
|
+
}
|
|
184
201
|
const kind = calloutKindOf(id);
|
|
185
202
|
if (kind)
|
|
186
203
|
return toggleCallout(state, dispatch, kind);
|
|
@@ -44,7 +44,7 @@ export function RichTextSlashMenu({ id, view, at, field, items, active, onHighli
|
|
|
44
44
|
return (_jsx("div", { ref: setMenu, id: id, role: "listbox", "aria-label": "Blocks", "data-slot": "rich-text-slash-menu", "data-side": placement?.side,
|
|
45
45
|
// Tall enough for every block, but a filtered list can still scroll:
|
|
46
46
|
// focusable for axe (scrollable-region-focusable), never by a press.
|
|
47
|
-
tabIndex: -1, onMouseDown: (event) => event.preventDefault(), style: placement ? { top: placement.top, left: placement.left } : undefined, className: cn('absolute z-50 flex max-h-
|
|
47
|
+
tabIndex: -1, onMouseDown: (event) => event.preventDefault(), style: placement ? { top: placement.top, left: placement.left } : undefined, className: cn('absolute z-50 flex max-h-128 w-56 flex-col gap-0.5 overflow-y-auto rounded-lg bg-popover p-1 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10', 'animate-in fade-in-0 zoom-in-95 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2',
|
|
48
48
|
// Measured before it's seen, so it never shows in the wrong place.
|
|
49
49
|
!placement && 'invisible'), children: items.map((item, index) => {
|
|
50
50
|
const Icon = item.icon;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// `/usr/bin`) never does, and neither does a "/" mid-line or inside a
|
|
9
9
|
// list, a quote or a code block.
|
|
10
10
|
import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
|
|
11
|
-
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS } from './rich-text-format-items.js';
|
|
11
|
+
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
|
|
12
12
|
import { toggleFormat } from './rich-text-formats.js';
|
|
13
13
|
const slashKey = new PluginKey('rich-text-slash');
|
|
14
14
|
// Longer than any item's name: past it, the person is writing, not picking.
|
|
@@ -82,6 +82,9 @@ const KEYWORDS = {
|
|
|
82
82
|
heading1: ['h1', 'title', 'heading'],
|
|
83
83
|
heading2: ['h2', 'subheading', 'heading'],
|
|
84
84
|
heading3: ['h3', 'heading'],
|
|
85
|
+
toggleHeading1: ['toggle', 'fold', 'collapse', 'heading'],
|
|
86
|
+
toggleHeading2: ['toggle', 'fold', 'collapse', 'heading'],
|
|
87
|
+
toggleHeading3: ['toggle', 'fold', 'collapse', 'heading'],
|
|
85
88
|
bullets: ['ul', 'unordered', 'bullet'],
|
|
86
89
|
numbers: ['ol', 'ordered', 'number'],
|
|
87
90
|
tasks: ['todo', 'checkbox', 'checklist'],
|
|
@@ -99,11 +102,12 @@ const KEYWORDS = {
|
|
|
99
102
|
'highlight-green': ['highlight', 'mark', 'marker', 'colour', 'color'],
|
|
100
103
|
'highlight-red': ['highlight', 'mark', 'marker', 'colour', 'color'],
|
|
101
104
|
};
|
|
102
|
-
// The menu's items: the blocks, in the toolbar's order
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
// the list "/" opens with stays short.
|
|
105
|
+
// The menu's items: the blocks, in the toolbar's order, the toggle
|
|
106
|
+
// headings after the plain ones (the toolbar's one Toggle heading isn't
|
|
107
|
+
// here). The kinds of callout past the default, and the highlights, only
|
|
108
|
+
// once something's typed ("/warn"), so the list "/" opens with stays short.
|
|
106
109
|
const BLOCKS = FORMAT_GROUPS.flat().filter((item) => KEYWORDS[item.id]);
|
|
110
|
+
BLOCKS.splice(BLOCKS.findIndex((item) => item.id === 'heading3') + 1, 0, ...TOGGLE_HEADING_VARIANTS);
|
|
107
111
|
/** The blocks matching what's typed after the "/": in the name, or the start of a keyword. */
|
|
108
112
|
export function slashItems(query) {
|
|
109
113
|
const typed = query.trim().toLowerCase();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NodeSchema } from '@milkdown/kit/transformer';
|
|
2
|
+
export declare const toggleHeadingRemark: import("@milkdown/utils").$Remark<"remarkToggleHeadings", unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Milkdown's heading schema with the `toggle` attribute, read from and
|
|
5
|
+
* written to the Markdown: for `ctx.update(headingSchema.key, …)`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withToggle<Ctx>(previous: (ctx: Ctx) => NodeSchema): (ctx: Ctx) => NodeSchema;
|
|
8
|
+
export declare const toggleHeadingInputRule: import("@milkdown/utils").$InputRule;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Toggle headings in the rich-text editor (src/lib/markdown-toggle.ts):
|
|
2
|
+
// Milkdown's heading node with a `toggle` attribute, false by default, so
|
|
3
|
+
// every heading the text already has stays plain.
|
|
4
|
+
// - Read: remarkToggleHeadings takes the `{toggle="true"}` marker off a
|
|
5
|
+
// heading's end and marks it `toggle`, which the schema reads.
|
|
6
|
+
// - Written: a toggle heading gets the marker back at its end; a plain one
|
|
7
|
+
// is written as Milkdown writes any heading.
|
|
8
|
+
// - Typed: `>## ` at a line's start makes a toggle `##` (`># ` and `>### `
|
|
9
|
+
// likewise), as Notion's `>` makes a toggle.
|
|
10
|
+
// - Picked: the slash menu's Toggle heading 1 to 3, and the toolbar's
|
|
11
|
+
// Toggle heading (rich-text-formats.ts).
|
|
12
|
+
// Only a toggle heading folds, and only it has a fold button
|
|
13
|
+
// (headingView in milkdown-editor.tsx, rich-text-fold.ts).
|
|
14
|
+
import { headingSchema } from '@milkdown/kit/preset/commonmark';
|
|
15
|
+
import { textblockTypeInputRule } from '@milkdown/kit/prose/inputrules';
|
|
16
|
+
import { $inputRule, $remark } from '@milkdown/kit/utils';
|
|
17
|
+
import { remarkToggleHeadings, TOGGLE_MARKER } from '../../lib/markdown-toggle.js';
|
|
18
|
+
export const toggleHeadingRemark = $remark('remarkToggleHeadings', () => remarkToggleHeadings);
|
|
19
|
+
/**
|
|
20
|
+
* Milkdown's heading schema with the `toggle` attribute, read from and
|
|
21
|
+
* written to the Markdown: for `ctx.update(headingSchema.key, …)`.
|
|
22
|
+
*/
|
|
23
|
+
export function withToggle(previous) {
|
|
24
|
+
return (ctx) => {
|
|
25
|
+
const base = previous(ctx);
|
|
26
|
+
return {
|
|
27
|
+
...base,
|
|
28
|
+
attrs: { ...base.attrs, toggle: { default: false, validate: 'boolean' } },
|
|
29
|
+
parseMarkdown: {
|
|
30
|
+
match: ({ type }) => type === 'heading',
|
|
31
|
+
runner: (state, node, type) => {
|
|
32
|
+
state.openNode(type, { level: node.depth, toggle: node.toggle === true });
|
|
33
|
+
state.next(node.children);
|
|
34
|
+
state.closeNode();
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
toMarkdown: {
|
|
38
|
+
match: (node) => node.type.name === 'heading',
|
|
39
|
+
runner: (state, node) => {
|
|
40
|
+
state.openNode('heading', undefined, { depth: node.attrs.level });
|
|
41
|
+
// A hard break at the end is left out, as Milkdown's own does.
|
|
42
|
+
const last = node.lastChild;
|
|
43
|
+
const content = last?.type.name === 'hardbreak' ? node.content.cut(0, node.content.size - last.nodeSize) : node.content;
|
|
44
|
+
state.next(content);
|
|
45
|
+
if (node.attrs.toggle)
|
|
46
|
+
state.addNode('text', undefined, content.size > 0 ? ` ${TOGGLE_MARKER}` : TOGGLE_MARKER);
|
|
47
|
+
state.closeNode();
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// `>`, then one to three `#`, then a space, at a line's start.
|
|
54
|
+
const TOGGLE_START = /^>(#{1,3})\s$/;
|
|
55
|
+
export const toggleHeadingInputRule = $inputRule((ctx) => textblockTypeInputRule(TOGGLE_START, headingSchema.type(ctx), (match) => ({ level: match[1].length, toggle: true })));
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { FillInChoice, FillInQueue, type FillInChoiceProps, type FillInQueueGrou
|
|
|
7
7
|
export { FillInField, FillInInput, FillInSelect, type FillInFieldKind, type FillInFieldProps, type FillInFieldSpec, type FillInInputKind, type FillInInputProps, type FillInSelectProps, type FillInSuggestion, type FillInValue, } from './components/app/fill-in-field.js';
|
|
8
8
|
export { Artwork, ArtworkTag, ArtworkToggle, type ArtworkAspect, type ArtworkProps, type ArtworkToggleProps, } from './components/app/artwork.js';
|
|
9
9
|
export { CountLink, type CountLinkProps } from './components/app/count-link.js';
|
|
10
|
-
export { DataTable, type DataTableCardLayout, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
10
|
+
export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
11
11
|
export { type RowGroup } from './components/app/table-groups.js';
|
|
12
12
|
export { byDay, type ByDayOptions } from './lib/group-by-day.js';
|
|
13
13
|
export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
/** A top-level heading, by its level (1 for `#`) and
|
|
1
|
+
/** A top-level heading, by its level (1 for `#`), its words and whether it's a toggle heading (the only kind that folds). */
|
|
2
2
|
export type FoldHeadingInput = {
|
|
3
3
|
level: number;
|
|
4
4
|
text: string;
|
|
5
|
+
toggle?: boolean;
|
|
5
6
|
};
|
|
6
7
|
/** A top-level heading as folding sees it. */
|
|
7
8
|
export type FoldHeading = FoldHeadingInput & {
|
|
@@ -9,7 +10,9 @@ export type FoldHeading = FoldHeadingInput & {
|
|
|
9
10
|
id: string;
|
|
10
11
|
/** Its index among the text's top-level blocks. */
|
|
11
12
|
index: number;
|
|
12
|
-
/**
|
|
13
|
+
/** A toggle heading: the only kind with a fold button. */
|
|
14
|
+
toggle: boolean;
|
|
15
|
+
/** A toggle heading with something under it to fold. */
|
|
13
16
|
foldable: boolean;
|
|
14
17
|
/** The ids of the headings it sits under, outermost first. */
|
|
15
18
|
parents: string[];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Folding a text by its headings (`foldKey` on <Markdown> and the
|
|
2
|
-
// rich-text editor, and NotesOutline beside them). A heading
|
|
3
|
-
// level of the text folds everything after
|
|
4
|
-
// its level or higher: a `##` folds its
|
|
5
|
-
// stops at the next `##` or `#`.
|
|
6
|
-
//
|
|
2
|
+
// rich-text editor, and NotesOutline beside them). A toggle heading
|
|
3
|
+
// (markdown-toggle.ts) at the top level of the text folds everything after
|
|
4
|
+
// it up to the next heading of its level or higher: a `##` folds its
|
|
5
|
+
// paragraphs and its `###`s, and stops at the next `##` or `#`. A plain
|
|
6
|
+
// heading never folds, though it still ends the sections above it, and
|
|
7
|
+
// NotesOutline still lists it. Headings inside a quote or a callout don't
|
|
8
|
+
// fold.
|
|
7
9
|
//
|
|
8
10
|
// Folding is the reader's, never the text's: what's folded is a set of
|
|
9
11
|
// heading ids, kept on the device (src/hooks/fold-store.ts), and the
|
|
@@ -15,6 +17,7 @@
|
|
|
15
17
|
import remarkGfm from 'remark-gfm';
|
|
16
18
|
import remarkParse from 'remark-parse';
|
|
17
19
|
import { unified } from 'unified';
|
|
20
|
+
import { takeToggleMarker } from './markdown-toggle.js';
|
|
18
21
|
function words(text) {
|
|
19
22
|
return text.replace(/\s+/g, ' ').trim();
|
|
20
23
|
}
|
|
@@ -32,11 +35,13 @@ export function foldPlan(blocks, folded = new Set()) {
|
|
|
32
35
|
if (block)
|
|
33
36
|
while (open.length > 0 && open[open.length - 1].level >= block.level)
|
|
34
37
|
open.pop().end = index;
|
|
35
|
-
|
|
38
|
+
// A plain heading's id in `folded` (folded before it was plain) hides nothing.
|
|
39
|
+
if (open.some((heading) => heading.toggle && folded.has(heading.id)))
|
|
36
40
|
hidden.add(index);
|
|
37
41
|
// Anything after a heading, before one of its level or higher, is its section.
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
const last = open[open.length - 1];
|
|
43
|
+
if (last?.toggle)
|
|
44
|
+
last.foldable = true;
|
|
40
45
|
if (!block)
|
|
41
46
|
return;
|
|
42
47
|
const text = words(block.text);
|
|
@@ -48,6 +53,7 @@ export function foldPlan(blocks, folded = new Set()) {
|
|
|
48
53
|
text,
|
|
49
54
|
id: count === 1 ? base : `${base}#${count}`,
|
|
50
55
|
index,
|
|
56
|
+
toggle: block.toggle === true,
|
|
51
57
|
foldable: false,
|
|
52
58
|
parents: open.map((one) => one.id),
|
|
53
59
|
end: blocks.length,
|
|
@@ -67,7 +73,13 @@ export function mdText(node) {
|
|
|
67
73
|
}
|
|
68
74
|
/** The top-level blocks of an mdast root, as foldPlan takes them. */
|
|
69
75
|
export function mdBlocks(root) {
|
|
70
|
-
return (root.children ?? []).map((node) =>
|
|
76
|
+
return (root.children ?? []).map((node) => {
|
|
77
|
+
if (node.type !== 'heading' || !node.depth)
|
|
78
|
+
return null;
|
|
79
|
+
// Read here without remarkToggleHeadings: the marker is still in its words.
|
|
80
|
+
const { text, toggle } = takeToggleMarker(mdText(node));
|
|
81
|
+
return { level: node.depth, text, toggle };
|
|
82
|
+
});
|
|
71
83
|
}
|
|
72
84
|
const parser = unified().use(remarkParse).use(remarkGfm);
|
|
73
85
|
/** The fold plan for a Markdown text, parsed as <Markdown> and the editor parse it. */
|
|
@@ -135,7 +147,8 @@ export function rehypeFold(options) {
|
|
|
135
147
|
const blocks = at.map((index) => {
|
|
136
148
|
const node = children[index];
|
|
137
149
|
const level = node.type === 'element' ? HEADING.exec(node.tagName ?? '')?.[1] : undefined;
|
|
138
|
-
|
|
150
|
+
// remarkToggleHeadings marked it, its marker gone.
|
|
151
|
+
return level ? { level: Number(level), text: hastText(node), toggle: node.properties?.dataToggle === 'true' } : null;
|
|
139
152
|
});
|
|
140
153
|
const plan = foldPlan(blocks, options.folded);
|
|
141
154
|
for (const heading of plan.headings) {
|
|
@@ -144,6 +157,7 @@ export function rehypeFold(options) {
|
|
|
144
157
|
...node.properties,
|
|
145
158
|
dataFoldId: heading.id,
|
|
146
159
|
dataFoldLabel: heading.text,
|
|
160
|
+
dataToggle: String(heading.toggle),
|
|
147
161
|
dataFoldable: String(heading.foldable),
|
|
148
162
|
dataFolded: String(heading.foldable && options.folded.has(heading.id)),
|
|
149
163
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The marker at a toggle heading's end, as it's written. */
|
|
2
|
+
export declare const TOGGLE_MARKER = "{toggle=\"true\"}";
|
|
3
|
+
/** `text` without a toggle marker at its end, and whether it had one. */
|
|
4
|
+
export declare function takeToggleMarker(text: string): {
|
|
5
|
+
text: string;
|
|
6
|
+
toggle: boolean;
|
|
7
|
+
};
|
|
8
|
+
type MdNode = {
|
|
9
|
+
type: string;
|
|
10
|
+
depth?: number;
|
|
11
|
+
value?: string;
|
|
12
|
+
children?: MdNode[];
|
|
13
|
+
data?: Record<string, unknown>;
|
|
14
|
+
toggle?: boolean;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A heading that's a toggle: true, with the marker taken out of its last
|
|
19
|
+
* text (and that text too, when the marker was all of it). False for any
|
|
20
|
+
* other node, untouched.
|
|
21
|
+
*/
|
|
22
|
+
export declare function takeToggle(node: MdNode): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Marks each toggle heading, its marker taken out: `toggle: true` on the
|
|
25
|
+
* mdast node (the editor's schema reads it) and a `data-toggle` property
|
|
26
|
+
* on its element (rehypeFold reads it).
|
|
27
|
+
*/
|
|
28
|
+
export declare function remarkToggleHeadings(): (tree: unknown) => void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Toggle headings (Notion's): the only headings that fold. A plain
|
|
2
|
+
// heading never folds and never shows a fold button; a toggle heading
|
|
3
|
+
// folds its section, as every heading did before 4.66.0.
|
|
4
|
+
//
|
|
5
|
+
// In Markdown a toggle heading is a heading whose line ends in Notion's
|
|
6
|
+
// own attribute, so a chat that writes Notion's Markdown writes it, and a
|
|
7
|
+
// plain heading stays plain Markdown:
|
|
8
|
+
//
|
|
9
|
+
// ## Safety {toggle="true"}
|
|
10
|
+
//
|
|
11
|
+
// Anything else reads it as a heading with those words at its end. These
|
|
12
|
+
// plugins take the marker off and mark the heading instead:
|
|
13
|
+
// `remarkToggleHeadings` for <Markdown> (a `data-toggle` property
|
|
14
|
+
// rehypeFold reads) and for the rich-text editor (its heading node's
|
|
15
|
+
// `toggle` attribute, written back with the marker by its schema). The
|
|
16
|
+
// marker never counts in a heading's words, so its fold id
|
|
17
|
+
// (markdown-fold.ts) is the same plain or toggle.
|
|
18
|
+
/** The marker at a toggle heading's end, as it's written. */
|
|
19
|
+
export const TOGGLE_MARKER = '{toggle="true"}';
|
|
20
|
+
// The marker at the end of a heading's text, the space before it and any
|
|
21
|
+
// after it. Single quotes, no quotes and spaces inside the braces are read
|
|
22
|
+
// too; it's written back as TOGGLE_MARKER.
|
|
23
|
+
const AT_END = /[ \t]*\{\s*toggle\s*=\s*(?:"true"|'true'|true)\s*\}[ \t]*$/;
|
|
24
|
+
/** `text` without a toggle marker at its end, and whether it had one. */
|
|
25
|
+
export function takeToggleMarker(text) {
|
|
26
|
+
const found = AT_END.exec(text);
|
|
27
|
+
return found ? { text: text.slice(0, found.index), toggle: true } : { text, toggle: false };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A heading that's a toggle: true, with the marker taken out of its last
|
|
31
|
+
* text (and that text too, when the marker was all of it). False for any
|
|
32
|
+
* other node, untouched.
|
|
33
|
+
*/
|
|
34
|
+
export function takeToggle(node) {
|
|
35
|
+
if (node.type !== 'heading')
|
|
36
|
+
return false;
|
|
37
|
+
const last = node.children?.[node.children.length - 1];
|
|
38
|
+
if (last?.type !== 'text' || typeof last.value !== 'string')
|
|
39
|
+
return false;
|
|
40
|
+
const taken = takeToggleMarker(last.value);
|
|
41
|
+
if (!taken.toggle)
|
|
42
|
+
return false;
|
|
43
|
+
if (taken.text)
|
|
44
|
+
last.value = taken.text;
|
|
45
|
+
else
|
|
46
|
+
node.children.pop();
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function visit(node, each) {
|
|
50
|
+
for (const child of node.children ?? [])
|
|
51
|
+
visit(child, each);
|
|
52
|
+
each(node);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Marks each toggle heading, its marker taken out: `toggle: true` on the
|
|
56
|
+
* mdast node (the editor's schema reads it) and a `data-toggle` property
|
|
57
|
+
* on its element (rehypeFold reads it).
|
|
58
|
+
*/
|
|
59
|
+
export function remarkToggleHeadings() {
|
|
60
|
+
return (tree) => {
|
|
61
|
+
visit(tree, (node) => {
|
|
62
|
+
if (!takeToggle(node))
|
|
63
|
+
return;
|
|
64
|
+
node.toggle = true;
|
|
65
|
+
const hProperties = node.data?.hProperties ?? {};
|
|
66
|
+
node.data = { ...node.data, hProperties: { ...hProperties, dataToggle: 'true' } };
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
package/eslint/index.d.ts
CHANGED
|
@@ -4,8 +4,13 @@ export declare const PACKAGE_NAME: string
|
|
|
4
4
|
export declare const PRIMITIVES: string[]
|
|
5
5
|
export declare const TOKEN_SYNTAX_RULES: { selector: string; message: string }[]
|
|
6
6
|
export declare const NO_BARE_FETCH: { selector: string; message: string }
|
|
7
|
+
export declare const TABLE_OPENS: { selector: string; message: string }
|
|
7
8
|
export declare function baseConfig(): Linter.Config
|
|
8
9
|
export declare function kebabCaseFilenames(files: string[], ignores?: string[]): Linter.Config
|
|
9
10
|
|
|
10
11
|
/** The lint config for an app built on the foundation. */
|
|
11
|
-
export default function uiFoundation(options?: {
|
|
12
|
+
export default function uiFoundation(options?: {
|
|
13
|
+
ignores?: string[]
|
|
14
|
+
/** Every DataTable must say how it opens a record (`opens`). */
|
|
15
|
+
requireTableOpens?: boolean
|
|
16
|
+
}): Linter.Config[]
|