@usememos/editor 26.10.13 → 26.10.14

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.
@@ -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` */
@@ -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 { Block } from '../model.js';
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
  /**
@@ -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:
@@ -72,9 +72,18 @@ export interface ListItemBlock {
72
72
  readonly start?: number;
73
73
  readonly content: Inline;
74
74
  }
75
+ /** The kinds of callout, as in GitHub's alert syntax (`> [!NOTE]`). */
76
+ export declare const CALLOUT_TYPES: readonly ["note", "tip", "important", "warning", "caution"];
77
+ export type CalloutType = (typeof CALLOUT_TYPES)[number];
78
+ /**
79
+ * One paragraph of a block quote. Adjacent quotes with the same `callout`
80
+ * form one blockquote.
81
+ */
75
82
  export interface QuoteBlock {
76
83
  readonly id: string;
77
84
  readonly type: 'quote';
85
+ /** Set on every paragraph of a callout, written as a GitHub alert (`> [!NOTE]`). */
86
+ readonly callout?: CalloutType;
78
87
  readonly content: Inline;
79
88
  }
80
89
  /** Code block. Content is plain text (no marks); lines are separated by "\n". */
@@ -107,8 +116,25 @@ export interface DividerBlock {
107
116
  readonly id: string;
108
117
  readonly type: 'divider';
109
118
  }
110
- export type TextBlock = ParagraphBlock | HeadingBlock | ListItemBlock | QuoteBlock | CodeBlock | RawBlock;
111
- export type Block = TextBlock | TableBlock | DividerBlock;
119
+ /**
120
+ * The title of a collapsible section, written as `<details>` and
121
+ * `<summary>`. The blocks after it, up to its `detailsEnd`, are the
122
+ * section's body. The title is plain text.
123
+ */
124
+ export interface DetailsBlock {
125
+ readonly id: string;
126
+ readonly type: 'details';
127
+ /** Written as `<details open>`: shown expanded where the Markdown is rendered. */
128
+ readonly open: boolean;
129
+ readonly content: Inline;
130
+ }
131
+ /** Ends the innermost collapsible section still open before it (`</details>`). Holds no text. */
132
+ export interface DetailsEndBlock {
133
+ readonly id: string;
134
+ readonly type: 'detailsEnd';
135
+ }
136
+ export type TextBlock = ParagraphBlock | HeadingBlock | ListItemBlock | QuoteBlock | CodeBlock | RawBlock | DetailsBlock;
137
+ export type Block = TextBlock | TableBlock | DividerBlock | DetailsEndBlock;
112
138
  export type BlockType = Block['type'];
113
139
  export interface Doc {
114
140
  readonly blocks: readonly Block[];
@@ -145,7 +171,7 @@ export declare function listItem(listType: ListType, content?: Inline, opts?: {
145
171
  start?: number;
146
172
  id?: string;
147
173
  }): ListItemBlock;
148
- export declare function quote(content?: Inline, id?: string): QuoteBlock;
174
+ export declare function quote(content?: Inline, id?: string, callout?: CalloutType): QuoteBlock;
149
175
  export declare function codeBlock(language?: string, text?: string, id?: string): CodeBlock;
150
176
  export declare function rawBlock(syntax: string, text?: string, id?: string): RawBlock;
151
177
  /** A raw HTML block. */
@@ -153,10 +179,21 @@ export declare function htmlBlock(text?: string, id?: string): RawBlock;
153
179
  export declare function table(align: readonly Align[], rows: readonly (readonly Inline[])[], id?: string): TableBlock;
154
180
  export declare function emptyTable(rows?: number, cols?: number, id?: string): TableBlock;
155
181
  export declare function divider(id?: string): DividerBlock;
182
+ /** The title of a collapsible section. A `detailsEnd` must follow its body. */
183
+ export declare function details(content?: Inline, opts?: {
184
+ open?: boolean;
185
+ id?: string;
186
+ }): DetailsBlock;
187
+ export declare function detailsEnd(id?: string): DetailsEndBlock;
156
188
  export declare function plain(text: string): Span[];
157
189
  export declare function isTextBlock(block: Block): block is TextBlock;
158
- /** Blocks whose content is plain text: no marks, links or images, and Enter inserts a newline. */
159
- export declare function isPlainTextBlock(block: Block): block is CodeBlock | RawBlock;
190
+ /** Blocks with no text and no cells: dividers and the ends of collapsible sections. */
191
+ export declare function isTextless(block: Block): block is DividerBlock | DetailsEndBlock;
192
+ /**
193
+ * Blocks whose content is plain text: no marks, links or images. In code and
194
+ * raw blocks Enter inserts a newline; a section title is one line.
195
+ */
196
+ export declare function isPlainTextBlock(block: Block): block is CodeBlock | RawBlock | DetailsBlock;
160
197
  /** Inline content at a position's container: the block's content, or a table cell. Null for dividers. */
161
198
  /**
162
199
  * 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;
@@ -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 border and title of each callout type. */
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
+ }
@@ -1,4 +1,4 @@
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';
@@ -55,6 +55,8 @@ 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>}`;
58
60
  /**
59
61
  * Runs of inline raw HTML that render as one piece: an opening tag through
60
62
  * its closing tag, with the text between (`<kbd>Ctrl</kbd>`), or a single tag
@@ -103,6 +105,8 @@ export declare class BlockRenderer {
103
105
  codeCopy: boolean;
104
106
  /** An image failed to load and now shows as unavailable. */
105
107
  onImageError?: () => void;
108
+ /** Collapsible sections shown collapsed, by the ID of their title block. */
109
+ collapsed: ReadonlySet<string>;
106
110
  /** Per block, the views that show their source. A block re-renders when its entry changes. */
107
111
  revealed: ReadonlyMap<string, BlockReveal>;
108
112
  /**
@@ -131,6 +135,8 @@ export declare class BlockRenderer {
131
135
  * skip layout while off screen; use it only when loading a document.
132
136
  */
133
137
  render(doc: Doc, force?: boolean, lazy?: boolean): void;
138
+ /** Marks blocks again after `collapsed` changed, without rendering any. */
139
+ updateSections(doc: Doc): void;
134
140
  elementFor(id: string): HTMLElement | undefined;
135
141
  /**
136
142
  * Keeps a block's element for a new version of the block, when the browser
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usememos/editor",
3
- "version": "26.10.13",
3
+ "version": "26.10.14",
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",