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