monobill-mintui 0.6.737 → 0.6.739

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 (177) hide show
  1. package/bin/component-dependencies.json +2 -1
  2. package/dist/components/alert/browser.js +4 -4
  3. package/dist/components/alert/index.cjs +1 -1
  4. package/dist/components/alert/index.js +4 -4
  5. package/dist/components/back-button/browser.js +1 -1
  6. package/dist/components/back-button/index.cjs +1 -1
  7. package/dist/components/back-button/index.js +1 -1
  8. package/dist/components/bottom-navigation/browser.js +2 -2
  9. package/dist/components/bottom-navigation/index.cjs +1 -1
  10. package/dist/components/bottom-navigation/index.js +2 -2
  11. package/dist/components/button/browser.js +1 -1
  12. package/dist/components/button/index.cjs +1 -1
  13. package/dist/components/button/index.js +1 -1
  14. package/dist/components/checkbox/browser.js +1 -1
  15. package/dist/components/checkbox/index.cjs +1 -1
  16. package/dist/components/checkbox/index.js +1 -1
  17. package/dist/components/chip/browser.js +1 -1
  18. package/dist/components/chip/index.cjs +1 -1
  19. package/dist/components/chip/index.js +1 -1
  20. package/dist/components/chunks/ScrollFade-58GqgRLY.js +1 -0
  21. package/dist/components/chunks/ScrollFade-kpfpO4Zb.js +160 -0
  22. package/dist/components/chunks/{back-button-C_aLMNZE.js → back-button-CQ3ZKGa1.js} +1 -1
  23. package/dist/components/chunks/{back-button-CMZR-p_D.js → back-button-DpPfWpAh.js} +2 -2
  24. package/dist/components/chunks/{button-THsh4Svz.js → button-CIuVIyLf.js} +2 -2
  25. package/dist/components/chunks/{button-CELyLLtj.js → button-CgymemwA.js} +1 -1
  26. package/dist/components/chunks/{caret-down-DUfiCBEs.js → caret-down-CikQdiAu.js} +1 -1
  27. package/dist/components/chunks/caret-down-DZinO2Vg.js +1 -0
  28. package/dist/components/chunks/caret-right-CMZIcNYV.js +1 -0
  29. package/dist/components/chunks/{caret-right-CppgjbLX.js → caret-right-ZvpF7jIK.js} +1 -1
  30. package/dist/components/chunks/{checkbox-d5UlscqI.js → checkbox-98ctQydC.js} +1 -1
  31. package/dist/components/chunks/{checkbox-CZViKLNo.js → checkbox-B8VzPrhn.js} +2 -2
  32. package/dist/components/chunks/{chip-G6SRCgLq.js → chip-Cqm_NPF5.js} +3 -3
  33. package/dist/components/chunks/{chip-DJ_kZURn.js → chip-dVw8BZP7.js} +1 -1
  34. package/dist/components/chunks/{close-ChHICicN.js → close-DtRLefjU.js} +1 -1
  35. package/dist/components/chunks/close-DuS1TdUB.js +1 -0
  36. package/dist/components/chunks/{confirm-action-BSHfjDfA.js → confirm-action-8Yx0K5j1.js} +1 -1
  37. package/dist/components/chunks/{confirm-action-CRZMTjpd.js → confirm-action-C0XX_TyJ.js} +2 -2
  38. package/dist/components/chunks/{date-picker-CTtYAkmM.js → date-picker-BJ_82oRR.js} +1 -1
  39. package/dist/components/chunks/{date-picker-CUf5eJR3.js → date-picker-BuJJ8gvT.js} +5 -5
  40. package/dist/components/chunks/icon-Cmx9FTmb.js +1 -0
  41. package/dist/components/chunks/{icon-1cs-hcBy.js → icon-CuRTWM4k.js} +67 -57
  42. package/dist/components/chunks/icon-pgeP1zxb.js +51 -0
  43. package/dist/components/chunks/icon-rdeLRs-R.js +1 -0
  44. package/dist/components/chunks/{input-Bu4xPosP.js → input-BpcFd35m.js} +3 -3
  45. package/dist/components/chunks/{input-Zqw53jts.js → input-DJaqPjMg.js} +1 -1
  46. package/dist/components/chunks/{modal-CL5EStu0.js → modal-BJtuPK1b.js} +1 -1
  47. package/dist/components/chunks/{modal-ss_OTDJJ.js → modal-BzRle8yT.js} +2 -2
  48. package/dist/components/chunks/{popover-DD7uyRXy.js → popover-BcN2LEbO.js} +15 -3
  49. package/dist/components/chunks/popover-N3cKN8iW.js +1 -0
  50. package/dist/components/chunks/search-DA6dk5kF.js +1 -0
  51. package/dist/components/chunks/{search-DKHcIR2F.js → search-Dw9cb1wC.js} +1 -1
  52. package/dist/components/chunks/{select-CX9oOwl5.js → select-Ctps8gPL.js} +1 -1
  53. package/dist/components/chunks/{select-DOMW7Plx.js → select-DPERiupq.js} +3 -3
  54. package/dist/components/chunks/sortable-Bj0VTUqS.js +1 -0
  55. package/dist/components/chunks/{sortable-CQtdBuGw.js → sortable-DWfdFpgA.js} +59 -22
  56. package/dist/components/chunks/{table-HnSpIfny.js → table-C4xUMQw6.js} +1 -1
  57. package/dist/components/chunks/{table-IU2Vmjwk.js → table-k97RfsAA.js} +1 -1
  58. package/dist/components/chunks/{time-picker-C7pJvGSM.js → time-picker-Bl8KsaJj.js} +3 -3
  59. package/dist/components/chunks/{time-picker-BaoT0NtA.js → time-picker-D74vZTpL.js} +1 -1
  60. package/dist/components/chunks/{warning-gkij2FhS.js → warning-B1-z7ww9.js} +1 -1
  61. package/dist/components/chunks/{warning-Cf8ePVsQ.js → warning-CfJwI6nV.js} +1 -1
  62. package/dist/components/confirm-action/browser.js +1 -1
  63. package/dist/components/confirm-action/index.cjs +1 -1
  64. package/dist/components/confirm-action/index.js +1 -1
  65. package/dist/components/date-picker/browser.js +1 -1
  66. package/dist/components/date-picker/index.cjs +1 -1
  67. package/dist/components/date-picker/index.js +1 -1
  68. package/dist/components/datetime-picker/browser.js +3 -3
  69. package/dist/components/datetime-picker/index.cjs +1 -1
  70. package/dist/components/datetime-picker/index.js +3 -3
  71. package/dist/components/dropzone/browser.js +4 -4
  72. package/dist/components/dropzone/index.cjs +1 -1
  73. package/dist/components/dropzone/index.js +4 -4
  74. package/dist/components/editor/Editor.d.ts +29 -2
  75. package/dist/components/editor/Editor.d.ts.map +1 -1
  76. package/dist/components/editor/browser.js +583 -232
  77. package/dist/components/editor/index.cjs +14 -8
  78. package/dist/components/editor/index.d.ts +2 -0
  79. package/dist/components/editor/index.d.ts.map +1 -1
  80. package/dist/components/editor/index.js +583 -232
  81. package/dist/components/form/Form.d.ts +5 -1
  82. package/dist/components/form/Form.d.ts.map +1 -1
  83. package/dist/components/form/browser.js +52 -40
  84. package/dist/components/form/index.cjs +1 -1
  85. package/dist/components/form/index.js +52 -40
  86. package/dist/components/icon/browser.js +1 -1
  87. package/dist/components/icon/icons/index.d.ts +1 -0
  88. package/dist/components/icon/icons/index.d.ts.map +1 -1
  89. package/dist/components/icon/icons/play.d.ts +3 -0
  90. package/dist/components/icon/icons/play.d.ts.map +1 -0
  91. package/dist/components/icon/index.cjs +1 -1
  92. package/dist/components/icon/index.js +1 -1
  93. package/dist/components/input/browser.js +1 -1
  94. package/dist/components/input/index.cjs +1 -1
  95. package/dist/components/input/index.js +1 -1
  96. package/dist/components/link/browser.js +1 -1
  97. package/dist/components/link/index.cjs +1 -1
  98. package/dist/components/link/index.js +1 -1
  99. package/dist/components/modal/browser.js +1 -1
  100. package/dist/components/modal/index.cjs +1 -1
  101. package/dist/components/modal/index.js +1 -1
  102. package/dist/components/navigation/browser.js +4 -4
  103. package/dist/components/navigation/index.cjs +1 -1
  104. package/dist/components/navigation/index.js +4 -4
  105. package/dist/components/off-canvas/browser.js +2 -2
  106. package/dist/components/off-canvas/index.cjs +1 -1
  107. package/dist/components/off-canvas/index.js +2 -2
  108. package/dist/components/page/browser.js +4 -4
  109. package/dist/components/page/index.cjs +1 -1
  110. package/dist/components/page/index.js +4 -4
  111. package/dist/components/popover/Popover.d.ts +4 -0
  112. package/dist/components/popover/Popover.d.ts.map +1 -1
  113. package/dist/components/popover/browser.js +1 -1
  114. package/dist/components/popover/index.cjs +1 -1
  115. package/dist/components/popover/index.js +1 -1
  116. package/dist/components/resource-table/browser.js +11 -11
  117. package/dist/components/resource-table/index.cjs +1 -1
  118. package/dist/components/resource-table/index.js +11 -11
  119. package/dist/components/scroll-fade/ScrollFade.d.ts.map +1 -1
  120. package/dist/components/scroll-fade/browser.js +1 -1
  121. package/dist/components/scroll-fade/index.cjs +1 -1
  122. package/dist/components/scroll-fade/index.js +1 -1
  123. package/dist/components/search/browser.js +7 -7
  124. package/dist/components/search/index.cjs +1 -1
  125. package/dist/components/search/index.js +7 -7
  126. package/dist/components/select/browser.js +1 -1
  127. package/dist/components/select/index.cjs +1 -1
  128. package/dist/components/select/index.js +1 -1
  129. package/dist/components/side-navigation/browser.js +6 -6
  130. package/dist/components/side-navigation/index.cjs +1 -1
  131. package/dist/components/side-navigation/index.js +6 -6
  132. package/dist/components/sortable/Sortable.d.ts +8 -0
  133. package/dist/components/sortable/Sortable.d.ts.map +1 -1
  134. package/dist/components/sortable/browser.js +1 -1
  135. package/dist/components/sortable/index.cjs +1 -1
  136. package/dist/components/sortable/index.js +1 -1
  137. package/dist/components/switch/browser.js +2 -2
  138. package/dist/components/switch/index.cjs +1 -1
  139. package/dist/components/switch/index.js +2 -2
  140. package/dist/components/table/browser.js +1 -1
  141. package/dist/components/table/index.cjs +1 -1
  142. package/dist/components/table/index.js +1 -1
  143. package/dist/components/tabs/browser.js +1 -1
  144. package/dist/components/tabs/index.cjs +1 -1
  145. package/dist/components/tabs/index.js +1 -1
  146. package/dist/components/tags/Tags.d.ts.map +1 -1
  147. package/dist/components/tags/browser.js +8 -17
  148. package/dist/components/tags/index.cjs +1 -1
  149. package/dist/components/tags/index.js +8 -17
  150. package/dist/components/time-picker/browser.js +1 -1
  151. package/dist/components/time-picker/index.cjs +1 -1
  152. package/dist/components/time-picker/index.js +1 -1
  153. package/dist/components/tree/browser.js +5 -5
  154. package/dist/components/tree/index.cjs +1 -1
  155. package/dist/components/tree/index.js +5 -5
  156. package/dist/editor.css +1 -1
  157. package/dist/icons/play.svg +3 -0
  158. package/dist/index.cjs +19 -13
  159. package/dist/index.css +3 -3
  160. package/dist/index.js +1080 -595
  161. package/dist/navigation-search.json +8 -1
  162. package/dist/scroll-fade.css +1 -1
  163. package/dist/tags.css +1 -1
  164. package/package.json +1 -1
  165. package/dist/components/chunks/ScrollFade-DOnPtfC2.js +0 -85
  166. package/dist/components/chunks/ScrollFade-FBvsnQ1i.js +0 -1
  167. package/dist/components/chunks/caret-down-BiAVkpX7.js +0 -1
  168. package/dist/components/chunks/caret-right-8n-rhz51.js +0 -1
  169. package/dist/components/chunks/close-CuYimzX0.js +0 -1
  170. package/dist/components/chunks/icon-Bv1J3LwC.js +0 -51
  171. package/dist/components/chunks/icon-C-6HOPtI.js +0 -1
  172. package/dist/components/chunks/icon-aNwWb0hA.js +0 -1
  173. package/dist/components/chunks/popover-2Cnva3AN.js +0 -1
  174. package/dist/components/chunks/search-BXku4V9r.js +0 -1
  175. package/dist/components/chunks/sortable-Brecvk9d.js +0 -1
  176. /package/dist/components/chunks/{link-B_fNmwOk.js → link-B4Hdsb2b.js} +0 -0
  177. /package/dist/components/chunks/{link-BxTQfAW9.js → link-rv2WDJw2.js} +0 -0
