@usememos/editor 26.10.16 → 26.10.18

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
@@ -63,13 +63,13 @@ The same names work in `new Editor(options)` and as React props, except that Rea
63
63
  | `referrerPolicy` | `ReferrerPolicy` | `referrerpolicy` for images, such as `no-referrer`. Images always load lazily. |
64
64
  | `onLinkClick` | `({ editor, href, event }) => boolean` | Called when a link is clicked to be opened: a plain click while read-only, Mod+click while editing, or Open on the link card. Return `true` to handle it, for example to route an in-app link or scroll to an anchor; otherwise the editor opens `href` in a new tab. |
65
65
  | `theme` | `{ classes?, tokens?, colorScheme? }` | Your own classes on rendered elements, colors and fonts, and light or dark. See [Theming](#theming). |
66
- | `toolbar` | `boolean \| { items? }` | Shows the formatting toolbar on selection. Default `true`. `items` lists its controls; they keep the built-in order: `textStyle`, `bold`, `italic`, `strike`, `inlineCode`, `link`, `quote`, `codeBlock`, `list` (exported as `TOOLBAR_ITEMS`). For example, `{ items: ['bold', 'italic', 'strike', 'inlineCode', 'link'] }` keeps it to inline formatting. |
66
+ | `toolbar` | `boolean \| { items? }` | Shows the formatting toolbar on selection, and the image toolbar on a selected image (see [Images](#images)). Default `true`. `items` lists the formatting toolbar's controls; they keep the built-in order: `textStyle`, `bold`, `italic`, `strike`, `inlineCode`, `link`, `quote`, `codeBlock`, `list` (exported as `TOOLBAR_ITEMS`). For example, `{ items: ['bold', 'italic', 'strike', 'inlineCode', 'link'] }` keeps it to inline formatting. `false` turns both toolbars off. |
67
67
  | `linkCard` | `boolean` | Default `true`. While editing, a link card shows under a link when the pointer rests on it or the caret is inside it: the URL as written, and buttons to open, copy, edit and remove the link. Open goes through `onLinkClick`. |
68
68
  | `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`. |
69
69
  | `slashMenu` | `false \| string[]` | Built-in slash menu items to show, in order, or `false` for none: `text`, `heading1`, `heading2`, `heading3`, `heading4`, `bulletList`, `numberedList`, `todoList`, `quote`, `callout`, `details`, `code`, `table`, `divider`. |
70
70
  | `slashHint` | `boolean` | Shows `labels.slashHint` ("Type '/' for commands") in the empty paragraph that has the caret. Default `false`. No effect when `slashMenu` is `false`. When the document is a single empty paragraph, `placeholder` shows instead. |
71
71
  | `labels` | `Partial<Labels>` | Overrides UI strings, for localization. See `src/labels.ts`. |
72
- | `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, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout icons and the callout menu), `openLink`, `copyLink`, `editLink` and `removeLink` (the link card), `imageAlignLeft`, `imageAlignCenter` and `imageAlignRight` (an image block's Align choices), `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
72
+ | `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, the block actions (`duplicate`, `delete`, the table cell actions, `altText` and `resetImageSize`), `bold`, `italic`, `strike`, `inlineCode`, `link`, `chevronDown` and `selected` (the formatting toolbar's menu buttons and their check mark), `chevronRight` (a menu row that opens a submenu, and a collapsible section's toggle), `calloutNote`, `calloutTip`, `calloutImportant`, `calloutWarning` and `calloutCaution` (callout icons and the callout menu), `openLink`, `copyLink`, `editLink` and `removeLink` (the link card), `imageAlignLeft`, `imageAlignCenter` and `imageAlignRight` (an image block's Align choices, in the image toolbar and the block menu), `blockHandle` and `imageUnavailable` (shown in place of an image that did not load). |
73
73
  | `onChange` | `(markdown: string, editor) => void` | Called after document changes, at most once per animation frame. |
74
74
  | `onSubmit` | `(markdown: string, editor) => void` | Called on Mod+Enter or Ctrl+Enter with the current Markdown, for comment boxes and chat inputs. |
75
75
  | `onFocus`, `onBlur` | `(editor) => void` | Focus events. |
@@ -325,9 +325,9 @@ Markdown shortcuts at the start of a line: `#`–`######`, `-`, `*`, `+`, `1.`,
325
325
 
326
326
  ## Images
327
327
 
328
- While editing, clicking an image selects it, with an outline. Its resize 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. 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 and alignment, with none of these controls.
328
+ While editing, clicking an image selects it, with an outline, and shows the image toolbar above it: Alt text, which opens a field for the alt text (Enter saves it, Escape keeps the old text); for a resized image, Reset size, which removes the width; and Delete. The toolbar shows for every image, inline, in a quote or in a list item alike, and Escape closes it. Its resize 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. 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 and alignment, with none of these controls.
329
329
 
330
- An image alone in its paragraph is an image block. It has the block handle and the block menu, like a table. Its block actions are an Align submenu (Left, Center, Right); Alt text, which opens a field for the alt text (Enter saves it, Escape keeps the old text); for a resized image, Reset size, which removes the width; then Duplicate and Delete. The alignment and size stay in the alt text when it is edited. The caret never rests beside an image block: arrow keys and a click select the image, Backspace at the start of the next block selects it and a second Backspace deletes it, and typing does nothing. Enter adds a paragraph after it. A centered image grows by twice the drag, so the resize handle stays under the pointer.
330
+ An image alone in its paragraph is an image block. Its toolbar starts with Align left, Align center and Align right, and it has the block handle and the block menu, like a table: an Align submenu, Alt text, Reset size, Duplicate and Delete, for the keyboard (Mod+/) and touch. The alignment and size stay in the alt text when it is edited. The caret never rests beside an image block: arrow keys and a click select the image, Backspace at the start of the next block selects it and a second Backspace deletes it, and typing does nothing. Enter adds a paragraph after it. A centered image grows by twice the drag, so the resize handle stays under the pointer.
331
331
 
332
332
  The size and the alignment are saved after the alt text, as in Obsidian and its image plugins: `![chart|320](chart.png)`, `![chart|320x200](chart.png)` with a height, `![chart|center](chart.png)` or `![chart|center|320](chart.png)`. The size is a whole number of CSS pixels, and the image never shows wider than the column. The alignment applies only to image blocks. Other Markdown renderers show the image at its own size, on the left, and read the alt text as `chart|center|320`. See [Image size and alignment](docs/syntax.md#image-size-and-alignment) in the syntax doc.
333
333
 
package/dist/base.css CHANGED
@@ -180,6 +180,10 @@
180
180
  .mbe-root.mbe-readonly a.mbe-link { cursor: pointer; }
181
181
  /* Inline even under a CSS reset such as Tailwind's preflight, which makes images blocks; alignment needs it. */
182
182
  .mbe-root .mbe-image { display: inline-block; max-width: 100%; height: auto; margin: 8px 0; vertical-align: bottom; }
183
+ /* An inline image gets room between the lines of text around it. An image
184
+ alone in its block does not: the block gap already separates it, and the
185
+ margin would make its block 16px taller than the image. */
186
+ .mbe-root .mbe-image-block .mbe-image { margin: 0; }
183
187
  /* An image alone in its paragraph moves within the column; it keeps its width. */
184
188
  .mbe-root .mbe-image-block[data-align="left"] { text-align: left; }
185
189
  .mbe-root .mbe-image-block[data-align="center"] { text-align: center; }
@@ -317,6 +321,7 @@
317
321
  .mbe-ui[hidden] { display: none !important; }
318
322
  .mbe-menu,
319
323
  .mbe-toolbar,
324
+ .mbe-image-toolbar,
320
325
  .mbe-link-card,
321
326
  .mbe-input-popover {
322
327
  position: fixed;
@@ -348,17 +353,22 @@
348
353
  .mbe-menu-loading { padding: 6px 8px; }
349
354
 
350
355
  /* Wider than the screen, the toolbar scrolls sideways; its max-width is set to fit. */
351
- .mbe-toolbar { box-sizing: border-box; display: flex; align-items: center; gap: 2px; padding: 4px; overflow-x: auto; scrollbar-width: none; }
352
- .mbe-toolbar::-webkit-scrollbar { display: none; }
356
+ .mbe-toolbar,
357
+ .mbe-image-toolbar { box-sizing: border-box; display: flex; align-items: center; gap: 2px; padding: 4px; overflow-x: auto; scrollbar-width: none; }
358
+ .mbe-toolbar::-webkit-scrollbar,
359
+ .mbe-image-toolbar::-webkit-scrollbar { display: none; }
360
+ /* A tool is a 28px control with a 16px icon, so a bar is 36px tall with its
361
+ 4px padding: compact next to the 24px lines it floats over, and the size
362
+ of a host app's own controls. */
353
363
  .mbe-tool {
354
364
  flex: none;
355
365
  font: inherit;
356
366
  color: inherit;
357
367
  background: none;
358
368
  border: none;
359
- padding: 4px 7px;
360
- min-width: 32px;
361
- min-height: 32px;
369
+ padding: 2px 6px;
370
+ min-width: 28px;
371
+ min-height: 28px;
362
372
  display: inline-flex;
363
373
  align-items: center;
364
374
  justify-content: center;
@@ -366,13 +376,13 @@
366
376
  }
367
377
  .mbe-tool[hidden],
368
378
  .mbe-tool-sep[hidden] { display: none; }
369
- .mbe-tool .mbe-icon { width: 18px; height: 18px; }
370
- .mbe-tool-menu { gap: 1px; padding-inline: 7px 4px; }
379
+ .mbe-tool .mbe-icon { width: 16px; height: 16px; }
380
+ .mbe-tool-menu { gap: 1px; padding-inline: 6px 3px; }
371
381
  .mbe-tool-icon,
372
382
  .mbe-tool-chevron { display: inline-flex; }
373
- .mbe-tool .mbe-tool-chevron .mbe-icon { width: 13px; height: 13px; }
383
+ .mbe-tool .mbe-tool-chevron .mbe-icon { width: 12px; height: 12px; }
374
384
  .mbe-tool.mbe-active { background: Highlight; color: HighlightText; }
375
- .mbe-tool-sep { flex: none; width: 1px; height: 18px; margin: 0 3px; background: GrayText; }
385
+ .mbe-tool-sep { flex: none; width: 1px; height: 16px; margin: 0 2px; background: GrayText; }
376
386
  .mbe-menu-check { flex: none; display: inline-flex; margin-inline-start: auto; }
377
387
  .mbe-menu-submenu { flex: none; display: inline-flex; margin-inline-start: auto; }
378
388
  .mbe-menu-submenu .mbe-icon { width: 14px; height: 14px; }
@@ -414,7 +424,7 @@
414
424
  .mbe-image-frame-small .mbe-resize-handle-right { left: 100%; }
415
425
  .mbe-image-resizing,
416
426
  .mbe-image-resizing .mbe-resize-handle { cursor: ew-resize; }
417
- .mbe-popover-input { font: inherit; color: inherit; width: 260px; padding: 5px 8px; }
427
+ .mbe-popover-input { font: inherit; color: inherit; box-sizing: border-box; height: 28px; width: 260px; padding: 0 8px; }
418
428
 
419
429
  .mbe-block-handle {
420
430
  position: fixed;