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.4
to
1.0.5
+1
-1
dist/index.cjs.js

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

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

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

import { jsx as d, jsxs as U, Fragment as J } from "react/jsx-runtime";
import ke, { useRef as T, useState as j, useLayoutEffect as Se, useEffect as z, useMemo as ee } from "react";
import { KeyboardShortcutManager as ge, PluginManager as Le, Editor as Ae, StatusBar as xe, calculateTextStats as Te, countLines as Me, getCursorPosition as Re, getSelectionInfo as Ie } from "@editora/core";
const Ne = ({
import { jsx as f, jsxs as q, Fragment as Q } from "react/jsx-runtime";
import Le, { useRef as R, useState as V, useLayoutEffect as Me, useEffect as O, useMemo as ne } from "react";
import { KeyboardShortcutManager as ye, PluginManager as Ne, Editor as Ie, StatusBar as De, calculateTextStats as He, countLines as Fe, getCursorPosition as Be, getSelectionInfo as ze } from "@editora/core";
const We = ({
isOpen: e,
options: t,
onSelect: u,
onClose: i,
anchorRef: r,
className: o = ""
onSelect: a,
onClose: o,
anchorRef: n,
className: r = ""
}) => {
const b = T(null), [h, c] = j(null), m = () => {
if (!e || !r.current) return;
const s = r.current.getBoundingClientRect(), x = b.current?.getBoundingClientRect(), L = x?.width || 120, N = x?.height || t.length * 36, l = 8, B = 4, D = window.innerWidth, p = window.innerHeight;
let w = s.bottom + B, a = s.left;
a + L > D - l && (a = D - L - l), a < l && (a = l), w + N > p - l && (w = s.top - N - B), w < l && (w = l), c({ top: w, left: a });
const m = R(null), [d, c] = V(null), g = () => {
if (!e || !n.current) return;
const s = n.current.getBoundingClientRect(), E = m.current?.getBoundingClientRect(), A = E?.width || 120, D = E?.height || t.length * 36, l = 8, B = 4, F = window.innerWidth, w = window.innerHeight;
let v = s.bottom + B, h = s.left;
h + A > F - l && (h = F - A - l), h < l && (h = l), v + D > w - l && (v = s.top - D - B), v < l && (v = l), c({ top: v, left: h });
};
return Se(() => {
return Me(() => {
if (!e) {

@@ -23,11 +23,11 @@ c(null);

}
m();
const s = window.requestAnimationFrame(m);
g();
const s = window.requestAnimationFrame(g);
return () => {
window.cancelAnimationFrame(s);
};
}, [e, t.length, r]), z(() => {
}, [e, t.length, n]), O(() => {
if (!e) return;
const s = () => {
m();
g();
};

@@ -37,22 +37,22 @@ return window.addEventListener("resize", s), window.addEventListener("scroll", s, !0), () => {

};
}, [e, t.length, r]), z(() => {
const s = (L) => {
b.current && !b.current.contains(L.target) && r.current && !r.current.contains(L.target) && i();
}, x = (L) => {
L.key === "Escape" && i();
}, [e, t.length, n]), O(() => {
const s = (A) => {
m.current && !m.current.contains(A.target) && n.current && !n.current.contains(A.target) && o();
}, E = (A) => {
A.key === "Escape" && o();
};
return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", x)), () => {
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", x);
return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", E)), () => {
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", E);
};
}, [e, i, r]), e ? /* @__PURE__ */ d(
}, [e, o, n]), e ? /* @__PURE__ */ f(
"div",
{
ref: b,
className: `rte-inline-menu ${o}`,
ref: m,
className: `rte-inline-menu ${r}`,
style: {
top: h?.top ?? -9999,
left: h?.left ?? -9999,
visibility: h ? "visible" : "hidden"
top: d?.top ?? -9999,
left: d?.left ?? -9999,
visibility: d ? "visible" : "hidden"
},
children: t.map((s) => /* @__PURE__ */ d(
children: t.map((s) => /* @__PURE__ */ f(
"div",

@@ -62,3 +62,3 @@ {

onClick: () => {
u(s.value), i();
a(s.value), o();
},

@@ -71,3 +71,3 @@ children: s.label

) : null;
}, G = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), De = {
}, G = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Oe = {
undo: "undo",

@@ -98,3 +98,3 @@ redo: "redo",

clearformatting: "clearFormatting"
}, He = (e, t) => {
}, Pe = (e, t) => {
if (!Array.isArray(t) || t.length === 0)

@@ -104,13 +104,13 @@ return e;

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

@@ -120,45 +120,45 @@ });

}
const m = G(c), s = De[m], x = i.get(m) || (s ? i.get(G(s)) : void 0) || r.get(m) || e.find(
(L) => G(L.command || "").includes(m)
const g = G(c), s = Oe[g], E = o.get(g) || (s ? o.get(G(s)) : void 0) || n.get(g) || e.find(
(A) => G(A.command || "").includes(g)
);
x && b.push(x);
}), b.length > 0 ? b : e;
}, de = ({
E && m.push(E);
}), m.length > 0 ? m : e;
}, be = ({
editor: e,
position: t = "top",
sticky: u = !1,
floating: i = !1,
readonly: r = !1,
showMoreOptions: o = !0,
itemsOverride: b
sticky: a = !1,
floating: o = !1,
readonly: n = !1,
showMoreOptions: r = !0,
itemsOverride: m
}) => {
const [h, c] = j(null), [m, s] = j(null), [x, L] = j(null), [N, l] = j(!1), B = T(null), D = T(null), p = T({}), w = T([]), a = T(null), A = T(null), M = T(null), v = ee(
() => He(e.pluginManager.getToolbarItems(), b),
[e, b]
), k = (n) => {
B.current = n, n && !n.collapsed && (D.current = n);
}, C = () => a.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, R = () => {
const [d, c] = V(null), [g, s] = V(null), [E, A] = V(null), [D, l] = V(!1), B = R(null), F = R(null), w = R({}), v = R([]), h = R(null), N = R(null), z = R(null), p = ne(
() => Pe(e.pluginManager.getToolbarItems(), m),
[e, m]
), u = (i) => {
B.current = i, i && !i.collapsed && (F.current = i);
}, k = () => h.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, W = () => {
if (typeof window > "u") return;
const n = a.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = n || null;
}, f = () => {
const n = C();
if (!n) return null;
const g = window.getSelection();
if (!g || g.rangeCount === 0) return null;
const S = g.getRangeAt(0);
return n.contains(S.commonAncestorContainer) ? S.cloneRange() : null;
}, y = () => {
const n = f();
n && k(n);
const i = h.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = i || null;
}, C = () => {
const i = k();
if (!i) return null;
const b = window.getSelection();
if (!b || b.rangeCount === 0) return null;
const T = b.getRangeAt(0);
return i.contains(T.commonAncestorContainer) ? T.cloneRange() : null;
}, x = () => {
const i = C();
i && u(i);
};
z(() => {
const n = () => {
y();
O(() => {
const i = () => {
x();
};
return document.addEventListener("selectionchange", n), () => {
document.removeEventListener("selectionchange", n);
return document.addEventListener("selectionchange", i), () => {
document.removeEventListener("selectionchange", i);
};
}, []);
const F = (n) => [
const S = (i) => [
"toggleBold",

@@ -173,73 +173,73 @@ "toggleItalic",

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

@@ -255,7 +255,7 @@ top: 0,

}
}, re = o && x !== null && x < v.length, Ce = (n) => {
r || !n.target.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") || (R(), y(), n.preventDefault());
}, oe = (n) => n.map((g, S) => {
const E = g.command || "";
return /* @__PURE__ */ d(
}, ce = r && E !== null && E < p.length, xe = (i) => {
n || !i.target.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") || (W(), x(), i.preventDefault());
}, se = (i) => i.map((b, T) => {
const y = b.command || "";
return /* @__PURE__ */ f(
"div",

@@ -265,18 +265,18 @@ {

style: {
display: o && x !== null && S >= x ? "none" : "flex"
display: r && E !== null && T >= E ? "none" : "flex"
},
children: g.type === "separator" ? /* @__PURE__ */ d("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : g.type === "dropdown" ? /* @__PURE__ */ U("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ U(
children: b.type === "separator" ? /* @__PURE__ */ f("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : b.type === "dropdown" ? /* @__PURE__ */ q("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ q(
"button",
{
className: "rte-toolbar-button",
"data-command": E,
"data-command": y,
"data-active": "false",
onMouseDown: (I) => {
I.preventDefault(), y();
onMouseDown: (M) => {
M.preventDefault(), x();
},
onClick: () => O(E),
disabled: r,
onClick: () => $(y),
disabled: n,
children: [
g.label,
b.label,
" ▼"

@@ -286,103 +286,103 @@ ]

),
h === E && /* @__PURE__ */ d("div", { className: "rte-toolbar-dropdown-menu", children: g.options?.map((I) => /* @__PURE__ */ d(
d === y && /* @__PURE__ */ f("div", { className: "rte-toolbar-dropdown-menu", children: b.options?.map((M) => /* @__PURE__ */ f(
"div",
{
className: "rte-toolbar-dropdown-item",
onMouseDown: (Q) => Q.preventDefault(),
onClick: () => H(E, I.value),
children: I.label
onMouseDown: (Y) => Y.preventDefault(),
onClick: () => L(y, M.value),
children: M.label
},
I.value
M.value
)) })
] }) : g.type === "inline-menu" ? /* @__PURE__ */ d(
] }) : b.type === "inline-menu" ? /* @__PURE__ */ f(
"button",
{
ref: P(E),
ref: H(y),
className: "rte-toolbar-button",
"data-command": E,
"data-command": y,
"data-active": "false",
onMouseDown: (I) => {
I.preventDefault(), y();
onMouseDown: (M) => {
M.preventDefault(), x();
},
onClick: () => $(E),
disabled: r,
title: g.label,
children: V(g.icon)
onClick: () => P(y),
disabled: n,
title: b.label,
children: U(b.icon)
}
) : g.type === "input" ? /* @__PURE__ */ d(
) : b.type === "input" ? /* @__PURE__ */ f(
"input",
{
type: "text",
className: `rte-toolbar-input ${g.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: g.placeholder,
onChange: (I) => H(E, I.target.value),
disabled: r,
onKeyDown: (I) => {
I.key === "Enter" && H(
E,
I.target.value
className: `rte-toolbar-input ${b.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: b.placeholder,
onChange: (M) => L(y, M.target.value),
disabled: n,
onKeyDown: (M) => {
M.key === "Enter" && L(
y,
M.target.value
);
},
title: g.label
title: b.label
}
) : g.type === "group" ? /* @__PURE__ */ d(
) : b.type === "group" ? /* @__PURE__ */ f(
"div",
{
className: `rte-toolbar-group-button ${g.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${g.label}`,
children: /* @__PURE__ */ d(
className: `rte-toolbar-group-button ${b.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${b.label}`,
children: /* @__PURE__ */ f(
"div",
{
className: `rte-toolbar-group-items ${g.label.toLowerCase().replace(/\s+/g, "-")}`,
children: oe(g.items || [])
className: `rte-toolbar-group-items ${b.label.toLowerCase().replace(/\s+/g, "-")}`,
children: se(b.items || [])
}
)
}
) : /* @__PURE__ */ d(
) : /* @__PURE__ */ f(
"button",
{
className: "rte-toolbar-button",
"data-command": E,
"data-command": y,
"data-active": "false",
onMouseDown: (I) => {
I.preventDefault(), y();
onMouseDown: (M) => {
M.preventDefault(), x();
},
onClick: () => H(E),
disabled: r,
title: g.label,
children: V(g.icon)
onClick: () => L(y),
disabled: n,
title: b.label,
children: U(b.icon)
}
)
},
S
T
);
});
return /* @__PURE__ */ U(J, { children: [
/* @__PURE__ */ U(
return /* @__PURE__ */ q(Q, { children: [
/* @__PURE__ */ q(
"div",
{
className: "rte-toolbar-wrapper",
style: pe,
onMouseDownCapture: Ce,
style: X,
onMouseDownCapture: xe,
children: [
/* @__PURE__ */ U("div", { className: "rte-toolbar", ref: a, children: [
/* @__PURE__ */ d(
/* @__PURE__ */ q("div", { className: "rte-toolbar", ref: h, children: [
/* @__PURE__ */ f(
"div",
{
className: "rte-toolbar-items-container",
ref: A,
style: o ? void 0 : { flexWrap: "wrap" },
children: oe(v)
ref: N,
style: r ? void 0 : { flexWrap: "wrap" },
children: se(p)
}
),
re && /* @__PURE__ */ d(
ce && /* @__PURE__ */ f(
"button",
{
ref: M,
className: `rte-toolbar-more-button ${N ? "active" : ""}`,
onMouseDown: (n) => {
n.preventDefault(), y();
ref: z,
className: `rte-toolbar-more-button ${D ? "active" : ""}`,
onMouseDown: (i) => {
i.preventDefault(), x();
},
onClick: () => l(!N),
disabled: r,
onClick: () => l(!D),
disabled: n,
title: "Show more options",

@@ -394,24 +394,24 @@ "aria-label": "More toolbar options",

] }),
re && /* @__PURE__ */ d(
ce && /* @__PURE__ */ f(
"div",
{
className: `rte-toolbar-expanded-row ${N ? "show" : ""}`,
children: v.map(
(n, g) => {
if (g < (x || 0)) return null;
const S = n.command || "";
return /* @__PURE__ */ d("div", { className: "rte-toolbar-item", children: n.type === "separator" ? /* @__PURE__ */ d("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : n.type === "dropdown" ? /* @__PURE__ */ U("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ U(
className: `rte-toolbar-expanded-row ${D ? "show" : ""}`,
children: p.map(
(i, b) => {
if (b < (E || 0)) return null;
const T = i.command || "";
return /* @__PURE__ */ f("div", { className: "rte-toolbar-item", children: i.type === "separator" ? /* @__PURE__ */ f("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : i.type === "dropdown" ? /* @__PURE__ */ q("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ q(
"button",
{
className: "rte-toolbar-button",
"data-command": S,
"data-command": T,
"data-active": "false",
onMouseDown: (E) => {
E.preventDefault(), y();
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => O(S),
disabled: r,
onClick: () => $(T),
disabled: n,
children: [
n.label,
i.label,
" ▼"

@@ -421,28 +421,28 @@ ]

),
h === S && /* @__PURE__ */ d("div", { className: "rte-toolbar-dropdown-menu", children: n.options?.map((E) => /* @__PURE__ */ d(
d === T && /* @__PURE__ */ f("div", { className: "rte-toolbar-dropdown-menu", children: i.options?.map((y) => /* @__PURE__ */ f(
"div",
{
className: "rte-toolbar-dropdown-item",
onMouseDown: (I) => I.preventDefault(),
onClick: () => H(S, E.value),
children: E.label
onMouseDown: (M) => M.preventDefault(),
onClick: () => L(T, y.value),
children: y.label
},
E.value
y.value
)) })
] }) : n.type === "inline-menu" ? /* @__PURE__ */ d(
] }) : i.type === "inline-menu" ? /* @__PURE__ */ f(
"button",
{
ref: P(S),
ref: H(T),
className: "rte-toolbar-button",
"data-command": S,
"data-command": T,
"data-active": "false",
onMouseDown: (E) => {
E.preventDefault(), y();
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => $(S),
disabled: r,
title: n.label,
children: V(n.icon)
onClick: () => P(T),
disabled: n,
title: i.label,
children: U(i.icon)
}
) : n.type === "input" ? /* @__PURE__ */ d(
) : i.type === "input" ? /* @__PURE__ */ f(
"input",

@@ -452,28 +452,28 @@ {

className: "rte-toolbar-input",
placeholder: n.placeholder,
onChange: (E) => H(S, E.target.value),
disabled: r,
onKeyDown: (E) => {
E.key === "Enter" && H(
S,
E.target.value
placeholder: i.placeholder,
onChange: (y) => L(T, y.target.value),
disabled: n,
onKeyDown: (y) => {
y.key === "Enter" && L(
T,
y.target.value
);
},
title: n.label
title: i.label
}
) : /* @__PURE__ */ d(
) : /* @__PURE__ */ f(
"button",
{
className: "rte-toolbar-button",
"data-command": S,
"data-command": T,
"data-active": "false",
onMouseDown: (E) => {
E.preventDefault(), y();
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => H(S),
disabled: r,
title: n.label,
children: V(n.icon)
onClick: () => L(T),
disabled: n,
title: i.label,
children: U(i.icon)
}
) }, g);
) }, b);
}

@@ -486,15 +486,15 @@ )

),
v.map((n) => {
if (n.type === "inline-menu") {
const g = n.command || "";
return /* @__PURE__ */ d(
Ne,
p.map((i) => {
if (i.type === "inline-menu") {
const b = i.command || "";
return /* @__PURE__ */ f(
We,
{
isOpen: m === g,
options: n.options || [],
onSelect: (S) => _(g, S),
isOpen: g === b,
options: i.options || [],
onSelect: (T) => _(b, T),
onClose: () => s(null),
anchorRef: P(g)
anchorRef: H(b)
},
`menu-${g || "unknown"}`
`menu-${b || "unknown"}`
);

@@ -506,16 +506,16 @@ }

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

@@ -527,3 +527,3 @@ await fetch(t.apiUrl, {

},
body: JSON.stringify({ content: m, timestamp: Date.now() })
body: JSON.stringify({ content: g, timestamp: Date.now() })
}), console.log("[Autosave] Content saved to API");

@@ -535,15 +535,15 @@ } catch (s) {

};
return u.current = setInterval(c, o), () => {
u.current && clearInterval(u.current);
return a.current = setInterval(c, r), () => {
a.current && clearInterval(a.current);
};
}, [t?.enabled, t?.intervalMs, t?.storageKey, t?.provider, t?.apiUrl, e]), { restore: () => {
if (!t?.enabled) return null;
const o = t.storageKey || "rte-autosave";
const r = t.storageKey || "rte-autosave";
if ((t.provider || "localStorage") === "localStorage")
try {
const h = localStorage.getItem(o), c = localStorage.getItem(`${o}-timestamp`);
if (h && c)
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(c))), h;
} catch (h) {
console.error("[Autosave] Failed to restore from localStorage:", h);
const d = localStorage.getItem(r), c = localStorage.getItem(`${r}-timestamp`);
if (d && c)
return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(c))), d;
} catch (d) {
console.error("[Autosave] Failed to restore from localStorage:", d);
}

@@ -553,3 +553,3 @@ return null;

}
const Fe = [
const $e = [
"p",

@@ -592,3 +592,3 @@ "br",

"hr"
], ze = {
], Ue = {
"*": ["class", "style", "id", "data-*"],

@@ -603,37 +603,37 @@ a: ["href", "target", "rel", "title"],

};
function be(e, t, u) {
function Ee(e, t, a) {
if (t?.sanitize === !1)
return e;
const i = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Fe, o = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : ze, b = document.createElement("div");
return b.innerHTML = e, he(b, i, o), b.innerHTML;
const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : $e, r = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ue, m = document.createElement("div");
return m.innerHTML = e, ke(m, o, r), m.innerHTML;
}
function he(e, t, u) {
const i = Array.from(e.childNodes);
for (const r of i)
if (r.nodeType === Node.ELEMENT_NODE) {
const o = r, b = o.tagName.toLowerCase();
if (!t.includes(b)) {
for (; o.firstChild; )
e.insertBefore(o.firstChild, o);
e.removeChild(o);
function ke(e, t, a) {
const o = Array.from(e.childNodes);
for (const n of o)
if (n.nodeType === Node.ELEMENT_NODE) {
const r = n, m = r.tagName.toLowerCase();
if (!t.includes(m)) {
for (; r.firstChild; )
e.insertBefore(r.firstChild, r);
e.removeChild(r);
continue;
}
We(o, u), he(o, t, u);
qe(r, a), ke(r, t, a);
} else {
if (r.nodeType === Node.TEXT_NODE)
if (n.nodeType === Node.TEXT_NODE)
continue;
e.removeChild(r);
e.removeChild(n);
}
}
function We(e, t) {
const u = e.tagName.toLowerCase(), i = Array.from(e.attributes), r = t[u] || [], o = t["*"] || [], b = [...r, ...o];
for (const h of i) {
const c = h.name.toLowerCase();
let m = !1;
b.includes(c) && (m = !0);
for (const s of b)
function qe(e, t) {
const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), n = t[a] || [], r = t["*"] || [], m = [...n, ...r];
for (const d of o) {
const c = d.name.toLowerCase();
let g = !1;
m.includes(c) && (g = !0);
for (const s of m)
if (s.endsWith("*")) {
const x = s.slice(0, -1);
if (c.startsWith(x)) {
m = !0;
const E = s.slice(0, -1);
if (c.startsWith(E)) {
g = !0;
break;

@@ -643,148 +643,242 @@ }

(c.startsWith("on") || // Event handlers
c === "javascript:" || c === "href" && h.value.trim().toLowerCase().startsWith("javascript:") || c === "src" && h.value.trim().toLowerCase().startsWith("javascript:")) && (m = !1), m || e.removeAttribute(h.name);
c === "javascript:" || c === "href" && d.value.trim().toLowerCase().startsWith("javascript:") || c === "src" && d.value.trim().toLowerCase().startsWith("javascript:")) && (g = !1), g || e.removeAttribute(d.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 Pe(e, t, u) {
return u?.sanitizeOnPaste === !1 ? e : be(e, t);
function Ke(e, t, a) {
return a?.sanitizeOnPaste === !1 ? e : Ee(e, t);
}
function Oe(e, t, u) {
return u?.sanitizeOnInput === !1 ? e : be(e, t);
function ve(e, t, a) {
return a?.sanitizeOnInput === !1 ? e : Ee(e, t);
}
const X = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), K = (e, t) => {
const i = !!t && X(e);
e.classList.toggle("rte-content-empty", i);
}, Ue = ({
const J = (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 && J(e);
e.classList.toggle("rte-content-empty", o);
}, ae = "data-rte-caret-marker", ie = "data-rte-range-start-marker", le = "data-rte-range-end-marker", te = () => Math.random().toString(36).slice(2), Ve = (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 n = a.cloneRange();
return n.selectNodeContents(e), n.setEnd(a.endContainer, a.endOffset), {
start: o.toString().length,
end: n.toString().length
};
} catch {
return null;
}
}, we = (e, t) => {
const a = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);
let o = a.nextNode(), n = Math.max(0, t), r = null;
for (; o; ) {
r = o;
const m = o.textContent?.length ?? 0;
if (n <= m)
return { node: o, offset: n };
n -= m, o = a.nextNode();
}
return r ? {
node: r,
offset: r.textContent?.length ?? 0
} : { node: e, offset: e.childNodes.length };
}, je = (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 = Ve(e);
try {
if (a.collapsed) {
const s = te(), E = document.createElement("span");
return E.setAttribute(ae, s), E.appendChild(document.createTextNode("​")), a.cloneRange().insertNode(E), { collapsed: !0, caretId: s, fallbackOffsets: o };
}
const n = te(), r = te(), m = document.createElement("span");
m.setAttribute(le, r), m.appendChild(document.createTextNode("​"));
const d = document.createElement("span");
d.setAttribute(ie, n), d.appendChild(document.createTextNode("​"));
const c = a.cloneRange();
c.collapse(!1), c.insertNode(m);
const g = a.cloneRange();
return g.collapse(!0), g.insertNode(d), { collapsed: !1, startId: n, endId: r, fallbackOffsets: o };
} catch {
return { collapsed: a.collapsed, fallbackOffsets: o };
}
}, Ge = (e) => {
e.querySelectorAll(
`[${ae}], [${ie}], [${le}]`
).forEach((t) => t.remove());
}, Xe = (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 n = e.querySelector(`[${ae}="${t.caretId}"]`);
return !n || !n.parentNode ? !1 : (o.setStartAfter(n), o.collapse(!0), a.removeAllRanges(), a.addRange(o), !0);
}
if (!t.collapsed && t.startId && t.endId) {
const n = e.querySelector(`[${ie}="${t.startId}"]`), r = e.querySelector(`[${le}="${t.endId}"]`);
return !n || !r || !n.parentNode || !r.parentNode ? !1 : (o.setStartAfter(n), o.setEndBefore(r), a.removeAllRanges(), a.addRange(o), !0);
}
} catch {
return !1;
}
return !1;
}, Je = (e, t) => {
if (!t) return;
const a = window.getSelection();
if (a)
try {
const o = we(e, t.start), n = we(e, t.end), r = document.createRange();
r.setStart(o.node, o.offset), r.setEnd(n.node, n.offset), a.removeAllRanges(), a.addRange(r);
} catch {
}
}, Qe = ({
editor: e,
defaultValue: t,
value: u,
readonly: i = !1,
placeholder: r,
onChange: o,
pasteConfig: b,
contentConfig: h,
value: a,
readonly: o = !1,
placeholder: n,
onChange: r,
pasteConfig: m,
contentConfig: d,
securityConfig: c,
performanceConfig: m,
performanceConfig: g,
accessibilityConfig: s,
autosaveConfig: x,
contextMenuConfig: L,
spellcheckConfig: N
autosaveConfig: E,
contextMenuConfig: A,
spellcheckConfig: D
}) => {
const l = T(null), B = u !== void 0, D = T(), { restore: p } = Be(
const l = R(null), B = a !== void 0, F = R(), w = d?.autoHeight === !0, v = typeof d?.minHeight == "number" ? d.minHeight : 200, h = typeof d?.maxHeight == "number" ? d.maxHeight : 0, N = (u) => {
if (!u || !w) return;
u.style.height = "auto";
const k = Math.max(v, u.scrollHeight);
if (h > 0) {
u.style.height = `${Math.min(k, h)}px`;
return;
}
u.style.height = `${k}px`;
}, { restore: z } = _e(
() => l.current?.innerHTML || "",
x
E
);
z(() => {
O(() => {
if (!l.current) return;
const a = p(), A = a ?? u ?? t ?? "";
A.trim() ? l.current.innerHTML !== A && (l.current.innerHTML = A) : r ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), K(l.current, r), a && o && o(a);
}, []), z(() => {
!l.current || !B || (u !== l.current.innerHTML && (l.current.innerHTML = u), K(l.current, r));
}, [u, B]), z(() => {
const u = z(), k = u ?? a ?? t ?? "";
k.trim() ? l.current.innerHTML !== k && (l.current.innerHTML = k) : n ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), j(l.current, n), N(l.current), u && r && r(u);
}, []), O(() => {
!l.current || !B || (a !== l.current.innerHTML && (l.current.innerHTML = a), j(l.current, n), N(l.current));
}, [a, B]), O(() => {
if (!l.current) return;
const a = l.current;
if (r) {
a.setAttribute("data-placeholder", r), X(a) && (a.innerHTML = ""), K(a, r);
const u = l.current;
if (n) {
u.setAttribute("data-placeholder", n), J(u) && (u.innerHTML = ""), j(u, n), N(u);
return;
}
a.removeAttribute("data-placeholder"), K(a, r);
}, [r]), z(() => {
u.removeAttribute("data-placeholder"), j(u, n), N(u);
}, [n]), O(() => {
if (!l.current) return;
const a = l.current;
const u = l.current;
if (s?.enableARIA !== !1) {
a.setAttribute("role", "textbox"), a.setAttribute("aria-multiline", "true"), a.setAttribute("aria-disabled", i ? "true" : "false");
const M = r?.trim();
M ? a.setAttribute("aria-label", M) : a.removeAttribute("aria-label");
u.setAttribute("role", "textbox"), u.setAttribute("aria-multiline", "true"), u.setAttribute("aria-disabled", o ? "true" : "false");
const W = n?.trim();
W ? u.setAttribute("aria-label", W) : u.removeAttribute("aria-label");
} else
a.removeAttribute("role"), a.removeAttribute("aria-multiline"), a.removeAttribute("aria-label"), a.removeAttribute("aria-disabled");
}, [s?.enableARIA, r, i]), z(() => {
u.removeAttribute("role"), u.removeAttribute("aria-multiline"), u.removeAttribute("aria-label"), u.removeAttribute("aria-disabled");
}, [s?.enableARIA, n, o]), O(() => {
N(l.current);
}, [w, v, h, a]), O(() => {
if (!l.current) return;
const a = () => {
if (!l.current || i) return;
r && X(l.current) && (l.current.innerHTML = "");
let R = l.current.innerHTML;
if (c?.sanitizeOnInput !== !1 && h?.sanitize !== !1 && (R = Oe(R, h, c), R !== l.current.innerHTML)) {
const f = window.getSelection(), y = f && f.rangeCount > 0 ? f.getRangeAt(0) : null;
if (l.current.innerHTML = R, y && f)
try {
f.removeAllRanges(), f.addRange(y);
} catch {
}
const u = () => {
if (!l.current || o) return;
n && J(l.current) && (l.current.innerHTML = "");
let I = l.current.innerHTML;
if (c?.sanitizeOnInput !== !1 && d?.sanitize !== !1) {
const H = ve(I, d, c);
if (H !== l.current.innerHTML) {
const L = je(l.current), $ = l.current.innerHTML, P = ve($, d, c);
l.current.innerHTML = P, Xe(l.current, L) || Je(l.current, L?.fallbackOffsets || null), Ge(l.current), I = l.current.innerHTML;
} else
I = H;
}
K(l.current, r), o && (m?.debounceInputMs ? (D.current && clearTimeout(D.current), D.current = setTimeout(() => {
o(R);
}, m.debounceInputMs)) : o(R));
}, A = (R) => {
if (i) {
R.preventDefault();
j(l.current, n), N(l.current), r && (g?.debounceInputMs ? (F.current && clearTimeout(F.current), F.current = setTimeout(() => {
r(I);
}, g.debounceInputMs)) : r(I));
}, k = (I) => {
if (o) {
I.preventDefault();
return;
}
R.preventDefault();
let f = R.clipboardData?.getData("text/html");
const y = R.clipboardData?.getData("text/plain"), F = !!f && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(f);
if (b?.clean || !b?.keepFormatting) {
y && document.execCommand("insertText", !1, y);
I.preventDefault();
let H = I.clipboardData?.getData("text/html");
const L = I.clipboardData?.getData("text/plain"), $ = !!H && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(H);
if (m?.clean || !m?.keepFormatting) {
L && document.execCommand("insertText", !1, L);
return;
}
if (b?.convertWord === !1 && F) {
y && document.execCommand("insertText", !1, y);
if (m?.convertWord === !1 && $) {
L && document.execCommand("insertText", !1, L);
return;
}
if (f) {
c?.sanitizeOnPaste !== !1 && h?.sanitize !== !1 && (f = Pe(f, h, c));
const W = window.getSelection();
if (W && W.rangeCount > 0) {
const P = W.getRangeAt(0);
P.deleteContents();
const H = document.createElement("div");
H.innerHTML = f;
const O = document.createDocumentFragment();
for (; H.firstChild; )
O.appendChild(H.firstChild);
P.insertNode(O), P.collapse(!1), W.removeAllRanges(), W.addRange(P);
if (H) {
c?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (H = Ke(H, d, c));
const P = window.getSelection();
if (P && P.rangeCount > 0) {
const _ = P.getRangeAt(0);
_.deleteContents();
const U = document.createElement("div");
U.innerHTML = H;
const X = document.createDocumentFragment();
for (; U.firstChild; )
X.appendChild(U.firstChild);
_.insertNode(X), _.collapse(!1), P.removeAllRanges(), P.addRange(_);
}
} else y && document.execCommand("insertText", !1, y);
}, M = (R) => {
const f = R.target;
(f.tagName === "IMG" || f.tagName === "VIDEO") && (f.style.resize = "both", f.style.overflow = "auto", f.style.display = "inline-block");
}, v = (R) => {
L?.enabled === !1 && R.preventDefault();
}, k = () => {
l.current && (r && X(l.current) && (l.current.innerHTML = ""), K(l.current, r));
}, C = l.current;
return C.addEventListener("input", a), C.addEventListener("paste", A), C.addEventListener("click", M), C.addEventListener("contextmenu", v), C.addEventListener("focus", k), C.addEventListener("blur", k), i || C.focus(), () => {
D.current && clearTimeout(D.current), C.removeEventListener("input", a), C.removeEventListener("paste", A), C.removeEventListener("click", M), C.removeEventListener("contextmenu", v), C.removeEventListener("focus", k), C.removeEventListener("blur", k);
} else L && document.execCommand("insertText", !1, L);
}, W = (I) => {
const H = I.target;
(H.tagName === "IMG" || H.tagName === "VIDEO") && (H.style.resize = "both", H.style.overflow = "auto", H.style.display = "inline-block");
}, C = (I) => {
A?.enabled === !1 && I.preventDefault();
}, x = () => {
l.current && (n && J(l.current) && (l.current.innerHTML = ""), j(l.current, n), N(l.current));
}, S = l.current;
return S.addEventListener("input", u), S.addEventListener("paste", k), S.addEventListener("click", W), S.addEventListener("contextmenu", C), S.addEventListener("focus", x), S.addEventListener("blur", x), o || S.focus(), () => {
F.current && clearTimeout(F.current), S.removeEventListener("input", u), S.removeEventListener("paste", k), S.removeEventListener("click", W), S.removeEventListener("contextmenu", C), S.removeEventListener("focus", x), S.removeEventListener("blur", x);
};
}, [e, o, b, h, c, m, r, L, i]);
const w = (N?.enabled ?? !1) && (N?.provider ?? "browser") === "browser";
return z(() => {
if (!l.current || typeof window > "u" || i || s?.keyboardNavigation === !1)
}, [e, r, m, d, c, g, n, A, o]);
const p = (D?.enabled ?? !1) && (D?.provider ?? "browser") === "browser";
return O(() => {
if (!l.current || typeof window > "u" || o || s?.keyboardNavigation === !1)
return;
const a = new ge(), A = l.current, M = (v) => {
a.handleKeyDown(v, (k, C) => {
const u = new ye(), k = l.current, W = (C) => {
u.handleKeyDown(C, (x, S) => {
if (typeof window < "u" && window.executeEditorCommand) {
const R = l.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = R || null, window.executeEditorCommand(k, C);
const I = l.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = I || null, window.executeEditorCommand(x, S);
}
});
};
return A.addEventListener("keydown", M), () => {
A.removeEventListener("keydown", M);
return k.addEventListener("keydown", W), () => {
k.removeEventListener("keydown", W);
};
}, [s?.keyboardNavigation, i]), /* @__PURE__ */ d(
}, [s?.keyboardNavigation, o]), /* @__PURE__ */ f(
"div",
{
ref: l,
contentEditable: !i,
contentEditable: !o,
suppressContentEditableWarning: !0,
spellCheck: i ? !1 : w,
spellCheck: o ? !1 : p,
tabIndex: s?.keyboardNavigation === !1 ? -1 : 0,
"aria-keyshortcuts": s?.keyboardNavigation === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y",
"data-viewport-only-scan": m?.viewportOnlyScan ? "true" : "false",
"data-viewport-only-scan": g?.viewportOnlyScan ? "true" : "false",
"data-a11y-checker": s?.checker ? "true" : "false",
"data-readonly": i ? "true" : "false",
className: `rte-content ${i ? "rte-content-readonly" : ""}`,
"data-readonly": o ? "true" : "false",
className: `rte-content ${o ? "rte-content-readonly" : ""}`,
style: {
minHeight: "200px",
maxHeight: "100%",
minHeight: `${v}px`,
maxHeight: w ? h > 0 ? `${h}px` : "none" : "100%",
padding: "16px",

@@ -796,4 +890,4 @@ outline: "none",

lineHeight: "1.5",
overflow: "auto",
flex: 1,
overflow: w ? h > 0 ? "auto" : "hidden" : "auto",
flex: w ? void 0 : 1,
boxSizing: "border-box",

@@ -805,88 +899,88 @@ wordWrap: "break-word",

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

@@ -906,6 +1000,6 @@ }

toggleCode: () => {
const a = window.getSelection();
if (a && a.rangeCount > 0) {
const A = a.getRangeAt(0), M = document.createElement("code");
A.surroundContents(M);
const h = window.getSelection();
if (h && h.rangeCount > 0) {
const N = h.getRangeAt(0), z = document.createElement("code");
N.surroundContents(z);
}

@@ -915,17 +1009,17 @@ },

if (B === "blockquote") {
const a = window.getSelection();
if (a && a.rangeCount > 0) {
const A = a.getRangeAt(0);
(A.commonAncestorContainer.nodeType === Node.TEXT_NODE ? A.commonAncestorContainer.parentElement : A.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
const h = window.getSelection();
if (h && h.rangeCount > 0) {
const N = h.getRangeAt(0);
(N.commonAncestorContainer.nodeType === Node.TEXT_NODE ? N.commonAncestorContainer.parentElement : N.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
}
} else B && document.execCommand("formatBlock", !1, B);
}
})[l]?.(), o(!1), s.current = null;
})[l]?.(), r(!1), s.current = null;
};
return !t || i ? /* @__PURE__ */ d("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ U(J, { children: [
/* @__PURE__ */ d("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }),
r && /* @__PURE__ */ U(
return !t || o ? /* @__PURE__ */ f("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ q(Q, { children: [
/* @__PURE__ */ f("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }),
n && /* @__PURE__ */ q(
"div",
{
ref: m,
ref: g,
className: "floating-toolbar",

@@ -935,4 +1029,4 @@ onMouseDown: (l) => l.preventDefault(),

position: "fixed",
top: `${b.top}px`,
left: `${b.left}px`,
top: `${m.top}px`,
left: `${m.left}px`,
transform: "translateX(-50%)",

@@ -943,44 +1037,44 @@ zIndex: 1e4,

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

@@ -990,7 +1084,7 @@ children: "⌫"

),
/* @__PURE__ */ d(
/* @__PURE__ */ f(
"button",
{
className: "floating-toolbar-btn",
onClick: () => N("createLink"),
onClick: () => D("createLink"),
title: "Insert Link",

@@ -1000,7 +1094,7 @@ children: "🔗"

),
/* @__PURE__ */ d(
/* @__PURE__ */ f(
"button",
{
className: "floating-toolbar-btn",
onClick: () => N("toggleCode"),
onClick: () => D("toggleCode"),
title: "Code",

@@ -1010,8 +1104,8 @@ children: "Code"

),
/* @__PURE__ */ d("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ d(
/* @__PURE__ */ f("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ f(
"button",
{
className: "floating-toolbar-btn",
onClick: () => N("setBlockType", "blockquote"),
onClick: () => D("setBlockType", "blockquote"),
title: "Quote",

@@ -1025,15 +1119,15 @@ children: "❝"

] });
}, qe = ({
}, Ze = ({
plugins: e,
children: t
}) => {
const u = e.filter((r) => r.context?.provider);
return u.length === 0 ? /* @__PURE__ */ d(J, { children: t }) : u.reduce(
(r, o) => {
const b = o.context.provider;
return /* @__PURE__ */ d(b, { children: r }, o.name);
const a = e.filter((n) => n.context?.provider);
return a.length === 0 ? /* @__PURE__ */ f(Q, { children: t }) : a.reduce(
(n, r) => {
const m = r.context.provider;
return /* @__PURE__ */ f(m, { children: n }, r.name);
},
/* @__PURE__ */ d(J, { children: t })
/* @__PURE__ */ f(Q, { children: t })
);
}, fe = /* @__PURE__ */ new Set(), me = /* @__PURE__ */ new Set(), te = (e) => !!e && typeof e == "object" && typeof e.name == "string", ve = (e) => {
}, pe = /* @__PURE__ */ new Set(), Ce = /* @__PURE__ */ new Set(), re = (e) => !!e && typeof e == "object" && typeof e.name == "string", Se = (e) => {
const t = e?.pluginFactories;

@@ -1044,17 +1138,17 @@ return {

};
}, $e = (e, t) => {
}, et = (e, t) => {
if (!Array.isArray(e)) return [];
const u = ve(t), i = [], r = [];
if (e.forEach((o) => {
if (te(o)) {
i.push(o);
const a = Se(t), o = [], n = [];
if (e.forEach((r) => {
if (re(r)) {
o.push(r);
return;
}
if (typeof o != "string") return;
const b = u[o];
if (typeof b == "function")
if (typeof r != "string") return;
const m = a[r];
if (typeof m == "function")
try {
const h = b();
if (te(h)) {
i.push(h);
const d = m();
if (re(d)) {
o.push(d);
return;

@@ -1064,7 +1158,7 @@ }

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

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

}
return i;
}, Ve = (e, t, u) => {
if (!t?.checker || e.some((o) => o?.name === "a11yChecker")) return e;
const i = ve(u).a11yChecker;
if (typeof i == "function")
return o;
}, tt = (e, t, a) => {
if (!t?.checker || e.some((r) => r?.name === "a11yChecker")) return e;
const o = Se(a).a11yChecker;
if (typeof o == "function")
try {
const o = i();
if (te(o))
return [...e, o];
const r = o();
if (re(r))
return [...e, r];
} catch {
}
const r = "accessibility.checker";
return me.has(r) || (me.add(r), console.warn(
const n = "accessibility.checker";
return Ce.has(n) || (Ce.add(n), console.warn(
'[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.'
)), e;
}, je = {
}, nt = {
readonly: !1,

@@ -1158,3 +1252,6 @@ placeholder: "",

allowedAttributes: {},
sanitize: !0
sanitize: !0,
autoHeight: !1,
minHeight: 200,
maxHeight: 0
},

@@ -1166,12 +1263,12 @@ security: {

};
function we(e, t) {
const u = { ...e };
for (const i in t) {
const r = t[i], o = u[i];
r !== void 0 && (typeof r == "object" && r !== null && !Array.isArray(r) && typeof o == "object" && o !== null && !Array.isArray(o) ? u[i] = we(o, r) : u[i] = r);
function Ae(e, t) {
const a = { ...e };
for (const o in t) {
const n = t[o], r = a[o];
n !== void 0 && (typeof n == "object" && n !== null && !Array.isArray(n) && typeof r == "object" && r !== null && !Array.isArray(r) ? a[o] = Ae(r, n) : a[o] = n);
}
return u;
return a;
}
function Ke(e) {
const t = we(je, {
function rt(e) {
const t = Ae(nt, {
readonly: e.readonly,

@@ -1195,6 +1292,6 @@ placeholder: e.placeholder,

if (e.floatingToolbar !== void 0) {
const i = 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: i ?? t.toolbar.floating
floating: o ?? t.toolbar.floating
};

@@ -1217,4 +1314,4 @@ }

onDestroy: e.onDestroy,
plugins: Ve(
$e(e.plugins, e.pluginConfig),
plugins: tt(
et(e.plugins, e.pluginConfig),
e.accessibility,

@@ -1226,11 +1323,11 @@ e.pluginConfig

}
const ne = /* @__PURE__ */ new Map();
const oe = /* @__PURE__ */ new Map();
typeof window < "u" && (window.registerEditorCommand = (e, t) => {
ne.set(e, t);
oe.set(e, t);
}, window.executeEditorCommand = (e, t) => {
const u = ne.get(e);
return u ? u(t) : (console.warn(`No handler registered for command: ${e}`), !1);
const a = oe.get(e);
return a ? a(t) : (console.warn(`No handler registered for command: ${e}`), !1);
});
const Ge = (e) => {
const t = ee(() => Ke(e), [
const ot = (e) => {
const t = ne(() => rt(e), [
e.id,

@@ -1258,36 +1355,36 @@ e.className,

e.mediaConfig
]), u = T(null), i = T(null), r = T(e.onInit), o = T(e.onDestroy), b = T(e.onChange), h = T(/* @__PURE__ */ new Set()), c = T(null), m = T(null), s = T(null);
z(() => {
r.current = e.onInit, o.current = e.onDestroy, b.current = e.onChange;
]), a = R(null), o = R(null), n = R(e.onInit), r = R(e.onDestroy), m = R(e.onChange), d = R(/* @__PURE__ */ new Set()), c = R(null), g = R(null), s = R(null);
O(() => {
n.current = e.onInit, r.current = e.onDestroy, m.current = e.onChange;
});
const x = (p) => {
b.current?.(p), h.current.forEach((w) => {
const E = (w) => {
m.current?.(w), d.current.forEach((v) => {
try {
w(p);
} catch (a) {
console.error("Editora onChange subscriber failed:", a);
v(w);
} catch (h) {
console.error("Editora onChange subscriber failed:", h);
}
});
}, L = ee(() => {
const p = new Le();
t.plugins.forEach((a) => {
p.register(a), a.commands && typeof window < "u" && Object.entries(a.commands).forEach(([A, M]) => {
ne.set(A, M);
}, A = ne(() => {
const w = new Ne();
t.plugins.forEach((h) => {
w.register(h), h.commands && typeof window < "u" && Object.entries(h.commands).forEach(([N, z]) => {
oe.set(N, z);
});
});
const w = new Ae(p);
return u.current = w, w;
const v = new Ie(w);
return a.current = v, v;
}, [t.plugins]);
z(() => {
const p = {
O(() => {
const w = {
getHTML: () => c.current?.querySelector(".rte-content")?.innerHTML || "",
setHTML: (w) => {
const a = c.current?.querySelector(".rte-content");
a && (a.innerHTML = w);
setHTML: (v) => {
const h = c.current?.querySelector(".rte-content");
h && (h.innerHTML = v);
},
execCommand: (w, a) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(w, a));
execCommand: (v, h) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(v, h));
},
registerCommand: (w, a) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(w, a);
registerCommand: (v, h) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(v, h);
},

@@ -1301,6 +1398,6 @@ focus: () => {

destroy: () => {
o.current && o.current();
r.current && r.current();
},
onChange: (w) => (h.current.add(w), () => {
h.current.delete(w);
onChange: (v) => (d.current.add(v), () => {
d.current.delete(v);
}),

@@ -1312,55 +1409,55 @@ getState: () => ({

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

@@ -1381,18 +1478,18 @@ {

children: [
l !== "bottom" && /* @__PURE__ */ d(
de,
l !== "bottom" && /* @__PURE__ */ f(
be,
{
editor: L,
editor: A,
position: l,
sticky: B,
floating: N,
floating: D,
readonly: t.readonly,
showMoreOptions: D,
showMoreOptions: F,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ d(
Ue,
/* @__PURE__ */ f(
Qe,
{
editor: L,
editor: A,
defaultValue: t.defaultValue,

@@ -1402,3 +1499,3 @@ value: t.value,

placeholder: t.placeholder,
onChange: x,
onChange: E,
pasteConfig: t.paste,

@@ -1414,19 +1511,19 @@ contentConfig: t.content,

),
l === "bottom" && /* @__PURE__ */ d(
de,
l === "bottom" && /* @__PURE__ */ f(
be,
{
editor: L,
editor: A,
position: l,
sticky: B,
floating: N,
floating: D,
readonly: t.readonly,
showMoreOptions: D,
showMoreOptions: F,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ d(
_e,
/* @__PURE__ */ f(
Ye,
{
editor: L,
isEnabled: N,
editor: A,
isEnabled: D,
viewportOnlyScan: t.performance.viewportOnlyScan,

@@ -1436,3 +1533,3 @@ readonly: t.readonly

),
t.statusbar.enabled && /* @__PURE__ */ d(
t.statusbar.enabled && /* @__PURE__ */ f(
"div",

@@ -1448,20 +1545,20 @@ {

) });
}, Ze = (e) => /* @__PURE__ */ d(Ge, { ...e });
function et(e = {}) {
const t = T(null), u = T(e.onCommand);
return z(() => {
u.current = e.onCommand;
}), z(() => {
}, st = (e) => /* @__PURE__ */ f(ot, { ...e });
function ut(e = {}) {
const t = R(null), a = R(e.onCommand);
return O(() => {
a.current = e.onCommand;
}), O(() => {
if (typeof window > "u" || e.enabled === !1) return;
const i = new ge(e);
t.current = i;
const r = (b) => i.handleKeyDown(b, (c, m) => {
u.current && u.current(c, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(c, m);
}), o = e.editorElement || document;
return o && o.addEventListener("keydown", r), () => {
o && o.removeEventListener("keydown", r);
const o = new ye(e);
t.current = o;
const n = (m) => o.handleKeyDown(m, (c, g) => {
a.current && a.current(c, g), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(c, g);
}), r = e.editorElement || document;
return r && r.addEventListener("keydown", n), () => {
r && r.removeEventListener("keydown", n);
};
}, [e.editorElement, e.enabled, e.shortcuts, e.customShortcuts]), {
getShortcuts: () => t.current?.getAllShortcuts() || [],
getShortcutForCommand: (i) => t.current?.getShortcutForCommand(i),
getShortcutForCommand: (o) => t.current?.getShortcutForCommand(o),
getShortcutsHelp: () => t.current?.getShortcutsHelp() || "",

@@ -1474,9 +1571,9 @@ enable: () => t.current?.enable(),

export {
Ue as EditorContent,
Ze as EditoraEditor,
Ne as InlineMenu,
Ze as RichTextEditor,
de as Toolbar,
Ke as mergeConfig,
et as useKeyboardShortcuts
Qe as EditorContent,
st as EditoraEditor,
We as InlineMenu,
st as RichTextEditor,
be as Toolbar,
rt as mergeConfig,
ut as useKeyboardShortcuts
};
{
"name": "@editora/react",
"version": "1.0.4",
"version": "1.0.5",
"description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.",

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

"peerDependencies": {
"@editora/core": "^1.0.4",
"@editora/plugins": "^1.0.4",
"@editora/themes": "^1.0.4",
"@editora/core": "^1.0.5",
"@editora/plugins": "^1.0.5",
"@editora/themes": "^1.0.5",
"react": ">=16.8.0 <20",

@@ -76,6 +76,6 @@ "react-dom": ">=16.8.0 <20"

"dependencies": {
"@editora/light-code-editor": "^1.0.2"
"@editora/light-code-editor": "^1.0.4"
},
"devDependencies": {
"@editora/core": "^1.0.4",
"@editora/core": "^1.0.5",
"@types/react": "^18.2.0",

@@ -82,0 +82,0 @@ "@types/react-dom": "^18.2.0",

@@ -141,2 +141,19 @@ # @editora/react

### Content Sizing (Scrollable vs Auto Height)
```tsx
// Default: fixed layout + scrollable content area
<EditoraEditor plugins={[BoldPlugin()]} />
// Optional: grow editor content height with content
<EditoraEditor
plugins={[BoldPlugin()]}
content={{
autoHeight: true,
minHeight: 220,
maxHeight: 700, // optional cap; keeps scrolling after cap
}}
/>
```
### With Custom Toolbar

@@ -143,0 +160,0 @@