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

@editora/react

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@editora/react - npm Package Compare versions

Comparing version
1.0.6
to
1.0.7
+1
-1
dist/index.cjs.js

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

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

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

"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
"require": "./dist/index.cjs.js",
"default": "./dist/index.esm.js"
}

@@ -61,5 +62,5 @@ },

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

@@ -77,6 +78,6 @@ "react-dom": ">=16.8 <21"

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

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