@usememos/editor 26.10.7 → 26.10.9
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 +11 -4
- package/dist/base.css +43 -0
- package/dist/index.js +426 -22
- package/dist/index.js.map +4 -4
- package/dist/style.css +85 -0
- package/dist/theme.css +16 -0
- package/dist/types/commands.d.ts +16 -1
- package/dist/types/editor.d.ts +17 -2
- package/dist/types/icons.d.ts +7 -0
- package/dist/types/labels.d.ts +4 -0
- package/dist/types/markdown/ast.d.ts +13 -0
- package/dist/types/markdown/inline.d.ts +1 -1
- package/dist/types/model.d.ts +7 -0
- package/dist/types/ui/image.d.ts +33 -0
- package/dist/types/view/dom.d.ts +6 -0
- package/package.json +1 -1
package/dist/style.css
CHANGED
|
@@ -111,6 +111,31 @@
|
|
|
111
111
|
margin: 8px 0;
|
|
112
112
|
vertical-align: bottom;
|
|
113
113
|
}
|
|
114
|
+
.mbe-root .mbe-image-unavailable {
|
|
115
|
+
display: inline-flex;
|
|
116
|
+
align-items: center;
|
|
117
|
+
gap: 6px;
|
|
118
|
+
box-sizing: border-box;
|
|
119
|
+
padding: 4px 8px;
|
|
120
|
+
border: 1px dashed GrayText;
|
|
121
|
+
}
|
|
122
|
+
.mbe-root .mbe-image-alt {
|
|
123
|
+
min-width: 0;
|
|
124
|
+
overflow: hidden;
|
|
125
|
+
text-overflow: ellipsis;
|
|
126
|
+
white-space: nowrap;
|
|
127
|
+
}
|
|
128
|
+
.mbe-root .mbe-image-selected {
|
|
129
|
+
outline: 2px solid Highlight;
|
|
130
|
+
outline-offset: -2px;
|
|
131
|
+
}
|
|
132
|
+
.mbe-root.mbe-image-selection,
|
|
133
|
+
.mbe-root.mbe-image-selection * {
|
|
134
|
+
caret-color: transparent;
|
|
135
|
+
}
|
|
136
|
+
.mbe-root.mbe-image-selection ::selection {
|
|
137
|
+
background: transparent;
|
|
138
|
+
}
|
|
114
139
|
.mbe-root .mbe-code-bar {
|
|
115
140
|
display: flex;
|
|
116
141
|
align-items: center;
|
|
@@ -332,6 +357,47 @@
|
|
|
332
357
|
gap: 4px;
|
|
333
358
|
padding: 4px;
|
|
334
359
|
}
|
|
360
|
+
.mbe-image-frame {
|
|
361
|
+
position: fixed;
|
|
362
|
+
pointer-events: none;
|
|
363
|
+
}
|
|
364
|
+
.mbe-image-handle {
|
|
365
|
+
position: absolute;
|
|
366
|
+
top: 50%;
|
|
367
|
+
width: 6px;
|
|
368
|
+
height: 40%;
|
|
369
|
+
min-height: 16px;
|
|
370
|
+
max-height: 48px;
|
|
371
|
+
box-sizing: border-box;
|
|
372
|
+
transform: translate(-50%, -50%);
|
|
373
|
+
pointer-events: auto;
|
|
374
|
+
touch-action: none;
|
|
375
|
+
cursor: ew-resize;
|
|
376
|
+
background: Canvas;
|
|
377
|
+
border: 1px solid CanvasText;
|
|
378
|
+
border-radius: 3px;
|
|
379
|
+
}
|
|
380
|
+
.mbe-image-handle::before {
|
|
381
|
+
content: "";
|
|
382
|
+
position: absolute;
|
|
383
|
+
inset: -6px -8px;
|
|
384
|
+
}
|
|
385
|
+
.mbe-image-handle-left {
|
|
386
|
+
left: 8px;
|
|
387
|
+
}
|
|
388
|
+
.mbe-image-handle-right {
|
|
389
|
+
left: calc(100% - 8px);
|
|
390
|
+
}
|
|
391
|
+
.mbe-image-frame-small .mbe-image-handle-left {
|
|
392
|
+
left: 0;
|
|
393
|
+
}
|
|
394
|
+
.mbe-image-frame-small .mbe-image-handle-right {
|
|
395
|
+
left: 100%;
|
|
396
|
+
}
|
|
397
|
+
.mbe-image-resizing,
|
|
398
|
+
.mbe-image-resizing .mbe-image-handle {
|
|
399
|
+
cursor: ew-resize;
|
|
400
|
+
}
|
|
335
401
|
.mbe-link-input {
|
|
336
402
|
font: inherit;
|
|
337
403
|
color: inherit;
|
|
@@ -469,6 +535,16 @@
|
|
|
469
535
|
.mbe-root .mbe-image {
|
|
470
536
|
border-radius: 8px;
|
|
471
537
|
}
|
|
538
|
+
.mbe-root .mbe-image-selected {
|
|
539
|
+
outline-color: var(--mbe-accent);
|
|
540
|
+
}
|
|
541
|
+
.mbe-root .mbe-image-unavailable {
|
|
542
|
+
border-color: var(--mbe-border);
|
|
543
|
+
background: var(--mbe-block-code-bg);
|
|
544
|
+
color: var(--mbe-muted);
|
|
545
|
+
font-size: 0.875em;
|
|
546
|
+
line-height: 20px;
|
|
547
|
+
}
|
|
472
548
|
.mbe-root .mbe-footnote-ref {
|
|
473
549
|
font-size: 0.75em;
|
|
474
550
|
line-height: 0;
|
|
@@ -674,6 +750,15 @@
|
|
|
674
750
|
.mbe-link-input:focus {
|
|
675
751
|
border-color: var(--mbe-accent);
|
|
676
752
|
}
|
|
753
|
+
.mbe-image-handle {
|
|
754
|
+
background: rgb(0 0 0 / 0.6);
|
|
755
|
+
border-color: rgb(255 255 255 / 0.85);
|
|
756
|
+
box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
|
|
757
|
+
}
|
|
758
|
+
.mbe-image-handle:hover,
|
|
759
|
+
.mbe-image-resizing .mbe-image-handle {
|
|
760
|
+
background: var(--mbe-accent);
|
|
761
|
+
}
|
|
677
762
|
.mbe-handle {
|
|
678
763
|
border-radius: 4px;
|
|
679
764
|
color: var(--mbe-muted);
|
package/dist/theme.css
CHANGED
|
@@ -93,6 +93,14 @@
|
|
|
93
93
|
.mbe-root :is(.mbe-raw-html, .mbe-token) { color: var(--mbe-muted); }
|
|
94
94
|
.mbe-root code { background: var(--mbe-code-bg); border-radius: 4px; padding: 2px 4px; }
|
|
95
95
|
.mbe-root .mbe-image { border-radius: 8px; }
|
|
96
|
+
.mbe-root .mbe-image-selected { outline-color: var(--mbe-accent); }
|
|
97
|
+
.mbe-root .mbe-image-unavailable {
|
|
98
|
+
border-color: var(--mbe-border);
|
|
99
|
+
background: var(--mbe-block-code-bg);
|
|
100
|
+
color: var(--mbe-muted);
|
|
101
|
+
font-size: 0.875em;
|
|
102
|
+
line-height: 20px;
|
|
103
|
+
}
|
|
96
104
|
/* Footnotes, rendered: a reference is a small raised label, a definition a small muted note. */
|
|
97
105
|
.mbe-root .mbe-footnote-ref { font-size: 0.75em; line-height: 0; color: var(--mbe-link); }
|
|
98
106
|
.mbe-root.mbe-readonly .mbe-footnote-ref { cursor: pointer; }
|
|
@@ -216,6 +224,14 @@
|
|
|
216
224
|
}
|
|
217
225
|
.mbe-link-input:focus { border-color: var(--mbe-accent); }
|
|
218
226
|
|
|
227
|
+
.mbe-image-handle {
|
|
228
|
+
background: rgb(0 0 0 / 0.6);
|
|
229
|
+
border-color: rgb(255 255 255 / 0.85);
|
|
230
|
+
box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
|
|
231
|
+
}
|
|
232
|
+
.mbe-image-handle:hover,
|
|
233
|
+
.mbe-image-resizing .mbe-image-handle { background: var(--mbe-accent); }
|
|
234
|
+
|
|
219
235
|
.mbe-handle {
|
|
220
236
|
border-radius: 4px;
|
|
221
237
|
color: var(--mbe-muted);
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Block, type EditorState, type HeadingLevel, type ListType, type Mark, type Position, type Selection, type TableBlock, type Align } from './model.js';
|
|
1
|
+
import { type Block, type EditorState, type HeadingLevel, type ImageAtom, type ListType, type Mark, type Position, type Selection, type TableBlock, type Align } from './model.js';
|
|
2
2
|
import type { InlineSyntax } from './markdown/options.js';
|
|
3
3
|
export type Command = (state: EditorState) => EditorState;
|
|
4
4
|
/** A copy of a block with a new ID. */
|
|
@@ -42,6 +42,21 @@ export declare function activeLink(state: EditorState): {
|
|
|
42
42
|
* collapsed selection inside a link, changes the whole link.
|
|
43
43
|
*/
|
|
44
44
|
export declare function setLink(state: EditorState, href: string | null): EditorState;
|
|
45
|
+
/** The image the selection covers exactly, with the position before it. Null when the selection is anything else. */
|
|
46
|
+
export declare function selectedImage(state: EditorState): {
|
|
47
|
+
pos: Position;
|
|
48
|
+
image: ImageAtom;
|
|
49
|
+
} | null;
|
|
50
|
+
/** Selects the image after `pos` as one unit. */
|
|
51
|
+
export declare function selectImage(state: EditorState, pos: Position): EditorState;
|
|
52
|
+
/** What `updateImage` changes. `null` removes a title or a size; a new width drops the height, so the image keeps its aspect ratio. */
|
|
53
|
+
export interface ImageChange {
|
|
54
|
+
readonly alt?: string;
|
|
55
|
+
readonly title?: string | null;
|
|
56
|
+
readonly width?: number | null;
|
|
57
|
+
}
|
|
58
|
+
/** Changes the image after `pos` and selects it. */
|
|
59
|
+
export declare function updateImage(state: EditorState, pos: Position, change: ImageChange): EditorState;
|
|
45
60
|
export type BlockTypeSpec = {
|
|
46
61
|
type: 'paragraph';
|
|
47
62
|
} | {
|
package/dist/types/editor.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as cmd from './commands.js';
|
|
1
2
|
import { type ChangeKind } from './history.js';
|
|
2
3
|
import { type Labels } from './labels.js';
|
|
3
4
|
import { type Icons } from './icons.js';
|
|
@@ -127,7 +128,9 @@ export interface SuggestionApi {
|
|
|
127
128
|
accept(index?: number): boolean;
|
|
128
129
|
}
|
|
129
130
|
/** Names `isActive` and `getAttributes` understand. */
|
|
130
|
-
export type ActiveName = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'taskList' | 'blockquote' | 'codeBlock' | 'table' | 'divider' | 'raw'
|
|
131
|
+
export type ActiveName = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'paragraph' | 'heading' | 'bulletList' | 'orderedList' | 'taskList' | 'blockquote' | 'codeBlock' | 'table' | 'divider' | 'raw'
|
|
132
|
+
/** The selection is exactly one image. */
|
|
133
|
+
| 'image';
|
|
131
134
|
/** A position that survives reloading the same Markdown: a block index and an offset. */
|
|
132
135
|
export interface PositionJSON {
|
|
133
136
|
readonly block: number;
|
|
@@ -172,6 +175,11 @@ export interface EditorCommands {
|
|
|
172
175
|
href: string;
|
|
173
176
|
}): boolean;
|
|
174
177
|
unsetLink(): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Changes the selected image (see `isActive('image')`): its alt text, its
|
|
180
|
+
* title, or its width in CSS pixels. `null` removes the title or the width.
|
|
181
|
+
*/
|
|
182
|
+
updateImage(attrs: cmd.ImageChange): boolean;
|
|
175
183
|
/** Inserts plain text at the selection, or in place of `range` (for example a suggestion's range). */
|
|
176
184
|
insertText(text: string, options?: {
|
|
177
185
|
range?: {
|
|
@@ -261,6 +269,9 @@ export declare class Editor {
|
|
|
261
269
|
private readonly toolbar;
|
|
262
270
|
private readonly linkPopover;
|
|
263
271
|
private readonly handle;
|
|
272
|
+
private readonly imageControls;
|
|
273
|
+
/** The selected image's element, which carries the selected class. */
|
|
274
|
+
private selectedImageEl;
|
|
264
275
|
private hintEl;
|
|
265
276
|
/**
|
|
266
277
|
* The block selection, by block ID, or null for a text selection. While it
|
|
@@ -298,7 +309,7 @@ export declare class Editor {
|
|
|
298
309
|
get isDestroyed(): boolean;
|
|
299
310
|
/** True if `name` applies at the selection: a mark on the selected text, or the type of the block with the caret. */
|
|
300
311
|
isActive(name: ActiveName, attrs?: Readonly<Record<string, unknown>>): boolean;
|
|
301
|
-
/** Attributes of `name` at the selection: `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block. */
|
|
312
|
+
/** Attributes of `name` at the selection: `src`, `alt`, `title`, `width` and `height` 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. */
|
|
302
313
|
getAttributes(name: ActiveName): Record<string, unknown>;
|
|
303
314
|
getSelection(): Selection;
|
|
304
315
|
/**
|
|
@@ -544,6 +555,10 @@ export declare class Editor {
|
|
|
544
555
|
/** A press anywhere but the block menu or the block handle closes the menu, in the editor's text too. */
|
|
545
556
|
private onDocumentPointerDown;
|
|
546
557
|
private updateUi;
|
|
558
|
+
/** Marks the selected image's element, and hides the browser's selection highlight over it. */
|
|
559
|
+
private paintSelectedImage;
|
|
560
|
+
/** The selected image of `state` and its element, or null. */
|
|
561
|
+
private imageTargetAt;
|
|
547
562
|
private syncActiveDescendant;
|
|
548
563
|
private hideUi;
|
|
549
564
|
/** Wraps an input event handler so the changes it makes keep the caret in view. */
|
package/dist/types/icons.d.ts
CHANGED
|
@@ -117,6 +117,13 @@ declare const ICONS: {
|
|
|
117
117
|
inlineCode: string[];
|
|
118
118
|
/** `link` */
|
|
119
119
|
link: string[];
|
|
120
|
+
/** `image-off` */
|
|
121
|
+
imageUnavailable: (string | [string, {
|
|
122
|
+
x1: string;
|
|
123
|
+
x2: string;
|
|
124
|
+
y1: string;
|
|
125
|
+
y2: string;
|
|
126
|
+
}])[];
|
|
120
127
|
/** `grip-vertical` */
|
|
121
128
|
blockHandle: [string, {
|
|
122
129
|
cx: string;
|
package/dist/types/labels.d.ts
CHANGED
|
@@ -49,5 +49,9 @@ export declare const DEFAULT_LABELS: {
|
|
|
49
49
|
alignCenter: string;
|
|
50
50
|
alignRight: string;
|
|
51
51
|
tableSection: string;
|
|
52
|
+
/** Shown in place of an image that did not load and has no alt text. */
|
|
53
|
+
imageUnavailable: string;
|
|
54
|
+
/** Accessible name of the handles that resize an image. */
|
|
55
|
+
resizeImage: string;
|
|
52
56
|
};
|
|
53
57
|
export type Labels = typeof DEFAULT_LABELS;
|
|
@@ -46,7 +46,20 @@ export interface ImageNode {
|
|
|
46
46
|
readonly title: string;
|
|
47
47
|
/** The image description; its plain text is the alt text. */
|
|
48
48
|
readonly children: InlineNode[];
|
|
49
|
+
/**
|
|
50
|
+
* A size written after the description, as in Obsidian: ``
|
|
51
|
+
* or ``. The description still ends with it; see
|
|
52
|
+
* `IMAGE_SIZE`. Not part of CommonMark, so the spec HTML ignores it.
|
|
53
|
+
*/
|
|
54
|
+
readonly width?: number;
|
|
55
|
+
readonly height?: number;
|
|
49
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The size at the end of an image description, as its plain text ends: `|320`
|
|
59
|
+
* or `|320x200`, whole CSS pixels from 1 to 99999. In the source the `|` must
|
|
60
|
+
* not be escaped; `\|320` and `|320` are text.
|
|
61
|
+
*/
|
|
62
|
+
export declare const IMAGE_SIZE: RegExp;
|
|
50
63
|
export type BlockNode = ParagraphNode | HeadingNode | {
|
|
51
64
|
readonly type: 'thematicBreak';
|
|
52
65
|
} | BlockQuoteNode | ListNode | CodeBlockNode | HtmlBlockNode | RawNode | TableNode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Inline } from '../model.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type InlineNode } from './ast.js';
|
|
3
3
|
import { type InlineSyntax, type MarkdownOptions } from './options.js';
|
|
4
4
|
/** Link reference definitions, keyed by normalized label. */
|
|
5
5
|
export type RefMap = Map<string, {
|
package/dist/types/model.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export interface ImageAtom {
|
|
|
8
8
|
readonly src: string;
|
|
9
9
|
readonly alt: string;
|
|
10
10
|
readonly title?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Display width in CSS pixels, saved after the alt text as in Obsidian:
|
|
13
|
+
* ``. Without it the image shows at its own size.
|
|
14
|
+
*/
|
|
15
|
+
readonly width?: number;
|
|
16
|
+
/** Display height in CSS pixels, saved as ``. Only read when a width is given. */
|
|
17
|
+
readonly height?: number;
|
|
11
18
|
}
|
|
12
19
|
/** A run of text that shares one format. A hard line break is a "\n" in the text. */
|
|
13
20
|
export interface Span {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Editor } from '../editor.js';
|
|
2
|
+
export declare class ImageControls {
|
|
3
|
+
private readonly editor;
|
|
4
|
+
/** A frame over the image, holding the two handles. It takes no pointer events itself. */
|
|
5
|
+
private readonly frame;
|
|
6
|
+
private readonly handles;
|
|
7
|
+
/** The image under the pointer, which shows handles while it is hovered. */
|
|
8
|
+
private hovered;
|
|
9
|
+
/** The selected image, which shows handles. */
|
|
10
|
+
private selected;
|
|
11
|
+
/** The image the frame is shown for. */
|
|
12
|
+
private framed;
|
|
13
|
+
private drag;
|
|
14
|
+
private hideTimer;
|
|
15
|
+
private readonly cleanup;
|
|
16
|
+
constructor(editor: Editor);
|
|
17
|
+
/** True when `node` is part of these controls. */
|
|
18
|
+
contains(node: Node): boolean;
|
|
19
|
+
/** Shows the handles for the selected image, or for none. */
|
|
20
|
+
update(selected: ImageTarget | null): void;
|
|
21
|
+
/** Moves the controls to where their image is now, after scrolling. */
|
|
22
|
+
reposition(): void;
|
|
23
|
+
hide(): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
private onOver;
|
|
26
|
+
private scheduleUnhover;
|
|
27
|
+
private cancelUnhover;
|
|
28
|
+
/** Shows the handles over the hovered image, else the selected one. Only images that loaded can be resized. */
|
|
29
|
+
private placeFrame;
|
|
30
|
+
private startDrag;
|
|
31
|
+
private moveDrag;
|
|
32
|
+
private endDrag;
|
|
33
|
+
}
|
package/dist/types/view/dom.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface RenderContext {
|
|
|
39
39
|
readonly icon?: (name: IconName) => Node | null;
|
|
40
40
|
/** Code blocks get a copy button. */
|
|
41
41
|
readonly codeCopy?: boolean;
|
|
42
|
+
/** An image failed to load and its element was replaced by the unavailable state. */
|
|
43
|
+
readonly onImageError?: () => void;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Which views of one block show their source: `REVEAL_BLOCK` for a whole raw
|
|
@@ -92,6 +94,8 @@ export declare class BlockRenderer {
|
|
|
92
94
|
icon?: (name: IconName) => Node | null;
|
|
93
95
|
/** Code blocks get a copy button. */
|
|
94
96
|
codeCopy: boolean;
|
|
97
|
+
/** An image failed to load and now shows as unavailable. */
|
|
98
|
+
onImageError?: () => void;
|
|
95
99
|
/** Per block, the views that show their source. A block re-renders when its entry changes. */
|
|
96
100
|
revealed: ReadonlyMap<string, BlockReveal>;
|
|
97
101
|
/**
|
|
@@ -134,6 +138,8 @@ export declare function childIndex(node: Node): number;
|
|
|
134
138
|
/** Plain text of a content element as the browser currently has it, with atoms as one character. */
|
|
135
139
|
export declare function domText(contentEl: HTMLElement): string;
|
|
136
140
|
export declare function domToPosition(root: HTMLElement, node: Node, offset: number): Position | null;
|
|
141
|
+
/** The atom (an image or a rendered token) that starts at `pos`, or null. */
|
|
142
|
+
export declare function atomAt(blockEl: HTMLElement, pos: Position): HTMLElement | null;
|
|
137
143
|
export declare function positionToDom(blockEl: HTMLElement, pos: Position): {
|
|
138
144
|
node: Node;
|
|
139
145
|
offset: number;
|