@usememos/editor 26.10.13 → 26.10.15
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 +59 -14
- package/dist/base.css +101 -13
- package/dist/emoji-data-WTFGY3MU.js +6 -0
- package/dist/emoji-data-WTFGY3MU.js.map +7 -0
- package/dist/emoji.js +74 -0
- package/dist/emoji.js.map +7 -0
- package/dist/index.js +1144 -148
- package/dist/index.js.map +4 -4
- package/dist/react.js.map +2 -2
- package/dist/style.css +215 -13
- package/dist/theme.css +37 -3
- package/dist/types/commands.d.ts +48 -3
- package/dist/types/editor.d.ts +59 -3
- package/dist/types/emoji/data.d.ts +1 -0
- package/dist/types/emoji/index.d.ts +21 -0
- package/dist/types/emoji/search.d.ts +17 -0
- package/dist/types/icons.d.ts +39 -0
- package/dist/types/labels.d.ts +20 -0
- package/dist/types/markdown/blocks.d.ts +2 -0
- package/dist/types/markdown/htmlSection.d.ts +10 -1
- package/dist/types/markdown/inline.d.ts +2 -0
- package/dist/types/markdown/lower.d.ts +11 -1
- package/dist/types/markdown/options.d.ts +14 -0
- package/dist/types/markdown/serialize.d.ts +8 -0
- package/dist/types/model.d.ts +62 -5
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/theme.d.ts +8 -0
- package/dist/types/ui/linkCard.d.ts +46 -0
- package/dist/types/view/dom.d.ts +14 -2
- package/dist/types/view/reveal.d.ts +1 -1
- package/package.json +5 -1
package/dist/types/editor.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { type MarkdownOptions } from './markdown/options.js';
|
|
|
6
6
|
import type { Extension } from './extension.js';
|
|
7
7
|
import { type SuggestionState } from './suggest/controller.js';
|
|
8
8
|
import { type Widget, type WidgetRender } from './widgets.js';
|
|
9
|
-
import { type Block, type EditorState, type HeadingLevel, type Position, type Selection } from './model.js';
|
|
9
|
+
import { type Block, type CalloutType, type EditorState, type HeadingLevel, type Position, type Selection } from './model.js';
|
|
10
10
|
import { type ToolbarItem } from './ui/toolbar.js';
|
|
11
11
|
import { type ResolveUrl } from './view/dom.js';
|
|
12
12
|
import { type Theme } from './theme.js';
|
|
@@ -73,6 +73,12 @@ export interface EditorOptions {
|
|
|
73
73
|
toolbar?: boolean | {
|
|
74
74
|
items?: readonly ToolbarItem[];
|
|
75
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Shows the link card while editing: the link's URL and buttons to open,
|
|
78
|
+
* copy, edit and remove it, when the pointer rests on a link or the caret
|
|
79
|
+
* is inside one. Default true.
|
|
80
|
+
*/
|
|
81
|
+
linkCard?: boolean;
|
|
76
82
|
/**
|
|
77
83
|
* The element menus, the toolbar and other popups are appended to.
|
|
78
84
|
* Default: the nearest open `<dialog>` or `aria-modal` ancestor of
|
|
@@ -141,6 +147,8 @@ export interface SuggestionApi {
|
|
|
141
147
|
}
|
|
142
148
|
/** Names `isActive` and `getAttributes` understand. */
|
|
143
149
|
export type ActiveName = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'taskList' | 'blockquote' | 'codeBlock' | 'table' | 'divider' | 'raw'
|
|
150
|
+
/** The title of a collapsible section. */
|
|
151
|
+
| 'details'
|
|
144
152
|
/** The selection is exactly one image. */
|
|
145
153
|
| 'image';
|
|
146
154
|
/** A position that survives reloading the same Markdown: a block index and an offset. */
|
|
@@ -180,6 +188,16 @@ export interface EditorCommands {
|
|
|
180
188
|
toggleOrderedList(): boolean;
|
|
181
189
|
toggleTaskList(): boolean;
|
|
182
190
|
toggleBlockquote(): boolean;
|
|
191
|
+
/** Turns the selected blocks into a callout of `type` (default `note`), or back into paragraphs when they are one already. */
|
|
192
|
+
toggleCallout(attrs?: {
|
|
193
|
+
type?: CalloutType;
|
|
194
|
+
}): boolean;
|
|
195
|
+
/** Changes the type of the callout with the caret, or turns the quote with the caret into a callout; `null` makes it a plain quote. */
|
|
196
|
+
setCallout(attrs: {
|
|
197
|
+
type: CalloutType | null;
|
|
198
|
+
}): boolean;
|
|
199
|
+
/** Turns the block with the caret into the title of a collapsible section with an empty body, or, on a title, removes the section and keeps its blocks. */
|
|
200
|
+
toggleDetails(): boolean;
|
|
183
201
|
toggleCodeBlock(attrs?: {
|
|
184
202
|
language?: string;
|
|
185
203
|
}): boolean;
|
|
@@ -218,7 +236,7 @@ export interface EditorCommands {
|
|
|
218
236
|
/** Scrolls the caret (the selection's focus end) into view, in scrolling containers and the window. */
|
|
219
237
|
scrollIntoView(): boolean;
|
|
220
238
|
}
|
|
221
|
-
export declare const SLASH_ITEM_IDS: readonly ["text", "heading1", "heading2", "heading3", "bulletList", "numberedList", "todoList", "quote", "code", "table", "divider"];
|
|
239
|
+
export declare const SLASH_ITEM_IDS: readonly ["text", "heading1", "heading2", "heading3", "heading4", "bulletList", "numberedList", "todoList", "quote", "callout", "details", "code", "table", "divider"];
|
|
222
240
|
export type SlashItemId = (typeof SLASH_ITEM_IDS)[number];
|
|
223
241
|
export declare class Editor {
|
|
224
242
|
/** The editable element the editor renders into: `options.element`, or for `useEditor`, the element `<EditorContent>` mounts. */
|
|
@@ -289,6 +307,9 @@ export declare class Editor {
|
|
|
289
307
|
/** The link popover, and the field for an image's alt text. */
|
|
290
308
|
private readonly inputPopover;
|
|
291
309
|
private readonly blockHandle;
|
|
310
|
+
/** Collapsible sections shown collapsed, by the ID of their title. View state: not saved, not undone. */
|
|
311
|
+
private readonly collapsed;
|
|
312
|
+
private readonly linkCard;
|
|
292
313
|
private readonly resizeHandles;
|
|
293
314
|
/** The selected image's element, which carries the selected class. */
|
|
294
315
|
private selectedImageEl;
|
|
@@ -329,7 +350,7 @@ export declare class Editor {
|
|
|
329
350
|
get isDestroyed(): boolean;
|
|
330
351
|
/** True if `name` applies at the selection: a mark on the selected text, or the type of the block with the caret. */
|
|
331
352
|
isActive(name: ActiveName, attrs?: Readonly<Record<string, unknown>>): boolean;
|
|
332
|
-
/** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block. */
|
|
353
|
+
/** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block, `callout` for a callout, `open` (saved as `<details open>`) and `collapsed` (shown collapsed now) for a section title. */
|
|
333
354
|
getAttributes(name: ActiveName): Record<string, unknown>;
|
|
334
355
|
getSelection(): Selection;
|
|
335
356
|
/**
|
|
@@ -546,6 +567,8 @@ export declare class Editor {
|
|
|
546
567
|
*/
|
|
547
568
|
private clickBelowLastBlock;
|
|
548
569
|
private onClick;
|
|
570
|
+
/** Opens a resolved link URL, as a click on a link does: through `onLinkClick`, else in a new tab. */
|
|
571
|
+
private openHref;
|
|
549
572
|
/** Copies the code of the code block holding `button`, and shows that it did for a moment. */
|
|
550
573
|
private copyCode;
|
|
551
574
|
/** The code block language input. */
|
|
@@ -567,6 +590,10 @@ export declare class Editor {
|
|
|
567
590
|
/** The blocks of the block selection, in document order. Empty when the selection is text. */
|
|
568
591
|
get selectedBlocks(): readonly Block[];
|
|
569
592
|
private blockRange;
|
|
593
|
+
/** `range` grown so that a collapsible section with its title or its end in it is in it whole. */
|
|
594
|
+
private wholeSections;
|
|
595
|
+
/** The next block a block selection moves to from `index`: blocks shown on screen, not section ends. */
|
|
596
|
+
private nextSelectable;
|
|
570
597
|
/** Selects whole blocks, from the block `anchor` to the block `head`. */
|
|
571
598
|
private selectBlockRange;
|
|
572
599
|
/** Leaves block selection, keeping the hidden caret as a collapsed selection. */
|
|
@@ -588,6 +615,8 @@ export declare class Editor {
|
|
|
588
615
|
private blockMenuSections;
|
|
589
616
|
/** The Align row of the block menu: a submenu of Left, Center and Right with the current one checked. */
|
|
590
617
|
private alignMenuItem;
|
|
618
|
+
/** True if the blocks `a` and `b` are in the same callout. */
|
|
619
|
+
private inSameCallout;
|
|
591
620
|
private closeBlockMenu;
|
|
592
621
|
/**
|
|
593
622
|
* A press anywhere but the block menu or the block handle closes the block menu,
|
|
@@ -595,6 +624,33 @@ export declare class Editor {
|
|
|
595
624
|
*/
|
|
596
625
|
private onDocumentPointerDown;
|
|
597
626
|
private updateUi;
|
|
627
|
+
/**
|
|
628
|
+
* Collapses or expands the collapsible section titled by the block
|
|
629
|
+
* `blockId`. This changes the view only: the Markdown, history and events
|
|
630
|
+
* stay as they are. A caret inside a section that collapses moves to the
|
|
631
|
+
* end of its title. Returns false when the block is not a section title.
|
|
632
|
+
*/
|
|
633
|
+
setSectionCollapsed(blockId: string, collapsed: boolean): boolean;
|
|
634
|
+
/** True when the section titled by `blockId` is shown collapsed. */
|
|
635
|
+
isSectionCollapsed(blockId: string): boolean;
|
|
636
|
+
/** Sections that are not saved open start collapsed, as a Markdown renderer shows them. */
|
|
637
|
+
private collapseClosedSections;
|
|
638
|
+
/** Expands the collapsed sections around the selection's focus, so the caret is never hidden. */
|
|
639
|
+
private expandAroundSelection;
|
|
640
|
+
/** Blocks the caret passes over: dividers, section ends, and blocks inside a collapsed section. */
|
|
641
|
+
private skipsCaret;
|
|
642
|
+
/** The link the caret is inside, not at its edge, with its element. */
|
|
643
|
+
private caretLink;
|
|
644
|
+
/** The document position where a rendered link starts. */
|
|
645
|
+
private linkStart;
|
|
646
|
+
/** The link a rendered link element shows, or null for one outside the document's blocks. */
|
|
647
|
+
private linkTargetOf;
|
|
648
|
+
/** The selection of a link's whole text, from a rendered link element. */
|
|
649
|
+
private linkSelection;
|
|
650
|
+
/** Opens the link popover for a link, as Mod+K does with the caret in it. */
|
|
651
|
+
private editLink;
|
|
652
|
+
/** Removes a link and keeps its text, as one undo step. */
|
|
653
|
+
private removeLink;
|
|
598
654
|
/** Marks the selected image's element, and hides the browser's selection highlight over it. */
|
|
599
655
|
private paintSelectedImage;
|
|
600
656
|
/** The selected image of `state` and its element, or null. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EMOJI_DATA: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Extension } from '@usememos/editor';
|
|
2
|
+
import { type Emoji } from './search.js';
|
|
3
|
+
export { type Emoji, parseEmoji, searchEmoji } from './search.js';
|
|
4
|
+
export interface EmojiOptions {
|
|
5
|
+
/** The suggestion's name, for `editor.suggestion.open(name)`. Default `emoji`. */
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
/** Most emoji shown. Default 8. */
|
|
8
|
+
readonly limit?: number;
|
|
9
|
+
/** Characters typed after `:` before the popup opens, so `:)` and `a :b` stay quiet. Default 2. Ctrl+Space opens it sooner. */
|
|
10
|
+
readonly minLength?: number;
|
|
11
|
+
/** Accessible name of the popup. Default `Emoji`. */
|
|
12
|
+
readonly label?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Every emoji the extension offers, loaded once on first use. */
|
|
15
|
+
export declare function loadEmoji(): Promise<readonly Emoji[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Emoji autocomplete: typing `:` and two letters at the start of a word lists
|
|
18
|
+
* emoji by GitHub's names and tags (`:tada`, `:party`). A pick replaces the
|
|
19
|
+
* typed name with the emoji, so the Markdown holds the character itself.
|
|
20
|
+
*/
|
|
21
|
+
export declare function emoji(options?: EmojiOptions): Extension;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Emoji {
|
|
2
|
+
/** The character, such as "🎉". */
|
|
3
|
+
readonly emoji: string;
|
|
4
|
+
/** Its names, the first the main one, such as ["tada"]. Typed as `:tada:` on GitHub. */
|
|
5
|
+
readonly names: readonly string[];
|
|
6
|
+
/** Other words it is found by, such as ["party"]. */
|
|
7
|
+
readonly tags: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
/** Reads the lines of `data.ts`: the emoji, its names and its tags, separated by tabs. */
|
|
10
|
+
export declare function parseEmoji(data: string): Emoji[];
|
|
11
|
+
/**
|
|
12
|
+
* Emoji whose names or tags match `query`, best first: a name equal to it,
|
|
13
|
+
* a name starting with it, a word of a name starting with it ("smile" finds
|
|
14
|
+
* "sweat_smile"), a tag starting with it, then a name containing it. Within
|
|
15
|
+
* a rank the data's order is kept, which puts common emoji first.
|
|
16
|
+
*/
|
|
17
|
+
export declare function searchEmoji(emoji: readonly Emoji[], query: string, limit?: number): Emoji[];
|
package/dist/types/icons.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ declare const ICONS: {
|
|
|
25
25
|
heading2: string[];
|
|
26
26
|
/** `heading-3` */
|
|
27
27
|
heading3: string[];
|
|
28
|
+
/** `heading-4` */
|
|
29
|
+
heading4: string[];
|
|
28
30
|
/** `list` */
|
|
29
31
|
bulletList: string[];
|
|
30
32
|
/** `list-ordered` */
|
|
@@ -39,6 +41,28 @@ declare const ICONS: {
|
|
|
39
41
|
}])[];
|
|
40
42
|
/** `text-quote` */
|
|
41
43
|
quote: string[];
|
|
44
|
+
/** `info`, as a Note callout */
|
|
45
|
+
callout: (string | [string, {
|
|
46
|
+
cx: string;
|
|
47
|
+
cy: string;
|
|
48
|
+
r: string;
|
|
49
|
+
}])[];
|
|
50
|
+
/** `info` */
|
|
51
|
+
calloutNote: (string | [string, {
|
|
52
|
+
cx: string;
|
|
53
|
+
cy: string;
|
|
54
|
+
r: string;
|
|
55
|
+
}])[];
|
|
56
|
+
/** `lightbulb` */
|
|
57
|
+
calloutTip: string[];
|
|
58
|
+
/** `message-square-warning` */
|
|
59
|
+
calloutImportant: string[];
|
|
60
|
+
/** `triangle-alert` */
|
|
61
|
+
calloutWarning: string[];
|
|
62
|
+
/** `octagon-alert` */
|
|
63
|
+
calloutCaution: string[];
|
|
64
|
+
/** `list-collapse` */
|
|
65
|
+
details: string[];
|
|
42
66
|
/** `square-code` */
|
|
43
67
|
code: (string | [string, {
|
|
44
68
|
x: string;
|
|
@@ -139,6 +163,21 @@ declare const ICONS: {
|
|
|
139
163
|
}])[];
|
|
140
164
|
/** `code` */
|
|
141
165
|
inlineCode: string[];
|
|
166
|
+
/** `external-link` */
|
|
167
|
+
openLink: string[];
|
|
168
|
+
/** `copy` */
|
|
169
|
+
copyLink: (string | [string, {
|
|
170
|
+
width: string;
|
|
171
|
+
height: string;
|
|
172
|
+
x: string;
|
|
173
|
+
y: string;
|
|
174
|
+
rx: string;
|
|
175
|
+
ry: string;
|
|
176
|
+
}])[];
|
|
177
|
+
/** `pencil` */
|
|
178
|
+
editLink: string[];
|
|
179
|
+
/** `unlink` */
|
|
180
|
+
removeLink: string[];
|
|
142
181
|
/** `link` */
|
|
143
182
|
link: string[];
|
|
144
183
|
/** `image-off` */
|
package/dist/types/labels.d.ts
CHANGED
|
@@ -3,13 +3,29 @@ export declare const DEFAULT_LABELS: {
|
|
|
3
3
|
heading1: string;
|
|
4
4
|
heading2: string;
|
|
5
5
|
heading3: string;
|
|
6
|
+
heading4: string;
|
|
6
7
|
bulletList: string;
|
|
7
8
|
numberedList: string;
|
|
8
9
|
todoList: string;
|
|
9
10
|
/** Accessible name of a task checkbox whose item has no text. */
|
|
10
11
|
task: string;
|
|
11
12
|
quote: string;
|
|
13
|
+
/** The slash menu item, and the title of a callout's block menu section. */
|
|
14
|
+
callout: string;
|
|
15
|
+
/** Callout types: each callout's title, and its block menu items. */
|
|
16
|
+
calloutNote: string;
|
|
17
|
+
calloutTip: string;
|
|
18
|
+
calloutImportant: string;
|
|
19
|
+
calloutWarning: string;
|
|
20
|
+
calloutCaution: string;
|
|
12
21
|
code: string;
|
|
22
|
+
/** The slash menu item that makes a collapsible section. */
|
|
23
|
+
details: string;
|
|
24
|
+
/** Shown in an empty section title. */
|
|
25
|
+
detailsHint: string;
|
|
26
|
+
/** The toggle of a collapsible section. */
|
|
27
|
+
expandSection: string;
|
|
28
|
+
collapseSection: string;
|
|
13
29
|
table: string;
|
|
14
30
|
divider: string;
|
|
15
31
|
noResults: string;
|
|
@@ -32,6 +48,10 @@ export declare const DEFAULT_LABELS: {
|
|
|
32
48
|
list: string;
|
|
33
49
|
linkPlaceholder: string;
|
|
34
50
|
removeLink: string;
|
|
51
|
+
/** The link card's buttons. */
|
|
52
|
+
openLink: string;
|
|
53
|
+
copyLink: string;
|
|
54
|
+
editLink: string;
|
|
35
55
|
/** Shown in the empty paragraph that has the caret, with the `slashHint` option. */
|
|
36
56
|
slashHint: string;
|
|
37
57
|
blockHandle: string;
|
|
@@ -2,3 +2,5 @@ import type { Root } from './ast.js';
|
|
|
2
2
|
import { type MarkdownOptions } from './options.js';
|
|
3
3
|
/** Parses Markdown source into a syntax tree. */
|
|
4
4
|
export declare function parseAst(src: string, options?: MarkdownOptions): Root;
|
|
5
|
+
/** True when `text` at the start of a line would start an HTML block that can interrupt a paragraph (types 1 to 6). */
|
|
6
|
+
export declare function interruptsParagraph(text: string): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Block } from '../model.js';
|
|
2
2
|
import type { BlockNode } from './ast.js';
|
|
3
3
|
import { type MarkdownOptions } from './options.js';
|
|
4
4
|
/**
|
|
@@ -7,6 +7,15 @@ import { type MarkdownOptions } from './options.js';
|
|
|
7
7
|
* nothing to join, including when the elements are never closed.
|
|
8
8
|
*/
|
|
9
9
|
export declare function htmlSectionEnd(nodes: readonly BlockNode[], i: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Collapsible sections among top-level blocks: an HTML block that is only
|
|
12
|
+
* `<details>` (or `<details open>`) and a `<summary>` of plain text, and the
|
|
13
|
+
* HTML block that is only `</details>` closing it, with Markdown between
|
|
14
|
+
* them. Returns their indexes, each mapped to the block it becomes. Sections
|
|
15
|
+
* nest. HTML between them that leaves an element open, which a renderer
|
|
16
|
+
* would close at the section's end, keeps the sections around it as HTML.
|
|
17
|
+
*/
|
|
18
|
+
export declare function detailsSections(nodes: readonly BlockNode[]): Map<number, Block>;
|
|
10
19
|
/** Marks where the blocks of slot `index` go in a section's HTML. Private-use characters, so they never meet real text. */
|
|
11
20
|
export declare const slotMarker: (index: number) => string;
|
|
12
21
|
/** Finds slot markers in text. */
|
|
@@ -26,6 +26,8 @@ export declare const AUTOLINK_EMAIL = "[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0
|
|
|
26
26
|
export declare function isUnicodeWhitespace(ch: string): boolean;
|
|
27
27
|
/** Unicode punctuation as the spec defines it (categories P and S). */
|
|
28
28
|
export declare function isUnicodePunctuation(ch: string): boolean;
|
|
29
|
+
/** Decodes the entity references in HTML text, such as a section title. */
|
|
30
|
+
export declare function decodeEntities(s: string): string;
|
|
29
31
|
/** Applies backslash escapes and entities, for link destinations, titles and info strings. */
|
|
30
32
|
export declare function unescapeString(s: string): string;
|
|
31
33
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Block, type Span } from '../model.js';
|
|
1
|
+
import { type Block, type CalloutType, type Span } from '../model.js';
|
|
2
2
|
import { type BlockNode, type InlineNode } from './ast.js';
|
|
3
3
|
import { type MarkdownOptions } from './options.js';
|
|
4
4
|
/**
|
|
@@ -6,4 +6,14 @@ import { type MarkdownOptions } from './options.js';
|
|
|
6
6
|
* one raw Markdown block holding `source`, the node's Markdown.
|
|
7
7
|
*/
|
|
8
8
|
export declare function lowerTopLevel(node: BlockNode, options: MarkdownOptions, source: string): Block[];
|
|
9
|
+
/** Lowers one block node, or returns null when the model cannot hold its structure (see `fitsModel`). */
|
|
10
|
+
export declare function lowerIfFits(node: BlockNode, options: MarkdownOptions): Block[] | null;
|
|
9
11
|
export declare function lowerInlines(nodes: readonly InlineNode[], options?: MarkdownOptions): Span[];
|
|
12
|
+
/**
|
|
13
|
+
* A GitHub alert: the first paragraph starts with a marker such as `[!NOTE]`
|
|
14
|
+
* alone on its line. Returns its type and the paragraph's content after the marker line.
|
|
15
|
+
*/
|
|
16
|
+
export declare function calloutOf(children: readonly BlockNode[]): {
|
|
17
|
+
type: CalloutType;
|
|
18
|
+
rest: readonly InlineNode[];
|
|
19
|
+
} | null;
|
|
@@ -15,6 +15,18 @@ export interface MarkdownOptions {
|
|
|
15
15
|
* `name@example.com` written without angle brackets are links. Default true.
|
|
16
16
|
*/
|
|
17
17
|
readonly autolinks?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* GitHub alerts: a blockquote whose first line is `[!NOTE]`, `[!TIP]`,
|
|
20
|
+
* `[!IMPORTANT]`, `[!WARNING]` or `[!CAUTION]` is a callout. Default true.
|
|
21
|
+
* With false, the marker is quoted text.
|
|
22
|
+
*/
|
|
23
|
+
readonly callouts?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Collapsible sections: `<details>` with a `<summary>` title, a blank line,
|
|
26
|
+
* Markdown, a blank line and `</details>` are a section whose title and body
|
|
27
|
+
* are edited in place. Default true. With false, the section is HTML.
|
|
28
|
+
*/
|
|
29
|
+
readonly details?: boolean;
|
|
18
30
|
/** Syntax outside CommonMark and GFM, such as math or footnotes. */
|
|
19
31
|
readonly syntax?: readonly MarkdownSyntax[];
|
|
20
32
|
}
|
|
@@ -66,6 +78,8 @@ export interface ResolvedMarkdown {
|
|
|
66
78
|
readonly breaks: boolean;
|
|
67
79
|
readonly setext: boolean;
|
|
68
80
|
readonly autolinks: boolean;
|
|
81
|
+
readonly callouts: boolean;
|
|
82
|
+
readonly details: boolean;
|
|
69
83
|
readonly syntax: readonly MarkdownSyntax[];
|
|
70
84
|
readonly inline: readonly InlineSyntax[];
|
|
71
85
|
readonly block: readonly BlockSyntax[];
|
|
@@ -14,6 +14,14 @@ export declare function serializeBlocks(blocks: readonly Block[], options?: Mark
|
|
|
14
14
|
export declare function isEmptyParagraph(block: Block): boolean;
|
|
15
15
|
/** Serializes inline content as it appears in a paragraph. */
|
|
16
16
|
export declare function serializeInline(inline: Inline, options?: MarkdownOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* A table cell's content as GFM can write it. GFM splits a row into cells
|
|
19
|
+
* before it parses code spans, and a backslash escapes the character after it
|
|
20
|
+
* there, so a pipe after an odd number of backslashes in a code span cannot be
|
|
21
|
+
* written: `\\|` ends the cell, and `\\\|` reads back as two backslashes.
|
|
22
|
+
* Such a pipe is written outside the code span, keeping its other marks.
|
|
23
|
+
*/
|
|
24
|
+
export declare function representableCell(inline: Inline): Inline;
|
|
17
25
|
/**
|
|
18
26
|
* The inline content as Markdown can represent it, which is what parsing the
|
|
19
27
|
* serialized output gives back:
|
package/dist/types/model.d.ts
CHANGED
|
@@ -70,11 +70,24 @@ export interface ListItemBlock {
|
|
|
70
70
|
readonly checked: boolean;
|
|
71
71
|
/** Ordered items only: the number of the first item of a list. Ignored on later items. */
|
|
72
72
|
readonly start?: number;
|
|
73
|
+
/** The item is inside a blockquote, with the quote blocks and quoted items around it (see `quoteKind`). */
|
|
74
|
+
readonly quote?: true;
|
|
75
|
+
/** Quoted items only: the item is inside a callout of this type. */
|
|
76
|
+
readonly callout?: CalloutType;
|
|
73
77
|
readonly content: Inline;
|
|
74
78
|
}
|
|
79
|
+
/** The kinds of callout, as in GitHub's alert syntax (`> [!NOTE]`). */
|
|
80
|
+
export declare const CALLOUT_TYPES: readonly ["note", "tip", "important", "warning", "caution"];
|
|
81
|
+
export type CalloutType = (typeof CALLOUT_TYPES)[number];
|
|
82
|
+
/**
|
|
83
|
+
* One paragraph of a block quote. Adjacent quotes and quoted list items with
|
|
84
|
+
* the same `callout` form one blockquote (see `quoteKind`).
|
|
85
|
+
*/
|
|
75
86
|
export interface QuoteBlock {
|
|
76
87
|
readonly id: string;
|
|
77
88
|
readonly type: 'quote';
|
|
89
|
+
/** Set on every paragraph of a callout, written as a GitHub alert (`> [!NOTE]`). */
|
|
90
|
+
readonly callout?: CalloutType;
|
|
78
91
|
readonly content: Inline;
|
|
79
92
|
}
|
|
80
93
|
/** Code block. Content is plain text (no marks); lines are separated by "\n". */
|
|
@@ -107,8 +120,25 @@ export interface DividerBlock {
|
|
|
107
120
|
readonly id: string;
|
|
108
121
|
readonly type: 'divider';
|
|
109
122
|
}
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The title of a collapsible section, written as `<details>` and
|
|
125
|
+
* `<summary>`. The blocks after it, up to its `detailsEnd`, are the
|
|
126
|
+
* section's body. The title is plain text.
|
|
127
|
+
*/
|
|
128
|
+
export interface DetailsBlock {
|
|
129
|
+
readonly id: string;
|
|
130
|
+
readonly type: 'details';
|
|
131
|
+
/** Written as `<details open>`: shown expanded where the Markdown is rendered. */
|
|
132
|
+
readonly open: boolean;
|
|
133
|
+
readonly content: Inline;
|
|
134
|
+
}
|
|
135
|
+
/** Ends the innermost collapsible section still open before it (`</details>`). Holds no text. */
|
|
136
|
+
export interface DetailsEndBlock {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly type: 'detailsEnd';
|
|
139
|
+
}
|
|
140
|
+
export type TextBlock = ParagraphBlock | HeadingBlock | ListItemBlock | QuoteBlock | CodeBlock | RawBlock | DetailsBlock;
|
|
141
|
+
export type Block = TextBlock | TableBlock | DividerBlock | DetailsEndBlock;
|
|
112
142
|
export type BlockType = Block['type'];
|
|
113
143
|
export interface Doc {
|
|
114
144
|
readonly blocks: readonly Block[];
|
|
@@ -139,13 +169,15 @@ export interface EditorState {
|
|
|
139
169
|
export declare function createId(): string;
|
|
140
170
|
export declare function paragraph(content?: Inline, id?: string): ParagraphBlock;
|
|
141
171
|
export declare function heading(level: HeadingLevel, content?: Inline, id?: string): HeadingBlock;
|
|
172
|
+
/** `quote` puts the item inside a blockquote: `'quote'` for a plain quote, or a callout's type. */
|
|
142
173
|
export declare function listItem(listType: ListType, content?: Inline, opts?: {
|
|
143
174
|
indent?: number;
|
|
144
175
|
checked?: boolean;
|
|
145
176
|
start?: number;
|
|
146
177
|
id?: string;
|
|
178
|
+
quote?: QuoteKind | null;
|
|
147
179
|
}): ListItemBlock;
|
|
148
|
-
export declare function quote(content?: Inline, id?: string): QuoteBlock;
|
|
180
|
+
export declare function quote(content?: Inline, id?: string, callout?: CalloutType): QuoteBlock;
|
|
149
181
|
export declare function codeBlock(language?: string, text?: string, id?: string): CodeBlock;
|
|
150
182
|
export declare function rawBlock(syntax: string, text?: string, id?: string): RawBlock;
|
|
151
183
|
/** A raw HTML block. */
|
|
@@ -153,10 +185,35 @@ export declare function htmlBlock(text?: string, id?: string): RawBlock;
|
|
|
153
185
|
export declare function table(align: readonly Align[], rows: readonly (readonly Inline[])[], id?: string): TableBlock;
|
|
154
186
|
export declare function emptyTable(rows?: number, cols?: number, id?: string): TableBlock;
|
|
155
187
|
export declare function divider(id?: string): DividerBlock;
|
|
188
|
+
/** The title of a collapsible section. A `detailsEnd` must follow its body. */
|
|
189
|
+
export declare function details(content?: Inline, opts?: {
|
|
190
|
+
open?: boolean;
|
|
191
|
+
id?: string;
|
|
192
|
+
}): DetailsBlock;
|
|
193
|
+
export declare function detailsEnd(id?: string): DetailsEndBlock;
|
|
156
194
|
export declare function plain(text: string): Span[];
|
|
195
|
+
/**
|
|
196
|
+
* Which blockquote a block is part of: `'quote'` for a plain quote, or the
|
|
197
|
+
* type of a callout. Quote blocks and quoted list items are the only blocks
|
|
198
|
+
* in quotes; adjacent ones of the same kind form one blockquote.
|
|
199
|
+
*/
|
|
200
|
+
export type QuoteKind = 'quote' | CalloutType;
|
|
201
|
+
/** The blockquote a block is part of, or null for a block outside quotes. */
|
|
202
|
+
export declare function quoteKind(block: Block | undefined): QuoteKind | null;
|
|
203
|
+
/** True if `a` and `b` are parts of one blockquote when they are neighbours. */
|
|
204
|
+
export declare function sameQuote(a: Block | undefined, b: Block | undefined): boolean;
|
|
205
|
+
/** A list item moved into a blockquote of `kind`, or out of any with null. Keeps its ID. */
|
|
206
|
+
export declare function withQuote(item: ListItemBlock, kind: QuoteKind | null): ListItemBlock;
|
|
207
|
+
/** A block as it is inside its blockquote: a quote block is a paragraph there, and a quoted list item a plain one. */
|
|
208
|
+
export declare function unquote(block: Block): Block;
|
|
157
209
|
export declare function isTextBlock(block: Block): block is TextBlock;
|
|
158
|
-
/** Blocks
|
|
159
|
-
export declare function
|
|
210
|
+
/** Blocks with no text and no cells: dividers and the ends of collapsible sections. */
|
|
211
|
+
export declare function isTextless(block: Block): block is DividerBlock | DetailsEndBlock;
|
|
212
|
+
/**
|
|
213
|
+
* Blocks whose content is plain text: no marks, links or images. In code and
|
|
214
|
+
* raw blocks Enter inserts a newline; a section title is one line.
|
|
215
|
+
*/
|
|
216
|
+
export declare function isPlainTextBlock(block: Block): block is CodeBlock | RawBlock | DetailsBlock;
|
|
160
217
|
/** Inline content at a position's container: the block's content, or a table cell. Null for dividers. */
|
|
161
218
|
/**
|
|
162
219
|
* The offset of the image in an image block, or null when `block` is not one.
|
|
@@ -2,7 +2,7 @@ import { Editor, type EditorOptions, type SuggestionState } from '@usememos/edit
|
|
|
2
2
|
import { type CSSProperties } from 'react';
|
|
3
3
|
export type { Editor, SuggestionState } from '@usememos/editor';
|
|
4
4
|
/** Constructor options that the React components take as props. */
|
|
5
|
-
type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'headingIds' | 'onLinkClick' | 'theme' | 'toolbar' | 'slashMenu' | 'slashHint' | 'labels' | 'icons'>;
|
|
5
|
+
type EditorProps = Pick<EditorOptions, 'markdown' | 'extensions' | 'placeholder' | 'editable' | 'taskToggle' | 'autofocus' | 'attributes' | 'resolveUrl' | 'referrerPolicy' | 'headingIds' | 'onLinkClick' | 'theme' | 'toolbar' | 'linkCard' | 'slashMenu' | 'slashHint' | 'labels' | 'icons'>;
|
|
6
6
|
export interface MarkdownEditorProps extends EditorProps {
|
|
7
7
|
/** Markdown. The editor updates only when this is not a value it emitted itself. */
|
|
8
8
|
value?: string;
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface ThemeClasses {
|
|
|
21
21
|
readonly table?: string;
|
|
22
22
|
/** The `<hr>` of a divider. */
|
|
23
23
|
readonly divider?: string;
|
|
24
|
+
/** The title row of a collapsible section. */
|
|
25
|
+
readonly details?: string;
|
|
24
26
|
/** Raw blocks: Markdown kept as source, or rendered by a view. */
|
|
25
27
|
readonly raw?: string;
|
|
26
28
|
/** `<img>` */
|
|
@@ -52,6 +54,12 @@ export interface ThemeColors {
|
|
|
52
54
|
/** Highlighted menu items and toolbar buttons. */
|
|
53
55
|
readonly hover?: string;
|
|
54
56
|
readonly danger?: string;
|
|
57
|
+
/** The icon of each callout type, and a light tint of it behind the text. */
|
|
58
|
+
readonly calloutNote?: string;
|
|
59
|
+
readonly calloutTip?: string;
|
|
60
|
+
readonly calloutImportant?: string;
|
|
61
|
+
readonly calloutWarning?: string;
|
|
62
|
+
readonly calloutCaution?: string;
|
|
55
63
|
}
|
|
56
64
|
/** Values written as --mbe-* custom properties on the root and on popups. Numbers are pixels. */
|
|
57
65
|
export interface ThemeTokens {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Editor } from '../editor.js';
|
|
2
|
+
/** A link in the document and its element. */
|
|
3
|
+
export interface LinkTarget {
|
|
4
|
+
readonly el: HTMLAnchorElement;
|
|
5
|
+
/** The URL as written in the Markdown. */
|
|
6
|
+
readonly href: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class LinkCard {
|
|
9
|
+
private readonly editor;
|
|
10
|
+
private readonly actions;
|
|
11
|
+
private readonly popup;
|
|
12
|
+
private readonly url;
|
|
13
|
+
private readonly copyButton;
|
|
14
|
+
private target;
|
|
15
|
+
/** What shows the card: the pointer on a link, or the caret in one. The pointer wins. */
|
|
16
|
+
private hovered;
|
|
17
|
+
private caret;
|
|
18
|
+
private showTimer;
|
|
19
|
+
private hideTimer;
|
|
20
|
+
private copiedTimer;
|
|
21
|
+
private readonly cleanup;
|
|
22
|
+
constructor(editor: Editor, actions: {
|
|
23
|
+
open: (target: LinkTarget, event: MouseEvent) => void;
|
|
24
|
+
edit: (target: LinkTarget) => void;
|
|
25
|
+
remove: (target: LinkTarget) => void;
|
|
26
|
+
/** The link of `el`, or null when it is not a link of the document. */
|
|
27
|
+
targetOf: (el: HTMLAnchorElement) => LinkTarget | null;
|
|
28
|
+
});
|
|
29
|
+
get isOpen(): boolean;
|
|
30
|
+
contains(node: Node): boolean;
|
|
31
|
+
/** Sets the link with the caret (null for none) and shows or hides the card to match. */
|
|
32
|
+
setCaret(target: LinkTarget | null): void;
|
|
33
|
+
/** Places the card under its link again, after scrolling or a layout change. */
|
|
34
|
+
reposition(): void;
|
|
35
|
+
hide(): void;
|
|
36
|
+
destroy(): void;
|
|
37
|
+
private onOver;
|
|
38
|
+
private onOut;
|
|
39
|
+
private render;
|
|
40
|
+
private place;
|
|
41
|
+
private copy;
|
|
42
|
+
private showCopied;
|
|
43
|
+
private scheduleHide;
|
|
44
|
+
private cancelHide;
|
|
45
|
+
private clearTimers;
|
|
46
|
+
}
|
package/dist/types/view/dom.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type Block, type Cell, type CodeBlock, type Doc, type Inline, type Position } from '../model.js';
|
|
1
|
+
import { type Block, type Cell, type CalloutType, type CodeBlock, type Doc, type Inline, type Position } from '../model.js';
|
|
2
2
|
import type { SyntaxView } from '../extension.js';
|
|
3
3
|
import type { Labels } from '../labels.js';
|
|
4
4
|
import type { IconName } from '../icons.js';
|
|
5
5
|
import type { ThemeClasses } from '../theme.js';
|
|
6
6
|
import { type Decoration } from '../decorations.js';
|
|
7
|
-
import type
|
|
7
|
+
import { type MarkdownOptions } from '../markdown/options.js';
|
|
8
8
|
export declare const BLOCK_ATTR = "data-block-id";
|
|
9
9
|
/** The view name for code blocks of a language: `code:mermaid`. */
|
|
10
10
|
export declare function codeViewName(language: string): string;
|
|
@@ -55,6 +55,14 @@ export type BlockReveal = ReadonlySet<string>;
|
|
|
55
55
|
export declare const REVEAL_BLOCK = "block";
|
|
56
56
|
export declare function tokenKey(cell: Cell | undefined, from: number): string;
|
|
57
57
|
export declare function sameReveal(a: BlockReveal | undefined, b: BlockReveal | undefined): boolean;
|
|
58
|
+
/** The label and icon name of a callout type, such as `calloutNote`. */
|
|
59
|
+
export declare function calloutName(type: CalloutType): `callout${Capitalize<CalloutType>}`;
|
|
60
|
+
/**
|
|
61
|
+
* Marks the built-in view of raw Markdown blocks in `RenderContext.views`.
|
|
62
|
+
* It is never called: the renderer draws those blocks itself (see
|
|
63
|
+
* `renderMarkdown`), and an extension's own `markdown` view replaces it.
|
|
64
|
+
*/
|
|
65
|
+
export declare const MARKDOWN_VIEW: SyntaxView;
|
|
58
66
|
/**
|
|
59
67
|
* Runs of inline raw HTML that render as one piece: an opening tag through
|
|
60
68
|
* its closing tag, with the text between (`<kbd>Ctrl</kbd>`), or a single tag
|
|
@@ -103,6 +111,8 @@ export declare class BlockRenderer {
|
|
|
103
111
|
codeCopy: boolean;
|
|
104
112
|
/** An image failed to load and now shows as unavailable. */
|
|
105
113
|
onImageError?: () => void;
|
|
114
|
+
/** Collapsible sections shown collapsed, by the ID of their title block. */
|
|
115
|
+
collapsed: ReadonlySet<string>;
|
|
106
116
|
/** Per block, the views that show their source. A block re-renders when its entry changes. */
|
|
107
117
|
revealed: ReadonlyMap<string, BlockReveal>;
|
|
108
118
|
/**
|
|
@@ -131,6 +141,8 @@ export declare class BlockRenderer {
|
|
|
131
141
|
* skip layout while off screen; use it only when loading a document.
|
|
132
142
|
*/
|
|
133
143
|
render(doc: Doc, force?: boolean, lazy?: boolean): void;
|
|
144
|
+
/** Marks blocks again after `collapsed` changed, without rendering any. */
|
|
145
|
+
updateSections(doc: Doc): void;
|
|
134
146
|
elementFor(id: string): HTMLElement | undefined;
|
|
135
147
|
/**
|
|
136
148
|
* Keeps a block's element for a new version of the block, when the browser
|
|
@@ -8,6 +8,6 @@ export declare function sameRevealed(a: ReadonlyMap<string, BlockReveal>, b: Rea
|
|
|
8
8
|
* Where the caret goes in a rendered block's source. A raw block: past its
|
|
9
9
|
* opening line going forward (such as a `$$` fence), at the end of its
|
|
10
10
|
* next-to-last line going back or on a click. A code block holds only the
|
|
11
|
-
* code:
|
|
11
|
+
* code, and raw Markdown has no fence: their start or their end.
|
|
12
12
|
*/
|
|
13
13
|
export declare function viewEntry(block: RawBlock | CodeBlock, forward: boolean): Position;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usememos/editor",
|
|
3
|
-
"version": "26.10.
|
|
3
|
+
"version": "26.10.15",
|
|
4
4
|
"description": "A block editor for Markdown. Zero runtime dependencies, with an optional React component.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"types": "./dist/types/react/index.d.ts",
|
|
35
35
|
"default": "./dist/react.js"
|
|
36
36
|
},
|
|
37
|
+
"./emoji": {
|
|
38
|
+
"types": "./dist/types/emoji/index.d.ts",
|
|
39
|
+
"default": "./dist/emoji.js"
|
|
40
|
+
},
|
|
37
41
|
"./style.css": "./dist/style.css",
|
|
38
42
|
"./base.css": "./dist/base.css",
|
|
39
43
|
"./theme.css": "./dist/theme.css",
|