@usememos/editor 26.10.1 → 26.10.3
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 +103 -29
- package/dist/base.css +18 -4
- package/dist/index.js +1848 -281
- package/dist/index.js.map +4 -4
- package/dist/react.js +24 -5
- package/dist/react.js.map +3 -3
- package/dist/style.css +65 -8
- package/dist/theme.css +10 -4
- package/dist/types/commands.d.ts +21 -0
- package/dist/types/editor.d.ts +170 -32
- package/dist/types/extension.d.ts +31 -10
- package/dist/types/extensions/footnotes.d.ts +5 -1
- package/dist/types/extensions/math.d.ts +3 -2
- package/dist/types/extensions/suggestion.d.ts +122 -30
- package/dist/types/extensions/tags.d.ts +13 -11
- package/dist/types/icons.d.ts +123 -0
- package/dist/types/index.d.ts +8 -4
- package/dist/types/labels.d.ts +8 -0
- package/dist/types/markdown/serialize.d.ts +4 -0
- package/dist/types/react/index.d.ts +17 -7
- package/dist/types/suggest/anchor.d.ts +21 -0
- package/dist/types/suggest/controller.d.ts +115 -0
- package/dist/types/suggest/match.d.ts +35 -0
- package/dist/types/suggest/source.d.ts +23 -0
- package/dist/types/ui/popup.d.ts +54 -6
- package/dist/types/view/dom.d.ts +52 -6
- package/dist/types/view/reveal.d.ts +6 -5
- package/dist/types/view/scroll.d.ts +6 -0
- package/package.json +6 -2
package/dist/types/view/dom.d.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
import { type Block, type Cell, type Doc, type Inline, type Position } from '../model.js';
|
|
1
|
+
import { type Block, type Cell, 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 { ThemeClasses } from '../theme.js';
|
|
5
5
|
import { type Decoration } from '../decorations.js';
|
|
6
6
|
export declare const BLOCK_ATTR = "data-block-id";
|
|
7
|
-
/**
|
|
8
|
-
export declare function
|
|
7
|
+
/** The view name for code blocks of a language: `code:mermaid`. */
|
|
8
|
+
export declare function codeViewName(language: string): string;
|
|
9
|
+
/** What a URL in the document is used for. */
|
|
10
|
+
export type UrlKind = 'link' | 'image';
|
|
11
|
+
/** Maps a link or image URL from the document to the URL to use, or null to drop it. The saved Markdown keeps the original. */
|
|
12
|
+
export type ResolveUrl = (url: string, kind: UrlKind) => string | null;
|
|
13
|
+
/**
|
|
14
|
+
* The default URL policy: relative URLs and fragments, and the schemes
|
|
15
|
+
* `http`, `https`, `mailto` and `tel`. Other URLs (`javascript:`, `data:`)
|
|
16
|
+
* are kept in the model but not used. Apps that allow more can call this
|
|
17
|
+
* for everything else.
|
|
18
|
+
*/
|
|
19
|
+
export declare const defaultResolveUrl: ResolveUrl;
|
|
9
20
|
/** What rendering needs besides the block. */
|
|
10
21
|
export interface RenderContext {
|
|
11
22
|
readonly doc: Document;
|
|
12
23
|
readonly labels: Labels;
|
|
13
|
-
readonly
|
|
24
|
+
readonly resolveUrl: ResolveUrl;
|
|
25
|
+
/** `referrerpolicy` for images. */
|
|
26
|
+
readonly referrerPolicy?: ReferrerPolicy;
|
|
14
27
|
/** Decorations for a text container. */
|
|
15
28
|
readonly decorate?: (block: Block, content: Inline, cell?: Cell) => readonly Decoration[];
|
|
29
|
+
/** Decorations for a code block's code, such as syntax highlighting. */
|
|
30
|
+
readonly decorateCode?: (block: CodeBlock) => readonly Decoration[];
|
|
16
31
|
/** Syntaxes that have a view. */
|
|
17
32
|
readonly views?: ReadonlyMap<string, SyntaxView>;
|
|
18
33
|
/** A token or raw block of an extension syntax, rendered; null shows its source. */
|
|
@@ -28,6 +43,16 @@ export type BlockReveal = ReadonlySet<string>;
|
|
|
28
43
|
export declare const REVEAL_BLOCK = "block";
|
|
29
44
|
export declare function tokenKey(cell: Cell | undefined, from: number): string;
|
|
30
45
|
export declare function sameReveal(a: BlockReveal | undefined, b: BlockReveal | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Runs of inline raw HTML that render as one piece: an opening tag through
|
|
48
|
+
* its closing tag, with the text between (`<kbd>Ctrl</kbd>`), or a single tag
|
|
49
|
+
* (`<br>`, an unmatched tag, a comment). Runs that would cross a link are
|
|
50
|
+
* left out. Offsets are into the container's text.
|
|
51
|
+
*/
|
|
52
|
+
export declare function htmlRuns(inline: Inline): {
|
|
53
|
+
from: number;
|
|
54
|
+
to: number;
|
|
55
|
+
}[];
|
|
31
56
|
/**
|
|
32
57
|
* Keyed reconciliation. Blocks are immutable, so a block whose object is the
|
|
33
58
|
* same as last render keeps its DOM element untouched.
|
|
@@ -38,10 +63,20 @@ export declare class BlockRenderer {
|
|
|
38
63
|
private rendered;
|
|
39
64
|
/** Last number written into each ordered item's marker, keyed by element. */
|
|
40
65
|
private readonly numbers;
|
|
41
|
-
/**
|
|
42
|
-
|
|
66
|
+
/** The URL policy for links and images. Set before a full render. */
|
|
67
|
+
resolveUrl: ResolveUrl;
|
|
68
|
+
/** `referrerpolicy` for images. */
|
|
69
|
+
referrerPolicy?: ReferrerPolicy;
|
|
43
70
|
/** Decorations for a text container. */
|
|
44
71
|
decorate?: RenderContext['decorate'];
|
|
72
|
+
/** Decorations for a code block's code. */
|
|
73
|
+
decorateCode?: RenderContext['decorateCode'];
|
|
74
|
+
/**
|
|
75
|
+
* Called when views that returned a promise settle, with the blocks that
|
|
76
|
+
* showed them. Those blocks must render again to show the finished view,
|
|
77
|
+
* or their source if it failed.
|
|
78
|
+
*/
|
|
79
|
+
onViewSettled?: (blockIds: readonly string[]) => void;
|
|
45
80
|
/** Widget elements to place after a block. */
|
|
46
81
|
widgetsAfter?: (blockId: string) => readonly HTMLElement[] | undefined;
|
|
47
82
|
/** Views of extension syntaxes, by syntax name. */
|
|
@@ -55,9 +90,20 @@ export declare class BlockRenderer {
|
|
|
55
90
|
* Cloned on reuse: typing re-renders a block and every formula in it.
|
|
56
91
|
*/
|
|
57
92
|
private readonly viewCache;
|
|
93
|
+
/** Views whose promise has not settled, by cache key, with the blocks showing them. */
|
|
94
|
+
private readonly pendingViews;
|
|
95
|
+
/** Views whose promise rejected or resolved to false: their source shows. */
|
|
96
|
+
private readonly failedViews;
|
|
97
|
+
/** The block being rendered, so a pending view knows which blocks to render again. */
|
|
98
|
+
private renderingBlock;
|
|
58
99
|
constructor(root: HTMLElement, labels: Labels);
|
|
59
100
|
private context;
|
|
60
101
|
private renderView;
|
|
102
|
+
/**
|
|
103
|
+
* A view that renders later (a diagram, a lazily loaded renderer) shows what
|
|
104
|
+
* it filled in at once, and its blocks render again when it settles.
|
|
105
|
+
*/
|
|
106
|
+
private awaitView;
|
|
61
107
|
/**
|
|
62
108
|
* `force` re-renders every block. `lazy` (with a full render) lets blocks
|
|
63
109
|
* skip layout while off screen; use it only when loading a document.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { SyntaxView } from '../extension.js';
|
|
2
|
-
import { type EditorState, type Position, type RawBlock } from '../model.js';
|
|
2
|
+
import { type CodeBlock, type EditorState, type Position, type RawBlock } from '../model.js';
|
|
3
3
|
import { type BlockReveal } from './dom.js';
|
|
4
4
|
/** Per block, the views that show their source. Empty when `active` is false (read-only or unfocused). */
|
|
5
5
|
export declare function revealedViews(state: EditorState, views: ReadonlyMap<string, SyntaxView>, active: boolean): Map<string, BlockReveal>;
|
|
6
6
|
export declare function sameRevealed(a: ReadonlyMap<string, BlockReveal>, b: ReadonlyMap<string, BlockReveal>): boolean;
|
|
7
7
|
/**
|
|
8
|
-
* Where the caret goes in a rendered
|
|
9
|
-
* line going forward (such as a `$$` fence), at the end of its
|
|
10
|
-
* line going back or on a click.
|
|
8
|
+
* Where the caret goes in a rendered block's source. A raw block: past its
|
|
9
|
+
* opening line going forward (such as a `$$` fence), at the end of its
|
|
10
|
+
* next-to-last line going back or on a click. A code block holds only the
|
|
11
|
+
* code: its start or its end.
|
|
11
12
|
*/
|
|
12
|
-
export declare function viewEntry(block: RawBlock, forward: boolean): Position;
|
|
13
|
+
export declare function viewEntry(block: RawBlock | CodeBlock, forward: boolean): Position;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scrolls `from` and each of its ancestors that scroll, then the window, by the least
|
|
3
|
+
* amount that shows `rect`. Like `scrollIntoView({ block: 'nearest' })`, but
|
|
4
|
+
* for a rectangle, so a caret inside a tall block is shown, not the block's top.
|
|
5
|
+
*/
|
|
6
|
+
export declare function scrollRectIntoView(from: Element, rect: DOMRect): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usememos/editor",
|
|
3
|
-
"version": "26.10.
|
|
3
|
+
"version": "26.10.3",
|
|
4
4
|
"description": "A block editor for standard Markdown. Zero runtime dependencies, with an optional React component.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -50,11 +50,15 @@
|
|
|
50
50
|
"prepack": "npm run build"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"react": ">=18"
|
|
53
|
+
"react": ">=18",
|
|
54
|
+
"react-dom": ">=18"
|
|
54
55
|
},
|
|
55
56
|
"peerDependenciesMeta": {
|
|
56
57
|
"react": {
|
|
57
58
|
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"react-dom": {
|
|
61
|
+
"optional": true
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
}
|