@usememos/editor 26.10.18 → 26.10.19
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 +25 -6
- package/dist/base.css +4 -0
- package/dist/index.js +207 -30
- package/dist/index.js.map +3 -3
- package/dist/style.css +9 -0
- package/dist/theme.css +2 -0
- package/dist/types/commands.d.ts +9 -0
- package/dist/types/editor.d.ts +25 -2
- package/dist/types/extension.d.ts +35 -3
- package/dist/types/extensions/tags.d.ts +15 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/theme.d.ts +2 -0
- package/dist/types/view/dom.d.ts +37 -1
- package/dist/types/view/reveal.d.ts +10 -5
- package/package.json +1 -1
package/dist/style.css
CHANGED
|
@@ -317,6 +317,12 @@
|
|
|
317
317
|
:is(.mbe-root, .mbe-flow) > .mbe-view-block > * {
|
|
318
318
|
margin-block: 0;
|
|
319
319
|
}
|
|
320
|
+
.mbe-root > .mbe-block-view {
|
|
321
|
+
overflow: visible;
|
|
322
|
+
}
|
|
323
|
+
.mbe-root.mbe-readonly :is([data-mbe-tag], [data-mbe-mention]) {
|
|
324
|
+
cursor: pointer;
|
|
325
|
+
}
|
|
320
326
|
.mbe-root .mbe-view-block.mbe-view-html {
|
|
321
327
|
white-space: normal;
|
|
322
328
|
}
|
|
@@ -817,6 +823,9 @@
|
|
|
817
823
|
.mbe-root.mbe-readonly .mbe-footnote-ref {
|
|
818
824
|
cursor: pointer;
|
|
819
825
|
}
|
|
826
|
+
.mbe-root.mbe-readonly [data-mbe-mention]:hover {
|
|
827
|
+
text-decoration: underline;
|
|
828
|
+
}
|
|
820
829
|
:is(.mbe-root, .mbe-flow) > .mbe-footnote {
|
|
821
830
|
font-size: 0.875em;
|
|
822
831
|
color: var(--mbe-muted);
|
package/dist/theme.css
CHANGED
|
@@ -110,6 +110,8 @@
|
|
|
110
110
|
/* Footnotes, rendered: a reference is a small raised label, a definition a small muted note. */
|
|
111
111
|
.mbe-root .mbe-footnote-ref { font-size: 0.75em; line-height: 0; color: var(--mbe-link); }
|
|
112
112
|
.mbe-root.mbe-readonly .mbe-footnote-ref { cursor: pointer; }
|
|
113
|
+
/* A mention with an onClick (tags.ts), read-only: underlined on hover, as a name that leads somewhere. */
|
|
114
|
+
.mbe-root.mbe-readonly [data-mbe-mention]:hover { text-decoration: underline; }
|
|
113
115
|
:is(.mbe-root, .mbe-flow) > .mbe-footnote { font-size: 0.875em; color: var(--mbe-muted); }
|
|
114
116
|
.mbe-root .mbe-footnote-label { margin-inline-end: 0.375em; color: var(--mbe-link); }
|
|
115
117
|
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -15,6 +15,15 @@ export declare function deleteBackward(state: EditorState): EditorState;
|
|
|
15
15
|
export declare function deleteForward(state: EditorState): EditorState;
|
|
16
16
|
/** Inserts text at the selection with the current format. "\n" is a hard line break. */
|
|
17
17
|
export declare function insertText(state: EditorState, text: string): EditorState;
|
|
18
|
+
/**
|
|
19
|
+
* Inserts a token such as `#tag` at the selection's focus, spaced as a word
|
|
20
|
+
* among words: a space before it unless the caret is at the start of the
|
|
21
|
+
* text or after whitespace, and a space after it unless one follows, which
|
|
22
|
+
* the caret moves past; either way the caret ends after that space. Selected
|
|
23
|
+
* text is kept, and the token takes the format at the caret as typed text
|
|
24
|
+
* would: plain in a code or raw block.
|
|
25
|
+
*/
|
|
26
|
+
export declare function insertToken(state: EditorState, token: string): EditorState;
|
|
18
27
|
/**
|
|
19
28
|
* ArrowDown on the last line of the last block, or ArrowUp on the first line
|
|
20
29
|
* of the first block, when that block is a code block, table or divider, or
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -221,6 +221,15 @@ export interface EditorCommands {
|
|
|
221
221
|
to: Position;
|
|
222
222
|
};
|
|
223
223
|
}): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Inserts a token such as `#tag` at the caret as a word of its own: with a
|
|
226
|
+
* space before it unless the caret is at the start of the text or after
|
|
227
|
+
* whitespace, and a space after it, reusing one that is already there; the
|
|
228
|
+
* caret ends after that space. Selected text is kept. The token is plain
|
|
229
|
+
* text in a code block or source mode, as typed text is. Does nothing, and
|
|
230
|
+
* returns false, while an input method is composing.
|
|
231
|
+
*/
|
|
232
|
+
insertToken(text: string): boolean;
|
|
224
233
|
insertMarkdown(markdown: string, options?: InsertMarkdownOptions): boolean;
|
|
225
234
|
insertTable(attrs?: {
|
|
226
235
|
rows?: number;
|
|
@@ -415,7 +424,7 @@ export declare class Editor {
|
|
|
415
424
|
on<K extends keyof EditorEvents>(type: K, handler: (payload: EditorEvents[K]) => void): () => void;
|
|
416
425
|
private emit;
|
|
417
426
|
private applyRuntime;
|
|
418
|
-
/** Sets the theme. Returns true when
|
|
427
|
+
/** Sets the theme. Returns true when every block must re-render, for new classes. */
|
|
419
428
|
private applyTheme;
|
|
420
429
|
/** Applies a command (a pure function of the state), records history, re-renders, and emits events. */
|
|
421
430
|
run(command: (state: EditorState) => EditorState | null, kind?: ChangeKind): boolean;
|
|
@@ -483,15 +492,29 @@ export declare class Editor {
|
|
|
483
492
|
* loading. Waits for an input method to finish composing.
|
|
484
493
|
*/
|
|
485
494
|
redecorate(): void;
|
|
495
|
+
/**
|
|
496
|
+
* Renders every view (`Extension.views`) again, or those of one syntax
|
|
497
|
+
* (`'math'`, `'code:mermaid'`), for when what a view shows depends on
|
|
498
|
+
* something besides its source that changed: a renderer that finished
|
|
499
|
+
* loading, or the font a diagram measured its text with. A view that
|
|
500
|
+
* failed is tried again. Only the blocks that show those views render
|
|
501
|
+
* again. The editor calls it itself when the theme's font tokens change.
|
|
502
|
+
* Waits for an input method to finish composing.
|
|
503
|
+
*/
|
|
504
|
+
refreshViews(syntax?: string): void;
|
|
505
|
+
/** Renders the given blocks again now, or when the composition in progress settles. */
|
|
506
|
+
private renderBlocksAgain;
|
|
486
507
|
/**
|
|
487
508
|
* Views that returned a promise settled: their blocks render again on the
|
|
488
509
|
* next frame, or when a composition settles, since rendering would end it.
|
|
489
510
|
*/
|
|
490
511
|
private viewsSettled;
|
|
491
|
-
/** A block rendered by a view (a formula block, a diagram), or null. */
|
|
512
|
+
/** A block rendered by a view (a formula block, a diagram, a block an extension's block view draws), or null. */
|
|
492
513
|
private viewBlock;
|
|
493
514
|
/** Re-renders if the views that show their source changed: after the selection, focus or editability changes. */
|
|
494
515
|
private refreshRevealed;
|
|
516
|
+
/** Whether an extension's block view draws `block` (see `BlockView`). */
|
|
517
|
+
private readonly hosted;
|
|
495
518
|
private onMouseUp;
|
|
496
519
|
/**
|
|
497
520
|
* When an arrow key at the edge of a block would move past a rendered raw
|
|
@@ -2,7 +2,7 @@ import type { Decoration, Decorator } from './decorations.js';
|
|
|
2
2
|
import type { Editor } from './editor.js';
|
|
3
3
|
import type { SuggestionConfig } from './extensions/suggestion.js';
|
|
4
4
|
import type { MarkdownSyntax } from './markdown/options.js';
|
|
5
|
-
import type { CodeBlock, Position } from './model.js';
|
|
5
|
+
import type { Block, CodeBlock, Position } from './model.js';
|
|
6
6
|
import type { ThemeClasses } from './theme.js';
|
|
7
7
|
export interface ExtensionContext {
|
|
8
8
|
readonly editor: Editor;
|
|
@@ -16,14 +16,40 @@ export type KeyHandler = (ctx: ExtensionContext) => boolean;
|
|
|
16
16
|
* Renders the Markdown source of a token (`kind` is `inline`, `element` a
|
|
17
17
|
* span), a raw block, or the code of a code block (`block`, a div) into
|
|
18
18
|
* `element`. Returns false, or throws, to show the source instead. Results
|
|
19
|
-
* are cached by source, so the output must depend on nothing else
|
|
19
|
+
* are cached by source, so the output must depend on nothing else; what a
|
|
20
|
+
* view reads from the editor instead (its font, for a layout that measures
|
|
21
|
+
* text) is current again after `editor.refreshViews()`, which the editor
|
|
22
|
+
* calls itself when the theme's font tokens change.
|
|
23
|
+
*
|
|
24
|
+
* `element` is not in the page yet, so it has no layout. A view that
|
|
25
|
+
* measures text uses the editor: `getComputedStyle(ctx.editor.root)` gives
|
|
26
|
+
* the font the view's text will have, for a canvas `measureText`.
|
|
20
27
|
*
|
|
21
28
|
* A view that finishes later (a diagram, a renderer that loads on demand)
|
|
22
29
|
* fills in what it can at once and returns a promise: the editor shows that
|
|
23
30
|
* meanwhile, and the finished element when the promise resolves. A promise
|
|
24
31
|
* that rejects or resolves to false shows the source.
|
|
25
32
|
*/
|
|
26
|
-
export type SyntaxView = (source: string, element: HTMLElement, kind: 'inline' | 'block') => void | false | PromiseLike<void | false>;
|
|
33
|
+
export type SyntaxView = (source: string, element: HTMLElement, kind: 'inline' | 'block', ctx: ExtensionContext) => void | false | PromiseLike<void | false>;
|
|
34
|
+
/**
|
|
35
|
+
* Draws whole blocks the app wants to show its own way, such as a paragraph
|
|
36
|
+
* that is one bare link shown as a preview card with data from a server.
|
|
37
|
+
* `match` picks the blocks; `render` draws one into `element`, a div the
|
|
38
|
+
* editor owns and keeps while the block is unchanged: typing elsewhere, a
|
|
39
|
+
* new selection or `redecorate()` never call `render` again, so app UI
|
|
40
|
+
* mounted into the element (a React portal) stays. The editor calls `render`
|
|
41
|
+
* again for a block whose content changed, and for a new block. It calls the
|
|
42
|
+
* function `render` returned when it lets the element go: the block was
|
|
43
|
+
* removed or changed, `editor.refreshViews()` ran, or the editor was
|
|
44
|
+
* destroyed. `render` returns false to leave the block as the editor draws
|
|
45
|
+
* it. While editing, the block shows as the editor draws it, editable, when
|
|
46
|
+
* the selection is in it, as a rendered formula shows its source; read-only
|
|
47
|
+
* always shows the view.
|
|
48
|
+
*/
|
|
49
|
+
export interface BlockView {
|
|
50
|
+
readonly match: (block: Block) => boolean;
|
|
51
|
+
readonly render: (block: Block, element: HTMLElement, ctx: ExtensionContext) => void | false | (() => void);
|
|
52
|
+
}
|
|
27
53
|
/** A code block's code, for decorations such as syntax highlighting. */
|
|
28
54
|
export interface CodeDecorationContext {
|
|
29
55
|
readonly block: CodeBlock;
|
|
@@ -78,6 +104,12 @@ export interface Extension {
|
|
|
78
104
|
* same. Read-only always shows the rendered view.
|
|
79
105
|
*/
|
|
80
106
|
readonly views?: Readonly<Record<string, SyntaxView>>;
|
|
107
|
+
/**
|
|
108
|
+
* Draws the blocks `match` picks with `render`, in place of the editor's
|
|
109
|
+
* own rendering; see `BlockView`. `editor.refreshViews(name)`, with this
|
|
110
|
+
* extension's name, draws them again.
|
|
111
|
+
*/
|
|
112
|
+
readonly blockView?: BlockView;
|
|
81
113
|
/**
|
|
82
114
|
* Theme classes for the elements this extension cares about, such as
|
|
83
115
|
* `token.math`. The editor's `theme` wins for the same key, and an earlier
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TextRange } from '../decorations.js';
|
|
2
|
+
import type { Editor } from '../editor.js';
|
|
2
3
|
import type { Extension } from '../extension.js';
|
|
3
4
|
/** Finds tags or mentions in `text[from, to)`. `text` is the whole container, so a scanner can look before `from`. */
|
|
4
5
|
export type TagScanner = (text: string, from: number, to: number) => Iterable<TextRange>;
|
|
@@ -13,6 +14,20 @@ export interface TagsOptions {
|
|
|
13
14
|
readonly attributes?: Readonly<Record<string, string>> | ((match: string) => Readonly<Record<string, string>> | undefined);
|
|
14
15
|
/** Finds matches in a run of text. Default `scanTags` or `scanMentions`. */
|
|
15
16
|
readonly scan?: TagScanner;
|
|
17
|
+
/**
|
|
18
|
+
* Called when a match is clicked to be followed, as `onLinkClick` is for a
|
|
19
|
+
* link: a plain click while read-only, Mod+click while editing. `match` is
|
|
20
|
+
* the text as written (`#work/planning`). Return true to handle it: the
|
|
21
|
+
* click then goes no further, neither to the browser nor to the page's
|
|
22
|
+
* own listeners. With this option, read-only matches show a pointer
|
|
23
|
+
* cursor, and mentions underline on hover; the editor marks each match with
|
|
24
|
+
* `data-mbe-tag` or `data-mbe-mention`.
|
|
25
|
+
*/
|
|
26
|
+
readonly onClick?: (ctx: {
|
|
27
|
+
readonly editor: Editor;
|
|
28
|
+
readonly match: string;
|
|
29
|
+
readonly event: MouseEvent;
|
|
30
|
+
}) => boolean | void;
|
|
16
31
|
}
|
|
17
32
|
/**
|
|
18
33
|
* The default tag grammar, memos': `#` and one or more segments separated
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type { EditorMode } from './sourceMode.js';
|
|
|
12
12
|
export type { MarkdownOptions } from './markdown/options.js';
|
|
13
13
|
export { docToHtml } from './clipboard/toHtml.js';
|
|
14
14
|
export { htmlToDoc } from './clipboard/fromHtml.js';
|
|
15
|
-
export type { CodeDecorationContext, Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
|
|
15
|
+
export type { BlockView, CodeDecorationContext, Extension, ExtensionContext, KeyHandler, SyntaxView } from './extension.js';
|
|
16
16
|
export type { ColorScheme, Theme, ThemeClasses, ThemeColors, ThemeTokens } from './theme.js';
|
|
17
17
|
export { defaultKeymap } from './extensions/keymap.js';
|
|
18
18
|
export { math, type MathOptions } from './extensions/math.js';
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -88,6 +88,8 @@ export interface Theme {
|
|
|
88
88
|
}
|
|
89
89
|
/** Merges class maps; a later map wins for the same key, and `heading` and `token` merge per entry. */
|
|
90
90
|
export declare function mergeClasses(maps: readonly (ThemeClasses | undefined)[]): ThemeClasses;
|
|
91
|
+
/** The token properties that change how text measures: a view that laid out text (a diagram) renders again when one changes. */
|
|
92
|
+
export declare const FONT_PROPERTIES: readonly string[];
|
|
91
93
|
/**
|
|
92
94
|
* The custom properties for `tokens`. Colors go in `--mbe-<name>-light` and
|
|
93
95
|
* `--mbe-<name>-dark`, which the stylesheet picks between with `light-dark()`.
|
package/dist/types/view/dom.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Block, type Cell, type CalloutType, type CodeBlock, type Doc, type Inline, type Position } from '../model.js';
|
|
2
|
-
import type { SyntaxView } from '../extension.js';
|
|
2
|
+
import type { BlockView, ExtensionContext, 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';
|
|
@@ -34,6 +34,8 @@ export interface RenderContext {
|
|
|
34
34
|
readonly views?: ReadonlyMap<string, SyntaxView>;
|
|
35
35
|
/** A token or raw block of an extension syntax, rendered; null shows its source. */
|
|
36
36
|
readonly view?: (syntax: string, source: string, kind: 'inline' | 'block') => HTMLElement | null;
|
|
37
|
+
/** The element an extension's block view draws a block of the document into, or null for none (see `BlockView`). */
|
|
38
|
+
readonly blockView?: (block: Block) => HTMLElement | null;
|
|
37
39
|
/** The document's Markdown options, for the Markdown inside an HTML section. */
|
|
38
40
|
readonly markdown?: MarkdownOptions;
|
|
39
41
|
/** Theme classes for rendered elements. */
|
|
@@ -103,6 +105,19 @@ export declare class BlockRenderer {
|
|
|
103
105
|
widgetsAfter?: (blockId: string) => readonly HTMLElement[] | undefined;
|
|
104
106
|
/** Views of extension syntaxes, by syntax name. */
|
|
105
107
|
views?: ReadonlyMap<string, SyntaxView>;
|
|
108
|
+
/** What a view gets besides its source: the editor. Set with `views`. */
|
|
109
|
+
viewContext?: ExtensionContext;
|
|
110
|
+
/** Block views of extensions, with the extension's name, in extension order. */
|
|
111
|
+
blockViews: readonly {
|
|
112
|
+
readonly name: string;
|
|
113
|
+
readonly view: BlockView;
|
|
114
|
+
}[];
|
|
115
|
+
/**
|
|
116
|
+
* Per block drawn by a block view, the element the view drew into (null
|
|
117
|
+
* when every matching view declined), kept while the block object is the
|
|
118
|
+
* same, and the function to call when the element is let go.
|
|
119
|
+
*/
|
|
120
|
+
private readonly hosted;
|
|
106
121
|
/** The document's Markdown options, for the Markdown inside an HTML section. */
|
|
107
122
|
markdown?: MarkdownOptions;
|
|
108
123
|
/** Theme classes for rendered elements. Set before a full render. */
|
|
@@ -128,6 +143,8 @@ export declare class BlockRenderer {
|
|
|
128
143
|
private readonly pendingViews;
|
|
129
144
|
/** Views whose promise rejected or resolved to false: their source shows. */
|
|
130
145
|
private readonly failedViews;
|
|
146
|
+
/** Per cached or failed view, the blocks that showed it, to render again when `dropViews` forgets it. */
|
|
147
|
+
private readonly viewBlocks;
|
|
131
148
|
/** The block being rendered, so a pending view knows which blocks to render again. */
|
|
132
149
|
private renderingBlock;
|
|
133
150
|
/** During a render, the loaded images of the block elements it replaces, by `src`. */
|
|
@@ -135,11 +152,30 @@ export declare class BlockRenderer {
|
|
|
135
152
|
constructor(root: HTMLElement, labels: Labels);
|
|
136
153
|
private context;
|
|
137
154
|
private renderView;
|
|
155
|
+
/** Whether a block view draws `block`: its blocks show their editable form only while the selection is in them. */
|
|
156
|
+
isHosted(block: Block): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* The element a block view drew `block` into: the one from the last render
|
|
159
|
+
* while the block object is the same, else a fresh one from the first
|
|
160
|
+
* matching view that does not decline. Null when none draws it.
|
|
161
|
+
*/
|
|
162
|
+
private renderBlockView;
|
|
163
|
+
private disposeHosted;
|
|
164
|
+
/** Lets every block view's element go: on destroy. */
|
|
165
|
+
destroy(): void;
|
|
166
|
+
private noteViewBlock;
|
|
138
167
|
/**
|
|
139
168
|
* A view that renders later (a diagram, a lazily loaded renderer) shows what
|
|
140
169
|
* it filled in at once, and its blocks render again when it settles.
|
|
141
170
|
*/
|
|
142
171
|
private awaitView;
|
|
172
|
+
/**
|
|
173
|
+
* Forgets rendered and failed views, of one syntax or all, so the next
|
|
174
|
+
* render runs the view again: for when what it shows depends on something
|
|
175
|
+
* besides its source that changed, such as the editor's font. Returns the
|
|
176
|
+
* rendered blocks that showed them, for the caller to render again.
|
|
177
|
+
*/
|
|
178
|
+
dropViews(syntax?: string): string[];
|
|
143
179
|
/**
|
|
144
180
|
* `force` re-renders every block. `lazy` (with a full render) lets blocks
|
|
145
181
|
* skip layout while off screen; use it only when loading a document.
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { SyntaxView } from '../extension.js';
|
|
2
|
-
import { type
|
|
2
|
+
import { type Block, type EditorState, type Position } from '../model.js';
|
|
3
3
|
import { type BlockReveal } from './dom.js';
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Per block, the views that show their source. Empty when `active` is false
|
|
6
|
+
* (read-only or unfocused). `hosted` says whether an extension's block view
|
|
7
|
+
* draws a block, which then shows its editable form instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function revealedViews(state: EditorState, views: ReadonlyMap<string, SyntaxView>, active: boolean, hosted?: (block: Block) => boolean): Map<string, BlockReveal>;
|
|
6
10
|
export declare function sameRevealed(a: ReadonlyMap<string, BlockReveal>, b: ReadonlyMap<string, BlockReveal>): boolean;
|
|
7
11
|
/**
|
|
8
12
|
* Where the caret goes in a rendered block's source. A raw block: past its
|
|
9
13
|
* opening line going forward (such as a `$$` fence), at the end of its
|
|
10
14
|
* next-to-last line going back or on a click. A code block holds only the
|
|
11
|
-
* code, and raw Markdown has no fence: their start or their end.
|
|
15
|
+
* code, and raw Markdown has no fence: their start or their end. So does any
|
|
16
|
+
* other block drawn by a block view; a table, its first or last cell.
|
|
12
17
|
*/
|
|
13
|
-
export declare function viewEntry(block:
|
|
18
|
+
export declare function viewEntry(block: Block, forward: boolean): Position;
|