monobill-mintui 0.6.737 → 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.
Files changed (72) hide show
  1. package/bin/component-dependencies.json +2 -1
  2. package/dist/components/chunks/{date-picker-CTtYAkmM.js → date-picker-R8J7EzuF.js} +1 -1
  3. package/dist/components/chunks/{date-picker-CUf5eJR3.js → date-picker-STjYRdxE.js} +1 -1
  4. package/dist/components/chunks/{popover-DD7uyRXy.js → popover-7-PJT1-5.js} +14 -2
  5. package/dist/components/chunks/popover-CD0v0njp.js +1 -0
  6. package/dist/components/chunks/{select-DOMW7Plx.js → select-hL6gV7mL.js} +1 -1
  7. package/dist/components/chunks/{select-CX9oOwl5.js → select-oEt5Dm4P.js} +1 -1
  8. package/dist/components/chunks/{time-picker-C7pJvGSM.js → time-picker-B7oXBU8q.js} +1 -1
  9. package/dist/components/chunks/{time-picker-BaoT0NtA.js → time-picker-QzH9kywR.js} +1 -1
  10. package/dist/components/date-picker/browser.js +1 -1
  11. package/dist/components/date-picker/index.cjs +1 -1
  12. package/dist/components/date-picker/index.js +1 -1
  13. package/dist/components/datetime-picker/browser.js +2 -2
  14. package/dist/components/datetime-picker/index.cjs +1 -1
  15. package/dist/components/datetime-picker/index.js +2 -2
  16. package/dist/components/editor/Editor.d.ts +29 -2
  17. package/dist/components/editor/Editor.d.ts.map +1 -1
  18. package/dist/components/editor/browser.js +559 -211
  19. package/dist/components/editor/index.cjs +14 -8
  20. package/dist/components/editor/index.d.ts +1 -0
  21. package/dist/components/editor/index.d.ts.map +1 -1
  22. package/dist/components/editor/index.js +559 -211
  23. package/dist/components/link/browser.js +1 -1
  24. package/dist/components/link/index.cjs +1 -1
  25. package/dist/components/link/index.js +1 -1
  26. package/dist/components/navigation/browser.js +2 -2
  27. package/dist/components/navigation/index.cjs +1 -1
  28. package/dist/components/navigation/index.js +2 -2
  29. package/dist/components/page/browser.js +1 -1
  30. package/dist/components/page/index.cjs +1 -1
  31. package/dist/components/page/index.js +1 -1
  32. package/dist/components/popover/Popover.d.ts +4 -0
  33. package/dist/components/popover/Popover.d.ts.map +1 -1
  34. package/dist/components/popover/browser.js +1 -1
  35. package/dist/components/popover/index.cjs +1 -1
  36. package/dist/components/popover/index.js +1 -1
  37. package/dist/components/resource-table/browser.js +4 -4
  38. package/dist/components/resource-table/index.cjs +1 -1
  39. package/dist/components/resource-table/index.js +4 -4
  40. package/dist/components/search/browser.js +1 -1
  41. package/dist/components/search/index.cjs +1 -1
  42. package/dist/components/search/index.js +1 -1
  43. package/dist/components/select/browser.js +1 -1
  44. package/dist/components/select/index.cjs +1 -1
  45. package/dist/components/select/index.js +1 -1
  46. package/dist/components/side-navigation/browser.js +1 -1
  47. package/dist/components/side-navigation/index.cjs +1 -1
  48. package/dist/components/side-navigation/index.js +1 -1
  49. package/dist/components/table/browser.js +1 -1
  50. package/dist/components/table/index.cjs +1 -1
  51. package/dist/components/table/index.js +1 -1
  52. package/dist/components/tags/browser.js +1 -1
  53. package/dist/components/tags/index.cjs +1 -1
  54. package/dist/components/tags/index.js +1 -1
  55. package/dist/components/time-picker/browser.js +1 -1
  56. package/dist/components/time-picker/index.cjs +1 -1
  57. package/dist/components/time-picker/index.js +1 -1
  58. package/dist/components/tree/browser.js +1 -1
  59. package/dist/components/tree/index.cjs +1 -1
  60. package/dist/components/tree/index.js +1 -1
  61. package/dist/editor.css +1 -1
  62. package/dist/index.cjs +15 -9
  63. package/dist/index.css +1 -1
  64. package/dist/index.js +566 -208
  65. package/package.json +1 -1
  66. package/dist/components/chunks/popover-2Cnva3AN.js +0 -1
  67. /package/dist/components/chunks/{link-B_fNmwOk.js → link-B4Hdsb2b.js} +0 -0
  68. /package/dist/components/chunks/{link-BxTQfAW9.js → link-rv2WDJw2.js} +0 -0
  69. /package/dist/components/chunks/{search-BXku4V9r.js → search-C3uTkxhf.js} +0 -0
  70. /package/dist/components/chunks/{search-DKHcIR2F.js → search-qSlGRuMR.js} +0 -0
  71. /package/dist/components/chunks/{table-IU2Vmjwk.js → table-BZ73d2Yb.js} +0 -0
  72. /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-DD7uyRXy.js";
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");
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 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>`;
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>${r(e)}</th>`).join("")}</tr></thead><tbody>${e.map((e) => `<tr>${e.map((e) => `<td>${r(e)}</td>`).join("")}</tr>`).join("")}</tbody></table>`;
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>${r(t[2])}</span></li>` : "";
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>${r(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
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>${r(n.replace(/\n/g, " "))}</p>`;
89
+ return `<p>${a(n.replace(/\n/g, " "))}</p>`;
44
90
  }).join("");
45
91
  }
46
- function r(e) {
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 i(e) {
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 a = class extends HTMLElement {
126
+ var s = class extends HTMLElement {
81
127
  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) => {
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, r) {
204
+ attributeChangedCallback(e, t, n) {
159
205
  if (this.isConnected) {
160
206
  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());
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(r || "");
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" ? i(e) : e.innerHTML;
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.preservedContent = 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" ? n(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
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,9 +256,9 @@ var a = class extends HTMLElement {
206
256
  this.selectImage(i), this.emitChange();
207
257
  }
208
258
  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;
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;
212
262
  this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
213
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") || "";
214
264
  this.innerHTML = "";
@@ -240,7 +290,7 @@ var a = class extends HTMLElement {
240
290
  let f = document.createElement("button");
241
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;
242
292
  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>
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>
244
294
  html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
245
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}
246
296
  .editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
@@ -249,17 +299,16 @@ var a = class extends HTMLElement {
249
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}
250
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}
251
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)}
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
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}
254
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}
255
304
  @media(max-width:640px){.editor{padding:.75rem}}
256
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", () => {
257
- !this.isConnected || this.editorFrame !== p || this.bindEditorFrame(i, a);
306
+ !this.isConnected || this.editorFrame !== p || this.bindEditorFrame(r, a);
258
307
  }), this.editorFrame = p;
259
308
  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;
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;
263
312
  let h = document.createElement("div");
264
313
  h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
265
314
  let g = null;
@@ -316,11 +365,11 @@ var a = class extends HTMLElement {
316
365
  e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
317
366
  }
318
367
  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, [
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, [
324
373
  "text",
325
374
  "text-muted",
326
375
  "surface",
@@ -330,19 +379,20 @@ var a = class extends HTMLElement {
330
379
  "focus"
331
380
  ].forEach((e) => {
332
381
  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) => {
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) => {
337
386
  let t = e.target;
338
387
  t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
339
- }), i.addEventListener("paste", (e) => {
388
+ }), r.addEventListener("paste", (e) => {
340
389
  let t = e.clipboardData?.getData("text/html") || "";
341
390
  if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
342
391
  let n = this.sanitizePastedHtml(t);
343
392
  n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
344
- }), i.addEventListener("beforeinput", (e) => {
393
+ }), r.addEventListener("beforeinput", (e) => {
345
394
  let t = e;
395
+ if (this.handleHistoryBeforeInput(t)) return;
346
396
  t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
347
397
  let n = t.shiftKey;
348
398
  if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
@@ -353,7 +403,7 @@ var a = class extends HTMLElement {
353
403
  }
354
404
  }
355
405
  this.applyInlineTypingState(t);
356
- }), i.addEventListener("keyup", (e) => {
406
+ }), r.addEventListener("keyup", (e) => {
357
407
  [
358
408
  "ArrowLeft",
359
409
  "ArrowRight",
@@ -364,15 +414,26 @@ var a = class extends HTMLElement {
364
414
  "PageUp",
365
415
  "PageDown"
366
416
  ].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
367
- }), i.addEventListener("mouseup", () => {
417
+ }), r.addEventListener("mouseup", () => {
368
418
  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) => {
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) => {
370
425
  this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
371
426
  let t = e.target, n = t.closest(".mint-editor-image-frame");
372
427
  n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
373
428
  let r = t.closest("table");
374
- this.selectTable(r), t.closest("a") && e.preventDefault();
375
- }), i.addEventListener("keydown", (e) => {
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) => {
376
437
  if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
377
438
  let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
378
439
  if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
@@ -381,26 +442,26 @@ var a = class extends HTMLElement {
381
442
  }
382
443
  }
383
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"));
384
- }), this.observer && this.observer.observe(i, {
445
+ }), this.observer && this.observer.observe(r, {
385
446
  childList: !0,
386
447
  subtree: !0,
387
448
  characterData: !0
388
- }), this.updateWordCount(), this.updateSelectionUI();
449
+ }), this.updateWordCount(), this.updateSelectionUI(), this.history.length === 0 ? this.resetHistory() : this.updateHistoryButtons();
389
450
  }
390
451
  buildToolbar(e) {
391
452
  let t = (t, n, r, i = e) => {
392
453
  let a = document.createElement("button");
393
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) => {
394
- e.preventDefault(), r();
455
+ e.preventDefault(), this.runHistoryTransaction(r);
395
456
  }), i.append(a), a;
396
457
  }, n = (e, t, n) => {
397
458
  let r = document.createElement("mint-popover");
398
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;
399
460
  }, r = (e, t, n, r) => {
400
461
  let i = this.createMenuOption(t, n);
401
- return i.addEventListener("click", r), e.append(i), i;
462
+ return i.addEventListener("click", () => this.runHistoryTransaction(r)), e.append(i), i;
402
463
  };
403
- t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
464
+ this.undoButton = t("Undo", "undo", () => this.undo()), this.redoButton = t("Redo", "redo", () => this.redo()), this.updateHistoryButtons();
404
465
  let i = document.createElement("button");
405
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`;
406
467
  let a = document.createElement("span");
@@ -540,12 +601,10 @@ var a = class extends HTMLElement {
540
601
  O,
541
602
  k,
542
603
  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);
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);
549
608
  [
550
609
  [
551
610
  "Align left",
@@ -568,50 +627,50 @@ var a = class extends HTMLElement {
568
627
  "justifyFull"
569
628
  ]
570
629
  ].forEach(([e, t, n]) => {
571
- r(N, e, t, () => {
572
- this.command(n), N.close(), this.updateTooltipLabel(M, `Text alignment: ${e}`);
630
+ r(M, e, t, () => {
631
+ this.command(n), M.close(), this.updateTooltipLabel(j, `Text alignment: ${e}`);
573
632
  });
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);
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);
578
637
  [
579
638
  ["Disc", "disc"],
580
639
  ["Circle", "circle"],
581
640
  ["Square", "square"]
582
- ].forEach(([e, t]) => r(I, e, "list", () => {
583
- this.applyListStyle("ul", t), I.close();
641
+ ].forEach(([e, t]) => r(F, e, "list", () => {
642
+ this.applyListStyle("ul", t), F.close();
584
643
  }));
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);
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);
588
647
  [
589
648
  ["Numbers", "decimal"],
590
649
  ["Lowercase letters", "lower-alpha"],
591
650
  ["Uppercase letters", "upper-alpha"],
592
651
  ["Lowercase Roman numerals", "lower-roman"],
593
652
  ["Uppercase Roman numerals", "upper-roman"]
594
- ].forEach(([e, t]) => r(z, e, "numbered-list", () => {
595
- this.applyListStyle("ol", t), z.close();
653
+ ].forEach(([e, t]) => r(R, e, "numbered-list", () => {
654
+ this.applyListStyle("ol", t), R.close();
596
655
  }));
597
- let B = p("Checklist", "checklist", () => this.toggleChecklist());
656
+ let z = p("Checklist", "checklist", () => this.toggleChecklist());
598
657
  f.push([
658
+ N,
599
659
  P,
600
- F,
601
- I
660
+ F
602
661
  ], [
662
+ I,
603
663
  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;
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;
615
674
  }
616
675
  buildColorPopover(e, t, n) {
617
676
  let r = [
@@ -682,7 +741,9 @@ var a = class extends HTMLElement {
682
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();
683
742
  return;
684
743
  }
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();
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();
686
747
  }
687
748
  readFontSize() {
688
749
  let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
@@ -699,58 +760,63 @@ var a = class extends HTMLElement {
699
760
  this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
700
761
  return;
701
762
  }
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();
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();
709
771
  }
710
772
  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;
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();
715
786
  }
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
787
  }
724
788
  applyListStyle(e, t) {
725
789
  if (!this.editor || this.sourceMode) return;
726
790
  this.editor.focus(), this.restoreSelection();
727
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;
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();
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();
734
800
  }
735
801
  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));
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
+ }
751
817
  }
752
- }
753
- this.emitChange(), this.updateSelectionUI();
818
+ this.emitChange();
819
+ }), this.updateSelectionUI());
754
820
  }