@@ -7,46 +7,93 @@ 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
- import "../chunks/icon-aNwWb0hA.js";
13
- import "../chunks/button-THsh4Svz.js";
14
- import "../chunks/modal-ss_OTDJJ.js";
15
- import "../chunks/input-Bu4xPosP.js";
16
- import "../chunks/popover-DD7uyRXy.js";
13
+ import "../chunks/icon-Cmx9FTmb.js";
14
+ import "../chunks/button-CIuVIyLf.js";
15
+ import "../chunks/modal-BzRle8yT.js";
16
+ import "../chunks/input-BpcFd35m.js";
17
+ import "../chunks/popover-BcN2LEbO.js";
18
+ import "../scroll-fade/index.js";
19
+ import "../chunks/select-DPERiupq.js";
17
20
  //#region src/components/editor/Editor.ts
18
21
  function t(e) {
19
22
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");
20
23
  }
21
24
  function n(e) {
25
+ return e.replace(/\r\n?/g, "\n").split("\n").map((e) => e.replace(/[\t ]+$/g, "")).join("\n").trim().replace(/\n{3,}/g, "\n\n");
26
+ }
27
+ function r(e, n) {
28
+ let r = n.createElement("template");
29
+ r.innerHTML = e.trim();
30
+ 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([
31
+ "area",
32
+ "base",
33
+ "br",
34
+ "col",
35
+ "embed",
36
+ "hr",
37
+ "img",
38
+ "input",
39
+ "link",
40
+ "meta",
41
+ "param",
42
+ "source",
43
+ "track",
44
+ "wbr"
45
+ ]), o = (e) => " ".repeat(e), s = (e) => Array.from(e.attributes).map((e) => ` ${e.name}="${t(e.value)}"`).join(""), c = (e) => {
46
+ if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
47
+ if (e.nodeType === Node.COMMENT_NODE) return `<!--${e.nodeValue || ""}-->`;
48
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
49
+ let n = e, r = n.tagName.toLowerCase(), i = `<${r}${s(n)}>`;
50
+ return a.has(r) ? i : `${i}${Array.from(n.childNodes).map(c).join("")}</${r}>`;
51
+ }, l = (e, n) => {
52
+ if (e.nodeType === Node.TEXT_NODE) return t(e.textContent || "");
53
+ if (e.nodeType === Node.COMMENT_NODE) return `${o(n)}<!--${e.nodeValue || ""}-->`;
54
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
55
+ let r = e, u = r.tagName.toLowerCase(), d = `<${u}${s(r)}>`;
56
+ if (a.has(u)) return `${o(n)}${d}`;
57
+ let f = Array.from(r.childNodes);
58
+ 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}>`;
59
+ let p = f.flatMap((e) => {
60
+ if (e.nodeType === Node.TEXT_NODE && !(e.textContent || "").trim()) return [];
61
+ let t = l(e, n + 1);
62
+ return t ? [t] : [];
63
+ });
64
+ return p.length ? `${o(n)}${d}\n${p.join("\n")}\n${o(n)}</${u}>` : `${o(n)}${d}</${u}>`;
65
+ };
66
+ return Array.from(r.content.childNodes).map((e) => l(e, 0)).filter(Boolean).join("\n");
67
+ }
68
+ function i(e) {
22
69
  return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
23
70
  let n = e.trim();
24
71
  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>`;
72
+ let r = n.match(/^```(\w*)\n([\s\S]*?)\n```$/);
73
+ if (r) return `<pre><code${r[1] ? ` class=\"language-${t(r[1])}\"` : ""}>${t(r[2])}</code></pre>`;
74
+ let i = n.match(/^(#{1,6})\s+([\s\S]+)$/);
75
+ if (i) return `<h${i[1].length}>${a(i[2])}</h${i[1].length}>`;
76
+ if (/^>\s?/.test(n)) return `<blockquote><p>${a(n.replace(/^>\s?/gm, "").replace(/\n/g, " "))}</p></blockquote>`;
30
77
  let o = n.split("\n").map((e) => e.trim()).filter(Boolean);
31
78
  if (o.length >= 2 && /^\|?\s*:?-{3,}/.test(o[1]) && o[0].includes("|")) {
32
79
  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>`;
80
+ 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
81
  }
35
82
  if (/^[-*+]\s+\[[ xX]\]\s/.test(n)) return `<ul data-mint-task-list="true">${n.split("\n").map((e) => {
36
83
  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>` : "";
84
+ return t ? `<li><input type="checkbox"${t[1].toLowerCase() === "x" ? " checked" : ""} contenteditable="false"><span>${a(t[2])}</span></li>` : "";
38
85
  }).join("")}</ul>`;
39
86
  if (/^([-*+]\s|\d+\.\s)/.test(n)) {
40
87
  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"}>`;
88
+ return `<${t ? "ol" : "ul"}>${e.map((e) => `<li>${a(e.replace(/^(?:[-*+]\s|\d+\.\s)/, ""))}</li>`).join("")}</${t ? "ol" : "ul"}>`;
42
89
  }
43
- return `<p>${r(n.replace(/\n/g, " "))}</p>`;
90
+ return `<p>${a(n.replace(/\n/g, " "))}</p>`;
44
91
  }).join("");
45
92
  }
46
- function r(e) {
93
+ function a(e) {
47
94
  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
95
  }
49
- function i(e) {
96
+ function o(e) {
50
97
  let t = (e) => {
51
98
  if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
52
99
  if (e.nodeType !== Node.ELEMENT_NODE) return "";
@@ -77,9 +124,9 @@ function i(e) {
77
124
  };
78
125
  return Array.from(e.childNodes).map(t).join("").trim();
79
126
  }
80
- var a = class extends HTMLElement {
127
+ var s = class extends HTMLElement {
81
128
  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) => {
129
+ 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
130
  if (e.button !== 0) return;
84
131
  e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
85
132
  stage: t,
@@ -155,14 +202,14 @@ var a = class extends HTMLElement {
155
202
  let e = this.editor?.ownerDocument.defaultView;
156
203
  e?.removeEventListener("pointermove", this.onGridResizeMove), e?.removeEventListener("pointerup", this.onGridResizeEnd), this.removeStageResizeListeners();
157
204
  }
158
- attributeChangedCallback(e, t, r) {
205
+ attributeChangedCallback(e, t, n) {
159
206
  if (this.isConnected) {
160
207
  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());
208
+ 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
209
  return;
163
210
  }
164
211
  if (e === "value") {
165
- this.setValue(r || "");
212
+ this.setValue(n || "");
166
213
  return;
167
214
  }
168
215
  e === "height" && (this.editorHeight = null), this.render();
@@ -178,17 +225,21 @@ var a = class extends HTMLElement {
178
225
  if (this.sourceMode && this.source) return this.source.value;
179
226
  if (!this.editor) return "";
180
227
  let e = this.cleanEditorCopy();
181
- return this.format === "markdown" ? i(e) : e.innerHTML;
228
+ return this.format === "markdown" ? o(e) : e.innerHTML;
182
229
  }
183
230
  set value(e) {
184
231
  this.setValue(e || "");
185
232
  }
186
233
  setValue(e) {
187
234
  if (!this.editor) {
188
- this.pendingValue = e, this.preservedContent = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
235
+ this.pendingValue = e, this.preservedContent = e, this.history = [], this.historyIndex = -1, this.updateHistoryButtons(), this.getAttribute("value") !== e && this.setAttribute("value", e);
236
+ return;
237
+ }
238
+ if (this.value === e) {
239
+ this.source && (this.source.value = e), this.updateHistoryButtons();
189
240
  return;
190
241
  }
191
- this.editor.innerHTML = this.format === "markdown" ? n(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
242
+ 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
243
  }
193
244
  insertResource(e) {
194
245
  let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
@@ -206,9 +257,9 @@ var a = class extends HTMLElement {
206
257
  this.selectImage(i), this.emitChange();
207
258
  }
208
259
  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;
260
+ let e = this.getAttribute("value"), n = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
261
+ 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;
262
+ let r = this.editor ? n : this.format === "markdown" ? i(n) : n;
212
263
  this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
213
264
  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
265
  this.innerHTML = "";
@@ -240,7 +291,7 @@ var a = class extends HTMLElement {
240
291
  let f = document.createElement("button");
241
292
  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
293
  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>
294
+ 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
295
  html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
245
296
  .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
297
  .editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
@@ -249,17 +300,16 @@ var a = class extends HTMLElement {
249
300
  .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
301
  .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
302
  .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
303
  .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
304
  .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
305
  @media(max-width:640px){.editor{padding:.75rem}}
256
306
  </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);
307
+ !this.isConnected || this.editorFrame !== p || this.bindEditorFrame(r, a);
258
308
  }), this.editorFrame = p;
259
309
  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;
310
+ 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) => {
311
+ this.editor && (this.editor.innerHTML = this.format === "markdown" ? i(m.value) : m.value), this.updateWordCount(), this.emitChange(e.inputType);
312
+ }), m.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), m.addEventListener("beforeinput", (e) => this.handleHistoryBeforeInput(e)), this.source = m;
263
313
  let h = document.createElement("div");
264
314
  h.className = "mint-editor-stage", h.style.height = o, h.append(p, m);
265
315
  let g = null;
@@ -316,11 +366,11 @@ var a = class extends HTMLElement {
316
366
  e?.removeEventListener("pointermove", this.onStageResizeMove), e?.removeEventListener("pointerup", this.onStageResizeEnd), e?.removeEventListener("pointercancel", this.onStageResizeEnd), this.stageResizeState = null;
317
367
  }
318
368
  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, [
369
+ let n = this.editorFrame?.contentDocument, r = n?.querySelector(".editor");
370
+ if (!n || !r) return;
371
+ r.contentEditable = String(!t), r.innerHTML = this.pendingValue === null ? e : this.format === "markdown" ? i(this.pendingValue) : this.pendingValue, this.pendingValue = null;
372
+ let a = getComputedStyle(this), o = n.body;
373
+ 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
374
  "text",
325
375
  "text-muted",
326
376
  "surface",
@@ -330,19 +380,20 @@ var a = class extends HTMLElement {
330
380
  "focus"
331
381
  ].forEach((e) => {
332
382
  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) => {
383
+ t && r.style.setProperty(`--mint-color-${e}`, t);
384
+ }), this.editor = r, r.addEventListener("input", (e) => {
385
+ this.normalizeTaskListItems(), this.emitChange(e.inputType), this.updateSelectionUI();
386
+ }), r.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), r.addEventListener("change", (e) => {
337
387
  let t = e.target;
338
388
  t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
339
- }), i.addEventListener("paste", (e) => {
389
+ }), r.addEventListener("paste", (e) => {
340
390
  let t = e.clipboardData?.getData("text/html") || "";
341
391
  if (!t || !this.editor?.contains(this.selection?.anchorNode || null)) return;
342
392
  let n = this.sanitizePastedHtml(t);
343
393
  n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
344
- }), i.addEventListener("beforeinput", (e) => {
394
+ }), r.addEventListener("beforeinput", (e) => {
345
395
  let t = e;
396
+ if (this.handleHistoryBeforeInput(t)) return;
346
397
  t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
347
398
  let n = t.shiftKey;
348
399
  if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
@@ -353,7 +404,7 @@ var a = class extends HTMLElement {
353
404
  }
354
405
  }
355
406
  this.applyInlineTypingState(t);
356
- }), i.addEventListener("keyup", (e) => {
407
+ }), r.addEventListener("keyup", (e) => {
357
408
  [
358
409
  "ArrowLeft",
359
410
  "ArrowRight",
@@ -364,15 +415,26 @@ var a = class extends HTMLElement {
364
415
  "PageUp",
365
416
  "PageDown"
366
417
  ].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
367
- }), i.addEventListener("mouseup", () => {
418
+ }), r.addEventListener("mouseup", () => {
368
419
  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) => {
420
+ }), n.addEventListener("selectionchange", () => this.updateSelectionUI()), n.addEventListener("pointerover", (e) => {
421
+ let t = e.target;
422
+ if (!t || t.nodeType !== Node.ELEMENT_NODE) return;
423
+ let n = t.closest("a[href]"), r = e.relatedTarget;
424
+ !n || r && r.nodeType && n.contains(r) || (this.bindEditorLinkTooltip(n), this.showTooltip(n));
425
+ }), 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
426
  this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
371
427
  let t = e.target, n = t.closest(".mint-editor-image-frame");
372
428
  n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
373
429
  let r = t.closest("table");
374
- this.selectTable(r), t.closest("a") && e.preventDefault();
375
- }), i.addEventListener("keydown", (e) => {
430
+ this.selectTable(r);
431
+ let i = t.closest("a[href]");
432
+ if (i) if (e.preventDefault(), this.isOpenLinkModifier(e)) this.openEditorLink(i, "new-tab");
433
+ else {
434
+ let e = i.getAttribute("data-mint-editor-open");
435
+ e && e !== "same-tab" && this.openEditorLink(i, e);
436
+ }
437
+ }), r.addEventListener("keydown", (e) => {
376
438
  if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
377
439
  let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
378
440
  if (t?.isCollapsed && r && i?.tagName === "UL" && i.hasAttribute("data-mint-task-list") && this.editor?.contains(r)) {
@@ -381,26 +443,26 @@ var a = class extends HTMLElement {
381
443
  }
382
444
  }
383
445
  (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, {
446
+ }), this.observer && this.observer.observe(r, {
385
447
  childList: !0,
386
448
  subtree: !0,
387
449
  characterData: !0
388
- }), this.updateWordCount(), this.updateSelectionUI();
450
+ }), this.updateWordCount(), this.updateSelectionUI(), this.history.length === 0 ? this.resetHistory() : this.updateHistoryButtons();
389
451
  }
390
452
  buildToolbar(e) {
391
453
  let t = (t, n, r, i = e) => {
392
454
  let a = document.createElement("button");
393
455
  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();
456
+ e.preventDefault(), this.runHistoryTransaction(r);
395
457
  }), i.append(a), a;
396
458
  }, n = (e, t, n) => {
397
459
  let r = document.createElement("mint-popover");
398
460
  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
461
  }, r = (e, t, n, r) => {
400
462
  let i = this.createMenuOption(t, n);
401
- return i.addEventListener("click", r), e.append(i), i;
463
+ return i.addEventListener("click", () => this.runHistoryTransaction(r)), e.append(i), i;
402
464
  };
403
- t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
465
+ this.undoButton = t("Undo", "undo", () => this.undo()), this.redoButton = t("Redo", "redo", () => this.redo()), this.updateHistoryButtons();
404
466
  let i = document.createElement("button");
405
467
  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
468
  let a = document.createElement("span");
@@ -451,7 +513,9 @@ var a = class extends HTMLElement {
451
513
  l.textContent = "16px", c.append(l, this.icon("caret-down")), c.addEventListener("pointerdown", () => this.saveSelection()), s.append(c), t("Increase font size", "plus", () => this.applyFontSize(this.readFontSize() + 1), s), this.fontSizeDisplay = l;
452
514
  let u = document.createElement("div");
453
515
  u.className = "mint-editor-toolbar-actions", e.append(u), u.append(s);
454
- let d = n(c, "mint-editor-font-size-popover", u), f = [[s, d]];
516
+ let d = n(c, "mint-editor-font-size-popover", u), f = document.createElement("mint-scroll-fade");
517
+ f.className = "mint-editor-font-size-options", f.setAttribute("axis", "vertical"), f.setAttribute("fade-size", "1rem"), d.append(f);
518
+ let p = [[s, d]];
455
519
  [
456
520
  8,
457
521
  9,
@@ -472,44 +536,44 @@ var a = class extends HTMLElement {
472
536
  let t = document.createElement("button");
473
537
  t.type = "button", t.className = "mint-editor-menu-option mint-editor-font-size-option", t.textContent = `${e}px`, t.addEventListener("click", () => {
474
538
  this.applyFontSize(e), d.close();
475
- }), d.append(t);
539
+ }), f.append(t);
476
540
  });
477
- let p = (e, n, r) => {
541
+ let m = (e, n, r) => {
478
542
  let i = t(e, n, r, u);
479
543
  return [
480
544
  "bold",
481
545
  "italic",
482
546
  "underline"
483
547
  ].includes(n) && (i.setAttribute("aria-pressed", "false"), this.inlineButtons.set(n, i)), i;
484
- }, m = (e) => {
548
+ }, h = (e) => {
485
549
  let t = e.querySelector(":scope > mint-icon");
486
550
  if (!t) return;
487
551
  let n = document.createElement("span");
488
552
  n.className = "mint-editor-color-icon", e.insertBefore(n, t), n.append(t);
489
- }, h = () => {
553
+ }, g = () => {
490
554
  let e = this.separator();
491
- return u.append(e), f.push([e]), e;
492
- }, g = p("Bold", "bold", () => this.toggleInline("bold")), _ = p("Italic", "italic", () => this.toggleInline("italic")), v = p("Underline", "underline", () => this.toggleInline("underline"));
493
- f.push([g], [_], [v]);
494
- let y = this.separator();
495
- u.append(y);
496
- let b = p("Text color", "text-color", () => {});
497
- b.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-text-color-trigger`, b.append(this.icon("caret-down")), b.classList.add("mint-editor-color-trigger"), m(b), b.style.setProperty("--editor-color", this.lastTextColor);
498
- let x = n(b, "mint-editor-color-popover", u);
499
- this.buildColorPopover(x, "text", b), this.colorTriggers.set("text", b);
500
- let S = p("Highlight color", "highlight", () => {});
501
- S.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-highlight-trigger`, S.append(this.icon("caret-down")), S.classList.add("mint-editor-color-trigger"), m(S), S.style.setProperty("--editor-color", this.lastBackgroundColor);
502
- let C = n(S, "mint-editor-color-popover", u);
503
- this.buildColorPopover(C, "background", S), this.colorTriggers.set("background", S), f.push([
504
- y,
555
+ return u.append(e), p.push([e]), e;
556
+ }, _ = m("Bold", "bold", () => this.toggleInline("bold")), v = m("Italic", "italic", () => this.toggleInline("italic")), y = m("Underline", "underline", () => this.toggleInline("underline"));
557
+ p.push([_], [v], [y]);
558
+ let b = this.separator();
559
+ u.append(b);
560
+ let x = m("Text color", "text-color", () => {});
561
+ x.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-text-color-trigger`, x.append(this.icon("caret-down")), x.classList.add("mint-editor-color-trigger"), h(x), x.style.setProperty("--editor-color", this.lastTextColor);
562
+ let S = n(x, "mint-editor-color-popover", u);
563
+ this.buildColorPopover(S, "text", x), this.colorTriggers.set("text", x);
564
+ let C = m("Highlight color", "highlight", () => {});
565
+ C.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-highlight-trigger`, C.append(this.icon("caret-down")), C.classList.add("mint-editor-color-trigger"), h(C), C.style.setProperty("--editor-color", this.lastBackgroundColor);
566
+ let w = n(C, "mint-editor-color-popover", u);
567
+ this.buildColorPopover(w, "background", C), this.colorTriggers.set("background", C), p.push([
505
568
  b,
506
569
  x,
507
570
  S,
508
- C
571
+ C,
572
+ w
509
573
  ]);
510
- let w = p("Font family", "font-family", () => {});
511
- w.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`, w.append(this.icon("caret-down"));
512
- let T = n(w, "mint-editor-font-family-popover", u);
574
+ let T = m("Font family", "font-family", () => {});
575
+ T.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-font-family-trigger`, T.append(this.icon("caret-down"));
576
+ let E = n(T, "mint-editor-font-family-popover", u);
513
577
  [
514
578
  ["Arial", "Arial, sans-serif"],
515
579
  ["Helvetica", "Helvetica, sans-serif"],
@@ -518,14 +582,14 @@ var a = class extends HTMLElement {
518
582
  ["Courier New", "\"Courier New\", monospace"],
519
583
  ["System UI", "system-ui, sans-serif"]
520
584
  ].forEach(([e, t]) => {
521
- r(T, e, "font-family", () => {
522
- this.applyFontFamily(t), T.close();
585
+ r(E, e, "font-family", () => {
586
+ this.applyFontFamily(t), E.close();
523
587
  });
524
- }), f.push([w, T]), h();
525
- let E = p("Insert link", "link", () => this.openLinkModal()), D = p("Insert image", "image", () => this.requestResource()), O = p("Insert table", "table", () => this.openTableModal()), k = document.createElement("button");
526
- k.type = "button", k.className = "mint-editor-tool-button", this.setTooltip(k, "Table options"), k.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, k.append(this.icon("caret-down")), k.hidden = !0, u.append(k);
527
- let A = n(k, "", u);
528
- this.tablePopover = A, [
588
+ }), p.push([T, E]), g();
589
+ let D = m("Insert link", "link", () => this.openLinkModal()), O = m("Insert image", "image", () => this.requestResource()), k = m("Insert table", "table", () => this.openTableModal()), A = document.createElement("button");
590
+ A.type = "button", A.className = "mint-editor-tool-button", this.setTooltip(A, "Table options"), A.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, A.append(this.icon("caret-down")), A.hidden = !0, u.append(A);
591
+ let j = n(A, "", u);
592
+ this.tablePopover = j, [
529
593
  ["Add row below", "table-row"],
530
594
  ["Add column right", "table-column"],
531
595
  ["Delete row", "table-row-delete"],
@@ -534,16 +598,14 @@ var a = class extends HTMLElement {
534
598
  ].forEach(([e, t]) => {
535
599
  let n = this.createMenuOption(e, t);
536
600
  n.addEventListener("click", () => {
537
- this.applyTableAction(e), A.close();
538
- }), A.append(n);
539
- }), k.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = k, f.push([E], [D], [
540
- O,
601
+ this.applyTableAction(e), j.close();
602
+ }), j.append(n);
603
+ }), A.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = A, p.push([D], [O], [
541
604
  k,
542
- A
543
- ]);
544
- let j = p("Add comment", "comment-plus", () => this.openCommentModal());
545
- f.push([j]), h();
546
- let M = p("Text alignment", "align-left", () => {});
605
+ A,
606
+ j
607
+ ]), g();
608
+ let M = m("Text alignment", "align-left", () => {});
547
609
  M.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, M.append(this.icon("caret-down")), this.alignmentTrigger = M;
548
610
  let N = n(M, "mint-editor-alignment-popover", u);
549
611
  [
@@ -571,8 +633,8 @@ var a = class extends HTMLElement {
571
633
  r(N, e, t, () => {
572
634
  this.command(n), N.close(), this.updateTooltipLabel(M, `Text alignment: ${e}`);
573
635
  });
574
- }), f.push([M, N]), h();
575
- let P = p("Bulleted list", "list", () => this.command("insertUnorderedList")), F = document.createElement("button");
636
+ }), p.push([M, N]), g();
637
+ let P = m("Bulleted list", "list", () => this.command("insertUnorderedList")), F = document.createElement("button");
576
638
  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
639
  let I = n(F, "mint-editor-list-popover", u);
578
640
  [
@@ -582,7 +644,7 @@ var a = class extends HTMLElement {
582
644
  ].forEach(([e, t]) => r(I, e, "list", () => {
583
645
  this.applyListStyle("ul", t), I.close();
584
646
  }));
585
- let L = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), R = document.createElement("button");
647
+ let L = m("Numbered list", "numbered-list", () => this.command("insertOrderedList")), R = document.createElement("button");
586
648
  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
649
  let z = n(R, "mint-editor-list-popover", u);
588
650
  [
@@ -594,8 +656,8 @@ var a = class extends HTMLElement {
594
656
  ].forEach(([e, t]) => r(z, e, "numbered-list", () => {
595
657
  this.applyListStyle("ol", t), z.close();
596
658
  }));
597
- let B = p("Checklist", "checklist", () => this.toggleChecklist());
598
- f.push([
659
+ let B = m("Checklist", "checklist", () => this.toggleChecklist());
660
+ p.push([
599
661
  P,
600
662
  F,
601
663
  I
@@ -603,15 +665,15 @@ var a = class extends HTMLElement {
603
665
  L,
604
666
  R,
605
667
  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]);
668
+ ], [B]), g();
669
+ let V = m("HTML source", "code", () => this.toggleSource());
670
+ p.push([V]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
671
+ let H = m("Clear formatting", "clear-formatting", () => this.clearFormatting());
672
+ p.push([H]);
611
673
  let U = document.createElement("button");
612
674
  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
675
  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;
676
+ 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 = p;
615
677
  }
616
678
  buildColorPopover(e, t, n) {
617
679
  let r = [
@@ -682,7 +744,9 @@ var a = class extends HTMLElement {
682
744
  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
745
  return;
684
746
  }
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();
747
+ this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), this.runHistoryTransaction(() => {
748
+ 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();
749
+ }), this.updateSelectionUI();
686
750
  }
687
751
  readFontSize() {
688
752
  let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
@@ -699,58 +763,63 @@ var a = class extends HTMLElement {
699
763
  this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
700
764
  return;
701
765
  }
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();
766
+ this.inlineStyleOverrides.delete("fontSize"), this.runHistoryTransaction(() => {
767
+ let e = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
768
+ n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((r) => {
769
+ if (e.has(r)) return;
770
+ let i = n.createElement("span");
771
+ 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);
772
+ }), this.emitChange();
773
+ }), this.updateSelectionUI();
709
774
  }
710
775
  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;
776
+ if (!(!this.editor || this.sourceMode)) {
777
+ if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
778
+ this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
779
+ return;
780
+ }
781
+ this.inlineStyleOverrides.delete("fontFamily"), this.runHistoryTransaction(() => {
782
+ let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
783
+ t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
784
+ if (n.has(r)) return;
785
+ let i = t.createElement("span");
786
+ i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
787
+ }), this.emitChange();
788
+ }), this.updateSelectionUI();
715
789
  }
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
790
  }
