Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@editora/react

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@editora/react - npm Package Compare versions

Comparing version
1.0.11
to
1.0.12
+1
-1
dist/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("react/jsx-runtime"),d=require("react"),K=require("@editora/core"),Ne=e=>e&&e.__esModule?e:{default:e},je=Ne(d),xe=({isOpen:e,options:t,onSelect:a,onClose:n,anchorRef:o,className:r=""})=>{const f=d.useRef(null),[c,u]=d.useState(null),g=()=>{var v;if(!e||!o.current)return;const l=o.current.getBoundingClientRect(),N=(v=f.current)==null?void 0:v.getBoundingClientRect(),A=(N==null?void 0:N.width)||120,M=(N==null?void 0:N.height)||t.length*36,i=8,F=4,H=window.innerWidth,y=window.innerHeight;let C=l.bottom+F,h=l.left;h+A>H-i&&(h=H-A-i),h<i&&(h=i),C+M>y-i&&(C=l.top-M-F),C<i&&(C=i),u({top:C,left:h})};return d.useLayoutEffect(()=>{if(!e){u(null);return}g();const l=window.requestAnimationFrame(g);return()=>{window.cancelAnimationFrame(l)}},[e,t.length,o]),d.useEffect(()=>{if(!e)return;const l=()=>{g()};return window.addEventListener("resize",l),window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("resize",l),window.removeEventListener("scroll",l,!0)}},[e,t.length,o]),d.useEffect(()=>{const l=A=>{f.current&&!f.current.contains(A.target)&&o.current&&!o.current.contains(A.target)&&n()},N=A=>{A.key==="Escape"&&n()};return e&&(document.addEventListener("mousedown",l),document.addEventListener("keydown",N)),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",N)}},[e,n,o]),e?m.jsx("div",{ref:f,className:`rte-inline-menu ${r}`,style:{top:(c==null?void 0:c.top)??-9999,left:(c==null?void 0:c.left)??-9999,visibility:c?"visible":"hidden"},children:t.map(l=>m.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{a(l.value),n()},children:l.label},l.value))}):null},Y=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),De={undo:"undo",redo:"redo",bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",textcolor:"openTextColorPicker",backgroundcolor:"openBackgroundColorPicker",fontsize:"setFontSize",increasefontsize:"increaseFontSize",decreasefontsize:"decreaseFontSize",heading:"setHeading",paragraph:"setHeading",textalignment:"setTextAlignment",direction:"setDirectionLTR",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",indent:"increaseIndent",outdent:"decreaseIndent",link:"openLinkDialog",image:"insertImage",video:"insertVideo",table:"insertTable",trackchanges:"toggleTrackChanges",accepttrackchanges:"acceptAllTrackChanges",rejecttrackchanges:"rejectAllTrackChanges",clearformatting:"clearFormatting",databinding:"openDataBindingDialog",databindingpreview:"openDataBindingDialog"},He=(e,t)=>{if(!Array.isArray(t)||t.length===0)return e;if(!t.every(u=>typeof u=="string"))return t;const n=new Map,o=new Map;e.forEach(u=>{n.set(Y(u.command||""),u),o.set(Y(u.label||""),u)});const r=t.flatMap(u=>u.split(/\s+/)).map(u=>u.trim()).filter(Boolean),f=[];let c=0;return r.forEach(u=>{if(u==="|"){c+=1,f.push({type:"separator",command:`__separator__${c}`,label:"|"});return}const g=Y(u),l=De[g],N=n.get(g)||(l?n.get(Y(l)):void 0)||o.get(g)||e.find(A=>Y(A.command||"").includes(g));N&&f.push(N)}),f.length>0?f:e},ae=({editor:e,position:t="top",sticky:a=!1,floating:n=!1,readonly:o=!1,showMoreOptions:r=!0,itemsOverride:f})=>{const[c,u]=d.useState(!1),[g,l]=d.useState(null),[N,A]=d.useState(null),[M,i]=d.useState(null),[F,H]=d.useState(!1),y=d.useRef(null),C=d.useRef(null),h=d.useRef({}),v=d.useRef([]),I=d.useRef(null),T=d.useRef(null),b=d.useRef(null),L=d.useMemo(()=>He(e.pluginManager.getToolbarItems(),f),[e,f]),w=s=>{y.current=s,s&&!s.collapsed&&(C.current=s)},p=()=>{var E;const s=(E=I.current)==null?void 0:E.closest("[data-editora-editor]");return(s==null?void 0:s.querySelector(".rte-content"))||null},j=()=>{var E;if(typeof window>"u")return;const s=(E=I.current)==null?void 0:E.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=s||null},R=s=>{if(typeof window>"u"||!s)return;const E=s.getAttribute("data-command");E&&(window.__editoraLastCommandButton=s,window.__editoraLastCommand=E)},k=()=>{const s=p();if(!s)return null;const E=window.getSelection();if(!E||E.rangeCount===0)return null;const x=E.getRangeAt(0);return s.contains(x.commonAncestorContainer)?x.cloneRange():null},S=()=>{const s=k();s&&w(s)};d.useEffect(()=>{var W;const s=(W=I.current)==null?void 0:W.closest("[data-editora-editor]");if(!s)return;const E=s.querySelector(".rte-content, .editora-content");u((E==null?void 0:E.getAttribute("data-track-changes"))==="true");const x=D=>{var X;u(!!((X=D.detail)!=null&&X.enabled))};return s.addEventListener("editora:track-changes-toggle",x),()=>{s.removeEventListener("editora:track-changes-toggle",x)}},[]),d.useEffect(()=>{const s=()=>{S()};return document.addEventListener("selectionchange",s),()=>{document.removeEventListener("selectionchange",s)}},[]),d.useEffect(()=>{if(!g)return;const s=x=>{const W=x.target;W&&W instanceof Element&&(W.closest(".rte-toolbar-dropdown")||l(null))},E=x=>{x.key==="Escape"&&l(null)};return document.addEventListener("pointerdown",s,!0),document.addEventListener("keydown",E),()=>{document.removeEventListener("pointerdown",s,!0),document.removeEventListener("keydown",E)}},[g]);const _=s=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(s),P=(s=!1)=>{const E=p();if(!E)return!1;const x=window.getSelection();if(!x)return!1;const W=x.rangeCount>0&&E.contains(x.getRangeAt(0).commonAncestorContainer),D=s?C.current||y.current:y.current||C.current;if(s&&D&&D.collapsed)return!1;if(D&&E.contains(D.commonAncestorContainer))try{return E.focus({preventScroll:!0}),x.removeAllRanges(),x.addRange(D),!0}catch{}return W};d.useEffect(()=>{if(!r){i(null),H(!1),v.current=[];return}let s=null;const E=()=>{if(!I.current||!T.current)return;const D=I.current.clientWidth,U=16,X=40,z=4,te=Math.max(0,D-U-X-z);let fe=0,me=0;const ne=T.current.children;for(let G=0;G<ne.length;G++){const re=ne[G].getBoundingClientRect().width;re>0&&(v.current[G]=re);const ge=v.current[G]??re,be=(ge>0?ge:40)+z;if(fe+be<=te)fe+=be,me++;else break}const he=Math.max(1,Math.min(me,ne.length));i(G=>G===he?G:he)},x=()=>{s!==null&&cancelAnimationFrame(s),s=requestAnimationFrame(E)};v.current=[],x();const W=new ResizeObserver(()=>{x()});return I.current&&W.observe(I.current),T.current&&W.observe(T.current),()=>{s!==null&&cancelAnimationFrame(s),W.disconnect()}},[L.length,r]),d.useEffect(()=>{F&&M!==null&&M>=L.length&&H(!1)},[F,M,L.length]);const q=s=>(h.current[s]||(h.current[s]=je.default.createRef()),h.current[s]),B=(s,E)=>{if(o)return;j(),s==="addComment"||s==="toggleComments"||P(_(s));const D={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[s];if(D){document.execCommand(D,!1),l(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(s,E),l(null)},O=s=>{o||(S(),l(g===s?null:s))},$=s=>{o||(S(),A(N===s?null:s),l(null))},V=(s,E)=>{o||(P(),B(s,E),w(null),C.current=null,A(null))},Q=(s,E)=>s&&s.startsWith("<svg")&&s.endsWith("</svg>")?m.jsx("span",{dangerouslySetInnerHTML:{__html:s}}):s&&s.length===1&&/^[BIUSH]$/.test(s)?m.jsx("span",{style:{fontWeight:"bold",fontSize:"14px",lineHeight:"1"},children:s}):s||"⚪",Me={...a&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},de=r&&M!==null&&M<L.length,Ce=s=>{if(o)return;const E=s.target;E.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")&&(R(E.closest("[data-command]")),j(),S(),s.preventDefault())},ee=(s,E=!0)=>s.map((x,W)=>{var X;const D=x.command||"",U=D==="toggleTrackChanges"&&c;return m.jsx("div",{className:"rte-toolbar-item",style:{display:E&&r&&M!==null&&W>=M?"none":"flex"},children:x.type==="separator"?m.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):x.type==="dropdown"?m.jsxs("div",{className:"rte-toolbar-dropdown",children:[m.jsxs("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":D,"data-active":U?"true":"false",onMouseDown:z=>{z.preventDefault(),S()},onClick:()=>O(D),disabled:o,children:[x.label," ▼"]}),g===D&&m.jsx("div",{className:"rte-toolbar-dropdown-menu",children:(X=x.options)==null?void 0:X.map(z=>m.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:te=>te.preventDefault(),onClick:()=>B(D,z.value),children:z.label},z.value))})]}):x.type==="inline-menu"?m.jsx("button",{ref:q(D),className:`rte-toolbar-button ${U?"active":""}`,"data-command":D,"data-active":U?"true":"false",onMouseDown:z=>{z.preventDefault(),S()},onClick:()=>$(D),disabled:o,title:x.label,children:Q(x.icon)}):x.type==="input"?m.jsx("input",{type:"text",className:`rte-toolbar-input ${x.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:x.placeholder,onChange:z=>B(D,z.target.value),disabled:o,onKeyDown:z=>{z.key==="Enter"&&B(D,z.target.value)},title:x.label}):x.type==="group"?m.jsx("div",{className:`rte-toolbar-group-button ${x.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${x.label}`,children:m.jsx("div",{className:`rte-toolbar-group-items ${x.label.toLowerCase().replace(/\s+/g,"-")}`,children:ee(x.items||[],!1)})}):m.jsx("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":D,"data-active":U?"true":"false",onMouseDown:z=>{z.preventDefault(),S()},onClick:()=>B(D),disabled:o,title:x.label,children:Q(x.icon)})},W)}),Ie=r&&M!==null?L.filter((s,E)=>E>=M):[];return m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"rte-toolbar-wrapper",style:Me,onMouseDownCapture:Ce,children:[m.jsxs("div",{className:"rte-toolbar",ref:I,children:[m.jsx("div",{className:"rte-toolbar-items-container",ref:T,style:r?void 0:{flexWrap:"wrap"},children:ee(L)}),de&&m.jsx("button",{ref:b,className:`rte-toolbar-more-button ${F?"active":""}`,onMouseDown:s=>{s.preventDefault(),S()},onClick:()=>H(!F),disabled:o,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),de&&m.jsx("div",{className:`rte-toolbar-expanded-row ${F?"show":""}`,children:ee(Ie,!1)})]}),L.map(s=>{if(s.type==="inline-menu"){const E=s.command||"";return m.jsx(xe,{isOpen:N===E,options:s.options||[],onSelect:x=>V(E,x),onClose:()=>A(null),anchorRef:q(E)},`menu-${E||"unknown"}`)}return null})]})};function Fe(e,t){const a=d.useRef(),n=d.useRef("");return d.useEffect(()=>{if(!(t!=null&&t.enabled))return;const r=t.intervalMs||3e4,f=t.storageKey||"rte-autosave",c=t.provider||"localStorage",u=async()=>{const g=e();if(g!==n.current){if(n.current=g,c==="localStorage")try{localStorage.setItem(f,g),localStorage.setItem(`${f}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(l){console.error("[Autosave] Failed to save to localStorage:",l)}else if(c==="api"&&t.apiUrl)try{await fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:g,timestamp:Date.now()})}),console.log("[Autosave] Content saved to API")}catch(l){console.error("[Autosave] Failed to save to API:",l)}}};return a.current=setInterval(u,r),()=>{a.current&&clearInterval(a.current)}},[t==null?void 0:t.enabled,t==null?void 0:t.intervalMs,t==null?void 0:t.storageKey,t==null?void 0:t.provider,t==null?void 0:t.apiUrl,e]),{restore:()=>{if(!(t!=null&&t.enabled))return null;const r=t.storageKey||"rte-autosave";if((t.provider||"localStorage")==="localStorage")try{const c=localStorage.getItem(r),u=localStorage.getItem(`${r}-timestamp`);if(c&&u)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(u))),c}catch(c){console.error("[Autosave] Failed to restore from localStorage:",c)}return null}}}const _e=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","section","sup","sub","hr"],Be={"*":["class","style","id","data-*","role","aria-*","tabindex","contenteditable","spellcheck"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function ye(e,t,a){if((t==null?void 0:t.sanitize)===!1)return e;const n=t!=null&&t.allowedTags&&t.allowedTags.length>0?t.allowedTags:_e,r=!!(t!=null&&t.allowedAttributes)&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:Be,f=document.createElement("div");return f.innerHTML=e,Se(f,n,r),f.innerHTML}function Se(e,t,a){const n=Array.from(e.childNodes);for(const o of n)if(o.nodeType===Node.ELEMENT_NODE){const r=o,f=r.tagName.toLowerCase();if(!t.includes(f)){for(;r.firstChild;)e.insertBefore(r.firstChild,r);e.removeChild(r);continue}ze(r,a),Se(r,t,a)}else{if(o.nodeType===Node.TEXT_NODE)continue;e.removeChild(o)}}function ze(e,t){const a=e.tagName.toLowerCase(),n=Array.from(e.attributes),o=t[a]||[],r=t["*"]||[],f=[...o,...r];for(const c of n){const u=c.name.toLowerCase();let g=!1;f.includes(u)&&(g=!0);for(const l of f)if(l.endsWith("*")){const N=l.slice(0,-1);if(u.startsWith(N)){g=!0;break}}(u.startsWith("on")||u==="javascript:"||u==="href"&&c.value.trim().toLowerCase().startsWith("javascript:")||u==="src"&&c.value.trim().toLowerCase().startsWith("javascript:"))&&(g=!1),g||e.removeAttribute(c.name)}e.hasAttribute("href")&&(e.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("href"),e.hasAttribute("src")&&(e.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("src")}function We(e,t,a){return(a==null?void 0:a.sanitizeOnPaste)===!1?e:ye(e,t)}function we(e,t,a){return(a==null?void 0:a.sanitizeOnInput)===!1?e:ye(e,t)}const Z=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),J=(e,t)=>{const n=!!t&&Z(e);e.classList.toggle("rte-content-empty",n)},ie="data-rte-caret-marker",ce="data-rte-range-start-marker",ue="data-rte-range-end-marker",oe=()=>Math.random().toString(36).slice(2),Oe=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;try{const n=a.cloneRange();n.selectNodeContents(e),n.setEnd(a.startContainer,a.startOffset);const o=a.cloneRange();return o.selectNodeContents(e),o.setEnd(a.endContainer,a.endOffset),{start:n.toString().length,end:o.toString().length}}catch{return null}},ve=(e,t)=>{var f,c;const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let n=a.nextNode(),o=Math.max(0,t),r=null;for(;n;){r=n;const u=((f=n.textContent)==null?void 0:f.length)??0;if(o<=u)return{node:n,offset:o};o-=u,n=a.nextNode()}return r?{node:r,offset:((c=r.textContent)==null?void 0:c.length)??0}:{node:e,offset:e.childNodes.length}},Pe=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;const n=Oe(e);try{if(a.collapsed){const l=oe(),N=document.createElement("span");return N.setAttribute(ie,l),N.appendChild(document.createTextNode("​")),a.cloneRange().insertNode(N),{collapsed:!0,caretId:l,fallbackOffsets:n}}const o=oe(),r=oe(),f=document.createElement("span");f.setAttribute(ue,r),f.appendChild(document.createTextNode("​"));const c=document.createElement("span");c.setAttribute(ce,o),c.appendChild(document.createTextNode("​"));const u=a.cloneRange();u.collapse(!1),u.insertNode(f);const g=a.cloneRange();return g.collapse(!0),g.insertNode(c),{collapsed:!1,startId:o,endId:r,fallbackOffsets:n}}catch{return{collapsed:a.collapsed,fallbackOffsets:n}}},$e=e=>{e.querySelectorAll(`[${ie}], [${ce}], [${ue}]`).forEach(t=>t.remove())},qe=(e,t)=>{if(!t)return!1;const a=window.getSelection();if(!a)return!1;try{const n=document.createRange();if(t.collapsed&&t.caretId){const o=e.querySelector(`[${ie}="${t.caretId}"]`);return!o||!o.parentNode?!1:(n.setStartAfter(o),n.collapse(!0),a.removeAllRanges(),a.addRange(n),!0)}if(!t.collapsed&&t.startId&&t.endId){const o=e.querySelector(`[${ce}="${t.startId}"]`),r=e.querySelector(`[${ue}="${t.endId}"]`);return!o||!r||!o.parentNode||!r.parentNode?!1:(n.setStartAfter(o),n.setEndBefore(r),a.removeAllRanges(),a.addRange(n),!0)}}catch{return!1}return!1},Ue=(e,t)=>{if(!t)return;const a=window.getSelection();if(a)try{const n=ve(e,t.start),o=ve(e,t.end),r=document.createRange();r.setStart(n.node,n.offset),r.setEnd(o.node,o.offset),a.removeAllRanges(),a.addRange(r)}catch{}},ke=({editor:e,defaultValue:t,value:a,readonly:n=!1,placeholder:o,onChange:r,pasteConfig:f,contentConfig:c,securityConfig:u,performanceConfig:g,accessibilityConfig:l,autosaveConfig:N,contextMenuConfig:A,spellcheckConfig:M})=>{const i=d.useRef(null),F=a!==void 0,H=d.useRef(),y=(c==null?void 0:c.autoHeight)===!0,C=typeof(c==null?void 0:c.minHeight)=="number"?c.minHeight:200,h=typeof(c==null?void 0:c.maxHeight)=="number"?c.maxHeight:0,v=b=>{if(!b||!y)return;b.style.height="auto";const L=Math.max(C,b.scrollHeight);if(h>0){b.style.height=`${Math.min(L,h)}px`;return}b.style.height=`${L}px`},{restore:I}=Fe(()=>{var b;return((b=i.current)==null?void 0:b.innerHTML)||""},N);d.useEffect(()=>{if(!i.current)return;const b=I(),L=b??a??t??"";L.trim()?i.current.innerHTML!==L&&(i.current.innerHTML=L):o?i.current.innerHTML="":i.current.innerHTML.trim()||(i.current.innerHTML="<p><br></p>"),J(i.current,o),v(i.current),b&&r&&r(b)},[]),d.useEffect(()=>{!i.current||!F||(a!==i.current.innerHTML&&(i.current.innerHTML=a),J(i.current,o),v(i.current))},[a,F]),d.useEffect(()=>{if(!i.current)return;const b=i.current;if(o){b.setAttribute("data-placeholder",o),Z(b)&&(b.innerHTML=""),J(b,o),v(b);return}b.removeAttribute("data-placeholder"),J(b,o),v(b)},[o]),d.useEffect(()=>{if(!i.current)return;const b=i.current;if((l==null?void 0:l.enableARIA)!==!1){b.setAttribute("role","textbox"),b.setAttribute("aria-multiline","true"),b.setAttribute("aria-disabled",n?"true":"false");const w=o==null?void 0:o.trim();w?b.setAttribute("aria-label",w):b.removeAttribute("aria-label")}else b.removeAttribute("role"),b.removeAttribute("aria-multiline"),b.removeAttribute("aria-label"),b.removeAttribute("aria-disabled")},[l==null?void 0:l.enableARIA,o,n]),d.useEffect(()=>{v(i.current)},[y,C,h,a]),d.useEffect(()=>{if(!i.current)return;const b=()=>{if(!i.current||n)return;o&&Z(i.current)&&(i.current.innerHTML="");let k=i.current.innerHTML;if((u==null?void 0:u.sanitizeOnInput)!==!1&&(c==null?void 0:c.sanitize)!==!1){const S=we(k,c,u);if(S!==i.current.innerHTML){const _=Pe(i.current),P=i.current.innerHTML,q=we(P,c,u);i.current.innerHTML=q,qe(i.current,_)||Ue(i.current,(_==null?void 0:_.fallbackOffsets)||null),$e(i.current),k=i.current.innerHTML}else k=S}J(i.current,o),v(i.current),r&&(g!=null&&g.debounceInputMs?(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{r(k)},g.debounceInputMs)):r(k))},L=k=>{var q,B;if(k.__editoraSmartPasteHandled===!0||k.defaultPrevented)return;if(n){k.preventDefault();return}k.preventDefault();let S=(q=k.clipboardData)==null?void 0:q.getData("text/html");const _=(B=k.clipboardData)==null?void 0:B.getData("text/plain"),P=!!S&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S);if(f!=null&&f.clean||!(f!=null&&f.keepFormatting)){_&&document.execCommand("insertText",!1,_);return}if((f==null?void 0:f.convertWord)===!1&&P){_&&document.execCommand("insertText",!1,_);return}if(S){(u==null?void 0:u.sanitizeOnPaste)!==!1&&(c==null?void 0:c.sanitize)!==!1&&(S=We(S,c,u));const O=window.getSelection();if(O&&O.rangeCount>0){const $=O.getRangeAt(0);$.deleteContents();const V=document.createElement("div");V.innerHTML=S;const Q=document.createDocumentFragment();for(;V.firstChild;)Q.appendChild(V.firstChild);$.insertNode(Q),$.collapse(!1),O.removeAllRanges(),O.addRange($)}}else _&&document.execCommand("insertText",!1,_)},w=k=>{const S=k.target;(S.tagName==="IMG"||S.tagName==="VIDEO")&&(S.style.resize="both",S.style.overflow="auto",S.style.display="inline-block")},p=k=>{(A==null?void 0:A.enabled)===!1&&k.preventDefault()},j=()=>{i.current&&(o&&Z(i.current)&&(i.current.innerHTML=""),J(i.current,o),v(i.current))},R=i.current;return R.addEventListener("input",b),R.addEventListener("paste",L),R.addEventListener("click",w),R.addEventListener("contextmenu",p),R.addEventListener("focus",j),R.addEventListener("blur",j),n||R.focus(),()=>{H.current&&clearTimeout(H.current),R.removeEventListener("input",b),R.removeEventListener("paste",L),R.removeEventListener("click",w),R.removeEventListener("contextmenu",p),R.removeEventListener("focus",j),R.removeEventListener("blur",j)}},[e,r,f,c,u,g,o,A,n]);const T=((M==null?void 0:M.enabled)??!1)&&((M==null?void 0:M.provider)??"browser")==="browser";return d.useEffect(()=>{if(!i.current||typeof window>"u"||n||(l==null?void 0:l.keyboardNavigation)===!1)return;const b=new K.KeyboardShortcutManager,L=i.current,w=p=>{b.handleKeyDown(p,(j,R)=>{var k;if(typeof window<"u"&&window.executeEditorCommand){const S=(k=i.current)==null?void 0:k.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=S||null,window.executeEditorCommand(j,R)}})};return L.addEventListener("keydown",w),()=>{L.removeEventListener("keydown",w)}},[l==null?void 0:l.keyboardNavigation,n]),m.jsx("div",{ref:i,contentEditable:!n,suppressContentEditableWarning:!0,spellCheck:n?!1:T,tabIndex:(l==null?void 0:l.keyboardNavigation)===!1?-1:0,"aria-keyshortcuts":(l==null?void 0:l.keyboardNavigation)===!1?void 0:"Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y","data-viewport-only-scan":g!=null&&g.viewportOnlyScan?"true":"false","data-a11y-checker":l!=null&&l.checker?"true":"false","data-readonly":n?"true":"false",className:`rte-content ${n?"rte-content-readonly":""}`,style:{minHeight:`${C}px`,maxHeight:y?h>0?`${h}px`:"none":"100%",padding:"16px",outline:"none",border:"1px solid #ddd",borderRadius:"0px 0px 4px 4px",fontSize:"14px",lineHeight:"1.5",overflow:y?h>0?"auto":"hidden":"auto",flex:y?void 0:1,boxSizing:"border-box",wordWrap:"break-word",overflowWrap:"break-word",marginBottom:"16px"}})},Ke=({editor:e,isEnabled:t,viewportOnlyScan:a=!0,readonly:n=!1})=>{const[o,r]=d.useState(!1),[f,c]=d.useState({top:0,left:0}),u=d.useRef(null),g=d.useRef(null),l=d.useRef(null),N=d.useRef(null),A=d.useRef(null);d.useEffect(()=>{var L;if(!t||n){r(!1);return}A.current=(L=u.current)==null?void 0:L.closest("[data-editora-editor]");const i=w=>{var S;if(A.current)return A.current;const p=(S=u.current)==null?void 0:S.closest("[data-editora-editor]");if(p)return A.current=p,p;const j=w==null?void 0:w.commonAncestorContainer,R=j?j.nodeType===Node.ELEMENT_NODE?j:j.parentElement:null,k=R==null?void 0:R.closest("[data-editora-editor]");return k?(A.current=k,k):null},F=w=>w&&w.querySelector(".rte-content, .editora-content")||null,H=w=>{if(!w||n)return!0;const p=w.getAttribute("contenteditable"),j=w.getAttribute("data-readonly");return p==="false"||j==="true"?!0:!!w.closest('[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]')},y=w=>{if(!w.anchorNode||!w.focusNode)return!1;try{const p=document.createRange();return p.setStart(w.anchorNode,w.anchorOffset),p.setEnd(w.focusNode,w.focusOffset),p.collapsed}catch{return!1}},C=(w,p)=>{const j=Array.from(p.getClientRects()).filter(k=>k.width>0||k.height>0);return j.length===0?p.getBoundingClientRect():y(w)?j[0]:j[j.length-1]},h=()=>{N.current&&clearTimeout(N.current);const w=window.getSelection();if(!w||w.rangeCount===0){r(!1),l.current=null;return}const p=w.getRangeAt(0);if(p.collapsed){r(!1),l.current=null;return}const j=w.toString().trim(),R=i(p),k=F(R);if(!k||!k.contains(p.commonAncestorContainer)){r(!1),l.current=null;return}if(H(k)){r(!1),l.current=null;return}if(a){const S=k.getBoundingClientRect(),_=S.bottom>=0&&S.top<=window.innerHeight,P=document.activeElement===k||k.contains(document.activeElement);if(!_&&!P){r(!1),l.current=null;return}}if(j.length>0){const S=C(w,p),_=k.getBoundingClientRect(),P=300;if(S&&_){const q=Math.max(8,S.top-50);let B=S.left+S.width/2;const O=P/2,$=_.left,V=_.right;B-O<$&&(B=$+O+10),B+O>V&&(B=V-O-10),c({top:q,left:B}),r(!0),l.current=p.cloneRange()}}else r(!1),l.current=null},v=w=>{var p;if(g.current&&!g.current.contains(w.target)){const j=i();window.getSelection(),((p=F(j))==null?void 0:p.contains(w.target))||(r(!1),l.current=null)}},I=w=>{w.key==="Escape"&&(r(!1),l.current=null)},T=F(i()),b=T&&typeof MutationObserver<"u"?new MutationObserver(()=>{H(T)&&(r(!1),l.current=null)}):null;return b&&T&&b.observe(T,{attributes:!0,attributeFilter:["contenteditable","data-readonly"]}),document.addEventListener("selectionchange",h),document.addEventListener("mousedown",v),document.addEventListener("keydown",I),T==null||T.addEventListener("mouseup",h),T==null||T.addEventListener("keyup",h),()=>{document.removeEventListener("selectionchange",h),document.removeEventListener("mousedown",v),document.removeEventListener("keydown",I),T==null||T.removeEventListener("mouseup",h),T==null||T.removeEventListener("keyup",h),b==null||b.disconnect(),N.current&&clearTimeout(N.current)}},[t,a,n]);const M=(i,F)=>{var h,v;if(n||!l.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=A.current||null);const H=(h=A.current)==null?void 0:h.querySelector(".rte-content, .editora-content");if(H&&(H.getAttribute("contenteditable")==="false"||H.getAttribute("data-readonly")==="true")){r(!1),l.current=null;return}H&&H.focus();const y=window.getSelection();if(y&&l.current)try{y.removeAllRanges(),y.addRange(l.current)}catch{}const C={toggleBold:()=>document.execCommand("bold",!1),toggleItalic:()=>document.execCommand("italic",!1),toggleUnderline:()=>document.execCommand("underline",!1),toggleStrikethrough:()=>document.execCommand("strikeThrough",!1),createLink:()=>{typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand("openLinkDialog")},clearFormatting:()=>{document.execCommand("removeFormat",!1),document.execCommand("unlink",!1)},toggleCode:()=>{const I=window.getSelection();if(I&&I.rangeCount>0){const T=I.getRangeAt(0),b=document.createElement("code");T.surroundContents(b)}},setBlockType:()=>{var I;if(F==="blockquote"){const T=window.getSelection();if(T&&T.rangeCount>0){const b=T.getRangeAt(0),L=b.commonAncestorContainer.nodeType===Node.TEXT_NODE?b.commonAncestorContainer.parentElement:b.commonAncestorContainer;((I=L==null?void 0:L.closest)==null?void 0:I.call(L,"blockquote"))?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else F&&document.execCommand("formatBlock",!1,F)}};(v=C[i])==null||v.call(C),r(!1),l.current=null};return!t||n?m.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}):m.jsxs(m.Fragment,{children:[m.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}),o&&m.jsxs("div",{ref:g,className:"floating-toolbar",onMouseDown:i=>i.preventDefault(),style:{position:"fixed",top:`${f.top}px`,left:`${f.left}px`,transform:"translateX(-50%)",zIndex:1e4,display:"flex"},children:[m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleBold"),title:"Bold (Ctrl+B)",children:m.jsx("strong",{children:"B"})}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleItalic"),title:"Italic (Ctrl+I)",children:m.jsx("em",{children:"I"})}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleUnderline"),title:"Underline (Ctrl+U)",children:m.jsx("u",{children:"U"})}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleStrikethrough"),title:"Strikethrough",children:m.jsx("s",{children:"S"})}),m.jsx("div",{className:"floating-toolbar-separator"}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("clearFormatting"),title:"Clear Formatting",children:"⌫"}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("createLink"),title:"Insert Link",children:"🔗"}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleCode"),title:"Code",children:"Code"}),m.jsx("div",{className:"floating-toolbar-separator"}),m.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},Ve=({plugins:e,children:t})=>{const a=e.filter(o=>{var r;return(r=o.context)==null?void 0:r.provider});return a.length===0?m.jsx(m.Fragment,{children:t}):a.reduce((o,r)=>{const f=r.context.provider;return m.jsx(f,{children:o},r.name)},m.jsx(m.Fragment,{children:t}))},Ee=new Set,pe=new Set,se=e=>!!e&&typeof e=="object"&&typeof e.name=="string",Re=e=>{const t=e==null?void 0:e.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},Ge=(e,t)=>{if(!Array.isArray(e))return[];const a=Re(t),n=[],o=[];if(e.forEach(r=>{if(se(r)){n.push(r);return}if(typeof r!="string")return;const f=a[r];if(typeof f=="function")try{const c=f();if(se(c)){n.push(c);return}}catch{}o.push(r)}),o.length>0){const r=o.slice().sort().join("|");Ee.has(r)||(Ee.add(r),console.warn(`[Editora React] Unresolved string plugin names: ${o.join(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return n},Xe=(e,t,a)=>{if(!(t!=null&&t.checker)||e.some(r=>(r==null?void 0:r.name)==="a11yChecker"))return e;const n=Re(a).a11yChecker;if(typeof n=="function")try{const r=n();if(se(r))return[...e,r]}catch{}const o="accessibility.checker";return pe.has(o)||(pe.add(o),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},Je={readonly:!1,placeholder:"",toolbar:{items:[],floating:!1,sticky:!1,showMoreOptions:!0},statusbar:{enabled:!1,position:"bottom"},menubar:{enabled:!1,items:[]},contextMenu:{enabled:!0},media:{uploadUrl:"",libraryUrl:"",maxFileSize:10*1024*1024,allowedTypes:["image/jpeg","image/png","image/gif","image/webp"],headers:{},withCredentials:!1},paste:{clean:!0,keepFormatting:!1,convertWord:!0},history:{maxSteps:100,debounceMs:300},language:{locale:"en",direction:"ltr"},spellcheck:{enabled:!1,provider:"browser",apiUrl:"",apiHeaders:{}},autosave:{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""},accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},content:{allowedTags:[],allowedAttributes:{},sanitize:!0,autoHeight:!1,minHeight:200,maxHeight:0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0}};function Ae(e,t){const a={...e};for(const n in t){const o=t[n],r=a[n];o!==void 0&&(typeof o=="object"&&o!==null&&!Array.isArray(o)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?a[n]=Ae(r,o):a[n]=o)}return a}function Te(e){const t=Ae(Je,{readonly:e.readonly,placeholder:e.placeholder,toolbar:e.toolbar,statusbar:e.statusbar,menubar:e.menubar,contextMenu:e.contextMenu,media:e.media,paste:e.paste,history:e.history,language:e.language,spellcheck:e.spellcheck,autosave:e.autosave,accessibility:e.accessibility,performance:e.performance,content:e.content,security:e.security});if(e.floatingToolbar!==void 0){const n=typeof e.floatingToolbar=="boolean"?e.floatingToolbar:e.floatingToolbar.enabled;t.toolbar={...t.toolbar,floating:n??t.toolbar.floating}}return e.mediaConfig&&(t.media={...t.media,uploadUrl:e.mediaConfig.uploadUrl||t.media.uploadUrl,libraryUrl:e.mediaConfig.libraryUrl||t.media.libraryUrl,maxFileSize:e.mediaConfig.maxFileSize||t.media.maxFileSize,allowedTypes:e.mediaConfig.allowedTypes||t.media.allowedTypes}),{...t,id:e.id,className:e.className,value:e.value,defaultValue:e.defaultValue,onChange:e.onChange,onInit:e.onInit,onDestroy:e.onDestroy,plugins:Xe(Ge(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const le=new Map,Qe=()=>{if(typeof window>"u")return{editorElement:null,contentElement:null};let e=window.__editoraCommandEditorRoot||null;if(!e){const a=window.__editoraLastCommandButton||null;e=(a==null?void 0:a.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor"))||null}const t=(e==null?void 0:e.querySelector(".rte-content, .editora-content"))||(e!=null&&e.matches(".rte-content, .editora-content")?e:null);return{editorElement:e,contentElement:t}};typeof window<"u"&&(window.registerEditorCommand=(e,t)=>{le.set(e,t)},window.executeEditorCommand=(e,t)=>{const a=le.get(e);if(a){const n=Qe();return a(t,n)}else return console.warn(`No handler registered for command: ${e}`),!1});const Ye=e=>{const t=d.useMemo(()=>Te(e),[e.id,e.className,e.value,e.defaultValue,e.readonly,e.placeholder,e.plugins,e.toolbar,e.menubar,e.contextMenu,e.media,e.paste,e.history,e.language,e.spellcheck,e.autosave,e.accessibility,e.performance,e.content,e.security,e.floatingToolbar,e.mediaConfig]),a=d.useRef(null),n=d.useRef(null),o=d.useRef(e.onInit),r=d.useRef(e.onDestroy),f=d.useRef(e.onChange),c=d.useRef(new Set),u=d.useRef(null),g=d.useRef(null),l=d.useRef(null);d.useEffect(()=>{o.current=e.onInit,r.current=e.onDestroy,f.current=e.onChange});const N=y=>{var C;(C=f.current)==null||C.call(f,y),c.current.forEach(h=>{try{h(y)}catch(v){console.error("Editora onChange subscriber failed:",v)}})},A=d.useMemo(()=>{const y=new K.PluginManager;t.plugins.forEach(h=>{y.register(h),h.commands&&typeof window<"u"&&Object.entries(h.commands).forEach(([v,I])=>{le.set(v,I)})});const C=new K.Editor(y);return a.current=C,C},[t.plugins]);d.useEffect(()=>{var C;const y={getHTML:()=>{var v;const h=(v=u.current)==null?void 0:v.querySelector(".rte-content");return(h==null?void 0:h.innerHTML)||""},setHTML:h=>{var I;const v=(I=u.current)==null?void 0:I.querySelector(".rte-content");v&&(v.innerHTML=h)},execCommand:(h,v)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=u.current||null,window.executeEditorCommand(h,v))},registerCommand:(h,v)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(h,v)},focus:()=>{var v;const h=(v=u.current)==null?void 0:v.querySelector(".rte-content");h==null||h.focus()},blur:()=>{var v;const h=(v=u.current)==null?void 0:v.querySelector(".rte-content");h==null||h.blur()},destroy:()=>{r.current&&r.current()},onChange:h=>(c.current.add(h),()=>{c.current.delete(h)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:((C=A.toolbar)==null?void 0:C.items)||[]}};return n.current=y,o.current&&o.current(y),()=>{c.current.clear(),r.current&&r.current()}},[]),d.useEffect(()=>{if(t.statusbar.enabled&&l.current&&u.current){g.current||(g.current=new K.StatusBar({enabled:!0,position:t.statusbar.position}),g.current.create(l.current));const y=u.current.querySelector(".rte-content");if(y){const C=()=>{const p=document.activeElement;return!!p&&(p===y||y.contains(p))},h=()=>{const p=y.getBoundingClientRect();return p.bottom>=0&&p.top<=window.innerHeight},v=()=>{const p=window.getSelection();if(!p||p.rangeCount===0)return null;const j=p.getRangeAt(0),R=j.commonAncestorContainer;return y.contains(R)?j:null},I=(p=!1)=>{var $;if(t.performance.viewportOnlyScan!==!1&&!h()&&!C())return;const R=v(),k=!!R||C();if(p&&!k)return;const S=y.textContent||"",{words:_,chars:P}=K.calculateTextStats(S),q=K.countLines(y);let B,O;R&&(B=K.getCursorPosition(y,R),R.collapsed||(O=K.getSelectionInfo(R,B),B=void 0)),($=g.current)==null||$.update({wordCount:_,charCount:P,lineCount:q,cursorPosition:B,selectionInfo:O})},T=()=>I(),b=()=>I(!0),L=()=>I(),w=()=>I();return y.addEventListener("input",T),y.addEventListener("focus",L),y.addEventListener("blur",w),document.addEventListener("selectionchange",b),I(),()=>{y.removeEventListener("input",T),y.removeEventListener("focus",L),y.removeEventListener("blur",w),document.removeEventListener("selectionchange",b)}}}else g.current&&(g.current.destroy(),g.current=null);return()=>{g.current&&(g.current.destroy(),g.current=null)}},[t.statusbar.enabled,t.statusbar.position,t.performance.viewportOnlyScan]);const M=t.toolbar.floating??!1,i=t.toolbar.position||"top",F=t.toolbar.sticky??!1,H=t.toolbar.showMoreOptions??!0;return m.jsx(Ve,{plugins:t.plugins,children:m.jsxs("div",{ref:u,id:t.id,"data-editora-editor":!0,"data-readonly":t.readonly?"true":"false",className:`rte-editor ${t.className||""}`,lang:t.language.locale,dir:t.language.direction,style:{display:"flex",flexDirection:"column",height:"100%"},children:[i!=="bottom"&&m.jsx(ae,{editor:A,position:i,sticky:F,floating:M,readonly:t.readonly,showMoreOptions:H,itemsOverride:t.toolbar.items}),m.jsx(ke,{editor:A,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:N,pasteConfig:t.paste,contentConfig:t.content,securityConfig:t.security,performanceConfig:t.performance,accessibilityConfig:t.accessibility,autosaveConfig:t.autosave,contextMenuConfig:t.contextMenu,spellcheckConfig:t.spellcheck}),i==="bottom"&&m.jsx(ae,{editor:A,position:i,sticky:F,floating:M,readonly:t.readonly,showMoreOptions:H,itemsOverride:t.toolbar.items}),m.jsx(Ke,{editor:A,isEnabled:M,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&m.jsx("div",{ref:l,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},Le=e=>m.jsx(Ye,{...e});function Ze(e={}){const t=d.useRef(null),a=d.useRef(e.onCommand);return d.useEffect(()=>{a.current=e.onCommand}),d.useEffect(()=>{if(typeof window>"u"||e.enabled===!1)return;const n=new K.KeyboardShortcutManager(e);t.current=n;const o=f=>n.handleKeyDown(f,(u,g)=>{a.current&&a.current(u,g),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(u,g)}),r=e.editorElement||document;return r&&r.addEventListener("keydown",o),()=>{r&&r.removeEventListener("keydown",o)}},[e.editorElement,e.enabled,e.shortcuts,e.customShortcuts]),{getShortcuts:()=>{var n;return((n=t.current)==null?void 0:n.getAllShortcuts())||[]},getShortcutForCommand:n=>{var o;return(o=t.current)==null?void 0:o.getShortcutForCommand(n)},getShortcutsHelp:()=>{var n;return((n=t.current)==null?void 0:n.getShortcutsHelp())||""},enable:()=>{var n;return(n=t.current)==null?void 0:n.enable()},disable:()=>{var n;return(n=t.current)==null?void 0:n.disable()},isEnabled:()=>{var n;return((n=t.current)==null?void 0:n.isEnabled())||!1}}}exports.EditorContent=ke;exports.EditoraEditor=Le;exports.InlineMenu=xe;exports.RichTextEditor=Le;exports.Toolbar=ae;exports.mergeConfig=Te;exports.useKeyboardShortcuts=Ze;
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react/jsx-runtime"),c=require("react"),q=require("@editora/core"),Ne=e=>e&&e.__esModule?e:{default:e},je=Ne(c),pe=({isOpen:e,options:t,onSelect:a,onClose:o,anchorRef:r,className:n=""})=>{const m=c.useRef(null),[g,u]=c.useState(null),h=()=>{if(!e||!r.current)return;const l=r.current.getBoundingClientRect(),L=m.current?.getBoundingClientRect(),R=L?.width||120,T=L?.height||t.length*36,s=8,D=4,I=window.innerWidth,p=window.innerHeight;let E=l.bottom+D,b=l.left;b+R>I-s&&(b=I-R-s),b<s&&(b=s),E+T>p-s&&(E=l.top-T-D),E<s&&(E=s),u({top:E,left:b})};return c.useLayoutEffect(()=>{if(!e){u(null);return}h();const l=window.requestAnimationFrame(h);return()=>{window.cancelAnimationFrame(l)}},[e,t.length,r]),c.useEffect(()=>{if(!e)return;const l=()=>{h()};return window.addEventListener("resize",l),window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("resize",l),window.removeEventListener("scroll",l,!0)}},[e,t.length,r]),c.useEffect(()=>{const l=R=>{m.current&&!m.current.contains(R.target)&&r.current&&!r.current.contains(R.target)&&o()},L=R=>{R.key==="Escape"&&o()};return e&&(document.addEventListener("mousedown",l),document.addEventListener("keydown",L)),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",L)}},[e,o,r]),e?d.jsx("div",{ref:m,className:`rte-inline-menu ${n}`,style:{top:g?.top??-9999,left:g?.left??-9999,visibility:g?"visible":"hidden"},children:t.map(l=>d.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{a(l.value),o()},children:l.label},l.value))}):null},X=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),De={undo:"undo",redo:"redo",bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",textcolor:"openTextColorPicker",backgroundcolor:"openBackgroundColorPicker",fontsize:"setFontSize",increasefontsize:"increaseFontSize",decreasefontsize:"decreaseFontSize",heading:"setHeading",paragraph:"setHeading",textalignment:"setTextAlignment",direction:"setDirectionLTR",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",indent:"increaseIndent",outdent:"decreaseIndent",link:"openLinkDialog",image:"insertImage",video:"insertVideo",table:"insertTable",trackchanges:"toggleTrackChanges",accepttrackchanges:"acceptAllTrackChanges",rejecttrackchanges:"rejectAllTrackChanges",clearformatting:"clearFormatting",databinding:"openDataBindingDialog",databindingpreview:"openDataBindingDialog"},He=(e,t)=>{if(!Array.isArray(t)||t.length===0)return e;if(!t.every(u=>typeof u=="string"))return t;const o=new Map,r=new Map;e.forEach(u=>{o.set(X(u.command||""),u),r.set(X(u.label||""),u)});const n=t.flatMap(u=>u.split(/\s+/)).map(u=>u.trim()).filter(Boolean),m=[];let g=0;return n.forEach(u=>{if(u==="|"){g+=1,m.push({type:"separator",command:`__separator__${g}`,label:"|"});return}const h=X(u),l=De[h],L=o.get(h)||(l?o.get(X(l)):void 0)||r.get(h)||e.find(R=>X(R.command||"").includes(h));L&&m.push(L)}),m.length>0?m:e},ne=({editor:e,position:t="top",sticky:a=!1,floating:o=!1,readonly:r=!1,showMoreOptions:n=!0,itemsOverride:m})=>{const[g,u]=c.useState(!1),[h,l]=c.useState(null),[L,R]=c.useState(null),[T,s]=c.useState(null),[D,I]=c.useState(!1),p=c.useRef(null),E=c.useRef(null),b=c.useRef({}),M=c.useRef([]),N=c.useRef(null),F=c.useRef(null),w=c.useRef(null),f=c.useMemo(()=>He(e.pluginManager.getToolbarItems(),m),[e,m]),C=i=>{p.current=i,i&&!i.collapsed&&(E.current=i)},x=()=>N.current?.closest("[data-editora-editor]")?.querySelector(".rte-content")||null,_=()=>{if(typeof window>"u")return;const i=N.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=i||null},y=i=>{if(typeof window>"u"||!i)return;const k=i.getAttribute("data-command");k&&(window.__editoraLastCommandButton=i,window.__editoraLastCommand=k)},A=()=>{const i=x();if(!i)return null;const k=window.getSelection();if(!k||k.rangeCount===0)return null;const v=k.getRangeAt(0);return i.contains(v.commonAncestorContainer)?v.cloneRange():null},S=()=>{const i=A();i&&C(i)};c.useEffect(()=>{const i=N.current?.closest("[data-editora-editor]");if(!i)return;const k=i.querySelector(".rte-content, .editora-content");u(k?.getAttribute("data-track-changes")==="true");const v=W=>{u(!!W.detail?.enabled)};return i.addEventListener("editora:track-changes-toggle",v),()=>{i.removeEventListener("editora:track-changes-toggle",v)}},[]),c.useEffect(()=>{const i=()=>{S()};return document.addEventListener("selectionchange",i),()=>{document.removeEventListener("selectionchange",i)}},[]),c.useEffect(()=>{if(!h)return;const i=v=>{const W=v.target;W&&W instanceof Element&&(W.closest(".rte-toolbar-dropdown")||l(null))},k=v=>{v.key==="Escape"&&l(null)};return document.addEventListener("pointerdown",i,!0),document.addEventListener("keydown",k),()=>{document.removeEventListener("pointerdown",i,!0),document.removeEventListener("keydown",k)}},[h]);const z=i=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(i),$=(i=!1)=>{const k=x();if(!k)return!1;const v=window.getSelection();if(!v)return!1;const W=v.rangeCount>0&&k.contains(v.getRangeAt(0).commonAncestorContainer),j=i?E.current||p.current:p.current||E.current;if(i&&j&&j.collapsed)return!1;if(j&&k.contains(j.commonAncestorContainer))try{return k.focus({preventScroll:!0}),v.removeAllRanges(),v.addRange(j),!0}catch{}return W};c.useEffect(()=>{if(!n){s(null),I(!1),M.current=[];return}let i=null;const k=()=>{if(!N.current||!F.current)return;const j=N.current.clientWidth,U=16,O=40,J=4,Ie=Math.max(0,j-U-O-J);let ue=0,de=0;const Z=F.current.children;for(let K=0;K<Z.length;K++){const ee=Z[K].getBoundingClientRect().width;ee>0&&(M.current[K]=ee);const me=M.current[K]??ee,ge=(me>0?me:40)+J;if(ue+ge<=Ie)ue+=ge,de++;else break}const fe=Math.max(1,Math.min(de,Z.length));s(K=>K===fe?K:fe)},v=()=>{i!==null&&cancelAnimationFrame(i),i=requestAnimationFrame(k)};M.current=[],v();const W=new ResizeObserver(()=>{v()});return N.current&&W.observe(N.current),F.current&&W.observe(F.current),()=>{i!==null&&cancelAnimationFrame(i),W.disconnect()}},[f.length,n]),c.useEffect(()=>{D&&T!==null&&T>=f.length&&I(!1)},[D,T,f.length]);const B=i=>(b.current[i]||(b.current[i]=je.default.createRef()),b.current[i]),H=(i,k)=>{if(r)return;_(),i==="addComment"||i==="toggleComments"||$(z(i));const j={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[i];if(j){document.execCommand(j,!1),l(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(i,k),l(null)},P=i=>{r||(S(),l(h===i?null:i))},V=i=>{r||(S(),R(L===i?null:i),l(null))},Ae=(i,k)=>{r||($(),H(i,k),C(null),E.current=null,R(null))},le=(i,k)=>i&&i.startsWith("<svg")&&i.endsWith("</svg>")?d.jsx("span",{dangerouslySetInnerHTML:{__html:i}}):i&&i.length===1&&/^[BIUSH]$/.test(i)?d.jsx("span",{style:{fontWeight:"bold",fontSize:"14px",lineHeight:"1"},children:i}):i||"⚪",Te={...a&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},ce=n&&T!==null&&T<f.length,Le=i=>{if(r)return;const k=i.target;k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")&&(y(k.closest("[data-command]")),_(),S(),i.preventDefault())},Y=(i,k=!0)=>i.map((v,W)=>{const j=v.command||"",U=j==="toggleTrackChanges"&&g;return d.jsx("div",{className:"rte-toolbar-item",style:{display:k&&n&&T!==null&&W>=T?"none":"flex"},children:v.type==="separator"?d.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):v.type==="dropdown"?d.jsxs("div",{className:"rte-toolbar-dropdown",children:[d.jsxs("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>P(j),disabled:r,children:[v.label," ▼"]}),h===j&&d.jsx("div",{className:"rte-toolbar-dropdown-menu",children:v.options?.map(O=>d.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:J=>J.preventDefault(),onClick:()=>H(j,O.value),children:O.label},O.value))})]}):v.type==="inline-menu"?d.jsx("button",{ref:B(j),className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>V(j),disabled:r,title:v.label,children:le(v.icon)}):v.type==="input"?d.jsx("input",{type:"text",className:`rte-toolbar-input ${v.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:v.placeholder,onChange:O=>H(j,O.target.value),disabled:r,onKeyDown:O=>{O.key==="Enter"&&H(j,O.target.value)},title:v.label}):v.type==="group"?d.jsx("div",{className:`rte-toolbar-group-button ${v.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${v.label}`,children:d.jsx("div",{className:`rte-toolbar-group-items ${v.label.toLowerCase().replace(/\s+/g,"-")}`,children:Y(v.items||[],!1)})}):d.jsx("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>H(j),disabled:r,title:v.label,children:le(v.icon)})},W)}),Me=n&&T!==null?f.filter((i,k)=>k>=T):[];return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"rte-toolbar-wrapper",style:Te,onMouseDownCapture:Le,children:[d.jsxs("div",{className:"rte-toolbar",ref:N,children:[d.jsx("div",{className:"rte-toolbar-items-container",ref:F,style:n?void 0:{flexWrap:"wrap"},children:Y(f)}),ce&&d.jsx("button",{ref:w,className:`rte-toolbar-more-button ${D?"active":""}`,onMouseDown:i=>{i.preventDefault(),S()},onClick:()=>I(!D),disabled:r,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),ce&&d.jsx("div",{className:`rte-toolbar-expanded-row ${D?"show":""}`,children:Y(Me,!1)})]}),f.map(i=>{if(i.type==="inline-menu"){const k=i.command||"";return d.jsx(pe,{isOpen:L===k,options:i.options||[],onSelect:v=>Ae(k,v),onClose:()=>R(null),anchorRef:B(k)},`menu-${k||"unknown"}`)}return null})]})};function Fe(e,t){const a=c.useRef(),o=c.useRef("");return c.useEffect(()=>{if(!t?.enabled)return;const n=t.intervalMs||3e4,m=t.storageKey||"rte-autosave",g=t.provider||"localStorage",u=async()=>{const h=e();if(h!==o.current){if(o.current=h,g==="localStorage")try{localStorage.setItem(m,h),localStorage.setItem(`${m}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(l){console.error("[Autosave] Failed to save to localStorage:",l)}else if(g==="api"&&t.apiUrl)try{await fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:h,timestamp:Date.now()})}),console.log("[Autosave] Content saved to API")}catch(l){console.error("[Autosave] Failed to save to API:",l)}}};return a.current=setInterval(u,n),()=>{a.current&&clearInterval(a.current)}},[t?.enabled,t?.intervalMs,t?.storageKey,t?.provider,t?.apiUrl,e]),{restore:()=>{if(!t?.enabled)return null;const n=t.storageKey||"rte-autosave";if((t.provider||"localStorage")==="localStorage")try{const g=localStorage.getItem(n),u=localStorage.getItem(`${n}-timestamp`);if(g&&u)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(u))),g}catch(g){console.error("[Autosave] Failed to restore from localStorage:",g)}return null}}}const _e=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","section","sup","sub","hr"],Be={"*":["class","style","id","data-*","role","aria-*","tabindex","contenteditable","spellcheck"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function ye(e,t,a){if(t?.sanitize===!1)return e;const o=t?.allowedTags&&t.allowedTags.length>0?t.allowedTags:_e,n=!!t?.allowedAttributes&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:Be,m=document.createElement("div");return m.innerHTML=e,Ee(m,o,n),m.innerHTML}function Ee(e,t,a){const o=Array.from(e.childNodes);for(const r of o)if(r.nodeType===Node.ELEMENT_NODE){const n=r,m=n.tagName.toLowerCase();if(!t.includes(m)){for(;n.firstChild;)e.insertBefore(n.firstChild,n);e.removeChild(n);continue}ze(n,a),Ee(n,t,a)}else{if(r.nodeType===Node.TEXT_NODE)continue;e.removeChild(r)}}function ze(e,t){const a=e.tagName.toLowerCase(),o=Array.from(e.attributes),r=t[a]||[],n=t["*"]||[],m=[...r,...n];for(const g of o){const u=g.name.toLowerCase();let h=!1;m.includes(u)&&(h=!0);for(const l of m)if(l.endsWith("*")){const L=l.slice(0,-1);if(u.startsWith(L)){h=!0;break}}(u.startsWith("on")||u==="javascript:"||u==="href"&&g.value.trim().toLowerCase().startsWith("javascript:")||u==="src"&&g.value.trim().toLowerCase().startsWith("javascript:"))&&(h=!1),h||e.removeAttribute(g.name)}e.hasAttribute("href")&&(e.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("href"),e.hasAttribute("src")&&(e.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("src")}function Oe(e,t,a){return a?.sanitizeOnPaste===!1?e:ye(e,t)}function he(e,t,a){return a?.sanitizeOnInput===!1?e:ye(e,t)}const Q=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),G=(e,t)=>{const o=!!t&&Q(e);e.classList.toggle("rte-content-empty",o)},ae="data-rte-caret-marker",ie="data-rte-range-start-marker",se="data-rte-range-end-marker",te=()=>Math.random().toString(36).slice(2),We=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;try{const o=a.cloneRange();o.selectNodeContents(e),o.setEnd(a.startContainer,a.startOffset);const r=a.cloneRange();return r.selectNodeContents(e),r.setEnd(a.endContainer,a.endOffset),{start:o.toString().length,end:r.toString().length}}catch{return null}},be=(e,t)=>{const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let o=a.nextNode(),r=Math.max(0,t),n=null;for(;o;){n=o;const m=o.textContent?.length??0;if(r<=m)return{node:o,offset:r};r-=m,o=a.nextNode()}return n?{node:n,offset:n.textContent?.length??0}:{node:e,offset:e.childNodes.length}},Pe=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;const o=We(e);try{if(a.collapsed){const l=te(),L=document.createElement("span");return L.setAttribute(ae,l),L.appendChild(document.createTextNode("​")),a.cloneRange().insertNode(L),{collapsed:!0,caretId:l,fallbackOffsets:o}}const r=te(),n=te(),m=document.createElement("span");m.setAttribute(se,n),m.appendChild(document.createTextNode("​"));const g=document.createElement("span");g.setAttribute(ie,r),g.appendChild(document.createTextNode("​"));const u=a.cloneRange();u.collapse(!1),u.insertNode(m);const h=a.cloneRange();return h.collapse(!0),h.insertNode(g),{collapsed:!1,startId:r,endId:n,fallbackOffsets:o}}catch{return{collapsed:a.collapsed,fallbackOffsets:o}}},$e=e=>{e.querySelectorAll(`[${ae}], [${ie}], [${se}]`).forEach(t=>t.remove())},qe=(e,t)=>{if(!t)return!1;const a=window.getSelection();if(!a)return!1;try{const o=document.createRange();if(t.collapsed&&t.caretId){const r=e.querySelector(`[${ae}="${t.caretId}"]`);return!r||!r.parentNode?!1:(o.setStartAfter(r),o.collapse(!0),a.removeAllRanges(),a.addRange(o),!0)}if(!t.collapsed&&t.startId&&t.endId){const r=e.querySelector(`[${ie}="${t.startId}"]`),n=e.querySelector(`[${se}="${t.endId}"]`);return!r||!n||!r.parentNode||!n.parentNode?!1:(o.setStartAfter(r),o.setEndBefore(n),a.removeAllRanges(),a.addRange(o),!0)}}catch{return!1}return!1},Ue=(e,t)=>{if(!t)return;const a=window.getSelection();if(a)try{const o=be(e,t.start),r=be(e,t.end),n=document.createRange();n.setStart(o.node,o.offset),n.setEnd(r.node,r.offset),a.removeAllRanges(),a.addRange(n)}catch{}},Ce=({editor:e,defaultValue:t,value:a,readonly:o=!1,placeholder:r,onChange:n,pasteConfig:m,contentConfig:g,securityConfig:u,performanceConfig:h,accessibilityConfig:l,autosaveConfig:L,contextMenuConfig:R,spellcheckConfig:T})=>{const s=c.useRef(null),D=a!==void 0,I=c.useRef(),p=g?.autoHeight===!0,E=typeof g?.minHeight=="number"?g.minHeight:200,b=typeof g?.maxHeight=="number"?g.maxHeight:0,M=w=>{if(!w||!p)return;w.style.height="auto";const f=Math.max(E,w.scrollHeight);if(b>0){w.style.height=`${Math.min(f,b)}px`;return}w.style.height=`${f}px`},{restore:N}=Fe(()=>s.current?.innerHTML||"",L);c.useEffect(()=>{if(!s.current)return;const w=N(),f=w??a??t??"";f.trim()?s.current.innerHTML!==f&&(s.current.innerHTML=f):r?s.current.innerHTML="":s.current.innerHTML.trim()||(s.current.innerHTML="<p><br></p>"),G(s.current,r),M(s.current),w&&n&&n(w)},[]),c.useEffect(()=>{!s.current||!D||(a!==s.current.innerHTML&&(s.current.innerHTML=a),G(s.current,r),M(s.current))},[a,D]),c.useEffect(()=>{if(!s.current)return;const w=s.current;if(r){w.setAttribute("data-placeholder",r),Q(w)&&(w.innerHTML=""),G(w,r),M(w);return}w.removeAttribute("data-placeholder"),G(w,r),M(w)},[r]),c.useEffect(()=>{if(!s.current)return;const w=s.current;if(l?.enableARIA!==!1){w.setAttribute("role","textbox"),w.setAttribute("aria-multiline","true"),w.setAttribute("aria-disabled",o?"true":"false");const C=r?.trim();C?w.setAttribute("aria-label",C):w.removeAttribute("aria-label")}else w.removeAttribute("role"),w.removeAttribute("aria-multiline"),w.removeAttribute("aria-label"),w.removeAttribute("aria-disabled")},[l?.enableARIA,r,o]),c.useEffect(()=>{M(s.current)},[p,E,b,a]),c.useEffect(()=>{if(!s.current)return;const w=()=>{if(!s.current||o)return;r&&Q(s.current)&&(s.current.innerHTML="");let A=s.current.innerHTML;if(u?.sanitizeOnInput!==!1&&g?.sanitize!==!1){const S=he(A,g,u);if(S!==s.current.innerHTML){const z=Pe(s.current),$=s.current.innerHTML,B=he($,g,u);s.current.innerHTML=B,qe(s.current,z)||Ue(s.current,z?.fallbackOffsets||null),$e(s.current),A=s.current.innerHTML}else A=S}G(s.current,r),M(s.current),n&&(h?.debounceInputMs?(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{n(A)},h.debounceInputMs)):n(A))},f=A=>{if(A.__editoraSmartPasteHandled===!0||A.defaultPrevented)return;if(o){A.preventDefault();return}A.preventDefault();let S=A.clipboardData?.getData("text/html");const z=A.clipboardData?.getData("text/plain"),$=!!S&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S);if(m?.clean||!m?.keepFormatting){z&&document.execCommand("insertText",!1,z);return}if(m?.convertWord===!1&&$){z&&document.execCommand("insertText",!1,z);return}if(S){u?.sanitizeOnPaste!==!1&&g?.sanitize!==!1&&(S=Oe(S,g,u));const B=window.getSelection();if(B&&B.rangeCount>0){const H=B.getRangeAt(0);H.deleteContents();const P=document.createElement("div");P.innerHTML=S;const V=document.createDocumentFragment();for(;P.firstChild;)V.appendChild(P.firstChild);H.insertNode(V),H.collapse(!1),B.removeAllRanges(),B.addRange(H)}}else z&&document.execCommand("insertText",!1,z)},C=A=>{const S=A.target;(S.tagName==="IMG"||S.tagName==="VIDEO")&&(S.style.resize="both",S.style.overflow="auto",S.style.display="inline-block")},x=A=>{R?.enabled===!1&&A.preventDefault()},_=()=>{s.current&&(r&&Q(s.current)&&(s.current.innerHTML=""),G(s.current,r),M(s.current))},y=s.current;return y.addEventListener("input",w),y.addEventListener("paste",f),y.addEventListener("click",C),y.addEventListener("contextmenu",x),y.addEventListener("focus",_),y.addEventListener("blur",_),o||y.focus(),()=>{I.current&&clearTimeout(I.current),y.removeEventListener("input",w),y.removeEventListener("paste",f),y.removeEventListener("click",C),y.removeEventListener("contextmenu",x),y.removeEventListener("focus",_),y.removeEventListener("blur",_)}},[e,n,m,g,u,h,r,R,o]);const F=(T?.enabled??!1)&&(T?.provider??"browser")==="browser";return c.useEffect(()=>{if(!s.current||typeof window>"u"||o||l?.keyboardNavigation===!1)return;const w=new q.KeyboardShortcutManager,f=s.current,C=x=>{w.handleKeyDown(x,(_,y)=>{if(typeof window<"u"&&window.executeEditorCommand){const A=s.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=A||null,window.executeEditorCommand(_,y)}})};return f.addEventListener("keydown",C),()=>{f.removeEventListener("keydown",C)}},[l?.keyboardNavigation,o]),d.jsx("div",{ref:s,contentEditable:!o,suppressContentEditableWarning:!0,spellCheck:o?!1:F,tabIndex:l?.keyboardNavigation===!1?-1:0,"aria-keyshortcuts":l?.keyboardNavigation===!1?void 0:"Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y","data-viewport-only-scan":h?.viewportOnlyScan?"true":"false","data-a11y-checker":l?.checker?"true":"false","data-readonly":o?"true":"false",className:`rte-content ${o?"rte-content-readonly":""}`,style:{minHeight:`${E}px`,maxHeight:p?b>0?`${b}px`:"none":"100%",padding:"16px",outline:"none",border:"1px solid #ddd",borderRadius:"0px 0px 4px 4px",fontSize:"14px",lineHeight:"1.5",overflow:p?b>0?"auto":"hidden":"auto",flex:p?void 0:1,boxSizing:"border-box",wordWrap:"break-word",overflowWrap:"break-word",marginBottom:"16px"}})},Ke=({editor:e,isEnabled:t,viewportOnlyScan:a=!0,readonly:o=!1})=>{const[r,n]=c.useState(!1),[m,g]=c.useState({top:0,left:0}),u=c.useRef(null),h=c.useRef(null),l=c.useRef(null),L=c.useRef(null),R=c.useRef(null);c.useEffect(()=>{if(!t||o){n(!1);return}R.current=u.current?.closest("[data-editora-editor]");const s=f=>{if(R.current)return R.current;const C=u.current?.closest("[data-editora-editor]");if(C)return R.current=C,C;const x=f?.commonAncestorContainer,y=(x?x.nodeType===Node.ELEMENT_NODE?x:x.parentElement:null)?.closest("[data-editora-editor]");return y?(R.current=y,y):null},D=f=>f&&f.querySelector(".rte-content, .editora-content")||null,I=f=>{if(!f||o)return!0;const C=f.getAttribute("contenteditable"),x=f.getAttribute("data-readonly");return C==="false"||x==="true"?!0:!!f.closest('[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]')},p=f=>{if(!f.anchorNode||!f.focusNode)return!1;try{const C=document.createRange();return C.setStart(f.anchorNode,f.anchorOffset),C.setEnd(f.focusNode,f.focusOffset),C.collapsed}catch{return!1}},E=(f,C)=>{const x=Array.from(C.getClientRects()).filter(y=>y.width>0||y.height>0);return x.length===0?C.getBoundingClientRect():p(f)?x[0]:x[x.length-1]},b=()=>{L.current&&clearTimeout(L.current);const f=window.getSelection();if(!f||f.rangeCount===0){n(!1),l.current=null;return}const C=f.getRangeAt(0);if(C.collapsed){n(!1),l.current=null;return}const x=f.toString().trim(),_=s(C),y=D(_);if(!y||!y.contains(C.commonAncestorContainer)){n(!1),l.current=null;return}if(I(y)){n(!1),l.current=null;return}if(a){const A=y.getBoundingClientRect(),S=A.bottom>=0&&A.top<=window.innerHeight,z=document.activeElement===y||y.contains(document.activeElement);if(!S&&!z){n(!1),l.current=null;return}}if(x.length>0){const A=E(f,C),S=y.getBoundingClientRect(),z=300;if(A&&S){const $=Math.max(8,A.top-50);let B=A.left+A.width/2;const H=z/2,P=S.left,V=S.right;B-H<P&&(B=P+H+10),B+H>V&&(B=V-H-10),g({top:$,left:B}),n(!0),l.current=C.cloneRange()}}else n(!1),l.current=null},M=f=>{if(h.current&&!h.current.contains(f.target)){const C=s();window.getSelection(),D(C)?.contains(f.target)||(n(!1),l.current=null)}},N=f=>{f.key==="Escape"&&(n(!1),l.current=null)},F=D(s()),w=F&&typeof MutationObserver<"u"?new MutationObserver(()=>{I(F)&&(n(!1),l.current=null)}):null;return w&&F&&w.observe(F,{attributes:!0,attributeFilter:["contenteditable","data-readonly"]}),document.addEventListener("selectionchange",b),document.addEventListener("mousedown",M),document.addEventListener("keydown",N),F?.addEventListener("mouseup",b),F?.addEventListener("keyup",b),()=>{document.removeEventListener("selectionchange",b),document.removeEventListener("mousedown",M),document.removeEventListener("keydown",N),F?.removeEventListener("mouseup",b),F?.removeEventListener("keyup",b),w?.disconnect(),L.current&&clearTimeout(L.current)}},[t,a,o]);const T=(s,D)=>{if(o||!l.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=R.current||null);const I=R.current?.querySelector(".rte-content, .editora-content");if(I&&(I.getAttribute("contenteditable")==="false"||I.getAttribute("data-readonly")==="true")){n(!1),l.current=null;return}I&&I.focus();const p=window.getSelection();if(p&&l.current)try{p.removeAllRanges(),p.addRange(l.current)}catch{}({toggleBold:()=>document.execCommand("bold",!1),toggleItalic:()=>document.execCommand("italic",!1),toggleUnderline:()=>document.execCommand("underline",!1),toggleStrikethrough:()=>document.execCommand("strikeThrough",!1),createLink:()=>{typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand("openLinkDialog")},clearFormatting:()=>{document.execCommand("removeFormat",!1),document.execCommand("unlink",!1)},toggleCode:()=>{const b=window.getSelection();if(b&&b.rangeCount>0){const M=b.getRangeAt(0),N=document.createElement("code");M.surroundContents(N)}},setBlockType:()=>{if(D==="blockquote"){const b=window.getSelection();if(b&&b.rangeCount>0){const M=b.getRangeAt(0);(M.commonAncestorContainer.nodeType===Node.TEXT_NODE?M.commonAncestorContainer.parentElement:M.commonAncestorContainer)?.closest?.("blockquote")?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else D&&document.execCommand("formatBlock",!1,D)}})[s]?.(),n(!1),l.current=null};return!t||o?d.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}):d.jsxs(d.Fragment,{children:[d.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}),r&&d.jsxs("div",{ref:h,className:"floating-toolbar",onMouseDown:s=>s.preventDefault(),style:{position:"fixed",top:`${m.top}px`,left:`${m.left}px`,transform:"translateX(-50%)",zIndex:1e4,display:"flex"},children:[d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleBold"),title:"Bold (Ctrl+B)",children:d.jsx("strong",{children:"B"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleItalic"),title:"Italic (Ctrl+I)",children:d.jsx("em",{children:"I"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleUnderline"),title:"Underline (Ctrl+U)",children:d.jsx("u",{children:"U"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleStrikethrough"),title:"Strikethrough",children:d.jsx("s",{children:"S"})}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("clearFormatting"),title:"Clear Formatting",children:"⌫"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("createLink"),title:"Insert Link",children:"🔗"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleCode"),title:"Code",children:"Code"}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},Ve=({plugins:e,children:t})=>{const a=e.filter(r=>r.context?.provider);return a.length===0?d.jsx(d.Fragment,{children:t}):a.reduce((r,n)=>{const m=n.context.provider;return d.jsx(m,{children:r},n.name)},d.jsx(d.Fragment,{children:t}))},we=new Set,ve=new Set,re=e=>!!e&&typeof e=="object"&&typeof e.name=="string",xe=e=>{const t=e?.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},Ge=(e,t)=>{if(!Array.isArray(e))return[];const a=xe(t),o=[],r=[];if(e.forEach(n=>{if(re(n)){o.push(n);return}if(typeof n!="string")return;const m=a[n];if(typeof m=="function")try{const g=m();if(re(g)){o.push(g);return}}catch{}r.push(n)}),r.length>0){const n=r.slice().sort().join("|");we.has(n)||(we.add(n),console.warn(`[Editora React] Unresolved string plugin names: ${r.join(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return o},Xe=(e,t,a)=>{if(!t?.checker||e.some(n=>n?.name==="a11yChecker"))return e;const o=xe(a).a11yChecker;if(typeof o=="function")try{const n=o();if(re(n))return[...e,n]}catch{}const r="accessibility.checker";return ve.has(r)||(ve.add(r),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},Je={readonly:!1,placeholder:"",toolbar:{items:[],floating:!1,sticky:!1,showMoreOptions:!0},statusbar:{enabled:!1,position:"bottom"},menubar:{enabled:!1,items:[]},contextMenu:{enabled:!0},media:{uploadUrl:"",libraryUrl:"",maxFileSize:10*1024*1024,allowedTypes:["image/jpeg","image/png","image/gif","image/webp"],headers:{},withCredentials:!1},paste:{clean:!0,keepFormatting:!1,convertWord:!0},history:{maxSteps:100,debounceMs:300},language:{locale:"en",direction:"ltr"},spellcheck:{enabled:!1,provider:"browser",apiUrl:"",apiHeaders:{}},autosave:{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""},accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},content:{allowedTags:[],allowedAttributes:{},sanitize:!0,autoHeight:!1,minHeight:200,maxHeight:0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0}};function ke(e,t){const a={...e};for(const o in t){const r=t[o],n=a[o];r!==void 0&&(typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof n=="object"&&n!==null&&!Array.isArray(n)?a[o]=ke(n,r):a[o]=r)}return a}function Se(e){const t=ke(Je,{readonly:e.readonly,placeholder:e.placeholder,toolbar:e.toolbar,statusbar:e.statusbar,menubar:e.menubar,contextMenu:e.contextMenu,media:e.media,paste:e.paste,history:e.history,language:e.language,spellcheck:e.spellcheck,autosave:e.autosave,accessibility:e.accessibility,performance:e.performance,content:e.content,security:e.security});if(e.floatingToolbar!==void 0){const o=typeof e.floatingToolbar=="boolean"?e.floatingToolbar:e.floatingToolbar.enabled;t.toolbar={...t.toolbar,floating:o??t.toolbar.floating}}return e.mediaConfig&&(t.media={...t.media,uploadUrl:e.mediaConfig.uploadUrl||t.media.uploadUrl,libraryUrl:e.mediaConfig.libraryUrl||t.media.libraryUrl,maxFileSize:e.mediaConfig.maxFileSize||t.media.maxFileSize,allowedTypes:e.mediaConfig.allowedTypes||t.media.allowedTypes}),{...t,id:e.id,className:e.className,value:e.value,defaultValue:e.defaultValue,onChange:e.onChange,onInit:e.onInit,onDestroy:e.onDestroy,plugins:Xe(Ge(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const oe=new Map,Qe=()=>{if(typeof window>"u")return{editorElement:null,contentElement:null};let e=window.__editoraCommandEditorRoot||null;e||(e=(window.__editoraLastCommandButton||null)?.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||null);const t=e?.querySelector(".rte-content, .editora-content")||(e?.matches(".rte-content, .editora-content")?e:null);return{editorElement:e,contentElement:t}};typeof window<"u"&&(window.registerEditorCommand=(e,t)=>{oe.set(e,t)},window.executeEditorCommand=(e,t)=>{const a=oe.get(e);if(a){const o=Qe();return a(t,o)}else return console.warn(`No handler registered for command: ${e}`),!1});const Ye=e=>{const t=c.useMemo(()=>Se(e),[e.id,e.className,e.value,e.defaultValue,e.readonly,e.placeholder,e.plugins,e.toolbar,e.menubar,e.contextMenu,e.media,e.paste,e.history,e.language,e.spellcheck,e.autosave,e.accessibility,e.performance,e.content,e.security,e.floatingToolbar,e.mediaConfig]),a=c.useRef(null),o=c.useRef(null),r=c.useRef(e.onInit),n=c.useRef(e.onDestroy),m=c.useRef(e.onChange),g=c.useRef(new Set),u=c.useRef(null),h=c.useRef(null),l=c.useRef(null);c.useEffect(()=>{r.current=e.onInit,n.current=e.onDestroy,m.current=e.onChange});const L=p=>{m.current?.(p),g.current.forEach(E=>{try{E(p)}catch(b){console.error("Editora onChange subscriber failed:",b)}})},R=c.useMemo(()=>{const p=new q.PluginManager;t.plugins.forEach(b=>{p.register(b),b.commands&&typeof window<"u"&&Object.entries(b.commands).forEach(([M,N])=>{oe.set(M,N)})});const E=new q.Editor(p);return a.current=E,E},[t.plugins]);c.useEffect(()=>{const p={getHTML:()=>u.current?.querySelector(".rte-content")?.innerHTML||"",setHTML:E=>{const b=u.current?.querySelector(".rte-content");b&&(b.innerHTML=E)},execCommand:(E,b)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=u.current||null,window.executeEditorCommand(E,b))},registerCommand:(E,b)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(E,b)},focus:()=>{u.current?.querySelector(".rte-content")?.focus()},blur:()=>{u.current?.querySelector(".rte-content")?.blur()},destroy:()=>{n.current&&n.current()},onChange:E=>(g.current.add(E),()=>{g.current.delete(E)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:R.toolbar?.items||[]}};return o.current=p,r.current&&r.current(p),()=>{g.current.clear(),n.current&&n.current()}},[]),c.useEffect(()=>{if(t.statusbar.enabled&&l.current&&u.current){h.current||(h.current=new q.StatusBar({enabled:!0,position:t.statusbar.position}),h.current.create(l.current));const p=u.current.querySelector(".rte-content");if(p){const E=()=>{const x=document.activeElement;return!!x&&(x===p||p.contains(x))},b=()=>{const x=p.getBoundingClientRect();return x.bottom>=0&&x.top<=window.innerHeight},M=()=>{const x=window.getSelection();if(!x||x.rangeCount===0)return null;const _=x.getRangeAt(0),y=_.commonAncestorContainer;return p.contains(y)?_:null},N=(x=!1)=>{if(t.performance.viewportOnlyScan!==!1&&!b()&&!E())return;const y=M(),A=!!y||E();if(x&&!A)return;const S=p.textContent||"",{words:z,chars:$}=q.calculateTextStats(S),B=q.countLines(p);let H,P;y&&(H=q.getCursorPosition(p,y),y.collapsed||(P=q.getSelectionInfo(y,H),H=void 0)),h.current?.update({wordCount:z,charCount:$,lineCount:B,cursorPosition:H,selectionInfo:P})},F=()=>N(),w=()=>N(!0),f=()=>N(),C=()=>N();return p.addEventListener("input",F),p.addEventListener("focus",f),p.addEventListener("blur",C),document.addEventListener("selectionchange",w),N(),()=>{p.removeEventListener("input",F),p.removeEventListener("focus",f),p.removeEventListener("blur",C),document.removeEventListener("selectionchange",w)}}}else h.current&&(h.current.destroy(),h.current=null);return()=>{h.current&&(h.current.destroy(),h.current=null)}},[t.statusbar.enabled,t.statusbar.position,t.performance.viewportOnlyScan]);const T=t.toolbar.floating??!1,s=t.toolbar.position||"top",D=t.toolbar.sticky??!1,I=t.toolbar.showMoreOptions??!0;return d.jsx(Ve,{plugins:t.plugins,children:d.jsxs("div",{ref:u,id:t.id,"data-editora-editor":!0,"data-readonly":t.readonly?"true":"false",className:`rte-editor ${t.className||""}`,lang:t.language.locale,dir:t.language.direction,style:{display:"flex",flexDirection:"column",height:"100%"},children:[s!=="bottom"&&d.jsx(ne,{editor:R,position:s,sticky:D,floating:T,readonly:t.readonly,showMoreOptions:I,itemsOverride:t.toolbar.items}),d.jsx(Ce,{editor:R,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:L,pasteConfig:t.paste,contentConfig:t.content,securityConfig:t.security,performanceConfig:t.performance,accessibilityConfig:t.accessibility,autosaveConfig:t.autosave,contextMenuConfig:t.contextMenu,spellcheckConfig:t.spellcheck}),s==="bottom"&&d.jsx(ne,{editor:R,position:s,sticky:D,floating:T,readonly:t.readonly,showMoreOptions:I,itemsOverride:t.toolbar.items}),d.jsx(Ke,{editor:R,isEnabled:T,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&d.jsx("div",{ref:l,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},Re=e=>d.jsx(Ye,{...e});function Ze(e={}){const t=c.useRef(null),a=c.useRef(e.onCommand);return c.useEffect(()=>{a.current=e.onCommand}),c.useEffect(()=>{if(typeof window>"u"||e.enabled===!1)return;const o=new q.KeyboardShortcutManager(e);t.current=o;const r=m=>o.handleKeyDown(m,(u,h)=>{a.current&&a.current(u,h),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(u,h)}),n=e.editorElement||document;return n&&n.addEventListener("keydown",r),()=>{n&&n.removeEventListener("keydown",r)}},[e.editorElement,e.enabled,e.shortcuts,e.customShortcuts]),{getShortcuts:()=>t.current?.getAllShortcuts()||[],getShortcutForCommand:o=>t.current?.getShortcutForCommand(o),getShortcutsHelp:()=>t.current?.getShortcutsHelp()||"",enable:()=>t.current?.enable(),disable:()=>t.current?.disable(),isEnabled:()=>t.current?.isEnabled()||!1}}exports.EditorContent=Ce;exports.EditoraEditor=Re;exports.InlineMenu=pe;exports.RichTextEditor=Re;exports.Toolbar=ne;exports.mergeConfig=Se;exports.useKeyboardShortcuts=Ze;