755
821
  splitTaskItem(e, t) {
756
822
  if (!this.editor) return;
@@ -803,44 +869,6 @@ var a = class extends HTMLElement {
803
869
  let a = this.selection, o = this.editor.ownerDocument.createRange();
804
870
  o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
805
871
  }
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
872
  updateToolbarOverflow() {
845
873
  let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
846
874
  if (!e || !t || !n) return;
@@ -856,7 +884,9 @@ var a = class extends HTMLElement {
856
884
  t.hidden = n.childElementCount === 0;
857
885
  }
858
886
  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());
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());
860
890
  }
861
891
  icon(e) {
862
892
  let t = document.createElement("mint-icon");
@@ -865,6 +895,48 @@ var a = class extends HTMLElement {
865
895
  setTooltip(e, t) {
866
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()));
867
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
+ }
868
940
  updateTooltipLabel(e, t) {
869
941
  e.setAttribute("data-editor-tooltip", t);
870
942
  let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
@@ -891,8 +963,23 @@ var a = class extends HTMLElement {
891
963
  }), document.body.append(n), this.tooltipPopup = n;
892
964
  }
893
965
  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";
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";
896
983
  }
897
984
  hideTooltip() {
898
985
  this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
@@ -928,7 +1015,9 @@ var a = class extends HTMLElement {
928
1015
  return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
929
1016
  }
930
1017
  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());
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());
932
1021
  }
