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
@@ -19,46 +19,92 @@ __mintLoadStyle('stack', '../../stack.css')
19
19
  __mintLoadStyle('modal', '../../modal.css')
20
20
  __mintLoadStyle('text', '../../text.css')
21
21
  __mintLoadStyle('input', '../../input.css')
22
+ __mintLoadStyle('select', '../../select.css')
22
23
  __mintLoadStyle('editor', '../../editor.css')
23
24
  import { t as e } from "../chunks/register-element-BFYmIynH.js";
24
25
  import "../chunks/icon-aNwWb0hA.js";
25
26
  import "../chunks/button-THsh4Svz.js";
26
27
  import "../chunks/modal-ss_OTDJJ.js";
27
28
  import "../chunks/input-Bu4xPosP.js";
28
- import "../chunks/popover-DD7uyRXy.js";
29
+ import "../chunks/popover-7-PJT1-5.js";
30
+ import "../chunks/select-hL6gV7mL.js";
29
31
  //#region src/components/editor/Editor.ts
30
32
  function t(e) {
31
33
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");
32
34
  }
33
35
  function n(e) {
36
+ return e.replace(/\r\n?/g, "\n").split("\n").map((e) => e.replace(/[\t ]+$/g, "")).join("\n").trim().replace(/\n{3,}/g, "\n\n");
37
+ }
38
+ function r(e, n) {
39
+ let r = n.createElement("template");
40
+ r.innerHTML = e.trim();
41
+ 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([
42
+ "area",
43
+ "base",
44
+ "br",
45
+ "col",
46
+ "embed",
47
+ "hr",
48
+ "img",
49
+ "input",
50
+ "link",
51
+ "meta",
52
+ "param",
53
+ "source",
54
+ "track",
55
+ "wbr"
56
+ ]), o = (e) => " ".repeat(e), s = (e) => Array.from(e.attributes).map((e) => ` ${e.name}="${t(e.value)}"`).join(""), c = (e) => {
57
+ if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
58
+ if (e.nodeType === Node.COMMENT_NODE) return `<!--${e.nodeValue || ""}-->`;
59
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
60
+ let n = e, r = n.tagName.toLowerCase(), i = `<${r}${s(n)}>`;
61
+ return a.has(r) ? i : `${i}${Array.from(n.childNodes).map(c).join("")}</${r}>`;
62
+ }, l = (e, n) => {
63
+ if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
64
+ if (e.nodeType === Node.COMMENT_NODE) return `${o(n)}<!--${e.nodeValue || ""}-->`;
65
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
66
+ let r = e, u = r.tagName.toLowerCase(), d = `<${u}${s(r)}>`;
67
+ if (a.has(u)) return `${o(n)}${d}`;
68
+ let f = Array.from(r.childNodes);
69
+ 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}>`;
70
+ let p = f.flatMap((e) => {
71
+ if (e.nodeType === Node.TEXT_NODE && !(e.textContent || "").trim()) return [];
72
+ let t = l(e, n + 1);
73
+ return t ? [t] : [];
74
+ });
75
+ return p.length ? `${o(n)}${d}\n${p.join("\n")}\n${o(n)}</${u}>` : `${o(n)}${d}</${u}>`;
76
+ };
77
+ return Array.from(r.content.childNodes).map((e) => l(e, 0)).filter(Boolean).join("\n");
78
+ }
79
+ function i(e) {
34
80
  return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
35
81
  let n = e.trim();
36
82
  if (!n) return "";
37
- let i = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
38
- if (i) return `<pre><code${i[1] ? ` class=\"language-${t(i[1])}\"` : ""}>${t(i[2])}</code></pre>`;
39
- let a = n.match(/^(#{1,6})\s+([\s\S]+)$/);
40
- if (a) return `<h${a[1].length}>${r(a[2])}</h${a[1].length}>`;
41
- if (/^>\s?/.test(n)) return `<blockquote><p>${r(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
83
+ let r = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
84
+ if (r) return `<pre><code${r[1] ? ` class=\"language-${t(r[1])}\"` : ""}>${t(r[2])}</code></pre>`;
85
+ let i = n.match(/^(#{1,6})\s+([\s\S]+)$/);
86
+ if (i) return `<h${i[1].length}>${a(i[2])}</h${i[1].length}>`;
87
+ if (/^>\s?/.test(n)) return `<blockquote><p>${a(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
42
88
  let o = n.split("\n").map((e) => e.trim()).filter(Boolean);
43
89
  if (o.length >= 2 && /^\|?\s*:?-{3,}/.test(o[1]) && o[0].includes("|")) {
44
90
  let e = [o[0], ...o.slice(2)].map((e) => e.replace(/^\|/, "").replace(/\|$/, "").split("|").map((e) => e.trim()));
45
- 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>`;
91
+ 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>`;
46
92
  }
47
93
  if (/^[-*+]\s+\[[ xX]\]\s/.test(n)) return `<ul data-mint-task-list="true">${n.split("\n").map((e) => {
48
94
  let t = e.match(/^[-*+]\s+\[([ xX])\]\s+(.*)$/);
49
- return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${r(t[2])}</span></li>` : "";
95
+ return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${a(t[2])}</span></li>` : "";
50
96
  }).join("")}</ul>`;
51
97
  if (/^([-*+]\s|\d+\.\s)/.test(n)) {
52
98
  let e = n.split("\n"), t = /^\d+\./.test(e[0]);
53
- return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${r(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
99
+ return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${a(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
54
100
  }
55
- return `<p>${r(n.replace(/\n/g, " "))}</p>`;
101
+ return `<p>${a(n.replace(/\n/g, " "))}</p>`;
56
102
  }).join("");
57
103
  }
58
- function r(e) {
104
+ function a(e) {
59
105
  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>");
60
106
  }
61
- function i(e) {
107
+ function o(e) {
62
108
  let t = (e) => {
63
109
  if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
64
110
  if (e.nodeType !== Node.ELEMENT_NODE) return "";
@@ -89,9 +135,9 @@ function i(e) {
89
135
  };
90
136
  return Array.from(e.childNodes).map(t).join("").trim();
91
137
  }
92
- var a = class extends HTMLElement {
138
+ var s = class extends HTMLElement {
93
139
  constructor(...e) {
94
- 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) => {
140
+ 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) => {
95
141
  if (e.button !== 0) return;
96
142
  e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
97
143
  stage: t,
@@ -167,14 +213,14 @@ var a = class extends HTMLElement {
167
213
  let e = this.editor?.ownerDocument.defaultView;
168
214
  e?.removeEventListener("pointermove", this.onGridResizeMove), e?.removeEventListener("pointerup", this.onGridResizeEnd), this.removeStageResizeListeners();
169
215
  }
170
- attributeChangedCallback(e, t, r) {
216
+ attributeChangedCallback(e, t, n) {
171
217
  if (this.isConnected) {
172
218
  if (e === "format") {
173
- 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());
219
+ 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());
174
220
  return;
175
221
  }
176
222
  if (e === "value") {
177
- this.setValue(r || "");
223
+ this.setValue(n || "");
178
224
  return;
179
225
  }
180
226
  e === "height" && (this.editorHeight = null), this.render();
@@ -190,17 +236,21 @@ var a = class extends HTMLElement {
190
236
  if (this.sourceMode && this.source) return this.source.value;
191
237
  if (!this.editor) return "";
192
238
  let e = this.cleanEditorCopy();
193
- return this.format === "markdown" ? i(e) : e.innerHTML;
239
+ return this.format === "markdown" ? o(e) : e.innerHTML;
194
240
  }
195
241
  set value(e) {
196
242
  this.setValue(e || "");
197
243
  }
198
244
  setValue(e) {
199
245
  if (!this.editor) {
200
- this.pendingValue = e, this.preservedContent = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
246
+ this.pendingValue = e, this.preservedContent = e, this.history = [], this.historyIndex = -1, this.updateHistoryButtons(), this.getAttribute("value") !== e && this.setAttribute("value", e);
247
+ return;
248
+ }
249
+ if (this.value === e) {
250
+ this.source && (this.source.value = e), this.updateHistoryButtons();
201
251
  return;
202
252
  }
203
- this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
253
+ this.editor.innerHTML = this.format === "markdown" ? i(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount(), this.resetHistory();
204
254
  }
205
255
  insertResource(e) {
206
256
  let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
@@ -218,9 +268,9 @@ var a = class extends HTMLElement {
218
268
  this.selectImage(i), this.emitChange();
219
269
  }
220
270
  render() {
221
- let e = this.getAttribute("value"), r = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
222
- 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;
223
- let i = this.editor ? r : this.format === "markdown" ? n(r) : r;
271
+ let e = this.getAttribute("value"), n = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
272
+ 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;
273
+ let r = this.editor ? n : this.format === "markdown" ? i(n) : n;
224
274
  this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
225
275
  let a = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", o = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, s = this.getAttribute("label") || "";
226
276
  this.innerHTML = "";
@@ -252,7 +302,7 @@ var a = class extends HTMLElement {
252
302
  let f = document.createElement("button");
253
303
  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;
254
304
  let p = document.createElement("iframe");
255
- 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>
305
+ 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>
256
306
  html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
257
307
  .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}
258
308
  .editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
@@ -261,17 +311,16 @@ var a = class extends HTMLElement {
261
311
  .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}
262
312
  .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}
263
313
  .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)}
264
- .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}
265
314
  .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}
266
315
  .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}
267
316
  @media(max-width:640px){.editor{padding:.75rem}}
268
317
  </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", () => {
269
- !this.isConnected || this.editorFrame !== p || this.bindEditorFrame(i, a);
318
+ !this.isConnected || this.editorFrame !== p || this.bindEditorFrame(r, a);
270
319
  }), this.editorFrame = p;
271
320
  let m = document.createElement("textarea");
272
- 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", () => {
273
- this.editor && (this.editor.innerHTML = this.format === "markdown" ? n(m.value) : m.value), this.updateWordCount(), this.emitChange();
274
- }), this.source = m;
321
+ 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) => {
322
+ this.editor && (this.editor.innerHTML = this.format === "markdown" ? i(m.value) : m.value), this.updateWordCount(), this.emitChange(e.inputType);
323
+ }), m.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), m.addEventListener("beforeinput", (e) => this.handleHistoryBeforeInput(e)), this.source = m;
275
324
  let h = document.createElement("div");
276
325
  h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
277
326
  let g = null;
@@ -328,11 +377,11 @@ var a = class extends HTMLElement {
328
377
  e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
329
378
  }
330
379
  bindEditorFrame(e, t) {
331
- let r = this.editorFrame?.contentDocument, i = r?.querySelector(".editor");
332
- if (!r || !i) return;
333
- i.contentEditable = String(!t), i.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? n(this.pendingValue) : this.pendingValue, this.pendingValue = null;
334
- let a = getComputedStyle(this), o = r.body;
335
- 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, [
380
+ let n = this.editorFrame?.contentDocument, r = n?.querySelector(".editor");
381
+ if (!n || !r) return;
382
+ r.contentEditable = String(!t), r.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? i(this.pendingValue) : this.pendingValue, this.pendingValue = null;
383
+ let a = getComputedStyle(this), o = n.body;
384
+ 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, [
336
385
  "text",
337
386
  "text-muted",
338
387
  "surface",
@@ -342,19 +391,20 @@ var a = class extends HTMLElement {
342
391
  "focus"
343
392
  ].forEach((e) => {
344
393
  let t = a.getPropertyValue(`--mint-color-${e}`).trim();
345
- t && i.style.setProperty(`--mint-color-${e}`, t);
346
- }), this.editor = i, i.addEventListener("input", () => {
347
- this.normalizeTaskListItems(), this.syncSource(), this.emitChange(), this.updateSelectionUI();
348
- }), i.addEventListener("change", (e) => {
394
+ t && r.style.setProperty(`--mint-color-${e}`, t);
395
+ }), this.editor = r, r.addEventListener("input", (e) => {
396
+ this.normalizeTaskListItems(), this.emitChange(e.inputType), this.updateSelectionUI();
397
+ }), r.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), r.addEventListener("change", (e) => {
349
398
  let t = e.target;
350
399
  t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
351
- }), i.addEventListener("paste", (e) => {
400
+ }), r.addEventListener("paste", (e) => {
352
401
  let t = e.clipboardData?.getData("text/html") || "";
353
402
  if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
354
403
  let n = this.sanitizePastedHtml(t);
355
404
  n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
356
- }), i.addEventListener("beforeinput", (e) => {
405
+ }), r.addEventListener("beforeinput", (e) => {
357
406
  let t = e;
407
+ if (this.handleHistoryBeforeInput(t)) return;
358
408
  t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
359
409
  let n = t.shiftKey;
360
410
  if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
@@ -365,7 +415,7 @@ var a = class extends HTMLElement {
365
415
  }
366
416
  }
367
417
  this.applyInlineTypingState(t);
368
- }), i.addEventListener("keyup", (e) => {
418
+ }), r.addEventListener("keyup", (e) => {
369
419
  [
370
420
  "ArrowLeft",
371
421
  "ArrowRight",
@@ -376,15 +426,26 @@ var a = class extends HTMLElement {
376
426
  "PageUp",
377
427
  "PageDown"
378
428
  ].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
379
- }), i.addEventListener("mouseup", () => {
429
+ }), r.addEventListener("mouseup", () => {
380
430
  this.updateSelectedImage(), this.updateSelectionUI();
381
- }), 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) => {
431
+ }), n.addEventListener("selectionchange", () => this.updateSelectionUI()), n.addEventListener("pointerover", (e) => {
432
+ let t = e.target;
433
+ if (!t || t.nodeType !== Node.ELEMENT_NODE) return;
434
+ let n = t.closest("a[href]"), r = e.relatedTarget;
435
+ !n || r && r.nodeType && n.contains(r) || (this.bindEditorLinkTooltip(n), this.showTooltip(n));
436
+ }), r.addEventListener("scroll", () => this.positionTableTools()), r.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), n.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), r.addEventListener("click", (e) => {
382
437
  this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
383
438
  let t = e.target, n = t.closest(".mint-editor-image-frame");
384
439
  n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
385
440
  let r = t.closest("table");
386
- this.selectTable(r), t.closest("a") && e.preventDefault();
387
- }), i.addEventListener("keydown", (e) => {
441
+ this.selectTable(r);
442
+ let i = t.closest("a[href]");
443
+ if (i) if (e.preventDefault(), this.isOpenLinkModifier(e)) this.openEditorLink(i, "new-tab");
444
+ else {
445
+ let e = i.getAttribute("data-mint-editor-open");
446
+ e && e !== "same-tab" && this.openEditorLink(i, e);
447
+ }
448
+ }), r.addEventListener("keydown", (e) => {
388
449
  if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
389
450
  let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
390
451
  if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
@@ -393,26 +454,26 @@ var a = class extends HTMLElement {
393
454
  }
394
455
  }
395
456
  (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"));
396
- }), this.observer && this.observer.observe(i, {
457
+ }), this.observer && this.observer.observe(r, {
397
458
  childList: !0,
398
459
  subtree: !0,
399
460
  characterData: !0
400
- }), this.updateWordCount(), this.updateSelectionUI();
461
+ }), this.updateWordCount(), this.updateSelectionUI(), this.history.length === 0 ? this.resetHistory() : this.updateHistoryButtons();
401
462
  }
402
463
  buildToolbar(e) {
403
464
  let t = (t, n, r, i = e) => {
404
465
  let a = document.createElement("button");
405
466
  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) => {
406
- e.preventDefault(), r();
467
+ e.preventDefault(), this.runHistoryTransaction(r);
407
468
  }), i.append(a), a;
408
469
  }, n = (e, t, n) => {
409
470
  let r = document.createElement("mint-popover");
410
471
  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;
411
472
  }, r = (e, t, n, r) => {
412
473
  let i = this.createMenuOption(t, n);
413
- return i.addEventListener("click", r), e.append(i), i;
474
+ return i.addEventListener("click", () => this.runHistoryTransaction(r)), e.append(i), i;
414
475
  };
415
- t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
476
+ this.undoButton = t("Undo", "undo", () => this.undo()), this.redoButton = t("Redo", "redo", () => this.redo()), this.updateHistoryButtons();
416
477
  let i = document.createElement("button");
417
478
  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`;
418
479
  let a = document.createElement("span");
@@ -552,12 +613,10 @@ var a = class extends HTMLElement {
552
613
  O,
553
614
  k,
554
615
  A
555
- ]);
556
- let j = p("Add comment", "comment-plus", () => this.openCommentModal());
557
- f.push([j]), h();
558
- let M = p("Text alignment", "align-left", () => {});
559
- M.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, M.append(this.icon("caret-down")), this.alignmentTrigger = M;
560
- let N = n(M, "mint-editor-alignment-popover", u);
616
+ ]), h();
617
+ let j = p("Text alignment", "align-left", () => {});
618
+ j.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, j.append(this.icon("caret-down")), this.alignmentTrigger = j;
619
+ let M = n(j, "mint-editor-alignment-popover", u);
561
620
  [
562
621
  [
563
622
  "Align left",
@@ -580,50 +639,50 @@ var a = class extends HTMLElement {
580
639
  "justifyFull"
581
640
  ]
582
641
  ].forEach(([e, t, n]) => {
583
- r(N, e, t, () => {
584
- this.command(n), N.close(), this.updateTooltipLabel(M, `Text alignment: ${e}`);
642
+ r(M, e, t, () => {
643
+ this.command(n), M.close(), this.updateTooltipLabel(j, `Text alignment: ${e}`);
585
644
  });
586
- }), f.push([M, N]), h();
587
- let P = p("Bulleted list", "list", () => this.command("insertUnorderedList")), F = document.createElement("button");
588
- 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);
589
- let I = n(F, "mint-editor-list-popover", u);
645
+ }), f.push([j, M]), h();
646
+ let N = p("Bulleted list", "list", () => this.command("insertUnorderedList")), P = document.createElement("button");
647
+ 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);
648
+ let F = n(P, "mint-editor-list-popover", u);
590
649
  [
591
650
  ["Disc", "disc"],
592
651
  ["Circle", "circle"],
593
652
  ["Square", "square"]
594
- ].forEach(([e, t]) => r(I, e, "list", () => {
595
- this.applyListStyle("ul", t), I.close();
653
+ ].forEach(([e, t]) => r(F, e, "list", () => {
654
+ this.applyListStyle("ul", t), F.close();
596
655
  }));
597
- let L = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), R = document.createElement("button");
598
- 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);
599
- let z = n(R, "mint-editor-list-popover", u);
656
+ let I = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), L = document.createElement("button");
657
+ 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);
658
+ let R = n(L, "mint-editor-list-popover", u);
600
659
  [
601
660
  ["Numbers", "decimal"],
602
661
  ["Lowercase letters", "lower-alpha"],
603
662
  ["Uppercase letters", "upper-alpha"],
604
663
  ["Lowercase Roman numerals", "lower-roman"],
605
664
  ["Uppercase Roman numerals", "upper-roman"]
606
- ].forEach(([e, t]) => r(z, e, "numbered-list", () => {
607
- this.applyListStyle("ol", t), z.close();
665
+ ].forEach(([e, t]) => r(R, e, "numbered-list", () => {
666
+ this.applyListStyle("ol", t), R.close();
608
667
  }));
609
- let B = p("Checklist", "checklist", () => this.toggleChecklist());
668
+ let z = p("Checklist", "checklist", () => this.toggleChecklist());
610
669
  f.push([
670
+ N,
611
671
  P,
612
- F,
613
- I
672
+ F
614
673
  ], [
674
+ I,
615
675
  L,
616
- R,
617
- z
618
- ], [B]), h();
619
- let V = p("HTML source", "code", () => this.toggleSource());
620
- f.push([V]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
621
- let H = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
622
- f.push([H]);
623
- let U = document.createElement("button");
624
- 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"));
625
- let W = document.createElement("mint-popover");
626
- 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;
676
+ R
677
+ ], [z]), h();
678
+ let B = p("HTML source", "code", () => this.toggleSource());
679
+ f.push([B]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
680
+ let V = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
681
+ f.push([V]);
682
+ let H = document.createElement("button");
683
+ 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"));
684
+ let U = document.createElement("mint-popover");
685
+ 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;
627
686
  }
628
687
  buildColorPopover(e, t, n) {
629
688
  let r = [
@@ -694,7 +753,9 @@ var a = class extends HTMLElement {
694
753
  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();
695
754
  return;
696
755
  }
697
- 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();
756
+ this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), this.runHistoryTransaction(() => {
757
+ 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();
758
+ }), this.updateSelectionUI();
698
759
  }
699
760
  readFontSize() {
700
761
  let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
@@ -711,58 +772,63 @@ var a = class extends HTMLElement {
711
772
  this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
712
773
  return;
713
774
  }
714
- this.inlineStyleOverrides.delete("fontSize");
715
- let r = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
716
- n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((e) => {
717
- if (r.has(e)) return;
718
- let i = n.createElement("span");
719
- 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);
720
- }), this.emitChange(), this.updateSelectionUI();
775
+ this.inlineStyleOverrides.delete("fontSize"), this.runHistoryTransaction(() => {
776
+ let e = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
777
+ n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((r) => {
778
+ if (e.has(r)) return;
779
+ let i = n.createElement("span");
780
+ 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);
781
+ }), this.emitChange();
782
+ }), this.updateSelectionUI();
721
783
  }
