@usememos/editor 26.10.6 → 26.10.8

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 CHANGED
@@ -67,7 +67,7 @@ The same names work in `new Editor(options)` and as React props, except that Rea
67
67
  | `popupContainer` | `HTMLElement` | Where menus, the toolbar and the autocomplete popup are appended. Default: the nearest open `<dialog>` or `aria-modal` ancestor of `element`, else `document.body`. |
68
68
  | `slashMenu` | `false \| string[]` | Built-in slash menu items to show, in order, or `false` for none: `text`, `heading1`, `heading2`, `heading3`, `bulletList`, `numberedList`, `todoList`, `quote`, `code`, `table`, `divider`. |
69
69
  | `labels` | `Partial<Labels>` | Overrides UI strings, for localization. See `src/labels.ts`. |
70
- | `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, `duplicate`, `delete`, the table actions, `bold`, `italic`, `strike`, `inlineCode`, `link` and `blockHandle`. |
70
+ | `icons` | `Partial<Record<IconName, string \| Element>>` | Replaces built-in icons, which are [Lucide](https://lucide.dev) icons. A string is shown as text; an element, such as an `<svg>`, is cloned for every place it appears. Names match the `labels` keys of the same controls: the slash menu items, `duplicate`, `delete`, the table actions, `bold`, `italic`, `strike`, `inlineCode`, `link`, `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
71
71
  | `onChange` | `(markdown: string, editor) => void` | Called after document changes, at most once per animation frame. |
72
72
  | `onSubmit` | `(markdown: string, editor) => void` | Called on Mod+Enter or Ctrl+Enter with the current Markdown, for comment boxes and chat inputs. |
73
73
  | `onFocus`, `onBlur` | `(editor) => void` | Focus events. |
