@editora/plugins 1.0.12 → 1.0.14

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 (53) hide show
  1. package/dist/approval-workflow.cjs.js +14 -14
  2. package/dist/approval-workflow.esm.js +265 -262
  3. package/dist/blockquote.cjs.js +1 -1
  4. package/dist/blockquote.esm.js +177 -15
  5. package/dist/blocks-library.cjs.js +6 -6
  6. package/dist/blocks-library.esm.js +95 -92
  7. package/dist/bold.cjs.js +1 -1
  8. package/dist/bold.esm.js +10 -6
  9. package/dist/capitalization.cjs.js +1 -1
  10. package/dist/capitalization.esm.js +124 -44
  11. package/dist/checklist.cjs.js +1 -1
  12. package/dist/checklist.esm.js +251 -191
  13. package/dist/citations.cjs.js +4 -4
  14. package/dist/citations.esm.js +131 -128
  15. package/dist/clear-formatting.cjs.js +1 -1
  16. package/dist/clear-formatting.esm.js +68 -36
  17. package/dist/code.cjs.js +27 -21
  18. package/dist/code.esm.js +72 -43
  19. package/dist/content-rules.cjs.js +5 -5
  20. package/dist/content-rules.esm.js +104 -101
  21. package/dist/data-binding.cjs.js +3 -3
  22. package/dist/data-binding.esm.js +51 -48
  23. package/dist/direction.cjs.js +1 -1
  24. package/dist/direction.esm.js +97 -74
  25. package/dist/doc-schema.cjs.js +4 -4
  26. package/dist/doc-schema.esm.js +104 -101
  27. package/dist/embed-iframe.cjs.js +21 -4
  28. package/dist/embed-iframe.esm.js +279 -116
  29. package/dist/heading.cjs.js +1 -1
  30. package/dist/heading.esm.js +239 -56
  31. package/dist/history.cjs.js +1 -1
  32. package/dist/history.esm.js +74 -89
  33. package/dist/inlineFormatting-DOYOJdnD.js +1 -0
  34. package/dist/inlineFormatting-DuVTGXYG.mjs +95 -0
  35. package/dist/italic.cjs.js +1 -1
  36. package/dist/italic.esm.js +12 -8
  37. package/dist/math.cjs.js +27 -21
  38. package/dist/math.esm.js +218 -146
  39. package/dist/merge-tag.cjs.js +8 -2
  40. package/dist/merge-tag.esm.js +130 -111
  41. package/dist/pii-redaction.cjs.js +6 -6
  42. package/dist/pii-redaction.esm.js +169 -166
  43. package/dist/smart-paste.cjs.js +5 -5
  44. package/dist/smart-paste.esm.js +120 -117
  45. package/dist/special-characters.cjs.js +6 -10
  46. package/dist/special-characters.esm.js +97 -75
  47. package/dist/strikethrough.cjs.js +1 -1
  48. package/dist/strikethrough.esm.js +11 -25
  49. package/dist/translation-workflow.cjs.js +7 -7
  50. package/dist/translation-workflow.esm.js +103 -100
  51. package/dist/underline.cjs.js +1 -1
  52. package/dist/underline.esm.js +7 -3
  53. package/package.json +3 -3