724
791
  applyListStyle(e, t) {
725
792
  if (!this.editor || this.sourceMode) return;
726
793
  this.editor.focus(), this.restoreSelection();
727
794
  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();
795
+ this.runHistoryTransaction(() => {
796
+ if (!i) {
797
+ this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
798
+ let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
799
+ i = n && this.editor.contains(n) ? n : null;
800
+ }
801
+ i && (i.style.listStyleType = t), this.emitChange();
802
+ }), this.updateSelectionUI();
734
803
  }
735
804
  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));
805
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
806
+ 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");
807
+ if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
808
+ else {
809
+ i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
810
+ let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
811
+ if (a && this.editor.contains(a)) {
812
+ a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
813
+ if (t.querySelector("input[type=\"checkbox\"]")) return;
814
+ let r = e.createElement("input");
815
+ r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
816
+ });
817
+ let t = a.parentElement;
818
+ 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));
819
+ }
751
820
  }
752
- }
753
- this.emitChange(), this.updateSelectionUI();
821
+ this.emitChange();
822
+ }), this.updateSelectionUI());
754
823
  }
755
824
  splitTaskItem(e, t) {
756
825
  if (!this.editor) return;
@@ -803,44 +872,6 @@ var a = class extends HTMLElement {
803
872
  let a = this.selection, o = this.editor.ownerDocument.createRange();
804
873
  o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
805
874
  }
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
875
  updateToolbarOverflow() {
845
876
  let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
846
877
  if (!e || !t || !n) return;
@@ -856,7 +887,9 @@ var a = class extends HTMLElement {
856
887
  t.hidden = n.childElementCount === 0;
857
888
  }
858
889
  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());
890
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
891
+ this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange();
892
+ }), this.updateSelectionUI());
860
893
  }