933
1022
  toggleInline(e) {
934
1023
  if (!this.editor || this.sourceMode) return;
@@ -940,7 +1029,9 @@ var a = class extends HTMLElement {
940
1029
  this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
941
1030
  return;
942
1031
  }
943
- this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
1032
+ this.runHistoryTransaction(() => {
1033
+ this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange();
1034
+ }), this.updateSelectionUI();
944
1035
  }
945
1036
  inlineStateAtSelection(e, t) {
946
1037
  let n = this.selection, r = this.inlineOverrides.get(e);
@@ -1211,24 +1302,7 @@ var a = class extends HTMLElement {
1211
1302
  e.replaceWith(...Array.from(e.childNodes));
1212
1303
  };
1213
1304
  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) => {
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) => {
1232
1306
  let n = e.trim();
1233
1307
  if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
1234
1308
  try {
@@ -1247,7 +1321,17 @@ var a = class extends HTMLElement {
1247
1321
  if (n === "style") {
1248
1322
  let n = o(t.value);
1249
1323
  n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
1250
- } else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
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)) : ([
1251
1335
  "colspan",
1252
1336
  "rowspan",
1253
1337
  "start",
@@ -1257,20 +1341,34 @@ var a = class extends HTMLElement {
1257
1341
  "border",
1258
1342
  "cellpadding",
1259
1343
  "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);
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);
1261
1345
  }
1262
1346
  for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
1263
1347
  return i.innerHTML.trim();
1264
1348
  }
1265
1349
  syncSource() {
1266
1350
  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;
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;
1269
1353
  }
1270
1354
  this.updateWordCount();
1271
1355
  }
