🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@editora/react

Package Overview
Dependencies
Maintainers
1
Versions
18
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.7
to
1.0.8
+1
-1
dist/index.cjs.js

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

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

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

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 = ({
import { jsx as h, jsxs as V, Fragment as Y } from "react/jsx-runtime";
import Me, { useRef as A, useState as j, useLayoutEffect as Ie, useEffect as W, useMemo as oe } from "react";
import { KeyboardShortcutManager as Ee, PluginManager as Ne, Editor as He, StatusBar as De, calculateTextStats as Fe, countLines as Be, getCursorPosition as ze, getSelectionInfo as We } from "@editora/core";
const Oe = ({
isOpen: e,

@@ -12,9 +12,9 @@ options: t,

}) => {
const m = R(null), [d, c] = V(null), g = () => {
const f = A(null), [d, c] = j(null), m = () => {
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 });
const s = n.current.getBoundingClientRect(), C = f.current?.getBoundingClientRect(), S = C?.width || 120, M = C?.height || t.length * 36, i = 8, F = 4, D = window.innerWidth, w = window.innerHeight;
let b = s.bottom + F, g = s.left;
g + S > D - i && (g = D - S - i), g < i && (g = i), b + M > w - i && (b = s.top - M - F), b < i && (b = i), c({ top: b, left: g });
};
return Me(() => {
return Ie(() => {
if (!e) {

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

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

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

};
}, [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();
}, [e, t.length, n]), W(() => {
const s = (S) => {
f.current && !f.current.contains(S.target) && n.current && !n.current.contains(S.target) && o();
}, C = (S) => {
S.key === "Escape" && o();
};
return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", E)), () => {
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", E);
return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", C)), () => {
document.removeEventListener("mousedown", s), document.removeEventListener("keydown", C);
};
}, [e, o, n]), e ? /* @__PURE__ */ f(
}, [e, o, n]), e ? /* @__PURE__ */ h(
"div",
{
ref: m,
ref: f,
className: `rte-inline-menu ${r}`,

@@ -58,3 +58,3 @@ style: {

},
children: t.map((s) => /* @__PURE__ */ f(
children: t.map((s) => /* @__PURE__ */ h(
"div",

@@ -72,3 +72,3 @@ {

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

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

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

@@ -107,9 +107,9 @@ return e;

e.forEach((c) => {
o.set(G(c.command || ""), c), n.set(G(c.label || ""), c);
o.set(X(c.command || ""), c), n.set(X(c.label || ""), c);
});
const r = t.flatMap((c) => c.split(/\s+/)).map((c) => c.trim()).filter(Boolean), m = [];
const r = t.flatMap((c) => c.split(/\s+/)).map((c) => c.trim()).filter(Boolean), f = [];
let d = 0;
return r.forEach((c) => {
if (c === "|") {
d += 1, m.push({
d += 1, f.push({
type: "separator",

@@ -121,8 +121,8 @@ command: `__separator__${d}`,

}
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)
const m = X(c), s = Pe[m], C = o.get(m) || (s ? o.get(X(s)) : void 0) || n.get(m) || e.find(
(S) => X(S.command || "").includes(m)
);
E && m.push(E);
}), m.length > 0 ? m : e;
}, be = ({
C && f.push(C);
}), f.length > 0 ? f : e;
}, we = ({
editor: e,

@@ -134,33 +134,33 @@ position: t = "top",

showMoreOptions: r = !0,
itemsOverride: m
itemsOverride: f
}) => {
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 = () => {
const [d, c] = j(null), [m, s] = j(null), [C, S] = j(null), [M, i] = j(!1), F = A(null), D = A(null), w = A({}), b = A([]), g = A(null), T = A(null), B = A(null), v = oe(
() => _e(e.pluginManager.getToolbarItems(), f),
[e, f]
), u = (l) => {
F.current = l, l && !l.collapsed && (D.current = l);
}, E = () => g.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, z = () => {
if (typeof window > "u") return;
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;
const l = g.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = l || null;
}, y = () => {
const l = E();
if (!l) return null;
const L = window.getSelection();
if (!L || L.rangeCount === 0) return null;
const p = L.getRangeAt(0);
return l.contains(p.commonAncestorContainer) ? p.cloneRange() : null;
}, x = () => {
const i = C();
i && u(i);
const l = y();
l && u(l);
};
O(() => {
const i = () => {
W(() => {
const l = () => {
x();
};
return document.addEventListener("selectionchange", i), () => {
document.removeEventListener("selectionchange", i);
return document.addEventListener("selectionchange", l), () => {
document.removeEventListener("selectionchange", l);
};
}, []);
const S = (i) => [
const k = (l) => [
"toggleBold",

@@ -175,72 +175,72 @@ "toggleItalic",

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

@@ -257,7 +257,7 @@ position: "sticky",

}
}, 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(
}, ue = r && C !== null && C < v.length, Te = (l) => {
n || !l.target.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") || (z(), x(), l.preventDefault());
}, Z = (l, L = !0) => l.map((p, q) => {
const H = p.command || "";
return /* @__PURE__ */ h(
"div",

@@ -267,18 +267,18 @@ {

style: {
display: r && E !== null && T >= E ? "none" : "flex"
display: L && r && C !== null && q >= C ? "none" : "flex"
},
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(
children: p.type === "separator" ? /* @__PURE__ */ h("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : p.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ V(
"button",
{
className: "rte-toolbar-button",
"data-command": y,
"data-command": H,
"data-active": "false",
onMouseDown: (M) => {
M.preventDefault(), x();
onMouseDown: (O) => {
O.preventDefault(), x();
},
onClick: () => $(y),
onClick: () => $(H),
disabled: n,
children: [
b.label,
p.label,
" ▼"

@@ -288,102 +288,102 @@ ]

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

@@ -396,104 +396,19 @@ title: "Show more options",

] }),
ce && /* @__PURE__ */ f(
"div",
{
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": T,
"data-active": "false",
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => $(T),
disabled: n,
children: [
i.label,
" ▼"
]
}
),
d === T && /* @__PURE__ */ f("div", { className: "rte-toolbar-dropdown-menu", children: i.options?.map((y) => /* @__PURE__ */ f(
"div",
{
className: "rte-toolbar-dropdown-item",
onMouseDown: (M) => M.preventDefault(),
onClick: () => L(T, y.value),
children: y.label
},
y.value
)) })
] }) : i.type === "inline-menu" ? /* @__PURE__ */ f(
"button",
{
ref: H(T),
className: "rte-toolbar-button",
"data-command": T,
"data-active": "false",
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => P(T),
disabled: n,
title: i.label,
children: U(i.icon)
}
) : i.type === "input" ? /* @__PURE__ */ f(
"input",
{
type: "text",
className: "rte-toolbar-input",
placeholder: i.placeholder,
onChange: (y) => L(T, y.target.value),
disabled: n,
onKeyDown: (y) => {
y.key === "Enter" && L(
T,
y.target.value
);
},
title: i.label
}
) : /* @__PURE__ */ f(
"button",
{
className: "rte-toolbar-button",
"data-command": T,
"data-active": "false",
onMouseDown: (y) => {
y.preventDefault(), x();
},
onClick: () => L(T),
disabled: n,
title: i.label,
children: U(i.icon)
}
) }, b);
}
)
}
)
ue && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${M ? "show" : ""}`, children: Z(Re, !1) })
]
}
),
p.map((i) => {
if (i.type === "inline-menu") {
const b = i.command || "";
return /* @__PURE__ */ f(
We,
v.map((l) => {
if (l.type === "inline-menu") {
const L = l.command || "";
return /* @__PURE__ */ h(
Oe,
{
isOpen: g === b,
options: i.options || [],
onSelect: (T) => _(b, T),
isOpen: m === L,
options: l.options || [],
onSelect: (p) => P(L, p),
onClose: () => s(null),
anchorRef: H(b)
anchorRef: N(L)
},
`menu-${b || "unknown"}`
`menu-${L || "unknown"}`
);

@@ -505,12 +420,12 @@ }

};
function _e(e, t) {
const a = R(), o = R("");
return O(() => {
function $e(e, t) {
const a = A(), o = A("");
return W(() => {
if (!t?.enabled) return;
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")
const r = t.intervalMs || 3e4, f = t.storageKey || "rte-autosave", d = t.provider || "localStorage", c = async () => {
const m = e();
if (m !== o.current) {
if (o.current = m, d === "localStorage")
try {
localStorage.setItem(m, g), localStorage.setItem(`${m}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage");
localStorage.setItem(f, m), localStorage.setItem(`${f}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage");
} catch (s) {

@@ -526,3 +441,3 @@ console.error("[Autosave] Failed to save to localStorage:", s);

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

@@ -551,3 +466,3 @@ } catch (s) {

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

@@ -590,3 +505,3 @@ "br",

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

@@ -601,14 +516,14 @@ a: ["href", "target", "rel", "title"],

};
function Ee(e, t, a) {
function ke(e, t, a) {
if (t?.sanitize === !1)
return e;
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;
const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ue, r = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : qe, f = document.createElement("div");
return f.innerHTML = e, Se(f, o, r), f.innerHTML;
}
function ke(e, t, a) {
function Se(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)) {
const r = n, f = r.tagName.toLowerCase();
if (!t.includes(f)) {
for (; r.firstChild; )

@@ -619,3 +534,3 @@ e.insertBefore(r.firstChild, r);

}
qe(r, a), ke(r, t, a);
Ke(r, a), Se(r, t, a);
} else {

@@ -627,13 +542,13 @@ if (n.nodeType === Node.TEXT_NODE)

}
function qe(e, t) {
const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), n = t[a] || [], r = t["*"] || [], m = [...n, ...r];
function Ke(e, t) {
const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), n = t[a] || [], r = t["*"] || [], f = [...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)
let m = !1;
f.includes(c) && (m = !0);
for (const s of f)
if (s.endsWith("*")) {
const E = s.slice(0, -1);
if (c.startsWith(E)) {
g = !0;
const C = s.slice(0, -1);
if (c.startsWith(C)) {
m = !0;
break;

@@ -643,16 +558,16 @@ }

(c.startsWith("on") || // Event handlers
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);
c === "javascript:" || c === "href" && d.value.trim().toLowerCase().startsWith("javascript:") || c === "src" && d.value.trim().toLowerCase().startsWith("javascript:")) && (m = !1), m || 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 Ke(e, t, a) {
return a?.sanitizeOnPaste === !1 ? e : Ee(e, t);
function Ve(e, t, a) {
return a?.sanitizeOnPaste === !1 ? e : ke(e, t);
}
function ve(e, t, a) {
return a?.sanitizeOnInput === !1 ? e : Ee(e, t);
return a?.sanitizeOnInput === !1 ? e : ke(e, t);
}
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);
const Q = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), G = (e, t) => {
const o = !!t && Q(e);
e.classList.toggle("rte-content-empty", o);
}, ae = "data-rte-caret-marker", ie = "data-rte-range-start-marker", le = "data-rte-range-end-marker", te = () => Math.random().toString(36).slice(2), Ve = (e) => {
}, le = "data-rte-caret-marker", ce = "data-rte-range-start-marker", se = "data-rte-range-end-marker", re = () => Math.random().toString(36).slice(2), je = (e) => {
const t = window.getSelection();

@@ -673,3 +588,3 @@ if (!t || t.rangeCount === 0) return null;

}
}, we = (e, t) => {
}, pe = (e, t) => {
const a = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);

@@ -679,6 +594,6 @@ let o = a.nextNode(), n = Math.max(0, t), r = null;

r = o;
const m = o.textContent?.length ?? 0;
if (n <= m)
const f = o.textContent?.length ?? 0;
if (n <= f)
return { node: o, offset: n };
n -= m, o = a.nextNode();
n -= f, o = a.nextNode();
}

@@ -689,3 +604,3 @@ return r ? {

} : { node: e, offset: e.childNodes.length };
}, je = (e) => {
}, Ge = (e) => {
const t = window.getSelection();

@@ -695,24 +610,24 @@ if (!t || t.rangeCount === 0) return null;

if (!e.contains(a.commonAncestorContainer)) return null;
const o = Ve(e);
const o = je(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 s = re(), C = document.createElement("span");
return C.setAttribute(le, s), C.appendChild(document.createTextNode("​")), a.cloneRange().insertNode(C), { collapsed: !0, caretId: s, fallbackOffsets: o };
}
const n = te(), r = te(), m = document.createElement("span");
m.setAttribute(le, r), m.appendChild(document.createTextNode("​"));
const n = re(), r = re(), f = document.createElement("span");
f.setAttribute(se, r), f.appendChild(document.createTextNode("​"));
const d = document.createElement("span");
d.setAttribute(ie, n), d.appendChild(document.createTextNode("​"));
d.setAttribute(ce, 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 };
c.collapse(!1), c.insertNode(f);
const m = a.cloneRange();
return m.collapse(!0), m.insertNode(d), { collapsed: !1, startId: n, endId: r, fallbackOffsets: o };
} catch {
return { collapsed: a.collapsed, fallbackOffsets: o };
}
}, Ge = (e) => {
}, Xe = (e) => {
e.querySelectorAll(
`[${ae}], [${ie}], [${le}]`
`[${le}], [${ce}], [${se}]`
).forEach((t) => t.remove());
}, Xe = (e, t) => {
}, Je = (e, t) => {
if (!t) return !1;

@@ -724,7 +639,7 @@ const a = window.getSelection();

if (t.collapsed && t.caretId) {
const n = e.querySelector(`[${ae}="${t.caretId}"]`);
const n = e.querySelector(`[${le}="${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}"]`);
const n = e.querySelector(`[${ce}="${t.startId}"]`), r = e.querySelector(`[${se}="${t.endId}"]`);
return !n || !r || !n.parentNode || !r.parentNode ? !1 : (o.setStartAfter(n), o.setEndBefore(r), a.removeAllRanges(), a.addRange(o), !0);

@@ -736,3 +651,3 @@ }

return !1;
}, Je = (e, t) => {
}, Qe = (e, t) => {
if (!t) return;

@@ -742,7 +657,7 @@ const a = window.getSelection();

try {
const o = we(e, t.start), n = we(e, t.end), r = document.createRange();
const o = pe(e, t.start), n = pe(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 = ({
}, Ye = ({
editor: e,

@@ -754,133 +669,133 @@ defaultValue: t,

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

@@ -890,4 +805,4 @@ "data-readonly": o ? "true" : "false",

style: {
minHeight: `${v}px`,
maxHeight: w ? h > 0 ? `${h}px` : "none" : "100%",
minHeight: `${b}px`,
maxHeight: w ? g > 0 ? `${g}px` : "none" : "100%",
padding: "16px",

@@ -899,3 +814,3 @@ outline: "none",

lineHeight: "1.5",
overflow: w ? h > 0 ? "auto" : "hidden" : "auto",
overflow: w ? g > 0 ? "auto" : "hidden" : "auto",
flex: w ? void 0 : 1,

@@ -908,3 +823,3 @@ boxSizing: "border-box",

);
}, Ye = ({
}, Ze = ({
editor: e,

@@ -915,4 +830,4 @@ isEnabled: t,

}) => {
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(() => {
const [n, r] = j(!1), [f, d] = j({ top: 0, left: 0 }), c = A(null), m = A(null), s = A(null), C = A(null), S = A(null);
W(() => {
if (!t || o) {

@@ -922,29 +837,29 @@ r(!1);

}
A.current = c.current?.closest("[data-editora-editor]");
const l = (p) => {
if (A.current) return A.current;
S.current = c.current?.closest("[data-editora-editor]");
const i = (v) => {
if (S.current) return S.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;
return S.current = u, u;
const E = v?.commonAncestorContainer, y = (E ? E.nodeType === Node.ELEMENT_NODE ? E : E.parentElement : null)?.closest("[data-editora-editor]");
return y ? (S.current = y, y) : null;
}, F = (v) => v && v.querySelector(".rte-content, .editora-content") || null, D = (v) => {
if (!v.anchorNode || !v.focusNode) return !1;
try {
const u = document.createRange();
return u.setStart(p.anchorNode, p.anchorOffset), u.setEnd(p.focusNode, p.focusOffset), u.collapsed;
return u.setStart(v.anchorNode, v.anchorOffset), u.setEnd(v.focusNode, v.focusOffset), u.collapsed;
} catch {
return !1;
}
}, 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) {
}, w = (v, u) => {
const E = Array.from(u.getClientRects()).filter((y) => y.width > 0 || y.height > 0);
return E.length === 0 ? u.getBoundingClientRect() : D(v) ? E[0] : E[E.length - 1];
}, b = () => {
C.current && clearTimeout(C.current);
const v = window.getSelection();
if (!v || v.rangeCount === 0) {
r(!1), s.current = null;
return;
}
const u = p.getRangeAt(0);
const u = v.getRangeAt(0);
if (u.collapsed) {

@@ -954,4 +869,4 @@ r(!1), s.current = null;

}
const k = p.toString().trim(), W = l(u), C = B(W);
if (!C || !C.contains(u.commonAncestorContainer)) {
const E = v.toString().trim(), z = i(u), y = F(z);
if (!y || !y.contains(u.commonAncestorContainer)) {
r(!1), s.current = null;

@@ -961,4 +876,4 @@ return;

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) {
const x = y.getBoundingClientRect(), k = x.bottom >= 0 && x.top <= window.innerHeight, R = document.activeElement === y || y.contains(document.activeElement);
if (!k && !R) {
r(!1), s.current = null;

@@ -968,29 +883,29 @@ return;

}
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();
if (E.length > 0) {
const x = w(v, u), k = y.getBoundingClientRect(), R = 300;
if (x && k) {
const N = Math.max(8, x.top - 50);
let I = x.left + x.width / 2;
const $ = R / 2, _ = k.left, P = k.right;
I - $ < _ && (I = _ + $ + 10), I + $ > P && (I = P - $ - 10), d({ top: N, left: I }), r(!0), s.current = u.cloneRange();
}
} else
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);
}, g = (v) => {
if (m.current && !m.current.contains(v.target)) {
const u = i();
window.getSelection(), F(u)?.contains(v.target) || (r(!1), s.current = null);
}
}, 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 = (v) => {
v.key === "Escape" && (r(!1), s.current = null);
}, B = F(i());
return document.addEventListener("selectionchange", b), document.addEventListener("mousedown", g), document.addEventListener("keydown", T), B?.addEventListener("mouseup", b), B?.addEventListener("keyup", b), () => {
document.removeEventListener("selectionchange", b), document.removeEventListener("mousedown", g), document.removeEventListener("keydown", T), B?.removeEventListener("mouseup", b), B?.removeEventListener("keyup", b), C.current && clearTimeout(C.current);
};
}, [t, a, o]);
const D = (l, B) => {
const M = (i, F) => {
if (o || !s.current) return;
typeof window < "u" && (window.__editoraCommandEditorRoot = A.current || null);
const F = A.current?.querySelector(".rte-content");
F && F.focus();
typeof window < "u" && (window.__editoraCommandEditorRoot = S.current || null);
const D = S.current?.querySelector(".rte-content");
D && D.focus();
const w = window.getSelection();

@@ -1014,31 +929,31 @@ if (w && s.current)

toggleCode: () => {
const h = window.getSelection();
if (h && h.rangeCount > 0) {
const N = h.getRangeAt(0), z = document.createElement("code");
N.surroundContents(z);
const g = window.getSelection();
if (g && g.rangeCount > 0) {
const T = g.getRangeAt(0), B = document.createElement("code");
T.surroundContents(B);
}
},
setBlockType: () => {
if (B === "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");
if (F === "blockquote") {
const g = window.getSelection();
if (g && g.rangeCount > 0) {
const T = g.getRangeAt(0);
(T.commonAncestorContainer.nodeType === Node.TEXT_NODE ? T.commonAncestorContainer.parentElement : T.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote");
}
} else B && document.execCommand("formatBlock", !1, B);
} else F && document.execCommand("formatBlock", !1, F);
}
})[l]?.(), r(!1), s.current = null;
})[i]?.(), r(!1), s.current = null;
};
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(
return !t || o ? /* @__PURE__ */ h("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(Y, { children: [
/* @__PURE__ */ h("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }),
n && /* @__PURE__ */ V(
"div",
{
ref: g,
ref: m,
className: "floating-toolbar",
onMouseDown: (l) => l.preventDefault(),
onMouseDown: (i) => i.preventDefault(),
style: {
position: "fixed",
top: `${m.top}px`,
left: `${m.left}px`,
top: `${f.top}px`,
left: `${f.left}px`,
transform: "translateX(-50%)",

@@ -1049,44 +964,44 @@ zIndex: 1e4,

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

@@ -1096,7 +1011,7 @@ children: "⌫"

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

@@ -1106,7 +1021,7 @@ children: "🔗"

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

@@ -1116,8 +1031,8 @@ children: "Code"

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

@@ -1131,3 +1046,3 @@ children: "❝"

] });
}, Ze = ({
}, et = ({
plugins: e,

@@ -1137,10 +1052,10 @@ children: t

const a = e.filter((n) => n.context?.provider);
return a.length === 0 ? /* @__PURE__ */ f(Q, { children: t }) : a.reduce(
return a.length === 0 ? /* @__PURE__ */ h(Y, { children: t }) : a.reduce(
(n, r) => {
const m = r.context.provider;
return /* @__PURE__ */ f(m, { children: n }, r.name);
const f = r.context.provider;
return /* @__PURE__ */ h(f, { children: n }, r.name);
},
/* @__PURE__ */ f(Q, { children: t })
/* @__PURE__ */ h(Y, { children: t })
);
}, pe = /* @__PURE__ */ new Set(), Ce = /* @__PURE__ */ new Set(), re = (e) => !!e && typeof e == "object" && typeof e.name == "string", Se = (e) => {
}, Ce = /* @__PURE__ */ new Set(), ye = /* @__PURE__ */ new Set(), ae = (e) => !!e && typeof e == "object" && typeof e.name == "string", Ae = (e) => {
const t = e?.pluginFactories;

@@ -1151,7 +1066,7 @@ return {

};
}, et = (e, t) => {
}, tt = (e, t) => {
if (!Array.isArray(e)) return [];
const a = Se(t), o = [], n = [];
const a = Ae(t), o = [], n = [];
if (e.forEach((r) => {
if (re(r)) {
if (ae(r)) {
o.push(r);

@@ -1161,7 +1076,7 @@ return;

if (typeof r != "string") return;
const m = a[r];
if (typeof m == "function")
const f = a[r];
if (typeof f == "function")
try {
const d = m();
if (re(d)) {
const d = f();
if (ae(d)) {
o.push(d);

@@ -1175,3 +1090,3 @@ return;

const r = n.slice().sort().join("|");
pe.has(r) || (pe.add(r), console.warn(
Ce.has(r) || (Ce.add(r), console.warn(
`[Editora React] Unresolved string plugin names: ${n.join(

@@ -1183,9 +1098,9 @@ ", "

return o;
}, tt = (e, t, a) => {
}, nt = (e, t, a) => {
if (!t?.checker || e.some((r) => r?.name === "a11yChecker")) return e;
const o = Se(a).a11yChecker;
const o = Ae(a).a11yChecker;
if (typeof o == "function")
try {
const r = o();
if (re(r))
if (ae(r))
return [...e, r];

@@ -1195,6 +1110,6 @@ } catch {

const n = "accessibility.checker";
return Ce.has(n) || (Ce.add(n), console.warn(
return ye.has(n) || (ye.add(n), console.warn(
'[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.'
)), e;
}, nt = {
}, rt = {
readonly: !1,

@@ -1277,12 +1192,12 @@ placeholder: "",

};
function Ae(e, t) {
function xe(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);
n !== void 0 && (typeof n == "object" && n !== null && !Array.isArray(n) && typeof r == "object" && r !== null && !Array.isArray(r) ? a[o] = xe(r, n) : a[o] = n);
}
return a;
}
function rt(e) {
const t = Ae(nt, {
function ot(e) {
const t = xe(rt, {
readonly: e.readonly,

@@ -1327,4 +1242,4 @@ placeholder: e.placeholder,

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

@@ -1336,11 +1251,11 @@ e.pluginConfig

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

@@ -1368,36 +1283,36 @@ e.className,

e.mediaConfig
]), 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;
]), a = A(null), o = A(null), n = A(e.onInit), r = A(e.onDestroy), f = A(e.onChange), d = A(/* @__PURE__ */ new Set()), c = A(null), m = A(null), s = A(null);
W(() => {
n.current = e.onInit, r.current = e.onDestroy, f.current = e.onChange;
});
const E = (w) => {
m.current?.(w), d.current.forEach((v) => {
const C = (w) => {
f.current?.(w), d.current.forEach((b) => {
try {
v(w);
} catch (h) {
console.error("Editora onChange subscriber failed:", h);
b(w);
} catch (g) {
console.error("Editora onChange subscriber failed:", g);
}
});
}, A = ne(() => {
}, S = oe(() => {
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);
t.plugins.forEach((g) => {
w.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([T, B]) => {
ie.set(T, B);
});
});
const v = new Ie(w);
return a.current = v, v;
const b = new He(w);
return a.current = b, b;
}, [t.plugins]);
O(() => {
W(() => {
const w = {
getHTML: () => c.current?.querySelector(".rte-content")?.innerHTML || "",
setHTML: (v) => {
const h = c.current?.querySelector(".rte-content");
h && (h.innerHTML = v);
setHTML: (b) => {
const g = c.current?.querySelector(".rte-content");
g && (g.innerHTML = b);
},
execCommand: (v, h) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(v, h));
execCommand: (b, g) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(b, g));
},
registerCommand: (v, h) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(v, h);
registerCommand: (b, g) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(b, g);
},

@@ -1413,4 +1328,4 @@ focus: () => {

},
onChange: (v) => (d.current.add(v), () => {
d.current.delete(v);
onChange: (b) => (d.current.add(b), () => {
d.current.delete(b);
}),

@@ -1422,3 +1337,3 @@ getState: () => ({

toolbar: {
items: A.toolbar?.items || []
items: S.toolbar?.items || []
}

@@ -1429,49 +1344,49 @@ };

};
}, []), O(() => {
}, []), W(() => {
if (t.statusbar.enabled && s.current && c.current) {
g.current || (g.current = new De({
m.current || (m.current = new De({
enabled: !0,
position: t.statusbar.position
}), g.current.create(s.current));
}), m.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())
const b = () => {
const y = document.activeElement;
return !!y && (y === w || w.contains(y));
}, g = () => {
const y = w.getBoundingClientRect();
return y.bottom >= 0 && y.top <= window.innerHeight;
}, T = () => {
const y = window.getSelection();
if (!y || y.rangeCount === 0) return null;
const x = y.getRangeAt(0), k = x.commonAncestorContainer;
return w.contains(k) ? x : null;
}, B = (y = !1) => {
if (t.performance.viewportOnlyScan !== !1 && !g() && !b())
return;
const S = N(), I = !!S || v();
if (C && !I)
const k = T(), R = !!k || b();
if (y && !R)
return;
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,
const N = w.textContent || "", { words: I, chars: $ } = Fe(N), _ = Be(w);
let P, U;
k && (P = ze(w, k), k.collapsed || (U = We(k, P), P = void 0)), m.current?.update({
wordCount: I,
charCount: $,
lineCount: P,
cursorPosition: _,
lineCount: _,
cursorPosition: P,
selectionInfo: U
});
}, 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);
}, v = () => B(), u = () => B(!0), E = () => B(), z = () => B();
return w.addEventListener("input", v), w.addEventListener("focus", E), w.addEventListener("blur", z), document.addEventListener("selectionchange", u), B(), () => {
w.removeEventListener("input", v), w.removeEventListener("focus", E), w.removeEventListener("blur", z), document.removeEventListener("selectionchange", u);
};
}
} else
g.current && (g.current.destroy(), g.current = null);
m.current && (m.current.destroy(), m.current = null);
return () => {
g.current && (g.current.destroy(), g.current = null);
m.current && (m.current.destroy(), m.current = null);
};
}, [t.statusbar.enabled, t.statusbar.position, t.performance.viewportOnlyScan]);
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(
const M = t.toolbar.floating ?? !1, i = t.toolbar.position || "top", F = t.toolbar.sticky ?? !1, D = t.toolbar.showMoreOptions ?? !0;
return /* @__PURE__ */ h(et, { plugins: t.plugins, children: /* @__PURE__ */ V(
"div",

@@ -1492,18 +1407,18 @@ {

children: [
l !== "bottom" && /* @__PURE__ */ f(
be,
i !== "bottom" && /* @__PURE__ */ h(
we,
{
editor: A,
position: l,
sticky: B,
floating: D,
editor: S,
position: i,
sticky: F,
floating: M,
readonly: t.readonly,
showMoreOptions: F,
showMoreOptions: D,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ f(
Qe,
/* @__PURE__ */ h(
Ye,
{
editor: A,
editor: S,
defaultValue: t.defaultValue,

@@ -1513,3 +1428,3 @@ value: t.value,

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

@@ -1525,19 +1440,19 @@ contentConfig: t.content,

),
l === "bottom" && /* @__PURE__ */ f(
be,
i === "bottom" && /* @__PURE__ */ h(
we,
{
editor: A,
position: l,
sticky: B,
floating: D,
editor: S,
position: i,
sticky: F,
floating: M,
readonly: t.readonly,
showMoreOptions: F,
showMoreOptions: D,
itemsOverride: t.toolbar.items
}
),
/* @__PURE__ */ f(
Ye,
/* @__PURE__ */ h(
Ze,
{
editor: A,
isEnabled: D,
editor: S,
isEnabled: M,
viewportOnlyScan: t.performance.viewportOnlyScan,

@@ -1547,3 +1462,3 @@ readonly: t.readonly

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

@@ -1559,13 +1474,13 @@ {

) });
}, st = (e) => /* @__PURE__ */ f(ot, { ...e });
function ut(e = {}) {
const t = R(null), a = R(e.onCommand);
return O(() => {
}, ut = (e) => /* @__PURE__ */ h(at, { ...e });
function dt(e = {}) {
const t = A(null), a = A(e.onCommand);
return W(() => {
a.current = e.onCommand;
}), O(() => {
}), W(() => {
if (typeof window > "u" || e.enabled === !1) return;
const o = new ye(e);
const o = new Ee(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);
const n = (f) => o.handleKeyDown(f, (c, m) => {
a.current && a.current(c, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(c, m);
}), r = e.editorElement || document;

@@ -1585,9 +1500,9 @@ return r && r.addEventListener("keydown", n), () => {

export {
Qe as EditorContent,
st as EditoraEditor,
We as InlineMenu,
st as RichTextEditor,
be as Toolbar,
rt as mergeConfig,
ut as useKeyboardShortcuts
Ye as EditorContent,
ut as EditoraEditor,
Oe as InlineMenu,
ut as RichTextEditor,
we as Toolbar,
ot as mergeConfig,
dt as useKeyboardShortcuts
};
{
"name": "@editora/react",
"version": "1.0.7",
"version": "1.0.8",
"description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.",

@@ -62,4 +62,4 @@ "author": "Ajay Kumar <ajaykr089@gmail.com>",

"@editora/core": "^1.0.6",
"@editora/plugins": "^1.0.6",
"@editora/themes": "^1.0.6",
"@editora/plugins": "^1.0.7",
"@editora/themes": "^1.0.7",
"react": ">=16.8 <21",

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

@@ -24,2 +24,3 @@ # @editora/react

- Optional but recommended: `@editora/plugins` (toolbar/plugin features), `@editora/themes` (default/dark/acme CSS)
- When using `@editora/plugins`, also import `@editora/plugins/styles.css` for plugin UI surfaces (table toolbar, dialogs, pickers).
- For smaller bundles: prefer `@editora/plugins/lite` or per-plugin subpaths like `@editora/plugins/bold`, and lazy-load heavy plugins (`document-manager`, `media-manager`, `spell-check`) via dynamic imports.

@@ -60,2 +61,3 @@

import "@editora/plugins/styles.css";
import "@editora/themes/themes/default.css";

@@ -98,2 +100,3 @@

import "@editora/plugins/styles.css";
import "@editora/themes/themes/default.css";

@@ -100,0 +103,0 @@