861
894
  icon(e) {
862
895
  let t = document.createElement("mint-icon");
@@ -865,6 +898,48 @@ var a = class extends HTMLElement {
865
898
  setTooltip(e, t) {
866
899
  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
900
  }
901
+ linkOpenModifier() {
902
+ let e = navigator.userAgentData?.platform || navigator.platform || "";
903
+ return /mac|iphone|ipad|ipod/i.test(e) ? "⌘" : "Ctrl";
904
+ }
905
+ isOpenLinkModifier(e) {
906
+ return this.linkOpenModifier() === "⌘" ? e.metaKey : e.ctrlKey;
907
+ }
908
+ openEditorLink(e, t) {
909
+ if (t === "same-tab") {
910
+ this.ownerDocument.defaultView?.location.assign(e.href);
911
+ return;
912
+ }
913
+ if (t === "new-tab") {
914
+ window.open(e.href, "_blank", "noopener,noreferrer");
915
+ return;
916
+ }
917
+ let n = t === "popup", r = n ? [
918
+ "popup=yes",
919
+ `width=${this.normalizePopupNumber(e.dataset.mintPopupWidth || "", 200, 4e3, "800")}`,
920
+ `height=${this.normalizePopupNumber(e.dataset.mintPopupHeight || "", 150, 4e3, "600")}`,
921
+ e.dataset.mintPopupLeft ? `left=${this.normalizePopupNumber(e.dataset.mintPopupLeft, 0, 1e4, "")}` : "",
922
+ e.dataset.mintPopupTop ? `top=${this.normalizePopupNumber(e.dataset.mintPopupTop, 0, 1e4, "")}` : "",
923
+ `resizable=${e.dataset.mintPopupResizable === "no" ? "no" : "yes"}`,
924
+ `scrollbars=${e.dataset.mintPopupScrollbars === "no" ? "no" : "yes"}`
925
+ ].filter(Boolean).join(",") : "popup=no", i = n ? "mint-editor-popup" : "mint-editor-window", a = window.open(e.href, i, r);
926
+ if (!a) return;
927
+ try {
928
+ a.opener = null;
929
+ } catch {}
930
+ let o = e.dataset.mintPopupTitle?.trim();
931
+ if (n && o) {
932
+ let e = () => {
933
+ try {
934
+ a.document.title = o;
935
+ } catch {}
936
+ };
937
+ e(), a.addEventListener("load", e, { once: !0 });
938
+ }
939
+ }
940
+ bindEditorLinkTooltip(e) {
941
+ 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()));
942
+ }
868
943
  updateTooltipLabel(e, t) {
869
944
  e.setAttribute("data-editor-tooltip", t);
870
945
  let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
@@ -891,8 +966,23 @@ var a = class extends HTMLElement {
891
966
  }), document.body.append(n), this.tooltipPopup = n;
