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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e6fda495d92cad60dac933e1fbe6466f0813def098debbe4bea232130db0721
4
- data.tar.gz: 0e579b377be3610f91228422dcd3480bae586942aee4294c5d3bd580f60f0de4
3
+ metadata.gz: 9a161b79f6c66266f236c0bae71c3ea540237a2a403fb2e047d43828e395bfda
4
+ data.tar.gz: '030840a6e183bc84837825ff7b8f646ebfb74fdd2d582c93c3475b38b88e633e'
5
5
  SHA512:
6
- metadata.gz: 4527448422497989de11f0173dbaab24f357c477e8661f7511f8b1d3f9794b60e0073496266205ae641975a08439cabbbe084a435f6b9499e3d9675a394959bf
7
- data.tar.gz: f43f34d4a40a05f0fdd13d29afa67c68abb9e55b13f0d3703e36181af4f7e1d12fcb4ddf29d706bdf301d877cd95147cb734310f9b5110fd449556984b35293f
6
+ metadata.gz: 1c03106f2eed700e7521b00a937ace2b854459633b99ee93f6ef99eb323fd017d95fd9d348d174decc8a5e9e3b028fe9b470f5943066563b3ba6a55d03871c2b
7
+ data.tar.gz: b1d3121c8bc34f2b560192523f0e9a5ec885d869df2b9bdf56da88bd16829b8a5b9c0b0e99fa95507c06b65a1ca381665678df5f74dca94501b81937c658189a
@@ -12884,7 +12884,7 @@ class Clipboard {
12884
12884
  }
12885
12885
 
12886
12886
  if (this.#isPlainTextOrURLPasted(clipboardData)) {
12887
- this.#pastePlainText(clipboardData);
12887
+ this.#pastePlainTextOrURL(clipboardData);
12888
12888
  event.preventDefault();
12889
12889
  return true
12890
12890
  }
@@ -12922,14 +12922,34 @@ class Clipboard {
12922
12922
  return types.length === 1 && types[0] === "text/plain"
12923
12923
  }
12924
12924
 
12925
+ // Browsers expose a copied URL in several shapes:
12926
+ // Safari [ text/plain, text/uri-list ]
12927
+ // App ShareSheet [ text/uri-list ]
12928
+ // Chromium macOS [ text/plain, text/html, (?:text/link-preview) ]
12925
12929
  #isOnlyURLPasted(clipboardData) {
12926
- // Safari URLs are copied as a text/plain + text/uri-list object
12927
- // App ShareSheet URLs are copied as solo text/uri-list object
12930
+ if (this.#isLexicalClipboardData(clipboardData)) return false
12931
+
12928
12932
  const types = Array.from(clipboardData.types);
12929
- return types.length
12930
- && types.length <= 2
12931
- && types.includes("text/uri-list")
12932
- && (types.length < 2 || types.includes("text/plain"))
12933
+ if (types.includes("text/uri-list")) {
12934
+ return types.every(type => type === "text/plain" || type === "text/uri-list")
12935
+ }
12936
+
12937
+ if (clipboardData.files.length) return false
12938
+
12939
+ const text = clipboardData.getData("text/plain").trim();
12940
+ if (!isAutolinkableURL(text)) return false
12941
+
12942
+ const html = clipboardData.getData("text/html");
12943
+ return !html || this.#htmlIsBareLinkToURL(html, text)
12944
+ }
12945
+
12946
+ #htmlIsBareLinkToURL(html, url) {
12947
+ const doc = parseHtml(html);
12948
+ if (doc.body.textContent.trim() !== url) return false
12949
+
12950
+ const links = doc.body.querySelectorAll("a");
12951
+ if (links.length === 0) return true
12952
+ return links.length === 1 && links[0].getAttribute("href") === url
12933
12953
  }
12934
12954
 
12935
12955
  #isPastingIntoCodeBlock() {
@@ -12963,14 +12983,12 @@ class Clipboard {
12963
12983
  }, { tag: jn });
12964
12984
  }
12965
12985
 
12966
- #pastePlainText(clipboardData) {
12967
- const item = clipboardData.items[0];
12986
+ #pastePlainTextOrURL(clipboardData) {
12987
+ const item = this.#plainTextOrURLItem(clipboardData);
12968
12988
  item.getAsString((text) => {
12969
- if (isAutolinkableURL(text) && this.contents.hasSelectedText()) {
12970
- this.contents.createLinkWithSelectedText(text);
12971
- } else if (isAutolinkableURL(text)) {
12972
- const nodeKey = this.contents.createLink(text);
12973
- this.#dispatchLinkInsertEvent(nodeKey, { url: text });
12989
+ const url = text.trim();
12990
+ if (isAutolinkableURL(url)) {
12991
+ this.#pasteURL(url);
12974
12992
  } else if (this.editorElement.supportsMarkdown) {
12975
12993
  this.#pasteMarkdown(text);
12976
12994
  } else {
@@ -12979,6 +12997,20 @@ class Clipboard {
12979
12997
  });
12980
12998
  }
12981
12999
 
13000
+ #plainTextOrURLItem(clipboardData) {
13001
+ const items = Array.from(clipboardData.items);
13002
+ return items.find((item) => item.type === "text/plain") || items.find((item) => item.type === "text/uri-list")
13003
+ }
13004
+
13005
+ #pasteURL(url) {
13006
+ if (this.contents.hasSelectedText()) {
13007
+ this.contents.createLinkWithSelectedText(url);
13008
+ } else {
13009
+ const nodeKey = this.contents.createLink(url);
13010
+ this.#dispatchLinkInsertEvent(nodeKey, { url });
13011
+ }
13012
+ }
13013
+
12982
13014
  #insertSingleLinkAt(selection, url) {
12983
13015
  if (!Fr(selection)) return
12984
13016
 
Binary file
Binary file