@anweb/nuxt-aneditor 0.1.6 → 0.1.7
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/module.json
CHANGED
|
@@ -57,6 +57,7 @@ const resetTypingStyle = () => {
|
|
|
57
57
|
if (!refContent.value) return;
|
|
58
58
|
const text = refContent.value.textContent ?? "";
|
|
59
59
|
if (text.trim()) return;
|
|
60
|
+
if (refContent.value.querySelector("figure, table, pre, hr, .an-editor__youtube, .an-editor__html")) return;
|
|
60
61
|
wasEmpty = true;
|
|
61
62
|
const inlines = refContent.value.querySelectorAll("strong, em, s, b, i, u, span:not([class])");
|
|
62
63
|
for (const el of inlines) {
|
|
@@ -513,37 +514,68 @@ const onKeydown = (e) => {
|
|
|
513
514
|
}
|
|
514
515
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
515
516
|
const sel = selection.getSelection();
|
|
516
|
-
if (sel)
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
517
|
+
if (!sel) return;
|
|
518
|
+
let node = sel.range.commonAncestorContainer;
|
|
519
|
+
if (node.nodeType === Node.TEXT_NODE) node = node.parentNode;
|
|
520
|
+
const el = node;
|
|
521
|
+
const cell = el?.closest?.("td, th");
|
|
522
|
+
if (cell && refContent.value?.contains(cell)) {
|
|
523
|
+
e.preventDefault();
|
|
524
|
+
const br = document.createElement("br");
|
|
525
|
+
sel.range.deleteContents();
|
|
526
|
+
sel.range.insertNode(br);
|
|
527
|
+
sel.range.setStartAfter(br);
|
|
528
|
+
sel.range.collapse(true);
|
|
529
|
+
sel.selection.removeAllRanges();
|
|
530
|
+
sel.selection.addRange(sel.range);
|
|
531
|
+
syncToModel();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (el?.closest?.("pre") && refContent.value?.contains(el)) return;
|
|
535
|
+
if (el?.closest?.("li") && refContent.value?.contains(el)) return;
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
if (!sel.range.collapsed) sel.range.deleteContents();
|
|
538
|
+
let block = sel.range.commonAncestorContainer;
|
|
539
|
+
if (block?.nodeType === Node.TEXT_NODE) block = block.parentNode;
|
|
540
|
+
while (block && block.parentNode !== refContent.value) {
|
|
541
|
+
block = block.parentNode;
|
|
542
|
+
}
|
|
543
|
+
const newP = document.createElement("p");
|
|
544
|
+
if (!block || block === refContent.value) {
|
|
545
|
+
newP.innerHTML = "<br>";
|
|
546
|
+
refContent.value.appendChild(newP);
|
|
547
|
+
} else {
|
|
548
|
+
const blockEl = block;
|
|
549
|
+
const tag = blockEl.tagName;
|
|
550
|
+
const isNonSplittable = tag === "FIGURE" || tag === "HR" || /^H[1-6]$/.test(tag) || blockEl.classList?.contains("an-editor__youtube") || blockEl.classList?.contains("an-editor__html");
|
|
551
|
+
if (isNonSplittable) {
|
|
552
|
+
newP.innerHTML = "<br>";
|
|
553
|
+
block.parentNode.insertBefore(newP, block);
|
|
554
|
+
} else {
|
|
555
|
+
const splitRange = document.createRange();
|
|
556
|
+
splitRange.setStart(sel.range.startContainer, sel.range.startOffset);
|
|
557
|
+
if (blockEl.lastChild) {
|
|
558
|
+
splitRange.setEndAfter(blockEl.lastChild);
|
|
559
|
+
} else {
|
|
560
|
+
splitRange.setEnd(blockEl, 0);
|
|
561
|
+
}
|
|
562
|
+
const afterContent = splitRange.extractContents();
|
|
563
|
+
newP.appendChild(afterContent);
|
|
564
|
+
if (!newP.textContent?.trim() && !newP.querySelector("img")) {
|
|
565
|
+
newP.innerHTML = "<br>";
|
|
566
|
+
}
|
|
567
|
+
block.parentNode.insertBefore(newP, block.nextSibling);
|
|
568
|
+
if (!blockEl.textContent?.trim() && !blockEl.querySelector("img")) {
|
|
569
|
+
blockEl.innerHTML = "<br>";
|
|
570
|
+
}
|
|
545
571
|
}
|
|
546
572
|
}
|
|
573
|
+
const newRange = document.createRange();
|
|
574
|
+
newRange.setStart(newP, 0);
|
|
575
|
+
newRange.collapse(true);
|
|
576
|
+
sel.selection.removeAllRanges();
|
|
577
|
+
sel.selection.addRange(newRange);
|
|
578
|
+
syncToModel();
|
|
547
579
|
}
|
|
548
580
|
};
|
|
549
581
|
const updateActiveFormats = () => {
|