722
784
  applyFontFamily(e) {
723
- if (!this.editor || this.sourceMode) return;
724
- if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
725
- this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
726
- return;
785
+ if (!(!this.editor || this.sourceMode)) {
786
+ if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
787
+ this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
788
+ return;
789
+ }
790
+ this.inlineStyleOverrides.delete("fontFamily"), this.runHistoryTransaction(() => {
791
+ let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
792
+ t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
793
+ if (n.has(r)) return;
794
+ let i = t.createElement("span");
795
+ i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
796
+ }), this.emitChange();
797
+ }), this.updateSelectionUI();
727
798
  }
728
- this.inlineStyleOverrides.delete("fontFamily");
729
- let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
730
- t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
731
- if (n.has(r)) return;
732
- let i = t.createElement("span");
733
- i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
734
- }), this.emitChange(), this.updateSelectionUI();
735
799
  }
736
800
  applyListStyle(e, t) {
737
801
  if (!this.editor || this.sourceMode) return;
738
802
  this.editor.focus(), this.restoreSelection();
739
803
  let n = this.selection?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest(e), i = r && this.editor.contains(r) ? r : null;
740
- if (!i) {
741
- this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
742
- let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
743
- i = n && this.editor.contains(n) ? n : null;
744
- }
745
- i && (i.style.listStyleType = t), this.emitChange(), this.updateSelectionUI();
804
+ this.runHistoryTransaction(() => {
805
+ if (!i) {
806
+ this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
807
+ let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
808
+ i = n && this.editor.contains(n) ? n : null;
809
+ }
810
+ i && (i.style.listStyleType = t), this.emitChange();
811
+ }), this.updateSelectionUI();
746
812
  }
