@editora/react
Advanced tools
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react/jsx-runtime"),u=require("react"),U=require("@editora/core"),Le=e=>e&&e.__esModule?e:{default:e},Me=Le(u),ve=({isOpen:e,options:t,onSelect:a,onClose:o,anchorRef:n,className:r=""})=>{const g=u.useRef(null),[m,l]=u.useState(null),h=()=>{if(!e||!n.current)return;const c=n.current.getBoundingClientRect(),y=g.current?.getBoundingClientRect(),k=y?.width||120,M=y?.height||t.length*36,i=8,D=4,H=window.innerWidth,v=window.innerHeight;let w=c.bottom+D,b=c.left;b+k>H-i&&(b=H-k-i),b<i&&(b=i),w+M>v-i&&(w=c.top-M-D),w<i&&(w=i),l({top:w,left:b})};return u.useLayoutEffect(()=>{if(!e){l(null);return}h();const c=window.requestAnimationFrame(h);return()=>{window.cancelAnimationFrame(c)}},[e,t.length,n]),u.useEffect(()=>{if(!e)return;const c=()=>{h()};return window.addEventListener("resize",c),window.addEventListener("scroll",c,!0),()=>{window.removeEventListener("resize",c),window.removeEventListener("scroll",c,!0)}},[e,t.length,n]),u.useEffect(()=>{const c=k=>{g.current&&!g.current.contains(k.target)&&n.current&&!n.current.contains(k.target)&&o()},y=k=>{k.key==="Escape"&&o()};return e&&(document.addEventListener("mousedown",c),document.addEventListener("keydown",y)),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",y)}},[e,o,n]),e?f.jsx("div",{ref:g,className:`rte-inline-menu ${r}`,style:{top:m?.top??-9999,left:m?.left??-9999,visibility:m?"visible":"hidden"},children:t.map(c=>f.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{a(c.value),o()},children:c.label},c.value))}):null},V=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),Ie={undo:"undo",redo:"redo",bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",textcolor:"openTextColorPicker",backgroundcolor:"openBackgroundColorPicker",fontsize:"setFontSize",increasefontsize:"increaseFontSize",decreasefontsize:"decreaseFontSize",heading:"setHeading",paragraph:"setHeading",textalignment:"setTextAlignment",direction:"setDirectionLTR",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",indent:"increaseIndent",outdent:"decreaseIndent",link:"openLinkDialog",image:"insertImage",video:"insertVideo",table:"insertTable",clearformatting:"clearFormatting"},Ne=(e,t)=>{if(!Array.isArray(t)||t.length===0)return e;if(!t.every(l=>typeof l=="string"))return t;const o=new Map,n=new Map;e.forEach(l=>{o.set(V(l.command||""),l),n.set(V(l.label||""),l)});const r=t.flatMap(l=>l.split(/\s+/)).map(l=>l.trim()).filter(Boolean),g=[];let m=0;return r.forEach(l=>{if(l==="|"){m+=1,g.push({type:"separator",command:`__separator__${m}`,label:"|"});return}const h=V(l),c=Ie[h],y=o.get(h)||(c?o.get(V(c)):void 0)||n.get(h)||e.find(k=>V(k.command||"").includes(h));y&&g.push(y)}),g.length>0?g:e},te=({editor:e,position:t="top",sticky:a=!1,floating:o=!1,readonly:n=!1,showMoreOptions:r=!0,itemsOverride:g})=>{const[m,l]=u.useState(null),[h,c]=u.useState(null),[y,k]=u.useState(null),[M,i]=u.useState(!1),D=u.useRef(null),H=u.useRef(null),v=u.useRef({}),w=u.useRef([]),b=u.useRef(null),A=u.useRef(null),F=u.useRef(null),p=u.useMemo(()=>Ne(e.pluginManager.getToolbarItems(),g),[e,g]),d=s=>{D.current=s,s&&!s.collapsed&&(H.current=s)},x=()=>b.current?.closest("[data-editora-editor]")?.querySelector(".rte-content")||null,B=()=>{if(typeof window>"u")return;const s=b.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=s||null},C=()=>{const s=x();if(!s)return null;const L=window.getSelection();if(!L||L.rangeCount===0)return null;const E=L.getRangeAt(0);return s.contains(E.commonAncestorContainer)?E.cloneRange():null},R=()=>{const s=C();s&&d(s)};u.useEffect(()=>{const s=()=>{R()};return document.addEventListener("selectionchange",s),()=>{document.removeEventListener("selectionchange",s)}},[]);const S=s=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(s),T=(s=!1)=>{const L=x();if(!L)return!1;const E=window.getSelection();if(!E)return!1;const $=E.rangeCount>0&&L.contains(E.getRangeAt(0).commonAncestorContainer),j=s?H.current||D.current:D.current||H.current;if(s&&j&&j.collapsed)return!1;if(j&&L.contains(j.commonAncestorContainer))try{return L.focus({preventScroll:!0}),E.removeAllRanges(),E.addRange(j),!0}catch{}return $};u.useEffect(()=>{if(!r){k(null),i(!1),w.current=[];return}let s=null;const L=()=>{if(!b.current||!A.current)return;const j=b.current.clientWidth,z=16,Q=40,le=4,Te=Math.max(0,j-z-Q-le);let ce=0,ue=0;const Y=A.current.children;for(let q=0;q<Y.length;q++){const Z=Y[q].getBoundingClientRect().width;Z>0&&(w.current[q]=Z);const fe=w.current[q]??Z,me=(fe>0?fe:40)+le;if(ce+me<=Te)ce+=me,ue++;else break}const de=Math.max(1,Math.min(ue,Y.length));k(q=>q===de?q:de)},E=()=>{s!==null&&cancelAnimationFrame(s),s=requestAnimationFrame(L)};w.current=[],E();const $=new ResizeObserver(()=>{E()});return b.current&&$.observe(b.current),A.current&&$.observe(A.current),()=>{s!==null&&cancelAnimationFrame(s),$.disconnect()}},[p.length,r]),u.useEffect(()=>{M&&y!==null&&y>=p.length&&i(!1)},[M,y,p.length]);const N=s=>(v.current[s]||(v.current[s]=Me.default.createRef()),v.current[s]),I=(s,L)=>{if(n)return;B(),s==="addComment"||s==="toggleComments"||T(S(s));const j={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[s];if(j){document.execCommand(j,!1),l(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(s,L),l(null)},O=s=>{n||(R(),l(m===s?null:s))},W=s=>{n||(R(),c(h===s?null:s),l(null))},_=(s,L)=>{n||(T(),I(s,L),d(null),H.current=null,c(null))},P=(s,L)=>s&&s.startsWith("<svg")&&s.endsWith("</svg>")?f.jsx("span",{dangerouslySetInnerHTML:{__html:s}}):s&&s.length===1&&/^[BIUSH]$/.test(s)?f.jsx("span",{style:{fontWeight:"bold",fontSize:"14px",lineHeight:"1"},children:s}):s||"⚪",G={...a&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},se=r&&y!==null&&y<p.length,Re=s=>{n||!s.target.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")||(B(),R(),s.preventDefault())},J=(s,L=!0)=>s.map((E,$)=>{const j=E.command||"";return f.jsx("div",{className:"rte-toolbar-item",style:{display:L&&r&&y!==null&&$>=y?"none":"flex"},children:E.type==="separator"?f.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):E.type==="dropdown"?f.jsxs("div",{className:"rte-toolbar-dropdown",children:[f.jsxs("button",{className:"rte-toolbar-button","data-command":j,"data-active":"false",onMouseDown:z=>{z.preventDefault(),R()},onClick:()=>O(j),disabled:n,children:[E.label," ▼"]}),m===j&&f.jsx("div",{className:"rte-toolbar-dropdown-menu",children:E.options?.map(z=>f.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:Q=>Q.preventDefault(),onClick:()=>I(j,z.value),children:z.label},z.value))})]}):E.type==="inline-menu"?f.jsx("button",{ref:N(j),className:"rte-toolbar-button","data-command":j,"data-active":"false",onMouseDown:z=>{z.preventDefault(),R()},onClick:()=>W(j),disabled:n,title:E.label,children:P(E.icon)}):E.type==="input"?f.jsx("input",{type:"text",className:`rte-toolbar-input ${E.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:E.placeholder,onChange:z=>I(j,z.target.value),disabled:n,onKeyDown:z=>{z.key==="Enter"&&I(j,z.target.value)},title:E.label}):E.type==="group"?f.jsx("div",{className:`rte-toolbar-group-button ${E.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${E.label}`,children:f.jsx("div",{className:`rte-toolbar-group-items ${E.label.toLowerCase().replace(/\s+/g,"-")}`,children:J(E.items||[],!1)})}):f.jsx("button",{className:"rte-toolbar-button","data-command":j,"data-active":"false",onMouseDown:z=>{z.preventDefault(),R()},onClick:()=>I(j),disabled:n,title:E.label,children:P(E.icon)})},$)}),Ae=r&&y!==null?p.filter((s,L)=>L>=y):[];return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"rte-toolbar-wrapper",style:G,onMouseDownCapture:Re,children:[f.jsxs("div",{className:"rte-toolbar",ref:b,children:[f.jsx("div",{className:"rte-toolbar-items-container",ref:A,style:r?void 0:{flexWrap:"wrap"},children:J(p)}),se&&f.jsx("button",{ref:F,className:`rte-toolbar-more-button ${M?"active":""}`,onMouseDown:s=>{s.preventDefault(),R()},onClick:()=>i(!M),disabled:n,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),se&&f.jsx("div",{className:`rte-toolbar-expanded-row ${M?"show":""}`,children:J(Ae,!1)})]}),p.map(s=>{if(s.type==="inline-menu"){const L=s.command||"";return f.jsx(ve,{isOpen:h===L,options:s.options||[],onSelect:E=>_(L,E),onClose:()=>c(null),anchorRef:N(L)},`menu-${L||"unknown"}`)}return null})]})};function je(e,t){const a=u.useRef(),o=u.useRef("");return u.useEffect(()=>{if(!t?.enabled)return;const r=t.intervalMs||3e4,g=t.storageKey||"rte-autosave",m=t.provider||"localStorage",l=async()=>{const h=e();if(h!==o.current){if(o.current=h,m==="localStorage")try{localStorage.setItem(g,h),localStorage.setItem(`${g}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(c){console.error("[Autosave] Failed to save to localStorage:",c)}else if(m==="api"&&t.apiUrl)try{await fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:h,timestamp:Date.now()})}),console.log("[Autosave] Content saved to API")}catch(c){console.error("[Autosave] Failed to save to API:",c)}}};return a.current=setInterval(l,r),()=>{a.current&&clearInterval(a.current)}},[t?.enabled,t?.intervalMs,t?.storageKey,t?.provider,t?.apiUrl,e]),{restore:()=>{if(!t?.enabled)return null;const r=t.storageKey||"rte-autosave";if((t.provider||"localStorage")==="localStorage")try{const m=localStorage.getItem(r),l=localStorage.getItem(`${r}-timestamp`);if(m&&l)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(l))),m}catch(m){console.error("[Autosave] Failed to restore from localStorage:",m)}return null}}}const He=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","sup","sub","hr"],De={"*":["class","style","id","data-*"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function pe(e,t,a){if(t?.sanitize===!1)return e;const o=t?.allowedTags&&t.allowedTags.length>0?t.allowedTags:He,r=!!t?.allowedAttributes&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:De,g=document.createElement("div");return g.innerHTML=e,Ee(g,o,r),g.innerHTML}function Ee(e,t,a){const o=Array.from(e.childNodes);for(const n of o)if(n.nodeType===Node.ELEMENT_NODE){const r=n,g=r.tagName.toLowerCase();if(!t.includes(g)){for(;r.firstChild;)e.insertBefore(r.firstChild,r);e.removeChild(r);continue}Fe(r,a),Ee(r,t,a)}else{if(n.nodeType===Node.TEXT_NODE)continue;e.removeChild(n)}}function Fe(e,t){const a=e.tagName.toLowerCase(),o=Array.from(e.attributes),n=t[a]||[],r=t["*"]||[],g=[...n,...r];for(const m of o){const l=m.name.toLowerCase();let h=!1;g.includes(l)&&(h=!0);for(const c of g)if(c.endsWith("*")){const y=c.slice(0,-1);if(l.startsWith(y)){h=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&m.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&m.value.trim().toLowerCase().startsWith("javascript:"))&&(h=!1),h||e.removeAttribute(m.name)}e.hasAttribute("href")&&(e.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("href"),e.hasAttribute("src")&&(e.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("src")}function Be(e,t,a){return a?.sanitizeOnPaste===!1?e:pe(e,t)}function ge(e,t,a){return a?.sanitizeOnInput===!1?e:pe(e,t)}const X=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),K=(e,t)=>{const o=!!t&&X(e);e.classList.toggle("rte-content-empty",o)},oe="data-rte-caret-marker",ae="data-rte-range-start-marker",ie="data-rte-range-end-marker",ee=()=>Math.random().toString(36).slice(2),ze=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;try{const o=a.cloneRange();o.selectNodeContents(e),o.setEnd(a.startContainer,a.startOffset);const n=a.cloneRange();return n.selectNodeContents(e),n.setEnd(a.endContainer,a.endOffset),{start:o.toString().length,end:n.toString().length}}catch{return null}},he=(e,t)=>{const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let o=a.nextNode(),n=Math.max(0,t),r=null;for(;o;){r=o;const g=o.textContent?.length??0;if(n<=g)return{node:o,offset:n};n-=g,o=a.nextNode()}return r?{node:r,offset:r.textContent?.length??0}:{node:e,offset:e.childNodes.length}},_e=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;const o=ze(e);try{if(a.collapsed){const c=ee(),y=document.createElement("span");return y.setAttribute(oe,c),y.appendChild(document.createTextNode("")),a.cloneRange().insertNode(y),{collapsed:!0,caretId:c,fallbackOffsets:o}}const n=ee(),r=ee(),g=document.createElement("span");g.setAttribute(ie,r),g.appendChild(document.createTextNode(""));const m=document.createElement("span");m.setAttribute(ae,n),m.appendChild(document.createTextNode(""));const l=a.cloneRange();l.collapse(!1),l.insertNode(g);const h=a.cloneRange();return h.collapse(!0),h.insertNode(m),{collapsed:!1,startId:n,endId:r,fallbackOffsets:o}}catch{return{collapsed:a.collapsed,fallbackOffsets:o}}},We=e=>{e.querySelectorAll(`[${oe}], [${ae}], [${ie}]`).forEach(t=>t.remove())},Oe=(e,t)=>{if(!t)return!1;const a=window.getSelection();if(!a)return!1;try{const o=document.createRange();if(t.collapsed&&t.caretId){const n=e.querySelector(`[${oe}="${t.caretId}"]`);return!n||!n.parentNode?!1:(o.setStartAfter(n),o.collapse(!0),a.removeAllRanges(),a.addRange(o),!0)}if(!t.collapsed&&t.startId&&t.endId){const n=e.querySelector(`[${ae}="${t.startId}"]`),r=e.querySelector(`[${ie}="${t.endId}"]`);return!n||!r||!n.parentNode||!r.parentNode?!1:(o.setStartAfter(n),o.setEndBefore(r),a.removeAllRanges(),a.addRange(o),!0)}}catch{return!1}return!1},Pe=(e,t)=>{if(!t)return;const a=window.getSelection();if(a)try{const o=he(e,t.start),n=he(e,t.end),r=document.createRange();r.setStart(o.node,o.offset),r.setEnd(n.node,n.offset),a.removeAllRanges(),a.addRange(r)}catch{}},ye=({editor:e,defaultValue:t,value:a,readonly:o=!1,placeholder:n,onChange:r,pasteConfig:g,contentConfig:m,securityConfig:l,performanceConfig:h,accessibilityConfig:c,autosaveConfig:y,contextMenuConfig:k,spellcheckConfig:M})=>{const i=u.useRef(null),D=a!==void 0,H=u.useRef(),v=m?.autoHeight===!0,w=typeof m?.minHeight=="number"?m.minHeight:200,b=typeof m?.maxHeight=="number"?m.maxHeight:0,A=d=>{if(!d||!v)return;d.style.height="auto";const x=Math.max(w,d.scrollHeight);if(b>0){d.style.height=`${Math.min(x,b)}px`;return}d.style.height=`${x}px`},{restore:F}=je(()=>i.current?.innerHTML||"",y);u.useEffect(()=>{if(!i.current)return;const d=F(),x=d??a??t??"";x.trim()?i.current.innerHTML!==x&&(i.current.innerHTML=x):n?i.current.innerHTML="":i.current.innerHTML.trim()||(i.current.innerHTML="<p><br></p>"),K(i.current,n),A(i.current),d&&r&&r(d)},[]),u.useEffect(()=>{!i.current||!D||(a!==i.current.innerHTML&&(i.current.innerHTML=a),K(i.current,n),A(i.current))},[a,D]),u.useEffect(()=>{if(!i.current)return;const d=i.current;if(n){d.setAttribute("data-placeholder",n),X(d)&&(d.innerHTML=""),K(d,n),A(d);return}d.removeAttribute("data-placeholder"),K(d,n),A(d)},[n]),u.useEffect(()=>{if(!i.current)return;const d=i.current;if(c?.enableARIA!==!1){d.setAttribute("role","textbox"),d.setAttribute("aria-multiline","true"),d.setAttribute("aria-disabled",o?"true":"false");const B=n?.trim();B?d.setAttribute("aria-label",B):d.removeAttribute("aria-label")}else d.removeAttribute("role"),d.removeAttribute("aria-multiline"),d.removeAttribute("aria-label"),d.removeAttribute("aria-disabled")},[c?.enableARIA,n,o]),u.useEffect(()=>{A(i.current)},[v,w,b,a]),u.useEffect(()=>{if(!i.current)return;const d=()=>{if(!i.current||o)return;n&&X(i.current)&&(i.current.innerHTML="");let T=i.current.innerHTML;if(l?.sanitizeOnInput!==!1&&m?.sanitize!==!1){const N=ge(T,m,l);if(N!==i.current.innerHTML){const I=_e(i.current),O=i.current.innerHTML,W=ge(O,m,l);i.current.innerHTML=W,Oe(i.current,I)||Pe(i.current,I?.fallbackOffsets||null),We(i.current),T=i.current.innerHTML}else T=N}K(i.current,n),A(i.current),r&&(h?.debounceInputMs?(H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{r(T)},h.debounceInputMs)):r(T))},x=T=>{if(o){T.preventDefault();return}T.preventDefault();let N=T.clipboardData?.getData("text/html");const I=T.clipboardData?.getData("text/plain"),O=!!N&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(N);if(g?.clean||!g?.keepFormatting){I&&document.execCommand("insertText",!1,I);return}if(g?.convertWord===!1&&O){I&&document.execCommand("insertText",!1,I);return}if(N){l?.sanitizeOnPaste!==!1&&m?.sanitize!==!1&&(N=Be(N,m,l));const W=window.getSelection();if(W&&W.rangeCount>0){const _=W.getRangeAt(0);_.deleteContents();const P=document.createElement("div");P.innerHTML=N;const G=document.createDocumentFragment();for(;P.firstChild;)G.appendChild(P.firstChild);_.insertNode(G),_.collapse(!1),W.removeAllRanges(),W.addRange(_)}}else I&&document.execCommand("insertText",!1,I)},B=T=>{const N=T.target;(N.tagName==="IMG"||N.tagName==="VIDEO")&&(N.style.resize="both",N.style.overflow="auto",N.style.display="inline-block")},C=T=>{k?.enabled===!1&&T.preventDefault()},R=()=>{i.current&&(n&&X(i.current)&&(i.current.innerHTML=""),K(i.current,n),A(i.current))},S=i.current;return S.addEventListener("input",d),S.addEventListener("paste",x),S.addEventListener("click",B),S.addEventListener("contextmenu",C),S.addEventListener("focus",R),S.addEventListener("blur",R),o||S.focus(),()=>{H.current&&clearTimeout(H.current),S.removeEventListener("input",d),S.removeEventListener("paste",x),S.removeEventListener("click",B),S.removeEventListener("contextmenu",C),S.removeEventListener("focus",R),S.removeEventListener("blur",R)}},[e,r,g,m,l,h,n,k,o]);const p=(M?.enabled??!1)&&(M?.provider??"browser")==="browser";return u.useEffect(()=>{if(!i.current||typeof window>"u"||o||c?.keyboardNavigation===!1)return;const d=new U.KeyboardShortcutManager,x=i.current,B=C=>{d.handleKeyDown(C,(R,S)=>{if(typeof window<"u"&&window.executeEditorCommand){const T=i.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=T||null,window.executeEditorCommand(R,S)}})};return x.addEventListener("keydown",B),()=>{x.removeEventListener("keydown",B)}},[c?.keyboardNavigation,o]),f.jsx("div",{ref:i,contentEditable:!o,suppressContentEditableWarning:!0,spellCheck:o?!1:p,tabIndex:c?.keyboardNavigation===!1?-1:0,"aria-keyshortcuts":c?.keyboardNavigation===!1?void 0:"Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y","data-viewport-only-scan":h?.viewportOnlyScan?"true":"false","data-a11y-checker":c?.checker?"true":"false","data-readonly":o?"true":"false",className:`rte-content ${o?"rte-content-readonly":""}`,style:{minHeight:`${w}px`,maxHeight:v?b>0?`${b}px`:"none":"100%",padding:"16px",outline:"none",border:"1px solid #ddd",borderRadius:"0px 0px 4px 4px",fontSize:"14px",lineHeight:"1.5",overflow:v?b>0?"auto":"hidden":"auto",flex:v?void 0:1,boxSizing:"border-box",wordWrap:"break-word",overflowWrap:"break-word"}})},$e=({editor:e,isEnabled:t,viewportOnlyScan:a=!0,readonly:o=!1})=>{const[n,r]=u.useState(!1),[g,m]=u.useState({top:0,left:0}),l=u.useRef(null),h=u.useRef(null),c=u.useRef(null),y=u.useRef(null),k=u.useRef(null);u.useEffect(()=>{if(!t||o){r(!1);return}k.current=l.current?.closest("[data-editora-editor]");const i=p=>{if(k.current)return k.current;const d=l.current?.closest("[data-editora-editor]");if(d)return k.current=d,d;const x=p?.commonAncestorContainer,C=(x?x.nodeType===Node.ELEMENT_NODE?x:x.parentElement:null)?.closest("[data-editora-editor]");return C?(k.current=C,C):null},D=p=>p&&p.querySelector(".rte-content, .editora-content")||null,H=p=>{if(!p.anchorNode||!p.focusNode)return!1;try{const d=document.createRange();return d.setStart(p.anchorNode,p.anchorOffset),d.setEnd(p.focusNode,p.focusOffset),d.collapsed}catch{return!1}},v=(p,d)=>{const x=Array.from(d.getClientRects()).filter(C=>C.width>0||C.height>0);return x.length===0?d.getBoundingClientRect():H(p)?x[0]:x[x.length-1]},w=()=>{y.current&&clearTimeout(y.current);const p=window.getSelection();if(!p||p.rangeCount===0){r(!1),c.current=null;return}const d=p.getRangeAt(0);if(d.collapsed){r(!1),c.current=null;return}const x=p.toString().trim(),B=i(d),C=D(B);if(!C||!C.contains(d.commonAncestorContainer)){r(!1),c.current=null;return}if(a){const R=C.getBoundingClientRect(),S=R.bottom>=0&&R.top<=window.innerHeight,T=document.activeElement===C||C.contains(document.activeElement);if(!S&&!T){r(!1),c.current=null;return}}if(x.length>0){const R=v(p,d),S=C.getBoundingClientRect(),T=300;if(R&&S){const N=Math.max(8,R.top-50);let I=R.left+R.width/2;const O=T/2,W=S.left,_=S.right;I-O<W&&(I=W+O+10),I+O>_&&(I=_-O-10),m({top:N,left:I}),r(!0),c.current=d.cloneRange()}}else r(!1),c.current=null},b=p=>{if(h.current&&!h.current.contains(p.target)){const d=i();window.getSelection(),D(d)?.contains(p.target)||(r(!1),c.current=null)}},A=p=>{p.key==="Escape"&&(r(!1),c.current=null)},F=D(i());return document.addEventListener("selectionchange",w),document.addEventListener("mousedown",b),document.addEventListener("keydown",A),F?.addEventListener("mouseup",w),F?.addEventListener("keyup",w),()=>{document.removeEventListener("selectionchange",w),document.removeEventListener("mousedown",b),document.removeEventListener("keydown",A),F?.removeEventListener("mouseup",w),F?.removeEventListener("keyup",w),y.current&&clearTimeout(y.current)}},[t,a,o]);const M=(i,D)=>{if(o||!c.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=k.current||null);const H=k.current?.querySelector(".rte-content");H&&H.focus();const v=window.getSelection();if(v&&c.current)try{v.removeAllRanges(),v.addRange(c.current)}catch{}({toggleBold:()=>document.execCommand("bold",!1),toggleItalic:()=>document.execCommand("italic",!1),toggleUnderline:()=>document.execCommand("underline",!1),toggleStrikethrough:()=>document.execCommand("strikeThrough",!1),createLink:()=>{typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand("openLinkDialog")},clearFormatting:()=>{document.execCommand("removeFormat",!1),document.execCommand("unlink",!1)},toggleCode:()=>{const b=window.getSelection();if(b&&b.rangeCount>0){const A=b.getRangeAt(0),F=document.createElement("code");A.surroundContents(F)}},setBlockType:()=>{if(D==="blockquote"){const b=window.getSelection();if(b&&b.rangeCount>0){const A=b.getRangeAt(0);(A.commonAncestorContainer.nodeType===Node.TEXT_NODE?A.commonAncestorContainer.parentElement:A.commonAncestorContainer)?.closest?.("blockquote")?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else D&&document.execCommand("formatBlock",!1,D)}})[i]?.(),r(!1),c.current=null};return!t||o?f.jsx("span",{ref:l,style:{display:"none"},"aria-hidden":"true"}):f.jsxs(f.Fragment,{children:[f.jsx("span",{ref:l,style:{display:"none"},"aria-hidden":"true"}),n&&f.jsxs("div",{ref:h,className:"floating-toolbar",onMouseDown:i=>i.preventDefault(),style:{position:"fixed",top:`${g.top}px`,left:`${g.left}px`,transform:"translateX(-50%)",zIndex:1e4,display:"flex"},children:[f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleBold"),title:"Bold (Ctrl+B)",children:f.jsx("strong",{children:"B"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleItalic"),title:"Italic (Ctrl+I)",children:f.jsx("em",{children:"I"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleUnderline"),title:"Underline (Ctrl+U)",children:f.jsx("u",{children:"U"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleStrikethrough"),title:"Strikethrough",children:f.jsx("s",{children:"S"})}),f.jsx("div",{className:"floating-toolbar-separator"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("clearFormatting"),title:"Clear Formatting",children:"⌫"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("createLink"),title:"Insert Link",children:"🔗"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("toggleCode"),title:"Code",children:"Code"}),f.jsx("div",{className:"floating-toolbar-separator"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>M("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},Ue=({plugins:e,children:t})=>{const a=e.filter(n=>n.context?.provider);return a.length===0?f.jsx(f.Fragment,{children:t}):a.reduce((n,r)=>{const g=r.context.provider;return f.jsx(g,{children:n},r.name)},f.jsx(f.Fragment,{children:t}))},be=new Set,we=new Set,ne=e=>!!e&&typeof e=="object"&&typeof e.name=="string",Ce=e=>{const t=e?.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},qe=(e,t)=>{if(!Array.isArray(e))return[];const a=Ce(t),o=[],n=[];if(e.forEach(r=>{if(ne(r)){o.push(r);return}if(typeof r!="string")return;const g=a[r];if(typeof g=="function")try{const m=g();if(ne(m)){o.push(m);return}}catch{}n.push(r)}),n.length>0){const r=n.slice().sort().join("|");be.has(r)||(be.add(r),console.warn(`[Editora React] Unresolved string plugin names: ${n.join(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return o},Ke=(e,t,a)=>{if(!t?.checker||e.some(r=>r?.name==="a11yChecker"))return e;const o=Ce(a).a11yChecker;if(typeof o=="function")try{const r=o();if(ne(r))return[...e,r]}catch{}const n="accessibility.checker";return we.has(n)||(we.add(n),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},Ve={readonly:!1,placeholder:"",toolbar:{items:[],floating:!1,sticky:!1,showMoreOptions:!0},statusbar:{enabled:!1,position:"bottom"},menubar:{enabled:!1,items:[]},contextMenu:{enabled:!0},media:{uploadUrl:"",libraryUrl:"",maxFileSize:10*1024*1024,allowedTypes:["image/jpeg","image/png","image/gif","image/webp"],headers:{},withCredentials:!1},paste:{clean:!0,keepFormatting:!1,convertWord:!0},history:{maxSteps:100,debounceMs:300},language:{locale:"en",direction:"ltr"},spellcheck:{enabled:!1,provider:"browser",apiUrl:"",apiHeaders:{}},autosave:{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""},accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},content:{allowedTags:[],allowedAttributes:{},sanitize:!0,autoHeight:!1,minHeight:200,maxHeight:0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0}};function xe(e,t){const a={...e};for(const o in t){const n=t[o],r=a[o];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?a[o]=xe(r,n):a[o]=n)}return a}function Se(e){const t=xe(Ve,{readonly:e.readonly,placeholder:e.placeholder,toolbar:e.toolbar,statusbar:e.statusbar,menubar:e.menubar,contextMenu:e.contextMenu,media:e.media,paste:e.paste,history:e.history,language:e.language,spellcheck:e.spellcheck,autosave:e.autosave,accessibility:e.accessibility,performance:e.performance,content:e.content,security:e.security});if(e.floatingToolbar!==void 0){const o=typeof e.floatingToolbar=="boolean"?e.floatingToolbar:e.floatingToolbar.enabled;t.toolbar={...t.toolbar,floating:o??t.toolbar.floating}}return e.mediaConfig&&(t.media={...t.media,uploadUrl:e.mediaConfig.uploadUrl||t.media.uploadUrl,libraryUrl:e.mediaConfig.libraryUrl||t.media.libraryUrl,maxFileSize:e.mediaConfig.maxFileSize||t.media.maxFileSize,allowedTypes:e.mediaConfig.allowedTypes||t.media.allowedTypes}),{...t,id:e.id,className:e.className,value:e.value,defaultValue:e.defaultValue,onChange:e.onChange,onInit:e.onInit,onDestroy:e.onDestroy,plugins:Ke(qe(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const re=new Map;typeof window<"u"&&(window.registerEditorCommand=(e,t)=>{re.set(e,t)},window.executeEditorCommand=(e,t)=>{const a=re.get(e);return a?a(t):(console.warn(`No handler registered for command: ${e}`),!1)});const Ge=e=>{const t=u.useMemo(()=>Se(e),[e.id,e.className,e.value,e.defaultValue,e.readonly,e.placeholder,e.plugins,e.toolbar,e.menubar,e.contextMenu,e.media,e.paste,e.history,e.language,e.spellcheck,e.autosave,e.accessibility,e.performance,e.content,e.security,e.floatingToolbar,e.mediaConfig]),a=u.useRef(null),o=u.useRef(null),n=u.useRef(e.onInit),r=u.useRef(e.onDestroy),g=u.useRef(e.onChange),m=u.useRef(new Set),l=u.useRef(null),h=u.useRef(null),c=u.useRef(null);u.useEffect(()=>{n.current=e.onInit,r.current=e.onDestroy,g.current=e.onChange});const y=v=>{g.current?.(v),m.current.forEach(w=>{try{w(v)}catch(b){console.error("Editora onChange subscriber failed:",b)}})},k=u.useMemo(()=>{const v=new U.PluginManager;t.plugins.forEach(b=>{v.register(b),b.commands&&typeof window<"u"&&Object.entries(b.commands).forEach(([A,F])=>{re.set(A,F)})});const w=new U.Editor(v);return a.current=w,w},[t.plugins]);u.useEffect(()=>{const v={getHTML:()=>l.current?.querySelector(".rte-content")?.innerHTML||"",setHTML:w=>{const b=l.current?.querySelector(".rte-content");b&&(b.innerHTML=w)},execCommand:(w,b)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=l.current||null,window.executeEditorCommand(w,b))},registerCommand:(w,b)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(w,b)},focus:()=>{l.current?.querySelector(".rte-content")?.focus()},blur:()=>{l.current?.querySelector(".rte-content")?.blur()},destroy:()=>{r.current&&r.current()},onChange:w=>(m.current.add(w),()=>{m.current.delete(w)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:k.toolbar?.items||[]}};return o.current=v,n.current&&n.current(v),()=>{m.current.clear(),r.current&&r.current()}},[]),u.useEffect(()=>{if(t.statusbar.enabled&&c.current&&l.current){h.current||(h.current=new U.StatusBar({enabled:!0,position:t.statusbar.position}),h.current.create(c.current));const v=l.current.querySelector(".rte-content");if(v){const w=()=>{const C=document.activeElement;return!!C&&(C===v||v.contains(C))},b=()=>{const C=v.getBoundingClientRect();return C.bottom>=0&&C.top<=window.innerHeight},A=()=>{const C=window.getSelection();if(!C||C.rangeCount===0)return null;const R=C.getRangeAt(0),S=R.commonAncestorContainer;return v.contains(S)?R:null},F=(C=!1)=>{if(t.performance.viewportOnlyScan!==!1&&!b()&&!w())return;const S=A(),T=!!S||w();if(C&&!T)return;const N=v.textContent||"",{words:I,chars:O}=U.calculateTextStats(N),W=U.countLines(v);let _,P;S&&(_=U.getCursorPosition(v,S),S.collapsed||(P=U.getSelectionInfo(S,_),_=void 0)),h.current?.update({wordCount:I,charCount:O,lineCount:W,cursorPosition:_,selectionInfo:P})},p=()=>F(),d=()=>F(!0),x=()=>F(),B=()=>F();return v.addEventListener("input",p),v.addEventListener("focus",x),v.addEventListener("blur",B),document.addEventListener("selectionchange",d),F(),()=>{v.removeEventListener("input",p),v.removeEventListener("focus",x),v.removeEventListener("blur",B),document.removeEventListener("selectionchange",d)}}}else h.current&&(h.current.destroy(),h.current=null);return()=>{h.current&&(h.current.destroy(),h.current=null)}},[t.statusbar.enabled,t.statusbar.position,t.performance.viewportOnlyScan]);const M=t.toolbar.floating??!1,i=t.toolbar.position||"top",D=t.toolbar.sticky??!1,H=t.toolbar.showMoreOptions??!0;return f.jsx(Ue,{plugins:t.plugins,children:f.jsxs("div",{ref:l,id:t.id,"data-editora-editor":!0,"data-readonly":t.readonly?"true":"false",className:`rte-editor ${t.className||""}`,lang:t.language.locale,dir:t.language.direction,style:{display:"flex",flexDirection:"column",height:"100%"},children:[i!=="bottom"&&f.jsx(te,{editor:k,position:i,sticky:D,floating:M,readonly:t.readonly,showMoreOptions:H,itemsOverride:t.toolbar.items}),f.jsx(ye,{editor:k,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:y,pasteConfig:t.paste,contentConfig:t.content,securityConfig:t.security,performanceConfig:t.performance,accessibilityConfig:t.accessibility,autosaveConfig:t.autosave,contextMenuConfig:t.contextMenu,spellcheckConfig:t.spellcheck}),i==="bottom"&&f.jsx(te,{editor:k,position:i,sticky:D,floating:M,readonly:t.readonly,showMoreOptions:H,itemsOverride:t.toolbar.items}),f.jsx($e,{editor:k,isEnabled:M,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&f.jsx("div",{ref:c,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},ke=e=>f.jsx(Ge,{...e});function Xe(e={}){const t=u.useRef(null),a=u.useRef(e.onCommand);return u.useEffect(()=>{a.current=e.onCommand}),u.useEffect(()=>{if(typeof window>"u"||e.enabled===!1)return;const o=new U.KeyboardShortcutManager(e);t.current=o;const n=g=>o.handleKeyDown(g,(l,h)=>{a.current&&a.current(l,h),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(l,h)}),r=e.editorElement||document;return r&&r.addEventListener("keydown",n),()=>{r&&r.removeEventListener("keydown",n)}},[e.editorElement,e.enabled,e.shortcuts,e.customShortcuts]),{getShortcuts:()=>t.current?.getAllShortcuts()||[],getShortcutForCommand:o=>t.current?.getShortcutForCommand(o),getShortcutsHelp:()=>t.current?.getShortcutsHelp()||"",enable:()=>t.current?.enable(),disable:()=>t.current?.disable(),isEnabled:()=>t.current?.isEnabled()||!1}}exports.EditorContent=ye;exports.EditoraEditor=ke;exports.InlineMenu=ve;exports.RichTextEditor=ke;exports.Toolbar=te;exports.mergeConfig=Se;exports.useKeyboardShortcuts=Xe; | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("react/jsx-runtime"),c=require("react"),$=require("@editora/core"),Me=e=>e&&e.__esModule?e:{default:e},Ie=Me(c),ve=({isOpen:e,options:t,onSelect:a,onClose:o,anchorRef:n,className:r=""})=>{const g=c.useRef(null),[m,l]=c.useState(null),h=()=>{if(!e||!n.current)return;const u=n.current.getBoundingClientRect(),C=g.current?.getBoundingClientRect(),R=C?.width||120,L=C?.height||t.length*36,s=8,j=4,N=window.innerWidth,v=window.innerHeight;let w=u.bottom+j,b=u.left;b+R>N-s&&(b=N-R-s),b<s&&(b=s),w+L>v-s&&(w=u.top-L-j),w<s&&(w=s),l({top:w,left:b})};return c.useLayoutEffect(()=>{if(!e){l(null);return}h();const u=window.requestAnimationFrame(h);return()=>{window.cancelAnimationFrame(u)}},[e,t.length,n]),c.useEffect(()=>{if(!e)return;const u=()=>{h()};return window.addEventListener("resize",u),window.addEventListener("scroll",u,!0),()=>{window.removeEventListener("resize",u),window.removeEventListener("scroll",u,!0)}},[e,t.length,n]),c.useEffect(()=>{const u=R=>{g.current&&!g.current.contains(R.target)&&n.current&&!n.current.contains(R.target)&&o()},C=R=>{R.key==="Escape"&&o()};return e&&(document.addEventListener("mousedown",u),document.addEventListener("keydown",C)),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",C)}},[e,o,n]),e?f.jsx("div",{ref:g,className:`rte-inline-menu ${r}`,style:{top:m?.top??-9999,left:m?.left??-9999,visibility:m?"visible":"hidden"},children:t.map(u=>f.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{a(u.value),o()},children:u.label},u.value))}):null},G=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),Ne={undo:"undo",redo:"redo",bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",textcolor:"openTextColorPicker",backgroundcolor:"openBackgroundColorPicker",fontsize:"setFontSize",increasefontsize:"increaseFontSize",decreasefontsize:"decreaseFontSize",heading:"setHeading",paragraph:"setHeading",textalignment:"setTextAlignment",direction:"setDirectionLTR",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",indent:"increaseIndent",outdent:"decreaseIndent",link:"openLinkDialog",image:"insertImage",video:"insertVideo",table:"insertTable",clearformatting:"clearFormatting"},je=(e,t)=>{if(!Array.isArray(t)||t.length===0)return e;if(!t.every(l=>typeof l=="string"))return t;const o=new Map,n=new Map;e.forEach(l=>{o.set(G(l.command||""),l),n.set(G(l.label||""),l)});const r=t.flatMap(l=>l.split(/\s+/)).map(l=>l.trim()).filter(Boolean),g=[];let m=0;return r.forEach(l=>{if(l==="|"){m+=1,g.push({type:"separator",command:`__separator__${m}`,label:"|"});return}const h=G(l),u=Ne[h],C=o.get(h)||(u?o.get(G(u)):void 0)||n.get(h)||e.find(R=>G(R.command||"").includes(h));C&&g.push(C)}),g.length>0?g:e},te=({editor:e,position:t="top",sticky:a=!1,floating:o=!1,readonly:n=!1,showMoreOptions:r=!0,itemsOverride:g})=>{const[m,l]=c.useState(null),[h,u]=c.useState(null),[C,R]=c.useState(null),[L,s]=c.useState(!1),j=c.useRef(null),N=c.useRef(null),v=c.useRef({}),w=c.useRef([]),b=c.useRef(null),A=c.useRef(null),F=c.useRef(null),E=c.useMemo(()=>je(e.pluginManager.getToolbarItems(),g),[e,g]),d=i=>{j.current=i,i&&!i.collapsed&&(N.current=i)},S=()=>b.current?.closest("[data-editora-editor]")?.querySelector(".rte-content")||null,_=()=>{if(typeof window>"u")return;const i=b.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=i||null},x=i=>{if(typeof window>"u"||!i)return;const k=i.getAttribute("data-command");k&&(window.__editoraLastCommandButton=i,window.__editoraLastCommand=k)},D=()=>{const i=S();if(!i)return null;const k=window.getSelection();if(!k||k.rangeCount===0)return null;const p=k.getRangeAt(0);return i.contains(p.commonAncestorContainer)?p.cloneRange():null},y=()=>{const i=D();i&&d(i)};c.useEffect(()=>{const i=()=>{y()};return document.addEventListener("selectionchange",i),()=>{document.removeEventListener("selectionchange",i)}},[]),c.useEffect(()=>{if(!m)return;const i=p=>{const P=p.target;P&&P instanceof Element&&(P.closest(".rte-toolbar-dropdown")||l(null))},k=p=>{p.key==="Escape"&&l(null)};return document.addEventListener("pointerdown",i,!0),document.addEventListener("keydown",k),()=>{document.removeEventListener("pointerdown",i,!0),document.removeEventListener("keydown",k)}},[m]);const T=i=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(i),M=(i=!1)=>{const k=S();if(!k)return!1;const p=window.getSelection();if(!p)return!1;const P=p.rangeCount>0&&k.contains(p.getRangeAt(0).commonAncestorContainer),I=i?N.current||j.current:j.current||N.current;if(i&&I&&I.collapsed)return!1;if(I&&k.contains(I.commonAncestorContainer))try{return k.focus({preventScroll:!0}),p.removeAllRanges(),p.addRange(I),!0}catch{}return P};c.useEffect(()=>{if(!r){R(null),s(!1),w.current=[];return}let i=null;const k=()=>{if(!b.current||!A.current)return;const I=b.current.clientWidth,z=16,Q=40,le=4,Te=Math.max(0,I-z-Q-le);let ce=0,ue=0;const Y=A.current.children;for(let q=0;q<Y.length;q++){const Z=Y[q].getBoundingClientRect().width;Z>0&&(w.current[q]=Z);const fe=w.current[q]??Z,me=(fe>0?fe:40)+le;if(ce+me<=Te)ce+=me,ue++;else break}const de=Math.max(1,Math.min(ue,Y.length));R(q=>q===de?q:de)},p=()=>{i!==null&&cancelAnimationFrame(i),i=requestAnimationFrame(k)};w.current=[],p();const P=new ResizeObserver(()=>{p()});return b.current&&P.observe(b.current),A.current&&P.observe(A.current),()=>{i!==null&&cancelAnimationFrame(i),P.disconnect()}},[E.length,r]),c.useEffect(()=>{L&&C!==null&&C>=E.length&&s(!1)},[L,C,E.length]);const H=i=>(v.current[i]||(v.current[i]=Ie.default.createRef()),v.current[i]),B=(i,k)=>{if(n)return;_(),i==="addComment"||i==="toggleComments"||M(T(i));const I={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[i];if(I){document.execCommand(I,!1),l(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(i,k),l(null)},O=i=>{n||(y(),l(m===i?null:i))},W=i=>{n||(y(),u(h===i?null:i),l(null))},U=(i,k)=>{n||(M(),B(i,k),d(null),N.current=null,u(null))},V=(i,k)=>i&&i.startsWith("<svg")&&i.endsWith("</svg>")?f.jsx("span",{dangerouslySetInnerHTML:{__html:i}}):i&&i.length===1&&/^[BIUSH]$/.test(i)?f.jsx("span",{style:{fontWeight:"bold",fontSize:"14px",lineHeight:"1"},children:i}):i||"⚪",Re={...a&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},se=r&&C!==null&&C<E.length,Ae=i=>{if(n)return;const k=i.target;k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")&&(x(k.closest("[data-command]")),_(),y(),i.preventDefault())},J=(i,k=!0)=>i.map((p,P)=>{const I=p.command||"";return f.jsx("div",{className:"rte-toolbar-item",style:{display:k&&r&&C!==null&&P>=C?"none":"flex"},children:p.type==="separator"?f.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):p.type==="dropdown"?f.jsxs("div",{className:"rte-toolbar-dropdown",children:[f.jsxs("button",{className:"rte-toolbar-button","data-command":I,"data-active":"false",onMouseDown:z=>{z.preventDefault(),y()},onClick:()=>O(I),disabled:n,children:[p.label," ▼"]}),m===I&&f.jsx("div",{className:"rte-toolbar-dropdown-menu",children:p.options?.map(z=>f.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:Q=>Q.preventDefault(),onClick:()=>B(I,z.value),children:z.label},z.value))})]}):p.type==="inline-menu"?f.jsx("button",{ref:H(I),className:"rte-toolbar-button","data-command":I,"data-active":"false",onMouseDown:z=>{z.preventDefault(),y()},onClick:()=>W(I),disabled:n,title:p.label,children:V(p.icon)}):p.type==="input"?f.jsx("input",{type:"text",className:`rte-toolbar-input ${p.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:p.placeholder,onChange:z=>B(I,z.target.value),disabled:n,onKeyDown:z=>{z.key==="Enter"&&B(I,z.target.value)},title:p.label}):p.type==="group"?f.jsx("div",{className:`rte-toolbar-group-button ${p.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${p.label}`,children:f.jsx("div",{className:`rte-toolbar-group-items ${p.label.toLowerCase().replace(/\s+/g,"-")}`,children:J(p.items||[],!1)})}):f.jsx("button",{className:"rte-toolbar-button","data-command":I,"data-active":"false",onMouseDown:z=>{z.preventDefault(),y()},onClick:()=>B(I),disabled:n,title:p.label,children:V(p.icon)})},P)}),Le=r&&C!==null?E.filter((i,k)=>k>=C):[];return f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"rte-toolbar-wrapper",style:Re,onMouseDownCapture:Ae,children:[f.jsxs("div",{className:"rte-toolbar",ref:b,children:[f.jsx("div",{className:"rte-toolbar-items-container",ref:A,style:r?void 0:{flexWrap:"wrap"},children:J(E)}),se&&f.jsx("button",{ref:F,className:`rte-toolbar-more-button ${L?"active":""}`,onMouseDown:i=>{i.preventDefault(),y()},onClick:()=>s(!L),disabled:n,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),se&&f.jsx("div",{className:`rte-toolbar-expanded-row ${L?"show":""}`,children:J(Le,!1)})]}),E.map(i=>{if(i.type==="inline-menu"){const k=i.command||"";return f.jsx(ve,{isOpen:h===k,options:i.options||[],onSelect:p=>U(k,p),onClose:()=>u(null),anchorRef:H(k)},`menu-${k||"unknown"}`)}return null})]})};function De(e,t){const a=c.useRef(),o=c.useRef("");return c.useEffect(()=>{if(!t?.enabled)return;const r=t.intervalMs||3e4,g=t.storageKey||"rte-autosave",m=t.provider||"localStorage",l=async()=>{const h=e();if(h!==o.current){if(o.current=h,m==="localStorage")try{localStorage.setItem(g,h),localStorage.setItem(`${g}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(u){console.error("[Autosave] Failed to save to localStorage:",u)}else if(m==="api"&&t.apiUrl)try{await fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:h,timestamp:Date.now()})}),console.log("[Autosave] Content saved to API")}catch(u){console.error("[Autosave] Failed to save to API:",u)}}};return a.current=setInterval(l,r),()=>{a.current&&clearInterval(a.current)}},[t?.enabled,t?.intervalMs,t?.storageKey,t?.provider,t?.apiUrl,e]),{restore:()=>{if(!t?.enabled)return null;const r=t.storageKey||"rte-autosave";if((t.provider||"localStorage")==="localStorage")try{const m=localStorage.getItem(r),l=localStorage.getItem(`${r}-timestamp`);if(m&&l)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(l))),m}catch(m){console.error("[Autosave] Failed to restore from localStorage:",m)}return null}}}const He=["p","br","strong","em","u","s","strike","del","b","i","h1","h2","h3","h4","h5","h6","ul","ol","li","a","img","video","audio","table","thead","tbody","tr","th","td","blockquote","pre","code","span","div","sup","sub","hr"],Fe={"*":["class","style","id","data-*"],a:["href","target","rel","title"],img:["src","alt","width","height","loading"],video:["src","controls","width","height","autoplay","loop","muted"],audio:["src","controls","autoplay","loop","muted"],table:["border","cellpadding","cellspacing"],td:["colspan","rowspan","align","valign"],th:["colspan","rowspan","align","valign"]};function pe(e,t,a){if(t?.sanitize===!1)return e;const o=t?.allowedTags&&t.allowedTags.length>0?t.allowedTags:He,r=!!t?.allowedAttributes&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:Fe,g=document.createElement("div");return g.innerHTML=e,Ee(g,o,r),g.innerHTML}function Ee(e,t,a){const o=Array.from(e.childNodes);for(const n of o)if(n.nodeType===Node.ELEMENT_NODE){const r=n,g=r.tagName.toLowerCase();if(!t.includes(g)){for(;r.firstChild;)e.insertBefore(r.firstChild,r);e.removeChild(r);continue}_e(r,a),Ee(r,t,a)}else{if(n.nodeType===Node.TEXT_NODE)continue;e.removeChild(n)}}function _e(e,t){const a=e.tagName.toLowerCase(),o=Array.from(e.attributes),n=t[a]||[],r=t["*"]||[],g=[...n,...r];for(const m of o){const l=m.name.toLowerCase();let h=!1;g.includes(l)&&(h=!0);for(const u of g)if(u.endsWith("*")){const C=u.slice(0,-1);if(l.startsWith(C)){h=!0;break}}(l.startsWith("on")||l==="javascript:"||l==="href"&&m.value.trim().toLowerCase().startsWith("javascript:")||l==="src"&&m.value.trim().toLowerCase().startsWith("javascript:"))&&(h=!1),h||e.removeAttribute(m.name)}e.hasAttribute("href")&&(e.getAttribute("href")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("href"),e.hasAttribute("src")&&(e.getAttribute("src")||"").trim().toLowerCase().startsWith("javascript:")&&e.removeAttribute("src")}function Be(e,t,a){return a?.sanitizeOnPaste===!1?e:pe(e,t)}function ge(e,t,a){return a?.sanitizeOnInput===!1?e:pe(e,t)}const X=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),K=(e,t)=>{const o=!!t&&X(e);e.classList.toggle("rte-content-empty",o)},oe="data-rte-caret-marker",ae="data-rte-range-start-marker",ie="data-rte-range-end-marker",ee=()=>Math.random().toString(36).slice(2),ze=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;try{const o=a.cloneRange();o.selectNodeContents(e),o.setEnd(a.startContainer,a.startOffset);const n=a.cloneRange();return n.selectNodeContents(e),n.setEnd(a.endContainer,a.endOffset),{start:o.toString().length,end:n.toString().length}}catch{return null}},he=(e,t)=>{const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let o=a.nextNode(),n=Math.max(0,t),r=null;for(;o;){r=o;const g=o.textContent?.length??0;if(n<=g)return{node:o,offset:n};n-=g,o=a.nextNode()}return r?{node:r,offset:r.textContent?.length??0}:{node:e,offset:e.childNodes.length}},We=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const a=t.getRangeAt(0);if(!e.contains(a.commonAncestorContainer))return null;const o=ze(e);try{if(a.collapsed){const u=ee(),C=document.createElement("span");return C.setAttribute(oe,u),C.appendChild(document.createTextNode("")),a.cloneRange().insertNode(C),{collapsed:!0,caretId:u,fallbackOffsets:o}}const n=ee(),r=ee(),g=document.createElement("span");g.setAttribute(ie,r),g.appendChild(document.createTextNode(""));const m=document.createElement("span");m.setAttribute(ae,n),m.appendChild(document.createTextNode(""));const l=a.cloneRange();l.collapse(!1),l.insertNode(g);const h=a.cloneRange();return h.collapse(!0),h.insertNode(m),{collapsed:!1,startId:n,endId:r,fallbackOffsets:o}}catch{return{collapsed:a.collapsed,fallbackOffsets:o}}},Oe=e=>{e.querySelectorAll(`[${oe}], [${ae}], [${ie}]`).forEach(t=>t.remove())},Pe=(e,t)=>{if(!t)return!1;const a=window.getSelection();if(!a)return!1;try{const o=document.createRange();if(t.collapsed&&t.caretId){const n=e.querySelector(`[${oe}="${t.caretId}"]`);return!n||!n.parentNode?!1:(o.setStartAfter(n),o.collapse(!0),a.removeAllRanges(),a.addRange(o),!0)}if(!t.collapsed&&t.startId&&t.endId){const n=e.querySelector(`[${ae}="${t.startId}"]`),r=e.querySelector(`[${ie}="${t.endId}"]`);return!n||!r||!n.parentNode||!r.parentNode?!1:(o.setStartAfter(n),o.setEndBefore(r),a.removeAllRanges(),a.addRange(o),!0)}}catch{return!1}return!1},$e=(e,t)=>{if(!t)return;const a=window.getSelection();if(a)try{const o=he(e,t.start),n=he(e,t.end),r=document.createRange();r.setStart(o.node,o.offset),r.setEnd(n.node,n.offset),a.removeAllRanges(),a.addRange(r)}catch{}},ye=({editor:e,defaultValue:t,value:a,readonly:o=!1,placeholder:n,onChange:r,pasteConfig:g,contentConfig:m,securityConfig:l,performanceConfig:h,accessibilityConfig:u,autosaveConfig:C,contextMenuConfig:R,spellcheckConfig:L})=>{const s=c.useRef(null),j=a!==void 0,N=c.useRef(),v=m?.autoHeight===!0,w=typeof m?.minHeight=="number"?m.minHeight:200,b=typeof m?.maxHeight=="number"?m.maxHeight:0,A=d=>{if(!d||!v)return;d.style.height="auto";const S=Math.max(w,d.scrollHeight);if(b>0){d.style.height=`${Math.min(S,b)}px`;return}d.style.height=`${S}px`},{restore:F}=De(()=>s.current?.innerHTML||"",C);c.useEffect(()=>{if(!s.current)return;const d=F(),S=d??a??t??"";S.trim()?s.current.innerHTML!==S&&(s.current.innerHTML=S):n?s.current.innerHTML="":s.current.innerHTML.trim()||(s.current.innerHTML="<p><br></p>"),K(s.current,n),A(s.current),d&&r&&r(d)},[]),c.useEffect(()=>{!s.current||!j||(a!==s.current.innerHTML&&(s.current.innerHTML=a),K(s.current,n),A(s.current))},[a,j]),c.useEffect(()=>{if(!s.current)return;const d=s.current;if(n){d.setAttribute("data-placeholder",n),X(d)&&(d.innerHTML=""),K(d,n),A(d);return}d.removeAttribute("data-placeholder"),K(d,n),A(d)},[n]),c.useEffect(()=>{if(!s.current)return;const d=s.current;if(u?.enableARIA!==!1){d.setAttribute("role","textbox"),d.setAttribute("aria-multiline","true"),d.setAttribute("aria-disabled",o?"true":"false");const _=n?.trim();_?d.setAttribute("aria-label",_):d.removeAttribute("aria-label")}else d.removeAttribute("role"),d.removeAttribute("aria-multiline"),d.removeAttribute("aria-label"),d.removeAttribute("aria-disabled")},[u?.enableARIA,n,o]),c.useEffect(()=>{A(s.current)},[v,w,b,a]),c.useEffect(()=>{if(!s.current)return;const d=()=>{if(!s.current||o)return;n&&X(s.current)&&(s.current.innerHTML="");let T=s.current.innerHTML;if(l?.sanitizeOnInput!==!1&&m?.sanitize!==!1){const M=ge(T,m,l);if(M!==s.current.innerHTML){const H=We(s.current),B=s.current.innerHTML,O=ge(B,m,l);s.current.innerHTML=O,Pe(s.current,H)||$e(s.current,H?.fallbackOffsets||null),Oe(s.current),T=s.current.innerHTML}else T=M}K(s.current,n),A(s.current),r&&(h?.debounceInputMs?(N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{r(T)},h.debounceInputMs)):r(T))},S=T=>{if(o){T.preventDefault();return}T.preventDefault();let M=T.clipboardData?.getData("text/html");const H=T.clipboardData?.getData("text/plain"),B=!!M&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(M);if(g?.clean||!g?.keepFormatting){H&&document.execCommand("insertText",!1,H);return}if(g?.convertWord===!1&&B){H&&document.execCommand("insertText",!1,H);return}if(M){l?.sanitizeOnPaste!==!1&&m?.sanitize!==!1&&(M=Be(M,m,l));const O=window.getSelection();if(O&&O.rangeCount>0){const W=O.getRangeAt(0);W.deleteContents();const U=document.createElement("div");U.innerHTML=M;const V=document.createDocumentFragment();for(;U.firstChild;)V.appendChild(U.firstChild);W.insertNode(V),W.collapse(!1),O.removeAllRanges(),O.addRange(W)}}else H&&document.execCommand("insertText",!1,H)},_=T=>{const M=T.target;(M.tagName==="IMG"||M.tagName==="VIDEO")&&(M.style.resize="both",M.style.overflow="auto",M.style.display="inline-block")},x=T=>{R?.enabled===!1&&T.preventDefault()},D=()=>{s.current&&(n&&X(s.current)&&(s.current.innerHTML=""),K(s.current,n),A(s.current))},y=s.current;return y.addEventListener("input",d),y.addEventListener("paste",S),y.addEventListener("click",_),y.addEventListener("contextmenu",x),y.addEventListener("focus",D),y.addEventListener("blur",D),o||y.focus(),()=>{N.current&&clearTimeout(N.current),y.removeEventListener("input",d),y.removeEventListener("paste",S),y.removeEventListener("click",_),y.removeEventListener("contextmenu",x),y.removeEventListener("focus",D),y.removeEventListener("blur",D)}},[e,r,g,m,l,h,n,R,o]);const E=(L?.enabled??!1)&&(L?.provider??"browser")==="browser";return c.useEffect(()=>{if(!s.current||typeof window>"u"||o||u?.keyboardNavigation===!1)return;const d=new $.KeyboardShortcutManager,S=s.current,_=x=>{d.handleKeyDown(x,(D,y)=>{if(typeof window<"u"&&window.executeEditorCommand){const T=s.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=T||null,window.executeEditorCommand(D,y)}})};return S.addEventListener("keydown",_),()=>{S.removeEventListener("keydown",_)}},[u?.keyboardNavigation,o]),f.jsx("div",{ref:s,contentEditable:!o,suppressContentEditableWarning:!0,spellCheck:o?!1:E,tabIndex:u?.keyboardNavigation===!1?-1:0,"aria-keyshortcuts":u?.keyboardNavigation===!1?void 0:"Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y","data-viewport-only-scan":h?.viewportOnlyScan?"true":"false","data-a11y-checker":u?.checker?"true":"false","data-readonly":o?"true":"false",className:`rte-content ${o?"rte-content-readonly":""}`,style:{minHeight:`${w}px`,maxHeight:v?b>0?`${b}px`:"none":"100%",padding:"16px",outline:"none",border:"1px solid #ddd",borderRadius:"0px 0px 4px 4px",fontSize:"14px",lineHeight:"1.5",overflow:v?b>0?"auto":"hidden":"auto",flex:v?void 0:1,boxSizing:"border-box",wordWrap:"break-word",overflowWrap:"break-word"}})},Ue=({editor:e,isEnabled:t,viewportOnlyScan:a=!0,readonly:o=!1})=>{const[n,r]=c.useState(!1),[g,m]=c.useState({top:0,left:0}),l=c.useRef(null),h=c.useRef(null),u=c.useRef(null),C=c.useRef(null),R=c.useRef(null);c.useEffect(()=>{if(!t||o){r(!1);return}R.current=l.current?.closest("[data-editora-editor]");const s=E=>{if(R.current)return R.current;const d=l.current?.closest("[data-editora-editor]");if(d)return R.current=d,d;const S=E?.commonAncestorContainer,x=(S?S.nodeType===Node.ELEMENT_NODE?S:S.parentElement:null)?.closest("[data-editora-editor]");return x?(R.current=x,x):null},j=E=>E&&E.querySelector(".rte-content, .editora-content")||null,N=E=>{if(!E.anchorNode||!E.focusNode)return!1;try{const d=document.createRange();return d.setStart(E.anchorNode,E.anchorOffset),d.setEnd(E.focusNode,E.focusOffset),d.collapsed}catch{return!1}},v=(E,d)=>{const S=Array.from(d.getClientRects()).filter(x=>x.width>0||x.height>0);return S.length===0?d.getBoundingClientRect():N(E)?S[0]:S[S.length-1]},w=()=>{C.current&&clearTimeout(C.current);const E=window.getSelection();if(!E||E.rangeCount===0){r(!1),u.current=null;return}const d=E.getRangeAt(0);if(d.collapsed){r(!1),u.current=null;return}const S=E.toString().trim(),_=s(d),x=j(_);if(!x||!x.contains(d.commonAncestorContainer)){r(!1),u.current=null;return}if(a){const D=x.getBoundingClientRect(),y=D.bottom>=0&&D.top<=window.innerHeight,T=document.activeElement===x||x.contains(document.activeElement);if(!y&&!T){r(!1),u.current=null;return}}if(S.length>0){const D=v(E,d),y=x.getBoundingClientRect(),T=300;if(D&&y){const M=Math.max(8,D.top-50);let H=D.left+D.width/2;const B=T/2,O=y.left,W=y.right;H-B<O&&(H=O+B+10),H+B>W&&(H=W-B-10),m({top:M,left:H}),r(!0),u.current=d.cloneRange()}}else r(!1),u.current=null},b=E=>{if(h.current&&!h.current.contains(E.target)){const d=s();window.getSelection(),j(d)?.contains(E.target)||(r(!1),u.current=null)}},A=E=>{E.key==="Escape"&&(r(!1),u.current=null)},F=j(s());return document.addEventListener("selectionchange",w),document.addEventListener("mousedown",b),document.addEventListener("keydown",A),F?.addEventListener("mouseup",w),F?.addEventListener("keyup",w),()=>{document.removeEventListener("selectionchange",w),document.removeEventListener("mousedown",b),document.removeEventListener("keydown",A),F?.removeEventListener("mouseup",w),F?.removeEventListener("keyup",w),C.current&&clearTimeout(C.current)}},[t,a,o]);const L=(s,j)=>{if(o||!u.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=R.current||null);const N=R.current?.querySelector(".rte-content");N&&N.focus();const v=window.getSelection();if(v&&u.current)try{v.removeAllRanges(),v.addRange(u.current)}catch{}({toggleBold:()=>document.execCommand("bold",!1),toggleItalic:()=>document.execCommand("italic",!1),toggleUnderline:()=>document.execCommand("underline",!1),toggleStrikethrough:()=>document.execCommand("strikeThrough",!1),createLink:()=>{typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand("openLinkDialog")},clearFormatting:()=>{document.execCommand("removeFormat",!1),document.execCommand("unlink",!1)},toggleCode:()=>{const b=window.getSelection();if(b&&b.rangeCount>0){const A=b.getRangeAt(0),F=document.createElement("code");A.surroundContents(F)}},setBlockType:()=>{if(j==="blockquote"){const b=window.getSelection();if(b&&b.rangeCount>0){const A=b.getRangeAt(0);(A.commonAncestorContainer.nodeType===Node.TEXT_NODE?A.commonAncestorContainer.parentElement:A.commonAncestorContainer)?.closest?.("blockquote")?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else j&&document.execCommand("formatBlock",!1,j)}})[s]?.(),r(!1),u.current=null};return!t||o?f.jsx("span",{ref:l,style:{display:"none"},"aria-hidden":"true"}):f.jsxs(f.Fragment,{children:[f.jsx("span",{ref:l,style:{display:"none"},"aria-hidden":"true"}),n&&f.jsxs("div",{ref:h,className:"floating-toolbar",onMouseDown:s=>s.preventDefault(),style:{position:"fixed",top:`${g.top}px`,left:`${g.left}px`,transform:"translateX(-50%)",zIndex:1e4,display:"flex"},children:[f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("toggleBold"),title:"Bold (Ctrl+B)",children:f.jsx("strong",{children:"B"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("toggleItalic"),title:"Italic (Ctrl+I)",children:f.jsx("em",{children:"I"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("toggleUnderline"),title:"Underline (Ctrl+U)",children:f.jsx("u",{children:"U"})}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("toggleStrikethrough"),title:"Strikethrough",children:f.jsx("s",{children:"S"})}),f.jsx("div",{className:"floating-toolbar-separator"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("clearFormatting"),title:"Clear Formatting",children:"⌫"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("createLink"),title:"Insert Link",children:"🔗"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("toggleCode"),title:"Code",children:"Code"}),f.jsx("div",{className:"floating-toolbar-separator"}),f.jsx("button",{className:"floating-toolbar-btn",onClick:()=>L("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},qe=({plugins:e,children:t})=>{const a=e.filter(n=>n.context?.provider);return a.length===0?f.jsx(f.Fragment,{children:t}):a.reduce((n,r)=>{const g=r.context.provider;return f.jsx(g,{children:n},r.name)},f.jsx(f.Fragment,{children:t}))},be=new Set,we=new Set,ne=e=>!!e&&typeof e=="object"&&typeof e.name=="string",Ce=e=>{const t=e?.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},Ke=(e,t)=>{if(!Array.isArray(e))return[];const a=Ce(t),o=[],n=[];if(e.forEach(r=>{if(ne(r)){o.push(r);return}if(typeof r!="string")return;const g=a[r];if(typeof g=="function")try{const m=g();if(ne(m)){o.push(m);return}}catch{}n.push(r)}),n.length>0){const r=n.slice().sort().join("|");be.has(r)||(be.add(r),console.warn(`[Editora React] Unresolved string plugin names: ${n.join(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return o},Ve=(e,t,a)=>{if(!t?.checker||e.some(r=>r?.name==="a11yChecker"))return e;const o=Ce(a).a11yChecker;if(typeof o=="function")try{const r=o();if(ne(r))return[...e,r]}catch{}const n="accessibility.checker";return we.has(n)||(we.add(n),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},Ge={readonly:!1,placeholder:"",toolbar:{items:[],floating:!1,sticky:!1,showMoreOptions:!0},statusbar:{enabled:!1,position:"bottom"},menubar:{enabled:!1,items:[]},contextMenu:{enabled:!0},media:{uploadUrl:"",libraryUrl:"",maxFileSize:10*1024*1024,allowedTypes:["image/jpeg","image/png","image/gif","image/webp"],headers:{},withCredentials:!1},paste:{clean:!0,keepFormatting:!1,convertWord:!0},history:{maxSteps:100,debounceMs:300},language:{locale:"en",direction:"ltr"},spellcheck:{enabled:!1,provider:"browser",apiUrl:"",apiHeaders:{}},autosave:{enabled:!1,intervalMs:3e4,storageKey:"rte-autosave",provider:"localStorage",apiUrl:""},accessibility:{enableARIA:!0,keyboardNavigation:!0,checker:!1},performance:{debounceInputMs:100,viewportOnlyScan:!0},content:{allowedTags:[],allowedAttributes:{},sanitize:!0,autoHeight:!1,minHeight:200,maxHeight:0},security:{sanitizeOnPaste:!0,sanitizeOnInput:!0}};function xe(e,t){const a={...e};for(const o in t){const n=t[o],r=a[o];n!==void 0&&(typeof n=="object"&&n!==null&&!Array.isArray(n)&&typeof r=="object"&&r!==null&&!Array.isArray(r)?a[o]=xe(r,n):a[o]=n)}return a}function ke(e){const t=xe(Ge,{readonly:e.readonly,placeholder:e.placeholder,toolbar:e.toolbar,statusbar:e.statusbar,menubar:e.menubar,contextMenu:e.contextMenu,media:e.media,paste:e.paste,history:e.history,language:e.language,spellcheck:e.spellcheck,autosave:e.autosave,accessibility:e.accessibility,performance:e.performance,content:e.content,security:e.security});if(e.floatingToolbar!==void 0){const o=typeof e.floatingToolbar=="boolean"?e.floatingToolbar:e.floatingToolbar.enabled;t.toolbar={...t.toolbar,floating:o??t.toolbar.floating}}return e.mediaConfig&&(t.media={...t.media,uploadUrl:e.mediaConfig.uploadUrl||t.media.uploadUrl,libraryUrl:e.mediaConfig.libraryUrl||t.media.libraryUrl,maxFileSize:e.mediaConfig.maxFileSize||t.media.maxFileSize,allowedTypes:e.mediaConfig.allowedTypes||t.media.allowedTypes}),{...t,id:e.id,className:e.className,value:e.value,defaultValue:e.defaultValue,onChange:e.onChange,onInit:e.onInit,onDestroy:e.onDestroy,plugins:Ve(Ke(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const re=new Map,Xe=()=>{if(typeof window>"u")return{editorElement:null,contentElement:null};const e=window.__editoraCommandEditorRoot||null,t=e?.querySelector('[contenteditable="true"]');return{editorElement:e,contentElement:t}};typeof window<"u"&&(window.registerEditorCommand=(e,t)=>{re.set(e,t)},window.executeEditorCommand=(e,t)=>{const a=re.get(e);if(a){const o=Xe();return a(t,o)}else return console.warn(`No handler registered for command: ${e}`),!1});const Je=e=>{const t=c.useMemo(()=>ke(e),[e.id,e.className,e.value,e.defaultValue,e.readonly,e.placeholder,e.plugins,e.toolbar,e.menubar,e.contextMenu,e.media,e.paste,e.history,e.language,e.spellcheck,e.autosave,e.accessibility,e.performance,e.content,e.security,e.floatingToolbar,e.mediaConfig]),a=c.useRef(null),o=c.useRef(null),n=c.useRef(e.onInit),r=c.useRef(e.onDestroy),g=c.useRef(e.onChange),m=c.useRef(new Set),l=c.useRef(null),h=c.useRef(null),u=c.useRef(null);c.useEffect(()=>{n.current=e.onInit,r.current=e.onDestroy,g.current=e.onChange});const C=v=>{g.current?.(v),m.current.forEach(w=>{try{w(v)}catch(b){console.error("Editora onChange subscriber failed:",b)}})},R=c.useMemo(()=>{const v=new $.PluginManager;t.plugins.forEach(b=>{v.register(b),b.commands&&typeof window<"u"&&Object.entries(b.commands).forEach(([A,F])=>{re.set(A,F)})});const w=new $.Editor(v);return a.current=w,w},[t.plugins]);c.useEffect(()=>{const v={getHTML:()=>l.current?.querySelector(".rte-content")?.innerHTML||"",setHTML:w=>{const b=l.current?.querySelector(".rte-content");b&&(b.innerHTML=w)},execCommand:(w,b)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=l.current||null,window.executeEditorCommand(w,b))},registerCommand:(w,b)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(w,b)},focus:()=>{l.current?.querySelector(".rte-content")?.focus()},blur:()=>{l.current?.querySelector(".rte-content")?.blur()},destroy:()=>{r.current&&r.current()},onChange:w=>(m.current.add(w),()=>{m.current.delete(w)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:R.toolbar?.items||[]}};return o.current=v,n.current&&n.current(v),()=>{m.current.clear(),r.current&&r.current()}},[]),c.useEffect(()=>{if(t.statusbar.enabled&&u.current&&l.current){h.current||(h.current=new $.StatusBar({enabled:!0,position:t.statusbar.position}),h.current.create(u.current));const v=l.current.querySelector(".rte-content");if(v){const w=()=>{const x=document.activeElement;return!!x&&(x===v||v.contains(x))},b=()=>{const x=v.getBoundingClientRect();return x.bottom>=0&&x.top<=window.innerHeight},A=()=>{const x=window.getSelection();if(!x||x.rangeCount===0)return null;const D=x.getRangeAt(0),y=D.commonAncestorContainer;return v.contains(y)?D:null},F=(x=!1)=>{if(t.performance.viewportOnlyScan!==!1&&!b()&&!w())return;const y=A(),T=!!y||w();if(x&&!T)return;const M=v.textContent||"",{words:H,chars:B}=$.calculateTextStats(M),O=$.countLines(v);let W,U;y&&(W=$.getCursorPosition(v,y),y.collapsed||(U=$.getSelectionInfo(y,W),W=void 0)),h.current?.update({wordCount:H,charCount:B,lineCount:O,cursorPosition:W,selectionInfo:U})},E=()=>F(),d=()=>F(!0),S=()=>F(),_=()=>F();return v.addEventListener("input",E),v.addEventListener("focus",S),v.addEventListener("blur",_),document.addEventListener("selectionchange",d),F(),()=>{v.removeEventListener("input",E),v.removeEventListener("focus",S),v.removeEventListener("blur",_),document.removeEventListener("selectionchange",d)}}}else h.current&&(h.current.destroy(),h.current=null);return()=>{h.current&&(h.current.destroy(),h.current=null)}},[t.statusbar.enabled,t.statusbar.position,t.performance.viewportOnlyScan]);const L=t.toolbar.floating??!1,s=t.toolbar.position||"top",j=t.toolbar.sticky??!1,N=t.toolbar.showMoreOptions??!0;return f.jsx(qe,{plugins:t.plugins,children:f.jsxs("div",{ref:l,id:t.id,"data-editora-editor":!0,"data-readonly":t.readonly?"true":"false",className:`rte-editor ${t.className||""}`,lang:t.language.locale,dir:t.language.direction,style:{display:"flex",flexDirection:"column",height:"100%"},children:[s!=="bottom"&&f.jsx(te,{editor:R,position:s,sticky:j,floating:L,readonly:t.readonly,showMoreOptions:N,itemsOverride:t.toolbar.items}),f.jsx(ye,{editor:R,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:C,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"&&f.jsx(te,{editor:R,position:s,sticky:j,floating:L,readonly:t.readonly,showMoreOptions:N,itemsOverride:t.toolbar.items}),f.jsx(Ue,{editor:R,isEnabled:L,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&f.jsx("div",{ref:u,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},Se=e=>f.jsx(Je,{...e});function Qe(e={}){const t=c.useRef(null),a=c.useRef(e.onCommand);return c.useEffect(()=>{a.current=e.onCommand}),c.useEffect(()=>{if(typeof window>"u"||e.enabled===!1)return;const o=new $.KeyboardShortcutManager(e);t.current=o;const n=g=>o.handleKeyDown(g,(l,h)=>{a.current&&a.current(l,h),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(l,h)}),r=e.editorElement||document;return r&&r.addEventListener("keydown",n),()=>{r&&r.removeEventListener("keydown",n)}},[e.editorElement,e.enabled,e.shortcuts,e.customShortcuts]),{getShortcuts:()=>t.current?.getAllShortcuts()||[],getShortcutForCommand:o=>t.current?.getShortcutForCommand(o),getShortcutsHelp:()=>t.current?.getShortcutsHelp()||"",enable:()=>t.current?.enable(),disable:()=>t.current?.disable(),isEnabled:()=>t.current?.isEnabled()||!1}}exports.EditorContent=ye;exports.EditoraEditor=Se;exports.InlineMenu=ve;exports.RichTextEditor=Se;exports.Toolbar=te;exports.mergeConfig=ke;exports.useKeyboardShortcuts=Qe; |
+406
-377
| import { jsx as h, jsxs as V, Fragment as Y } from "react/jsx-runtime"; | ||
| import Me, { useRef as A, useState as j, useLayoutEffect as Ie, useEffect as W, useMemo as oe } from "react"; | ||
| import { KeyboardShortcutManager as Ee, PluginManager as Ne, Editor as He, StatusBar as De, calculateTextStats as Fe, countLines as Be, getCursorPosition as ze, getSelectionInfo as We } from "@editora/core"; | ||
| import Ie, { useRef as x, useState as j, useLayoutEffect as Ne, useEffect as B, useMemo as oe } from "react"; | ||
| import { KeyboardShortcutManager as Ee, PluginManager as He, Editor as De, StatusBar as Fe, calculateTextStats as Be, countLines as ze, getCursorPosition as We, getSelectionInfo as _e } from "@editora/core"; | ||
| const Oe = ({ | ||
@@ -12,9 +12,9 @@ isOpen: e, | ||
| }) => { | ||
| const f = A(null), [d, c] = j(null), m = () => { | ||
| const f = x(null), [d, c] = j(null), m = () => { | ||
| if (!e || !n.current) return; | ||
| const s = n.current.getBoundingClientRect(), C = f.current?.getBoundingClientRect(), S = C?.width || 120, M = C?.height || t.length * 36, i = 8, F = 4, D = window.innerWidth, w = window.innerHeight; | ||
| let b = s.bottom + F, g = s.left; | ||
| g + S > D - i && (g = D - S - i), g < i && (g = i), b + M > w - i && (b = s.top - M - F), b < i && (b = i), c({ top: b, left: g }); | ||
| const s = n.current.getBoundingClientRect(), y = f.current?.getBoundingClientRect(), A = y?.width || 120, T = y?.height || t.length * 36, l = 8, H = 4, N = window.innerWidth, w = window.innerHeight; | ||
| let b = s.bottom + H, g = s.left; | ||
| g + A > N - l && (g = N - A - l), g < l && (g = l), b + T > w - l && (b = s.top - T - H), b < l && (b = l), c({ top: b, left: g }); | ||
| }; | ||
| return Ie(() => { | ||
| return Ne(() => { | ||
| if (!e) { | ||
@@ -29,3 +29,3 @@ c(null); | ||
| }; | ||
| }, [e, t.length, n]), W(() => { | ||
| }, [e, t.length, n]), B(() => { | ||
| if (!e) return; | ||
@@ -38,10 +38,10 @@ const s = () => { | ||
| }; | ||
| }, [e, t.length, n]), W(() => { | ||
| const s = (S) => { | ||
| f.current && !f.current.contains(S.target) && n.current && !n.current.contains(S.target) && o(); | ||
| }, C = (S) => { | ||
| S.key === "Escape" && o(); | ||
| }, [e, t.length, n]), B(() => { | ||
| const s = (A) => { | ||
| f.current && !f.current.contains(A.target) && n.current && !n.current.contains(A.target) && o(); | ||
| }, y = (A) => { | ||
| A.key === "Escape" && o(); | ||
| }; | ||
| return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", C)), () => { | ||
| document.removeEventListener("mousedown", s), document.removeEventListener("keydown", C); | ||
| return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", y)), () => { | ||
| document.removeEventListener("mousedown", s), document.removeEventListener("keydown", y); | ||
| }; | ||
@@ -71,3 +71,3 @@ }, [e, o, n]), e ? /* @__PURE__ */ h( | ||
| ) : null; | ||
| }, X = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Pe = { | ||
| }, J = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Pe = { | ||
| undo: "undo", | ||
@@ -98,3 +98,3 @@ redo: "redo", | ||
| clearformatting: "clearFormatting" | ||
| }, _e = (e, t) => { | ||
| }, $e = (e, t) => { | ||
| if (!Array.isArray(t) || t.length === 0) | ||
@@ -106,3 +106,3 @@ return e; | ||
| e.forEach((c) => { | ||
| o.set(X(c.command || ""), c), n.set(X(c.label || ""), c); | ||
| o.set(J(c.command || ""), c), n.set(J(c.label || ""), c); | ||
| }); | ||
@@ -120,6 +120,6 @@ const r = t.flatMap((c) => c.split(/\s+/)).map((c) => c.trim()).filter(Boolean), f = []; | ||
| } | ||
| const m = X(c), s = Pe[m], C = o.get(m) || (s ? o.get(X(s)) : void 0) || n.get(m) || e.find( | ||
| (S) => X(S.command || "").includes(m) | ||
| const m = J(c), s = Pe[m], y = o.get(m) || (s ? o.get(J(s)) : void 0) || n.get(m) || e.find( | ||
| (A) => J(A.command || "").includes(m) | ||
| ); | ||
| C && f.push(C); | ||
| y && f.push(y); | ||
| }), f.length > 0 ? f : e; | ||
@@ -135,31 +135,46 @@ }, we = ({ | ||
| }) => { | ||
| const [d, c] = j(null), [m, s] = j(null), [C, S] = j(null), [M, i] = j(!1), F = A(null), D = A(null), w = A({}), b = A([]), g = A(null), T = A(null), B = A(null), v = oe( | ||
| () => _e(e.pluginManager.getToolbarItems(), f), | ||
| const [d, c] = j(null), [m, s] = j(null), [y, A] = j(null), [T, l] = j(!1), H = x(null), N = x(null), w = x({}), b = x([]), g = x(null), L = x(null), z = x(null), p = oe( | ||
| () => $e(e.pluginManager.getToolbarItems(), f), | ||
| [e, f] | ||
| ), u = (l) => { | ||
| F.current = l, l && !l.collapsed && (D.current = l); | ||
| }, E = () => g.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, z = () => { | ||
| ), u = (i) => { | ||
| H.current = i, i && !i.collapsed && (N.current = i); | ||
| }, S = () => g.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, W = () => { | ||
| if (typeof window > "u") return; | ||
| const l = g.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = l || null; | ||
| }, y = () => { | ||
| const l = E(); | ||
| if (!l) return null; | ||
| const L = window.getSelection(); | ||
| if (!L || L.rangeCount === 0) return null; | ||
| const p = L.getRangeAt(0); | ||
| return l.contains(p.commonAncestorContainer) ? p.cloneRange() : null; | ||
| }, x = () => { | ||
| const l = y(); | ||
| l && u(l); | ||
| const i = g.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = i || null; | ||
| }, E = (i) => { | ||
| if (typeof window > "u" || !i) return; | ||
| const k = i.getAttribute("data-command"); | ||
| k && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = k); | ||
| }, D = () => { | ||
| const i = S(); | ||
| if (!i) return null; | ||
| const k = window.getSelection(); | ||
| if (!k || k.rangeCount === 0) return null; | ||
| const v = k.getRangeAt(0); | ||
| return i.contains(v.commonAncestorContainer) ? v.cloneRange() : null; | ||
| }, C = () => { | ||
| const i = D(); | ||
| i && u(i); | ||
| }; | ||
| W(() => { | ||
| const l = () => { | ||
| x(); | ||
| B(() => { | ||
| const i = () => { | ||
| C(); | ||
| }; | ||
| return document.addEventListener("selectionchange", l), () => { | ||
| document.removeEventListener("selectionchange", l); | ||
| return document.addEventListener("selectionchange", i), () => { | ||
| document.removeEventListener("selectionchange", i); | ||
| }; | ||
| }, []); | ||
| const k = (l) => [ | ||
| }, []), B(() => { | ||
| if (!d) return; | ||
| const i = (v) => { | ||
| const U = v.target; | ||
| U && U instanceof Element && (U.closest(".rte-toolbar-dropdown") || c(null)); | ||
| }, k = (v) => { | ||
| v.key === "Escape" && c(null); | ||
| }; | ||
| return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", k), () => { | ||
| document.removeEventListener("pointerdown", i, !0), document.removeEventListener("keydown", k); | ||
| }; | ||
| }, [d]); | ||
| const R = (i) => [ | ||
| "toggleBold", | ||
@@ -174,28 +189,28 @@ "toggleItalic", | ||
| "toggleCode" | ||
| ].includes(l), R = (l = !1) => { | ||
| const L = E(); | ||
| if (!L) return !1; | ||
| const p = window.getSelection(); | ||
| if (!p) return !1; | ||
| const q = p.rangeCount > 0 && L.contains(p.getRangeAt(0).commonAncestorContainer), H = l ? D.current || F.current : F.current || D.current; | ||
| if (l && H && H.collapsed) | ||
| ].includes(i), M = (i = !1) => { | ||
| const k = S(); | ||
| if (!k) return !1; | ||
| const v = window.getSelection(); | ||
| if (!v) return !1; | ||
| const U = v.rangeCount > 0 && k.contains(v.getRangeAt(0).commonAncestorContainer), I = i ? N.current || H.current : H.current || N.current; | ||
| if (i && I && I.collapsed) | ||
| return !1; | ||
| if (H && L.contains(H.commonAncestorContainer)) | ||
| if (I && k.contains(I.commonAncestorContainer)) | ||
| try { | ||
| return L.focus({ preventScroll: !0 }), p.removeAllRanges(), p.addRange(H), !0; | ||
| return k.focus({ preventScroll: !0 }), v.removeAllRanges(), v.addRange(I), !0; | ||
| } catch { | ||
| } | ||
| return q; | ||
| return U; | ||
| }; | ||
| W(() => { | ||
| B(() => { | ||
| if (!r) { | ||
| S(null), i(!1), b.current = []; | ||
| A(null), l(!1), b.current = []; | ||
| return; | ||
| } | ||
| let l = null; | ||
| const L = () => { | ||
| if (!g.current || !T.current) return; | ||
| const H = g.current.clientWidth, O = 16, ee = 40, de = 4, Le = Math.max(0, H - O - ee - de); | ||
| let i = null; | ||
| const k = () => { | ||
| if (!g.current || !L.current) return; | ||
| const I = g.current.clientWidth, O = 16, ee = 40, de = 4, Me = Math.max(0, I - O - ee - de); | ||
| let fe = 0, me = 0; | ||
| const te = T.current.children; | ||
| const te = L.current.children; | ||
| for (let K = 0; K < te.length; K++) { | ||
@@ -205,3 +220,3 @@ const ne = te[K].getBoundingClientRect().width; | ||
| const he = b.current[K] ?? ne, be = (he > 0 ? he : 40) + de; | ||
| if (fe + be <= Le) | ||
| if (fe + be <= Me) | ||
| fe += be, me++; | ||
@@ -212,36 +227,36 @@ else | ||
| const ge = Math.max(1, Math.min(me, te.length)); | ||
| S((K) => K === ge ? K : ge); | ||
| }, p = () => { | ||
| l !== null && cancelAnimationFrame(l), l = requestAnimationFrame(L); | ||
| A((K) => K === ge ? K : ge); | ||
| }, v = () => { | ||
| i !== null && cancelAnimationFrame(i), i = requestAnimationFrame(k); | ||
| }; | ||
| b.current = [], p(); | ||
| const q = new ResizeObserver(() => { | ||
| p(); | ||
| b.current = [], v(); | ||
| const U = new ResizeObserver(() => { | ||
| v(); | ||
| }); | ||
| return g.current && q.observe(g.current), T.current && q.observe(T.current), () => { | ||
| l !== null && cancelAnimationFrame(l), q.disconnect(); | ||
| return g.current && U.observe(g.current), L.current && U.observe(L.current), () => { | ||
| i !== null && cancelAnimationFrame(i), U.disconnect(); | ||
| }; | ||
| }, [v.length, r]), W(() => { | ||
| M && C !== null && C >= v.length && i(!1); | ||
| }, [M, C, v.length]); | ||
| const N = (l) => (w.current[l] || (w.current[l] = Me.createRef()), w.current[l]), I = (l, L) => { | ||
| }, [p.length, r]), B(() => { | ||
| T && y !== null && y >= p.length && l(!1); | ||
| }, [T, y, p.length]); | ||
| const F = (i) => (w.current[i] || (w.current[i] = Ie.createRef()), w.current[i]), _ = (i, k) => { | ||
| if (n) return; | ||
| z(), l === "addComment" || l === "toggleComments" || R(k(l)); | ||
| const H = { | ||
| W(), i === "addComment" || i === "toggleComments" || M(R(i)); | ||
| const I = { | ||
| toggleBold: "bold", | ||
| toggleItalic: "italic", | ||
| toggleUnderline: "underline" | ||
| }[l]; | ||
| if (H) { | ||
| document.execCommand(H, !1), c(null); | ||
| }[i]; | ||
| if (I) { | ||
| document.execCommand(I, !1), c(null); | ||
| return; | ||
| } | ||
| typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(l, L), c(null); | ||
| }, $ = (l) => { | ||
| n || (x(), c(d === l ? null : l)); | ||
| }, _ = (l) => { | ||
| n || (x(), s(m === l ? null : l), c(null)); | ||
| }, P = (l, L) => { | ||
| n || (R(), I(l, L), u(null), D.current = null, s(null)); | ||
| }, U = (l, L) => l && l.startsWith("<svg") && l.endsWith("</svg>") ? /* @__PURE__ */ h("span", { dangerouslySetInnerHTML: { __html: l } }) : l && l.length === 1 && /^[BIUSH]$/.test(l) ? /* @__PURE__ */ h("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: l }) : l || "⚪", J = { | ||
| typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, k), c(null); | ||
| }, $ = (i) => { | ||
| n || (C(), c(d === i ? null : i)); | ||
| }, P = (i) => { | ||
| n || (C(), s(m === i ? null : i), c(null)); | ||
| }, q = (i, k) => { | ||
| n || (M(), _(i, k), u(null), N.current = null, s(null)); | ||
| }, X = (i, k) => i && i.startsWith("<svg") && i.endsWith("</svg>") ? /* @__PURE__ */ h("span", { dangerouslySetInnerHTML: { __html: i } }) : i && i.length === 1 && /^[BIUSH]$/.test(i) ? /* @__PURE__ */ h("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: i }) : i || "⚪", Le = { | ||
| ...a && { | ||
@@ -258,6 +273,8 @@ position: "sticky", | ||
| } | ||
| }, ue = r && C !== null && C < v.length, Te = (l) => { | ||
| n || !l.target.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") || (z(), x(), l.preventDefault()); | ||
| }, Z = (l, L = !0) => l.map((p, q) => { | ||
| const H = p.command || ""; | ||
| }, ue = r && y !== null && y < p.length, Te = (i) => { | ||
| if (n) return; | ||
| const k = i.target; | ||
| k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (E(k.closest("[data-command]")), W(), C(), i.preventDefault()); | ||
| }, Z = (i, k = !0) => i.map((v, U) => { | ||
| const I = v.command || ""; | ||
| return /* @__PURE__ */ h( | ||
@@ -268,5 +285,5 @@ "div", | ||
| style: { | ||
| display: L && r && C !== null && q >= C ? "none" : "flex" | ||
| display: k && r && y !== null && U >= y ? "none" : "flex" | ||
| }, | ||
| children: p.type === "separator" ? /* @__PURE__ */ h("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : p.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [ | ||
| children: v.type === "separator" ? /* @__PURE__ */ h("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : v.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [ | ||
| /* @__PURE__ */ V( | ||
@@ -276,11 +293,11 @@ "button", | ||
| className: "rte-toolbar-button", | ||
| "data-command": H, | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), x(); | ||
| O.preventDefault(), C(); | ||
| }, | ||
| onClick: () => $(H), | ||
| onClick: () => $(I), | ||
| disabled: n, | ||
| children: [ | ||
| p.label, | ||
| v.label, | ||
| " ▼" | ||
@@ -290,3 +307,3 @@ ] | ||
| ), | ||
| d === H && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: p.options?.map((O) => /* @__PURE__ */ h( | ||
| d === I && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: v.options?.map((O) => /* @__PURE__ */ h( | ||
| "div", | ||
@@ -296,3 +313,3 @@ { | ||
| onMouseDown: (ee) => ee.preventDefault(), | ||
| onClick: () => I(H, O.value), | ||
| onClick: () => _(I, O.value), | ||
| children: O.label | ||
@@ -302,43 +319,43 @@ }, | ||
| )) }) | ||
| ] }) : p.type === "inline-menu" ? /* @__PURE__ */ h( | ||
| ] }) : v.type === "inline-menu" ? /* @__PURE__ */ h( | ||
| "button", | ||
| { | ||
| ref: N(H), | ||
| ref: F(I), | ||
| className: "rte-toolbar-button", | ||
| "data-command": H, | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), x(); | ||
| O.preventDefault(), C(); | ||
| }, | ||
| onClick: () => _(H), | ||
| onClick: () => P(I), | ||
| disabled: n, | ||
| title: p.label, | ||
| children: U(p.icon) | ||
| title: v.label, | ||
| children: X(v.icon) | ||
| } | ||
| ) : p.type === "input" ? /* @__PURE__ */ h( | ||
| ) : v.type === "input" ? /* @__PURE__ */ h( | ||
| "input", | ||
| { | ||
| type: "text", | ||
| className: `rte-toolbar-input ${p.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| placeholder: p.placeholder, | ||
| onChange: (O) => I(H, O.target.value), | ||
| className: `rte-toolbar-input ${v.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| placeholder: v.placeholder, | ||
| onChange: (O) => _(I, O.target.value), | ||
| disabled: n, | ||
| onKeyDown: (O) => { | ||
| O.key === "Enter" && I( | ||
| H, | ||
| O.key === "Enter" && _( | ||
| I, | ||
| O.target.value | ||
| ); | ||
| }, | ||
| title: p.label | ||
| title: v.label | ||
| } | ||
| ) : p.type === "group" ? /* @__PURE__ */ h( | ||
| ) : v.type === "group" ? /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-button ${p.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${p.label}`, | ||
| className: `rte-toolbar-group-button ${v.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${v.label}`, | ||
| children: /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-items ${p.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: Z(p.items || [], !1) | ||
| className: `rte-toolbar-group-items ${v.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: Z(v.items || [], !1) | ||
| } | ||
@@ -351,17 +368,17 @@ ) | ||
| className: "rte-toolbar-button", | ||
| "data-command": H, | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), x(); | ||
| O.preventDefault(), C(); | ||
| }, | ||
| onClick: () => I(H), | ||
| onClick: () => _(I), | ||
| disabled: n, | ||
| title: p.label, | ||
| children: U(p.icon) | ||
| title: v.label, | ||
| children: X(v.icon) | ||
| } | ||
| ) | ||
| }, | ||
| q | ||
| U | ||
| ); | ||
| }), Re = r && C !== null ? v.filter((l, L) => L >= C) : []; | ||
| }), Re = r && y !== null ? p.filter((i, k) => k >= y) : []; | ||
| return /* @__PURE__ */ V(Y, { children: [ | ||
@@ -372,3 +389,3 @@ /* @__PURE__ */ V( | ||
| className: "rte-toolbar-wrapper", | ||
| style: J, | ||
| style: Le, | ||
| onMouseDownCapture: Te, | ||
@@ -381,5 +398,5 @@ children: [ | ||
| className: "rte-toolbar-items-container", | ||
| ref: T, | ||
| ref: L, | ||
| style: r ? void 0 : { flexWrap: "wrap" }, | ||
| children: Z(v) | ||
| children: Z(p) | ||
| } | ||
@@ -390,8 +407,8 @@ ), | ||
| { | ||
| ref: B, | ||
| className: `rte-toolbar-more-button ${M ? "active" : ""}`, | ||
| onMouseDown: (l) => { | ||
| l.preventDefault(), x(); | ||
| ref: z, | ||
| className: `rte-toolbar-more-button ${T ? "active" : ""}`, | ||
| onMouseDown: (i) => { | ||
| i.preventDefault(), C(); | ||
| }, | ||
| onClick: () => i(!M), | ||
| onClick: () => l(!T), | ||
| disabled: n, | ||
@@ -404,19 +421,19 @@ title: "Show more options", | ||
| ] }), | ||
| ue && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${M ? "show" : ""}`, children: Z(Re, !1) }) | ||
| ue && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${T ? "show" : ""}`, children: Z(Re, !1) }) | ||
| ] | ||
| } | ||
| ), | ||
| v.map((l) => { | ||
| if (l.type === "inline-menu") { | ||
| const L = l.command || ""; | ||
| p.map((i) => { | ||
| if (i.type === "inline-menu") { | ||
| const k = i.command || ""; | ||
| return /* @__PURE__ */ h( | ||
| Oe, | ||
| { | ||
| isOpen: m === L, | ||
| options: l.options || [], | ||
| onSelect: (p) => P(L, p), | ||
| isOpen: m === k, | ||
| options: i.options || [], | ||
| onSelect: (v) => q(k, v), | ||
| onClose: () => s(null), | ||
| anchorRef: N(L) | ||
| anchorRef: F(k) | ||
| }, | ||
| `menu-${L || "unknown"}` | ||
| `menu-${k || "unknown"}` | ||
| ); | ||
@@ -428,5 +445,5 @@ } | ||
| }; | ||
| function $e(e, t) { | ||
| const a = A(), o = A(""); | ||
| return W(() => { | ||
| function Ue(e, t) { | ||
| const a = x(), o = x(""); | ||
| return B(() => { | ||
| if (!t?.enabled) return; | ||
@@ -473,3 +490,3 @@ const r = t.intervalMs || 3e4, f = t.storageKey || "rte-autosave", d = t.provider || "localStorage", c = async () => { | ||
| } | ||
| const Ue = [ | ||
| const qe = [ | ||
| "p", | ||
@@ -512,3 +529,3 @@ "br", | ||
| "hr" | ||
| ], qe = { | ||
| ], Ke = { | ||
| "*": ["class", "style", "id", "data-*"], | ||
@@ -526,3 +543,3 @@ a: ["href", "target", "rel", "title"], | ||
| return e; | ||
| const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ue, r = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : qe, f = document.createElement("div"); | ||
| const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : qe, r = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ke, f = document.createElement("div"); | ||
| return f.innerHTML = e, Se(f, o, r), f.innerHTML; | ||
@@ -541,3 +558,3 @@ } | ||
| } | ||
| Ke(r, a), Se(r, t, a); | ||
| Ve(r, a), Se(r, t, a); | ||
| } else { | ||
@@ -549,3 +566,3 @@ if (n.nodeType === Node.TEXT_NODE) | ||
| } | ||
| function Ke(e, t) { | ||
| function Ve(e, t) { | ||
| const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), n = t[a] || [], r = t["*"] || [], f = [...n, ...r]; | ||
@@ -558,4 +575,4 @@ for (const d of o) { | ||
| if (s.endsWith("*")) { | ||
| const C = s.slice(0, -1); | ||
| if (c.startsWith(C)) { | ||
| const y = s.slice(0, -1); | ||
| if (c.startsWith(y)) { | ||
| m = !0; | ||
@@ -570,3 +587,3 @@ break; | ||
| } | ||
| function Ve(e, t, a) { | ||
| function je(e, t, a) { | ||
| return a?.sanitizeOnPaste === !1 ? e : ke(e, t); | ||
@@ -580,3 +597,3 @@ } | ||
| e.classList.toggle("rte-content-empty", o); | ||
| }, le = "data-rte-caret-marker", ce = "data-rte-range-start-marker", se = "data-rte-range-end-marker", re = () => Math.random().toString(36).slice(2), je = (e) => { | ||
| }, le = "data-rte-caret-marker", ce = "data-rte-range-start-marker", se = "data-rte-range-end-marker", re = () => Math.random().toString(36).slice(2), Ge = (e) => { | ||
| const t = window.getSelection(); | ||
@@ -611,3 +628,3 @@ if (!t || t.rangeCount === 0) return null; | ||
| } : { node: e, offset: e.childNodes.length }; | ||
| }, Ge = (e) => { | ||
| }, Xe = (e) => { | ||
| const t = window.getSelection(); | ||
@@ -617,7 +634,7 @@ if (!t || t.rangeCount === 0) return null; | ||
| if (!e.contains(a.commonAncestorContainer)) return null; | ||
| const o = je(e); | ||
| const o = Ge(e); | ||
| try { | ||
| if (a.collapsed) { | ||
| const s = re(), C = document.createElement("span"); | ||
| return C.setAttribute(le, s), C.appendChild(document.createTextNode("")), a.cloneRange().insertNode(C), { collapsed: !0, caretId: s, fallbackOffsets: o }; | ||
| const s = re(), y = document.createElement("span"); | ||
| return y.setAttribute(le, s), y.appendChild(document.createTextNode("")), a.cloneRange().insertNode(y), { collapsed: !0, caretId: s, fallbackOffsets: o }; | ||
| } | ||
@@ -635,7 +652,7 @@ const n = re(), r = re(), f = document.createElement("span"); | ||
| } | ||
| }, Xe = (e) => { | ||
| }, Je = (e) => { | ||
| e.querySelectorAll( | ||
| `[${le}], [${ce}], [${se}]` | ||
| ).forEach((t) => t.remove()); | ||
| }, Je = (e, t) => { | ||
| }, Qe = (e, t) => { | ||
| if (!t) return !1; | ||
@@ -658,3 +675,3 @@ const a = window.getSelection(); | ||
| return !1; | ||
| }, Qe = (e, t) => { | ||
| }, Ye = (e, t) => { | ||
| if (!t) return; | ||
@@ -668,3 +685,3 @@ const a = window.getSelection(); | ||
| } | ||
| }, Ye = ({ | ||
| }, Ze = ({ | ||
| editor: e, | ||
@@ -681,62 +698,62 @@ defaultValue: t, | ||
| accessibilityConfig: s, | ||
| autosaveConfig: C, | ||
| contextMenuConfig: S, | ||
| spellcheckConfig: M | ||
| autosaveConfig: y, | ||
| contextMenuConfig: A, | ||
| spellcheckConfig: T | ||
| }) => { | ||
| const i = A(null), F = a !== void 0, D = A(), w = d?.autoHeight === !0, b = typeof d?.minHeight == "number" ? d.minHeight : 200, g = typeof d?.maxHeight == "number" ? d.maxHeight : 0, T = (u) => { | ||
| const l = x(null), H = a !== void 0, N = x(), w = d?.autoHeight === !0, b = typeof d?.minHeight == "number" ? d.minHeight : 200, g = typeof d?.maxHeight == "number" ? d.maxHeight : 0, L = (u) => { | ||
| if (!u || !w) return; | ||
| u.style.height = "auto"; | ||
| const E = Math.max(b, u.scrollHeight); | ||
| const S = Math.max(b, u.scrollHeight); | ||
| if (g > 0) { | ||
| u.style.height = `${Math.min(E, g)}px`; | ||
| u.style.height = `${Math.min(S, g)}px`; | ||
| return; | ||
| } | ||
| u.style.height = `${E}px`; | ||
| }, { restore: B } = $e( | ||
| () => i.current?.innerHTML || "", | ||
| C | ||
| u.style.height = `${S}px`; | ||
| }, { restore: z } = Ue( | ||
| () => l.current?.innerHTML || "", | ||
| y | ||
| ); | ||
| W(() => { | ||
| if (!i.current) return; | ||
| const u = B(), E = u ?? a ?? t ?? ""; | ||
| E.trim() ? i.current.innerHTML !== E && (i.current.innerHTML = E) : n ? i.current.innerHTML = "" : i.current.innerHTML.trim() || (i.current.innerHTML = "<p><br></p>"), G(i.current, n), T(i.current), u && r && r(u); | ||
| }, []), W(() => { | ||
| !i.current || !F || (a !== i.current.innerHTML && (i.current.innerHTML = a), G(i.current, n), T(i.current)); | ||
| }, [a, F]), W(() => { | ||
| if (!i.current) return; | ||
| const u = i.current; | ||
| B(() => { | ||
| if (!l.current) return; | ||
| const u = z(), S = u ?? a ?? t ?? ""; | ||
| S.trim() ? l.current.innerHTML !== S && (l.current.innerHTML = S) : n ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), G(l.current, n), L(l.current), u && r && r(u); | ||
| }, []), B(() => { | ||
| !l.current || !H || (a !== l.current.innerHTML && (l.current.innerHTML = a), G(l.current, n), L(l.current)); | ||
| }, [a, H]), B(() => { | ||
| if (!l.current) return; | ||
| const u = l.current; | ||
| if (n) { | ||
| u.setAttribute("data-placeholder", n), Q(u) && (u.innerHTML = ""), G(u, n), T(u); | ||
| u.setAttribute("data-placeholder", n), Q(u) && (u.innerHTML = ""), G(u, n), L(u); | ||
| return; | ||
| } | ||
| u.removeAttribute("data-placeholder"), G(u, n), T(u); | ||
| }, [n]), W(() => { | ||
| if (!i.current) return; | ||
| const u = i.current; | ||
| u.removeAttribute("data-placeholder"), G(u, n), L(u); | ||
| }, [n]), B(() => { | ||
| if (!l.current) return; | ||
| const u = l.current; | ||
| if (s?.enableARIA !== !1) { | ||
| u.setAttribute("role", "textbox"), u.setAttribute("aria-multiline", "true"), u.setAttribute("aria-disabled", o ? "true" : "false"); | ||
| const z = n?.trim(); | ||
| z ? u.setAttribute("aria-label", z) : u.removeAttribute("aria-label"); | ||
| const W = n?.trim(); | ||
| W ? u.setAttribute("aria-label", W) : u.removeAttribute("aria-label"); | ||
| } else | ||
| u.removeAttribute("role"), u.removeAttribute("aria-multiline"), u.removeAttribute("aria-label"), u.removeAttribute("aria-disabled"); | ||
| }, [s?.enableARIA, n, o]), W(() => { | ||
| T(i.current); | ||
| }, [w, b, g, a]), W(() => { | ||
| if (!i.current) return; | ||
| }, [s?.enableARIA, n, o]), B(() => { | ||
| L(l.current); | ||
| }, [w, b, g, a]), B(() => { | ||
| if (!l.current) return; | ||
| const u = () => { | ||
| if (!i.current || o) return; | ||
| n && Q(i.current) && (i.current.innerHTML = ""); | ||
| let R = i.current.innerHTML; | ||
| if (!l.current || o) return; | ||
| n && Q(l.current) && (l.current.innerHTML = ""); | ||
| let R = l.current.innerHTML; | ||
| if (c?.sanitizeOnInput !== !1 && d?.sanitize !== !1) { | ||
| const N = ve(R, d, c); | ||
| if (N !== i.current.innerHTML) { | ||
| const I = Ge(i.current), $ = i.current.innerHTML, _ = ve($, d, c); | ||
| i.current.innerHTML = _, Je(i.current, I) || Qe(i.current, I?.fallbackOffsets || null), Xe(i.current), R = i.current.innerHTML; | ||
| const M = ve(R, d, c); | ||
| if (M !== l.current.innerHTML) { | ||
| const F = Xe(l.current), _ = l.current.innerHTML, $ = ve(_, d, c); | ||
| l.current.innerHTML = $, Qe(l.current, F) || Ye(l.current, F?.fallbackOffsets || null), Je(l.current), R = l.current.innerHTML; | ||
| } else | ||
| R = N; | ||
| R = M; | ||
| } | ||
| G(i.current, n), T(i.current), r && (m?.debounceInputMs ? (D.current && clearTimeout(D.current), D.current = setTimeout(() => { | ||
| G(l.current, n), L(l.current), r && (m?.debounceInputMs ? (N.current && clearTimeout(N.current), N.current = setTimeout(() => { | ||
| r(R); | ||
| }, m.debounceInputMs)) : r(R)); | ||
| }, E = (R) => { | ||
| }, S = (R) => { | ||
| if (o) { | ||
@@ -747,52 +764,52 @@ R.preventDefault(); | ||
| R.preventDefault(); | ||
| let N = R.clipboardData?.getData("text/html"); | ||
| const I = R.clipboardData?.getData("text/plain"), $ = !!N && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(N); | ||
| let M = R.clipboardData?.getData("text/html"); | ||
| const F = R.clipboardData?.getData("text/plain"), _ = !!M && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(M); | ||
| if (f?.clean || !f?.keepFormatting) { | ||
| I && document.execCommand("insertText", !1, I); | ||
| F && document.execCommand("insertText", !1, F); | ||
| return; | ||
| } | ||
| if (f?.convertWord === !1 && $) { | ||
| I && document.execCommand("insertText", !1, I); | ||
| if (f?.convertWord === !1 && _) { | ||
| F && document.execCommand("insertText", !1, F); | ||
| return; | ||
| } | ||
| if (N) { | ||
| c?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (N = Ve(N, d, c)); | ||
| const _ = window.getSelection(); | ||
| if (_ && _.rangeCount > 0) { | ||
| const P = _.getRangeAt(0); | ||
| if (M) { | ||
| c?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (M = je(M, d, c)); | ||
| const $ = window.getSelection(); | ||
| if ($ && $.rangeCount > 0) { | ||
| const P = $.getRangeAt(0); | ||
| P.deleteContents(); | ||
| const U = document.createElement("div"); | ||
| U.innerHTML = N; | ||
| const J = document.createDocumentFragment(); | ||
| for (; U.firstChild; ) | ||
| J.appendChild(U.firstChild); | ||
| P.insertNode(J), P.collapse(!1), _.removeAllRanges(), _.addRange(P); | ||
| const q = document.createElement("div"); | ||
| q.innerHTML = M; | ||
| const X = document.createDocumentFragment(); | ||
| for (; q.firstChild; ) | ||
| X.appendChild(q.firstChild); | ||
| P.insertNode(X), P.collapse(!1), $.removeAllRanges(), $.addRange(P); | ||
| } | ||
| } else I && document.execCommand("insertText", !1, I); | ||
| }, z = (R) => { | ||
| const N = R.target; | ||
| (N.tagName === "IMG" || N.tagName === "VIDEO") && (N.style.resize = "both", N.style.overflow = "auto", N.style.display = "inline-block"); | ||
| }, y = (R) => { | ||
| S?.enabled === !1 && R.preventDefault(); | ||
| }, x = () => { | ||
| i.current && (n && Q(i.current) && (i.current.innerHTML = ""), G(i.current, n), T(i.current)); | ||
| }, k = i.current; | ||
| return k.addEventListener("input", u), k.addEventListener("paste", E), k.addEventListener("click", z), k.addEventListener("contextmenu", y), k.addEventListener("focus", x), k.addEventListener("blur", x), o || k.focus(), () => { | ||
| D.current && clearTimeout(D.current), k.removeEventListener("input", u), k.removeEventListener("paste", E), k.removeEventListener("click", z), k.removeEventListener("contextmenu", y), k.removeEventListener("focus", x), k.removeEventListener("blur", x); | ||
| } else F && document.execCommand("insertText", !1, F); | ||
| }, W = (R) => { | ||
| const M = R.target; | ||
| (M.tagName === "IMG" || M.tagName === "VIDEO") && (M.style.resize = "both", M.style.overflow = "auto", M.style.display = "inline-block"); | ||
| }, E = (R) => { | ||
| A?.enabled === !1 && R.preventDefault(); | ||
| }, D = () => { | ||
| l.current && (n && Q(l.current) && (l.current.innerHTML = ""), G(l.current, n), L(l.current)); | ||
| }, C = l.current; | ||
| return C.addEventListener("input", u), C.addEventListener("paste", S), C.addEventListener("click", W), C.addEventListener("contextmenu", E), C.addEventListener("focus", D), C.addEventListener("blur", D), o || C.focus(), () => { | ||
| N.current && clearTimeout(N.current), C.removeEventListener("input", u), C.removeEventListener("paste", S), C.removeEventListener("click", W), C.removeEventListener("contextmenu", E), C.removeEventListener("focus", D), C.removeEventListener("blur", D); | ||
| }; | ||
| }, [e, r, f, d, c, m, n, S, o]); | ||
| const v = (M?.enabled ?? !1) && (M?.provider ?? "browser") === "browser"; | ||
| return W(() => { | ||
| if (!i.current || typeof window > "u" || o || s?.keyboardNavigation === !1) | ||
| }, [e, r, f, d, c, m, n, A, o]); | ||
| const p = (T?.enabled ?? !1) && (T?.provider ?? "browser") === "browser"; | ||
| return B(() => { | ||
| if (!l.current || typeof window > "u" || o || s?.keyboardNavigation === !1) | ||
| return; | ||
| const u = new Ee(), E = i.current, z = (y) => { | ||
| u.handleKeyDown(y, (x, k) => { | ||
| const u = new Ee(), S = l.current, W = (E) => { | ||
| u.handleKeyDown(E, (D, C) => { | ||
| if (typeof window < "u" && window.executeEditorCommand) { | ||
| const R = i.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = R || null, window.executeEditorCommand(x, k); | ||
| const R = l.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = R || null, window.executeEditorCommand(D, C); | ||
| } | ||
| }); | ||
| }; | ||
| return E.addEventListener("keydown", z), () => { | ||
| E.removeEventListener("keydown", z); | ||
| return S.addEventListener("keydown", W), () => { | ||
| S.removeEventListener("keydown", W); | ||
| }; | ||
@@ -802,6 +819,6 @@ }, [s?.keyboardNavigation, o]), /* @__PURE__ */ h( | ||
| { | ||
| ref: i, | ||
| ref: l, | ||
| contentEditable: !o, | ||
| suppressContentEditableWarning: !0, | ||
| spellCheck: o ? !1 : v, | ||
| spellCheck: o ? !1 : p, | ||
| tabIndex: s?.keyboardNavigation === !1 ? -1 : 0, | ||
@@ -830,3 +847,3 @@ "aria-keyshortcuts": s?.keyboardNavigation === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y", | ||
| ); | ||
| }, Ze = ({ | ||
| }, et = ({ | ||
| editor: e, | ||
@@ -837,4 +854,4 @@ isEnabled: t, | ||
| }) => { | ||
| const [n, r] = j(!1), [f, d] = j({ top: 0, left: 0 }), c = A(null), m = A(null), s = A(null), C = A(null), S = A(null); | ||
| W(() => { | ||
| const [n, r] = j(!1), [f, d] = j({ top: 0, left: 0 }), c = x(null), m = x(null), s = x(null), y = x(null), A = x(null); | ||
| B(() => { | ||
| if (!t || o) { | ||
@@ -844,29 +861,29 @@ r(!1); | ||
| } | ||
| S.current = c.current?.closest("[data-editora-editor]"); | ||
| const i = (v) => { | ||
| if (S.current) return S.current; | ||
| A.current = c.current?.closest("[data-editora-editor]"); | ||
| const l = (p) => { | ||
| if (A.current) return A.current; | ||
| const u = c.current?.closest("[data-editora-editor]"); | ||
| if (u) | ||
| return S.current = u, u; | ||
| const E = v?.commonAncestorContainer, y = (E ? E.nodeType === Node.ELEMENT_NODE ? E : E.parentElement : null)?.closest("[data-editora-editor]"); | ||
| return y ? (S.current = y, y) : null; | ||
| }, F = (v) => v && v.querySelector(".rte-content, .editora-content") || null, D = (v) => { | ||
| if (!v.anchorNode || !v.focusNode) return !1; | ||
| return A.current = u, u; | ||
| const S = p?.commonAncestorContainer, E = (S ? S.nodeType === Node.ELEMENT_NODE ? S : S.parentElement : null)?.closest("[data-editora-editor]"); | ||
| return E ? (A.current = E, E) : null; | ||
| }, H = (p) => p && p.querySelector(".rte-content, .editora-content") || null, N = (p) => { | ||
| if (!p.anchorNode || !p.focusNode) return !1; | ||
| try { | ||
| const u = document.createRange(); | ||
| return u.setStart(v.anchorNode, v.anchorOffset), u.setEnd(v.focusNode, v.focusOffset), u.collapsed; | ||
| return u.setStart(p.anchorNode, p.anchorOffset), u.setEnd(p.focusNode, p.focusOffset), u.collapsed; | ||
| } catch { | ||
| return !1; | ||
| } | ||
| }, w = (v, u) => { | ||
| const E = Array.from(u.getClientRects()).filter((y) => y.width > 0 || y.height > 0); | ||
| return E.length === 0 ? u.getBoundingClientRect() : D(v) ? E[0] : E[E.length - 1]; | ||
| }, w = (p, u) => { | ||
| const S = Array.from(u.getClientRects()).filter((E) => E.width > 0 || E.height > 0); | ||
| return S.length === 0 ? u.getBoundingClientRect() : N(p) ? S[0] : S[S.length - 1]; | ||
| }, b = () => { | ||
| C.current && clearTimeout(C.current); | ||
| const v = window.getSelection(); | ||
| if (!v || v.rangeCount === 0) { | ||
| y.current && clearTimeout(y.current); | ||
| const p = window.getSelection(); | ||
| if (!p || p.rangeCount === 0) { | ||
| r(!1), s.current = null; | ||
| return; | ||
| } | ||
| const u = v.getRangeAt(0); | ||
| const u = p.getRangeAt(0); | ||
| if (u.collapsed) { | ||
@@ -876,4 +893,4 @@ r(!1), s.current = null; | ||
| } | ||
| const E = v.toString().trim(), z = i(u), y = F(z); | ||
| if (!y || !y.contains(u.commonAncestorContainer)) { | ||
| const S = p.toString().trim(), W = l(u), E = H(W); | ||
| if (!E || !E.contains(u.commonAncestorContainer)) { | ||
| r(!1), s.current = null; | ||
@@ -883,4 +900,4 @@ return; | ||
| if (a) { | ||
| const x = y.getBoundingClientRect(), k = x.bottom >= 0 && x.top <= window.innerHeight, R = document.activeElement === y || y.contains(document.activeElement); | ||
| if (!k && !R) { | ||
| const D = E.getBoundingClientRect(), C = D.bottom >= 0 && D.top <= window.innerHeight, R = document.activeElement === E || E.contains(document.activeElement); | ||
| if (!C && !R) { | ||
| r(!1), s.current = null; | ||
@@ -890,29 +907,29 @@ return; | ||
| } | ||
| if (E.length > 0) { | ||
| const x = w(v, u), k = y.getBoundingClientRect(), R = 300; | ||
| if (x && k) { | ||
| const N = Math.max(8, x.top - 50); | ||
| let I = x.left + x.width / 2; | ||
| const $ = R / 2, _ = k.left, P = k.right; | ||
| I - $ < _ && (I = _ + $ + 10), I + $ > P && (I = P - $ - 10), d({ top: N, left: I }), r(!0), s.current = u.cloneRange(); | ||
| if (S.length > 0) { | ||
| const D = w(p, u), C = E.getBoundingClientRect(), R = 300; | ||
| if (D && C) { | ||
| const M = Math.max(8, D.top - 50); | ||
| let F = D.left + D.width / 2; | ||
| const _ = R / 2, $ = C.left, P = C.right; | ||
| F - _ < $ && (F = $ + _ + 10), F + _ > P && (F = P - _ - 10), d({ top: M, left: F }), r(!0), s.current = u.cloneRange(); | ||
| } | ||
| } else | ||
| r(!1), s.current = null; | ||
| }, g = (v) => { | ||
| if (m.current && !m.current.contains(v.target)) { | ||
| const u = i(); | ||
| window.getSelection(), F(u)?.contains(v.target) || (r(!1), s.current = null); | ||
| }, g = (p) => { | ||
| if (m.current && !m.current.contains(p.target)) { | ||
| const u = l(); | ||
| window.getSelection(), H(u)?.contains(p.target) || (r(!1), s.current = null); | ||
| } | ||
| }, T = (v) => { | ||
| v.key === "Escape" && (r(!1), s.current = null); | ||
| }, B = F(i()); | ||
| return document.addEventListener("selectionchange", b), document.addEventListener("mousedown", g), document.addEventListener("keydown", T), B?.addEventListener("mouseup", b), B?.addEventListener("keyup", b), () => { | ||
| document.removeEventListener("selectionchange", b), document.removeEventListener("mousedown", g), document.removeEventListener("keydown", T), B?.removeEventListener("mouseup", b), B?.removeEventListener("keyup", b), C.current && clearTimeout(C.current); | ||
| }, L = (p) => { | ||
| p.key === "Escape" && (r(!1), s.current = null); | ||
| }, z = H(l()); | ||
| return document.addEventListener("selectionchange", b), document.addEventListener("mousedown", g), document.addEventListener("keydown", L), z?.addEventListener("mouseup", b), z?.addEventListener("keyup", b), () => { | ||
| document.removeEventListener("selectionchange", b), document.removeEventListener("mousedown", g), document.removeEventListener("keydown", L), z?.removeEventListener("mouseup", b), z?.removeEventListener("keyup", b), y.current && clearTimeout(y.current); | ||
| }; | ||
| }, [t, a, o]); | ||
| const M = (i, F) => { | ||
| const T = (l, H) => { | ||
| if (o || !s.current) return; | ||
| typeof window < "u" && (window.__editoraCommandEditorRoot = S.current || null); | ||
| const D = S.current?.querySelector(".rte-content"); | ||
| D && D.focus(); | ||
| typeof window < "u" && (window.__editoraCommandEditorRoot = A.current || null); | ||
| const N = A.current?.querySelector(".rte-content"); | ||
| N && N.focus(); | ||
| const w = window.getSelection(); | ||
@@ -938,16 +955,16 @@ if (w && s.current) | ||
| if (g && g.rangeCount > 0) { | ||
| const T = g.getRangeAt(0), B = document.createElement("code"); | ||
| T.surroundContents(B); | ||
| const L = g.getRangeAt(0), z = document.createElement("code"); | ||
| L.surroundContents(z); | ||
| } | ||
| }, | ||
| setBlockType: () => { | ||
| if (F === "blockquote") { | ||
| if (H === "blockquote") { | ||
| const g = window.getSelection(); | ||
| if (g && g.rangeCount > 0) { | ||
| const T = g.getRangeAt(0); | ||
| (T.commonAncestorContainer.nodeType === Node.TEXT_NODE ? T.commonAncestorContainer.parentElement : T.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote"); | ||
| const L = g.getRangeAt(0); | ||
| (L.commonAncestorContainer.nodeType === Node.TEXT_NODE ? L.commonAncestorContainer.parentElement : L.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote"); | ||
| } | ||
| } else F && document.execCommand("formatBlock", !1, F); | ||
| } else H && document.execCommand("formatBlock", !1, H); | ||
| } | ||
| })[i]?.(), r(!1), s.current = null; | ||
| })[l]?.(), r(!1), s.current = null; | ||
| }; | ||
@@ -961,3 +978,3 @@ return !t || o ? /* @__PURE__ */ h("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(Y, { children: [ | ||
| className: "floating-toolbar", | ||
| onMouseDown: (i) => i.preventDefault(), | ||
| onMouseDown: (l) => l.preventDefault(), | ||
| style: { | ||
@@ -976,3 +993,3 @@ position: "fixed", | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("toggleBold"), | ||
| onClick: () => T("toggleBold"), | ||
| title: "Bold (Ctrl+B)", | ||
@@ -986,3 +1003,3 @@ children: /* @__PURE__ */ h("strong", { children: "B" }) | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("toggleItalic"), | ||
| onClick: () => T("toggleItalic"), | ||
| title: "Italic (Ctrl+I)", | ||
@@ -996,3 +1013,3 @@ children: /* @__PURE__ */ h("em", { children: "I" }) | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("toggleUnderline"), | ||
| onClick: () => T("toggleUnderline"), | ||
| title: "Underline (Ctrl+U)", | ||
@@ -1006,3 +1023,3 @@ children: /* @__PURE__ */ h("u", { children: "U" }) | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("toggleStrikethrough"), | ||
| onClick: () => T("toggleStrikethrough"), | ||
| title: "Strikethrough", | ||
@@ -1017,3 +1034,3 @@ children: /* @__PURE__ */ h("s", { children: "S" }) | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("clearFormatting"), | ||
| onClick: () => T("clearFormatting"), | ||
| title: "Clear Formatting", | ||
@@ -1027,3 +1044,3 @@ children: "⌫" | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("createLink"), | ||
| onClick: () => T("createLink"), | ||
| title: "Insert Link", | ||
@@ -1037,3 +1054,3 @@ children: "🔗" | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("toggleCode"), | ||
| onClick: () => T("toggleCode"), | ||
| title: "Code", | ||
@@ -1048,3 +1065,3 @@ children: "Code" | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => M("setBlockType", "blockquote"), | ||
| onClick: () => T("setBlockType", "blockquote"), | ||
| title: "Quote", | ||
@@ -1058,3 +1075,3 @@ children: "❝" | ||
| ] }); | ||
| }, et = ({ | ||
| }, tt = ({ | ||
| plugins: e, | ||
@@ -1077,3 +1094,3 @@ children: t | ||
| }; | ||
| }, tt = (e, t) => { | ||
| }, nt = (e, t) => { | ||
| if (!Array.isArray(e)) return []; | ||
@@ -1107,3 +1124,3 @@ const a = Ae(t), o = [], n = []; | ||
| return o; | ||
| }, nt = (e, t, a) => { | ||
| }, rt = (e, t, a) => { | ||
| if (!t?.checker || e.some((r) => r?.name === "a11yChecker")) return e; | ||
@@ -1122,3 +1139,3 @@ const o = Ae(a).a11yChecker; | ||
| )), e; | ||
| }, rt = { | ||
| }, ot = { | ||
| readonly: !1, | ||
@@ -1209,4 +1226,4 @@ placeholder: "", | ||
| } | ||
| function ot(e) { | ||
| const t = xe(rt, { | ||
| function at(e) { | ||
| const t = xe(ot, { | ||
| readonly: e.readonly, | ||
@@ -1251,4 +1268,4 @@ placeholder: e.placeholder, | ||
| onDestroy: e.onDestroy, | ||
| plugins: nt( | ||
| tt(e.plugins, e.pluginConfig), | ||
| plugins: rt( | ||
| nt(e.plugins, e.pluginConfig), | ||
| e.accessibility, | ||
@@ -1260,3 +1277,11 @@ e.pluginConfig | ||
| } | ||
| const ie = /* @__PURE__ */ new Map(); | ||
| const ie = /* @__PURE__ */ new Map(), it = () => { | ||
| if (typeof window > "u") | ||
| return { editorElement: null, contentElement: null }; | ||
| const e = window.__editoraCommandEditorRoot || null, t = e?.querySelector('[contenteditable="true"]'); | ||
| return { | ||
| editorElement: e, | ||
| contentElement: t | ||
| }; | ||
| }; | ||
| typeof window < "u" && (window.registerEditorCommand = (e, t) => { | ||
@@ -1266,6 +1291,10 @@ ie.set(e, t); | ||
| const a = ie.get(e); | ||
| return a ? a(t) : (console.warn(`No handler registered for command: ${e}`), !1); | ||
| if (a) { | ||
| const o = it(); | ||
| return a(t, o); | ||
| } else | ||
| return console.warn(`No handler registered for command: ${e}`), !1; | ||
| }); | ||
| const at = (e) => { | ||
| const t = oe(() => ot(e), [ | ||
| const lt = (e) => { | ||
| const t = oe(() => at(e), [ | ||
| e.id, | ||
@@ -1293,7 +1322,7 @@ e.className, | ||
| e.mediaConfig | ||
| ]), a = A(null), o = A(null), n = A(e.onInit), r = A(e.onDestroy), f = A(e.onChange), d = A(/* @__PURE__ */ new Set()), c = A(null), m = A(null), s = A(null); | ||
| W(() => { | ||
| ]), a = x(null), o = x(null), n = x(e.onInit), r = x(e.onDestroy), f = x(e.onChange), d = x(/* @__PURE__ */ new Set()), c = x(null), m = x(null), s = x(null); | ||
| B(() => { | ||
| n.current = e.onInit, r.current = e.onDestroy, f.current = e.onChange; | ||
| }); | ||
| const C = (w) => { | ||
| const y = (w) => { | ||
| f.current?.(w), d.current.forEach((b) => { | ||
@@ -1306,13 +1335,13 @@ try { | ||
| }); | ||
| }, S = oe(() => { | ||
| const w = new Ne(); | ||
| }, A = oe(() => { | ||
| const w = new He(); | ||
| t.plugins.forEach((g) => { | ||
| w.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([T, B]) => { | ||
| ie.set(T, B); | ||
| w.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([L, z]) => { | ||
| ie.set(L, z); | ||
| }); | ||
| }); | ||
| const b = new He(w); | ||
| const b = new De(w); | ||
| return a.current = b, b; | ||
| }, [t.plugins]); | ||
| W(() => { | ||
| B(() => { | ||
| const w = { | ||
@@ -1347,3 +1376,3 @@ getHTML: () => c.current?.querySelector(".rte-content")?.innerHTML || "", | ||
| toolbar: { | ||
| items: S.toolbar?.items || [] | ||
| items: A.toolbar?.items || [] | ||
| } | ||
@@ -1354,5 +1383,5 @@ }; | ||
| }; | ||
| }, []), W(() => { | ||
| }, []), B(() => { | ||
| if (t.statusbar.enabled && s.current && c.current) { | ||
| m.current || (m.current = new De({ | ||
| m.current || (m.current = new Fe({ | ||
| enabled: !0, | ||
@@ -1364,30 +1393,30 @@ position: t.statusbar.position | ||
| const b = () => { | ||
| const y = document.activeElement; | ||
| return !!y && (y === w || w.contains(y)); | ||
| const E = document.activeElement; | ||
| return !!E && (E === w || w.contains(E)); | ||
| }, g = () => { | ||
| const y = w.getBoundingClientRect(); | ||
| return y.bottom >= 0 && y.top <= window.innerHeight; | ||
| }, T = () => { | ||
| const y = window.getSelection(); | ||
| if (!y || y.rangeCount === 0) return null; | ||
| const x = y.getRangeAt(0), k = x.commonAncestorContainer; | ||
| return w.contains(k) ? x : null; | ||
| }, B = (y = !1) => { | ||
| const E = w.getBoundingClientRect(); | ||
| return E.bottom >= 0 && E.top <= window.innerHeight; | ||
| }, L = () => { | ||
| const E = window.getSelection(); | ||
| if (!E || E.rangeCount === 0) return null; | ||
| const D = E.getRangeAt(0), C = D.commonAncestorContainer; | ||
| return w.contains(C) ? D : null; | ||
| }, z = (E = !1) => { | ||
| if (t.performance.viewportOnlyScan !== !1 && !g() && !b()) | ||
| return; | ||
| const k = T(), R = !!k || b(); | ||
| if (y && !R) | ||
| const C = L(), R = !!C || b(); | ||
| if (E && !R) | ||
| return; | ||
| const N = w.textContent || "", { words: I, chars: $ } = Fe(N), _ = Be(w); | ||
| let P, U; | ||
| k && (P = ze(w, k), k.collapsed || (U = We(k, P), P = void 0)), m.current?.update({ | ||
| wordCount: I, | ||
| charCount: $, | ||
| lineCount: _, | ||
| const M = w.textContent || "", { words: F, chars: _ } = Be(M), $ = ze(w); | ||
| let P, q; | ||
| C && (P = We(w, C), C.collapsed || (q = _e(C, P), P = void 0)), m.current?.update({ | ||
| wordCount: F, | ||
| charCount: _, | ||
| lineCount: $, | ||
| cursorPosition: P, | ||
| selectionInfo: U | ||
| selectionInfo: q | ||
| }); | ||
| }, v = () => B(), u = () => B(!0), E = () => B(), z = () => B(); | ||
| return w.addEventListener("input", v), w.addEventListener("focus", E), w.addEventListener("blur", z), document.addEventListener("selectionchange", u), B(), () => { | ||
| w.removeEventListener("input", v), w.removeEventListener("focus", E), w.removeEventListener("blur", z), document.removeEventListener("selectionchange", u); | ||
| }, p = () => z(), u = () => z(!0), S = () => z(), W = () => z(); | ||
| return w.addEventListener("input", p), w.addEventListener("focus", S), w.addEventListener("blur", W), document.addEventListener("selectionchange", u), z(), () => { | ||
| w.removeEventListener("input", p), w.removeEventListener("focus", S), w.removeEventListener("blur", W), document.removeEventListener("selectionchange", u); | ||
| }; | ||
@@ -1401,4 +1430,4 @@ } | ||
| }, [t.statusbar.enabled, t.statusbar.position, t.performance.viewportOnlyScan]); | ||
| const M = t.toolbar.floating ?? !1, i = t.toolbar.position || "top", F = t.toolbar.sticky ?? !1, D = t.toolbar.showMoreOptions ?? !0; | ||
| return /* @__PURE__ */ h(et, { plugins: t.plugins, children: /* @__PURE__ */ V( | ||
| const T = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", H = t.toolbar.sticky ?? !1, N = t.toolbar.showMoreOptions ?? !0; | ||
| return /* @__PURE__ */ h(tt, { plugins: t.plugins, children: /* @__PURE__ */ V( | ||
| "div", | ||
@@ -1419,11 +1448,11 @@ { | ||
| children: [ | ||
| i !== "bottom" && /* @__PURE__ */ h( | ||
| l !== "bottom" && /* @__PURE__ */ h( | ||
| we, | ||
| { | ||
| editor: S, | ||
| position: i, | ||
| sticky: F, | ||
| floating: M, | ||
| editor: A, | ||
| position: l, | ||
| sticky: H, | ||
| floating: T, | ||
| readonly: t.readonly, | ||
| showMoreOptions: D, | ||
| showMoreOptions: N, | ||
| itemsOverride: t.toolbar.items | ||
@@ -1433,5 +1462,5 @@ } | ||
| /* @__PURE__ */ h( | ||
| Ye, | ||
| Ze, | ||
| { | ||
| editor: S, | ||
| editor: A, | ||
| defaultValue: t.defaultValue, | ||
@@ -1441,3 +1470,3 @@ value: t.value, | ||
| placeholder: t.placeholder, | ||
| onChange: C, | ||
| onChange: y, | ||
| pasteConfig: t.paste, | ||
@@ -1453,11 +1482,11 @@ contentConfig: t.content, | ||
| ), | ||
| i === "bottom" && /* @__PURE__ */ h( | ||
| l === "bottom" && /* @__PURE__ */ h( | ||
| we, | ||
| { | ||
| editor: S, | ||
| position: i, | ||
| sticky: F, | ||
| floating: M, | ||
| editor: A, | ||
| position: l, | ||
| sticky: H, | ||
| floating: T, | ||
| readonly: t.readonly, | ||
| showMoreOptions: D, | ||
| showMoreOptions: N, | ||
| itemsOverride: t.toolbar.items | ||
@@ -1467,6 +1496,6 @@ } | ||
| /* @__PURE__ */ h( | ||
| Ze, | ||
| et, | ||
| { | ||
| editor: S, | ||
| isEnabled: M, | ||
| editor: A, | ||
| isEnabled: T, | ||
| viewportOnlyScan: t.performance.viewportOnlyScan, | ||
@@ -1487,8 +1516,8 @@ readonly: t.readonly | ||
| ) }); | ||
| }, ut = (e) => /* @__PURE__ */ h(at, { ...e }); | ||
| function dt(e = {}) { | ||
| const t = A(null), a = A(e.onCommand); | ||
| return W(() => { | ||
| }, ft = (e) => /* @__PURE__ */ h(lt, { ...e }); | ||
| function mt(e = {}) { | ||
| const t = x(null), a = x(e.onCommand); | ||
| return B(() => { | ||
| a.current = e.onCommand; | ||
| }), W(() => { | ||
| }), B(() => { | ||
| if (typeof window > "u" || e.enabled === !1) return; | ||
@@ -1513,9 +1542,9 @@ const o = new Ee(e); | ||
| export { | ||
| Ye as EditorContent, | ||
| ut as EditoraEditor, | ||
| Ze as EditorContent, | ||
| ft as EditoraEditor, | ||
| Oe as InlineMenu, | ||
| ut as RichTextEditor, | ||
| ft as RichTextEditor, | ||
| we as Toolbar, | ||
| ot as mergeConfig, | ||
| dt as useKeyboardShortcuts | ||
| at as mergeConfig, | ||
| mt as useKeyboardShortcuts | ||
| }; |
+6
-6
| { | ||
| "name": "@editora/react", | ||
| "version": "1.0.8", | ||
| "version": "1.0.9", | ||
| "description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.", | ||
@@ -61,5 +61,5 @@ "author": "Ajay Kumar <ajaykr089@gmail.com>", | ||
| "peerDependencies": { | ||
| "@editora/core": "^1.0.6", | ||
| "@editora/plugins": "^1.0.7", | ||
| "@editora/themes": "^1.0.7", | ||
| "@editora/core": "^1.0.7", | ||
| "@editora/plugins": "^1.0.8", | ||
| "@editora/themes": "^1.0.8", | ||
| "react": ">=16.8 <21", | ||
@@ -77,6 +77,6 @@ "react-dom": ">=16.8 <21" | ||
| "dependencies": { | ||
| "@editora/light-code-editor": "^1.0.5" | ||
| "@editora/light-code-editor": "^1.0.6" | ||
| }, | ||
| "devDependencies": { | ||
| "@editora/core": "^1.0.6", | ||
| "@editora/core": "^1.0.7", | ||
| "@types/react": "^18.2.0", | ||
@@ -83,0 +83,0 @@ "@types/react-dom": "^18.2.0", |
102944
1.81%1783
1.83%