@usememos/editor 26.10.12 → 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.
@@ -14,11 +14,20 @@ 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:
20
28
  * - Whitespace at the edges of a bold, italic or strike run moves outside it,
21
- * because `**foo **` is not valid emphasis.
29
+ * because `**foo **` is not valid emphasis. Whitespace in a code span
30
+ * stays: the delimiter then sits next to the backtick, as in `` **` a`** ``.
22
31
  * - A "\n" in a code span is a hard break outside the code span.
23
32
  * - Spaces and tabs that start or end a line of text are dropped, because
24
33
  * Markdown strips them. Writing them as character references instead would
@@ -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' | '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,9 +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 { MarkdownOptions } from '../markdown/options.js';
7
8
  export declare const BLOCK_ATTR = "data-block-id";
8
9
  /** The view name for code blocks of a language: `code:mermaid`. */
9
10
  export declare function codeViewName(language: string): string;
@@ -33,6 +34,8 @@ export interface RenderContext {
33
34
  readonly views?: ReadonlyMap<string, SyntaxView>;
34
35
  /** A token or raw block of an extension syntax, rendered; null shows its source. */
35
36
  readonly view?: (syntax: string, source: string, kind: 'inline' | 'block') => HTMLElement | null;
37
+ /** The document's Markdown options, for the Markdown inside an HTML section. */
38
+ readonly markdown?: MarkdownOptions;
36
39
  /** Theme classes for rendered elements. */
37
40
  readonly classes: ThemeClasses;
38
41
  /** The icon of a UI control, or null for none. */
@@ -52,6 +55,8 @@ export type BlockReveal = ReadonlySet<string>;
52
55
  export declare const REVEAL_BLOCK = "block";
53
56
  export declare function tokenKey(cell: Cell | undefined, from: number): string;
54
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>}`;
55
60
  /**
56
61
  * Runs of inline raw HTML that render as one piece: an opening tag through
57
62
  * its closing tag, with the text between (`<kbd>Ctrl</kbd>`), or a single tag
@@ -90,6 +95,8 @@ export declare class BlockRenderer {
90
95
  widgetsAfter?: (blockId: string) => readonly HTMLElement[] | undefined;
91
96
  /** Views of extension syntaxes, by syntax name. */
92
97
  views?: ReadonlyMap<string, SyntaxView>;
98
+ /** The document's Markdown options, for the Markdown inside an HTML section. */
99
+ markdown?: MarkdownOptions;
93
100
  /** Theme classes for rendered elements. Set before a full render. */
94
101
  classes: ThemeClasses;
95
102
  /** The icon of a UI control. */
@@ -98,6 +105,8 @@ export declare class BlockRenderer {
98
105
  codeCopy: boolean;
99
106
  /** An image failed to load and now shows as unavailable. */
100
107
  onImageError?: () => void;
108
+ /** Collapsible sections shown collapsed, by the ID of their title block. */
109
+ collapsed: ReadonlySet<string>;
101
110
  /** Per block, the views that show their source. A block re-renders when its entry changes. */
102
111
  revealed: ReadonlyMap<string, BlockReveal>;
103
112
  /**
@@ -126,6 +135,8 @@ export declare class BlockRenderer {
126
135
  * skip layout while off screen; use it only when loading a document.
127
136
  */
128
137
  render(doc: Doc, force?: boolean, lazy?: boolean): void;
138
+ /** Marks blocks again after `collapsed` changed, without rendering any. */
139
+ updateSections(doc: Doc): void;
129
140
  elementFor(id: string): HTMLElement | undefined;
130
141
  /**
131
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.12",
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",