747
813
  toggleChecklist() {
748
- if (!this.editor || this.sourceMode) return;
749
- this.editor.focus(), this.restoreSelection();
750
- 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");
751
- if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
752
- else {
753
- i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
754
- let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
755
- if (a && this.editor.contains(a)) {
756
- a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
757
- if (t.querySelector("input[type=\"checkbox\"]")) return;
758
- let r = e.createElement("input");
759
- r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
760
- });
761
- let t = a.parentElement;
762
- 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));
814
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
815
+ 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");
816
+ if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
817
+ else {
818
+ i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
819
+ let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
820
+ if (a && this.editor.contains(a)) {
821
+ a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
822
+ if (t.querySelector("input[type=\"checkbox\"]")) return;
823
+ let r = e.createElement("input");
824
+ r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
825
+ });
826
+ let t = a.parentElement;
827
+ 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));
828
+ }
763
829
  }
764
- }
765
- this.emitChange(), this.updateSelectionUI();
830
+ this.emitChange();
831
+ }), this.updateSelectionUI());
766
832
  }
767
833
  splitTaskItem(e, t) {
768
834
  if (!this.editor) return;
@@ -815,44 +881,6 @@ var a = class extends HTMLElement {
815
881
  let a = this.selection, o = this.editor.ownerDocument.createRange();
816
882
  o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
817
883
  }
818
- openCommentModal() {
819
- this.saveSelection();
820
- let e = this._savedRange?.toString() || "", t = document.createElement("mint-modal");
821
- t.setAttribute("heading", "Add comment"), t.setAttribute("size", "small");
822
- let n = document.createElement("div");
823
- n.setAttribute("slot", "body"), n.className = "mint-editor-modal-fields";
824
- let r = document.createElement("p");
825
- 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.";
826
- let i = document.createElement("textarea");
827
- i.className = "mint-editor-comment-input", i.setAttribute("aria-label", "Comment"), i.setAttribute("placeholder", "Write a comment…"), i.rows = 4, n.append(r, i);
828
- let a = document.createElement("div");
829
- a.setAttribute("slot", "actions"), a.className = "mint-editor-modal-actions";
830
- let o = document.createElement("mint-button");
831
- o.textContent = "Cancel", o.setAttribute("variant", "ghost"), this.setTooltip(o, "Cancel"), o.addEventListener("click", () => t.close());
832
- let s = document.createElement("mint-button");
833
- s.textContent = "Add comment", s.setAttribute("tone", "action"), s.toggleAttribute("disabled", !e), this.setTooltip(s, "Add comment"), s.addEventListener("click", () => {
834
- let n = i.value.trim();
835
- !n || !e || (this.insertComment(n, e), t.close());
836
- }), a.append(o, s), t.append(n, a), this.append(t), t.open();
837
- }
838
- insertComment(e, t) {
839
- let n = this._savedRange;
840
- if (this.editor && n && !n.collapsed && this.editor.contains(n.commonAncestorContainer) && this.format === "html") {
841
- let t = this.editor.ownerDocument.createElement("span");
842
- t.className = "mint-editor-comment", t.setAttribute("data-mint-comment", e), t.title = `Comment: ${e}`, t.append(n.extractContents()), n.insertNode(t);
843
- let r = this.selection;
844
- n.selectNodeContents(t), r?.removeAllRanges(), r?.addRange(n);
845
- }
846
- this.dispatchEvent(new CustomEvent("mint-editor-comment-request", {
847
- bubbles: !0,
848
- composed: !0,
849
- detail: {
850
- selectedText: t,
851
- comment: e,
852
- format: this.format
853
- }
854
- })), this.emitChange();
855
- }
856
884
  updateToolbarOverflow() {
857
885
  let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
858
886
  if (!e || !t || !n) return;
@@ -868,7 +896,9 @@ var a = class extends HTMLElement {
868
896
  t.hidden = n.childElementCount === 0;
869
897
  }
870
898
  clearFormatting() {
871
- !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());
899
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
900
+ this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange();
901
+ }), this.updateSelectionUI());
872
902
  }
