@editora/react
Advanced tools
@@ -1,1 +0,1 @@ | ||
| "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; | ||
| "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const d=require("react/jsx-runtime"),l=require("react"),U=require("@editora/core"),Pe=e=>e&&e.__esModule?e:{default:e},$e=Pe(l),ke=({isOpen:e,options:t,onSelect:o,onClose:a,anchorRef:r,className:n=""})=>{const g=l.useRef(null),[m,h]=l.useState(null),u=()=>{if(!e||!r.current)return;const c=r.current.getBoundingClientRect(),T=g.current?.getBoundingClientRect(),S=T?.width||120,R=T?.height||t.length*36,s=8,j=4,M=window.innerWidth,p=window.innerHeight;let E=c.bottom+j,b=c.left;b+S>M-s&&(b=M-S-s),b<s&&(b=s),E+R>p-s&&(E=c.top-R-j),E<s&&(E=s),h({top:E,left:b})};return l.useLayoutEffect(()=>{if(!e){h(null);return}u();const c=window.requestAnimationFrame(u);return()=>{window.cancelAnimationFrame(c)}},[e,t.length,r]),l.useEffect(()=>{if(!e)return;const c=()=>{u()};return window.addEventListener("resize",c),window.addEventListener("scroll",c,!0),()=>{window.removeEventListener("resize",c),window.removeEventListener("scroll",c,!0)}},[e,t.length,r]),l.useEffect(()=>{const c=S=>{g.current&&!g.current.contains(S.target)&&r.current&&!r.current.contains(S.target)&&a()},T=S=>{S.key==="Escape"&&a()};return e&&(document.addEventListener("mousedown",c),document.addEventListener("keydown",T)),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",T)}},[e,a,r]),e?d.jsx("div",{ref:g,className:`rte-inline-menu ${n}`,style:{top:m?.top??-9999,left:m?.left??-9999,visibility:m?"visible":"hidden"},children:t.map(c=>d.jsx("div",{className:"rte-inline-menu-item",onClick:()=>{o(c.value),a()},children:c.label},c.value))}):null},Q=e=>e.toLowerCase().replace(/[^a-z0-9]/g,""),qe=(e,t)=>`${t}:${e.type}:${e.command||""}:${e.label||""}`,Ue=typeof window<"u"?l.useLayoutEffect:l.useEffect,Ke={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"},Ve=(e,t)=>{if(t==null||t==="")return e;const o=typeof t=="string"?[t]:t;if(!Array.isArray(o)||o.length===0)return e;if(!o.every(u=>typeof u=="string"))return o;const r=new Map,n=new Map;e.forEach(u=>{r.set(Q(u.command||""),u),n.set(Q(u.label||""),u)});const g=o.flatMap(u=>u.split(/\s+/)).map(u=>u.trim()).filter(Boolean),m=[];let h=0;return g.forEach(u=>{if(u==="|"){h+=1,m.push({type:"separator",command:`__separator__${h}`,label:"|"});return}const c=Q(u),T=Ke[c],S=r.get(c)||(T?r.get(Q(T)):void 0)||n.get(c)||e.find(R=>Q(R.command||"").includes(c));S&&m.push(S)}),m.length>0?m:e},ie=({editor:e,position:t="top",sticky:o=!1,floating:a=!1,readonly:r=!1,showMoreOptions:n=!0,itemsOverride:g})=>{const[m,h]=l.useState(!1),[u,c]=l.useState(null),[T,S]=l.useState(null),[R,s]=l.useState(null),[j,M]=l.useState(!1),p=l.useRef(null),E=l.useRef(!1),b=l.useRef(null),I=l.useRef(null),_=l.useRef({}),F=l.useRef({}),v=l.useRef(""),f=l.useRef(null),C=l.useRef(null),k=l.useRef(null),D=l.useMemo(()=>Ve(e.pluginManager.getToolbarItems(),g),[e,g]),y=l.useMemo(()=>D.map((i,x)=>qe(i,x)),[D]);l.useEffect(()=>{p.current=R},[R]),l.useEffect(()=>{E.current=j},[j]);const A=i=>{b.current=i,i&&!i.collapsed&&(I.current=i)},L=()=>f.current?.closest("[data-editora-editor]")?.querySelector(".rte-content")||null,B=()=>{if(typeof window>"u")return;const i=f.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=i||null},$=i=>{if(typeof window>"u"||!i)return;const x=i.getAttribute("data-command");x&&(window.__editoraLastCommandButton=i,window.__editoraLastCommand=x)},z=()=>{const i=L();if(!i)return null;const x=window.getSelection();if(!x||x.rangeCount===0)return null;const w=x.getRangeAt(0);return i.contains(w.commonAncestorContainer)?w.cloneRange():null},H=()=>{const i=z();i&&A(i)};l.useEffect(()=>{const i=f.current?.closest("[data-editora-editor]");if(!i)return;const x=i.querySelector(".rte-content, .editora-content");h(x?.getAttribute("data-track-changes")==="true");const w=O=>{h(!!O.detail?.enabled)};return i.addEventListener("editora:track-changes-toggle",w),()=>{i.removeEventListener("editora:track-changes-toggle",w)}},[]),l.useEffect(()=>{const i=()=>{H()};return document.addEventListener("selectionchange",i),()=>{document.removeEventListener("selectionchange",i)}},[]),l.useEffect(()=>{if(!u)return;const i=w=>{const O=w.target;O&&O instanceof Element&&(O.closest(".rte-toolbar-dropdown")||c(null))},x=w=>{w.key==="Escape"&&c(null)};return document.addEventListener("pointerdown",i,!0),document.addEventListener("keydown",x),()=>{document.removeEventListener("pointerdown",i,!0),document.removeEventListener("keydown",x)}},[u]);const P=i=>["toggleBold","toggleItalic","toggleUnderline","toggleStrikethrough","openTextColorPicker","openBackgroundColorPicker","openLinkDialog","removeLink","toggleCode"].includes(i),K=(i=!1)=>{const x=L();if(!x)return!1;const w=window.getSelection();if(!w)return!1;const O=w.rangeCount>0&&x.contains(w.getRangeAt(0).commonAncestorContainer),N=i?I.current||b.current:b.current||I.current;if(i&&N&&N.collapsed)return!1;if(N&&x.contains(N.commonAncestorContainer))try{return x.focus({preventScroll:!0}),w.removeAllRanges(),w.addRange(N),!0}catch{}return O};Ue(()=>{if(!n){s(null),M(!1),p.current=null,E.current=!1,F.current={},v.current="";return}const i=y.join("|");if(v.current!==i&&(v.current=i,F.current={},E.current&&(E.current=!1,M(!1)),p.current!==null)){p.current=null,s(null);return}let w=null;const O=()=>{if(!f.current||!C.current)return;const W=f.current.clientWidth,ee=16,ze=40,he=4,We=Math.max(0,W-ee-ze-he);let be=0,we=0;const te=C.current.children;for(let V=0;V<te.length;V++){const Oe=te[V],G=y[V],re=G?F.current[G]:void 0,oe=typeof re=="number"&&re>0?re:Oe.getBoundingClientRect().width;G&&oe>0&&(F.current[G]=oe);const ve=(G?F.current[G]:void 0)??oe,pe=(ve>0?ve:40)+he;if(be+pe<=We)be+=pe,we++;else break}const ne=Math.max(1,Math.min(we,te.length));p.current=ne,s(V=>V===ne?V:ne)},N=()=>{w!==null&&cancelAnimationFrame(w),w=requestAnimationFrame(O)};N();const q=new ResizeObserver(()=>{N()});return f.current&&q.observe(f.current),()=>{w!==null&&cancelAnimationFrame(w),q.disconnect()}},[y,n]),l.useEffect(()=>{j&&R!==null&&R>=D.length&&M(!1)},[j,R,D.length]);const fe=i=>(_.current[i]||(_.current[i]=$e.default.createRef()),_.current[i]),J=(i,x)=>{if(r)return;B(),i==="addComment"||i==="toggleComments"||K(P(i));const N={toggleBold:"bold",toggleItalic:"italic",toggleUnderline:"underline"}[i];if(N){document.execCommand(N,!1),c(null);return}typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(i,x),c(null)},Ne=i=>{r||(H(),c(u===i?null:i))},je=i=>{r||(H(),S(T===i?null:i),c(null))},De=(i,x)=>{r||(K(),J(i,x),A(null),I.current=null,S(null))},me=(i,x)=>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||"⚪",He={...o&&{position:"sticky",top:0,zIndex:100,backgroundColor:"#fff",boxShadow:"0 2px 4px rgba(0,0,0,0.1)"},...t==="bottom"&&{order:2}},Fe=!n||R!==null,ge=n&&R!==null&&R<D.length,_e=i=>{if(r)return;const x=i.target;x.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button")&&($(x.closest("[data-command]")),B(),H(),i.preventDefault())},Z=(i,x=!0)=>i.map((w,O)=>{const N=w.command||"",q=N==="toggleTrackChanges"&&m;return d.jsx("div",{className:"rte-toolbar-item",style:{display:x&&n&&R!==null&&O>=R?"none":"flex"},children:w.type==="separator"?d.jsx("div",{className:"rte-toolbar-separator","aria-hidden":"true"}):w.type==="dropdown"?d.jsxs("div",{className:"rte-toolbar-dropdown",children:[d.jsxs("button",{className:`rte-toolbar-button ${q?"active":""}`,"data-command":N,"data-active":q?"true":"false",onMouseDown:W=>{W.preventDefault(),H()},onClick:()=>Ne(N),disabled:r,children:[w.label," ▼"]}),u===N&&d.jsx("div",{className:"rte-toolbar-dropdown-menu",children:w.options?.map(W=>d.jsx("div",{className:"rte-toolbar-dropdown-item",onMouseDown:ee=>ee.preventDefault(),onClick:()=>J(N,W.value),children:W.label},W.value))})]}):w.type==="inline-menu"?d.jsx("button",{ref:fe(N),className:`rte-toolbar-button ${q?"active":""}`,"data-command":N,"data-active":q?"true":"false",onMouseDown:W=>{W.preventDefault(),H()},onClick:()=>je(N),disabled:r,title:w.label,children:me(w.icon)}):w.type==="input"?d.jsx("input",{type:"text",className:`rte-toolbar-input ${w.label.toLowerCase().replace(/\s+/g,"-")}`,placeholder:w.placeholder,onChange:W=>J(N,W.target.value),disabled:r,onKeyDown:W=>{W.key==="Enter"&&J(N,W.target.value)},title:w.label}):w.type==="group"?d.jsx("div",{className:`rte-toolbar-group-button ${w.label.toLowerCase().replace(/\s+/g,"-")}`,title:`${w.label}`,children:d.jsx("div",{className:`rte-toolbar-group-items ${w.label.toLowerCase().replace(/\s+/g,"-")}`,children:Z(w.items||[],!1)})}):d.jsx("button",{className:`rte-toolbar-button ${q?"active":""}`,"data-command":N,"data-active":q?"true":"false",onMouseDown:W=>{W.preventDefault(),H()},onClick:()=>J(N),disabled:r,title:w.label,children:me(w.icon)})},O)}),Be=n&&R!==null?D.filter((i,x)=>x>=R):[];return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"rte-toolbar-wrapper",style:{...He,...Fe?null:{visibility:"hidden"}},onMouseDownCapture:_e,children:[d.jsxs("div",{className:"rte-toolbar",ref:f,children:[d.jsx("div",{className:"rte-toolbar-items-container",ref:C,style:n?void 0:{flexWrap:"wrap"},children:Z(D)}),ge&&d.jsx("button",{ref:k,className:`rte-toolbar-more-button ${j?"active":""}`,onMouseDown:i=>{i.preventDefault(),H()},onClick:()=>M(!j),disabled:r,title:"Show more options","aria-label":"More toolbar options",children:"☰"})]}),ge&&d.jsx("div",{className:`rte-toolbar-expanded-row ${j?"show":""}`,children:Z(Be,!1)})]}),D.map(i=>{if(i.type==="inline-menu"){const x=i.command||"";return d.jsx(ke,{isOpen:T===x,options:i.options||[],onSelect:w=>De(x,w),onClose:()=>S(null),anchorRef:fe(x)},`menu-${x||"unknown"}`)}return null})]})};function Ge(e,t){const o=l.useRef(),a=l.useRef("");return l.useEffect(()=>{if(!t?.enabled)return;const n=t.intervalMs||3e4,g=t.storageKey||"rte-autosave",m=t.provider||"localStorage",h=async()=>{const u=e();if(u!==a.current){if(a.current=u,m==="localStorage")try{localStorage.setItem(g,u),localStorage.setItem(`${g}-timestamp`,Date.now().toString()),console.log("[Autosave] Content saved to localStorage")}catch(c){console.error("[Autosave] Failed to save to localStorage:",c)}else if(m==="api"&&t.apiUrl)try{await fetch(t.apiUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:u,timestamp:Date.now()})}),console.log("[Autosave] Content saved to API")}catch(c){console.error("[Autosave] Failed to save to API:",c)}}};return o.current=setInterval(h,n),()=>{o.current&&clearInterval(o.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 m=localStorage.getItem(n),h=localStorage.getItem(`${n}-timestamp`);if(m&&h)return console.log("[Autosave] Restored from localStorage, saved at:",new Date(parseInt(h))),m}catch(m){console.error("[Autosave] Failed to restore from localStorage:",m)}return null}}}const Xe=["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"],Je={"*":["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 Re(e,t,o){if(t?.sanitize===!1)return e;const a=t?.allowedTags&&t.allowedTags.length>0?t.allowedTags:Xe,n=!!t?.allowedAttributes&&Object.keys(t.allowedAttributes).length>0?t.allowedAttributes:Je,g=document.createElement("div");return g.innerHTML=e,Se(g,a,n),g.innerHTML}function Se(e,t,o){const a=Array.from(e.childNodes);for(const r of a)if(r.nodeType===Node.ELEMENT_NODE){const n=r,g=n.tagName.toLowerCase();if(!t.includes(g)){for(;n.firstChild;)e.insertBefore(n.firstChild,n);e.removeChild(n);continue}Qe(n,o),Se(n,t,o)}else{if(r.nodeType===Node.TEXT_NODE)continue;e.removeChild(r)}}function Qe(e,t){const o=e.tagName.toLowerCase(),a=Array.from(e.attributes),r=t[o]||[],n=t["*"]||[],g=[...r,...n];for(const m of a){const h=m.name.toLowerCase();let u=!1;g.includes(h)&&(u=!0);for(const c of g)if(c.endsWith("*")){const T=c.slice(0,-1);if(h.startsWith(T)){u=!0;break}}(h.startsWith("on")||h==="javascript:"||h==="href"&&m.value.trim().toLowerCase().startsWith("javascript:")||h==="src"&&m.value.trim().toLowerCase().startsWith("javascript:"))&&(u=!1),u||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 Ye(e,t,o){return o?.sanitizeOnPaste===!1?e:Re(e,t)}function ye(e,t,o){return o?.sanitizeOnInput===!1?e:Re(e,t)}const Y=e=>(e.textContent||"").replace(/\u200B/g,"").trim().length>0?!1:!e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"),X=(e,t)=>{const a=!!t&&Y(e);e.classList.toggle("rte-content-empty",a)},ce="data-rte-caret-marker",ue="data-rte-range-start-marker",de="data-rte-range-end-marker",ae=()=>Math.random().toString(36).slice(2),Ze=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const o=t.getRangeAt(0);if(!e.contains(o.commonAncestorContainer))return null;try{const a=o.cloneRange();a.selectNodeContents(e),a.setEnd(o.startContainer,o.startOffset);const r=o.cloneRange();return r.selectNodeContents(e),r.setEnd(o.endContainer,o.endOffset),{start:a.toString().length,end:r.toString().length}}catch{return null}},Ee=(e,t)=>{const o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let a=o.nextNode(),r=Math.max(0,t),n=null;for(;a;){n=a;const g=a.textContent?.length??0;if(r<=g)return{node:a,offset:r};r-=g,a=o.nextNode()}return n?{node:n,offset:n.textContent?.length??0}:{node:e,offset:e.childNodes.length}},et=e=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const o=t.getRangeAt(0);if(!e.contains(o.commonAncestorContainer))return null;const a=Ze(e);try{if(o.collapsed){const c=ae(),T=document.createElement("span");return T.setAttribute(ce,c),T.appendChild(document.createTextNode("")),o.cloneRange().insertNode(T),{collapsed:!0,caretId:c,fallbackOffsets:a}}const r=ae(),n=ae(),g=document.createElement("span");g.setAttribute(de,n),g.appendChild(document.createTextNode(""));const m=document.createElement("span");m.setAttribute(ue,r),m.appendChild(document.createTextNode(""));const h=o.cloneRange();h.collapse(!1),h.insertNode(g);const u=o.cloneRange();return u.collapse(!0),u.insertNode(m),{collapsed:!1,startId:r,endId:n,fallbackOffsets:a}}catch{return{collapsed:o.collapsed,fallbackOffsets:a}}},tt=e=>{e.querySelectorAll(`[${ce}], [${ue}], [${de}]`).forEach(t=>t.remove())},nt=(e,t)=>{if(!t)return!1;const o=window.getSelection();if(!o)return!1;try{const a=document.createRange();if(t.collapsed&&t.caretId){const r=e.querySelector(`[${ce}="${t.caretId}"]`);return!r||!r.parentNode?!1:(a.setStartAfter(r),a.collapse(!0),o.removeAllRanges(),o.addRange(a),!0)}if(!t.collapsed&&t.startId&&t.endId){const r=e.querySelector(`[${ue}="${t.startId}"]`),n=e.querySelector(`[${de}="${t.endId}"]`);return!r||!n||!r.parentNode||!n.parentNode?!1:(a.setStartAfter(r),a.setEndBefore(n),o.removeAllRanges(),o.addRange(a),!0)}}catch{return!1}return!1},rt=(e,t)=>{if(!t)return;const o=window.getSelection();if(o)try{const a=Ee(e,t.start),r=Ee(e,t.end),n=document.createRange();n.setStart(a.node,a.offset),n.setEnd(r.node,r.offset),o.removeAllRanges(),o.addRange(n)}catch{}},Ae=({editor:e,defaultValue:t,value:o,readonly:a=!1,placeholder:r,onChange:n,pasteConfig:g,contentConfig:m,securityConfig:h,performanceConfig:u,accessibilityConfig:c,autosaveConfig:T,contextMenuConfig:S,spellcheckConfig:R})=>{const s=l.useRef(null),j=o!==void 0,M=l.useRef(),p=m?.autoHeight===!0,E=typeof m?.minHeight=="number"?m.minHeight:200,b=typeof m?.maxHeight=="number"?m.maxHeight:0,I=v=>{if(!v||!p)return;v.style.height="auto";const f=Math.max(E,v.scrollHeight);if(b>0){v.style.height=`${Math.min(f,b)}px`;return}v.style.height=`${f}px`},{restore:_}=Ge(()=>s.current?.innerHTML||"",T);l.useEffect(()=>{if(!s.current)return;const v=_(),f=v??o??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>"),X(s.current,r),I(s.current),v&&n&&n(v)},[]),l.useEffect(()=>{!s.current||!j||(o!==s.current.innerHTML&&(s.current.innerHTML=o),X(s.current,r),I(s.current))},[o,j]),l.useEffect(()=>{if(!s.current)return;const v=s.current;if(r){v.setAttribute("data-placeholder",r),Y(v)&&(v.innerHTML=""),X(v,r),I(v);return}v.removeAttribute("data-placeholder"),X(v,r),I(v)},[r]),l.useEffect(()=>{if(!s.current)return;const v=s.current;if(c?.enableARIA!==!1){v.setAttribute("role","textbox"),v.setAttribute("aria-multiline","true"),v.setAttribute("aria-disabled",a?"true":"false");const C=r?.trim();C?v.setAttribute("aria-label",C):v.removeAttribute("aria-label")}else v.removeAttribute("role"),v.removeAttribute("aria-multiline"),v.removeAttribute("aria-label"),v.removeAttribute("aria-disabled")},[c?.enableARIA,r,a]),l.useEffect(()=>{I(s.current)},[p,E,b,o]),l.useEffect(()=>{if(!s.current)return;const v=()=>{if(!s.current||a)return;r&&Y(s.current)&&(s.current.innerHTML="");let A=s.current.innerHTML;if(h?.sanitizeOnInput!==!1&&m?.sanitize!==!1){const L=ye(A,m,h);if(L!==s.current.innerHTML){const B=et(s.current),$=s.current.innerHTML,z=ye($,m,h);s.current.innerHTML=z,nt(s.current,B)||rt(s.current,B?.fallbackOffsets||null),tt(s.current),A=s.current.innerHTML}else A=L}X(s.current,r),I(s.current),n&&(u?.debounceInputMs?(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{n(A)},u.debounceInputMs)):n(A))},f=A=>{if(A.__editoraSmartPasteHandled===!0||A.defaultPrevented)return;if(a){A.preventDefault();return}A.preventDefault();let L=A.clipboardData?.getData("text/html");const B=A.clipboardData?.getData("text/plain"),$=!!L&&/class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(L);if(g?.clean||!g?.keepFormatting){B&&document.execCommand("insertText",!1,B);return}if(g?.convertWord===!1&&$){B&&document.execCommand("insertText",!1,B);return}if(L){h?.sanitizeOnPaste!==!1&&m?.sanitize!==!1&&(L=Ye(L,m,h));const z=window.getSelection();if(z&&z.rangeCount>0){const H=z.getRangeAt(0);H.deleteContents();const P=document.createElement("div");P.innerHTML=L;const K=document.createDocumentFragment();for(;P.firstChild;)K.appendChild(P.firstChild);H.insertNode(K),H.collapse(!1),z.removeAllRanges(),z.addRange(H)}}else B&&document.execCommand("insertText",!1,B)},C=A=>{const L=A.target;(L.tagName==="IMG"||L.tagName==="VIDEO")&&(L.style.resize="both",L.style.overflow="auto",L.style.display="inline-block")},k=A=>{S?.enabled===!1&&A.preventDefault()},D=()=>{s.current&&(r&&Y(s.current)&&(s.current.innerHTML=""),X(s.current,r),I(s.current))},y=s.current;return y.addEventListener("input",v),y.addEventListener("paste",f),y.addEventListener("click",C),y.addEventListener("contextmenu",k),y.addEventListener("focus",D),y.addEventListener("blur",D),a||y.focus(),()=>{M.current&&clearTimeout(M.current),y.removeEventListener("input",v),y.removeEventListener("paste",f),y.removeEventListener("click",C),y.removeEventListener("contextmenu",k),y.removeEventListener("focus",D),y.removeEventListener("blur",D)}},[e,n,g,m,h,u,r,S,a]);const F=(R?.enabled??!1)&&(R?.provider??"browser")==="browser";return l.useEffect(()=>{if(!s.current||typeof window>"u"||a||c?.keyboardNavigation===!1)return;const v=new U.KeyboardShortcutManager,f=s.current,C=k=>{v.handleKeyDown(k,(D,y)=>{if(typeof window<"u"&&window.executeEditorCommand){const A=s.current?.closest("[data-editora-editor]");window.__editoraCommandEditorRoot=A||null,window.executeEditorCommand(D,y)}})};return f.addEventListener("keydown",C),()=>{f.removeEventListener("keydown",C)}},[c?.keyboardNavigation,a]),d.jsx("div",{ref:s,contentEditable:!a,suppressContentEditableWarning:!0,spellCheck:a?!1:F,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":u?.viewportOnlyScan?"true":"false","data-a11y-checker":c?.checker?"true":"false","data-readonly":a?"true":"false",className:`rte-content ${a?"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"}})},ot=({editor:e,isEnabled:t,viewportOnlyScan:o=!0,readonly:a=!1})=>{const[r,n]=l.useState(!1),[g,m]=l.useState({top:0,left:0}),h=l.useRef(null),u=l.useRef(null),c=l.useRef(null),T=l.useRef(null),S=l.useRef(null);l.useEffect(()=>{if(!t||a){n(!1);return}S.current=h.current?.closest("[data-editora-editor]");const s=f=>{if(S.current)return S.current;const C=h.current?.closest("[data-editora-editor]");if(C)return S.current=C,C;const k=f?.commonAncestorContainer,y=(k?k.nodeType===Node.ELEMENT_NODE?k:k.parentElement:null)?.closest("[data-editora-editor]");return y?(S.current=y,y):null},j=f=>f&&f.querySelector(".rte-content, .editora-content")||null,M=f=>{if(!f||a)return!0;const C=f.getAttribute("contenteditable"),k=f.getAttribute("data-readonly");return C==="false"||k==="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 k=Array.from(C.getClientRects()).filter(y=>y.width>0||y.height>0);return k.length===0?C.getBoundingClientRect():p(f)?k[0]:k[k.length-1]},b=()=>{T.current&&clearTimeout(T.current);const f=window.getSelection();if(!f||f.rangeCount===0){n(!1),c.current=null;return}const C=f.getRangeAt(0);if(C.collapsed){n(!1),c.current=null;return}const k=f.toString().trim(),D=s(C),y=j(D);if(!y||!y.contains(C.commonAncestorContainer)){n(!1),c.current=null;return}if(M(y)){n(!1),c.current=null;return}if(o){const A=y.getBoundingClientRect(),L=A.bottom>=0&&A.top<=window.innerHeight,B=document.activeElement===y||y.contains(document.activeElement);if(!L&&!B){n(!1),c.current=null;return}}if(k.length>0){const A=E(f,C),L=y.getBoundingClientRect(),B=300;if(A&&L){const $=Math.max(8,A.top-50);let z=A.left+A.width/2;const H=B/2,P=L.left,K=L.right;z-H<P&&(z=P+H+10),z+H>K&&(z=K-H-10),m({top:$,left:z}),n(!0),c.current=C.cloneRange()}}else n(!1),c.current=null},I=f=>{if(u.current&&!u.current.contains(f.target)){const C=s();window.getSelection(),j(C)?.contains(f.target)||(n(!1),c.current=null)}},_=f=>{f.key==="Escape"&&(n(!1),c.current=null)},F=j(s()),v=F&&typeof MutationObserver<"u"?new MutationObserver(()=>{M(F)&&(n(!1),c.current=null)}):null;return v&&F&&v.observe(F,{attributes:!0,attributeFilter:["contenteditable","data-readonly"]}),document.addEventListener("selectionchange",b),document.addEventListener("mousedown",I),document.addEventListener("keydown",_),F?.addEventListener("mouseup",b),F?.addEventListener("keyup",b),()=>{document.removeEventListener("selectionchange",b),document.removeEventListener("mousedown",I),document.removeEventListener("keydown",_),F?.removeEventListener("mouseup",b),F?.removeEventListener("keyup",b),v?.disconnect(),T.current&&clearTimeout(T.current)}},[t,o,a]);const R=(s,j)=>{if(a||!c.current)return;typeof window<"u"&&(window.__editoraCommandEditorRoot=S.current||null);const M=S.current?.querySelector(".rte-content, .editora-content");if(M&&(M.getAttribute("contenteditable")==="false"||M.getAttribute("data-readonly")==="true")){n(!1),c.current=null;return}M&&M.focus();const p=window.getSelection();if(p&&c.current)try{p.removeAllRanges(),p.addRange(c.current)}catch{}({toggleBold:()=>document.execCommand("bold",!1),toggleItalic:()=>document.execCommand("italic",!1),toggleUnderline:()=>document.execCommand("underline",!1),toggleStrikethrough:()=>document.execCommand("strikeThrough",!1),createLink:()=>{typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand("openLinkDialog")},clearFormatting:()=>{document.execCommand("removeFormat",!1),document.execCommand("unlink",!1)},toggleCode:()=>{const b=window.getSelection();if(b&&b.rangeCount>0){const I=b.getRangeAt(0),_=document.createElement("code");I.surroundContents(_)}},setBlockType:()=>{if(j==="blockquote"){const b=window.getSelection();if(b&&b.rangeCount>0){const I=b.getRangeAt(0);(I.commonAncestorContainer.nodeType===Node.TEXT_NODE?I.commonAncestorContainer.parentElement:I.commonAncestorContainer)?.closest?.("blockquote")?document.execCommand("formatBlock",!1,"p"):document.execCommand("formatBlock",!1,"blockquote")}}else j&&document.execCommand("formatBlock",!1,j)}})[s]?.(),n(!1),c.current=null};return!t||a?d.jsx("span",{ref:h,style:{display:"none"},"aria-hidden":"true"}):d.jsxs(d.Fragment,{children:[d.jsx("span",{ref:h,style:{display:"none"},"aria-hidden":"true"}),r&&d.jsxs("div",{ref:u,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:[d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("toggleBold"),title:"Bold (Ctrl+B)",children:d.jsx("strong",{children:"B"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("toggleItalic"),title:"Italic (Ctrl+I)",children:d.jsx("em",{children:"I"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("toggleUnderline"),title:"Underline (Ctrl+U)",children:d.jsx("u",{children:"U"})}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("toggleStrikethrough"),title:"Strikethrough",children:d.jsx("s",{children:"S"})}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("clearFormatting"),title:"Clear Formatting",children:"⌫"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("createLink"),title:"Insert Link",children:"🔗"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("toggleCode"),title:"Code",children:"Code"}),d.jsx("div",{className:"floating-toolbar-separator"}),d.jsx("button",{className:"floating-toolbar-btn",onClick:()=>R("setBlockType","blockquote"),title:"Quote",children:"❝"})]})]})},at=({plugins:e,children:t})=>{const o=e.filter(r=>r.context?.provider);return o.length===0?d.jsx(d.Fragment,{children:t}):o.reduce((r,n)=>{const g=n.context.provider;return d.jsx(g,{children:r},n.name)},d.jsx(d.Fragment,{children:t}))},Ce=new Set,xe=new Set,se=e=>!!e&&typeof e=="object"&&typeof e.name=="string",Te=e=>{const t=e?.pluginFactories;return{...(typeof window<"u"?window.EditoraReactPlugins:void 0)||{},...t||{}}},it=(e,t)=>{if(!Array.isArray(e))return[];const o=Te(t),a=[],r=[];if(e.forEach(n=>{if(se(n)){a.push(n);return}if(typeof n!="string")return;const g=o[n];if(typeof g=="function")try{const m=g();if(se(m)){a.push(m);return}}catch{}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(", ")}. Pass plugin instances or provide plugin factories via "pluginConfig.pluginFactories" or "window.EditoraReactPlugins".`))}return a},st=(e,t,o)=>{if(!t?.checker||e.some(n=>n?.name==="a11yChecker"))return e;const a=Te(o).a11yChecker;if(typeof a=="function")try{const n=a();if(se(n))return[...e,n]}catch{}const r="accessibility.checker";return xe.has(r)||(xe.add(r),console.warn('[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.')),e},lt={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 Le(e,t){const o={...e};for(const a in t){const r=t[a],n=o[a];r!==void 0&&(typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof n=="object"&&n!==null&&!Array.isArray(n)?o[a]=Le(n,r):o[a]=r)}return o}function Me(e){const t=Le(lt,{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 a=typeof e.floatingToolbar=="boolean"?e.floatingToolbar:e.floatingToolbar.enabled;t.toolbar={...t.toolbar,floating:a??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:st(it(e.plugins,e.pluginConfig),e.accessibility,e.pluginConfig),pluginConfig:e.pluginConfig||{}}}const le=new Map,ct=()=>{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)=>{le.set(e,t)},window.executeEditorCommand=(e,t)=>{const o=le.get(e);if(o){const a=ct();return o(t,a)}else return console.warn(`No handler registered for command: ${e}`),!1});const ut=e=>{const t=l.useMemo(()=>Me(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]),o=l.useRef(null),a=l.useRef(null),r=l.useRef(e.onInit),n=l.useRef(e.onDestroy),g=l.useRef(e.onChange),m=l.useRef(new Set),h=l.useRef(null),u=l.useRef(null),c=l.useRef(null);l.useEffect(()=>{r.current=e.onInit,n.current=e.onDestroy,g.current=e.onChange});const T=p=>{g.current?.(p),m.current.forEach(E=>{try{E(p)}catch(b){console.error("Editora onChange subscriber failed:",b)}})},S=l.useMemo(()=>{const p=new U.PluginManager;t.plugins.forEach(b=>{p.register(b),b.commands&&typeof window<"u"&&Object.entries(b.commands).forEach(([I,_])=>{le.set(I,_)})});const E=new U.Editor(p);return o.current=E,E},[t.plugins]);l.useEffect(()=>{const p={getHTML:()=>h.current?.querySelector(".rte-content")?.innerHTML||"",setHTML:E=>{const b=h.current?.querySelector(".rte-content");b&&(b.innerHTML=E)},execCommand:(E,b)=>{typeof window<"u"&&window.executeEditorCommand&&(window.__editoraCommandEditorRoot=h.current||null,window.executeEditorCommand(E,b))},registerCommand:(E,b)=>{typeof window<"u"&&window.registerEditorCommand&&window.registerEditorCommand(E,b)},focus:()=>{h.current?.querySelector(".rte-content")?.focus()},blur:()=>{h.current?.querySelector(".rte-content")?.blur()},destroy:()=>{n.current&&n.current()},onChange:E=>(m.current.add(E),()=>{m.current.delete(E)}),getState:()=>({plugins:t.plugins,config:t}),toolbar:{items:S.toolbar?.items||[]}};return a.current=p,r.current&&r.current(p),()=>{m.current.clear(),n.current&&n.current()}},[]),l.useEffect(()=>{if(t.statusbar.enabled&&c.current&&h.current){u.current||(u.current=new U.StatusBar({enabled:!0,position:t.statusbar.position}),u.current.create(c.current));const p=h.current.querySelector(".rte-content");if(p){const E=()=>{const k=document.activeElement;return!!k&&(k===p||p.contains(k))},b=()=>{const k=p.getBoundingClientRect();return k.bottom>=0&&k.top<=window.innerHeight},I=()=>{const k=window.getSelection();if(!k||k.rangeCount===0)return null;const D=k.getRangeAt(0),y=D.commonAncestorContainer;return p.contains(y)?D:null},_=(k=!1)=>{if(t.performance.viewportOnlyScan!==!1&&!b()&&!E())return;const y=I(),A=!!y||E();if(k&&!A)return;const L=p.textContent||"",{words:B,chars:$}=U.calculateTextStats(L),z=U.countLines(p);let H,P;y&&(H=U.getCursorPosition(p,y),y.collapsed||(P=U.getSelectionInfo(y,H),H=void 0)),u.current?.update({wordCount:B,charCount:$,lineCount:z,cursorPosition:H,selectionInfo:P})},F=()=>_(),v=()=>_(!0),f=()=>_(),C=()=>_();return p.addEventListener("input",F),p.addEventListener("focus",f),p.addEventListener("blur",C),document.addEventListener("selectionchange",v),_(),()=>{p.removeEventListener("input",F),p.removeEventListener("focus",f),p.removeEventListener("blur",C),document.removeEventListener("selectionchange",v)}}}else u.current&&(u.current.destroy(),u.current=null);return()=>{u.current&&(u.current.destroy(),u.current=null)}},[t.statusbar.enabled,t.statusbar.position,t.performance.viewportOnlyScan]);const R=t.toolbar.floating??!1,s=t.toolbar.position||"top",j=t.toolbar.sticky??!1,M=t.toolbar.showMoreOptions??!0;return d.jsx(at,{plugins:t.plugins,children:d.jsxs("div",{ref:h,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(ie,{editor:S,position:s,sticky:j,floating:R,readonly:t.readonly,showMoreOptions:M,itemsOverride:t.toolbar.items}),d.jsx(Ae,{editor:S,defaultValue:t.defaultValue,value:t.value,readonly:t.readonly,placeholder:t.placeholder,onChange:T,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(ie,{editor:S,position:s,sticky:j,floating:R,readonly:t.readonly,showMoreOptions:M,itemsOverride:t.toolbar.items}),d.jsx(ot,{editor:S,isEnabled:R,viewportOnlyScan:t.performance.viewportOnlyScan,readonly:t.readonly}),t.statusbar.enabled&&d.jsx("div",{ref:c,className:"editora-statusbar-container",style:{order:t.statusbar.position==="top"?-1:1}})]})})},Ie=e=>d.jsx(ut,{...e});function dt(e={}){const t=l.useRef(null),o=l.useRef(e.onCommand);return l.useEffect(()=>{o.current=e.onCommand}),l.useEffect(()=>{if(typeof window>"u"||e.enabled===!1)return;const a=new U.KeyboardShortcutManager(e);t.current=a;const r=g=>a.handleKeyDown(g,(h,u)=>{o.current&&o.current(h,u),typeof window<"u"&&window.executeEditorCommand&&window.executeEditorCommand(h,u)}),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:a=>t.current?.getShortcutForCommand(a),getShortcutsHelp:()=>t.current?.getShortcutsHelp()||"",enable:()=>t.current?.enable(),disable:()=>t.current?.disable(),isEnabled:()=>t.current?.isEnabled()||!1}}exports.EditorContent=Ae;exports.EditoraEditor=Ie;exports.InlineMenu=ke;exports.RichTextEditor=Ie;exports.Toolbar=ie;exports.mergeConfig=Me;exports.useKeyboardShortcuts=dt; |
+578
-558
@@ -1,25 +0,25 @@ | ||
| 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 = ({ | ||
| import { jsx as w, jsxs as V, Fragment as te } from "react/jsx-runtime"; | ||
| import qe, { useRef as L, useState as G, useLayoutEffect as Re, useEffect as F, useMemo as ne } from "react"; | ||
| import { KeyboardShortcutManager as Te, PluginManager as Ke, Editor as je, StatusBar as Ve, calculateTextStats as Ge, countLines as Xe, getCursorPosition as Je, getSelectionInfo as Qe } from "@editora/core"; | ||
| const Ye = ({ | ||
| isOpen: e, | ||
| options: t, | ||
| onSelect: a, | ||
| onClose: o, | ||
| onSelect: o, | ||
| onClose: a, | ||
| anchorRef: r, | ||
| className: n = "" | ||
| }) => { | ||
| const u = L(null), [f, s] = G(null), m = () => { | ||
| const f = L(null), [d, m] = G(null), s = () => { | ||
| 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 }); | ||
| const c = r.current.getBoundingClientRect(), R = f.current?.getBoundingClientRect(), A = R?.width || 120, S = R?.height || t.length * 36, l = 8, D = 4, M = window.innerWidth, v = window.innerHeight; | ||
| let y = c.bottom + D, g = c.left; | ||
| g + A > M - l && (g = M - A - l), g < l && (g = l), y + S > v - l && (y = c.top - S - D), y < l && (y = l), m({ top: y, left: g }); | ||
| }; | ||
| return He(() => { | ||
| return Re(() => { | ||
| if (!e) { | ||
| s(null); | ||
| m(null); | ||
| return; | ||
| } | ||
| m(); | ||
| const c = window.requestAnimationFrame(m); | ||
| s(); | ||
| const c = window.requestAnimationFrame(s); | ||
| return () => { | ||
@@ -31,3 +31,3 @@ window.cancelAnimationFrame(c); | ||
| const c = () => { | ||
| m(); | ||
| s(); | ||
| }; | ||
@@ -39,5 +39,5 @@ return window.addEventListener("resize", c), window.addEventListener("scroll", c, !0), () => { | ||
| const c = (A) => { | ||
| u.current && !u.current.contains(A.target) && r.current && !r.current.contains(A.target) && o(); | ||
| f.current && !f.current.contains(A.target) && r.current && !r.current.contains(A.target) && a(); | ||
| }, R = (A) => { | ||
| A.key === "Escape" && o(); | ||
| A.key === "Escape" && a(); | ||
| }; | ||
@@ -47,13 +47,13 @@ return e && (document.addEventListener("mousedown", c), document.addEventListener("keydown", R)), () => { | ||
| }; | ||
| }, [e, o, r]), e ? /* @__PURE__ */ h( | ||
| }, [e, a, r]), e ? /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| ref: u, | ||
| ref: f, | ||
| className: `rte-inline-menu ${n}`, | ||
| style: { | ||
| top: f?.top ?? -9999, | ||
| left: f?.left ?? -9999, | ||
| visibility: f ? "visible" : "hidden" | ||
| top: d?.top ?? -9999, | ||
| left: d?.left ?? -9999, | ||
| visibility: d ? "visible" : "hidden" | ||
| }, | ||
| children: t.map((c) => /* @__PURE__ */ h( | ||
| children: t.map((c) => /* @__PURE__ */ w( | ||
| "div", | ||
@@ -63,3 +63,3 @@ { | ||
| onClick: () => { | ||
| a(c.value), o(); | ||
| o(c.value), a(); | ||
| }, | ||
@@ -72,3 +72,3 @@ children: c.label | ||
| ) : null; | ||
| }, Q = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Ue = { | ||
| }, Z = (e) => e.toLowerCase().replace(/[^a-z0-9]/g, ""), Ze = (e, t) => `${t}:${e.type}:${e.command || ""}:${e.label || ""}`, et = typeof window < "u" ? Re : F, tt = { | ||
| undo: "undo", | ||
@@ -104,18 +104,21 @@ redo: "redo", | ||
| databindingpreview: "openDataBindingDialog" | ||
| }, qe = (e, t) => { | ||
| if (!Array.isArray(t) || t.length === 0) | ||
| }, nt = (e, t) => { | ||
| if (t == null || t === "") | ||
| return e; | ||
| if (!t.every((s) => typeof s == "string")) | ||
| return t; | ||
| const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(); | ||
| const o = typeof t == "string" ? [t] : t; | ||
| if (!Array.isArray(o) || o.length === 0) | ||
| return e; | ||
| if (!o.every((s) => typeof s == "string")) | ||
| return o; | ||
| const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(); | ||
| e.forEach((s) => { | ||
| o.set(Q(s.command || ""), s), r.set(Q(s.label || ""), s); | ||
| r.set(Z(s.command || ""), s), n.set(Z(s.label || ""), s); | ||
| }); | ||
| const n = t.flatMap((s) => s.split(/\s+/)).map((s) => s.trim()).filter(Boolean), u = []; | ||
| let f = 0; | ||
| return n.forEach((s) => { | ||
| const f = o.flatMap((s) => s.split(/\s+/)).map((s) => s.trim()).filter(Boolean), d = []; | ||
| let m = 0; | ||
| return f.forEach((s) => { | ||
| if (s === "|") { | ||
| f += 1, u.push({ | ||
| m += 1, d.push({ | ||
| type: "separator", | ||
| command: `__separator__${f}`, | ||
| command: `__separator__${m}`, | ||
| label: "|" | ||
@@ -125,54 +128,63 @@ }); | ||
| } | ||
| 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) | ||
| const c = Z(s), R = tt[c], A = r.get(c) || (R ? r.get(Z(R)) : void 0) || n.get(c) || e.find( | ||
| (S) => Z(S.command || "").includes(c) | ||
| ); | ||
| R && u.push(R); | ||
| }), u.length > 0 ? u : e; | ||
| }, ve = ({ | ||
| A && d.push(A); | ||
| }), d.length > 0 ? d : e; | ||
| }, ke = ({ | ||
| editor: e, | ||
| position: t = "top", | ||
| sticky: a = !1, | ||
| floating: o = !1, | ||
| sticky: o = !1, | ||
| floating: a = !1, | ||
| readonly: r = !1, | ||
| showMoreOptions: n = !0, | ||
| itemsOverride: u | ||
| itemsOverride: f | ||
| }) => { | ||
| 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 = () => { | ||
| const [d, m] = G(!1), [s, c] = G(null), [R, A] = G(null), [S, l] = G(null), [D, M] = G(!1), v = L(null), y = L(!1), g = L(null), I = L(null), z = L({}), _ = L({}), b = L(""), u = L(null), C = L(null), k = L(null), H = ne( | ||
| () => nt(e.pluginManager.getToolbarItems(), f), | ||
| [e, f] | ||
| ), p = ne( | ||
| () => H.map((i, E) => Ze(i, E)), | ||
| [H] | ||
| ); | ||
| F(() => { | ||
| v.current = S; | ||
| }, [S]), F(() => { | ||
| y.current = D; | ||
| }, [D]); | ||
| const x = (i) => { | ||
| g.current = i, i && !i.collapsed && (I.current = i); | ||
| }, T = () => u.current?.closest("[data-editora-editor]")?.querySelector(".rte-content") || null, W = () => { | ||
| if (typeof window > "u") return; | ||
| const i = N.current?.closest("[data-editora-editor]"); | ||
| const i = u.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = i || null; | ||
| }, p = (i) => { | ||
| }, q = (i) => { | ||
| if (typeof window > "u" || !i) return; | ||
| const k = i.getAttribute("data-command"); | ||
| k && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = k); | ||
| }, x = () => { | ||
| const i = E(); | ||
| const E = i.getAttribute("data-command"); | ||
| E && (window.__editoraLastCommandButton = i, window.__editoraLastCommand = E); | ||
| }, O = () => { | ||
| const i = T(); | ||
| if (!i) return null; | ||
| const k = window.getSelection(); | ||
| if (!k || k.rangeCount === 0) return null; | ||
| const w = k.getRangeAt(0); | ||
| return i.contains(w.commonAncestorContainer) ? w.cloneRange() : null; | ||
| }, S = () => { | ||
| const i = x(); | ||
| i && C(i); | ||
| const E = window.getSelection(); | ||
| if (!E || E.rangeCount === 0) return null; | ||
| const h = E.getRangeAt(0); | ||
| return i.contains(h.commonAncestorContainer) ? h.cloneRange() : null; | ||
| }, B = () => { | ||
| const i = O(); | ||
| i && x(i); | ||
| }; | ||
| F(() => { | ||
| const i = N.current?.closest("[data-editora-editor]"); | ||
| const i = u.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); | ||
| const E = i.querySelector(".rte-content, .editora-content"); | ||
| m(E?.getAttribute("data-track-changes") === "true"); | ||
| const h = ($) => { | ||
| m(!!$.detail?.enabled); | ||
| }; | ||
| return i.addEventListener("editora:track-changes-toggle", w), () => { | ||
| i.removeEventListener("editora:track-changes-toggle", w); | ||
| return i.addEventListener("editora:track-changes-toggle", h), () => { | ||
| i.removeEventListener("editora:track-changes-toggle", h); | ||
| }; | ||
| }, []), F(() => { | ||
| const i = () => { | ||
| S(); | ||
| B(); | ||
| }; | ||
@@ -183,14 +195,14 @@ return document.addEventListener("selectionchange", i), () => { | ||
| }, []), F(() => { | ||
| if (!m) return; | ||
| const i = (w) => { | ||
| const $ = w.target; | ||
| if (!s) return; | ||
| const i = (h) => { | ||
| const $ = h.target; | ||
| $ && $ instanceof Element && ($.closest(".rte-toolbar-dropdown") || c(null)); | ||
| }, k = (w) => { | ||
| w.key === "Escape" && c(null); | ||
| }, E = (h) => { | ||
| h.key === "Escape" && c(null); | ||
| }; | ||
| return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", k), () => { | ||
| document.removeEventListener("pointerdown", i, !0), document.removeEventListener("keydown", k); | ||
| return document.addEventListener("pointerdown", i, !0), document.addEventListener("keydown", E), () => { | ||
| document.removeEventListener("pointerdown", i, !0), document.removeEventListener("keydown", E); | ||
| }; | ||
| }, [m]); | ||
| const W = (i) => [ | ||
| }, [s]); | ||
| const U = (i) => [ | ||
| "toggleBold", | ||
@@ -205,13 +217,13 @@ "toggleItalic", | ||
| "toggleCode" | ||
| ].includes(i), q = (i = !1) => { | ||
| const k = E(); | ||
| if (!k) return !1; | ||
| 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) | ||
| ].includes(i), j = (i = !1) => { | ||
| const E = T(); | ||
| if (!E) return !1; | ||
| const h = window.getSelection(); | ||
| if (!h) return !1; | ||
| const $ = h.rangeCount > 0 && E.contains(h.getRangeAt(0).commonAncestorContainer), N = i ? I.current || g.current : g.current || I.current; | ||
| if (i && N && N.collapsed) | ||
| return !1; | ||
| if (D && k.contains(D.commonAncestorContainer)) | ||
| if (N && E.contains(N.commonAncestorContainer)) | ||
| try { | ||
| return k.focus({ preventScroll: !0 }), w.removeAllRanges(), w.addRange(D), !0; | ||
| return E.focus({ preventScroll: !0 }), h.removeAllRanges(), h.addRange(N), !0; | ||
| } catch { | ||
@@ -221,41 +233,46 @@ } | ||
| }; | ||
| F(() => { | ||
| et(() => { | ||
| if (!n) { | ||
| l(null), I(!1), M.current = []; | ||
| l(null), M(!1), v.current = null, y.current = !1, _.current = {}, b.current = ""; | ||
| return; | ||
| } | ||
| let i = null; | ||
| const k = () => { | ||
| 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++; | ||
| const i = p.join("|"); | ||
| if (b.current !== i && (b.current = i, _.current = {}, y.current && (y.current = !1, M(!1)), v.current !== null)) { | ||
| v.current = null, l(null); | ||
| return; | ||
| } | ||
| let h = null; | ||
| const $ = () => { | ||
| if (!u.current || !C.current) return; | ||
| const P = u.current.clientWidth, oe = 16, Pe = 40, ve = 4, $e = Math.max(0, P - oe - Pe - ve); | ||
| let pe = 0, ye = 0; | ||
| const ae = C.current.children; | ||
| for (let X = 0; X < ae.length; X++) { | ||
| const Ue = ae[X], J = p[X], le = J ? _.current[J] : void 0, ce = typeof le == "number" && le > 0 ? le : Ue.getBoundingClientRect().width; | ||
| J && ce > 0 && (_.current[J] = ce); | ||
| const Ce = (J ? _.current[J] : void 0) ?? ce, Ee = (Ce > 0 ? Ce : 40) + ve; | ||
| if (pe + Ee <= $e) | ||
| pe += Ee, ye++; | ||
| else | ||
| break; | ||
| } | ||
| const he = Math.max(1, Math.min(ge, ne.length)); | ||
| l((K) => K === he ? K : he); | ||
| }, w = () => { | ||
| i !== null && cancelAnimationFrame(i), i = requestAnimationFrame(k); | ||
| const ie = Math.max(1, Math.min(ye, ae.length)); | ||
| v.current = ie, l((X) => X === ie ? X : ie); | ||
| }, N = () => { | ||
| h !== null && cancelAnimationFrame(h), h = requestAnimationFrame($); | ||
| }; | ||
| M.current = [], w(); | ||
| const $ = new ResizeObserver(() => { | ||
| w(); | ||
| N(); | ||
| const K = new ResizeObserver(() => { | ||
| N(); | ||
| }); | ||
| return N.current && $.observe(N.current), _.current && $.observe(_.current), () => { | ||
| i !== null && cancelAnimationFrame(i), $.disconnect(); | ||
| return u.current && K.observe(u.current), () => { | ||
| h !== null && cancelAnimationFrame(h), K.disconnect(); | ||
| }; | ||
| }, [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) => { | ||
| }, [p, n]), F(() => { | ||
| D && S !== null && S >= H.length && M(!1); | ||
| }, [D, S, H.length]); | ||
| const he = (i) => (z.current[i] || (z.current[i] = qe.createRef()), z.current[i]), Y = (i, E) => { | ||
| if (r) return; | ||
| z(), i === "addComment" || i === "toggleComments" || q(W(i)); | ||
| const D = { | ||
| W(), i === "addComment" || i === "toggleComments" || j(U(i)); | ||
| const N = { | ||
| toggleBold: "bold", | ||
@@ -265,15 +282,15 @@ toggleItalic: "italic", | ||
| }[i]; | ||
| if (D) { | ||
| document.execCommand(D, !1), c(null); | ||
| if (N) { | ||
| document.execCommand(N, !1), c(null); | ||
| return; | ||
| } | ||
| typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, k), c(null); | ||
| }, 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 && { | ||
| typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(i, E), c(null); | ||
| }, He = (i) => { | ||
| r || (B(), c(s === i ? null : i)); | ||
| }, Be = (i) => { | ||
| r || (B(), A(R === i ? null : i), c(null)); | ||
| }, Fe = (i, E) => { | ||
| r || (j(), Y(i, E), x(null), I.current = null, A(null)); | ||
| }, be = (i, E) => i && i.startsWith("<svg") && i.endsWith("</svg>") ? /* @__PURE__ */ w("span", { dangerouslySetInnerHTML: { __html: i } }) : i && i.length === 1 && /^[BIUSH]$/.test(i) ? /* @__PURE__ */ w("span", { style: { fontWeight: "bold", fontSize: "14px", lineHeight: "1" }, children: i }) : i || "⚪", _e = { | ||
| ...o && { | ||
| position: "sticky", | ||
@@ -289,9 +306,9 @@ top: 0, | ||
| } | ||
| }, fe = n && T !== null && T < d.length, Me = (i) => { | ||
| }, ze = !n || S !== null, we = n && S !== null && S < H.length, We = (i) => { | ||
| if (r) return; | ||
| const k = i.target; | ||
| 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( | ||
| const E = i.target; | ||
| E.closest(".rte-toolbar-button, .rte-toolbar-dropdown-item, .rte-toolbar-more-button") && (q(E.closest("[data-command]")), W(), B(), i.preventDefault()); | ||
| }, re = (i, E = !0) => i.map((h, $) => { | ||
| const N = h.command || "", K = N === "toggleTrackChanges" && d; | ||
| return /* @__PURE__ */ w( | ||
| "div", | ||
@@ -301,18 +318,18 @@ { | ||
| style: { | ||
| display: k && n && T !== null && $ >= T ? "none" : "flex" | ||
| display: E && n && S !== null && $ >= S ? "none" : "flex" | ||
| }, | ||
| 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: [ | ||
| children: h.type === "separator" ? /* @__PURE__ */ w("div", { className: "rte-toolbar-separator", "aria-hidden": "true" }) : h.type === "dropdown" ? /* @__PURE__ */ V("div", { className: "rte-toolbar-dropdown", children: [ | ||
| /* @__PURE__ */ V( | ||
| "button", | ||
| { | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| className: `rte-toolbar-button ${K ? "active" : ""}`, | ||
| "data-command": N, | ||
| "data-active": K ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| P.preventDefault(), B(); | ||
| }, | ||
| onClick: () => U(D), | ||
| onClick: () => He(N), | ||
| disabled: r, | ||
| children: [ | ||
| w.label, | ||
| h.label, | ||
| " ▼" | ||
@@ -322,8 +339,8 @@ ] | ||
| ), | ||
| m === D && /* @__PURE__ */ h("div", { className: "rte-toolbar-dropdown-menu", children: w.options?.map((P) => /* @__PURE__ */ h( | ||
| s === N && /* @__PURE__ */ w("div", { className: "rte-toolbar-dropdown-menu", children: h.options?.map((P) => /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| className: "rte-toolbar-dropdown-item", | ||
| onMouseDown: (Y) => Y.preventDefault(), | ||
| onClick: () => B(D, P.value), | ||
| onMouseDown: (oe) => oe.preventDefault(), | ||
| onClick: () => Y(N, P.value), | ||
| children: P.label | ||
@@ -333,59 +350,59 @@ }, | ||
| )) }) | ||
| ] }) : w.type === "inline-menu" ? /* @__PURE__ */ h( | ||
| ] }) : h.type === "inline-menu" ? /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| ref: O(D), | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| ref: he(N), | ||
| className: `rte-toolbar-button ${K ? "active" : ""}`, | ||
| "data-command": N, | ||
| "data-active": K ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| P.preventDefault(), B(); | ||
| }, | ||
| onClick: () => X(D), | ||
| onClick: () => Be(N), | ||
| disabled: r, | ||
| title: w.label, | ||
| children: ue(w.icon) | ||
| title: h.label, | ||
| children: be(h.icon) | ||
| } | ||
| ) : w.type === "input" ? /* @__PURE__ */ h( | ||
| ) : h.type === "input" ? /* @__PURE__ */ w( | ||
| "input", | ||
| { | ||
| type: "text", | ||
| className: `rte-toolbar-input ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| placeholder: w.placeholder, | ||
| onChange: (P) => B(D, P.target.value), | ||
| className: `rte-toolbar-input ${h.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| placeholder: h.placeholder, | ||
| onChange: (P) => Y(N, P.target.value), | ||
| disabled: r, | ||
| onKeyDown: (P) => { | ||
| P.key === "Enter" && B( | ||
| D, | ||
| P.key === "Enter" && Y( | ||
| N, | ||
| P.target.value | ||
| ); | ||
| }, | ||
| title: w.label | ||
| title: h.label | ||
| } | ||
| ) : w.type === "group" ? /* @__PURE__ */ h( | ||
| ) : h.type === "group" ? /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-button ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${w.label}`, | ||
| children: /* @__PURE__ */ h( | ||
| className: `rte-toolbar-group-button ${h.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| title: `${h.label}`, | ||
| children: /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| className: `rte-toolbar-group-items ${w.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: te(w.items || [], !1) | ||
| className: `rte-toolbar-group-items ${h.label.toLowerCase().replace(/\s+/g, "-")}`, | ||
| children: re(h.items || [], !1) | ||
| } | ||
| ) | ||
| } | ||
| ) : /* @__PURE__ */ h( | ||
| ) : /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: `rte-toolbar-button ${j ? "active" : ""}`, | ||
| "data-command": D, | ||
| "data-active": j ? "true" : "false", | ||
| className: `rte-toolbar-button ${K ? "active" : ""}`, | ||
| "data-command": N, | ||
| "data-active": K ? "true" : "false", | ||
| onMouseDown: (P) => { | ||
| P.preventDefault(), S(); | ||
| P.preventDefault(), B(); | ||
| }, | ||
| onClick: () => B(D), | ||
| onClick: () => Y(N), | ||
| disabled: r, | ||
| title: w.label, | ||
| children: ue(w.icon) | ||
| title: h.label, | ||
| children: be(h.icon) | ||
| } | ||
@@ -396,4 +413,4 @@ ) | ||
| ); | ||
| }), Ie = n && T !== null ? d.filter((i, k) => k >= T) : []; | ||
| return /* @__PURE__ */ V(ee, { children: [ | ||
| }), Oe = n && S !== null ? H.filter((i, E) => E >= S) : []; | ||
| return /* @__PURE__ */ V(te, { children: [ | ||
| /* @__PURE__ */ V( | ||
@@ -403,24 +420,27 @@ "div", | ||
| className: "rte-toolbar-wrapper", | ||
| style: Re, | ||
| onMouseDownCapture: Me, | ||
| style: { | ||
| ..._e, | ||
| ...ze ? null : { visibility: "hidden" } | ||
| }, | ||
| onMouseDownCapture: We, | ||
| children: [ | ||
| /* @__PURE__ */ V("div", { className: "rte-toolbar", ref: N, children: [ | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ V("div", { className: "rte-toolbar", ref: u, children: [ | ||
| /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| className: "rte-toolbar-items-container", | ||
| ref: _, | ||
| ref: C, | ||
| style: n ? void 0 : { flexWrap: "wrap" }, | ||
| children: te(d) | ||
| children: re(H) | ||
| } | ||
| ), | ||
| fe && /* @__PURE__ */ h( | ||
| we && /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| ref: b, | ||
| className: `rte-toolbar-more-button ${H ? "active" : ""}`, | ||
| ref: k, | ||
| className: `rte-toolbar-more-button ${D ? "active" : ""}`, | ||
| onMouseDown: (i) => { | ||
| i.preventDefault(), S(); | ||
| i.preventDefault(), B(); | ||
| }, | ||
| onClick: () => I(!H), | ||
| onClick: () => M(!D), | ||
| disabled: r, | ||
@@ -433,19 +453,19 @@ title: "Show more options", | ||
| ] }), | ||
| fe && /* @__PURE__ */ h("div", { className: `rte-toolbar-expanded-row ${H ? "show" : ""}`, children: te(Ie, !1) }) | ||
| we && /* @__PURE__ */ w("div", { className: `rte-toolbar-expanded-row ${D ? "show" : ""}`, children: re(Oe, !1) }) | ||
| ] | ||
| } | ||
| ), | ||
| d.map((i) => { | ||
| H.map((i) => { | ||
| if (i.type === "inline-menu") { | ||
| const k = i.command || ""; | ||
| return /* @__PURE__ */ h( | ||
| $e, | ||
| const E = i.command || ""; | ||
| return /* @__PURE__ */ w( | ||
| Ye, | ||
| { | ||
| isOpen: R === k, | ||
| isOpen: R === E, | ||
| options: i.options || [], | ||
| onSelect: (w) => Le(k, w), | ||
| onSelect: (h) => Fe(E, h), | ||
| onClose: () => A(null), | ||
| anchorRef: O(k) | ||
| anchorRef: he(E) | ||
| }, | ||
| `menu-${k || "unknown"}` | ||
| `menu-${E || "unknown"}` | ||
| ); | ||
@@ -457,16 +477,16 @@ } | ||
| }; | ||
| function je(e, t) { | ||
| const a = L(), o = L(""); | ||
| function rt(e, t) { | ||
| const o = L(), a = L(""); | ||
| return F(() => { | ||
| if (!t?.enabled) return; | ||
| 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, f === "localStorage") | ||
| const n = t.intervalMs || 3e4, f = t.storageKey || "rte-autosave", d = t.provider || "localStorage", m = async () => { | ||
| const s = e(); | ||
| if (s !== a.current) { | ||
| if (a.current = s, d === "localStorage") | ||
| try { | ||
| localStorage.setItem(u, m), localStorage.setItem(`${u}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage"); | ||
| localStorage.setItem(f, s), localStorage.setItem(`${f}-timestamp`, Date.now().toString()), console.log("[Autosave] Content saved to localStorage"); | ||
| } catch (c) { | ||
| console.error("[Autosave] Failed to save to localStorage:", c); | ||
| } | ||
| else if (f === "api" && t.apiUrl) | ||
| else if (d === "api" && t.apiUrl) | ||
| try { | ||
@@ -478,3 +498,3 @@ await fetch(t.apiUrl, { | ||
| }, | ||
| body: JSON.stringify({ content: m, timestamp: Date.now() }) | ||
| body: JSON.stringify({ content: s, timestamp: Date.now() }) | ||
| }), console.log("[Autosave] Content saved to API"); | ||
@@ -486,4 +506,4 @@ } catch (c) { | ||
| }; | ||
| return a.current = setInterval(s, n), () => { | ||
| a.current && clearInterval(a.current); | ||
| return o.current = setInterval(m, n), () => { | ||
| o.current && clearInterval(o.current); | ||
| }; | ||
@@ -495,7 +515,7 @@ }, [t?.enabled, t?.intervalMs, t?.storageKey, t?.provider, t?.apiUrl, e]), { restore: () => { | ||
| try { | ||
| 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); | ||
| const d = localStorage.getItem(n), m = localStorage.getItem(`${n}-timestamp`); | ||
| if (d && m) | ||
| return console.log("[Autosave] Restored from localStorage, saved at:", new Date(parseInt(m))), d; | ||
| } catch (d) { | ||
| console.error("[Autosave] Failed to restore from localStorage:", d); | ||
| } | ||
@@ -505,3 +525,3 @@ return null; | ||
| } | ||
| const Ke = [ | ||
| const ot = [ | ||
| "p", | ||
@@ -545,3 +565,3 @@ "br", | ||
| "hr" | ||
| ], Ve = { | ||
| ], at = { | ||
| "*": ["class", "style", "id", "data-*", "role", "aria-*", "tabindex", "contenteditable", "spellcheck"], | ||
@@ -556,14 +576,14 @@ a: ["href", "target", "rel", "title"], | ||
| }; | ||
| function Se(e, t, a) { | ||
| function Me(e, t, o) { | ||
| if (t?.sanitize === !1) | ||
| return e; | ||
| 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; | ||
| const a = t?.allowedTags && t.allowedTags.length > 0 ? t.allowedTags : ot, n = !!t?.allowedAttributes && Object.keys(t.allowedAttributes).length > 0 ? t.allowedAttributes : at, f = document.createElement("div"); | ||
| return f.innerHTML = e, Ie(f, a, n), f.innerHTML; | ||
| } | ||
| function Ae(e, t, a) { | ||
| const o = Array.from(e.childNodes); | ||
| for (const r of o) | ||
| function Ie(e, t, o) { | ||
| const a = Array.from(e.childNodes); | ||
| for (const r of a) | ||
| if (r.nodeType === Node.ELEMENT_NODE) { | ||
| const n = r, u = n.tagName.toLowerCase(); | ||
| if (!t.includes(u)) { | ||
| const n = r, f = n.tagName.toLowerCase(); | ||
| if (!t.includes(f)) { | ||
| for (; n.firstChild; ) | ||
@@ -574,3 +594,3 @@ e.insertBefore(n.firstChild, n); | ||
| } | ||
| Ge(n, a), Ae(n, t, a); | ||
| it(n, o), Ie(n, t, o); | ||
| } else { | ||
@@ -582,41 +602,41 @@ if (r.nodeType === Node.TEXT_NODE) | ||
| } | ||
| 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; | ||
| u.includes(s) && (m = !0); | ||
| for (const c of u) | ||
| function it(e, t) { | ||
| const o = e.tagName.toLowerCase(), a = Array.from(e.attributes), r = t[o] || [], n = t["*"] || [], f = [...r, ...n]; | ||
| for (const d of a) { | ||
| const m = d.name.toLowerCase(); | ||
| let s = !1; | ||
| f.includes(m) && (s = !0); | ||
| for (const c of f) | ||
| if (c.endsWith("*")) { | ||
| const R = c.slice(0, -1); | ||
| if (s.startsWith(R)) { | ||
| m = !0; | ||
| if (m.startsWith(R)) { | ||
| s = !0; | ||
| break; | ||
| } | ||
| } | ||
| (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); | ||
| (m.startsWith("on") || // Event handlers | ||
| m === "javascript:" || m === "href" && d.value.trim().toLowerCase().startsWith("javascript:") || m === "src" && d.value.trim().toLowerCase().startsWith("javascript:")) && (s = !1), s || e.removeAttribute(d.name); | ||
| } | ||
| e.hasAttribute("href") && (e.getAttribute("href") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("href"), e.hasAttribute("src") && (e.getAttribute("src") || "").trim().toLowerCase().startsWith("javascript:") && e.removeAttribute("src"); | ||
| } | ||
| function Xe(e, t, a) { | ||
| return a?.sanitizeOnPaste === !1 ? e : Se(e, t); | ||
| function lt(e, t, o) { | ||
| return o?.sanitizeOnPaste === !1 ? e : Me(e, t); | ||
| } | ||
| function pe(e, t, a) { | ||
| return a?.sanitizeOnInput === !1 ? e : Se(e, t); | ||
| function Se(e, t, o) { | ||
| return o?.sanitizeOnInput === !1 ? e : Me(e, t); | ||
| } | ||
| 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); | ||
| }, 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 ee = (e) => (e.textContent || "").replace(/\u200B/g, "").trim().length > 0 ? !1 : !e.querySelector("img, video, table, iframe, hr, pre, blockquote, ul, ol"), Q = (e, t) => { | ||
| const a = !!t && ee(e); | ||
| e.classList.toggle("rte-content-empty", a); | ||
| }, fe = "data-rte-caret-marker", me = "data-rte-range-start-marker", ge = "data-rte-range-end-marker", se = () => Math.random().toString(36).slice(2), ct = (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 = t.getRangeAt(0); | ||
| if (!e.contains(o.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, | ||
| const a = o.cloneRange(); | ||
| a.selectNodeContents(e), a.setEnd(o.startContainer, o.startOffset); | ||
| const r = o.cloneRange(); | ||
| return r.selectNodeContents(e), r.setEnd(o.endContainer, o.endOffset), { | ||
| start: a.toString().length, | ||
| end: r.toString().length | ||
@@ -627,11 +647,11 @@ }; | ||
| } | ||
| }, ye = (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 u = o.textContent?.length ?? 0; | ||
| if (r <= u) | ||
| return { node: o, offset: r }; | ||
| r -= u, o = a.nextNode(); | ||
| }, Ae = (e, t) => { | ||
| const o = document.createTreeWalker(e, NodeFilter.SHOW_TEXT); | ||
| let a = o.nextNode(), r = Math.max(0, t), n = null; | ||
| for (; a; ) { | ||
| n = a; | ||
| const f = a.textContent?.length ?? 0; | ||
| if (r <= f) | ||
| return { node: a, offset: r }; | ||
| r -= f, a = o.nextNode(); | ||
| } | ||
@@ -642,41 +662,41 @@ return n ? { | ||
| } : { node: e, offset: e.childNodes.length }; | ||
| }, Qe = (e) => { | ||
| }, st = (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 = Je(e); | ||
| const o = t.getRangeAt(0); | ||
| if (!e.contains(o.commonAncestorContainer)) return null; | ||
| const a = ct(e); | ||
| try { | ||
| if (a.collapsed) { | ||
| 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 }; | ||
| if (o.collapsed) { | ||
| const c = se(), R = document.createElement("span"); | ||
| return R.setAttribute(fe, c), R.appendChild(document.createTextNode("")), o.cloneRange().insertNode(R), { collapsed: !0, caretId: c, fallbackOffsets: a }; | ||
| } | ||
| 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 s = a.cloneRange(); | ||
| s.collapse(!1), s.insertNode(u); | ||
| const m = a.cloneRange(); | ||
| return m.collapse(!0), m.insertNode(f), { collapsed: !1, startId: r, endId: n, fallbackOffsets: o }; | ||
| const r = se(), n = se(), f = document.createElement("span"); | ||
| f.setAttribute(ge, n), f.appendChild(document.createTextNode("")); | ||
| const d = document.createElement("span"); | ||
| d.setAttribute(me, r), d.appendChild(document.createTextNode("")); | ||
| const m = o.cloneRange(); | ||
| m.collapse(!1), m.insertNode(f); | ||
| const s = o.cloneRange(); | ||
| return s.collapse(!0), s.insertNode(d), { collapsed: !1, startId: r, endId: n, fallbackOffsets: a }; | ||
| } catch { | ||
| return { collapsed: a.collapsed, fallbackOffsets: o }; | ||
| return { collapsed: o.collapsed, fallbackOffsets: a }; | ||
| } | ||
| }, Ye = (e) => { | ||
| }, ut = (e) => { | ||
| e.querySelectorAll( | ||
| `[${ce}], [${se}], [${de}]` | ||
| `[${fe}], [${me}], [${ge}]` | ||
| ).forEach((t) => t.remove()); | ||
| }, Ze = (e, t) => { | ||
| }, dt = (e, t) => { | ||
| if (!t) return !1; | ||
| const a = window.getSelection(); | ||
| if (!a) return !1; | ||
| const o = window.getSelection(); | ||
| if (!o) return !1; | ||
| try { | ||
| const o = document.createRange(); | ||
| const a = document.createRange(); | ||
| if (t.collapsed && t.caretId) { | ||
| const r = e.querySelector(`[${ce}="${t.caretId}"]`); | ||
| return !r || !r.parentNode ? !1 : (o.setStartAfter(r), o.collapse(!0), a.removeAllRanges(), a.addRange(o), !0); | ||
| const r = e.querySelector(`[${fe}="${t.caretId}"]`); | ||
| return !r || !r.parentNode ? !1 : (a.setStartAfter(r), a.collapse(!0), o.removeAllRanges(), o.addRange(a), !0); | ||
| } | ||
| if (!t.collapsed && t.startId && t.endId) { | ||
| 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); | ||
| const r = e.querySelector(`[${me}="${t.startId}"]`), n = e.querySelector(`[${ge}="${t.endId}"]`); | ||
| return !r || !n || !r.parentNode || !n.parentNode ? !1 : (a.setStartAfter(r), a.setEndBefore(n), o.removeAllRanges(), o.addRange(a), !0); | ||
| } | ||
@@ -687,37 +707,37 @@ } catch { | ||
| return !1; | ||
| }, et = (e, t) => { | ||
| }, ft = (e, t) => { | ||
| if (!t) return; | ||
| const a = window.getSelection(); | ||
| if (a) | ||
| const o = window.getSelection(); | ||
| if (o) | ||
| try { | ||
| 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); | ||
| const a = Ae(e, t.start), r = Ae(e, t.end), n = document.createRange(); | ||
| n.setStart(a.node, a.offset), n.setEnd(r.node, r.offset), o.removeAllRanges(), o.addRange(n); | ||
| } catch { | ||
| } | ||
| }, tt = ({ | ||
| }, mt = ({ | ||
| editor: e, | ||
| defaultValue: t, | ||
| value: a, | ||
| readonly: o = !1, | ||
| value: o, | ||
| readonly: a = !1, | ||
| placeholder: r, | ||
| onChange: n, | ||
| pasteConfig: u, | ||
| contentConfig: f, | ||
| securityConfig: s, | ||
| performanceConfig: m, | ||
| pasteConfig: f, | ||
| contentConfig: d, | ||
| securityConfig: m, | ||
| performanceConfig: s, | ||
| accessibilityConfig: c, | ||
| autosaveConfig: R, | ||
| contextMenuConfig: A, | ||
| spellcheckConfig: T | ||
| spellcheckConfig: S | ||
| }) => { | ||
| 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) => { | ||
| const l = L(null), D = o !== void 0, M = L(), v = d?.autoHeight === !0, y = typeof d?.minHeight == "number" ? d.minHeight : 200, g = typeof d?.maxHeight == "number" ? d.maxHeight : 0, I = (b) => { | ||
| if (!b || !v) return; | ||
| b.style.height = "auto"; | ||
| const d = Math.max(y, b.scrollHeight); | ||
| const u = Math.max(y, b.scrollHeight); | ||
| if (g > 0) { | ||
| b.style.height = `${Math.min(d, g)}px`; | ||
| b.style.height = `${Math.min(u, g)}px`; | ||
| return; | ||
| } | ||
| b.style.height = `${d}px`; | ||
| }, { restore: N } = je( | ||
| b.style.height = `${u}px`; | ||
| }, { restore: z } = rt( | ||
| () => l.current?.innerHTML || "", | ||
@@ -728,14 +748,14 @@ R | ||
| if (!l.current) return; | ||
| 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); | ||
| const b = z(), u = b ?? o ?? t ?? ""; | ||
| u.trim() ? l.current.innerHTML !== u && (l.current.innerHTML = u) : r ? l.current.innerHTML = "" : l.current.innerHTML.trim() || (l.current.innerHTML = "<p><br></p>"), Q(l.current, r), I(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(() => { | ||
| !l.current || !D || (o !== l.current.innerHTML && (l.current.innerHTML = o), Q(l.current, r), I(l.current)); | ||
| }, [o, D]), F(() => { | ||
| if (!l.current) return; | ||
| const b = l.current; | ||
| if (r) { | ||
| b.setAttribute("data-placeholder", r), Z(b) && (b.innerHTML = ""), J(b, r), M(b); | ||
| b.setAttribute("data-placeholder", r), ee(b) && (b.innerHTML = ""), Q(b, r), I(b); | ||
| return; | ||
| } | ||
| b.removeAttribute("data-placeholder"), J(b, r), M(b); | ||
| b.removeAttribute("data-placeholder"), Q(b, r), I(b); | ||
| }, [r]), F(() => { | ||
@@ -745,3 +765,3 @@ if (!l.current) return; | ||
| if (c?.enableARIA !== !1) { | ||
| b.setAttribute("role", "textbox"), b.setAttribute("aria-multiline", "true"), b.setAttribute("aria-disabled", o ? "true" : "false"); | ||
| b.setAttribute("role", "textbox"), b.setAttribute("aria-multiline", "true"), b.setAttribute("aria-disabled", a ? "true" : "false"); | ||
| const C = r?.trim(); | ||
@@ -751,25 +771,25 @@ C ? b.setAttribute("aria-label", C) : b.removeAttribute("aria-label"); | ||
| 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(() => { | ||
| }, [c?.enableARIA, r, a]), F(() => { | ||
| I(l.current); | ||
| }, [v, y, g, o]), F(() => { | ||
| if (!l.current) return; | ||
| const b = () => { | ||
| if (!l.current || o) return; | ||
| r && Z(l.current) && (l.current.innerHTML = ""); | ||
| if (!l.current || a) return; | ||
| r && ee(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; | ||
| if (m?.sanitizeOnInput !== !1 && d?.sanitize !== !1) { | ||
| const T = Se(x, d, m); | ||
| if (T !== l.current.innerHTML) { | ||
| const W = st(l.current), q = l.current.innerHTML, O = Se(q, d, m); | ||
| l.current.innerHTML = O, dt(l.current, W) || ft(l.current, W?.fallbackOffsets || null), ut(l.current), x = l.current.innerHTML; | ||
| } else | ||
| x = S; | ||
| x = T; | ||
| } | ||
| J(l.current, r), M(l.current), n && (m?.debounceInputMs ? (I.current && clearTimeout(I.current), I.current = setTimeout(() => { | ||
| Q(l.current, r), I(l.current), n && (s?.debounceInputMs ? (M.current && clearTimeout(M.current), M.current = setTimeout(() => { | ||
| n(x); | ||
| }, m.debounceInputMs)) : n(x)); | ||
| }, d = (x) => { | ||
| }, s.debounceInputMs)) : n(x)); | ||
| }, u = (x) => { | ||
| if (x.__editoraSmartPasteHandled === !0 || x.defaultPrevented) | ||
| return; | ||
| if (o) { | ||
| if (a) { | ||
| x.preventDefault(); | ||
@@ -779,14 +799,14 @@ return; | ||
| 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) { | ||
| let T = x.clipboardData?.getData("text/html"); | ||
| const W = x.clipboardData?.getData("text/plain"), q = !!T && /class=["'][^"']*Mso|xmlns:w=|urn:schemas-microsoft-com:office/i.test(T); | ||
| if (f?.clean || !f?.keepFormatting) { | ||
| W && document.execCommand("insertText", !1, W); | ||
| return; | ||
| } | ||
| if (u?.convertWord === !1 && q) { | ||
| if (f?.convertWord === !1 && q) { | ||
| W && document.execCommand("insertText", !1, W); | ||
| return; | ||
| } | ||
| if (S) { | ||
| s?.sanitizeOnPaste !== !1 && f?.sanitize !== !1 && (S = Xe(S, f, s)); | ||
| if (T) { | ||
| m?.sanitizeOnPaste !== !1 && d?.sanitize !== !1 && (T = lt(T, d, m)); | ||
| const O = window.getSelection(); | ||
@@ -797,49 +817,49 @@ if (O && O.rangeCount > 0) { | ||
| const U = document.createElement("div"); | ||
| U.innerHTML = S; | ||
| const X = document.createDocumentFragment(); | ||
| U.innerHTML = T; | ||
| const j = document.createDocumentFragment(); | ||
| for (; U.firstChild; ) | ||
| X.appendChild(U.firstChild); | ||
| B.insertNode(X), B.collapse(!1), O.removeAllRanges(), O.addRange(B); | ||
| j.appendChild(U.firstChild); | ||
| B.insertNode(j), B.collapse(!1), O.removeAllRanges(), O.addRange(B); | ||
| } | ||
| } 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) => { | ||
| const T = x.target; | ||
| (T.tagName === "IMG" || T.tagName === "VIDEO") && (T.style.resize = "both", T.style.overflow = "auto", T.style.display = "inline-block"); | ||
| }, k = (x) => { | ||
| A?.enabled === !1 && x.preventDefault(); | ||
| }, z = () => { | ||
| l.current && (r && Z(l.current) && (l.current.innerHTML = ""), J(l.current, r), M(l.current)); | ||
| }, H = () => { | ||
| l.current && (r && ee(l.current) && (l.current.innerHTML = ""), Q(l.current, r), I(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); | ||
| return p.addEventListener("input", b), p.addEventListener("paste", u), p.addEventListener("click", C), p.addEventListener("contextmenu", k), p.addEventListener("focus", H), p.addEventListener("blur", H), a || p.focus(), () => { | ||
| M.current && clearTimeout(M.current), p.removeEventListener("input", b), p.removeEventListener("paste", u), p.removeEventListener("click", C), p.removeEventListener("contextmenu", k), p.removeEventListener("focus", H), p.removeEventListener("blur", H); | ||
| }; | ||
| }, [e, n, u, f, s, m, r, A, o]); | ||
| const _ = (T?.enabled ?? !1) && (T?.provider ?? "browser") === "browser"; | ||
| }, [e, n, f, d, m, s, r, A, a]); | ||
| const _ = (S?.enabled ?? !1) && (S?.provider ?? "browser") === "browser"; | ||
| return F(() => { | ||
| if (!l.current || typeof window > "u" || o || c?.keyboardNavigation === !1) | ||
| if (!l.current || typeof window > "u" || a || c?.keyboardNavigation === !1) | ||
| return; | ||
| const b = new ke(), d = l.current, C = (E) => { | ||
| b.handleKeyDown(E, (z, p) => { | ||
| const b = new Te(), u = l.current, C = (k) => { | ||
| b.handleKeyDown(k, (H, p) => { | ||
| if (typeof window < "u" && window.executeEditorCommand) { | ||
| const x = l.current?.closest("[data-editora-editor]"); | ||
| window.__editoraCommandEditorRoot = x || null, window.executeEditorCommand(z, p); | ||
| window.__editoraCommandEditorRoot = x || null, window.executeEditorCommand(H, p); | ||
| } | ||
| }); | ||
| }; | ||
| return d.addEventListener("keydown", C), () => { | ||
| d.removeEventListener("keydown", C); | ||
| return u.addEventListener("keydown", C), () => { | ||
| u.removeEventListener("keydown", C); | ||
| }; | ||
| }, [c?.keyboardNavigation, o]), /* @__PURE__ */ h( | ||
| }, [c?.keyboardNavigation, a]), /* @__PURE__ */ w( | ||
| "div", | ||
| { | ||
| ref: l, | ||
| contentEditable: !o, | ||
| contentEditable: !a, | ||
| suppressContentEditableWarning: !0, | ||
| spellCheck: o ? !1 : _, | ||
| spellCheck: a ? !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-viewport-only-scan": s?.viewportOnlyScan ? "true" : "false", | ||
| "data-a11y-checker": c?.checker ? "true" : "false", | ||
| "data-readonly": o ? "true" : "false", | ||
| className: `rte-content ${o ? "rte-content-readonly" : ""}`, | ||
| "data-readonly": a ? "true" : "false", | ||
| className: `rte-content ${a ? "rte-content-readonly" : ""}`, | ||
| style: { | ||
@@ -863,47 +883,47 @@ minHeight: `${y}px`, | ||
| ); | ||
| }, nt = ({ | ||
| }, gt = ({ | ||
| editor: e, | ||
| isEnabled: t, | ||
| viewportOnlyScan: a = !0, | ||
| readonly: o = !1 | ||
| viewportOnlyScan: o = !0, | ||
| readonly: a = !1 | ||
| }) => { | ||
| 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); | ||
| const [r, n] = G(!1), [f, d] = G({ top: 0, left: 0 }), m = L(null), s = L(null), c = L(null), R = L(null), A = L(null); | ||
| F(() => { | ||
| if (!t || o) { | ||
| if (!t || a) { | ||
| n(!1); | ||
| return; | ||
| } | ||
| A.current = s.current?.closest("[data-editora-editor]"); | ||
| const l = (d) => { | ||
| A.current = m.current?.closest("[data-editora-editor]"); | ||
| const l = (u) => { | ||
| if (A.current) return A.current; | ||
| const C = s.current?.closest("[data-editora-editor]"); | ||
| const C = m.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]"); | ||
| const k = u?.commonAncestorContainer, p = (k ? k.nodeType === Node.ELEMENT_NODE ? k : k.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( | ||
| }, D = (u) => u && u.querySelector(".rte-content, .editora-content") || null, M = (u) => { | ||
| if (!u || a) return !0; | ||
| const C = u.getAttribute("contenteditable"), k = u.getAttribute("data-readonly"); | ||
| return C === "false" || k === "true" ? !0 : !!u.closest( | ||
| '[readonly], [data-readonly="true"], .rte-editor[data-readonly="true"], editora-editor[readonly]' | ||
| ); | ||
| }, v = (d) => { | ||
| if (!d.anchorNode || !d.focusNode) return !1; | ||
| }, v = (u) => { | ||
| if (!u.anchorNode || !u.focusNode) return !1; | ||
| try { | ||
| const C = document.createRange(); | ||
| return C.setStart(d.anchorNode, d.anchorOffset), C.setEnd(d.focusNode, d.focusOffset), C.collapsed; | ||
| return C.setStart(u.anchorNode, u.anchorOffset), C.setEnd(u.focusNode, u.focusOffset), C.collapsed; | ||
| } catch { | ||
| return !1; | ||
| } | ||
| }, 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]; | ||
| }, y = (u, C) => { | ||
| const k = Array.from(C.getClientRects()).filter((p) => p.width > 0 || p.height > 0); | ||
| return k.length === 0 ? C.getBoundingClientRect() : v(u) ? k[0] : k[k.length - 1]; | ||
| }, g = () => { | ||
| R.current && clearTimeout(R.current); | ||
| const d = window.getSelection(); | ||
| if (!d || d.rangeCount === 0) { | ||
| const u = window.getSelection(); | ||
| if (!u || u.rangeCount === 0) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| const C = d.getRangeAt(0); | ||
| const C = u.getRangeAt(0); | ||
| if (C.collapsed) { | ||
@@ -913,3 +933,3 @@ n(!1), c.current = null; | ||
| } | ||
| const E = d.toString().trim(), z = l(C), p = H(z); | ||
| const k = u.toString().trim(), H = l(C), p = D(H); | ||
| if (!p || !p.contains(C.commonAncestorContainer)) { | ||
@@ -919,9 +939,9 @@ n(!1), c.current = null; | ||
| } | ||
| if (I(p)) { | ||
| if (M(p)) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| if (a) { | ||
| const x = p.getBoundingClientRect(), S = x.bottom >= 0 && x.top <= window.innerHeight, W = document.activeElement === p || p.contains(document.activeElement); | ||
| if (!S && !W) { | ||
| if (o) { | ||
| const x = p.getBoundingClientRect(), T = x.bottom >= 0 && x.top <= window.innerHeight, W = document.activeElement === p || p.contains(document.activeElement); | ||
| if (!T && !W) { | ||
| n(!1), c.current = null; | ||
@@ -931,21 +951,21 @@ return; | ||
| } | ||
| if (E.length > 0) { | ||
| const x = y(d, C), S = p.getBoundingClientRect(), W = 300; | ||
| if (x && S) { | ||
| if (k.length > 0) { | ||
| const x = y(u, C), T = p.getBoundingClientRect(), W = 300; | ||
| if (x && T) { | ||
| 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(); | ||
| const B = W / 2, U = T.left, j = T.right; | ||
| O - B < U && (O = U + B + 10), O + B > j && (O = j - B - 10), d({ top: q, left: O }), n(!0), c.current = C.cloneRange(); | ||
| } | ||
| } else | ||
| n(!1), c.current = null; | ||
| }, M = (d) => { | ||
| if (m.current && !m.current.contains(d.target)) { | ||
| }, I = (u) => { | ||
| if (s.current && !s.current.contains(u.target)) { | ||
| const C = l(); | ||
| window.getSelection(), H(C)?.contains(d.target) || (n(!1), c.current = null); | ||
| window.getSelection(), D(C)?.contains(u.target) || (n(!1), c.current = null); | ||
| } | ||
| }, N = (d) => { | ||
| d.key === "Escape" && (n(!1), c.current = null); | ||
| }, _ = H(l()), b = _ && typeof MutationObserver < "u" ? new MutationObserver(() => { | ||
| I(_) && (n(!1), c.current = null); | ||
| }, z = (u) => { | ||
| u.key === "Escape" && (n(!1), c.current = null); | ||
| }, _ = D(l()), b = _ && typeof MutationObserver < "u" ? new MutationObserver(() => { | ||
| M(_) && (n(!1), c.current = null); | ||
| }) : null; | ||
@@ -955,15 +975,15 @@ return b && _ && b.observe(_, { | ||
| 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); | ||
| }), document.addEventListener("selectionchange", g), document.addEventListener("mousedown", I), document.addEventListener("keydown", z), _?.addEventListener("mouseup", g), _?.addEventListener("keyup", g), () => { | ||
| document.removeEventListener("selectionchange", g), document.removeEventListener("mousedown", I), document.removeEventListener("keydown", z), _?.removeEventListener("mouseup", g), _?.removeEventListener("keyup", g), b?.disconnect(), R.current && clearTimeout(R.current); | ||
| }; | ||
| }, [t, a, o]); | ||
| const T = (l, H) => { | ||
| if (o || !c.current) return; | ||
| }, [t, o, a]); | ||
| const S = (l, D) => { | ||
| if (a || !c.current) return; | ||
| typeof window < "u" && (window.__editoraCommandEditorRoot = A.current || null); | ||
| const I = A.current?.querySelector(".rte-content, .editora-content"); | ||
| if (I && (I.getAttribute("contenteditable") === "false" || I.getAttribute("data-readonly") === "true")) { | ||
| const M = A.current?.querySelector(".rte-content, .editora-content"); | ||
| if (M && (M.getAttribute("contenteditable") === "false" || M.getAttribute("data-readonly") === "true")) { | ||
| n(!1), c.current = null; | ||
| return; | ||
| } | ||
| I && I.focus(); | ||
| M && M.focus(); | ||
| const v = window.getSelection(); | ||
@@ -989,23 +1009,23 @@ if (v && c.current) | ||
| if (g && g.rangeCount > 0) { | ||
| const M = g.getRangeAt(0), N = document.createElement("code"); | ||
| M.surroundContents(N); | ||
| const I = g.getRangeAt(0), z = document.createElement("code"); | ||
| I.surroundContents(z); | ||
| } | ||
| }, | ||
| setBlockType: () => { | ||
| if (H === "blockquote") { | ||
| if (D === "blockquote") { | ||
| const g = window.getSelection(); | ||
| if (g && g.rangeCount > 0) { | ||
| 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"); | ||
| const I = g.getRangeAt(0); | ||
| (I.commonAncestorContainer.nodeType === Node.TEXT_NODE ? I.commonAncestorContainer.parentElement : I.commonAncestorContainer)?.closest?.("blockquote") ? document.execCommand("formatBlock", !1, "p") : document.execCommand("formatBlock", !1, "blockquote"); | ||
| } | ||
| } else H && document.execCommand("formatBlock", !1, H); | ||
| } else D && document.execCommand("formatBlock", !1, D); | ||
| } | ||
| })[l]?.(), n(!1), c.current = null; | ||
| }; | ||
| 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" }), | ||
| return !t || a ? /* @__PURE__ */ w("span", { ref: m, style: { display: "none" }, "aria-hidden": "true" }) : /* @__PURE__ */ V(te, { children: [ | ||
| /* @__PURE__ */ w("span", { ref: m, style: { display: "none" }, "aria-hidden": "true" }), | ||
| r && /* @__PURE__ */ V( | ||
| "div", | ||
| { | ||
| ref: m, | ||
| ref: s, | ||
| className: "floating-toolbar", | ||
@@ -1015,4 +1035,4 @@ onMouseDown: (l) => l.preventDefault(), | ||
| position: "fixed", | ||
| top: `${u.top}px`, | ||
| left: `${u.left}px`, | ||
| top: `${f.top}px`, | ||
| left: `${f.left}px`, | ||
| transform: "translateX(-50%)", | ||
@@ -1023,44 +1043,44 @@ zIndex: 1e4, | ||
| children: [ | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("toggleBold"), | ||
| onClick: () => S("toggleBold"), | ||
| title: "Bold (Ctrl+B)", | ||
| children: /* @__PURE__ */ h("strong", { children: "B" }) | ||
| children: /* @__PURE__ */ w("strong", { children: "B" }) | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("toggleItalic"), | ||
| onClick: () => S("toggleItalic"), | ||
| title: "Italic (Ctrl+I)", | ||
| children: /* @__PURE__ */ h("em", { children: "I" }) | ||
| children: /* @__PURE__ */ w("em", { children: "I" }) | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("toggleUnderline"), | ||
| onClick: () => S("toggleUnderline"), | ||
| title: "Underline (Ctrl+U)", | ||
| children: /* @__PURE__ */ h("u", { children: "U" }) | ||
| children: /* @__PURE__ */ w("u", { children: "U" }) | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("toggleStrikethrough"), | ||
| onClick: () => S("toggleStrikethrough"), | ||
| title: "Strikethrough", | ||
| children: /* @__PURE__ */ h("s", { children: "S" }) | ||
| children: /* @__PURE__ */ w("s", { children: "S" }) | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h("div", { className: "floating-toolbar-separator" }), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w("div", { className: "floating-toolbar-separator" }), | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("clearFormatting"), | ||
| onClick: () => S("clearFormatting"), | ||
| title: "Clear Formatting", | ||
@@ -1070,7 +1090,7 @@ children: "⌫" | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("createLink"), | ||
| onClick: () => S("createLink"), | ||
| title: "Insert Link", | ||
@@ -1080,7 +1100,7 @@ children: "🔗" | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("toggleCode"), | ||
| onClick: () => S("toggleCode"), | ||
| title: "Code", | ||
@@ -1090,8 +1110,8 @@ children: "Code" | ||
| ), | ||
| /* @__PURE__ */ h("div", { className: "floating-toolbar-separator" }), | ||
| /* @__PURE__ */ h( | ||
| /* @__PURE__ */ w("div", { className: "floating-toolbar-separator" }), | ||
| /* @__PURE__ */ w( | ||
| "button", | ||
| { | ||
| className: "floating-toolbar-btn", | ||
| onClick: () => T("setBlockType", "blockquote"), | ||
| onClick: () => S("setBlockType", "blockquote"), | ||
| title: "Quote", | ||
@@ -1105,15 +1125,15 @@ children: "❝" | ||
| ] }); | ||
| }, rt = ({ | ||
| }, ht = ({ | ||
| plugins: e, | ||
| children: t | ||
| }) => { | ||
| const a = e.filter((r) => r.context?.provider); | ||
| return a.length === 0 ? /* @__PURE__ */ h(ee, { children: t }) : a.reduce( | ||
| const o = e.filter((r) => r.context?.provider); | ||
| return o.length === 0 ? /* @__PURE__ */ w(te, { children: t }) : o.reduce( | ||
| (r, n) => { | ||
| const u = n.context.provider; | ||
| return /* @__PURE__ */ h(u, { children: r }, n.name); | ||
| const f = n.context.provider; | ||
| return /* @__PURE__ */ w(f, { children: r }, n.name); | ||
| }, | ||
| /* @__PURE__ */ h(ee, { children: t }) | ||
| /* @__PURE__ */ w(te, { children: t }) | ||
| ); | ||
| }, Ce = /* @__PURE__ */ new Set(), Ee = /* @__PURE__ */ new Set(), ie = (e) => !!e && typeof e == "object" && typeof e.name == "string", xe = (e) => { | ||
| }, xe = /* @__PURE__ */ new Set(), Le = /* @__PURE__ */ new Set(), ue = (e) => !!e && typeof e == "object" && typeof e.name == "string", Ne = (e) => { | ||
| const t = e?.pluginFactories; | ||
@@ -1124,17 +1144,17 @@ return { | ||
| }; | ||
| }, ot = (e, t) => { | ||
| }, bt = (e, t) => { | ||
| if (!Array.isArray(e)) return []; | ||
| const a = xe(t), o = [], r = []; | ||
| const o = Ne(t), a = [], r = []; | ||
| if (e.forEach((n) => { | ||
| if (ie(n)) { | ||
| o.push(n); | ||
| if (ue(n)) { | ||
| a.push(n); | ||
| return; | ||
| } | ||
| if (typeof n != "string") return; | ||
| const u = a[n]; | ||
| if (typeof u == "function") | ||
| const f = o[n]; | ||
| if (typeof f == "function") | ||
| try { | ||
| const f = u(); | ||
| if (ie(f)) { | ||
| o.push(f); | ||
| const d = f(); | ||
| if (ue(d)) { | ||
| a.push(d); | ||
| return; | ||
@@ -1147,3 +1167,3 @@ } | ||
| const n = r.slice().sort().join("|"); | ||
| Ce.has(n) || (Ce.add(n), console.warn( | ||
| xe.has(n) || (xe.add(n), console.warn( | ||
| `[Editora React] Unresolved string plugin names: ${r.join( | ||
@@ -1154,10 +1174,10 @@ ", " | ||
| } | ||
| return o; | ||
| }, at = (e, t, a) => { | ||
| return a; | ||
| }, wt = (e, t, o) => { | ||
| if (!t?.checker || e.some((n) => n?.name === "a11yChecker")) return e; | ||
| const o = xe(a).a11yChecker; | ||
| if (typeof o == "function") | ||
| const a = Ne(o).a11yChecker; | ||
| if (typeof a == "function") | ||
| try { | ||
| const n = o(); | ||
| if (ie(n)) | ||
| const n = a(); | ||
| if (ue(n)) | ||
| return [...e, n]; | ||
@@ -1167,6 +1187,6 @@ } catch { | ||
| const r = "accessibility.checker"; | ||
| return Ee.has(r) || (Ee.add(r), console.warn( | ||
| return Le.has(r) || (Le.add(r), console.warn( | ||
| '[Editora React] accessibility.checker=true requires an "a11yChecker" plugin instance or factory.' | ||
| )), e; | ||
| }, it = { | ||
| }, vt = { | ||
| readonly: !1, | ||
@@ -1249,12 +1269,12 @@ placeholder: "", | ||
| }; | ||
| function Te(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] = Te(n, r) : a[o] = r); | ||
| function De(e, t) { | ||
| const o = { ...e }; | ||
| for (const a in t) { | ||
| const r = t[a], n = o[a]; | ||
| r !== void 0 && (typeof r == "object" && r !== null && !Array.isArray(r) && typeof n == "object" && n !== null && !Array.isArray(n) ? o[a] = De(n, r) : o[a] = r); | ||
| } | ||
| return a; | ||
| return o; | ||
| } | ||
| function lt(e) { | ||
| const t = Te(it, { | ||
| function pt(e) { | ||
| const t = De(vt, { | ||
| readonly: e.readonly, | ||
@@ -1278,6 +1298,6 @@ placeholder: e.placeholder, | ||
| if (e.floatingToolbar !== void 0) { | ||
| const o = typeof e.floatingToolbar == "boolean" ? e.floatingToolbar : e.floatingToolbar.enabled; | ||
| const a = typeof e.floatingToolbar == "boolean" ? e.floatingToolbar : e.floatingToolbar.enabled; | ||
| t.toolbar = { | ||
| ...t.toolbar, | ||
| floating: o ?? t.toolbar.floating | ||
| floating: a ?? t.toolbar.floating | ||
| }; | ||
@@ -1300,4 +1320,4 @@ } | ||
| onDestroy: e.onDestroy, | ||
| plugins: at( | ||
| ot(e.plugins, e.pluginConfig), | ||
| plugins: wt( | ||
| bt(e.plugins, e.pluginConfig), | ||
| e.accessibility, | ||
@@ -1309,3 +1329,3 @@ e.pluginConfig | ||
| } | ||
| const le = /* @__PURE__ */ new Map(), ct = () => { | ||
| const de = /* @__PURE__ */ new Map(), yt = () => { | ||
| if (typeof window > "u") | ||
@@ -1322,13 +1342,13 @@ return { editorElement: null, contentElement: null }; | ||
| typeof window < "u" && (window.registerEditorCommand = (e, t) => { | ||
| le.set(e, t); | ||
| de.set(e, t); | ||
| }, window.executeEditorCommand = (e, t) => { | ||
| const a = le.get(e); | ||
| if (a) { | ||
| const o = ct(); | ||
| return a(t, o); | ||
| const o = de.get(e); | ||
| if (o) { | ||
| const a = yt(); | ||
| return o(t, a); | ||
| } else | ||
| return console.warn(`No handler registered for command: ${e}`), !1; | ||
| }); | ||
| const st = (e) => { | ||
| const t = ae(() => lt(e), [ | ||
| const Ct = (e) => { | ||
| const t = ne(() => pt(e), [ | ||
| e.id, | ||
@@ -1356,8 +1376,8 @@ e.className, | ||
| e.mediaConfig | ||
| ]), 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); | ||
| ]), o = L(null), a = L(null), r = L(e.onInit), n = L(e.onDestroy), f = L(e.onChange), d = L(/* @__PURE__ */ new Set()), m = L(null), s = L(null), c = L(null); | ||
| F(() => { | ||
| r.current = e.onInit, n.current = e.onDestroy, u.current = e.onChange; | ||
| r.current = e.onInit, n.current = e.onDestroy, f.current = e.onChange; | ||
| }); | ||
| const R = (v) => { | ||
| u.current?.(v), f.current.forEach((y) => { | ||
| f.current?.(v), d.current.forEach((y) => { | ||
| try { | ||
@@ -1369,21 +1389,21 @@ y(v); | ||
| }); | ||
| }, A = ae(() => { | ||
| const v = new Be(); | ||
| }, A = ne(() => { | ||
| const v = new Ke(); | ||
| t.plugins.forEach((g) => { | ||
| v.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([M, N]) => { | ||
| le.set(M, N); | ||
| v.register(g), g.commands && typeof window < "u" && Object.entries(g.commands).forEach(([I, z]) => { | ||
| de.set(I, z); | ||
| }); | ||
| }); | ||
| const y = new Fe(v); | ||
| return a.current = y, y; | ||
| const y = new je(v); | ||
| return o.current = y, y; | ||
| }, [t.plugins]); | ||
| F(() => { | ||
| const v = { | ||
| getHTML: () => s.current?.querySelector(".rte-content")?.innerHTML || "", | ||
| getHTML: () => m.current?.querySelector(".rte-content")?.innerHTML || "", | ||
| setHTML: (y) => { | ||
| const g = s.current?.querySelector(".rte-content"); | ||
| const g = m.current?.querySelector(".rte-content"); | ||
| g && (g.innerHTML = y); | ||
| }, | ||
| execCommand: (y, g) => { | ||
| typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = s.current || null, window.executeEditorCommand(y, g)); | ||
| typeof window < "u" && window.executeEditorCommand && (window.__editoraCommandEditorRoot = m.current || null, window.executeEditorCommand(y, g)); | ||
| }, | ||
@@ -1394,6 +1414,6 @@ registerCommand: (y, g) => { | ||
| focus: () => { | ||
| s.current?.querySelector(".rte-content")?.focus(); | ||
| m.current?.querySelector(".rte-content")?.focus(); | ||
| }, | ||
| blur: () => { | ||
| s.current?.querySelector(".rte-content")?.blur(); | ||
| m.current?.querySelector(".rte-content")?.blur(); | ||
| }, | ||
@@ -1403,4 +1423,4 @@ destroy: () => { | ||
| }, | ||
| onChange: (y) => (f.current.add(y), () => { | ||
| f.current.delete(y); | ||
| onChange: (y) => (d.current.add(y), () => { | ||
| d.current.delete(y); | ||
| }), | ||
@@ -1415,33 +1435,33 @@ getState: () => ({ | ||
| }; | ||
| return o.current = v, r.current && r.current(v), () => { | ||
| f.current.clear(), n.current && n.current(); | ||
| return a.current = v, r.current && r.current(v), () => { | ||
| d.current.clear(), n.current && n.current(); | ||
| }; | ||
| }, []), F(() => { | ||
| if (t.statusbar.enabled && c.current && s.current) { | ||
| m.current || (m.current = new _e({ | ||
| if (t.statusbar.enabled && c.current && m.current) { | ||
| s.current || (s.current = new Ve({ | ||
| enabled: !0, | ||
| position: t.statusbar.position | ||
| }), m.current.create(c.current)); | ||
| const v = s.current.querySelector(".rte-content"); | ||
| }), s.current.create(c.current)); | ||
| const v = m.current.querySelector(".rte-content"); | ||
| if (v) { | ||
| const y = () => { | ||
| const E = document.activeElement; | ||
| return !!E && (E === v || v.contains(E)); | ||
| const k = document.activeElement; | ||
| return !!k && (k === v || v.contains(k)); | ||
| }, g = () => { | ||
| const E = v.getBoundingClientRect(); | ||
| return E.bottom >= 0 && E.top <= window.innerHeight; | ||
| }, M = () => { | ||
| const E = window.getSelection(); | ||
| if (!E || E.rangeCount === 0) return null; | ||
| const z = E.getRangeAt(0), p = z.commonAncestorContainer; | ||
| return v.contains(p) ? z : null; | ||
| }, N = (E = !1) => { | ||
| const k = v.getBoundingClientRect(); | ||
| return k.bottom >= 0 && k.top <= window.innerHeight; | ||
| }, I = () => { | ||
| const k = window.getSelection(); | ||
| if (!k || k.rangeCount === 0) return null; | ||
| const H = k.getRangeAt(0), p = H.commonAncestorContainer; | ||
| return v.contains(p) ? H : null; | ||
| }, z = (k = !1) => { | ||
| if (t.performance.viewportOnlyScan !== !1 && !g() && !y()) | ||
| return; | ||
| const p = M(), x = !!p || y(); | ||
| if (E && !x) | ||
| const p = I(), x = !!p || y(); | ||
| if (k && !x) | ||
| return; | ||
| const S = v.textContent || "", { words: W, chars: q } = ze(S), O = Oe(v); | ||
| const T = v.textContent || "", { words: W, chars: q } = Ge(T), O = Xe(v); | ||
| let B, U; | ||
| p && (B = We(v, p), p.collapsed || (U = Pe(p, B), B = void 0)), m.current?.update({ | ||
| p && (B = Je(v, p), p.collapsed || (U = Qe(p, B), B = void 0)), s.current?.update({ | ||
| wordCount: W, | ||
@@ -1453,18 +1473,18 @@ charCount: q, | ||
| }); | ||
| }, _ = () => 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); | ||
| }, _ = () => z(), b = () => z(!0), u = () => z(), C = () => z(); | ||
| return v.addEventListener("input", _), v.addEventListener("focus", u), v.addEventListener("blur", C), document.addEventListener("selectionchange", b), z(), () => { | ||
| v.removeEventListener("input", _), v.removeEventListener("focus", u), v.removeEventListener("blur", C), document.removeEventListener("selectionchange", b); | ||
| }; | ||
| } | ||
| } else | ||
| m.current && (m.current.destroy(), m.current = null); | ||
| s.current && (s.current.destroy(), s.current = null); | ||
| return () => { | ||
| m.current && (m.current.destroy(), m.current = null); | ||
| s.current && (s.current.destroy(), s.current = null); | ||
| }; | ||
| }, [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, I = t.toolbar.showMoreOptions ?? !0; | ||
| return /* @__PURE__ */ h(rt, { plugins: t.plugins, children: /* @__PURE__ */ V( | ||
| const S = t.toolbar.floating ?? !1, l = t.toolbar.position || "top", D = t.toolbar.sticky ?? !1, M = t.toolbar.showMoreOptions ?? !0; | ||
| return /* @__PURE__ */ w(ht, { plugins: t.plugins, children: /* @__PURE__ */ V( | ||
| "div", | ||
| { | ||
| ref: s, | ||
| ref: m, | ||
| id: t.id, | ||
@@ -1482,16 +1502,16 @@ "data-editora-editor": !0, | ||
| children: [ | ||
| l !== "bottom" && /* @__PURE__ */ h( | ||
| ve, | ||
| l !== "bottom" && /* @__PURE__ */ w( | ||
| ke, | ||
| { | ||
| editor: A, | ||
| position: l, | ||
| sticky: H, | ||
| floating: T, | ||
| sticky: D, | ||
| floating: S, | ||
| readonly: t.readonly, | ||
| showMoreOptions: I, | ||
| showMoreOptions: M, | ||
| itemsOverride: t.toolbar.items | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| tt, | ||
| /* @__PURE__ */ w( | ||
| mt, | ||
| { | ||
@@ -1514,19 +1534,19 @@ editor: A, | ||
| ), | ||
| l === "bottom" && /* @__PURE__ */ h( | ||
| ve, | ||
| l === "bottom" && /* @__PURE__ */ w( | ||
| ke, | ||
| { | ||
| editor: A, | ||
| position: l, | ||
| sticky: H, | ||
| floating: T, | ||
| sticky: D, | ||
| floating: S, | ||
| readonly: t.readonly, | ||
| showMoreOptions: I, | ||
| showMoreOptions: M, | ||
| itemsOverride: t.toolbar.items | ||
| } | ||
| ), | ||
| /* @__PURE__ */ h( | ||
| nt, | ||
| /* @__PURE__ */ w( | ||
| gt, | ||
| { | ||
| editor: A, | ||
| isEnabled: T, | ||
| isEnabled: S, | ||
| viewportOnlyScan: t.performance.viewportOnlyScan, | ||
@@ -1536,3 +1556,3 @@ readonly: t.readonly | ||
| ), | ||
| t.statusbar.enabled && /* @__PURE__ */ h( | ||
| t.statusbar.enabled && /* @__PURE__ */ w( | ||
| "div", | ||
@@ -1548,13 +1568,13 @@ { | ||
| ) }); | ||
| }, gt = (e) => /* @__PURE__ */ h(st, { ...e }); | ||
| function ht(e = {}) { | ||
| const t = L(null), a = L(e.onCommand); | ||
| }, At = (e) => /* @__PURE__ */ w(Ct, { ...e }); | ||
| function xt(e = {}) { | ||
| const t = L(null), o = L(e.onCommand); | ||
| return F(() => { | ||
| a.current = e.onCommand; | ||
| o.current = e.onCommand; | ||
| }), F(() => { | ||
| if (typeof window > "u" || e.enabled === !1) return; | ||
| const o = new ke(e); | ||
| t.current = o; | ||
| const r = (u) => o.handleKeyDown(u, (s, m) => { | ||
| a.current && a.current(s, m), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(s, m); | ||
| const a = new Te(e); | ||
| t.current = a; | ||
| const r = (f) => a.handleKeyDown(f, (m, s) => { | ||
| o.current && o.current(m, s), typeof window < "u" && window.executeEditorCommand && window.executeEditorCommand(m, s); | ||
| }), n = e.editorElement || document; | ||
@@ -1566,3 +1586,3 @@ return n && n.addEventListener("keydown", r), () => { | ||
| getShortcuts: () => t.current?.getAllShortcuts() || [], | ||
| getShortcutForCommand: (o) => t.current?.getShortcutForCommand(o), | ||
| getShortcutForCommand: (a) => t.current?.getShortcutForCommand(a), | ||
| getShortcutsHelp: () => t.current?.getShortcutsHelp() || "", | ||
@@ -1575,9 +1595,9 @@ enable: () => t.current?.enable(), | ||
| export { | ||
| tt as EditorContent, | ||
| gt as EditoraEditor, | ||
| $e as InlineMenu, | ||
| gt as RichTextEditor, | ||
| ve as Toolbar, | ||
| lt as mergeConfig, | ||
| ht as useKeyboardShortcuts | ||
| mt as EditorContent, | ||
| At as EditoraEditor, | ||
| Ye as InlineMenu, | ||
| At as RichTextEditor, | ||
| ke as Toolbar, | ||
| pt as mergeConfig, | ||
| xt as useKeyboardShortcuts | ||
| }; |
+4
-4
| { | ||
| "name": "@editora/react", | ||
| "version": "1.0.12", | ||
| "version": "1.0.13", | ||
| "description": "React components for Editora - Best Free Premium Rich Text Editor. Free React WYSIWYG editor with enterprise features, 30+ free plugins, and accessibility support.", | ||
@@ -67,5 +67,5 @@ "author": "Ajay Kumar <ajaykr089@gmail.com>", | ||
| "peerDependencies": { | ||
| "@editora/core": "^1.0.7", | ||
| "@editora/plugins": "^1.0.8", | ||
| "@editora/themes": "^1.0.8", | ||
| "@editora/core": "^1.0.9", | ||
| "@editora/plugins": "^1.0.11", | ||
| "@editora/themes": "^1.0.10", | ||
| "react": ">=16.8 <21", | ||
@@ -72,0 +72,0 @@ "react-dom": ">=16.8 <21" |
+1
-1
@@ -556,5 +556,5 @@ # @editora/react | ||
| - [Documentation](https://github.com/ajaykr089/Editora#readme) | ||
| - [Documentation](https://editora-ecosystem.netlify.app/) | ||
| - [GitHub Repository](https://github.com/ajaykr089/Editora) | ||
| - [Issue Tracker](https://github.com/ajaykr089/Editora/issues) | ||
| - [npm Package](https://www.npmjs.com/package/@editora/react) |
108446
1.35%1854
1.2%