@@ -1,38 +1,127 @@
1
- const i = () => {
2
- const o = () => {
1
+ const f = '.rte-content, .editora-content, [contenteditable="true"]', w = "[data-editora-editor], .rte-editor, .editora-editor, editora-editor", h = (t) => t ? t.nodeType === Node.ELEMENT_NODE ? t : t.parentElement : null, v = (t) => {
2
+ const e = t?.contentElement;
3
+ if (e instanceof HTMLElement) return e;
4
+ const n = t?.editorElement;
5
+ if (n instanceof HTMLElement) {
6
+ const s = n.querySelector(f);
7
+ if (s instanceof HTMLElement) return s;
8
+ if (n.getAttribute("contenteditable") === "true") return n;
9
+ }
10
+ const r = window.__editoraCommandEditorRoot;
11
+ if (r instanceof HTMLElement) {
12
+ const s = r.querySelector(f);
13
+ if (s instanceof HTMLElement) return s;
14
+ if (r.getAttribute("contenteditable") === "true") return r;
15
+ }
16
+ const c = window.getSelection();
17
+ if (c && c.rangeCount > 0) {
18
+ const s = h(c.getRangeAt(0).startContainer), i = s?.closest(f);
19
+ if (i instanceof HTMLElement) return i;
20
+ const a = s?.closest(w)?.querySelector(f);
21
+ if (a instanceof HTMLElement) return a;
22
+ }
23
+ const l = document.activeElement, d = l instanceof HTMLElement ? l.closest(f) : null;
24
+ return d instanceof HTMLElement ? d : document.querySelector(f);
25
+ }, R = (t) => {
26
+ const e = window.getSelection();
27
+ if (!e || e.rangeCount === 0 || e.isCollapsed) return null;
28
+ const n = e.getRangeAt(0);
29
+ return !t.contains(n.startContainer) || !t.contains(n.endContainer) ? null : n;
30
+ }, S = (t, e) => {
31
+ if (!e.data) return !1;
32
+ if (typeof t.intersectsNode == "function")
3
33
  try {
4
- const e = window.getSelection();
5
- if (e && e.rangeCount > 0 && !e.isCollapsed) {
6
- const t = e.getRangeAt(0), r = t.toString().toUpperCase();
7
- return t.deleteContents(), t.insertNode(document.createTextNode(r)), !0;
8
- }
34
+ return t.intersectsNode(e);
35
+ } catch {
9
36
  return !1;
10
- } catch (e) {
11
- return console.error("Failed to convert to uppercase:", e), !1;
12
37
  }
13
- }, a = () => {
14
- try {
15
- const e = window.getSelection();
16
- if (e && e.rangeCount > 0 && !e.isCollapsed) {
17
- const t = e.getRangeAt(0), r = t.toString().toLowerCase();
18
- return t.deleteContents(), t.insertNode(document.createTextNode(r)), !0;
38
+ const n = document.createRange();
39
+ return n.selectNodeContents(e), t.compareBoundaryPoints(Range.END_TO_START, n) < 0 && t.compareBoundaryPoints(Range.START_TO_END, n) > 0;
40
+ }, L = (t, e) => {
41
+ const n = [], r = document.createTreeWalker(t, NodeFilter.SHOW_TEXT);
42
+ let c = r.nextNode();
43
+ for (; c; ) {
44
+ const l = c;
45
+ if (S(e, l)) {
46
+ const d = l === e.startContainer ? e.startOffset : 0, s = l === e.endContainer ? e.endOffset : l.data.length;
47
+ d < s && n.push({
48
+ node: l,
49
+ start: d,
50
+ end: s,
51
+ text: l.data.slice(d, s)
52
+ });
53
+ }
54
+ c = r.nextNode();
55
+ }
56
+ return n;
57
+ }, x = (t) => new RegExp("\\p{L}", "u").test(t), y = (t) => /[\p{M}'’-]/u.test(t), _ = () => {
58
+ let t = !1;
59
+ return (e) => {
60
+ let n = "";
61
+ return Array.from(e.text).forEach((r) => {
62
+ if (x(r)) {
63
+ n += t ? r.toLocaleLowerCase() : r.toLocaleUpperCase(), t = !0;
64
+ return;
19
65
  }
20
- return !1;
21
- } catch (e) {
22
- return console.error("Failed to convert to lowercase:", e), !1;
66
+ n += r, y(r) || (t = !1);
67
+ }), n;
68
+ };
69
+ }, M = (t) => {
70
+ if (t.length === 0) return;
71
+ const e = t[0], n = t[t.length - 1], r = window.getSelection();
72
+ if (!r) return;
73
+ const c = document.createRange();
74
+ c.setStart(e.node, e.start), c.setEnd(n.node, n.end), r.removeAllRanges(), r.addRange(c);
75
+ }, H = (t, e, n) => {
76
+ if (e !== n) {
77
+ if (typeof window.execEditorCommand == "function") {
78
+ window.execEditorCommand("recordDomTransaction", t, e, n);
79
+ return;
23
80
  }
24
- }, n = () => {
25
- try {
26
- const e = window.getSelection();
27
- if (e && e.rangeCount > 0 && !e.isCollapsed) {
28
- const t = e.getRangeAt(0), r = t.toString().replace(/\w\S*/g, (l) => l.charAt(0).toUpperCase() + l.substr(1).toLowerCase());
29
- return t.deleteContents(), t.insertNode(document.createTextNode(r)), !0;
81
+ if (typeof window.executeEditorCommand == "function")
82
+ try {
83
+ window.executeEditorCommand("recordDomTransaction", { editor: t, beforeHTML: e, afterHTML: n });
84
+ } catch {
30
85
  }
31
- return !1;
32
- } catch (e) {
33
- return console.error("Failed to convert to title case:", e), !1;
86
+ }
87
+ }, N = () => {
88
+ const t = (i, o) => {
89
+ try {
90
+ const a = v(o);
91
+ if (!a) return !1;
92
+ const m = R(a);
93
+ if (!m) return !1;
94
+ const p = L(a, m);
95
+ if (p.length === 0) return !1;
96
+ const C = a.innerHTML;
97
+ p.forEach((u, T) => {
98
+ const E = i(u, T);
99
+ u.node.replaceData(u.start, u.end - u.start, E), u.end = u.start + E.length;
100
+ });
101
+ const g = a.innerHTML;
102
+ return C === g ? !1 : (H(a, C, g), a.dispatchEvent(new window.Event("input", { bubbles: !0 })), M(p), !0);
103
+ } catch (a) {
104
+ return console.error("Failed to transform capitalization:", a), !1;
34
105
  }
35
- };
106
+ }, e = (i, o) => t((a) => a.text.toLocaleUpperCase(), o), n = (i, o) => t((a) => a.text.toLocaleLowerCase(), o), r = (i, o) => t(_(), o), c = (i, o) => {
107
+ if (!i) return !1;
108
+ switch (i) {
109
+ case "uppercase":
110
+ return e(void 0, o);
111
+ case "lowercase":
112
+ return n(void 0, o);
113
+ case "titlecase":
114
+ return r(void 0, o);
115
+ default:
116
+ return !1;
117
+ }
118
+ }, l = (i, o) => typeof i == "string" ? { value: i, context: o } : typeof o == "string" ? { value: o } : {
119
+ value: void 0,
120
+ context: o
121
+ }, d = (i, o) => {
122
+ if (o && typeof o == "object" && !o.doc)
123
+ return o;
124
+ }, s = (i) => (o, a) => i(void 0, d(o, a));
36
125
  return {
37
126
  name: "capitalization",
38
127
  toolbar: [
@@ -49,22 +138,13 @@ const i = () => {
49
138
  }
50
139
  ],
51
140
  commands: {
52
- setCapitalization: (e) => {
53
- if (!e) return !1;
54
- switch (e) {
55
- case "uppercase":
56
- return o();
57
- case "lowercase":
58
- return a();
59
- case "titlecase":
60
- return n();
61
- default:
62
- return !1;
63
- }
141
+ setCapitalization: (i, o) => {
142
+ const { value: a, context: m } = l(i, o);
143
+ return c(a, m);
64
144
  },
65
- toUpperCase: o,
66
- toLowerCase: a,
67
- toTitleCase: n
145
+ toUpperCase: s(e),
146
+ toLowerCase: s(n),
147
+ toTitleCase: s(r)
68
148
  },
69
149
  keymap: {
70
150
  "Mod-Shift-u": "toUpperCase",
@@ -74,5 +154,5 @@ const i = () => {
74
154
  };
75
155
  };
76
156
  export {
77
- i as CapitalizationPlugin
157
+ N as CapitalizationPlugin
78
158
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const N="__editoraCommandEditorRoot",w=e=>{if(!e)return null;const t=e.querySelector('[contenteditable="true"]');return t instanceof HTMLElement?t:null},A=()=>{if(typeof window>"u")return null;const e=window[N];if(!(e instanceof HTMLElement))return null;window[N]=null;const t=e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||(e.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")?e:null);if(t){const r=w(t);if(r)return r;if(t.getAttribute("contenteditable")==="true")return t}if(e.getAttribute("contenteditable")==="true")return e;const n=e.closest('[contenteditable="true"]');return n instanceof HTMLElement?n:null},_=()=>{const e=A();if(e&&document.contains(e))return e;const t=window.getSelection();if(t&&t.rangeCount>0){let r=t.getRangeAt(0).startContainer;for(;r&&r!==document.body;){if(r.nodeType===Node.ELEMENT_NODE){const o=r;if(o.getAttribute("contenteditable")==="true")return o}r=r.parentNode}}const n=document.activeElement;if(n){if(n.getAttribute("contenteditable")==="true")return n;const r=n.closest('[contenteditable="true"]');if(r)return r}return document.querySelector('[contenteditable="true"]')},S=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,H=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const n=t.getRangeAt(0);return e.contains(n.commonAncestorContainer)?n:null},y=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},M=(e,t)=>{if(t===e.innerHTML)return;const n=window.execEditorCommand||window.executeEditorCommand;if(typeof n=="function")try{n("recordDomTransaction",e,t,e.innerHTML)}catch{}},k=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const n=window.getSelection();if(!n)return;const r=document.createRange();r.selectNodeContents(e),r.collapse(!1),n.removeAllRanges();try{n.addRange(r)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},v=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const n=[];e.childNodes.forEach(r=>{r.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(r.tagName)||n.push(r)}),n.forEach(r=>t.appendChild(r)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},C=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const n=document.createElement("p");return n.innerHTML=e.trim()||"<br>",t.appendChild(n),t},T=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),I=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI"]),b=e=>I.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",R=(e,t)=>{const n=[],r=new Set,o=i=>{!i||r.has(i)||t.contains(i)&&b(i)&&(i.closest("ul, ol")||(r.add(i),n.push(i)))},u=i=>{let a=i;for(;a&&a!==document.body;){if(a.nodeType===Node.ELEMENT_NODE){const h=a;if(b(h))return h;if(h.getAttribute("contenteditable")==="true")break}a=a.parentNode}return null};if(e.collapsed)return o(u(e.startContainer)),n;const d=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>{const a=i;if(!b(a)||a.closest("ul, ol"))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const h=document.createRange();return h.selectNodeContents(a),e.compareBoundaryPoints(Range.END_TO_START,h)>0&&e.compareBoundaryPoints(Range.START_TO_END,h)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let l=d.nextNode();for(;l;)o(l),l=d.nextNode();if(n.length===0&&o(u(e.commonAncestorContainer)),n.length<=1)return n;const m=n.filter(i=>!n.some(a=>a!==i&&i.contains(a)));return m.length>0?m:n},O=e=>{const t=[],n=document.createElement("div"),r=()=>{const o=n.innerHTML.trim();if(!o)return;const u=document.createElement("p");u.innerHTML=o,t.push(u),n.innerHTML=""};if(e.childNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(o.tagName)){r();return}if(o.nodeType===Node.ELEMENT_NODE&&o.tagName==="P"){r();const u=o.innerHTML.trim(),d=document.createElement("p");d.innerHTML=u||"<br>",t.push(d);return}o.nodeType===Node.TEXT_NODE&&!(o.textContent||"").trim()||n.appendChild(o.cloneNode(!0))}),r(),t.length===0){const o=document.createElement("p");o.innerHTML="<br>",t.push(o)}return t},P=()=>({name:"checklist",init:()=>{if(typeof document>"u"||typeof window>"u"||window.__checklistPluginClickInitialized)return;window.__checklistPluginClickInitialized=!0;const e=t=>{const r=t.target.closest('li[data-type="checklist-item"]');if(!r)return;const o=r.getBoundingClientRect();if(!(t.clientX-o.left<32))return;t.preventDefault(),t.stopPropagation();const l=r.closest("[contenteditable], .rte-content, .editora-content");if(l?.getAttribute("contenteditable")==="false"||!!l?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;const i=l?.innerHTML||"",a=r.getAttribute("data-checked")==="true";r.setAttribute("data-checked",(!a).toString()),l&&(M(l,i),y(l))};document.addEventListener("click",e)},nodes:{checklist:{content:"checklistItem+",group:"block",parseDOM:[{tag:'ul[data-type="checklist"]'}],toDOM:()=>["ul",{"data-type":"checklist"},0]},checklistItem:{content:"paragraph",attrs:{checked:{default:!1}},parseDOM:[{tag:'li[data-type="checklist-item"]',getAttrs:e=>({checked:e.getAttribute("data-checked")==="true"})}],toDOM:e=>["li",{"data-type":"checklist-item","data-checked":e?.attrs?.checked?"true":"false"},0]}},toolbar:[{label:"Checklist",command:"toggleChecklist",icon:'<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleChecklist:()=>{try{const e=_();if(!e)return!1;const t=e.innerHTML,n=()=>(M(e,t),y(e),!0),r=H(e);if(!r)return!1;const o=S(r.startContainer);if(!o)return!1;const u=o.closest('ul[data-type="checklist"]');if(u&&e.contains(u)){const c=T(u);if(c.length===0)return!1;const p=document.createDocumentFragment();let s=null;return c.forEach((f,g)=>{const E=O(f);E.forEach(L=>{p.appendChild(L),!s&&(f.contains(r.startContainer)||g===0)&&(s=L)}),!s&&g===0&&E[0]&&(s=E[0])}),u.replaceWith(p),s&&k(s,e),n()}const d=o.closest("ul, ol");if(d&&e.contains(d)){let c;if(d.tagName.toLowerCase()==="ul")c=d;else{for(c=document.createElement("ul");d.firstChild;)c.appendChild(d.firstChild);d.replaceWith(c)}c.setAttribute("data-type","checklist");let p=T(c);p.length===0&&(c.appendChild(C("")),p=T(c));let s=null;p.forEach(g=>{g.setAttribute("data-type","checklist-item"),g.hasAttribute("data-checked")||g.setAttribute("data-checked","false");const E=v(g);g.contains(r.startContainer)&&(s=E)});const f=c.querySelector(':scope > li[data-type="checklist-item"] > p');return k(s||f||c,e),n()}const l=R(r,e);if(l.length>1){const c=document.createElement("ul");c.setAttribute("data-type","checklist"),l.forEach(f=>{c.appendChild(C(f.innerHTML))}),l[0].replaceWith(c),l.slice(1).forEach(f=>{f.isConnected&&f.remove()});const s=c.querySelector(':scope > li[data-type="checklist-item"] > p');return s&&k(s,e),n()}const m=l[0]||o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(m&&m!==e){const c=document.createElement("ul");c.setAttribute("data-type","checklist");const p=C(m.innerHTML);c.appendChild(p),m.replaceWith(c);const s=p.querySelector(":scope > p");return s&&k(s,e),n()}const i=document.createElement("ul");i.setAttribute("data-type","checklist");const a=C("");i.appendChild(a),r.deleteContents(),r.insertNode(i);const h=a.querySelector(":scope > p");return h&&k(h,e),n()}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});exports.ChecklistPlugin=P;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M="__editoraCommandEditorRoot",H=e=>{if(!e)return null;const t=e.querySelector('[contenteditable="true"]');return t instanceof HTMLElement?t:null},R=()=>{if(typeof window>"u")return null;const e=window[M];if(!(e instanceof HTMLElement))return null;window[M]=null;const t=e.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||(e.matches("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")?e:null);if(t){const n=H(t);if(n)return n;if(t.getAttribute("contenteditable")==="true")return t}if(e.getAttribute("contenteditable")==="true")return e;const r=e.closest('[contenteditable="true"]');return r instanceof HTMLElement?r:null},_=()=>{const e=R();if(e&&document.contains(e))return e;const t=window.getSelection();if(t&&t.rangeCount>0){let n=t.getRangeAt(0).startContainer;for(;n&&n!==document.body;){if(n.nodeType===Node.ELEMENT_NODE){const o=n;if(o.getAttribute("contenteditable")==="true")return o}n=n.parentNode}}const r=document.activeElement;if(r){if(r.getAttribute("contenteditable")==="true")return r;const n=r.closest('[contenteditable="true"]');if(n)return n}return document.querySelector('[contenteditable="true"]')},A=e=>e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null,I=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const r=t.getRangeAt(0);return e.contains(r.commonAncestorContainer)?r:null},T=e=>{e.dispatchEvent(new Event("input",{bubbles:!0}))},b=(e,t)=>{if(t===e.innerHTML)return;const r=window.execEditorCommand||window.executeEditorCommand;if(typeof r=="function")try{r("recordDomTransaction",e,t,e.innerHTML)}catch{}},C=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!1),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},N=e=>{let t=e.querySelector(":scope > p");if(!t){t=document.createElement("p");const r=[];e.childNodes.forEach(n=>{n.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(n.tagName)||r.push(n)}),r.forEach(n=>t.appendChild(n)),e.insertBefore(t,e.firstChild)}return t.innerHTML.trim()||(t.innerHTML="<br>"),t},v=e=>(e.textContent||"").replace(/\u200B/g,"").trim()?!1:!e.querySelector("img, video, table, iframe, hr, pre, ul, ol"),P=()=>{const e=document.createElement("p");return e.innerHTML="<br>",e},S=(e,t)=>{if(!e.isConnected){t.focus({preventScroll:!0});return}const r=window.getSelection();if(!r)return;const n=document.createRange();n.selectNodeContents(e),n.collapse(!0),r.removeAllRanges();try{r.addRange(n)}catch{t.focus({preventScroll:!0});return}t.focus({preventScroll:!0})},x=(e,t)=>{e.appendChild(t),e.innerHTML.trim()||(e.innerHTML="<br>")},O=(e,t,r)=>{const n=P();t.parentNode?.insertBefore(n,t.nextSibling),r.remove(),y(t).length===0&&t.remove(),S(n,e)},D=(e,t,r)=>{const n=N(t),o=r.cloneRange();o.deleteContents();const i=document.createRange();i.setStart(o.startContainer,o.startOffset),i.setEndAfter(n.lastChild||n);const d=document.createDocumentFragment();try{d.appendChild(i.extractContents())}catch{}n.innerHTML.trim()||(n.innerHTML="<br>");const c=document.createElement("li");c.setAttribute("data-type","checklist-item"),c.setAttribute("data-checked","false");const h=document.createElement("p");x(h,d),c.appendChild(h),t.parentNode?.insertBefore(c,t.nextSibling),S(h,e)},k=e=>{const t=document.createElement("li");t.setAttribute("data-type","checklist-item"),t.setAttribute("data-checked","false");const r=document.createElement("p");return r.innerHTML=e.trim()||"<br>",t.appendChild(r),t},y=e=>Array.from(e.children).filter(t=>t instanceof HTMLLIElement),F=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI"]),L=e=>F.has(e.tagName)&&e.getAttribute("contenteditable")!=="true",B=(e,t)=>{const r=[],n=new Set,o=s=>{!s||n.has(s)||t.contains(s)&&L(s)&&(s.closest("ul, ol")||(n.add(s),r.push(s)))},i=s=>{let l=s;for(;l&&l!==document.body;){if(l.nodeType===Node.ELEMENT_NODE){const p=l;if(L(p))return p;if(p.getAttribute("contenteditable")==="true")break}l=l.parentNode}return null};if(e.collapsed)return o(i(e.startContainer)),r;const d=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:s=>{const l=s;if(!L(l)||l.closest("ul, ol"))return NodeFilter.FILTER_SKIP;if(typeof e.intersectsNode=="function")return e.intersectsNode(l)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP;const p=document.createRange();return p.selectNodeContents(l),e.compareBoundaryPoints(Range.END_TO_START,p)>0&&e.compareBoundaryPoints(Range.START_TO_END,p)<0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let c=d.nextNode();for(;c;)o(c),c=d.nextNode();if(r.length===0&&o(i(e.commonAncestorContainer)),r.length<=1)return r;const h=r.filter(s=>!r.some(l=>l!==s&&s.contains(l)));return h.length>0?h:r},K=e=>{const t=[],r=document.createElement("div"),n=()=>{const o=r.innerHTML.trim();if(!o)return;const i=document.createElement("p");i.innerHTML=o,t.push(i),r.innerHTML=""};if(e.childNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE&&["UL","OL"].includes(o.tagName)){n();return}if(o.nodeType===Node.ELEMENT_NODE&&o.tagName==="P"){n();const i=o.innerHTML.trim(),d=document.createElement("p");d.innerHTML=i||"<br>",t.push(d);return}o.nodeType===Node.TEXT_NODE&&!(o.textContent||"").trim()||r.appendChild(o.cloneNode(!0))}),n(),t.length===0){const o=document.createElement("p");o.innerHTML="<br>",t.push(o)}return t},z=()=>({name:"checklist",init:()=>{if(!(typeof document>"u"||typeof window>"u")){if(!window.__checklistPluginClickInitialized){window.__checklistPluginClickInitialized=!0;const e=t=>{const n=t.target.closest('li[data-type="checklist-item"]');if(!n)return;const o=n.getBoundingClientRect();if(!(t.clientX-o.left<32))return;t.preventDefault(),t.stopPropagation();const c=n.closest("[contenteditable], .rte-content, .editora-content");if(c?.getAttribute("contenteditable")==="false"||!!c?.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;const s=c?.innerHTML||"",l=n.getAttribute("data-checked")==="true";n.setAttribute("data-checked",(!l).toString()),c&&(b(c,s),T(c))};document.addEventListener("click",e)}if(!window.__checklistPluginKeydownInitialized){window.__checklistPluginKeydownInitialized=!0;const e=t=>{if(t.key!=="Enter"||t.shiftKey||t.altKey||t.ctrlKey||t.metaKey||t.defaultPrevented)return;const r=window.getSelection();if(!r||r.rangeCount===0)return;const n=r.getRangeAt(0),i=A(n.startContainer)?.closest('li[data-type="checklist-item"]');if(!i)return;const d=i.closest('ul[data-type="checklist"]');if(!d)return;const c=i.closest("[contenteditable], .rte-content, .editora-content");if(!c||c.getAttribute("contenteditable")==="false"||!!c.closest('[data-readonly="true"], .editora-editor[readonly], editora-editor[readonly]'))return;t.preventDefault();const s=c.innerHTML,l=N(i);v(l)?O(c,d,i):D(c,i,n),b(c,s),T(c)};document.addEventListener("keydown",e)}}},nodes:{checklist:{content:"checklistItem+",group:"block",parseDOM:[{tag:'ul[data-type="checklist"]'}],toDOM:()=>["ul",{"data-type":"checklist"},0]},checklistItem:{content:"paragraph",attrs:{checked:{default:!1}},parseDOM:[{tag:'li[data-type="checklist-item"]',getAttrs:e=>({checked:e.getAttribute("data-checked")==="true"})}],toDOM:e=>["li",{"data-type":"checklist-item","data-checked":e?.attrs?.checked?"true":"false"},0]}},toolbar:[{label:"Checklist",command:"toggleChecklist",icon:'<svg width="24px" height="24px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="#000000"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.75 4.48h-.71L2 3.43l.71-.7.69.68L4.81 2l.71.71-1.77 1.77zM6.99 3h8v1h-8V3zm0 3h8v1h-8V6zm8 3h-8v1h8V9zm-8 3h8v1h-8v-1zM3.04 7.48h.71l1.77-1.77-.71-.7L3.4 6.42l-.69-.69-.71.71 1.04 1.04zm.71 3.01h-.71L2 9.45l.71-.71.69.69 1.41-1.42.71.71-1.77 1.77zm-.71 3.01h.71l1.77-1.77-.71-.71-1.41 1.42-.69-.69-.71.7 1.04 1.05z"></path></g></svg>',shortcut:"Mod-Shift-9"}],commands:{toggleChecklist:()=>{try{const e=_();if(!e)return!1;const t=e.innerHTML,r=()=>(b(e,t),T(e),!0),n=I(e);if(!n)return!1;const o=A(n.startContainer);if(!o)return!1;const i=o.closest('ul[data-type="checklist"]');if(i&&e.contains(i)){const a=y(i);if(a.length===0)return!1;const f=document.createDocumentFragment();let u=null;return a.forEach((m,g)=>{const E=K(m);E.forEach(w=>{f.appendChild(w),!u&&(m.contains(n.startContainer)||g===0)&&(u=w)}),!u&&g===0&&E[0]&&(u=E[0])}),i.replaceWith(f),u&&C(u,e),r()}const d=o.closest("ul, ol");if(d&&e.contains(d)){let a;if(d.tagName.toLowerCase()==="ul")a=d;else{for(a=document.createElement("ul");d.firstChild;)a.appendChild(d.firstChild);d.replaceWith(a)}a.setAttribute("data-type","checklist");let f=y(a);f.length===0&&(a.appendChild(k("")),f=y(a));let u=null;f.forEach(g=>{g.setAttribute("data-type","checklist-item"),g.hasAttribute("data-checked")||g.setAttribute("data-checked","false");const E=N(g);g.contains(n.startContainer)&&(u=E)});const m=a.querySelector(':scope > li[data-type="checklist-item"] > p');return C(u||m||a,e),r()}const c=B(n,e);if(c.length>1){const a=document.createElement("ul");a.setAttribute("data-type","checklist"),c.forEach(m=>{a.appendChild(k(m.innerHTML))}),c[0].replaceWith(a),c.slice(1).forEach(m=>{m.isConnected&&m.remove()});const u=a.querySelector(':scope > li[data-type="checklist-item"] > p');return u&&C(u,e),r()}const h=c[0]||o.closest("p, h1, h2, h3, h4, h5, h6, blockquote, pre");if(h&&h!==e){const a=document.createElement("ul");a.setAttribute("data-type","checklist");const f=k(h.innerHTML);a.appendChild(f),h.replaceWith(a);const u=f.querySelector(":scope > p");return u&&C(u,e),r()}const s=document.createElement("ul");s.setAttribute("data-type","checklist");const l=k("");s.appendChild(l),n.deleteContents(),n.insertNode(s);const p=l.querySelector(":scope > p");return p&&C(p,e),r()}catch(e){return console.error("Failed to toggle checklist:",e),!1}}},keymap:{"Mod-Shift-9":"toggleChecklist"}});exports.ChecklistPlugin=z;