873
903
  icon(e) {
874
904
  let t = document.createElement("mint-icon");
@@ -877,6 +907,48 @@ var a = class extends HTMLElement {
877
907
  setTooltip(e, t) {
878
908
  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()));
879
909
  }
910
+ linkOpenModifier() {
911
+ let e = navigator.userAgentData?.platform || navigator.platform || "";
912
+ return /mac|iphone|ipad|ipod/i.test(e) ? "⌘" : "Ctrl";
913
+ }
914
+ isOpenLinkModifier(e) {
915
+ return this.linkOpenModifier() === "⌘" ? e.metaKey : e.ctrlKey;
916
+ }
917
+ openEditorLink(e, t) {
918
+ if (t === "same-tab") {
919
+ this.ownerDocument.defaultView?.location.assign(e.href);
920
+ return;
921
+ }
922
+ if (t === "new-tab") {
923
+ window.open(e.href, "_blank", "noopener,noreferrer");
924
+ return;
925
+ }
926
+ let n = t === "popup", r = n ? [
927
+ "popup=yes",
928
+ `width=${this.normalizePopupNumber(e.dataset.mintPopupWidth || "", 200, 4e3, "800")}`,
929
+ `height=${this.normalizePopupNumber(e.dataset.mintPopupHeight || "", 150, 4e3, "600")}`,
930
+ e.dataset.mintPopupLeft ? `left=${this.normalizePopupNumber(e.dataset.mintPopupLeft, 0, 1e4, "")}` : "",
931
+ e.dataset.mintPopupTop ? `top=${this.normalizePopupNumber(e.dataset.mintPopupTop, 0, 1e4, "")}` : "",
932
+ `resizable=${e.dataset.mintPopupResizable === "no" ? "no" : "yes"}`,
933
+ `scrollbars=${e.dataset.mintPopupScrollbars === "no" ? "no" : "yes"}`
934
+ ].filter(Boolean).join(",") : "popup=no", i = n ? "mint-editor-popup" : "mint-editor-window", a = window.open(e.href, i, r);
935
+ if (!a) return;
936
+ try {
937
+ a.opener = null;
938
+ } catch {}
939
+ let o = e.dataset.mintPopupTitle?.trim();
940
+ if (n && o) {
941
+ let e = () => {
942
+ try {
943
+ a.document.title = o;
944
+ } catch {}
945
+ };
946
+ e(), a.addEventListener("load", e, { once: !0 });
947
+ }
948
+ }
949
+ bindEditorLinkTooltip(e) {
950
+ 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()));
951
+ }
880
952
  updateTooltipLabel(e, t) {
881
953
  e.setAttribute("data-editor-tooltip", t);
882
954
  let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
@@ -903,8 +975,23 @@ var a = class extends HTMLElement {
903
975
  }), document.body.append(n), this.tooltipPopup = n;
