@37signals/lexxy 0.9.20 → 0.9.21

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.
Files changed (2) hide show
  1. package/dist/lexxy.esm.js +46 -14
  2. package/package.json +1 -1
package/dist/lexxy.esm.js CHANGED
@@ -6486,7 +6486,7 @@ class Clipboard {
6486
6486
  }
6487
6487
 
6488
6488
  if (this.#isPlainTextOrURLPasted(clipboardData)) {
6489
- this.#pastePlainText(clipboardData);
6489
+ this.#pastePlainTextOrURL(clipboardData);
6490
6490
  event.preventDefault();
6491
6491
  return true
6492
6492
  }
@@ -6524,14 +6524,34 @@ class Clipboard {
6524
6524
  return types.length === 1 && types[0] === "text/plain"
6525
6525
  }
6526
6526
 
6527
+ // Browsers expose a copied URL in several shapes:
6528
+ // Safari [ text/plain, text/uri-list ]
6529
+ // App ShareSheet [ text/uri-list ]
6530
+ // Chromium macOS [ text/plain, text/html, (?:text/link-preview) ]
6527
6531
  #isOnlyURLPasted(clipboardData) {
6528
- // Safari URLs are copied as a text/plain + text/uri-list object
6529
- // App ShareSheet URLs are copied as solo text/uri-list object
6532
+ if (this.#isLexicalClipboardData(clipboardData)) return false
6533
+
6530
6534
  const types = Array.from(clipboardData.types);
6531
- return types.length
6532
- && types.length <= 2
6533
- && types.includes("text/uri-list")
6534
- && (types.length < 2 || types.includes("text/plain"))
6535
+ if (types.includes("text/uri-list")) {
6536
+ return types.every(type => type === "text/plain" || type === "text/uri-list")
6537
+ }
6538
+
6539
+ if (clipboardData.files.length) return false
6540
+
6541
+ const text = clipboardData.getData("text/plain").trim();
6542
+ if (!isAutolinkableURL(text)) return false
6543
+
6544
+ const html = clipboardData.getData("text/html");
6545
+ return !html || this.#htmlIsBareLinkToURL(html, text)
6546
+ }
6547
+
6548
+ #htmlIsBareLinkToURL(html, url) {
6549
+ const doc = parseHtml(html);
6550
+ if (doc.body.textContent.trim() !== url) return false
6551
+
6552
+ const links = doc.body.querySelectorAll("a");
6553
+ if (links.length === 0) return true
6554
+ return links.length === 1 && links[0].getAttribute("href") === url
6535
6555
  }
6536
6556
 
6537
6557
  #isPastingIntoCodeBlock() {
@@ -6565,14 +6585,12 @@ class Clipboard {
6565
6585
  }, { tag: PASTE_TAG });
6566
6586
  }
6567
6587
 
6568
- #pastePlainText(clipboardData) {
6569
- const item = clipboardData.items[0];
6588
+ #pastePlainTextOrURL(clipboardData) {
6589
+ const item = this.#plainTextOrURLItem(clipboardData);
6570
6590
  item.getAsString((text) => {
6571
- if (isAutolinkableURL(text) && this.contents.hasSelectedText()) {
6572
- this.contents.createLinkWithSelectedText(text);
6573
- } else if (isAutolinkableURL(text)) {
6574
- const nodeKey = this.contents.createLink(text);
6575
- this.#dispatchLinkInsertEvent(nodeKey, { url: text });
6591
+ const url = text.trim();
6592
+ if (isAutolinkableURL(url)) {
6593
+ this.#pasteURL(url);
6576
6594
  } else if (this.editorElement.supportsMarkdown) {
6577
6595
  this.#pasteMarkdown(text);
6578
6596
  } else {
@@ -6581,6 +6599,20 @@ class Clipboard {
6581
6599
  });
6582
6600
  }
6583
6601
 
6602
+ #plainTextOrURLItem(clipboardData) {
6603
+ const items = Array.from(clipboardData.items);
6604
+ return items.find((item) => item.type === "text/plain") || items.find((item) => item.type === "text/uri-list")
6605
+ }
6606
+
6607
+ #pasteURL(url) {
6608
+ if (this.contents.hasSelectedText()) {
6609
+ this.contents.createLinkWithSelectedText(url);
6610
+ } else {
6611
+ const nodeKey = this.contents.createLink(url);
6612
+ this.#dispatchLinkInsertEvent(nodeKey, { url });
6613
+ }
6614
+ }
6615
+
6584
6616
  #insertSingleLinkAt(selection, url) {
6585
6617
  if (!$isRangeSelection(selection)) return
6586
6618
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@37signals/lexxy",
3
- "version": "0.9.20",
3
+ "version": "0.9.21",
4
4
  "description": "Lexxy - A modern rich text editor for Rails.",
5
5
  "module": "dist/lexxy.esm.js",
6
6
  "type": "module",