892
967
  }
893
968
  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";
969
+ let r = e.getBoundingClientRect(), i = {
970
+ left: r.left,
971
+ top: r.top,
972
+ width: r.width,
973
+ bottom: r.bottom
974
+ }, a = e.ownerDocument.defaultView?.frameElement;
975
+ if (a) {
976
+ let e = a.getBoundingClientRect(), t = a.clientWidth ? e.width / a.clientWidth : 1, n = a.clientHeight ? e.height / a.clientHeight : 1;
977
+ i = {
978
+ left: e.left + r.left * t,
979
+ top: e.top + r.top * n,
980
+ width: r.width * t,
981
+ bottom: e.top + r.bottom * n
982
+ };
983
+ }
984
+ 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);
985
+ n.style.left = `${s}px`, n.style.top = `${c}px`, n.style.visibility = "visible";
896
986
  }
897
987
  hideTooltip() {
898
988
  this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
@@ -928,7 +1018,9 @@ var a = class extends HTMLElement {
928
1018
  return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
929
1019
  }
930
1020
  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());
1021
+ !this.editor || this.sourceMode || (this.runHistoryTransaction(() => {
1022
+ this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange();
1023
+ }), this.updateSelectionUI());
932
1024
  }
933
1025
  toggleInline(e) {
934
1026
  if (!this.editor || this.sourceMode) return;
@@ -940,7 +1032,9 @@ var a = class extends HTMLElement {
940
1032
  this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
941
1033
  return;
942
1034
  }
943
- this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
1035
+ this.runHistoryTransaction(() => {
1036
+ this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange();
1037
+ }), this.updateSelectionUI();
944
1038
  }