904
976
  }
905
977
  n.textContent = t, n.setAttribute("aria-hidden", "false"), n.style.visibility = "hidden", n.style.display = "block";
906
- 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);
907
- n.style.left = `${a}px`, n.style.top = `${o}px`, n.style.visibility = "visible";
978
+ let r = e.getBoundingClientRect(), i = {
979
+ left: r.left,
980
+ top: r.top,
981
+ width: r.width,
982
+ bottom: r.bottom
983
+ }, a = e.ownerDocument.defaultView?.frameElement;
984
+ if (a) {
985
+ let e = a.getBoundingClientRect(), t = a.clientWidth ? e.width / a.clientWidth : 1, n = a.clientHeight ? e.height / a.clientHeight : 1;
986
+ i = {
987
+ left: e.left + r.left * t,
988
+ top: e.top + r.top * n,
989
+ width: r.width * t,
990
+ bottom: e.top + r.bottom * n
991
+ };
992
+ }
993
+ 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);
994
+ n.style.left = `${s}px`, n.style.top = `${c}px`, n.style.visibility = "visible";
908
995
  }
909
996
  hideTooltip() {
910
997
  this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
@@ -940,7 +1027,9 @@ var a = class extends HTMLElement {
940
1027
  return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
941
1028
  }
942
1029
  command(e, t) {
943
- !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
1030
+ !this.editor || this.sourceMode || (this.runHistoryTransaction(() => {
1031
+ this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange();
1032
+ }), this.updateSelectionUI());
944
1033
  }
945
1034
  toggleInline(e) {
946
1035
  if (!this.editor || this.sourceMode) return;
@@ -952,7 +1041,9 @@ var a = class extends HTMLElement {
952
1041
  this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
953
1042
  return;
954
1043
  }
955
- this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
1044
+ this.runHistoryTransaction(() => {
1045
+ this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange();
1046
+ }), this.updateSelectionUI();
956
1047
  }
957
1048
  inlineStateAtSelection(e, t) {
958
1049
  let n = this.selection, r = this.inlineOverrides.get(e);
@@ -1223,24 +1314,7 @@ var a = class extends HTMLElement {
1223
1314
  e.replaceWith(...Array.from(e.childNodes));
1224
1315
  };
1225
1316
  for (let e of Array.from(i.querySelectorAll("*"))) e.tagName.includes(":") && l(e);
1226
- let u = new Set([
1227
- "href",
1228
- "src",
1229
- "alt",
1230
- "title",
1231
- "colspan",
1232
- "rowspan",
1233
- "start",
1234
- "value",
1235
- "type",
1236
- "width",
1237
- "height",
1238
- "border",
1239
- "cellpadding",
1240
- "cellspacing",
1241
- "scope",
1242
- "dir"
1243
- ]), d = (e, t = !1) => {
1317
+ 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) => {
1244
1318
  let n = e.trim();
1245
1319
  if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
1246
1320
  try {
@@ -1259,7 +1333,17 @@ var a = class extends HTMLElement {
1259
1333
  if (n === "style") {
1260
1334
  let n = o(t.value);
1261
1335
  n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
1262
- } else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
1336
+ } else if (!u.has(n)) e.removeAttribute(t.name);
1337
+ else if ((n === "href" || n === "src") && !d(t.value, n === "src")) e.removeAttribute(t.name);
1338
+ else if (n === "target" && !/^(_self|_blank|mint-editor-window|mint-editor-popup)$/i.test(t.value.trim())) e.removeAttribute(t.name);
1339
+ else if (n === "rel") {
1340
+ let n = t.value.toLowerCase().split(/\s+/).filter((e) => ["noopener", "noreferrer"].includes(e));
1341
+ n.length ? e.setAttribute("rel", Array.from(new Set(n)).join(" ")) : e.removeAttribute(t.name);
1342
+ } else if (n === "data-mint-editor-open" && !/^(same-tab|new-tab|new-window|popup)$/.test(t.value)) e.removeAttribute(t.name);
1343
+ else if (/^data-mint-popup-(width|height|left|top)$/.test(n)) {
1344
+ let r = Number.parseInt(t.value, 10), i = /width|height/.test(n) ? 150 : 0;
1345
+ !Number.isFinite(r) || r < i || r > 1e4 ? e.removeAttribute(t.name) : e.setAttribute(t.name, String(r));
1346
+ } 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)) : ([
1263
1347
  "colspan",
1264
1348
  "rowspan",
1265
1349
  "start",
@@ -1269,20 +1353,34 @@ var a = class extends HTMLElement {
1269
1353
  "border",
1270
1354
  "cellpadding",
1271
1355
  "cellspacing"
1272
- ].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);
1356
+ ].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);
1273
1357
  }