@@ -98,10 +98,10 @@ function Composer() {
98
98
  | `setMarkdown(markdown, { history? })` | Replaces the document. `history: 'clear'` (default) clears undo history; `'keep'` makes the replacement one undo step. Does not emit `change`. |
99
99
  | `isEmpty` | True when the document holds only empty paragraphs. |
100
100
  | `state` | The document and selection, immutable. |
101
- | `commands.*` | Edits. Each applies one change, records one undo step, and returns `true` if it did something: `toggleBold`, `toggleItalic`, `toggleStrike`, `toggleCode`, `setParagraph`, `toggleHeading({ level })`, `toggleBulletList`, `toggleOrderedList`, `toggleTaskList`, `toggleBlockquote`, `toggleCodeBlock({ language? })`, `setLink({ href })`, `unsetLink`, `insertText(text, { range? })`, `insertMarkdown(markdown, options?)`, `insertTable({ rows?, cols? })`, `insertDivider`, `indent`, `outdent`, `undo`, `redo`, `selectAll`, `selectBlocks`, `focus(position?)`, `blur`, `scrollIntoView`. `selectBlocks` selects the blocks the selection touches as whole blocks, as Escape does; it returns `false` when read-only. `scrollIntoView` changes nothing in the document: it scrolls the caret into view in the editor's scrolling containers and the window, for example after an `insertMarkdown` from code. |
101
+ | `commands.*` | Edits. Each applies one change, records one undo step, and returns `true` if it did something: `toggleBold`, `toggleItalic`, `toggleStrike`, `toggleCode`, `setParagraph`, `toggleHeading({ level })`, `toggleBulletList`, `toggleOrderedList`, `toggleTaskList`, `toggleBlockquote`, `toggleCodeBlock({ language? })`, `setLink({ href })`, `unsetLink`, `updateImage({ alt?, title?, width? })`, `insertText(text, { range? })`, `insertMarkdown(markdown, options?)`, `insertTable({ rows?, cols? })`, `insertDivider`, `indent`, `outdent`, `undo`, `redo`, `selectAll`, `selectBlocks`, `focus(position?)`, `blur`, `scrollIntoView`. `selectBlocks` selects the blocks the selection touches as whole blocks, as Escape does; it returns `false` when read-only. `updateImage` changes the selected image; `null` removes its title or width, and a new width drops a height so the image keeps its aspect ratio. `scrollIntoView` changes nothing in the document: it scrolls the caret into view in the editor's scrolling containers and the window, for example after an `insertMarkdown` from code. |
102
102
  | `run(fn)` | Applies a custom command: a function from state to a new state, or `null`. The pure commands are exported as `commands` from the package. |
103
- | `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote`, `codeBlock`, `table`, `divider`, `raw`. `attrs` narrows it, for example `isActive('heading', { level: 2 })`. |
104
- | `getAttributes(name)` | `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block. |
103
+ | `isActive(name, attrs?)` | `bold`, `italic`, `strike`, `code`, `link`, `image` (the selection is exactly one image), or the type of the block with the caret: `paragraph`, `heading`, `bulletList`, `orderedList`, `taskList`, `blockquote`, `codeBlock`, `table`, `divider`, `raw`. `attrs` narrows it, for example `isActive('heading', { level: 2 })`. |
104
+ | `getAttributes(name)` | `src`, `alt`, `title`, `width` and `height` of the selected image, `href` of a link, `level` of a heading, `language` of a code block, `checked` of a task, `syntax` of a raw block. |
105
105
  | `selectedBlocks` | The blocks of a block selection, in document order, or an empty array when the selection is text. |
106
106
  | `getSelection()`, `setSelection(selection)` | Read or move the selection. `setSelection` also takes a `SelectionJSON`, and clamps one that does not fit the document. |
107
107
  | `selectionToJSON()` | The selection as JSON-safe data (block index and offset). It still fits after reloading the same Markdown, so an app can store the caret and restore it. |
@@ -296,12 +296,19 @@ To style the editor entirely with your own classes, import `@usememos/editor/bas
296
296
  | Tab, Shift+Tab | Indent and outdent list items; next and previous table cell |
297
297
  | Mod+Shift+V | Paste as plain text |
298
298
  | Mod+Enter, Ctrl+Enter | `submit` |
299
+ | Click an image | Select it. Backspace or Delete removes it, ArrowLeft and ArrowRight move past it, Enter starts a new paragraph after it, typing replaces it |
299
300
  | Escape | Close a menu or the toolbar; otherwise select the block with the caret (or every block a text selection crosses); in a block selection, leave the editor |
300
301
 
301
302
  With blocks selected: ArrowUp and ArrowDown select the block above or below, Shift extends the selection, Mod+A selects every block, Backspace and Delete delete them, Mod+C, Mod+X and paste copy, cut and replace them as whole blocks, Mod+D duplicates them, and the block type keys, Tab and the mark keys apply to all of them. Enter, ArrowLeft and ArrowRight go back to editing text. Typing does nothing. See [Block selection](docs/architecture.md#block-selection).
302
303
 
303
304
  Markdown shortcuts at the start of a line: `#`–`######`, `-`, `*`, `+`, `1.`, `[ ]`, `[x]`, `>`, ` ``` `, `---`. Inline: `**bold**`, `*italic*`, `_italic_`, `` `code` ``, `~~strike~~`.
304
305
 
306
+ ## Images
307
+
308
+ While editing, clicking an image selects it, with an outline. Its side handles, shown on hover and on the selected image, resize it: the width follows the pointer up to the width of the line, keeps the aspect ratio, and snaps to the width of other images in the document when it comes within 8 pixels. Each resize is one undo step. The **Alt text** button over a selected image edits its alt text; Enter saves and Escape cancels. An image that does not load, or whose URL `resolveUrl` dropped, shows an icon and its alt text (`labels.imageUnavailable` when it has none), and can still be selected and deleted. Read-only editors show images at their saved size, with none of these controls.
309
+
310
+ The size is saved after the alt text, as in Obsidian: `![chart|320](chart.png)`, or `![chart|320x200](chart.png)` with a height. It is a whole number of CSS pixels, and the image never shows wider than the column. Other Markdown renderers show the image at its own size and read the alt text as `chart|320`. See [Images](docs/syntax.md#links-and-images) in the syntax doc.
311
+
305
312
  ## What saving changes
306
313
 
307
314
  Blocks you did not edit are saved exactly as they were loaded, byte for byte, including the blank lines between them. `getMarkdown()` right after loading returns the input unchanged.
package/dist/base.css CHANGED
@@ -100,6 +100,21 @@
100
100
  .mbe-root a.mbe-link { cursor: text; }
101
101
  .mbe-root.mbe-readonly a.mbe-link { cursor: pointer; }
102
102
  .mbe-root .mbe-image { max-width: 100%; height: auto; margin: 8px 0; vertical-align: bottom; }
103
+ /* An image that did not load: an icon and its alt text, on one line. */
104
+ .mbe-root .mbe-image-unavailable {
105
+ display: inline-flex;
106
+ align-items: center;
107
+ gap: 6px;
108
+ box-sizing: border-box;
109
+ padding: 4px 8px;
110
+ border: 1px dashed GrayText;
111
+ }
112
+ .mbe-root .mbe-image-alt { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
113
+ /* A selected image has an outline instead of the browser's selection highlight and caret. */
114
+ .mbe-root .mbe-image-selected { outline: 2px solid Highlight; outline-offset: 2px; }
115
+ .mbe-root.mbe-image-selection,
116
+ .mbe-root.mbe-image-selection * { caret-color: transparent; }
117
+ .mbe-root.mbe-image-selection ::selection { background: transparent; }
103
118
 
104
119
  /* Code */
105
120
  .mbe-root .mbe-code-bar { display: flex; align-items: center; }
@@ -235,6 +250,33 @@
235
250
  .mbe-tool-sep { width: 1px; align-self: stretch; margin: 3px 2px; background: GrayText; }
236
251
 
237
252
  .mbe-link-popover { display: flex; gap: 4px; padding: 4px; }
253
+
254
+ /* The handles that resize an image: a frame over it that only its handles respond to. */
255
+ .mbe-image-frame { position: fixed; pointer-events: none; }
256
+ .mbe-image-handle {
257
+ position: absolute;
258
+ top: 50%;
259
+ width: 6px;
260
+ height: 40%;
261
+ min-height: 16px;
262
+ max-height: 48px;
263
+ box-sizing: border-box;
264
+ transform: translate(-50%, -50%);
265
+ pointer-events: auto;
266
+ touch-action: none;
267
+ cursor: ew-resize;
268
+ background: Canvas;
269
+ border: 1px solid CanvasText;
270
+ border-radius: 3px;
271
+ }
272
+ /* A larger area to grab than the handle shows. */
273
+ .mbe-image-handle::before { content: ''; position: absolute; inset: -6px -8px; }
274
+ .mbe-image-handle-left { left: 8px; }
275
+ .mbe-image-handle-right { left: calc(100% - 8px); }
276
+ .mbe-image-frame-small .mbe-image-handle-left { left: 0; }
277
+ .mbe-image-frame-small .mbe-image-handle-right { left: 100%; }
278
+ .mbe-image-resizing,
279
+ .mbe-image-resizing .mbe-image-handle { cursor: ew-resize; }
238
280
  .mbe-link-input { font: inherit; color: inherit; width: 260px; padding: 5px 8px; }
239
281
 
240
282
  .mbe-handle {