autumnnote 1.6.5 → 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 +89 -75
- package/dist/autumnnote.es.js.map +1 -1
- package/dist/autumnnote.umd.js +87 -73
- package/dist/autumnnote.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/js/Context.js +4 -4
- package/src/js/core/dom.js +3 -3
- 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 +7 -5
- package/src/js/editing/Typing.js +2 -2
- package/src/js/index.js +1 -1
- package/src/js/module/AutoSaveRestore.js +3 -2
- package/src/js/module/BubbleToolbar.js +1 -1
- 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 +6 -6
- package/src/js/module/EmojiDialog.js +1 -1
- package/src/js/module/FindReplace.js +6 -7
- package/src/js/module/IconDialog.js +1 -1
- package/src/js/module/ImageCropOverlay.js +1 -0
- package/src/js/module/ImageDialog.js +3 -3
- package/src/js/module/ImageResizer.js +2 -2
- 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 +2 -2
- package/src/js/module/TableTooltip.js +50 -32
- package/src/js/module/Toolbar.js +13 -10
- 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 */
|
|
@@ -386,7 +386,7 @@
|
|
|
386
386
|
function fontSize(size, editable = document) {
|
|
387
387
|
const sel = globalThis.getSelection();
|
|
388
388
|
const wasCollapsed = !sel?.rangeCount || sel.getRangeAt(0).collapsed;
|
|
389
|
-
if (wasCollapsed && sel
|
|
389
|
+
if (wasCollapsed && sel?.rangeCount > 0) {
|
|
390
390
|
try {
|
|
391
391
|
const range = sel.getRangeAt(0);
|
|
392
392
|
const span = document.createElement("span");
|
|
@@ -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
|
|
@@ -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
|
}
|
|
@@ -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];
|
|
@@ -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
|
}
|
|
@@ -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() {
|
|
@@ -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 = "";
|
|
@@ -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
|
/**
|
|
@@ -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
|
}
|
|
@@ -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(() => {
|
|
@@ -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,7 +9010,7 @@
|
|
|
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
9015
|
if (this._sizePopover?.parentNode) this._sizePopover.remove();
|
|
9008
9016
|
this._sizePopover = null;
|
|
@@ -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");
|
|
@@ -9275,7 +9284,7 @@
|
|
|
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,7 +13079,7 @@
|
|
|
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
|
}
|
|
@@ -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();
|
|
@@ -15659,7 +15673,7 @@
|
|
|
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
|