1274
1358
  for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
1275
1359
  return i.innerHTML.trim();
1276
1360
  }
1277
1361
  syncSource() {
1278
1362
  if (this.source && this.editor) {
1279
- let e = this.cleanEditorCopy();
1280
- this.source.value = this.format === "markdown" ? i(e) : e.innerHTML, this.preservedContent = this.format === "markdown" ? this.source.value : this.editor.innerHTML;
1363
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
1364
+ this.sourceMode || (this.source.value = t), this.preservedContent = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? t : this.editor.innerHTML;
1281
1365
  }
1282
1366
  this.updateWordCount();
1283
1367
  }
1284
- emitChange() {
1285
- this.syncSource();
1368
+ emitChange(e) {
1369
+ if (this.historyTransactionDepth > 0) {
1370
+ this.historyTransactionPending = !0;
1371
+ return;
1372
+ }
1373
+ this.syncSource(), this.applyingHistory || this.recordHistory(e || null), this.dispatchValueEvents();
1374
+ }
1375
+ runHistoryTransaction(e) {
1376
+ this.historyTransactionDepth += 1;
1377
+ try {
1378
+ e();
1379
+ } finally {
1380
+ --this.historyTransactionDepth, this.historyTransactionDepth === 0 && this.historyTransactionPending && (this.historyTransactionPending = !1, this.syncSource(), this.recordHistory(null), this.dispatchValueEvents());
1381
+ }
1382
+ }
1383
+ dispatchValueEvents() {
1286
1384
  let e = this.value;
1287
1385
  this.dispatchEvent(new CustomEvent("input", {
1288
1386
  bubbles: !0,
@@ -1294,6 +1392,119 @@ var a = class extends HTMLElement {
1294
1392
  detail: { value: e }
1295
1393
  }));
1296
1394
  }
1395
+ resetHistory() {
1396
+ this.history = [], this.historyIndex = -1, this.editor && this.recordHistory(null), this.updateHistoryButtons();
1397
+ }
1398
+ refreshCurrentHistorySnapshot() {
1399
+ if (this.historyIndex < 0) return;
1400
+ let e = this.captureHistorySnapshot(null);
1401
+ e && (this.history[this.historyIndex] = e);
1402
+ }
1403
+ captureHistoryPoint(e, t) {
1404
+ let n = this.editor;
1405
+ if (!n || !e || e !== n && !n.contains(e)) return null;
1406
+ let r = [], i = e;
1407
+ for (; i && i !== n;) {
1408
+ let e = i.parentNode;
1409
+ if (!e) return null;
1410
+ r.unshift(Array.prototype.indexOf.call(e.childNodes, i)), i = e;
1411
+ }
1412
+ return i === n ? {
1413
+ path: r,
1414
+ offset: Math.max(0, Math.min(t, e.nodeType === Node.TEXT_NODE ? (e.textContent || "").length : e.childNodes.length))
1415
+ } : null;
1416
+ }
1417
+ resolveHistoryPoint(e) {
1418
+ let t = this.editor;
1419
+ if (!t || !e) return null;
1420
+ let n = t;
1421
+ for (let t of e.path) {
1422
+ let e = n.childNodes[Math.max(0, Math.min(t, n.childNodes.length - 1))];
1423
+ if (!e) break;
1424
+ n = e;
1425
+ }
1426
+ let r = n.nodeType === Node.TEXT_NODE ? (n.textContent || "").length : n.childNodes.length;
1427
+ return {
1428
+ node: n,
1429
+ offset: Math.max(0, Math.min(e.offset, r))
1430
+ };
1431
+ }
1432
+ captureHistorySnapshot(e) {
1433
+ if (!this.editor) return null;
1434
+ let t = this.selection, n = this.sourceMode && this.source ? {
1435
+ start: this.source.selectionStart,
1436
+ end: this.source.selectionEnd,
1437
+ direction: this.source.selectionDirection
1438
+ } : null, r = this.cleanEditorCopy(), i = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? o(r) : r.innerHTML;
1439
+ return {
1440
+ html: r.innerHTML,
1441
+ source: i,
1442
+ anchor: this.captureHistoryPoint(t?.anchorNode || null, t?.anchorOffset || 0),
1443
+ focus: this.captureHistoryPoint(t?.focusNode || null, t?.focusOffset || 0),
1444
+ sourceSelection: n,
1445
+ group: e,
1446
+ time: Date.now()
1447
+ };
1448
+ }
1449
+ recordHistory(e) {
1450
+ if (!this.editor || this.applyingHistory) return;
1451
+ let t = e === "insertText" || e === "insertCompositionText" ? "typing" : e === "deleteContentBackward" || e === "deleteContentForward" || e === "deleteByCut" ? "deleting" : null, n = this.captureHistorySnapshot(t);
1452
+ if (!n) return;
1453
+ if (this.historyIndex < 0) {
1454
+ this.history = [n], this.historyIndex = 0, this.updateHistoryButtons();
1455
+ return;
1456
+ }
1457
+ let r = this.history[this.historyIndex];
1458
+ if (n.html === r.html && n.source === r.source) {
1459
+ n.group = t, this.history[this.historyIndex] = n, this.updateHistoryButtons();
1460
+ return;
1461
+ }
1462
+ 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();
1463
+ }
1464
+ updateHistoryButtons() {
1465
+ let e = this.historyIndex > 0 && this.historyIndex < this.history.length, t = this.historyIndex >= 0 && this.historyIndex < this.history.length - 1;
1466
+ this.undoButton && (this.undoButton.disabled = !e), this.redoButton && (this.redoButton.disabled = !t);
1467
+ }
1468
+ restoreHistorySelection(e) {
1469
+ if (this.sourceMode && this.source && e.sourceSelection) {
1470
+ let t = Math.min(e.sourceSelection.start, this.source.value.length), n = Math.min(e.sourceSelection.end, this.source.value.length);
1471
+ this.source.setSelectionRange(t, n, e.sourceSelection.direction), this.source.focus();
1472
+ return;
1473
+ }
1474
+ let t = this.selection, n = this.resolveHistoryPoint(e.anchor), r = this.resolveHistoryPoint(e.focus);
1475
+ if (!(!t || !n || !r)) if (t.removeAllRanges(), typeof t.setBaseAndExtent == "function") t.setBaseAndExtent(n.node, n.offset, r.node, r.offset);
1476
+ else {
1477
+ let e = this.editor.ownerDocument.createRange();
1478
+ e.setStart(n.node, n.offset), e.setEnd(r.node, r.offset), t.addRange(e);
1479
+ }
1480
+ }
1481
+ applyHistorySnapshot(e) {
1482
+ if (!(!this.editor || !this.source)) {
1483
+ this.applyingHistory = !0;
1484
+ try {
1485
+ this.editor.innerHTML = e.html, this.source.value = e.source, this.editor.querySelectorAll(".mint-editor-image-frame").forEach((e) => {
1486
+ e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.append(this.createResizeHandle());
1487
+ }), 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();
1488
+ } finally {
1489
+ this.applyingHistory = !1;
1490
+ }
1491
+ this.dispatchValueEvents();
1492
+ }
1493
+ }
1494
+ undo() {
1495
+ this.historyIndex <= 0 || (--this.historyIndex, this.applyHistorySnapshot(this.history[this.historyIndex]));
1496
+ }
1497
+ redo() {
1498
+ this.historyIndex >= this.history.length - 1 || (this.historyIndex += 1, this.applyHistorySnapshot(this.history[this.historyIndex]));
1499
+ }
1500
+ handleHistoryKeydown(e) {
1501
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return;
1502
+ let t = e.key.toLowerCase();
1503
+ t === "z" ? (e.preventDefault(), e.shiftKey ? this.redo() : this.undo()) : t === "y" && !e.shiftKey && (e.preventDefault(), this.redo());
1504
+ }
1505
+ handleHistoryBeforeInput(e) {
1506
+ return e.inputType === "historyUndo" ? (e.preventDefault(), this.undo(), !0) : e.inputType === "historyRedo" ? (e.preventDefault(), this.redo(), !0) : !1;
1507
+ }
1297
1508
  updateWordCount() {
1298
1509
  if (!this.editor || !this.count) return;
1299
1510
  let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
@@ -1395,21 +1606,158 @@ var a = class extends HTMLElement {
1395
1606
  }
1396
1607
  openLinkModal() {
1397
1608
  this.saveSelection();
1398
- let e = document.createElement("mint-modal");
1399
- e.setAttribute("heading", "Insert link"), e.setAttribute("size", "small");
1400
- let t = document.createElement("div");
1401
- t.setAttribute("slot", "body");
1402
- let n = document.createElement("mint-input");
1403
- n.setAttribute("type", "url"), n.setAttribute("label", "Link URL"), n.setAttribute("placeholder", "https://example.com"), t.append(n);
1609
+ let e = this._savedRange, t = e && !e.collapsed ? e.toString() : "", n = document.createElement("mint-modal");
1610
+ n.setAttribute("heading", "Insert link"), n.setAttribute("size", "small");
1404
1611
  let r = document.createElement("div");
1405
- r.setAttribute("slot", "actions"), r.className = "mint-editor-modal-actions";
1406
- let i = document.createElement("mint-button");
1407
- i.textContent = "Cancel", i.setAttribute("variant", "ghost"), this.setTooltip(i, "Cancel"), i.addEventListener("click", () => e.close());
1408
- let a = document.createElement("mint-button");
1409
- a.textContent = "Insert link", a.setAttribute("tone", "action"), this.setTooltip(a, "Insert link"), a.addEventListener("click", () => {
1410
- let t = String(n.value || "").trim();
1411
- t && (this.command("createLink", t), e.close());
1412
- }), r.append(i, a), e.append(t, r), this.append(e), e.open();
1612
+ r.setAttribute("slot", "body"), r.className = "mint-editor-modal-fields";
1613
+ let i = document.createElement("mint-input");
1614
+ i.setAttribute("type", "text"), i.setAttribute("label", "Link text"), i.setAttribute("placeholder", "Text to display"), t && i.setAttribute("value", t);
1615
+ let a = document.createElement("mint-input");
1616
+ a.setAttribute("type", "url"), a.setAttribute("label", "Link URL"), a.setAttribute("placeholder", "https://example.com"), r.append(i, a);
1617
+ let o = document.createElement("mint-select");
1618
+ o.className = "mint-editor-link-target", o.setAttribute("label", "Open in"), o.setAttribute("value", "same-tab"), [
1619
+ ["same-tab", "Same tab"],
1620
+ ["new-tab", "New tab"],
1621
+ ["new-window", "New window"],
1622
+ ["popup", "Popup"]
1623
+ ].forEach(([e, t]) => {
1624
+ let n = document.createElement("option");
1625
+ n.value = e, n.textContent = t, o.append(n);
1626
+ }), r.append(o);
1627
+ let s = document.createElement("mint-button");
1628
+ s.className = "mint-editor-link-advanced", s.textContent = "Advanced settings", s.setAttribute("variant", "ghost"), s.setAttribute("aria-expanded", "false"), s.hidden = !0;
1629
+ let c = document.createElement("div");
1630
+ c.className = "mint-editor-popup-settings", c.id = `${this.id || "mint-editor"}-popup-settings`, c.hidden = !0, s.setAttribute("aria-controls", c.id);
1631
+ let l = document.createElement("mint-input");
1632
+ l.setAttribute("type", "text"), l.setAttribute("label", "Window title"), l.setAttribute("placeholder", "Link popup");
1633
+ let u = document.createElement("mint-input");
1634
+ u.setAttribute("type", "number"), u.setAttribute("label", "Width"), u.setAttribute("min", "200"), u.setAttribute("max", "4000"), u.setAttribute("value", "800");
1635
+ let d = document.createElement("mint-input");
1636
+ d.setAttribute("type", "number"), d.setAttribute("label", "Height"), d.setAttribute("min", "150"), d.setAttribute("max", "4000"), d.setAttribute("value", "600");
1637
+ let f = document.createElement("mint-input");
1638
+ f.setAttribute("type", "number"), f.setAttribute("label", "Left position"), f.setAttribute("min", "0"), f.setAttribute("max", "10000"), f.setAttribute("placeholder", "Automatic");
1639
+ let p = document.createElement("mint-input");
1640
+ p.setAttribute("type", "number"), p.setAttribute("label", "Top position"), p.setAttribute("min", "0"), p.setAttribute("max", "10000"), p.setAttribute("placeholder", "Automatic");
1641
+ let m = document.createElement("mint-select");
1642
+ m.setAttribute("label", "Resizable"), m.setAttribute("value", "yes");
1643
+ let h = document.createElement("mint-select");
1644
+ h.setAttribute("label", "Scrollbars"), h.setAttribute("value", "yes"), [
1645
+ [
1646
+ m,
1647
+ "yes",
1648
+ "Yes"
1649
+ ],
1650
+ [
1651
+ m,
1652
+ "no",
1653
+ "No"
1654
+ ],
1655
+ [
1656
+ h,
1657
+ "yes",
1658
+ "Yes"
1659
+ ],
1660
+ [
1661
+ h,
1662
+ "no",
1663
+ "No"
1664
+ ]
1665
+ ].forEach(([e, t, n]) => {
1666
+ let r = document.createElement("option");
1667
+ r.value = String(t), r.textContent = String(n), e.append(r);
1668
+ }), c.append(l, u, d, f, p, m, h), s.addEventListener("click", () => {
1669
+ c.hidden = !c.hidden, s.setAttribute("aria-expanded", String(!c.hidden));
1670
+ }), o.addEventListener("change", (e) => {
1671
+ let t = String(e.detail?.value || o.value);
1672
+ s.hidden = t !== "popup", t !== "popup" && (c.hidden = !0, s.setAttribute("aria-expanded", "false"));
1673
+ }), r.append(s, c);
1674
+ let g = document.createElement("div");
1675
+ g.setAttribute("slot", "actions"), g.className = "mint-editor-modal-actions";
1676
+ let _ = document.createElement("mint-button");
1677
+ _.textContent = "Cancel", _.setAttribute("variant", "ghost"), this.setTooltip(_, "Cancel"), _.addEventListener("click", () => n.close());
1678
+ let v = document.createElement("mint-button");
1679
+ v.textContent = "Insert link", v.setAttribute("tone", "action"), this.setTooltip(v, "Insert link"), v.addEventListener("click", () => {
1680
+ let e = String(a.value || "").trim(), t = String(i.value || ""), r = String(o.value || "same-tab"), s = {
1681
+ title: String(l.value || ""),
1682
+ width: String(u.value || "800"),
1683
+ height: String(d.value || "600"),
1684
+ left: String(f.value || ""),
1685
+ top: String(p.value || ""),
1686
+ resizable: String(m.value || "yes"),
1687
+ scrollbars: String(h.value || "yes")
1688
+ };
1689
+ e && t.trim() && (this.insertLink(e, t, r, s), n.close());
1690
+ }), g.append(_, v), n.append(r, g), this.append(n), n.open();
1691
+ }
1692
+ insertLink(e, t, n, r) {
1693
+ let i = this.editor, a = this._savedRange;
1694
+ if (!i || this.sourceMode || !a || !i.contains(a.commonAncestorContainer)) return;
1695
+ let o = a.collapsed ? "" : a.toString();
1696
+ if (o && o === t) {
1697
+ let t = a.cloneRange();
1698
+ this.runHistoryTransaction(() => {
1699
+ this.command("createLink", e);
1700
+ let a = Array.from(i.querySelectorAll("a[href]")).filter((e) => {
1701
+ try {
1702
+ return t.intersectsNode(e);
1703
+ } catch {
1704
+ return !1;
1705
+ }
1706
+ }), o = this.selection?.anchorNode, s = (o?.nodeType === Node.ELEMENT_NODE ? o : o?.parentElement)?.closest("a[href]");
1707
+ (a.length ? a : s ? [s] : []).forEach((e) => this.configureLinkTarget(e, n, r)), this.emitChange();
1708
+ }), this.updateSelectionUI();
1709
+ return;
1710
+ }
1711
+ this.runHistoryTransaction(() => {
1712
+ i.focus(), this.restoreSelection();
1713
+ let a = this.selection;
1714
+ if (!a?.rangeCount) return;
1715
+ let o = a.getRangeAt(0);
1716
+ if (!i.contains(o.commonAncestorContainer)) return;
1717
+ let s = (e) => {
1718
+ let t = (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest("a[href]");
1719
+ return t && i.contains(t) ? t : null;
1720
+ }, c = s(o.startContainer), l = s(o.endContainer), u, d;
1721
+ if (c && c === l) {
1722
+ if (d = c, o.collapsed) d.textContent = t, u = d;
1723
+ else {
1724
+ o.deleteContents();
1725
+ let e = i.ownerDocument.createTextNode(t);
1726
+ o.insertNode(e), u = e;
1727
+ }
1728
+ d.href = e;
1729
+ } else {
1730
+ d = i.ownerDocument.createElement("a"), d.href = e, o.deleteContents();
1731
+ let n = i.ownerDocument.createTextNode(t);
1732
+ d.append(n), o.insertNode(d), u = d;
1733
+ }
1734
+ this.configureLinkTarget(d, n, r), o.setStartAfter(u), o.collapse(!0), a.removeAllRanges(), a.addRange(o), this.emitChange();
1735
+ }), this.updateSelectionUI();
1736
+ }
1737
+ configureLinkTarget(e, t, n) {
1738
+ e.setAttribute("target", {
1739
+ "same-tab": "_self",
1740
+ "new-tab": "_blank",
1741
+ "new-window": "mint-editor-window",
1742
+ popup: "mint-editor-popup"
1743
+ }[t]), e.setAttribute("data-mint-editor-open", t), t === "same-tab" ? e.removeAttribute("rel") : e.setAttribute("rel", "noopener noreferrer");
1744
+ let r = {
1745
+ "data-mint-popup-title": n.title.trim().slice(0, 120),
1746
+ "data-mint-popup-width": this.normalizePopupNumber(n.width, 200, 4e3, "800"),
1747
+ "data-mint-popup-height": this.normalizePopupNumber(n.height, 150, 4e3, "600"),
1748
+ "data-mint-popup-left": this.normalizePopupNumber(n.left, 0, 1e4, ""),
1749
+ "data-mint-popup-top": this.normalizePopupNumber(n.top, 0, 1e4, ""),
1750
+ "data-mint-popup-resizable": n.resizable === "no" ? "no" : "yes",
1751
+ "data-mint-popup-scrollbars": n.scrollbars === "no" ? "no" : "yes"
1752
+ };
1753
+ Object.entries(r).forEach(([n, r]) => {
1754
+ t === "popup" && r ? e.setAttribute(n, r) : e.removeAttribute(n);
1755
+ });
1756
+ }
1757
+ normalizePopupNumber(e, t, n, r) {
1758
+ if (!e.trim()) return r;
1759
+ let i = Number.parseInt(e, 10);
1760
+ return Number.isFinite(i) ? String(Math.max(t, Math.min(n, i))) : r;
1413
1761
  }
1414
1762
  selectedTable() {
1415
1763
  let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
@@ -1512,9 +1860,9 @@ var a = class extends HTMLElement {
1512
1860
  toggleSource() {
1513
1861
  if (!(!this.editor || !this.source)) {
1514
1862
  if (this.sourceMode = !this.sourceMode, this.clearInlineTypingState(), this.source.hidden = !this.sourceMode, this.editor.hidden = this.sourceMode, this.sourceMode) {
1515
- let e = this.cleanEditorCopy();
1516
- this.source.value = this.format === "markdown" ? i(e) : e.innerHTML;
1517
- } else this.editor.innerHTML = this.format === "markdown" ? n(this.source.value) : this.source.value;
1863
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
1864
+ this.source.value = this.format === "markdown" ? n(t) : r(t, this.editor.ownerDocument), this.refreshCurrentHistorySnapshot(), this.preservedContent = this.source.value, this.dispatchValueEvents();
1865
+ } else this.editor.innerHTML = this.format === "markdown" ? i(this.source.value) : this.source.value, this.syncSource(), this.emitChange();
1518
1866
  this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
1519
1867
  }
1520
1868
  }
@@ -1543,6 +1891,6 @@ var a = class extends HTMLElement {
1543
1891
  t && this.selectImage(t);
1544
1892
  }
1545
1893
  };
1546
- customElements.get("mint-editor") || e("mint-editor", a);
1894
+ customElements.get("mint-editor") || e("mint-editor", s);
1547
1895
  //#endregion
1548
- export { a as default };
1896
+ export { s as default };