@@ -1,4 +0,4 @@

import { jsx as b, jsxs as X, Fragment as ne } from "react/jsx-runtime";
import De, { useRef as D, useState as J, useLayoutEffect as He, useEffect as z, useMemo as ie } from "react";
import { KeyboardShortcutManager as Te, PluginManager as Fe, Editor as Be, StatusBar as _e, calculateTextStats as ze, countLines as We, getCursorPosition as Oe, getSelectionInfo as Pe } from "@editora/core";
import { jsx as h, jsxs as V, Fragment as ee } from "react/jsx-runtime";
import De, { useRef as L, useState as G, useLayoutEffect as He, useEffect as F, useMemo as ae } from "react";
import { KeyboardShortcutManager as ke, PluginManager as Be, Editor as Fe, StatusBar as _e, calculateTextStats as ze, countLines as Oe, getCursorPosition as We, getSelectionInfo as Pe } from "@editora/core";
const $e = ({

@@ -8,53 +8,50 @@ isOpen: e,

onSelect: a,
onClose: n,
anchorRef: o,
className: r = ""
onClose: o,
anchorRef: r,
className: n = ""
}) => {
const u = D(null), [c, d] = J(null), f = () => {
var w;
if (!e || !o.current)
return;
const s = o.current.getBoundingClientRect(), C = (w = u.current) == null ? void 0 : w.getBoundingClientRect(), T = (C == null ? void 0 : C.width) || 120, R = (C == null ? void 0 : C.height) || t.length * 36, i = 8, B = 4, F = window.innerWidth, y = window.innerHeight;
let M = s.bottom + B, m = s.left;
m + T > F - i && (m = F - T - i), m < i && (m = i), M + R > y - i && (M = s.top - R - B), M < i && (M = i), d({ top: M, left: m });
const u = L(null), [f, s] = G(null), m = () => {
if (!e || !r.current) return;
const c = r.current.getBoundingClientRect(), R = u.current?.getBoundingClientRect(), A = R?.width || 120, T = R?.height || t.length * 36, l = 8, H = 4, I = window.innerWidth, v = window.innerHeight;
let y = c.bottom + H, g = c.left;
g + A > I - l && (g = I - A - l), g < l && (g = l), y + T > v - l && (y = c.top - T - H), y < l && (y = l), s({ top: y, left: g });
};
return He(() => {
if (!e) {
d(null);
s(null);
return;
}
f();
const s = window.requestAnimationFrame(f);
m();
const c = window.requestAnimationFrame(m);
return () => {
window.cancelAnimationFrame(s);
window.cancelAnimationFrame(c);
};
}, [e, t.length, o]), z(() => {
if (!e)
return;
const s = () => {
f();
}, [e, t.length, r]), F(() => {
if (!e) return;
const c = () => {
m();
};
return window.addEventListener("resize", s), window.addEventListener("scroll", s, !0), () => {
window.removeEventListener("resize", s), window.removeEventListener("scroll", s, !0);
return window.addEventListener("resize", c), window.addEventListener("scroll", c, !0), () => {
window.removeEventListener("resize", c), window.removeEventListener("scroll", c, !0);
};
}, [e, t.length, o]), z(() => {
const s = (T) => {
u.current && !u.current.contains(T.target) && o.current && !o.current.contains(T.target) && n();
}, C = (T) => {
T.key === "Escape" && n();
}, [e, t.length, r]), F(() => {
const c = (A) => {
u.current && !u.current.contains(A.target) && r.current && !r.current.contains(A.target) && o();
}, R = (A) => {
A.key === "Escape" && o();
};
return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", C)), () => {
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", C);
return e && (document.addEventListener("mousedown", c), document.addEventListener("keydown", R)), () => {
document.removeEventListener("mousedown", c), document.removeEventListener("keydown", R);
};
}, [e, n, o]), e ? /* @__PURE__ */ b(
}, [e, o, r]), e ? /* @__PURE__ */ h(
"div",
{
ref: u,
className: `rte-inline-menu ${r}`,
className: `rte-inline-menu ${n}`,
style: {
top: (c == null ? void 0 : c.top) ?? -9999,
left: (c == null ? void 0 : c.left) ?? -9999,
visibility: c ? "visible" : "hidden"
top: f?.top ?? -9999,
left: f?.left ?? -9999,
visibility: f ? "visible" : "hidden"
},
children: t.map((s) => /* @__PURE__ */ b(
children: t.map((c) => /* @__PURE__ */ h(
"div",

@@ -64,11 +61,11 @@ {

onClick: () => {
a(s.value), n();
a(c.value), o();
},
children: s.label
children: c.label
},
s.value
c.value
))
}
) : null;
}, ee = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Ue = {
}, Q = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Ue = {
undo: "undo",

@@ -107,15 +104,15 @@ redo: "redo",

return e;
if (!t.every((d) => typeof d == "string"))
if (!t.every((s) => typeof s == "string"))
return t;
const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
e.forEach((d) => {
n.set(ee(d.command || ""), d), o.set(ee(d.label || ""), d);
const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
e.forEach((s) => {
o.set(Q(s.command || ""), s), r.set(Q(s.label || ""), s);
});
const r = t.flatMap((d) => d.split(/\s+/)).map((d) => d.trim()).filter(Boolean), u = [];
let c = 0;
return r.forEach((d) => {
if (d === "|") {
c += 1, u.push({
const n = t.flatMap((s) => s.split(/\s+/)).map((s) => s.trim()).filter(Boolean), u = [];
let f = 0;
return n.forEach((s) => {
if (s === "|") {
f += 1, u.push({
type: "separator",
command: `__separator__${c}`,
command: `__separator__${f}`,
label: "|"

@@ -125,84 +122,71 @@ });

}
const f = ee(d), s = Ue[f], C = n.get(f) || (s ? n.get(ee(s)) : void 0) || o.get(f) || e.find(
(T) => ee(T.command || "").includes(f)
const m = Q(s), c = Ue[m], R = o.get(m) || (c ? o.get(Q(c)) : void 0) || r.get(m) || e.find(
(A) => Q(A.command || "").includes(m)
);
C && u.push(C);
R && u.push(R);
}), u.length > 0 ? u : e;
}, Ee = ({
}, ve = ({
editor: e,
position: t = "top",
sticky: a = !1,
floating: n = !1,
readonly: o = !1,
showMoreOptions: r = !0,
floating: o = !1,
readonly: r = !1,
showMoreOptions: n = !0,
itemsOverride: u
}) => {
const [c, d] = J(!1), [f, s] = J(null), [C, T] = J(null), [R, i] = J(null), [B, F] = J(!1), y = D(null), M = D(null), m = D({}), w = D([]), I = D(null), L = D(null), h = D(null), x = ie(
const [f, s] = G(!1), [m, c] = G(null), [R, A] = G(null), [T, l] = G(null), [H, I] = G(!1), v = L(null), y = L(null), g = L({}), M = L([]), N = L(null), _ = L(null), b = L(null), d = ae(
() => qe(e.pluginManager.getToolbarItems(), u),
[e, u]
), g = (l) => {
y.current = l, l && !l.collapsed && (M.current = l);
}, p = () => {
var v;
const l = (v = I.current) == null ? void 0 : v.closest("[data-editora-editor]");
return (l == null ? void 0 : l.querySelector(".rte-content")) || null;
}, N = () => {
var v;
if (typeof window > "u")
return;
const l = (v = I.current) == null ? void 0 : v.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = l || null;
}, A = (l) => {
if (typeof window > "u" || !l)
return;
const v = l.getAttribute("data-command");
v && (window.__editoraLastCommandButton = l, window.__editoraLastCommand = v);
), C = (i) => {
v.current = i, i && !i.collapsed && (y.current = i);
}, E = () => N.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, z = () => {
if (typeof window > "u") return;
const i = N.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = i || null;
}, p = (i) => {
if (typeof window > "u" || !i) return;
const k = i.getAttribute("data-command");
k && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = k);
}, x = () => {
const i = E();
if (!i) return null;
const k = window.getSelection();
if (!k || k.rangeCount === 0) return null;
const w = k.getRangeAt(0);
return i.contains(w.commonAncestorContainer) ? w.cloneRange() : null;
}, S = () => {
const l = p();
if (!l)
return null;
const v = window.getSelection();
if (!v || v.rangeCount === 0)
return null;
const E = v.getRangeAt(0);
return l.contains(E.commonAncestorContainer) ? E.cloneRange() : null;
}, k = () => {
const l = S();
l && g(l);
const i = x();
i && C(i);
};
z(() => {
var P;
const l = (P = I.current) == null ? void 0 : P.closest("[data-editora-editor]");
if (!l)
return;
const v = l.querySelector(".rte-content, .editora-content");
d((v == null ? void 0 : v.getAttribute("data-track-changes")) === "true");
const E = (H) => {
var Q;
d(!!((Q = H.detail) != null && Q.enabled));
F(() => {
const i = N.current?.closest("[data-editora-editor]");
if (!i) return;
const k = i.querySelector(".rte-content, .editora-content");
s(k?.getAttribute("data-track-changes") === "true");
const w = ($) => {
s(!!$.detail?.enabled);
};
return l.addEventListener("editora:track-changes-toggle", E), () => {
l.removeEventListener("editora:track-changes-toggle", E);
return i.addEventListener("editora:track-changes-toggle", w), () => {
i.removeEventListener("editora:track-changes-toggle", w);
};
}, []), z(() => {
const l = () => {
k();
}, []), F(() => {
const i = () => {
S();
};
return document.addEventListener("selectionchange", l), () => {
document.removeEventListener("selectionchange", l);
return document.addEventListener("selectionchange", i), () => {
document.removeEventListener("selectionchange", i);
};
}, []), z(() => {
if (!f)
return;
const l = (E) => {
const P = E.target;
P && P instanceof Element && (P.closest(".rte-toolbar-dropdown") || s(null));
}, v = (E) => {
E.key === "Escape" && s(null);
}, []), F(() => {
if (!m) return;
const i = (w) => {
const $ = w.target;
$ && $ instanceof Element && ($.closest(".rte-toolbar-dropdown") || c(null));
}, k = (w) => {
w.key === "Escape" && c(null);
};
return document.addEventListener("pointerdown", l, !0), document.addEventListener("keydown", v), () => {
document.removeEventListener("pointerdown", l, !0), document.removeEventListener("keydown", v);
return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", k), () => {
document.removeEventListener("pointerdown", i, !0), document.removeEventListener("keydown", k);
};
}, [f]);
const _ = (l) => [
}, [m]);
const W = (i) => [
"toggleBold",

@@ -217,76 +201,72 @@ "toggleItalic",

"toggleCode"
].includes(l), U = (l = !1) => {
const v = p();
if (!v)
].includes(i), q = (i = !1) => {
const k = E();
if (!k) return !1;
const w = window.getSelection();
if (!w) return !1;
const $ = w.rangeCount > 0 && k.contains(w.getRangeAt(0).commonAncestorContainer), D = i ? y.current || v.current : v.current || y.current;
if (i && D && D.collapsed)
return !1;
const E = window.getSelection();
if (!E)
return !1;
const P = E.rangeCount > 0 && v.contains(E.getRangeAt(0).commonAncestorContainer), H = l ? M.current || y.current : y.current || M.current;
if (l && H && H.collapsed)
return !1;
if (H && v.contains(H.commonAncestorContainer))
if (D && k.contains(D.commonAncestorContainer))
try {
return v.focus({ preventScroll: !0 }), E.removeAllRanges(), E.addRange(H), !0;
return k.focus({ preventScroll: !0 }), w.removeAllRanges(), w.addRange(D), !0;
} catch {
}
return P;
return $;
};
z(() => {
if (!r) {
i(null), F(!1), w.current = [];
F(() => {
if (!n) {
l(null), I(!1), M.current = [];
return;
}
let l = null;
const v = () => {
if (!I.current || !L.current)
return;
const H = I.current.clientWidth, K = 16, Q = 40, O = 4, oe = Math.max(0, H - K - Q - O);
let ge = 0, be = 0;
const ae = L.current.children;
for (let G = 0; G < ae.length; G++) {
const le = ae[G].getBoundingClientRect().width;
le > 0 && (w.current[G] = le);
const ve = w.current[G] ?? le, pe = (ve > 0 ? ve : 40) + O;
if (ge + pe <= oe)
ge += pe, be++;
let i = null;
const k = () => {
if (!N.current || !_.current) return;
const D = N.current.clientWidth, j = 16, P = 40, Y = 4, Ne = Math.max(0, D - j - P - Y);
let me = 0, ge = 0;
const ne = _.current.children;
for (let K = 0; K < ne.length; K++) {
const re = ne[K].getBoundingClientRect().width;
re > 0 && (M.current[K] = re);
const be = M.current[K] ?? re, we = (be > 0 ? be : 40) + Y;
if (me + we <= Ne)
me += we, ge++;
else
break;
}
const we = Math.max(1, Math.min(be, ae.length));
i((G) => G === we ? G : we);
}, E = () => {
l !== null && cancelAnimationFrame(l), l = requestAnimationFrame(v);
const he = Math.max(1, Math.min(ge, ne.length));
l((K) => K === he ? K : he);
}, w = () => {
i !== null && cancelAnimationFrame(i), i = requestAnimationFrame(k);
};
w.current = [], E();
const P = new ResizeObserver(() => {
E();
M.current = [], w();
const $ = new ResizeObserver(() => {
w();
});
return I.current && P.observe(I.current), L.current && P.observe(L.current), () => {
l !== null && cancelAnimationFrame(l), P.disconnect();
return N.current && $.observe(N.current), _.current && $.observe(_.current), () => {
i !== null && cancelAnimationFrame(i), $.disconnect();
};
}, [x.length, r]), z(() => {
B && R !== null && R >= x.length && F(!1);
}, [B, R, x.length]);
const j = (l) => (m.current[l] || (m.current[l] = De.createRef()), m.current[l]), W = (l, v) => {
if (o)
return;
N(), l === "addComment" || l === "toggleComments" || U(_(l));
const H = {
}, [d.length, n]), F(() => {
H && T !== null && T >= d.length && I(!1);
}, [H, T, d.length]);
const O = (i) => (g.current[i] || (g.current[i] = De.createRef()), g.current[i]), B = (i, k) => {
if (r) return;
z(), i === "addComment" || i === "toggleComments" || q(W(i));
const D = {
toggleBold: "bold",
toggleItalic: "italic",
toggleUnderline: "underline"
}[l];
if (H) {
document.execCommand(H, !1), s(null);
}[i];
if (D) {
document.execCommand(D, !1), c(null);
return;
}
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(l, v), s(null);
}, $ = (l) => {
o || (k(), s(f === l ? null : l));
}, q = (l) => {
o || (k(), T(C === l ? null : l), s(null));
}, V = (l, v) => {
o || (U(), W(l, v), g(null), M.current = null, T(null));
}, Z = (l, v) => l && l.startsWith("<svg") && l.endsWith("</svg>") ? /* @__PURE__ */ b("span", { dangerouslySetInnerHTML: { __html: l } }) : l && l.length === 1 && /^[BIUSH]$/.test(l) ? /* @__PURE__ */ b("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: l }) : l || "⚪", Ie = {
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, k), c(null);
}, U = (i) => {
r || (S(), c(m === i ? null : i));
}, X = (i) => {
r || (S(), A(R === i ? null : i), c(null));
}, Le = (i, k) => {
r || (q(), B(i, k), C(null), y.current = null, A(null));
}, ue = (i, k) => i && i.startsWith("<svg") && i.endsWith("</svg>") ? /* @__PURE__ */ h("span", { dangerouslySetInnerHTML: { __html: i } }) : i && i.length === 1 && /^[BIUSH]$/.test(i) ? /* @__PURE__ */ h("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: i }) : i || "⚪", Re = {
...a && {

@@ -303,11 +283,9 @@ position: "sticky",

}
}, he = r && R !== null && R < x.length, Ce = (l) => {
if (o)
return;
const v = l.target;
v.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (A(v.closest("[data-command]")), N(), k(), l.preventDefault());
}, re = (l, v = !0) => l.map((E, P) => {
var Q;
const H = E.command || "", K = H === "toggleTrackChanges" && c;
return /* @__PURE__ */ b(
}, fe = n && T !== null && T < d.length, Me = (i) => {
if (r) return;
const k = i.target;
k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (p(k.closest("[data-command]")), z(), S(), i.preventDefault());
}, te = (i, k = !0) => i.map((w, $) => {
const D = w.command || "", j = D === "toggleTrackChanges" && f;
return /* @__PURE__ */ h(
"div",

@@ -317,18 +295,18 @@ {

style: {
display: v && r && R !== null && P >= R ? "none" : "flex"
display: k && n && T !== null && $ >= T ? "none" : "flex"
},
children: E.type === "separator" ? /* @__PURE__ */ b("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : E.type === "dropdown" ? /* @__PURE__ */ X("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ X(
children: w.type === "separator" ? /* @__PURE__ */ h("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : w.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ V(
"button",
{
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": H,
"data-active": K ? "true" : "false",
onMouseDown: (O) => {
O.preventDefault(), k();
className: `rte-toolbar-button ${j ? "active" : ""}`,
"data-command": D,
"data-active": j ? "true" : "false",
onMouseDown: (P) => {
P.preventDefault(), S();
},
onClick: () => $(H),
disabled: o,
onClick: () => U(D),
disabled: r,
children: [
E.label,
w.label,
" ▼"

@@ -338,103 +316,103 @@ ]

),
f === H && /* @__PURE__ */ b("div", { className: "rte-toolbar-dropdown-menu", children: (Q = E.options) == null ? void 0 : Q.map((O) => /* @__PURE__ */ b(
m === D && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: w.options?.map((P) => /* @__PURE__ */ h(
"div",
{
className: "rte-toolbar-dropdown-item",
onMouseDown: (oe) => oe.preventDefault(),
onClick: () => W(H, O.value),
children: O.label
onMouseDown: (Y) => Y.preventDefault(),
onClick: () => B(D, P.value),
children: P.label
},
O.value
P.value
)) })
] }) : E.type === "inline-menu" ? /* @__PURE__ */ b(
] }) : w.type === "inline-menu" ? /* @__PURE__ */ h(
"button",
{
ref: j(H),
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": H,
"data-active": K ? "true" : "false",
onMouseDown: (O) => {
O.preventDefault(), k();
ref: O(D),
className: `rte-toolbar-button ${j ? "active" : ""}`,
"data-command": D,
"data-active": j ? "true" : "false",
onMouseDown: (P) => {
P.preventDefault(), S();
},
onClick: () => q(H),
disabled: o,
title: E.label,
children: Z(E.icon)
onClick: () => X(D),
disabled: r,
title: w.label,
children: ue(w.icon)
}
) : E.type === "input" ? /* @__PURE__ */ b(
) : w.type === "input" ? /* @__PURE__ */ h(
"input",
{
type: "text",
className: `rte-toolbar-input ${E.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: E.placeholder,
onChange: (O) => W(H, O.target.value),
disabled: o,
onKeyDown: (O) => {
O.key === "Enter" && W(
H,
O.target.value
className: `rte-toolbar-input ${w.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: w.placeholder,
onChange: (P) => B(D, P.target.value),
disabled: r,
onKeyDown: (P) => {
P.key === "Enter" && B(
D,
P.target.value
);
},
title: E.label
title: w.label
}
) : E.type === "group" ? /* @__PURE__ */ b(
) : w.type === "group" ? /* @__PURE__ */ h(
"div",
{
className: `rte-toolbar-group-button ${E.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${E.label}`,
children: /* @__PURE__ */ b(
className: `rte-toolbar-group-button ${w.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${w.label}`,
children: /* @__PURE__ */ h(
"div",
{
className: `rte-toolbar-group-items ${E.label.toLowerCase().replace(/\s+/g, "-")}`,
children: re(E.items || [], !1)
className: `rte-toolbar-group-items ${w.label.toLowerCase().replace(/\s+/g, "-")}`,
children: te(w.items || [], !1)
}
)
}
) : /* @__PURE__ */ b(
) : /* @__PURE__ */ h(
"button",
{
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": H,
"data-active": K ? "true" : "false",
onMouseDown: (O) => {
O.preventDefault(), k();
className: `rte-toolbar-button ${j ? "active" : ""}`,
"data-command": D,
"data-active": j ? "true" : "false",
onMouseDown: (P) => {
P.preventDefault(), S();
},
onClick: () => W(H),
disabled: o,
title: E.label,
children: Z(E.icon)
onClick: () => B(D),
disabled: r,
title: w.label,
children: ue(w.icon)
}
)
},
P
$
);
}), Ne = r && R !== null ? x.filter((l, v) => v >= R) : [];
return /* @__PURE__ */ X(ne, { children: [
/* @__PURE__ */ X(
}), Ie = n && T !== null ? d.filter((i, k) => k >= T) : [];
return /* @__PURE__ */ V(ee, { children: [
/* @__PURE__ */ V(
"div",
{
className: "rte-toolbar-wrapper",
style: Ie,
onMouseDownCapture: Ce,
style: Re,
onMouseDownCapture: Me,
children: [
/* @__PURE__ */ X("div", { className: "rte-toolbar", ref: I, children: [
/* @__PURE__ */ b(
/* @__PURE__ */ V("div", { className: "rte-toolbar", ref: N, children: [
/* @__PURE__ */ h(
"div",
{
className: "rte-toolbar-items-container",
ref: L,
style: r ? void 0 : { flexWrap: "wrap" },
children: re(x)
ref: _,
style: n ? void 0 : { flexWrap: "wrap" },
children: te(d)
}
),
he && /* @__PURE__ */ b(
fe && /* @__PURE__ */ h(
"button",
{
ref: h,
className: `rte-toolbar-more-button ${B ? "active" : ""}`,
onMouseDown: (l) => {
l.preventDefault(), k();
ref: b,
className: `rte-toolbar-more-button ${H ? "active" : ""}`,
onMouseDown: (i) => {
i.preventDefault(), S();
},
onClick: () => F(!B),
disabled: o,
onClick: () => I(!H),
disabled: r,
title: "Show more options",

@@ -446,19 +424,19 @@ "aria-label": "More toolbar options",

] }),
he && /* @__PURE__ */ b("div", { className: `rte-toolbar-expanded-row ${B ? "show" : ""}`, children: re(Ne, !1) })
fe && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${H ? "show" : ""}`, children: te(Ie, !1) })
]
}
),
x.map((l) => {
if (l.type === "inline-menu") {
const v = l.command || "";
return /* @__PURE__ */ b(
d.map((i) => {
if (i.type === "inline-menu") {
const k = i.command || "";
return /* @__PURE__ */ h(
$e,
{
isOpen: C === v,
options: l.options || [],
onSelect: (E) => V(v, E),
onClose: () => T(null),
anchorRef: j(v)
isOpen: R === k,
options: i.options || [],
onSelect: (w) => Le(k, w),
onClose: () => A(null),
anchorRef: O(k)
},
`menu-${v || "unknown"}`
`menu-${k || "unknown"}`
);

@@ -471,16 +449,15 @@ }

function je(e, t) {
const a = D(), n = D("");
return z(() => {
if (!(t != null && t.enabled))
return;
const r = t.intervalMs || 3e4, u = t.storageKey || "rte-autosave", c = t.provider || "localStorage", d = async () => {
const f = e();
if (f !== n.current) {
if (n.current = f, c === "localStorage")
const a = L(), o = L("");
return F(() => {
if (!t?.enabled) return;
const n = t.intervalMs || 3e4, u = t.storageKey || "rte-autosave", f = t.provider || "localStorage", s = async () => {
const m = e();
if (m !== o.current) {
if (o.current = m, f === "localStorage")
try {
localStorage.setItem(u, f), localStorage.setItem(`${u}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage");
} catch (s) {
console.error("[Autosave] Failed to save to localStorage:", s);
localStorage.setItem(u, m), localStorage.setItem(`${u}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage");
} catch (c) {
console.error("[Autosave] Failed to save to localStorage:", c);
}
else if (c === "api" && t.apiUrl)
else if (f === "api" && t.apiUrl)
try {

@@ -492,23 +469,22 @@ await fetch(t.apiUrl, {

},
body: JSON.stringify({ content: f, timestamp: Date.now() })
body: JSON.stringify({ content: m, timestamp: Date.now() })
}), console.log("[Autosave] Content saved to API");
} catch (s) {
console.error("[Autosave] Failed to save to API:", s);
} catch (c) {
console.error("[Autosave] Failed to save to API:", c);
}
}
};
return a.current = setInterval(d, r), () => {
return a.current = setInterval(s, n), () => {
a.current && clearInterval(a.current);
};
}, [t == null ? void 0 : t.enabled, t == null ? void 0 : t.intervalMs, t == null ? void 0 : t.storageKey, t == null ? void 0 : t.provider, t == null ? void 0 : t.apiUrl, e]), { restore: () => {
if (!(t != null && t.enabled))
return null;
const r = t.storageKey || "rte-autosave";
}, [t?.enabled, t?.intervalMs, t?.storageKey, t?.provider, t?.apiUrl, e]), { restore: () => {
if (!t?.enabled) return null;
const n = t.storageKey || "rte-autosave";
if ((t.provider || "localStorage") === "localStorage")
try {
const c = localStorage.getItem(r), d = localStorage.getItem(`${r}-timestamp`);
if (c && d)
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(d))), c;
} catch (c) {
console.error("[Autosave] Failed to restore from localStorage:", c);
const f = localStorage.getItem(n), s = localStorage.getItem(`${n}-timestamp`);
if (f && s)
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(s))), f;
} catch (f) {
console.error("[Autosave] Failed to restore from localStorage:", f);
}

@@ -567,42 +543,42 @@ return null;

};
function Le(e, t, a) {
if ((t == null ? void 0 : t.sanitize) === !1)
function Se(e, t, a) {
if (t?.sanitize === !1)
return e;
const n = t != null && t.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ke, r = !!(t != null && t.allowedAttributes) && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ve, u = document.createElement("div");
return u.innerHTML = e, xe(u, n, r), u.innerHTML;
const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ke, n = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ve, u = document.createElement("div");
return u.innerHTML = e, Ae(u, o, n), u.innerHTML;
}
function xe(e, t, a) {
const n = Array.from(e.childNodes);
for (const o of n)
if (o.nodeType === Node.ELEMENT_NODE) {
const r = o, u = r.tagName.toLowerCase();
function Ae(e, t, a) {
const o = Array.from(e.childNodes);
for (const r of o)
if (r.nodeType === Node.ELEMENT_NODE) {
const n = r, u = n.tagName.toLowerCase();
if (!t.includes(u)) {
for (; r.firstChild; )
e.insertBefore(r.firstChild, r);
e.removeChild(r);
for (; n.firstChild; )
e.insertBefore(n.firstChild, n);
e.removeChild(n);
continue;
}
Ge(r, a), xe(r, t, a);
Ge(n, a), Ae(n, t, a);
} else {
if (o.nodeType === Node.TEXT_NODE)
if (r.nodeType === Node.TEXT_NODE)
continue;
e.removeChild(o);
e.removeChild(r);
}
}
function Ge(e, t) {
const a = e.tagName.toLowerCase(), n = Array.from(e.attributes), o = t[a] || [], r = t["*"] || [], u = [...o, ...r];
for (const c of n) {
const d = c.name.toLowerCase();
let f = !1;
u.includes(d) && (f = !0);
for (const s of u)
if (s.endsWith("*")) {
const C = s.slice(0, -1);
if (d.startsWith(C)) {
f = !0;
const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), r = t[a] || [], n = t["*"] || [], u = [...r, ...n];
for (const f of o) {
const s = f.name.toLowerCase();
let m = !1;
u.includes(s) && (m = !0);
for (const c of u)
if (c.endsWith("*")) {
const R = c.slice(0, -1);
if (s.startsWith(R)) {
m = !0;
break;
}
}
(d.startsWith("on") || // Event handlers
d === "javascript:" || d === "href" && c.value.trim().toLowerCase().startsWith("javascript:") || d === "src" && c.value.trim().toLowerCase().startsWith("javascript:")) && (f = !1), f || e.removeAttribute(c.name);
(s.startsWith("on") || // Event handlers
s === "javascript:" || s === "href" && f.value.trim().toLowerCase().startsWith("javascript:") || s === "src" && f.value.trim().toLowerCase().startsWith("javascript:")) && (m = !1), m || e.removeAttribute(f.name);
}

@@ -612,24 +588,22 @@ e.hasAttribute("href") && (e.getAttribute("href") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("href"), e.hasAttribute("src") && (e.getAttribute("src") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("src");

function Xe(e, t, a) {
return (a == null ? void 0 : a.sanitizeOnPaste) === !1 ? e : Le(e, t);
return a?.sanitizeOnPaste === !1 ? e : Se(e, t);
}
function ye(e, t, a) {
return (a == null ? void 0 : a.sanitizeOnInput) === !1 ? e : Le(e, t);
function pe(e, t, a) {
return a?.sanitizeOnInput === !1 ? e : Se(e, t);
}
const te = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), Y = (e, t) => {
const n = !!t && te(e);
e.classList.toggle("rte-content-empty", n);
}, ue = "data-rte-caret-marker", me = "data-rte-range-start-marker", fe = "data-rte-range-end-marker", se = () => Math.random().toString(36).slice(2), Je = (e) => {
const Z = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), J = (e, t) => {
const o = !!t && Z(e);
e.classList.toggle("rte-content-empty", o);
}, ce = "data-rte-caret-marker", se = "data-rte-range-start-marker", de = "data-rte-range-end-marker", oe = () => Math.random().toString(36).slice(2), Je = (e) => {
const t = window.getSelection();
if (!t || t.rangeCount === 0)
return null;
if (!t || t.rangeCount === 0) return null;
const a = t.getRangeAt(0);
if (!e.contains(a.commonAncestorContainer))
return null;
if (!e.contains(a.commonAncestorContainer)) return null;
try {
const n = a.cloneRange();
n.selectNodeContents(e), n.setEnd(a.startContainer, a.startOffset);
const o = a.cloneRange();
return o.selectNodeContents(e), o.setEnd(a.endContainer, a.endOffset), {
start: n.toString().length,
end: o.toString().length
o.selectNodeContents(e), o.setEnd(a.startContainer, a.startOffset);
const r = a.cloneRange();
return r.selectNodeContents(e), r.setEnd(a.endContainer, a.endOffset), {
start: o.toString().length,
end: r.toString().length
};

@@ -639,60 +613,55 @@ } catch {

}
}, ke = (e, t) => {
var u, c;
}, ye = (e, t) => {
const a = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
let n = a.nextNode(), o = Math.max(0, t), r = null;
for (; n; ) {
r = n;
const d = ((u = n.textContent) == null ? void 0 : u.length) ?? 0;
if (o <= d)
return { node: n, offset: o };
o -= d, n = a.nextNode();
let o = a.nextNode(), r = Math.max(0, t), n = null;
for (; o; ) {
n = o;
const u = o.textContent?.length ?? 0;
if (r <= u)
return { node: o, offset: r };
r -= u, o = a.nextNode();
}
return r ? {
node: r,
offset: ((c = r.textContent) == null ? void 0 : c.length) ?? 0
return n ? {
node: n,
offset: n.textContent?.length ?? 0
} : { node: e, offset: e.childNodes.length };
}, Qe = (e) => {
const t = window.getSelection();
if (!t || t.rangeCount === 0)
return null;
if (!t || t.rangeCount === 0) return null;
const a = t.getRangeAt(0);
if (!e.contains(a.commonAncestorContainer))
return null;
const n = Je(e);
if (!e.contains(a.commonAncestorContainer)) return null;
const o = Je(e);
try {
if (a.collapsed) {
const s = se(), C = document.createElement("span");
return C.setAttribute(ue, s), C.appendChild(document.createTextNode("​")), a.cloneRange().insertNode(C), { collapsed: !0, caretId: s, fallbackOffsets: n };
const c = oe(), R = document.createElement("span");
return R.setAttribute(ce, c), R.appendChild(document.createTextNode("​")), a.cloneRange().insertNode(R), { collapsed: !0, caretId: c, fallbackOffsets: o };
}
const o = se(), r = se(), u = document.createElement("span");
u.setAttribute(fe, r), u.appendChild(document.createTextNode("​"));
const c = document.createElement("span");
c.setAttribute(me, o), c.appendChild(document.createTextNode("​"));
const d = a.cloneRange();
d.collapse(!1), d.insertNode(u);
const f = a.cloneRange();
return f.collapse(!0), f.insertNode(c), { collapsed: !1, startId: o, endId: r, fallbackOffsets: n };
const r = oe(), n = oe(), u = document.createElement("span");
u.setAttribute(de, n), u.appendChild(document.createTextNode("​"));
const f = document.createElement("span");
f.setAttribute(se, r), f.appendChild(document.createTextNode("​"));
const s = a.cloneRange();
s.collapse(!1), s.insertNode(u);
const m = a.cloneRange();
return m.collapse(!0), m.insertNode(f), { collapsed: !1, startId: r, endId: n, fallbackOffsets: o };
} catch {
return { collapsed: a.collapsed, fallbackOffsets: n };
return { collapsed: a.collapsed, fallbackOffsets: o };
}
}, Ye = (e) => {
e.querySelectorAll(
`[${ue}], [${me}], [${fe}]`
`[${ce}], [${se}], [${de}]`
).forEach((t) => t.remove());
}, Ze = (e, t) => {
if (!t)
return !1;
if (!t) return !1;
const a = window.getSelection();
if (!a)
return !1;
if (!a) return !1;
try {
const n = document.createRange();
const o = document.createRange();
if (t.collapsed && t.caretId) {
const o = e.querySelector(`[${ue}="${t.caretId}"]`);
return !o || !o.parentNode ? !1 : (n.setStartAfter(o), n.collapse(!0), a.removeAllRanges(), a.addRange(n), !0);
const r = e.querySelector(`[${ce}="${t.caretId}"]`);
return !r || !r.parentNode ? !1 : (o.setStartAfter(r), o.collapse(!0), a.removeAllRanges(), a.addRange(o), !0);
}
if (!t.collapsed && t.startId && t.endId) {
const o = e.querySelector(`[${me}="${t.startId}"]`), r = e.querySelector(`[${fe}="${t.endId}"]`);
return !o || !r || !o.parentNode || !r.parentNode ? !1 : (n.setStartAfter(o), n.setEndBefore(r), a.removeAllRanges(), a.addRange(n), !0);
const r = e.querySelector(`[${se}="${t.startId}"]`), n = e.querySelector(`[${de}="${t.endId}"]`);
return !r || !n || !r.parentNode || !n.parentNode ? !1 : (o.setStartAfter(r), o.setEndBefore(n), a.removeAllRanges(), a.addRange(o), !0);
}

@@ -704,9 +673,8 @@ } catch {

}, et = (e, t) => {
if (!t)
return;
if (!t) return;
const a = window.getSelection();
if (a)
try {
const n = ke(e, t.start), o = ke(e, t.end), r = document.createRange();
r.setStart(n.node, n.offset), r.setEnd(o.node, o.offset), a.removeAllRanges(), a.addRange(r);
const o = ye(e, t.start), r = ye(e, t.end), n = document.createRange();
n.setStart(o.node, o.offset), n.setEnd(r.node, r.offset), a.removeAllRanges(), a.addRange(n);
} catch {

@@ -718,156 +686,144 @@ }

value: a,
readonly: n = !1,
placeholder: o,
onChange: r,
readonly: o = !1,
placeholder: r,
onChange: n,
pasteConfig: u,
contentConfig: c,
securityConfig: d,
performanceConfig: f,
accessibilityConfig: s,
autosaveConfig: C,
contextMenuConfig: T,
spellcheckConfig: R
contentConfig: f,
securityConfig: s,
performanceConfig: m,
accessibilityConfig: c,
autosaveConfig: R,
contextMenuConfig: A,
spellcheckConfig: T
}) => {
const i = D(null), B = a !== void 0, F = D(), y = (c == null ? void 0 : c.autoHeight) === !0, M = typeof (c == null ? void 0 : c.minHeight) == "number" ? c.minHeight : 200, m = typeof (c == null ? void 0 : c.maxHeight) == "number" ? c.maxHeight : 0, w = (h) => {
if (!h || !y)
const l = L(null), H = a !== void 0, I = L(), v = f?.autoHeight === !0, y = typeof f?.minHeight == "number" ? f.minHeight : 200, g = typeof f?.maxHeight == "number" ? f.maxHeight : 0, M = (b) => {
if (!b || !v) return;
b.style.height = "auto";
const d = Math.max(y, b.scrollHeight);
if (g > 0) {
b.style.height = `${Math.min(d, g)}px`;
return;
h.style.height = "auto";
const x = Math.max(M, h.scrollHeight);
if (m > 0) {
h.style.height = `${Math.min(x, m)}px`;
return;
}
h.style.height = `${x}px`;
}, { restore: I } = je(
() => {
var h;
return ((h = i.current) == null ? void 0 : h.innerHTML) || "";
},
C
b.style.height = `${d}px`;
}, { restore: N } = je(
() => l.current?.innerHTML || "",
R
);
z(() => {
if (!i.current)
F(() => {
if (!l.current) return;
const b = N(), d = b ?? a ?? t ?? "";
d.trim() ? l.current.innerHTML !== d && (l.current.innerHTML = d) : r ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), J(l.current, r), M(l.current), b && n && n(b);
}, []), F(() => {
!l.current || !H || (a !== l.current.innerHTML && (l.current.innerHTML = a), J(l.current, r), M(l.current));
}, [a, H]), F(() => {
if (!l.current) return;
const b = l.current;
if (r) {
b.setAttribute("data-placeholder", r), Z(b) && (b.innerHTML = ""), J(b, r), M(b);
return;
const h = I(), x = h ?? a ?? t ?? "";
x.trim() ? i.current.innerHTML !== x && (i.current.innerHTML = x) : o ? i.current.innerHTML = "" : i.current.innerHTML.trim() || (i.current.innerHTML = "<p><br></p>"), Y(i.current, o), w(i.current), h && r && r(h);
}, []), z(() => {
!i.current || !B || (a !== i.current.innerHTML && (i.current.innerHTML = a), Y(i.current, o), w(i.current));
}, [a, B]), z(() => {
if (!i.current)
return;
const h = i.current;
if (o) {
h.setAttribute("data-placeholder", o), te(h) && (h.innerHTML = ""), Y(h, o), w(h);
return;
}
h.removeAttribute("data-placeholder"), Y(h, o), w(h);
}, [o]), z(() => {
if (!i.current)
return;
const h = i.current;
if ((s == null ? void 0 : s.enableARIA) !== !1) {
h.setAttribute("role", "textbox"), h.setAttribute("aria-multiline", "true"), h.setAttribute("aria-disabled", n ? "true" : "false");
const g = o == null ? void 0 : o.trim();
g ? h.setAttribute("aria-label", g) : h.removeAttribute("aria-label");
b.removeAttribute("data-placeholder"), J(b, r), M(b);
}, [r]), F(() => {
if (!l.current) return;
const b = l.current;
if (c?.enableARIA !== !1) {
b.setAttribute("role", "textbox"), b.setAttribute("aria-multiline", "true"), b.setAttribute("aria-disabled", o ? "true" : "false");
const C = r?.trim();
C ? b.setAttribute("aria-label", C) : b.removeAttribute("aria-label");
} else
h.removeAttribute("role"), h.removeAttribute("aria-multiline"), h.removeAttribute("aria-label"), h.removeAttribute("aria-disabled");
}, [s == null ? void 0 : s.enableARIA, o, n]), z(() => {
w(i.current);
}, [y, M, m, a]), z(() => {
if (!i.current)
return;
const h = () => {
if (!i.current || n)
return;
o && te(i.current) && (i.current.innerHTML = "");
let S = i.current.innerHTML;
if ((d == null ? void 0 : d.sanitizeOnInput) !== !1 && (c == null ? void 0 : c.sanitize) !== !1) {
const k = ye(S, c, d);
if (k !== i.current.innerHTML) {
const _ = Qe(i.current), U = i.current.innerHTML, j = ye(U, c, d);
i.current.innerHTML = j, Ze(i.current, _) || et(i.current, (_ == null ? void 0 : _.fallbackOffsets) || null), Ye(i.current), S = i.current.innerHTML;
b.removeAttribute("role"), b.removeAttribute("aria-multiline"), b.removeAttribute("aria-label"), b.removeAttribute("aria-disabled");
}, [c?.enableARIA, r, o]), F(() => {
M(l.current);
}, [v, y, g, a]), F(() => {
if (!l.current) return;
const b = () => {
if (!l.current || o) return;
r && Z(l.current) && (l.current.innerHTML = "");
let x = l.current.innerHTML;
if (s?.sanitizeOnInput !== !1 && f?.sanitize !== !1) {
const S = pe(x, f, s);
if (S !== l.current.innerHTML) {
const W = Qe(l.current), q = l.current.innerHTML, O = pe(q, f, s);
l.current.innerHTML = O, Ze(l.current, W) || et(l.current, W?.fallbackOffsets || null), Ye(l.current), x = l.current.innerHTML;
} else
S = k;
x = S;
}
Y(i.current, o), w(i.current), r && (f != null && f.debounceInputMs ? (F.current && clearTimeout(F.current), F.current = setTimeout(() => {
r(S);
}, f.debounceInputMs)) : r(S));
}, x = (S) => {
var j, W;
if (S.__editoraSmartPasteHandled === !0 || S.defaultPrevented)
J(l.current, r), M(l.current), n && (m?.debounceInputMs ? (I.current && clearTimeout(I.current), I.current = setTimeout(() => {
n(x);
}, m.debounceInputMs)) : n(x));
}, d = (x) => {
if (x.__editoraSmartPasteHandled === !0 || x.defaultPrevented)
return;
if (n) {
S.preventDefault();
if (o) {
x.preventDefault();
return;
}
S.preventDefault();
let k = (j = S.clipboardData) == null ? void 0 : j.getData("text/html");
const _ = (W = S.clipboardData) == null ? void 0 : W.getData("text/plain"), U = !!k && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(k);
if (u != null && u.clean || !(u != null && u.keepFormatting)) {
_ && document.execCommand("insertText", !1, _);
x.preventDefault();
let S = x.clipboardData?.getData("text/html");
const W = x.clipboardData?.getData("text/plain"), q = !!S && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S);
if (u?.clean || !u?.keepFormatting) {
W && document.execCommand("insertText", !1, W);
return;
}
if ((u == null ? void 0 : u.convertWord) === !1 && U) {
_ && document.execCommand("insertText", !1, _);
if (u?.convertWord === !1 && q) {
W && document.execCommand("insertText", !1, W);
return;
}
if (k) {
(d == null ? void 0 : d.sanitizeOnPaste) !== !1 && (c == null ? void 0 : c.sanitize) !== !1 && (k = Xe(k, c, d));
const $ = window.getSelection();
if ($ && $.rangeCount > 0) {
const q = $.getRangeAt(0);
q.deleteContents();
const V = document.createElement("div");
V.innerHTML = k;
const Z = document.createDocumentFragment();
for (; V.firstChild; )
Z.appendChild(V.firstChild);
q.insertNode(Z), q.collapse(!1), $.removeAllRanges(), $.addRange(q);
if (S) {
s?.sanitizeOnPaste !== !1 && f?.sanitize !== !1 && (S = Xe(S, f, s));
const O = window.getSelection();
if (O && O.rangeCount > 0) {
const B = O.getRangeAt(0);
B.deleteContents();
const U = document.createElement("div");
U.innerHTML = S;
const X = document.createDocumentFragment();
for (; U.firstChild; )
X.appendChild(U.firstChild);
B.insertNode(X), B.collapse(!1), O.removeAllRanges(), O.addRange(B);
}
} else
_ && document.execCommand("insertText", !1, _);
}, g = (S) => {
const k = S.target;
(k.tagName === "IMG" || k.tagName === "VIDEO") && (k.style.resize = "both", k.style.overflow = "auto", k.style.display = "inline-block");
}, p = (S) => {
(T == null ? void 0 : T.enabled) === !1 && S.preventDefault();
}, N = () => {
i.current && (o && te(i.current) && (i.current.innerHTML = ""), Y(i.current, o), w(i.current));
}, A = i.current;
return A.addEventListener("input", h), A.addEventListener("paste", x), A.addEventListener("click", g), A.addEventListener("contextmenu", p), A.addEventListener("focus", N), A.addEventListener("blur", N), n || A.focus(), () => {
F.current && clearTimeout(F.current), A.removeEventListener("input", h), A.removeEventListener("paste", x), A.removeEventListener("click", g), A.removeEventListener("contextmenu", p), A.removeEventListener("focus", N), A.removeEventListener("blur", N);
} else W && document.execCommand("insertText", !1, W);
}, C = (x) => {
const S = x.target;
(S.tagName === "IMG" || S.tagName === "VIDEO") && (S.style.resize = "both", S.style.overflow = "auto", S.style.display = "inline-block");
}, E = (x) => {
A?.enabled === !1 && x.preventDefault();
}, z = () => {
l.current && (r && Z(l.current) && (l.current.innerHTML = ""), J(l.current, r), M(l.current));
}, p = l.current;
return p.addEventListener("input", b), p.addEventListener("paste", d), p.addEventListener("click", C), p.addEventListener("contextmenu", E), p.addEventListener("focus", z), p.addEventListener("blur", z), o || p.focus(), () => {
I.current && clearTimeout(I.current), p.removeEventListener("input", b), p.removeEventListener("paste", d), p.removeEventListener("click", C), p.removeEventListener("contextmenu", E), p.removeEventListener("focus", z), p.removeEventListener("blur", z);
};
}, [e, r, u, c, d, f, o, T, n]);
const L = ((R == null ? void 0 : R.enabled) ?? !1) && ((R == null ? void 0 : R.provider) ?? "browser") === "browser";
return z(() => {
if (!i.current || typeof window > "u" || n || (s == null ? void 0 : s.keyboardNavigation) === !1)
}, [e, n, u, f, s, m, r, A, o]);
const _ = (T?.enabled ?? !1) && (T?.provider ?? "browser") === "browser";
return F(() => {
if (!l.current || typeof window > "u" || o || c?.keyboardNavigation === !1)
return;
const h = new Te(), x = i.current, g = (p) => {
h.handleKeyDown(p, (N, A) => {
var S;
const b = new ke(), d = l.current, C = (E) => {
b.handleKeyDown(E, (z, p) => {
if (typeof window < "u" && window.executeEditorCommand) {
const k = (S = i.current) == null ? void 0 : S.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = k || null, window.executeEditorCommand(N, A);
const x = l.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = x || null, window.executeEditorCommand(z, p);
}
});
};
return x.addEventListener("keydown", g), () => {
x.removeEventListener("keydown", g);
return d.addEventListener("keydown", C), () => {
d.removeEventListener("keydown", C);
};
}, [s == null ? void 0 : s.keyboardNavigation, n]), /* @__PURE__ */ b(
}, [c?.keyboardNavigation, o]), /* @__PURE__ */ h(
"div",
{
ref: i,
contentEditable: !n,
ref: l,
contentEditable: !o,
suppressContentEditableWarning: !0,
spellCheck: n ? !1 : L,
tabIndex: (s == null ? void 0 : s.keyboardNavigation) === !1 ? -1 : 0,
"aria-keyshortcuts": (s == null ? void 0 : s.keyboardNavigation) === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y",
"data-viewport-only-scan": f != null && f.viewportOnlyScan ? "true" : "false",
"data-a11y-checker": s != null && s.checker ? "true" : "false",
"data-readonly": n ? "true" : "false",
className: `rte-content ${n ? "rte-content-readonly" : ""}`,
spellCheck: o ? !1 : _,
tabIndex: c?.keyboardNavigation === !1 ? -1 : 0,
"aria-keyshortcuts": c?.keyboardNavigation === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y",
"data-viewport-only-scan": m?.viewportOnlyScan ? "true" : "false",
"data-a11y-checker": c?.checker ? "true" : "false",
"data-readonly": o ? "true" : "false",
className: `rte-content ${o ? "rte-content-readonly" : ""}`,
style: {
minHeight: `${M}px`,
maxHeight: y ? m > 0 ? `${m}px` : "none" : "100%",
minHeight: `${y}px`,
maxHeight: v ? g > 0 ? `${g}px` : "none" : "100%",
padding: "16px",

@@ -879,4 +835,4 @@ outline: "none",

lineHeight: "1.5",
overflow: y ? m > 0 ? "auto" : "hidden" : "auto",
flex: y ? void 0 : 1,
overflow: v ? g > 0 ? "auto" : "hidden" : "auto",
flex: v ? void 0 : 1,
boxSizing: "border-box",

@@ -893,114 +849,106 @@ wordWrap: "break-word",

viewportOnlyScan: a = !0,
readonly: n = !1
readonly: o = !1
}) => {
const [o, r] = J(!1), [u, c] = J({ top: 0, left: 0 }), d = D(null), f = D(null), s = D(null), C = D(null), T = D(null);
z(() => {
var x;
if (!t || n) {
r(!1);
const [r, n] = G(!1), [u, f] = G({ top: 0, left: 0 }), s = L(null), m = L(null), c = L(null), R = L(null), A = L(null);
F(() => {
if (!t || o) {
n(!1);
return;
}
T.current = (x = d.current) == null ? void 0 : x.closest("[data-editora-editor]");
const i = (g) => {
var k;
if (T.current)
return T.current;
const p = (k = d.current) == null ? void 0 : k.closest("[data-editora-editor]");
if (p)
return T.current = p, p;
const N = g == null ? void 0 : g.commonAncestorContainer, A = N ? N.nodeType === Node.ELEMENT_NODE ? N : N.parentElement : null, S = A == null ? void 0 : A.closest("[data-editora-editor]");
return S ? (T.current = S, S) : null;
}, B = (g) => g && g.querySelector(".rte-content, .editora-content") || null, F = (g) => {
if (!g || n)
return !0;
const p = g.getAttribute("contenteditable"), N = g.getAttribute("data-readonly");
return p === "false" || N === "true" ? !0 : !!g.closest(
A.current = s.current?.closest("[data-editora-editor]");
const l = (d) => {
if (A.current) return A.current;
const C = s.current?.closest("[data-editora-editor]");
if (C)
return A.current = C, C;
const E = d?.commonAncestorContainer, p = (E ? E.nodeType === Node.ELEMENT_NODE ? E : E.parentElement : null)?.closest("[data-editora-editor]");
return p ? (A.current = p, p) : null;
}, H = (d) => d && d.querySelector(".rte-content, .editora-content") || null, I = (d) => {
if (!d || o) return !0;
const C = d.getAttribute("contenteditable"), E = d.getAttribute("data-readonly");
return C === "false" || E === "true" ? !0 : !!d.closest(
'[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]'
);
}, y = (g) => {
if (!g.anchorNode || !g.focusNode)
return !1;
}, v = (d) => {
if (!d.anchorNode || !d.focusNode) return !1;
try {
const p = document.createRange();
return p.setStart(g.anchorNode, g.anchorOffset), p.setEnd(g.focusNode, g.focusOffset), p.collapsed;
const C = document.createRange();
return C.setStart(d.anchorNode, d.anchorOffset), C.setEnd(d.focusNode, d.focusOffset), C.collapsed;
} catch {
return !1;
}
}, M = (g, p) => {
const N = Array.from(p.getClientRects()).filter((S) => S.width > 0 || S.height > 0);
return N.length === 0 ? p.getBoundingClientRect() : y(g) ? N[0] : N[N.length - 1];
}, m = () => {
C.current && clearTimeout(C.current);
const g = window.getSelection();
if (!g || g.rangeCount === 0) {
r(!1), s.current = null;
}, y = (d, C) => {
const E = Array.from(C.getClientRects()).filter((p) => p.width > 0 || p.height > 0);
return E.length === 0 ? C.getBoundingClientRect() : v(d) ? E[0] : E[E.length - 1];
}, g = () => {
R.current && clearTimeout(R.current);
const d = window.getSelection();
if (!d || d.rangeCount === 0) {
n(!1), c.current = null;
return;
}
const p = g.getRangeAt(0);
if (p.collapsed) {
r(!1), s.current = null;
const C = d.getRangeAt(0);
if (C.collapsed) {
n(!1), c.current = null;
return;
}
const N = g.toString().trim(), A = i(p), S = B(A);
if (!S || !S.contains(p.commonAncestorContainer)) {
r(!1), s.current = null;
const E = d.toString().trim(), z = l(C), p = H(z);
if (!p || !p.contains(C.commonAncestorContainer)) {
n(!1), c.current = null;
return;
}
if (F(S)) {
r(!1), s.current = null;
if (I(p)) {
n(!1), c.current = null;
return;
}
if (a) {
const k = S.getBoundingClientRect(), _ = k.bottom >= 0 && k.top <= window.innerHeight, U = document.activeElement === S || S.contains(document.activeElement);
if (!_ && !U) {
r(!1), s.current = null;
const x = p.getBoundingClientRect(), S = x.bottom >= 0 && x.top <= window.innerHeight, W = document.activeElement === p || p.contains(document.activeElement);
if (!S && !W) {
n(!1), c.current = null;
return;
}
}
if (N.length > 0) {
const k = M(g, p), _ = S.getBoundingClientRect(), U = 300;
if (k && _) {
const j = Math.max(8, k.top - 50);
let W = k.left + k.width / 2;
const $ = U / 2, q = _.left, V = _.right;
W - $ < q && (W = q + $ + 10), W + $ > V && (W = V - $ - 10), c({ top: j, left: W }), r(!0), s.current = p.cloneRange();
if (E.length > 0) {
const x = y(d, C), S = p.getBoundingClientRect(), W = 300;
if (x && S) {
const q = Math.max(8, x.top - 50);
let O = x.left + x.width / 2;
const B = W / 2, U = S.left, X = S.right;
O - B < U && (O = U + B + 10), O + B > X && (O = X - B - 10), f({ top: q, left: O }), n(!0), c.current = C.cloneRange();
}
} else
r(!1), s.current = null;
}, w = (g) => {
var p;
if (f.current && !f.current.contains(g.target)) {
const N = i();
window.getSelection(), ((p = B(N)) == null ? void 0 : p.contains(g.target)) || (r(!1), s.current = null);
n(!1), c.current = null;
}, M = (d) => {
if (m.current && !m.current.contains(d.target)) {
const C = l();
window.getSelection(), H(C)?.contains(d.target) || (n(!1), c.current = null);
}
}, I = (g) => {
g.key === "Escape" && (r(!1), s.current = null);
}, L = B(i()), h = L && typeof MutationObserver < "u" ? new MutationObserver(() => {
F(L) && (r(!1), s.current = null);
}, N = (d) => {
d.key === "Escape" && (n(!1), c.current = null);
}, _ = H(l()), b = _ && typeof MutationObserver < "u" ? new MutationObserver(() => {
I(_) && (n(!1), c.current = null);
}) : null;
return h && L && h.observe(L, {
return b && _ && b.observe(_, {
attributes: !0,
attributeFilter: ["contenteditable", "data-readonly"]
}), document.addEventListener("selectionchange", m), document.addEventListener("mousedown", w), document.addEventListener("keydown", I), L == null || L.addEventListener("mouseup", m), L == null || L.addEventListener("keyup", m), () => {
document.removeEventListener("selectionchange", m), document.removeEventListener("mousedown", w), document.removeEventListener("keydown", I), L == null || L.removeEventListener("mouseup", m), L == null || L.removeEventListener("keyup", m), h == null || h.disconnect(), C.current && clearTimeout(C.current);
}), document.addEventListener("selectionchange", g), document.addEventListener("mousedown", M), document.addEventListener("keydown", N), _?.addEventListener("mouseup", g), _?.addEventListener("keyup", g), () => {
document.removeEventListener("selectionchange", g), document.removeEventListener("mousedown", M), document.removeEventListener("keydown", N), _?.removeEventListener("mouseup", g), _?.removeEventListener("keyup", g), b?.disconnect(), R.current && clearTimeout(R.current);
};
}, [t, a, n]);
const R = (i, B) => {
var m, w;
if (n || !s.current)
}, [t, a, o]);
const T = (l, H) => {
if (o || !c.current) return;
typeof window < "u" && (window.__editoraCommandEditorRoot = A.current || null);
const I = A.current?.querySelector(".rte-content, .editora-content");
if (I && (I.getAttribute("contenteditable") === "false" || I.getAttribute("data-readonly") === "true")) {
n(!1), c.current = null;
return;
typeof window < "u" && (window.__editoraCommandEditorRoot = T.current || null);
const F = (m = T.current) == null ? void 0 : m.querySelector(".rte-content, .editora-content");
if (F && (F.getAttribute("contenteditable") === "false" || F.getAttribute("data-readonly") === "true")) {
r(!1), s.current = null;
return;
}
F && F.focus();
const y = window.getSelection();
if (y && s.current)
I && I.focus();
const v = window.getSelection();
if (v && c.current)
try {
y.removeAllRanges(), y.addRange(s.current);
v.removeAllRanges(), v.addRange(c.current);
} catch {
}
const M = {
({
toggleBold: () => document.execCommand("bold", !1),

@@ -1017,30 +965,27 @@ toggleItalic: () => document.execCommand("italic", !1),

toggleCode: () => {
const I = window.getSelection();
if (I && I.rangeCount > 0) {
const L = I.getRangeAt(0), h = document.createElement("code");
L.surroundContents(h);
const g = window.getSelection();
if (g && g.rangeCount > 0) {
const M = g.getRangeAt(0), N = document.createElement("code");
M.surroundContents(N);
}
},
setBlockType: () => {
var I;
if (B === "blockquote") {
const L = window.getSelection();
if (L && L.rangeCount > 0) {
const h = L.getRangeAt(0), x = h.commonAncestorContainer.nodeType === Node.TEXT_NODE ? h.commonAncestorContainer.parentElement : h.commonAncestorContainer;
((I = x == null ? void 0 : x.closest) == null ? void 0 : I.call(x, "blockquote")) ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
if (H === "blockquote") {
const g = window.getSelection();
if (g && g.rangeCount > 0) {
const M = g.getRangeAt(0);
(M.commonAncestorContainer.nodeType === Node.TEXT_NODE ? M.commonAncestorContainer.parentElement : M.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
}
} else
B && document.execCommand("formatBlock", !1, B);
} else H && document.execCommand("formatBlock", !1, H);
}
};
(w = M[i]) == null || w.call(M), r(!1), s.current = null;
})[l]?.(), n(!1), c.current = null;
};
return !t || n ? /* @__PURE__ */ b("span", { ref: d, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ X(ne, { children: [
/* @__PURE__ */ b("span", { ref: d, style: { display: "none" }, "aria-hidden": "true" }),
o && /* @__PURE__ */ X(
return !t || o ? /* @__PURE__ */ h("span", { ref: s, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(ee, { children: [
/* @__PURE__ */ h("span", { ref: s, style: { display: "none" }, "aria-hidden": "true" }),
r && /* @__PURE__ */ V(
"div",
{
ref: f,
ref: m,
className: "floating-toolbar",
onMouseDown: (i) => i.preventDefault(),
onMouseDown: (l) => l.preventDefault(),
style: {

@@ -1055,44 +1000,44 @@ position: "fixed",

children: [
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("toggleBold"),
onClick: () => T("toggleBold"),
title: "Bold (Ctrl+B)",
children: /* @__PURE__ */ b("strong", { children: "B" })
children: /* @__PURE__ */ h("strong", { children: "B" })
}
),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("toggleItalic"),
onClick: () => T("toggleItalic"),
title: "Italic (Ctrl+I)",
children: /* @__PURE__ */ b("em", { children: "I" })
children: /* @__PURE__ */ h("em", { children: "I" })
}
),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("toggleUnderline"),
onClick: () => T("toggleUnderline"),
title: "Underline (Ctrl+U)",
children: /* @__PURE__ */ b("u", { children: "U" })
children: /* @__PURE__ */ h("u", { children: "U" })
}
),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("toggleStrikethrough"),
onClick: () => T("toggleStrikethrough"),
title: "Strikethrough",
children: /* @__PURE__ */ b("s", { children: "S" })
children: /* @__PURE__ */ h("s", { children: "S" })
}
),
/* @__PURE__ */ b("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ b(
/* @__PURE__ */ h("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("clearFormatting"),
onClick: () => T("clearFormatting"),
title: "Clear Formatting",

@@ -1102,7 +1047,7 @@ children: "⌫"

),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("createLink"),
onClick: () => T("createLink"),
title: "Insert Link",

@@ -1112,7 +1057,7 @@ children: "🔗"

),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("toggleCode"),
onClick: () => T("toggleCode"),
title: "Code",

@@ -1122,8 +1067,8 @@ children: "Code"

),
/* @__PURE__ */ b("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ b(
/* @__PURE__ */ h("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ h(
"button",
{
className: "floating-toolbar-btn",
onClick: () => R("setBlockType", "blockquote"),
onClick: () => T("setBlockType", "blockquote"),
title: "Quote",

@@ -1141,15 +1086,12 @@ children: "❝"

}) => {
const a = e.filter((o) => {
var r;
return (r = o.context) == null ? void 0 : r.provider;
});
return a.length === 0 ? /* @__PURE__ */ b(ne, { children: t }) : a.reduce(
(o, r) => {
const u = r.context.provider;
return /* @__PURE__ */ b(u, { children: o }, r.name);
const a = e.filter((r) => r.context?.provider);
return a.length === 0 ? /* @__PURE__ */ h(ee, { children: t }) : a.reduce(
(r, n) => {
const u = n.context.provider;
return /* @__PURE__ */ h(u, { children: r }, n.name);
},
/* @__PURE__ */ b(ne, { children: t })
/* @__PURE__ */ h(ee, { children: t })
);
}, Se = /* @__PURE__ */ new Set(), Ae = /* @__PURE__ */ new Set(), ce = (e) => !!e && typeof e == "object" && typeof e.name == "string", Re = (e) => {
const t = e == null ? void 0 : e.pluginFactories;
}, Ce = /* @__PURE__ */ new Set(), Ee = /* @__PURE__ */ new Set(), ie = (e) => !!e && typeof e == "object" && typeof e.name == "string", xe = (e) => {
const t = e?.pluginFactories;
return {

@@ -1160,18 +1102,16 @@ ...(typeof window < "u" ? window.EditoraReactPlugins : void 0) || {},

}, ot = (e, t) => {
if (!Array.isArray(e))
return [];
const a = Re(t), n = [], o = [];
if (e.forEach((r) => {
if (ce(r)) {
n.push(r);
if (!Array.isArray(e)) return [];
const a = xe(t), o = [], r = [];
if (e.forEach((n) => {
if (ie(n)) {
o.push(n);
return;
}
if (typeof r != "string")
return;
const u = a[r];
if (typeof n != "string") return;
const u = a[n];
if (typeof u == "function")
try {
const c = u();
if (ce(c)) {
n.push(c);
const f = u();
if (ie(f)) {
o.push(f);
return;

@@ -1181,7 +1121,7 @@ }

}
o.push(r);
}), o.length > 0) {
const r = o.slice().sort().join("|");
Se.has(r) || (Se.add(r), console.warn(
`[Editora React] Unresolved string plugin names: ${o.join(
r.push(n);
}), r.length > 0) {
const n = r.slice().sort().join("|");
Ce.has(n) || (Ce.add(n), console.warn(
`[Editora React] Unresolved string plugin names: ${r.join(
", "

@@ -1191,19 +1131,18 @@ )}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`

}
return n;
return o;
}, at = (e, t, a) => {
if (!(t != null && t.checker) || e.some((r) => (r == null ? void 0 : r.name) === "a11yChecker"))
return e;
const n = Re(a).a11yChecker;
if (typeof n == "function")
if (!t?.checker || e.some((n) => n?.name === "a11yChecker")) return e;
const o = xe(a).a11yChecker;
if (typeof o == "function")
try {
const r = n();
if (ce(r))
return [...e, r];
const n = o();
if (ie(n))
return [...e, n];
} catch {
}
const o = "accessibility.checker";
return Ae.has(o) || (Ae.add(o), console.warn(
const r = "accessibility.checker";
return Ee.has(r) || (Ee.add(r), console.warn(
'[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.'
)), e;
}, lt = {
}, it = {
readonly: !1,

@@ -1286,12 +1225,12 @@ placeholder: "",

};
function Me(e, t) {
function Te(e, t) {
const a = { ...e };
for (const n in t) {
const o = t[n], r = a[n];
o !== void 0 && (typeof o == "object" && o !== null && !Array.isArray(o) && typeof r == "object" && r !== null && !Array.isArray(r) ? a[n] = Me(r, o) : a[n] = o);
for (const o in t) {
const r = t[o], n = a[o];
r !== void 0 && (typeof r == "object" && r !== null && !Array.isArray(r) && typeof n == "object" && n !== null && !Array.isArray(n) ? a[o] = Te(n, r) : a[o] = r);
}
return a;
}
function st(e) {
const t = Me(lt, {
function lt(e) {
const t = Te(it, {
readonly: e.readonly,

@@ -1315,6 +1254,6 @@ placeholder: e.placeholder,

if (e.floatingToolbar !== void 0) {
const n = typeof e.floatingToolbar == "boolean" ? e.floatingToolbar : e.floatingToolbar.enabled;
const o = typeof e.floatingToolbar == "boolean" ? e.floatingToolbar : e.floatingToolbar.enabled;
t.toolbar = {
...t.toolbar,
floating: n ?? t.toolbar.floating
floating: o ?? t.toolbar.floating
};

@@ -1345,11 +1284,8 @@ }

}
const de = /* @__PURE__ */ new Map(), it = () => {
const le = /* @__PURE__ */ new Map(), ct = () => {
if (typeof window > "u")
return { editorElement: null, contentElement: null };
let e = window.__editoraCommandEditorRoot || null;
if (!e) {
const a = window.__editoraLastCommandButton || null;
e = (a == null ? void 0 : a.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")) || null;
}
const t = (e == null ? void 0 : e.querySelector(".rte-content, .editora-content")) || (e != null && e.matches(".rte-content, .editora-content") ? e : null);
e || (e = (window.__editoraLastCommandButton || null)?.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || null);
const t = e?.querySelector(".rte-content, .editora-content") || (e?.matches(".rte-content, .editora-content") ? e : null);
return {

@@ -1361,13 +1297,13 @@ editorElement: e,

typeof window < "u" && (window.registerEditorCommand = (e, t) => {
de.set(e, t);
le.set(e, t);
}, window.executeEditorCommand = (e, t) => {
const a = de.get(e);
const a = le.get(e);
if (a) {
const n = it();
return a(t, n);
const o = ct();
return a(t, o);
} else
return console.warn(`No handler registered for command: ${e}`), !1;
});
const ct = (e) => {
const t = ie(() => st(e), [
const st = (e) => {
const t = ae(() => lt(e), [
e.id,

@@ -1395,59 +1331,48 @@ e.className,

e.mediaConfig
]), a = D(null), n = D(null), o = D(e.onInit), r = D(e.onDestroy), u = D(e.onChange), c = D(/* @__PURE__ */ new Set()), d = D(null), f = D(null), s = D(null);
z(() => {
o.current = e.onInit, r.current = e.onDestroy, u.current = e.onChange;
]), a = L(null), o = L(null), r = L(e.onInit), n = L(e.onDestroy), u = L(e.onChange), f = L(/* @__PURE__ */ new Set()), s = L(null), m = L(null), c = L(null);
F(() => {
r.current = e.onInit, n.current = e.onDestroy, u.current = e.onChange;
});
const C = (y) => {
var M;
(M = u.current) == null || M.call(u, y), c.current.forEach((m) => {
const R = (v) => {
u.current?.(v), f.current.forEach((y) => {
try {
m(y);
} catch (w) {
console.error("Editora onChange subscriber failed:", w);
y(v);
} catch (g) {
console.error("Editora onChange subscriber failed:", g);
}
});
}, T = ie(() => {
const y = new Fe();
t.plugins.forEach((m) => {
y.register(m), m.commands && typeof window < "u" && Object.entries(m.commands).forEach(([w, I]) => {
de.set(w, I);
}, A = ae(() => {
const v = new Be();
t.plugins.forEach((g) => {
v.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([M, N]) => {
le.set(M, N);
});
});
const M = new Be(y);
return a.current = M, M;
const y = new Fe(v);
return a.current = y, y;
}, [t.plugins]);
z(() => {
var M;
const y = {
getHTML: () => {
var w;
const m = (w = d.current) == null ? void 0 : w.querySelector(".rte-content");
return (m == null ? void 0 : m.innerHTML) || "";
F(() => {
const v = {
getHTML: () => s.current?.querySelector(".rte-content")?.innerHTML || "",
setHTML: (y) => {
const g = s.current?.querySelector(".rte-content");
g && (g.innerHTML = y);
},
setHTML: (m) => {
var I;
const w = (I = d.current) == null ? void 0 : I.querySelector(".rte-content");
w && (w.innerHTML = m);
execCommand: (y, g) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = s.current || null, window.executeEditorCommand(y, g));
},
execCommand: (m, w) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = d.current || null, window.executeEditorCommand(m, w));
registerCommand: (y, g) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(y, g);
},
registerCommand: (m, w) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(m, w);
},
focus: () => {
var w;
const m = (w = d.current) == null ? void 0 : w.querySelector(".rte-content");
m == null || m.focus();
s.current?.querySelector(".rte-content")?.focus();
},
blur: () => {
var w;
const m = (w = d.current) == null ? void 0 : w.querySelector(".rte-content");
m == null || m.blur();
s.current?.querySelector(".rte-content")?.blur();
},
destroy: () => {
r.current && r.current();
n.current && n.current();
},
onChange: (m) => (c.current.add(m), () => {
c.current.delete(m);
onChange: (y) => (f.current.add(y), () => {
f.current.delete(y);
}),

@@ -1459,60 +1384,58 @@ getState: () => ({

toolbar: {
items: ((M = T.toolbar) == null ? void 0 : M.items) || []
items: A.toolbar?.items || []
}
};
return n.current = y, o.current && o.current(y), () => {
c.current.clear(), r.current && r.current();
return o.current = v, r.current && r.current(v), () => {
f.current.clear(), n.current && n.current();
};
}, []), z(() => {
if (t.statusbar.enabled && s.current && d.current) {
f.current || (f.current = new _e({
}, []), F(() => {
if (t.statusbar.enabled && c.current && s.current) {
m.current || (m.current = new _e({
enabled: !0,
position: t.statusbar.position
}), f.current.create(s.current));
const y = d.current.querySelector(".rte-content");
if (y) {
const M = () => {
const p = document.activeElement;
return !!p && (p === y || y.contains(p));
}, m = () => {
const p = y.getBoundingClientRect();
return p.bottom >= 0 && p.top <= window.innerHeight;
}, w = () => {
const p = window.getSelection();
if (!p || p.rangeCount === 0)
return null;
const N = p.getRangeAt(0), A = N.commonAncestorContainer;
return y.contains(A) ? N : null;
}, I = (p = !1) => {
var q;
if (t.performance.viewportOnlyScan !== !1 && !m() && !M())
}), m.current.create(c.current));
const v = s.current.querySelector(".rte-content");
if (v) {
const y = () => {
const E = document.activeElement;
return !!E && (E === v || v.contains(E));
}, g = () => {
const E = v.getBoundingClientRect();
return E.bottom >= 0 && E.top <= window.innerHeight;
}, M = () => {
const E = window.getSelection();
if (!E || E.rangeCount === 0) return null;
const z = E.getRangeAt(0), p = z.commonAncestorContainer;
return v.contains(p) ? z : null;
}, N = (E = !1) => {
if (t.performance.viewportOnlyScan !== !1 && !g() && !y())
return;
const A = w(), S = !!A || M();
if (p && !S)
const p = M(), x = !!p || y();
if (E && !x)
return;
const k = y.textContent || "", { words: _, chars: U } = ze(k), j = We(y);
let W, $;
A && (W = Oe(y, A), A.collapsed || ($ = Pe(A, W), W = void 0)), (q = f.current) == null || q.update({
wordCount: _,
charCount: U,
lineCount: j,
cursorPosition: W,
selectionInfo: $
const S = v.textContent || "", { words: W, chars: q } = ze(S), O = Oe(v);
let B, U;
p && (B = We(v, p), p.collapsed || (U = Pe(p, B), B = void 0)), m.current?.update({
wordCount: W,
charCount: q,
lineCount: O,
cursorPosition: B,
selectionInfo: U
});
}, L = () => I(), h = () => I(!0), x = () => I(), g = () => I();
return y.addEventListener("input", L), y.addEventListener("focus", x), y.addEventListener("blur", g), document.addEventListener("selectionchange", h), I(), () => {
y.removeEventListener("input", L), y.removeEventListener("focus", x), y.removeEventListener("blur", g), document.removeEventListener("selectionchange", h);
}, _ = () => N(), b = () => N(!0), d = () => N(), C = () => N();
return v.addEventListener("input", _), v.addEventListener("focus", d), v.addEventListener("blur", C), document.addEventListener("selectionchange", b), N(), () => {
v.removeEventListener("input", _), v.removeEventListener("focus", d), v.removeEventListener("blur", C), document.removeEventListener("selectionchange", b);
};
}
} else
f.current && (f.current.destroy(), f.current = null);
m.current && (m.current.destroy(), m.current = null);
return () => {
f.current && (f.current.destroy(), f.current = null);
m.current && (m.current.destroy(), m.current = null);
};
}, [t.statusbar.enabled, t.statusbar.position, t.performance.viewportOnlyScan]);
const R = t.toolbar.floating ?? !1, i = t.toolbar.position || "top", B = t.toolbar.sticky ?? !1, F = t.toolbar.showMoreOptions ?? !0;
return /* @__PURE__ */ b(rt, { plugins: t.plugins, children: /* @__PURE__ */ X(
const T = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", H = t.toolbar.sticky ?? !1, I = t.toolbar.showMoreOptions ?? !0;
return /* @__PURE__ */ h(rt, { plugins: t.plugins, children: /* @__PURE__ */ V(
"div",
{
ref: d,
ref: s,
id: t.id,

@@ -1530,18 +1453,18 @@ "data-editora-editor": !0,

children: [
i !== "bottom" && /* @__PURE__ */ b(
Ee,
l !== "bottom" && /* @__PURE__ */ h(
ve,
{
editor: T,
position: i,
sticky: B,
floating: R,
editor: A,
position: l,
sticky: H,
floating: T,
readonly: t.readonly,
showMoreOptions: F,
showMoreOptions: I,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
tt,
{
editor: T,
editor: A,
defaultValue: t.defaultValue,

@@ -1551,3 +1474,3 @@ value: t.value,

placeholder: t.placeholder,
onChange: C,
onChange: R,
pasteConfig: t.paste,

@@ -1563,19 +1486,19 @@ contentConfig: t.content,

),
i === "bottom" && /* @__PURE__ */ b(
Ee,
l === "bottom" && /* @__PURE__ */ h(
ve,
{
editor: T,
position: i,
sticky: B,
floating: R,
editor: A,
position: l,
sticky: H,
floating: T,
readonly: t.readonly,
showMoreOptions: F,
showMoreOptions: I,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ b(
/* @__PURE__ */ h(
nt,
{
editor: T,
isEnabled: R,
editor: A,
isEnabled: T,
viewportOnlyScan: t.performance.viewportOnlyScan,

@@ -1585,6 +1508,6 @@ readonly: t.readonly

),
t.statusbar.enabled && /* @__PURE__ */ b(
t.statusbar.enabled && /* @__PURE__ */ h(
"div",
{
ref: s,
ref: c,
className: "editora-statusbar-container",

@@ -1597,43 +1520,24 @@ style: { order: t.statusbar.position === "top" ? -1 : 1 }

) });
}, ht = (e) => /* @__PURE__ */ b(ct, { ...e });
function gt(e = {}) {
const t = D(null), a = D(e.onCommand);
return z(() => {
}, gt = (e) => /* @__PURE__ */ h(st, { ...e });
function ht(e = {}) {
const t = L(null), a = L(e.onCommand);
return F(() => {
a.current = e.onCommand;
}), z(() => {
if (typeof window > "u" || e.enabled === !1)
return;
const n = new Te(e);
t.current = n;
const o = (u) => n.handleKeyDown(u, (d, f) => {
a.current && a.current(d, f), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(d, f);
}), r = e.editorElement || document;
return r && r.addEventListener("keydown", o), () => {
r && r.removeEventListener("keydown", o);
}), F(() => {
if (typeof window > "u" || e.enabled === !1) return;
const o = new ke(e);
t.current = o;
const r = (u) => o.handleKeyDown(u, (s, m) => {
a.current && a.current(s, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(s, m);
}), n = e.editorElement || document;
return n && n.addEventListener("keydown", r), () => {
n && n.removeEventListener("keydown", r);
};
}, [e.editorElement, e.enabled, e.shortcuts, e.customShortcuts]), {
getShortcuts: () => {
var n;
return ((n = t.current) == null ? void 0 : n.getAllShortcuts()) || [];
},
getShortcutForCommand: (n) => {
var o;
return (o = t.current) == null ? void 0 : o.getShortcutForCommand(n);
},
getShortcutsHelp: () => {
var n;
return ((n = t.current) == null ? void 0 : n.getShortcutsHelp()) || "";
},
enable: () => {
var n;
return (n = t.current) == null ? void 0 : n.enable();
},
disable: () => {
var n;
return (n = t.current) == null ? void 0 : n.disable();
},
isEnabled: () => {
var n;
return ((n = t.current) == null ? void 0 : n.isEnabled()) || !1;
}
getShortcuts: () => t.current?.getAllShortcuts() || [],
getShortcutForCommand: (o) => t.current?.getShortcutForCommand(o),
getShortcutsHelp: () => t.current?.getShortcutsHelp() || "",
enable: () => t.current?.enable(),
disable: () => t.current?.disable(),
isEnabled: () => t.current?.isEnabled() || !1
};

@@ -1643,8 +1547,8 @@ }

tt as EditorContent,
ht as EditoraEditor,
gt as EditoraEditor,
$e as InlineMenu,
ht as RichTextEditor,
Ee as Toolbar,
st as mergeConfig,
gt as useKeyboardShortcuts
gt as RichTextEditor,
ve as Toolbar,
lt as mergeConfig,
ht as useKeyboardShortcuts
};
{
"name": "@editora/react",
"version": "1.0.11",
"version": "1.0.12",
"description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.",

@@ -67,5 +67,5 @@ "author": "Ajay Kumar <ajaykr089@gmail.com>",

"peerDependencies": {
"@editora/core": "^1.0.9",
"@editora/plugins": "^1.0.10",
"@editora/themes": "^1.0.10",
"@editora/core": "^1.0.7",
"@editora/plugins": "^1.0.8",
"@editora/themes": "^1.0.8",
"react": ">=16.8 <21",

@@ -72,0 +72,0 @@ "react-dom": ">=16.8 <21"