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

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

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

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

import { jsx as p, jsxs as Y, Fragment as ge } from "react/jsx-runtime";
import it, { useRef as T, useState as Q, useLayoutEffect as Pe, useEffect as O, useMemo as me } from "react";
import { KeyboardShortcutManager as Ue, PluginManager as lt, Editor as st, StatusBar as ct, calculateTextStats as ut, countLines as dt, getCursorPosition as ft, getSelectionInfo as gt } from "@editora/core";
const mt = ({
import { jsx as w, jsxs as Z, Fragment as me } from "react/jsx-runtime";
import st, { useRef as S, useState as X, useLayoutEffect as Ue, useEffect as F, useMemo as he } from "react";
import { KeyboardShortcutManager as qe, PluginManager as ct, Editor as ut, StatusBar as dt, calculateTextStats as ft, countLines as gt, getCursorPosition as mt, getSelectionInfo as ht } from "@editora/core";
const bt = ({
isOpen: e,

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

}) => {
const u = T(null), [d, c] = Q(null), s = () => {
const u = S(null), [d, c] = X(null), s = () => {
if (!e || !o.current) return;
const g = o.current.getBoundingClientRect(), N = u.current?.getBoundingClientRect(), y = N?.width || 120, x = N?.height || t.length * 36, l = 8, D = 4, _ = window.innerWidth, v = window.innerHeight;
let w = g.bottom + D, C = g.left;
C + y > _ - l && (C = _ - y - l), C < l && (C = l), w + x > v - l && (w = g.top - x - D), w < l && (w = l), c({ top: w, left: C });
const g = o.current.getBoundingClientRect(), R = u.current?.getBoundingClientRect(), y = R?.width || 120, z = R?.height || t.length * 36, l = 8, A = 4, _ = window.innerWidth, p = window.innerHeight;
let v = g.bottom + A, k = g.left;
k + y > _ - l && (k = _ - y - l), k < l && (k = l), v + z > p - l && (v = g.top - z - A), v < l && (v = l), c({ top: v, left: k });
};
return Pe(() => {
return Ue(() => {
if (!e) {

@@ -29,3 +29,3 @@ c(null);

};
}, [e, t.length, o]), O(() => {
}, [e, t.length, o]), F(() => {
if (!e) return;

@@ -38,12 +38,12 @@ const g = () => {

};
}, [e, t.length, o]), O(() => {
}, [e, t.length, o]), F(() => {
const g = (y) => {
u.current && !u.current.contains(y.target) && o.current && !o.current.contains(y.target) && r();
}, N = (y) => {
}, R = (y) => {
y.key === "Escape" && r();
};
return e && (document.addEventListener("mousedown", g), document.addEventListener("keydown", N)), () => {
document.removeEventListener("mousedown", g), document.removeEventListener("keydown", N);
return e && (document.addEventListener("mousedown", g), document.addEventListener("keydown", R)), () => {
document.removeEventListener("mousedown", g), document.removeEventListener("keydown", R);
};
}, [e, r, o]), e ? /* @__PURE__ */ p(
}, [e, r, o]), e ? /* @__PURE__ */ w(
"div",

@@ -58,8 +58,8 @@ {

},
children: t.map((g) => /* @__PURE__ */ p(
children: t.map((g) => /* @__PURE__ */ w(
"div",
{
className: "rte-inline-menu-item",
onMouseDown: (N) => {
N.preventDefault();
onMouseDown: (R) => {
R.preventDefault();
},

@@ -75,3 +75,3 @@ onClick: () => {

) : null;
}, Fe = {
}, _e = {
bold: !1,

@@ -87,7 +87,7 @@ italic: !1,

alignment: null
}, ht = "p,h1,h2,h3,h4,h5,h6,blockquote,li,pre,div", bt = /* @__PURE__ */ new Set(["P", "H1", "H2", "H3", "H4", "H5", "H6", "BLOCKQUOTE", "LI", "PRE", "DIV"]);
function qe(e) {
}, pt = "p,h1,h2,h3,h4,h5,h6,blockquote,li,pre,div", vt = /* @__PURE__ */ new Set(["P", "H1", "H2", "H3", "H4", "H5", "H6", "BLOCKQUOTE", "LI", "PRE", "DIV"]);
function Ke(e) {
return e ? e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement : null;
}
function pt(e) {
function wt(e) {
const t = window.getSelection();

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

}
function wt(e, t) {
function yt(e, t) {
try {

@@ -106,6 +106,6 @@ return e.intersectsNode(t);

}
function Ke(e, t) {
function je(e, t) {
if (t.collapsed) return [];
const n = [], r = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, {
acceptNode: (a) => a.textContent?.trim() && wt(t, a) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
acceptNode: (a) => a.textContent?.trim() && yt(t, a) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
});

@@ -117,4 +117,4 @@ let o = r.nextNode();

}
function ie(e, t, n) {
let r = qe(e);
function le(e, t, n) {
let r = Ke(e);
for (; r && t.contains(r); ) {

@@ -127,3 +127,3 @@ if (n(r)) return !0;

}
function vt(e) {
function Et(e) {
if (e === "bold" || e === "bolder") return 700;

@@ -133,21 +133,21 @@ const t = Number.parseInt(e, 10);

}
function je(e) {
return e.matches("b,strong") ? !0 : !!e.style.fontWeight && vt(e.style.fontWeight) >= 600;
function Ve(e) {
return e.matches("b,strong") ? !0 : !!e.style.fontWeight && Et(e.style.fontWeight) >= 600;
}
function yt(e) {
function Ct(e) {
return e.matches("i,em") ? !0 : e.style.fontStyle === "italic";
}
function Ve(e) {
function Ge(e) {
return e.matches("u") ? !0 : `${e.style.textDecoration} ${e.style.textDecorationLine}`.includes("underline");
}
function Et(e) {
function kt(e) {
return e.matches("s,strike,del") ? !0 : `${e.style.textDecoration} ${e.style.textDecorationLine} ${window.getComputedStyle(e).textDecorationLine}`.includes("line-through");
}
function oe(e, t, n) {
function ae(e, t, n) {
if (t.collapsed)
return ie(t.startContainer, e, n);
const r = Ke(e, t);
return r.length === 0 ? ie(t.startContainer, e, n) : r.every((o) => ie(o, e, n));
return le(t.startContainer, e, n);
const r = je(e, t);
return r.length === 0 ? le(t.startContainer, e, n) : r.every((o) => le(o, e, n));
}
function ue(e, t, n) {
function de(e, t, n) {
try {

@@ -157,8 +157,8 @@ const r = document.queryCommandState(e);

if (e === "bold") {
if (ie(n.startContainer, t, je)) return !0;
if (de(n.startContainer, t)?.matches("h1,h2,h3,h4,h5,h6")) return !1;
if (le(n.startContainer, t, Ve)) return !0;
if (fe(n.startContainer, t)?.matches("h1,h2,h3,h4,h5,h6")) return !1;
}
if (e === "underline") {
if (ie(n.startContainer, t, Ve)) return !0;
if (ie(
if (le(n.startContainer, t, Ge)) return !0;
if (le(
n.startContainer,

@@ -174,16 +174,16 @@ t,

}
function de(e, t) {
const n = qe(e);
function fe(e, t) {
const n = Ke(e);
if (!n || !t.contains(n) || n === t) return null;
const r = n.closest(ht);
const r = n.closest(pt);
return r instanceof HTMLElement && t.contains(r) ? r : null;
}
function Ct(e, t) {
const n = /* @__PURE__ */ new Set(), r = de(t.startContainer, e), o = de(t.endContainer, e);
return r && n.add(r), o && n.add(o), t.collapsed || Ke(e, t).forEach((a) => {
const u = de(a, e);
function St(e, t) {
const n = /* @__PURE__ */ new Set(), r = fe(t.startContainer, e), o = fe(t.endContainer, e);
return r && n.add(r), o && n.add(o), t.collapsed || je(e, t).forEach((a) => {
const u = fe(a, e);
u && n.add(u);
}), Array.from(n).filter((a) => bt.has(a.tagName));
}), Array.from(n).filter((a) => vt.has(a.tagName));
}
function he(e) {
function be(e) {
const t = e.filter((r) => !!r);

@@ -194,3 +194,3 @@ if (t.length === 0) return null;

}
function kt(e) {
function Lt(e) {
const t = e.map((n) => {

@@ -204,5 +204,5 @@ const r = n.closest("li"), o = r instanceof HTMLElement ? r : n, a = o.tagName.toLowerCase();

});
return he(t);
return be(t);
}
function St(e) {
function Tt(e) {
const t = e.map((n) => {

@@ -215,6 +215,6 @@ const r = n.closest("li");

});
return he(t);
return be(t);
}
function Tt(e, t) {
return he(t.map((n) => {
function At(e, t) {
return be(t.map((n) => {
let r = n;

@@ -230,28 +230,28 @@ for (; r && r !== e && e.contains(r); ) {

}
function Lt(e) {
function Rt(e) {
const t = e.trim().toLowerCase();
return t === "start" ? "left" : t === "end" ? "right" : t === "left" || t === "center" || t === "right" || t === "justify" ? t : null;
}
function At(e) {
return he(e.map((t) => Lt(t.style.textAlign || window.getComputedStyle(t).textAlign)));
function xt(e) {
return be(e.map((t) => Rt(t.style.textAlign || window.getComputedStyle(t).textAlign)));
}
function J(e) {
if (!e || typeof window > "u") return Fe;
const t = pt(e);
if (!t) return Fe;
const n = Ct(e, t), r = t.collapsed ? ue("bold", e, t) : null, o = t.collapsed ? ue("italic", e, t) : null, a = t.collapsed ? ue("underline", e, t) : null, u = t.collapsed ? ue("strikeThrough", e, t) : null;
if (!e || typeof window > "u") return _e;
const t = wt(e);
if (!t) return _e;
const n = St(e, t), r = t.collapsed ? de("bold", e, t) : null, o = t.collapsed ? de("italic", e, t) : null, a = t.collapsed ? de("underline", e, t) : null, u = t.collapsed ? de("strikeThrough", e, t) : null;
return {
bold: r ?? oe(e, t, je),
italic: o ?? oe(e, t, yt),
underline: a ?? oe(e, t, Ve),
strikethrough: u ?? oe(e, t, Et),
link: oe(e, t, (d) => d.matches("a[href]")),
code: oe(e, t, (d) => d.matches("code")),
blockType: n.length > 0 ? kt(n) : null,
listType: n.length > 0 ? St(n) : null,
direction: n.length > 0 ? Tt(e, n) : null,
alignment: n.length > 0 ? At(n) : null
bold: r ?? ae(e, t, Ve),
italic: o ?? ae(e, t, Ct),
underline: a ?? ae(e, t, Ge),
strikethrough: u ?? ae(e, t, kt),
link: ae(e, t, (d) => d.matches("a[href]")),
code: ae(e, t, (d) => d.matches("code")),
blockType: n.length > 0 ? Lt(n) : null,
listType: n.length > 0 ? Tt(n) : null,
direction: n.length > 0 ? At(e, n) : null,
alignment: n.length > 0 ? xt(n) : null
};
}
function U(e, t) {
function j(e, t) {
switch (e) {

@@ -289,3 +289,3 @@ case "toggleBold":

}
const se = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Rt = (e, t) => `${t}:${e.type}:${e.command || ""}:${e.label || ""}`, xt = typeof window < "u" ? Pe : O, Mt = {
const ce = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Mt = (e, t) => `${t}:${e.type}:${e.command || ""}:${e.label || ""}`, It = typeof window < "u" ? Ue : F, Nt = {
undo: "undo",

@@ -300,2 +300,3 @@ redo: "redo",

fontsize: "setFontSize",
formatpainter: "toggleFormatPainter",
increasefontsize: "increaseFontSize",

@@ -322,3 +323,3 @@ decreasefontsize: "decreaseFontSize",

databindingpreview: "openDataBindingDialog"
}, It = (e, t) => {
}, Ht = (e, t) => {
if (t == null || t === "")

@@ -333,3 +334,3 @@ return e;

e.forEach((s) => {
o.set(se(s.command || ""), s), a.set(se(s.label || ""), s);
o.set(ce(s.command || ""), s), a.set(ce(s.label || ""), s);
});

@@ -347,8 +348,8 @@ const u = n.flatMap((s) => s.split(/\s+/)).map((s) => s.trim()).filter(Boolean), d = [];

}
const g = se(s), N = Mt[g], y = o.get(g) || (N ? o.get(se(N)) : void 0) || a.get(g) || e.find(
(x) => se(x.command || "").includes(g)
const g = ce(s), R = Nt[g], y = o.get(g) || (R ? o.get(ce(R)) : void 0) || a.get(g) || e.find(
(z) => ce(z.command || "").includes(g)
);
y && d.push(y);
}), d.length > 0 ? d : e;
}, _e = ({
}, Oe = ({
editor: e,

@@ -362,63 +363,74 @@ position: t = "top",

}) => {
const [d, c] = Q(!1), [s, g] = Q(null), [N, y] = Q(null), [x, l] = Q(null), [D, _] = Q(!1), [v, w] = Q(() => J(null)), C = T(""), B = T(null), I = T(!1), z = T(null), P = T(null), m = T({}), H = T({}), f = T(""), E = T(null), A = T(null), G = T(null), k = me(
() => It(e.pluginManager.getToolbarItems(), u),
const [d, c] = X(!1), [s, g] = X(!1), [R, y] = X(null), [z, l] = X(null), [A, _] = X(null), [p, v] = X(!1), [k, $] = X(() => J(null)), I = S(""), U = S(null), q = S(!1), h = S(null), N = S(null), f = S({}), C = S({}), T = S(""), P = S(null), x = S(null), M = S(null), E = he(
() => Ht(e.pluginManager.getToolbarItems(), u),
[e, u]
), M = me(
() => k.map((i, b) => Rt(i, b)),
[k]
), L = he(
() => E.map((i, b) => Mt(i, b)),
[E]
);
O(() => {
B.current = x;
}, [x]), O(() => {
I.current = D;
}, [D]);
const R = (i) => {
z.current = i, i && !i.collapsed ? P.current = i : P.current = null;
}, S = () => E.current?.closest("[data-editora-editor]")?.querySelector(".rte-content, .editora-content") || null, L = () => {
const i = J(S()), b = JSON.stringify(i);
b !== C.current && (C.current = b, w(i));
}, W = () => {
F(() => {
U.current = A;
}, [A]), F(() => {
q.current = p;
}, [p]);
const D = (i) => {
h.current = i, i && !i.collapsed ? N.current = i : N.current = null;
}, W = () => P.current?.closest("[data-editora-editor]")?.querySelector(".rte-content, .editora-content") || null, O = () => {
const i = J(W()), b = JSON.stringify(i);
b !== I.current && (I.current = b, $(i));
}, G = () => {
if (typeof window > "u") return;
const i = E.current?.closest("[data-editora-editor]");
const i = P.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = i || null;
}, j = (i) => {
}, Q = (i) => {
if (typeof window > "u" || !i) return;
const b = i.getAttribute("data-command");
b && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = b);
}, X = () => {
const i = S();
}, ue = () => {
const i = W();
if (!i) return null;
const b = window.getSelection();
if (!b || b.rangeCount === 0) return null;
const h = b.getRangeAt(0);
return i.contains(h.commonAncestorContainer) ? h.cloneRange() : null;
}, q = () => {
const i = X();
i && R(i);
const m = b.getRangeAt(0);
return i.contains(m.commonAncestorContainer) ? m.cloneRange() : null;
}, Y = () => {
const i = ue();
i && D(i);
};
O(() => {
const i = E.current?.closest("[data-editora-editor]");
F(() => {
const i = P.current?.closest("[data-editora-editor]");
if (!i) return;
const b = i.querySelector(".rte-content, .editora-content");
c(b?.getAttribute("data-track-changes") === "true");
const h = (V) => {
c(!!V.detail?.enabled);
const m = (K) => {
c(!!K.detail?.enabled);
};
return i.addEventListener("editora:track-changes-toggle", h), () => {
i.removeEventListener("editora:track-changes-toggle", h);
return i.addEventListener("editora:track-changes-toggle", m), () => {
i.removeEventListener("editora:track-changes-toggle", m);
};
}, []), O(() => {
}, []), F(() => {
const i = P.current?.closest("[data-editora-editor]");
if (!i) return;
const b = i.querySelector(".rte-content, .editora-content");
g(b?.classList.contains("rte-format-painter-active") ?? !1);
const m = (K) => {
g(!!K.detail?.active);
};
return i.addEventListener("editora:format-painter-toggle", m), () => {
i.removeEventListener("editora:format-painter-toggle", m);
};
}, []), F(() => {
const i = () => {
q(), L();
}, b = S();
return document.addEventListener("selectionchange", i), b?.addEventListener("input", L), b?.addEventListener("keyup", L), b?.addEventListener("mouseup", L), L(), () => {
document.removeEventListener("selectionchange", i), b?.removeEventListener("input", L), b?.removeEventListener("keyup", L), b?.removeEventListener("mouseup", L);
Y(), O();
}, b = W();
return document.addEventListener("selectionchange", i), b?.addEventListener("input", O), b?.addEventListener("keyup", O), b?.addEventListener("mouseup", O), O(), () => {
document.removeEventListener("selectionchange", i), b?.removeEventListener("input", O), b?.removeEventListener("keyup", O), b?.removeEventListener("mouseup", O);
};
}, []), O(() => {
if (!s) return;
const i = (h) => {
const V = h.target;
V && V instanceof Element && (V.closest(".rte-toolbar-dropdown") || g(null));
}, b = (h) => {
h.key === "Escape" && g(null);
}, []), F(() => {
if (!R) return;
const i = (m) => {
const K = m.target;
K && K instanceof Element && (K.closest(".rte-toolbar-dropdown") || y(null));
}, b = (m) => {
m.key === "Escape" && y(null);
};

@@ -428,4 +440,4 @@ return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", b), () => {

};
}, [s]);
const ce = (i) => [
}, [R]);
const Ze = (i) => [
"toggleBold",

@@ -440,11 +452,11 @@ "toggleItalic",

"toggleCode"
].includes(i), Re = (i = !1) => {
const b = S();
].includes(i), xe = (i = !1) => {
const b = W();
if (!b) return !1;
const h = window.getSelection();
if (!h) return !1;
const V = (F) => F ? F.startContainer.isConnected && F.endContainer.isConnected && b.contains(F.startContainer) && b.contains(F.endContainer) : !1, $ = h.rangeCount > 0 && V(h.getRangeAt(0)) ? h.getRangeAt(0) : null, K = V(z.current) ? z.current : null, ee = V(P.current) && !P.current.collapsed ? P.current : null, te = i ? ee || K || $ : K || $ || ee;
if (te)
const m = window.getSelection();
if (!m) return !1;
const K = (H) => H ? H.startContainer.isConnected && H.endContainer.isConnected && b.contains(H.startContainer) && b.contains(H.endContainer) : !1, B = m.rangeCount > 0 && K(m.getRangeAt(0)) ? m.getRangeAt(0) : null, V = K(h.current) ? h.current : null, te = K(N.current) && !N.current.collapsed ? N.current : null, ne = i ? te || V || B : V || B || te;
if (ne)
try {
return b.focus({ preventScroll: !0 }), h.removeAllRanges(), h.addRange(te), !0;
return b.focus({ preventScroll: !0 }), m.removeAllRanges(), m.addRange(ne), !0;
} catch {

@@ -454,52 +466,52 @@ }

};
xt(() => {
It(() => {
if (!a) {
l(null), _(!1), B.current = null, I.current = !1, H.current = {}, f.current = "";
_(null), v(!1), U.current = null, q.current = !1, C.current = {}, T.current = "";
return;
}
const i = M.join("|");
if (f.current !== i && (f.current = i, H.current = {}, I.current && (I.current = !1, _(!1)), B.current !== null)) {
B.current = null, l(null);
const i = L.join("|");
if (T.current !== i && (T.current = i, C.current = {}, q.current && (q.current = !1, v(!1)), U.current !== null)) {
U.current = null, _(null);
return;
}
let h = null;
const V = () => {
if (!E.current || !A.current) return;
const ee = E.current.clientWidth, te = 16, F = 40, ne = 4, pe = Math.max(0, ee - te - F - ne);
let Ne = 0, He = 0;
const we = A.current.children;
for (let Z = 0; Z < we.length; Z++) {
const at = we[Z], re = M[Z], ye = re ? H.current[re] : void 0, Ee = typeof ye == "number" && ye > 0 ? ye : at.getBoundingClientRect().width;
re && Ee > 0 && (H.current[re] = Ee);
const De = (re ? H.current[re] : void 0) ?? Ee, Be = (De > 0 ? De : 40) + ne;
if (Ne + Be <= pe)
Ne += Be, He++;
let m = null;
const K = () => {
if (!P.current || !x.current) return;
const te = P.current.clientWidth, ne = 16, H = 40, re = 4, ve = Math.max(0, te - ne - H - re);
let He = 0, De = 0;
const we = x.current.children;
for (let ee = 0; ee < we.length; ee++) {
const lt = we[ee], oe = L[ee], Ee = oe ? C.current[oe] : void 0, Ce = typeof Ee == "number" && Ee > 0 ? Ee : lt.getBoundingClientRect().width;
oe && Ce > 0 && (C.current[oe] = Ce);
const Be = (oe ? C.current[oe] : void 0) ?? Ce, Fe = (Be > 0 ? Be : 40) + re;
if (He + Fe <= ve)
He += Fe, De++;
else
break;
}
const ve = Math.max(1, Math.min(He, we.length));
B.current = ve, l((Z) => Z === ve ? Z : ve);
}, $ = () => {
h !== null && cancelAnimationFrame(h), h = requestAnimationFrame(V);
const ye = Math.max(1, Math.min(De, we.length));
U.current = ye, _((ee) => ee === ye ? ee : ye);
}, B = () => {
m !== null && cancelAnimationFrame(m), m = requestAnimationFrame(K);
};
$();
const K = new ResizeObserver(() => {
$();
B();
const V = new ResizeObserver(() => {
B();
});
return E.current && K.observe(E.current), () => {
h !== null && cancelAnimationFrame(h), K.disconnect();
return P.current && V.observe(P.current), () => {
m !== null && cancelAnimationFrame(m), V.disconnect();
};
}, [M, a]), O(() => {
D && x !== null && x >= k.length && _(!1);
}, [D, x, k.length]);
const xe = (i) => (m.current[i] || (m.current[i] = it.createRef()), m.current[i]), le = (i, b) => {
}, [L, a]), F(() => {
p && A !== null && A >= E.length && v(!1);
}, [p, A, E.length]);
const Me = (i) => (f.current[i] || (f.current[i] = st.createRef()), f.current[i]), se = (i, b) => {
if (o) return;
W(), i === "addComment" || i === "toggleComments" || Re(ce(i)), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, b), requestAnimationFrame(L), g(null);
}, Ye = (i) => {
o || (q(), g(s === i ? null : i));
}, Ze = (i) => {
o || (q(), y(N === i ? null : i), g(null));
}, et = (i, b) => {
o || (Re(), le(i, b), y(null));
}, Me = (i, b) => i && i.startsWith("<svg") && i.endsWith("</svg>") ? /* @__PURE__ */ p("span", { dangerouslySetInnerHTML: { __html: i } }) : i && i.length === 1 && /^[BIUSH]$/.test(i) ? /* @__PURE__ */ p("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: i }) : i || "⚪", tt = {
G(), i === "addComment" || i === "toggleComments" || xe(Ze(i)), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, b), requestAnimationFrame(O), y(null);
}, et = (i) => {
o || (Y(), y(R === i ? null : i));
}, tt = (i) => {
o || (Y(), l(z === i ? null : i), y(null));
}, nt = (i, b) => {
o || (xe(), se(i, b), l(null));
}, Ie = (i, b) => i && i.startsWith("<svg") && i.endsWith("</svg>") ? /* @__PURE__ */ w("span", { dangerouslySetInnerHTML: { __html: i } }) : i && i.length === 1 && /^[BIUSH]$/.test(i) ? /* @__PURE__ */ w("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: i }) : i || "⚪", rt = {
...n && {

@@ -516,9 +528,9 @@ position: "sticky",

}
}, nt = !a || x !== null, Ie = a && x !== null && x < k.length, rt = (i) => {
}, ot = !a || A !== null, Ne = a && A !== null && A < E.length, at = (i) => {
if (o) return;
const b = i.target;
b.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (j(b.closest("[data-command]")), W(), q(), i.preventDefault());
}, be = (i, b = !0) => i.map((h, V) => {
const $ = h.command || "", K = $ === "toggleTrackChanges" && d || U($, v), ee = "options" in h ? h.options : void 0, te = $ === "setBlockType" && ee?.find((F) => F.value === (v.blockType || "p"))?.label || h.label;
return /* @__PURE__ */ p(
b.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (Q(b.closest("[data-command]")), G(), Y(), i.preventDefault());
}, pe = (i, b = !0) => i.map((m, K) => {
const B = m.command || "", V = B === "toggleTrackChanges" && d || B === "toggleFormatPainter" && s || j(B, k), te = "options" in m ? m.options : void 0, ne = B === "setBlockType" && te?.find((H) => H.value === (k.blockType || "p"))?.label || m.label;
return /* @__PURE__ */ w(
"div",

@@ -528,19 +540,19 @@ {

style: {
display: b && a && x !== null && V >= x ? "none" : "flex"
display: b && a && A !== null && K >= A ? "none" : "flex"
},
children: h.type === "separator" ? /* @__PURE__ */ p("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : h.type === "dropdown" ? /* @__PURE__ */ Y("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ Y(
children: m.type === "separator" ? /* @__PURE__ */ w("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : m.type === "dropdown" ? /* @__PURE__ */ Z("div", { className: "rte-toolbar-dropdown", children: [
/* @__PURE__ */ Z(
"button",
{
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": $,
"data-active": K ? "true" : "false",
"aria-pressed": K ? "true" : "false",
onMouseDown: (F) => {
F.preventDefault(), q();
className: `rte-toolbar-button ${V ? "active" : ""}`,
"data-command": B,
"data-active": V ? "true" : "false",
"aria-pressed": V ? "true" : "false",
onMouseDown: (H) => {
H.preventDefault(), Y();
},
onClick: () => Ye($),
onClick: () => et(B),
disabled: o,
children: [
te,
ne,
" ▼"

@@ -550,84 +562,84 @@ ]

),
s === $ && /* @__PURE__ */ p("div", { className: "rte-toolbar-dropdown-menu", children: h.options?.map((F) => {
const ne = $ === "setBlockType" && v.blockType === F.value;
return /* @__PURE__ */ p(
R === B && /* @__PURE__ */ w("div", { className: "rte-toolbar-dropdown-menu", children: m.options?.map((H) => {
const re = B === "setBlockType" && k.blockType === H.value;
return /* @__PURE__ */ w(
"div",
{
className: `rte-toolbar-dropdown-item ${ne ? "active" : ""}`,
"data-active": ne ? "true" : "false",
"aria-selected": ne ? "true" : "false",
onMouseDown: (pe) => pe.preventDefault(),
onClick: () => le($, F.value),
children: F.label
className: `rte-toolbar-dropdown-item ${re ? "active" : ""}`,
"data-active": re ? "true" : "false",
"aria-selected": re ? "true" : "false",
onMouseDown: (ve) => ve.preventDefault(),
onClick: () => se(B, H.value),
children: H.label
},
F.value
H.value
);
}) })
] }) : h.type === "inline-menu" ? /* @__PURE__ */ p(
] }) : m.type === "inline-menu" ? /* @__PURE__ */ w(
"button",
{
ref: xe($),
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": $,
"data-active": K ? "true" : "false",
"aria-pressed": K ? "true" : "false",
onMouseDown: (F) => {
F.preventDefault(), q();
ref: Me(B),
className: `rte-toolbar-button ${V ? "active" : ""}`,
"data-command": B,
"data-active": V ? "true" : "false",
"aria-pressed": V ? "true" : "false",
onMouseDown: (H) => {
H.preventDefault(), Y();
},
onClick: () => Ze($),
onClick: () => tt(B),
disabled: o,
title: h.label,
children: Me(h.icon)
title: m.label,
children: Ie(m.icon)
}
) : h.type === "input" ? /* @__PURE__ */ p(
) : m.type === "input" ? /* @__PURE__ */ w(
"input",
{
type: "text",
className: `rte-toolbar-input ${h.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: h.placeholder,
onChange: (F) => le($, F.target.value),
className: `rte-toolbar-input ${m.label.toLowerCase().replace(/\s+/g, "-")}`,
placeholder: m.placeholder,
onChange: (H) => se(B, H.target.value),
disabled: o,
onKeyDown: (F) => {
F.key === "Enter" && le(
$,
F.target.value
onKeyDown: (H) => {
H.key === "Enter" && se(
B,
H.target.value
);
},
title: h.label
title: m.label
}
) : h.type === "group" ? /* @__PURE__ */ p(
) : m.type === "group" ? /* @__PURE__ */ w(
"div",
{
className: `rte-toolbar-group-button ${h.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${h.label}`,
children: /* @__PURE__ */ p(
className: `rte-toolbar-group-button ${m.label.toLowerCase().replace(/\s+/g, "-")}`,
title: `${m.label}`,
children: /* @__PURE__ */ w(
"div",
{
className: `rte-toolbar-group-items ${h.label.toLowerCase().replace(/\s+/g, "-")}`,
children: be(h.items || [], !1)
className: `rte-toolbar-group-items ${m.label.toLowerCase().replace(/\s+/g, "-")}`,
children: pe(m.items || [], !1)
}
)
}
) : /* @__PURE__ */ p(
) : /* @__PURE__ */ w(
"button",
{
className: `rte-toolbar-button ${K ? "active" : ""}`,
"data-command": $,
"data-active": K ? "true" : "false",
"aria-pressed": K ? "true" : "false",
onMouseDown: (F) => {
F.preventDefault(), q();
className: `rte-toolbar-button ${V ? "active" : ""}`,
"data-command": B,
"data-active": V ? "true" : "false",
"aria-pressed": V ? "true" : "false",
onMouseDown: (H) => {
H.preventDefault(), Y();
},
onClick: () => le($),
onClick: () => se(B),
disabled: o,
title: h.label,
children: Me(h.icon)
title: m.label,
children: Ie(m.icon)
}
)
},
V
K
);
}), ot = a && x !== null ? k.filter((i, b) => b >= x) : [];
return /* @__PURE__ */ Y(ge, { children: [
/* @__PURE__ */ Y(
}), it = a && A !== null ? E.filter((i, b) => b >= A) : [];
return /* @__PURE__ */ Z(me, { children: [
/* @__PURE__ */ Z(
"div",

@@ -637,26 +649,26 @@ {

style: {
...tt,
...nt ? null : { visibility: "hidden" }
...rt,
...ot ? null : { visibility: "hidden" }
},
onMouseDownCapture: rt,
onMouseDownCapture: at,
children: [
/* @__PURE__ */ Y("div", { className: "rte-toolbar", ref: E, children: [
/* @__PURE__ */ p(
/* @__PURE__ */ Z("div", { className: "rte-toolbar", ref: P, children: [
/* @__PURE__ */ w(
"div",
{
className: "rte-toolbar-items-container",
ref: A,
ref: x,
style: a ? void 0 : { flexWrap: "wrap" },
children: be(k)
children: pe(E)
}
),
Ie && /* @__PURE__ */ p(
Ne && /* @__PURE__ */ w(
"button",
{
ref: G,
className: `rte-toolbar-more-button ${D ? "active" : ""}`,
ref: M,
className: `rte-toolbar-more-button ${p ? "active" : ""}`,
onMouseDown: (i) => {
i.preventDefault(), q();
i.preventDefault(), Y();
},
onClick: () => _(!D),
onClick: () => v(!p),
disabled: o,

@@ -669,17 +681,17 @@ title: "Show more options",

] }),
Ie && /* @__PURE__ */ p("div", { className: `rte-toolbar-expanded-row ${D ? "show" : ""}`, children: be(ot, !1) })
Ne && /* @__PURE__ */ w("div", { className: `rte-toolbar-expanded-row ${p ? "show" : ""}`, children: pe(it, !1) })
]
}
),
k.map((i) => {
E.map((i) => {
if (i.type === "inline-menu") {
const b = i.command || "";
return /* @__PURE__ */ p(
mt,
return /* @__PURE__ */ w(
bt,
{
isOpen: N === b,
isOpen: z === b,
options: i.options || [],
onSelect: (h) => et(b, h),
onClose: () => y(null),
anchorRef: xe(b)
onSelect: (m) => nt(b, m),
onClose: () => l(null),
anchorRef: Me(b)
},

@@ -693,5 +705,5 @@ `menu-${b || "unknown"}`

};
function Nt(e, t) {
const n = T(), r = T("");
return O(() => {
function Dt(e, t) {
const n = S(), r = S("");
return F(() => {
if (!t?.enabled) return;

@@ -738,3 +750,3 @@ const a = t.intervalMs || 3e4, u = t.storageKey || "rte-autosave", d = t.provider || "localStorage", c = async () => {

}
const Ht = [
const Bt = [
"p",

@@ -779,3 +791,3 @@ "br",

"hr"
], Dt = {
], Ft = {
"*": ["class", "style", "id", "data-*", "role", "aria-*", "tabindex", "contenteditable", "spellcheck", "dir", "lang"],

@@ -791,9 +803,9 @@ a: ["href", "target", "rel", "title"],

};
function Ge(e, t, n) {
function Je(e, t, n) {
if (t?.sanitize === !1)
return e;
const r = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ht, a = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Dt, u = document.createElement("div");
return u.innerHTML = e, Je(u, r, a), u.innerHTML;
const r = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Bt, a = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ft, u = document.createElement("div");
return u.innerHTML = e, Xe(u, r, a), u.innerHTML;
}
function Je(e, t, n) {
function Xe(e, t, n) {
const r = Array.from(e.childNodes);

@@ -809,3 +821,3 @@ for (const o of r)

}
Bt(a, n), Je(a, t, n);
_t(a, n), Xe(a, t, n);
} else {

@@ -817,3 +829,3 @@ if (o.nodeType === Node.TEXT_NODE)

}
function Bt(e, t) {
function _t(e, t) {
const n = e.tagName.toLowerCase(), r = Array.from(e.attributes), o = t[n] || [], a = t["*"] || [], u = [...o, ...a];

@@ -826,4 +838,4 @@ for (const d of r) {

if (g.endsWith("*")) {
const N = g.slice(0, -1);
if (c.startsWith(N)) {
const R = g.slice(0, -1);
if (c.startsWith(R)) {
s = !0;

@@ -838,12 +850,12 @@ break;

}
function Ft(e, t, n) {
return n?.sanitizeOnPaste === !1 ? e : Ge(e, t);
function Ot(e, t, n) {
return n?.sanitizeOnPaste === !1 ? e : Je(e, t);
}
function Oe(e, t, n) {
return n?.sanitizeOnInput === !1 ? e : Ge(e, t);
function $e(e, t, n) {
return n?.sanitizeOnInput === !1 ? e : Je(e, t);
}
const fe = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), ae = (e, t) => {
const r = !!t && fe(e);
const ge = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), ie = (e, t) => {
const r = !!t && ge(e);
e.classList.toggle("rte-content-empty", r);
}, Te = "data-rte-caret-marker", Le = "data-rte-range-start-marker", Ae = "data-rte-range-end-marker", Ce = () => Math.random().toString(36).slice(2), _t = (e) => {
}, Te = "data-rte-caret-marker", Ae = "data-rte-range-start-marker", Re = "data-rte-range-end-marker", ke = () => Math.random().toString(36).slice(2), $t = (e) => {
const t = window.getSelection();

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

}
}, $e = (e, t) => {
}, Pe = (e, t) => {
const n = document.createTreeWalker(e, NodeFilter.SHOW_TEXT);

@@ -879,3 +891,3 @@ let r = n.nextNode(), o = Math.max(0, t), a = null;

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

@@ -885,12 +897,12 @@ if (!t || t.rangeCount === 0) return null;

if (!e.contains(n.commonAncestorContainer)) return null;
const r = _t(e);
const r = $t(e);
try {
if (n.collapsed) {
const g = Ce(), N = document.createElement("span");
return N.setAttribute(Te, g), N.appendChild(document.createTextNode("​")), n.cloneRange().insertNode(N), { collapsed: !0, caretId: g, fallbackOffsets: r };
const g = ke(), R = document.createElement("span");
return R.setAttribute(Te, g), R.appendChild(document.createTextNode("​")), n.cloneRange().insertNode(R), { collapsed: !0, caretId: g, fallbackOffsets: r };
}
const o = Ce(), a = Ce(), u = document.createElement("span");
u.setAttribute(Ae, a), u.appendChild(document.createTextNode("​"));
const o = ke(), a = ke(), u = document.createElement("span");
u.setAttribute(Re, a), u.appendChild(document.createTextNode("​"));
const d = document.createElement("span");
d.setAttribute(Le, o), d.appendChild(document.createTextNode("​"));
d.setAttribute(Ae, o), d.appendChild(document.createTextNode("​"));
const c = n.cloneRange();

@@ -903,7 +915,7 @@ c.collapse(!1), c.insertNode(u);

}
}, $t = (e) => {
}, Wt = (e) => {
e.querySelectorAll(
`[${Te}], [${Le}], [${Ae}]`
`[${Te}], [${Ae}], [${Re}]`
).forEach((t) => t.remove());
}, Wt = (e, t) => {
}, zt = (e, t) => {
if (!t) return !1;

@@ -919,3 +931,3 @@ const n = window.getSelection();

if (!t.collapsed && t.startId && t.endId) {
const o = e.querySelector(`[${Le}="${t.startId}"]`), a = e.querySelector(`[${Ae}="${t.endId}"]`);
const o = e.querySelector(`[${Ae}="${t.startId}"]`), a = e.querySelector(`[${Re}="${t.endId}"]`);
return !o || !a || !o.parentNode || !a.parentNode ? !1 : (r.setStartAfter(o), r.setEndBefore(a), n.removeAllRanges(), n.addRange(r), !0);

@@ -927,3 +939,3 @@ }

return !1;
}, zt = (e, t) => {
}, Ut = (e, t) => {
if (!t) return;

@@ -933,7 +945,7 @@ const n = window.getSelection();

try {
const r = $e(e, t.start), o = $e(e, t.end), a = document.createRange();
const r = Pe(e, t.start), o = Pe(e, t.end), a = document.createRange();
a.setStart(r.node, r.offset), a.setEnd(o.node, o.offset), n.removeAllRanges(), n.addRange(a);
} catch {
}
}, Pt = ({
}, qt = ({
editor: e,

@@ -950,137 +962,137 @@ defaultValue: t,

accessibilityConfig: g,
autosaveConfig: N,
autosaveConfig: R,
contextMenuConfig: y,
spellcheckConfig: x
spellcheckConfig: z
}) => {
const l = T(null), D = n !== void 0, _ = T(), v = T(null), w = d?.autoHeight === !0, C = typeof d?.minHeight == "number" ? d.minHeight : 200, B = typeof d?.maxHeight == "number" ? d.maxHeight : 0, I = (m) => {
if (!m || !w) return;
m.style.height = "auto";
const H = Math.max(C, m.scrollHeight);
if (B > 0) {
m.style.height = `${Math.min(H, B)}px`;
const l = S(null), A = n !== void 0, _ = S(), p = S(null), v = d?.autoHeight === !0, k = typeof d?.minHeight == "number" ? d.minHeight : 200, $ = typeof d?.maxHeight == "number" ? d.maxHeight : 0, I = (h) => {
if (!h || !v) return;
h.style.height = "auto";
const N = Math.max(k, h.scrollHeight);
if ($ > 0) {
h.style.height = `${Math.min(N, $)}px`;
return;
}
m.style.height = `${H}px`;
}, { restore: z } = Nt(
h.style.height = `${N}px`;
}, { restore: U } = Dt(
() => l.current?.innerHTML || "",
N
R
);
O(() => {
F(() => {
if (!l.current) return;
const m = z(), H = m ?? n ?? t ?? "";
H.trim() ? l.current.innerHTML !== H && (l.current.innerHTML = H) : o ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), ae(l.current, o), I(l.current), m && a && a(m);
}, []), O(() => {
!l.current || !D || (n !== l.current.innerHTML && (l.current.innerHTML = n), ae(l.current, o), I(l.current));
}, [n, D]), O(() => {
const h = U(), N = h ?? n ?? t ?? "";
N.trim() ? l.current.innerHTML !== N && (l.current.innerHTML = N) : o ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), ie(l.current, o), I(l.current), h && a && a(h);
}, []), F(() => {
!l.current || !A || (n !== l.current.innerHTML && (l.current.innerHTML = n), ie(l.current, o), I(l.current));
}, [n, A]), F(() => {
if (!l.current) return;
const m = l.current;
const h = l.current;
if (o) {
m.setAttribute("data-placeholder", o), fe(m) && (m.innerHTML = ""), ae(m, o), I(m);
h.setAttribute("data-placeholder", o), ge(h) && (h.innerHTML = ""), ie(h, o), I(h);
return;
}
m.removeAttribute("data-placeholder"), ae(m, o), I(m);
}, [o]), O(() => {
h.removeAttribute("data-placeholder"), ie(h, o), I(h);
}, [o]), F(() => {
if (!l.current) return;
const m = l.current;
const h = l.current;
if (g?.enableARIA !== !1) {
m.setAttribute("role", "textbox"), m.setAttribute("aria-multiline", "true"), m.setAttribute("aria-disabled", r ? "true" : "false");
h.setAttribute("role", "textbox"), h.setAttribute("aria-multiline", "true"), h.setAttribute("aria-disabled", r ? "true" : "false");
const f = o?.trim();
f ? m.setAttribute("aria-label", f) : m.removeAttribute("aria-label");
f ? h.setAttribute("aria-label", f) : h.removeAttribute("aria-label");
} else
m.removeAttribute("role"), m.removeAttribute("aria-multiline"), m.removeAttribute("aria-label"), m.removeAttribute("aria-disabled");
}, [g?.enableARIA, o, r]), O(() => {
h.removeAttribute("role"), h.removeAttribute("aria-multiline"), h.removeAttribute("aria-label"), h.removeAttribute("aria-disabled");
}, [g?.enableARIA, o, r]), F(() => {
I(l.current);
}, [w, C, B, n]), O(() => {
}, [v, k, $, n]), F(() => {
if (!l.current) return;
const m = (R, S) => {
const L = v.current;
if (v.current = null, !L || L.beforeHTML === S || L.inputType === "historyUndo" || L.inputType === "historyRedo") return;
const h = (E, L) => {
const D = p.current;
if (p.current = null, !D || D.beforeHTML === L || D.inputType === "historyUndo" || D.inputType === "historyRedo") return;
const W = window.execEditorCommand;
typeof W == "function" && W("recordDomTransaction", R, L.beforeHTML, S);
}, H = (R) => {
typeof W == "function" && W("recordDomTransaction", E, D.beforeHTML, L);
}, N = (E) => {
if (!l.current || r) return;
const S = R.inputType || null;
if (S === "historyUndo" || S === "historyRedo") {
v.current = null;
const L = E.inputType || null;
if (L === "historyUndo" || L === "historyRedo") {
p.current = null;
return;
}
v.current = {
p.current = {
beforeHTML: l.current.innerHTML,
inputType: S
inputType: L
};
}, f = () => {
if (!l.current || r) return;
o && fe(l.current) && (l.current.innerHTML = "");
let R = l.current.innerHTML;
o && ge(l.current) && (l.current.innerHTML = "");
let E = l.current.innerHTML;
if (c?.sanitizeOnInput !== !1 && d?.sanitize !== !1) {
const S = Oe(R, d, c);
if (S !== l.current.innerHTML) {
const L = Ot(l.current), W = l.current.innerHTML, j = Oe(W, d, c);
l.current.innerHTML = j, Wt(l.current, L) || zt(l.current, L?.fallbackOffsets || null), $t(l.current), R = l.current.innerHTML;
const L = $e(E, d, c);
if (L !== l.current.innerHTML) {
const D = Pt(l.current), W = l.current.innerHTML, O = $e(W, d, c);
l.current.innerHTML = O, zt(l.current, D) || Ut(l.current, D?.fallbackOffsets || null), Wt(l.current), E = l.current.innerHTML;
} else
R = S;
E = L;
}
ae(l.current, o), I(l.current), m(l.current, R), a && (s?.debounceInputMs ? (_.current && clearTimeout(_.current), _.current = setTimeout(() => {
a(R);
}, s.debounceInputMs)) : a(R));
}, E = (R) => {
if (R.__editoraSmartPasteHandled === !0 || R.defaultPrevented)
ie(l.current, o), I(l.current), h(l.current, E), a && (s?.debounceInputMs ? (_.current && clearTimeout(_.current), _.current = setTimeout(() => {
a(E);
}, s.debounceInputMs)) : a(E));
}, C = (E) => {
if (E.__editoraSmartPasteHandled === !0 || E.defaultPrevented)
return;
if (r) {
R.preventDefault();
E.preventDefault();
return;
}
R.preventDefault();
let S = R.clipboardData?.getData("text/html");
const L = R.clipboardData?.getData("text/plain"), W = !!S && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S);
E.preventDefault();
let L = E.clipboardData?.getData("text/html");
const D = E.clipboardData?.getData("text/plain"), W = !!L && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(L);
if (u?.clean || !u?.keepFormatting) {
L && document.execCommand("insertText", !1, L);
D && document.execCommand("insertText", !1, D);
return;
}
if (u?.convertWord === !1 && W) {
L && document.execCommand("insertText", !1, L);
D && document.execCommand("insertText", !1, D);
return;
}
if (S) {
c?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (S = Ft(S, d, c));
const j = window.getSelection();
if (j && j.rangeCount > 0) {
const X = j.getRangeAt(0);
X.deleteContents();
const q = document.createElement("div");
q.innerHTML = S;
const ce = document.createDocumentFragment();
for (; q.firstChild; )
ce.appendChild(q.firstChild);
X.insertNode(ce), X.collapse(!1), j.removeAllRanges(), j.addRange(X);
if (L) {
c?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (L = Ot(L, d, c));
const O = window.getSelection();
if (O && O.rangeCount > 0) {
const G = O.getRangeAt(0);
G.deleteContents();
const Q = document.createElement("div");
Q.innerHTML = L;
const ue = document.createDocumentFragment();
for (; Q.firstChild; )
ue.appendChild(Q.firstChild);
G.insertNode(ue), G.collapse(!1), O.removeAllRanges(), O.addRange(G);
}
} else L && document.execCommand("insertText", !1, L);
}, A = (R) => {
const S = R.target;
(S.tagName === "IMG" || S.tagName === "VIDEO") && (S.style.resize = "both", S.style.overflow = "auto", S.style.display = "inline-block");
}, G = (R) => {
y?.enabled === !1 && R.preventDefault();
}, k = () => {
l.current && (o && fe(l.current) && (l.current.innerHTML = ""), ae(l.current, o), I(l.current));
} else D && document.execCommand("insertText", !1, D);
}, T = (E) => {
const L = E.target;
(L.tagName === "IMG" || L.tagName === "VIDEO") && (L.style.resize = "both", L.style.overflow = "auto", L.style.display = "inline-block");
}, P = (E) => {
y?.enabled === !1 && E.preventDefault();
}, x = () => {
l.current && (o && ge(l.current) && (l.current.innerHTML = ""), ie(l.current, o), I(l.current));
}, M = l.current;
return M.addEventListener("beforeinput", H), M.addEventListener("input", f), M.addEventListener("paste", E), M.addEventListener("click", A), M.addEventListener("contextmenu", G), M.addEventListener("focus", k), M.addEventListener("blur", k), r || M.focus(), () => {
_.current && clearTimeout(_.current), M.removeEventListener("beforeinput", H), M.removeEventListener("input", f), M.removeEventListener("paste", E), M.removeEventListener("click", A), M.removeEventListener("contextmenu", G), M.removeEventListener("focus", k), M.removeEventListener("blur", k);
return M.addEventListener("beforeinput", N), M.addEventListener("input", f), M.addEventListener("paste", C), M.addEventListener("click", T), M.addEventListener("contextmenu", P), M.addEventListener("focus", x), M.addEventListener("blur", x), r || M.focus(), () => {
_.current && clearTimeout(_.current), M.removeEventListener("beforeinput", N), M.removeEventListener("input", f), M.removeEventListener("paste", C), M.removeEventListener("click", T), M.removeEventListener("contextmenu", P), M.removeEventListener("focus", x), M.removeEventListener("blur", x);
};
}, [e, a, u, d, c, s, o, y, r]);
const P = (x?.enabled ?? !1) && (x?.provider ?? "browser") === "browser";
return O(() => {
const q = (z?.enabled ?? !1) && (z?.provider ?? "browser") === "browser";
return F(() => {
if (!l.current || typeof window > "u" || r || g?.keyboardNavigation === !1)
return;
const m = new Ue(), H = l.current, f = (E) => {
m.handleKeyDown(E, (A, G) => {
const h = new qe(), N = l.current, f = (C) => {
h.handleKeyDown(C, (T, P) => {
if (typeof window < "u" && window.executeEditorCommand) {
const k = l.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = k || null, window.executeEditorCommand(A, G);
const x = l.current?.closest("[data-editora-editor]");
window.__editoraCommandEditorRoot = x || null, window.executeEditorCommand(T, P);
}
});
};
return H.addEventListener("keydown", f), () => {
H.removeEventListener("keydown", f);
return N.addEventListener("keydown", f), () => {
N.removeEventListener("keydown", f);
};
}, [g?.keyboardNavigation, r]), /* @__PURE__ */ p(
}, [g?.keyboardNavigation, r]), /* @__PURE__ */ w(
"div",

@@ -1091,3 +1103,3 @@ {

suppressContentEditableWarning: !0,
spellCheck: r ? !1 : P,
spellCheck: r ? !1 : q,
tabIndex: g?.keyboardNavigation === !1 ? -1 : 0,

@@ -1100,4 +1112,4 @@ "aria-keyshortcuts": g?.keyboardNavigation === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y",

style: {
minHeight: `${C}px`,
maxHeight: w ? B > 0 ? `${B}px` : "none" : "100%",
minHeight: `${k}px`,
maxHeight: v ? $ > 0 ? `${$}px` : "none" : "100%",
padding: "16px",

@@ -1109,4 +1121,4 @@ outline: "none",

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

@@ -1119,3 +1131,3 @@ wordWrap: "break-word",

);
}, Ut = ({
}, Kt = ({
editor: e,

@@ -1126,4 +1138,4 @@ isEnabled: t,

}) => {
const [o, a] = Q(!1), [u, d] = Q({ top: 0, left: 0 }), [c, s] = Q(() => J(null)), g = T(null), N = T(null), y = T(null), x = T(null), l = T(null);
O(() => {
const [o, a] = X(!1), [u, d] = X({ top: 0, left: 0 }), [c, s] = X(() => J(null)), g = S(null), R = S(null), y = S(null), z = S(null), l = S(null);
F(() => {
if (!t || r) {

@@ -1136,26 +1148,26 @@ a(!1);

if (l.current) return l.current;
const E = g.current?.closest("[data-editora-editor]");
if (E)
return l.current = E, E;
const A = f?.commonAncestorContainer, k = (A ? A.nodeType === Node.ELEMENT_NODE ? A : A.parentElement : null)?.closest("[data-editora-editor]");
return k ? (l.current = k, k) : null;
}, v = (f) => f && f.querySelector(".rte-content, .editora-content") || null, w = (f) => {
const C = g.current?.closest("[data-editora-editor]");
if (C)
return l.current = C, C;
const T = f?.commonAncestorContainer, x = (T ? T.nodeType === Node.ELEMENT_NODE ? T : T.parentElement : null)?.closest("[data-editora-editor]");
return x ? (l.current = x, x) : null;
}, p = (f) => f && f.querySelector(".rte-content, .editora-content") || null, v = (f) => {
if (!f || r) return !0;
const E = f.getAttribute("contenteditable"), A = f.getAttribute("data-readonly");
return E === "false" || A === "true" ? !0 : !!f.closest(
const C = f.getAttribute("contenteditable"), T = f.getAttribute("data-readonly");
return C === "false" || T === "true" ? !0 : !!f.closest(
'[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]'
);
}, C = (f) => {
}, k = (f) => {
if (!f.anchorNode || !f.focusNode) return !1;
try {
const E = document.createRange();
return E.setStart(f.anchorNode, f.anchorOffset), E.setEnd(f.focusNode, f.focusOffset), E.collapsed;
const C = document.createRange();
return C.setStart(f.anchorNode, f.anchorOffset), C.setEnd(f.focusNode, f.focusOffset), C.collapsed;
} catch {
return !1;
}
}, B = (f, E) => {
const A = Array.from(E.getClientRects()).filter((k) => k.width > 0 || k.height > 0);
return A.length === 0 ? E.getBoundingClientRect() : C(f) ? A[0] : A[A.length - 1];
}, $ = (f, C) => {
const T = Array.from(C.getClientRects()).filter((x) => x.width > 0 || x.height > 0);
return T.length === 0 ? C.getBoundingClientRect() : k(f) ? T[0] : T[T.length - 1];
}, I = () => {
x.current && clearTimeout(x.current);
z.current && clearTimeout(z.current);
const f = window.getSelection();

@@ -1166,13 +1178,13 @@ if (!f || f.rangeCount === 0) {

}
const E = f.getRangeAt(0);
if (E.collapsed) {
const C = f.getRangeAt(0);
if (C.collapsed) {
a(!1), s(J(null)), y.current = null;
return;
}
const A = f.toString().trim(), G = _(E), k = v(G);
if (!k || !k.contains(E.commonAncestorContainer)) {
const T = f.toString().trim(), P = _(C), x = p(P);
if (!x || !x.contains(C.commonAncestorContainer)) {
a(!1), s(J(null)), y.current = null;
return;
}
if (w(k)) {
if (v(x)) {
a(!1), s(J(null)), y.current = null;

@@ -1182,4 +1194,4 @@ return;

if (n) {
const M = k.getBoundingClientRect(), R = M.bottom >= 0 && M.top <= window.innerHeight, S = document.activeElement === k || k.contains(document.activeElement);
if (!R && !S) {
const M = x.getBoundingClientRect(), E = M.bottom >= 0 && M.top <= window.innerHeight, L = document.activeElement === x || x.contains(document.activeElement);
if (!E && !L) {
a(!1), s(J(null)), y.current = null;

@@ -1189,76 +1201,76 @@ return;

}
if (A.length > 0) {
const M = B(f, E), R = k.getBoundingClientRect(), S = 300;
if (M && R) {
const L = Math.max(8, M.top - 50);
if (T.length > 0) {
const M = $(f, C), E = x.getBoundingClientRect(), L = 300;
if (M && E) {
const D = Math.max(8, M.top - 50);
let W = M.left + M.width / 2;
const j = S / 2, X = R.left, q = R.right;
W - j < X && (W = X + j + 10), W + j > q && (W = q - j - 10), d({ top: L, left: W }), s(J(k)), a(!0), y.current = E.cloneRange();
const O = L / 2, G = E.left, Q = E.right;
W - O < G && (W = G + O + 10), W + O > Q && (W = Q - O - 10), d({ top: D, left: W }), s(J(x)), a(!0), y.current = C.cloneRange();
}
} else
a(!1), s(J(null)), y.current = null;
}, z = (f) => {
if (N.current && !N.current.contains(f.target)) {
const E = _();
window.getSelection(), v(E)?.contains(f.target) || (a(!1), y.current = null);
}, U = (f) => {
if (R.current && !R.current.contains(f.target)) {
const C = _();
window.getSelection(), p(C)?.contains(f.target) || (a(!1), y.current = null);
}
}, P = (f) => {
}, q = (f) => {
f.key === "Escape" && (a(!1), y.current = null);
}, m = v(_()), H = m && typeof MutationObserver < "u" ? new MutationObserver(() => {
w(m) && (a(!1), y.current = null);
}, h = p(_()), N = h && typeof MutationObserver < "u" ? new MutationObserver(() => {
v(h) && (a(!1), y.current = null);
}) : null;
return H && m && H.observe(m, {
return N && h && N.observe(h, {
attributes: !0,
attributeFilter: ["contenteditable", "data-readonly"]
}), document.addEventListener("selectionchange", I), document.addEventListener("mousedown", z), document.addEventListener("keydown", P), m?.addEventListener("mouseup", I), m?.addEventListener("keyup", I), () => {
document.removeEventListener("selectionchange", I), document.removeEventListener("mousedown", z), document.removeEventListener("keydown", P), m?.removeEventListener("mouseup", I), m?.removeEventListener("keyup", I), H?.disconnect(), x.current && clearTimeout(x.current);
}), document.addEventListener("selectionchange", I), document.addEventListener("mousedown", U), document.addEventListener("keydown", q), h?.addEventListener("mouseup", I), h?.addEventListener("keyup", I), () => {
document.removeEventListener("selectionchange", I), document.removeEventListener("mousedown", U), document.removeEventListener("keydown", q), h?.removeEventListener("mouseup", I), h?.removeEventListener("keyup", I), N?.disconnect(), z.current && clearTimeout(z.current);
};
}, [t, n, r]);
const D = (_, v) => {
const A = (_, p) => {
if (r || !y.current) return;
typeof window < "u" && (window.__editoraCommandEditorRoot = l.current || null);
const w = l.current?.querySelector(".rte-content, .editora-content");
if (w && (w.getAttribute("contenteditable") === "false" || w.getAttribute("data-readonly") === "true")) {
const v = l.current?.querySelector(".rte-content, .editora-content");
if (v && (v.getAttribute("contenteditable") === "false" || v.getAttribute("data-readonly") === "true")) {
a(!1), y.current = null;
return;
}
w && w.focus();
const C = window.getSelection();
if (C && y.current)
v && v.focus();
const k = window.getSelection();
if (k && y.current)
try {
C.removeAllRanges(), C.addRange(y.current);
k.removeAllRanges(), k.addRange(y.current);
} catch {
}
const B = (z, P) => {
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(z, P);
const $ = (U, q) => {
typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(U, q);
};
({
toggleBold: () => B("toggleBold"),
toggleItalic: () => B("toggleItalic"),
toggleUnderline: () => B("toggleUnderline"),
toggleStrikethrough: () => B("toggleStrikethrough"),
toggleBold: () => $("toggleBold"),
toggleItalic: () => $("toggleItalic"),
toggleUnderline: () => $("toggleUnderline"),
toggleStrikethrough: () => $("toggleStrikethrough"),
createLink: () => {
B("openLinkDialog");
$("openLinkDialog");
},
clearFormatting: () => {
B("clearFormatting");
$("clearFormatting");
},
toggleCode: () => {
const z = window.getSelection();
if (z && z.rangeCount > 0) {
const P = z.getRangeAt(0), m = document.createElement("code");
P.surroundContents(m);
const U = window.getSelection();
if (U && U.rangeCount > 0) {
const q = U.getRangeAt(0), h = document.createElement("code");
q.surroundContents(h);
}
},
setBlockType: () => {
typeof window > "u" || !window.executeEditorCommand || (v === "blockquote" ? window.executeEditorCommand("toggleBlockquote") : v && window.executeEditorCommand("setBlockType", v));
typeof window > "u" || !window.executeEditorCommand || (p === "blockquote" ? window.executeEditorCommand("toggleBlockquote") : p && window.executeEditorCommand("setBlockType", p));
}
})[_]?.(), requestAnimationFrame(() => s(J(w || null))), a(!1), y.current = null;
})[_]?.(), requestAnimationFrame(() => s(J(v || null))), a(!1), y.current = null;
};
return !t || r ? /* @__PURE__ */ p("span", { ref: g, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ Y(ge, { children: [
/* @__PURE__ */ p("span", { ref: g, style: { display: "none" }, "aria-hidden": "true" }),
o && /* @__PURE__ */ Y(
return !t || r ? /* @__PURE__ */ w("span", { ref: g, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ Z(me, { children: [
/* @__PURE__ */ w("span", { ref: g, style: { display: "none" }, "aria-hidden": "true" }),
o && /* @__PURE__ */ Z(
"div",
{
ref: N,
ref: R,
className: "floating-toolbar",

@@ -1275,52 +1287,52 @@ onMouseDown: (_) => _.preventDefault(),

children: [
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: `floating-toolbar-btn ${U("toggleBold", c) ? "active" : ""}`,
"data-active": U("toggleBold", c) ? "true" : "false",
"aria-pressed": U("toggleBold", c) ? "true" : "false",
onClick: () => D("toggleBold"),
className: `floating-toolbar-btn ${j("toggleBold", c) ? "active" : ""}`,
"data-active": j("toggleBold", c) ? "true" : "false",
"aria-pressed": j("toggleBold", c) ? "true" : "false",
onClick: () => A("toggleBold"),
title: "Bold (Ctrl+B)",
children: /* @__PURE__ */ p("strong", { children: "B" })
children: /* @__PURE__ */ w("strong", { children: "B" })
}
),
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: `floating-toolbar-btn ${U("toggleItalic", c) ? "active" : ""}`,
"data-active": U("toggleItalic", c) ? "true" : "false",
"aria-pressed": U("toggleItalic", c) ? "true" : "false",
onClick: () => D("toggleItalic"),
className: `floating-toolbar-btn ${j("toggleItalic", c) ? "active" : ""}`,
"data-active": j("toggleItalic", c) ? "true" : "false",
"aria-pressed": j("toggleItalic", c) ? "true" : "false",
onClick: () => A("toggleItalic"),
title: "Italic (Ctrl+I)",
children: /* @__PURE__ */ p("em", { children: "I" })
children: /* @__PURE__ */ w("em", { children: "I" })
}
),
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: `floating-toolbar-btn ${U("toggleUnderline", c) ? "active" : ""}`,
"data-active": U("toggleUnderline", c) ? "true" : "false",
"aria-pressed": U("toggleUnderline", c) ? "true" : "false",
onClick: () => D("toggleUnderline"),
className: `floating-toolbar-btn ${j("toggleUnderline", c) ? "active" : ""}`,
"data-active": j("toggleUnderline", c) ? "true" : "false",
"aria-pressed": j("toggleUnderline", c) ? "true" : "false",
onClick: () => A("toggleUnderline"),
title: "Underline (Ctrl+U)",
children: /* @__PURE__ */ p("u", { children: "U" })
children: /* @__PURE__ */ w("u", { children: "U" })
}
),
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: `floating-toolbar-btn ${U("toggleStrikethrough", c) ? "active" : ""}`,
"data-active": U("toggleStrikethrough", c) ? "true" : "false",
"aria-pressed": U("toggleStrikethrough", c) ? "true" : "false",
onClick: () => D("toggleStrikethrough"),
className: `floating-toolbar-btn ${j("toggleStrikethrough", c) ? "active" : ""}`,
"data-active": j("toggleStrikethrough", c) ? "true" : "false",
"aria-pressed": j("toggleStrikethrough", c) ? "true" : "false",
onClick: () => A("toggleStrikethrough"),
title: "Strikethrough",
children: /* @__PURE__ */ p("s", { children: "S" })
children: /* @__PURE__ */ w("s", { children: "S" })
}
),
/* @__PURE__ */ p("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ p(
/* @__PURE__ */ w("div", { className: "floating-toolbar-separator" }),
/* @__PURE__ */ w(
"button",
{
className: "floating-toolbar-btn",
onClick: () => D("clearFormatting"),
onClick: () => A("clearFormatting"),
title: "Clear Formatting",

@@ -1330,9 +1342,9 @@ children: "⌫"

),
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: `floating-toolbar-btn ${U("openLinkDialog", c) ? "active" : ""}`,
"data-active": U("openLinkDialog", c) ? "true" : "false",
"aria-pressed": U("openLinkDialog", c) ? "true" : "false",
onClick: () => D("createLink"),
className: `floating-toolbar-btn ${j("openLinkDialog", c) ? "active" : ""}`,
"data-active": j("openLinkDialog", c) ? "true" : "false",
"aria-pressed": j("openLinkDialog", c) ? "true" : "false",
onClick: () => A("createLink"),
title: "Insert Link",

@@ -1342,7 +1354,7 @@ children: "🔗"

),
/* @__PURE__ */ p(
/* @__PURE__ */ w(
"button",
{
className: "floating-toolbar-btn",
onClick: () => D("toggleCode"),
onClick: () => A("toggleCode"),
title: "Code",

@@ -1352,8 +1364,8 @@ children: "Code"

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

@@ -1367,3 +1379,3 @@ children: "❝"

] });
}, qt = ({
}, jt = ({
plugins: e,

@@ -1373,10 +1385,10 @@ children: t

const n = e.filter((o) => o.context?.provider);
return n.length === 0 ? /* @__PURE__ */ p(ge, { children: t }) : n.reduce(
return n.length === 0 ? /* @__PURE__ */ w(me, { children: t }) : n.reduce(
(o, a) => {
const u = a.context.provider;
return /* @__PURE__ */ p(u, { children: o }, a.name);
return /* @__PURE__ */ w(u, { children: o }, a.name);
},
/* @__PURE__ */ p(ge, { children: t })
/* @__PURE__ */ w(me, { children: t })
);
}, We = /* @__PURE__ */ new Set(), ze = /* @__PURE__ */ new Set(), ke = (e) => !!e && typeof e == "object" && typeof e.name == "string", Xe = (e) => {
}, We = /* @__PURE__ */ new Set(), ze = /* @__PURE__ */ new Set(), Se = (e) => !!e && typeof e == "object" && typeof e.name == "string", Qe = (e) => {
const t = e?.pluginFactories;

@@ -1387,7 +1399,7 @@ return {

};
}, Kt = (e, t) => {
}, Vt = (e, t) => {
if (!Array.isArray(e)) return [];
const n = Xe(t), r = [], o = [];
const n = Qe(t), r = [], o = [];
if (e.forEach((a) => {
if (ke(a)) {
if (Se(a)) {
r.push(a);

@@ -1401,3 +1413,3 @@ return;

const d = u();
if (ke(d)) {
if (Se(d)) {
r.push(d);

@@ -1418,9 +1430,9 @@ return;

return r;
}, jt = (e, t, n) => {
}, Gt = (e, t, n) => {
if (!t?.checker || e.some((a) => a?.name === "a11yChecker")) return e;
const r = Xe(n).a11yChecker;
const r = Qe(n).a11yChecker;
if (typeof r == "function")
try {
const a = r();
if (ke(a))
if (Se(a))
return [...e, a];

@@ -1433,3 +1445,3 @@ } catch {

)), e;
}, Vt = {
}, Jt = {
readonly: !1,

@@ -1512,12 +1524,12 @@ placeholder: "",

};
function Qe(e, t) {
function Ye(e, t) {
const n = { ...e };
for (const r in t) {
const o = t[r], a = n[r];
o !== void 0 && (typeof o == "object" && o !== null && !Array.isArray(o) && typeof a == "object" && a !== null && !Array.isArray(a) ? n[r] = Qe(a, o) : n[r] = o);
o !== void 0 && (typeof o == "object" && o !== null && !Array.isArray(o) && typeof a == "object" && a !== null && !Array.isArray(a) ? n[r] = Ye(a, o) : n[r] = o);
}
return n;
}
function Gt(e) {
const t = Qe(Vt, {
function Xt(e) {
const t = Ye(Jt, {
readonly: e.readonly,

@@ -1562,4 +1574,4 @@ placeholder: e.placeholder,

onDestroy: e.onDestroy,
plugins: jt(
Kt(e.plugins, e.pluginConfig),
plugins: Gt(
Vt(e.plugins, e.pluginConfig),
e.accessibility,

@@ -1571,3 +1583,3 @@ e.pluginConfig

}
const Se = /* @__PURE__ */ new Map(), Jt = () => {
const Le = /* @__PURE__ */ new Map(), Qt = () => {
if (typeof window > "u")

@@ -1584,7 +1596,7 @@ return { editorElement: null, contentElement: null };

typeof window < "u" && (window.registerEditorCommand = (e, t) => {
Se.set(e, t);
Le.set(e, t);
}, window.executeEditorCommand = (e, t) => {
const n = Se.get(e);
const n = Le.get(e);
if (n) {
const r = Jt();
const r = Qt();
return n(t, r);

@@ -1594,4 +1606,4 @@ } else

});
const Xt = (e) => {
const t = me(() => Gt(e), [
const Yt = (e) => {
const t = he(() => Xt(e), [
e.id,

@@ -1619,36 +1631,36 @@ e.className,

e.mediaConfig
]), n = T(null), r = T(null), o = T(e.onInit), a = T(e.onDestroy), u = T(e.onChange), d = T(/* @__PURE__ */ new Set()), c = T(null), s = T(null), g = T(null);
O(() => {
]), n = S(null), r = S(null), o = S(e.onInit), a = S(e.onDestroy), u = S(e.onChange), d = S(/* @__PURE__ */ new Set()), c = S(null), s = S(null), g = S(null);
F(() => {
o.current = e.onInit, a.current = e.onDestroy, u.current = e.onChange;
});
const N = (v) => {
u.current?.(v), d.current.forEach((w) => {
const R = (p) => {
u.current?.(p), d.current.forEach((v) => {
try {
w(v);
} catch (C) {
console.error("Editora onChange subscriber failed:", C);
v(p);
} catch (k) {
console.error("Editora onChange subscriber failed:", k);
}
});
}, y = me(() => {
const v = new lt();
t.plugins.forEach((C) => {
v.register(C), C.commands && typeof window < "u" && Object.entries(C.commands).forEach(([B, I]) => {
Se.set(B, I);
}, y = he(() => {
const p = new ct();
t.plugins.forEach((k) => {
p.register(k), k.commands && typeof window < "u" && Object.entries(k.commands).forEach(([$, I]) => {
Le.set($, I);
});
});
const w = new st(v);
return n.current = w, w;
const v = new ut(p);
return n.current = v, v;
}, [t.plugins]);
O(() => {
const v = {
F(() => {
const p = {
getHTML: () => c.current?.querySelector(".rte-content")?.innerHTML || "",
setHTML: (w) => {
const C = c.current?.querySelector(".rte-content");
C && (C.innerHTML = w);
setHTML: (v) => {
const k = c.current?.querySelector(".rte-content");
k && (k.innerHTML = v);
},
execCommand: (w, C) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(w, C));
execCommand: (v, k) => {
typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(v, k));
},
registerCommand: (w, C) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(w, C);
registerCommand: (v, k) => {
typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(v, k);
},

@@ -1664,4 +1676,4 @@ focus: () => {

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

@@ -1676,42 +1688,42 @@ getState: () => ({

};
return r.current = v, o.current && o.current(v), () => {
return r.current = p, o.current && o.current(p), () => {
d.current.clear(), a.current && a.current();
};
}, []), O(() => {
}, []), F(() => {
if (t.statusbar.enabled && g.current && c.current) {
s.current || (s.current = new ct({
s.current || (s.current = new dt({
enabled: !0,
position: t.statusbar.position
}), s.current.create(g.current));
const v = c.current.querySelector(".rte-content");
if (v) {
const w = () => {
const p = c.current.querySelector(".rte-content");
if (p) {
const v = () => {
const f = document.activeElement;
return !!f && (f === v || v.contains(f));
}, C = () => {
const f = v.getBoundingClientRect();
return !!f && (f === p || p.contains(f));
}, k = () => {
const f = p.getBoundingClientRect();
return f.bottom >= 0 && f.top <= window.innerHeight;
}, B = () => {
}, $ = () => {
const f = window.getSelection();
if (!f || f.rangeCount === 0) return null;
const E = f.getRangeAt(0), A = E.commonAncestorContainer;
return v.contains(A) ? E : null;
const C = f.getRangeAt(0), T = C.commonAncestorContainer;
return p.contains(T) ? C : null;
}, I = (f = !1) => {
if (t.performance.viewportOnlyScan !== !1 && !C() && !w())
if (t.performance.viewportOnlyScan !== !1 && !k() && !v())
return;
const A = B(), G = !!A || w();
if (f && !G)
const T = $(), P = !!T || v();
if (f && !P)
return;
const k = v.textContent || "", { words: M, chars: R } = ut(k), S = dt(v);
let L, W;
A && (L = ft(v, A), A.collapsed || (W = gt(A, L), L = void 0)), s.current?.update({
const x = p.textContent || "", { words: M, chars: E } = ft(x), L = gt(p);
let D, W;
T && (D = mt(p, T), T.collapsed || (W = ht(T, D), D = void 0)), s.current?.update({
wordCount: M,
charCount: R,
lineCount: S,
cursorPosition: L,
charCount: E,
lineCount: L,
cursorPosition: D,
selectionInfo: W
});
}, z = () => I(), P = () => I(!0), m = () => I(), H = () => I();
return v.addEventListener("input", z), v.addEventListener("focus", m), v.addEventListener("blur", H), document.addEventListener("selectionchange", P), I(), () => {
v.removeEventListener("input", z), v.removeEventListener("focus", m), v.removeEventListener("blur", H), document.removeEventListener("selectionchange", P);
}, U = () => I(), q = () => I(!0), h = () => I(), N = () => I();
return p.addEventListener("input", U), p.addEventListener("focus", h), p.addEventListener("blur", N), document.addEventListener("selectionchange", q), I(), () => {
p.removeEventListener("input", U), p.removeEventListener("focus", h), p.removeEventListener("blur", N), document.removeEventListener("selectionchange", q);
};

@@ -1725,4 +1737,4 @@ }

}, [t.statusbar.enabled, t.statusbar.position, t.performance.viewportOnlyScan]);
const x = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", D = t.toolbar.sticky ?? !1, _ = t.toolbar.showMoreOptions ?? !0;
return /* @__PURE__ */ p(qt, { plugins: t.plugins, children: /* @__PURE__ */ Y(
const z = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", A = t.toolbar.sticky ?? !1, _ = t.toolbar.showMoreOptions ?? !0;
return /* @__PURE__ */ w(jt, { plugins: t.plugins, children: /* @__PURE__ */ Z(
"div",

@@ -1743,9 +1755,9 @@ {

children: [
l !== "bottom" && /* @__PURE__ */ p(
_e,
l !== "bottom" && /* @__PURE__ */ w(
Oe,
{
editor: y,
position: l,
sticky: D,
floating: x,
sticky: A,
floating: z,
readonly: t.readonly,

@@ -1756,4 +1768,4 @@ showMoreOptions: _,

),
/* @__PURE__ */ p(
Pt,
/* @__PURE__ */ w(
qt,
{

@@ -1765,3 +1777,3 @@ editor: y,

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

@@ -1777,9 +1789,9 @@ contentConfig: t.content,

),
l === "bottom" && /* @__PURE__ */ p(
_e,
l === "bottom" && /* @__PURE__ */ w(
Oe,
{
editor: y,
position: l,
sticky: D,
floating: x,
sticky: A,
floating: z,
readonly: t.readonly,

@@ -1790,7 +1802,7 @@ showMoreOptions: _,

),
/* @__PURE__ */ p(
Ut,
/* @__PURE__ */ w(
Kt,
{
editor: y,
isEnabled: x,
isEnabled: z,
viewportOnlyScan: t.performance.viewportOnlyScan,

@@ -1800,3 +1812,3 @@ readonly: t.readonly

),
t.statusbar.enabled && /* @__PURE__ */ p(
t.statusbar.enabled && /* @__PURE__ */ w(
"div",

@@ -1812,10 +1824,10 @@ {

) });
}, en = (e) => /* @__PURE__ */ p(Xt, { ...e });
function tn(e = {}) {
const t = T(null), n = T(e.onCommand);
return O(() => {
}, nn = (e) => /* @__PURE__ */ w(Yt, { ...e });
function rn(e = {}) {
const t = S(null), n = S(e.onCommand);
return F(() => {
n.current = e.onCommand;
}), O(() => {
}), F(() => {
if (typeof window > "u" || e.enabled === !1) return;
const r = new Ue(e);
const r = new qe(e);
t.current = r;

@@ -1838,9 +1850,9 @@ const o = (u) => r.handleKeyDown(u, (c, s) => {

export {
Pt as EditorContent,
en as EditoraEditor,
mt as InlineMenu,
en as RichTextEditor,
_e as Toolbar,
Gt as mergeConfig,
tn as useKeyboardShortcuts
qt as EditorContent,
nn as EditoraEditor,
bt as InlineMenu,
nn as RichTextEditor,
Oe as Toolbar,
Xt as mergeConfig,
rn as useKeyboardShortcuts
};
{
"name": "@editora/react",
"version": "1.0.16",
"version": "1.0.17",
"description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.",

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

"peerDependencies": {
"@editora/core": "^1.0.11",
"@editora/plugins": "^1.0.14",
"@editora/core": "^1.0.12",
"@editora/plugins": "^1.0.15",
"@editora/themes": "^1.0.12",

@@ -86,3 +86,3 @@ "react": ">=16.8 <21",

"devDependencies": {
"@editora/core": "^1.0.11",
"@editora/core": "^1.0.12",
"@types/react": "^18.2.0",

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