945
1039
  inlineStateAtSelection(e, t) {
946
1040
  let n = this.selection, r = this.inlineOverrides.get(e);
@@ -1211,24 +1305,7 @@ var a = class extends HTMLElement {
1211
1305
  e.replaceWith(...Array.from(e.childNodes));
1212
1306
  };
1213
1307
  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) => {
1308
+ 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
1309
  let n = e.trim();
1233
1310
  if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
1234
1311
  try {
@@ -1247,7 +1324,17 @@ var a = class extends HTMLElement {
1247
1324
  if (n === "style") {
1248
1325
  let n = o(t.value);
1249
1326
  n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
1250
- } else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
1327
+ } else if (!u.has(n)) e.removeAttribute(t.name);
1328
+ else if ((n === "href" || n === "src") && !d(t.value, n === "src")) e.removeAttribute(t.name);
1329
+ else if (n === "target" && !/^(_self|_blank|mint-editor-window|mint-editor-popup)$/i.test(t.value.trim())) e.removeAttribute(t.name);
1330
+ else if (n === "rel") {
1331
+ let n = t.value.toLowerCase().split(/\s+/).filter((e) => ["noopener", "noreferrer"].includes(e));
1332
+ n.length ? e.setAttribute("rel", Array.from(new Set(n)).join(" ")) : e.removeAttribute(t.name);
1333
+ } else if (n === "data-mint-editor-open" && !/^(same-tab|new-tab|new-window|popup)$/.test(t.value)) e.removeAttribute(t.name);
1334
+ else if (/^data-mint-popup-(width|height|left|top)$/.test(n)) {
1335
+ let r = Number.parseInt(t.value, 10), i = /width|height/.test(n) ? 150 : 0;
1336
+ !Number.isFinite(r) || r < i || r > 1e4 ? e.removeAttribute(t.name) : e.setAttribute(t.name, String(r));
1337
+ } 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
1338
  "colspan",
1252
1339
  "rowspan",
1253
1340
  "start",
@@ -1257,20 +1344,34 @@ var a = class extends HTMLElement {
1257
1344
  "border",
1258
1345
  "cellpadding",
1259
1346
  "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);
1347
+ ].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
1348
  }
1262
1349
  for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
1263
1350
  return i.innerHTML.trim();
1264
1351
  }
1265
1352
  syncSource() {
1266
1353
  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;
1354
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
1355
+ this.sourceMode || (this.source.value = t), this.preservedContent = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? t : this.editor.innerHTML;
1269
1356
  }
1270
1357
  this.updateWordCount();
1271
1358
  }