1272
- emitChange() {
1273
- this.syncSource();
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() {
1274
1372
  let e = this.value;
1275
1373
  this.dispatchEvent(new CustomEvent("input", {
1276
1374
  bubbles: !0,
@@ -1282,6 +1380,119 @@ var a = class extends HTMLElement {
1282
1380
  detail: { value: e }
1283
1381
  }));
1284
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
+ }
1285
1496
  updateWordCount() {
1286
1497
  if (!this.editor || !this.count) return;
1287
1498
  let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
@@ -1383,21 +1594,158 @@ var a = class extends HTMLElement {
1383
1594
  }
1384
1595
  openLinkModal() {
1385
1596
  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);
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");
1392
1599
  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();
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;
1401
1749
  }
1402
1750
  selectedTable() {
1403
1751
  let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
@@ -1500,9 +1848,9 @@ var a = class extends HTMLElement {
1500
1848
  toggleSource() {
1501
1849
  if (!(!this.editor || !this.source)) {
1502
1850
  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;
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();
1506
1854
  this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
1507
1855
  }
1508
1856
  }
@@ -1531,6 +1879,6 @@ var a = class extends HTMLElement {
1531
1879
  t && this.selectImage(t);
1532
1880
  }
1533
1881
  };
1534
- customElements.get("mint-editor") || e("mint-editor", a);
1882
+ customElements.get("mint-editor") || e("mint-editor", s);
1535
1883
  //#endregion
1536
- export { a as default };
1884
+ export { s as default };