autumnnote 1.6.3 → 1.6.6
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/autumnnote.es.js +133 -119
- package/dist/autumnnote.es.js.map +1 -1
- package/dist/autumnnote.umd.js +131 -117
- package/dist/autumnnote.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/js/Context.js +4 -4
- package/src/js/core/detectLang.js +1 -1
- package/src/js/core/dom.js +6 -8
- package/src/js/core/markdown.js +2 -2
- package/src/js/core/range.js +1 -1
- package/src/js/editing/History.js +2 -2
- package/src/js/editing/Style.js +17 -15
- package/src/js/editing/Typing.js +7 -7
- package/src/js/index.js +1 -1
- package/src/js/module/AutoSaveRestore.js +3 -2
- package/src/js/module/BaseDialog.js +1 -1
- package/src/js/module/BubbleToolbar.js +3 -3
- package/src/js/module/Buttons.js +8 -8
- package/src/js/module/Clipboard.js +4 -4
- package/src/js/module/CodeTooltip.js +1 -1
- package/src/js/module/ContextMenu.js +14 -12
- package/src/js/module/Editor.js +10 -10
- package/src/js/module/EmojiDialog.js +1 -1
- package/src/js/module/FindReplace.js +6 -7
- package/src/js/module/IconDialog.js +2 -2
- package/src/js/module/ImageCropOverlay.js +2 -1
- package/src/js/module/ImageDialog.js +3 -3
- package/src/js/module/ImageResizer.js +3 -3
- package/src/js/module/ImageTooltip.js +5 -3
- package/src/js/module/LinkDialog.js +1 -1
- package/src/js/module/LinkTooltip.js +3 -3
- package/src/js/module/Mention.js +3 -3
- package/src/js/module/TableTooltip.js +57 -39
- package/src/js/module/Toolbar.js +21 -20
- package/src/js/module/VideoDialog.js +5 -2
- package/src/js/renderer.js +2 -2
package/dist/autumnnote.umd.js
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
return val !== null && typeof val === "object" && !Array.isArray(val);
|
|
43
43
|
}
|
|
44
44
|
/** @param {Node} node */
|
|
45
|
-
var isElement = (node) => node
|
|
45
|
+
var isElement = (node) => node?.nodeType === 1;
|
|
46
46
|
/** @param {Node} node */
|
|
47
47
|
var isPara = (node) => isElement(node) && /^(p|div|li|h[1-6]|blockquote|td|th|pre)$/i.test(node.nodeName);
|
|
48
48
|
/** @param {Node} node */
|
|
@@ -321,7 +321,7 @@
|
|
|
321
321
|
*/
|
|
322
322
|
function underline() {
|
|
323
323
|
const sel = globalThis.getSelection();
|
|
324
|
-
if (!sel
|
|
324
|
+
if (!sel?.rangeCount) return;
|
|
325
325
|
let container = sel.getRangeAt(0).commonAncestorContainer;
|
|
326
326
|
if (container.nodeType === 3) container = container.parentElement;
|
|
327
327
|
const uEl = container?.closest("u");
|
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
*/
|
|
342
342
|
function strikethrough() {
|
|
343
343
|
const sel = globalThis.getSelection();
|
|
344
|
-
if (!sel
|
|
344
|
+
if (!sel?.rangeCount) return;
|
|
345
345
|
let sc = sel.getRangeAt(0).startContainer;
|
|
346
346
|
if (sc.nodeType === 3) sc = sc.parentElement;
|
|
347
347
|
const sEl = sc?.closest("s") || sc?.closest("strike");
|
|
@@ -385,8 +385,8 @@
|
|
|
385
385
|
*/
|
|
386
386
|
function fontSize(size, editable = document) {
|
|
387
387
|
const sel = globalThis.getSelection();
|
|
388
|
-
const wasCollapsed = !sel
|
|
389
|
-
if (wasCollapsed && sel
|
|
388
|
+
const wasCollapsed = !sel?.rangeCount || sel.getRangeAt(0).collapsed;
|
|
389
|
+
if (wasCollapsed && sel?.rangeCount > 0) {
|
|
390
390
|
try {
|
|
391
391
|
const range = sel.getRangeAt(0);
|
|
392
392
|
const span = document.createElement("span");
|
|
@@ -460,7 +460,7 @@
|
|
|
460
460
|
*/
|
|
461
461
|
function outdent() {
|
|
462
462
|
const sel = globalThis.getSelection();
|
|
463
|
-
if (sel
|
|
463
|
+
if (sel?.rangeCount) {
|
|
464
464
|
let container = sel.getRangeAt(0).commonAncestorContainer;
|
|
465
465
|
if (container.nodeType === 3) container = container.parentElement;
|
|
466
466
|
const checkLi = container?.closest(".an-checklist li");
|
|
@@ -510,7 +510,7 @@
|
|
|
510
510
|
try {
|
|
511
511
|
const nr = document.createRange();
|
|
512
512
|
const firstChild = p.firstChild;
|
|
513
|
-
nr.setStart(firstChild
|
|
513
|
+
nr.setStart(firstChild?.nodeType === 3 ? firstChild : p, 0);
|
|
514
514
|
nr.collapse(true);
|
|
515
515
|
const s = globalThis.getSelection();
|
|
516
516
|
if (s) {
|
|
@@ -589,7 +589,7 @@
|
|
|
589
589
|
*/
|
|
590
590
|
function toggleInlineCode(_editable) {
|
|
591
591
|
const sel = globalThis.getSelection();
|
|
592
|
-
if (!sel
|
|
592
|
+
if (!sel?.rangeCount) return;
|
|
593
593
|
const range = sel.getRangeAt(0);
|
|
594
594
|
let container = range.commonAncestorContainer;
|
|
595
595
|
if (container.nodeType === 3) container = container.parentElement;
|
|
@@ -645,7 +645,7 @@
|
|
|
645
645
|
*/
|
|
646
646
|
function isInlineCode() {
|
|
647
647
|
const sel = globalThis.getSelection();
|
|
648
|
-
if (!sel
|
|
648
|
+
if (!sel?.rangeCount) return false;
|
|
649
649
|
let sc = sel.getRangeAt(0).startContainer;
|
|
650
650
|
if (sc.nodeType === 3) sc = sc.parentElement;
|
|
651
651
|
const code = sc?.closest("code");
|
|
@@ -667,7 +667,7 @@
|
|
|
667
667
|
*/
|
|
668
668
|
function toggleChecklist() {
|
|
669
669
|
const sel = globalThis.getSelection();
|
|
670
|
-
if (!sel
|
|
670
|
+
if (!sel?.rangeCount) return;
|
|
671
671
|
const range = sel.getRangeAt(0);
|
|
672
672
|
let container = range.commonAncestorContainer;
|
|
673
673
|
if (container.nodeType === 3) container = container.parentElement;
|
|
@@ -716,7 +716,7 @@
|
|
|
716
716
|
"LI"
|
|
717
717
|
]);
|
|
718
718
|
let block = container;
|
|
719
|
-
while (block
|
|
719
|
+
while (block?.parentNode && !BLOCK_TAGS.has(block.tagName)) block = block.parentNode;
|
|
720
720
|
const itemText = block && BLOCK_TAGS.has(block.tagName) ? Array.from(block.childNodes).map((n) => n.textContent).join("").replaceAll("\xA0", " ") : "";
|
|
721
721
|
const ul = document.createElement("ul");
|
|
722
722
|
ul.className = "an-checklist";
|
|
@@ -803,7 +803,7 @@
|
|
|
803
803
|
*/
|
|
804
804
|
function isInChecklist() {
|
|
805
805
|
const sel = globalThis.getSelection();
|
|
806
|
-
if (!sel
|
|
806
|
+
if (!sel?.rangeCount) return false;
|
|
807
807
|
let container = sel.getRangeAt(0).commonAncestorContainer;
|
|
808
808
|
if (container.nodeType === 3) container = container.parentElement;
|
|
809
809
|
return !!container?.closest(".an-checklist li");
|
|
@@ -889,10 +889,10 @@
|
|
|
889
889
|
var underlineBtn = btn("underline", "underline", "Underline (Ctrl+U)", () => underline(), () => {
|
|
890
890
|
if (document.queryCommandState("underline")) return true;
|
|
891
891
|
const sel = globalThis.getSelection();
|
|
892
|
-
if (!sel
|
|
892
|
+
if (!sel?.rangeCount) return false;
|
|
893
893
|
let sc = sel.getRangeAt(0).startContainer;
|
|
894
894
|
if (sc.nodeType === 3) sc = sc.parentElement;
|
|
895
|
-
return !!
|
|
895
|
+
return !!sc?.closest("u");
|
|
896
896
|
});
|
|
897
897
|
var strikeBtn = btn("strikethrough", "strikethrough", "Strikethrough", () => strikethrough(), () => document.queryCommandState("strikeThrough"));
|
|
898
898
|
var superscriptBtn = btn("superscript", "superscript", "Superscript", () => superscript(), () => document.queryCommandState("superscript"));
|
|
@@ -952,11 +952,11 @@
|
|
|
952
952
|
getValue: (ctx) => {
|
|
953
953
|
try {
|
|
954
954
|
const sel = globalThis.getSelection();
|
|
955
|
-
if (sel
|
|
955
|
+
if (sel?.rangeCount) {
|
|
956
956
|
let el = sel.getRangeAt(0).startContainer;
|
|
957
|
-
if (el
|
|
958
|
-
while (el
|
|
959
|
-
const size = el
|
|
957
|
+
if (el?.nodeType === 3) el = el.parentElement;
|
|
958
|
+
while (el?.nodeType === 1 && !el.style.fontSize) el = el.parentElement;
|
|
959
|
+
const size = el?.style.fontSize || "";
|
|
960
960
|
if (size) return size;
|
|
961
961
|
}
|
|
962
962
|
const editable = ctx?.layoutInfo?.editable;
|
|
@@ -1057,7 +1057,7 @@
|
|
|
1057
1057
|
getValue: () => {
|
|
1058
1058
|
try {
|
|
1059
1059
|
const sel = globalThis.getSelection();
|
|
1060
|
-
if (!sel
|
|
1060
|
+
if (!sel?.rangeCount) return "";
|
|
1061
1061
|
const BLOCKS = new Set([
|
|
1062
1062
|
"P",
|
|
1063
1063
|
"DIV",
|
|
@@ -1074,7 +1074,7 @@
|
|
|
1074
1074
|
"TH"
|
|
1075
1075
|
]);
|
|
1076
1076
|
let el = sel.getRangeAt(0).startContainer;
|
|
1077
|
-
if (el
|
|
1077
|
+
if (el?.nodeType === 3) el = el.parentElement;
|
|
1078
1078
|
while (el && !BLOCKS.has(
|
|
1079
1079
|
/** @type {Element} */
|
|
1080
1080
|
el.tagName
|
|
@@ -4199,7 +4199,7 @@
|
|
|
4199
4199
|
}
|
|
4200
4200
|
if (options.focusColor) container.style.setProperty("--an-focus-color", options.focusColor);
|
|
4201
4201
|
targetEl.style.display = "none";
|
|
4202
|
-
targetEl.
|
|
4202
|
+
targetEl.after(container);
|
|
4203
4203
|
return {
|
|
4204
4204
|
container,
|
|
4205
4205
|
editable
|
|
@@ -4602,7 +4602,7 @@
|
|
|
4602
4602
|
icon.remove();
|
|
4603
4603
|
textNode.remove();
|
|
4604
4604
|
const nr = document.createRange();
|
|
4605
|
-
if (prevNode
|
|
4605
|
+
if (prevNode?.nodeType === Node.TEXT_NODE) nr.setStart(prevNode, prevNode.textContent.length);
|
|
4606
4606
|
else if (prevNode) nr.setStartAfter(prevNode);
|
|
4607
4607
|
else if (parent) nr.setStart(parent, 0);
|
|
4608
4608
|
nr.collapse(true);
|
|
@@ -4639,7 +4639,7 @@
|
|
|
4639
4639
|
const icon = textNode.nextSibling;
|
|
4640
4640
|
const after = icon.nextSibling;
|
|
4641
4641
|
event.preventDefault();
|
|
4642
|
-
if (after
|
|
4642
|
+
if (after?.nodeType === Node.TEXT_NODE) {
|
|
4643
4643
|
const offset = (after.textContent || "").startsWith("") ? 1 : 0;
|
|
4644
4644
|
return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
|
|
4645
4645
|
}
|
|
@@ -4649,7 +4649,7 @@
|
|
|
4649
4649
|
const icon = textNode.nextSibling.nextSibling;
|
|
4650
4650
|
const after = icon.nextSibling;
|
|
4651
4651
|
event.preventDefault();
|
|
4652
|
-
if (after
|
|
4652
|
+
if (after?.nodeType === Node.TEXT_NODE) {
|
|
4653
4653
|
const offset = (after.textContent || "").startsWith("") ? 1 : 0;
|
|
4654
4654
|
return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
|
|
4655
4655
|
}
|
|
@@ -4674,7 +4674,7 @@
|
|
|
4674
4674
|
if (isFAIcon(next)) {
|
|
4675
4675
|
const after = next.nextSibling;
|
|
4676
4676
|
event.preventDefault();
|
|
4677
|
-
if (after
|
|
4677
|
+
if (after?.nodeType === Node.TEXT_NODE) {
|
|
4678
4678
|
const offset = (after.textContent || "").startsWith("") ? 1 : 0;
|
|
4679
4679
|
return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
|
|
4680
4680
|
}
|
|
@@ -4684,7 +4684,7 @@
|
|
|
4684
4684
|
const icon = next.nextSibling;
|
|
4685
4685
|
const after = icon.nextSibling;
|
|
4686
4686
|
event.preventDefault();
|
|
4687
|
-
if (after
|
|
4687
|
+
if (after?.nodeType === Node.TEXT_NODE) {
|
|
4688
4688
|
const offset = (after.textContent || "").startsWith("") ? 1 : 0;
|
|
4689
4689
|
return moveCaret((nr) => nr.setStart(after, Math.min(offset, after.textContent.length)));
|
|
4690
4690
|
}
|
|
@@ -4786,11 +4786,11 @@
|
|
|
4786
4786
|
newLi.appendChild(cb);
|
|
4787
4787
|
if (afterFrag.textContent.replace(/[\u00a0\u200B]/g, "").length > 0) newLi.appendChild(afterFrag);
|
|
4788
4788
|
let cursorNode = newLi.childNodes[1];
|
|
4789
|
-
if (
|
|
4789
|
+
if (cursorNode?.nodeType !== Node.TEXT_NODE) {
|
|
4790
4790
|
cursorNode = document.createTextNode("");
|
|
4791
4791
|
newLi.appendChild(cursorNode);
|
|
4792
4792
|
}
|
|
4793
|
-
checkLi.
|
|
4793
|
+
checkLi.after(newLi);
|
|
4794
4794
|
const nr = document.createRange();
|
|
4795
4795
|
nr.setStart(cursorNode, 0);
|
|
4796
4796
|
nr.collapse(true);
|
|
@@ -4878,7 +4878,7 @@
|
|
|
4878
4878
|
return `\`${inner()}\``;
|
|
4879
4879
|
case "pre": {
|
|
4880
4880
|
const codeEl = el.querySelector("code");
|
|
4881
|
-
const langMatch = /language-(\S+)/.exec(codeEl
|
|
4881
|
+
const langMatch = /language-(\S+)/.exec(codeEl?.className || "");
|
|
4882
4882
|
return `\n\n\`\`\`${langMatch ? langMatch[1] : ""}\n${(codeEl || el).textContent || ""}\n\`\`\`\n\n`;
|
|
4883
4883
|
}
|
|
4884
4884
|
case "blockquote": return `\n\n${inner().trim().split("\n").map((l) => `> ${l}`).join("\n")}\n\n`;
|
|
@@ -4909,7 +4909,7 @@
|
|
|
4909
4909
|
case "table": {
|
|
4910
4910
|
const rows = Array.from(el.querySelectorAll("tr"));
|
|
4911
4911
|
if (!rows.length) return inner();
|
|
4912
|
-
const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replaceAll("|",
|
|
4912
|
+
const cellTexts = rows.map((tr) => Array.from(tr.querySelectorAll("th, td")).map((c) => c.textContent.trim().replaceAll("|", String.raw`\|`)));
|
|
4913
4913
|
const cols = Math.max(...cellTexts.map((r) => r.length));
|
|
4914
4914
|
const padRow = (row) => {
|
|
4915
4915
|
const r = [...row];
|
|
@@ -5072,7 +5072,7 @@
|
|
|
5072
5072
|
* @returns {string|null}
|
|
5073
5073
|
*/
|
|
5074
5074
|
function detectLang(code) {
|
|
5075
|
-
if (!code
|
|
5075
|
+
if (!code?.trim()) return null;
|
|
5076
5076
|
const s = code.trim();
|
|
5077
5077
|
if (/(:\s*(string|number|boolean|void|never|any|unknown)\b|interface\s+\w+\s*\{|type\s+\w+\s*[=<(]|<\w+>\s*[;,)]|readonly\s+\w|enum\s+\w+\s*\{|\?\s*:\s*\w|as\s+\w+\s*[;,)\]])/.test(s)) return "typescript";
|
|
5078
5078
|
if (/\bprintln!\s*\(|\bprint!\s*\(|\bfn\s+\w+\s*(<[^>]*>)?\s*\(|\blet\s+mut\s|\bpub\s+fn\s|\buse\s+std::|\bimpl\s+\w+|\bOption<|\bResult<\w+/.test(s)) return "rust";
|
|
@@ -5136,7 +5136,7 @@
|
|
|
5136
5136
|
const onSelChange = () => {
|
|
5137
5137
|
if (!this.context._alive) return;
|
|
5138
5138
|
const sel = globalThis.getSelection();
|
|
5139
|
-
if (sel
|
|
5139
|
+
if (sel?.rangeCount > 0 && editable.contains(sel.anchorNode)) {
|
|
5140
5140
|
this.context.invoke("toolbar.refresh");
|
|
5141
5141
|
if (typeof this.options.onSelectionChange === "function") this.options.onSelectionChange(this.context);
|
|
5142
5142
|
}
|
|
@@ -5146,7 +5146,7 @@
|
|
|
5146
5146
|
};
|
|
5147
5147
|
const fixChecklistCursor = (event) => {
|
|
5148
5148
|
const sel = globalThis.getSelection();
|
|
5149
|
-
if (!sel
|
|
5149
|
+
if (!sel?.rangeCount) return;
|
|
5150
5150
|
const r = sel.getRangeAt(0);
|
|
5151
5151
|
if (!r.collapsed) return;
|
|
5152
5152
|
const sc = r.startContainer;
|
|
@@ -5156,7 +5156,7 @@
|
|
|
5156
5156
|
if (!li) return;
|
|
5157
5157
|
const cb = li.querySelector("input[type=\"checkbox\"]");
|
|
5158
5158
|
if (!cb) return;
|
|
5159
|
-
if (event
|
|
5159
|
+
if (event?.type === "mouseup") {
|
|
5160
5160
|
let caret = null;
|
|
5161
5161
|
if (document.caretRangeFromPoint) caret = document.caretRangeFromPoint(event.clientX, event.clientY);
|
|
5162
5162
|
else if (document.caretPositionFromPoint) {
|
|
@@ -5200,7 +5200,7 @@
|
|
|
5200
5200
|
let _compositionSupSub = null;
|
|
5201
5201
|
const onCompositionStart = () => {
|
|
5202
5202
|
const sel = globalThis.getSelection();
|
|
5203
|
-
if (!sel
|
|
5203
|
+
if (!sel?.rangeCount) {
|
|
5204
5204
|
_compositionSupSub = null;
|
|
5205
5205
|
return;
|
|
5206
5206
|
}
|
|
@@ -5218,7 +5218,7 @@
|
|
|
5218
5218
|
_compositionSupSub = null;
|
|
5219
5219
|
if (!tag) return;
|
|
5220
5220
|
const sel = globalThis.getSelection();
|
|
5221
|
-
if (!sel
|
|
5221
|
+
if (!sel?.rangeCount) return;
|
|
5222
5222
|
let node = sel.getRangeAt(0).startContainer;
|
|
5223
5223
|
if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
|
|
5224
5224
|
const el = node;
|
|
@@ -5552,7 +5552,7 @@
|
|
|
5552
5552
|
formatBlock(tagName);
|
|
5553
5553
|
if (tagName === "pre") {
|
|
5554
5554
|
const sel = globalThis.getSelection();
|
|
5555
|
-
if (sel
|
|
5555
|
+
if (sel?.rangeCount > 0) {
|
|
5556
5556
|
const container = sel.getRangeAt(0).commonAncestorContainer;
|
|
5557
5557
|
const pre = container.nodeType === 1 ? container.closest("pre") : container.parentElement?.closest("pre");
|
|
5558
5558
|
if (pre && !pre.dataset.language) {
|
|
@@ -5612,10 +5612,7 @@
|
|
|
5612
5612
|
if (!sel || sel.rangeCount === 0) return;
|
|
5613
5613
|
const safeUrl = sanitiseUrl(url);
|
|
5614
5614
|
if (!safeUrl) return;
|
|
5615
|
-
if (
|
|
5616
|
-
const displayText = this._escapeAttr(text || safeUrl);
|
|
5617
|
-
execCommand("insertHTML", `<a href="${this._escapeAttr(safeUrl)}"${openInNewTab ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${displayText}</a>`);
|
|
5618
|
-
} else {
|
|
5615
|
+
if (sel.toString().trim().length > 0) {
|
|
5619
5616
|
execCommand("createLink", safeUrl);
|
|
5620
5617
|
if (openInNewTab) {
|
|
5621
5618
|
const link = this._getClosestAnchor();
|
|
@@ -5624,6 +5621,9 @@
|
|
|
5624
5621
|
/** @type {Element} */ link.setAttribute("rel", "noopener noreferrer");
|
|
5625
5622
|
}
|
|
5626
5623
|
}
|
|
5624
|
+
} else {
|
|
5625
|
+
const displayText = this._escapeAttr(text || safeUrl);
|
|
5626
|
+
execCommand("insertHTML", `<a href="${this._escapeAttr(safeUrl)}"${openInNewTab ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${displayText}</a>`);
|
|
5627
5627
|
}
|
|
5628
5628
|
this.afterCommand();
|
|
5629
5629
|
}
|
|
@@ -5801,7 +5801,7 @@
|
|
|
5801
5801
|
this._refreshRaf = null;
|
|
5802
5802
|
this._disposers.forEach((d) => d());
|
|
5803
5803
|
this._disposers = [];
|
|
5804
|
-
if (this.el
|
|
5804
|
+
if (this.el?.parentNode) this.el.remove();
|
|
5805
5805
|
this.el = null;
|
|
5806
5806
|
}
|
|
5807
5807
|
_buildButtons() {
|
|
@@ -6012,7 +6012,7 @@
|
|
|
6012
6012
|
let savedRange = null;
|
|
6013
6013
|
const saveSelection = () => {
|
|
6014
6014
|
const sel = globalThis.getSelection();
|
|
6015
|
-
savedRange = sel
|
|
6015
|
+
savedRange = sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
|
|
6016
6016
|
};
|
|
6017
6017
|
const restoreSelection = () => {
|
|
6018
6018
|
if (!savedRange) return;
|
|
@@ -6130,7 +6130,10 @@
|
|
|
6130
6130
|
select.appendChild(placeholder);
|
|
6131
6131
|
items.forEach((item) => {
|
|
6132
6132
|
const value = typeof item === "object" ? item.value : item;
|
|
6133
|
-
|
|
6133
|
+
let label;
|
|
6134
|
+
if (typeof item !== "object") label = item;
|
|
6135
|
+
else if (def.name === "paragraphStyle") label = this.context.locale.toolbar.paragraphItems?.[item.value] || item.label;
|
|
6136
|
+
else label = item.label;
|
|
6134
6137
|
const isHeader = typeof item === "object" && !!item.disabled;
|
|
6135
6138
|
const attrs = { value };
|
|
6136
6139
|
if (isHeader) attrs.disabled = "";
|
|
@@ -6142,7 +6145,7 @@
|
|
|
6142
6145
|
let _savedRange = null;
|
|
6143
6146
|
const dMousedown = on(select, "mousedown", () => {
|
|
6144
6147
|
const sel = globalThis.getSelection();
|
|
6145
|
-
_savedRange = sel
|
|
6148
|
+
_savedRange = sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null;
|
|
6146
6149
|
});
|
|
6147
6150
|
const disposer = on(select, "change", (e) => {
|
|
6148
6151
|
const value = e.target.value;
|
|
@@ -6230,9 +6233,9 @@
|
|
|
6230
6233
|
);
|
|
6231
6234
|
if (!def || typeof def.getValue !== "function") return;
|
|
6232
6235
|
let raw = (def.getValue(this.context) || "").replace(/["']/g, "").trim();
|
|
6233
|
-
if (!raw) raw = this.options.defaultFontFamily || this.options.fontFamilies
|
|
6236
|
+
if (!raw) raw = this.options.defaultFontFamily || this.options.fontFamilies?.[0] || "";
|
|
6234
6237
|
const sel = select;
|
|
6235
|
-
const matched = Array.from(sel.options).find((opt) => opt.value
|
|
6238
|
+
const matched = Array.from(sel.options).find((opt) => opt.value?.toLowerCase() === raw.toLowerCase());
|
|
6236
6239
|
sel.value = matched ? matched.value : "";
|
|
6237
6240
|
});
|
|
6238
6241
|
}
|
|
@@ -6491,7 +6494,7 @@
|
|
|
6491
6494
|
* @param {Node} node
|
|
6492
6495
|
*/
|
|
6493
6496
|
_revokeRemovedBlobs(node) {
|
|
6494
|
-
if (!this._blobRegistry
|
|
6497
|
+
if (!this._blobRegistry?.size) return;
|
|
6495
6498
|
const imgs = [];
|
|
6496
6499
|
if (node.nodeName === "IMG") imgs.push(node);
|
|
6497
6500
|
else if (node.querySelectorAll) imgs.push(...node.querySelectorAll("img"));
|
|
@@ -6629,7 +6632,7 @@
|
|
|
6629
6632
|
}
|
|
6630
6633
|
_onDrop(event) {
|
|
6631
6634
|
const dt = event.dataTransfer;
|
|
6632
|
-
if (!dt
|
|
6635
|
+
if (!dt?.files?.length) return;
|
|
6633
6636
|
const imageFiles = Array.from(dt.files).filter((f) => f.type.startsWith("image/"));
|
|
6634
6637
|
if (imageFiles.length === 0) return;
|
|
6635
6638
|
event.preventDefault();
|
|
@@ -6658,7 +6661,7 @@
|
|
|
6658
6661
|
]);
|
|
6659
6662
|
const maxBytes = (this.options.maxImageSize || 5) * 1024 * 1024;
|
|
6660
6663
|
files.forEach((file) => {
|
|
6661
|
-
if (!file
|
|
6664
|
+
if (!file?.type?.startsWith("image/")) return;
|
|
6662
6665
|
if (UNSUPPORTED.has(file.type)) {
|
|
6663
6666
|
const message = `Image format "${file.type}" is not supported for display in web browsers. Please convert to PNG, JPEG, or WebP first.`;
|
|
6664
6667
|
this.context.triggerEvent("imageError", {
|
|
@@ -6701,7 +6704,7 @@
|
|
|
6701
6704
|
* @returns {string}
|
|
6702
6705
|
*/
|
|
6703
6706
|
resolveImages(html) {
|
|
6704
|
-
if (!this._blobRegistry
|
|
6707
|
+
if (!this._blobRegistry?.size) return html;
|
|
6705
6708
|
return html.replace(/blob:[^"'> \t\n\r]*/g, (url) => this._blobRegistry.get(url) || url);
|
|
6706
6709
|
}
|
|
6707
6710
|
/**
|
|
@@ -7017,7 +7020,7 @@
|
|
|
7017
7020
|
if (this._dialog) {
|
|
7018
7021
|
this._dialog.style.display = "flex";
|
|
7019
7022
|
this._removeTrap = trapFocus(this._dialog, () => this._close());
|
|
7020
|
-
setTimeout(() => this._firstInput
|
|
7023
|
+
setTimeout(() => this._firstInput?.focus(), 50);
|
|
7021
7024
|
}
|
|
7022
7025
|
}
|
|
7023
7026
|
_close() {
|
|
@@ -7163,7 +7166,7 @@
|
|
|
7163
7166
|
_prefill() {
|
|
7164
7167
|
const sel = globalThis.getSelection();
|
|
7165
7168
|
let anchor = null;
|
|
7166
|
-
if (sel
|
|
7169
|
+
if (sel?.rangeCount > 0) {
|
|
7167
7170
|
let node = sel.getRangeAt(0).startContainer;
|
|
7168
7171
|
while (node) {
|
|
7169
7172
|
if (node.nodeName === "A") {
|
|
@@ -7316,8 +7319,8 @@
|
|
|
7316
7319
|
return overlay;
|
|
7317
7320
|
}
|
|
7318
7321
|
_onFileChange() {
|
|
7319
|
-
const file = this._fileInput
|
|
7320
|
-
if (!file
|
|
7322
|
+
const file = this._fileInput?.files?.[0];
|
|
7323
|
+
if (!file?.type?.startsWith("image/")) return;
|
|
7321
7324
|
if (!new Set([
|
|
7322
7325
|
"image/jpeg",
|
|
7323
7326
|
"image/png",
|
|
@@ -7357,7 +7360,7 @@
|
|
|
7357
7360
|
_onInsert() {
|
|
7358
7361
|
const src = this._urlInput.value.trim();
|
|
7359
7362
|
const alt = this._altInput.value.trim();
|
|
7360
|
-
const alignRadio = this._alignRow
|
|
7363
|
+
const alignRadio = this._alignRow?.querySelector("input[name=\"an-img-align\"]:checked");
|
|
7361
7364
|
const align = alignRadio ? alignRadio.value : "";
|
|
7362
7365
|
if (!src) {
|
|
7363
7366
|
this._urlInput.focus();
|
|
@@ -7417,7 +7420,10 @@
|
|
|
7417
7420
|
box.append(urlLabel, urlInput, hintEl, widthLabel, widthInput, btnRow);
|
|
7418
7421
|
const d0 = on(urlInput, "input", () => {
|
|
7419
7422
|
const info = this._parseVideoUrl(urlInput.value.trim());
|
|
7420
|
-
|
|
7423
|
+
let hint = "";
|
|
7424
|
+
if (info) hint = this.context.locale.videoDialog.detected(info.type);
|
|
7425
|
+
else if (urlInput.value) hint = this.context.locale.videoDialog.unknownFormat;
|
|
7426
|
+
hintEl.textContent = hint;
|
|
7421
7427
|
});
|
|
7422
7428
|
const d4 = on(urlInput, "keydown", (e) => {
|
|
7423
7429
|
if (e.key === "Enter") {
|
|
@@ -7497,7 +7503,7 @@
|
|
|
7497
7503
|
const iframeTitle = `${info.type} video player`;
|
|
7498
7504
|
return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><iframe src="${info.embedUrl}" width="${width}" height="${height}" title="${iframeTitle}" frameborder="0" allowfullscreen allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" style="display:block;max-width:100%"></iframe><div class="an-video-shield"></div></div>`;
|
|
7499
7505
|
}
|
|
7500
|
-
if (info
|
|
7506
|
+
if (info?.type === "Direct video") return `<div class="an-video-wrapper" style="position:relative;display:block;width:${width}px;max-width:100%"><video src="${info.embedUrl.replaceAll("\"", "%22")}" width="${width}" height="${height}" controls style="display:block;max-width:100%"></video><div class="an-video-shield"></div></div>`;
|
|
7501
7507
|
const safeSrc = (() => {
|
|
7502
7508
|
try {
|
|
7503
7509
|
const p = new URL(url);
|
|
@@ -7594,7 +7600,7 @@
|
|
|
7594
7600
|
this._positionRaf = null;
|
|
7595
7601
|
}
|
|
7596
7602
|
this._deselect();
|
|
7597
|
-
if (this._overlay
|
|
7603
|
+
if (this._overlay?.parentNode) this._overlay.remove();
|
|
7598
7604
|
this._overlay = null;
|
|
7599
7605
|
}
|
|
7600
7606
|
/** @returns {HTMLImageElement|null} */
|
|
@@ -7637,7 +7643,7 @@
|
|
|
7637
7643
|
_onDocClick(e) {
|
|
7638
7644
|
if (!this._activeImg) return;
|
|
7639
7645
|
if (e.target === this._activeImg) return;
|
|
7640
|
-
if (this._overlay
|
|
7646
|
+
if (this._overlay?.contains(e.target)) return;
|
|
7641
7647
|
if (e.target.closest(".an-contextmenu")) return;
|
|
7642
7648
|
this._deselect();
|
|
7643
7649
|
}
|
|
@@ -7669,7 +7675,7 @@
|
|
|
7669
7675
|
const containerRect = offsetParent.getBoundingClientRect();
|
|
7670
7676
|
const rect = this._activeImg.getBoundingClientRect();
|
|
7671
7677
|
const p = this._lastOverlayPos;
|
|
7672
|
-
if (p
|
|
7678
|
+
if (p?.l === rect.left && p.t === rect.top && p.w === rect.width && p.h === rect.height) return;
|
|
7673
7679
|
this._lastOverlayPos = {
|
|
7674
7680
|
l: rect.left,
|
|
7675
7681
|
t: rect.top,
|
|
@@ -7999,7 +8005,7 @@
|
|
|
7999
8005
|
this._clearTimers();
|
|
8000
8006
|
this._disposers.forEach((d) => d());
|
|
8001
8007
|
this._disposers = [];
|
|
8002
|
-
if (this._el
|
|
8008
|
+
if (this._el?.parentNode) this._el.remove();
|
|
8003
8009
|
this._el = null;
|
|
8004
8010
|
}
|
|
8005
8011
|
_buildTooltip() {
|
|
@@ -8093,7 +8099,7 @@
|
|
|
8093
8099
|
_truncateUrl(url) {
|
|
8094
8100
|
try {
|
|
8095
8101
|
const u = new URL(url);
|
|
8096
|
-
const display = u.host + (u.pathname
|
|
8102
|
+
const display = u.host + (u.pathname === "/" ? "" : u.pathname);
|
|
8097
8103
|
return display.length > 48 ? display.slice(0, 48) + "…" : display;
|
|
8098
8104
|
} catch {
|
|
8099
8105
|
return url.length > 48 ? url.slice(0, 48) + "…" : url;
|
|
@@ -8118,7 +8124,7 @@
|
|
|
8118
8124
|
});
|
|
8119
8125
|
if (this._copyBtn) {
|
|
8120
8126
|
this._copyBtn.classList.add("an-link-tooltip-btn--copied");
|
|
8121
|
-
setTimeout(() => this._copyBtn
|
|
8127
|
+
setTimeout(() => this._copyBtn?.classList.remove("an-link-tooltip-btn--copied"), 1e3);
|
|
8122
8128
|
}
|
|
8123
8129
|
}
|
|
8124
8130
|
_editLink() {
|
|
@@ -8353,7 +8359,8 @@
|
|
|
8353
8359
|
const match = /rotate\((-?[\d.]+)deg\)/.exec(current);
|
|
8354
8360
|
const next = ((match ? Number.parseFloat(match[1]) : 0) + delta + 360) % 360;
|
|
8355
8361
|
const cleaned = current.replace(/rotate\(-?[\d.]+deg\)/, "").trim();
|
|
8356
|
-
img.style.transform =
|
|
8362
|
+
if (cleaned) img.style.transform = `${cleaned} rotate(${next}deg)`;
|
|
8363
|
+
else img.style.transform = next === 0 ? "" : `rotate(${next}deg)`;
|
|
8357
8364
|
this.context.invoke("editor.afterCommand");
|
|
8358
8365
|
this.context.invoke("imageResizer.updateOverlay");
|
|
8359
8366
|
requestAnimationFrame(() => {
|
|
@@ -8714,7 +8721,7 @@
|
|
|
8714
8721
|
vIdx += c.colSpan || 1;
|
|
8715
8722
|
if (vIdx > visualIdx) {
|
|
8716
8723
|
const next = c.nextElementSibling;
|
|
8717
|
-
return next
|
|
8724
|
+
return next?.tagName === "TD" || next?.tagName === "TH" ? next : null;
|
|
8718
8725
|
}
|
|
8719
8726
|
}
|
|
8720
8727
|
return null;
|
|
@@ -8856,8 +8863,7 @@
|
|
|
8856
8863
|
const onSelMouseup = () => {
|
|
8857
8864
|
this._selectDragging = false;
|
|
8858
8865
|
};
|
|
8859
|
-
this._disposers.push(on(editable, "mousedown", onSelMousedown), on(editable, "mousemove", onSelMousemove), on(document, "mouseup", onSelMouseup))
|
|
8860
|
-
this._disposers.push(on(editable, "mouseover", (e) => {
|
|
8866
|
+
this._disposers.push(on(editable, "mousedown", onSelMousedown), on(editable, "mousemove", onSelMousemove), on(document, "mouseup", onSelMouseup), on(editable, "mouseover", (e) => {
|
|
8861
8867
|
if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
|
|
8862
8868
|
const table = e.target?.closest("table");
|
|
8863
8869
|
if (table && editable.contains(table)) {
|
|
@@ -8945,12 +8951,14 @@
|
|
|
8945
8951
|
_startY = e.clientY;
|
|
8946
8952
|
_table = _nearCell.closest("table");
|
|
8947
8953
|
if (_edge === "col") {
|
|
8948
|
-
|
|
8949
|
-
_colIdx = getVisualColIndex(_nearCell);
|
|
8954
|
+
_colIdx = getVisualColIndex(_nearCell) + (_nearCell.colSpan || 1) - 1;
|
|
8950
8955
|
_colCells = _colIdx >= 0 ? Array.from(_table.querySelectorAll("tr")).map((r) => getCellAtVisualCol(r, _colIdx)).filter(Boolean).filter((c) => (c.colSpan || 1) === 1) : [];
|
|
8956
|
+
_startW = _colCells.length > 0 ? _colCells[0].offsetWidth : Math.max(30, Math.round(_nearCell.offsetWidth / (_nearCell.colSpan || 1)));
|
|
8951
8957
|
document.body.style.cursor = "col-resize";
|
|
8952
8958
|
} else {
|
|
8953
|
-
|
|
8959
|
+
const tr = _nearCell.closest("tr");
|
|
8960
|
+
const lastRowIdx = (tr ? Array.from(_table.rows).indexOf(tr) : 0) + (_nearCell.rowSpan || 1) - 1;
|
|
8961
|
+
_row = _table.rows[lastRowIdx] || tr;
|
|
8954
8962
|
_startH = _row ? _row.offsetHeight : 40;
|
|
8955
8963
|
document.body.style.cursor = "row-resize";
|
|
8956
8964
|
}
|
|
@@ -9002,11 +9010,11 @@
|
|
|
9002
9010
|
this._clearTimers();
|
|
9003
9011
|
this._disposers.forEach((d) => d());
|
|
9004
9012
|
this._disposers = [];
|
|
9005
|
-
if (this._el
|
|
9013
|
+
if (this._el?.parentNode) this._el.remove();
|
|
9006
9014
|
this._el = null;
|
|
9007
|
-
if (this._sizePopover
|
|
9015
|
+
if (this._sizePopover?.parentNode) this._sizePopover.remove();
|
|
9008
9016
|
this._sizePopover = null;
|
|
9009
|
-
if (this._shadePopover
|
|
9017
|
+
if (this._shadePopover?.parentNode) this._shadePopover.remove();
|
|
9010
9018
|
this._shadePopover = null;
|
|
9011
9019
|
}
|
|
9012
9020
|
_buildTooltip() {
|
|
@@ -9153,7 +9161,7 @@
|
|
|
9153
9161
|
}
|
|
9154
9162
|
_getCell() {
|
|
9155
9163
|
const sel = globalThis.getSelection();
|
|
9156
|
-
if (sel
|
|
9164
|
+
if (sel?.rangeCount) {
|
|
9157
9165
|
let container = sel.getRangeAt(0).commonAncestorContainer;
|
|
9158
9166
|
if (container.nodeType === 3) container = container.parentElement;
|
|
9159
9167
|
const cellFromSel = container?.closest("td, th");
|
|
@@ -9190,7 +9198,7 @@
|
|
|
9190
9198
|
if (!startCell) return [];
|
|
9191
9199
|
if (!endCell || startCell === endCell) return [startCell];
|
|
9192
9200
|
const table = startCell.closest("table");
|
|
9193
|
-
if (!table
|
|
9201
|
+
if (!table?.contains(endCell)) return [startCell];
|
|
9194
9202
|
const { gridMap, cellPos } = buildGridMap(table);
|
|
9195
9203
|
const sp = cellPos.get(startCell);
|
|
9196
9204
|
const ep = cellPos.get(endCell);
|
|
@@ -9262,7 +9270,8 @@
|
|
|
9262
9270
|
const refRow = selectedRows.reduce((best, r) => {
|
|
9263
9271
|
const bi = allRows.indexOf(best);
|
|
9264
9272
|
const ri = allRows.indexOf(r);
|
|
9265
|
-
|
|
9273
|
+
if (position === "above") return ri < bi ? r : best;
|
|
9274
|
+
return ri > bi ? r : best;
|
|
9266
9275
|
}, selectedRows[0]);
|
|
9267
9276
|
const colCount = Array.from(refRow.cells).reduce((sum, c) => sum + (c.colSpan || 1), 0);
|
|
9268
9277
|
const newRow = document.createElement("tr");
|
|
@@ -9270,12 +9279,12 @@
|
|
|
9270
9279
|
for (let i = 0; i < colCount; i++) {
|
|
9271
9280
|
const td = createElement("td", {}, ["\xA0"]);
|
|
9272
9281
|
const ref = refCells[i];
|
|
9273
|
-
if (ref
|
|
9274
|
-
if (ref
|
|
9282
|
+
if (ref?.style.width) td.style.width = ref.style.width;
|
|
9283
|
+
if (ref?.style.minWidth) td.style.minWidth = ref.style.minWidth;
|
|
9275
9284
|
newRow.appendChild(td);
|
|
9276
9285
|
}
|
|
9277
9286
|
if (position === "above") refRow.parentElement?.insertBefore(newRow, refRow);
|
|
9278
|
-
else refRow.
|
|
9287
|
+
else refRow.after(newRow);
|
|
9279
9288
|
requestAnimationFrame(() => this._positionNear(this._activeTable));
|
|
9280
9289
|
this.context.invoke("editor.afterCommand");
|
|
9281
9290
|
}
|
|
@@ -9380,8 +9389,15 @@
|
|
|
9380
9389
|
first.colSpan = maxC - minC + 1;
|
|
9381
9390
|
first.rowSpan = maxR - minR + 1;
|
|
9382
9391
|
first.style.verticalAlign = "middle";
|
|
9383
|
-
first.
|
|
9384
|
-
|
|
9392
|
+
first.style.height = "";
|
|
9393
|
+
first.style.minHeight = "";
|
|
9394
|
+
const parts = rectCells.map((c) => c.innerHTML.replace(/^(<br\s*\/?>|\s)+$/i, "").trim()).filter((h) => h !== "");
|
|
9395
|
+
first.innerHTML = parts.length ? parts.join("<br>") : "<br>";
|
|
9396
|
+
rectCells.slice(1).forEach((c) => {
|
|
9397
|
+
const row = c.parentElement;
|
|
9398
|
+
c.remove();
|
|
9399
|
+
if (row && row.cells.length === 0) row.remove();
|
|
9400
|
+
});
|
|
9385
9401
|
this._clearSelection();
|
|
9386
9402
|
this.context.invoke("editor.afterCommand");
|
|
9387
9403
|
}
|
|
@@ -9433,12 +9449,9 @@
|
|
|
9433
9449
|
const targetRow = tableRows[r + dr];
|
|
9434
9450
|
if (!targetRow) continue;
|
|
9435
9451
|
let ref = null;
|
|
9436
|
-
for (const tc of targetRow.cells) {
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
ref = tc;
|
|
9440
|
-
break;
|
|
9441
|
-
}
|
|
9452
|
+
for (const tc of targetRow.cells) if (cellPos.get(tc)?.c > c) {
|
|
9453
|
+
ref = tc;
|
|
9454
|
+
break;
|
|
9442
9455
|
}
|
|
9443
9456
|
for (let dc = 0; dc < cs; dc++) targetRow.insertBefore(createElement(tag, {}, ["\xA0"]), ref);
|
|
9444
9457
|
}
|
|
@@ -9533,7 +9546,11 @@
|
|
|
9533
9546
|
this._sizeTitleEl.textContent = isCol ? this.context.locale.tooltips.table.columnWidthPx : this.context.locale.tooltips.table.rowHeightPx;
|
|
9534
9547
|
this._sizeInputEl.min = "1";
|
|
9535
9548
|
this._sizeInputEl.max = "2000";
|
|
9536
|
-
this._sizeInputEl.value =
|
|
9549
|
+
if (isCol) this._sizeInputEl.value = cell.offsetWidth || 120;
|
|
9550
|
+
else {
|
|
9551
|
+
const refRow = cell.closest("tr");
|
|
9552
|
+
this._sizeInputEl.value = refRow ? refRow.offsetHeight || 40 : 40;
|
|
9553
|
+
}
|
|
9537
9554
|
this._sizeApply = (val) => {
|
|
9538
9555
|
const table = cell.closest("table");
|
|
9539
9556
|
if (!table) return;
|
|
@@ -9621,8 +9638,7 @@
|
|
|
9621
9638
|
customRow.appendChild(colorInput);
|
|
9622
9639
|
customRow.appendChild(customLabel);
|
|
9623
9640
|
pop.appendChild(customRow);
|
|
9624
|
-
this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()), on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()))
|
|
9625
|
-
this._disposers.push(on(document, "click", (e) => {
|
|
9641
|
+
this._disposers.push(on(pop, "mousedown", (e) => e.preventDefault()), on(pop, "mouseenter", () => this._clearTimers()), on(pop, "mouseleave", () => this._scheduleHide()), on(document, "click", (e) => {
|
|
9626
9642
|
const et = e.target;
|
|
9627
9643
|
if (this._shadePopover && this._shadePopover.style.display !== "none" && !this._shadePopover.contains(et) && !this._el?.contains(et)) this._hideCellShadePopover();
|
|
9628
9644
|
}));
|
|
@@ -12496,7 +12512,7 @@
|
|
|
12496
12512
|
const editable = this.context.layoutInfo.editable;
|
|
12497
12513
|
if (savedRange) savedRange.select();
|
|
12498
12514
|
const sel = globalThis.getSelection();
|
|
12499
|
-
let range = sel
|
|
12515
|
+
let range = sel?.rangeCount > 0 ? sel.getRangeAt(0) : null;
|
|
12500
12516
|
if (!range) {
|
|
12501
12517
|
range = document.createRange();
|
|
12502
12518
|
range.selectNodeContents(editable);
|
|
@@ -13063,13 +13079,13 @@
|
|
|
13063
13079
|
const _sc = range.startContainer;
|
|
13064
13080
|
const _tdAnchor = (_sc.nodeType === 1 ? _sc : _sc.parentElement)?.closest("td, th");
|
|
13065
13081
|
range.deleteContents();
|
|
13066
|
-
if (_tdAnchor
|
|
13082
|
+
if (_tdAnchor?.isConnected && !_tdAnchor.contains(range.startContainer)) {
|
|
13067
13083
|
range.setStart(_tdAnchor, 0);
|
|
13068
13084
|
range.collapse(true);
|
|
13069
13085
|
}
|
|
13070
13086
|
range.insertNode(iconEl);
|
|
13071
13087
|
let caretTextNode = iconEl.nextSibling;
|
|
13072
|
-
if (
|
|
13088
|
+
if (caretTextNode?.nodeType !== Node.TEXT_NODE) {
|
|
13073
13089
|
caretTextNode = document.createTextNode("");
|
|
13074
13090
|
iconEl.parentNode.insertBefore(caretTextNode, iconEl.nextSibling);
|
|
13075
13091
|
} else if (!caretTextNode.textContent) caretTextNode.textContent = "";
|
|
@@ -13289,7 +13305,7 @@
|
|
|
13289
13305
|
constructor(context) {
|
|
13290
13306
|
this.context = context;
|
|
13291
13307
|
this.options = context.options || {};
|
|
13292
|
-
this._items = this.options.contextMenu
|
|
13308
|
+
this._items = this.options.contextMenu?.items || defaultItems;
|
|
13293
13309
|
this.el = null;
|
|
13294
13310
|
this._disposers = [];
|
|
13295
13311
|
this._menuDisposers = [];
|
|
@@ -13309,11 +13325,9 @@
|
|
|
13309
13325
|
this._renderItems(this._items);
|
|
13310
13326
|
const editable = this.context.layoutInfo?.editable;
|
|
13311
13327
|
if (editable) this._disposers.push(on(editable, "contextmenu", (e) => this._onContextMenu(e)));
|
|
13312
|
-
this._disposers.push(on(document, "click", (e) => this._maybeHide(e)))
|
|
13313
|
-
this._disposers.push(on(document, "keydown", (e) => {
|
|
13328
|
+
this._disposers.push(on(document, "click", (e) => this._maybeHide(e)), on(document, "keydown", (e) => {
|
|
13314
13329
|
if (e.key === "Escape") this.hide();
|
|
13315
|
-
}));
|
|
13316
|
-
this._disposers.push(on(globalThis, "scroll", () => this.hide(), { passive: true }));
|
|
13330
|
+
}), on(globalThis, "scroll", () => this.hide(), { passive: true }));
|
|
13317
13331
|
return this;
|
|
13318
13332
|
}
|
|
13319
13333
|
destroy() {
|
|
@@ -13578,7 +13592,7 @@
|
|
|
13578
13592
|
if (this.context.layoutInfo.container.classList.contains("an-disabled")) return;
|
|
13579
13593
|
event.preventDefault();
|
|
13580
13594
|
const winSel = globalThis.getSelection();
|
|
13581
|
-
this._savedRange = winSel
|
|
13595
|
+
this._savedRange = winSel?.rangeCount > 0 ? winSel.getRangeAt(0).cloneRange() : null;
|
|
13582
13596
|
this._renderItems(this._items);
|
|
13583
13597
|
const openX = event.clientX;
|
|
13584
13598
|
let openY = event.clientY;
|
|
@@ -13603,8 +13617,8 @@
|
|
|
13603
13617
|
}
|
|
13604
13618
|
_reposition(x, y) {
|
|
13605
13619
|
if (!this.el) return;
|
|
13606
|
-
const rx = x
|
|
13607
|
-
const ry = y
|
|
13620
|
+
const rx = x === void 0 ? this._lastX : x;
|
|
13621
|
+
const ry = y === void 0 ? this._lastY : y;
|
|
13608
13622
|
const w = this.el.offsetWidth;
|
|
13609
13623
|
const h = this.el.offsetHeight;
|
|
13610
13624
|
let left = rx;
|
|
@@ -13660,7 +13674,7 @@
|
|
|
13660
13674
|
const editable = this.context.layoutInfo?.editable;
|
|
13661
13675
|
let node = range.startContainer;
|
|
13662
13676
|
if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
|
|
13663
|
-
if (!node || !editable
|
|
13677
|
+
if (!node || !editable?.contains(node)) return;
|
|
13664
13678
|
const cs = globalThis.getComputedStyle(node);
|
|
13665
13679
|
const explicitFontFamily = this._findExplicitStyle(node, editable, "fontFamily");
|
|
13666
13680
|
const explicitFontSize = this._findExplicitStyle(node, editable, "fontSize");
|
|
@@ -13679,7 +13693,7 @@
|
|
|
13679
13693
|
_findExplicitStyle(node, boundary, prop) {
|
|
13680
13694
|
let el = node;
|
|
13681
13695
|
while (el && el !== boundary && el !== document.body) {
|
|
13682
|
-
if (el.style
|
|
13696
|
+
if (el.style?.[prop]) return el.style[prop];
|
|
13683
13697
|
if (el.nodeName === "FONT") {
|
|
13684
13698
|
if (prop === "fontFamily" && el.getAttribute("face")) return el.getAttribute("face");
|
|
13685
13699
|
if (prop === "fontSize" && el.getAttribute("size")) return null;
|
|
@@ -14128,7 +14142,7 @@
|
|
|
14128
14142
|
this._matches = this._matches.filter((m) => m.mark);
|
|
14129
14143
|
this._currentIndex = 0;
|
|
14130
14144
|
if (this._matches.length === 0) return;
|
|
14131
|
-
if (this._matches[0]
|
|
14145
|
+
if (this._matches[0]?.mark) {
|
|
14132
14146
|
this._matches[0].mark.className = "an-highlight an-highlight-current";
|
|
14133
14147
|
this._matches[0].mark.scrollIntoView({
|
|
14134
14148
|
block: "center",
|
|
@@ -14146,7 +14160,7 @@
|
|
|
14146
14160
|
const results = [];
|
|
14147
14161
|
if (this._lastQuery !== query || this._lastCaseSensitive !== this._caseSensitive) {
|
|
14148
14162
|
const flags = this._caseSensitive ? "g" : "gi";
|
|
14149
|
-
const escaped = query.replace(/[.*+?^${}()|[\]\\]/g,
|
|
14163
|
+
const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
14150
14164
|
this._queryRegex = new RegExp(escaped, flags);
|
|
14151
14165
|
this._lastQuery = query;
|
|
14152
14166
|
this._lastCaseSensitive = this._caseSensitive;
|
|
@@ -14184,7 +14198,7 @@
|
|
|
14184
14198
|
}
|
|
14185
14199
|
_scrollToMatch(index) {
|
|
14186
14200
|
const match = this._matches[index];
|
|
14187
|
-
if (!match
|
|
14201
|
+
if (!match?.mark) return;
|
|
14188
14202
|
this._matches.forEach((m, i) => {
|
|
14189
14203
|
if (m.mark) m.mark.className = i === index ? "an-highlight an-highlight-current" : "an-highlight";
|
|
14190
14204
|
});
|
|
@@ -14196,7 +14210,7 @@
|
|
|
14196
14210
|
_replace() {
|
|
14197
14211
|
if (this._matches.length === 0 || this._currentIndex < 0) return;
|
|
14198
14212
|
const match = this._matches[this._currentIndex];
|
|
14199
|
-
if (!match
|
|
14213
|
+
if (!match?.mark?.parentNode) return;
|
|
14200
14214
|
const replacement = this._replaceInput ? this._replaceInput.value : "";
|
|
14201
14215
|
const parent = match.mark.parentNode;
|
|
14202
14216
|
const textNode = document.createTextNode(replacement);
|
|
@@ -14216,7 +14230,7 @@
|
|
|
14216
14230
|
if (this._matches.length === 0) return;
|
|
14217
14231
|
const replacement = this._replaceInput ? this._replaceInput.value : "";
|
|
14218
14232
|
this._matches.forEach(({ mark }) => {
|
|
14219
|
-
if (!mark
|
|
14233
|
+
if (!mark?.parentNode) return;
|
|
14220
14234
|
const textNode = document.createTextNode(replacement);
|
|
14221
14235
|
mark.parentNode.insertBefore(textNode, mark);
|
|
14222
14236
|
mark.remove();
|
|
@@ -14592,7 +14606,7 @@
|
|
|
14592
14606
|
const startY = e.clientY;
|
|
14593
14607
|
const orig = { ...this._box };
|
|
14594
14608
|
const r = this._imgRect;
|
|
14595
|
-
const lockAR = this._arCheck
|
|
14609
|
+
const lockAR = this._arCheck?.checked;
|
|
14596
14610
|
const aspect = orig.w / (orig.h || 1);
|
|
14597
14611
|
const onMove = (me) => {
|
|
14598
14612
|
const dx = me.clientX - startX;
|
|
@@ -15418,14 +15432,14 @@
|
|
|
15418
15432
|
if (!this._btnCache) return;
|
|
15419
15433
|
this._btnCache.forEach((btn) => {
|
|
15420
15434
|
const activeFn = _ACTIVE[btn.dataset.name];
|
|
15421
|
-
btn.classList.toggle("an-active", !!
|
|
15435
|
+
btn.classList.toggle("an-active", !!activeFn?.());
|
|
15422
15436
|
});
|
|
15423
15437
|
}
|
|
15424
15438
|
/** Read the current selection's color and update the color-strip indicators. */
|
|
15425
15439
|
_syncColorStrips() {
|
|
15426
15440
|
if (!this._el) return;
|
|
15427
15441
|
const sel = globalThis.getSelection();
|
|
15428
|
-
if (!sel
|
|
15442
|
+
if (!sel?.rangeCount) return;
|
|
15429
15443
|
let node = sel.getRangeAt(0).startContainer;
|
|
15430
15444
|
if (node.nodeType === Node.TEXT_NODE) node = node.parentElement;
|
|
15431
15445
|
if (!node) return;
|
|
@@ -15653,13 +15667,13 @@
|
|
|
15653
15667
|
}
|
|
15654
15668
|
} catch (_) {}
|
|
15655
15669
|
const sel = globalThis.getSelection();
|
|
15656
|
-
if (!sel
|
|
15670
|
+
if (!sel?.rangeCount) return;
|
|
15657
15671
|
const rects = sel.getRangeAt(0).getClientRects();
|
|
15658
15672
|
if (rects.length > 0) this._caretRect = rects[rects.length - 1];
|
|
15659
15673
|
}
|
|
15660
15674
|
_getQueryAtCursor() {
|
|
15661
15675
|
const sel = globalThis.getSelection();
|
|
15662
|
-
if (!sel
|
|
15676
|
+
if (!sel?.rangeCount) return null;
|
|
15663
15677
|
const range = sel.getRangeAt(0);
|
|
15664
15678
|
if (!range.collapsed) return null;
|
|
15665
15679
|
const node = range.startContainer;
|
|
@@ -15777,12 +15791,12 @@
|
|
|
15777
15791
|
this.layoutInfo.editable = editable;
|
|
15778
15792
|
this._registerModules();
|
|
15779
15793
|
const toolbar = this._modules.get("toolbar");
|
|
15780
|
-
if (toolbar
|
|
15794
|
+
if (toolbar?.el) {
|
|
15781
15795
|
container.insertBefore(toolbar.el, editable);
|
|
15782
15796
|
this.layoutInfo.toolbar = toolbar.el;
|
|
15783
15797
|
}
|
|
15784
15798
|
const statusbar = this._modules.get("statusbar");
|
|
15785
|
-
if (statusbar
|
|
15799
|
+
if (statusbar?.el) {
|
|
15786
15800
|
container.appendChild(statusbar.el);
|
|
15787
15801
|
this.layoutInfo.statusbar = statusbar.el;
|
|
15788
15802
|
}
|
|
@@ -16277,7 +16291,7 @@
|
|
|
16277
16291
|
return this;
|
|
16278
16292
|
},
|
|
16279
16293
|
/** Library version */
|
|
16280
|
-
version: "1.6.
|
|
16294
|
+
version: "1.6.6"
|
|
16281
16295
|
};
|
|
16282
16296
|
/**
|
|
16283
16297
|
* @param {string|Element|NodeList|Element[]} selector
|