monobill-mintui 0.6.736 → 0.6.738
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 +2 -1
- package/dist/components/chunks/{date-picker-CTtYAkmM.js → date-picker-R8J7EzuF.js} +1 -1
- package/dist/components/chunks/{date-picker-CUf5eJR3.js → date-picker-STjYRdxE.js} +1 -1
- package/dist/components/chunks/{popover-DD7uyRXy.js → popover-7-PJT1-5.js} +14 -2
- package/dist/components/chunks/popover-CD0v0njp.js +1 -0
- package/dist/components/chunks/{select-DOMW7Plx.js → select-hL6gV7mL.js} +1 -1
- package/dist/components/chunks/{select-CX9oOwl5.js → select-oEt5Dm4P.js} +1 -1
- package/dist/components/chunks/{time-picker-C7pJvGSM.js → time-picker-B7oXBU8q.js} +1 -1
- package/dist/components/chunks/{time-picker-BaoT0NtA.js → time-picker-QzH9kywR.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 +2 -2
- package/dist/components/datetime-picker/index.cjs +1 -1
- package/dist/components/datetime-picker/index.js +2 -2
- package/dist/components/editor/Editor.d.ts +31 -2
- package/dist/components/editor/Editor.d.ts.map +1 -1
- package/dist/components/editor/browser.js +599 -247
- package/dist/components/editor/index.cjs +14 -8
- package/dist/components/editor/index.d.ts +1 -0
- package/dist/components/editor/index.d.ts.map +1 -1
- package/dist/components/editor/index.js +599 -247
- package/dist/components/link/browser.js +1 -1
- package/dist/components/link/index.cjs +1 -1
- package/dist/components/link/index.js +1 -1
- package/dist/components/navigation/browser.js +2 -2
- package/dist/components/navigation/index.cjs +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/page/browser.js +1 -1
- package/dist/components/page/index.cjs +1 -1
- package/dist/components/page/index.js +1 -1
- package/dist/components/popover/Popover.d.ts +4 -0
- 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 +4 -4
- package/dist/components/resource-table/index.cjs +1 -1
- package/dist/components/resource-table/index.js +4 -4
- package/dist/components/search/browser.js +1 -1
- package/dist/components/search/index.cjs +1 -1
- package/dist/components/search/index.js +1 -1
- 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 +1 -1
- package/dist/components/side-navigation/index.cjs +1 -1
- package/dist/components/side-navigation/index.js +1 -1
- 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/tags/browser.js +1 -1
- package/dist/components/tags/index.cjs +1 -1
- package/dist/components/tags/index.js +1 -1
- 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 +1 -1
- package/dist/components/tree/index.cjs +1 -1
- package/dist/components/tree/index.js +1 -1
- package/dist/editor.css +1 -1
- package/dist/index.cjs +15 -9
- package/dist/index.css +1 -1
- package/dist/index.js +610 -248
- package/package.json +1 -1
- package/dist/components/chunks/popover-2Cnva3AN.js +0 -1
- /package/dist/components/chunks/{link-B_fNmwOk.js → link-B4Hdsb2b.js} +0 -0
- /package/dist/components/chunks/{link-BxTQfAW9.js → link-rv2WDJw2.js} +0 -0
- /package/dist/components/chunks/{search-BXku4V9r.js → search-C3uTkxhf.js} +0 -0
- /package/dist/components/chunks/{search-DKHcIR2F.js → search-qSlGRuMR.js} +0 -0
- /package/dist/components/chunks/{table-IU2Vmjwk.js → table-BZ73d2Yb.js} +0 -0
- /package/dist/components/chunks/{table-HnSpIfny.js → table-D82Gvcva.js} +0 -0
|
@@ -7,46 +7,92 @@ import '../../stack.css'
|
|
|
7
7
|
import '../../modal.css'
|
|
8
8
|
import '../../text.css'
|
|
9
9
|
import '../../input.css'
|
|
10
|
+
import '../../select.css'
|
|
10
11
|
import '../../editor.css'
|
|
11
12
|
import { t as e } from "../chunks/register-element-BFYmIynH.js";
|
|
12
13
|
import "../chunks/icon-aNwWb0hA.js";
|
|
13
14
|
import "../chunks/button-THsh4Svz.js";
|
|
14
15
|
import "../chunks/modal-ss_OTDJJ.js";
|
|
15
16
|
import "../chunks/input-Bu4xPosP.js";
|
|
16
|
-
import "../chunks/popover-
|
|
17
|
+
import "../chunks/popover-7-PJT1-5.js";
|
|
18
|
+
import "../chunks/select-hL6gV7mL.js";
|
|
17
19
|
//#region src/components/editor/Editor.ts
|
|
18
20
|
function t(e) {
|
|
19
21
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """);
|
|
20
22
|
}
|
|
21
23
|
function n(e) {
|
|
24
|
+
return e.replace(/\r\n?/g, "\n").split("\n").map((e) => e.replace(/[\t ]+$/g, "")).join("\n").trim().replace(/\n{3,}/g, "\n\n");
|
|
25
|
+
}
|
|
26
|
+
function r(e, n) {
|
|
27
|
+
let r = n.createElement("template");
|
|
28
|
+
r.innerHTML = e.trim();
|
|
29
|
+
let i = new Set(/* @__PURE__ */ "address.article.aside.blockquote.body.caption.dd.details.dialog.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.summary.table.tbody.td.tfoot.th.thead.tr.ul".split(".")), a = new Set([
|
|
30
|
+
"area",
|
|
31
|
+
"base",
|
|
32
|
+
"br",
|
|
33
|
+
"col",
|
|
34
|
+
"embed",
|
|
35
|
+
"hr",
|
|
36
|
+
"img",
|
|
37
|
+
"input",
|
|
38
|
+
"link",
|
|
39
|
+
"meta",
|
|
40
|
+
"param",
|
|
41
|
+
"source",
|
|
42
|
+
"track",
|
|
43
|
+
"wbr"
|
|
44
|
+
]), o = (e) => " ".repeat(e), s = (e) => Array.from(e.attributes).map((e) => ` ${e.name}="${t(e.value)}"`).join(""), c = (e) => {
|
|
45
|
+
if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
|
|
46
|
+
if (e.nodeType === Node.COMMENT_NODE) return `<!--${e.nodeValue || ""}-->`;
|
|
47
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return "";
|
|
48
|
+
let n = e, r = n.tagName.toLowerCase(), i = `<${r}${s(n)}>`;
|
|
49
|
+
return a.has(r) ? i : `${i}${Array.from(n.childNodes).map(c).join("")}</${r}>`;
|
|
50
|
+
}, l = (e, n) => {
|
|
51
|
+
if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
|
|
52
|
+
if (e.nodeType === Node.COMMENT_NODE) return `${o(n)}<!--${e.nodeValue || ""}-->`;
|
|
53
|
+
if (e.nodeType !== Node.ELEMENT_NODE) return "";
|
|
54
|
+
let r = e, u = r.tagName.toLowerCase(), d = `<${u}${s(r)}>`;
|
|
55
|
+
if (a.has(u)) return `${o(n)}${d}`;
|
|
56
|
+
let f = Array.from(r.childNodes);
|
|
57
|
+
if (u === "pre" || f.every((e) => e.nodeType === Node.TEXT_NODE || e.nodeType === Node.ELEMENT_NODE && !i.has(e.tagName.toLowerCase()))) return `${o(n)}${d}${f.map(c).join("")}</${u}>`;
|
|
58
|
+
let p = f.flatMap((e) => {
|
|
59
|
+
if (e.nodeType === Node.TEXT_NODE && !(e.textContent || "").trim()) return [];
|
|
60
|
+
let t = l(e, n + 1);
|
|
61
|
+
return t ? [t] : [];
|
|
62
|
+
});
|
|
63
|
+
return p.length ? `${o(n)}${d}\n${p.join("\n")}\n${o(n)}</${u}>` : `${o(n)}${d}</${u}>`;
|
|
64
|
+
};
|
|
65
|
+
return Array.from(r.content.childNodes).map((e) => l(e, 0)).filter(Boolean).join("\n");
|
|
66
|
+
}
|
|
67
|
+
function i(e) {
|
|
22
68
|
return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
|
|
23
69
|
let n = e.trim();
|
|
24
70
|
if (!n) return "";
|
|
25
|
-
let
|
|
26
|
-
if (
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
29
|
-
if (/^>\s?/.test(n)) return `<blockquote><p>${
|
|
71
|
+
let r = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
|
|
72
|
+
if (r) return `<pre><code${r[1] ? ` class=\"language-${t(r[1])}\"` : ""}>${t(r[2])}</code></pre>`;
|
|
73
|
+
let i = n.match(/^(#{1,6})\s+([\s\S]+)$/);
|
|
74
|
+
if (i) return `<h${i[1].length}>${a(i[2])}</h${i[1].length}>`;
|
|
75
|
+
if (/^>\s?/.test(n)) return `<blockquote><p>${a(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
|
|
30
76
|
let o = n.split("\n").map((e) => e.trim()).filter(Boolean);
|
|
31
77
|
if (o.length >= 2 && /^\|?\s*:?-{3,}/.test(o[1]) && o[0].includes("|")) {
|
|
32
78
|
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>${
|
|
79
|
+
return `<table><thead><tr>${(e.shift() || []).map((e) => `<th>${a(e)}</th>`).join("")}</tr></thead><tbody>${e.map((e) => `<tr>${e.map((e) => `<td>${a(e)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
|
|
34
80
|
}
|
|
35
81
|
if (/^[-*+]\s+\[[ xX]\]\s/.test(n)) return `<ul data-mint-task-list="true">${n.split("\n").map((e) => {
|
|
36
82
|
let t = e.match(/^[-*+]\s+\[([ xX])\]\s+(.*)$/);
|
|
37
|
-
return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${
|
|
83
|
+
return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${a(t[2])}</span></li>` : "";
|
|
38
84
|
}).join("")}</ul>`;
|
|
39
85
|
if (/^([-*+]\s|\d+\.\s)/.test(n)) {
|
|
40
86
|
let e = n.split("\n"), t = /^\d+\./.test(e[0]);
|
|
41
|
-
return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${
|
|
87
|
+
return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${a(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
|
|
42
88
|
}
|
|
43
|
-
return `<p>${
|
|
89
|
+
return `<p>${a(n.replace(/\n/g, " "))}</p>`;
|
|
44
90
|
}).join("");
|
|
45
91
|
}
|
|
46
|
-
function
|
|
92
|
+
function a(e) {
|
|
47
93
|
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
94
|
}
|
|
49
|
-
function
|
|
95
|
+
function o(e) {
|
|
50
96
|
let t = (e) => {
|
|
51
97
|
if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
|
|
52
98
|
if (e.nodeType !== Node.ELEMENT_NODE) return "";
|
|
@@ -77,9 +123,9 @@ function i(e) {
|
|
|
77
123
|
};
|
|
78
124
|
return Array.from(e.childNodes).map(t).join("").trim();
|
|
79
125
|
}
|
|
80
|
-
var
|
|
126
|
+
var s = class extends HTMLElement {
|
|
81
127
|
constructor(...e) {
|
|
82
|
-
super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = 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) => {
|
|
128
|
+
super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.preservedContent = null, this.history = [], this.historyIndex = -1, this.applyingHistory = !1, this.historyTransactionDepth = 0, this.historyTransactionPending = !1, this.undoButton = null, this.redoButton = 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
129
|
if (e.button !== 0) return;
|
|
84
130
|
e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
|
|
85
131
|
stage: t,
|
|
@@ -155,14 +201,14 @@ var a = class extends HTMLElement {
|
|
|
155
201
|
let e = this.editor?.ownerDocument.defaultView;
|
|
156
202
|
e?.removeEventListener("pointermove", this.onGridResizeMove), e?.removeEventListener("pointerup", this.onGridResizeEnd), this.removeStageResizeListeners();
|
|
157
203
|
}
|
|
158
|
-
attributeChangedCallback(e, t,
|
|
204
|
+
attributeChangedCallback(e, t, n) {
|
|
159
205
|
if (this.isConnected) {
|
|
160
206
|
if (e === "format") {
|
|
161
|
-
t !==
|
|
207
|
+
t !== n && (this.updateFormatUI(), this.sourceMode && this.source && this.editor ? this.editor.innerHTML = n === "markdown" ? i(this.source.value) : this.source.value : n === "markdown" && t !== "markdown" && this.editor && (this.editor.innerHTML = i(this.editor.innerHTML)), this.syncSource());
|
|
162
208
|
return;
|
|
163
209
|
}
|
|
164
210
|
if (e === "value") {
|
|
165
|
-
this.setValue(
|
|
211
|
+
this.setValue(n || "");
|
|
166
212
|
return;
|
|
167
213
|
}
|
|
168
214
|
e === "height" && (this.editorHeight = null), this.render();
|
|
@@ -178,17 +224,21 @@ var a = class extends HTMLElement {
|
|
|
178
224
|
if (this.sourceMode && this.source) return this.source.value;
|
|
179
225
|
if (!this.editor) return "";
|
|
180
226
|
let e = this.cleanEditorCopy();
|
|
181
|
-
return this.format === "markdown" ?
|
|
227
|
+
return this.format === "markdown" ? o(e) : e.innerHTML;
|
|
182
228
|
}
|
|
183
229
|
set value(e) {
|
|
184
230
|
this.setValue(e || "");
|
|
185
231
|
}
|
|
186
232
|
setValue(e) {
|
|
187
233
|
if (!this.editor) {
|
|
188
|
-
this.pendingValue = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
|
|
234
|
+
this.pendingValue = e, this.preservedContent = e, this.history = [], this.historyIndex = -1, this.updateHistoryButtons(), this.getAttribute("value") !== e && this.setAttribute("value", e);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (this.value === e) {
|
|
238
|
+
this.source && (this.source.value = e), this.updateHistoryButtons();
|
|
189
239
|
return;
|
|
190
240
|
}
|
|
191
|
-
this.editor.innerHTML = this.format === "markdown" ?
|
|
241
|
+
this.editor.innerHTML = this.format === "markdown" ? i(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount(), this.resetHistory();
|
|
192
242
|
}
|
|
193
243
|
insertResource(e) {
|
|
194
244
|
let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
|
|
@@ -206,21 +256,23 @@ var a = class extends HTMLElement {
|
|
|
206
256
|
this.selectImage(i), this.emitChange();
|
|
207
257
|
}
|
|
208
258
|
render() {
|
|
209
|
-
let e = this.
|
|
259
|
+
let e = this.getAttribute("value"), n = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
|
|
260
|
+
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 = n) : this.preservedContent = e : this.preservedContent = this.pendingValue;
|
|
261
|
+
let r = this.editor ? n : this.format === "markdown" ? i(n) : n;
|
|
210
262
|
this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
|
|
211
|
-
let
|
|
263
|
+
let a = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", o = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, s = this.getAttribute("label") || "";
|
|
212
264
|
this.innerHTML = "";
|
|
213
|
-
let
|
|
214
|
-
if (
|
|
265
|
+
let c = document.createElement("div");
|
|
266
|
+
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) {
|
|
215
267
|
let e = document.createElement("label");
|
|
216
|
-
e.className = "mint-editor-label", e.textContent =
|
|
268
|
+
e.className = "mint-editor-label", e.textContent = s, e.id = `${this.id || "mint-editor"}-label`, c.append(e);
|
|
217
269
|
}
|
|
218
|
-
let c = document.createElement("div");
|
|
219
|
-
c.className = "mint-editor-shell";
|
|
220
270
|
let l = document.createElement("div");
|
|
221
|
-
l.className = "mint-editor-
|
|
271
|
+
l.className = "mint-editor-shell";
|
|
222
272
|
let u = document.createElement("div");
|
|
223
|
-
u.className = "mint-editor-
|
|
273
|
+
u.className = "mint-editor-toolbar", u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Text formatting"), this.toolbar = u, this.buildToolbar(u);
|
|
274
|
+
let d = document.createElement("div");
|
|
275
|
+
d.className = "mint-editor-inline-table-tools", d.setAttribute("role", "toolbar"), d.setAttribute("aria-label", "Table tools"), d.hidden = !0;
|
|
224
276
|
for (let [e, t] of [
|
|
225
277
|
["Add row above", "arrow-up"],
|
|
226
278
|
["Add row below", "arrow-down"],
|
|
@@ -233,12 +285,12 @@ var a = class extends HTMLElement {
|
|
|
233
285
|
let n = document.createElement("button");
|
|
234
286
|
n.type = "button", n.className = "mint-editor-table-tool-button", this.setTooltip(n, e), n.append(this.icon(t)), n.addEventListener("pointerdown", (e) => {
|
|
235
287
|
e.preventDefault(), this.saveSelection();
|
|
236
|
-
}), n.addEventListener("click", () => this.applyTableAction(e)),
|
|
288
|
+
}), n.addEventListener("click", () => this.applyTableAction(e)), d.append(n);
|
|
237
289
|
}
|
|
238
|
-
let
|
|
239
|
-
|
|
240
|
-
let
|
|
241
|
-
|
|
290
|
+
let f = document.createElement("button");
|
|
291
|
+
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;
|
|
292
|
+
let p = document.createElement("iframe");
|
|
293
|
+
p.className = "mint-editor-frame", p.title = s ? `${s} editor` : "Rich text editor", p.setAttribute("sandbox", "allow-same-origin allow-popups allow-popups-to-escape-sandbox"), p.style.height = "100%", p.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
242
294
|
html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
|
|
243
295
|
.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}
|
|
244
296
|
.editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
|
|
@@ -247,56 +299,57 @@ var a = class extends HTMLElement {
|
|
|
247
299
|
.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}
|
|
248
300
|
.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}
|
|
249
301
|
.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)}
|
|
250
|
-
.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}
|
|
251
302
|
.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}
|
|
252
303
|
.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}
|
|
253
304
|
@media(max-width:640px){.editor{padding:.75rem}}
|
|
254
|
-
</style></head><body><div class="editor" contenteditable="${!
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
m.
|
|
261
|
-
let h =
|
|
305
|
+
</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", () => {
|
|
306
|
+
!this.isConnected || this.editorFrame !== p || this.bindEditorFrame(r, a);
|
|
307
|
+
}), this.editorFrame = p;
|
|
308
|
+
let m = document.createElement("textarea");
|
|
309
|
+
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" ? n : r, m.addEventListener("input", (e) => {
|
|
310
|
+
this.editor && (this.editor.innerHTML = this.format === "markdown" ? i(m.value) : m.value), this.updateWordCount(), this.emitChange(e.inputType);
|
|
311
|
+
}), m.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), m.addEventListener("beforeinput", (e) => this.handleHistoryBeforeInput(e)), this.source = m;
|
|
312
|
+
let h = document.createElement("div");
|
|
313
|
+
h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
|
|
314
|
+
let g = null;
|
|
262
315
|
[
|
|
263
316
|
"false",
|
|
264
317
|
"0",
|
|
265
318
|
"off",
|
|
266
319
|
"no"
|
|
267
|
-
].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (
|
|
268
|
-
let
|
|
269
|
-
|
|
270
|
-
let
|
|
271
|
-
|
|
320
|
+
].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);
|
|
321
|
+
let _ = document.createElement("div");
|
|
322
|
+
_.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}`));
|
|
323
|
+
let v = _.querySelector("[data-remove=\"image\"]");
|
|
324
|
+
v && this.setTooltip(v, "Remove image"), _.querySelector("mint-input")?.addEventListener("input", (e) => {
|
|
272
325
|
if (!this.selectedImage) return;
|
|
273
326
|
let t = Number(e.target.value);
|
|
274
327
|
this.selectedImage.style.width = `${Math.max(10, Math.min(100, t))}%`, this.emitChange();
|
|
275
|
-
}),
|
|
328
|
+
}), _.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
|
|
276
329
|
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());
|
|
277
|
-
})),
|
|
330
|
+
})), _.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
|
|
278
331
|
this.selectedImage?.remove(), this.selectImage(null), this.emitChange();
|
|
279
|
-
}),
|
|
280
|
-
let
|
|
281
|
-
|
|
282
|
-
let y = document.createElement("span");
|
|
283
|
-
y.className = "mint-editor-mode", y.textContent = "p";
|
|
332
|
+
}), c.append(l, _);
|
|
333
|
+
let y = document.createElement("div");
|
|
334
|
+
y.className = "mint-editor-footer";
|
|
284
335
|
let b = document.createElement("span");
|
|
285
|
-
b.className = "mint-editor-
|
|
286
|
-
let x = document.createElement("
|
|
287
|
-
x.className = "mint-editor-
|
|
288
|
-
let S =
|
|
289
|
-
|
|
336
|
+
b.className = "mint-editor-mode", b.textContent = "p";
|
|
337
|
+
let x = document.createElement("span");
|
|
338
|
+
x.className = "mint-editor-word-count", this.count = x;
|
|
339
|
+
let S = document.createElement("div");
|
|
340
|
+
S.className = "mint-editor-footer-end", S.append(x), g && S.append(g), y.append(b, S), this.footerMode = b, l.append(y);
|
|
341
|
+
let C = this.getAttribute("error");
|
|
342
|
+
if (C) {
|
|
290
343
|
let e = document.createElement("div");
|
|
291
|
-
e.className = "mint-editor-error", e.textContent =
|
|
344
|
+
e.className = "mint-editor-error", e.textContent = C, c.append(e);
|
|
292
345
|
}
|
|
293
|
-
this.append(
|
|
294
|
-
let
|
|
295
|
-
if (
|
|
346
|
+
this.append(c);
|
|
347
|
+
let w = this.querySelector(".mint-editor-stage");
|
|
348
|
+
if (w && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
|
|
296
349
|
if (!e || !this.editorFrame) return;
|
|
297
350
|
let t = Math.max(0, e.contentRect.width), n = Math.max(0, e.contentRect.height);
|
|
298
351
|
this.editorFrame.style.width = `${t}px`, this.editorFrame.style.height = `${n}px`;
|
|
299
|
-
}), this.frameResizeObserver.observe(
|
|
352
|
+
}), this.frameResizeObserver.observe(w)), this.toolbar && typeof ResizeObserver < "u") {
|
|
300
353
|
this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = new ResizeObserver(() => this.updateToolbarOverflow()), this.toolbarResizeObserver.observe(this.toolbar);
|
|
301
354
|
let e = this.toolbar.querySelector(".mint-editor-toolbar-actions");
|
|
302
355
|
e && this.toolbarResizeObserver.observe(e), requestAnimationFrame(() => this.updateToolbarOverflow());
|
|
@@ -312,11 +365,11 @@ var a = class extends HTMLElement {
|
|
|
312
365
|
e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
|
|
313
366
|
}
|
|
314
367
|
bindEditorFrame(e, t) {
|
|
315
|
-
let
|
|
316
|
-
if (!
|
|
317
|
-
|
|
318
|
-
let a = getComputedStyle(this), o =
|
|
319
|
-
o.style.font = a.font, o.style.color = a.color, o.style.background = a.backgroundColor, getComputedStyle(
|
|
368
|
+
let n = this.editorFrame?.contentDocument, r = n?.querySelector(".editor");
|
|
369
|
+
if (!n || !r) return;
|
|
370
|
+
r.contentEditable = String(!t), r.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? i(this.pendingValue) : this.pendingValue, this.pendingValue = null;
|
|
371
|
+
let a = getComputedStyle(this), o = n.body;
|
|
372
|
+
o.style.font = a.font, o.style.color = a.color, o.style.background = a.backgroundColor, getComputedStyle(r), r.style.font = a.font, r.style.background = a.backgroundColor, [
|
|
320
373
|
"text",
|
|
321
374
|
"text-muted",
|
|
322
375
|
"surface",
|
|
@@ -326,19 +379,20 @@ var a = class extends HTMLElement {
|
|
|
326
379
|
"focus"
|
|
327
380
|
].forEach((e) => {
|
|
328
381
|
let t = a.getPropertyValue(`--mint-color-${e}`).trim();
|
|
329
|
-
t &&
|
|
330
|
-
}), this.editor =
|
|
331
|
-
this.normalizeTaskListItems(), this.
|
|
332
|
-
}),
|
|
382
|
+
t && r.style.setProperty(`--mint-color-${e}`, t);
|
|
383
|
+
}), this.editor = r, r.addEventListener("input", (e) => {
|
|
384
|
+
this.normalizeTaskListItems(), this.emitChange(e.inputType), this.updateSelectionUI();
|
|
385
|
+
}), r.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), r.addEventListener("change", (e) => {
|
|
333
386
|
let t = e.target;
|
|
334
387
|
t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
|
|
335
|
-
}),
|
|
388
|
+
}), r.addEventListener("paste", (e) => {
|
|
336
389
|
let t = e.clipboardData?.getData("text/html") || "";
|
|
337
390
|
if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
|
|
338
391
|
let n = this.sanitizePastedHtml(t);
|
|
339
392
|
n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
|
|
340
|
-
}),
|
|
393
|
+
}), r.addEventListener("beforeinput", (e) => {
|
|
341
394
|
let t = e;
|
|
395
|
+
if (this.handleHistoryBeforeInput(t)) return;
|
|
342
396
|
t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
|
|
343
397
|
let n = t.shiftKey;
|
|
344
398
|
if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
|
|
@@ -349,7 +403,7 @@ var a = class extends HTMLElement {
|
|
|
349
403
|
}
|
|
350
404
|
}
|
|
351
405
|
this.applyInlineTypingState(t);
|
|
352
|
-
}),
|
|
406
|
+
}), r.addEventListener("keyup", (e) => {
|
|
353
407
|
[
|
|
354
408
|
"ArrowLeft",
|
|
355
409
|
"ArrowRight",
|
|
@@ -360,15 +414,26 @@ var a = class extends HTMLElement {
|
|
|
360
414
|
"PageUp",
|
|
361
415
|
"PageDown"
|
|
362
416
|
].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
|
|
363
|
-
}),
|
|
417
|
+
}), r.addEventListener("mouseup", () => {
|
|
364
418
|
this.updateSelectedImage(), this.updateSelectionUI();
|
|
365
|
-
}),
|
|
419
|
+
}), n.addEventListener("selectionchange", () => this.updateSelectionUI()), n.addEventListener("pointerover", (e) => {
|
|
420
|
+
let t = e.target;
|
|
421
|
+
if (!t || t.nodeType !== Node.ELEMENT_NODE) return;
|
|
422
|
+
let n = t.closest("a[href]"), r = e.relatedTarget;
|
|
423
|
+
!n || r && r.nodeType && n.contains(r) || (this.bindEditorLinkTooltip(n), this.showTooltip(n));
|
|
424
|
+
}), r.addEventListener("scroll", () => this.positionTableTools()), r.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), n.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), r.addEventListener("click", (e) => {
|
|
366
425
|
this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
|
|
367
426
|
let t = e.target, n = t.closest(".mint-editor-image-frame");
|
|
368
427
|
n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
|
|
369
428
|
let r = t.closest("table");
|
|
370
|
-
this.selectTable(r)
|
|
371
|
-
|
|
429
|
+
this.selectTable(r);
|
|
430
|
+
let i = t.closest("a[href]");
|
|
431
|
+
if (i) if (e.preventDefault(), this.isOpenLinkModifier(e)) this.openEditorLink(i, "new-tab");
|
|
432
|
+
else {
|
|
433
|
+
let e = i.getAttribute("data-mint-editor-open");
|
|
434
|
+
e && e !== "same-tab" && this.openEditorLink(i, e);
|
|
435
|
+
}
|
|
436
|
+
}), r.addEventListener("keydown", (e) => {
|
|
372
437
|
if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
|
|
373
438
|
let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
|
|
374
439
|
if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
|
|
@@ -377,26 +442,26 @@ var a = class extends HTMLElement {
|
|
|
377
442
|
}
|
|
378
443
|
}
|
|
379
444
|
(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"));
|
|
380
|
-
}), this.observer && this.observer.observe(
|
|
445
|
+
}), this.observer && this.observer.observe(r, {
|
|
381
446
|
childList: !0,
|
|
382
447
|
subtree: !0,
|
|
383
448
|
characterData: !0
|
|
384
|
-
}), this.updateWordCount(), this.updateSelectionUI();
|
|
449
|
+
}), this.updateWordCount(), this.updateSelectionUI(), this.history.length === 0 ? this.resetHistory() : this.updateHistoryButtons();
|
|
385
450
|
}
|
|
386
451
|
buildToolbar(e) {
|
|
387
452
|
let t = (t, n, r, i = e) => {
|
|
388
453
|
let a = document.createElement("button");
|
|
389
454
|
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) => {
|
|
390
|
-
e.preventDefault(), r
|
|
455
|
+
e.preventDefault(), this.runHistoryTransaction(r);
|
|
391
456
|
}), i.append(a), a;
|
|
392
457
|
}, n = (e, t, n) => {
|
|
393
458
|
let r = document.createElement("mint-popover");
|
|
394
459
|
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;
|
|
395
460
|
}, r = (e, t, n, r) => {
|
|
396
461
|
let i = this.createMenuOption(t, n);
|
|
397
|
-
return i.addEventListener("click", r), e.append(i), i;
|
|
462
|
+
return i.addEventListener("click", () => this.runHistoryTransaction(r)), e.append(i), i;
|
|
398
463
|
};
|
|
399
|
-
t("Undo", "undo", () => this.
|
|
464
|
+
this.undoButton = t("Undo", "undo", () => this.undo()), this.redoButton = t("Redo", "redo", () => this.redo()), this.updateHistoryButtons();
|
|
400
465
|
let i = document.createElement("button");
|
|
401
466
|
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`;
|
|
402
467
|
let a = document.createElement("span");
|
|
@@ -536,12 +601,10 @@ var a = class extends HTMLElement {
|
|
|
536
601
|
O,
|
|
537
602
|
k,
|
|
538
603
|
A
|
|
539
|
-
]);
|
|
540
|
-
let j = p("
|
|
541
|
-
|
|
542
|
-
let M =
|
|
543
|
-
M.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, M.append(this.icon("caret-down")), this.alignmentTrigger = M;
|
|
544
|
-
let N = n(M, "mint-editor-alignment-popover", u);
|
|
604
|
+
]), h();
|
|
605
|
+
let j = p("Text alignment", "align-left", () => {});
|
|
606
|
+
j.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, j.append(this.icon("caret-down")), this.alignmentTrigger = j;
|
|
607
|
+
let M = n(j, "mint-editor-alignment-popover", u);
|
|
545
608
|
[
|
|
546
609
|
[
|
|
547
610
|
"Align left",
|
|
@@ -564,50 +627,50 @@ var a = class extends HTMLElement {
|
|
|
564
627
|
"justifyFull"
|
|
565
628
|
]
|
|
566
629
|
].forEach(([e, t, n]) => {
|
|
567
|
-
r(
|
|
568
|
-
this.command(n),
|
|
630
|
+
r(M, e, t, () => {
|
|
631
|
+
this.command(n), M.close(), this.updateTooltipLabel(j, `Text alignment: ${e}`);
|
|
569
632
|
});
|
|
570
|
-
}), f.push([
|
|
571
|
-
let
|
|
572
|
-
|
|
573
|
-
let
|
|
633
|
+
}), f.push([j, M]), h();
|
|
634
|
+
let N = p("Bulleted list", "list", () => this.command("insertUnorderedList")), P = document.createElement("button");
|
|
635
|
+
P.type = "button", P.className = "mint-editor-tool-button mint-editor-list-options-trigger", P.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-bullet-options-trigger`, this.setTooltip(P, "Bulleted list style"), P.append(this.icon("caret-down")), P.addEventListener("pointerdown", () => this.saveSelection()), u.append(P);
|
|
636
|
+
let F = n(P, "mint-editor-list-popover", u);
|
|
574
637
|
[
|
|
575
638
|
["Disc", "disc"],
|
|
576
639
|
["Circle", "circle"],
|
|
577
640
|
["Square", "square"]
|
|
578
|
-
].forEach(([e, t]) => r(
|
|
579
|
-
this.applyListStyle("ul", t),
|
|
641
|
+
].forEach(([e, t]) => r(F, e, "list", () => {
|
|
642
|
+
this.applyListStyle("ul", t), F.close();
|
|
580
643
|
}));
|
|
581
|
-
let
|
|
582
|
-
|
|
583
|
-
let
|
|
644
|
+
let I = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), L = document.createElement("button");
|
|
645
|
+
L.type = "button", L.className = "mint-editor-tool-button mint-editor-list-options-trigger", L.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-numbered-options-trigger`, this.setTooltip(L, "Numbered list style"), L.append(this.icon("caret-down")), L.addEventListener("pointerdown", () => this.saveSelection()), u.append(L);
|
|
646
|
+
let R = n(L, "mint-editor-list-popover", u);
|
|
584
647
|
[
|
|
585
648
|
["Numbers", "decimal"],
|
|
586
649
|
["Lowercase letters", "lower-alpha"],
|
|
587
650
|
["Uppercase letters", "upper-alpha"],
|
|
588
651
|
["Lowercase Roman numerals", "lower-roman"],
|
|
589
652
|
["Uppercase Roman numerals", "upper-roman"]
|
|
590
|
-
].forEach(([e, t]) => r(
|
|
591
|
-
this.applyListStyle("ol", t),
|
|
653
|
+
].forEach(([e, t]) => r(R, e, "numbered-list", () => {
|
|
654
|
+
this.applyListStyle("ol", t), R.close();
|
|
592
655
|
}));
|
|
593
|
-
let
|
|
656
|
+
let z = p("Checklist", "checklist", () => this.toggleChecklist());
|
|
594
657
|
f.push([
|
|
658
|
+
N,
|
|
595
659
|
P,
|
|
596
|
-
F
|
|
597
|
-
I
|
|
660
|
+
F
|
|
598
661
|
], [
|
|
662
|
+
I,
|
|
599
663
|
L,
|
|
600
|
-
R
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
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;
|
|
664
|
+
R
|
|
665
|
+
], [z]), h();
|
|
666
|
+
let B = p("HTML source", "code", () => this.toggleSource());
|
|
667
|
+
f.push([B]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
|
|
668
|
+
let V = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
|
|
669
|
+
f.push([V]);
|
|
670
|
+
let H = document.createElement("button");
|
|
671
|
+
H.type = "button", H.className = "mint-editor-tool-button mint-editor-overflow-trigger", this.setTooltip(H, "More formatting options"), H.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-overflow-trigger`, H.append(this.icon("ellipsis"));
|
|
672
|
+
let U = document.createElement("mint-popover");
|
|
673
|
+
U.setAttribute("trigger-id", H.id), U.setAttribute("padding", "0.25rem"), U.setAttribute("direction", "down"), U.className = "mint-editor-menu-popover mint-editor-overflow-popover", e.append(H, U), this.overflowTrigger = H, this.overflowPopover = U, this.overflowGroups = f;
|
|
611
674
|
}
|
|
612
675
|
buildColorPopover(e, t, n) {
|
|
613
676
|
let r = [
|
|
@@ -678,7 +741,9 @@ var a = class extends HTMLElement {
|
|
|
678
741
|
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();
|
|
679
742
|
return;
|
|
680
743
|
}
|
|
681
|
-
this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"),
|
|
744
|
+
this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), this.runHistoryTransaction(() => {
|
|
745
|
+
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();
|
|
746
|
+
}), this.updateSelectionUI();
|
|
682
747
|
}
|
|
683
748
|
readFontSize() {
|
|
684
749
|
let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
|
|
@@ -695,58 +760,63 @@ var a = class extends HTMLElement {
|
|
|
695
760
|
this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
696
761
|
return;
|
|
697
762
|
}
|
|
698
|
-
this.inlineStyleOverrides.delete("fontSize")
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
763
|
+
this.inlineStyleOverrides.delete("fontSize"), this.runHistoryTransaction(() => {
|
|
764
|
+
let e = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
|
|
765
|
+
n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((r) => {
|
|
766
|
+
if (e.has(r)) return;
|
|
767
|
+
let i = n.createElement("span");
|
|
768
|
+
i.style.fontSize = `${t}px`, r.getAttribute("face") && (i.style.fontFamily = r.getAttribute("face") || ""), r.getAttribute("color") && (i.style.color = r.getAttribute("color") || ""), i.append(...Array.from(r.childNodes)), r.replaceWith(i);
|
|
769
|
+
}), this.emitChange();
|
|
770
|
+
}), this.updateSelectionUI();
|
|
705
771
|
}
|
|
706
772
|
applyFontFamily(e) {
|
|
707
|
-
if (!this.editor || this.sourceMode)
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
773
|
+
if (!(!this.editor || this.sourceMode)) {
|
|
774
|
+
if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
|
|
775
|
+
this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
this.inlineStyleOverrides.delete("fontFamily"), this.runHistoryTransaction(() => {
|
|
779
|
+
let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
|
|
780
|
+
t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
|
|
781
|
+
if (n.has(r)) return;
|
|
782
|
+
let i = t.createElement("span");
|
|
783
|
+
i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
|
|
784
|
+
}), this.emitChange();
|
|
785
|
+
}), this.updateSelectionUI();
|
|
711
786
|
}
|
|
712
|
-
this.inlineStyleOverrides.delete("fontFamily");
|
|
713
|
-
let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
|
|
714
|
-
t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
|
|
715
|
-
if (n.has(r)) return;
|
|
716
|
-
let i = t.createElement("span");
|
|
717
|
-
i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
|
|
718
|
-
}), this.emitChange(), this.updateSelectionUI();
|
|
719
787
|
}
|
|
720
788
|
applyListStyle(e, t) {
|
|
721
789
|
if (!this.editor || this.sourceMode) return;
|
|
722
790
|
this.editor.focus(), this.restoreSelection();
|
|
723
791
|
let n = this.selection?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest(e), i = r && this.editor.contains(r) ? r : null;
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
792
|
+
this.runHistoryTransaction(() => {
|
|
793
|
+
if (!i) {
|
|
794
|
+
this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
|
|
795
|
+
let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
|
|
796
|
+
i = n && this.editor.contains(n) ? n : null;
|
|
797
|
+
}
|
|
798
|
+
i && (i.style.listStyleType = t), this.emitChange();
|
|
799
|
+
}), this.updateSelectionUI();
|
|
730
800
|
}
|
|
731
801
|
toggleChecklist() {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
802
|
+
!this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
|
|
803
|
+
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");
|
|
804
|
+
if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
|
|
805
|
+
else {
|
|
806
|
+
i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
|
|
807
|
+
let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
|
|
808
|
+
if (a && this.editor.contains(a)) {
|
|
809
|
+
a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
|
|
810
|
+
if (t.querySelector("input[type=\"checkbox\"]")) return;
|
|
811
|
+
let r = e.createElement("input");
|
|
812
|
+
r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
|
|
813
|
+
});
|
|
814
|
+
let t = a.parentElement;
|
|
815
|
+
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));
|
|
816
|
+
}
|
|
747
817
|
}
|
|
748
|
-
|
|
749
|
-
|
|
818
|
+
this.emitChange();
|
|
819
|
+
}), this.updateSelectionUI());
|
|
750
820
|
}
|
|
751
821
|
splitTaskItem(e, t) {
|
|
752
822
|
if (!this.editor) return;
|
|
@@ -799,44 +869,6 @@ var a = class extends HTMLElement {
|
|
|
799
869
|
let a = this.selection, o = this.editor.ownerDocument.createRange();
|
|
800
870
|
o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
|
|
801
871
|
}
|
|
802
|
-
openCommentModal() {
|
|
803
|
-
this.saveSelection();
|
|
804
|
-
let e = this._savedRange?.toString() || "", t = document.createElement("mint-modal");
|
|
805
|
-
t.setAttribute("heading", "Add comment"), t.setAttribute("size", "small");
|
|
806
|
-
let n = document.createElement("div");
|
|
807
|
-
n.setAttribute("slot", "body"), n.className = "mint-editor-modal-fields";
|
|
808
|
-
let r = document.createElement("p");
|
|
809
|
-
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.";
|
|
810
|
-
let i = document.createElement("textarea");
|
|
811
|
-
i.className = "mint-editor-comment-input", i.setAttribute("aria-label", "Comment"), i.setAttribute("placeholder", "Write a comment…"), i.rows = 4, n.append(r, i);
|
|
812
|
-
let a = document.createElement("div");
|
|
813
|
-
a.setAttribute("slot", "actions"), a.className = "mint-editor-modal-actions";
|
|
814
|
-
let o = document.createElement("mint-button");
|
|
815
|
-
o.textContent = "Cancel", o.setAttribute("variant", "ghost"), this.setTooltip(o, "Cancel"), o.addEventListener("click", () => t.close());
|
|
816
|
-
let s = document.createElement("mint-button");
|
|
817
|
-
s.textContent = "Add comment", s.setAttribute("tone", "action"), s.toggleAttribute("disabled", !e), this.setTooltip(s, "Add comment"), s.addEventListener("click", () => {
|
|
818
|
-
let n = i.value.trim();
|
|
819
|
-
!n || !e || (this.insertComment(n, e), t.close());
|
|
820
|
-
}), a.append(o, s), t.append(n, a), this.append(t), t.open();
|
|
821
|
-
}
|
|
822
|
-
insertComment(e, t) {
|
|
823
|
-
let n = this._savedRange;
|
|
824
|
-
if (this.editor && n && !n.collapsed && this.editor.contains(n.commonAncestorContainer) && this.format === "html") {
|
|
825
|
-
let t = this.editor.ownerDocument.createElement("span");
|
|
826
|
-
t.className = "mint-editor-comment", t.setAttribute("data-mint-comment", e), t.title = `Comment: ${e}`, t.append(n.extractContents()), n.insertNode(t);
|
|
827
|
-
let r = this.selection;
|
|
828
|
-
n.selectNodeContents(t), r?.removeAllRanges(), r?.addRange(n);
|
|
829
|
-
}
|
|
830
|
-
this.dispatchEvent(new CustomEvent("mint-editor-comment-request", {
|
|
831
|
-
bubbles: !0,
|
|
832
|
-
composed: !0,
|
|
833
|
-
detail: {
|
|
834
|
-
selectedText: t,
|
|
835
|
-
comment: e,
|
|
836
|
-
format: this.format
|
|
837
|
-
}
|
|
838
|
-
})), this.emitChange();
|
|
839
|
-
}
|
|
840
872
|
updateToolbarOverflow() {
|
|
841
873
|
let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
|
|
842
874
|
if (!e || !t || !n) return;
|
|
@@ -852,7 +884,9 @@ var a = class extends HTMLElement {
|
|
|
852
884
|
t.hidden = n.childElementCount === 0;
|
|
853
885
|
}
|
|
854
886
|
clearFormatting() {
|
|
855
|
-
!this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.
|
|
887
|
+
!this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
|
|
888
|
+
this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange();
|
|
889
|
+
}), this.updateSelectionUI());
|
|
856
890
|
}
|
|
857
891
|
icon(e) {
|
|
858
892
|
let t = document.createElement("mint-icon");
|
|
@@ -861,6 +895,48 @@ var a = class extends HTMLElement {
|
|
|
861
895
|
setTooltip(e, t) {
|
|
862
896
|
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()));
|
|
863
897
|
}
|
|
898
|
+
linkOpenModifier() {
|
|
899
|
+
let e = navigator.userAgentData?.platform || navigator.platform || "";
|
|
900
|
+
return /mac|iphone|ipad|ipod/i.test(e) ? "⌘" : "Ctrl";
|
|
901
|
+
}
|
|
902
|
+
isOpenLinkModifier(e) {
|
|
903
|
+
return this.linkOpenModifier() === "⌘" ? e.metaKey : e.ctrlKey;
|
|
904
|
+
}
|
|
905
|
+
openEditorLink(e, t) {
|
|
906
|
+
if (t === "same-tab") {
|
|
907
|
+
this.ownerDocument.defaultView?.location.assign(e.href);
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
if (t === "new-tab") {
|
|
911
|
+
window.open(e.href, "_blank", "noopener,noreferrer");
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
let n = t === "popup", r = n ? [
|
|
915
|
+
"popup=yes",
|
|
916
|
+
`width=${this.normalizePopupNumber(e.dataset.mintPopupWidth || "", 200, 4e3, "800")}`,
|
|
917
|
+
`height=${this.normalizePopupNumber(e.dataset.mintPopupHeight || "", 150, 4e3, "600")}`,
|
|
918
|
+
e.dataset.mintPopupLeft ? `left=${this.normalizePopupNumber(e.dataset.mintPopupLeft, 0, 1e4, "")}` : "",
|
|
919
|
+
e.dataset.mintPopupTop ? `top=${this.normalizePopupNumber(e.dataset.mintPopupTop, 0, 1e4, "")}` : "",
|
|
920
|
+
`resizable=${e.dataset.mintPopupResizable === "no" ? "no" : "yes"}`,
|
|
921
|
+
`scrollbars=${e.dataset.mintPopupScrollbars === "no" ? "no" : "yes"}`
|
|
922
|
+
].filter(Boolean).join(",") : "popup=no", i = n ? "mint-editor-popup" : "mint-editor-window", a = window.open(e.href, i, r);
|
|
923
|
+
if (!a) return;
|
|
924
|
+
try {
|
|
925
|
+
a.opener = null;
|
|
926
|
+
} catch {}
|
|
927
|
+
let o = e.dataset.mintPopupTitle?.trim();
|
|
928
|
+
if (n && o) {
|
|
929
|
+
let e = () => {
|
|
930
|
+
try {
|
|
931
|
+
a.document.title = o;
|
|
932
|
+
} catch {}
|
|
933
|
+
};
|
|
934
|
+
e(), a.addEventListener("load", e, { once: !0 });
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
bindEditorLinkTooltip(e) {
|
|
938
|
+
e.dataset.editorTooltipBound !== "true" && (e.dataset.editorTooltipBound = "true", e.setAttribute("data-editor-tooltip", `${this.linkOpenModifier()} + click to open`), e.addEventListener("pointerenter", () => this.showTooltip(e)), e.addEventListener("pointerleave", () => this.hideTooltip()), e.addEventListener("focus", () => this.showTooltip(e)), e.addEventListener("blur", () => this.hideTooltip()));
|
|
939
|
+
}
|
|
864
940
|
updateTooltipLabel(e, t) {
|
|
865
941
|
e.setAttribute("data-editor-tooltip", t);
|
|
866
942
|
let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
|
|
@@ -887,8 +963,23 @@ var a = class extends HTMLElement {
|
|
|
887
963
|
}), document.body.append(n), this.tooltipPopup = n;
|
|
888
964
|
}
|
|
889
965
|
n.textContent = t, n.setAttribute("aria-hidden", "false"), n.style.visibility = "hidden", n.style.display = "block";
|
|
890
|
-
let r = e.getBoundingClientRect(), i =
|
|
891
|
-
|
|
966
|
+
let r = e.getBoundingClientRect(), i = {
|
|
967
|
+
left: r.left,
|
|
968
|
+
top: r.top,
|
|
969
|
+
width: r.width,
|
|
970
|
+
bottom: r.bottom
|
|
971
|
+
}, a = e.ownerDocument.defaultView?.frameElement;
|
|
972
|
+
if (a) {
|
|
973
|
+
let e = a.getBoundingClientRect(), t = a.clientWidth ? e.width / a.clientWidth : 1, n = a.clientHeight ? e.height / a.clientHeight : 1;
|
|
974
|
+
i = {
|
|
975
|
+
left: e.left + r.left * t,
|
|
976
|
+
top: e.top + r.top * n,
|
|
977
|
+
width: r.width * t,
|
|
978
|
+
bottom: e.top + r.bottom * n
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
let o = n.getBoundingClientRect(), s = Math.max(8, Math.min(window.innerWidth - o.width - 8, i.left + i.width / 2 - o.width / 2)), c = i.top >= o.height + 6 + 8 ? i.top - o.height - 6 : Math.min(window.innerHeight - o.height - 8, i.bottom + 6);
|
|
982
|
+
n.style.left = `${s}px`, n.style.top = `${c}px`, n.style.visibility = "visible";
|
|
892
983
|
}
|
|
893
984
|
hideTooltip() {
|
|
894
985
|
this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
|
|
@@ -924,7 +1015,9 @@ var a = class extends HTMLElement {
|
|
|
924
1015
|
return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
|
|
925
1016
|
}
|
|
926
1017
|
command(e, t) {
|
|
927
|
-
!this.editor || this.sourceMode || (this.
|
|
1018
|
+
!this.editor || this.sourceMode || (this.runHistoryTransaction(() => {
|
|
1019
|
+
this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange();
|
|
1020
|
+
}), this.updateSelectionUI());
|
|
928
1021
|
}
|
|
929
1022
|
toggleInline(e) {
|
|
930
1023
|
if (!this.editor || this.sourceMode) return;
|
|
@@ -936,7 +1029,9 @@ var a = class extends HTMLElement {
|
|
|
936
1029
|
this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
|
|
937
1030
|
return;
|
|
938
1031
|
}
|
|
939
|
-
this.
|
|
1032
|
+
this.runHistoryTransaction(() => {
|
|
1033
|
+
this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange();
|
|
1034
|
+
}), this.updateSelectionUI();
|
|
940
1035
|
}
|
|
941
1036
|
inlineStateAtSelection(e, t) {
|
|
942
1037
|
let n = this.selection, r = this.inlineOverrides.get(e);
|
|
@@ -1207,24 +1302,7 @@ var a = class extends HTMLElement {
|
|
|
1207
1302
|
e.replaceWith(...Array.from(e.childNodes));
|
|
1208
1303
|
};
|
|
1209
1304
|
for (let e of Array.from(i.querySelectorAll("*"))) e.tagName.includes(":") && l(e);
|
|
1210
|
-
let u = new Set(
|
|
1211
|
-
"href",
|
|
1212
|
-
"src",
|
|
1213
|
-
"alt",
|
|
1214
|
-
"title",
|
|
1215
|
-
"colspan",
|
|
1216
|
-
"rowspan",
|
|
1217
|
-
"start",
|
|
1218
|
-
"value",
|
|
1219
|
-
"type",
|
|
1220
|
-
"width",
|
|
1221
|
-
"height",
|
|
1222
|
-
"border",
|
|
1223
|
-
"cellpadding",
|
|
1224
|
-
"cellspacing",
|
|
1225
|
-
"scope",
|
|
1226
|
-
"dir"
|
|
1227
|
-
]), d = (e, t = !1) => {
|
|
1305
|
+
let u = new Set(/* @__PURE__ */ "href.src.alt.title.target.rel.data-mint-editor-open.data-mint-popup-title.data-mint-popup-width.data-mint-popup-height.data-mint-popup-left.data-mint-popup-top.data-mint-popup-resizable.data-mint-popup-scrollbars.colspan.rowspan.start.value.type.width.height.border.cellpadding.cellspacing.scope.dir".split(".")), d = (e, t = !1) => {
|
|
1228
1306
|
let n = e.trim();
|
|
1229
1307
|
if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
|
|
1230
1308
|
try {
|
|
@@ -1243,7 +1321,17 @@ var a = class extends HTMLElement {
|
|
|
1243
1321
|
if (n === "style") {
|
|
1244
1322
|
let n = o(t.value);
|
|
1245
1323
|
n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
|
|
1246
|
-
} else u.has(n)
|
|
1324
|
+
} else if (!u.has(n)) e.removeAttribute(t.name);
|
|
1325
|
+
else if ((n === "href" || n === "src") && !d(t.value, n === "src")) e.removeAttribute(t.name);
|
|
1326
|
+
else if (n === "target" && !/^(_self|_blank|mint-editor-window|mint-editor-popup)$/i.test(t.value.trim())) e.removeAttribute(t.name);
|
|
1327
|
+
else if (n === "rel") {
|
|
1328
|
+
let n = t.value.toLowerCase().split(/\s+/).filter((e) => ["noopener", "noreferrer"].includes(e));
|
|
1329
|
+
n.length ? e.setAttribute("rel", Array.from(new Set(n)).join(" ")) : e.removeAttribute(t.name);
|
|
1330
|
+
} else if (n === "data-mint-editor-open" && !/^(same-tab|new-tab|new-window|popup)$/.test(t.value)) e.removeAttribute(t.name);
|
|
1331
|
+
else if (/^data-mint-popup-(width|height|left|top)$/.test(n)) {
|
|
1332
|
+
let r = Number.parseInt(t.value, 10), i = /width|height/.test(n) ? 150 : 0;
|
|
1333
|
+
!Number.isFinite(r) || r < i || r > 1e4 ? e.removeAttribute(t.name) : e.setAttribute(t.name, String(r));
|
|
1334
|
+
} else /^data-mint-popup-(resizable|scrollbars)$/.test(n) && !/^(yes|no)$/.test(t.value) ? e.removeAttribute(t.name) : n === "data-mint-popup-title" && t.value.length > 120 ? e.setAttribute(n, t.value.slice(0, 120)) : ([
|
|
1247
1335
|
"colspan",
|
|
1248
1336
|
"rowspan",
|
|
1249
1337
|
"start",
|
|
@@ -1253,20 +1341,34 @@ var a = class extends HTMLElement {
|
|
|
1253
1341
|
"border",
|
|
1254
1342
|
"cellpadding",
|
|
1255
1343
|
"cellspacing"
|
|
1256
|
-
].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)
|
|
1344
|
+
].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);
|
|
1257
1345
|
}
|
|
1258
1346
|
for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
|
|
1259
1347
|
return i.innerHTML.trim();
|
|
1260
1348
|
}
|
|
1261
1349
|
syncSource() {
|
|
1262
1350
|
if (this.source && this.editor) {
|
|
1263
|
-
let e = this.cleanEditorCopy();
|
|
1264
|
-
this.source.value = this.format === "markdown" ?
|
|
1351
|
+
let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
|
|
1352
|
+
this.sourceMode || (this.source.value = t), this.preservedContent = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? t : this.editor.innerHTML;
|
|
1265
1353
|
}
|
|
1266
1354
|
this.updateWordCount();
|
|
1267
1355
|
}
|
|
1268
|
-
emitChange() {
|
|
1269
|
-
this.
|
|
1356
|
+
emitChange(e) {
|
|
1357
|
+
if (this.historyTransactionDepth > 0) {
|
|
1358
|
+
this.historyTransactionPending = !0;
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
this.syncSource(), this.applyingHistory || this.recordHistory(e || null), this.dispatchValueEvents();
|
|
1362
|
+
}
|
|
1363
|
+
runHistoryTransaction(e) {
|
|
1364
|
+
this.historyTransactionDepth += 1;
|
|
1365
|
+
try {
|
|
1366
|
+
e();
|
|
1367
|
+
} finally {
|
|
1368
|
+
--this.historyTransactionDepth, this.historyTransactionDepth === 0 && this.historyTransactionPending && (this.historyTransactionPending = !1, this.syncSource(), this.recordHistory(null), this.dispatchValueEvents());
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
dispatchValueEvents() {
|
|
1270
1372
|
let e = this.value;
|
|
1271
1373
|
this.dispatchEvent(new CustomEvent("input", {
|
|
1272
1374
|
bubbles: !0,
|
|
@@ -1278,6 +1380,119 @@ var a = class extends HTMLElement {
|
|
|
1278
1380
|
detail: { value: e }
|
|
1279
1381
|
}));
|
|
1280
1382
|
}
|
|
1383
|
+
resetHistory() {
|
|
1384
|
+
this.history = [], this.historyIndex = -1, this.editor && this.recordHistory(null), this.updateHistoryButtons();
|
|
1385
|
+
}
|
|
1386
|
+
refreshCurrentHistorySnapshot() {
|
|
1387
|
+
if (this.historyIndex < 0) return;
|
|
1388
|
+
let e = this.captureHistorySnapshot(null);
|
|
1389
|
+
e && (this.history[this.historyIndex] = e);
|
|
1390
|
+
}
|
|
1391
|
+
captureHistoryPoint(e, t) {
|
|
1392
|
+
let n = this.editor;
|
|
1393
|
+
if (!n || !e || e !== n && !n.contains(e)) return null;
|
|
1394
|
+
let r = [], i = e;
|
|
1395
|
+
for (; i && i !== n;) {
|
|
1396
|
+
let e = i.parentNode;
|
|
1397
|
+
if (!e) return null;
|
|
1398
|
+
r.unshift(Array.prototype.indexOf.call(e.childNodes, i)), i = e;
|
|
1399
|
+
}
|
|
1400
|
+
return i === n ? {
|
|
1401
|
+
path: r,
|
|
1402
|
+
offset: Math.max(0, Math.min(t, e.nodeType === Node.TEXT_NODE ? (e.textContent || "").length : e.childNodes.length))
|
|
1403
|
+
} : null;
|
|
1404
|
+
}
|
|
1405
|
+
resolveHistoryPoint(e) {
|
|
1406
|
+
let t = this.editor;
|
|
1407
|
+
if (!t || !e) return null;
|
|
1408
|
+
let n = t;
|
|
1409
|
+
for (let t of e.path) {
|
|
1410
|
+
let e = n.childNodes[Math.max(0, Math.min(t, n.childNodes.length - 1))];
|
|
1411
|
+
if (!e) break;
|
|
1412
|
+
n = e;
|
|
1413
|
+
}
|
|
1414
|
+
let r = n.nodeType === Node.TEXT_NODE ? (n.textContent || "").length : n.childNodes.length;
|
|
1415
|
+
return {
|
|
1416
|
+
node: n,
|
|
1417
|
+
offset: Math.max(0, Math.min(e.offset, r))
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
captureHistorySnapshot(e) {
|
|
1421
|
+
if (!this.editor) return null;
|
|
1422
|
+
let t = this.selection, n = this.sourceMode && this.source ? {
|
|
1423
|
+
start: this.source.selectionStart,
|
|
1424
|
+
end: this.source.selectionEnd,
|
|
1425
|
+
direction: this.source.selectionDirection
|
|
1426
|
+
} : null, r = this.cleanEditorCopy(), i = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? o(r) : r.innerHTML;
|
|
1427
|
+
return {
|
|
1428
|
+
html: r.innerHTML,
|
|
1429
|
+
source: i,
|
|
1430
|
+
anchor: this.captureHistoryPoint(t?.anchorNode || null, t?.anchorOffset || 0),
|
|
1431
|
+
focus: this.captureHistoryPoint(t?.focusNode || null, t?.focusOffset || 0),
|
|
1432
|
+
sourceSelection: n,
|
|
1433
|
+
group: e,
|
|
1434
|
+
time: Date.now()
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
recordHistory(e) {
|
|
1438
|
+
if (!this.editor || this.applyingHistory) return;
|
|
1439
|
+
let t = e === "insertText" || e === "insertCompositionText" ? "typing" : e === "deleteContentBackward" || e === "deleteContentForward" || e === "deleteByCut" ? "deleting" : null, n = this.captureHistorySnapshot(t);
|
|
1440
|
+
if (!n) return;
|
|
1441
|
+
if (this.historyIndex < 0) {
|
|
1442
|
+
this.history = [n], this.historyIndex = 0, this.updateHistoryButtons();
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
let r = this.history[this.historyIndex];
|
|
1446
|
+
if (n.html === r.html && n.source === r.source) {
|
|
1447
|
+
n.group = t, this.history[this.historyIndex] = n, this.updateHistoryButtons();
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
t !== null && r.group === t && n.time - r.time <= 900 ? this.history[this.historyIndex] = n : (this.history = this.history.slice(0, this.historyIndex + 1), this.history.push(n), this.historyIndex = this.history.length - 1, this.history.length > 100 && (this.history.shift(), this.historyIndex = this.history.length - 1)), this.updateHistoryButtons();
|
|
1451
|
+
}
|
|
1452
|
+
updateHistoryButtons() {
|
|
1453
|
+
let e = this.historyIndex > 0 && this.historyIndex < this.history.length, t = this.historyIndex >= 0 && this.historyIndex < this.history.length - 1;
|
|
1454
|
+
this.undoButton && (this.undoButton.disabled = !e), this.redoButton && (this.redoButton.disabled = !t);
|
|
1455
|
+
}
|
|
1456
|
+
restoreHistorySelection(e) {
|
|
1457
|
+
if (this.sourceMode && this.source && e.sourceSelection) {
|
|
1458
|
+
let t = Math.min(e.sourceSelection.start, this.source.value.length), n = Math.min(e.sourceSelection.end, this.source.value.length);
|
|
1459
|
+
this.source.setSelectionRange(t, n, e.sourceSelection.direction), this.source.focus();
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
let t = this.selection, n = this.resolveHistoryPoint(e.anchor), r = this.resolveHistoryPoint(e.focus);
|
|
1463
|
+
if (!(!t || !n || !r)) if (t.removeAllRanges(), typeof t.setBaseAndExtent == "function") t.setBaseAndExtent(n.node, n.offset, r.node, r.offset);
|
|
1464
|
+
else {
|
|
1465
|
+
let e = this.editor.ownerDocument.createRange();
|
|
1466
|
+
e.setStart(n.node, n.offset), e.setEnd(r.node, r.offset), t.addRange(e);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
applyHistorySnapshot(e) {
|
|
1470
|
+
if (!(!this.editor || !this.source)) {
|
|
1471
|
+
this.applyingHistory = !0;
|
|
1472
|
+
try {
|
|
1473
|
+
this.editor.innerHTML = e.html, this.source.value = e.source, this.editor.querySelectorAll(".mint-editor-image-frame").forEach((e) => {
|
|
1474
|
+
e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.append(this.createResizeHandle());
|
|
1475
|
+
}), this.selectImage(null), this.selectTable(null), this.clearInlineTypingState(), this.preservedContent = this.format === "markdown" ? e.source : e.html, this.updateWordCount(), this.restoreHistorySelection(e), this.updateSelectedImage(), this.updateSelectionUI(), this.updateHistoryButtons();
|
|
1476
|
+
} finally {
|
|
1477
|
+
this.applyingHistory = !1;
|
|
1478
|
+
}
|
|
1479
|
+
this.dispatchValueEvents();
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
undo() {
|
|
1483
|
+
this.historyIndex <= 0 || (--this.historyIndex, this.applyHistorySnapshot(this.history[this.historyIndex]));
|
|
1484
|
+
}
|
|
1485
|
+
redo() {
|
|
1486
|
+
this.historyIndex >= this.history.length - 1 || (this.historyIndex += 1, this.applyHistorySnapshot(this.history[this.historyIndex]));
|
|
1487
|
+
}
|
|
1488
|
+
handleHistoryKeydown(e) {
|
|
1489
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey) return;
|
|
1490
|
+
let t = e.key.toLowerCase();
|
|
1491
|
+
t === "z" ? (e.preventDefault(), e.shiftKey ? this.redo() : this.undo()) : t === "y" && !e.shiftKey && (e.preventDefault(), this.redo());
|
|
1492
|
+
}
|
|
1493
|
+
handleHistoryBeforeInput(e) {
|
|
1494
|
+
return e.inputType === "historyUndo" ? (e.preventDefault(), this.undo(), !0) : e.inputType === "historyRedo" ? (e.preventDefault(), this.redo(), !0) : !1;
|
|
1495
|
+
}
|
|
1281
1496
|
updateWordCount() {
|
|
1282
1497
|
if (!this.editor || !this.count) return;
|
|
1283
1498
|
let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
|
|
@@ -1379,21 +1594,158 @@ var a = class extends HTMLElement {
|
|
|
1379
1594
|
}
|
|
1380
1595
|
openLinkModal() {
|
|
1381
1596
|
this.saveSelection();
|
|
1382
|
-
let e = document.createElement("mint-modal");
|
|
1383
|
-
|
|
1384
|
-
let t = document.createElement("div");
|
|
1385
|
-
t.setAttribute("slot", "body");
|
|
1386
|
-
let n = document.createElement("mint-input");
|
|
1387
|
-
n.setAttribute("type", "url"), n.setAttribute("label", "Link URL"), n.setAttribute("placeholder", "https://example.com"), t.append(n);
|
|
1597
|
+
let e = this._savedRange, t = e && !e.collapsed ? e.toString() : "", n = document.createElement("mint-modal");
|
|
1598
|
+
n.setAttribute("heading", "Insert link"), n.setAttribute("size", "small");
|
|
1388
1599
|
let r = document.createElement("div");
|
|
1389
|
-
r.setAttribute("slot", "
|
|
1390
|
-
let i = document.createElement("mint-
|
|
1391
|
-
i.
|
|
1392
|
-
let a = document.createElement("mint-
|
|
1393
|
-
a.
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1600
|
+
r.setAttribute("slot", "body"), r.className = "mint-editor-modal-fields";
|
|
1601
|
+
let i = document.createElement("mint-input");
|
|
1602
|
+
i.setAttribute("type", "text"), i.setAttribute("label", "Link text"), i.setAttribute("placeholder", "Text to display"), t && i.setAttribute("value", t);
|
|
1603
|
+
let a = document.createElement("mint-input");
|
|
1604
|
+
a.setAttribute("type", "url"), a.setAttribute("label", "Link URL"), a.setAttribute("placeholder", "https://example.com"), r.append(i, a);
|
|
1605
|
+
let o = document.createElement("mint-select");
|
|
1606
|
+
o.className = "mint-editor-link-target", o.setAttribute("label", "Open in"), o.setAttribute("value", "same-tab"), [
|
|
1607
|
+
["same-tab", "Same tab"],
|
|
1608
|
+
["new-tab", "New tab"],
|
|
1609
|
+
["new-window", "New window"],
|
|
1610
|
+
["popup", "Popup"]
|
|
1611
|
+
].forEach(([e, t]) => {
|
|
1612
|
+
let n = document.createElement("option");
|
|
1613
|
+
n.value = e, n.textContent = t, o.append(n);
|
|
1614
|
+
}), r.append(o);
|
|
1615
|
+
let s = document.createElement("mint-button");
|
|
1616
|
+
s.className = "mint-editor-link-advanced", s.textContent = "Advanced settings", s.setAttribute("variant", "ghost"), s.setAttribute("aria-expanded", "false"), s.hidden = !0;
|
|
1617
|
+
let c = document.createElement("div");
|
|
1618
|
+
c.className = "mint-editor-popup-settings", c.id = `${this.id || "mint-editor"}-popup-settings`, c.hidden = !0, s.setAttribute("aria-controls", c.id);
|
|
1619
|
+
let l = document.createElement("mint-input");
|
|
1620
|
+
l.setAttribute("type", "text"), l.setAttribute("label", "Window title"), l.setAttribute("placeholder", "Link popup");
|
|
1621
|
+
let u = document.createElement("mint-input");
|
|
1622
|
+
u.setAttribute("type", "number"), u.setAttribute("label", "Width"), u.setAttribute("min", "200"), u.setAttribute("max", "4000"), u.setAttribute("value", "800");
|
|
1623
|
+
let d = document.createElement("mint-input");
|
|
1624
|
+
d.setAttribute("type", "number"), d.setAttribute("label", "Height"), d.setAttribute("min", "150"), d.setAttribute("max", "4000"), d.setAttribute("value", "600");
|
|
1625
|
+
let f = document.createElement("mint-input");
|
|
1626
|
+
f.setAttribute("type", "number"), f.setAttribute("label", "Left position"), f.setAttribute("min", "0"), f.setAttribute("max", "10000"), f.setAttribute("placeholder", "Automatic");
|
|
1627
|
+
let p = document.createElement("mint-input");
|
|
1628
|
+
p.setAttribute("type", "number"), p.setAttribute("label", "Top position"), p.setAttribute("min", "0"), p.setAttribute("max", "10000"), p.setAttribute("placeholder", "Automatic");
|
|
1629
|
+
let m = document.createElement("mint-select");
|
|
1630
|
+
m.setAttribute("label", "Resizable"), m.setAttribute("value", "yes");
|
|
1631
|
+
let h = document.createElement("mint-select");
|
|
1632
|
+
h.setAttribute("label", "Scrollbars"), h.setAttribute("value", "yes"), [
|
|
1633
|
+
[
|
|
1634
|
+
m,
|
|
1635
|
+
"yes",
|
|
1636
|
+
"Yes"
|
|
1637
|
+
],
|
|
1638
|
+
[
|
|
1639
|
+
m,
|
|
1640
|
+
"no",
|
|
1641
|
+
"No"
|
|
1642
|
+
],
|
|
1643
|
+
[
|
|
1644
|
+
h,
|
|
1645
|
+
"yes",
|
|
1646
|
+
"Yes"
|
|
1647
|
+
],
|
|
1648
|
+
[
|
|
1649
|
+
h,
|
|
1650
|
+
"no",
|
|
1651
|
+
"No"
|
|
1652
|
+
]
|
|
1653
|
+
].forEach(([e, t, n]) => {
|
|
1654
|
+
let r = document.createElement("option");
|
|
1655
|
+
r.value = String(t), r.textContent = String(n), e.append(r);
|
|
1656
|
+
}), c.append(l, u, d, f, p, m, h), s.addEventListener("click", () => {
|
|
1657
|
+
c.hidden = !c.hidden, s.setAttribute("aria-expanded", String(!c.hidden));
|
|
1658
|
+
}), o.addEventListener("change", (e) => {
|
|
1659
|
+
let t = String(e.detail?.value || o.value);
|
|
1660
|
+
s.hidden = t !== "popup", t !== "popup" && (c.hidden = !0, s.setAttribute("aria-expanded", "false"));
|
|
1661
|
+
}), r.append(s, c);
|
|
1662
|
+
let g = document.createElement("div");
|
|
1663
|
+
g.setAttribute("slot", "actions"), g.className = "mint-editor-modal-actions";
|
|
1664
|
+
let _ = document.createElement("mint-button");
|
|
1665
|
+
_.textContent = "Cancel", _.setAttribute("variant", "ghost"), this.setTooltip(_, "Cancel"), _.addEventListener("click", () => n.close());
|
|
1666
|
+
let v = document.createElement("mint-button");
|
|
1667
|
+
v.textContent = "Insert link", v.setAttribute("tone", "action"), this.setTooltip(v, "Insert link"), v.addEventListener("click", () => {
|
|
1668
|
+
let e = String(a.value || "").trim(), t = String(i.value || ""), r = String(o.value || "same-tab"), s = {
|
|
1669
|
+
title: String(l.value || ""),
|
|
1670
|
+
width: String(u.value || "800"),
|
|
1671
|
+
height: String(d.value || "600"),
|
|
1672
|
+
left: String(f.value || ""),
|
|
1673
|
+
top: String(p.value || ""),
|
|
1674
|
+
resizable: String(m.value || "yes"),
|
|
1675
|
+
scrollbars: String(h.value || "yes")
|
|
1676
|
+
};
|
|
1677
|
+
e && t.trim() && (this.insertLink(e, t, r, s), n.close());
|
|
1678
|
+
}), g.append(_, v), n.append(r, g), this.append(n), n.open();
|
|
1679
|
+
}
|
|
1680
|
+
insertLink(e, t, n, r) {
|
|
1681
|
+
let i = this.editor, a = this._savedRange;
|
|
1682
|
+
if (!i || this.sourceMode || !a || !i.contains(a.commonAncestorContainer)) return;
|
|
1683
|
+
let o = a.collapsed ? "" : a.toString();
|
|
1684
|
+
if (o && o === t) {
|
|
1685
|
+
let t = a.cloneRange();
|
|
1686
|
+
this.runHistoryTransaction(() => {
|
|
1687
|
+
this.command("createLink", e);
|
|
1688
|
+
let a = Array.from(i.querySelectorAll("a[href]")).filter((e) => {
|
|
1689
|
+
try {
|
|
1690
|
+
return t.intersectsNode(e);
|
|
1691
|
+
} catch {
|
|
1692
|
+
return !1;
|
|
1693
|
+
}
|
|
1694
|
+
}), o = this.selection?.anchorNode, s = (o?.nodeType === Node.ELEMENT_NODE ? o : o?.parentElement)?.closest("a[href]");
|
|
1695
|
+
(a.length ? a : s ? [s] : []).forEach((e) => this.configureLinkTarget(e, n, r)), this.emitChange();
|
|
1696
|
+
}), this.updateSelectionUI();
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
this.runHistoryTransaction(() => {
|
|
1700
|
+
i.focus(), this.restoreSelection();
|
|
1701
|
+
let a = this.selection;
|
|
1702
|
+
if (!a?.rangeCount) return;
|
|
1703
|
+
let o = a.getRangeAt(0);
|
|
1704
|
+
if (!i.contains(o.commonAncestorContainer)) return;
|
|
1705
|
+
let s = (e) => {
|
|
1706
|
+
let t = (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest("a[href]");
|
|
1707
|
+
return t && i.contains(t) ? t : null;
|
|
1708
|
+
}, c = s(o.startContainer), l = s(o.endContainer), u, d;
|
|
1709
|
+
if (c && c === l) {
|
|
1710
|
+
if (d = c, o.collapsed) d.textContent = t, u = d;
|
|
1711
|
+
else {
|
|
1712
|
+
o.deleteContents();
|
|
1713
|
+
let e = i.ownerDocument.createTextNode(t);
|
|
1714
|
+
o.insertNode(e), u = e;
|
|
1715
|
+
}
|
|
1716
|
+
d.href = e;
|
|
1717
|
+
} else {
|
|
1718
|
+
d = i.ownerDocument.createElement("a"), d.href = e, o.deleteContents();
|
|
1719
|
+
let n = i.ownerDocument.createTextNode(t);
|
|
1720
|
+
d.append(n), o.insertNode(d), u = d;
|
|
1721
|
+
}
|
|
1722
|
+
this.configureLinkTarget(d, n, r), o.setStartAfter(u), o.collapse(!0), a.removeAllRanges(), a.addRange(o), this.emitChange();
|
|
1723
|
+
}), this.updateSelectionUI();
|
|
1724
|
+
}
|
|
1725
|
+
configureLinkTarget(e, t, n) {
|
|
1726
|
+
e.setAttribute("target", {
|
|
1727
|
+
"same-tab": "_self",
|
|
1728
|
+
"new-tab": "_blank",
|
|
1729
|
+
"new-window": "mint-editor-window",
|
|
1730
|
+
popup: "mint-editor-popup"
|
|
1731
|
+
}[t]), e.setAttribute("data-mint-editor-open", t), t === "same-tab" ? e.removeAttribute("rel") : e.setAttribute("rel", "noopener noreferrer");
|
|
1732
|
+
let r = {
|
|
1733
|
+
"data-mint-popup-title": n.title.trim().slice(0, 120),
|
|
1734
|
+
"data-mint-popup-width": this.normalizePopupNumber(n.width, 200, 4e3, "800"),
|
|
1735
|
+
"data-mint-popup-height": this.normalizePopupNumber(n.height, 150, 4e3, "600"),
|
|
1736
|
+
"data-mint-popup-left": this.normalizePopupNumber(n.left, 0, 1e4, ""),
|
|
1737
|
+
"data-mint-popup-top": this.normalizePopupNumber(n.top, 0, 1e4, ""),
|
|
1738
|
+
"data-mint-popup-resizable": n.resizable === "no" ? "no" : "yes",
|
|
1739
|
+
"data-mint-popup-scrollbars": n.scrollbars === "no" ? "no" : "yes"
|
|
1740
|
+
};
|
|
1741
|
+
Object.entries(r).forEach(([n, r]) => {
|
|
1742
|
+
t === "popup" && r ? e.setAttribute(n, r) : e.removeAttribute(n);
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
normalizePopupNumber(e, t, n, r) {
|
|
1746
|
+
if (!e.trim()) return r;
|
|
1747
|
+
let i = Number.parseInt(e, 10);
|
|
1748
|
+
return Number.isFinite(i) ? String(Math.max(t, Math.min(n, i))) : r;
|
|
1397
1749
|
}
|
|
1398
1750
|
selectedTable() {
|
|
1399
1751
|
let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
|
|
@@ -1496,9 +1848,9 @@ var a = class extends HTMLElement {
|
|
|
1496
1848
|
toggleSource() {
|
|
1497
1849
|
if (!(!this.editor || !this.source)) {
|
|
1498
1850
|
if (this.sourceMode = !this.sourceMode, this.clearInlineTypingState(), this.source.hidden = !this.sourceMode, this.editor.hidden = this.sourceMode, this.sourceMode) {
|
|
1499
|
-
let e = this.cleanEditorCopy();
|
|
1500
|
-
this.source.value = this.format === "markdown" ?
|
|
1501
|
-
} else this.editor.innerHTML = this.format === "markdown" ?
|
|
1851
|
+
let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
|
|
1852
|
+
this.source.value = this.format === "markdown" ? n(t) : r(t, this.editor.ownerDocument), this.refreshCurrentHistorySnapshot(), this.preservedContent = this.source.value, this.dispatchValueEvents();
|
|
1853
|
+
} else this.editor.innerHTML = this.format === "markdown" ? i(this.source.value) : this.source.value, this.syncSource(), this.emitChange();
|
|
1502
1854
|
this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
|
|
1503
1855
|
}
|
|
1504
1856
|
}
|
|
@@ -1527,6 +1879,6 @@ var a = class extends HTMLElement {
|
|
|
1527
1879
|
t && this.selectImage(t);
|
|
1528
1880
|
}
|
|
1529
1881
|
};
|
|
1530
|
-
customElements.get("mint-editor") || e("mint-editor",
|
|
1882
|
+
customElements.get("mint-editor") || e("mint-editor", s);
|
|
1531
1883
|
//#endregion
|
|
1532
|
-
export {
|
|
1884
|
+
export { s as default };
|