@37signals/lexxy 0.1.17-beta → 0.1.18-beta
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/dist/lexxy.esm.js +23 -11
- package/package.json +1 -1
package/dist/lexxy.esm.js
CHANGED
|
@@ -2288,10 +2288,10 @@ class Contents {
|
|
|
2288
2288
|
const selection = $getSelection();
|
|
2289
2289
|
if (!$isRangeSelection(selection)) return
|
|
2290
2290
|
|
|
2291
|
-
const topLevelElement = selection.anchor.getNode().
|
|
2291
|
+
const topLevelElement = selection.anchor.getNode().getTopLevelElement();
|
|
2292
2292
|
|
|
2293
2293
|
// Check if format is already applied
|
|
2294
|
-
if (isFormatAppliedFn(topLevelElement)) {
|
|
2294
|
+
if (topLevelElement && isFormatAppliedFn(topLevelElement)) {
|
|
2295
2295
|
this.#unwrap(topLevelElement);
|
|
2296
2296
|
} else {
|
|
2297
2297
|
this.#insertNodeWrappingAllSelectedNodes(newNodeFn);
|
|
@@ -2521,10 +2521,7 @@ class Contents {
|
|
|
2521
2521
|
const node = $getNodeByKey(nodeKey);
|
|
2522
2522
|
if (!node) return
|
|
2523
2523
|
|
|
2524
|
-
|
|
2525
|
-
try {
|
|
2526
|
-
previousNode = node.getTopLevelElementOrThrow();
|
|
2527
|
-
} catch {}
|
|
2524
|
+
const previousNode = node.getTopLevelElement() || node;
|
|
2528
2525
|
|
|
2529
2526
|
const newNode = options.attachment ? this.#createCustomAttachmentNodeWithHtml(html, options.attachment) : this.#createHtmlNodeWith(html);
|
|
2530
2527
|
previousNode.insertAfter(newNode);
|
|
@@ -2551,16 +2548,21 @@ class Contents {
|
|
|
2551
2548
|
if (!$isRangeSelection(selection)) return
|
|
2552
2549
|
|
|
2553
2550
|
const selectedNodes = selection.extract();
|
|
2554
|
-
if (selectedNodes.length === 0)
|
|
2555
|
-
|
|
2551
|
+
if (selectedNodes.length === 0) {
|
|
2552
|
+
return
|
|
2553
|
+
}
|
|
2556
2554
|
const topLevelElements = new Set();
|
|
2557
2555
|
selectedNodes.forEach((node) => {
|
|
2558
2556
|
const topLevel = node.getTopLevelElementOrThrow();
|
|
2559
2557
|
topLevelElements.add(topLevel);
|
|
2560
2558
|
});
|
|
2561
2559
|
|
|
2562
|
-
const elements = this.#
|
|
2563
|
-
if (elements.length === 0)
|
|
2560
|
+
const elements = this.#withoutTrailingEmptyParagraphs(Array.from(topLevelElements));
|
|
2561
|
+
if (elements.length === 0) {
|
|
2562
|
+
this.#removeStandaloneEmptyParagraph();
|
|
2563
|
+
this.insertAtCursor(newNodeFn());
|
|
2564
|
+
return
|
|
2565
|
+
}
|
|
2564
2566
|
|
|
2565
2567
|
const wrappingNode = newNodeFn();
|
|
2566
2568
|
elements[0].insertBefore(wrappingNode);
|
|
@@ -2572,7 +2574,7 @@ class Contents {
|
|
|
2572
2574
|
});
|
|
2573
2575
|
}
|
|
2574
2576
|
|
|
2575
|
-
#
|
|
2577
|
+
#withoutTrailingEmptyParagraphs(elements) {
|
|
2576
2578
|
let lastNonEmptyIndex = elements.length - 1;
|
|
2577
2579
|
|
|
2578
2580
|
// Find the last non-empty paragraph
|
|
@@ -2596,6 +2598,16 @@ class Contents {
|
|
|
2596
2598
|
return children.length === 0 || children.every(child => $isLineBreakNode(child))
|
|
2597
2599
|
}
|
|
2598
2600
|
|
|
2601
|
+
#removeStandaloneEmptyParagraph() {
|
|
2602
|
+
const root = $getRoot();
|
|
2603
|
+
if (root.getChildrenSize() === 1) {
|
|
2604
|
+
const firstChild = root.getFirstChild();
|
|
2605
|
+
if (firstChild && $isParagraphNode(firstChild) && this.#isElementEmpty(firstChild)) {
|
|
2606
|
+
firstChild.remove();
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2599
2611
|
#insertNodeWrappingAllSelectedLines(newNodeFn) {
|
|
2600
2612
|
this.editor.update(() => {
|
|
2601
2613
|
const selection = $getSelection();
|