@usememos/editor 26.10.8 → 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 CHANGED
@@ -305,7 +305,7 @@ Markdown shortcuts at the start of a line: `#`–`######`, `-`, `*`, `+`, `1.`,
305
305
 
306
306
  ## Images
307
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.
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. 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
309
 
310
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
311
 
package/dist/base.css CHANGED
@@ -110,8 +110,9 @@
110
110
  border: 1px dashed GrayText;
111
111
  }
112
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; }
113
+ /* A selected image has an outline instead of the browser's selection highlight and caret.
114
+ The outline is drawn inside the image, so a container that clips its overflow does not cut it. */
115
+ .mbe-root .mbe-image-selected { outline: 2px solid Highlight; outline-offset: -2px; }
115
116
  .mbe-root.mbe-image-selection,
116
117
  .mbe-root.mbe-image-selection * { caret-color: transparent; }
117
118
  .mbe-root.mbe-image-selection ::selection { background: transparent; }
package/dist/index.js CHANGED
@@ -2074,9 +2074,6 @@ var DEFAULT_LABELS = {
2074
2074
  tableSection: "Table",
2075
2075
  /** Shown in place of an image that did not load and has no alt text. */
2076
2076
  imageUnavailable: "Image unavailable",
2077
- /** The button over a selected image that edits its alt text, and the field's name. */
2078
- altText: "Alt text",
2079
- altTextPlaceholder: "Describe the image\u2026",
2080
2077
  /** Accessible name of the handles that resize an image. */
2081
2078
  resizeImage: "Resize image"
2082
2079
  };
@@ -6556,21 +6553,6 @@ var ImageControls = class {
6556
6553
  return el;
6557
6554
  };
6558
6555
  this.handles = { left: handle("left"), right: handle("right") };