1272
- emitChange() {
1273
- this.syncSource();
1359
+ emitChange(e) {
1360
+ if (this.historyTransactionDepth > 0) {
1361
+ this.historyTransactionPending = !0;
1362
+ return;
1363
+ }
1364
+ this.syncSource(), this.applyingHistory || this.recordHistory(e || null), this.dispatchValueEvents();
1365
+ }
1366
+ runHistoryTransaction(e) {
1367
+ this.historyTransactionDepth += 1;
1368
+ try {
1369
+ e();
1370
+ } finally {
1371
+ --this.historyTransactionDepth, this.historyTransactionDepth === 0 && this.historyTransactionPending && (this.historyTransactionPending = !1, this.syncSource(), this.recordHistory(null), this.dispatchValueEvents());
1372
+ }
1373
+ }
1374
+ dispatchValueEvents() {
1274
1375
  let e = this.value;
1275
1376
  this.dispatchEvent(new CustomEvent("input", {
1276
1377
  bubbles: !0,
@@ -1282,6 +1383,119 @@ var a = class extends HTMLElement {
1282
1383
  detail: { value: e }
1283
1384
  }));
1284
1385
  }
1386
+ resetHistory() {
1387
+ this.history = [], this.historyIndex = -1, this.editor && this.recordHistory(null), this.updateHistoryButtons();
1388
+ }
1389
+ refreshCurrentHistorySnapshot() {
1390
+ if (this.historyIndex < 0) return;
1391
+ let e = this.captureHistorySnapshot(null);
1392
+ e && (this.history[this.historyIndex] = e);
1393
+ }
1394
+ captureHistoryPoint(e, t) {
1395
+ let n = this.editor;
1396
+ if (!n || !e || e !== n && !n.contains(e)) return null;
1397
+ let r = [], i = e;
1398
+ for (; i && i !== n;) {
1399
+ let e = i.parentNode;
1400
+ if (!e) return null;
1401
+ r.unshift(Array.prototype.indexOf.call(e.childNodes, i)), i = e;
1402
+ }
1403
+ return i === n ? {
1404
+ path: r,
1405
+ offset: Math.max(0, Math.min(t, e.nodeType === Node.TEXT_NODE ? (e.textContent || "").length : e.childNodes.length))
1406
+ } : null;
1407
+ }
1408
+ resolveHistoryPoint(e) {
1409
+ let t = this.editor;
1410
+ if (!t || !e) return null;
1411
+ let n = t;
1412
+ for (let t of e.path) {
1413
+ let e = n.childNodes[Math.max(0, Math.min(t, n.childNodes.length - 1))];
1414
+ if (!e) break;
1415
+ n = e;
1416
+ }
1417
+ let r = n.nodeType === Node.TEXT_NODE ? (n.textContent || "").length : n.childNodes.length;
1418
+ return {
1419
+ node: n,
1420
+ offset: Math.max(0, Math.min(e.offset, r))
1421
+ };
1422
+ }
1423
+ captureHistorySnapshot(e) {
1424
+ if (!this.editor) return null;
1425
+ let t = this.selection, n = this.sourceMode && this.source ? {
1426
+ start: this.source.selectionStart,
1427
+ end: this.source.selectionEnd,
1428
+ direction: this.source.selectionDirection
1429
+ } : null, r = this.cleanEditorCopy(), i = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? o(r) : r.innerHTML;
1430
+ return {
1431
+ html: r.innerHTML,
1432
+ source: i,
1433
+ anchor: this.captureHistoryPoint(t?.anchorNode || null, t?.anchorOffset || 0),
1434
+ focus: this.captureHistoryPoint(t?.focusNode || null, t?.focusOffset || 0),
1435
+ sourceSelection: n,
1436
+ group: e,
1437
+ time: Date.now()
1438
+ };
1439
+ }
1440
+ recordHistory(e) {
1441
+ if (!this.editor || this.applyingHistory) return;
1442
+ let t = e === "insertText" || e === "insertCompositionText" ? "typing" : e === "deleteContentBackward" || e === "deleteContentForward" || e === "deleteByCut" ? "deleting" : null, n = this.captureHistorySnapshot(t);
1443
+ if (!n) return;
1444
+ if (this.historyIndex < 0) {
1445
+ this.history = [n], this.historyIndex = 0, this.updateHistoryButtons();
1446
+ return;
1447
+ }
1448
+ let r = this.history[this.historyIndex];
1449
+ if (n.html === r.html && n.source === r.source) {
1450
+ n.group = t, this.history[this.historyIndex] = n, this.updateHistoryButtons();
1451
+ return;
1452
+ }
1453
+ 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();
1454
+ }
1455
+ updateHistoryButtons() {
1456
+ let e = this.historyIndex > 0 && this.historyIndex < this.history.length, t = this.historyIndex >= 0 && this.historyIndex < this.history.length - 1;
1457
+ this.undoButton && (this.undoButton.disabled = !e), this.redoButton && (this.redoButton.disabled = !t);
1458
+ }
1459
+ restoreHistorySelection(e) {
1460
+ if (this.sourceMode && this.source && e.sourceSelection) {
1461
+ let t = Math.min(e.sourceSelection.start, this.source.value.length), n = Math.min(e.sourceSelection.end, this.source.value.length);
1462
+ this.source.setSelectionRange(t, n, e.sourceSelection.direction), this.source.focus();
1463
+ return;
1464
+ }
1465
+ let t = this.selection, n = this.resolveHistoryPoint(e.anchor), r = this.resolveHistoryPoint(e.focus);
1466
+ if (!(!t || !n || !r)) if (t.removeAllRanges(), typeof t.setBaseAndExtent == "function") t.setBaseAndExtent(n.node, n.offset, r.node, r.offset);
1467
+ else {
1468
+ let e = this.editor.ownerDocument.createRange();
1469
+ e.setStart(n.node, n.offset), e.setEnd(r.node, r.offset), t.addRange(e);
1470
+ }
1471
+ }
1472
+ applyHistorySnapshot(e) {
1473
+ if (!(!this.editor || !this.source)) {
1474
+ this.applyingHistory = !0;
1475
+ try {
1476
+ this.editor.innerHTML = e.html, this.source.value = e.source, this.editor.querySelectorAll(".mint-editor-image-frame").forEach((e) => {
1477
+ e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.append(this.createResizeHandle());
1478
+ }), 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();
1479
+ } finally {
1480
+ this.applyingHistory = !1;
1481
+ }
1482
+ this.dispatchValueEvents();
1483
+ }
1484
+ }
1485
+ undo() {
1486
+ this.historyIndex <= 0 || (--this.historyIndex, this.applyHistorySnapshot(this.history[this.historyIndex]));
1487
+ }
1488
+ redo() {
1489
+ this.historyIndex >= this.history.length - 1 || (this.historyIndex += 1, this.applyHistorySnapshot(this.history[this.historyIndex]));
1490
+ }
1491
+ handleHistoryKeydown(e) {
1492
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return;
1493
+ let t = e.key.toLowerCase();
1494
+ t === "z" ? (e.preventDefault(), e.shiftKey ? this.redo() : this.undo()) : t === "y" && !e.shiftKey && (e.preventDefault(), this.redo());
1495
+ }
1496
+ handleHistoryBeforeInput(e) {
1497
+ return e.inputType === "historyUndo" ? (e.preventDefault(), this.undo(), !0) : e.inputType === "historyRedo" ? (e.preventDefault(), this.redo(), !0) : !1;
1498
+ }
1285
1499
  updateWordCount() {
1286
1500
  if (!this.editor || !this.count) return;
1287
1501
  let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
@@ -1383,21 +1597,158 @@ var a = class extends HTMLElement {
1383
1597
  }
1384
1598
  openLinkModal() {
1385
1599
  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);
1600
+ let e = this._savedRange, t = e && !e.collapsed ? e.toString() : "", n = document.createElement("mint-modal");
1601
+ n.setAttribute("heading", "Insert link"), n.setAttribute("size", "small");
1392
1602
  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();
1603
+ r.setAttribute("slot", "body"), r.className = "mint-editor-modal-fields";
1604
+ let i = document.createElement("mint-input");
1605
+ i.setAttribute("type", "text"), i.setAttribute("label", "Link text"), i.setAttribute("placeholder", "Text to display"), t && i.setAttribute("value", t);
1606
+ let a = document.createElement("mint-input");
1607
+ a.setAttribute("type", "url"), a.setAttribute("label", "Link URL"), a.setAttribute("placeholder", "https://example.com"), r.append(i, a);
1608
+ let o = document.createElement("mint-select");
1609
+ o.className = "mint-editor-link-target", o.setAttribute("label", "Open in"), o.setAttribute("value", "same-tab"), [
1610
+ ["same-tab", "Same tab"],
1611
+ ["new-tab", "New tab"],
1612
+ ["new-window", "New window"],
1613
+ ["popup", "Popup"]
1614
+ ].forEach(([e, t]) => {
1615
+ let n = document.createElement("option");
1616
+ n.value = e, n.textContent = t, o.append(n);
1617
+ }), r.append(o);
1618
+ let s = document.createElement("mint-button");
1619
+ s.className = "mint-editor-link-advanced", s.textContent = "Advanced settings", s.setAttribute("variant", "ghost"), s.setAttribute("aria-expanded", "false"), s.hidden = !0;
1620
+ let c = document.createElement("div");
1621
+ c.className = "mint-editor-popup-settings", c.id = `${this.id || "mint-editor"}-popup-settings`, c.hidden = !0, s.setAttribute("aria-controls", c.id);
1622
+ let l = document.createElement("mint-input");
1623
+ l.setAttribute("type", "text"), l.setAttribute("label", "Window title"), l.setAttribute("placeholder", "Link popup");
1624
+ let u = document.createElement("mint-input");
1625
+ u.setAttribute("type", "number"), u.setAttribute("label", "Width"), u.setAttribute("min", "200"), u.setAttribute("max", "4000"), u.setAttribute("value", "800");
1626
+ let d = document.createElement("mint-input");
1627
+ d.setAttribute("type", "number"), d.setAttribute("label", "Height"), d.setAttribute("min", "150"), d.setAttribute("max", "4000"), d.setAttribute("value", "600");
1628
+ let f = document.createElement("mint-input");
1629
+ f.setAttribute("type", "number"), f.setAttribute("label", "Left position"), f.setAttribute("min", "0"), f.setAttribute("max", "10000"), f.setAttribute("placeholder", "Automatic");
1630
+ let p = document.createElement("mint-input");
1631
+ p.setAttribute("type", "number"), p.setAttribute("label", "Top position"), p.setAttribute("min", "0"), p.setAttribute("max", "10000"), p.setAttribute("placeholder", "Automatic");
1632
+ let m = document.createElement("mint-select");
1633
+ m.setAttribute("label", "Resizable"), m.setAttribute("value", "yes");
1634
+ let h = document.createElement("mint-select");
1635
+ h.setAttribute("label", "Scrollbars"), h.setAttribute("value", "yes"), [
1636
+ [
1637
+ m,
1638
+ "yes",
1639
+ "Yes"
1640
+ ],
1641
+ [
1642
+ m,
1643
+ "no",
1644
+ "No"
1645
+ ],
1646
+ [
1647
+ h,
1648
+ "yes",
1649
+ "Yes"
1650
+ ],
1651
+ [
1652
+ h,
1653
+ "no",
1654
+ "No"
1655
+ ]
1656
+ ].forEach(([e, t, n]) => {
1657
+ let r = document.createElement("option");
1658
+ r.value = String(t), r.textContent = String(n), e.append(r);
1659
+ }), c.append(l, u, d, f, p, m, h), s.addEventListener("click", () => {
1660
+ c.hidden = !c.hidden, s.setAttribute("aria-expanded", String(!c.hidden));
1661
+ }), o.addEventListener("change", (e) => {
1662
+ let t = String(e.detail?.value || o.value);
1663
+ s.hidden = t !== "popup", t !== "popup" && (c.hidden = !0, s.setAttribute("aria-expanded", "false"));
1664
+ }), r.append(s, c);
1665
+ let g = document.createElement("div");
1666
+ g.setAttribute("slot", "actions"), g.className = "mint-editor-modal-actions";
1667
+ let _ = document.createElement("mint-button");
1668
+ _.textContent = "Cancel", _.setAttribute("variant", "ghost"), this.setTooltip(_, "Cancel"), _.addEventListener("click", () => n.close());
1669
+ let v = document.createElement("mint-button");
1670
+ v.textContent = "Insert link", v.setAttribute("tone", "action"), this.setTooltip(v, "Insert link"), v.addEventListener("click", () => {
1671
+ let e = String(a.value || "").trim(), t = String(i.value || ""), r = String(o.value || "same-tab"), s = {
1672
+ title: String(l.value || ""),
1673
+ width: String(u.value || "800"),
1674
+ height: String(d.value || "600"),
1675
+ left: String(f.value || ""),
1676
+ top: String(p.value || ""),
1677
+ resizable: String(m.value || "yes"),
1678
+ scrollbars: String(h.value || "yes")
1679
+ };
1680
+ e && t.trim() && (this.insertLink(e, t, r, s), n.close());
1681
+ }), g.append(_, v), n.append(r, g), this.append(n), n.open();
1682
+ }
1683
+ insertLink(e, t, n, r) {
1684
+ let i = this.editor, a = this._savedRange;
1685
+ if (!i || this.sourceMode || !a || !i.contains(a.commonAncestorContainer)) return;
1686
+ let o = a.collapsed ? "" : a.toString();
1687
+ if (o && o === t) {
1688
+ let t = a.cloneRange();
1689
+ this.runHistoryTransaction(() => {
1690
+ this.command("createLink", e);
1691
+ let a = Array.from(i.querySelectorAll("a[href]")).filter((e) => {
1692
+ try {
1693
+ return t.intersectsNode(e);
1694
+ } catch {
1695
+ return !1;
1696
+ }
1697
+ }), o = this.selection?.anchorNode, s = (o?.nodeType === Node.ELEMENT_NODE ? o : o?.parentElement)?.closest("a[href]");
1698
+ (a.length ? a : s ? [s] : []).forEach((e) => this.configureLinkTarget(e, n, r)), this.emitChange();
1699
+ }), this.updateSelectionUI();
1700
+ return;
1701
+ }
1702
+ this.runHistoryTransaction(() => {
1703
+ i.focus(), this.restoreSelection();
1704
+ let a = this.selection;
1705
+ if (!a?.rangeCount) return;
1706
+ let o = a.getRangeAt(0);
1707
+ if (!i.contains(o.commonAncestorContainer)) return;
1708
+ let s = (e) => {
1709
+ let t = (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest("a[href]");
1710
+ return t && i.contains(t) ? t : null;
1711
+ }, c = s(o.startContainer), l = s(o.endContainer), u, d;
1712
+ if (c && c === l) {
1713
+ if (d = c, o.collapsed) d.textContent = t, u = d;
1714
+ else {
1715
+ o.deleteContents();
1716
+ let e = i.ownerDocument.createTextNode(t);
1717
+ o.insertNode(e), u = e;
1718
+ }
1719
+ d.href = e;
1720
+ } else {
1721
+ d = i.ownerDocument.createElement("a"), d.href = e, o.deleteContents();
1722
+ let n = i.ownerDocument.createTextNode(t);
1723
+ d.append(n), o.insertNode(d), u = d;
1724
+ }
1725
+ this.configureLinkTarget(d, n, r), o.setStartAfter(u), o.collapse(!0), a.removeAllRanges(), a.addRange(o), this.emitChange();
1726
+ }), this.updateSelectionUI();
1727
+ }
1728
+ configureLinkTarget(e, t, n) {
1729
+ e.setAttribute("target", {
1730
+ "same-tab": "_self",
1731
+ "new-tab": "_blank",
1732
+ "new-window": "mint-editor-window",
1733
+ popup: "mint-editor-popup"
1734
+ }[t]), e.setAttribute("data-mint-editor-open", t), t === "same-tab" ? e.removeAttribute("rel") : e.setAttribute("rel", "noopener noreferrer");
1735
+ let r = {
1736
+ "data-mint-popup-title": n.title.trim().slice(0, 120),
1737
+ "data-mint-popup-width": this.normalizePopupNumber(n.width, 200, 4e3, "800"),
1738
+ "data-mint-popup-height": this.normalizePopupNumber(n.height, 150, 4e3, "600"),
1739
+ "data-mint-popup-left": this.normalizePopupNumber(n.left, 0, 1e4, ""),
1740
+ "data-mint-popup-top": this.normalizePopupNumber(n.top, 0, 1e4, ""),
1741
+ "data-mint-popup-resizable": n.resizable === "no" ? "no" : "yes",
1742
+ "data-mint-popup-scrollbars": n.scrollbars === "no" ? "no" : "yes"
1743
+ };
1744
+ Object.entries(r).forEach(([n, r]) => {
1745
+ t === "popup" && r ? e.setAttribute(n, r) : e.removeAttribute(n);
1746
+ });
1747
+ }
1748
+ normalizePopupNumber(e, t, n, r) {
1749
+ if (!e.trim()) return r;
1750
+ let i = Number.parseInt(e, 10);
1751
+ return Number.isFinite(i) ? String(Math.max(t, Math.min(n, i))) : r;
1401
1752
  }
1402
1753
  selectedTable() {
1403
1754
  let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
@@ -1500,9 +1851,9 @@ var a = class extends HTMLElement {
1500
1851
  toggleSource() {
1501
1852
  if (!(!this.editor || !this.source)) {
1502
1853
  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;
1854
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? o(e) : e.innerHTML;
1855
+ this.source.value = this.format === "markdown" ? n(t) : r(t, this.editor.ownerDocument), this.refreshCurrentHistorySnapshot(), this.preservedContent = this.source.value, this.dispatchValueEvents();
1856
+ } else this.editor.innerHTML = this.format === "markdown" ? i(this.source.value) : this.source.value, this.syncSource(), this.emitChange();
1506
1857
  this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
1507
1858
  }
1508
1859
  }
@@ -1531,6 +1882,6 @@ var a = class extends HTMLElement {
1531
1882
  t && this.selectImage(t);
1532
1883
  }
1533
1884
  };
1534
- customElements.get("mint-editor") || e("mint-editor", a);
1885
+ customElements.get("mint-editor") || e("mint-editor", s);
1535
1886
  //#endregion
1536
- export { a as default };
1887
+ export { s as default };