monobill-mintui 0.6.735 → 0.6.737
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/bin/component-dependencies.json +10 -0
- package/dist/back-button.css +1 -1
- package/dist/components/alert/browser.js +4 -4
- package/dist/components/alert/index.cjs +1 -1
- package/dist/components/alert/index.js +4 -4
- package/dist/components/back-button/browser.js +1 -1
- package/dist/components/back-button/index.cjs +1 -1
- package/dist/components/back-button/index.js +1 -1
- package/dist/components/bottom-navigation/browser.js +2 -2
- package/dist/components/bottom-navigation/index.cjs +1 -1
- package/dist/components/bottom-navigation/index.js +2 -2
- package/dist/components/button/Button.d.ts.map +1 -1
- package/dist/components/button/browser.js +1 -1
- package/dist/components/button/index.cjs +1 -1
- package/dist/components/button/index.js +1 -1
- package/dist/components/checkbox/browser.js +1 -1
- package/dist/components/checkbox/index.cjs +1 -1
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/chip/browser.js +1 -1
- package/dist/components/chip/index.cjs +1 -1
- package/dist/components/chip/index.js +1 -1
- package/dist/components/chunks/ScrollFade-DOnPtfC2.js +85 -0
- package/dist/components/chunks/ScrollFade-FBvsnQ1i.js +1 -0
- package/dist/components/chunks/{back-button-CC-TMsIw.js → back-button-CMZR-p_D.js} +2 -2
- package/dist/components/chunks/{back-button-Cwznte3M.js → back-button-C_aLMNZE.js} +1 -1
- package/dist/components/chunks/{button-DFoOu1dY.js → button-CELyLLtj.js} +1 -1
- package/dist/components/chunks/{button-p4PvDgg3.js → button-THsh4Svz.js} +3 -3
- package/dist/components/chunks/caret-down-BiAVkpX7.js +1 -0
- package/dist/components/chunks/{caret-down-Re0eHop6.js → caret-down-DUfiCBEs.js} +1 -1
- package/dist/components/chunks/caret-right-8n-rhz51.js +1 -0
- package/dist/components/chunks/{caret-right-pQsg_Tvf.js → caret-right-CppgjbLX.js} +1 -1
- package/dist/components/chunks/{checkbox-DKKOOaAA.js → checkbox-CZViKLNo.js} +2 -2
- package/dist/components/chunks/{checkbox-al-mdHK7.js → checkbox-d5UlscqI.js} +1 -1
- package/dist/components/chunks/{chip-BhhRXO_g.js → chip-DJ_kZURn.js} +1 -1
- package/dist/components/chunks/{chip-WYtVlBo_.js → chip-G6SRCgLq.js} +3 -3
- package/dist/components/chunks/{close-DfFS9Iww.js → close-ChHICicN.js} +1 -1
- package/dist/components/chunks/close-CuYimzX0.js +1 -0
- package/dist/components/chunks/{confirm-action-kvEHHFbd.js → confirm-action-BSHfjDfA.js} +1 -1
- package/dist/components/chunks/{confirm-action-CLs_pBDb.js → confirm-action-CRZMTjpd.js} +2 -2
- package/dist/components/chunks/{date-picker-BxAHKxaJ.js → date-picker-CTtYAkmM.js} +1 -1
- package/dist/components/chunks/{date-picker-COWiQYAf.js → date-picker-CUf5eJR3.js} +5 -5
- package/dist/components/chunks/{icon-BTPOIKHZ.js → icon-1cs-hcBy.js} +308 -240
- package/dist/components/chunks/{icon-C7YkjDlz.js → icon-Bv1J3LwC.js} +7 -7
- package/dist/components/chunks/icon-C-6HOPtI.js +1 -0
- package/dist/components/chunks/icon-aNwWb0hA.js +1 -0
- package/dist/components/chunks/{input-DfadWNai.js → input-Bu4xPosP.js} +3 -3
- package/dist/components/chunks/{input-9ZDaMAQH.js → input-Zqw53jts.js} +1 -1
- package/dist/components/chunks/{modal-C3gfernp.js → modal-CL5EStu0.js} +1 -1
- package/dist/components/chunks/{modal-CITn4Kxv.js → modal-ss_OTDJJ.js} +2 -2
- package/dist/components/chunks/popover-2Cnva3AN.js +1 -0
- package/dist/components/chunks/{popover-DPNBidSz.js → popover-DD7uyRXy.js} +3 -3
- package/dist/components/chunks/search-BXku4V9r.js +1 -0
- package/dist/components/chunks/{search-CKDqbJNo.js → search-DKHcIR2F.js} +1 -1
- package/dist/components/chunks/{select-DzapiRgp.js → select-CX9oOwl5.js} +1 -1
- package/dist/components/chunks/{select-FAoUWWgL.js → select-DOMW7Plx.js} +3 -3
- package/dist/components/chunks/{table-BNZVNp5g.js → table-HnSpIfny.js} +1 -1
- package/dist/components/chunks/{table-BNNRNEZ9.js → table-IU2Vmjwk.js} +1 -1
- package/dist/components/chunks/{time-picker-CllURo12.js → time-picker-BaoT0NtA.js} +1 -1
- package/dist/components/chunks/{time-picker-Cfza0IJy.js → time-picker-C7pJvGSM.js} +3 -3
- package/dist/components/chunks/{warning-CAvTb3wK.js → warning-Cf8ePVsQ.js} +1 -1
- package/dist/components/chunks/{warning-aKvCzp6B.js → warning-gkij2FhS.js} +1 -1
- package/dist/components/confirm-action/browser.js +1 -1
- package/dist/components/confirm-action/index.cjs +1 -1
- package/dist/components/confirm-action/index.js +1 -1
- package/dist/components/date-picker/browser.js +1 -1
- package/dist/components/date-picker/index.cjs +1 -1
- package/dist/components/date-picker/index.js +1 -1
- package/dist/components/datetime-picker/browser.js +3 -3
- package/dist/components/datetime-picker/index.cjs +1 -1
- package/dist/components/datetime-picker/index.js +3 -3
- package/dist/components/dropzone/browser.js +4 -4
- package/dist/components/dropzone/index.cjs +1 -1
- package/dist/components/dropzone/index.js +4 -4
- package/dist/components/editor/Editor.d.ts +135 -0
- package/dist/components/editor/Editor.d.ts.map +1 -0
- package/dist/components/editor/browser.js +1548 -0
- package/dist/components/editor/index.cjs +29 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.d.ts.map +1 -0
- package/dist/components/editor/index.js +1536 -0
- package/dist/components/icon/browser.js +1 -1
- package/dist/components/icon/icons/bold.d.ts +3 -0
- package/dist/components/icon/icons/bold.d.ts.map +1 -0
- package/dist/components/icon/icons/clear-formatting.d.ts +3 -0
- package/dist/components/icon/icons/clear-formatting.d.ts.map +1 -0
- package/dist/components/icon/icons/index.d.ts +7 -0
- package/dist/components/icon/icons/index.d.ts.map +1 -1
- package/dist/components/icon/icons/italic.d.ts +3 -0
- package/dist/components/icon/icons/italic.d.ts.map +1 -0
- package/dist/components/icon/icons/numbered-list.d.ts +3 -0
- package/dist/components/icon/icons/numbered-list.d.ts.map +1 -0
- package/dist/components/icon/icons/quote.d.ts +3 -0
- package/dist/components/icon/icons/quote.d.ts.map +1 -0
- package/dist/components/icon/icons/toolbar-icons.d.ts +13 -0
- package/dist/components/icon/icons/toolbar-icons.d.ts.map +1 -0
- package/dist/components/icon/icons/underline.d.ts +3 -0
- package/dist/components/icon/icons/underline.d.ts.map +1 -0
- package/dist/components/icon/index.cjs +1 -1
- package/dist/components/icon/index.js +1 -1
- package/dist/components/input/browser.js +1 -1
- package/dist/components/input/index.cjs +1 -1
- package/dist/components/input/index.js +1 -1
- package/dist/components/modal/browser.js +1 -1
- package/dist/components/modal/index.cjs +1 -1
- package/dist/components/modal/index.js +1 -1
- package/dist/components/navigation/browser.js +3 -3
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +3 -3
- package/dist/components/off-canvas/browser.js +2 -2
- package/dist/components/off-canvas/index.cjs +1 -1
- package/dist/components/off-canvas/index.js +2 -2
- package/dist/components/page/browser.js +4 -4
- package/dist/components/page/index.cjs +1 -1
- package/dist/components/page/index.js +4 -4
- package/dist/components/popover/Popover.d.ts.map +1 -1
- package/dist/components/popover/browser.js +1 -1
- package/dist/components/popover/index.cjs +1 -1
- package/dist/components/popover/index.js +1 -1
- package/dist/components/resource-table/browser.js +11 -11
- package/dist/components/resource-table/index.cjs +1 -1
- package/dist/components/resource-table/index.js +11 -11
- package/dist/components/scroll-fade/ScrollFade.d.ts +2 -1
- package/dist/components/scroll-fade/ScrollFade.d.ts.map +1 -1
- package/dist/components/scroll-fade/browser.js +1 -1
- package/dist/components/scroll-fade/index.cjs +1 -1
- package/dist/components/scroll-fade/index.js +1 -1
- package/dist/components/search/browser.js +7 -7
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +7 -7
- package/dist/components/select/browser.js +1 -1
- package/dist/components/select/index.cjs +1 -1
- package/dist/components/select/index.js +1 -1
- package/dist/components/side-navigation/browser.js +6 -6
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +6 -6
- package/dist/components/switch/browser.js +2 -2
- package/dist/components/switch/index.cjs +1 -1
- package/dist/components/switch/index.js +2 -2
- package/dist/components/table/browser.js +1 -1
- package/dist/components/table/index.cjs +1 -1
- package/dist/components/table/index.js +1 -1
- package/dist/components/tabs/browser.js +1 -1
- package/dist/components/tabs/index.cjs +1 -1
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/tags/browser.js +4 -4
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +4 -4
- package/dist/components/time-picker/browser.js +1 -1
- package/dist/components/time-picker/index.cjs +1 -1
- package/dist/components/time-picker/index.js +1 -1
- package/dist/components/tree/browser.js +4 -4
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +4 -4
- package/dist/editor.css +2 -0
- package/dist/icon.css +1 -1
- package/dist/icons/bank.svg +1 -1
- package/dist/icons/basket.svg +1 -1
- package/dist/icons/bold.svg +3 -0
- package/dist/icons/building.svg +1 -1
- package/dist/icons/buildings.svg +1 -1
- package/dist/icons/cash.svg +1 -1
- package/dist/icons/clear-formatting.svg +1 -0
- package/dist/icons/coupon.svg +1 -1
- package/dist/icons/delivery-location.svg +1 -1
- package/dist/icons/dollar-sign.svg +1 -1
- package/dist/icons/dress.svg +1 -1
- package/dist/icons/gift.svg +1 -1
- package/dist/icons/heart.svg +1 -1
- package/dist/icons/installments.svg +1 -1
- package/dist/icons/inventory.svg +1 -1
- package/dist/icons/invoice.svg +1 -1
- package/dist/icons/italic.svg +3 -0
- package/dist/icons/jacket.svg +1 -1
- package/dist/icons/loyalty-points.svg +1 -1
- package/dist/icons/membership.svg +1 -1
- package/dist/icons/numbered-list.svg +3 -0
- package/dist/icons/out-of-stock.svg +1 -1
- package/dist/icons/package.svg +1 -1
- package/dist/icons/percent-discount.svg +1 -1
- package/dist/icons/pickup.svg +1 -1
- package/dist/icons/price-label.svg +1 -1
- package/dist/icons/product-review.svg +1 -1
- package/dist/icons/quote.svg +3 -0
- package/dist/icons/receipt.svg +1 -1
- package/dist/icons/refund.svg +1 -1
- package/dist/icons/return.svg +1 -1
- package/dist/icons/sale-burst.svg +1 -1
- package/dist/icons/secure-checkout.svg +1 -1
- package/dist/icons/shirt.svg +1 -1
- package/dist/icons/shoe.svg +1 -1
- package/dist/icons/shopping-bag.svg +1 -1
- package/dist/icons/shopping-cart.svg +1 -1
- package/dist/icons/storefront.svg +1 -1
- package/dist/icons/support.svg +1 -1
- package/dist/icons/underline.svg +3 -0
- package/dist/icons/wallet.svg +1 -1
- package/dist/icons/warehouse.svg +1 -1
- package/dist/index.cjs +39 -11
- package/dist/index.css +10 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2134 -544
- package/dist/navigation-search.json +49 -0
- package/dist/navigation.css +1 -1
- package/dist/popover.css +1 -1
- package/dist/theme.css +3 -0
- package/package.json +10 -1
- package/dist/components/chunks/ScrollFade-Cg9fVO0V.js +0 -82
- package/dist/components/chunks/ScrollFade-Dfq2B1Hm.js +0 -1
- package/dist/components/chunks/caret-down-CpUOfgtN.js +0 -1
- package/dist/components/chunks/caret-right-CFbw7Ckp.js +0 -1
- package/dist/components/chunks/close-DljmolQP.js +0 -1
- package/dist/components/chunks/icon-BBZaAS5t.js +0 -1
- package/dist/components/chunks/icon-DgYUbNhm.js +0 -1
- package/dist/components/chunks/popover-CWWKb7L1.js +0 -1
- package/dist/components/chunks/search-BL-fP9qz.js +0 -1
|
@@ -0,0 +1,1536 @@
|
|
|
1
|
+
import '../../theme.css'
|
|
2
|
+
import '../../button.css'
|
|
3
|
+
import '../../spinner.css'
|
|
4
|
+
import '../../icon.css'
|
|
5
|
+
import '../../popover.css'
|
|
6
|
+
import '../../stack.css'
|
|
7
|
+
import '../../modal.css'
|
|
8
|
+
import '../../text.css'
|
|
9
|
+
import '../../input.css'
|
|
10
|
+
import '../../editor.css'
|
|
11
|
+
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
12
|
+
import "../chunks/icon-aNwWb0hA.js";
|
|
13
|
+
import "../chunks/button-THsh4Svz.js";
|
|
14
|
+
import "../chunks/modal-ss_OTDJJ.js";
|
|
15
|
+
import "../chunks/input-Bu4xPosP.js";
|
|
16
|
+
import "../chunks/popover-DD7uyRXy.js";
|
|
17
|
+
//#region src/components/editor/Editor.ts
|
|
18
|
+
function t(e) {
|
|
19
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """);
|
|
20
|
+
}
|
|
21
|
+
function n(e) {
|
|
22
|
+
return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
|
|
23
|
+
let n = e.trim();
|
|
24
|
+
if (!n) return "";
|
|
25
|
+
let i = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
|
|
26
|
+
if (i) return `<pre><code${i[1] ? ` class=\"language-${t(i[1])}\"` : ""}>${t(i[2])}</code></pre>`;
|
|
27
|
+
let a = n.match(/^(#{1,6})\s+([\s\S]+)$/);
|
|
28
|
+
if (a) return `<h${a[1].length}>${r(a[2])}</h${a[1].length}>`;
|
|
29
|
+
if (/^>\s?/.test(n)) return `<blockquote><p>${r(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
|
|
30
|
+
let o = n.split("\n").map((e) => e.trim()).filter(Boolean);
|
|
31
|
+
if (o.length >= 2 && /^\|?\s*:?-{3,}/.test(o[1]) && o[0].includes("|")) {
|
|
32
|
+
let e = [o[0], ...o.slice(2)].map((e) => e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim()));
|
|
33
|
+
return `<table><thead><tr>${(e.shift() || []).map((e) => `<th>${r(e)}</th>`).join("")}</tr></thead><tbody>${e.map((e) => `<tr>${e.map((e) => `<td>${r(e)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
34
|
+
}
|
|
35
|
+
if (/^[-*+]\s+\[[ xX]\]\s/.test(n)) return `<ul data-mint-task-list="true">${n.split("\n").map((e) => {
|
|
36
|
+
let t = e.match(/^[-*+]\s+\[([ xX])\]\s+(.*)$/);
|
|
37
|
+
return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${r(t[2])}</span></li>` : "";
|
|
38
|
+
}).join("")}</ul>`;
|
|
39
|
+
if (/^([-*+]\s|\d+\.\s)/.test(n)) {
|
|
40
|
+
let e = n.split("\n"), t = /^\d+\./.test(e[0]);
|
|
41
|
+
return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${r(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
|
|
42
|
+
}
|
|
43
|
+
return `<p>${r(n.replace(/\n/g, " "))}</p>`;
|
|
44
|
+
}).join("");
|
|
45
|
+
}
|
|
46
|
+
function r(e) {
|
|
47
|
+
return t(e).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/__(.+?)__/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/_(.+?)_/g, "<em>$1</em>").replace(/~~(.+?)~~/g, "<s>$1</s>").replace(/!\[([^\]]*)\]\(([^)]+)\)/g, "<img alt=\"$1\" src=\"$2\">").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "<a href=\"$2\">$1</a>");
|
|
48
|
+
}
|
|
49
|
+
function i(e) {
|
|
50
|
+
let t = (e) => {
|
|
51
|
+
if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
|
|
52
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return "";
|
|
53
|
+
let n = e, r = Array.from(n.childNodes).map(t).join(""), i = n.tagName.toLowerCase();
|
|
54
|
+
if (/^h[1-6]$/.test(i)) return `${"#".repeat(Number(i[1]))} ${r.trim()}\n\n`;
|
|
55
|
+
if (i === "p" || i === "div") return `${r.trim()}\n\n`;
|
|
56
|
+
if (i === "strong" || i === "b") return `**${r}**`;
|
|
57
|
+
if (i === "em" || i === "i") return `*${r}*`;
|
|
58
|
+
if (i === "u") return `<u>${r}</u>`;
|
|
59
|
+
if (i === "s" || i === "del") return `~~${r}~~`;
|
|
60
|
+
if (i === "code") return `\`${r}\``;
|
|
61
|
+
if (i === "pre") return `\`\`\`\n${n.textContent || ""}\n\`\`\`\n\n`;
|
|
62
|
+
if (i === "a") return `[${r}](${n.getAttribute("href") || ""})`;
|
|
63
|
+
if (i === "img") return ` || ""})`;
|
|
64
|
+
if (i === "br") return " \n";
|
|
65
|
+
if (i === "blockquote") return r.trim().split("\n").map((e) => `> ${e}`).join("\n") + "\n\n";
|
|
66
|
+
if (i === "ul" || i === "ol") {
|
|
67
|
+
let e = i === "ul" && n.hasAttribute("data-mint-task-list");
|
|
68
|
+
return Array.from(n.children).map((n, r) => {
|
|
69
|
+
if (e) {
|
|
70
|
+
let e = n.querySelector("input[type=\"checkbox\"]"), r = Array.from(n.childNodes).filter((e) => !(e.nodeType === Node.ELEMENT_NODE && e.tagName === "INPUT")).map(t).join("").trim();
|
|
71
|
+
return `- [${e?.checked ? "x" : " "}] ${r}`;
|
|
72
|
+
}
|
|
73
|
+
return `${i === "ol" ? `${r + 1}.` : "-"} ${t(n).trim()}`;
|
|
74
|
+
}).join("\n") + "\n\n";
|
|
75
|
+
}
|
|
76
|
+
return i === "input" && n.type === "checkbox" ? "" : i === "li" ? r : i === "table" ? Array.from(n.querySelectorAll("tr")).map((e) => `| ${Array.from(e.children).map((e) => (e.textContent || "").trim()).join(" | ")} |`).join("\n") + "\n\n" : i === "span" && n.classList.contains("mint-editor-image-frame") ? t(n.querySelector("img") || n) : r;
|
|
77
|
+
};
|
|
78
|
+
return Array.from(e.childNodes).map(t).join("").trim();
|
|
79
|
+
}
|
|
80
|
+
var a = class extends HTMLElement {
|
|
81
|
+
constructor(...e) {
|
|
82
|
+
super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.preservedContent = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
|
|
83
|
+
if (e.button !== 0) return;
|
|
84
|
+
e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
|
|
85
|
+
stage: t,
|
|
86
|
+
startY: e.clientY,
|
|
87
|
+
startHeight: t.getBoundingClientRect().height,
|
|
88
|
+
pointerId: e.pointerId
|
|
89
|
+
};
|
|
90
|
+
let n = this.ownerDocument.defaultView;
|
|
91
|
+
n?.addEventListener("pointermove", this.onStageResizeMove), n?.addEventListener("pointerup", this.onStageResizeEnd), n?.addEventListener("pointercancel", this.onStageResizeEnd);
|
|
92
|
+
}, this.onStageResizeMove = (e) => {
|
|
93
|
+
let t = this.stageResizeState;
|
|
94
|
+
if (!t || e.pointerId !== t.pointerId) return;
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
let n = Math.max(320, Math.min(1600, (this.ownerDocument.defaultView?.innerHeight || 900) * .9)), r = Math.round(Math.max(160, Math.min(n, t.startHeight + e.clientY - t.startY)));
|
|
97
|
+
t.stage.style.height = `${r}px`, this.editorHeight = r;
|
|
98
|
+
}, this.onStageResizeEnd = (e) => {
|
|
99
|
+
!this.stageResizeState || e.pointerId !== this.stageResizeState.pointerId || (this.stageResizeState = null, this.removeStageResizeListeners());
|
|
100
|
+
}, this.onTableResizeMove = (e) => {
|
|
101
|
+
let t = this.tableResizeState;
|
|
102
|
+
if (!t || e.pointerId !== t.pointerId) return;
|
|
103
|
+
let n = this.editor?.clientWidth || t.startWidth + 300;
|
|
104
|
+
t.table.style.width = `${Math.max(160, Math.min(n, t.startWidth + e.clientX - t.startX))}px`, t.table.style.height = `${Math.max(60, t.startHeight + e.clientY - t.startY)}px`, this.positionTableTools();
|
|
105
|
+
}, this.onTableResizeEnd = (e) => {
|
|
106
|
+
!this.tableResizeState || e.pointerId !== this.tableResizeState.pointerId || (this.tableResizeState = null, this.ownerDocument.defaultView?.removeEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.removeEventListener("pointerup", this.onTableResizeEnd), this.emitChange());
|
|
107
|
+
}, this.onGridResizeMove = (e) => {
|
|
108
|
+
let t = this.gridResizeState;
|
|
109
|
+
if (!(!t || e.pointerId !== t.pointerId)) {
|
|
110
|
+
if (t.kind === "row") {
|
|
111
|
+
let n = t.table.rows[t.index];
|
|
112
|
+
n && (n.style.height = `${Math.max(28, t.size + e.clientY - t.start)}px`);
|
|
113
|
+
} else {
|
|
114
|
+
this.ensureTableColumns(t.table);
|
|
115
|
+
let n = t.table.querySelectorAll("col")[t.index];
|
|
116
|
+
n && (n.style.width = `${Math.max(48, t.size + e.clientX - t.start)}px`);
|
|
117
|
+
}
|
|
118
|
+
this.positionTableTools();
|
|
119
|
+
}
|
|
120
|
+
}, this.onGridResizeEnd = (e) => {
|
|
121
|
+
if (!this.gridResizeState || e.pointerId !== this.gridResizeState.pointerId) return;
|
|
122
|
+
this.gridResizeState = null;
|
|
123
|
+
let t = this.editor?.ownerDocument.defaultView;
|
|
124
|
+
t?.removeEventListener("pointermove", this.onGridResizeMove), t?.removeEventListener("pointerup", this.onGridResizeEnd), t?.removeEventListener("pointercancel", this.onGridResizeEnd), this.emitChange();
|
|
125
|
+
}, this.onResizeMove = (e) => {
|
|
126
|
+
if (!this.resizeState || e.pointerId !== this.resizeState.pointerId) return;
|
|
127
|
+
let t = this.editor?.clientWidth || 1e3, n = Math.max(80, Math.min(t, this.resizeState.startWidth + e.clientX - this.resizeState.startX));
|
|
128
|
+
this.resizeState.frame.style.width = `${n}px`;
|
|
129
|
+
}, this.onResizeEnd = (e) => {
|
|
130
|
+
!this.resizeState || e.pointerId !== this.resizeState.pointerId || (this.resizeState = null, this.editor?.ownerDocument.defaultView?.removeEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.removeEventListener("pointerup", this.onResizeEnd), this.emitChange());
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
static get observedAttributes() {
|
|
134
|
+
return [
|
|
135
|
+
"label",
|
|
136
|
+
"placeholder",
|
|
137
|
+
"disabled",
|
|
138
|
+
"error",
|
|
139
|
+
"height",
|
|
140
|
+
"compact",
|
|
141
|
+
"format",
|
|
142
|
+
"value",
|
|
143
|
+
"resizable"
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
connectedCallback() {
|
|
147
|
+
this.editor || this.render(), this.observer = new MutationObserver(() => this.updateWordCount()), this.editor && this.observer.observe(this.editor, {
|
|
148
|
+
childList: !0,
|
|
149
|
+
subtree: !0,
|
|
150
|
+
characterData: !0
|
|
151
|
+
}), this.ownerDocument.defaultView?.addEventListener("resize", this.positionTableTools);
|
|
152
|
+
}
|
|
153
|
+
disconnectedCallback() {
|
|
154
|
+
this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = null, this.tooltipPopup?.remove(), this.tooltipPopup = null, this.frameResizeObserver?.disconnect(), this.frameResizeObserver = null, this.observer?.disconnect(), this.observer = null, this.ownerDocument.defaultView?.removeEventListener("resize", this.positionTableTools), this.editor?.ownerDocument.defaultView?.removeEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.removeEventListener("pointerup", this.onResizeEnd), this.ownerDocument.defaultView?.removeEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.removeEventListener("pointerup", this.onTableResizeEnd);
|
|
155
|
+
let e = this.editor?.ownerDocument.defaultView;
|
|
156
|
+
e?.removeEventListener("pointermove", this.onGridResizeMove), e?.removeEventListener("pointerup", this.onGridResizeEnd), this.removeStageResizeListeners();
|
|
157
|
+
}
|
|
158
|
+
attributeChangedCallback(e, t, r) {
|
|
159
|
+
if (this.isConnected) {
|
|
160
|
+
if (e === "format") {
|
|
161
|
+
t !== r && (this.updateFormatUI(), this.sourceMode && this.source && this.editor ? this.editor.innerHTML = r === "markdown" ? n(this.source.value) : this.source.value : r === "markdown" && t !== "markdown" && this.editor && (this.editor.innerHTML = n(this.editor.innerHTML)), this.syncSource());
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (e === "value") {
|
|
165
|
+
this.setValue(r || "");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
e === "height" && (this.editorHeight = null), this.render();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
get format() {
|
|
172
|
+
return this.getAttribute("format") === "markdown" ? "markdown" : "html";
|
|
173
|
+
}
|
|
174
|
+
set format(e) {
|
|
175
|
+
this.setAttribute("format", e === "markdown" ? "markdown" : "html");
|
|
176
|
+
}
|
|
177
|
+
get value() {
|
|
178
|
+
if (this.sourceMode && this.source) return this.source.value;
|
|
179
|
+
if (!this.editor) return "";
|
|
180
|
+
let e = this.cleanEditorCopy();
|
|
181
|
+
return this.format === "markdown" ? i(e) : e.innerHTML;
|
|
182
|
+
}
|
|
183
|
+
set value(e) {
|
|
184
|
+
this.setValue(e || "");
|
|
185
|
+
}
|
|
186
|
+
setValue(e) {
|
|
187
|
+
if (!this.editor) {
|
|
188
|
+
this.pendingValue = e, this.preservedContent = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
|
|
192
|
+
}
|
|
193
|
+
insertResource(e) {
|
|
194
|
+
let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
|
|
195
|
+
if (!n || !this.editor) return;
|
|
196
|
+
this.editor.focus(), this.restoreSelection();
|
|
197
|
+
let r = this.editor.ownerDocument, i = r.createElement("span");
|
|
198
|
+
i.className = "mint-editor-image-frame", i.contentEditable = "false", i.style.width = "min(100%, 420px)";
|
|
199
|
+
let a = r.createElement("img");
|
|
200
|
+
a.src = n, a.alt = t.alt || t.label || "", a.draggable = !1, i.append(a, this.createResizeHandle());
|
|
201
|
+
let o = this.selection;
|
|
202
|
+
if (o?.rangeCount && this.editor.contains(o.anchorNode)) {
|
|
203
|
+
let e = o.getRangeAt(0);
|
|
204
|
+
e.deleteContents(), e.insertNode(i), e.setStartAfter(i), e.collapse(!0), o.removeAllRanges(), o.addRange(e);
|
|
205
|
+
} else this.editor.append(i, r.createElement("br"));
|
|
206
|
+
this.selectImage(i), this.emitChange();
|
|
207
|
+
}
|
|
208
|
+
render() {
|
|
209
|
+
let e = this.getAttribute("value"), r = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
|
|
210
|
+
this.editor ? this.preservedContent = this.format === "markdown" && this.source ? this.source.value : this.editor.innerHTML : this.pendingValue === null ? e === null ? this.preservedContent === null && (this.preservedContent = r) : this.preservedContent = e : this.preservedContent = this.pendingValue;
|
|
211
|
+
let i = this.editor ? r : this.format === "markdown" ? n(r) : r;
|
|
212
|
+
this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
|
|
213
|
+
let a = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", o = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, s = this.getAttribute("label") || "";
|
|
214
|
+
this.innerHTML = "";
|
|
215
|
+
let c = document.createElement("div");
|
|
216
|
+
if (c.className = "mint-editor-root", this.hasAttribute("error") && c.classList.add("mint-editor-has-error"), this.hasAttribute("compact") && c.classList.add("mint-editor-compact"), s) {
|
|
217
|
+
let e = document.createElement("label");
|
|
218
|
+
e.className = "mint-editor-label", e.textContent = s, e.id = `${this.id || "mint-editor"}-label`, c.append(e);
|
|
219
|
+
}
|
|
220
|
+
let l = document.createElement("div");
|
|
221
|
+
l.className = "mint-editor-shell";
|
|
222
|
+
let u = document.createElement("div");
|
|
223
|
+
u.className = "mint-editor-toolbar", u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Text formatting"), this.toolbar = u, this.buildToolbar(u);
|
|
224
|
+
let d = document.createElement("div");
|
|
225
|
+
d.className = "mint-editor-inline-table-tools", d.setAttribute("role", "toolbar"), d.setAttribute("aria-label", "Table tools"), d.hidden = !0;
|
|
226
|
+
for (let [e, t] of [
|
|
227
|
+
["Add row above", "arrow-up"],
|
|
228
|
+
["Add row below", "arrow-down"],
|
|
229
|
+
["Delete row", "remove"],
|
|
230
|
+
["Add column left", "arrow-left"],
|
|
231
|
+
["Add column right", "arrow-right"],
|
|
232
|
+
["Delete column", "remove"],
|
|
233
|
+
["Delete table", "trash"]
|
|
234
|
+
]) {
|
|
235
|
+
let n = document.createElement("button");
|
|
236
|
+
n.type = "button", n.className = "mint-editor-table-tool-button", this.setTooltip(n, e), n.append(this.icon(t)), n.addEventListener("pointerdown", (e) => {
|
|
237
|
+
e.preventDefault(), this.saveSelection();
|
|
238
|
+
}), n.addEventListener("click", () => this.applyTableAction(e)), d.append(n);
|
|
239
|
+
}
|
|
240
|
+
let f = document.createElement("button");
|
|
241
|
+
f.type = "button", f.className = "mint-editor-table-resize-handle", this.setTooltip(f, "Resize table"), f.addEventListener("pointerdown", (e) => this.startTableResize(e)), this.inlineTableTools = d, this.tableResizeHandle = f;
|
|
242
|
+
let p = document.createElement("iframe");
|
|
243
|
+
p.className = "mint-editor-frame", p.title = s ? `${s} editor` : "Rich text editor", p.setAttribute("sandbox", "allow-same-origin"), p.style.height = "100%", p.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
244
|
+
html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
|
|
245
|
+
.editor{box-sizing:border-box;width:100%;height:100%;min-width:0;min-height:0;overflow:auto;overflow-wrap:anywhere;padding:1rem;outline:0;color:var(--mint-color-text,#202833);background:var(--mint-color-surface,#fff);font:inherit;line-height:1.55}
|
|
246
|
+
.editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
|
|
247
|
+
.editor :where(img,video,iframe,table,pre){max-width:100%}.editor img,.editor video{height:auto}.editor pre,.editor table{overflow:auto}
|
|
248
|
+
.editor :where(h1,h2,h3){max-width:100%;overflow-wrap:anywhere;line-height:1.2}.editor h1{font-size:2em}.editor h2{font-size:1.5em}.editor h3{font-size:1.2em}
|
|
249
|
+
.editor :where(p,ul,ol,blockquote,table){max-width:100%;overflow-wrap:anywhere;margin:.65em 0}.editor a{color:var(--mint-color-primary,#1e5bff);text-decoration:underline}
|
|
250
|
+
.editor table{width:100%;border-collapse:collapse;table-layout:fixed}.editor table.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}.editor :where(td,th){box-sizing:border-box;min-width:3rem;max-width:none;overflow-wrap:anywhere;padding:.5rem;border:1px solid var(--mint-color-border,#dfe3e9);text-align:left;vertical-align:top}.editor th{background:var(--mint-color-surface-subtle,#f8f9fb);font-weight:600}
|
|
251
|
+
.editor ul[data-mint-task-list]{padding-left:1.6rem;list-style:none}.editor ul[data-mint-task-list] li{display:flex;align-items:flex-start;gap:.5rem}.editor ul[data-mint-task-list] input[type=checkbox]{flex:0 0 auto;margin:.45em 0 0;accent-color:var(--mint-color-primary,#1e5bff)}
|
|
252
|
+
.editor .mint-editor-comment{border-radius:.15rem;background:rgb(255 224 130 / 45%);box-shadow:0 1px 0 rgb(198 120 0 / 65%);cursor:help}
|
|
253
|
+
.mint-editor-image-frame{position:relative;display:inline-block;max-width:100%;margin:.5rem 0;vertical-align:middle}.mint-editor-image-frame img{display:block;width:100%;height:auto;max-height:none;border-radius:.25rem;object-fit:contain}.mint-editor-image-frame.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}
|
|
254
|
+
.mint-editor-resize-handle{position:absolute;right:-.45rem;bottom:-.45rem;width:.9rem;height:.9rem;padding:0;border:2px solid var(--mint-color-surface,#fff);border-radius:50%;background:var(--mint-color-primary,#1e5bff);cursor:nwse-resize;touch-action:none}
|
|
255
|
+
@media(max-width:640px){.editor{padding:.75rem}}
|
|
256
|
+
</style></head><body><div class="editor" contenteditable="${!a}" role="textbox" aria-multiline="true" aria-label="${t(s || "Rich text editor")}" data-placeholder="${t(this.getAttribute("placeholder") || "Start writing…")}"></div></body></html>`, p.addEventListener("load", () => {
|
|
257
|
+
!this.isConnected || this.editorFrame !== p || this.bindEditorFrame(i, a);
|
|
258
|
+
}), this.editorFrame = p;
|
|
259
|
+
let m = document.createElement("textarea");
|
|
260
|
+
m.className = "mint-editor-source", m.style.height = "100%", m.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), m.hidden = !0, m.value = this.format === "markdown" ? r : i, m.addEventListener("input", () => {
|
|
261
|
+
this.editor && (this.editor.innerHTML = this.format === "markdown" ? n(m.value) : m.value), this.updateWordCount(), this.emitChange();
|
|
262
|
+
}), this.source = m;
|
|
263
|
+
let h = document.createElement("div");
|
|
264
|
+
h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
|
|
265
|
+
let g = null;
|
|
266
|
+
[
|
|
267
|
+
"false",
|
|
268
|
+
"0",
|
|
269
|
+
"off",
|
|
270
|
+
"no"
|
|
271
|
+
].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (g = document.createElement("button"), g.type = "button", g.className = "mint-editor-stage-resize-handle", this.setTooltip(g, "Resize editor"), g.addEventListener("pointerdown", (e) => this.onStageResizeStart(e, h))), l.append(u, h, d, f);
|
|
272
|
+
let _ = document.createElement("div");
|
|
273
|
+
_.className = "mint-editor-image-tools", _.hidden = !0, _.innerHTML = "<span>Image width</span><mint-input type=\"number\" min=\"10\" max=\"100\" value=\"100\" aria-label=\"Image width percent\"></mint-input><span>%</span><mint-button variant=\"ghost\" data-align=\"left\">Left</mint-button><mint-button variant=\"ghost\" data-align=\"center\">Center</mint-button><mint-button variant=\"ghost\" data-align=\"right\">Right</mint-button><mint-button variant=\"ghost\" data-remove=\"image\">Remove</mint-button>", _.querySelectorAll("[data-align]").forEach((e) => this.setTooltip(e, `Align image ${e.dataset.align}`));
|
|
274
|
+
let v = _.querySelector("[data-remove=\"image\"]");
|
|
275
|
+
v && this.setTooltip(v, "Remove image"), _.querySelector("mint-input")?.addEventListener("input", (e) => {
|
|
276
|
+
if (!this.selectedImage) return;
|
|
277
|
+
let t = Number(e.target.value);
|
|
278
|
+
this.selectedImage.style.width = `${Math.max(10, Math.min(100, t))}%`, this.emitChange();
|
|
279
|
+
}), _.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
|
|
280
|
+
this.selectedImage && (this.selectedImage.style.marginLeft = e.dataset.align === "right" || e.dataset.align === "center" ? "auto" : "0", this.selectedImage.style.marginRight = e.dataset.align === "left" || e.dataset.align === "center" ? "auto" : "0", this.emitChange());
|
|
281
|
+
})), _.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
|
|
282
|
+
this.selectedImage?.remove(), this.selectImage(null), this.emitChange();
|
|
283
|
+
}), c.append(l, _);
|
|
284
|
+
let y = document.createElement("div");
|
|
285
|
+
y.className = "mint-editor-footer";
|
|
286
|
+
let b = document.createElement("span");
|
|
287
|
+
b.className = "mint-editor-mode", b.textContent = "p";
|
|
288
|
+
let x = document.createElement("span");
|
|
289
|
+
x.className = "mint-editor-word-count", this.count = x;
|
|
290
|
+
let S = document.createElement("div");
|
|
291
|
+
S.className = "mint-editor-footer-end", S.append(x), g && S.append(g), y.append(b, S), this.footerMode = b, l.append(y);
|
|
292
|
+
let C = this.getAttribute("error");
|
|
293
|
+
if (C) {
|
|
294
|
+
let e = document.createElement("div");
|
|
295
|
+
e.className = "mint-editor-error", e.textContent = C, c.append(e);
|
|
296
|
+
}
|
|
297
|
+
this.append(c);
|
|
298
|
+
let w = this.querySelector(".mint-editor-stage");
|
|
299
|
+
if (w && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
|
|
300
|
+
if (!e || !this.editorFrame) return;
|
|
301
|
+
let t = Math.max(0, e.contentRect.width), n = Math.max(0, e.contentRect.height);
|
|
302
|
+
this.editorFrame.style.width = `${t}px`, this.editorFrame.style.height = `${n}px`;
|
|
303
|
+
}), this.frameResizeObserver.observe(w)), this.toolbar && typeof ResizeObserver < "u") {
|
|
304
|
+
this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = new ResizeObserver(() => this.updateToolbarOverflow()), this.toolbarResizeObserver.observe(this.toolbar);
|
|
305
|
+
let e = this.toolbar.querySelector(".mint-editor-toolbar-actions");
|
|
306
|
+
e && this.toolbarResizeObserver.observe(e), requestAnimationFrame(() => this.updateToolbarOverflow());
|
|
307
|
+
}
|
|
308
|
+
this.sourceMode = !1, this.observer && this.editor && this.observer.observe(this.editor, {
|
|
309
|
+
childList: !0,
|
|
310
|
+
subtree: !0,
|
|
311
|
+
characterData: !0
|
|
312
|
+
}), this.updateWordCount(), this.updateFormatUI();
|
|
313
|
+
}
|
|
314
|
+
removeStageResizeListeners() {
|
|
315
|
+
let e = this.ownerDocument.defaultView;
|
|
316
|
+
e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
|
|
317
|
+
}
|
|
318
|
+
bindEditorFrame(e, t) {
|
|
319
|
+
let r = this.editorFrame?.contentDocument, i = r?.querySelector(".editor");
|
|
320
|
+
if (!r || !i) return;
|
|
321
|
+
i.contentEditable = String(!t), i.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? n(this.pendingValue) : this.pendingValue, this.pendingValue = null;
|
|
322
|
+
let a = getComputedStyle(this), o = r.body;
|
|
323
|
+
o.style.font = a.font, o.style.color = a.color, o.style.background = a.backgroundColor, getComputedStyle(i), i.style.font = a.font, i.style.background = a.backgroundColor, [
|
|
324
|
+
"text",
|
|
325
|
+
"text-muted",
|
|
326
|
+
"surface",
|
|
327
|
+
"surface-subtle",
|
|
328
|
+
"border",
|
|
329
|
+
"primary",
|
|
330
|
+
"focus"
|
|
331
|
+
].forEach((e) => {
|
|
332
|
+
let t = a.getPropertyValue(`--mint-color-${e}`).trim();
|
|
333
|
+
t && i.style.setProperty(`--mint-color-${e}`, t);
|
|
334
|
+
}), this.editor = i, i.addEventListener("input", () => {
|
|
335
|
+
this.normalizeTaskListItems(), this.syncSource(), this.emitChange(), this.updateSelectionUI();
|
|
336
|
+
}), i.addEventListener("change", (e) => {
|
|
337
|
+
let t = e.target;
|
|
338
|
+
t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
|
|
339
|
+
}), i.addEventListener("paste", (e) => {
|
|
340
|
+
let t = e.clipboardData?.getData("text/html") || "";
|
|
341
|
+
if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
|
|
342
|
+
let n = this.sanitizePastedHtml(t);
|
|
343
|
+
n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
|
|
344
|
+
}), i.addEventListener("beforeinput", (e) => {
|
|
345
|
+
let t = e;
|
|
346
|
+
t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
|
|
347
|
+
let n = t.shiftKey;
|
|
348
|
+
if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
|
|
349
|
+
let e = this.selection?.anchorNode, n = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("li"), r = n?.parentElement;
|
|
350
|
+
if (n && r?.tagName === "UL" && r.hasAttribute("data-mint-task-list") && this.editor?.contains(n)) {
|
|
351
|
+
t.preventDefault(), this.isEmptyTaskItem(n) ? this.exitTaskList(n, r) : this.splitTaskItem(n, r);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
this.applyInlineTypingState(t);
|
|
356
|
+
}), i.addEventListener("keyup", (e) => {
|
|
357
|
+
[
|
|
358
|
+
"ArrowLeft",
|
|
359
|
+
"ArrowRight",
|
|
360
|
+
"ArrowUp",
|
|
361
|
+
"ArrowDown",
|
|
362
|
+
"Home",
|
|
363
|
+
"End",
|
|
364
|
+
"PageUp",
|
|
365
|
+
"PageDown"
|
|
366
|
+
].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
|
|
367
|
+
}), i.addEventListener("mouseup", () => {
|
|
368
|
+
this.updateSelectedImage(), this.updateSelectionUI();
|
|
369
|
+
}), r.addEventListener("selectionchange", () => this.updateSelectionUI()), i.addEventListener("scroll", () => this.positionTableTools()), i.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), r.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), i.addEventListener("click", (e) => {
|
|
370
|
+
this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
|
|
371
|
+
let t = e.target, n = t.closest(".mint-editor-image-frame");
|
|
372
|
+
n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
|
|
373
|
+
let r = t.closest("table");
|
|
374
|
+
this.selectTable(r), t.closest("a") && e.preventDefault();
|
|
375
|
+
}), i.addEventListener("keydown", (e) => {
|
|
376
|
+
if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
|
|
377
|
+
let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
|
|
378
|
+
if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
|
|
379
|
+
e.preventDefault(), this.isEmptyTaskItem(r) ? this.exitTaskList(r, i) : this.splitTaskItem(r, i);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
(e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "b" && (e.preventDefault(), this.toggleInline("bold")), (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "i" && (e.preventDefault(), this.toggleInline("italic")), (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "u" && (e.preventDefault(), this.toggleInline("underline"));
|
|
384
|
+
}), this.observer && this.observer.observe(i, {
|
|
385
|
+
childList: !0,
|
|
386
|
+
subtree: !0,
|
|
387
|
+
characterData: !0
|
|
388
|
+
}), this.updateWordCount(), this.updateSelectionUI();
|
|
389
|
+
}
|
|
390
|
+
buildToolbar(e) {
|
|
391
|
+
let t = (t, n, r, i = e) => {
|
|
392
|
+
let a = document.createElement("button");
|
|
393
|
+
return a.type = "button", a.className = `mint-editor-tool-button mint-editor-toolbar-${n}`, this.setTooltip(a, t), a.append(this.icon(n)), a.addEventListener("pointerdown", () => this.saveSelection()), a.addEventListener("click", (e) => {
|
|
394
|
+
e.preventDefault(), r();
|
|
395
|
+
}), i.append(a), a;
|
|
396
|
+
}, n = (e, t, n) => {
|
|
397
|
+
let r = document.createElement("mint-popover");
|
|
398
|
+
return r.id = `${e.id}-menu`, r.setAttribute("trigger-id", e.id), r.setAttribute("padding", "0.25rem"), r.setAttribute("direction", "down"), r.className = `mint-editor-menu-popover ${t}`, n.append(r), r;
|
|
399
|
+
}, r = (e, t, n, r) => {
|
|
400
|
+
let i = this.createMenuOption(t, n);
|
|
401
|
+
return i.addEventListener("click", r), e.append(i), i;
|
|
402
|
+
};
|
|
403
|
+
t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
|
|
404
|
+
let i = document.createElement("button");
|
|
405
|
+
i.type = "button", i.className = "mint-editor-tool-button mint-editor-block-trigger", this.setTooltip(i, "Text style"), i.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-block-trigger`;
|
|
406
|
+
let a = document.createElement("span");
|
|
407
|
+
a.className = "mint-editor-block-label", a.textContent = "Paragraph", i.append(a, this.icon("caret-down")), i.addEventListener("pointerdown", () => this.saveSelection()), this.blockButton = i, e.append(i);
|
|
408
|
+
let o = n(i, "mint-editor-block-popover", e);
|
|
409
|
+
[
|
|
410
|
+
[
|
|
411
|
+
"p",
|
|
412
|
+
"Paragraph",
|
|
413
|
+
"paragraph"
|
|
414
|
+
],
|
|
415
|
+
[
|
|
416
|
+
"h1",
|
|
417
|
+
"Heading 1",
|
|
418
|
+
"heading"
|
|
419
|
+
],
|
|
420
|
+
[
|
|
421
|
+
"h2",
|
|
422
|
+
"Heading 2",
|
|
423
|
+
"heading"
|
|
424
|
+
],
|
|
425
|
+
[
|
|
426
|
+
"h3",
|
|
427
|
+
"Heading 3",
|
|
428
|
+
"heading"
|
|
429
|
+
],
|
|
430
|
+
[
|
|
431
|
+
"blockquote",
|
|
432
|
+
"Quote",
|
|
433
|
+
"quote"
|
|
434
|
+
],
|
|
435
|
+
[
|
|
436
|
+
"div",
|
|
437
|
+
"Div",
|
|
438
|
+
"code"
|
|
439
|
+
]
|
|
440
|
+
].forEach(([e, t, n]) => {
|
|
441
|
+
let r = this.createMenuOption(t, n);
|
|
442
|
+
r.dataset.blockTag = e, r.addEventListener("click", () => {
|
|
443
|
+
this.command("formatBlock", e), o.close(), this.updateSelectionUI();
|
|
444
|
+
}), o.append(r);
|
|
445
|
+
}), this.blockPopover = o;
|
|
446
|
+
let s = document.createElement("div");
|
|
447
|
+
s.className = "mint-editor-font-size-control", t("Decrease font size", "minus", () => this.applyFontSize(this.readFontSize() - 1), s);
|
|
448
|
+
let c = document.createElement("button");
|
|
449
|
+
c.type = "button", c.className = "mint-editor-tool-button mint-editor-font-size-value", c.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-size-trigger`, c.setAttribute("aria-label", "Font size");
|
|
450
|
+
let l = document.createElement("span");
|
|
451
|
+
l.textContent = "16px", c.append(l, this.icon("caret-down")), c.addEventListener("pointerdown", () => this.saveSelection()), s.append(c), t("Increase font size", "plus", () => this.applyFontSize(this.readFontSize() + 1), s), this.fontSizeDisplay = l;
|
|
452
|
+
let u = document.createElement("div");
|
|
453
|
+
u.className = "mint-editor-toolbar-actions", e.append(u), u.append(s);
|
|
454
|
+
let d = n(c, "mint-editor-font-size-popover", u), f = [[s, d]];
|
|
455
|
+
[
|
|
456
|
+
8,
|
|
457
|
+
9,
|
|
458
|
+
10,
|
|
459
|
+
11,
|
|
460
|
+
12,
|
|
461
|
+
14,
|
|
462
|
+
16,
|
|
463
|
+
18,
|
|
464
|
+
20,
|
|
465
|
+
24,
|
|
466
|
+
28,
|
|
467
|
+
32,
|
|
468
|
+
36,
|
|
469
|
+
48,
|
|
470
|
+
72
|
|
471
|
+
].forEach((e) => {
|
|
472
|
+
let t = document.createElement("button");
|
|
473
|
+
t.type = "button", t.className = "mint-editor-menu-option mint-editor-font-size-option", t.textContent = `${e}px`, t.addEventListener("click", () => {
|
|
474
|
+
this.applyFontSize(e), d.close();
|
|
475
|
+
}), d.append(t);
|
|
476
|
+
});
|
|
477
|
+
let p = (e, n, r) => {
|
|
478
|
+
let i = t(e, n, r, u);
|
|
479
|
+
return [
|
|
480
|
+
"bold",
|
|
481
|
+
"italic",
|
|
482
|
+
"underline"
|
|
483
|
+
].includes(n) && (i.setAttribute("aria-pressed", "false"), this.inlineButtons.set(n, i)), i;
|
|
484
|
+
}, m = (e) => {
|
|
485
|
+
let t = e.querySelector(":scope > mint-icon");
|
|
486
|
+
if (!t) return;
|
|
487
|
+
let n = document.createElement("span");
|
|
488
|
+
n.className = "mint-editor-color-icon", e.insertBefore(n, t), n.append(t);
|
|
489
|
+
}, h = () => {
|
|
490
|
+
let e = this.separator();
|
|
491
|
+
return u.append(e), f.push([e]), e;
|
|
492
|
+
}, g = p("Bold", "bold", () => this.toggleInline("bold")), _ = p("Italic", "italic", () => this.toggleInline("italic")), v = p("Underline", "underline", () => this.toggleInline("underline"));
|
|
493
|
+
f.push([g], [_], [v]);
|
|
494
|
+
let y = this.separator();
|
|
495
|
+
u.append(y);
|
|
496
|
+
let b = p("Text color", "text-color", () => {});
|
|
497
|
+
b.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-text-color-trigger`, b.append(this.icon("caret-down")), b.classList.add("mint-editor-color-trigger"), m(b), b.style.setProperty("--editor-color", this.lastTextColor);
|
|
498
|
+
let x = n(b, "mint-editor-color-popover", u);
|
|
499
|
+
this.buildColorPopover(x, "text", b), this.colorTriggers.set("text", b);
|
|
500
|
+
let S = p("Highlight color", "highlight", () => {});
|
|
501
|
+
S.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-highlight-trigger`, S.append(this.icon("caret-down")), S.classList.add("mint-editor-color-trigger"), m(S), S.style.setProperty("--editor-color", this.lastBackgroundColor);
|
|
502
|
+
let C = n(S, "mint-editor-color-popover", u);
|
|
503
|
+
this.buildColorPopover(C, "background", S), this.colorTriggers.set("background", S), f.push([
|
|
504
|
+
y,
|
|
505
|
+
b,
|
|
506
|
+
x,
|
|
507
|
+
S,
|
|
508
|
+
C
|
|
509
|
+
]);
|
|
510
|
+
let w = p("Font family", "font-family", () => {});
|
|
511
|
+
w.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`, w.append(this.icon("caret-down"));
|
|
512
|
+
let T = n(w, "mint-editor-font-family-popover", u);
|
|
513
|
+
[
|
|
514
|
+
["Arial", "Arial, sans-serif"],
|
|
515
|
+
["Helvetica", "Helvetica, sans-serif"],
|
|
516
|
+
["Georgia", "Georgia, serif"],
|
|
517
|
+
["Times New Roman", "\"Times New Roman\", serif"],
|
|
518
|
+
["Courier New", "\"Courier New\", monospace"],
|
|
519
|
+
["System UI", "system-ui, sans-serif"]
|
|
520
|
+
].forEach(([e, t]) => {
|
|
521
|
+
r(T, e, "font-family", () => {
|
|
522
|
+
this.applyFontFamily(t), T.close();
|
|
523
|
+
});
|
|
524
|
+
}), f.push([w, T]), h();
|
|
525
|
+
let E = p("Insert link", "link", () => this.openLinkModal()), D = p("Insert image", "image", () => this.requestResource()), O = p("Insert table", "table", () => this.openTableModal()), k = document.createElement("button");
|
|
526
|
+
k.type = "button", k.className = "mint-editor-tool-button", this.setTooltip(k, "Table options"), k.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, k.append(this.icon("caret-down")), k.hidden = !0, u.append(k);
|
|
527
|
+
let A = n(k, "", u);
|
|
528
|
+
this.tablePopover = A, [
|
|
529
|
+
["Add row below", "table-row"],
|
|
530
|
+
["Add column right", "table-column"],
|
|
531
|
+
["Delete row", "table-row-delete"],
|
|
532
|
+
["Delete column", "table-column-delete"],
|
|
533
|
+
["Delete table", "trash"]
|
|
534
|
+
].forEach(([e, t]) => {
|
|
535
|
+
let n = this.createMenuOption(e, t);
|
|
536
|
+
n.addEventListener("click", () => {
|
|
537
|
+
this.applyTableAction(e), A.close();
|
|
538
|
+
}), A.append(n);
|
|
539
|
+
}), k.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = k, f.push([E], [D], [
|
|
540
|
+
O,
|
|
541
|
+
k,
|
|
542
|
+
A
|
|
543
|
+
]);
|
|
544
|
+
let j = p("Add comment", "comment-plus", () => this.openCommentModal());
|
|
545
|
+
f.push([j]), h();
|
|
546
|
+
let M = p("Text alignment", "align-left", () => {});
|
|
547
|
+
M.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, M.append(this.icon("caret-down")), this.alignmentTrigger = M;
|
|
548
|
+
let N = n(M, "mint-editor-alignment-popover", u);
|
|
549
|
+
[
|
|
550
|
+
[
|
|
551
|
+
"Align left",
|
|
552
|
+
"align-left",
|
|
553
|
+
"justifyLeft"
|
|
554
|
+
],
|
|
555
|
+
[
|
|
556
|
+
"Align center",
|
|
557
|
+
"align-center",
|
|
558
|
+
"justifyCenter"
|
|
559
|
+
],
|
|
560
|
+
[
|
|
561
|
+
"Align right",
|
|
562
|
+
"align-right",
|
|
563
|
+
"justifyRight"
|
|
564
|
+
],
|
|
565
|
+
[
|
|
566
|
+
"Justify",
|
|
567
|
+
"align-justify",
|
|
568
|
+
"justifyFull"
|
|
569
|
+
]
|
|
570
|
+
].forEach(([e, t, n]) => {
|
|
571
|
+
r(N, e, t, () => {
|
|
572
|
+
this.command(n), N.close(), this.updateTooltipLabel(M, `Text alignment: ${e}`);
|
|
573
|
+
});
|
|
574
|
+
}), f.push([M, N]), h();
|
|
575
|
+
let P = p("Bulleted list", "list", () => this.command("insertUnorderedList")), F = document.createElement("button");
|
|
576
|
+
F.type = "button", F.className = "mint-editor-tool-button mint-editor-list-options-trigger", F.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-bullet-options-trigger`, this.setTooltip(F, "Bulleted list style"), F.append(this.icon("caret-down")), F.addEventListener("pointerdown", () => this.saveSelection()), u.append(F);
|
|
577
|
+
let I = n(F, "mint-editor-list-popover", u);
|
|
578
|
+
[
|
|
579
|
+
["Disc", "disc"],
|
|
580
|
+
["Circle", "circle"],
|
|
581
|
+
["Square", "square"]
|
|
582
|
+
].forEach(([e, t]) => r(I, e, "list", () => {
|
|
583
|
+
this.applyListStyle("ul", t), I.close();
|
|
584
|
+
}));
|
|
585
|
+
let L = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), R = document.createElement("button");
|
|
586
|
+
R.type = "button", R.className = "mint-editor-tool-button mint-editor-list-options-trigger", R.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-numbered-options-trigger`, this.setTooltip(R, "Numbered list style"), R.append(this.icon("caret-down")), R.addEventListener("pointerdown", () => this.saveSelection()), u.append(R);
|
|
587
|
+
let z = n(R, "mint-editor-list-popover", u);
|
|
588
|
+
[
|
|
589
|
+
["Numbers", "decimal"],
|
|
590
|
+
["Lowercase letters", "lower-alpha"],
|
|
591
|
+
["Uppercase letters", "upper-alpha"],
|
|
592
|
+
["Lowercase Roman numerals", "lower-roman"],
|
|
593
|
+
["Uppercase Roman numerals", "upper-roman"]
|
|
594
|
+
].forEach(([e, t]) => r(z, e, "numbered-list", () => {
|
|
595
|
+
this.applyListStyle("ol", t), z.close();
|
|
596
|
+
}));
|
|
597
|
+
let B = p("Checklist", "checklist", () => this.toggleChecklist());
|
|
598
|
+
f.push([
|
|
599
|
+
P,
|
|
600
|
+
F,
|
|
601
|
+
I
|
|
602
|
+
], [
|
|
603
|
+
L,
|
|
604
|
+
R,
|
|
605
|
+
z
|
|
606
|
+
], [B]), h();
|
|
607
|
+
let V = p("HTML source", "code", () => this.toggleSource());
|
|
608
|
+
f.push([V]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
|
|
609
|
+
let H = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
|
|
610
|
+
f.push([H]);
|
|
611
|
+
let U = document.createElement("button");
|
|
612
|
+
U.type = "button", U.className = "mint-editor-tool-button mint-editor-overflow-trigger", this.setTooltip(U, "More formatting options"), U.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-overflow-trigger`, U.append(this.icon("ellipsis"));
|
|
613
|
+
let W = document.createElement("mint-popover");
|
|
614
|
+
W.setAttribute("trigger-id", U.id), W.setAttribute("padding", "0.25rem"), W.setAttribute("direction", "down"), W.className = "mint-editor-menu-popover mint-editor-overflow-popover", e.append(U, W), this.overflowTrigger = U, this.overflowPopover = W, this.overflowGroups = f;
|
|
615
|
+
}
|
|
616
|
+
buildColorPopover(e, t, n) {
|
|
617
|
+
let r = [
|
|
618
|
+
"#bcebd1",
|
|
619
|
+
"#fff0b3",
|
|
620
|
+
"#f7c9c9",
|
|
621
|
+
"#e9c8f5",
|
|
622
|
+
"#c4e1f2",
|
|
623
|
+
"#20bd70",
|
|
624
|
+
"#f1c40f",
|
|
625
|
+
"#e33b2e",
|
|
626
|
+
"#b65bd0",
|
|
627
|
+
"#3298d4",
|
|
628
|
+
"#168f77",
|
|
629
|
+
"#e77d1e",
|
|
630
|
+
"#b9372b",
|
|
631
|
+
"#823a9d",
|
|
632
|
+
"#2874a6",
|
|
633
|
+
"#edf0f2",
|
|
634
|
+
"#cfd5d8",
|
|
635
|
+
"#9eadae",
|
|
636
|
+
"#7e8d8f",
|
|
637
|
+
"#35495e"
|
|
638
|
+
], i = document.createElement("div");
|
|
639
|
+
i.className = "mint-editor-color-grid", i.setAttribute("role", "group"), i.setAttribute("aria-label", t === "text" ? "Text colors" : "Highlight colors");
|
|
640
|
+
let a = () => t === "text" ? this.lastTextColor : this.lastBackgroundColor, o = (r, o = !0) => {
|
|
641
|
+
this.applyEditorColor(t, r);
|
|
642
|
+
let s = this.colorRecentSwatches.get(t);
|
|
643
|
+
s && (s.style.backgroundColor = a(), s.dataset.color = a());
|
|
644
|
+
let c = e.querySelector("input[type=\"color\"]");
|
|
645
|
+
c && document.activeElement !== c && (c.value = a()), n.style.setProperty("--editor-color", a()), i.querySelectorAll(".mint-editor-color-swatch").forEach((e) => {
|
|
646
|
+
let t = !!e.dataset.color && e.dataset.color.toLowerCase() === a().toLowerCase();
|
|
647
|
+
e.toggleAttribute("data-selected", t), e.setAttribute("aria-pressed", String(t));
|
|
648
|
+
}), o && e.close();
|
|
649
|
+
}, s = (e, t, n = "") => {
|
|
650
|
+
let r = document.createElement("button");
|
|
651
|
+
return r.type = "button", r.className = `mint-editor-color-swatch ${n}`.trim(), r.dataset.color = t, r.style.backgroundColor = t, r.setAttribute("aria-label", e), r.setAttribute("aria-pressed", String(t.toLowerCase() === a().toLowerCase())), r.toggleAttribute("data-selected", t.toLowerCase() === a().toLowerCase()), this.setTooltip(r, e), r.addEventListener("pointerdown", (e) => {
|
|
652
|
+
e.preventDefault(), this.saveSelection();
|
|
653
|
+
}), r.addEventListener("click", (e) => {
|
|
654
|
+
e.preventDefault(), o(t);
|
|
655
|
+
}), i.append(r), r;
|
|
656
|
+
};
|
|
657
|
+
r.forEach((e, t) => s(`Color ${t + 1}: ${e}`, e)), s("Black", "#000000", "is-utility-swatch"), s("White", "#ffffff", "is-utility-swatch");
|
|
658
|
+
let c = s("Last used color", a(), "is-utility-swatch is-recent-swatch");
|
|
659
|
+
this.colorRecentSwatches.set(t, c);
|
|
660
|
+
let l = document.createElement("button");
|
|
661
|
+
l.type = "button", l.className = "mint-editor-color-swatch mint-editor-no-color", l.setAttribute("aria-label", t === "text" ? "Reset text color" : "Remove highlight"), l.textContent = "/", this.setTooltip(l, t === "text" ? "Reset text color" : "Remove highlight"), l.addEventListener("pointerdown", (e) => {
|
|
662
|
+
e.preventDefault(), this.saveSelection();
|
|
663
|
+
}), l.addEventListener("click", (e) => {
|
|
664
|
+
e.preventDefault(), o(null);
|
|
665
|
+
}), i.append(l);
|
|
666
|
+
let u = document.createElement("input");
|
|
667
|
+
u.type = "color", u.className = "mint-editor-native-color-picker", u.value = a(), u.setAttribute("aria-label", "Choose a custom color");
|
|
668
|
+
let d = document.createElement("button");
|
|
669
|
+
d.type = "button", d.className = "mint-editor-color-swatch mint-editor-custom-color", d.setAttribute("aria-label", "Choose custom color"), d.append(this.icon("palette")), this.setTooltip(d, "Choose custom color"), d.addEventListener("pointerdown", (e) => {
|
|
670
|
+
e.preventDefault(), this.saveSelection();
|
|
671
|
+
}), d.addEventListener("click", (e) => {
|
|
672
|
+
e.preventDefault(), e.stopPropagation(), u.click();
|
|
673
|
+
}), u.addEventListener("pointerdown", () => this.saveSelection()), u.addEventListener("click", (e) => e.stopPropagation()), u.addEventListener("input", () => n.style.setProperty("--editor-color", u.value)), u.addEventListener("change", () => o(u.value));
|
|
674
|
+
let f = document.createElement("div");
|
|
675
|
+
f.className = "mint-editor-custom-color-cell", f.append(d, u), i.append(f), e.append(i);
|
|
676
|
+
}
|
|
677
|
+
applyEditorColor(e, t) {
|
|
678
|
+
if (!this.editor || this.sourceMode) return;
|
|
679
|
+
this.editor.focus(), this.restoreSelection();
|
|
680
|
+
let n = this.editor.ownerDocument, r = this.selection, i = e === "text" ? t || getComputedStyle(this.editor).color || "#202833" : t || getComputedStyle(this.editor).backgroundColor || "transparent";
|
|
681
|
+
if (r?.isCollapsed) {
|
|
682
|
+
this.inlineStyleOverrides.set(e === "text" ? "color" : "backgroundColor", i), this.preserveInlineOverridesOnNextEditorClick = !0, e === "text" && t && (this.lastTextColor = t), e === "background" && t && (this.lastBackgroundColor = t), this.colorTriggers.get(e)?.style.setProperty("--editor-color", e === "text" ? this.lastTextColor : this.lastBackgroundColor), this.emitChange(), this.updateSelectionUI();
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), e === "text" ? (n.execCommand("foreColor", !1, i), t && (this.lastTextColor = t), this.colorTriggers.get("text")?.style.setProperty("--editor-color", this.lastTextColor)) : (n.execCommand("hiliteColor", !1, i) || n.execCommand("backColor", !1, i), t && (this.lastBackgroundColor = t), this.colorTriggers.get("background")?.style.setProperty("--editor-color", this.lastBackgroundColor)), this.emitChange(), this.updateSelectionUI();
|
|
686
|
+
}
|
|
687
|
+
readFontSize() {
|
|
688
|
+
let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
|
|
689
|
+
if (Number.isFinite(t) && t > 0) return Math.round(t);
|
|
690
|
+
let n = this._savedRange, r = e?.anchorNode && this.editor?.contains(e.anchorNode) ? e.anchorNode : n?.startContainer, i = r?.nodeType === Node.ELEMENT_NODE ? r : r?.parentElement, a = i ? Number.parseFloat(getComputedStyle(i).fontSize) : 16;
|
|
691
|
+
return Number.isFinite(a) && a > 0 ? Math.round(a) : 16;
|
|
692
|
+
}
|
|
693
|
+
applyFontSize(e) {
|
|
694
|
+
if (!this.editor || this.sourceMode) return;
|
|
695
|
+
let t = Math.max(8, Math.min(96, Math.round(e)));
|
|
696
|
+
this.editor.focus(), this.restoreSelection();
|
|
697
|
+
let n = this.editor.ownerDocument;
|
|
698
|
+
if (this.selection?.isCollapsed) {
|
|
699
|
+
this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
this.inlineStyleOverrides.delete("fontSize");
|
|
703
|
+
let r = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
|
|
704
|
+
n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((e) => {
|
|
705
|
+
if (r.has(e)) return;
|
|
706
|
+
let i = n.createElement("span");
|
|
707
|
+
i.style.fontSize = `${t}px`, e.getAttribute("face") && (i.style.fontFamily = e.getAttribute("face") || ""), e.getAttribute("color") && (i.style.color = e.getAttribute("color") || ""), i.append(...Array.from(e.childNodes)), e.replaceWith(i);
|
|
708
|
+
}), this.emitChange(), this.updateSelectionUI();
|
|
709
|
+
}
|
|
710
|
+
applyFontFamily(e) {
|
|
711
|
+
if (!this.editor || this.sourceMode) return;
|
|
712
|
+
if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
|
|
713
|
+
this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
this.inlineStyleOverrides.delete("fontFamily");
|
|
717
|
+
let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
|
|
718
|
+
t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
|
|
719
|
+
if (n.has(r)) return;
|
|
720
|
+
let i = t.createElement("span");
|
|
721
|
+
i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
|
|
722
|
+
}), this.emitChange(), this.updateSelectionUI();
|
|
723
|
+
}
|
|
724
|
+
applyListStyle(e, t) {
|
|
725
|
+
if (!this.editor || this.sourceMode) return;
|
|
726
|
+
this.editor.focus(), this.restoreSelection();
|
|
727
|
+
let n = this.selection?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest(e), i = r && this.editor.contains(r) ? r : null;
|
|
728
|
+
if (!i) {
|
|
729
|
+
this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
|
|
730
|
+
let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
|
|
731
|
+
i = n && this.editor.contains(n) ? n : null;
|
|
732
|
+
}
|
|
733
|
+
i && (i.style.listStyleType = t), this.emitChange(), this.updateSelectionUI();
|
|
734
|
+
}
|
|
735
|
+
toggleChecklist() {
|
|
736
|
+
if (!this.editor || this.sourceMode) return;
|
|
737
|
+
this.editor.focus(), this.restoreSelection();
|
|
738
|
+
let e = this.editor.ownerDocument, t = this.selection?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, r = n?.closest("ul[data-mint-task-list]"), i = n?.closest("ul");
|
|
739
|
+
if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
|
|
740
|
+
else {
|
|
741
|
+
i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
|
|
742
|
+
let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
|
|
743
|
+
if (a && this.editor.contains(a)) {
|
|
744
|
+
a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
|
|
745
|
+
if (t.querySelector("input[type=\"checkbox\"]")) return;
|
|
746
|
+
let r = e.createElement("input");
|
|
747
|
+
r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
|
|
748
|
+
});
|
|
749
|
+
let t = a.parentElement;
|
|
750
|
+
t && t !== this.editor && /^(P|H[1-6])$/.test(t.tagName) && t.parentElement === this.editor && (Array.from(t.childNodes).filter((e) => e === a ? !1 : e.nodeType === Node.TEXT_NODE ? !!e.textContent?.trim() : e.nodeType === Node.ELEMENT_NODE && !e.matches("br")).length === 0 ? t.replaceWith(a) : t.parentNode?.insertBefore(a, t.nextSibling));
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
this.emitChange(), this.updateSelectionUI();
|
|
754
|
+
}
|
|
755
|
+
splitTaskItem(e, t) {
|
|
756
|
+
if (!this.editor) return;
|
|
757
|
+
let n = this.editor.ownerDocument, r = this.selection, i = r?.anchorNode, a = Array.from(e.children).find((e) => e.matches("input[type=\"checkbox\"]"));
|
|
758
|
+
if (a) e.firstChild !== a && (a.remove(), e.insertBefore(a, e.firstChild));
|
|
759
|
+
else {
|
|
760
|
+
let r = n.createElement("input");
|
|
761
|
+
r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${t.children.length} complete`), e.insertBefore(r, e.firstChild);
|
|
762
|
+
}
|
|
763
|
+
let o = n.createRange();
|
|
764
|
+
r?.isCollapsed && i && (i === e || e.contains(i)) ? o.setStart(i, r.anchorOffset) : o.setStart(e, e.childNodes.length), o.setEnd(e, e.childNodes.length);
|
|
765
|
+
let s = o.extractContents(), c = n.createElement("li"), l = n.createElement("input");
|
|
766
|
+
l.type = "checkbox", l.setAttribute("contenteditable", "false"), l.setAttribute("aria-label", `Task ${t.children.length + 1} complete`), c.append(l, s), this.isEmptyTaskItem(c) && c.append(n.createElement("br")), this.isEmptyTaskItem(e) && e.append(n.createElement("br")), t.insertBefore(c, e.nextSibling);
|
|
767
|
+
let u = n.createRange();
|
|
768
|
+
u.setStart(c, 1), u.collapse(!0), r?.removeAllRanges(), r?.addRange(u), this.syncSource(), this.emitChange(), this.updateSelectionUI();
|
|
769
|
+
}
|
|
770
|
+
normalizeTaskListItems() {
|
|
771
|
+
if (!this.editor) return;
|
|
772
|
+
let e = this.selection, t = e?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t.closest("li") : t?.parentElement?.closest("li");
|
|
773
|
+
for (let r of this.editor.querySelectorAll("ul[data-mint-task-list]")) Array.from(r.children).forEach((r, i) => {
|
|
774
|
+
if (r.tagName !== "LI") return;
|
|
775
|
+
let a = r, o = Array.from(a.children).find((e) => e.matches("input[type=\"checkbox\"]"));
|
|
776
|
+
if (!o) {
|
|
777
|
+
if (o = this.editor.ownerDocument.createElement("input"), o.type = "checkbox", o.setAttribute("contenteditable", "false"), o.setAttribute("aria-label", `Task ${i + 1} complete`), a.insertBefore(o, a.firstChild), e?.isCollapsed && n === a && t === a) {
|
|
778
|
+
let t = this.editor.ownerDocument.createRange();
|
|
779
|
+
t.setStart(a, 1), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
|
|
780
|
+
}
|
|
781
|
+
} else if (o.setAttribute("contenteditable", "false"), o.hasAttribute("aria-label") || o.setAttribute("aria-label", `Task ${i + 1} complete`), a.firstChild !== o && (o.remove(), a.insertBefore(o, a.firstChild), e?.isCollapsed && n === a && t === a)) {
|
|
782
|
+
let t = this.editor.ownerDocument.createRange();
|
|
783
|
+
t.setStart(a, 1), t.collapse(!0), e.removeAllRanges(), e.addRange(t);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
isEmptyTaskItem(e) {
|
|
788
|
+
let t = (e) => {
|
|
789
|
+
if (e.nodeType === Node.TEXT_NODE) return !!e.textContent?.trim();
|
|
790
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return !1;
|
|
791
|
+
let n = e;
|
|
792
|
+
return n.matches("input[type=\"checkbox\"], br") ? !1 : n.matches("img, video, audio, iframe, table, hr, pre, canvas, object, embed") ? !0 : Array.from(n.childNodes).some(t);
|
|
793
|
+
};
|
|
794
|
+
return !Array.from(e.childNodes).some(t);
|
|
795
|
+
}
|
|
796
|
+
exitTaskList(e, t) {
|
|
797
|
+
if (!this.editor || !t.parentNode) return;
|
|
798
|
+
let n = t.parentNode, r = t.cloneNode(!1);
|
|
799
|
+
for (; e.nextElementSibling;) r.append(e.nextElementSibling);
|
|
800
|
+
e.remove();
|
|
801
|
+
let i = this.editor.ownerDocument.createElement("p");
|
|
802
|
+
i.append(this.editor.ownerDocument.createElement("br")), t.children.length > 0 ? n.insertBefore(i, t.nextSibling) : (n.insertBefore(i, t), t.remove()), r.children.length && n.insertBefore(r, i.nextSibling), this.editor.focus();
|
|
803
|
+
let a = this.selection, o = this.editor.ownerDocument.createRange();
|
|
804
|
+
o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
|
|
805
|
+
}
|
|
806
|
+
openCommentModal() {
|
|
807
|
+
this.saveSelection();
|
|
808
|
+
let e = this._savedRange?.toString() || "", t = document.createElement("mint-modal");
|
|
809
|
+
t.setAttribute("heading", "Add comment"), t.setAttribute("size", "small");
|
|
810
|
+
let n = document.createElement("div");
|
|
811
|
+
n.setAttribute("slot", "body"), n.className = "mint-editor-modal-fields";
|
|
812
|
+
let r = document.createElement("p");
|
|
813
|
+
r.className = "mint-editor-comment-hint", r.textContent = e ? `Comment on: “${e.slice(0, 120)}${e.length > 120 ? "…" : ""}”` : "Select some text in the document before adding a comment.";
|
|
814
|
+
let i = document.createElement("textarea");
|
|
815
|
+
i.className = "mint-editor-comment-input", i.setAttribute("aria-label", "Comment"), i.setAttribute("placeholder", "Write a comment…"), i.rows = 4, n.append(r, i);
|
|
816
|
+
let a = document.createElement("div");
|
|
817
|
+
a.setAttribute("slot", "actions"), a.className = "mint-editor-modal-actions";
|
|
818
|
+
let o = document.createElement("mint-button");
|
|
819
|
+
o.textContent = "Cancel", o.setAttribute("variant", "ghost"), this.setTooltip(o, "Cancel"), o.addEventListener("click", () => t.close());
|
|
820
|
+
let s = document.createElement("mint-button");
|
|
821
|
+
s.textContent = "Add comment", s.setAttribute("tone", "action"), s.toggleAttribute("disabled", !e), this.setTooltip(s, "Add comment"), s.addEventListener("click", () => {
|
|
822
|
+
let n = i.value.trim();
|
|
823
|
+
!n || !e || (this.insertComment(n, e), t.close());
|
|
824
|
+
}), a.append(o, s), t.append(n, a), this.append(t), t.open();
|
|
825
|
+
}
|
|
826
|
+
insertComment(e, t) {
|
|
827
|
+
let n = this._savedRange;
|
|
828
|
+
if (this.editor && n && !n.collapsed && this.editor.contains(n.commonAncestorContainer) && this.format === "html") {
|
|
829
|
+
let t = this.editor.ownerDocument.createElement("span");
|
|
830
|
+
t.className = "mint-editor-comment", t.setAttribute("data-mint-comment", e), t.title = `Comment: ${e}`, t.append(n.extractContents()), n.insertNode(t);
|
|
831
|
+
let r = this.selection;
|
|
832
|
+
n.selectNodeContents(t), r?.removeAllRanges(), r?.addRange(n);
|
|
833
|
+
}
|
|
834
|
+
this.dispatchEvent(new CustomEvent("mint-editor-comment-request", {
|
|
835
|
+
bubbles: !0,
|
|
836
|
+
composed: !0,
|
|
837
|
+
detail: {
|
|
838
|
+
selectedText: t,
|
|
839
|
+
comment: e,
|
|
840
|
+
format: this.format
|
|
841
|
+
}
|
|
842
|
+
})), this.emitChange();
|
|
843
|
+
}
|
|
844
|
+
updateToolbarOverflow() {
|
|
845
|
+
let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
|
|
846
|
+
if (!e || !t || !n) return;
|
|
847
|
+
let r = e.querySelector(".mint-editor-toolbar-actions"), i = this.blockButton;
|
|
848
|
+
if (!r || !i) return;
|
|
849
|
+
for (let e of this.overflowGroups) for (let t of e) r.append(t);
|
|
850
|
+
t.hidden = !1;
|
|
851
|
+
let a = this.overflowGroups.length - 1, o = () => {
|
|
852
|
+
let e = [...r.children].filter((e) => e instanceof HTMLElement && !e.matches("mint-popover") && !e.hidden), t = Number.parseFloat(getComputedStyle(r).columnGap) || 0;
|
|
853
|
+
return e.reduce((e, t) => e + t.getBoundingClientRect().width, 0) + Math.max(0, e.length - 1) * t;
|
|
854
|
+
};
|
|
855
|
+
for (; o() > r.clientWidth + 1 && a >= 0;) [...this.overflowGroups[a]].reverse().filter((e) => !e.matches("mint-popover")).forEach((e) => n.insertBefore(e, n.firstChild)), a--;
|
|
856
|
+
t.hidden = n.childElementCount === 0;
|
|
857
|
+
}
|
|
858
|
+
clearFormatting() {
|
|
859
|
+
!this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
|
|
860
|
+
}
|
|
861
|
+
icon(e) {
|
|
862
|
+
let t = document.createElement("mint-icon");
|
|
863
|
+
return t.setAttribute("name", e), t.setAttribute("aria-hidden", "true"), t;
|
|
864
|
+
}
|
|
865
|
+
setTooltip(e, t) {
|
|
866
|
+
this.updateTooltipLabel(e, t), e.dataset.editorTooltipBound !== "true" && (e.dataset.editorTooltipBound = "true", e.addEventListener("pointerenter", () => this.showTooltip(e)), e.addEventListener("pointerleave", () => this.hideTooltip()), e.addEventListener("focus", () => this.showTooltip(e)), e.addEventListener("blur", () => this.hideTooltip()));
|
|
867
|
+
}
|
|
868
|
+
updateTooltipLabel(e, t) {
|
|
869
|
+
e.setAttribute("data-editor-tooltip", t);
|
|
870
|
+
let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
|
|
871
|
+
e.setAttribute("data-editor-overflow-label", r), e.setAttribute("aria-label", t), e.removeAttribute("title");
|
|
872
|
+
}
|
|
873
|
+
showTooltip(e) {
|
|
874
|
+
if (e.closest(".mint-editor-overflow-popover")) {
|
|
875
|
+
this.hideTooltip();
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
let t = e.getAttribute("data-editor-tooltip");
|
|
879
|
+
if (!t || e.matches(":disabled,[hidden]")) return;
|
|
880
|
+
let n = this.tooltipPopup;
|
|
881
|
+
if (!n) {
|
|
882
|
+
n = document.createElement("div"), n.className = "mint-editor-tooltip-popup", n.setAttribute("role", "tooltip"), n.setAttribute("aria-hidden", "true");
|
|
883
|
+
let e = getComputedStyle(this);
|
|
884
|
+
[
|
|
885
|
+
"text",
|
|
886
|
+
"surface",
|
|
887
|
+
"border"
|
|
888
|
+
].forEach((t) => {
|
|
889
|
+
let r = e.getPropertyValue(`--mint-color-${t}`).trim();
|
|
890
|
+
r && n.style.setProperty(`--mint-color-${t}`, r);
|
|
891
|
+
}), document.body.append(n), this.tooltipPopup = n;
|
|
892
|
+
}
|
|
893
|
+
n.textContent = t, n.setAttribute("aria-hidden", "false"), n.style.visibility = "hidden", n.style.display = "block";
|
|
894
|
+
let r = e.getBoundingClientRect(), i = n.getBoundingClientRect(), a = Math.max(8, Math.min(window.innerWidth - i.width - 8, r.left + r.width / 2 - i.width / 2)), o = r.top >= i.height + 6 + 8 ? r.top - i.height - 6 : Math.min(window.innerHeight - i.height - 8, r.bottom + 6);
|
|
895
|
+
n.style.left = `${a}px`, n.style.top = `${o}px`, n.style.visibility = "visible";
|
|
896
|
+
}
|
|
897
|
+
hideTooltip() {
|
|
898
|
+
this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
|
|
899
|
+
}
|
|
900
|
+
closeEditorPopovers() {
|
|
901
|
+
this.querySelectorAll("mint-popover").forEach((e) => {
|
|
902
|
+
e.close?.call(e);
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
createMenuOption(e, t) {
|
|
906
|
+
let n = {
|
|
907
|
+
"table-row": "table",
|
|
908
|
+
"table-column": "columns",
|
|
909
|
+
"table-row-delete": "remove",
|
|
910
|
+
"table-column-delete": "remove",
|
|
911
|
+
paragraph: "file-alt",
|
|
912
|
+
heading: "heading"
|
|
913
|
+
}, r = document.createElement("button");
|
|
914
|
+
r.type = "button", r.className = "mint-editor-menu-option";
|
|
915
|
+
let i = this.icon(n[t] || t);
|
|
916
|
+
i.classList.add("mint-editor-menu-icon");
|
|
917
|
+
let a = document.createElement("span");
|
|
918
|
+
return a.className = "mint-editor-menu-label", a.textContent = e, r.append(i, a), r;
|
|
919
|
+
}
|
|
920
|
+
updateFormatUI() {
|
|
921
|
+
if (this.source && this.source.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), this.sourceButton) {
|
|
922
|
+
let e = `${this.format.toUpperCase()} source`, t = this.sourceButton.querySelector(".mint-editor-button-label");
|
|
923
|
+
t && (t.textContent = e), this.updateTooltipLabel(this.sourceButton, e);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
separator() {
|
|
927
|
+
let e = document.createElement("span");
|
|
928
|
+
return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
|
|
929
|
+
}
|
|
930
|
+
command(e, t) {
|
|
931
|
+
!this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
|
|
932
|
+
}
|
|
933
|
+
toggleInline(e) {
|
|
934
|
+
if (!this.editor || this.sourceMode) return;
|
|
935
|
+
this.editor.focus(), this.restoreSelection();
|
|
936
|
+
let t = this.selection;
|
|
937
|
+
if (!t?.rangeCount || !this.editor.contains(t.anchorNode)) return;
|
|
938
|
+
let n = t.getRangeAt(0), r = !this.inlineStateAtSelection(e, n), i = this.editor.ownerDocument;
|
|
939
|
+
if (n.collapsed) {
|
|
940
|
+
this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
|
|
944
|
+
}
|
|
945
|
+
inlineStateAtSelection(e, t) {
|
|
946
|
+
let n = this.selection, r = this.inlineOverrides.get(e);
|
|
947
|
+
if (t.collapsed && r !== void 0) return r;
|
|
948
|
+
let i = this.formatAtCaret(e, t);
|
|
949
|
+
if (i || !t.collapsed) return i;
|
|
950
|
+
let a = t.cloneRange(), o = t.startContainer, s = t.startOffset;
|
|
951
|
+
if (o.nodeType !== Node.TEXT_NODE || s === 0) {
|
|
952
|
+
let e = o.nodeType === Node.ELEMENT_NODE ? o.childNodes[s - 1] : null;
|
|
953
|
+
if (e) {
|
|
954
|
+
for (o = e; o.lastChild;) o = o.lastChild;
|
|
955
|
+
o.nodeType === Node.TEXT_NODE && (s = o.textContent?.length || 0);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (o.nodeType === Node.TEXT_NODE && s > 0) try {
|
|
959
|
+
a.setStart(o, s - 1), a.setEnd(o, s), n?.removeAllRanges(), n?.addRange(a), i = this.formatAtCaret(e, a);
|
|
960
|
+
} catch {} finally {
|
|
961
|
+
n?.removeAllRanges(), n?.addRange(t);
|
|
962
|
+
}
|
|
963
|
+
return i;
|
|
964
|
+
}
|
|
965
|
+
applyInlineTypingState(e) {
|
|
966
|
+
if (e.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1), e.inputType.startsWith("delete")) {
|
|
967
|
+
this.clearInlineTypingState();
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
if (!this.editor || this.sourceMode || e.inputType !== "insertText" || !e.data || this.inlineOverrides.size === 0 && this.inlineStyleOverrides.size === 0) return;
|
|
971
|
+
let t = this.selection;
|
|
972
|
+
if (!t?.rangeCount || !t.isCollapsed || !this.editor.contains(t.anchorNode)) return;
|
|
973
|
+
let n = t.getRangeAt(0), r = this.editor.ownerDocument;
|
|
974
|
+
e.preventDefault();
|
|
975
|
+
let i = r.createTextNode(e.data), a = [
|
|
976
|
+
"bold",
|
|
977
|
+
"italic",
|
|
978
|
+
"underline"
|
|
979
|
+
].map((e) => {
|
|
980
|
+
let t = this.formatAtCaret(e, n);
|
|
981
|
+
return [
|
|
982
|
+
e,
|
|
983
|
+
this.inlineOverrides.has(e) ? this.inlineOverrides.get(e) : t,
|
|
984
|
+
t
|
|
985
|
+
];
|
|
986
|
+
}), o = a.some(([e, t, n]) => e === "underline" && !t && n) ? (n.startContainer.nodeType === Node.ELEMENT_NODE ? n.startContainer : n.startContainer.parentElement)?.closest("u") : null;
|
|
987
|
+
for (let [e, t, n] of a.reverse()) {
|
|
988
|
+
if (t === n) continue;
|
|
989
|
+
let a = t ? e === "bold" ? "strong" : e === "italic" ? "em" : "u" : "span", o = r.createElement(a);
|
|
990
|
+
t || (e === "bold" ? o.style.fontWeight = "normal" : e === "italic" ? o.style.fontStyle = "normal" : o.style.textDecoration = "none"), o.append(i), i = o;
|
|
991
|
+
}
|
|
992
|
+
if (this.inlineStyleOverrides.size) {
|
|
993
|
+
let e = r.createElement("span");
|
|
994
|
+
this.inlineStyleOverrides.forEach((t, n) => {
|
|
995
|
+
e.style[n] = t;
|
|
996
|
+
}), e.append(i), i = e;
|
|
997
|
+
}
|
|
998
|
+
if (n.deleteContents(), n.insertNode(i), o && o.parentNode && this.isAtEndOfInlineRun(i, o)) {
|
|
999
|
+
o.parentNode.insertBefore(i, o.nextSibling);
|
|
1000
|
+
for (let e = i.parentNode; e && e !== o;) {
|
|
1001
|
+
let t = e.parentNode;
|
|
1002
|
+
e instanceof HTMLElement && !e.textContent?.length && !e.querySelector("img,br,table,hr,iframe,video,audio") && e.remove(), e = t;
|
|
1003
|
+
}
|
|
1004
|
+
!o.textContent?.length && !o.querySelector("img,br,table,hr,iframe,video,audio") && o.remove();
|
|
1005
|
+
}
|
|
1006
|
+
let s = i;
|
|
1007
|
+
for (; s.lastChild;) s = s.lastChild;
|
|
1008
|
+
s.nodeType === Node.TEXT_NODE ? n.setStart(s, s.textContent?.length || 0) : n.setStartAfter(s), n.collapse(!0), t.removeAllRanges(), t.addRange(n), this.editor.dispatchEvent(new InputEvent("input", {
|
|
1009
|
+
bubbles: !0,
|
|
1010
|
+
inputType: "insertText",
|
|
1011
|
+
data: e.data
|
|
1012
|
+
}));
|
|
1013
|
+
}
|
|
1014
|
+
isAtEndOfInlineRun(e, t) {
|
|
1015
|
+
for (let n = e; n && n !== t; n = n.parentNode) for (let e = n.nextSibling; e; e = e.nextSibling) if (!(e.nodeType === Node.TEXT_NODE && !e.textContent?.trim())) return !1;
|
|
1016
|
+
return !0;
|
|
1017
|
+
}
|
|
1018
|
+
formatAtCaret(e, t) {
|
|
1019
|
+
let n = t.startContainer, r = n.nodeType === Node.ELEMENT_NODE ? n : n.parentElement;
|
|
1020
|
+
if (t.collapsed && n.nodeType === Node.ELEMENT_NODE && t.startOffset > 0) {
|
|
1021
|
+
let e = n.childNodes[t.startOffset - 1];
|
|
1022
|
+
for (; e?.lastChild;) e = e.lastChild;
|
|
1023
|
+
e?.nodeType === Node.TEXT_NODE ? r = e.parentElement : e?.nodeType === Node.ELEMENT_NODE && (r = e);
|
|
1024
|
+
}
|
|
1025
|
+
if (!r) return !1;
|
|
1026
|
+
let i = [];
|
|
1027
|
+
for (let e = r; e && e !== this.editor; e = e.parentElement) i.push(e);
|
|
1028
|
+
for (let t of i) {
|
|
1029
|
+
let n = t.style;
|
|
1030
|
+
if (e === "bold") {
|
|
1031
|
+
if (n.fontWeight) {
|
|
1032
|
+
let e = Number.parseInt(n.fontWeight, 10);
|
|
1033
|
+
return Number.isFinite(e) ? e >= 600 : n.fontWeight === "bold" || n.fontWeight === "bolder";
|
|
1034
|
+
}
|
|
1035
|
+
if (["B", "STRONG"].includes(t.tagName)) return !0;
|
|
1036
|
+
} else if (e === "italic") {
|
|
1037
|
+
if (n.fontStyle) return ["italic", "oblique"].includes(n.fontStyle);
|
|
1038
|
+
if (["I", "EM"].includes(t.tagName)) return !0;
|
|
1039
|
+
} else {
|
|
1040
|
+
if (n.textDecorationLine || n.textDecoration) return (n.textDecorationLine || n.textDecoration).includes("underline");
|
|
1041
|
+
if (t.tagName === "U") return !0;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
let a = getComputedStyle(r);
|
|
1045
|
+
if (e === "bold") {
|
|
1046
|
+
let e = Number.parseInt(a.fontWeight, 10);
|
|
1047
|
+
return Number.isFinite(e) && e >= 600;
|
|
1048
|
+
}
|
|
1049
|
+
return e === "italic" ? ["italic", "oblique"].includes(a.fontStyle) : a.textDecorationLine.includes("underline");
|
|
1050
|
+
}
|
|
1051
|
+
requestResource() {
|
|
1052
|
+
this.saveSelection(), this.dispatchEvent(new CustomEvent("mint-editor-resource-request", {
|
|
1053
|
+
bubbles: !0,
|
|
1054
|
+
composed: !0,
|
|
1055
|
+
detail: { resourceType: "media" }
|
|
1056
|
+
}));
|
|
1057
|
+
}
|
|
1058
|
+
get selection() {
|
|
1059
|
+
return this.editor?.ownerDocument.getSelection() || null;
|
|
1060
|
+
}
|
|
1061
|
+
saveSelection() {
|
|
1062
|
+
let e = this.selection;
|
|
1063
|
+
e?.rangeCount && this.editor?.contains(e.anchorNode) && (this._savedRange = e.getRangeAt(0).cloneRange());
|
|
1064
|
+
}
|
|
1065
|
+
restoreSelection() {
|
|
1066
|
+
let e = this._savedRange;
|
|
1067
|
+
if (!e) return;
|
|
1068
|
+
let t = this.selection;
|
|
1069
|
+
t?.removeAllRanges(), t?.addRange(e), this._savedRange = void 0;
|
|
1070
|
+
}
|
|
1071
|
+
clearInlineTypingState() {
|
|
1072
|
+
this.inlineOverrides.clear(), this.inlineStyleOverrides.clear(), this.preserveInlineOverridesOnNextEditorClick = !1;
|
|
1073
|
+
}
|
|
1074
|
+
cleanEditorCopy() {
|
|
1075
|
+
let e = this.editor?.cloneNode(!0);
|
|
1076
|
+
return e ? (e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.querySelectorAll(".mint-editor-image-frame,table").forEach((e) => e.classList.remove("is-selected")), e) : document.createElement("div");
|
|
1077
|
+
}
|
|
1078
|
+
insertPastedHtml(e) {
|
|
1079
|
+
let t = this.editor, n = this.selection;
|
|
1080
|
+
if (!t || !n?.rangeCount) return;
|
|
1081
|
+
let r = t.ownerDocument, i = n.getRangeAt(0);
|
|
1082
|
+
if (!t.contains(i.startContainer) || !t.contains(i.endContainer)) return;
|
|
1083
|
+
let a = r.createElement("div");
|
|
1084
|
+
a.innerHTML = e;
|
|
1085
|
+
let o = r.createDocumentFragment();
|
|
1086
|
+
for (; a.firstChild;) o.append(a.firstChild);
|
|
1087
|
+
if (!o.hasChildNodes()) return;
|
|
1088
|
+
let s = !!o.querySelector?.("p,h1,h2,h3,h4,h5,h6,blockquote,pre,div,ul,ol,table"), c = !i.collapsed && i.toString() === t.textContent, l = i.startContainer === t && i.startOffset === 0 && i.endContainer === t && i.endOffset === t.childNodes.length;
|
|
1089
|
+
if (c || l) {
|
|
1090
|
+
t.replaceChildren(o), this.placeCaretAfterPastedContent(t.lastChild, n);
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
i.deleteContents(), i.collapse(!0);
|
|
1094
|
+
let u = i.startContainer;
|
|
1095
|
+
if (u.nodeType !== Node.ELEMENT_NODE && (u = u.parentNode || t), s) {
|
|
1096
|
+
let e = (u.nodeType === Node.ELEMENT_NODE ? u : u.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,pre");
|
|
1097
|
+
if (e && t.contains(e) && e.parentNode) {
|
|
1098
|
+
let t = r.createRange();
|
|
1099
|
+
t.selectNodeContents(e), t.setStart(i.startContainer, i.startOffset);
|
|
1100
|
+
let a = t.extractContents(), s = e.parentNode, c = e.nextSibling, l = e.cloneNode(!1);
|
|
1101
|
+
l.append(a);
|
|
1102
|
+
let u = this.hasPastedBlockContent(e), d = this.hasPastedBlockContent(l);
|
|
1103
|
+
u || s.removeChild(e);
|
|
1104
|
+
let f = o.lastChild;
|
|
1105
|
+
s.insertBefore(o, c), d ? s.insertBefore(l, c) : l.remove(), this.placeCaretAfterPastedContent(f, n);
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
let d = o.lastChild;
|
|
1110
|
+
i.insertNode(o), this.placeCaretAfterPastedContent(d, n);
|
|
1111
|
+
}
|
|
1112
|
+
hasPastedBlockContent(e) {
|
|
1113
|
+
return (e.textContent || "").replace(/\u00a0/g, " ").trim() ? !0 : !!e.querySelector("img,table,hr,ul,ol,iframe,video,audio");
|
|
1114
|
+
}
|
|
1115
|
+
placeCaretAfterPastedContent(e, t) {
|
|
1116
|
+
if (!e?.parentNode) return;
|
|
1117
|
+
let n = this.editor?.ownerDocument.createRange();
|
|
1118
|
+
n && (n.selectNodeContents(e), n.collapse(!1), t.removeAllRanges(), t.addRange(n), this.saveSelection());
|
|
1119
|
+
}
|
|
1120
|
+
sanitizePastedHtml(e) {
|
|
1121
|
+
let t = this.editor?.ownerDocument, n = t?.defaultView?.DOMParser;
|
|
1122
|
+
if (!t || !n) return "";
|
|
1123
|
+
let r = new n().parseFromString(e, "text/html"), i = r.body, a = /* @__PURE__ */ "color.background-color.font-family.font-size.font-weight.font-style.text-decoration.text-decoration-line.text-align.vertical-align.line-height.text-indent.list-style-type.margin-top.margin-right.margin-bottom.margin-left.padding-top.padding-right.padding-bottom.padding-left.border.border-top.border-right.border-bottom.border-left.border-collapse.width.height".split("."), o = (e) => {
|
|
1124
|
+
let t = r.createElement("span");
|
|
1125
|
+
t.setAttribute("style", e);
|
|
1126
|
+
let n = /* @__PURE__ */ new Map();
|
|
1127
|
+
for (let e of a) {
|
|
1128
|
+
let r = t.style.getPropertyValue(e).trim();
|
|
1129
|
+
!r || /url\s*\(|expression\s*\(/i.test(r) || e.startsWith("margin-") && Number.parseFloat(r) === 0 || n.set(e, r);
|
|
1130
|
+
}
|
|
1131
|
+
let i = e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-size\s*:\s*([^;]+)/i)?.[1]?.trim();
|
|
1132
|
+
if (!n.has("font-size") && i) {
|
|
1133
|
+
t.style.setProperty("font-size", i);
|
|
1134
|
+
let e = t.style.getPropertyValue("font-size").trim();
|
|
1135
|
+
e && !/url\s*\(|expression\s*\(/i.test(e) && n.set("font-size", e);
|
|
1136
|
+
}
|
|
1137
|
+
let o = e.match(/(?:^|;)\s*mso-(?:ansi|bidi)-font-family\s*:\s*([^;]+)/i)?.[1]?.trim();
|
|
1138
|
+
if (!n.has("font-family") && o) {
|
|
1139
|
+
t.style.setProperty("font-family", o);
|
|
1140
|
+
let e = t.style.getPropertyValue("font-family").trim();
|
|
1141
|
+
e && !/url\s*\(|expression\s*\(/i.test(e) && n.set("font-family", e);
|
|
1142
|
+
}
|
|
1143
|
+
let s = e.match(/(?:^|;)\s*mso-highlight\s*:\s*([^;]+)/i)?.[1]?.trim();
|
|
1144
|
+
if (!n.has("background-color") && s) {
|
|
1145
|
+
t.style.backgroundColor = s;
|
|
1146
|
+
let e = t.style.backgroundColor.trim();
|
|
1147
|
+
e && n.set("background-color", e);
|
|
1148
|
+
}
|
|
1149
|
+
return !n.has("background-color") && t.style.backgroundColor && n.set("background-color", t.style.backgroundColor), Array.from(n, ([e, t]) => `${e}:${t}`).join(";");
|
|
1150
|
+
}, s = (e, t) => {
|
|
1151
|
+
let n = o([t, e.getAttribute("style") || ""].filter(Boolean).join(";"));
|
|
1152
|
+
n && e.setAttribute("style", n);
|
|
1153
|
+
};
|
|
1154
|
+
for (let e of Array.from(r.querySelectorAll("style"))) {
|
|
1155
|
+
let t = e.textContent || "";
|
|
1156
|
+
for (let e of t.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
1157
|
+
let t = e[2].trim();
|
|
1158
|
+
if (!(!t || !/\.(?:Mso|WordSection)/i.test(e[1]))) for (let n of e[1].split(",")) {
|
|
1159
|
+
let e = n.trim();
|
|
1160
|
+
if (/^(?:[a-z][\w-]*)?(?:\.[\w-]+)+$/i.test(e)) try {
|
|
1161
|
+
r.querySelectorAll(e).forEach((e) => s(e, t));
|
|
1162
|
+
} catch {}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
r.querySelectorAll("style,script,iframe,object,embed,form,input,button,select,textarea,link,meta,base,svg,math,canvas,video,audio").forEach((e) => e.remove());
|
|
1167
|
+
for (let e of Array.from(i.querySelectorAll("font"))) {
|
|
1168
|
+
let t = r.createElement("span"), n = [], i = e.getAttribute("face"), a = e.getAttribute("color"), s = e.getAttribute("size"), c = {
|
|
1169
|
+
1: "8pt",
|
|
1170
|
+
2: "10pt",
|
|
1171
|
+
3: "12pt",
|
|
1172
|
+
4: "14pt",
|
|
1173
|
+
5: "18pt",
|
|
1174
|
+
6: "24pt",
|
|
1175
|
+
7: "36pt"
|
|
1176
|
+
};
|
|
1177
|
+
i && n.push(`font-family:${i}`), a && n.push(`color:${a}`), s && c[s] && n.push(`font-size:${c[s]}`);
|
|
1178
|
+
let l = e.getAttribute("style") || "", u = o([n.join(";"), l].filter(Boolean).join(";"));
|
|
1179
|
+
for (u && t.setAttribute("style", u); e.firstChild;) t.append(e.firstChild);
|
|
1180
|
+
e.replaceWith(t);
|
|
1181
|
+
}
|
|
1182
|
+
for (let e of Array.from(i.querySelectorAll("p,div"))) {
|
|
1183
|
+
let t = e.getAttribute("class") || "", n = t.match(/MsoHeading([1-6])/i)?.[1] || (/MsoTitle/i.test(t) ? "1" : /MsoSubtitle/i.test(t) ? "2" : "");
|
|
1184
|
+
if (!n) continue;
|
|
1185
|
+
let i = r.createElement(`h${n}`);
|
|
1186
|
+
for (let t of Array.from(e.attributes)) i.setAttribute(t.name, t.value);
|
|
1187
|
+
for (; e.firstChild;) i.append(e.firstChild);
|
|
1188
|
+
e.replaceWith(i);
|
|
1189
|
+
}
|
|
1190
|
+
let c = (e) => {
|
|
1191
|
+
let t = r.createDocumentFragment(), n = null, i = "";
|
|
1192
|
+
for (let a of Array.from(e.childNodes)) if (a.nodeType === Node.ELEMENT_NODE) {
|
|
1193
|
+
let e = a, s = e.getAttribute("class") || "", l = e.getAttribute("style") || "", u = ["P", "DIV"].includes(e.tagName) && Array.from(e.children).find((e) => e.tagName === "SPAN" && /mso-list\s*:\s*ignore/i.test(e.getAttribute("style") || "")) || null;
|
|
1194
|
+
if (["P", "DIV"].includes(e.tagName) && (/mso-list\s*:/i.test(l) || /MsoListParagraph/i.test(s) || u)) {
|
|
1195
|
+
let a = (u?.textContent || e.textContent || "").replace(/\u00a0/g, " ").trim();
|
|
1196
|
+
u?.remove();
|
|
1197
|
+
let s = /^(?:\d+|[a-z]|[ivxlcdm]+)[.)]/i.test(a) ? "ol" : "ul";
|
|
1198
|
+
(!n || i !== s) && (n = r.createElement(s), i = s, t.append(n));
|
|
1199
|
+
let c = r.createElement("li"), d = o(l.replace(/(?:^|;)\s*mso-list\s*:[^;]*/gi, ""));
|
|
1200
|
+
for (d && c.setAttribute("style", d); e.firstChild;) c.append(e.firstChild);
|
|
1201
|
+
n.append(c);
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (n = null, i = "", c(e), e.tagName === "DIV" && /WordSection/i.test(s)) for (; e.firstChild;) t.append(e.firstChild);
|
|
1205
|
+
else t.append(e);
|
|
1206
|
+
} else a.nodeType === Node.TEXT_NODE && !(a.textContent || "").trim() ? n || t.append(a) : (n = null, i = "", a.nodeType !== Node.COMMENT_NODE && t.append(a));
|
|
1207
|
+
e.replaceChildren(t);
|
|
1208
|
+
};
|
|
1209
|
+
c(i);
|
|
1210
|
+
let l = (e) => {
|
|
1211
|
+
e.replaceWith(...Array.from(e.childNodes));
|
|
1212
|
+
};
|
|
1213
|
+
for (let e of Array.from(i.querySelectorAll("*"))) e.tagName.includes(":") && l(e);
|
|
1214
|
+
let u = new Set([
|
|
1215
|
+
"href",
|
|
1216
|
+
"src",
|
|
1217
|
+
"alt",
|
|
1218
|
+
"title",
|
|
1219
|
+
"colspan",
|
|
1220
|
+
"rowspan",
|
|
1221
|
+
"start",
|
|
1222
|
+
"value",
|
|
1223
|
+
"type",
|
|
1224
|
+
"width",
|
|
1225
|
+
"height",
|
|
1226
|
+
"border",
|
|
1227
|
+
"cellpadding",
|
|
1228
|
+
"cellspacing",
|
|
1229
|
+
"scope",
|
|
1230
|
+
"dir"
|
|
1231
|
+
]), d = (e, t = !1) => {
|
|
1232
|
+
let n = e.trim();
|
|
1233
|
+
if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
|
|
1234
|
+
try {
|
|
1235
|
+
return [
|
|
1236
|
+
"http:",
|
|
1237
|
+
"https:",
|
|
1238
|
+
"mailto:",
|
|
1239
|
+
"tel:"
|
|
1240
|
+
].includes(new URL(n, "https://mint.invalid").protocol);
|
|
1241
|
+
} catch {
|
|
1242
|
+
return !1;
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
for (let e of Array.from(i.querySelectorAll("*"))) for (let t of Array.from(e.attributes)) {
|
|
1246
|
+
let n = t.name.toLowerCase();
|
|
1247
|
+
if (n === "style") {
|
|
1248
|
+
let n = o(t.value);
|
|
1249
|
+
n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
|
|
1250
|
+
} else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
|
|
1251
|
+
"colspan",
|
|
1252
|
+
"rowspan",
|
|
1253
|
+
"start",
|
|
1254
|
+
"value",
|
|
1255
|
+
"width",
|
|
1256
|
+
"height",
|
|
1257
|
+
"border",
|
|
1258
|
+
"cellpadding",
|
|
1259
|
+
"cellspacing"
|
|
1260
|
+
].includes(n) && !/^\d+(?:%|px)?$/i.test(t.value.trim()) || n === "scope" && !/^(row|col|rowgroup|colgroup)$/i.test(t.value) || n === "dir" && !/^(ltr|rtl|auto)$/i.test(t.value) || n === "type" && !/^(1|a|A|i|I)$/i.test(t.value)) && e.removeAttribute(t.name) : e.removeAttribute(t.name);
|
|
1261
|
+
}
|
|
1262
|
+
for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
|
|
1263
|
+
return i.innerHTML.trim();
|
|
1264
|
+
}
|
|
1265
|
+
syncSource() {
|
|
1266
|
+
if (this.source && this.editor) {
|
|
1267
|
+
let e = this.cleanEditorCopy();
|
|
1268
|
+
this.source.value = this.format === "markdown" ? i(e) : e.innerHTML, this.preservedContent = this.format === "markdown" ? this.source.value : this.editor.innerHTML;
|
|
1269
|
+
}
|
|
1270
|
+
this.updateWordCount();
|
|
1271
|
+
}
|
|
1272
|
+
emitChange() {
|
|
1273
|
+
this.syncSource();
|
|
1274
|
+
let e = this.value;
|
|
1275
|
+
this.dispatchEvent(new CustomEvent("input", {
|
|
1276
|
+
bubbles: !0,
|
|
1277
|
+
composed: !0,
|
|
1278
|
+
detail: { value: e }
|
|
1279
|
+
})), this.dispatchEvent(new CustomEvent("change", {
|
|
1280
|
+
bubbles: !0,
|
|
1281
|
+
composed: !0,
|
|
1282
|
+
detail: { value: e }
|
|
1283
|
+
}));
|
|
1284
|
+
}
|
|
1285
|
+
updateWordCount() {
|
|
1286
|
+
if (!this.editor || !this.count) return;
|
|
1287
|
+
let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
|
|
1288
|
+
this.count.textContent = `${e} ${e === 1 ? "word" : "words"}`;
|
|
1289
|
+
}
|
|
1290
|
+
updateSelectionUI() {
|
|
1291
|
+
if (!this.editor) return;
|
|
1292
|
+
let e = this.selection, t = e?.anchorNode, n = !!t && this.editor.contains(t), r = n ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null, i = !this.sourceMode && n ? r?.closest("table") : null;
|
|
1293
|
+
this.selectTable(i && this.editor.contains(i) ? i : null);
|
|
1294
|
+
let a = this.sourceMode || !i;
|
|
1295
|
+
if (this.tableTrigger?.hidden !== a && (this.tableTrigger?.toggleAttribute("hidden", a), this.updateToolbarOverflow()), this.sourceMode || !n) return;
|
|
1296
|
+
let o = r?.closest("h1,h2,h3,h4,h5,h6,p,blockquote,div,li,td,th,pre"), s = o?.tagName.toLowerCase() || "p", c = {
|
|
1297
|
+
p: "Paragraph",
|
|
1298
|
+
h1: "Heading 1",
|
|
1299
|
+
h2: "Heading 2",
|
|
1300
|
+
h3: "Heading 3",
|
|
1301
|
+
h4: "Heading 4",
|
|
1302
|
+
h5: "Heading 5",
|
|
1303
|
+
h6: "Heading 6",
|
|
1304
|
+
blockquote: "Quote",
|
|
1305
|
+
div: "Div",
|
|
1306
|
+
li: "List item",
|
|
1307
|
+
td: "Table cell",
|
|
1308
|
+
th: "Table header",
|
|
1309
|
+
pre: "Code block"
|
|
1310
|
+
}, l = [
|
|
1311
|
+
"h1",
|
|
1312
|
+
"h2",
|
|
1313
|
+
"h3",
|
|
1314
|
+
"h4",
|
|
1315
|
+
"h5",
|
|
1316
|
+
"h6",
|
|
1317
|
+
"blockquote",
|
|
1318
|
+
"div",
|
|
1319
|
+
"li",
|
|
1320
|
+
"td",
|
|
1321
|
+
"th",
|
|
1322
|
+
"pre"
|
|
1323
|
+
].includes(s) ? s : "p";
|
|
1324
|
+
this.fontSizeDisplay && (this.fontSizeDisplay.textContent = `${this.readFontSize()}px`);
|
|
1325
|
+
let u = o ? getComputedStyle(o).textAlign : "left", d = u === "center" ? "align-center" : u === "right" || u === "end" ? "align-right" : u === "justify" ? "align-justify" : "align-left", f = d === "align-center" ? "Align center" : d === "align-right" ? "Align right" : d === "align-justify" ? "Justify" : "Align left", p = this.alignmentTrigger?.querySelector("mint-icon");
|
|
1326
|
+
p && p.setAttribute("name", d), this.alignmentTrigger && this.updateTooltipLabel(this.alignmentTrigger, `Text alignment: ${f}`);
|
|
1327
|
+
let m = this.toolbar?.querySelector(".mint-editor-toolbar-checklist");
|
|
1328
|
+
m?.classList.toggle("is-active", !!r?.closest("ul[data-mint-task-list]")), m?.setAttribute("aria-pressed", String(!!r?.closest("ul[data-mint-task-list]")));
|
|
1329
|
+
let h = r?.closest("ul,ol"), g = h?.tagName === "UL" && !h.hasAttribute("data-mint-task-list"), _ = h?.tagName === "OL", v = this.toolbar?.querySelector(".mint-editor-toolbar-list"), y = this.toolbar?.querySelector(".mint-editor-toolbar-numbered-list");
|
|
1330
|
+
if (v?.classList.toggle("is-active", !!g), v?.setAttribute("aria-pressed", String(!!g)), y?.classList.toggle("is-active", !!_), y?.setAttribute("aria-pressed", String(!!_)), this.blockButton) {
|
|
1331
|
+
let e = this.blockButton.querySelector(".mint-editor-block-label"), t = c[l] || "Paragraph";
|
|
1332
|
+
e && (e.textContent = t), this.updateTooltipLabel(this.blockButton, `Text style: ${t}`);
|
|
1333
|
+
}
|
|
1334
|
+
this.footerMode && (this.footerMode.textContent = s), this.blockPopover?.querySelectorAll("[data-block-tag]").forEach((e) => {
|
|
1335
|
+
let t = e.dataset.blockTag === l;
|
|
1336
|
+
e.toggleAttribute("data-active", t), e.setAttribute("aria-pressed", String(t));
|
|
1337
|
+
});
|
|
1338
|
+
for (let [t, n] of this.inlineButtons) {
|
|
1339
|
+
let r = e?.rangeCount ? e.getRangeAt(0) : null, i = r ? this.inlineStateAtSelection(t, r) : !1;
|
|
1340
|
+
n.classList.toggle("is-active", i), n.setAttribute("aria-pressed", String(i));
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
insertTable(e, t) {
|
|
1344
|
+
if (!this.editor) return;
|
|
1345
|
+
let n = this.editor.ownerDocument, r = n.createElement("table");
|
|
1346
|
+
r.className = "mint-editor-table";
|
|
1347
|
+
let i = n.createElement("tbody");
|
|
1348
|
+
for (let r = 0; r < e; r++) {
|
|
1349
|
+
let e = n.createElement("tr");
|
|
1350
|
+
for (let i = 0; i < t; i++) {
|
|
1351
|
+
let t = n.createElement(r === 0 ? "th" : "td");
|
|
1352
|
+
t.innerHTML = "<br>", e.append(t);
|
|
1353
|
+
}
|
|
1354
|
+
i.append(e);
|
|
1355
|
+
}
|
|
1356
|
+
r.append(i), this.editor.focus(), this.restoreSelection();
|
|
1357
|
+
let a = this.selection;
|
|
1358
|
+
if (a?.rangeCount && this.editor.contains(a.anchorNode)) {
|
|
1359
|
+
let e = a.getRangeAt(0), t = (e.startContainer.nodeType === Node.ELEMENT_NODE ? e.startContainer : e.startContainer.parentElement)?.closest("a");
|
|
1360
|
+
t && this.editor.contains(t) && (e.setStartAfter(t), e.collapse(!0)), e.deleteContents(), e.insertNode(r), e.setStartAfter(r), e.collapse(!0), a.removeAllRanges(), a.addRange(e);
|
|
1361
|
+
} else this.editor.append(r);
|
|
1362
|
+
this.emitChange();
|
|
1363
|
+
}
|
|
1364
|
+
openTableModal() {
|
|
1365
|
+
this.saveSelection();
|
|
1366
|
+
let e = document.createElement("mint-modal");
|
|
1367
|
+
e.setAttribute("heading", "Insert table"), e.setAttribute("size", "small");
|
|
1368
|
+
let t = document.createElement("div");
|
|
1369
|
+
t.setAttribute("slot", "body"), t.className = "mint-editor-modal-fields";
|
|
1370
|
+
let n = document.createElement("mint-input");
|
|
1371
|
+
n.setAttribute("type", "number"), n.setAttribute("label", "Rows"), n.setAttribute("min", "1"), n.setAttribute("max", "12"), n.setAttribute("value", "3");
|
|
1372
|
+
let r = document.createElement("mint-input");
|
|
1373
|
+
r.setAttribute("type", "number"), r.setAttribute("label", "Columns"), r.setAttribute("min", "1"), r.setAttribute("max", "10"), r.setAttribute("value", "3"), t.append(n, r);
|
|
1374
|
+
let i = document.createElement("div");
|
|
1375
|
+
i.setAttribute("slot", "actions"), i.className = "mint-editor-modal-actions";
|
|
1376
|
+
let a = document.createElement("mint-button");
|
|
1377
|
+
a.textContent = "Cancel", a.setAttribute("variant", "ghost"), this.setTooltip(a, "Cancel"), a.addEventListener("click", () => e.close());
|
|
1378
|
+
let o = document.createElement("mint-button");
|
|
1379
|
+
o.textContent = "Insert table", o.setAttribute("tone", "action"), this.setTooltip(o, "Insert table"), o.addEventListener("click", () => {
|
|
1380
|
+
let t = Math.max(1, Math.min(12, Number(n.value) || 3)), i = Math.max(1, Math.min(10, Number(r.value) || 3));
|
|
1381
|
+
e.close(), this.insertTable(t, i);
|
|
1382
|
+
}), i.append(a, o), e.append(t, i), this.append(e), e.open();
|
|
1383
|
+
}
|
|
1384
|
+
openLinkModal() {
|
|
1385
|
+
this.saveSelection();
|
|
1386
|
+
let e = document.createElement("mint-modal");
|
|
1387
|
+
e.setAttribute("heading", "Insert link"), e.setAttribute("size", "small");
|
|
1388
|
+
let t = document.createElement("div");
|
|
1389
|
+
t.setAttribute("slot", "body");
|
|
1390
|
+
let n = document.createElement("mint-input");
|
|
1391
|
+
n.setAttribute("type", "url"), n.setAttribute("label", "Link URL"), n.setAttribute("placeholder", "https://example.com"), t.append(n);
|
|
1392
|
+
let r = document.createElement("div");
|
|
1393
|
+
r.setAttribute("slot", "actions"), r.className = "mint-editor-modal-actions";
|
|
1394
|
+
let i = document.createElement("mint-button");
|
|
1395
|
+
i.textContent = "Cancel", i.setAttribute("variant", "ghost"), this.setTooltip(i, "Cancel"), i.addEventListener("click", () => e.close());
|
|
1396
|
+
let a = document.createElement("mint-button");
|
|
1397
|
+
a.textContent = "Insert link", a.setAttribute("tone", "action"), this.setTooltip(a, "Insert link"), a.addEventListener("click", () => {
|
|
1398
|
+
let t = String(n.value || "").trim();
|
|
1399
|
+
t && (this.command("createLink", t), e.close());
|
|
1400
|
+
}), r.append(i, a), e.append(t, r), this.append(e), e.open();
|
|
1401
|
+
}
|
|
1402
|
+
selectedTable() {
|
|
1403
|
+
let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
|
|
1404
|
+
return t && this.editor?.contains(t) ? t : null;
|
|
1405
|
+
}
|
|
1406
|
+
applyTableAction(e) {
|
|
1407
|
+
let t = this.selectedTable();
|
|
1408
|
+
if (!t) return;
|
|
1409
|
+
let n = this._savedRange, r = (n?.startContainer.nodeType === Node.ELEMENT_NODE ? n.startContainer : n?.startContainer.parentElement)?.closest("td,th"), i = r?.parentElement;
|
|
1410
|
+
if (e === "Add row below" || e === "Add row above") {
|
|
1411
|
+
let n = i?.cloneNode(!0);
|
|
1412
|
+
n && (n.querySelectorAll("th,td").forEach((e) => e.innerHTML = "<br>"), (i?.parentElement || t.querySelector("tbody") || t).insertBefore(n, e === "Add row above" ? i : i?.nextSibling || null));
|
|
1413
|
+
}
|
|
1414
|
+
if (e === "Add column right" || e === "Add column left") {
|
|
1415
|
+
let n = (r ? Array.from(r.parentElement.children).indexOf(r) : (t.querySelector("tr")?.children.length || 1) - 1) + (e === "Add column right" ? 1 : 0);
|
|
1416
|
+
t.querySelectorAll("tr").forEach((e) => {
|
|
1417
|
+
let r = e.querySelector("th") ? "th" : "td", i = t.ownerDocument.createElement(r);
|
|
1418
|
+
i.innerHTML = "<br>", e.insertBefore(i, e.children[n] || null);
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
if (e === "Delete row" && i && t.querySelectorAll("tr").length > 1 && i.remove(), e === "Delete column" && r && r.parentElement.children.length > 1) {
|
|
1422
|
+
let e = Array.from(r.parentElement.children).indexOf(r);
|
|
1423
|
+
t.querySelectorAll("tr").forEach((t) => t.children[e]?.remove());
|
|
1424
|
+
}
|
|
1425
|
+
e === "Delete table" && t.remove(), this.emitChange(), this.updateSelectionUI();
|
|
1426
|
+
}
|
|
1427
|
+
selectTable(e) {
|
|
1428
|
+
this.selectedTableElement !== e && this.selectedTableElement?.classList.remove("is-selected"), this.selectedTableElement = e, e?.classList.add("is-selected");
|
|
1429
|
+
let t = !!e && !this.sourceMode;
|
|
1430
|
+
this.inlineTableTools && (this.inlineTableTools.hidden = !t), this.tableResizeHandle && (this.tableResizeHandle.hidden = !t), t && this.positionTableTools();
|
|
1431
|
+
}
|
|
1432
|
+
positionTableTools() {
|
|
1433
|
+
let e = this.selectedTableElement, t = this.querySelector(".mint-editor-shell"), n = this.editorFrame;
|
|
1434
|
+
if (!e || !t || !n || !this.inlineTableTools || !this.tableResizeHandle || this.sourceMode) return;
|
|
1435
|
+
let r = t.getBoundingClientRect(), i = n.getBoundingClientRect(), a = e.getBoundingClientRect(), o = i.left + a.left - r.left, s = i.top + a.top - r.top, c = this.inlineTableTools.offsetWidth || 280, l = Math.max(6, Math.min(t.clientWidth - c - 6, o + a.width / 2 - c / 2)), u = Math.max(6, s - this.inlineTableTools.offsetHeight - 10);
|
|
1436
|
+
this.inlineTableTools.style.left = `${l}px`, this.inlineTableTools.style.top = `${u}px`, this.tableResizeHandle.style.left = `${Math.max(0, o + a.width - 18)}px`, this.tableResizeHandle.style.top = `${Math.max(0, s + a.height - 18)}px`;
|
|
1437
|
+
}
|
|
1438
|
+
startTableResize(e) {
|
|
1439
|
+
let t = this.selectedTableElement;
|
|
1440
|
+
if (!t) return;
|
|
1441
|
+
e.preventDefault(), e.stopPropagation();
|
|
1442
|
+
let n = t.getBoundingClientRect();
|
|
1443
|
+
this.tableResizeState = {
|
|
1444
|
+
table: t,
|
|
1445
|
+
startX: e.clientX,
|
|
1446
|
+
startY: e.clientY,
|
|
1447
|
+
startWidth: n.width,
|
|
1448
|
+
startHeight: n.height,
|
|
1449
|
+
pointerId: e.pointerId
|
|
1450
|
+
}, this.ownerDocument.defaultView?.addEventListener("pointermove", this.onTableResizeMove), this.ownerDocument.defaultView?.addEventListener("pointerup", this.onTableResizeEnd);
|
|
1451
|
+
}
|
|
1452
|
+
startGridResize(e) {
|
|
1453
|
+
let t = e.target?.closest("td,th"), n = t?.closest("table");
|
|
1454
|
+
if (!t || !n || !this.editor?.contains(n)) return;
|
|
1455
|
+
let r = t.getBoundingClientRect(), i = Math.abs(e.clientX - r.right) <= 7, a = Math.abs(e.clientY - r.bottom) <= 7;
|
|
1456
|
+
if (!i && !a) return;
|
|
1457
|
+
let o = t.parentElement, s = Array.from(n.rows).indexOf(o);
|
|
1458
|
+
if (a) this.gridResizeState = {
|
|
1459
|
+
table: n,
|
|
1460
|
+
kind: "row",
|
|
1461
|
+
index: s,
|
|
1462
|
+
start: e.clientY,
|
|
1463
|
+
size: o.getBoundingClientRect().height,
|
|
1464
|
+
pointerId: e.pointerId
|
|
1465
|
+
};
|
|
1466
|
+
else {
|
|
1467
|
+
let i = Array.from(o.cells).indexOf(t);
|
|
1468
|
+
this.ensureTableColumns(n);
|
|
1469
|
+
let a = n.querySelectorAll("col")[i];
|
|
1470
|
+
this.gridResizeState = {
|
|
1471
|
+
table: n,
|
|
1472
|
+
kind: "column",
|
|
1473
|
+
index: i,
|
|
1474
|
+
start: e.clientX,
|
|
1475
|
+
size: a?.getBoundingClientRect().width || r.width,
|
|
1476
|
+
pointerId: e.pointerId
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
e.preventDefault(), e.stopPropagation();
|
|
1480
|
+
let c = this.editor?.ownerDocument.defaultView;
|
|
1481
|
+
c?.addEventListener("pointermove", this.onGridResizeMove), c?.addEventListener("pointerup", this.onGridResizeEnd), c?.addEventListener("pointercancel", this.onGridResizeEnd);
|
|
1482
|
+
}
|
|
1483
|
+
updateGridResizeCursor(e) {
|
|
1484
|
+
let t = this.editor;
|
|
1485
|
+
if (!t || this.gridResizeState) return;
|
|
1486
|
+
let n = e.target?.closest("td,th");
|
|
1487
|
+
if (!n) {
|
|
1488
|
+
t.style.cursor = "";
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
let r = n.getBoundingClientRect(), i = Math.abs(e.clientX - r.right) <= 7, a = Math.abs(e.clientY - r.bottom) <= 7;
|
|
1492
|
+
t.style.cursor = i && a ? "nwse-resize" : i ? "col-resize" : a ? "row-resize" : "";
|
|
1493
|
+
}
|
|
1494
|
+
ensureTableColumns(e) {
|
|
1495
|
+
let t = e.querySelector("colgroup");
|
|
1496
|
+
t || (t = e.ownerDocument.createElement("colgroup"), e.insertBefore(t, e.firstChild));
|
|
1497
|
+
let n = Math.max(1, ...Array.from(e.rows, (e) => e.cells.length));
|
|
1498
|
+
for (; t.children.length < n;) t.append(e.ownerDocument.createElement("col"));
|
|
1499
|
+
}
|
|
1500
|
+
toggleSource() {
|
|
1501
|
+
if (!(!this.editor || !this.source)) {
|
|
1502
|
+
if (this.sourceMode = !this.sourceMode, this.clearInlineTypingState(), this.source.hidden = !this.sourceMode, this.editor.hidden = this.sourceMode, this.sourceMode) {
|
|
1503
|
+
let e = this.cleanEditorCopy();
|
|
1504
|
+
this.source.value = this.format === "markdown" ? i(e) : e.innerHTML;
|
|
1505
|
+
} else this.editor.innerHTML = this.format === "markdown" ? n(this.source.value) : this.source.value;
|
|
1506
|
+
this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
createResizeHandle() {
|
|
1510
|
+
let e = (this.editor?.ownerDocument || document).createElement("button");
|
|
1511
|
+
return e.type = "button", e.className = "mint-editor-resize-handle", this.setTooltip(e, "Resize image"), e.addEventListener("pointerdown", (t) => {
|
|
1512
|
+
t.preventDefault(), t.stopPropagation();
|
|
1513
|
+
let n = e.parentElement;
|
|
1514
|
+
this.resizeState = {
|
|
1515
|
+
frame: n,
|
|
1516
|
+
startX: t.clientX,
|
|
1517
|
+
startWidth: n.getBoundingClientRect().width,
|
|
1518
|
+
pointerId: t.pointerId
|
|
1519
|
+
}, this.editor?.ownerDocument.defaultView?.addEventListener("pointermove", this.onResizeMove), this.editor?.ownerDocument.defaultView?.addEventListener("pointerup", this.onResizeEnd);
|
|
1520
|
+
}), e;
|
|
1521
|
+
}
|
|
1522
|
+
selectImage(e) {
|
|
1523
|
+
this.selectedImage?.classList.remove("is-selected"), this.selectedImage = e, e?.classList.add("is-selected");
|
|
1524
|
+
let t = this.querySelector(".mint-editor-image-tools");
|
|
1525
|
+
t && (t.hidden = !e);
|
|
1526
|
+
let n = t?.querySelector("mint-input");
|
|
1527
|
+
e && n && (n.value = `${Math.round(e.getBoundingClientRect().width / Math.max(1, this.editor?.clientWidth || e.getBoundingClientRect().width) * 100)}`);
|
|
1528
|
+
}
|
|
1529
|
+
updateSelectedImage() {
|
|
1530
|
+
let e = this.selection?.anchorNode, t = e?.nodeType === Node.ELEMENT_NODE ? e.closest(".mint-editor-image-frame") : e?.parentElement?.closest(".mint-editor-image-frame");
|
|
1531
|
+
t && this.selectImage(t);
|
|
1532
|
+
}
|
|
1533
|
+
};
|
|
1534
|
+
customElements.get("mint-editor") || e("mint-editor", a);
|
|
1535
|
+
//#endregion
|
|
1536
|
+
export { a as default };
|