lexxy 0.9.25 → 0.9.26

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: 92ba1a84cc251d9d9b65ab65cb2dbd24fb1e8180456855cc32620efa0d3b5e85
4
- data.tar.gz: 5f2f17fe5d328e1e8961067cd297692d87fa70901c81b9c55527cb5ac3887503
3
+ metadata.gz: f5c63b2cb8499843f516d8404a2a7573f93452f753b54672b53d80a60242d0ef
4
+ data.tar.gz: 13d59b10d606353cbc379ea5e940b40647fbe17a497f11a565c633ca1ae51519
5
5
  SHA512:
6
- metadata.gz: b281de9a7ad1d3ca00bee0ddb2f5841eda6db4747d20421d127fb375f01d20b509052bb006cd168a8def21ff59c1c2f71cd0362817cca70aa7881caf6883e1b2
7
- data.tar.gz: bf512346a4f6bfab93053150eda97fa1f0c04915a29fc2c06a1187ce76b295bd3c5cfb0dc72d14698d6a0cf7631af9ffa6a2e5edb10ae4627693502877d14f6d
6
+ metadata.gz: 0e0b6c3b8763c773fbc0ebe6a4d17cc5c8ee00813c48e66151975640daf3866b9a9558128584812aba21de840982ff0273200158b529343fd98b0992641622b8
7
+ data.tar.gz: 72db851395aea2ad408a62dd78afd2e0cea0843b1484f39a19755f58d6a8a65c482c029bb876d5f109018820bee4b8141365976b35508bfd83adc0c9754dd543
data/README.md CHANGED
@@ -21,6 +21,7 @@ A modern rich text editor for Rails.
21
21
 
22
22
  - Bug reports and pull requests are welcome on [GitHub Issues](https://github.com/basecamp/lexxy/issues). Help is especially welcome with [those tagged as "Help Wanted"](https://github.com/basecamp/lexxy/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22help%20wanted%22).
23
23
  - For questions and general Lexxy discussion, please use the [Discussions section](https://github.com/basecamp/lexxy/discussions)
24
+ - To build with a development version of Lexical, use `bin/link-to-local-lexical`.
24
25
 
25
26
  ## License
26
27
 
@@ -12485,6 +12485,7 @@ class PastedContentFormatter {
12485
12485
  this.#stripStyleElements();
12486
12486
  this.#unwrapPlaceholderAnchors();
12487
12487
  this.#stripTableCellColorStyles();
12488
+ this.#unwrapWrappedListChildren();
12488
12489
  this.#nestStrayListChildren();
12489
12490
  this.#stripStrayListChildren();
12490
12491
  return this.doc
@@ -12526,6 +12527,29 @@ class PastedContentFormatter {
12526
12527
  }
12527
12528
  }
12528
12529
 
12530
+ // Some sources wrap runs of <li>s in a stray element (e.g. a <div> directly
12531
+ // inside the list). Dissolve such wrappers so their items become direct
12532
+ // list children and any nested list they hide becomes visible to
12533
+ // #nestStrayListChildren below.
12534
+ #unwrapWrappedListChildren() {
12535
+ for (const list of this.doc.querySelectorAll("ol, ul")) {
12536
+ let wrapper = this.#wrappedListChild(list);
12537
+ while (wrapper) {
12538
+ wrapper.replaceWith(...wrapper.childNodes);
12539
+ wrapper = this.#wrappedListChild(list);
12540
+ }
12541
+ }
12542
+ }
12543
+
12544
+ #wrappedListChild(list) {
12545
+ for (const child of list.children) {
12546
+ if (child.tagName !== "LI" && !this.#isNestedList(child) && this.#containsListItems(child)) {
12547
+ return child
12548
+ }
12549
+ }
12550
+ return null
12551
+ }
12552
+
12529
12553
  // Some sources (e.g. Gmail) nest a sublist as a direct child of the parent
12530
12554
  // <ol>/<ul> instead of inside a <li>. Move each nested list into its
12531
12555
  // preceding <li> so the import preserves the nesting instead of dropping it.
@@ -12542,15 +12566,40 @@ class PastedContentFormatter {
12542
12566
  }
12543
12567
  }
12544
12568
 
12545
- // Only <li> is a valid child of a list; drop stray <br>/whitespace so the
12546
- // import doesn't wrap them into an empty leading item.
12569
+ // Only <li> is a valid child of a list. Unwrap remaining stray children
12570
+ // that still hold list items (a nested list with no preceding <li> to nest
12571
+ // under) so the items survive, and drop stray <br>/whitespace so the import
12572
+ // doesn't wrap them into an empty leading item.
12547
12573
  #stripStrayListChildren() {
12548
12574
  for (const list of this.doc.querySelectorAll("ol, ul")) {
12549
- for (const child of Array.from(list.childNodes)) {
12550
- if (child.nodeType === Node.ELEMENT_NODE && child.tagName === "LI") continue
12551
- list.removeChild(child);
12575
+ let stray = this.#firstStrayListChild(list);
12576
+ while (stray) {
12577
+ if (this.#containsListItems(stray)) {
12578
+ stray.replaceWith(...stray.childNodes);
12579
+ } else {
12580
+ stray.remove();
12581
+ }
12582
+
12583
+ stray = this.#firstStrayListChild(list);
12584
+ }
12585
+ }
12586
+ }
12587
+
12588
+ #firstStrayListChild(list) {
12589
+ for (const child of list.childNodes) {
12590
+ if (child.nodeType !== Node.ELEMENT_NODE || child.tagName !== "LI") {
12591
+ return child
12552
12592
  }
12553
12593
  }
12594
+ return null
12595
+ }
12596
+
12597
+ #isNestedList(node) {
12598
+ return node.nodeType === Node.ELEMENT_NODE && (node.tagName === "OL" || node.tagName === "UL")
12599
+ }
12600
+
12601
+ #containsListItems(node) {
12602
+ return node.nodeType === Node.ELEMENT_NODE && node.querySelector("li") !== null
12554
12603
  }
12555
12604
  }
12556
12605
 
Binary file
Binary file