6559
- this.toolbar = new Popup(root, "mbe-toolbar mbe-image-toolbar");
6560
- this.toolbar.el.setAttribute("role", "toolbar");
6561
- const altButton = doc.createElement("button");
6562
- altButton.type = "button";
6563
- altButton.className = "mbe-tool mbe-tool-alt";
6564
- altButton.textContent = labels.altText;
6565
- altButton.addEventListener("click", () => this.openAlt());
6566
- this.toolbar.el.appendChild(altButton);
6567
- this.altPopover = new Popup(root, "mbe-link-popover mbe-alt-popover");
6568
- this.altInput = doc.createElement("input");
6569
- this.altInput.type = "text";
6570
- this.altInput.className = "mbe-link-input mbe-alt-input";
6571
- this.altInput.placeholder = labels.altTextPlaceholder;
6572
- this.altInput.setAttribute("aria-label", labels.altText);
6573
- this.altPopover.el.appendChild(this.altInput);
6574
6556
  const on = (target, type, fn) => {
6575
6557
  target.addEventListener(type, fn);
6576
6558
  this.cleanup.push(() => target.removeEventListener(type, fn));
@@ -6587,98 +6569,44 @@ var ImageControls = class {
6587
6569
  on(this.frame, "pointerup", (e) => this.endDrag(e, true));
6588
6570
  on(this.frame, "pointercancel", (e) => this.endDrag(e, false));
6589
6571
  on(this.frame, "lostpointercapture", (e) => this.endDrag(e, true));
6590
- on(this.altInput, "keydown", (e) => {
6591
- if (e.key === "Enter") {
6592
- e.preventDefault();
6593
- this.finishAlt(this.altInput.value.trim());
6594
- } else if (e.key === "Escape") {
6595
- e.preventDefault();
6596
- this.finishAlt(null);
6597
- }
6598
- });
6599
- on(this.altInput, "blur", () => {
6600
- setTimeout(() => {
6601
- if (this.altPopover.isOpen && doc.activeElement !== this.altInput) this.closeAlt();
6602
- }, 150);
6603
- });
6604
6572
  }
6605
6573
  /** A frame over the image, holding the two handles. It takes no pointer events itself. */
6606
6574
  frame;
6607
6575
  handles;
6608
- toolbar;
6609
- altPopover;
6610
- altInput;
6611
6576
  /** The image under the pointer, which shows handles while it is hovered. */
6612
6577
  hovered = null;
6613
- /** The selected image, which shows handles and the toolbar. */
6578
+ /** The selected image, which shows handles. */
6614
6579
  selected = null;
6615
6580
  /** The image the frame is shown for. */
6616
6581
  framed = null;
6617
6582
  drag = null;
6618
- altDone = null;
6619
6583
  hideTimer = null;
6620
6584
  cleanup = [];
6621
- /** True while the alt text field is open. */
6622
- get isEditingAlt() {
6623
- return this.altPopover.isOpen;
6624
- }
6625
- /** True while an image is being resized. */
6626
- get isResizing() {
6627
- return this.drag !== null;
6628
- }
6629
6585
  /** True when `node` is part of these controls. */
6630
6586
  contains(node) {
6631
- return this.frame.contains(node) || this.toolbar.el.contains(node) || this.altPopover.el.contains(node);
6587
+ return this.frame.contains(node);
6632
6588
  }
6633
- /**
6634
- * Shows the controls for the selected image, or hides them for none. The
6635
- * toolbar shows only when `toolbar` is true (the editor is focused and not
6636
- * busy with something else).
6637
- */
6638
- update(selected, toolbar) {
6589
+ /** Shows the handles for the selected image, or for none. */
6590
+ update(selected) {
6639
6591
  this.selected = selected;
6640
- if (this.drag) return;
6641
- if (!selected) {
6642
- this.toolbar.hide();
6643
- if (this.altPopover.isOpen) this.closeAlt();
6644
- } else if (toolbar && !this.altPopover.isOpen) {
6645
- this.showToolbar(selected.el);
6646
- } else if (!toolbar) {
6647
- this.toolbar.hide();
6648
- }
6649
- this.placeFrame();
6592
+ if (!this.drag) this.placeFrame();
6650
6593
  }
6651
6594
  /** Moves the controls to where their image is now, after scrolling. */
6652
6595
  reposition() {
6653
6596
  if (this.drag) return;
6654
6597
  if (this.selected && !this.selected.el.isConnected) this.selected = null;
6655
- if (this.toolbar.isOpen && this.selected) this.showToolbar(this.selected.el);
6656
- if (this.altPopover.isOpen && this.selected) this.altPopover.show(this.selected.el.getBoundingClientRect(), "below");
6657
6598
  this.placeFrame();
6658
6599
  }
6659
6600
  hide() {
6660
6601
  if (this.drag) return;
6661
6602
  this.hovered = null;
6662
6603
  this.selected = null;
6663
- this.toolbar.hide();
6664
- if (this.altPopover.isOpen) this.closeAlt();
6665
6604
  this.placeFrame();
6666
6605
  }
6667
6606
  destroy() {
6668
6607
  this.cancelUnhover();
6669
6608
  for (const fn of this.cleanup) fn();
6670
6609
  this.frame.remove();
6671
- this.toolbar.destroy();
6672
- this.altPopover.destroy();
6673
- }
6674
- /** The toolbar goes inside the image's top corner, as in Notion, or above an image too small to hold it. */
6675
- showToolbar(el) {
6676
- const rect = el.getBoundingClientRect();
6677
- if (rect.width < 120 || rect.height < 60) return this.toolbar.show(rect, "above", 8);
6678
- const rtl = el.ownerDocument.defaultView.getComputedStyle(el).direction === "rtl";
6679
- const inset = 8;
6680
- const corner = { left: rect.left + inset, right: rect.right - inset, top: rect.top, bottom: rect.top + inset };
6681
- this.toolbar.show(corner, "below", 0, rtl ? "start" : "end");
6682
6610
  }
6683
6611
  // -- Hover ----------------------------------------------------------------
6684
6612
  onOver(e) {
@@ -6741,7 +6669,6 @@ var ImageControls = class {
6741
6669
  const others = Array.from(this.editor.root.querySelectorAll("img.mbe-image")).filter((other) => other !== el).map((other) => other.getBoundingClientRect().width).filter((w) => w > 0);
6742
6670
  const max = Math.max(MIN_WIDTH, columnWidth(el));
6743
6671
  this.drag = { el, side, pointer: e.pointerId, startX: e.clientX, startWidth: width, max, snaps: [...others, max], width };
6744
- this.toolbar.hide();
6745
6672
  this.frame.classList.add("mbe-image-resizing");
6746
6673
  this.editor.selectImageAt(target.pos);
6747
6674
  }
@@ -6773,32 +6700,6 @@ var ImageControls = class {
6773
6700
  this.editor.refreshImageUi();
6774
6701
  }
6775
6702
  }
6776
- // -- Alt text -------------------------------------------------------------
6777
- openAlt() {
6778
- const selected = this.selected;
6779
- if (!selected) return;
6780
- const { pos, image } = selected;
6781
- this.toolbar.hide();
6782
- this.altDone = (alt) => {
6783
- if (alt !== null) this.editor.updateImageAt(pos, { alt });
6784
- this.editor.focus();
6785
- if (alt === null) this.editor.selectImageAt(pos);
6786
- };
6787
- this.altInput.value = image.alt;
6788
- this.altPopover.show(selected.el.getBoundingClientRect(), "below");
6789
- this.altInput.focus();
6790
- this.altInput.select();
6791
- }
6792
- closeAlt() {
6793
- this.altDone = null;
6794
- this.altPopover.hide();
6795
- }
6796
- finishAlt(alt) {
6797
- const done = this.altDone;
6798
- this.altDone = null;
6799
- this.altPopover.hide();
6800
- done?.(alt);
6801
- }
6802
6703
  };
6803
6704
  function columnWidth(el) {
6804
6705
  let box = el.parentElement;
@@ -8566,9 +8467,9 @@ var Editor = class {
8566
8467
  }
8567
8468
  onFocusOut(e) {
8568
8469
  const next = e.relatedTarget;
8569
- if (next && (this.root.contains(next) || this.linkPopover.contains(next) || this.imageControls.contains(next))) return;
8470
+ if (next && (this.root.contains(next) || this.linkPopover.contains(next))) return;
8570
8471
  queueMicrotask(() => {
8571
- if (this.hasFocus() || this.linkPopover.isOpen || this.imageControls.isEditingAlt) return;
8472
+ if (this.hasFocus() || this.linkPopover.isOpen) return;
8572
8473
  if (!this.focused) return;
8573
8474
  this.focused = false;
8574
8475
  this.root.classList.remove("mbe-focused");
@@ -8941,12 +8842,9 @@ var Editor = class {
8941
8842
  this.hintEl = nextHint;
8942
8843
  }
8943
8844
  this.suggestions.update(focused);
8944
- const image = !this.readOnly && !this.blockSel && (focused || this.imageControls.isEditingAlt) ? this.imageTargetAt(this.state) : null;
8845
+ const image = focused && !this.readOnly && !this.blockSel ? this.imageTargetAt(this.state) : null;
8945
8846
  this.paintSelectedImage(image?.el ?? null);
8946
- this.imageControls.update(
8947
- image,
8948
- focused && !this.composing && !this.suggestions.isActive && !this.blockMenu.isOpen && !this.imageControls.isResizing
8949
- );
8847
+ this.imageControls.update(image);
8950
8848
  if (this.toolbar) {
8951
8849
  const block3 = this.state.doc.blocks.find((b) => b.id === pos.blockId);
8952
8850
  const closed = this.toolbarClosedFor;