@editora/react
Advanced tools
+21
| MIT License | ||
| Copyright (c) 2026 Ajay Kumar | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -1,1 +0,1 @@ | ||
| "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; | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react/jsx-runtime"),c=require("react"),q=require("@editora/core"),Ne=e=>e&&e.__esModule?e:{default:e},je=Ne(c),pe=({isOpen:e,options:t,onSelect:a,onClose:o,anchorRef:r,className:n=""})=>{const m=c.useRef(null),[g,u]=c.useState(null),h=()=>{if(!e||!r.current)return;const l=r.current.getBoundingClientRect(),L=m.current?.getBoundingClientRect(),R=L?.width||120,T=L?.height||t.length*36,s=8,D=4,I=window.innerWidth,p=window.innerHeight;let E=l.bottom+D,b=l.left;b+R>I-s&&(b=I-R-s),b<s&&(b=s),E+T>p-s&&(E=l.top-T-D),E<s&&(E=s),u({top:E,left:b})};return c.useLayoutEffect(()=>{if(!e){u(null);return}h();const l=window.requestAnimationFrame(h);return()=>{window.cancelAnimationFrame(l)}},[e,t.length,r]),c.useEffect(()=>{if(!e)return;const l=()=>{h()};return window.addEventListener("resize",l),window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("resize",l),window.removeEventListener("scroll",l,!0)}},[e,t.length,r]),c.useEffect(()=>{const l=R=>{m.current&&!m.current.contains(R.target)&&r.current&&!r.current.contains(R.target)&&o()},L=R=>{R.key==="Escape"&&o()};return e&&(document.addEventListener("mousedown",l),document.addEventListener("keydown",L)),()=>{document.removeEventListener("mousedown",l),document.removeEventListener("keydown",L)}},[e,o,r]),e?d.jsx("div",{ref:m,className:`rte-inline-menu ${n}`,style:{top:g?.top??-9999,left:g?.left??-9999,visibility:g?"visible":"hidden"},children:t.map(l=>d.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{a(l.value),o()},children:l.label},l.value))}):null},X=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),De={undo:"undo",redo:"redo",bold:"toggleBold",italic:"toggleItalic",underline:"toggleUnderline",strikethrough:"toggleStrikethrough",textcolor:"openTextColorPicker",backgroundcolor:"openBackgroundColorPicker",fontsize:"setFontSize",increasefontsize:"increaseFontSize",decreasefontsize:"decreaseFontSize",heading:"setHeading",paragraph:"setHeading",textalignment:"setTextAlignment",direction:"setDirectionLTR",bullist:"toggleBulletList",numlist:"toggleOrderedList",checklist:"toggleChecklist",indent:"increaseIndent",outdent:"decreaseIndent",link:"openLinkDialog",image:"insertImage",video:"insertVideo",table:"insertTable",trackchanges:"toggleTrackChanges",accepttrackchanges:"acceptAllTrackChanges",rejecttrackchanges:"rejectAllTrackChanges",clearformatting:"clearFormatting",databinding:"openDataBindingDialog",databindingpreview:"openDataBindingDialog"},He=(e,t)=>{if(!Array.isArray(t)||t.length===0)return e;if(!t.every(u=>typeof u=="string"))return t;const o=new Map,r=new Map;e.forEach(u=>{o.set(X(u.command||""),u),r.set(X(u.label||""),u)});const n=t.flatMap(u=>u.split(/\s+/)).map(u=>u.trim()).filter(Boolean),m=[];let g=0;return n.forEach(u=>{if(u==="|"){g+=1,m.push({type:"separator",command:`__separator__${g}`,label:"|"});return}const h=X(u),l=De[h],L=o.get(h)||(l?o.get(X(l)):void 0)||r.get(h)||e.find(R=>X(R.command||"").includes(h));L&&m.push(L)}),m.length>0?m:e},ne=({editor:e,position:t="top",sticky:a=!1,floating:o=!1,readonly:r=!1,showMoreOptions:n=!0,itemsOverride:m})=>{const[g,u]=c.useState(!1),[h,l]=c.useState(null),[L,R]=c.useState(null),[T,s]=c.useState(null),[D,I]=c.useState(!1),p=c.useRef(null),E=c.useRef(null),b=c.useRef({}),M=c.useRef([]),N=c.useRef(null),F=c.useRef(null),w=c.useRef(null),f=c.useMemo(()=>He(e.pluginManager.getToolbarItems(),m),[e,m]),C=i=>{p.current=i,i&&!i.collapsed&&(E.current=i)},x=()=>N.current?.closest("[data-editora-editor]")?.querySelector(".rte-content")||null,_=()=>{if(typeof window>"u")return;const i=N.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=i||null},y=i=>{if(typeof window>"u"||!i)return;const k=i.getAttribute("data-command");k&&(window.__editoraLastCommandButton=i,window.__editoraLastCommand=k)},A=()=>{const i=x();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},S=()=>{const i=A();i&&C(i)};c.useEffect(()=>{const i=N.current?.closest("[data-editora-editor]");if(!i)return;const k=i.querySelector(".rte-content, .editora-content");u(k?.getAttribute("data-track-changes")==="true");const v=W=>{u(!!W.detail?.enabled)};return i.addEventListener("editora:track-changes-toggle",v),()=>{i.removeEventListener("editora:track-changes-toggle",v)}},[]),c.useEffect(()=>{const i=()=>{S()};return document.addEventListener("selectionchange",i),()=>{document.removeEventListener("selectionchange",i)}},[]),c.useEffect(()=>{if(!h)return;const i=v=>{const W=v.target;W&&W instanceof Element&&(W.closest(".rte-toolbar-dropdown")||l(null))},k=v=>{v.key==="Escape"&&l(null)};return document.addEventListener("pointerdown",i,!0),document.addEventListener("keydown",k),()=>{document.removeEventListener("pointerdown",i,!0),document.removeEventListener("keydown",k)}},[h]);const z=i=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(i),$=(i=!1)=>{const k=x();if(!k)return!1;const v=window.getSelection();if(!v)return!1;const W=v.rangeCount>0&&k.contains(v.getRangeAt(0).commonAncestorContainer),j=i?E.current||p.current:p.current||E.current;if(i&&j&&j.collapsed)return!1;if(j&&k.contains(j.commonAncestorContainer))try{return k.focus({preventScroll:!0}),v.removeAllRanges(),v.addRange(j),!0}catch{}return W};c.useEffect(()=>{if(!n){s(null),I(!1),M.current=[];return}let i=null;const k=()=>{if(!N.current||!F.current)return;const j=N.current.clientWidth,U=16,O=40,J=4,Ie=Math.max(0,j-U-O-J);let ue=0,de=0;const Z=F.current.children;for(let K=0;K<Z.length;K++){const ee=Z[K].getBoundingClientRect().width;ee>0&&(M.current[K]=ee);const me=M.current[K]??ee,ge=(me>0?me:40)+J;if(ue+ge<=Ie)ue+=ge,de++;else break}const fe=Math.max(1,Math.min(de,Z.length));s(K=>K===fe?K:fe)},v=()=>{i!==null&&cancelAnimationFrame(i),i=requestAnimationFrame(k)};M.current=[],v();const W=new ResizeObserver(()=>{v()});return N.current&&W.observe(N.current),F.current&&W.observe(F.current),()=>{i!==null&&cancelAnimationFrame(i),W.disconnect()}},[f.length,n]),c.useEffect(()=>{D&&T!==null&&T>=f.length&&I(!1)},[D,T,f.length]);const B=i=>(b.current[i]||(b.current[i]=je.default.createRef()),b.current[i]),H=(i,k)=>{if(r)return;_(),i==="addComment"||i==="toggleComments"||$(z(i));const j={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[i];if(j){document.execCommand(j,!1),l(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(i,k),l(null)},P=i=>{r||(S(),l(h===i?null:i))},V=i=>{r||(S(),R(L===i?null:i),l(null))},Ae=(i,k)=>{r||($(),H(i,k),C(null),E.current=null,R(null))},le=(i,k)=>i&&i.startsWith("<svg")&&i.endsWith("</svg>")?d.jsx("span",{dangerouslySetInnerHTML:{__html:i}}):i&&i.length===1&&/^[BIUSH]$/.test(i)?d.jsx("span",{style:{fontWeight:"bold",fontSize:"14px",lineHeight:"1"},children:i}):i||"⚪",Te={...a&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},ce=n&&T!==null&&T<f.length,Le=i=>{if(r)return;const k=i.target;k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")&&(y(k.closest("[data-command]")),_(),S(),i.preventDefault())},Y=(i,k=!0)=>i.map((v,W)=>{const j=v.command||"",U=j==="toggleTrackChanges"&&g;return d.jsx("div",{className:"rte-toolbar-item",style:{display:k&&n&&T!==null&&W>=T?"none":"flex"},children:v.type==="separator"?d.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):v.type==="dropdown"?d.jsxs("div",{className:"rte-toolbar-dropdown",children:[d.jsxs("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>P(j),disabled:r,children:[v.label," ▼"]}),h===j&&d.jsx("div",{className:"rte-toolbar-dropdown-menu",children:v.options?.map(O=>d.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:J=>J.preventDefault(),onClick:()=>H(j,O.value),children:O.label},O.value))})]}):v.type==="inline-menu"?d.jsx("button",{ref:B(j),className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>V(j),disabled:r,title:v.label,children:le(v.icon)}):v.type==="input"?d.jsx("input",{type:"text",className:`rte-toolbar-input ${v.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:v.placeholder,onChange:O=>H(j,O.target.value),disabled:r,onKeyDown:O=>{O.key==="Enter"&&H(j,O.target.value)},title:v.label}):v.type==="group"?d.jsx("div",{className:`rte-toolbar-group-button ${v.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${v.label}`,children:d.jsx("div",{className:`rte-toolbar-group-items ${v.label.toLowerCase().replace(/\s+/g,"-")}`,children:Y(v.items||[],!1)})}):d.jsx("button",{className:`rte-toolbar-button ${U?"active":""}`,"data-command":j,"data-active":U?"true":"false",onMouseDown:O=>{O.preventDefault(),S()},onClick:()=>H(j),disabled:r,title:v.label,children:le(v.icon)})},W)}),Me=n&&T!==null?f.filter((i,k)=>k>=T):[];return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"rte-toolbar-wrapper",style:Te,onMouseDownCapture:Le,children:[d.jsxs("div",{className:"rte-toolbar",ref:N,children:[d.jsx("div",{className:"rte-toolbar-items-container",ref:F,style:n?void 0:{flexWrap:"wrap"},children:Y(f)}),ce&&d.jsx("button",{ref:w,className:`rte-toolbar-more-button ${D?"active":""}`,onMouseDown:i=>{i.preventDefault(),S()},onClick:()=>I(!D),disabled:r,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),ce&&d.jsx("div",{className:`rte-toolbar-expanded-row ${D?"show":""}`,children:Y(Me,!1)})]}),f.map(i=>{if(i.type==="inline-menu"){const k=i.command||"";return d.jsx(pe,{isOpen:L===k,options:i.options||[],onSelect:v=>Ae(k,v),onClose:()=>R(null),anchorRef:B(k)},`menu-${k||"unknown"}`)}return null})]})};function Fe(e,t){const a=c.useRef(),o=c.useRef("");return c.useEffect(()=>{if(!t?.enabled)return;const n=t.intervalMs||3e4,m=t.storageKey||"rte-autosave",g=t.provider||"localStorage",u=async()=>{const h=e();if(h!==o.current){if(o.current=h,g==="localStorage")try{localStorage.setItem(m,h),localStorage.setItem(`${m}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(l){console.error("[Autosave] Failed to save to localStorage:",l)}else if(g==="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(l){console.error("[Autosave] Failed to save to API:",l)}}};return a.current=setInterval(u,n),()=>{a.current&&clearInterval(a.current)}},[t?.enabled,t?.intervalMs,t?.storageKey,t?.provider,t?.apiUrl,e]),{restore:()=>{if(!t?.enabled)return null;const n=t.storageKey||"rte-autosave";if((t.provider||"localStorage")==="localStorage")try{const g=localStorage.getItem(n),u=localStorage.getItem(`${n}-timestamp`);if(g&&u)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(u))),g}catch(g){console.error("[Autosave] Failed to restore from localStorage:",g)}return null}}}const _e=["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","section","sup","sub","hr"],Be={"*":["class","style","id","data-*","role","aria-*","tabindex","contenteditable","spellcheck"],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 ye(e,t,a){if(t?.sanitize===!1)return e;const o=t?.allowedTags&&t.allowedTags.length>0?t.allowedTags:_e,n=!!t?.allowedAttributes&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:Be,m=document.createElement("div");return m.innerHTML=e,Ee(m,o,n),m.innerHTML}function Ee(e,t,a){const o=Array.from(e.childNodes);for(const r of o)if(r.nodeType===Node.ELEMENT_NODE){const n=r,m=n.tagName.toLowerCase();if(!t.includes(m)){for(;n.firstChild;)e.insertBefore(n.firstChild,n);e.removeChild(n);continue}ze(n,a),Ee(n,t,a)}else{if(r.nodeType===Node.TEXT_NODE)continue;e.removeChild(r)}}function ze(e,t){const a=e.tagName.toLowerCase(),o=Array.from(e.attributes),r=t[a]||[],n=t["*"]||[],m=[...r,...n];for(const g of o){const u=g.name.toLowerCase();let h=!1;m.includes(u)&&(h=!0);for(const l of m)if(l.endsWith("*")){const L=l.slice(0,-1);if(u.startsWith(L)){h=!0;break}}(u.startsWith("on")||u==="javascript:"||u==="href"&&g.value.trim().toLowerCase().startsWith("javascript:")||u==="src"&&g.value.trim().toLowerCase().startsWith("javascript:"))&&(h=!1),h||e.removeAttribute(g.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 Oe(e,t,a){return a?.sanitizeOnPaste===!1?e:ye(e,t)}function he(e,t,a){return a?.sanitizeOnInput===!1?e:ye(e,t)}const Q=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),G=(e,t)=>{const o=!!t&&Q(e);e.classList.toggle("rte-content-empty",o)},ae="data-rte-caret-marker",ie="data-rte-range-start-marker",se="data-rte-range-end-marker",te=()=>Math.random().toString(36).slice(2),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;try{const o=a.cloneRange();o.selectNodeContents(e),o.setEnd(a.startContainer,a.startOffset);const r=a.cloneRange();return r.selectNodeContents(e),r.setEnd(a.endContainer,a.endOffset),{start:o.toString().length,end:r.toString().length}}catch{return null}},be=(e,t)=>{const a=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let o=a.nextNode(),r=Math.max(0,t),n=null;for(;o;){n=o;const m=o.textContent?.length??0;if(r<=m)return{node:o,offset:r};r-=m,o=a.nextNode()}return n?{node:n,offset:n.textContent?.length??0}:{node:e,offset:e.childNodes.length}},Pe=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=We(e);try{if(a.collapsed){const l=te(),L=document.createElement("span");return L.setAttribute(ae,l),L.appendChild(document.createTextNode("")),a.cloneRange().insertNode(L),{collapsed:!0,caretId:l,fallbackOffsets:o}}const r=te(),n=te(),m=document.createElement("span");m.setAttribute(se,n),m.appendChild(document.createTextNode(""));const g=document.createElement("span");g.setAttribute(ie,r),g.appendChild(document.createTextNode(""));const u=a.cloneRange();u.collapse(!1),u.insertNode(m);const h=a.cloneRange();return h.collapse(!0),h.insertNode(g),{collapsed:!1,startId:r,endId:n,fallbackOffsets:o}}catch{return{collapsed:a.collapsed,fallbackOffsets:o}}},$e=e=>{e.querySelectorAll(`[${ae}], [${ie}], [${se}]`).forEach(t=>t.remove())},qe=(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 r=e.querySelector(`[${ae}="${t.caretId}"]`);return!r||!r.parentNode?!1:(o.setStartAfter(r),o.collapse(!0),a.removeAllRanges(),a.addRange(o),!0)}if(!t.collapsed&&t.startId&&t.endId){const r=e.querySelector(`[${ie}="${t.startId}"]`),n=e.querySelector(`[${se}="${t.endId}"]`);return!r||!n||!r.parentNode||!n.parentNode?!1:(o.setStartAfter(r),o.setEndBefore(n),a.removeAllRanges(),a.addRange(o),!0)}}catch{return!1}return!1},Ue=(e,t)=>{if(!t)return;const a=window.getSelection();if(a)try{const o=be(e,t.start),r=be(e,t.end),n=document.createRange();n.setStart(o.node,o.offset),n.setEnd(r.node,r.offset),a.removeAllRanges(),a.addRange(n)}catch{}},Ce=({editor:e,defaultValue:t,value:a,readonly:o=!1,placeholder:r,onChange:n,pasteConfig:m,contentConfig:g,securityConfig:u,performanceConfig:h,accessibilityConfig:l,autosaveConfig:L,contextMenuConfig:R,spellcheckConfig:T})=>{const s=c.useRef(null),D=a!==void 0,I=c.useRef(),p=g?.autoHeight===!0,E=typeof g?.minHeight=="number"?g.minHeight:200,b=typeof g?.maxHeight=="number"?g.maxHeight:0,M=w=>{if(!w||!p)return;w.style.height="auto";const f=Math.max(E,w.scrollHeight);if(b>0){w.style.height=`${Math.min(f,b)}px`;return}w.style.height=`${f}px`},{restore:N}=Fe(()=>s.current?.innerHTML||"",L);c.useEffect(()=>{if(!s.current)return;const w=N(),f=w??a??t??"";f.trim()?s.current.innerHTML!==f&&(s.current.innerHTML=f):r?s.current.innerHTML="":s.current.innerHTML.trim()||(s.current.innerHTML="<p><br></p>"),G(s.current,r),M(s.current),w&&n&&n(w)},[]),c.useEffect(()=>{!s.current||!D||(a!==s.current.innerHTML&&(s.current.innerHTML=a),G(s.current,r),M(s.current))},[a,D]),c.useEffect(()=>{if(!s.current)return;const w=s.current;if(r){w.setAttribute("data-placeholder",r),Q(w)&&(w.innerHTML=""),G(w,r),M(w);return}w.removeAttribute("data-placeholder"),G(w,r),M(w)},[r]),c.useEffect(()=>{if(!s.current)return;const w=s.current;if(l?.enableARIA!==!1){w.setAttribute("role","textbox"),w.setAttribute("aria-multiline","true"),w.setAttribute("aria-disabled",o?"true":"false");const C=r?.trim();C?w.setAttribute("aria-label",C):w.removeAttribute("aria-label")}else w.removeAttribute("role"),w.removeAttribute("aria-multiline"),w.removeAttribute("aria-label"),w.removeAttribute("aria-disabled")},[l?.enableARIA,r,o]),c.useEffect(()=>{M(s.current)},[p,E,b,a]),c.useEffect(()=>{if(!s.current)return;const w=()=>{if(!s.current||o)return;r&&Q(s.current)&&(s.current.innerHTML="");let A=s.current.innerHTML;if(u?.sanitizeOnInput!==!1&&g?.sanitize!==!1){const S=he(A,g,u);if(S!==s.current.innerHTML){const z=Pe(s.current),$=s.current.innerHTML,B=he($,g,u);s.current.innerHTML=B,qe(s.current,z)||Ue(s.current,z?.fallbackOffsets||null),$e(s.current),A=s.current.innerHTML}else A=S}G(s.current,r),M(s.current),n&&(h?.debounceInputMs?(I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{n(A)},h.debounceInputMs)):n(A))},f=A=>{if(A.__editoraSmartPasteHandled===!0||A.defaultPrevented)return;if(o){A.preventDefault();return}A.preventDefault();let S=A.clipboardData?.getData("text/html");const z=A.clipboardData?.getData("text/plain"),$=!!S&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S);if(m?.clean||!m?.keepFormatting){z&&document.execCommand("insertText",!1,z);return}if(m?.convertWord===!1&&$){z&&document.execCommand("insertText",!1,z);return}if(S){u?.sanitizeOnPaste!==!1&&g?.sanitize!==!1&&(S=Oe(S,g,u));const B=window.getSelection();if(B&&B.rangeCount>0){const H=B.getRangeAt(0);H.deleteContents();const P=document.createElement("div");P.innerHTML=S;const V=document.createDocumentFragment();for(;P.firstChild;)V.appendChild(P.firstChild);H.insertNode(V),H.collapse(!1),B.removeAllRanges(),B.addRange(H)}}else z&&document.execCommand("insertText",!1,z)},C=A=>{const S=A.target;(S.tagName==="IMG"||S.tagName==="VIDEO")&&(S.style.resize="both",S.style.overflow="auto",S.style.display="inline-block")},x=A=>{R?.enabled===!1&&A.preventDefault()},_=()=>{s.current&&(r&&Q(s.current)&&(s.current.innerHTML=""),G(s.current,r),M(s.current))},y=s.current;return y.addEventListener("input",w),y.addEventListener("paste",f),y.addEventListener("click",C),y.addEventListener("contextmenu",x),y.addEventListener("focus",_),y.addEventListener("blur",_),o||y.focus(),()=>{I.current&&clearTimeout(I.current),y.removeEventListener("input",w),y.removeEventListener("paste",f),y.removeEventListener("click",C),y.removeEventListener("contextmenu",x),y.removeEventListener("focus",_),y.removeEventListener("blur",_)}},[e,n,m,g,u,h,r,R,o]);const F=(T?.enabled??!1)&&(T?.provider??"browser")==="browser";return c.useEffect(()=>{if(!s.current||typeof window>"u"||o||l?.keyboardNavigation===!1)return;const w=new q.KeyboardShortcutManager,f=s.current,C=x=>{w.handleKeyDown(x,(_,y)=>{if(typeof window<"u"&&window.executeEditorCommand){const A=s.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=A||null,window.executeEditorCommand(_,y)}})};return f.addEventListener("keydown",C),()=>{f.removeEventListener("keydown",C)}},[l?.keyboardNavigation,o]),d.jsx("div",{ref:s,contentEditable:!o,suppressContentEditableWarning:!0,spellCheck:o?!1:F,tabIndex:l?.keyboardNavigation===!1?-1:0,"aria-keyshortcuts":l?.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":l?.checker?"true":"false","data-readonly":o?"true":"false",className:`rte-content ${o?"rte-content-readonly":""}`,style:{minHeight:`${E}px`,maxHeight:p?b>0?`${b}px`:"none":"100%",padding:"16px",outline:"none",border:"1px solid #ddd",borderRadius:"0px 0px 4px 4px",fontSize:"14px",lineHeight:"1.5",overflow:p?b>0?"auto":"hidden":"auto",flex:p?void 0:1,boxSizing:"border-box",wordWrap:"break-word",overflowWrap:"break-word",marginBottom:"16px"}})},Ke=({editor:e,isEnabled:t,viewportOnlyScan:a=!0,readonly:o=!1})=>{const[r,n]=c.useState(!1),[m,g]=c.useState({top:0,left:0}),u=c.useRef(null),h=c.useRef(null),l=c.useRef(null),L=c.useRef(null),R=c.useRef(null);c.useEffect(()=>{if(!t||o){n(!1);return}R.current=u.current?.closest("[data-editora-editor]");const s=f=>{if(R.current)return R.current;const C=u.current?.closest("[data-editora-editor]");if(C)return R.current=C,C;const x=f?.commonAncestorContainer,y=(x?x.nodeType===Node.ELEMENT_NODE?x:x.parentElement:null)?.closest("[data-editora-editor]");return y?(R.current=y,y):null},D=f=>f&&f.querySelector(".rte-content, .editora-content")||null,I=f=>{if(!f||o)return!0;const C=f.getAttribute("contenteditable"),x=f.getAttribute("data-readonly");return C==="false"||x==="true"?!0:!!f.closest('[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]')},p=f=>{if(!f.anchorNode||!f.focusNode)return!1;try{const C=document.createRange();return C.setStart(f.anchorNode,f.anchorOffset),C.setEnd(f.focusNode,f.focusOffset),C.collapsed}catch{return!1}},E=(f,C)=>{const x=Array.from(C.getClientRects()).filter(y=>y.width>0||y.height>0);return x.length===0?C.getBoundingClientRect():p(f)?x[0]:x[x.length-1]},b=()=>{L.current&&clearTimeout(L.current);const f=window.getSelection();if(!f||f.rangeCount===0){n(!1),l.current=null;return}const C=f.getRangeAt(0);if(C.collapsed){n(!1),l.current=null;return}const x=f.toString().trim(),_=s(C),y=D(_);if(!y||!y.contains(C.commonAncestorContainer)){n(!1),l.current=null;return}if(I(y)){n(!1),l.current=null;return}if(a){const A=y.getBoundingClientRect(),S=A.bottom>=0&&A.top<=window.innerHeight,z=document.activeElement===y||y.contains(document.activeElement);if(!S&&!z){n(!1),l.current=null;return}}if(x.length>0){const A=E(f,C),S=y.getBoundingClientRect(),z=300;if(A&&S){const $=Math.max(8,A.top-50);let B=A.left+A.width/2;const H=z/2,P=S.left,V=S.right;B-H<P&&(B=P+H+10),B+H>V&&(B=V-H-10),g({top:$,left:B}),n(!0),l.current=C.cloneRange()}}else n(!1),l.current=null},M=f=>{if(h.current&&!h.current.contains(f.target)){const C=s();window.getSelection(),D(C)?.contains(f.target)||(n(!1),l.current=null)}},N=f=>{f.key==="Escape"&&(n(!1),l.current=null)},F=D(s()),w=F&&typeof MutationObserver<"u"?new MutationObserver(()=>{I(F)&&(n(!1),l.current=null)}):null;return w&&F&&w.observe(F,{attributes:!0,attributeFilter:["contenteditable","data-readonly"]}),document.addEventListener("selectionchange",b),document.addEventListener("mousedown",M),document.addEventListener("keydown",N),F?.addEventListener("mouseup",b),F?.addEventListener("keyup",b),()=>{document.removeEventListener("selectionchange",b),document.removeEventListener("mousedown",M),document.removeEventListener("keydown",N),F?.removeEventListener("mouseup",b),F?.removeEventListener("keyup",b),w?.disconnect(),L.current&&clearTimeout(L.current)}},[t,a,o]);const T=(s,D)=>{if(o||!l.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=R.current||null);const I=R.current?.querySelector(".rte-content, .editora-content");if(I&&(I.getAttribute("contenteditable")==="false"||I.getAttribute("data-readonly")==="true")){n(!1),l.current=null;return}I&&I.focus();const p=window.getSelection();if(p&&l.current)try{p.removeAllRanges(),p.addRange(l.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 M=b.getRangeAt(0),N=document.createElement("code");M.surroundContents(N)}},setBlockType:()=>{if(D==="blockquote"){const b=window.getSelection();if(b&&b.rangeCount>0){const M=b.getRangeAt(0);(M.commonAncestorContainer.nodeType===Node.TEXT_NODE?M.commonAncestorContainer.parentElement:M.commonAncestorContainer)?.closest?.("blockquote")?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else D&&document.execCommand("formatBlock",!1,D)}})[s]?.(),n(!1),l.current=null};return!t||o?d.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}):d.jsxs(d.Fragment,{children:[d.jsx("span",{ref:u,style:{display:"none"},"aria-hidden":"true"}),r&&d.jsxs("div",{ref:h,className:"floating-toolbar",onMouseDown:s=>s.preventDefault(),style:{position:"fixed",top:`${m.top}px`,left:`${m.left}px`,transform:"translateX(-50%)",zIndex:1e4,display:"flex"},children:[d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleBold"),title:"Bold (Ctrl+B)",children:d.jsx("strong",{children:"B"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleItalic"),title:"Italic (Ctrl+I)",children:d.jsx("em",{children:"I"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleUnderline"),title:"Underline (Ctrl+U)",children:d.jsx("u",{children:"U"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleStrikethrough"),title:"Strikethrough",children:d.jsx("s",{children:"S"})}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("clearFormatting"),title:"Clear Formatting",children:"⌫"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("createLink"),title:"Insert Link",children:"🔗"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("toggleCode"),title:"Code",children:"Code"}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>T("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},Ve=({plugins:e,children:t})=>{const a=e.filter(r=>r.context?.provider);return a.length===0?d.jsx(d.Fragment,{children:t}):a.reduce((r,n)=>{const m=n.context.provider;return d.jsx(m,{children:r},n.name)},d.jsx(d.Fragment,{children:t}))},we=new Set,ve=new Set,re=e=>!!e&&typeof e=="object"&&typeof e.name=="string",xe=e=>{const t=e?.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},Ge=(e,t)=>{if(!Array.isArray(e))return[];const a=xe(t),o=[],r=[];if(e.forEach(n=>{if(re(n)){o.push(n);return}if(typeof n!="string")return;const m=a[n];if(typeof m=="function")try{const g=m();if(re(g)){o.push(g);return}}catch{}r.push(n)}),r.length>0){const n=r.slice().sort().join("|");we.has(n)||(we.add(n),console.warn(`[Editora React] Unresolved string plugin names: ${r.join(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return o},Xe=(e,t,a)=>{if(!t?.checker||e.some(n=>n?.name==="a11yChecker"))return e;const o=xe(a).a11yChecker;if(typeof o=="function")try{const n=o();if(re(n))return[...e,n]}catch{}const r="accessibility.checker";return ve.has(r)||(ve.add(r),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},Je={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 ke(e,t){const a={...e};for(const o in t){const r=t[o],n=a[o];r!==void 0&&(typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof n=="object"&&n!==null&&!Array.isArray(n)?a[o]=ke(n,r):a[o]=r)}return a}function Se(e){const t=ke(Je,{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:Xe(Ge(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const oe=new Map,Qe=()=>{if(typeof window>"u")return{editorElement:null,contentElement:null};let e=window.__editoraCommandEditorRoot||null;e||(e=(window.__editoraLastCommandButton||null)?.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor")||null);const t=e?.querySelector(".rte-content, .editora-content")||(e?.matches(".rte-content, .editora-content")?e:null);return{editorElement:e,contentElement:t}};typeof window<"u"&&(window.registerEditorCommand=(e,t)=>{oe.set(e,t)},window.executeEditorCommand=(e,t)=>{const a=oe.get(e);if(a){const o=Qe();return a(t,o)}else return console.warn(`No handler registered for command: ${e}`),!1});const Ye=e=>{const t=c.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=c.useRef(null),o=c.useRef(null),r=c.useRef(e.onInit),n=c.useRef(e.onDestroy),m=c.useRef(e.onChange),g=c.useRef(new Set),u=c.useRef(null),h=c.useRef(null),l=c.useRef(null);c.useEffect(()=>{r.current=e.onInit,n.current=e.onDestroy,m.current=e.onChange});const L=p=>{m.current?.(p),g.current.forEach(E=>{try{E(p)}catch(b){console.error("Editora onChange subscriber failed:",b)}})},R=c.useMemo(()=>{const p=new q.PluginManager;t.plugins.forEach(b=>{p.register(b),b.commands&&typeof window<"u"&&Object.entries(b.commands).forEach(([M,N])=>{oe.set(M,N)})});const E=new q.Editor(p);return a.current=E,E},[t.plugins]);c.useEffect(()=>{const p={getHTML:()=>u.current?.querySelector(".rte-content")?.innerHTML||"",setHTML:E=>{const b=u.current?.querySelector(".rte-content");b&&(b.innerHTML=E)},execCommand:(E,b)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=u.current||null,window.executeEditorCommand(E,b))},registerCommand:(E,b)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(E,b)},focus:()=>{u.current?.querySelector(".rte-content")?.focus()},blur:()=>{u.current?.querySelector(".rte-content")?.blur()},destroy:()=>{n.current&&n.current()},onChange:E=>(g.current.add(E),()=>{g.current.delete(E)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:R.toolbar?.items||[]}};return o.current=p,r.current&&r.current(p),()=>{g.current.clear(),n.current&&n.current()}},[]),c.useEffect(()=>{if(t.statusbar.enabled&&l.current&&u.current){h.current||(h.current=new q.StatusBar({enabled:!0,position:t.statusbar.position}),h.current.create(l.current));const p=u.current.querySelector(".rte-content");if(p){const E=()=>{const x=document.activeElement;return!!x&&(x===p||p.contains(x))},b=()=>{const x=p.getBoundingClientRect();return x.bottom>=0&&x.top<=window.innerHeight},M=()=>{const x=window.getSelection();if(!x||x.rangeCount===0)return null;const _=x.getRangeAt(0),y=_.commonAncestorContainer;return p.contains(y)?_:null},N=(x=!1)=>{if(t.performance.viewportOnlyScan!==!1&&!b()&&!E())return;const y=M(),A=!!y||E();if(x&&!A)return;const S=p.textContent||"",{words:z,chars:$}=q.calculateTextStats(S),B=q.countLines(p);let H,P;y&&(H=q.getCursorPosition(p,y),y.collapsed||(P=q.getSelectionInfo(y,H),H=void 0)),h.current?.update({wordCount:z,charCount:$,lineCount:B,cursorPosition:H,selectionInfo:P})},F=()=>N(),w=()=>N(!0),f=()=>N(),C=()=>N();return p.addEventListener("input",F),p.addEventListener("focus",f),p.addEventListener("blur",C),document.addEventListener("selectionchange",w),N(),()=>{p.removeEventListener("input",F),p.removeEventListener("focus",f),p.removeEventListener("blur",C),document.removeEventListener("selectionchange",w)}}}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 T=t.toolbar.floating??!1,s=t.toolbar.position||"top",D=t.toolbar.sticky??!1,I=t.toolbar.showMoreOptions??!0;return d.jsx(Ve,{plugins:t.plugins,children:d.jsxs("div",{ref:u,id:t.id,"data-editora-editor":!0,"data-readonly":t.readonly?"true":"false",className:`rte-editor ${t.className||""}`,lang:t.language.locale,dir:t.language.direction,style:{display:"flex",flexDirection:"column",height:"100%"},children:[s!=="bottom"&&d.jsx(ne,{editor:R,position:s,sticky:D,floating:T,readonly:t.readonly,showMoreOptions:I,itemsOverride:t.toolbar.items}),d.jsx(Ce,{editor:R,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:L,pasteConfig:t.paste,contentConfig:t.content,securityConfig:t.security,performanceConfig:t.performance,accessibilityConfig:t.accessibility,autosaveConfig:t.autosave,contextMenuConfig:t.contextMenu,spellcheckConfig:t.spellcheck}),s==="bottom"&&d.jsx(ne,{editor:R,position:s,sticky:D,floating:T,readonly:t.readonly,showMoreOptions:I,itemsOverride:t.toolbar.items}),d.jsx(Ke,{editor:R,isEnabled:T,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&d.jsx("div",{ref:l,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},Re=e=>d.jsx(Ye,{...e});function Ze(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 q.KeyboardShortcutManager(e);t.current=o;const r=m=>o.handleKeyDown(m,(u,h)=>{a.current&&a.current(u,h),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(u,h)}),n=e.editorElement||document;return n&&n.addEventListener("keydown",r),()=>{n&&n.removeEventListener("keydown",r)}},[e.editorElement,e.enabled,e.shortcuts,e.customShortcuts]),{getShortcuts:()=>t.current?.getAllShortcuts()||[],getShortcutForCommand:o=>t.current?.getShortcutForCommand(o),getShortcutsHelp:()=>t.current?.getShortcutsHelp()||"",enable:()=>t.current?.enable(),disable:()=>t.current?.disable(),isEnabled:()=>t.current?.isEnabled()||!1}}exports.EditorContent=Ce;exports.EditoraEditor=Re;exports.InlineMenu=pe;exports.RichTextEditor=Re;exports.Toolbar=ne;exports.mergeConfig=Se;exports.useKeyboardShortcuts=Ze; |
+628
-587
@@ -1,5 +0,5 @@ | ||
| import { jsx as h, jsxs as V, Fragment as Y } from "react/jsx-runtime"; | ||
| 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 = ({ | ||
| import { jsx as h, jsxs as V, Fragment as ee } from "react/jsx-runtime"; | ||
| import De, { useRef as L, useState as G, useLayoutEffect as He, useEffect as F, useMemo as ae } from "react"; | ||
| import { KeyboardShortcutManager as ke, PluginManager as Be, Editor as Fe, StatusBar as _e, calculateTextStats as ze, countLines as Oe, getCursorPosition as We, getSelectionInfo as Pe } from "@editora/core"; | ||
| const $e = ({ | ||
| isOpen: e, | ||
@@ -9,49 +9,49 @@ options: t, | ||
| onClose: o, | ||
| anchorRef: n, | ||
| className: r = "" | ||
| anchorRef: r, | ||
| className: n = "" | ||
| }) => { | ||
| const f = x(null), [d, c] = j(null), m = () => { | ||
| if (!e || !n.current) return; | ||
| 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 }); | ||
| const u = L(null), [f, s] = G(null), m = () => { | ||
| if (!e || !r.current) return; | ||
| const c = r.current.getBoundingClientRect(), R = u.current?.getBoundingClientRect(), A = R?.width || 120, T = R?.height || t.length * 36, l = 8, H = 4, I = window.innerWidth, v = window.innerHeight; | ||
| let y = c.bottom + H, g = c.left; | ||
| g + A > I - l && (g = I - A - l), g < l && (g = l), y + T > v - l && (y = c.top - T - H), y < l && (y = l), s({ top: y, left: g }); | ||
| }; | ||
| return Ne(() => { | ||
| return He(() => { | ||
| if (!e) { | ||
| c(null); | ||
| s(null); | ||
| return; | ||
| } | ||
| m(); | ||
| const s = window.requestAnimationFrame(m); | ||
| const c = window.requestAnimationFrame(m); | ||
| return () => { | ||
| window.cancelAnimationFrame(s); | ||
| window.cancelAnimationFrame(c); | ||
| }; | ||
| }, [e, t.length, n]), B(() => { | ||
| }, [e, t.length, r]), F(() => { | ||
| if (!e) return; | ||
| const s = () => { | ||
| const c = () => { | ||
| m(); | ||
| }; | ||
| return window.addEventListener("resize", s), window.addEventListener("scroll", s, !0), () => { | ||
| window.removeEventListener("resize", s), window.removeEventListener("scroll", s, !0); | ||
| return window.addEventListener("resize", c), window.addEventListener("scroll", c, !0), () => { | ||
| window.removeEventListener("resize", c), window.removeEventListener("scroll", c, !0); | ||
| }; | ||
| }, [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) => { | ||
| }, [e, t.length, r]), F(() => { | ||
| const c = (A) => { | ||
| u.current && !u.current.contains(A.target) && r.current && !r.current.contains(A.target) && o(); | ||
| }, R = (A) => { | ||
| A.key === "Escape" && o(); | ||
| }; | ||
| return e && (document.addEventListener("mousedown", s), document.addEventListener("keydown", y)), () => { | ||
| document.removeEventListener("mousedown", s), document.removeEventListener("keydown", y); | ||
| return e && (document.addEventListener("mousedown", c), document.addEventListener("keydown", R)), () => { | ||
| document.removeEventListener("mousedown", c), document.removeEventListener("keydown", R); | ||
| }; | ||
| }, [e, o, n]), e ? /* @__PURE__ */ h( | ||
| }, [e, o, r]), e ? /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| ref: f, | ||
| className: `rte-inline-menu ${r}`, | ||
| ref: u, | ||
| className: `rte-inline-menu ${n}`, | ||
| style: { | ||
| top: d?.top ?? -9999, | ||
| left: d?.left ?? -9999, | ||
| visibility: d ? "visible" : "hidden" | ||
| top: f?.top ?? -9999, | ||
| left: f?.left ?? -9999, | ||
| visibility: f ? "visible" : "hidden" | ||
| }, | ||
| children: t.map((s) => /* @__PURE__ */ h( | ||
| children: t.map((c) => /* @__PURE__ */ h( | ||
| "div", | ||
@@ -61,11 +61,11 @@ { | ||
| onClick: () => { | ||
| a(s.value), o(); | ||
| a(c.value), o(); | ||
| }, | ||
| children: s.label | ||
| children: c.label | ||
| }, | ||
| s.value | ||
| c.value | ||
| )) | ||
| } | ||
| ) : null; | ||
| }, J = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Pe = { | ||
| }, Q = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Ue = { | ||
| undo: "undo", | ||
@@ -95,19 +95,24 @@ redo: "redo", | ||
| table: "insertTable", | ||
| clearformatting: "clearFormatting" | ||
| }, $e = (e, t) => { | ||
| trackchanges: "toggleTrackChanges", | ||
| accepttrackchanges: "acceptAllTrackChanges", | ||
| rejecttrackchanges: "rejectAllTrackChanges", | ||
| clearformatting: "clearFormatting", | ||
| databinding: "openDataBindingDialog", | ||
| databindingpreview: "openDataBindingDialog" | ||
| }, qe = (e, t) => { | ||
| if (!Array.isArray(t) || t.length === 0) | ||
| return e; | ||
| if (!t.every((c) => typeof c == "string")) | ||
| if (!t.every((s) => typeof s == "string")) | ||
| return t; | ||
| const o = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(); | ||
| e.forEach((c) => { | ||
| o.set(J(c.command || ""), c), n.set(J(c.label || ""), c); | ||
| const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(); | ||
| e.forEach((s) => { | ||
| o.set(Q(s.command || ""), s), r.set(Q(s.label || ""), s); | ||
| }); | ||
| const r = t.flatMap((c) => c.split(/\s+/)).map((c) => c.trim()).filter(Boolean), f = []; | ||
| let d = 0; | ||
| return r.forEach((c) => { | ||
| if (c === "|") { | ||
| d += 1, f.push({ | ||
| const n = t.flatMap((s) => s.split(/\s+/)).map((s) => s.trim()).filter(Boolean), u = []; | ||
| let f = 0; | ||
| return n.forEach((s) => { | ||
| if (s === "|") { | ||
| f += 1, u.push({ | ||
| type: "separator", | ||
| command: `__separator__${d}`, | ||
| command: `__separator__${f}`, | ||
| label: "|" | ||
@@ -117,8 +122,8 @@ }); | ||
| } | ||
| 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) | ||
| const m = Q(s), c = Ue[m], R = o.get(m) || (c ? o.get(Q(c)) : void 0) || r.get(m) || e.find( | ||
| (A) => Q(A.command || "").includes(m) | ||
| ); | ||
| y && f.push(y); | ||
| }), f.length > 0 ? f : e; | ||
| }, we = ({ | ||
| R && u.push(R); | ||
| }), u.length > 0 ? u : e; | ||
| }, ve = ({ | ||
| editor: e, | ||
@@ -128,33 +133,44 @@ position: t = "top", | ||
| floating: o = !1, | ||
| readonly: n = !1, | ||
| showMoreOptions: r = !0, | ||
| itemsOverride: f | ||
| readonly: r = !1, | ||
| showMoreOptions: n = !0, | ||
| itemsOverride: u | ||
| }) => { | ||
| 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 = (i) => { | ||
| H.current = i, i && !i.collapsed && (N.current = i); | ||
| }, S = () => g.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, W = () => { | ||
| const [f, s] = G(!1), [m, c] = G(null), [R, A] = G(null), [T, l] = G(null), [H, I] = G(!1), v = L(null), y = L(null), g = L({}), M = L([]), N = L(null), _ = L(null), b = L(null), d = ae( | ||
| () => qe(e.pluginManager.getToolbarItems(), u), | ||
| [e, u] | ||
| ), C = (i) => { | ||
| v.current = i, i && !i.collapsed && (y.current = i); | ||
| }, E = () => N.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, z = () => { | ||
| if (typeof window > "u") return; | ||
| const i = g.current?.closest("[data-editora-editor]"); | ||
| const i = N.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = i || null; | ||
| }, E = (i) => { | ||
| }, p = (i) => { | ||
| if (typeof window > "u" || !i) return; | ||
| const k = i.getAttribute("data-command"); | ||
| k && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = k); | ||
| }, D = () => { | ||
| const i = S(); | ||
| }, x = () => { | ||
| const i = E(); | ||
| 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); | ||
| const w = k.getRangeAt(0); | ||
| return i.contains(w.commonAncestorContainer) ? w.cloneRange() : null; | ||
| }, S = () => { | ||
| const i = x(); | ||
| i && C(i); | ||
| }; | ||
| B(() => { | ||
| F(() => { | ||
| const i = N.current?.closest("[data-editora-editor]"); | ||
| if (!i) return; | ||
| const k = i.querySelector(".rte-content, .editora-content"); | ||
| s(k?.getAttribute("data-track-changes") === "true"); | ||
| const w = ($) => { | ||
| s(!!$.detail?.enabled); | ||
| }; | ||
| return i.addEventListener("editora:track-changes-toggle", w), () => { | ||
| i.removeEventListener("editora:track-changes-toggle", w); | ||
| }; | ||
| }, []), F(() => { | ||
| const i = () => { | ||
| C(); | ||
| S(); | ||
| }; | ||
@@ -164,9 +180,9 @@ return document.addEventListener("selectionchange", i), () => { | ||
| }; | ||
| }, []), 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); | ||
| }, []), F(() => { | ||
| if (!m) return; | ||
| const i = (w) => { | ||
| const $ = w.target; | ||
| $ && $ instanceof Element && ($.closest(".rte-toolbar-dropdown") || c(null)); | ||
| }, k = (w) => { | ||
| w.key === "Escape" && c(null); | ||
| }; | ||
@@ -176,4 +192,4 @@ return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", k), () => { | ||
| }; | ||
| }, [d]); | ||
| const R = (i) => [ | ||
| }, [m]); | ||
| const W = (i) => [ | ||
| "toggleBold", | ||
@@ -188,20 +204,20 @@ "toggleItalic", | ||
| "toggleCode" | ||
| ].includes(i), M = (i = !1) => { | ||
| const k = S(); | ||
| ].includes(i), q = (i = !1) => { | ||
| const k = E(); | ||
| 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) | ||
| const w = window.getSelection(); | ||
| if (!w) return !1; | ||
| const $ = w.rangeCount > 0 && k.contains(w.getRangeAt(0).commonAncestorContainer), D = i ? y.current || v.current : v.current || y.current; | ||
| if (i && D && D.collapsed) | ||
| return !1; | ||
| if (I && k.contains(I.commonAncestorContainer)) | ||
| if (D && k.contains(D.commonAncestorContainer)) | ||
| try { | ||
| return k.focus({ preventScroll: !0 }), v.removeAllRanges(), v.addRange(I), !0; | ||
| return k.focus({ preventScroll: !0 }), w.removeAllRanges(), w.addRange(D), !0; | ||
| } catch { | ||
| } | ||
| return U; | ||
| return $; | ||
| }; | ||
| B(() => { | ||
| if (!r) { | ||
| A(null), l(!1), b.current = []; | ||
| F(() => { | ||
| if (!n) { | ||
| l(null), I(!1), M.current = []; | ||
| return; | ||
@@ -211,34 +227,34 @@ } | ||
| 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 = L.current.children; | ||
| for (let K = 0; K < te.length; K++) { | ||
| const ne = te[K].getBoundingClientRect().width; | ||
| ne > 0 && (b.current[K] = ne); | ||
| const he = b.current[K] ?? ne, be = (he > 0 ? he : 40) + de; | ||
| if (fe + be <= Me) | ||
| fe += be, me++; | ||
| if (!N.current || !_.current) return; | ||
| const D = N.current.clientWidth, j = 16, P = 40, Y = 4, Ne = Math.max(0, D - j - P - Y); | ||
| let me = 0, ge = 0; | ||
| const ne = _.current.children; | ||
| for (let K = 0; K < ne.length; K++) { | ||
| const re = ne[K].getBoundingClientRect().width; | ||
| re > 0 && (M.current[K] = re); | ||
| const be = M.current[K] ?? re, we = (be > 0 ? be : 40) + Y; | ||
| if (me + we <= Ne) | ||
| me += we, ge++; | ||
| else | ||
| break; | ||
| } | ||
| const ge = Math.max(1, Math.min(me, te.length)); | ||
| A((K) => K === ge ? K : ge); | ||
| }, v = () => { | ||
| const he = Math.max(1, Math.min(ge, ne.length)); | ||
| l((K) => K === he ? K : he); | ||
| }, w = () => { | ||
| i !== null && cancelAnimationFrame(i), i = requestAnimationFrame(k); | ||
| }; | ||
| b.current = [], v(); | ||
| const U = new ResizeObserver(() => { | ||
| v(); | ||
| M.current = [], w(); | ||
| const $ = new ResizeObserver(() => { | ||
| w(); | ||
| }); | ||
| return g.current && U.observe(g.current), L.current && U.observe(L.current), () => { | ||
| i !== null && cancelAnimationFrame(i), U.disconnect(); | ||
| return N.current && $.observe(N.current), _.current && $.observe(_.current), () => { | ||
| i !== null && cancelAnimationFrame(i), $.disconnect(); | ||
| }; | ||
| }, [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; | ||
| W(), i === "addComment" || i === "toggleComments" || M(R(i)); | ||
| const I = { | ||
| }, [d.length, n]), F(() => { | ||
| H && T !== null && T >= d.length && I(!1); | ||
| }, [H, T, d.length]); | ||
| const O = (i) => (g.current[i] || (g.current[i] = De.createRef()), g.current[i]), B = (i, k) => { | ||
| if (r) return; | ||
| z(), i === "addComment" || i === "toggleComments" || q(W(i)); | ||
| const D = { | ||
| toggleBold: "bold", | ||
@@ -248,14 +264,14 @@ toggleItalic: "italic", | ||
| }[i]; | ||
| if (I) { | ||
| document.execCommand(I, !1), c(null); | ||
| if (D) { | ||
| document.execCommand(D, !1), c(null); | ||
| return; | ||
| } | ||
| 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 = { | ||
| }, U = (i) => { | ||
| r || (S(), c(m === i ? null : i)); | ||
| }, X = (i) => { | ||
| r || (S(), A(R === i ? null : i), c(null)); | ||
| }, Le = (i, k) => { | ||
| r || (q(), B(i, k), C(null), y.current = null, A(null)); | ||
| }, ue = (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 || "⚪", Re = { | ||
| ...a && { | ||
@@ -272,8 +288,8 @@ position: "sticky", | ||
| } | ||
| }, ue = r && y !== null && y < p.length, Te = (i) => { | ||
| if (n) return; | ||
| }, fe = n && T !== null && T < d.length, Me = (i) => { | ||
| if (r) 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 || ""; | ||
| k.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (p(k.closest("[data-command]")), z(), S(), i.preventDefault()); | ||
| }, te = (i, k = !0) => i.map((w, $) => { | ||
| const D = w.command || "", j = D === "toggleTrackChanges" && f; | ||
| return /* @__PURE__ */ h( | ||
@@ -284,18 +300,18 @@ "div", | ||
| style: { | ||
| display: k && r && y !== null && U >= y ? "none" : "flex" | ||
| display: k && n && T !== null && $ >= T ? "none" : "flex" | ||
| }, | ||
| 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: [ | ||
| children: w.type === "separator" ? /* @__PURE__ */ h("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : w.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [ | ||
| /* @__PURE__ */ V( | ||
| "button", | ||
| { | ||
| className: "rte-toolbar-button", | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), C(); | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| }, | ||
| onClick: () => $(I), | ||
| disabled: n, | ||
| onClick: () => U(D), | ||
| disabled: r, | ||
| children: [ | ||
| v.label, | ||
| w.label, | ||
| " ▼" | ||
@@ -305,53 +321,53 @@ ] | ||
| ), | ||
| d === I && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: v.options?.map((O) => /* @__PURE__ */ h( | ||
| m === D && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: w.options?.map((P) => /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| className: "rte-toolbar-dropdown-item", | ||
| onMouseDown: (ee) => ee.preventDefault(), | ||
| onClick: () => _(I, O.value), | ||
| children: O.label | ||
| onMouseDown: (Y) => Y.preventDefault(), | ||
| onClick: () => B(D, P.value), | ||
| children: P.label | ||
| }, | ||
| O.value | ||
| P.value | ||
| )) }) | ||
| ] }) : v.type === "inline-menu" ? /* @__PURE__ */ h( | ||
| ] }) : w.type === "inline-menu" ? /* @__PURE__ */ h( | ||
| "button", | ||
| { | ||
| ref: F(I), | ||
| className: "rte-toolbar-button", | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), C(); | ||
| ref: O(D), | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| }, | ||
| onClick: () => P(I), | ||
| disabled: n, | ||
| title: v.label, | ||
| children: X(v.icon) | ||
| onClick: () => X(D), | ||
| disabled: r, | ||
| title: w.label, | ||
| children: ue(w.icon) | ||
| } | ||
| ) : v.type === "input" ? /* @__PURE__ */ h( | ||
| ) : w.type === "input" ? /* @__PURE__ */ h( | ||
| "input", | ||
| { | ||
| type: "text", | ||
| 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, | ||
| O.target.value | ||
| className: `rte-toolbar-input ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| placeholder: w.placeholder, | ||
| onChange: (P) => B(D, P.target.value), | ||
| disabled: r, | ||
| onKeyDown: (P) => { | ||
| P.key === "Enter" && B( | ||
| D, | ||
| P.target.value | ||
| ); | ||
| }, | ||
| title: v.label | ||
| title: w.label | ||
| } | ||
| ) : v.type === "group" ? /* @__PURE__ */ h( | ||
| ) : w.type === "group" ? /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-button ${v.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${v.label}`, | ||
| className: `rte-toolbar-group-button ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${w.label}`, | ||
| children: /* @__PURE__ */ h( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-items ${v.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: Z(v.items || [], !1) | ||
| className: `rte-toolbar-group-items ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: te(w.items || [], !1) | ||
| } | ||
@@ -363,19 +379,19 @@ ) | ||
| { | ||
| className: "rte-toolbar-button", | ||
| "data-command": I, | ||
| "data-active": "false", | ||
| onMouseDown: (O) => { | ||
| O.preventDefault(), C(); | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| }, | ||
| onClick: () => _(I), | ||
| disabled: n, | ||
| title: v.label, | ||
| children: X(v.icon) | ||
| onClick: () => B(D), | ||
| disabled: r, | ||
| title: w.label, | ||
| children: ue(w.icon) | ||
| } | ||
| ) | ||
| }, | ||
| U | ||
| $ | ||
| ); | ||
| }), Re = r && y !== null ? p.filter((i, k) => k >= y) : []; | ||
| return /* @__PURE__ */ V(Y, { children: [ | ||
| }), Ie = n && T !== null ? d.filter((i, k) => k >= T) : []; | ||
| return /* @__PURE__ */ V(ee, { children: [ | ||
| /* @__PURE__ */ V( | ||
@@ -385,6 +401,6 @@ "div", | ||
| className: "rte-toolbar-wrapper", | ||
| style: Le, | ||
| onMouseDownCapture: Te, | ||
| style: Re, | ||
| onMouseDownCapture: Me, | ||
| children: [ | ||
| /* @__PURE__ */ V("div", { className: "rte-toolbar", ref: g, children: [ | ||
| /* @__PURE__ */ V("div", { className: "rte-toolbar", ref: N, children: [ | ||
| /* @__PURE__ */ h( | ||
@@ -394,17 +410,17 @@ "div", | ||
| className: "rte-toolbar-items-container", | ||
| ref: L, | ||
| style: r ? void 0 : { flexWrap: "wrap" }, | ||
| children: Z(p) | ||
| ref: _, | ||
| style: n ? void 0 : { flexWrap: "wrap" }, | ||
| children: te(d) | ||
| } | ||
| ), | ||
| ue && /* @__PURE__ */ h( | ||
| fe && /* @__PURE__ */ h( | ||
| "button", | ||
| { | ||
| ref: z, | ||
| className: `rte-toolbar-more-button ${T ? "active" : ""}`, | ||
| ref: b, | ||
| className: `rte-toolbar-more-button ${H ? "active" : ""}`, | ||
| onMouseDown: (i) => { | ||
| i.preventDefault(), C(); | ||
| i.preventDefault(), S(); | ||
| }, | ||
| onClick: () => l(!T), | ||
| disabled: n, | ||
| onClick: () => I(!H), | ||
| disabled: r, | ||
| title: "Show more options", | ||
@@ -416,17 +432,17 @@ "aria-label": "More toolbar options", | ||
| ] }), | ||
| ue && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${T ? "show" : ""}`, children: Z(Re, !1) }) | ||
| fe && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${H ? "show" : ""}`, children: te(Ie, !1) }) | ||
| ] | ||
| } | ||
| ), | ||
| p.map((i) => { | ||
| d.map((i) => { | ||
| if (i.type === "inline-menu") { | ||
| const k = i.command || ""; | ||
| return /* @__PURE__ */ h( | ||
| Oe, | ||
| $e, | ||
| { | ||
| isOpen: m === k, | ||
| isOpen: R === k, | ||
| options: i.options || [], | ||
| onSelect: (v) => q(k, v), | ||
| onClose: () => s(null), | ||
| anchorRef: F(k) | ||
| onSelect: (w) => Le(k, w), | ||
| onClose: () => A(null), | ||
| anchorRef: O(k) | ||
| }, | ||
@@ -440,16 +456,16 @@ `menu-${k || "unknown"}` | ||
| }; | ||
| function Ue(e, t) { | ||
| const a = x(), o = x(""); | ||
| return B(() => { | ||
| function je(e, t) { | ||
| const a = L(), o = L(""); | ||
| return F(() => { | ||
| if (!t?.enabled) return; | ||
| const r = t.intervalMs || 3e4, f = t.storageKey || "rte-autosave", d = t.provider || "localStorage", c = async () => { | ||
| const n = t.intervalMs || 3e4, u = t.storageKey || "rte-autosave", f = t.provider || "localStorage", s = async () => { | ||
| const m = e(); | ||
| if (m !== o.current) { | ||
| if (o.current = m, d === "localStorage") | ||
| if (o.current = m, f === "localStorage") | ||
| try { | ||
| localStorage.setItem(f, m), localStorage.setItem(`${f}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage"); | ||
| } catch (s) { | ||
| console.error("[Autosave] Failed to save to localStorage:", s); | ||
| localStorage.setItem(u, m), localStorage.setItem(`${u}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage"); | ||
| } catch (c) { | ||
| console.error("[Autosave] Failed to save to localStorage:", c); | ||
| } | ||
| else if (d === "api" && t.apiUrl) | ||
| else if (f === "api" && t.apiUrl) | ||
| try { | ||
@@ -463,8 +479,8 @@ await fetch(t.apiUrl, { | ||
| }), console.log("[Autosave] Content saved to API"); | ||
| } catch (s) { | ||
| console.error("[Autosave] Failed to save to API:", s); | ||
| } catch (c) { | ||
| console.error("[Autosave] Failed to save to API:", c); | ||
| } | ||
| } | ||
| }; | ||
| return a.current = setInterval(c, r), () => { | ||
| return a.current = setInterval(s, n), () => { | ||
| a.current && clearInterval(a.current); | ||
@@ -474,10 +490,10 @@ }; | ||
| if (!t?.enabled) return null; | ||
| const r = t.storageKey || "rte-autosave"; | ||
| const n = t.storageKey || "rte-autosave"; | ||
| if ((t.provider || "localStorage") === "localStorage") | ||
| try { | ||
| const d = localStorage.getItem(r), c = localStorage.getItem(`${r}-timestamp`); | ||
| if (d && c) | ||
| return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(c))), d; | ||
| } catch (d) { | ||
| console.error("[Autosave] Failed to restore from localStorage:", d); | ||
| const f = localStorage.getItem(n), s = localStorage.getItem(`${n}-timestamp`); | ||
| if (f && s) | ||
| return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(s))), f; | ||
| } catch (f) { | ||
| console.error("[Autosave] Failed to restore from localStorage:", f); | ||
| } | ||
@@ -487,3 +503,3 @@ return null; | ||
| } | ||
| const qe = [ | ||
| const Ke = [ | ||
| "p", | ||
@@ -523,7 +539,8 @@ "br", | ||
| "div", | ||
| "section", | ||
| "sup", | ||
| "sub", | ||
| "hr" | ||
| ], Ke = { | ||
| "*": ["class", "style", "id", "data-*"], | ||
| ], Ve = { | ||
| "*": ["class", "style", "id", "data-*", "role", "aria-*", "tabindex", "contenteditable", "spellcheck"], | ||
| a: ["href", "target", "rel", "title"], | ||
@@ -537,36 +554,36 @@ img: ["src", "alt", "width", "height", "loading"], | ||
| }; | ||
| function ke(e, t, a) { | ||
| function Se(e, t, a) { | ||
| if (t?.sanitize === !1) | ||
| return e; | ||
| 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; | ||
| const o = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : Ke, n = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : Ve, u = document.createElement("div"); | ||
| return u.innerHTML = e, Ae(u, o, n), u.innerHTML; | ||
| } | ||
| function Se(e, t, a) { | ||
| function Ae(e, t, a) { | ||
| const o = Array.from(e.childNodes); | ||
| for (const n of o) | ||
| if (n.nodeType === Node.ELEMENT_NODE) { | ||
| const r = n, f = r.tagName.toLowerCase(); | ||
| if (!t.includes(f)) { | ||
| for (; r.firstChild; ) | ||
| e.insertBefore(r.firstChild, r); | ||
| e.removeChild(r); | ||
| for (const r of o) | ||
| if (r.nodeType === Node.ELEMENT_NODE) { | ||
| const n = r, u = n.tagName.toLowerCase(); | ||
| if (!t.includes(u)) { | ||
| for (; n.firstChild; ) | ||
| e.insertBefore(n.firstChild, n); | ||
| e.removeChild(n); | ||
| continue; | ||
| } | ||
| Ve(r, a), Se(r, t, a); | ||
| Ge(n, a), Ae(n, t, a); | ||
| } else { | ||
| if (n.nodeType === Node.TEXT_NODE) | ||
| if (r.nodeType === Node.TEXT_NODE) | ||
| continue; | ||
| e.removeChild(n); | ||
| e.removeChild(r); | ||
| } | ||
| } | ||
| function Ve(e, t) { | ||
| const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), n = t[a] || [], r = t["*"] || [], f = [...n, ...r]; | ||
| for (const d of o) { | ||
| const c = d.name.toLowerCase(); | ||
| function Ge(e, t) { | ||
| const a = e.tagName.toLowerCase(), o = Array.from(e.attributes), r = t[a] || [], n = t["*"] || [], u = [...r, ...n]; | ||
| for (const f of o) { | ||
| const s = f.name.toLowerCase(); | ||
| let m = !1; | ||
| f.includes(c) && (m = !0); | ||
| for (const s of f) | ||
| if (s.endsWith("*")) { | ||
| const y = s.slice(0, -1); | ||
| if (c.startsWith(y)) { | ||
| u.includes(s) && (m = !0); | ||
| for (const c of u) | ||
| if (c.endsWith("*")) { | ||
| const R = c.slice(0, -1); | ||
| if (s.startsWith(R)) { | ||
| m = !0; | ||
@@ -576,17 +593,17 @@ break; | ||
| } | ||
| (c.startsWith("on") || // Event handlers | ||
| c === "javascript:" || c === "href" && d.value.trim().toLowerCase().startsWith("javascript:") || c === "src" && d.value.trim().toLowerCase().startsWith("javascript:")) && (m = !1), m || e.removeAttribute(d.name); | ||
| (s.startsWith("on") || // Event handlers | ||
| s === "javascript:" || s === "href" && f.value.trim().toLowerCase().startsWith("javascript:") || s === "src" && f.value.trim().toLowerCase().startsWith("javascript:")) && (m = !1), m || e.removeAttribute(f.name); | ||
| } | ||
| e.hasAttribute("href") && (e.getAttribute("href") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("href"), e.hasAttribute("src") && (e.getAttribute("src") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("src"); | ||
| } | ||
| function je(e, t, a) { | ||
| return a?.sanitizeOnPaste === !1 ? e : ke(e, t); | ||
| function Xe(e, t, a) { | ||
| return a?.sanitizeOnPaste === !1 ? e : Se(e, t); | ||
| } | ||
| function ve(e, t, a) { | ||
| return a?.sanitizeOnInput === !1 ? e : ke(e, t); | ||
| function pe(e, t, a) { | ||
| return a?.sanitizeOnInput === !1 ? e : Se(e, t); | ||
| } | ||
| const Q = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), G = (e, t) => { | ||
| const o = !!t && Q(e); | ||
| const Z = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), J = (e, t) => { | ||
| const o = !!t && Z(e); | ||
| 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), Ge = (e) => { | ||
| }, ce = "data-rte-caret-marker", se = "data-rte-range-start-marker", de = "data-rte-range-end-marker", oe = () => Math.random().toString(36).slice(2), Je = (e) => { | ||
| const t = window.getSelection(); | ||
@@ -599,6 +616,6 @@ if (!t || t.rangeCount === 0) return null; | ||
| o.selectNodeContents(e), o.setEnd(a.startContainer, a.startOffset); | ||
| const n = a.cloneRange(); | ||
| return n.selectNodeContents(e), n.setEnd(a.endContainer, a.endOffset), { | ||
| const r = a.cloneRange(); | ||
| return r.selectNodeContents(e), r.setEnd(a.endContainer, a.endOffset), { | ||
| start: o.toString().length, | ||
| end: n.toString().length | ||
| end: r.toString().length | ||
| }; | ||
@@ -608,17 +625,17 @@ } catch { | ||
| } | ||
| }, pe = (e, t) => { | ||
| }, ye = (e, t) => { | ||
| const a = document.createTreeWalker(e, NodeFilter.SHOW_TEXT); | ||
| let o = a.nextNode(), n = Math.max(0, t), r = null; | ||
| let o = a.nextNode(), r = Math.max(0, t), n = null; | ||
| for (; o; ) { | ||
| r = o; | ||
| const f = o.textContent?.length ?? 0; | ||
| if (n <= f) | ||
| return { node: o, offset: n }; | ||
| n -= f, o = a.nextNode(); | ||
| n = o; | ||
| const u = o.textContent?.length ?? 0; | ||
| if (r <= u) | ||
| return { node: o, offset: r }; | ||
| r -= u, o = a.nextNode(); | ||
| } | ||
| return r ? { | ||
| node: r, | ||
| offset: r.textContent?.length ?? 0 | ||
| return n ? { | ||
| node: n, | ||
| offset: n.textContent?.length ?? 0 | ||
| } : { node: e, offset: e.childNodes.length }; | ||
| }, Xe = (e) => { | ||
| }, Qe = (e) => { | ||
| const t = window.getSelection(); | ||
@@ -628,24 +645,24 @@ if (!t || t.rangeCount === 0) return null; | ||
| if (!e.contains(a.commonAncestorContainer)) return null; | ||
| const o = Ge(e); | ||
| const o = Je(e); | ||
| try { | ||
| if (a.collapsed) { | ||
| 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 }; | ||
| const c = oe(), R = document.createElement("span"); | ||
| return R.setAttribute(ce, c), R.appendChild(document.createTextNode("")), a.cloneRange().insertNode(R), { collapsed: !0, caretId: c, fallbackOffsets: o }; | ||
| } | ||
| const n = re(), r = re(), f = document.createElement("span"); | ||
| const r = oe(), n = oe(), u = document.createElement("span"); | ||
| u.setAttribute(de, n), u.appendChild(document.createTextNode("")); | ||
| const f = document.createElement("span"); | ||
| f.setAttribute(se, r), f.appendChild(document.createTextNode("")); | ||
| const d = document.createElement("span"); | ||
| d.setAttribute(ce, n), d.appendChild(document.createTextNode("")); | ||
| const c = a.cloneRange(); | ||
| c.collapse(!1), c.insertNode(f); | ||
| const s = a.cloneRange(); | ||
| s.collapse(!1), s.insertNode(u); | ||
| const m = a.cloneRange(); | ||
| return m.collapse(!0), m.insertNode(d), { collapsed: !1, startId: n, endId: r, fallbackOffsets: o }; | ||
| return m.collapse(!0), m.insertNode(f), { collapsed: !1, startId: r, endId: n, fallbackOffsets: o }; | ||
| } catch { | ||
| return { collapsed: a.collapsed, fallbackOffsets: o }; | ||
| } | ||
| }, Je = (e) => { | ||
| }, Ye = (e) => { | ||
| e.querySelectorAll( | ||
| `[${le}], [${ce}], [${se}]` | ||
| `[${ce}], [${se}], [${de}]` | ||
| ).forEach((t) => t.remove()); | ||
| }, Qe = (e, t) => { | ||
| }, Ze = (e, t) => { | ||
| if (!t) return !1; | ||
@@ -657,8 +674,8 @@ const a = window.getSelection(); | ||
| if (t.collapsed && t.caretId) { | ||
| const n = e.querySelector(`[${le}="${t.caretId}"]`); | ||
| return !n || !n.parentNode ? !1 : (o.setStartAfter(n), o.collapse(!0), a.removeAllRanges(), a.addRange(o), !0); | ||
| const r = e.querySelector(`[${ce}="${t.caretId}"]`); | ||
| return !r || !r.parentNode ? !1 : (o.setStartAfter(r), o.collapse(!0), a.removeAllRanges(), a.addRange(o), !0); | ||
| } | ||
| if (!t.collapsed && t.startId && t.endId) { | ||
| const n = e.querySelector(`[${ce}="${t.startId}"]`), r = e.querySelector(`[${se}="${t.endId}"]`); | ||
| return !n || !r || !n.parentNode || !r.parentNode ? !1 : (o.setStartAfter(n), o.setEndBefore(r), a.removeAllRanges(), a.addRange(o), !0); | ||
| const r = e.querySelector(`[${se}="${t.startId}"]`), n = e.querySelector(`[${de}="${t.endId}"]`); | ||
| return !r || !n || !r.parentNode || !n.parentNode ? !1 : (o.setStartAfter(r), o.setEndBefore(n), a.removeAllRanges(), a.addRange(o), !0); | ||
| } | ||
@@ -669,3 +686,3 @@ } catch { | ||
| return !1; | ||
| }, Ye = (e, t) => { | ||
| }, et = (e, t) => { | ||
| if (!t) return; | ||
@@ -675,7 +692,7 @@ const a = window.getSelection(); | ||
| try { | ||
| const o = pe(e, t.start), n = pe(e, t.end), r = document.createRange(); | ||
| r.setStart(o.node, o.offset), r.setEnd(n.node, n.offset), a.removeAllRanges(), a.addRange(r); | ||
| const o = ye(e, t.start), r = ye(e, t.end), n = document.createRange(); | ||
| n.setStart(o.node, o.offset), n.setEnd(r.node, r.offset), a.removeAllRanges(), a.addRange(n); | ||
| } catch { | ||
| } | ||
| }, Ze = ({ | ||
| }, tt = ({ | ||
| editor: e, | ||
@@ -685,126 +702,128 @@ defaultValue: t, | ||
| readonly: o = !1, | ||
| placeholder: n, | ||
| onChange: r, | ||
| pasteConfig: f, | ||
| contentConfig: d, | ||
| securityConfig: c, | ||
| placeholder: r, | ||
| onChange: n, | ||
| pasteConfig: u, | ||
| contentConfig: f, | ||
| securityConfig: s, | ||
| performanceConfig: m, | ||
| accessibilityConfig: s, | ||
| autosaveConfig: y, | ||
| accessibilityConfig: c, | ||
| autosaveConfig: R, | ||
| contextMenuConfig: A, | ||
| spellcheckConfig: T | ||
| }) => { | ||
| 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 S = Math.max(b, u.scrollHeight); | ||
| const l = L(null), H = a !== void 0, I = L(), v = f?.autoHeight === !0, y = typeof f?.minHeight == "number" ? f.minHeight : 200, g = typeof f?.maxHeight == "number" ? f.maxHeight : 0, M = (b) => { | ||
| if (!b || !v) return; | ||
| b.style.height = "auto"; | ||
| const d = Math.max(y, b.scrollHeight); | ||
| if (g > 0) { | ||
| u.style.height = `${Math.min(S, g)}px`; | ||
| b.style.height = `${Math.min(d, g)}px`; | ||
| return; | ||
| } | ||
| u.style.height = `${S}px`; | ||
| }, { restore: z } = Ue( | ||
| b.style.height = `${d}px`; | ||
| }, { restore: N } = je( | ||
| () => l.current?.innerHTML || "", | ||
| y | ||
| R | ||
| ); | ||
| B(() => { | ||
| F(() => { | ||
| 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(() => { | ||
| const b = N(), d = b ?? a ?? t ?? ""; | ||
| d.trim() ? l.current.innerHTML !== d && (l.current.innerHTML = d) : r ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), J(l.current, r), M(l.current), b && n && n(b); | ||
| }, []), F(() => { | ||
| !l.current || !H || (a !== l.current.innerHTML && (l.current.innerHTML = a), J(l.current, r), M(l.current)); | ||
| }, [a, H]), F(() => { | ||
| if (!l.current) return; | ||
| const u = l.current; | ||
| if (n) { | ||
| u.setAttribute("data-placeholder", n), Q(u) && (u.innerHTML = ""), G(u, n), L(u); | ||
| const b = l.current; | ||
| if (r) { | ||
| b.setAttribute("data-placeholder", r), Z(b) && (b.innerHTML = ""), J(b, r), M(b); | ||
| return; | ||
| } | ||
| u.removeAttribute("data-placeholder"), G(u, n), L(u); | ||
| }, [n]), B(() => { | ||
| b.removeAttribute("data-placeholder"), J(b, r), M(b); | ||
| }, [r]), F(() => { | ||
| 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 W = n?.trim(); | ||
| W ? u.setAttribute("aria-label", W) : u.removeAttribute("aria-label"); | ||
| const b = l.current; | ||
| if (c?.enableARIA !== !1) { | ||
| b.setAttribute("role", "textbox"), b.setAttribute("aria-multiline", "true"), b.setAttribute("aria-disabled", o ? "true" : "false"); | ||
| const C = r?.trim(); | ||
| C ? b.setAttribute("aria-label", C) : b.removeAttribute("aria-label"); | ||
| } else | ||
| u.removeAttribute("role"), u.removeAttribute("aria-multiline"), u.removeAttribute("aria-label"), u.removeAttribute("aria-disabled"); | ||
| }, [s?.enableARIA, n, o]), B(() => { | ||
| L(l.current); | ||
| }, [w, b, g, a]), B(() => { | ||
| b.removeAttribute("role"), b.removeAttribute("aria-multiline"), b.removeAttribute("aria-label"), b.removeAttribute("aria-disabled"); | ||
| }, [c?.enableARIA, r, o]), F(() => { | ||
| M(l.current); | ||
| }, [v, y, g, a]), F(() => { | ||
| if (!l.current) return; | ||
| const u = () => { | ||
| const b = () => { | ||
| 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 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; | ||
| r && Z(l.current) && (l.current.innerHTML = ""); | ||
| let x = l.current.innerHTML; | ||
| if (s?.sanitizeOnInput !== !1 && f?.sanitize !== !1) { | ||
| const S = pe(x, f, s); | ||
| if (S !== l.current.innerHTML) { | ||
| const W = Qe(l.current), q = l.current.innerHTML, O = pe(q, f, s); | ||
| l.current.innerHTML = O, Ze(l.current, W) || et(l.current, W?.fallbackOffsets || null), Ye(l.current), x = l.current.innerHTML; | ||
| } else | ||
| R = M; | ||
| x = S; | ||
| } | ||
| G(l.current, n), L(l.current), r && (m?.debounceInputMs ? (N.current && clearTimeout(N.current), N.current = setTimeout(() => { | ||
| r(R); | ||
| }, m.debounceInputMs)) : r(R)); | ||
| }, S = (R) => { | ||
| J(l.current, r), M(l.current), n && (m?.debounceInputMs ? (I.current && clearTimeout(I.current), I.current = setTimeout(() => { | ||
| n(x); | ||
| }, m.debounceInputMs)) : n(x)); | ||
| }, d = (x) => { | ||
| if (x.__editoraSmartPasteHandled === !0 || x.defaultPrevented) | ||
| return; | ||
| if (o) { | ||
| R.preventDefault(); | ||
| x.preventDefault(); | ||
| return; | ||
| } | ||
| R.preventDefault(); | ||
| 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) { | ||
| F && document.execCommand("insertText", !1, F); | ||
| x.preventDefault(); | ||
| let S = x.clipboardData?.getData("text/html"); | ||
| const W = x.clipboardData?.getData("text/plain"), q = !!S && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(S); | ||
| if (u?.clean || !u?.keepFormatting) { | ||
| W && document.execCommand("insertText", !1, W); | ||
| return; | ||
| } | ||
| if (f?.convertWord === !1 && _) { | ||
| F && document.execCommand("insertText", !1, F); | ||
| if (u?.convertWord === !1 && q) { | ||
| W && document.execCommand("insertText", !1, W); | ||
| return; | ||
| } | ||
| 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 q = document.createElement("div"); | ||
| q.innerHTML = M; | ||
| if (S) { | ||
| s?.sanitizeOnPaste !== !1 && f?.sanitize !== !1 && (S = Xe(S, f, s)); | ||
| const O = window.getSelection(); | ||
| if (O && O.rangeCount > 0) { | ||
| const B = O.getRangeAt(0); | ||
| B.deleteContents(); | ||
| const U = document.createElement("div"); | ||
| U.innerHTML = S; | ||
| const X = document.createDocumentFragment(); | ||
| for (; q.firstChild; ) | ||
| X.appendChild(q.firstChild); | ||
| P.insertNode(X), P.collapse(!1), $.removeAllRanges(), $.addRange(P); | ||
| for (; U.firstChild; ) | ||
| X.appendChild(U.firstChild); | ||
| B.insertNode(X), B.collapse(!1), O.removeAllRanges(), O.addRange(B); | ||
| } | ||
| } 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); | ||
| } else W && document.execCommand("insertText", !1, W); | ||
| }, C = (x) => { | ||
| const S = x.target; | ||
| (S.tagName === "IMG" || S.tagName === "VIDEO") && (S.style.resize = "both", S.style.overflow = "auto", S.style.display = "inline-block"); | ||
| }, E = (x) => { | ||
| A?.enabled === !1 && x.preventDefault(); | ||
| }, z = () => { | ||
| l.current && (r && Z(l.current) && (l.current.innerHTML = ""), J(l.current, r), M(l.current)); | ||
| }, p = l.current; | ||
| return p.addEventListener("input", b), p.addEventListener("paste", d), p.addEventListener("click", C), p.addEventListener("contextmenu", E), p.addEventListener("focus", z), p.addEventListener("blur", z), o || p.focus(), () => { | ||
| I.current && clearTimeout(I.current), p.removeEventListener("input", b), p.removeEventListener("paste", d), p.removeEventListener("click", C), p.removeEventListener("contextmenu", E), p.removeEventListener("focus", z), p.removeEventListener("blur", z); | ||
| }; | ||
| }, [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) | ||
| }, [e, n, u, f, s, m, r, A, o]); | ||
| const _ = (T?.enabled ?? !1) && (T?.provider ?? "browser") === "browser"; | ||
| return F(() => { | ||
| if (!l.current || typeof window > "u" || o || c?.keyboardNavigation === !1) | ||
| return; | ||
| const u = new Ee(), S = l.current, W = (E) => { | ||
| u.handleKeyDown(E, (D, C) => { | ||
| const b = new ke(), d = l.current, C = (E) => { | ||
| b.handleKeyDown(E, (z, p) => { | ||
| if (typeof window < "u" && window.executeEditorCommand) { | ||
| const R = l.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = R || null, window.executeEditorCommand(D, C); | ||
| const x = l.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = x || null, window.executeEditorCommand(z, p); | ||
| } | ||
| }); | ||
| }; | ||
| return S.addEventListener("keydown", W), () => { | ||
| S.removeEventListener("keydown", W); | ||
| return d.addEventListener("keydown", C), () => { | ||
| d.removeEventListener("keydown", C); | ||
| }; | ||
| }, [s?.keyboardNavigation, o]), /* @__PURE__ */ h( | ||
| }, [c?.keyboardNavigation, o]), /* @__PURE__ */ h( | ||
| "div", | ||
@@ -815,12 +834,12 @@ { | ||
| suppressContentEditableWarning: !0, | ||
| spellCheck: o ? !1 : p, | ||
| tabIndex: s?.keyboardNavigation === !1 ? -1 : 0, | ||
| "aria-keyshortcuts": s?.keyboardNavigation === !1 ? void 0 : "Ctrl+B Ctrl+I Ctrl+U Ctrl+Z Ctrl+Y", | ||
| spellCheck: o ? !1 : _, | ||
| 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": m?.viewportOnlyScan ? "true" : "false", | ||
| "data-a11y-checker": s?.checker ? "true" : "false", | ||
| "data-a11y-checker": c?.checker ? "true" : "false", | ||
| "data-readonly": o ? "true" : "false", | ||
| className: `rte-content ${o ? "rte-content-readonly" : ""}`, | ||
| style: { | ||
| minHeight: `${b}px`, | ||
| maxHeight: w ? g > 0 ? `${g}px` : "none" : "100%", | ||
| minHeight: `${y}px`, | ||
| maxHeight: v ? g > 0 ? `${g}px` : "none" : "100%", | ||
| padding: "16px", | ||
@@ -832,11 +851,12 @@ outline: "none", | ||
| lineHeight: "1.5", | ||
| overflow: w ? g > 0 ? "auto" : "hidden" : "auto", | ||
| flex: w ? void 0 : 1, | ||
| overflow: v ? g > 0 ? "auto" : "hidden" : "auto", | ||
| flex: v ? void 0 : 1, | ||
| boxSizing: "border-box", | ||
| wordWrap: "break-word", | ||
| overflowWrap: "break-word" | ||
| overflowWrap: "break-word", | ||
| marginBottom: "16px" | ||
| } | ||
| } | ||
| ); | ||
| }, et = ({ | ||
| }, nt = ({ | ||
| editor: e, | ||
@@ -847,82 +867,101 @@ isEnabled: t, | ||
| }) => { | ||
| 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(() => { | ||
| const [r, n] = G(!1), [u, f] = G({ top: 0, left: 0 }), s = L(null), m = L(null), c = L(null), R = L(null), A = L(null); | ||
| F(() => { | ||
| if (!t || o) { | ||
| r(!1); | ||
| n(!1); | ||
| return; | ||
| } | ||
| A.current = c.current?.closest("[data-editora-editor]"); | ||
| const l = (p) => { | ||
| A.current = s.current?.closest("[data-editora-editor]"); | ||
| const l = (d) => { | ||
| if (A.current) return A.current; | ||
| const u = c.current?.closest("[data-editora-editor]"); | ||
| if (u) | ||
| 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; | ||
| const C = s.current?.closest("[data-editora-editor]"); | ||
| if (C) | ||
| return A.current = C, C; | ||
| const E = d?.commonAncestorContainer, p = (E ? E.nodeType === Node.ELEMENT_NODE ? E : E.parentElement : null)?.closest("[data-editora-editor]"); | ||
| return p ? (A.current = p, p) : null; | ||
| }, H = (d) => d && d.querySelector(".rte-content, .editora-content") || null, I = (d) => { | ||
| if (!d || o) return !0; | ||
| const C = d.getAttribute("contenteditable"), E = d.getAttribute("data-readonly"); | ||
| return C === "false" || E === "true" ? !0 : !!d.closest( | ||
| '[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]' | ||
| ); | ||
| }, v = (d) => { | ||
| if (!d.anchorNode || !d.focusNode) return !1; | ||
| try { | ||
| const u = document.createRange(); | ||
| return u.setStart(p.anchorNode, p.anchorOffset), u.setEnd(p.focusNode, p.focusOffset), u.collapsed; | ||
| const C = document.createRange(); | ||
| return C.setStart(d.anchorNode, d.anchorOffset), C.setEnd(d.focusNode, d.focusOffset), C.collapsed; | ||
| } catch { | ||
| return !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 = () => { | ||
| y.current && clearTimeout(y.current); | ||
| const p = window.getSelection(); | ||
| if (!p || p.rangeCount === 0) { | ||
| r(!1), s.current = null; | ||
| }, y = (d, C) => { | ||
| const E = Array.from(C.getClientRects()).filter((p) => p.width > 0 || p.height > 0); | ||
| return E.length === 0 ? C.getBoundingClientRect() : v(d) ? E[0] : E[E.length - 1]; | ||
| }, g = () => { | ||
| R.current && clearTimeout(R.current); | ||
| const d = window.getSelection(); | ||
| if (!d || d.rangeCount === 0) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| const u = p.getRangeAt(0); | ||
| if (u.collapsed) { | ||
| r(!1), s.current = null; | ||
| const C = d.getRangeAt(0); | ||
| if (C.collapsed) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| const S = p.toString().trim(), W = l(u), E = H(W); | ||
| if (!E || !E.contains(u.commonAncestorContainer)) { | ||
| r(!1), s.current = null; | ||
| const E = d.toString().trim(), z = l(C), p = H(z); | ||
| if (!p || !p.contains(C.commonAncestorContainer)) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| if (I(p)) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| if (a) { | ||
| 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; | ||
| const x = p.getBoundingClientRect(), S = x.bottom >= 0 && x.top <= window.innerHeight, W = document.activeElement === p || p.contains(document.activeElement); | ||
| if (!S && !W) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| } | ||
| 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(); | ||
| if (E.length > 0) { | ||
| const x = y(d, C), S = p.getBoundingClientRect(), W = 300; | ||
| if (x && S) { | ||
| const q = Math.max(8, x.top - 50); | ||
| let O = x.left + x.width / 2; | ||
| const B = W / 2, U = S.left, X = S.right; | ||
| O - B < U && (O = U + B + 10), O + B > X && (O = X - B - 10), f({ top: q, left: O }), n(!0), c.current = C.cloneRange(); | ||
| } | ||
| } else | ||
| 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); | ||
| n(!1), c.current = null; | ||
| }, M = (d) => { | ||
| if (m.current && !m.current.contains(d.target)) { | ||
| const C = l(); | ||
| window.getSelection(), H(C)?.contains(d.target) || (n(!1), c.current = null); | ||
| } | ||
| }, 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); | ||
| }, N = (d) => { | ||
| d.key === "Escape" && (n(!1), c.current = null); | ||
| }, _ = H(l()), b = _ && typeof MutationObserver < "u" ? new MutationObserver(() => { | ||
| I(_) && (n(!1), c.current = null); | ||
| }) : null; | ||
| return b && _ && b.observe(_, { | ||
| attributes: !0, | ||
| attributeFilter: ["contenteditable", "data-readonly"] | ||
| }), document.addEventListener("selectionchange", g), document.addEventListener("mousedown", M), document.addEventListener("keydown", N), _?.addEventListener("mouseup", g), _?.addEventListener("keyup", g), () => { | ||
| document.removeEventListener("selectionchange", g), document.removeEventListener("mousedown", M), document.removeEventListener("keydown", N), _?.removeEventListener("mouseup", g), _?.removeEventListener("keyup", g), b?.disconnect(), R.current && clearTimeout(R.current); | ||
| }; | ||
| }, [t, a, o]); | ||
| const T = (l, H) => { | ||
| if (o || !s.current) return; | ||
| if (o || !c.current) return; | ||
| typeof window < "u" && (window.__editoraCommandEditorRoot = A.current || null); | ||
| const N = A.current?.querySelector(".rte-content"); | ||
| N && N.focus(); | ||
| const w = window.getSelection(); | ||
| if (w && s.current) | ||
| const I = A.current?.querySelector(".rte-content, .editora-content"); | ||
| if (I && (I.getAttribute("contenteditable") === "false" || I.getAttribute("data-readonly") === "true")) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| I && I.focus(); | ||
| const v = window.getSelection(); | ||
| if (v && c.current) | ||
| try { | ||
| w.removeAllRanges(), w.addRange(s.current); | ||
| v.removeAllRanges(), v.addRange(c.current); | ||
| } catch { | ||
@@ -944,4 +983,4 @@ } | ||
| if (g && g.rangeCount > 0) { | ||
| const L = g.getRangeAt(0), z = document.createElement("code"); | ||
| L.surroundContents(z); | ||
| const M = g.getRangeAt(0), N = document.createElement("code"); | ||
| M.surroundContents(N); | ||
| } | ||
@@ -953,12 +992,12 @@ }, | ||
| if (g && g.rangeCount > 0) { | ||
| 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"); | ||
| const M = g.getRangeAt(0); | ||
| (M.commonAncestorContainer.nodeType === Node.TEXT_NODE ? M.commonAncestorContainer.parentElement : M.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote"); | ||
| } | ||
| } else H && document.execCommand("formatBlock", !1, H); | ||
| } | ||
| })[l]?.(), r(!1), s.current = null; | ||
| })[l]?.(), n(!1), c.current = null; | ||
| }; | ||
| return !t || o ? /* @__PURE__ */ h("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(Y, { children: [ | ||
| /* @__PURE__ */ h("span", { ref: c, style: { display: "none" }, "aria-hidden": "true" }), | ||
| n && /* @__PURE__ */ V( | ||
| return !t || o ? /* @__PURE__ */ h("span", { ref: s, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(ee, { children: [ | ||
| /* @__PURE__ */ h("span", { ref: s, style: { display: "none" }, "aria-hidden": "true" }), | ||
| r && /* @__PURE__ */ V( | ||
| "div", | ||
@@ -971,4 +1010,4 @@ { | ||
| position: "fixed", | ||
| top: `${f.top}px`, | ||
| left: `${f.left}px`, | ||
| top: `${u.top}px`, | ||
| left: `${u.left}px`, | ||
| transform: "translateX(-50%)", | ||
@@ -1057,15 +1096,15 @@ zIndex: 1e4, | ||
| ] }); | ||
| }, tt = ({ | ||
| }, rt = ({ | ||
| plugins: e, | ||
| children: t | ||
| }) => { | ||
| const a = e.filter((n) => n.context?.provider); | ||
| return a.length === 0 ? /* @__PURE__ */ h(Y, { children: t }) : a.reduce( | ||
| (n, r) => { | ||
| const f = r.context.provider; | ||
| return /* @__PURE__ */ h(f, { children: n }, r.name); | ||
| const a = e.filter((r) => r.context?.provider); | ||
| return a.length === 0 ? /* @__PURE__ */ h(ee, { children: t }) : a.reduce( | ||
| (r, n) => { | ||
| const u = n.context.provider; | ||
| return /* @__PURE__ */ h(u, { children: r }, n.name); | ||
| }, | ||
| /* @__PURE__ */ h(Y, { children: t }) | ||
| /* @__PURE__ */ h(ee, { children: t }) | ||
| ); | ||
| }, Ce = /* @__PURE__ */ new Set(), ye = /* @__PURE__ */ new Set(), ae = (e) => !!e && typeof e == "object" && typeof e.name == "string", Ae = (e) => { | ||
| }, Ce = /* @__PURE__ */ new Set(), Ee = /* @__PURE__ */ new Set(), ie = (e) => !!e && typeof e == "object" && typeof e.name == "string", xe = (e) => { | ||
| const t = e?.pluginFactories; | ||
@@ -1076,17 +1115,17 @@ return { | ||
| }; | ||
| }, nt = (e, t) => { | ||
| }, ot = (e, t) => { | ||
| if (!Array.isArray(e)) return []; | ||
| const a = Ae(t), o = [], n = []; | ||
| if (e.forEach((r) => { | ||
| if (ae(r)) { | ||
| o.push(r); | ||
| const a = xe(t), o = [], r = []; | ||
| if (e.forEach((n) => { | ||
| if (ie(n)) { | ||
| o.push(n); | ||
| return; | ||
| } | ||
| if (typeof r != "string") return; | ||
| const f = a[r]; | ||
| if (typeof f == "function") | ||
| if (typeof n != "string") return; | ||
| const u = a[n]; | ||
| if (typeof u == "function") | ||
| try { | ||
| const d = f(); | ||
| if (ae(d)) { | ||
| o.push(d); | ||
| const f = u(); | ||
| if (ie(f)) { | ||
| o.push(f); | ||
| return; | ||
@@ -1096,7 +1135,7 @@ } | ||
| } | ||
| n.push(r); | ||
| }), n.length > 0) { | ||
| const r = n.slice().sort().join("|"); | ||
| Ce.has(r) || (Ce.add(r), console.warn( | ||
| `[Editora React] Unresolved string plugin names: ${n.join( | ||
| r.push(n); | ||
| }), r.length > 0) { | ||
| const n = r.slice().sort().join("|"); | ||
| Ce.has(n) || (Ce.add(n), console.warn( | ||
| `[Editora React] Unresolved string plugin names: ${r.join( | ||
| ", " | ||
@@ -1107,17 +1146,17 @@ )}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".` | ||
| return o; | ||
| }, rt = (e, t, a) => { | ||
| if (!t?.checker || e.some((r) => r?.name === "a11yChecker")) return e; | ||
| const o = Ae(a).a11yChecker; | ||
| }, at = (e, t, a) => { | ||
| if (!t?.checker || e.some((n) => n?.name === "a11yChecker")) return e; | ||
| const o = xe(a).a11yChecker; | ||
| if (typeof o == "function") | ||
| try { | ||
| const r = o(); | ||
| if (ae(r)) | ||
| return [...e, r]; | ||
| const n = o(); | ||
| if (ie(n)) | ||
| return [...e, n]; | ||
| } catch { | ||
| } | ||
| const n = "accessibility.checker"; | ||
| return ye.has(n) || (ye.add(n), console.warn( | ||
| const r = "accessibility.checker"; | ||
| return Ee.has(r) || (Ee.add(r), console.warn( | ||
| '[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.' | ||
| )), e; | ||
| }, ot = { | ||
| }, it = { | ||
| readonly: !1, | ||
@@ -1200,12 +1239,12 @@ placeholder: "", | ||
| }; | ||
| function xe(e, t) { | ||
| function Te(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); | ||
| const r = t[o], n = a[o]; | ||
| r !== void 0 && (typeof r == "object" && r !== null && !Array.isArray(r) && typeof n == "object" && n !== null && !Array.isArray(n) ? a[o] = Te(n, r) : a[o] = r); | ||
| } | ||
| return a; | ||
| } | ||
| function at(e) { | ||
| const t = xe(ot, { | ||
| function lt(e) { | ||
| const t = Te(it, { | ||
| readonly: e.readonly, | ||
@@ -1250,4 +1289,4 @@ placeholder: e.placeholder, | ||
| onDestroy: e.onDestroy, | ||
| plugins: rt( | ||
| nt(e.plugins, e.pluginConfig), | ||
| plugins: at( | ||
| ot(e.plugins, e.pluginConfig), | ||
| e.accessibility, | ||
@@ -1259,6 +1298,8 @@ e.pluginConfig | ||
| } | ||
| const ie = /* @__PURE__ */ new Map(), it = () => { | ||
| const le = /* @__PURE__ */ new Map(), ct = () => { | ||
| if (typeof window > "u") | ||
| return { editorElement: null, contentElement: null }; | ||
| const e = window.__editoraCommandEditorRoot || null, t = e?.querySelector('[contenteditable="true"]'); | ||
| let e = window.__editoraCommandEditorRoot || null; | ||
| e || (e = (window.__editoraLastCommandButton || null)?.closest("[data-editora-editor], .rte-editor, .editora-editor, editora-editor") || null); | ||
| const t = e?.querySelector(".rte-content, .editora-content") || (e?.matches(".rte-content, .editora-content") ? e : null); | ||
| return { | ||
@@ -1270,7 +1311,7 @@ editorElement: e, | ||
| typeof window < "u" && (window.registerEditorCommand = (e, t) => { | ||
| ie.set(e, t); | ||
| le.set(e, t); | ||
| }, window.executeEditorCommand = (e, t) => { | ||
| const a = ie.get(e); | ||
| const a = le.get(e); | ||
| if (a) { | ||
| const o = it(); | ||
| const o = ct(); | ||
| return a(t, o); | ||
@@ -1280,4 +1321,4 @@ } else | ||
| }); | ||
| const lt = (e) => { | ||
| const t = oe(() => at(e), [ | ||
| const st = (e) => { | ||
| const t = ae(() => lt(e), [ | ||
| e.id, | ||
@@ -1305,10 +1346,10 @@ e.className, | ||
| e.mediaConfig | ||
| ]), 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; | ||
| ]), a = L(null), o = L(null), r = L(e.onInit), n = L(e.onDestroy), u = L(e.onChange), f = L(/* @__PURE__ */ new Set()), s = L(null), m = L(null), c = L(null); | ||
| F(() => { | ||
| r.current = e.onInit, n.current = e.onDestroy, u.current = e.onChange; | ||
| }); | ||
| const y = (w) => { | ||
| f.current?.(w), d.current.forEach((b) => { | ||
| const R = (v) => { | ||
| u.current?.(v), f.current.forEach((y) => { | ||
| try { | ||
| b(w); | ||
| y(v); | ||
| } catch (g) { | ||
@@ -1318,36 +1359,36 @@ console.error("Editora onChange subscriber failed:", g); | ||
| }); | ||
| }, A = oe(() => { | ||
| const w = new He(); | ||
| }, A = ae(() => { | ||
| const v = new Be(); | ||
| t.plugins.forEach((g) => { | ||
| w.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([L, z]) => { | ||
| ie.set(L, z); | ||
| v.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([M, N]) => { | ||
| le.set(M, N); | ||
| }); | ||
| }); | ||
| const b = new De(w); | ||
| return a.current = b, b; | ||
| const y = new Fe(v); | ||
| return a.current = y, y; | ||
| }, [t.plugins]); | ||
| B(() => { | ||
| const w = { | ||
| getHTML: () => c.current?.querySelector(".rte-content")?.innerHTML || "", | ||
| setHTML: (b) => { | ||
| const g = c.current?.querySelector(".rte-content"); | ||
| g && (g.innerHTML = b); | ||
| F(() => { | ||
| const v = { | ||
| getHTML: () => s.current?.querySelector(".rte-content")?.innerHTML || "", | ||
| setHTML: (y) => { | ||
| const g = s.current?.querySelector(".rte-content"); | ||
| g && (g.innerHTML = y); | ||
| }, | ||
| execCommand: (b, g) => { | ||
| typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = c.current || null, window.executeEditorCommand(b, g)); | ||
| execCommand: (y, g) => { | ||
| typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = s.current || null, window.executeEditorCommand(y, g)); | ||
| }, | ||
| registerCommand: (b, g) => { | ||
| typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(b, g); | ||
| registerCommand: (y, g) => { | ||
| typeof window < "u" && window.registerEditorCommand && window.registerEditorCommand(y, g); | ||
| }, | ||
| focus: () => { | ||
| c.current?.querySelector(".rte-content")?.focus(); | ||
| s.current?.querySelector(".rte-content")?.focus(); | ||
| }, | ||
| blur: () => { | ||
| c.current?.querySelector(".rte-content")?.blur(); | ||
| s.current?.querySelector(".rte-content")?.blur(); | ||
| }, | ||
| destroy: () => { | ||
| r.current && r.current(); | ||
| n.current && n.current(); | ||
| }, | ||
| onChange: (b) => (d.current.add(b), () => { | ||
| d.current.delete(b); | ||
| onChange: (y) => (f.current.add(y), () => { | ||
| f.current.delete(y); | ||
| }), | ||
@@ -1362,42 +1403,42 @@ getState: () => ({ | ||
| }; | ||
| return o.current = w, n.current && n.current(w), () => { | ||
| d.current.clear(), r.current && r.current(); | ||
| return o.current = v, r.current && r.current(v), () => { | ||
| f.current.clear(), n.current && n.current(); | ||
| }; | ||
| }, []), B(() => { | ||
| if (t.statusbar.enabled && s.current && c.current) { | ||
| m.current || (m.current = new Fe({ | ||
| }, []), F(() => { | ||
| if (t.statusbar.enabled && c.current && s.current) { | ||
| m.current || (m.current = new _e({ | ||
| enabled: !0, | ||
| position: t.statusbar.position | ||
| }), m.current.create(s.current)); | ||
| const w = c.current.querySelector(".rte-content"); | ||
| if (w) { | ||
| const b = () => { | ||
| }), m.current.create(c.current)); | ||
| const v = s.current.querySelector(".rte-content"); | ||
| if (v) { | ||
| const y = () => { | ||
| const E = document.activeElement; | ||
| return !!E && (E === w || w.contains(E)); | ||
| return !!E && (E === v || v.contains(E)); | ||
| }, g = () => { | ||
| const E = w.getBoundingClientRect(); | ||
| const E = v.getBoundingClientRect(); | ||
| return E.bottom >= 0 && E.top <= window.innerHeight; | ||
| }, L = () => { | ||
| }, M = () => { | ||
| 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()) | ||
| const z = E.getRangeAt(0), p = z.commonAncestorContainer; | ||
| return v.contains(p) ? z : null; | ||
| }, N = (E = !1) => { | ||
| if (t.performance.viewportOnlyScan !== !1 && !g() && !y()) | ||
| return; | ||
| const C = L(), R = !!C || b(); | ||
| if (E && !R) | ||
| const p = M(), x = !!p || y(); | ||
| if (E && !x) | ||
| return; | ||
| 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: q | ||
| const S = v.textContent || "", { words: W, chars: q } = ze(S), O = Oe(v); | ||
| let B, U; | ||
| p && (B = We(v, p), p.collapsed || (U = Pe(p, B), B = void 0)), m.current?.update({ | ||
| wordCount: W, | ||
| charCount: q, | ||
| lineCount: O, | ||
| cursorPosition: B, | ||
| selectionInfo: 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); | ||
| }, _ = () => N(), b = () => N(!0), d = () => N(), C = () => N(); | ||
| return v.addEventListener("input", _), v.addEventListener("focus", d), v.addEventListener("blur", C), document.addEventListener("selectionchange", b), N(), () => { | ||
| v.removeEventListener("input", _), v.removeEventListener("focus", d), v.removeEventListener("blur", C), document.removeEventListener("selectionchange", b); | ||
| }; | ||
@@ -1411,7 +1452,7 @@ } | ||
| }, [t.statusbar.enabled, t.statusbar.position, t.performance.viewportOnlyScan]); | ||
| 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( | ||
| const T = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", H = t.toolbar.sticky ?? !1, I = t.toolbar.showMoreOptions ?? !0; | ||
| return /* @__PURE__ */ h(rt, { plugins: t.plugins, children: /* @__PURE__ */ V( | ||
| "div", | ||
| { | ||
| ref: c, | ||
| ref: s, | ||
| id: t.id, | ||
@@ -1430,3 +1471,3 @@ "data-editora-editor": !0, | ||
| l !== "bottom" && /* @__PURE__ */ h( | ||
| we, | ||
| ve, | ||
| { | ||
@@ -1438,3 +1479,3 @@ editor: A, | ||
| readonly: t.readonly, | ||
| showMoreOptions: N, | ||
| showMoreOptions: I, | ||
| itemsOverride: t.toolbar.items | ||
@@ -1444,3 +1485,3 @@ } | ||
| /* @__PURE__ */ h( | ||
| Ze, | ||
| tt, | ||
| { | ||
@@ -1452,3 +1493,3 @@ editor: A, | ||
| placeholder: t.placeholder, | ||
| onChange: y, | ||
| onChange: R, | ||
| pasteConfig: t.paste, | ||
@@ -1465,3 +1506,3 @@ contentConfig: t.content, | ||
| l === "bottom" && /* @__PURE__ */ h( | ||
| we, | ||
| ve, | ||
| { | ||
@@ -1473,3 +1514,3 @@ editor: A, | ||
| readonly: t.readonly, | ||
| showMoreOptions: N, | ||
| showMoreOptions: I, | ||
| itemsOverride: t.toolbar.items | ||
@@ -1479,3 +1520,3 @@ } | ||
| /* @__PURE__ */ h( | ||
| et, | ||
| nt, | ||
| { | ||
@@ -1491,3 +1532,3 @@ editor: A, | ||
| { | ||
| ref: s, | ||
| ref: c, | ||
| className: "editora-statusbar-container", | ||
@@ -1500,16 +1541,16 @@ style: { order: t.statusbar.position === "top" ? -1 : 1 } | ||
| ) }); | ||
| }, ft = (e) => /* @__PURE__ */ h(lt, { ...e }); | ||
| function mt(e = {}) { | ||
| const t = x(null), a = x(e.onCommand); | ||
| return B(() => { | ||
| }, gt = (e) => /* @__PURE__ */ h(st, { ...e }); | ||
| function ht(e = {}) { | ||
| const t = L(null), a = L(e.onCommand); | ||
| return F(() => { | ||
| a.current = e.onCommand; | ||
| }), B(() => { | ||
| }), F(() => { | ||
| if (typeof window > "u" || e.enabled === !1) return; | ||
| const o = new Ee(e); | ||
| const o = new ke(e); | ||
| t.current = o; | ||
| const n = (f) => o.handleKeyDown(f, (c, m) => { | ||
| a.current && a.current(c, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(c, m); | ||
| }), r = e.editorElement || document; | ||
| return r && r.addEventListener("keydown", n), () => { | ||
| r && r.removeEventListener("keydown", n); | ||
| const r = (u) => o.handleKeyDown(u, (s, m) => { | ||
| a.current && a.current(s, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(s, m); | ||
| }), n = e.editorElement || document; | ||
| return n && n.addEventListener("keydown", r), () => { | ||
| n && n.removeEventListener("keydown", r); | ||
| }; | ||
@@ -1526,9 +1567,9 @@ }, [e.editorElement, e.enabled, e.shortcuts, e.customShortcuts]), { | ||
| export { | ||
| Ze as EditorContent, | ||
| ft as EditoraEditor, | ||
| Oe as InlineMenu, | ||
| ft as RichTextEditor, | ||
| we as Toolbar, | ||
| at as mergeConfig, | ||
| mt as useKeyboardShortcuts | ||
| tt as EditorContent, | ||
| gt as EditoraEditor, | ||
| $e as InlineMenu, | ||
| gt as RichTextEditor, | ||
| ve as Toolbar, | ||
| lt as mergeConfig, | ||
| ht as useKeyboardShortcuts | ||
| }; |
+4
-4
| { | ||
| "name": "@editora/react", | ||
| "version": "1.0.9", | ||
| "version": "1.0.10", | ||
| "description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.", | ||
@@ -76,6 +76,6 @@ "author": "Ajay Kumar <ajaykr089@gmail.com>", | ||
| "dependencies": { | ||
| "@editora/light-code-editor": "^1.0.6" | ||
| "@editora/light-code-editor": "^1.0.7" | ||
| }, | ||
| "devDependencies": { | ||
| "@editora/core": "^1.0.7", | ||
| "@editora/core": "^1.0.8", | ||
| "@types/react": "^18.2.0", | ||
@@ -89,3 +89,3 @@ "@types/react-dom": "^18.2.0", | ||
| }, | ||
| "gitHead": "694494db58b809f0dcf24501696284faa1ab68a5" | ||
| "gitHead": "80e0808ae4909de63b8e0f1dd915b06b33a8ed44" | ||
| } |
+2
-1
@@ -25,3 +25,4 @@ # @editora/react | ||
| - When using `@editora/plugins`, also import `@editora/plugins/styles.css` for plugin UI surfaces (table toolbar, dialogs, pickers). | ||
| - For smaller bundles: prefer `@editora/plugins/lite` or per-plugin subpaths like `@editora/plugins/bold`, and lazy-load heavy plugins (`document-manager`, `media-manager`, `spell-check`) via dynamic imports. | ||
| - For plugin imports: use `@editora/plugins` (full), `@editora/plugins/lite` (common), `@editora/plugins/enterprise` (advanced), or per-plugin subpaths like `@editora/plugins/bold`. | ||
| - All plugin entry paths are free and fully customizable. | ||
@@ -28,0 +29,0 @@ Minimal install: |
107749
4.67%6
20%1832
2.75%555
0.18%