@nextblock-cms/editor 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -4
- package/index.mjs +10 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -461,14 +461,14 @@ https://github.com/highlightjs/highlight.js/issues/2277`),Ze=I,Ne=Z),pe===void 0
|
|
|
461
461
|
<circle cx="9" cy="15" r="1.5" fill="currentColor"/>
|
|
462
462
|
</svg>
|
|
463
463
|
`,n.setAttribute("aria-hidden","true"),t.dataset.tooltip=`Click for options
|
|
464
|
-
Hold for drag`,t.appendChild(e),t.appendChild(n);const r=()=>t.classList.add("tiptap-drag-handle--hint"),s=()=>t.classList.remove("tiptap-drag-handle--hint");return n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",s),t.addEventListener("mouseleave",s),e.addEventListener("mousedown",o=>{o.preventDefault(),o.stopPropagation()}),e.addEventListener("dragstart",o=>{o.preventDefault(),o.stopPropagation()}),e.addEventListener("keydown",o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),e.click())}),e.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),t.classList.remove("tiptap-drag-handle--hint");const i=new CustomEvent("tiptap-gutter-toggle",{bubbles:!0,detail:{handle:t,button:e}});t.dispatchEvent(i)}),t},onNodeChange:({editor:t,node:e})=>{if(!pn)return;const n=(e==null?void 0:e.type.name)==="doc";!!e&&!n&&t.isFocused&&t.isEditable?(pn.dataset.active="true",pn.style.visibility="",pn.style.pointerEvents="auto"):(pn.dataset.active="false",pn.classList.remove("tiptap-drag-handle--hint"),pn.removeAttribute("data-menu-open"),pn.style.visibility="hidden",pn.style.pointerEvents="none",Zi==null||Zi.setAttribute("aria-expanded","false"))}})];var LI=typeof document<"u",II=function(){},hd=LI?C.useLayoutEffect:II;const jI={...ne},PI=jI.useInsertionEffect,BI=PI||(t=>t());function HI(t){const e=ne.useRef(()=>{if(process.env.NODE_ENV!=="production")throw new Error("Cannot call an event handler while rendering.")});return BI(()=>{e.current=t}),ne.useCallback(function(){for(var n=arguments.length,r=new Array(n),s=0;s<n;s++)r[s]=arguments[s];return e.current==null?void 0:e.current(...r)},[])}var $I=typeof document<"u",zI=function(){},fl=$I?C.useLayoutEffect:zI;function ya(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!ya(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!ya(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function aw(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function Km(t,e){const n=aw(t);return Math.round(e*n)/n}function iu(t){const e=ne.useRef(t);return fl(()=>{e.current=t}),e}function FI(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:l=!0,whileElementsMounted:a,open:c}=t,[u,d]=ne.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[h,f]=ne.useState(r);ya(h,r)||f(r);const[p,g]=ne.useState(null),[y,b]=ne.useState(null),x=ne.useCallback(F=>{F!==w.current&&(w.current=F,g(F))},[]),E=ne.useCallback(F=>{F!==T.current&&(T.current=F,b(F))},[]),S=o||p,M=i||y,w=ne.useRef(null),T=ne.useRef(null),k=ne.useRef(u),N=a!=null,R=iu(a),B=iu(s),P=iu(c),L=ne.useCallback(()=>{if(!w.current||!T.current)return;const F={placement:e,strategy:n,middleware:h};B.current&&(F.platform=B.current),bh(w.current,T.current,F).then(le=>{const Se={...le,isPositioned:P.current!==!1};H.current&&!ya(k.current,Se)&&(k.current=Se,Xw.flushSync(()=>{d(Se)}))})},[h,e,n,B,P]);fl(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(F=>({...F,isPositioned:!1})))},[c]);const H=ne.useRef(!1);fl(()=>(H.current=!0,()=>{H.current=!1}),[]),fl(()=>{if(S&&(w.current=S),M&&(T.current=M),S&&M){if(R.current)return R.current(S,M,L);L()}},[S,M,L,R,N]);const se=ne.useMemo(()=>({reference:w,floating:T,setReference:x,setFloating:E}),[x,E]),oe=ne.useMemo(()=>({reference:S,floating:M}),[S,M]),we=ne.useMemo(()=>{const F={position:n,left:0,top:0};if(!oe.floating)return F;const le=Km(oe.floating,u.x),Se=Km(oe.floating,u.y);return l?{...F,transform:"translate("+le+"px, "+Se+"px)",...aw(oe.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:le,top:Se}},[n,l,oe.floating,u.x,u.y]);return ne.useMemo(()=>({...u,update:L,refs:se,elements:oe,floatingStyles:we}),[u,L,se,oe,we])}const hi=(t,e)=>({...R0(t),options:[t,e]}),ec=(t,e)=>({..._0(t),options:[t,e]}),tc=(t,e)=>({...O0(t),options:[t,e]}),UI=(t,e)=>({...D0(t),options:[t,e]}),VI={...ne};let Gm=!1,WI=0;const Jm=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+WI++;function qI(){const[t,e]=ne.useState(()=>Gm?Jm():void 0);return hd(()=>{t==null&&e(Jm())},[]),ne.useEffect(()=>{Gm=!0},[]),t}const KI=VI.useId,GI=KI||qI;let fd;process.env.NODE_ENV!=="production"&&(fd=new Set);function JI(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];const s="Floating UI: "+n.join(" ");if(!((t=fd)!=null&&t.has(s))){var o;(o=fd)==null||o.add(s),console.error(s)}}function YI(){const t=new Map;return{emit(e,n){var r;(r=t.get(e))==null||r.forEach(s=>s(n))},on(e,n){t.has(e)||t.set(e,new Set),t.get(e).add(n)},off(e,n){var r;(r=t.get(e))==null||r.delete(n)}}}const XI=ne.createContext(null),ZI=ne.createContext(null),QI=()=>{var t;return((t=ne.useContext(XI))==null?void 0:t.id)||null},e2=()=>ne.useContext(ZI);function t2(t){const{open:e=!1,onOpenChange:n,elements:r}=t,s=GI(),o=ne.useRef({}),[i]=ne.useState(()=>YI()),l=QI()!=null;if(process.env.NODE_ENV!=="production"){const f=r.reference;f&&!gt(f)&&JI("Cannot pass a virtual element to the `elements.reference` option,","as it must be a real DOM element. Use `refs.setPositionReference()`","instead.")}const[a,c]=ne.useState(r.reference),u=HI((f,p,g)=>{o.current.openEvent=f?p:void 0,i.emit("openchange",{open:f,event:p,reason:g,nested:l}),n==null||n(f,p,g)}),d=ne.useMemo(()=>({setPositionReference:c}),[]),h=ne.useMemo(()=>({reference:a||r.reference||null,floating:r.floating||null,domReference:r.reference}),[a,r.reference,r.floating]);return ne.useMemo(()=>({dataRef:o,open:e,onOpenChange:u,elements:h,events:i,floatingId:s,refs:d}),[e,u,h,i,s,d])}function fi(t){t===void 0&&(t={});const{nodeId:e}=t,n=t2({...t,elements:{reference:null,floating:null,...t.elements}}),r=t.rootContext||n,s=r.elements,[o,i]=ne.useState(null),[l,a]=ne.useState(null),u=(s==null?void 0:s.domReference)||o,d=ne.useRef(null),h=e2();hd(()=>{u&&(d.current=u)},[u]);const f=FI({...t,elements:{...s,...l&&{reference:l}}}),p=ne.useCallback(E=>{const S=gt(E)?{getBoundingClientRect:()=>E.getBoundingClientRect(),getClientRects:()=>E.getClientRects(),contextElement:E}:E;a(S),f.refs.setReference(S)},[f.refs]),g=ne.useCallback(E=>{(gt(E)||E===null)&&(d.current=E,i(E)),(gt(f.refs.reference.current)||f.refs.reference.current===null||E!==null&&!gt(E))&&f.refs.setReference(E)},[f.refs]),y=ne.useMemo(()=>({...f.refs,setReference:g,setPositionReference:p,domReference:d}),[f.refs,g,p]),b=ne.useMemo(()=>({...f.elements,domReference:u}),[f.elements,u]),x=ne.useMemo(()=>({...f,...r,refs:y,elements:b,nodeId:e}),[f,y,b,e,r]);return hd(()=>{r.dataRef.current.floatingContext=x;const E=h==null?void 0:h.nodesRef.current.find(S=>S.id===e);E&&(E.context=x)}),ne.useMemo(()=>({...f,context:x,refs:y,elements:b}),[f,y,b,x])}const n2="_pickerRoot_1wq30_1",r2="_picker_1wq30_1",Ym={pickerRoot:n2,picker:r2};function nc(){return(nc=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function cw(t,e){if(t==null)return{};var n,r,s={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(s[n]=t[n]);return s}function pd(t){var e=C.useRef(t),n=C.useRef(function(r){e.current&&e.current(r)});return e.current=t,n.current}var qo=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t<e?e:t},bo=function(t){return"touches"in t},md=function(t){return t&&t.ownerDocument.defaultView||self},Xm=function(t,e,n){var r=t.getBoundingClientRect(),s=bo(e)?(function(o,i){for(var l=0;l<o.length;l++)if(o[l].identifier===i)return o[l];return o[0]})(e.touches,n):e;return{left:qo((s.pageX-(r.left+md(t).pageXOffset))/r.width),top:qo((s.pageY-(r.top+md(t).pageYOffset))/r.height)}},Zm=function(t){!bo(t)&&t.preventDefault()},uw=C.memo(function(t){var e=t.onMove,n=t.onKey,r=cw(t,["onMove","onKey"]),s=C.useRef(null),o=pd(e),i=pd(n),l=C.useRef(null),a=C.useRef(!1),c=C.useMemo(function(){var f=function(y){Zm(y),(bo(y)?y.touches.length>0:y.buttons>0)&&s.current?o(Xm(s.current,y,l.current)):g(!1)},p=function(){return g(!1)};function g(y){var b=a.current,x=md(s.current),E=y?x.addEventListener:x.removeEventListener;E(b?"touchmove":"mousemove",f),E(b?"touchend":"mouseup",p)}return[function(y){var b=y.nativeEvent,x=s.current;if(x&&(Zm(b),!(function(S,M){return M&&!bo(S)})(b,a.current)&&x)){if(bo(b)){a.current=!0;var E=b.changedTouches||[];E.length&&(l.current=E[0].identifier)}x.focus(),o(Xm(x,b,l.current)),g(!0)}},function(y){var b=y.which||y.keyCode;b<37||b>40||(y.preventDefault(),i({left:b===39?.05:b===37?-.05:0,top:b===40?.05:b===38?-.05:0}))},g]},[i,o]),u=c[0],d=c[1],h=c[2];return C.useEffect(function(){return h},[h]),C.createElement("div",nc({},r,{onTouchStart:u,onMouseDown:u,className:"react-colorful__interactive",ref:s,onKeyDown:d,tabIndex:0,role:"slider"}))}),Uh=function(t){return t.filter(Boolean).join(" ")},dw=function(t){var e=t.color,n=t.left,r=t.top,s=r===void 0?.5:r,o=Uh(["react-colorful__pointer",t.className]);return C.createElement("div",{className:o,style:{top:100*s+"%",left:100*n+"%"}},C.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:e}}))},ut=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n},s2=function(t){return c2(gd(t))},gd=function(t){return t[0]==="#"&&(t=t.substring(1)),t.length<6?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?ut(parseInt(t[3]+t[3],16)/255,2):1}:{r:parseInt(t.substring(0,2),16),g:parseInt(t.substring(2,4),16),b:parseInt(t.substring(4,6),16),a:t.length===8?ut(parseInt(t.substring(6,8),16)/255,2):1}},o2=function(t){return a2(l2(t))},i2=function(t){var e=t.s,n=t.v,r=t.a,s=(200-e)*n/100;return{h:ut(t.h),s:ut(s>0&&s<200?e*n/100/(s<=100?s:200-s)*100:0),l:ut(s/2),a:ut(r,2)}},yd=function(t){var e=i2(t);return"hsl("+e.h+", "+e.s+"%, "+e.l+"%)"},l2=function(t){var e=t.h,n=t.s,r=t.v,s=t.a;e=e/360*6,n/=100,r/=100;var o=Math.floor(e),i=r*(1-n),l=r*(1-(e-o)*n),a=r*(1-(1-e+o)*n),c=o%6;return{r:ut(255*[r,l,i,i,a,r][c]),g:ut(255*[a,r,r,l,i,i][c]),b:ut(255*[i,i,a,r,r,l][c]),a:ut(s,2)}},Qi=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},a2=function(t){var e=t.r,n=t.g,r=t.b,s=t.a,o=s<1?Qi(ut(255*s)):"";return"#"+Qi(e)+Qi(n)+Qi(r)+o},c2=function(t){var e=t.r,n=t.g,r=t.b,s=t.a,o=Math.max(e,n,r),i=o-Math.min(e,n,r),l=i?o===e?(n-r)/i:o===n?2+(r-e)/i:4+(e-n)/i:0;return{h:ut(60*(l<0?l+6:l)),s:ut(o?i/o*100:0),v:ut(o/255*100),a:s}},u2=C.memo(function(t){var e=t.hue,n=t.onChange,r=Uh(["react-colorful__hue",t.className]);return C.createElement("div",{className:r},C.createElement(uw,{onMove:function(s){n({h:360*s.left})},onKey:function(s){n({h:qo(e+360*s.left,0,360)})},"aria-label":"Hue","aria-valuenow":ut(e),"aria-valuemax":"360","aria-valuemin":"0"},C.createElement(dw,{className:"react-colorful__hue-pointer",left:e/360,color:yd({h:e,s:100,v:100,a:1})})))}),d2=C.memo(function(t){var e=t.hsva,n=t.onChange,r={backgroundColor:yd({h:e.h,s:100,v:100,a:1})};return C.createElement("div",{className:"react-colorful__saturation",style:r},C.createElement(uw,{onMove:function(s){n({s:100*s.left,v:100-100*s.top})},onKey:function(s){n({s:qo(e.s+100*s.left,0,100),v:qo(e.v-100*s.top,0,100)})},"aria-label":"Color","aria-valuetext":"Saturation "+ut(e.s)+"%, Brightness "+ut(e.v)+"%"},C.createElement(dw,{className:"react-colorful__saturation-pointer",top:1-e.v/100,left:e.s/100,color:yd(e)})))}),hw=function(t,e){if(t===e)return!0;for(var n in t)if(t[n]!==e[n])return!1;return!0},h2=function(t,e){return t.toLowerCase()===e.toLowerCase()||hw(gd(t),gd(e))};function f2(t,e,n){var r=pd(n),s=C.useState(function(){return t.toHsva(e)}),o=s[0],i=s[1],l=C.useRef({color:e,hsva:o});C.useEffect(function(){if(!t.equal(e,l.current.color)){var c=t.toHsva(e);l.current={hsva:c,color:e},i(c)}},[e,t]),C.useEffect(function(){var c;hw(o,l.current.hsva)||t.equal(c=t.fromHsva(o),l.current.color)||(l.current={hsva:o,color:c},r(c))},[o,t,r]);var a=C.useCallback(function(c){i(function(u){return Object.assign({},u,c)})},[]);return[o,a]}var p2=typeof window<"u"?C.useLayoutEffect:C.useEffect,m2=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0},Qm=new Map,g2=function(t){p2(function(){var e=t.current?t.current.ownerDocument:document;if(e!==void 0&&!Qm.has(e)){var n=e.createElement("style");n.innerHTML=`.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`,Qm.set(e,n);var r=m2();r&&n.setAttribute("nonce",r),e.head.appendChild(n)}},[])},y2=function(t){var e=t.className,n=t.colorModel,r=t.color,s=r===void 0?n.defaultColor:r,o=t.onChange,i=cw(t,["className","colorModel","color","onChange"]),l=C.useRef(null);g2(l);var a=f2(n,s,o),c=a[0],u=a[1],d=Uh(["react-colorful",e]);return C.createElement("div",nc({},i,{ref:l,className:d}),C.createElement(d2,{hsva:c,onChange:u}),C.createElement(u2,{hue:c.h,onChange:u,className:"react-colorful__last-control"}))},b2={defaultColor:"000",toHsva:s2,fromHsva:function(t){return o2({h:t.h,s:t.s,v:t.v,a:1})},equal:h2},x2=function(t){return C.createElement(y2,nc({},t,{colorModel:b2}))};const eg="#1F2937",tg="#FFF7D1",w2=["#FFF7D1","#FFEAE3","#DCFCE7","#DBEAFE"],v2=[{title:"Brand",colors:[{label:"Primary",value:"hsl(var(--primary))"},{label:"Secondary",value:"hsl(var(--secondary))"},{label:"Accent",value:"hsl(var(--accent))"},{label:"Ring",value:"hsl(var(--ring))"}]},{title:"Neutrals",colors:[{label:"Foreground",value:"hsl(var(--foreground))"},{label:"Muted",value:"hsl(var(--muted-foreground))"},{label:"Background",value:"hsl(var(--background))"},{label:"Card",value:"hsl(var(--card))"}]},{title:"States",colors:[{label:"Warning",value:"hsl(var(--warning))"},{label:"Destructive",value:"hsl(var(--destructive))"},{label:"Success",value:"hsl(var(--chart-2))"},{label:"Info",value:"hsl(var(--chart-5))"}]},{title:"Utility",colors:[{label:"Secondary FG",value:"hsl(var(--secondary-foreground))"},{label:"Accent FG",value:"hsl(var(--accent-foreground))"},{label:"Primary FG",value:"hsl(var(--primary-foreground))"},{label:"Border",value:"hsl(var(--border))"}]}],k2=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,S2=/^#[0-9a-f]{6}$/i,fw=/^rgba?\((\s*\d{1,3}\s*,){2}\s*\d{1,3}\s*(,\s*(0|1|0?\.\d+)\s*)?\)$/i,pw=/^hsla?\((\s*\d{1,3}\s*,)(\s*\d{1,3}%\s*,)\s*\d{1,3}%\s*(,\s*(0|1|0?\.\d+)\s*)?\)$/i;function ba(t){const e=t.replace("#","").trim();return e.length===3||e.length===4?`#${e.split("").map(r=>r+r).join("").toUpperCase()}`:e.length===6||e.length===8?`#${e.toUpperCase()}`:t}function mw(t){const e=ba(t).replace("#","");if(e.length!==6&&e.length!==8)return null;const n=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),s=parseInt(e.slice(4,6),16),o=e.length===8?parseInt(e.slice(6,8),16)/255:1;return{r:n,g:r,b:s,a:o}}function bd(t,e,n){return`#${[t,e,n].map(r=>Math.max(0,Math.min(255,Math.round(r))).toString(16).padStart(2,"0")).join("").toUpperCase()}`}function xo(t,e=2){const n=10**e;return Math.round(t*n)/n}function wo(t,e,n,r=1){const s=t/255,o=e/255,i=n/255,l=Math.max(s,o,i),a=Math.min(s,o,i);let c=0,u=0;const d=(l+a)/2;if(l!==a){const g=l-a;switch(u=d>.5?g/(2-l-a):g/(l+a),l){case s:c=(o-i)/g+(o<i?6:0);break;case o:c=(i-s)/g+2;break;case i:c=(s-o)/g+4;break}c/=6}const h=Math.round(c*360),f=Math.round(u*100),p=Math.round(d*100);return r!==1?`hsla(${h}, ${f}%, ${p}%, ${xo(r,2)})`:`hsl(${h}, ${f}%, ${p}%)`}function ng(t){if(typeof window>"u"||typeof document>"u")return null;const e=document.createElement("span");if(e.style.color="",e.style.color=t,!e.style.color)return null;e.style.position="absolute",e.style.visibility="hidden",e.style.pointerEvents="none",document.body.appendChild(e);const n=getComputedStyle(e).color;document.body.removeChild(e);const r=n.match(/rgba?\(([^)]+)\)/i);if(!r)return null;const[s,o,i,l]=r[1].split(",").map(a=>a.trim()).map((a,c)=>c===3?parseFloat(a):parseInt(a,10));return[s,o,i].some(a=>Number.isNaN(a))?null:{r:s,g:o,b:i,a:typeof l=="number"&&!Number.isNaN(l)?l:1}}function Ln(t){if(!t)return null;const e=t.trim();if(k2.test(e)){const r=ba(e),s=mw(r);if(!s)return null;const o=`#${r.replace("#","").slice(0,6)}`;return{source:r,hex:o,rgb:s.a===1?`rgb(${s.r}, ${s.g}, ${s.b})`:`rgba(${s.r}, ${s.g}, ${s.b}, ${xo(s.a,2)})`,hsl:wo(s.r,s.g,s.b,s.a),alpha:s.a}}if(fw.test(e)||pw.test(e)){const r=ng(e);return r?{source:e,hex:bd(r.r,r.g,r.b),rgb:r.a===1?`rgb(${r.r}, ${r.g}, ${r.b})`:`rgba(${r.r}, ${r.g}, ${r.b}, ${xo(r.a,2)})`,hsl:wo(r.r,r.g,r.b,r.a),alpha:r.a}:null}const n=ng(e);return n?{source:e,hex:bd(n.r,n.g,n.b),rgb:n.a===1?`rgb(${n.r}, ${n.g}, ${n.b})`:`rgba(${n.r}, ${n.g}, ${n.b}, ${xo(n.a,2)})`,hsl:wo(n.r,n.g,n.b,n.a),alpha:n.a}:null}function gw(t){const e=mw(t);if(e)return{source:ba(t),hex:bd(e.r,e.g,e.b),rgb:e.a===1?`rgb(${e.r}, ${e.g}, ${e.b})`:`rgba(${e.r}, ${e.g}, ${e.b}, ${xo(e.a,2)})`,hsl:wo(e.r,e.g,e.b,e.a),alpha:e.a};const n=ba(t);return{source:n,hex:n.slice(0,7),rgb:"rgb(0, 0, 0)",hsl:wo(0,0,0,1),alpha:1}}const eo=Ln(eg)??gw(eg),rg=Ln(tg)??gw(tg);function yw({editor:t,className:e,initialMode:n="text"}){const r=C.useRef(null),[s,o]=C.useState(n),[i,l]=C.useState(null),[a,c]=C.useState(eo),[u,d]=C.useState(rg);C.useEffect(()=>{o(n)},[n]);const[h,f]=C.useState(eo.hex),[p,g]=C.useState(!1),[y,b]=C.useState(eo.rgb),[x,E]=C.useState(!1),[S,M]=C.useState(eo.hsl),[w,T]=C.useState(!1),k=s==="text"?a:u;C.useEffect(()=>{const L=()=>{if(i)return;const H=t.getAttributes("textStyle").color,se=t.getAttributes("highlight").color,oe=Ln(H)??eo,we=Ln(se)??rg;c(oe),d(we)};return L(),t.on("selectionUpdate",L),t.on("transaction",L),()=>{t.off("selectionUpdate",L),t.off("transaction",L)}},[t,i,s]),C.useEffect(()=>{i!=="hex"&&f(k.hex),i!=="rgb"&&b(k.rgb),i!=="hsl"&&M(k.hsl),i===null&&(g(!1),E(!1),T(!1))},[k,i]);const N=C.useCallback((L,H,se=!0)=>{const oe=t.chain();se&&oe.focus(),L==="text"?(c(H),oe.setColor(H.source).run()):(d(H),oe.setHighlight({color:H.source}).run())},[t,c,d]),R=C.useCallback((L,H)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{N(L,H,!1)},300)},[N]),B=C.useCallback(L=>{r.current&&clearTimeout(r.current);const H=Ln(L);H&&(N(s,H,!1),g(!1))},[N,s,g]),P=C.useCallback(L=>{r.current&&clearTimeout(r.current);const H=Ln(L);H&&(N(s,H),g(!1))},[N,s,g]);return m.jsxs("div",{className:$e.cn("flex w-full sm:w-auto flex-col gap-3 sm:gap-4",e),children:[m.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.jsxs("div",{className:"inline-flex items-center gap-1 rounded-md bg-muted/60 p-1",children:[m.jsx(ce.Button,{type:"button",variant:s==="text"?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>o("text"),children:"Text"}),m.jsx(ce.Button,{type:"button",variant:s==="highlight"?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>o("highlight"),children:"Highlight"})]}),m.jsx("div",{className:"flex items-center",children:m.jsx(ce.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>{s==="text"?t.chain().focus().unsetColor().run():t.chain().focus().unsetHighlight().run()},children:"Remove Color"})})]}),m.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-4",children:[m.jsx("div",{className:Ym.pickerRoot,children:m.jsx(x2,{color:k.hex,onChange:B,className:Ym.picker})}),m.jsxs("div",{className:"flex w-full flex-col gap-2 text-[11px] sm:w-[150px]",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"HEX"}),m.jsx(ps.Input,{value:h,onFocus:()=>l("hex"),onChange:L=>{const H=L.target.value;if(f(H),S2.test(H)){const se=Ln(H);se&&(R(s,se),g(!1))}else g(!0)},onBlur:()=>{l(null),p&&(f(k.hex),g(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",p&&"border-destructive focus-visible:ring-destructive")})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"RGB"}),m.jsx(ps.Input,{value:y,onFocus:()=>l("rgb"),onChange:L=>{const H=L.target.value;if(b(H),fw.test(H)){const se=Ln(H);se&&(R(s,se),E(!1))}else E(!0)},onBlur:()=>{l(null),x&&(b(k.rgb),E(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",x&&"border-destructive focus-visible:ring-destructive")})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"HSL"}),m.jsx(ps.Input,{value:S,onFocus:()=>l("hsl"),onChange:L=>{const H=L.target.value;if(M(H),pw.test(H)){const se=Ln(H);se&&(R(s,se),T(!1))}else T(!0)},onBlur:()=>{l(null),w&&(M(k.hsl),T(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",w&&"border-destructive focus-visible:ring-destructive")})]})]})]}),m.jsxs("div",{className:"space-y-1.5",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Theme colors"}),m.jsx("div",{className:"space-y-1",children:v2.map(L=>m.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.jsx("span",{className:"w-16 shrink-0 text-[11px] font-medium text-muted-foreground/80",children:L.title}),m.jsx("div",{className:"flex items-center gap-1.5",children:L.colors.map(H=>m.jsx("button",{type:"button",onClick:()=>P(H.value),className:"h-6 w-6 rounded border border-border bg-background shadow-sm transition hover:border-primary/40 hover:shadow-sm",style:{background:H.value},"aria-label":`${L.title} color ${H.label}`,title:`${L.title} color ${H.label}`},H.label))})]},L.title))})]}),s==="highlight"?m.jsxs("div",{className:"space-y-2",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Highlight presets"}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:w2.map(L=>m.jsxs("button",{type:"button",onClick:()=>P(L),className:"flex items-center gap-1 rounded-full border bg-background px-2 py-1 text-[11px] shadow-sm transition hover:border-primary/40 hover:shadow-sm",children:[m.jsx("span",{className:"h-3.5 w-3.5 rounded-full border",style:{background:L},"aria-hidden":!0}),L]},L))})]}):null]})}const C2=["px","pt","rem","em","%"];function pl(t){if(!t)return null;const n=String(t).trim().match(/^(-?\d*\.?\d+)(px|pt|rem|em|%)$/i);if(!n)return null;const r=parseFloat(n[1]),s=n[2].toLowerCase();return Number.isFinite(r)?{value:r,unit:s}:null}function xd(t){if(!t)return null;const{value:e,unit:n}=t;return n==="%"?`${Math.max(1,Math.round(e))}%`:n==="px"||n==="pt"?`${Math.max(1,Math.round(e))}${n}`:`${Math.max(.01,Math.round(e*100)/100)}${n}`}function E2(t){const e=pl(t);return e?xd(e):null}function M2(){if(typeof document>"u")return[];const t=[];try{const n=Array.from(document.styleSheets),r=[],s=[];for(const l of n){const a=l.href,c=l.ownerNode;`${a||""} ${(c==null?void 0:c.textContent)||""}`.toLowerCase().includes("globals.css")?r.push(l):s.push(l)}const o=[...r,...s],i=new Set(["h1","h2","h3","h4","h5","h6"]);for(const l of o){let a=null;try{a=l.cssRules}catch{continue}if(a){for(const c of Array.from(a))if(c.style){const d=c.style.fontSize,h=c.selectorText;if(d&&h&&i.has(h)){const f=E2(d)??d.trim();if(f){const p=parseInt(h.replace("h",""),10);t.push({level:p,value:f})}}}}}}catch{}const e=new Map;for(const n of t)e.has(n.level)||e.set(n.level,n.value);return Array.from(e.entries()).map(([n,r])=>({level:n,value:r}))}function A2(t){if(typeof document>"u")return 0;try{const e=document.createElement("span");e.style.position="absolute",e.style.visibility="hidden",e.style.fontSize=t,document.body.appendChild(e);const n=parseFloat(getComputedStyle(e).fontSize);return document.body.removeChild(e),Number.isFinite(n)?n:0}catch{return 0}}function xa(){if(typeof document>"u")return 16;try{const t=parseFloat(getComputedStyle(document.documentElement).fontSize);return Number.isFinite(t)&&t>0?t:16}catch{return 16}}function Vh(t){try{const e=t.state.selection.from,n=t.view.domAtPos(e),r=n&&n.node||t.view.dom,s=r.nodeType===1?r:t.view.dom,o=parseFloat(getComputedStyle(s).fontSize);return Number.isFinite(o)&&o>0?o:xa()}catch{return xa()}}function T2(t,e,n){const r=xa(),s=Vh(n);switch(e){case"px":return t;case"pt":return t*(96/72);case"rem":return t*r;case"em":return t*s;case"%":return t/100*s}}function N2(t,e,n){const r=xa(),s=Vh(n);switch(e){case"px":return t;case"pt":return t*(72/96);case"rem":return t/r;case"em":return t/s;case"%":return t/s*100}}function bw({editor:t,className:e}){const[n,r]=C.useState([]),[s,o]=C.useState(null),[i,l]=C.useState(""),[a,c]=C.useState("px"),[u,d]=C.useState(!1),h=C.useRef(null),f=C.useCallback(()=>{const S=t.getAttributes("textStyle").fontSize,M=pl(S);if(M)l(String(M.value)),c(M.unit),d(!1);else{if(S&&typeof S=="string"){const w=A2(S);if(w>0&&!s){l(String(Math.round(w))),c("px"),d(!1);return}}s||(l(""),c("px"),d(!1))}},[t,s]);C.useEffect(()=>{f();const S=()=>f();return t.on("selectionUpdate",S),t.on("transaction",S),()=>{t.off("selectionUpdate",S),t.off("transaction",S)}},[t,f]),C.useEffect(()=>{r(M2())},[]);const p=C.useCallback((S,M=!0)=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{const w=t.chain();M&&w.focus(),w.setFontSize(S).run()},120)},[t]),g=C.useCallback(S=>{l(S);const M=`${S}${a}`,w=pl(M);if(w){d(!1);const T=xd(w);T&&p(T,!1)}else d(S.trim().length>0)},[a,p]),y=C.useCallback(S=>{const M=a;c(S);let w=0;const T=parseFloat(i);Number.isFinite(T)?w=T2(T,M,t):w=Vh(t);let k=N2(w,S,t),N;S==="px"||S==="pt"||S==="%"?N=String(Math.round(k)):N=String(Math.max(.01,Math.round(k*100)/100)),l(N);const R=xd(pl(`${N}${S}`));R&&p(R)},[a,i,t,p]),b=C.useCallback(()=>{h.current&&clearTimeout(h.current),t.chain().focus().unsetFontSize().run(),d(!1)},[t]),x=C.useMemo(()=>a==="px"||a==="pt"||a==="%"?1:.01,[a]),E=C.useMemo(()=>{switch(a){case"%":return"100";case"px":return"16";case"pt":return"12";case"rem":return"1";case"em":return"1";default:return""}},[a]);return m.jsxs("div",{className:$e.cn("space-y-3",e),onMouseDown:S=>S.stopPropagation(),children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx(ss,{className:"h-4 w-4 text-muted-foreground"}),m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Font size"})]}),m.jsxs(ce.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:b,title:"Erase font size","aria-label":"Erase font size",children:[m.jsx(kL,{className:"h-3.5 w-3.5 mr-1"}),"Erase"]})]}),m.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2 items-end",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"Value"}),m.jsx(ps.Input,{type:"number",inputMode:"decimal",step:x,placeholder:E,value:i,onFocus:()=>o("value"),onChange:S=>g(S.target.value),onBlur:()=>o(null),className:$e.cn("h-9",u&&"border-destructive focus-visible:ring-destructive"),spellCheck:!1})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"Unit"}),m.jsx("div",{className:"flex gap-1",children:m.jsx("select",{value:a,onChange:S=>y(S.target.value),onFocus:()=>o("unit"),onBlur:()=>o(null),className:"h-9 w-[84px] rounded-md border border-input bg-background px-2 text-sm shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",children:C2.map(S=>m.jsx("option",{value:S,children:S},S))})})]})]}),m.jsxs("div",{className:"space-y-2",children:[n.length>0?m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Headings"}),m.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:n.map(({level:S,value:M})=>m.jsx("button",{type:"button",onClick:()=>p(M),className:"h-8 w-full rounded-md border bg-background px-2 text-xs font-medium shadow-sm transition hover:border-primary/40 hover:shadow-sm",title:`Apply H${S} (${M})`,children:`H${S} (${M})`},`h${S}`))})]}):null,m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Keywords"}),m.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:["xx-small","x-small","small","medium","large","x-large"].map(S=>m.jsx("button",{type:"button",onClick:()=>p(S),className:"h-8 w-full rounded-md border bg-background px-2 text-xs font-medium shadow-sm transition hover:border-primary/40 hover:shadow-sm",title:`Apply ${S}`,children:S.replace(/\b\w/g,M=>M.toUpperCase())},S))})]})]})]})}const R2=({editor:t})=>{var s;const[e,n]=C.useState(((s=t.getAttributes("link"))==null?void 0:s.href)??"");C.useEffect(()=>{const o=()=>{var i;n(((i=t.getAttributes("link"))==null?void 0:i.href)??"")};return t.on("selectionUpdate",o),t.on("transaction",o),()=>{t.off("selectionUpdate",o),t.off("transaction",o)}},[t]);const r=()=>{const o=e.trim();o?t.chain().focus().extendMarkRange("link").setLink({href:o}).run():t.chain().focus().extendMarkRange("link").unsetLink().run()};return m.jsxs("div",{className:"p-2 flex items-center gap-2",onMouseDown:o=>o.preventDefault(),children:[m.jsx("input",{type:"url",value:e,onChange:o=>n(o.target.value),placeholder:"Enter URL",className:"bg-background p-1 rounded border border-input text-sm",onKeyDown:o=>o.key==="Enter"&&r()}),m.jsx(ce.Button,{type:"button",size:"sm",onClick:r,children:"Set Link"})]})},_2=({editor:t})=>m.jsx("div",{className:"w-[380px]",children:m.jsx(yw,{editor:t,className:"p-4",initialMode:t.isActive("highlight")?"highlight":"text"})}),Wh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),[o,i]=C.useState(!1),[l,a]=C.useState(!1),{x:c,y:u,refs:d,strategy:h,update:f}=fi({placement:"top",middleware:[hi(6),tc(),ec()],whileElementsMounted:Bs}),p=C.useCallback(()=>{if(!t||!t.isEditable)return!1;const{state:y}=t,{from:b,to:x}=y.selection,E=b!==x,S=y.selection instanceof K,M=t.isActive("codeBlock"),w=y.selection.empty&&(t.isActive("alert-widget")||t.isActive("cta-widget")),T=t.isActive("image");return E&&!S&&!M&&!w&&!T},[t]),g=C.useCallback(()=>{if(!(!t||!p()))try{const{from:y,to:b}=t.state.selection,x=t.view.coordsAtPos(y),E=t.view.coordsAtPos(b),S={getBoundingClientRect:()=>({x:x.left,y:x.top,top:x.top,left:x.left,bottom:E.bottom,right:E.right,width:E.right-x.left,height:E.bottom-x.top})};d.setReference(S),f(),requestAnimationFrame(()=>s(!0))}catch(y){console.warn("BubbleMenu positioning error:",y)}},[t,d,f,p]);return C.useEffect(()=>{if(!t)return;let y=0;const b=()=>{cancelAnimationFrame(y),y=requestAnimationFrame(()=>{p()?(n(!0),g()):!o&&!l&&n(!1)})},x=({event:E})=>{o||l||d.floating.current&&E.relatedTarget&&d.floating.current.contains(E.relatedTarget)||n(!1)};return b(),t.on("selectionUpdate",b),t.on("transaction",b),t.on("focus",b),t.on("blur",x),()=>{cancelAnimationFrame(y),t.off("selectionUpdate",b),t.off("transaction",b),t.off("focus",b),t.off("blur",x)}},[t,p,g,o,l,d.floating]),!t||!e?null:m.jsxs("div",{ref:d.setFloating,style:{position:h,top:u??0,left:c??0,zIndex:1e4,visibility:r?"visible":"hidden"},className:"flex gap-1 items-center bg-background border rounded-lg p-1 shadow-lg",onMouseDown:y=>y.preventDefault(),children:[m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleBold().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("bold")?"bg-accent":""}`,"aria-label":"Bold",title:"Bold",children:m.jsx(ga,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleItalic().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("italic")?"bg-accent":""}`,"aria-label":"Italic",title:"Italic",children:m.jsx(Bh,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleUnderline().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("underline")?"bg-accent":""}`,"aria-label":"Underline",title:"Underline",children:m.jsx($h,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleStrike().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("strike")?"bg-accent":""}`,"aria-label":"Strikethrough",title:"Strikethrough",children:m.jsx(ew,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleCode().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("code")?"bg-accent":""}`,"aria-label":"Inline code",title:"Inline code",children:m.jsx(Fs,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleSubscript().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("subscript")?"bg-accent":""}`,"aria-label":"Subscript",title:"Subscript",children:m.jsx(tw,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleSuperscript().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("superscript")?"bg-accent":""}`,"aria-label":"Superscript",title:"Superscript",children:m.jsx(nw,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("left").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"left"})?"bg-accent":""}`,"aria-label":"Align left",title:"Align left",children:m.jsx(Ds,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("center").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"center"})?"bg-accent":""}`,"aria-label":"Align center",title:"Align center",children:m.jsx(ii,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("right").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"right"})?"bg-accent":""}`,"aria-label":"Align right",title:"Align right",children:m.jsx(li,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("justify").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"justify"})?"bg-accent":""}`,"aria-label":"Justify",title:"Justify",children:m.jsx(Ph,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsxs(vt.Popover,{open:l,onOpenChange:a,children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",className:"p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center","aria-label":"Font size",title:"Font size",onMouseDown:y=>y.preventDefault(),children:m.jsx(ss,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:y=>y.preventDefault(),onMouseDown:y=>y.stopPropagation(),className:"w-[360px] p-0",side:"top",align:"start",children:m.jsx(bw,{editor:t,className:"p-4"})})]}),m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("link")?"bg-accent":""}`,"aria-label":"Link",title:"Link",onMouseDown:y=>y.preventDefault(),children:m.jsx(Ja,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{className:"w-auto p-0",side:"top",align:"start",children:m.jsx(R2,{editor:t})})]}),m.jsxs(vt.Popover,{open:o,onOpenChange:i,children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",onMouseDown:y=>y.preventDefault(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("textStyle")||t.isActive("highlight")?"bg-accent":""}`,"aria-label":"Color / highlight",title:"Color / highlight",children:m.jsx(Hh,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:y=>y.preventDefault(),onMouseDown:y=>y.stopPropagation(),className:"w-auto p-0",side:"top",align:"start",children:m.jsx(_2,{editor:t})})]}),m.jsx("div",{className:"w-px bg-border h-5"})]})};function sg(t,e){t.storage.mediaPicker={open:e}}function rc(t){var e,n;return(n=(e=t.storage)==null?void 0:e.mediaPicker)==null?void 0:n.open}const O2=[{title:"Heading 1",icon:m.jsx(Ls,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:1}).run()},{title:"Heading 2",icon:m.jsx(ai,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:2}).run()},{title:"Bullet List",icon:m.jsx(Us,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBulletList().run()},{title:"Ordered List",icon:m.jsx(ci,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleOrderedList().run()},{title:"Blockquote",icon:m.jsx(di,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBlockquote().run()},{title:"Code Block",icon:m.jsx(Fs,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleCodeBlock().run()},{title:"Image",icon:m.jsx(es,{className:"h-4 w-4"}),command:async t=>{const e=rc(t);if(e){const r=await e();r!=null&&r.src&&t.chain().focus().setImage({src:r.src,alt:r.alt||void 0}).updateAttributes("image",{blurDataURL:r.blurDataURL||void 0}).run();return}const n=window.prompt("URL");n&&t.chain().focus().setImage({src:n}).run()}},{title:"Table",icon:m.jsx(ui,{className:"h-4 w-4"}),command:t=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{title:"Horizontal Rule",icon:m.jsx(Xa,{className:"h-4 w-4"}),command:t=>t.chain().focus().setHorizontalRule().run()},{title:"Link",icon:m.jsx(Ja,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter URL:");e&&t.chain().focus().setLink({href:e}).run()}},{title:"CSS Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter CSS (without <style> tags):","/* your styles */");if(e!=null){const n=`<style>${e}</style>`;t.commands.insertContentAt({from:0,to:0},n)}}},{title:"Script Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter JavaScript (without <script> tags):","// your script");if(e!=null){const n=`<script>${e}<\/script>`,r=t.state.doc.content.size;t.commands.insertContentAt(r,n)}}},{title:"DIV Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Optional class for DIV:",""),n=window.prompt("Optional inline style for DIV:",""),r=window.prompt("Optional content for DIV:","New block"),s=`${e?` class="${e}"`:""}${n?` style="${n}"`:""}`,i=r?`<p>${(l=>l.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'"))(r)}</p>`:"<p><br /></p>";t.chain().focus().insertContent(`<div${s}>${i}</div>`).run()}},{title:"Alert Widget",icon:m.jsx(Qa,{className:"h-4 w-4"}),command:t=>{t.chain().focus().setAlertWidget().run()}},{title:"CTA Widget",icon:m.jsx(Ya,{className:"h-4 w-4"}),command:t=>{t.chain().focus().setCtaWidget({text:"Learn more",url:"",style:"primary",size:"medium",textAlign:"center"}).run()}}],qh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(null),[o,i]=C.useState(null),l=C.useRef(null),a=C.useRef(null),c=C.useRef(!1),u=C.useCallback(()=>{l.current&&l.current.setAttribute("aria-expanded","false"),a.current&&a.current.removeAttribute("data-menu-open"),l.current=null,a.current=null,s(null),n(!1)},[]),{x:d,y:h,refs:f,strategy:p}=fi({placement:"right-start",open:e,middleware:[hi(8),tc(),ec()],whileElementsMounted:Bs});C.useEffect(()=>{c.current=e},[e]),C.useEffect(()=>{r?f.setReference(r):f.setReference(null)},[r,f]);const g=C.useCallback(()=>!(!t||!t.isEditable||t.isActive("image")),[t]);C.useEffect(()=>{if(!t)return;const b=t.view.dom.parentElement;if(!b)return;const x=E=>{var T;const S=E,{handle:M,button:w}=S.detail;try{const k=t.state.selection,N=k==null?void 0:k.$from;if(N){let R=N.depth;for(;R>0&&!((T=N.node(R))!=null&&T.isBlock);)R-=1;const B=typeof N.after=="function"?N.after(R):void 0;typeof B=="number"?i(B):typeof N.pos=="number"?i(N.pos):i(null)}else i(null)}catch{i(null)}if(l.current===w&&c.current){u();return}l.current&&l.current!==w&&l.current.setAttribute("aria-expanded","false"),a.current&&a.current!==M&&a.current.removeAttribute("data-menu-open"),l.current=w,a.current=M,w.setAttribute("aria-expanded","true"),M.setAttribute("data-menu-open","true"),s(w),n(!0)};return b.addEventListener("tiptap-gutter-toggle",x),()=>{b.removeEventListener("tiptap-gutter-toggle",x)}},[t,g,u]),C.useEffect(()=>{if(!t)return;const b=()=>{g()||u()};return t.on("selectionUpdate",b),t.on("transaction",b),t.on("blur",u),()=>{t.off("selectionUpdate",b),t.off("transaction",b),t.off("blur",u)}},[t,g,u]),C.useEffect(()=>{if(!e)return;const b=E=>{const S=E.target,M=f.floating.current;if(M&&!M.contains(S)){const w=l.current;(!w||!w.contains(S))&&u()}},x=E=>{E.key==="Escape"&&u()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",x)}},[e,u,f]);const y=b=>{o!=null?t.chain().focus().insertContentAt(o,{type:"paragraph"}).setTextSelection(o+1).run():t.chain().focus().run(),b(t),u()};return!r||!e?null:m.jsx("div",{ref:f.setFloating,style:{position:p,top:h??0,left:d??0,zIndex:10001},className:"w-48 rounded-md bg-white p-1 shadow-lg max-h-[400px] overflow-auto",onMouseDown:b=>b.preventDefault(),children:m.jsx("div",{className:"flex flex-col",children:O2.map(b=>m.jsxs(ce.Button,{type:"button",variant:"ghost",className:"justify-start",onClick:()=>y(b.command),children:[b.icon,m.jsx("span",{className:"ml-2",children:b.title})]},b.title))})})},D2=[{title:"Text",description:"Start writing with plain text",icon:m.jsx(ss,{className:"h-4 w-4"}),command:t=>t.chain().focus().clearNodes().run(),category:"basic",keywords:["text","paragraph","plain"]},{title:"Heading 1",description:"Large section heading",icon:m.jsx(Ls,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:1}).run(),category:"headings",keywords:["heading","h1","title","large"]},{title:"Heading 2",description:"Medium section heading",icon:m.jsx(ai,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:2}).run(),category:"headings",keywords:["heading","h2","subtitle","medium"]},{title:"Heading 3",description:"Small section heading",icon:m.jsx(Ga,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:3}).run(),category:"headings",keywords:["heading","h3","small"]},{title:"Bullet List",description:"Create a simple bulleted list",icon:m.jsx(Us,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBulletList().run(),category:"lists",keywords:["bullet","list","unordered","ul"]},{title:"Numbered List",description:"Create a list with numbering",icon:m.jsx(ci,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleOrderedList().run(),category:"lists",keywords:["numbered","list","ordered","ol"]},{title:"Task List",description:"Create a list with checkboxes",icon:m.jsx(Za,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleTaskList().run(),category:"lists",keywords:["task","todo","checkbox","checklist"]},{title:"Image",description:"Insert an image",icon:m.jsx(es,{className:"h-4 w-4"}),command:async t=>{const e=rc(t);if(e){const r=await e();r!=null&&r.src&&t.chain().focus().setImage({src:r.src,alt:r.alt||void 0}).updateAttributes("image",{blurDataURL:r.blurDataURL||void 0}).run();return}const n=window.prompt("Enter image URL:");n&&t.chain().focus().setImage({src:n}).run()},category:"media",keywords:["image","picture","photo","img"]},{title:"Video",description:"Embed a video from URL",icon:m.jsx(sw,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter video URL (YouTube, Vimeo, etc.):");e&&t.chain().focus().insertContent(`<p><a href="${e}" target="_blank">Video: ${e}</a></p>`).run()},category:"media",keywords:["video","youtube","vimeo","embed"]},{title:"Blockquote",description:"Create a quote or citation",icon:m.jsx(di,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBlockquote().run(),category:"advanced",keywords:["quote","blockquote","citation"]},{title:"Code Block",description:"Create a code block with syntax highlighting",icon:m.jsx(Fs,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleCodeBlock().run(),category:"advanced",keywords:["code","programming","syntax","block"]},{title:"Table",description:"Insert a table with rows and columns",icon:m.jsx(ui,{className:"h-4 w-4"}),command:t=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),category:"advanced",keywords:["table","grid","rows","columns"]},{title:"Horizontal Rule",description:"Insert a horizontal divider",icon:m.jsx(Xa,{className:"h-4 w-4"}),command:t=>t.chain().focus().setHorizontalRule().run(),category:"advanced",keywords:["divider","separator","line","hr"]},{title:"Alert",description:"Insert an alert or notice",icon:m.jsx(Qa,{className:"h-4 w-4"}),command:t=>{t.can().setAlertWidget()?t.chain().focus().setAlertWidget().run():t.chain().focus().toggleBlockquote().run()},category:"advanced",keywords:["alert","notice","warning","info"]},{title:"Call to Action",description:"Insert a call to action button",icon:m.jsx(Ya,{className:"h-4 w-4"}),command:t=>{t.can().setCtaWidget()?t.chain().focus().setCtaWidget({text:"Click me",url:"#",style:"primary",size:"medium",textAlign:"center"}).run():t.chain().focus().insertContent("Call to Action").run()},category:"advanced",keywords:["cta","button","action","link"]}],og={basic:m.jsx(ss,{className:"h-3 w-3"}),headings:m.jsx(RL,{className:"h-3 w-3"}),lists:m.jsx(Us,{className:"h-3 w-3"}),media:m.jsx(es,{className:"h-3 w-3"}),advanced:m.jsx(gI,{className:"h-3 w-3"})},ig={basic:"Basic",headings:"Headings",lists:"Lists",media:"Media",advanced:"Advanced"},xw=({editor:t,wrapperRef:e})=>{const[n,r]=C.useState(!1),[s,o]=C.useState(!1),[i,l]=C.useState(!1),[a,c]=C.useState(""),[u,d]=C.useState("all"),[h,f]=C.useState({top:-9999,left:-9999,width:0}),{x:p,y:g,refs:y,strategy:b,update:x}=fi({placement:"bottom-start",open:n,onOpenChange:r,middleware:[hi(10),tc({fallbackPlacements:["top-start","bottom-start","right-start"]}),ec({padding:8}),UI({apply({availableWidth:k,availableHeight:N,elements:R}){Object.assign(R.floating.style,{maxWidth:`${Math.min(400,k-16)}px`,maxHeight:`${Math.min(500,N-16)}px`})}})],whileElementsMounted:Bs}),E=C.useCallback(()=>{const{$from:k}=t.state.selection,N=k.parent;if(N.type.name==="paragraph"&&N.content.size===0||N.type.name==="heading"&&N.content.size===0)return!0;if(N.type.name==="listItem"&&N.content.size===1){const R=N.firstChild;if(R&&R.type.name==="paragraph"&&R.content.size===0)return!0}return t.isEditable},[t]),S=C.useCallback(()=>{if(!(e!=null&&e.current))return;const k=e.current.getBoundingClientRect(),N=t.view.dom.getBoundingClientRect(),B=t.view.coordsAtPos(t.state.selection.from).top-k.top,P=N.left-k.left,L=N.width;f({top:B,left:P,width:L}),x(),requestAnimationFrame(()=>l(!0))},[t,x,e]);C.useEffect(()=>{if(!t)return;let k=0;const N=()=>{cancelAnimationFrame(k),k=requestAnimationFrame(()=>{E()?(o(!0),l(!1),S()):(o(!1),r(!1),l(!1))})},R=()=>{o(!1),r(!1),l(!1)};return N(),t.on("selectionUpdate",N),t.on("transaction",N),t.on("focus",N),t.on("blur",R),()=>{cancelAnimationFrame(k),t.off("selectionUpdate",N),t.off("transaction",N),t.off("focus",N),t.off("blur",R)}},[t,E,S]);const M=k=>{k(t),r(!1),c(""),d("all")},w=D2.filter(k=>{const N=u==="all"||k.category===u,R=a===""||k.title.toLowerCase().includes(a.toLowerCase())||k.description.toLowerCase().includes(a.toLowerCase())||k.keywords.some(B=>B.toLowerCase().includes(a.toLowerCase()));return N&&R}),T=w.reduce((k,N)=>(k[N.category]||(k[N.category]=[]),k[N.category].push(N),k),{});return s?m.jsxs(m.Fragment,{children:[m.jsx("div",{style:{position:"absolute",top:h.top,left:h.left,width:h.width,visibility:i?"visible":"hidden",zIndex:1e4},className:"group",children:m.jsxs("div",{className:"relative py-4 w-[95%] mx-auto flex items-center","aria-label":"Insert block",children:[m.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-full h-0.5 bg-gradient-to-r from-transparent via-slate-300 to-transparent dark:via-slate-600 transform origin-center scale-x-0 opacity-0 group-hover:scale-x-100 group-hover:opacity-100 transition-all duration-300"}),m.jsxs("div",{ref:y.setReference,className:"relative z-10 cursor-pointer mx-auto",onClick:()=>r(k=>!k),children:[m.jsx("div",{className:"absolute -inset-3 rounded-full bg-primary/10 dark:bg-primary/20 scale-0 opacity-0 group-hover:scale-100 group-hover:opacity-100 transition-all duration-300 ease-out animate-pulse"}),m.jsx("div",{className:"relative bg-background border border-border p-1.5 rounded-full shadow-sm group-hover:shadow-md transition-all duration-200",children:m.jsx(dL,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors duration-200"})})]})]})}),n&&m.jsxs("div",{ref:y.setFloating,style:{position:b,top:g??0,left:p??0,zIndex:10001},className:"bg-background border border-border shadow-lg rounded-lg p-2 w-96 max-h-[500px] overflow-hidden",onMouseDown:k=>k.preventDefault(),children:[m.jsx("div",{className:"p-2 border-b border-border",children:m.jsx("input",{type:"text",placeholder:"Search blocks...",value:a,onChange:k=>c(k.target.value),className:"w-full px-3 py-2 text-sm bg-muted border border-input rounded-md focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent",autoFocus:!0})}),m.jsxs("div",{className:"flex gap-1 p-2 border-b border-border overflow-x-auto",children:[m.jsx(ce.Button,{variant:u==="all"?"default":"ghost",size:"sm",onClick:()=>d("all"),className:"text-xs whitespace-nowrap",children:"All"}),Object.entries(ig).map(([k,N])=>m.jsxs(ce.Button,{variant:u===k?"default":"ghost",size:"sm",onClick:()=>d(k),className:"text-xs whitespace-nowrap flex items-center gap-1",children:[og[k],N]},k))]}),m.jsxs("div",{className:"max-h-80 overflow-y-auto",children:[u==="all"?Object.entries(T).map(([k,N])=>m.jsxs("div",{className:"py-2",children:[m.jsxs("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2",children:[og[k],ig[k]]}),N.map(R=>m.jsx(ce.Button,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left",onClick:()=>M(R.command),children:m.jsxs("div",{className:"flex items-center gap-3 w-full",children:[m.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md border bg-muted",children:R.icon}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"font-medium text-sm",children:R.title}),m.jsx("p",{className:"text-xs text-muted-foreground truncate",children:R.description})]})]})},R.title))]},k)):w.map(k=>m.jsx(ce.Button,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left",onClick:()=>M(k.command),children:m.jsxs("div",{className:"flex items-center gap-3 w-full",children:[m.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md border bg-muted",children:k.icon}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"font-medium text-sm",children:k.title}),m.jsx("p",{className:"text-xs text-muted-foreground truncate",children:k.description})]})]})},k.title)),w.length===0&&m.jsxs("div",{className:"p-4 text-center text-sm text-muted-foreground",children:['No blocks found for "',a,'"']})]})]})]}):null},L2=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),lg=new Set(["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","noscript","ol","p","pre","section","table","tfoot","ul","video","thead","tbody","tr","th","td","colgroup"]);function ww(t){const e=t.match(/^<\/?\s*([a-zA-Z0-9:-]+)/);return e?e[1].toLowerCase():null}function I2(t){return/^<\s*[^/!][^>]*>$/.test(t)}function ag(t){return/^<\s*\//.test(t)}function j2(t){if(/\/\s*>$/.test(t))return!0;const e=ww(t);return e?L2.has(e):!1}function P2(t){return/^<\s*!/.test(t)}function lu(t,e=2){if(!t)return"";const n=t.replace(/\r\n?/g,`
|
|
465
|
-
`).split(/(<[^>]+>)/g).filter(Boolean),r=" ".repeat(e);let s=0
|
|
464
|
+
Hold for drag`,t.appendChild(e),t.appendChild(n);const r=()=>t.classList.add("tiptap-drag-handle--hint"),s=()=>t.classList.remove("tiptap-drag-handle--hint");return n.addEventListener("mouseenter",r),n.addEventListener("mouseleave",s),t.addEventListener("mouseleave",s),e.addEventListener("mousedown",o=>{o.preventDefault(),o.stopPropagation()}),e.addEventListener("dragstart",o=>{o.preventDefault(),o.stopPropagation()}),e.addEventListener("keydown",o=>{(o.key==="Enter"||o.key===" ")&&(o.preventDefault(),e.click())}),e.addEventListener("click",o=>{o.preventDefault(),o.stopPropagation(),t.classList.remove("tiptap-drag-handle--hint");const i=new CustomEvent("tiptap-gutter-toggle",{bubbles:!0,detail:{handle:t,button:e}});t.dispatchEvent(i)}),t},onNodeChange:({editor:t,node:e})=>{if(!pn)return;const n=(e==null?void 0:e.type.name)==="doc";!!e&&!n&&t.isFocused&&t.isEditable?(pn.dataset.active="true",pn.style.visibility="",pn.style.pointerEvents="auto"):(pn.dataset.active="false",pn.classList.remove("tiptap-drag-handle--hint"),pn.removeAttribute("data-menu-open"),pn.style.visibility="hidden",pn.style.pointerEvents="none",Zi==null||Zi.setAttribute("aria-expanded","false"))}})];var LI=typeof document<"u",II=function(){},hd=LI?C.useLayoutEffect:II;const jI={...ne},PI=jI.useInsertionEffect,BI=PI||(t=>t());function HI(t){const e=ne.useRef(()=>{if(process.env.NODE_ENV!=="production")throw new Error("Cannot call an event handler while rendering.")});return BI(()=>{e.current=t}),ne.useCallback(function(){for(var n=arguments.length,r=new Array(n),s=0;s<n;s++)r[s]=arguments[s];return e.current==null?void 0:e.current(...r)},[])}var $I=typeof document<"u",zI=function(){},fl=$I?C.useLayoutEffect:zI;function ya(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!ya(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!ya(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function aw(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function Km(t,e){const n=aw(t);return Math.round(e*n)/n}function iu(t){const e=ne.useRef(t);return fl(()=>{e.current=t}),e}function FI(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:l=!0,whileElementsMounted:a,open:c}=t,[u,d]=ne.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[h,f]=ne.useState(r);ya(h,r)||f(r);const[p,g]=ne.useState(null),[y,b]=ne.useState(null),x=ne.useCallback(F=>{F!==w.current&&(w.current=F,g(F))},[]),E=ne.useCallback(F=>{F!==T.current&&(T.current=F,b(F))},[]),S=o||p,M=i||y,w=ne.useRef(null),T=ne.useRef(null),k=ne.useRef(u),N=a!=null,R=iu(a),B=iu(s),P=iu(c),L=ne.useCallback(()=>{if(!w.current||!T.current)return;const F={placement:e,strategy:n,middleware:h};B.current&&(F.platform=B.current),bh(w.current,T.current,F).then(le=>{const Se={...le,isPositioned:P.current!==!1};H.current&&!ya(k.current,Se)&&(k.current=Se,Xw.flushSync(()=>{d(Se)}))})},[h,e,n,B,P]);fl(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(F=>({...F,isPositioned:!1})))},[c]);const H=ne.useRef(!1);fl(()=>(H.current=!0,()=>{H.current=!1}),[]),fl(()=>{if(S&&(w.current=S),M&&(T.current=M),S&&M){if(R.current)return R.current(S,M,L);L()}},[S,M,L,R,N]);const se=ne.useMemo(()=>({reference:w,floating:T,setReference:x,setFloating:E}),[x,E]),oe=ne.useMemo(()=>({reference:S,floating:M}),[S,M]),we=ne.useMemo(()=>{const F={position:n,left:0,top:0};if(!oe.floating)return F;const le=Km(oe.floating,u.x),Se=Km(oe.floating,u.y);return l?{...F,transform:"translate("+le+"px, "+Se+"px)",...aw(oe.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:le,top:Se}},[n,l,oe.floating,u.x,u.y]);return ne.useMemo(()=>({...u,update:L,refs:se,elements:oe,floatingStyles:we}),[u,L,se,oe,we])}const hi=(t,e)=>({...R0(t),options:[t,e]}),ec=(t,e)=>({..._0(t),options:[t,e]}),tc=(t,e)=>({...O0(t),options:[t,e]}),UI=(t,e)=>({...D0(t),options:[t,e]}),VI={...ne};let Gm=!1,WI=0;const Jm=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+WI++;function qI(){const[t,e]=ne.useState(()=>Gm?Jm():void 0);return hd(()=>{t==null&&e(Jm())},[]),ne.useEffect(()=>{Gm=!0},[]),t}const KI=VI.useId,GI=KI||qI;let fd;process.env.NODE_ENV!=="production"&&(fd=new Set);function JI(){for(var t,e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];const s="Floating UI: "+n.join(" ");if(!((t=fd)!=null&&t.has(s))){var o;(o=fd)==null||o.add(s),console.error(s)}}function YI(){const t=new Map;return{emit(e,n){var r;(r=t.get(e))==null||r.forEach(s=>s(n))},on(e,n){t.has(e)||t.set(e,new Set),t.get(e).add(n)},off(e,n){var r;(r=t.get(e))==null||r.delete(n)}}}const XI=ne.createContext(null),ZI=ne.createContext(null),QI=()=>{var t;return((t=ne.useContext(XI))==null?void 0:t.id)||null},e2=()=>ne.useContext(ZI);function t2(t){const{open:e=!1,onOpenChange:n,elements:r}=t,s=GI(),o=ne.useRef({}),[i]=ne.useState(()=>YI()),l=QI()!=null;if(process.env.NODE_ENV!=="production"){const f=r.reference;f&&!gt(f)&&JI("Cannot pass a virtual element to the `elements.reference` option,","as it must be a real DOM element. Use `refs.setPositionReference()`","instead.")}const[a,c]=ne.useState(r.reference),u=HI((f,p,g)=>{o.current.openEvent=f?p:void 0,i.emit("openchange",{open:f,event:p,reason:g,nested:l}),n==null||n(f,p,g)}),d=ne.useMemo(()=>({setPositionReference:c}),[]),h=ne.useMemo(()=>({reference:a||r.reference||null,floating:r.floating||null,domReference:r.reference}),[a,r.reference,r.floating]);return ne.useMemo(()=>({dataRef:o,open:e,onOpenChange:u,elements:h,events:i,floatingId:s,refs:d}),[e,u,h,i,s,d])}function fi(t){t===void 0&&(t={});const{nodeId:e}=t,n=t2({...t,elements:{reference:null,floating:null,...t.elements}}),r=t.rootContext||n,s=r.elements,[o,i]=ne.useState(null),[l,a]=ne.useState(null),u=(s==null?void 0:s.domReference)||o,d=ne.useRef(null),h=e2();hd(()=>{u&&(d.current=u)},[u]);const f=FI({...t,elements:{...s,...l&&{reference:l}}}),p=ne.useCallback(E=>{const S=gt(E)?{getBoundingClientRect:()=>E.getBoundingClientRect(),getClientRects:()=>E.getClientRects(),contextElement:E}:E;a(S),f.refs.setReference(S)},[f.refs]),g=ne.useCallback(E=>{(gt(E)||E===null)&&(d.current=E,i(E)),(gt(f.refs.reference.current)||f.refs.reference.current===null||E!==null&&!gt(E))&&f.refs.setReference(E)},[f.refs]),y=ne.useMemo(()=>({...f.refs,setReference:g,setPositionReference:p,domReference:d}),[f.refs,g,p]),b=ne.useMemo(()=>({...f.elements,domReference:u}),[f.elements,u]),x=ne.useMemo(()=>({...f,...r,refs:y,elements:b,nodeId:e}),[f,y,b,e,r]);return hd(()=>{r.dataRef.current.floatingContext=x;const E=h==null?void 0:h.nodesRef.current.find(S=>S.id===e);E&&(E.context=x)}),ne.useMemo(()=>({...f,context:x,refs:y,elements:b}),[f,y,b,x])}const n2="_pickerRoot_1wq30_1",r2="_picker_1wq30_1",Ym={pickerRoot:n2,picker:r2};function nc(){return(nc=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function cw(t,e){if(t==null)return{};var n,r,s={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(s[n]=t[n]);return s}function pd(t){var e=C.useRef(t),n=C.useRef(function(r){e.current&&e.current(r)});return e.current=t,n.current}var qo=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=1),t>n?n:t<e?e:t},bo=function(t){return"touches"in t},md=function(t){return t&&t.ownerDocument.defaultView||self},Xm=function(t,e,n){var r=t.getBoundingClientRect(),s=bo(e)?(function(o,i){for(var l=0;l<o.length;l++)if(o[l].identifier===i)return o[l];return o[0]})(e.touches,n):e;return{left:qo((s.pageX-(r.left+md(t).pageXOffset))/r.width),top:qo((s.pageY-(r.top+md(t).pageYOffset))/r.height)}},Zm=function(t){!bo(t)&&t.preventDefault()},uw=C.memo(function(t){var e=t.onMove,n=t.onKey,r=cw(t,["onMove","onKey"]),s=C.useRef(null),o=pd(e),i=pd(n),l=C.useRef(null),a=C.useRef(!1),c=C.useMemo(function(){var f=function(y){Zm(y),(bo(y)?y.touches.length>0:y.buttons>0)&&s.current?o(Xm(s.current,y,l.current)):g(!1)},p=function(){return g(!1)};function g(y){var b=a.current,x=md(s.current),E=y?x.addEventListener:x.removeEventListener;E(b?"touchmove":"mousemove",f),E(b?"touchend":"mouseup",p)}return[function(y){var b=y.nativeEvent,x=s.current;if(x&&(Zm(b),!(function(S,M){return M&&!bo(S)})(b,a.current)&&x)){if(bo(b)){a.current=!0;var E=b.changedTouches||[];E.length&&(l.current=E[0].identifier)}x.focus(),o(Xm(x,b,l.current)),g(!0)}},function(y){var b=y.which||y.keyCode;b<37||b>40||(y.preventDefault(),i({left:b===39?.05:b===37?-.05:0,top:b===40?.05:b===38?-.05:0}))},g]},[i,o]),u=c[0],d=c[1],h=c[2];return C.useEffect(function(){return h},[h]),C.createElement("div",nc({},r,{onTouchStart:u,onMouseDown:u,className:"react-colorful__interactive",ref:s,onKeyDown:d,tabIndex:0,role:"slider"}))}),Uh=function(t){return t.filter(Boolean).join(" ")},dw=function(t){var e=t.color,n=t.left,r=t.top,s=r===void 0?.5:r,o=Uh(["react-colorful__pointer",t.className]);return C.createElement("div",{className:o,style:{top:100*s+"%",left:100*n+"%"}},C.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:e}}))},ut=function(t,e,n){return e===void 0&&(e=0),n===void 0&&(n=Math.pow(10,e)),Math.round(n*t)/n},s2=function(t){return c2(gd(t))},gd=function(t){return t[0]==="#"&&(t=t.substring(1)),t.length<6?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?ut(parseInt(t[3]+t[3],16)/255,2):1}:{r:parseInt(t.substring(0,2),16),g:parseInt(t.substring(2,4),16),b:parseInt(t.substring(4,6),16),a:t.length===8?ut(parseInt(t.substring(6,8),16)/255,2):1}},o2=function(t){return a2(l2(t))},i2=function(t){var e=t.s,n=t.v,r=t.a,s=(200-e)*n/100;return{h:ut(t.h),s:ut(s>0&&s<200?e*n/100/(s<=100?s:200-s)*100:0),l:ut(s/2),a:ut(r,2)}},yd=function(t){var e=i2(t);return"hsl("+e.h+", "+e.s+"%, "+e.l+"%)"},l2=function(t){var e=t.h,n=t.s,r=t.v,s=t.a;e=e/360*6,n/=100,r/=100;var o=Math.floor(e),i=r*(1-n),l=r*(1-(e-o)*n),a=r*(1-(1-e+o)*n),c=o%6;return{r:ut(255*[r,l,i,i,a,r][c]),g:ut(255*[a,r,r,l,i,i][c]),b:ut(255*[i,i,a,r,r,l][c]),a:ut(s,2)}},Qi=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},a2=function(t){var e=t.r,n=t.g,r=t.b,s=t.a,o=s<1?Qi(ut(255*s)):"";return"#"+Qi(e)+Qi(n)+Qi(r)+o},c2=function(t){var e=t.r,n=t.g,r=t.b,s=t.a,o=Math.max(e,n,r),i=o-Math.min(e,n,r),l=i?o===e?(n-r)/i:o===n?2+(r-e)/i:4+(e-n)/i:0;return{h:ut(60*(l<0?l+6:l)),s:ut(o?i/o*100:0),v:ut(o/255*100),a:s}},u2=C.memo(function(t){var e=t.hue,n=t.onChange,r=Uh(["react-colorful__hue",t.className]);return C.createElement("div",{className:r},C.createElement(uw,{onMove:function(s){n({h:360*s.left})},onKey:function(s){n({h:qo(e+360*s.left,0,360)})},"aria-label":"Hue","aria-valuenow":ut(e),"aria-valuemax":"360","aria-valuemin":"0"},C.createElement(dw,{className:"react-colorful__hue-pointer",left:e/360,color:yd({h:e,s:100,v:100,a:1})})))}),d2=C.memo(function(t){var e=t.hsva,n=t.onChange,r={backgroundColor:yd({h:e.h,s:100,v:100,a:1})};return C.createElement("div",{className:"react-colorful__saturation",style:r},C.createElement(uw,{onMove:function(s){n({s:100*s.left,v:100-100*s.top})},onKey:function(s){n({s:qo(e.s+100*s.left,0,100),v:qo(e.v-100*s.top,0,100)})},"aria-label":"Color","aria-valuetext":"Saturation "+ut(e.s)+"%, Brightness "+ut(e.v)+"%"},C.createElement(dw,{className:"react-colorful__saturation-pointer",top:1-e.v/100,left:e.s/100,color:yd(e)})))}),hw=function(t,e){if(t===e)return!0;for(var n in t)if(t[n]!==e[n])return!1;return!0},h2=function(t,e){return t.toLowerCase()===e.toLowerCase()||hw(gd(t),gd(e))};function f2(t,e,n){var r=pd(n),s=C.useState(function(){return t.toHsva(e)}),o=s[0],i=s[1],l=C.useRef({color:e,hsva:o});C.useEffect(function(){if(!t.equal(e,l.current.color)){var c=t.toHsva(e);l.current={hsva:c,color:e},i(c)}},[e,t]),C.useEffect(function(){var c;hw(o,l.current.hsva)||t.equal(c=t.fromHsva(o),l.current.color)||(l.current={hsva:o,color:c},r(c))},[o,t,r]);var a=C.useCallback(function(c){i(function(u){return Object.assign({},u,c)})},[]);return[o,a]}var p2=typeof window<"u"?C.useLayoutEffect:C.useEffect,m2=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0},Qm=new Map,g2=function(t){p2(function(){var e=t.current?t.current.ownerDocument:document;if(e!==void 0&&!Qm.has(e)){var n=e.createElement("style");n.innerHTML=`.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`,Qm.set(e,n);var r=m2();r&&n.setAttribute("nonce",r),e.head.appendChild(n)}},[])},y2=function(t){var e=t.className,n=t.colorModel,r=t.color,s=r===void 0?n.defaultColor:r,o=t.onChange,i=cw(t,["className","colorModel","color","onChange"]),l=C.useRef(null);g2(l);var a=f2(n,s,o),c=a[0],u=a[1],d=Uh(["react-colorful",e]);return C.createElement("div",nc({},i,{ref:l,className:d}),C.createElement(d2,{hsva:c,onChange:u}),C.createElement(u2,{hue:c.h,onChange:u,className:"react-colorful__last-control"}))},b2={defaultColor:"000",toHsva:s2,fromHsva:function(t){return o2({h:t.h,s:t.s,v:t.v,a:1})},equal:h2},x2=function(t){return C.createElement(y2,nc({},t,{colorModel:b2}))};const eg="#1F2937",tg="#FFF7D1",w2=["#FFF7D1","#FFEAE3","#DCFCE7","#DBEAFE"],v2=[{title:"Brand",colors:[{label:"Primary",value:"hsl(var(--primary))"},{label:"Secondary",value:"hsl(var(--secondary))"},{label:"Accent",value:"hsl(var(--accent))"},{label:"Ring",value:"hsl(var(--ring))"}]},{title:"Neutrals",colors:[{label:"Foreground",value:"hsl(var(--foreground))"},{label:"Muted",value:"hsl(var(--muted-foreground))"},{label:"Background",value:"hsl(var(--background))"},{label:"Card",value:"hsl(var(--card))"}]},{title:"States",colors:[{label:"Warning",value:"hsl(var(--warning))"},{label:"Destructive",value:"hsl(var(--destructive))"},{label:"Success",value:"hsl(var(--chart-2))"},{label:"Info",value:"hsl(var(--chart-5))"}]},{title:"Utility",colors:[{label:"Secondary FG",value:"hsl(var(--secondary-foreground))"},{label:"Accent FG",value:"hsl(var(--accent-foreground))"},{label:"Primary FG",value:"hsl(var(--primary-foreground))"},{label:"Border",value:"hsl(var(--border))"}]}],k2=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,S2=/^#[0-9a-f]{6}$/i,fw=/^rgba?\((\s*\d{1,3}\s*,){2}\s*\d{1,3}\s*(,\s*(0|1|0?\.\d+)\s*)?\)$/i,pw=/^hsla?\((\s*\d{1,3}\s*,)(\s*\d{1,3}%\s*,)\s*\d{1,3}%\s*(,\s*(0|1|0?\.\d+)\s*)?\)$/i;function ba(t){const e=t.replace("#","").trim();return e.length===3||e.length===4?`#${e.split("").map(r=>r+r).join("").toUpperCase()}`:e.length===6||e.length===8?`#${e.toUpperCase()}`:t}function mw(t){const e=ba(t).replace("#","");if(e.length!==6&&e.length!==8)return null;const n=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),s=parseInt(e.slice(4,6),16),o=e.length===8?parseInt(e.slice(6,8),16)/255:1;return{r:n,g:r,b:s,a:o}}function bd(t,e,n){return`#${[t,e,n].map(r=>Math.max(0,Math.min(255,Math.round(r))).toString(16).padStart(2,"0")).join("").toUpperCase()}`}function xo(t,e=2){const n=10**e;return Math.round(t*n)/n}function wo(t,e,n,r=1){const s=t/255,o=e/255,i=n/255,l=Math.max(s,o,i),a=Math.min(s,o,i);let c=0,u=0;const d=(l+a)/2;if(l!==a){const g=l-a;switch(u=d>.5?g/(2-l-a):g/(l+a),l){case s:c=(o-i)/g+(o<i?6:0);break;case o:c=(i-s)/g+2;break;case i:c=(s-o)/g+4;break}c/=6}const h=Math.round(c*360),f=Math.round(u*100),p=Math.round(d*100);return r!==1?`hsla(${h}, ${f}%, ${p}%, ${xo(r,2)})`:`hsl(${h}, ${f}%, ${p}%)`}function ng(t){if(typeof window>"u"||typeof document>"u")return null;const e=document.createElement("span");if(e.style.color="",e.style.color=t,!e.style.color)return null;e.style.position="absolute",e.style.visibility="hidden",e.style.pointerEvents="none",document.body.appendChild(e);const n=getComputedStyle(e).color;document.body.removeChild(e);const r=n.match(/rgba?\(([^)]+)\)/i);if(!r)return null;const[s,o,i,l]=r[1].split(",").map(a=>a.trim()).map((a,c)=>c===3?parseFloat(a):parseInt(a,10));return[s,o,i].some(a=>Number.isNaN(a))?null:{r:s,g:o,b:i,a:typeof l=="number"&&!Number.isNaN(l)?l:1}}function Ln(t){if(!t)return null;const e=t.trim();if(k2.test(e)){const r=ba(e),s=mw(r);if(!s)return null;const o=`#${r.replace("#","").slice(0,6)}`;return{source:r,hex:o,rgb:s.a===1?`rgb(${s.r}, ${s.g}, ${s.b})`:`rgba(${s.r}, ${s.g}, ${s.b}, ${xo(s.a,2)})`,hsl:wo(s.r,s.g,s.b,s.a),alpha:s.a}}if(fw.test(e)||pw.test(e)){const r=ng(e);return r?{source:e,hex:bd(r.r,r.g,r.b),rgb:r.a===1?`rgb(${r.r}, ${r.g}, ${r.b})`:`rgba(${r.r}, ${r.g}, ${r.b}, ${xo(r.a,2)})`,hsl:wo(r.r,r.g,r.b,r.a),alpha:r.a}:null}const n=ng(e);return n?{source:e,hex:bd(n.r,n.g,n.b),rgb:n.a===1?`rgb(${n.r}, ${n.g}, ${n.b})`:`rgba(${n.r}, ${n.g}, ${n.b}, ${xo(n.a,2)})`,hsl:wo(n.r,n.g,n.b,n.a),alpha:n.a}:null}function gw(t){const e=mw(t);if(e)return{source:ba(t),hex:bd(e.r,e.g,e.b),rgb:e.a===1?`rgb(${e.r}, ${e.g}, ${e.b})`:`rgba(${e.r}, ${e.g}, ${e.b}, ${xo(e.a,2)})`,hsl:wo(e.r,e.g,e.b,e.a),alpha:e.a};const n=ba(t);return{source:n,hex:n.slice(0,7),rgb:"rgb(0, 0, 0)",hsl:wo(0,0,0,1),alpha:1}}const eo=Ln(eg)??gw(eg),rg=Ln(tg)??gw(tg);function yw({editor:t,className:e,initialMode:n="text"}){const r=C.useRef(null),[s,o]=C.useState(n),[i,l]=C.useState(null),[a,c]=C.useState(eo),[u,d]=C.useState(rg);C.useEffect(()=>{o(n)},[n]);const[h,f]=C.useState(eo.hex),[p,g]=C.useState(!1),[y,b]=C.useState(eo.rgb),[x,E]=C.useState(!1),[S,M]=C.useState(eo.hsl),[w,T]=C.useState(!1),k=s==="text"?a:u;C.useEffect(()=>{const L=()=>{if(i)return;const H=t.getAttributes("textStyle").color,se=t.getAttributes("highlight").color,oe=Ln(H)??eo,we=Ln(se)??rg;c(oe),d(we)};return L(),t.on("selectionUpdate",L),t.on("transaction",L),()=>{t.off("selectionUpdate",L),t.off("transaction",L)}},[t,i,s]),C.useEffect(()=>{i!=="hex"&&f(k.hex),i!=="rgb"&&b(k.rgb),i!=="hsl"&&M(k.hsl),i===null&&(g(!1),E(!1),T(!1))},[k,i]);const N=C.useCallback((L,H,se=!0)=>{const oe=t.chain();se&&oe.focus(),L==="text"?(c(H),oe.setColor(H.source).run()):(d(H),oe.setHighlight({color:H.source}).run())},[t,c,d]),R=C.useCallback((L,H)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{N(L,H,!1)},300)},[N]),B=C.useCallback(L=>{r.current&&clearTimeout(r.current);const H=Ln(L);H&&(N(s,H,!1),g(!1))},[N,s,g]),P=C.useCallback(L=>{r.current&&clearTimeout(r.current);const H=Ln(L);H&&(N(s,H),g(!1))},[N,s,g]);return m.jsxs("div",{className:$e.cn("flex w-full sm:w-auto flex-col gap-3 sm:gap-4",e),children:[m.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.jsxs("div",{className:"inline-flex items-center gap-1 rounded-md bg-muted/60 p-1",children:[m.jsx(ce.Button,{type:"button",variant:s==="text"?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>o("text"),children:"Text"}),m.jsx(ce.Button,{type:"button",variant:s==="highlight"?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>o("highlight"),children:"Highlight"})]}),m.jsx("div",{className:"flex items-center",children:m.jsx(ce.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>{s==="text"?t.chain().focus().unsetColor().run():t.chain().focus().unsetHighlight().run()},children:"Remove Color"})})]}),m.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:gap-4",children:[m.jsx("div",{className:Ym.pickerRoot,children:m.jsx(x2,{color:k.hex,onChange:B,className:Ym.picker})}),m.jsxs("div",{className:"flex w-full flex-col gap-2 text-[11px] sm:w-[150px]",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"HEX"}),m.jsx(ps.Input,{value:h,onFocus:()=>l("hex"),onChange:L=>{const H=L.target.value;if(f(H),S2.test(H)){const se=Ln(H);se&&(R(s,se),g(!1))}else g(!0)},onBlur:()=>{l(null),p&&(f(k.hex),g(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",p&&"border-destructive focus-visible:ring-destructive")})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"RGB"}),m.jsx(ps.Input,{value:y,onFocus:()=>l("rgb"),onChange:L=>{const H=L.target.value;if(b(H),fw.test(H)){const se=Ln(H);se&&(R(s,se),E(!1))}else E(!0)},onBlur:()=>{l(null),x&&(b(k.rgb),E(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",x&&"border-destructive focus-visible:ring-destructive")})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"HSL"}),m.jsx(ps.Input,{value:S,onFocus:()=>l("hsl"),onChange:L=>{const H=L.target.value;if(M(H),pw.test(H)){const se=Ln(H);se&&(R(s,se),T(!1))}else T(!0)},onBlur:()=>{l(null),w&&(M(k.hsl),T(!1))},spellCheck:!1,className:$e.cn("h-8 w-full text-xs",w&&"border-destructive focus-visible:ring-destructive")})]})]})]}),m.jsxs("div",{className:"space-y-1.5",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Theme colors"}),m.jsx("div",{className:"space-y-1",children:v2.map(L=>m.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m.jsx("span",{className:"w-16 shrink-0 text-[11px] font-medium text-muted-foreground/80",children:L.title}),m.jsx("div",{className:"flex items-center gap-1.5",children:L.colors.map(H=>m.jsx("button",{type:"button",onClick:()=>P(H.value),className:"h-6 w-6 rounded border border-border bg-background shadow-sm transition hover:border-primary/40 hover:shadow-sm",style:{background:H.value},"aria-label":`${L.title} color ${H.label}`,title:`${L.title} color ${H.label}`},H.label))})]},L.title))})]}),s==="highlight"?m.jsxs("div",{className:"space-y-2",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Highlight presets"}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:w2.map(L=>m.jsxs("button",{type:"button",onClick:()=>P(L),className:"flex items-center gap-1 rounded-full border bg-background px-2 py-1 text-[11px] shadow-sm transition hover:border-primary/40 hover:shadow-sm",children:[m.jsx("span",{className:"h-3.5 w-3.5 rounded-full border",style:{background:L},"aria-hidden":!0}),L]},L))})]}):null]})}const C2=["px","pt","rem","em","%"];function pl(t){if(!t)return null;const n=String(t).trim().match(/^(-?\d*\.?\d+)(px|pt|rem|em|%)$/i);if(!n)return null;const r=parseFloat(n[1]),s=n[2].toLowerCase();return Number.isFinite(r)?{value:r,unit:s}:null}function xd(t){if(!t)return null;const{value:e,unit:n}=t;return n==="%"?`${Math.max(1,Math.round(e))}%`:n==="px"||n==="pt"?`${Math.max(1,Math.round(e))}${n}`:`${Math.max(.01,Math.round(e*100)/100)}${n}`}function E2(t){const e=pl(t);return e?xd(e):null}function M2(){if(typeof document>"u")return[];const t=[];try{const n=Array.from(document.styleSheets),r=[],s=[];for(const l of n){const a=l.href,c=l.ownerNode;`${a||""} ${(c==null?void 0:c.textContent)||""}`.toLowerCase().includes("globals.css")?r.push(l):s.push(l)}const o=[...r,...s],i=new Set(["h1","h2","h3","h4","h5","h6"]);for(const l of o){let a=null;try{a=l.cssRules}catch{continue}if(a){for(const c of Array.from(a))if(c.style){const d=c.style.fontSize,h=c.selectorText;if(d&&h&&i.has(h)){const f=E2(d)??d.trim();if(f){const p=parseInt(h.replace("h",""),10);t.push({level:p,value:f})}}}}}}catch{}const e=new Map;for(const n of t)e.has(n.level)||e.set(n.level,n.value);return Array.from(e.entries()).map(([n,r])=>({level:n,value:r}))}function A2(t){if(typeof document>"u")return 0;try{const e=document.createElement("span");e.style.position="absolute",e.style.visibility="hidden",e.style.fontSize=t,document.body.appendChild(e);const n=parseFloat(getComputedStyle(e).fontSize);return document.body.removeChild(e),Number.isFinite(n)?n:0}catch{return 0}}function xa(){if(typeof document>"u")return 16;try{const t=parseFloat(getComputedStyle(document.documentElement).fontSize);return Number.isFinite(t)&&t>0?t:16}catch{return 16}}function Vh(t){try{const e=t.state.selection.from,n=t.view.domAtPos(e),r=n&&n.node||t.view.dom,s=r.nodeType===1?r:t.view.dom,o=parseFloat(getComputedStyle(s).fontSize);return Number.isFinite(o)&&o>0?o:xa()}catch{return xa()}}function T2(t,e,n){const r=xa(),s=Vh(n);switch(e){case"px":return t;case"pt":return t*(96/72);case"rem":return t*r;case"em":return t*s;case"%":return t/100*s}}function N2(t,e,n){const r=xa(),s=Vh(n);switch(e){case"px":return t;case"pt":return t*(72/96);case"rem":return t/r;case"em":return t/s;case"%":return t/s*100}}function bw({editor:t,className:e}){const[n,r]=C.useState([]),[s,o]=C.useState(null),[i,l]=C.useState(""),[a,c]=C.useState("px"),[u,d]=C.useState(!1),h=C.useRef(null),f=C.useCallback(()=>{const S=t.getAttributes("textStyle").fontSize,M=pl(S);if(M)l(String(M.value)),c(M.unit),d(!1);else{if(S&&typeof S=="string"){const w=A2(S);if(w>0&&!s){l(String(Math.round(w))),c("px"),d(!1);return}}s||(l(""),c("px"),d(!1))}},[t,s]);C.useEffect(()=>{f();const S=()=>f();return t.on("selectionUpdate",S),t.on("transaction",S),()=>{t.off("selectionUpdate",S),t.off("transaction",S)}},[t,f]),C.useEffect(()=>{r(M2())},[]);const p=C.useCallback((S,M=!0)=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{const w=t.chain();M&&w.focus(),w.setFontSize(S).run()},120)},[t]),g=C.useCallback(S=>{l(S);const M=`${S}${a}`,w=pl(M);if(w){d(!1);const T=xd(w);T&&p(T,!1)}else d(S.trim().length>0)},[a,p]),y=C.useCallback(S=>{const M=a;c(S);let w=0;const T=parseFloat(i);Number.isFinite(T)?w=T2(T,M,t):w=Vh(t);const k=N2(w,S,t);let N;S==="px"||S==="pt"||S==="%"?N=String(Math.round(k)):N=String(Math.max(.01,Math.round(k*100)/100)),l(N);const R=xd(pl(`${N}${S}`));R&&p(R)},[a,i,t,p]),b=C.useCallback(()=>{h.current&&clearTimeout(h.current),t.chain().focus().unsetFontSize().run(),d(!1)},[t]),x=C.useMemo(()=>a==="px"||a==="pt"||a==="%"?1:.01,[a]),E=C.useMemo(()=>{switch(a){case"%":return"100";case"px":return"16";case"pt":return"12";case"rem":return"1";case"em":return"1";default:return""}},[a]);return m.jsxs("div",{className:$e.cn("space-y-3",e),onMouseDown:S=>S.stopPropagation(),children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx(ss,{className:"h-4 w-4 text-muted-foreground"}),m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Font size"})]}),m.jsxs(ce.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:b,title:"Erase font size","aria-label":"Erase font size",children:[m.jsx(kL,{className:"h-3.5 w-3.5 mr-1"}),"Erase"]})]}),m.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2 items-end",children:[m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"Value"}),m.jsx(ps.Input,{type:"number",inputMode:"decimal",step:x,placeholder:E,value:i,onFocus:()=>o("value"),onChange:S=>g(S.target.value),onBlur:()=>o(null),className:$e.cn("h-9",u&&"border-destructive focus-visible:ring-destructive"),spellCheck:!1})]}),m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"font-medium text-muted-foreground",children:"Unit"}),m.jsx("div",{className:"flex gap-1",children:m.jsx("select",{value:a,onChange:S=>y(S.target.value),onFocus:()=>o("unit"),onBlur:()=>o(null),className:"h-9 w-[84px] rounded-md border border-input bg-background px-2 text-sm shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-ring",children:C2.map(S=>m.jsx("option",{value:S,children:S},S))})})]})]}),m.jsxs("div",{className:"space-y-2",children:[n.length>0?m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Headings"}),m.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:n.map(({level:S,value:M})=>m.jsx("button",{type:"button",onClick:()=>p(M),className:"h-8 w-full rounded-md border bg-background px-2 text-xs font-medium shadow-sm transition hover:border-primary/40 hover:shadow-sm",title:`Apply H${S} (${M})`,children:`H${S} (${M})`},`h${S}`))})]}):null,m.jsxs("div",{className:"space-y-1",children:[m.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Keywords"}),m.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:["xx-small","x-small","small","medium","large","x-large"].map(S=>m.jsx("button",{type:"button",onClick:()=>p(S),className:"h-8 w-full rounded-md border bg-background px-2 text-xs font-medium shadow-sm transition hover:border-primary/40 hover:shadow-sm",title:`Apply ${S}`,children:S.replace(/\b\w/g,M=>M.toUpperCase())},S))})]})]})]})}const R2=({editor:t})=>{var s;const[e,n]=C.useState(((s=t.getAttributes("link"))==null?void 0:s.href)??"");C.useEffect(()=>{const o=()=>{var i;n(((i=t.getAttributes("link"))==null?void 0:i.href)??"")};return t.on("selectionUpdate",o),t.on("transaction",o),()=>{t.off("selectionUpdate",o),t.off("transaction",o)}},[t]);const r=()=>{const o=e.trim();o?t.chain().focus().extendMarkRange("link").setLink({href:o}).run():t.chain().focus().extendMarkRange("link").unsetLink().run()};return m.jsxs("div",{className:"p-2 flex items-center gap-2",onMouseDown:o=>o.preventDefault(),children:[m.jsx("input",{type:"url",value:e,onChange:o=>n(o.target.value),placeholder:"Enter URL",className:"bg-background p-1 rounded border border-input text-sm",onKeyDown:o=>o.key==="Enter"&&r()}),m.jsx(ce.Button,{type:"button",size:"sm",onClick:r,children:"Set Link"})]})},_2=({editor:t})=>m.jsx("div",{className:"w-[380px]",children:m.jsx(yw,{editor:t,className:"p-4",initialMode:t.isActive("highlight")?"highlight":"text"})}),Wh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),[o,i]=C.useState(!1),[l,a]=C.useState(!1),{x:c,y:u,refs:d,strategy:h,update:f}=fi({placement:"top",middleware:[hi(6),tc(),ec()],whileElementsMounted:Bs}),p=C.useCallback(()=>{if(!t||!t.isEditable)return!1;const{state:y}=t,{from:b,to:x}=y.selection,E=b!==x,S=y.selection instanceof K,M=t.isActive("codeBlock"),w=y.selection.empty&&(t.isActive("alert-widget")||t.isActive("cta-widget")),T=t.isActive("image");return E&&!S&&!M&&!w&&!T},[t]),g=C.useCallback(()=>{if(!(!t||!p()))try{const{from:y,to:b}=t.state.selection,x=t.view.coordsAtPos(y),E=t.view.coordsAtPos(b),S={getBoundingClientRect:()=>({x:x.left,y:x.top,top:x.top,left:x.left,bottom:E.bottom,right:E.right,width:E.right-x.left,height:E.bottom-x.top})};d.setReference(S),f(),requestAnimationFrame(()=>s(!0))}catch(y){console.warn("BubbleMenu positioning error:",y)}},[t,d,f,p]);return C.useEffect(()=>{if(!t)return;let y=0;const b=()=>{cancelAnimationFrame(y),y=requestAnimationFrame(()=>{p()?(n(!0),g()):!o&&!l&&n(!1)})},x=({event:E})=>{o||l||d.floating.current&&E.relatedTarget&&d.floating.current.contains(E.relatedTarget)||n(!1)};return b(),t.on("selectionUpdate",b),t.on("transaction",b),t.on("focus",b),t.on("blur",x),()=>{cancelAnimationFrame(y),t.off("selectionUpdate",b),t.off("transaction",b),t.off("focus",b),t.off("blur",x)}},[t,p,g,o,l,d.floating]),!t||!e?null:m.jsxs("div",{ref:d.setFloating,style:{position:h,top:u??0,left:c??0,zIndex:1e4,visibility:r?"visible":"hidden"},className:"flex gap-1 items-center bg-background border rounded-lg p-1 shadow-lg",onMouseDown:y=>y.preventDefault(),children:[m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleBold().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("bold")?"bg-accent":""}`,"aria-label":"Bold",title:"Bold",children:m.jsx(ga,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleItalic().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("italic")?"bg-accent":""}`,"aria-label":"Italic",title:"Italic",children:m.jsx(Bh,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleUnderline().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("underline")?"bg-accent":""}`,"aria-label":"Underline",title:"Underline",children:m.jsx($h,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleStrike().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("strike")?"bg-accent":""}`,"aria-label":"Strikethrough",title:"Strikethrough",children:m.jsx(ew,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleCode().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("code")?"bg-accent":""}`,"aria-label":"Inline code",title:"Inline code",children:m.jsx(Fs,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleSubscript().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("subscript")?"bg-accent":""}`,"aria-label":"Subscript",title:"Subscript",children:m.jsx(tw,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().toggleSuperscript().run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("superscript")?"bg-accent":""}`,"aria-label":"Superscript",title:"Superscript",children:m.jsx(nw,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("left").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"left"})?"bg-accent":""}`,"aria-label":"Align left",title:"Align left",children:m.jsx(Ds,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("center").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"center"})?"bg-accent":""}`,"aria-label":"Align center",title:"Align center",children:m.jsx(ii,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("right").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"right"})?"bg-accent":""}`,"aria-label":"Align right",title:"Align right",children:m.jsx(li,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("button",{type:"button",onClick:()=>t.chain().focus().setTextAlign("justify").run(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive({textAlign:"justify"})?"bg-accent":""}`,"aria-label":"Justify",title:"Justify",children:m.jsx(Ph,{className:"h-4 w-4 pointer-events-none"})}),m.jsx("div",{className:"w-px bg-border h-5"}),m.jsxs(vt.Popover,{open:l,onOpenChange:a,children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",className:"p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center","aria-label":"Font size",title:"Font size",onMouseDown:y=>y.preventDefault(),children:m.jsx(ss,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:y=>y.preventDefault(),onMouseDown:y=>y.stopPropagation(),className:"w-[360px] p-0",side:"top",align:"start",children:m.jsx(bw,{editor:t,className:"p-4"})})]}),m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("link")?"bg-accent":""}`,"aria-label":"Link",title:"Link",onMouseDown:y=>y.preventDefault(),children:m.jsx(Ja,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{className:"w-auto p-0",side:"top",align:"start",children:m.jsx(R2,{editor:t})})]}),m.jsxs(vt.Popover,{open:o,onOpenChange:i,children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx("button",{type:"button",onMouseDown:y=>y.preventDefault(),className:`p-1.5 rounded hover:bg-accent transition-colors duration-100 flex items-center justify-center ${t.isActive("textStyle")||t.isActive("highlight")?"bg-accent":""}`,"aria-label":"Color / highlight",title:"Color / highlight",children:m.jsx(Hh,{className:"h-4 w-4 pointer-events-none"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:y=>y.preventDefault(),onMouseDown:y=>y.stopPropagation(),className:"w-auto p-0",side:"top",align:"start",children:m.jsx(_2,{editor:t})})]}),m.jsx("div",{className:"w-px bg-border h-5"})]})};function sg(t,e){t.storage.mediaPicker={open:e}}function rc(t){var e,n;return(n=(e=t.storage)==null?void 0:e.mediaPicker)==null?void 0:n.open}const O2=[{title:"Heading 1",icon:m.jsx(Ls,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:1}).run()},{title:"Heading 2",icon:m.jsx(ai,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:2}).run()},{title:"Bullet List",icon:m.jsx(Us,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBulletList().run()},{title:"Ordered List",icon:m.jsx(ci,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleOrderedList().run()},{title:"Blockquote",icon:m.jsx(di,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBlockquote().run()},{title:"Code Block",icon:m.jsx(Fs,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleCodeBlock().run()},{title:"Image",icon:m.jsx(es,{className:"h-4 w-4"}),command:async t=>{const e=rc(t);if(e){const r=await e();r!=null&&r.src&&t.chain().focus().setImage({src:r.src,alt:r.alt||void 0}).updateAttributes("image",{blurDataURL:r.blurDataURL||void 0}).run();return}const n=window.prompt("URL");n&&t.chain().focus().setImage({src:n}).run()}},{title:"Table",icon:m.jsx(ui,{className:"h-4 w-4"}),command:t=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{title:"Horizontal Rule",icon:m.jsx(Xa,{className:"h-4 w-4"}),command:t=>t.chain().focus().setHorizontalRule().run()},{title:"Link",icon:m.jsx(Ja,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter URL:");e&&t.chain().focus().setLink({href:e}).run()}},{title:"CSS Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter CSS (without <style> tags):","/* your styles */");if(e!=null){const n=`<style>${e}</style>`;t.commands.insertContentAt({from:0,to:0},n)}}},{title:"Script Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter JavaScript (without <script> tags):","// your script");if(e!=null){const n=`<script>${e}<\/script>`,r=t.state.doc.content.size;t.commands.insertContentAt(r,n)}}},{title:"DIV Block",icon:m.jsx(Fr,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Optional class for DIV:",""),n=window.prompt("Optional inline style for DIV:",""),r=window.prompt("Optional content for DIV:","New block"),s=`${e?` class="${e}"`:""}${n?` style="${n}"`:""}`,i=r?`<p>${(l=>l.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"))(r)}</p>`:"<p><br /></p>";t.chain().focus().insertContent(`<div${s}>${i}</div>`).run()}},{title:"Alert Widget",icon:m.jsx(Qa,{className:"h-4 w-4"}),command:t=>{t.chain().focus().setAlertWidget().run()}},{title:"CTA Widget",icon:m.jsx(Ya,{className:"h-4 w-4"}),command:t=>{t.chain().focus().setCtaWidget({text:"Learn more",url:"",style:"primary",size:"medium",textAlign:"center"}).run()}}],qh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(null),[o,i]=C.useState(null),l=C.useRef(null),a=C.useRef(null),c=C.useRef(!1),u=C.useCallback(()=>{l.current&&l.current.setAttribute("aria-expanded","false"),a.current&&a.current.removeAttribute("data-menu-open"),l.current=null,a.current=null,s(null),n(!1)},[]),{x:d,y:h,refs:f,strategy:p}=fi({placement:"right-start",open:e,middleware:[hi(8),tc(),ec()],whileElementsMounted:Bs});C.useEffect(()=>{c.current=e},[e]),C.useEffect(()=>{r?f.setReference(r):f.setReference(null)},[r,f]);const g=C.useCallback(()=>!(!t||!t.isEditable||t.isActive("image")),[t]);C.useEffect(()=>{if(!t)return;const b=t.view.dom.parentElement;if(!b)return;const x=E=>{var T;const S=E,{handle:M,button:w}=S.detail;try{const k=t.state.selection,N=k==null?void 0:k.$from;if(N){let R=N.depth;for(;R>0&&!((T=N.node(R))!=null&&T.isBlock);)R-=1;const B=typeof N.after=="function"?N.after(R):void 0;typeof B=="number"?i(B):typeof N.pos=="number"?i(N.pos):i(null)}else i(null)}catch{i(null)}if(l.current===w&&c.current){u();return}l.current&&l.current!==w&&l.current.setAttribute("aria-expanded","false"),a.current&&a.current!==M&&a.current.removeAttribute("data-menu-open"),l.current=w,a.current=M,w.setAttribute("aria-expanded","true"),M.setAttribute("data-menu-open","true"),s(w),n(!0)};return b.addEventListener("tiptap-gutter-toggle",x),()=>{b.removeEventListener("tiptap-gutter-toggle",x)}},[t,g,u]),C.useEffect(()=>{if(!t)return;const b=()=>{g()||u()};return t.on("selectionUpdate",b),t.on("transaction",b),t.on("blur",u),()=>{t.off("selectionUpdate",b),t.off("transaction",b),t.off("blur",u)}},[t,g,u]),C.useEffect(()=>{if(!e)return;const b=E=>{const S=E.target,M=f.floating.current;if(M&&!M.contains(S)){const w=l.current;(!w||!w.contains(S))&&u()}},x=E=>{E.key==="Escape"&&u()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",x)}},[e,u,f]);const y=b=>{o!=null?t.chain().focus().insertContentAt(o,{type:"paragraph"}).setTextSelection(o+1).run():t.chain().focus().run(),b(t),u()};return!r||!e?null:m.jsx("div",{ref:f.setFloating,style:{position:p,top:h??0,left:d??0,zIndex:10001},className:"w-48 rounded-md bg-white p-1 shadow-lg max-h-[400px] overflow-auto",onMouseDown:b=>b.preventDefault(),children:m.jsx("div",{className:"flex flex-col",children:O2.map(b=>m.jsxs(ce.Button,{type:"button",variant:"ghost",className:"justify-start",onClick:()=>y(b.command),children:[b.icon,m.jsx("span",{className:"ml-2",children:b.title})]},b.title))})})},D2=[{title:"Text",description:"Start writing with plain text",icon:m.jsx(ss,{className:"h-4 w-4"}),command:t=>t.chain().focus().clearNodes().run(),category:"basic",keywords:["text","paragraph","plain"]},{title:"Heading 1",description:"Large section heading",icon:m.jsx(Ls,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:1}).run(),category:"headings",keywords:["heading","h1","title","large"]},{title:"Heading 2",description:"Medium section heading",icon:m.jsx(ai,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:2}).run(),category:"headings",keywords:["heading","h2","subtitle","medium"]},{title:"Heading 3",description:"Small section heading",icon:m.jsx(Ga,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleHeading({level:3}).run(),category:"headings",keywords:["heading","h3","small"]},{title:"Bullet List",description:"Create a simple bulleted list",icon:m.jsx(Us,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBulletList().run(),category:"lists",keywords:["bullet","list","unordered","ul"]},{title:"Numbered List",description:"Create a list with numbering",icon:m.jsx(ci,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleOrderedList().run(),category:"lists",keywords:["numbered","list","ordered","ol"]},{title:"Task List",description:"Create a list with checkboxes",icon:m.jsx(Za,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleTaskList().run(),category:"lists",keywords:["task","todo","checkbox","checklist"]},{title:"Image",description:"Insert an image",icon:m.jsx(es,{className:"h-4 w-4"}),command:async t=>{const e=rc(t);if(e){const r=await e();r!=null&&r.src&&t.chain().focus().setImage({src:r.src,alt:r.alt||void 0}).updateAttributes("image",{blurDataURL:r.blurDataURL||void 0}).run();return}const n=window.prompt("Enter image URL:");n&&t.chain().focus().setImage({src:n}).run()},category:"media",keywords:["image","picture","photo","img"]},{title:"Video",description:"Embed a video from URL",icon:m.jsx(sw,{className:"h-4 w-4"}),command:t=>{const e=window.prompt("Enter video URL (YouTube, Vimeo, etc.):");e&&t.chain().focus().insertContent(`<p><a href="${e}" target="_blank">Video: ${e}</a></p>`).run()},category:"media",keywords:["video","youtube","vimeo","embed"]},{title:"Blockquote",description:"Create a quote or citation",icon:m.jsx(di,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleBlockquote().run(),category:"advanced",keywords:["quote","blockquote","citation"]},{title:"Code Block",description:"Create a code block with syntax highlighting",icon:m.jsx(Fs,{className:"h-4 w-4"}),command:t=>t.chain().focus().toggleCodeBlock().run(),category:"advanced",keywords:["code","programming","syntax","block"]},{title:"Table",description:"Insert a table with rows and columns",icon:m.jsx(ui,{className:"h-4 w-4"}),command:t=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),category:"advanced",keywords:["table","grid","rows","columns"]},{title:"Horizontal Rule",description:"Insert a horizontal divider",icon:m.jsx(Xa,{className:"h-4 w-4"}),command:t=>t.chain().focus().setHorizontalRule().run(),category:"advanced",keywords:["divider","separator","line","hr"]},{title:"Alert",description:"Insert an alert or notice",icon:m.jsx(Qa,{className:"h-4 w-4"}),command:t=>{t.can().setAlertWidget()?t.chain().focus().setAlertWidget().run():t.chain().focus().toggleBlockquote().run()},category:"advanced",keywords:["alert","notice","warning","info"]},{title:"Call to Action",description:"Insert a call to action button",icon:m.jsx(Ya,{className:"h-4 w-4"}),command:t=>{t.can().setCtaWidget()?t.chain().focus().setCtaWidget({text:"Click me",url:"#",style:"primary",size:"medium",textAlign:"center"}).run():t.chain().focus().insertContent("Call to Action").run()},category:"advanced",keywords:["cta","button","action","link"]}],og={basic:m.jsx(ss,{className:"h-3 w-3"}),headings:m.jsx(RL,{className:"h-3 w-3"}),lists:m.jsx(Us,{className:"h-3 w-3"}),media:m.jsx(es,{className:"h-3 w-3"}),advanced:m.jsx(gI,{className:"h-3 w-3"})},ig={basic:"Basic",headings:"Headings",lists:"Lists",media:"Media",advanced:"Advanced"},xw=({editor:t,wrapperRef:e})=>{const[n,r]=C.useState(!1),[s,o]=C.useState(!1),[i,l]=C.useState(!1),[a,c]=C.useState(""),[u,d]=C.useState("all"),[h,f]=C.useState({top:-9999,left:-9999,width:0}),{x:p,y:g,refs:y,strategy:b,update:x}=fi({placement:"bottom-start",open:n,onOpenChange:r,middleware:[hi(10),tc({fallbackPlacements:["top-start","bottom-start","right-start"]}),ec({padding:8}),UI({apply({availableWidth:k,availableHeight:N,elements:R}){Object.assign(R.floating.style,{maxWidth:`${Math.min(400,k-16)}px`,maxHeight:`${Math.min(500,N-16)}px`})}})],whileElementsMounted:Bs}),E=C.useCallback(()=>{const{$from:k}=t.state.selection,N=k.parent;if(N.type.name==="paragraph"&&N.content.size===0||N.type.name==="heading"&&N.content.size===0)return!0;if(N.type.name==="listItem"&&N.content.size===1){const R=N.firstChild;if(R&&R.type.name==="paragraph"&&R.content.size===0)return!0}return t.isEditable},[t]),S=C.useCallback(()=>{if(!(e!=null&&e.current))return;const k=e.current.getBoundingClientRect(),N=t.view.dom.getBoundingClientRect(),B=t.view.coordsAtPos(t.state.selection.from).top-k.top,P=N.left-k.left,L=N.width;f({top:B,left:P,width:L}),x(),requestAnimationFrame(()=>l(!0))},[t,x,e]);C.useEffect(()=>{if(!t)return;let k=0;const N=()=>{cancelAnimationFrame(k),k=requestAnimationFrame(()=>{E()?(o(!0),l(!1),S()):(o(!1),r(!1),l(!1))})},R=()=>{o(!1),r(!1),l(!1)};return N(),t.on("selectionUpdate",N),t.on("transaction",N),t.on("focus",N),t.on("blur",R),()=>{cancelAnimationFrame(k),t.off("selectionUpdate",N),t.off("transaction",N),t.off("focus",N),t.off("blur",R)}},[t,E,S]);const M=k=>{k(t),r(!1),c(""),d("all")},w=D2.filter(k=>{const N=u==="all"||k.category===u,R=a===""||k.title.toLowerCase().includes(a.toLowerCase())||k.description.toLowerCase().includes(a.toLowerCase())||k.keywords.some(B=>B.toLowerCase().includes(a.toLowerCase()));return N&&R}),T=w.reduce((k,N)=>(k[N.category]||(k[N.category]=[]),k[N.category].push(N),k),{});return s?m.jsxs(m.Fragment,{children:[m.jsx("div",{style:{position:"absolute",top:h.top,left:h.left,width:h.width,visibility:i?"visible":"hidden",zIndex:1e4},className:"group",children:m.jsxs("div",{className:"relative py-4 w-[95%] mx-auto flex items-center","aria-label":"Insert block",children:[m.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-full h-0.5 bg-gradient-to-r from-transparent via-slate-300 to-transparent dark:via-slate-600 transform origin-center scale-x-0 opacity-0 group-hover:scale-x-100 group-hover:opacity-100 transition-all duration-300"}),m.jsxs("div",{ref:y.setReference,className:"relative z-10 cursor-pointer mx-auto",onClick:()=>r(k=>!k),children:[m.jsx("div",{className:"absolute -inset-3 rounded-full bg-primary/10 dark:bg-primary/20 scale-0 opacity-0 group-hover:scale-100 group-hover:opacity-100 transition-all duration-300 ease-out animate-pulse"}),m.jsx("div",{className:"relative bg-background border border-border p-1.5 rounded-full shadow-sm group-hover:shadow-md transition-all duration-200",children:m.jsx(dL,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors duration-200"})})]})]})}),n&&m.jsxs("div",{ref:y.setFloating,style:{position:b,top:g??0,left:p??0,zIndex:10001},className:"bg-background border border-border shadow-lg rounded-lg p-2 w-96 max-h-[500px] overflow-hidden",onMouseDown:k=>k.preventDefault(),children:[m.jsx("div",{className:"p-2 border-b border-border",children:m.jsx("input",{type:"text",placeholder:"Search blocks...",value:a,onChange:k=>c(k.target.value),className:"w-full px-3 py-2 text-sm bg-muted border border-input rounded-md focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent",autoFocus:!0})}),m.jsxs("div",{className:"flex gap-1 p-2 border-b border-border overflow-x-auto",children:[m.jsx(ce.Button,{variant:u==="all"?"default":"ghost",size:"sm",onClick:()=>d("all"),className:"text-xs whitespace-nowrap",children:"All"}),Object.entries(ig).map(([k,N])=>m.jsxs(ce.Button,{variant:u===k?"default":"ghost",size:"sm",onClick:()=>d(k),className:"text-xs whitespace-nowrap flex items-center gap-1",children:[og[k],N]},k))]}),m.jsxs("div",{className:"max-h-80 overflow-y-auto",children:[u==="all"?Object.entries(T).map(([k,N])=>m.jsxs("div",{className:"py-2",children:[m.jsxs("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2",children:[og[k],ig[k]]}),N.map(R=>m.jsx(ce.Button,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left",onClick:()=>M(R.command),children:m.jsxs("div",{className:"flex items-center gap-3 w-full",children:[m.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md border bg-muted",children:R.icon}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"font-medium text-sm",children:R.title}),m.jsx("p",{className:"text-xs text-muted-foreground truncate",children:R.description})]})]})},R.title))]},k)):w.map(k=>m.jsx(ce.Button,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left",onClick:()=>M(k.command),children:m.jsxs("div",{className:"flex items-center gap-3 w-full",children:[m.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md border bg-muted",children:k.icon}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("p",{className:"font-medium text-sm",children:k.title}),m.jsx("p",{className:"text-xs text-muted-foreground truncate",children:k.description})]})]})},k.title)),w.length===0&&m.jsxs("div",{className:"p-4 text-center text-sm text-muted-foreground",children:['No blocks found for "',a,'"']})]})]})]}):null},L2=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),lg=new Set(["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","noscript","ol","p","pre","section","table","tfoot","ul","video","thead","tbody","tr","th","td","colgroup"]);function ww(t){const e=t.match(/^<\/?\s*([a-zA-Z0-9:-]+)/);return e?e[1].toLowerCase():null}function I2(t){return/^<\s*[^/!][^>]*>$/.test(t)}function ag(t){return/^<\s*\//.test(t)}function j2(t){if(/\/\s*>$/.test(t))return!0;const e=ww(t);return e?L2.has(e):!1}function P2(t){return/^<\s*!/.test(t)}function lu(t,e=2){if(!t)return"";const n=t.replace(/\r\n?/g,`
|
|
465
|
+
`).split(/(<[^>]+>)/g).filter(Boolean),r=" ".repeat(e);let s=0;const o=[];let i=null;for(let l=0;l<n.length;l++){const a=n[l];if(a.startsWith("<")){const c=ww(a);c&&(c==="pre"||c==="code"||c==="script"||c==="style")&&ag(a)&&(i=null),ag(a)&&s>0&&(s-=1);const u=c&&lg.has(c)||P2(a),d=`${u?r.repeat(s):""}${a.trim()}`;if(u)o.push(d);else{const h=o.length?o[o.length-1]:"";h&&!h.endsWith(`
|
|
466
466
|
`)?o[o.length-1]=h+a.trim():o.push(r.repeat(s)+a.trim())}c&&I2(a)&&!j2(a)&&lg.has(c)&&(s+=1,(c==="pre"||c==="code"||c==="script"||c==="style")&&(i=c))}else if(i){const c=a.split(`
|
|
467
|
-
`);for(const u of c)o.push(u)}else{
|
|
467
|
+
`);for(const u of c)o.push(u)}else{const c=a.replace(/\s+/g," ");if(c.length>0){const u=o.length?o[o.length-1]:"";if(u&&!u.endsWith(`
|
|
468
468
|
`))o[o.length-1]=u+c;else{const d=c.replace(/^ +/,"");d&&o.push(r.repeat(s)+d)}}}}return o.join(`
|
|
469
469
|
`).replace(/\n{3,}/g,`
|
|
470
470
|
|
|
471
|
-
`)}const Kh=t=>{const[e,n]=C.useState({canUndo:!1,canRedo:!1,historyDepth:0,isHistoryEmpty:!0}),r=C.useCallback(()=>{if(!t){n({canUndo:!1,canRedo:!1,historyDepth:0,isHistoryEmpty:!0});return}const a=t.can().undo(),c=t.can().redo();n({canUndo:a,canRedo:c,historyDepth:a?1:0,isHistoryEmpty:!a&&!c})},[t]);C.useEffect(()=>{if(t)return r(),t.on("transaction",r),t.on("update",r),t.on("selectionUpdate",r),t.on("focus",r),t.on("blur",r),()=>{t.off("transaction",r),t.off("update",r),t.off("selectionUpdate",r),t.off("focus",r),t.off("blur",r)}},[t,r]);const s=C.useCallback(()=>{if(!t||!e.canUndo)return!1;try{console.log("useEditorHistory - Attempting undo operation");const a=t.chain().focus().undo().run();return console.log("useEditorHistory - Undo result:",a),a}catch(a){return console.error("useEditorHistory - Undo operation failed:",a),!1}},[t,e.canUndo]),o=C.useCallback(()=>{if(!t||!e.canRedo)return!1;try{console.log("useEditorHistory - Attempting redo operation");const a=t.chain().focus().redo().run();return console.log("useEditorHistory - Redo result:",a),a}catch(a){return console.error("useEditorHistory - Redo operation failed:",a),!1}},[t,e.canRedo]),i=C.useCallback(()=>{if(t)try{t.commands.clearContent(),r()}catch(a){console.warn("Clear history operation failed:",a)}},[t,r]),l=C.useCallback(()=>({...e}),[e]);return{...e,undo:s,redo:o,clearHistory:i,getHistoryState:l}},vw=(t,e)=>t?e==="undo"?t.can().undo():t.can().redo():!1,B2=(t,e)=>{if(!t||!vw(t,e))return!1;try{return e==="undo"?t.chain().focus().undo().run():t.chain().focus().redo().run()}catch(n){return console.warn(`${e} operation failed:`,n),!1}},wd=t=>{const e=typeof navigator<"u"&&navigator.platform.includes("Mac"),n=e?"Cmd":"Ctrl";return t==="undo"?`${n}+Z`:e?`${n}+Shift+Z`:`${n}+Y`},Gh=({editor:t,className:e,showLabels:n=!1,size:r="sm"})=>{const{canUndo:s,canRedo:o,undo:i,redo:l}=Kh(t);C.useEffect(()=>{if(!t)return;const u=d=>{t.isFocused&&(d.ctrlKey||d.metaKey)&&(d.key==="z"&&!d.shiftKey?(d.preventDefault(),i()):(d.key==="z"&&d.shiftKey||d.key==="y")&&(d.preventDefault(),l()))};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,i,l]);const a=r==="sm"?"sm":r==="lg"?"lg":"default",c=r==="sm"?"h-4 w-4":r==="lg"?"h-6 w-6":"h-5 w-5";return m.jsxs("div",{className:$e.cn("flex items-center gap-1",e),children:[m.jsxs(ce.Button,{variant:s?"outline":"ghost",size:a,onClick:i,disabled:!s,title:`Undo last action (${wd("undo")})`,"aria-label":"Undo last action",className:$e.cn("transition-all duration-200 border-2",r==="sm"?"h-8 w-8 p-0":r==="lg"?"h-10 w-10 p-0":"h-9 w-9 p-0",s?"border-primary/20 hover:border-primary/40 hover:bg-primary/10 hover:text-primary hover:scale-105 active:scale-95 shadow-sm":"opacity-40 cursor-not-allowed border-transparent",s&&"bg-primary/5",n&&"w-auto px-3"),children:[m.jsx(SI,{className:$e.cn(c,"transition-colors duration-200",s?s?"text-primary":"text-current":"text-muted-foreground")}),n&&m.jsx("span",{className:"ml-2",children:"Undo"})]}),m.jsxs(ce.Button,{variant:o?"outline":"ghost",size:a,onClick:l,disabled:!o,title:`Redo last undone action (${wd("redo")})`,"aria-label":"Redo last undone action",className:$e.cn("transition-all duration-200 border-2",r==="sm"?"h-8 w-8 p-0":r==="lg"?"h-10 w-10 p-0":"h-9 w-9 p-0",o?"border-primary/20 hover:border-primary/40 hover:bg-primary/10 hover:text-primary hover:scale-105 active:scale-95 shadow-sm":"opacity-40 cursor-not-allowed border-transparent",o&&"bg-primary/5",n&&"w-auto px-3"),children:[m.jsx(QL,{className:$e.cn(c,"transition-colors duration-200",o?o?"text-primary":"text-current":"text-muted-foreground")}),n&&m.jsx("span",{className:"ml-2",children:"Redo"})]})]})},Ve=({onClick:t,isActive:e,disabled:n,children:r,title:s,ariaLabel:o,shortcut:i})=>{const l=i?`${s} (${i})`:s;return m.jsx(ce.Button,{variant:e?"default":"ghost",size:"sm",onClick:t,disabled:n,title:l,"aria-label":o||s,className:`h-8 w-8 p-0 transition-all duration-200 ${n?"opacity-40 cursor-not-allowed":"hover:bg-accent hover:text-accent-foreground hover:scale-105"}`,children:r})},H2=({editor:t})=>m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsxs(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2","aria-label":"Font size menu",title:"Font size menu",children:[m.jsx(ss,{className:"h-4 w-4 mr-1"}),"Size"]})}),m.jsx(vt.PopoverContent,{onFocusOutside:e=>e.preventDefault(),className:"w-[360px] p-0",side:"bottom",align:"start",children:m.jsx(bw,{editor:t,className:"p-4"})})]}),$2=({editor:t})=>m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Color menu",title:"Color menu",children:m.jsx(Hh,{className:"h-4 w-4"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:e=>e.preventDefault(),className:"w-[380px] p-0",side:"bottom",align:"start",children:m.jsx(yw,{editor:t,className:"p-4"})})]}),z2=({editor:t})=>{const e=async()=>{const s=rc(t);if(s){const i=await s();i!=null&&i.src&&(t.chain().focus().setImage({src:i.src,alt:i.alt||void 0}).run(),i.blurDataURL&&t.chain().focus().updateAttributes("image",{blurDataURL:i.blurDataURL}).run());return}const o=window.prompt("Enter image URL:");o&&t.chain().focus().setImage({src:o}).run()},n=()=>{t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},r=()=>{const s=window.prompt("Enter URL:");s&&t.chain().focus().setLink({href:s}).run()};return m.jsxs(Ke.DropdownMenu,{children:[m.jsx(Ke.DropdownMenuTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2",children:"Insert"})}),m.jsxs(Ke.DropdownMenuContent,{children:[m.jsxs(Ke.DropdownMenuItem,{onClick:e,children:[m.jsx(es,{className:"h-4 w-4 mr-2"}),"Image"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:n,children:[m.jsx(ui,{className:"h-4 w-4 mr-2"}),"Table"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:r,children:[m.jsx(Ja,{className:"h-4 w-4 mr-2"}),"Link"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setHorizontalRule().run(),children:[m.jsx(Xa,{className:"h-4 w-4 mr-2"}),"Horizontal Rule"]}),m.jsx(Ke.DropdownMenuSeparator,{}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Enter CSS (without <style> tags):","/* your styles */");if(s!=null){const o=`<style>${s}</style>`;t.commands.insertContentAt({from:0,to:0},o)}},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"CSS Block"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Enter JavaScript (without <script> tags):","// your script");if(s!=null){const o=`<script>${s}<\/script>`,i=t.state.doc.content.size;t.commands.insertContentAt(i,o)}},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"Script Block"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Optional class for DIV:",""),o=window.prompt("Optional inline style for DIV:",""),i=window.prompt("Optional content for DIV:","New block"),l=`${s?` class="${s}"`:""}${o?` style="${o}"`:""}`,c=i?`<p>${(u=>u.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"))(i)}</p>`:"<p><br /></p>";t.chain().focus().insertContent(`<div${l}>${c}</div>`).run()},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"DIV Block"]}),m.jsx(Ke.DropdownMenuSeparator,{}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setAlertWidget().run(),children:[m.jsx(Qa,{className:"h-4 w-4 mr-2"}),"Alert Widget"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setCtaWidget({text:"Learn more",url:"",style:"primary",size:"medium",textAlign:"center"}).run(),children:[m.jsx(Ya,{className:"h-4 w-4 mr-2"}),"CTA Widget"]})]})]})},F2=({editor:t})=>{const e=()=>{const s=t.getHTML(),o=new Blob([s],{type:"text/html"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.html",l.click(),URL.revokeObjectURL(i)},n=()=>{const s=JSON.stringify(t.getJSON(),null,2),o=new Blob([s],{type:"application/json"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.json",l.click(),URL.revokeObjectURL(i)},r=()=>{const s=t.getText(),o=new Blob([s],{type:"text/plain"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.txt",l.click(),URL.revokeObjectURL(i)};return m.jsxs(Ke.DropdownMenu,{children:[m.jsx(Ke.DropdownMenuTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2","aria-label":"Export menu",title:"Export menu",children:m.jsx(Qx,{className:"h-4 w-4 mr-1"})})}),m.jsxs(Ke.DropdownMenuContent,{children:[m.jsx(Ke.DropdownMenuItem,{onClick:e,children:"Export as HTML"}),m.jsx(Ke.DropdownMenuItem,{onClick:n,children:"Export as JSON"}),m.jsx(Ke.DropdownMenuItem,{onClick:r,children:"Export as Text"})]})]})},Jh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(""),[o,i]=C.useState(!1),[l,a]=C.useState(null),c=C.useRef([]);if(C.useEffect(()=>{if(!t)return;const f=g=>{try{const y=t.getHTML();s(lu(y)),n(!0)}catch{}},p="editor:openSourceView";return window.addEventListener(p,f),()=>window.removeEventListener(p,f)},[t]),!t)return null;const u=()=>{const f=t.getHTML();s(lu(f)),n(!0)},d=()=>{t.chain().focus().setContent(r).run(),n(!1)},h=()=>{for(const w of c.current)try{URL.revokeObjectURL(w)}catch{}c.current=[];const f=t.getHTML(),y=new DOMParser().parseFromString(`<div id="__content__">${f}</div>`,"text/html").body.querySelector("#__content__");Array.from(y.querySelectorAll("script")).forEach(w=>{if(!w.getAttribute("src")){const T=w.textContent||"",k=new Blob([T],{type:"text/javascript"}),N=URL.createObjectURL(k);w.setAttribute("src",N),w.textContent="",c.current.push(N)}});const E=`<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><title>Preview</title></head><body>${y.innerHTML}</body></html>`,S=new Blob([E],{type:"text/html"}),M=URL.createObjectURL(S);c.current.push(M),l&&URL.revokeObjectURL(l),a(M),i(!0)};return m.jsxs("div",{className:"border-b bg-background p-2 relative",children:[m.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[m.jsx("div",{className:"flex items-center gap-1 mr-2 p-1 rounded-md bg-muted/30 border border-border/50",children:m.jsx(Gh,{editor:t,size:"sm",showLabels:!1})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),isActive:t.isActive("heading",{level:1}),title:"Heading 1",children:m.jsx(Ls,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),isActive:t.isActive("heading",{level:2}),title:"Heading 2",children:m.jsx(ai,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),isActive:t.isActive("heading",{level:3}),title:"Heading 3",children:m.jsx(Ga,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBold().run(),isActive:t.isActive("bold"),title:"Bold",children:m.jsx(ga,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleItalic().run(),isActive:t.isActive("italic"),title:"Italic",children:m.jsx(Bh,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleUnderline().run(),isActive:t.isActive("underline"),title:"Underline",children:m.jsx($h,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleStrike().run(),isActive:t.isActive("strike"),title:"Strikethrough",children:m.jsx(ew,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleCode().run(),isActive:t.isActive("code"),title:"Inline Code",children:m.jsx(Fs,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleSubscript().run(),isActive:t.isActive("subscript"),title:"Subscript",children:m.jsx(tw,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleSuperscript().run(),isActive:t.isActive("superscript"),title:"Superscript",children:m.jsx(nw,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("left").run(),isActive:t.isActive({textAlign:"left"}),title:"Align Left",children:m.jsx(Ds,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("center").run(),isActive:t.isActive({textAlign:"center"}),title:"Align Center",children:m.jsx(ii,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("right").run(),isActive:t.isActive({textAlign:"right"}),title:"Align Right",children:m.jsx(li,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("justify").run(),isActive:t.isActive({textAlign:"justify"}),title:"Justify",children:m.jsx(Ph,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBulletList().run(),isActive:t.isActive("bulletList"),title:"Bullet List",children:m.jsx(Us,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleOrderedList().run(),isActive:t.isActive("orderedList"),title:"Numbered List",children:m.jsx(ci,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleTaskList().run(),isActive:t.isActive("taskList"),title:"Task List",children:m.jsx(Za,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBlockquote().run(),isActive:t.isActive("blockquote"),title:"Blockquote",children:m.jsx(di,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleCodeBlock().run(),isActive:t.isActive("codeBlock"),title:"Code Block",children:m.jsx(Fr,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(H2,{editor:t}),m.jsx($2,{editor:t}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(z2,{editor:t}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:u,title:"View Source (HTML)",children:m.jsx(ML,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:h,title:"Preview (executes scripts)",children:m.jsx(CL,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(F2,{editor:t})]}),e&&m.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:m.jsxs("div",{className:"bg-background border rounded-md shadow-xl w-[90vw] max-w-4xl h-[70vh] flex flex-col",children:[m.jsx("div",{className:"p-3 border-b font-semibold",children:"Edit HTML Source"}),m.jsx("textarea",{className:"flex-1 p-3 font-mono text-sm outline-none resize-none bg-muted/30",value:r,onChange:f=>s(f.target.value),spellCheck:!1}),m.jsxs("div",{className:"p-3 border-t flex justify-end gap-2",children:[m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:()=>n(!1),children:"Cancel"}),m.jsx(ce.Button,{variant:"secondary",size:"sm",onClick:()=>s(lu(r)),children:"Format"}),m.jsx(ce.Button,{size:"sm",onClick:d,children:"Apply"})]})]})}),o&&m.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:m.jsxs("div",{className:"bg-background border rounded-md shadow-xl w-[95vw] max-w-5xl h-[80vh] flex flex-col",children:[m.jsxs("div",{className:"p-3 border-b flex items-center justify-between",children:[m.jsx("div",{className:"font-semibold",children:"Preview"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:()=>{h()},children:"Refresh"}),m.jsx(ce.Button,{size:"sm",onClick:()=>{for(const f of c.current)try{URL.revokeObjectURL(f)}catch{}c.current=[],l&&URL.revokeObjectURL(l),a(null),i(!1)},children:"Close"})]})]}),m.jsx("div",{className:"flex-1",children:m.jsx("iframe",{title:"Editor Preview",className:"w-full h-full",sandbox:"allow-scripts allow-same-origin allow-modals",src:l??void 0})})]})})]})},kw=({editor:t,className:e,onDragStart:n,onDragEnd:r,onNodeChange:s})=>{const o=C.useRef(null);return C.useEffect(()=>{if(!t||!o.current)return;const i=c=>{n==null||n(c)},l=c=>{r==null||r(c)},a=o.current;return a.addEventListener("dragstart",i),a.addEventListener("dragend",l),()=>{a.removeEventListener("dragstart",i),a.removeEventListener("dragend",l)}},[t,n,r]),t?m.jsx("div",{ref:o,className:$e.cn("drag-handle-button","flex items-center justify-center","w-7 h-7 rounded-md border-2","text-slate-500 hover:text-slate-700","border-slate-200/50 hover:border-slate-300","bg-slate-50/50 hover:bg-slate-100/80","active:bg-slate-200/80 active:border-slate-400","cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out","opacity-0 group-hover:opacity-100","hover:scale-105 active:scale-95","hover:shadow-sm active:shadow-none","focus:opacity-100 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1","dark:text-slate-400 dark:hover:text-slate-200","dark:border-slate-700/50 dark:hover:border-slate-600","dark:bg-slate-800/50 dark:hover:bg-slate-700/80","dark:active:bg-slate-600/80 dark:active:border-slate-500",e),role:"button",tabIndex:0,"aria-label":"Drag to reorder this block",title:"Hold and drag to reorder this block",draggable:!0,children:m.jsx(TL,{className:"w-4 h-4"})}):null},Sw=({editor:t,className:e})=>{const[n,r]=C.useState(!1),[s,o]=C.useState("format"),[i,l]=C.useState(!1),a=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||window.innerWidth<=768;C.useEffect(()=>{const h=()=>{r(a())};return h(),window.addEventListener("resize",h),()=>window.removeEventListener("resize",h)},[]),C.useEffect(()=>{if(!t)return;const h=()=>{const{selection:f}=t.state;!f.empty&&a()?r(!0):i||r(!1)};return t.on("selectionUpdate",h),t.on("focus",h),t.on("blur",()=>{i||r(!1)}),()=>{t.off("selectionUpdate",h),t.off("focus",h),t.off("blur",()=>r(!1))}},[t,i]);const c=[{icon:m.jsx(ga,{className:"h-4 w-4"}),label:"Bold",action:()=>t.chain().focus().toggleBold().run(),isActive:()=>t.isActive("bold"),section:"format"},{icon:m.jsx(Bh,{className:"h-4 w-4"}),label:"Italic",action:()=>t.chain().focus().toggleItalic().run(),isActive:()=>t.isActive("italic"),section:"format"},{icon:m.jsx($h,{className:"h-4 w-4"}),label:"Underline",action:()=>t.chain().focus().toggleUnderline().run(),isActive:()=>t.isActive("underline"),section:"format"},{icon:m.jsx(Fs,{className:"h-4 w-4"}),label:"Code",action:()=>t.chain().focus().toggleCode().run(),isActive:()=>t.isActive("code"),section:"format"},{icon:m.jsx(Hh,{className:"h-4 w-4"}),label:"Highlight",action:()=>t.chain().focus().toggleHighlight().run(),isActive:()=>t.isActive("highlight"),section:"format"},{icon:m.jsx(ss,{className:"h-4 w-4"}),label:"Paragraph",action:()=>t.chain().focus().setParagraph().run(),isActive:()=>t.isActive("paragraph"),section:"blocks"},{icon:m.jsx(Ls,{className:"h-4 w-4"}),label:"Heading 1",action:()=>t.chain().focus().toggleHeading({level:1}).run(),isActive:()=>t.isActive("heading",{level:1}),section:"blocks"},{icon:m.jsx(ai,{className:"h-4 w-4"}),label:"Heading 2",action:()=>t.chain().focus().toggleHeading({level:2}).run(),isActive:()=>t.isActive("heading",{level:2}),section:"blocks"},{icon:m.jsx(Ga,{className:"h-4 w-4"}),label:"Heading 3",action:()=>t.chain().focus().toggleHeading({level:3}).run(),isActive:()=>t.isActive("heading",{level:3}),section:"blocks"},{icon:m.jsx(Us,{className:"h-4 w-4"}),label:"Bullet List",action:()=>t.chain().focus().toggleBulletList().run(),isActive:()=>t.isActive("bulletList"),section:"blocks"},{icon:m.jsx(ci,{className:"h-4 w-4"}),label:"Numbered List",action:()=>t.chain().focus().toggleOrderedList().run(),isActive:()=>t.isActive("orderedList"),section:"blocks"},{icon:m.jsx(Za,{className:"h-4 w-4"}),label:"Task List",action:()=>t.chain().focus().toggleTaskList().run(),isActive:()=>t.isActive("taskList"),section:"blocks"},{icon:m.jsx(di,{className:"h-4 w-4"}),label:"Quote",action:()=>t.chain().focus().toggleBlockquote().run(),isActive:()=>t.isActive("blockquote"),section:"blocks"},{icon:m.jsx(Ja,{className:"h-4 w-4"}),label:"Link",action:()=>{const h=window.prompt("Enter URL:");h&&t.chain().focus().setLink({href:h}).run()},isActive:()=>t.isActive("link"),section:"insert"},{icon:m.jsx(es,{className:"h-4 w-4"}),label:"Image",action:async()=>{const h=rc(t);if(h){const p=await h();p!=null&&p.src&&t.chain().focus().setImage({src:p.src,alt:p.alt||void 0}).run();return}const f=window.prompt("Enter image URL:");f&&t.chain().focus().setImage({src:f}).run()},section:"insert"},{icon:m.jsx(ui,{className:"h-4 w-4"}),label:"Table",action:()=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),section:"insert"},{icon:m.jsx(Ds,{className:"h-4 w-4"}),label:"Align Left",action:()=>t.chain().focus().setTextAlign("left").run(),isActive:()=>t.isActive({textAlign:"left"}),section:"align"},{icon:m.jsx(ii,{className:"h-4 w-4"}),label:"Align Center",action:()=>t.chain().focus().setTextAlign("center").run(),isActive:()=>t.isActive({textAlign:"center"}),section:"align"},{icon:m.jsx(li,{className:"h-4 w-4"}),label:"Align Right",action:()=>t.chain().focus().setTextAlign("right").run(),isActive:()=>t.isActive({textAlign:"right"}),section:"align"}],u=[{key:"format",label:"Format",icon:m.jsx(ga,{className:"h-3 w-3"})},{key:"blocks",label:"Blocks",icon:m.jsx(Ls,{className:"h-3 w-3"})},{key:"insert",label:"Insert",icon:m.jsx(es,{className:"h-3 w-3"})},{key:"align",label:"Align",icon:m.jsx(Ds,{className:"h-3 w-3"})}],d=c.filter(h=>h.section===s);return!n&&!i?null:m.jsxs("div",{className:$e.cn("fixed bottom-0 left-0 right-0 z-50 bg-background border-t border-border shadow-lg","transform transition-transform duration-300 ease-in-out",n||i?"translate-y-0":"translate-y-full",e),children:[m.jsx("div",{className:"flex justify-center py-2 border-b border-border",children:m.jsxs(ce.Button,{variant:"ghost",size:"sm",onClick:()=>l(!i),className:"flex items-center gap-2",children:[i?m.jsx(ow,{className:"h-4 w-4"}):m.jsx(KL,{className:"h-4 w-4"}),m.jsx("span",{className:"text-xs",children:i?"Close":"Tools"})]})}),(i||n)&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"flex border-b border-border bg-muted/50",children:u.map(h=>m.jsx(ce.Button,{variant:s===h.key?"default":"ghost",size:"sm",onClick:()=>o(h.key),className:"flex-1 rounded-none text-xs py-2 h-auto",children:m.jsxs("div",{className:"flex flex-col items-center gap-1",children:[h.icon,m.jsx("span",{children:h.label})]})},h.key))}),m.jsx("div",{className:"p-2",children:m.jsx("div",{className:"flex flex-wrap gap-1 justify-center",children:d.map((h,f)=>{var p;return m.jsxs(ce.Button,{variant:(p=h.isActive)!=null&&p.call(h)?"default":"ghost",size:"sm",onClick:h.action,className:"flex flex-col items-center gap-1 h-auto py-2 px-3 min-w-[60px]",title:h.label,children:[h.icon,m.jsx("span",{className:"text-xs",children:h.label})]},f)})})})]}),m.jsx("div",{className:"h-safe-area-inset-bottom"})]})},sc=({content:t,onChange:e,placeholder:n,editable:r=!0,showToolbar:s=!0,showCharacterCount:o=!0,className:i,onFocus:l,onBlur:a,useEnhancedFloatingMenu:c=!0,showMobileToolbar:u=!0,enableAdvancedPlaceholders:d=!0,enableFocusMode:h=!1,showKeyboardShortcuts:f=!1})=>{var T,k,N;const p=C.useRef(null),[g,y]=C.useState({isOpen:!1,searchTerm:"",replaceTerm:"",currentMatch:0,totalMatches:0,caseSensitive:!1,wholeWord:!1}),b=wb({extensions:Fh,content:t,editable:r,immediatelyRender:!1,onUpdate:({editor:R})=>{e(R.getHTML())},onFocus:()=>{l==null||l()},onBlur:()=>{a==null||a()},editorProps:{attributes:{class:$e.cn("prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl","mx-auto focus:outline-none p-4 min-h-[500px] w-full","prose-headings:scroll-mt-[80px] prose-headings:font-semibold","prose-h1:text-4xl prose-h2:text-3xl prose-h3:text-2xl","prose-p:leading-7 prose-li:leading-7","prose-pre:bg-muted prose-pre:border prose-pre:rounded-lg","prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded","prose-blockquote:border-l-4 prose-blockquote:border-primary prose-blockquote:pl-4","prose-table:border-collapse prose-table:border prose-table:border-border","prose-th:border prose-th:border-border prose-th:bg-muted prose-th:p-2","prose-td:border prose-td:border-border prose-td:p-2","prose-img:rounded-lg prose-img:shadow-sm",i)},handleKeyDown:(R,B)=>{if(B.ctrlKey||B.metaKey)switch(B.key){case"f":return B.preventDefault(),y(P=>({...P,isOpen:!P.isOpen})),!0;case"s":return B.preventDefault(),!0;default:return!1}return!1}}});C.useEffect(()=>{if(!b)return;const R=b.getHTML();if(t!==R){const{from:B,to:P}=b.state.selection;b.commands.setContent(t,{emitUpdate:!1}),b.commands.setTextSelection({from:B,to:P})}},[t,b]);const x=R=>{if(!b||!R){y(oe=>({...oe,totalMatches:0,currentMatch:0}));return}const B=b.getText(),P=g.caseSensitive?"g":"gi",L=g.wholeWord?`\\b${R}\\b`:R,H=new RegExp(L,P),se=B.match(H);y(oe=>({...oe,totalMatches:se?se.length:0,currentMatch:se?1:0}))},E=()=>{if(!b||!g.searchTerm)return;const R=b.getHTML(),B=g.caseSensitive?"g":"gi",P=g.wholeWord?`\\b${g.searchTerm}\\b`:g.searchTerm,L=new RegExp(P,B),H=R.replace(L,g.replaceTerm);b.commands.setContent(H),y(se=>({...se,totalMatches:0,currentMatch:0}))};if(!b)return null;const S=(T=b.storage)==null?void 0:T.characterCount,M=((k=S==null?void 0:S.characters)==null?void 0:k.call(S))??0,w=((N=S==null?void 0:S.words)==null?void 0:N.call(S))??0;return m.jsxs("div",{ref:p,className:$e.cn("relative w-full rounded-lg border bg-background shadow-sm","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",i),children:[s&&m.jsx(Jh,{editor:b}),g.isOpen&&m.jsxs("div",{className:"border-b bg-muted/50 p-3",children:[m.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[m.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[m.jsx(cI,{className:"h-4 w-4 text-muted-foreground"}),m.jsx(ps.Input,{placeholder:"Search...",value:g.searchTerm,onChange:R=>{const B=R.target.value;y(P=>({...P,searchTerm:B})),x(B)},className:"h-8"}),m.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:g.totalMatches>0?`${g.currentMatch}/${g.totalMatches}`:"No matches"})]}),m.jsx(ce.Button,{variant:"ghost",size:"sm",onClick:()=>y(R=>({...R,isOpen:!1})),children:m.jsx(ow,{className:"h-4 w-4"})})]}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx(tI,{className:"h-4 w-4 text-muted-foreground"}),m.jsx(ps.Input,{placeholder:"Replace with...",value:g.replaceTerm,onChange:R=>y(B=>({...B,replaceTerm:R.target.value})),className:"h-8 flex-1"}),m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:E,disabled:!g.searchTerm||g.totalMatches===0,children:"Replace All"})]})]}),m.jsx(Wh,{editor:b}),c?m.jsx(xw,{editor:b,wrapperRef:p}):m.jsx(qh,{editor:b}),m.jsx(kw,{editor:b,onDragStart:R=>{console.log("Drag started:",R),document.body.classList.add("dragging")},onDragEnd:R=>{console.log("Drag ended:",R),document.body.classList.remove("dragging")},onNodeChange:({node:R,editor:B,pos:P})=>{R&&console.log("Hovering over node:",R.type.name,"at position:",P)}}),m.jsx(bb,{editor:b}),o&&S&&m.jsxs("div",{className:"absolute bottom-2 right-2 z-10 text-xs text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border",children:[M," characters / ",w," words"]}),f&&m.jsxs("div",{className:"absolute bottom-2 left-2 text-xs text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border opacity-0 hover:opacity-100 transition-opacity",children:[m.jsx("div",{children:"Ctrl+F: Search"}),m.jsx("div",{children:"Ctrl+S: Save"}),m.jsx("div",{children:"/: Commands"}),m.jsx("div",{children:"Ctrl+K: Insert Link"}),m.jsx("div",{children:"Ctrl+Shift+H: Highlight"}),m.jsx("div",{children:"Ctrl+Alt+1-6: Headings"})]}),u&&m.jsx(Sw,{editor:b})]})},U2=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),{x:o,y:i,refs:l,strategy:a,update:c}=fi({placement:"top",strategy:"fixed",open:e,onOpenChange:n,middleware:[hi(-12)],whileElementsMounted:Bs}),u=C.useCallback(()=>t.isActive("image"),[t]),d=t.getAttributes("image")||{},h=C.useCallback(()=>{const{state:y,view:b}=t,x=()=>{var M,w;try{if(y.selection instanceof K){const N=b.nodeDOM(y.selection.from);if(N){const R=((M=N.closest)==null?void 0:M.call(N,".tiptap-image-wrapper"))??N;return R.querySelector("img")??R}}const T=b.dom.querySelector(".tiptap-image-wrapper.ProseMirror-selectednode");if(T)return T.querySelector("img")??T;const k=b.dom.querySelector(".ProseMirror-selectednode");if(k){const N=((w=k.closest)==null?void 0:w.call(k,".tiptap-image-wrapper"))??k;return N.querySelector("img")??N}}catch{}return null},E=h._lastEl,S=x()??E;if(S){h._lastEl=S;const M={getBoundingClientRect:()=>{const w=x()??h._lastEl;return w?w.getBoundingClientRect():new DOMRect(0,0,0,0)}};l.setReference(M)}else{const M=b.coordsAtPos(y.selection.from),w={getBoundingClientRect:()=>new DOMRect(M.left,M.top,0,0)};l.setReference(w)}requestAnimationFrame(()=>{c(),requestAnimationFrame(()=>s(!0))})},[t,l,c]);if(C.useEffect(()=>{const y=()=>{const b=u();n(b),s(!1),b&&h()};return y(),t.on("selectionUpdate",y),t.on("transaction",y),t.on("focus",y),t.on("blur",()=>n(!1)),()=>{t.off("selectionUpdate",y),t.off("transaction",y),t.off("focus",y)}},[t,u,h]),!e)return null;const f=y=>{t.chain().focus().updateAttributes("image",{align:y}).run(),requestAnimationFrame(()=>h())},p=()=>{t.chain().focus().deleteSelection().run()},g=()=>{const y=d==null?void 0:d.src;if(y)try{const b=document.createElement("a");b.href=y;const x=(y.split("?")[0]||"").split("/").pop()||"image";b.download=x,document.body.appendChild(b),b.click(),b.remove()}catch{}};return m.jsxs("div",{ref:l.setFloating,style:{position:a,top:i??0,left:o??0,zIndex:10002,visibility:r?"visible":"hidden",pointerEvents:"auto"},className:"bg-background/95 backdrop-blur border rounded-full shadow-lg px-3 py-2 flex items-center gap-1",onMouseDown:y=>y.preventDefault(),children:[m.jsx(ce.Button,{size:"icon",variant:d.align==="left"?"default":"ghost",title:"Align left",onClick:()=>f("left"),children:m.jsx(Ds,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:d.align==="center"?"default":"ghost",title:"Align center",onClick:()=>f("center"),children:m.jsx(ii,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:d.align==="right"?"default":"ghost",title:"Align right",onClick:()=>f("right"),children:m.jsx(li,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",title:"Download",onClick:g,children:m.jsx(Qx,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",title:"Delete",onClick:p,children:m.jsx(rw,{className:"h-4 w-4"})})]})},cg=t=>t.isActive("table")||t.isActive("tableCell")||t.isActive("tableHeader")||t.isActive("tableRow"),V2=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),{refs:o,x:i,y:l,strategy:a,update:c}=fi({placement:"bottom",strategy:"fixed",middleware:[hi(12),tc(),ec()],whileElementsMounted:Bs,open:e,onOpenChange:n}),u=C.useCallback(()=>{var R;const{state:k,view:N}=t;try{const{from:B}=k.selection,{node:P}=N.domAtPos(B);let L=null;return P.nodeType===Node.ELEMENT_NODE?L=P:(P.nodeType===Node.TEXT_NODE||P!=null&&P.parentElement)&&(L=P.parentElement),((R=L==null?void 0:L.closest)==null?void 0:R.call(L,"td, th"))??null}catch{return null}},[t]),d=C.useCallback(()=>{const k=u();return(k==null?void 0:k.closest("table"))??null},[u]),h=C.useCallback(()=>{if(!cg(t)){n(!1);return}const k=d();if(!k){n(!1);return}o.setReference(k),n(!0),s(!1),requestAnimationFrame(()=>{c(),requestAnimationFrame(()=>s(!0))})},[t,o,d,c]);if(C.useEffect(()=>{const k=()=>{cg(t)?h():n(!1)},N=()=>n(!1);return k(),t.on("selectionUpdate",k),t.on("transaction",k),t.on("focus",k),t.on("blur",N),()=>{t.off("selectionUpdate",k),t.off("transaction",k),t.off("focus",k),t.off("blur",N)}},[t,h]),!e)return null;const f=t.can(),p=typeof f.addRowAfter=="function"?f.addRowAfter():!1,g=typeof f.deleteRow=="function"?f.deleteRow():!1,y=typeof f.addColumnAfter=="function"?f.addColumnAfter():!1,b=typeof f.deleteColumn=="function"?f.deleteColumn():!1,x=typeof f.deleteTable=="function"?f.deleteTable():!1,E=()=>{t.chain().focus().addRowAfter().run(),h()},S=()=>{t.chain().focus().deleteRow().run(),h()},M=()=>{t.chain().focus().addColumnAfter().run(),h()},w=()=>{t.chain().focus().deleteColumn().run(),h()},T=()=>{t.chain().focus().deleteTable().run(),n(!1)};return m.jsxs("div",{ref:o.setFloating,style:{position:a,top:l??0,left:i??0,zIndex:10002,visibility:r?"visible":"hidden"},className:"flex items-center gap-1 rounded-full border bg-background/95 px-2 py-1 shadow-lg",onMouseDown:k=>k.preventDefault(),children:[m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:E,disabled:!p,title:"Add row below","aria-label":"Add row below",children:m.jsx(lI,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:S,disabled:!g,title:"Delete current row","aria-label":"Delete current row",children:m.jsx(oI,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:M,disabled:!y,title:"Add column to the right","aria-label":"Add column to the right",children:m.jsx(xL,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:w,disabled:!b,title:"Delete current column","aria-label":"Delete current column",children:m.jsx(yL,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:T,disabled:!x,title:"Delete table","aria-label":"Delete table",children:m.jsx(rw,{className:"h-4 w-4"})})]})},Cw=({content:t,onChange:e,placeholder:n,editable:r=!0,showToolbar:s=!0,showCharacterCount:o=!0,className:i,onFocus:l,onBlur:a,openImagePicker:c})=>{var g,y,b;const u=C.useRef(null),d=wb({extensions:Fh,content:t,editable:r,immediatelyRender:!1,onUpdate:({editor:x})=>e(x.getHTML()),onFocus:()=>{l==null||l()},onBlur:()=>{a==null||a()},editorProps:{attributes:{class:$e.cn("prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl","mx-auto focus:outline-none min-h-[500px] w-full","pl-12 pr-4 py-4","prose-headings:scroll-mt-[80px] prose-headings:font-semibold","prose-h1:text-4xl prose-h2:text-3xl prose-h3:text-2xl","prose-p:leading-7 prose-li:leading-7","prose-pre:bg-muted prose-pre:border prose-pre:rounded-lg","prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded","prose-blockquote:border-l-4 prose-blockquote:border-primary prose-blockquote:pl-4","prose-table:border-collapse prose-table:border prose-table:border-border","prose-th:border prose-th:border-border prose-th:bg-muted prose-th:p-2","prose-td:border prose-td:border-border prose-td:p-2","prose-img:rounded-lg prose-img:shadow-sm")}}});if(C.useEffect(()=>{if(d)return sg(d,c),()=>sg(d,void 0)},[d,c]),C.useEffect(()=>{if(!d)return;const x=d.getHTML();if(t!==x){const{from:E,to:S}=d.state.selection;d.commands.setContent(t,{emitUpdate:!1}),d.commands.setTextSelection({from:E,to:S})}},[t,d]),!d)return null;const h=(g=d.storage)==null?void 0:g.characterCount,f=((y=h==null?void 0:h.characters)==null?void 0:y.call(h))??0,p=((b=h==null?void 0:h.words)==null?void 0:b.call(h))??0;return m.jsxs("div",{ref:u,className:$e.cn("relative w-full rounded-lg border bg-background shadow-sm","flex flex-col h-full min-h-0","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",i),children:[s&&m.jsx(Jh,{editor:d}),m.jsx(Wh,{editor:d}),m.jsx(qh,{editor:d}),m.jsx(U2,{editor:d}),m.jsx(V2,{editor:d}),m.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.jsx(bb,{editor:d})}),o&&h&&m.jsxs("div",{className:"absolute bottom-2 right-2 text-xs z-10 text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border",children:[f," characters / ",p," words"]})]})},Ew=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("flex items-center gap-1 rounded-md bg-background p-1",t),...e}));Ew.displayName="Toolbar";const Mw=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("flex items-center gap-1",t),...e}));Mw.displayName="ToolbarGroup";const Aw=C.forwardRef(({className:t,isActive:e,...n},r)=>m.jsx("button",{ref:r,className:$e.cn("inline-flex items-center justify-center rounded-md p-1.5 text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{"bg-accent text-accent-foreground":e},t),...n}));Aw.displayName="ToolbarButton";const Tw=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("mx-1 h-7 w-px bg-muted",t),...e}));Tw.displayName="ToolbarSeparator";const W2=({html:t,className:e})=>{const n=C.useRef(null);return C.useEffect(()=>{const r=n.current;if(!r)return;r.innerHTML=t;const s=[];return Array.from(r.querySelectorAll("script")).forEach(i=>{var a;const l=document.createElement("script");for(const c of Array.from(i.attributes))l.setAttribute(c.name,c.value);if(i.src)l.src=i.src;else{const c=i.textContent||"",u=new Blob([c],{type:l.type||"text/javascript"}),d=URL.createObjectURL(u);l.src=d,l.async=!1,s.push(d)}(a=i.parentNode)==null||a.insertBefore(l,i),i.remove()}),()=>{s.forEach(i=>{try{URL.revokeObjectURL(i)}catch{}})}},[t]),m.jsx("div",{ref:n,className:e})},q2=fe.create({name:"enhancedFocus",addOptions(){return{className:"has-focus",mode:"all",showFocusRing:!0,highlightSelection:!0,dimUnfocused:!1,animateTransitions:!0}},addProseMirrorPlugins(){return[new me({key:new ye("enhancedFocus"),props:{decorations:({doc:t,selection:e})=>{const{from:n,to:r}=e,s=[];if(t.nodesBetween(n,r,(o,i)=>{const l=De.node(i,i+o.nodeSize,{class:this.options.className});s.push(l)}),this.options.highlightSelection&&n!==r){const o=De.inline(n,r,{class:"selection-highlight"});s.push(o)}if(this.options.showFocusRing){const o=De.widget(n,()=>{const i=document.createElement("div");return i.className="focus-ring",i});s.push(o)}return be.create(t,s)}},view:()=>({update:(t,e)=>{const{state:n}=t,{selection:r}=n,s=e.selection;r.eq(s)||this.editor.emit("selectionUpdate",{editor:this.editor,transaction:n.tr})}})})]},addGlobalAttributes(){return[{types:["paragraph","heading","blockquote","codeBlock","listItem"],attributes:{"data-focused":{default:null,renderHTML:t=>t["data-focused"]?{"data-focused":t["data-focused"]}:{}}}}]},onCreate(){const t=this.editor.view.dom;this.options.animateTransitions&&t.classList.add("focus-transitions"),this.options.dimUnfocused&&t.classList.add("dim-unfocused")},onSelectionUpdate(){const{state:t}=this.editor,{selection:e}=t,{from:n,to:r}=e,s=t.tr;let o=!1;t.doc.descendants((i,l)=>{if(i.isText||i.isLeaf)return;const a=l,c=l+i.nodeSize,u=n>=a&&r<=c,d=i.attrs["data-focused"];u&&!d?(s.setNodeMarkup(l,void 0,{...i.attrs,"data-focused":"true"}),o=!0):!u&&d&&(s.setNodeMarkup(l,void 0,{...i.attrs,"data-focused":null}),o=!0)}),o&&this.editor.view.dispatch(s)},addStorage(){return{isFocused:!1}},onFocus(){this.editor.view.dom.classList.add("editor-focused"),this.storage.isFocused=!0},onBlur(){this.editor.view.dom.classList.remove("editor-focused"),this.storage.isFocused=!1}}),K2=fe.create({name:"keyboardShortcuts",addOptions(){return{enableAdvancedShortcuts:!0,enableCustomShortcuts:!0,showShortcutHints:!1}},addKeyboardShortcuts(){const t={};return this.options.enableAdvancedShortcuts&&(t["Mod-Shift-x"]=()=>this.editor.commands.toggleStrike(),t["Mod-Shift-h"]=()=>this.editor.commands.toggleHighlight(),t["Mod-Shift-c"]=()=>this.editor.commands.toggleCode(),t["Mod-Alt-1"]=()=>this.editor.commands.toggleHeading({level:1}),t["Mod-Alt-2"]=()=>this.editor.commands.toggleHeading({level:2}),t["Mod-Alt-3"]=()=>this.editor.commands.toggleHeading({level:3}),t["Mod-Alt-4"]=()=>this.editor.commands.toggleHeading({level:4}),t["Mod-Alt-5"]=()=>this.editor.commands.toggleHeading({level:5}),t["Mod-Alt-6"]=()=>this.editor.commands.toggleHeading({level:6}),t["Mod-Alt-0"]=()=>this.editor.commands.setParagraph(),t["Mod-Shift-8"]=()=>this.editor.commands.toggleBulletList(),t["Mod-Shift-7"]=()=>this.editor.commands.toggleOrderedList(),t["Mod-Shift-9"]=()=>this.editor.commands.toggleTaskList(),t["Mod-Shift-b"]=()=>this.editor.commands.toggleBlockquote(),t["Mod-Alt-c"]=()=>this.editor.commands.toggleCodeBlock(),t["Mod-Shift-minus"]=()=>this.editor.commands.setHorizontalRule(),t["Mod-Shift-l"]=()=>this.editor.commands.setTextAlign("left"),t["Mod-Shift-e"]=()=>this.editor.commands.setTextAlign("center"),t["Mod-Shift-r"]=()=>this.editor.commands.setTextAlign("right"),t["Mod-Shift-j"]=()=>this.editor.commands.setTextAlign("justify"),t["Mod-comma"]=()=>this.editor.commands.toggleSubscript(),t["Mod-period"]=()=>this.editor.commands.toggleSuperscript(),t["Mod-Alt-t"]=()=>this.editor.can().insertTable()?this.editor.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}):!1,t["Mod-Home"]=()=>this.editor.commands.focus("start"),t["Mod-End"]=()=>this.editor.commands.focus("end"),t["Mod-a"]=()=>this.editor.commands.selectAll(),t["Mod-\\"]=()=>this.editor.commands.unsetAllMarks()&&this.editor.commands.clearNodes(),t["Mod-k"]=()=>{const e=window.prompt("Enter URL:");return e?this.editor.commands.setLink({href:e}):!1},t["Mod-Shift-i"]=()=>{const e=window.prompt("Enter image URL:");return e?this.editor.commands.setImage({src:e}):!1},t["Alt-ArrowUp"]=()=>{const{selection:e}=this.editor.state,{$from:n}=e,r=n.nodeBefore;if(r){const s=n.pos-r.nodeSize;return this.editor.commands.setTextSelection(s)}return!1},t["Alt-ArrowDown"]=()=>{const{selection:e}=this.editor.state,{$to:n}=e,r=n.nodeAfter;if(r){const s=n.pos+r.nodeSize;return this.editor.commands.setTextSelection(s)}return!1},t["Mod-Shift-d"]=()=>{const{selection:e}=this.editor.state,{from:n,to:r}=e,s=this.editor.state.doc.textBetween(n,r);return s?this.editor.commands.insertContentAt(r,`
|
|
471
|
+
`)}const Kh=t=>{const[e,n]=C.useState({canUndo:!1,canRedo:!1,historyDepth:0,isHistoryEmpty:!0}),r=C.useCallback(()=>{if(!t){n({canUndo:!1,canRedo:!1,historyDepth:0,isHistoryEmpty:!0});return}const a=t.can().undo(),c=t.can().redo();n({canUndo:a,canRedo:c,historyDepth:a?1:0,isHistoryEmpty:!a&&!c})},[t]);C.useEffect(()=>{if(t)return r(),t.on("transaction",r),t.on("update",r),t.on("selectionUpdate",r),t.on("focus",r),t.on("blur",r),()=>{t.off("transaction",r),t.off("update",r),t.off("selectionUpdate",r),t.off("focus",r),t.off("blur",r)}},[t,r]);const s=C.useCallback(()=>{if(!t||!e.canUndo)return!1;try{console.log("useEditorHistory - Attempting undo operation");const a=t.chain().focus().undo().run();return console.log("useEditorHistory - Undo result:",a),a}catch(a){return console.error("useEditorHistory - Undo operation failed:",a),!1}},[t,e.canUndo]),o=C.useCallback(()=>{if(!t||!e.canRedo)return!1;try{console.log("useEditorHistory - Attempting redo operation");const a=t.chain().focus().redo().run();return console.log("useEditorHistory - Redo result:",a),a}catch(a){return console.error("useEditorHistory - Redo operation failed:",a),!1}},[t,e.canRedo]),i=C.useCallback(()=>{if(t)try{t.commands.clearContent(),r()}catch(a){console.warn("Clear history operation failed:",a)}},[t,r]),l=C.useCallback(()=>({...e}),[e]);return{...e,undo:s,redo:o,clearHistory:i,getHistoryState:l}},vw=(t,e)=>t?e==="undo"?t.can().undo():t.can().redo():!1,B2=(t,e)=>{if(!t||!vw(t,e))return!1;try{return e==="undo"?t.chain().focus().undo().run():t.chain().focus().redo().run()}catch(n){return console.warn(`${e} operation failed:`,n),!1}},wd=t=>{const e=typeof navigator<"u"&&navigator.platform.includes("Mac"),n=e?"Cmd":"Ctrl";return t==="undo"?`${n}+Z`:e?`${n}+Shift+Z`:`${n}+Y`},Gh=({editor:t,className:e,showLabels:n=!1,size:r="sm"})=>{const{canUndo:s,canRedo:o,undo:i,redo:l}=Kh(t);C.useEffect(()=>{if(!t)return;const u=d=>{t.isFocused&&(d.ctrlKey||d.metaKey)&&(d.key==="z"&&!d.shiftKey?(d.preventDefault(),i()):(d.key==="z"&&d.shiftKey||d.key==="y")&&(d.preventDefault(),l()))};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,i,l]);const a=r==="sm"?"sm":r==="lg"?"lg":"default",c=r==="sm"?"h-4 w-4":r==="lg"?"h-6 w-6":"h-5 w-5";return m.jsxs("div",{className:$e.cn("flex items-center gap-1",e),children:[m.jsxs(ce.Button,{variant:s?"outline":"ghost",size:a,onClick:i,disabled:!s,title:`Undo last action (${wd("undo")})`,"aria-label":"Undo last action",className:$e.cn("transition-all duration-200 border-2",r==="sm"?"h-8 w-8 p-0":r==="lg"?"h-10 w-10 p-0":"h-9 w-9 p-0",s?"border-primary/20 hover:border-primary/40 hover:bg-primary/10 hover:text-primary hover:scale-105 active:scale-95 shadow-sm":"opacity-40 cursor-not-allowed border-transparent",s&&"bg-primary/5",n&&"w-auto px-3"),children:[m.jsx(SI,{className:$e.cn(c,"transition-colors duration-200",s?s?"text-primary":"text-current":"text-muted-foreground")}),n&&m.jsx("span",{className:"ml-2",children:"Undo"})]}),m.jsxs(ce.Button,{variant:o?"outline":"ghost",size:a,onClick:l,disabled:!o,title:`Redo last undone action (${wd("redo")})`,"aria-label":"Redo last undone action",className:$e.cn("transition-all duration-200 border-2",r==="sm"?"h-8 w-8 p-0":r==="lg"?"h-10 w-10 p-0":"h-9 w-9 p-0",o?"border-primary/20 hover:border-primary/40 hover:bg-primary/10 hover:text-primary hover:scale-105 active:scale-95 shadow-sm":"opacity-40 cursor-not-allowed border-transparent",o&&"bg-primary/5",n&&"w-auto px-3"),children:[m.jsx(QL,{className:$e.cn(c,"transition-colors duration-200",o?o?"text-primary":"text-current":"text-muted-foreground")}),n&&m.jsx("span",{className:"ml-2",children:"Redo"})]})]})},Ve=({onClick:t,isActive:e,disabled:n,children:r,title:s,ariaLabel:o,shortcut:i})=>{const l=i?`${s} (${i})`:s;return m.jsx(ce.Button,{variant:e?"default":"ghost",size:"sm",onClick:t,disabled:n,title:l,"aria-label":o||s,className:`h-8 w-8 p-0 transition-all duration-200 ${n?"opacity-40 cursor-not-allowed":"hover:bg-accent hover:text-accent-foreground hover:scale-105"}`,children:r})},H2=({editor:t})=>m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsxs(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2","aria-label":"Font size menu",title:"Font size menu",children:[m.jsx(ss,{className:"h-4 w-4 mr-1"}),"Size"]})}),m.jsx(vt.PopoverContent,{onFocusOutside:e=>e.preventDefault(),className:"w-[360px] p-0",side:"bottom",align:"start",children:m.jsx(bw,{editor:t,className:"p-4"})})]}),$2=({editor:t})=>m.jsxs(vt.Popover,{children:[m.jsx(vt.PopoverTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0","aria-label":"Color menu",title:"Color menu",children:m.jsx(Hh,{className:"h-4 w-4"})})}),m.jsx(vt.PopoverContent,{onFocusOutside:e=>e.preventDefault(),className:"w-[380px] p-0",side:"bottom",align:"start",children:m.jsx(yw,{editor:t,className:"p-4"})})]}),z2=({editor:t})=>{const e=async()=>{const s=rc(t);if(s){const i=await s();i!=null&&i.src&&(t.chain().focus().setImage({src:i.src,alt:i.alt||void 0}).run(),i.blurDataURL&&t.chain().focus().updateAttributes("image",{blurDataURL:i.blurDataURL}).run());return}const o=window.prompt("Enter image URL:");o&&t.chain().focus().setImage({src:o}).run()},n=()=>{t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},r=()=>{const s=window.prompt("Enter URL:");s&&t.chain().focus().setLink({href:s}).run()};return m.jsxs(Ke.DropdownMenu,{children:[m.jsx(Ke.DropdownMenuTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2",children:"Insert"})}),m.jsxs(Ke.DropdownMenuContent,{children:[m.jsxs(Ke.DropdownMenuItem,{onClick:e,children:[m.jsx(es,{className:"h-4 w-4 mr-2"}),"Image"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:n,children:[m.jsx(ui,{className:"h-4 w-4 mr-2"}),"Table"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:r,children:[m.jsx(Ja,{className:"h-4 w-4 mr-2"}),"Link"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setHorizontalRule().run(),children:[m.jsx(Xa,{className:"h-4 w-4 mr-2"}),"Horizontal Rule"]}),m.jsx(Ke.DropdownMenuSeparator,{}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Enter CSS (without <style> tags):","/* your styles */");if(s!=null){const o=`<style>${s}</style>`;t.commands.insertContentAt({from:0,to:0},o)}},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"CSS Block"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Enter JavaScript (without <script> tags):","// your script");if(s!=null){const o=`<script>${s}<\/script>`,i=t.state.doc.content.size;t.commands.insertContentAt(i,o)}},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"Script Block"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>{const s=window.prompt("Optional class for DIV:",""),o=window.prompt("Optional inline style for DIV:",""),i=window.prompt("Optional content for DIV:","New block"),l=`${s?` class="${s}"`:""}${o?` style="${o}"`:""}`,c=i?`<p>${(u=>u.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"))(i)}</p>`:"<p><br /></p>";t.chain().focus().insertContent(`<div${l}>${c}</div>`).run()},children:[m.jsx(Fr,{className:"h-4 w-4 mr-2"}),"DIV Block"]}),m.jsx(Ke.DropdownMenuSeparator,{}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setAlertWidget().run(),children:[m.jsx(Qa,{className:"h-4 w-4 mr-2"}),"Alert Widget"]}),m.jsxs(Ke.DropdownMenuItem,{onClick:()=>t.chain().focus().setCtaWidget({text:"Learn more",url:"",style:"primary",size:"medium",textAlign:"center"}).run(),children:[m.jsx(Ya,{className:"h-4 w-4 mr-2"}),"CTA Widget"]})]})]})},F2=({editor:t})=>{const e=()=>{const s=t.getHTML(),o=new Blob([s],{type:"text/html"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.html",l.click(),URL.revokeObjectURL(i)},n=()=>{const s=JSON.stringify(t.getJSON(),null,2),o=new Blob([s],{type:"application/json"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.json",l.click(),URL.revokeObjectURL(i)},r=()=>{const s=t.getText(),o=new Blob([s],{type:"text/plain"}),i=URL.createObjectURL(o),l=document.createElement("a");l.href=i,l.download="document.txt",l.click(),URL.revokeObjectURL(i)};return m.jsxs(Ke.DropdownMenu,{children:[m.jsx(Ke.DropdownMenuTrigger,{asChild:!0,children:m.jsx(ce.Button,{variant:"ghost",size:"sm",className:"h-8 px-2","aria-label":"Export menu",title:"Export menu",children:m.jsx(Qx,{className:"h-4 w-4 mr-1"})})}),m.jsxs(Ke.DropdownMenuContent,{children:[m.jsx(Ke.DropdownMenuItem,{onClick:e,children:"Export as HTML"}),m.jsx(Ke.DropdownMenuItem,{onClick:n,children:"Export as JSON"}),m.jsx(Ke.DropdownMenuItem,{onClick:r,children:"Export as Text"})]})]})},Jh=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(""),[o,i]=C.useState(!1),[l,a]=C.useState(null),c=C.useRef([]);if(C.useEffect(()=>{if(!t)return;const f=g=>{try{const y=t.getHTML();s(lu(y)),n(!0)}catch{}},p="editor:openSourceView";return window.addEventListener(p,f),()=>window.removeEventListener(p,f)},[t]),!t)return null;const u=()=>{const f=t.getHTML();s(lu(f)),n(!0)},d=()=>{t.chain().focus().setContent(r).run(),n(!1)},h=()=>{for(const w of c.current)try{URL.revokeObjectURL(w)}catch{}c.current=[];const f=t.getHTML(),y=new DOMParser().parseFromString(`<div id="__content__">${f}</div>`,"text/html").body.querySelector("#__content__");Array.from(y.querySelectorAll("script")).forEach(w=>{if(!w.getAttribute("src")){const T=w.textContent||"",k=new Blob([T],{type:"text/javascript"}),N=URL.createObjectURL(k);w.setAttribute("src",N),w.textContent="",c.current.push(N)}});const E=`<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><title>Preview</title></head><body>${y.innerHTML}</body></html>`,S=new Blob([E],{type:"text/html"}),M=URL.createObjectURL(S);c.current.push(M),l&&URL.revokeObjectURL(l),a(M),i(!0)};return m.jsxs("div",{className:"border-b bg-background p-2 relative",children:[m.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[m.jsx("div",{className:"flex items-center gap-1 mr-2 p-1 rounded-md bg-muted/30 border border-border/50",children:m.jsx(Gh,{editor:t,size:"sm",showLabels:!1})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:1}).run(),isActive:t.isActive("heading",{level:1}),title:"Heading 1",children:m.jsx(Ls,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:2}).run(),isActive:t.isActive("heading",{level:2}),title:"Heading 2",children:m.jsx(ai,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleHeading({level:3}).run(),isActive:t.isActive("heading",{level:3}),title:"Heading 3",children:m.jsx(Ga,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBold().run(),isActive:t.isActive("bold"),title:"Bold",children:m.jsx(ga,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleItalic().run(),isActive:t.isActive("italic"),title:"Italic",children:m.jsx(Bh,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleUnderline().run(),isActive:t.isActive("underline"),title:"Underline",children:m.jsx($h,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleStrike().run(),isActive:t.isActive("strike"),title:"Strikethrough",children:m.jsx(ew,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleCode().run(),isActive:t.isActive("code"),title:"Inline Code",children:m.jsx(Fs,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleSubscript().run(),isActive:t.isActive("subscript"),title:"Subscript",children:m.jsx(tw,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleSuperscript().run(),isActive:t.isActive("superscript"),title:"Superscript",children:m.jsx(nw,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("left").run(),isActive:t.isActive({textAlign:"left"}),title:"Align Left",children:m.jsx(Ds,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("center").run(),isActive:t.isActive({textAlign:"center"}),title:"Align Center",children:m.jsx(ii,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("right").run(),isActive:t.isActive({textAlign:"right"}),title:"Align Right",children:m.jsx(li,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().setTextAlign("justify").run(),isActive:t.isActive({textAlign:"justify"}),title:"Justify",children:m.jsx(Ph,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBulletList().run(),isActive:t.isActive("bulletList"),title:"Bullet List",children:m.jsx(Us,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleOrderedList().run(),isActive:t.isActive("orderedList"),title:"Numbered List",children:m.jsx(ci,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleTaskList().run(),isActive:t.isActive("taskList"),title:"Task List",children:m.jsx(Za,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleBlockquote().run(),isActive:t.isActive("blockquote"),title:"Blockquote",children:m.jsx(di,{className:"h-4 w-4"})}),m.jsx(Ve,{onClick:()=>t.chain().focus().toggleCodeBlock().run(),isActive:t.isActive("codeBlock"),title:"Code Block",children:m.jsx(Fr,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(H2,{editor:t}),m.jsx($2,{editor:t}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(z2,{editor:t}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:u,title:"View Source (HTML)",children:m.jsx(ML,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(Ve,{onClick:h,title:"Preview (executes scripts)",children:m.jsx(CL,{className:"h-4 w-4"})}),m.jsx(Jt.Separator,{orientation:"vertical",className:"h-6 mx-1"}),m.jsx(F2,{editor:t})]}),e&&m.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:m.jsxs("div",{className:"bg-background border rounded-md shadow-xl w-[90vw] max-w-4xl h-[70vh] flex flex-col",children:[m.jsx("div",{className:"p-3 border-b font-semibold",children:"Edit HTML Source"}),m.jsx("textarea",{className:"flex-1 p-3 font-mono text-sm outline-none resize-none bg-muted/30",value:r,onChange:f=>s(f.target.value),spellCheck:!1}),m.jsxs("div",{className:"p-3 border-t flex justify-end gap-2",children:[m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:()=>n(!1),children:"Cancel"}),m.jsx(ce.Button,{variant:"secondary",size:"sm",onClick:()=>s(lu(r)),children:"Format"}),m.jsx(ce.Button,{size:"sm",onClick:d,children:"Apply"})]})]})}),o&&m.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",children:m.jsxs("div",{className:"bg-background border rounded-md shadow-xl w-[95vw] max-w-5xl h-[80vh] flex flex-col",children:[m.jsxs("div",{className:"p-3 border-b flex items-center justify-between",children:[m.jsx("div",{className:"font-semibold",children:"Preview"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:()=>{h()},children:"Refresh"}),m.jsx(ce.Button,{size:"sm",onClick:()=>{for(const f of c.current)try{URL.revokeObjectURL(f)}catch{}c.current=[],l&&URL.revokeObjectURL(l),a(null),i(!1)},children:"Close"})]})]}),m.jsx("div",{className:"flex-1",children:m.jsx("iframe",{title:"Editor Preview",className:"w-full h-full",sandbox:"allow-scripts allow-same-origin allow-modals",src:l??void 0})})]})})]})},kw=({editor:t,className:e,onDragStart:n,onDragEnd:r,onNodeChange:s})=>{const o=C.useRef(null);return C.useEffect(()=>{if(!t||!o.current)return;const i=c=>{n==null||n(c)},l=c=>{r==null||r(c)},a=o.current;return a.addEventListener("dragstart",i),a.addEventListener("dragend",l),()=>{a.removeEventListener("dragstart",i),a.removeEventListener("dragend",l)}},[t,n,r]),t?m.jsx("div",{ref:o,className:$e.cn("drag-handle-button","flex items-center justify-center","w-7 h-7 rounded-md border-2","text-slate-500 hover:text-slate-700","border-slate-200/50 hover:border-slate-300","bg-slate-50/50 hover:bg-slate-100/80","active:bg-slate-200/80 active:border-slate-400","cursor-grab active:cursor-grabbing","transition-all duration-200 ease-in-out","opacity-0 group-hover:opacity-100","hover:scale-105 active:scale-95","hover:shadow-sm active:shadow-none","focus:opacity-100 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-1","dark:text-slate-400 dark:hover:text-slate-200","dark:border-slate-700/50 dark:hover:border-slate-600","dark:bg-slate-800/50 dark:hover:bg-slate-700/80","dark:active:bg-slate-600/80 dark:active:border-slate-500",e),role:"button",tabIndex:0,"aria-label":"Drag to reorder this block",title:"Hold and drag to reorder this block",draggable:!0,children:m.jsx(TL,{className:"w-4 h-4"})}):null},Sw=({editor:t,className:e})=>{const[n,r]=C.useState(!1),[s,o]=C.useState("format"),[i,l]=C.useState(!1),a=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||window.innerWidth<=768;C.useEffect(()=>{const h=()=>{r(a())};return h(),window.addEventListener("resize",h),()=>window.removeEventListener("resize",h)},[]),C.useEffect(()=>{if(!t)return;const h=()=>{const{selection:f}=t.state;!f.empty&&a()?r(!0):i||r(!1)};return t.on("selectionUpdate",h),t.on("focus",h),t.on("blur",()=>{i||r(!1)}),()=>{t.off("selectionUpdate",h),t.off("focus",h),t.off("blur",()=>r(!1))}},[t,i]);const c=[{icon:m.jsx(ga,{className:"h-4 w-4"}),label:"Bold",action:()=>t.chain().focus().toggleBold().run(),isActive:()=>t.isActive("bold"),section:"format"},{icon:m.jsx(Bh,{className:"h-4 w-4"}),label:"Italic",action:()=>t.chain().focus().toggleItalic().run(),isActive:()=>t.isActive("italic"),section:"format"},{icon:m.jsx($h,{className:"h-4 w-4"}),label:"Underline",action:()=>t.chain().focus().toggleUnderline().run(),isActive:()=>t.isActive("underline"),section:"format"},{icon:m.jsx(Fs,{className:"h-4 w-4"}),label:"Code",action:()=>t.chain().focus().toggleCode().run(),isActive:()=>t.isActive("code"),section:"format"},{icon:m.jsx(Hh,{className:"h-4 w-4"}),label:"Highlight",action:()=>t.chain().focus().toggleHighlight().run(),isActive:()=>t.isActive("highlight"),section:"format"},{icon:m.jsx(ss,{className:"h-4 w-4"}),label:"Paragraph",action:()=>t.chain().focus().setParagraph().run(),isActive:()=>t.isActive("paragraph"),section:"blocks"},{icon:m.jsx(Ls,{className:"h-4 w-4"}),label:"Heading 1",action:()=>t.chain().focus().toggleHeading({level:1}).run(),isActive:()=>t.isActive("heading",{level:1}),section:"blocks"},{icon:m.jsx(ai,{className:"h-4 w-4"}),label:"Heading 2",action:()=>t.chain().focus().toggleHeading({level:2}).run(),isActive:()=>t.isActive("heading",{level:2}),section:"blocks"},{icon:m.jsx(Ga,{className:"h-4 w-4"}),label:"Heading 3",action:()=>t.chain().focus().toggleHeading({level:3}).run(),isActive:()=>t.isActive("heading",{level:3}),section:"blocks"},{icon:m.jsx(Us,{className:"h-4 w-4"}),label:"Bullet List",action:()=>t.chain().focus().toggleBulletList().run(),isActive:()=>t.isActive("bulletList"),section:"blocks"},{icon:m.jsx(ci,{className:"h-4 w-4"}),label:"Numbered List",action:()=>t.chain().focus().toggleOrderedList().run(),isActive:()=>t.isActive("orderedList"),section:"blocks"},{icon:m.jsx(Za,{className:"h-4 w-4"}),label:"Task List",action:()=>t.chain().focus().toggleTaskList().run(),isActive:()=>t.isActive("taskList"),section:"blocks"},{icon:m.jsx(di,{className:"h-4 w-4"}),label:"Quote",action:()=>t.chain().focus().toggleBlockquote().run(),isActive:()=>t.isActive("blockquote"),section:"blocks"},{icon:m.jsx(Ja,{className:"h-4 w-4"}),label:"Link",action:()=>{const h=window.prompt("Enter URL:");h&&t.chain().focus().setLink({href:h}).run()},isActive:()=>t.isActive("link"),section:"insert"},{icon:m.jsx(es,{className:"h-4 w-4"}),label:"Image",action:async()=>{const h=rc(t);if(h){const p=await h();p!=null&&p.src&&t.chain().focus().setImage({src:p.src,alt:p.alt||void 0}).run();return}const f=window.prompt("Enter image URL:");f&&t.chain().focus().setImage({src:f}).run()},section:"insert"},{icon:m.jsx(ui,{className:"h-4 w-4"}),label:"Table",action:()=>t.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),section:"insert"},{icon:m.jsx(Ds,{className:"h-4 w-4"}),label:"Align Left",action:()=>t.chain().focus().setTextAlign("left").run(),isActive:()=>t.isActive({textAlign:"left"}),section:"align"},{icon:m.jsx(ii,{className:"h-4 w-4"}),label:"Align Center",action:()=>t.chain().focus().setTextAlign("center").run(),isActive:()=>t.isActive({textAlign:"center"}),section:"align"},{icon:m.jsx(li,{className:"h-4 w-4"}),label:"Align Right",action:()=>t.chain().focus().setTextAlign("right").run(),isActive:()=>t.isActive({textAlign:"right"}),section:"align"}],u=[{key:"format",label:"Format",icon:m.jsx(ga,{className:"h-3 w-3"})},{key:"blocks",label:"Blocks",icon:m.jsx(Ls,{className:"h-3 w-3"})},{key:"insert",label:"Insert",icon:m.jsx(es,{className:"h-3 w-3"})},{key:"align",label:"Align",icon:m.jsx(Ds,{className:"h-3 w-3"})}],d=c.filter(h=>h.section===s);return!n&&!i?null:m.jsxs("div",{className:$e.cn("fixed bottom-0 left-0 right-0 z-50 bg-background border-t border-border shadow-lg","transform transition-transform duration-300 ease-in-out",n||i?"translate-y-0":"translate-y-full",e),children:[m.jsx("div",{className:"flex justify-center py-2 border-b border-border",children:m.jsxs(ce.Button,{variant:"ghost",size:"sm",onClick:()=>l(!i),className:"flex items-center gap-2",children:[i?m.jsx(ow,{className:"h-4 w-4"}):m.jsx(KL,{className:"h-4 w-4"}),m.jsx("span",{className:"text-xs",children:i?"Close":"Tools"})]})}),(i||n)&&m.jsxs(m.Fragment,{children:[m.jsx("div",{className:"flex border-b border-border bg-muted/50",children:u.map(h=>m.jsx(ce.Button,{variant:s===h.key?"default":"ghost",size:"sm",onClick:()=>o(h.key),className:"flex-1 rounded-none text-xs py-2 h-auto",children:m.jsxs("div",{className:"flex flex-col items-center gap-1",children:[h.icon,m.jsx("span",{children:h.label})]})},h.key))}),m.jsx("div",{className:"p-2",children:m.jsx("div",{className:"flex flex-wrap gap-1 justify-center",children:d.map((h,f)=>{var p;return m.jsxs(ce.Button,{variant:(p=h.isActive)!=null&&p.call(h)?"default":"ghost",size:"sm",onClick:h.action,className:"flex flex-col items-center gap-1 h-auto py-2 px-3 min-w-[60px]",title:h.label,children:[h.icon,m.jsx("span",{className:"text-xs",children:h.label})]},f)})})})]}),m.jsx("div",{className:"h-safe-area-inset-bottom"})]})},sc=({content:t,onChange:e,placeholder:n,editable:r=!0,showToolbar:s=!0,showCharacterCount:o=!0,className:i,onFocus:l,onBlur:a,useEnhancedFloatingMenu:c=!0,showMobileToolbar:u=!0,enableAdvancedPlaceholders:d=!0,enableFocusMode:h=!1,showKeyboardShortcuts:f=!1})=>{var T,k,N;const p=C.useRef(null),[g,y]=C.useState({isOpen:!1,searchTerm:"",replaceTerm:"",currentMatch:0,totalMatches:0,caseSensitive:!1,wholeWord:!1}),b=wb({extensions:Fh,content:t,editable:r,immediatelyRender:!1,onUpdate:({editor:R})=>{e(R.getHTML())},onFocus:()=>{l==null||l()},onBlur:()=>{a==null||a()},editorProps:{attributes:{class:$e.cn("prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl","mx-auto focus:outline-none p-4 min-h-[500px] w-full","prose-headings:scroll-mt-[80px] prose-headings:font-semibold","prose-h1:text-4xl prose-h2:text-3xl prose-h3:text-2xl","prose-p:leading-7 prose-li:leading-7","prose-pre:bg-muted prose-pre:border prose-pre:rounded-lg","prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded","prose-blockquote:border-l-4 prose-blockquote:border-primary prose-blockquote:pl-4","prose-table:border-collapse prose-table:border prose-table:border-border","prose-th:border prose-th:border-border prose-th:bg-muted prose-th:p-2","prose-td:border prose-td:border-border prose-td:p-2","prose-img:rounded-lg prose-img:shadow-sm",i)},handleKeyDown:(R,B)=>{if(B.ctrlKey||B.metaKey)switch(B.key){case"f":return B.preventDefault(),y(P=>({...P,isOpen:!P.isOpen})),!0;case"s":return B.preventDefault(),!0;default:return!1}return!1}}});C.useEffect(()=>{if(!b)return;const R=b.getHTML();if(t!==R){const{from:B,to:P}=b.state.selection;b.commands.setContent(t,{emitUpdate:!1}),b.commands.setTextSelection({from:B,to:P})}},[t,b]);const x=R=>{if(!b||!R){y(oe=>({...oe,totalMatches:0,currentMatch:0}));return}const B=b.getText(),P=g.caseSensitive?"g":"gi",L=g.wholeWord?`\\b${R}\\b`:R,H=new RegExp(L,P),se=B.match(H);y(oe=>({...oe,totalMatches:se?se.length:0,currentMatch:se?1:0}))},E=()=>{if(!b||!g.searchTerm)return;const R=b.getHTML(),B=g.caseSensitive?"g":"gi",P=g.wholeWord?`\\b${g.searchTerm}\\b`:g.searchTerm,L=new RegExp(P,B),H=R.replace(L,g.replaceTerm);b.commands.setContent(H),y(se=>({...se,totalMatches:0,currentMatch:0}))};if(!b)return null;const S=(T=b.storage)==null?void 0:T.characterCount,M=((k=S==null?void 0:S.characters)==null?void 0:k.call(S))??0,w=((N=S==null?void 0:S.words)==null?void 0:N.call(S))??0;return m.jsxs("div",{ref:p,className:$e.cn("relative w-full rounded-lg border bg-background shadow-sm","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",i),children:[s&&m.jsx(Jh,{editor:b}),g.isOpen&&m.jsxs("div",{className:"border-b bg-muted/50 p-3",children:[m.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[m.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[m.jsx(cI,{className:"h-4 w-4 text-muted-foreground"}),m.jsx(ps.Input,{placeholder:"Search...",value:g.searchTerm,onChange:R=>{const B=R.target.value;y(P=>({...P,searchTerm:B})),x(B)},className:"h-8"}),m.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:g.totalMatches>0?`${g.currentMatch}/${g.totalMatches}`:"No matches"})]}),m.jsx(ce.Button,{variant:"ghost",size:"sm",onClick:()=>y(R=>({...R,isOpen:!1})),children:m.jsx(ow,{className:"h-4 w-4"})})]}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx(tI,{className:"h-4 w-4 text-muted-foreground"}),m.jsx(ps.Input,{placeholder:"Replace with...",value:g.replaceTerm,onChange:R=>y(B=>({...B,replaceTerm:R.target.value})),className:"h-8 flex-1"}),m.jsx(ce.Button,{variant:"outline",size:"sm",onClick:E,disabled:!g.searchTerm||g.totalMatches===0,children:"Replace All"})]})]}),m.jsx(Wh,{editor:b}),c?m.jsx(xw,{editor:b,wrapperRef:p}):m.jsx(qh,{editor:b}),m.jsx(kw,{editor:b,onDragStart:R=>{console.log("Drag started:",R),document.body.classList.add("dragging")},onDragEnd:R=>{console.log("Drag ended:",R),document.body.classList.remove("dragging")},onNodeChange:({node:R,editor:B,pos:P})=>{R&&console.log("Hovering over node:",R.type.name,"at position:",P)}}),m.jsx(bb,{editor:b}),o&&S&&m.jsxs("div",{className:"absolute bottom-2 right-2 z-10 text-xs text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border",children:[M," characters / ",w," words"]}),f&&m.jsxs("div",{className:"absolute bottom-2 left-2 text-xs text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border opacity-0 hover:opacity-100 transition-opacity",children:[m.jsx("div",{children:"Ctrl+F: Search"}),m.jsx("div",{children:"Ctrl+S: Save"}),m.jsx("div",{children:"/: Commands"}),m.jsx("div",{children:"Ctrl+K: Insert Link"}),m.jsx("div",{children:"Ctrl+Shift+H: Highlight"}),m.jsx("div",{children:"Ctrl+Alt+1-6: Headings"})]}),u&&m.jsx(Sw,{editor:b})]})},U2=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),{x:o,y:i,refs:l,strategy:a,update:c}=fi({placement:"top",strategy:"fixed",open:e,onOpenChange:n,middleware:[hi(-12)],whileElementsMounted:Bs}),u=C.useCallback(()=>t.isActive("image"),[t]),d=t.getAttributes("image")||{},h=C.useCallback(()=>{const{state:y,view:b}=t,x=()=>{var M,w;try{if(y.selection instanceof K){const N=b.nodeDOM(y.selection.from);if(N){const R=((M=N.closest)==null?void 0:M.call(N,".tiptap-image-wrapper"))??N;return R.querySelector("img")??R}}const T=b.dom.querySelector(".tiptap-image-wrapper.ProseMirror-selectednode");if(T)return T.querySelector("img")??T;const k=b.dom.querySelector(".ProseMirror-selectednode");if(k){const N=((w=k.closest)==null?void 0:w.call(k,".tiptap-image-wrapper"))??k;return N.querySelector("img")??N}}catch{}return null},E=h._lastEl,S=x()??E;if(S){h._lastEl=S;const M={getBoundingClientRect:()=>{const w=x()??h._lastEl;return w?w.getBoundingClientRect():new DOMRect(0,0,0,0)}};l.setReference(M)}else{const M=b.coordsAtPos(y.selection.from),w={getBoundingClientRect:()=>new DOMRect(M.left,M.top,0,0)};l.setReference(w)}requestAnimationFrame(()=>{c(),requestAnimationFrame(()=>s(!0))})},[t,l,c]);if(C.useEffect(()=>{const y=()=>{const b=u();n(b),s(!1),b&&h()};return y(),t.on("selectionUpdate",y),t.on("transaction",y),t.on("focus",y),t.on("blur",()=>n(!1)),()=>{t.off("selectionUpdate",y),t.off("transaction",y),t.off("focus",y)}},[t,u,h]),!e)return null;const f=y=>{t.chain().focus().updateAttributes("image",{align:y}).run(),requestAnimationFrame(()=>h())},p=()=>{t.chain().focus().deleteSelection().run()},g=()=>{const y=d==null?void 0:d.src;if(y)try{const b=document.createElement("a");b.href=y;const x=(y.split("?")[0]||"").split("/").pop()||"image";b.download=x,document.body.appendChild(b),b.click(),b.remove()}catch{}};return m.jsxs("div",{ref:l.setFloating,style:{position:a,top:i??0,left:o??0,zIndex:10002,visibility:r?"visible":"hidden",pointerEvents:"auto"},className:"bg-background/95 backdrop-blur border rounded-full shadow-lg px-3 py-2 flex items-center gap-1",onMouseDown:y=>y.preventDefault(),children:[m.jsx(ce.Button,{size:"icon",variant:d.align==="left"?"default":"ghost",title:"Align left",onClick:()=>f("left"),children:m.jsx(Ds,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:d.align==="center"?"default":"ghost",title:"Align center",onClick:()=>f("center"),children:m.jsx(ii,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:d.align==="right"?"default":"ghost",title:"Align right",onClick:()=>f("right"),children:m.jsx(li,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",title:"Download",onClick:g,children:m.jsx(Qx,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",title:"Delete",onClick:p,children:m.jsx(rw,{className:"h-4 w-4"})})]})},cg=t=>t.isActive("table")||t.isActive("tableCell")||t.isActive("tableHeader")||t.isActive("tableRow"),V2=({editor:t})=>{const[e,n]=C.useState(!1),[r,s]=C.useState(!1),{refs:o,x:i,y:l,strategy:a,update:c}=fi({placement:"bottom",strategy:"fixed",middleware:[hi(12),tc(),ec()],whileElementsMounted:Bs,open:e,onOpenChange:n}),u=C.useCallback(()=>{var R;const{state:k,view:N}=t;try{const{from:B}=k.selection,{node:P}=N.domAtPos(B);let L=null;return P.nodeType===Node.ELEMENT_NODE?L=P:(P.nodeType===Node.TEXT_NODE||P!=null&&P.parentElement)&&(L=P.parentElement),((R=L==null?void 0:L.closest)==null?void 0:R.call(L,"td, th"))??null}catch{return null}},[t]),d=C.useCallback(()=>{const k=u();return(k==null?void 0:k.closest("table"))??null},[u]),h=C.useCallback(()=>{if(!cg(t)){n(!1);return}const k=d();if(!k){n(!1);return}o.setReference(k),n(!0),s(!1),requestAnimationFrame(()=>{c(),requestAnimationFrame(()=>s(!0))})},[t,o,d,c]);if(C.useEffect(()=>{const k=()=>{cg(t)?h():n(!1)},N=()=>n(!1);return k(),t.on("selectionUpdate",k),t.on("transaction",k),t.on("focus",k),t.on("blur",N),()=>{t.off("selectionUpdate",k),t.off("transaction",k),t.off("focus",k),t.off("blur",N)}},[t,h]),!e)return null;const f=t.can(),p=typeof f.addRowAfter=="function"?f.addRowAfter():!1,g=typeof f.deleteRow=="function"?f.deleteRow():!1,y=typeof f.addColumnAfter=="function"?f.addColumnAfter():!1,b=typeof f.deleteColumn=="function"?f.deleteColumn():!1,x=typeof f.deleteTable=="function"?f.deleteTable():!1,E=()=>{t.chain().focus().addRowAfter().run(),h()},S=()=>{t.chain().focus().deleteRow().run(),h()},M=()=>{t.chain().focus().addColumnAfter().run(),h()},w=()=>{t.chain().focus().deleteColumn().run(),h()},T=()=>{t.chain().focus().deleteTable().run(),n(!1)};return m.jsxs("div",{ref:o.setFloating,style:{position:a,top:l??0,left:i??0,zIndex:10002,visibility:r?"visible":"hidden"},className:"flex items-center gap-1 rounded-full border bg-background/95 px-2 py-1 shadow-lg",onMouseDown:k=>k.preventDefault(),children:[m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:E,disabled:!p,title:"Add row below","aria-label":"Add row below",children:m.jsx(lI,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:S,disabled:!g,title:"Delete current row","aria-label":"Delete current row",children:m.jsx(oI,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:M,disabled:!y,title:"Add column to the right","aria-label":"Add column to the right",children:m.jsx(xL,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:w,disabled:!b,title:"Delete current column","aria-label":"Delete current column",children:m.jsx(yL,{className:"h-4 w-4"})}),m.jsx(ce.Button,{size:"icon",variant:"ghost",onClick:T,disabled:!x,title:"Delete table","aria-label":"Delete table",children:m.jsx(rw,{className:"h-4 w-4"})})]})},Cw=({content:t,onChange:e,placeholder:n,editable:r=!0,showToolbar:s=!0,showCharacterCount:o=!0,className:i,onFocus:l,onBlur:a,openImagePicker:c})=>{var g,y,b;const u=C.useRef(null),d=wb({extensions:Fh,content:t,editable:r,immediatelyRender:!1,onUpdate:({editor:x})=>e(x.getHTML()),onFocus:()=>{l==null||l()},onBlur:()=>{a==null||a()},editorProps:{attributes:{class:$e.cn("prose dark:prose-invert prose-sm sm:prose-base lg:prose-lg xl:prose-2xl","mx-auto focus:outline-none min-h-[500px] w-full","pl-12 pr-4 py-4","prose-headings:scroll-mt-[80px] prose-headings:font-semibold","prose-h1:text-4xl prose-h2:text-3xl prose-h3:text-2xl","prose-p:leading-7 prose-li:leading-7","prose-pre:bg-muted prose-pre:border prose-pre:rounded-lg","prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:rounded","prose-blockquote:border-l-4 prose-blockquote:border-primary prose-blockquote:pl-4","prose-table:border-collapse prose-table:border prose-table:border-border","prose-th:border prose-th:border-border prose-th:bg-muted prose-th:p-2","prose-td:border prose-td:border-border prose-td:p-2","prose-img:rounded-lg prose-img:shadow-sm")}}});if(C.useEffect(()=>{if(d)return sg(d,c),()=>sg(d,void 0)},[d,c]),C.useEffect(()=>{if(!d)return;const x=d.getHTML();if(t!==x){const{from:E,to:S}=d.state.selection;d.commands.setContent(t,{emitUpdate:!1}),d.commands.setTextSelection({from:E,to:S})}},[t,d]),!d)return null;const h=(g=d.storage)==null?void 0:g.characterCount,f=((y=h==null?void 0:h.characters)==null?void 0:y.call(h))??0,p=((b=h==null?void 0:h.words)==null?void 0:b.call(h))??0;return m.jsxs("div",{ref:u,className:$e.cn("relative w-full rounded-lg border bg-background shadow-sm","flex flex-col h-full min-h-0","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",i),children:[s&&m.jsx(Jh,{editor:d}),m.jsx(Wh,{editor:d}),m.jsx(qh,{editor:d}),m.jsx(U2,{editor:d}),m.jsx(V2,{editor:d}),m.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.jsx(bb,{editor:d})}),o&&h&&m.jsxs("div",{className:"absolute bottom-2 right-2 text-xs z-10 text-muted-foreground bg-background/80 backdrop-blur-sm rounded px-2 py-1 border",children:[f," characters / ",p," words"]})]})},Ew=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("flex items-center gap-1 rounded-md bg-background p-1",t),...e}));Ew.displayName="Toolbar";const Mw=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("flex items-center gap-1",t),...e}));Mw.displayName="ToolbarGroup";const Aw=C.forwardRef(({className:t,isActive:e,...n},r)=>m.jsx("button",{ref:r,className:$e.cn("inline-flex items-center justify-center rounded-md p-1.5 text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",{"bg-accent text-accent-foreground":e},t),...n}));Aw.displayName="ToolbarButton";const Tw=C.forwardRef(({className:t,...e},n)=>m.jsx("div",{ref:n,className:$e.cn("mx-1 h-7 w-px bg-muted",t),...e}));Tw.displayName="ToolbarSeparator";const W2=({html:t,className:e})=>{const n=C.useRef(null);return C.useEffect(()=>{const r=n.current;if(!r)return;r.innerHTML=t;const s=[];return Array.from(r.querySelectorAll("script")).forEach(i=>{var a;const l=document.createElement("script");for(const c of Array.from(i.attributes))l.setAttribute(c.name,c.value);if(i.src)l.src=i.src;else{const c=i.textContent||"",u=new Blob([c],{type:l.type||"text/javascript"}),d=URL.createObjectURL(u);l.src=d,l.async=!1,s.push(d)}(a=i.parentNode)==null||a.insertBefore(l,i),i.remove()}),()=>{s.forEach(i=>{try{URL.revokeObjectURL(i)}catch(l){process.env.NODE_ENV!=="production"&&console.warn("Failed to revoke object URL",i,l)}})}},[t]),m.jsx("div",{ref:n,className:e})},q2=fe.create({name:"enhancedFocus",addOptions(){return{className:"has-focus",mode:"all",showFocusRing:!0,highlightSelection:!0,dimUnfocused:!1,animateTransitions:!0}},addProseMirrorPlugins(){return[new me({key:new ye("enhancedFocus"),props:{decorations:({doc:t,selection:e})=>{const{from:n,to:r}=e,s=[];if(t.nodesBetween(n,r,(o,i)=>{const l=De.node(i,i+o.nodeSize,{class:this.options.className});s.push(l)}),this.options.highlightSelection&&n!==r){const o=De.inline(n,r,{class:"selection-highlight"});s.push(o)}if(this.options.showFocusRing){const o=De.widget(n,()=>{const i=document.createElement("div");return i.className="focus-ring",i});s.push(o)}return be.create(t,s)}},view:()=>({update:(t,e)=>{const{state:n}=t,{selection:r}=n,s=e.selection;r.eq(s)||this.editor.emit("selectionUpdate",{editor:this.editor,transaction:n.tr})}})})]},addGlobalAttributes(){return[{types:["paragraph","heading","blockquote","codeBlock","listItem"],attributes:{"data-focused":{default:null,renderHTML:t=>t["data-focused"]?{"data-focused":t["data-focused"]}:{}}}}]},onCreate(){const t=this.editor.view.dom;this.options.animateTransitions&&t.classList.add("focus-transitions"),this.options.dimUnfocused&&t.classList.add("dim-unfocused")},onSelectionUpdate(){const{state:t}=this.editor,{selection:e}=t,{from:n,to:r}=e,s=t.tr;let o=!1;t.doc.descendants((i,l)=>{if(i.isText||i.isLeaf)return;const a=l,c=l+i.nodeSize,u=n>=a&&r<=c,d=i.attrs["data-focused"];u&&!d?(s.setNodeMarkup(l,void 0,{...i.attrs,"data-focused":"true"}),o=!0):!u&&d&&(s.setNodeMarkup(l,void 0,{...i.attrs,"data-focused":null}),o=!0)}),o&&this.editor.view.dispatch(s)},addStorage(){return{isFocused:!1}},onFocus(){this.editor.view.dom.classList.add("editor-focused"),this.storage.isFocused=!0},onBlur(){this.editor.view.dom.classList.remove("editor-focused"),this.storage.isFocused=!1}}),K2=fe.create({name:"keyboardShortcuts",addOptions(){return{enableAdvancedShortcuts:!0,enableCustomShortcuts:!0,showShortcutHints:!1}},addKeyboardShortcuts(){const t={};return this.options.enableAdvancedShortcuts&&(t["Mod-Shift-x"]=()=>this.editor.commands.toggleStrike(),t["Mod-Shift-h"]=()=>this.editor.commands.toggleHighlight(),t["Mod-Shift-c"]=()=>this.editor.commands.toggleCode(),t["Mod-Alt-1"]=()=>this.editor.commands.toggleHeading({level:1}),t["Mod-Alt-2"]=()=>this.editor.commands.toggleHeading({level:2}),t["Mod-Alt-3"]=()=>this.editor.commands.toggleHeading({level:3}),t["Mod-Alt-4"]=()=>this.editor.commands.toggleHeading({level:4}),t["Mod-Alt-5"]=()=>this.editor.commands.toggleHeading({level:5}),t["Mod-Alt-6"]=()=>this.editor.commands.toggleHeading({level:6}),t["Mod-Alt-0"]=()=>this.editor.commands.setParagraph(),t["Mod-Shift-8"]=()=>this.editor.commands.toggleBulletList(),t["Mod-Shift-7"]=()=>this.editor.commands.toggleOrderedList(),t["Mod-Shift-9"]=()=>this.editor.commands.toggleTaskList(),t["Mod-Shift-b"]=()=>this.editor.commands.toggleBlockquote(),t["Mod-Alt-c"]=()=>this.editor.commands.toggleCodeBlock(),t["Mod-Shift-minus"]=()=>this.editor.commands.setHorizontalRule(),t["Mod-Shift-l"]=()=>this.editor.commands.setTextAlign("left"),t["Mod-Shift-e"]=()=>this.editor.commands.setTextAlign("center"),t["Mod-Shift-r"]=()=>this.editor.commands.setTextAlign("right"),t["Mod-Shift-j"]=()=>this.editor.commands.setTextAlign("justify"),t["Mod-comma"]=()=>this.editor.commands.toggleSubscript(),t["Mod-period"]=()=>this.editor.commands.toggleSuperscript(),t["Mod-Alt-t"]=()=>this.editor.can().insertTable()?this.editor.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}):!1,t["Mod-Home"]=()=>this.editor.commands.focus("start"),t["Mod-End"]=()=>this.editor.commands.focus("end"),t["Mod-a"]=()=>this.editor.commands.selectAll(),t["Mod-\\"]=()=>this.editor.commands.unsetAllMarks()&&this.editor.commands.clearNodes(),t["Mod-k"]=()=>{const e=window.prompt("Enter URL:");return e?this.editor.commands.setLink({href:e}):!1},t["Mod-Shift-i"]=()=>{const e=window.prompt("Enter image URL:");return e?this.editor.commands.setImage({src:e}):!1},t["Alt-ArrowUp"]=()=>{const{selection:e}=this.editor.state,{$from:n}=e,r=n.nodeBefore;if(r){const s=n.pos-r.nodeSize;return this.editor.commands.setTextSelection(s)}return!1},t["Alt-ArrowDown"]=()=>{const{selection:e}=this.editor.state,{$to:n}=e,r=n.nodeAfter;if(r){const s=n.pos+r.nodeSize;return this.editor.commands.setTextSelection(s)}return!1},t["Mod-Shift-d"]=()=>{const{selection:e}=this.editor.state,{from:n,to:r}=e,s=this.editor.state.doc.textBetween(n,r);return s?this.editor.commands.insertContentAt(r,`
|
|
472
472
|
${s}`):!1},t["Mod-Shift-k"]=()=>{const{selection:e}=this.editor.state,{$from:n,$to:r}=e,s=n.start(),o=r.end();return this.editor.commands.deleteRange({from:s,to:o})},t["Mod-Backspace"]=()=>{const{selection:e}=this.editor.state,{from:n}=e,r=this.editor.state.doc.resolve(n);let s=n;const o=r.parent.textContent,i=r.parentOffset;for(let l=i-1;l>=0;l--){if(/\s/.test(o[l])){s=n-(i-l-1);break}l===0&&(s=n-i)}return this.editor.commands.deleteRange({from:s,to:n})},t["Mod-Delete"]=()=>{const{selection:e}=this.editor.state,{to:n}=e,r=this.editor.state.doc.resolve(n);let s=n;const o=r.parent.textContent,i=r.parentOffset;for(let l=i;l<o.length;l++){if(/\s/.test(o[l])){s=n+(l-i);break}l===o.length-1&&(s=n+(o.length-i))}return this.editor.commands.deleteRange({from:n,to:s})}),this.options.enableCustomShortcuts&&(t["Mod-Shift-a"]=()=>this.editor.can().setAlertWidget()?this.editor.commands.setAlertWidget():!1,t["Mod-Shift-t"]=()=>this.editor.can().setCtaWidget()?this.editor.commands.setCtaWidget({text:"Click me",url:"#",style:"primary",size:"medium",textAlign:"center"}):!1,t["Mod-Shift-f"]=()=>(this.editor.view.dom.classList.toggle("focus-mode"),!0),t["Mod-Shift-w"]=()=>(this.editor.view.dom.classList.toggle("writing-mode"),!0),t["Mod-Shift-u"]=()=>{const{selection:e}=this.editor.state,{from:n,to:r}=e,s=this.editor.state.doc.textBetween(n,r);return s?this.editor.commands.insertContentAt({from:n,to:r},s.toUpperCase()):!1},t["Mod-Shift-l"]=()=>{const{selection:e}=this.editor.state,{from:n,to:r}=e,s=this.editor.state.doc.textBetween(n,r);return s?this.editor.commands.insertContentAt({from:n,to:r},s.toLowerCase()):!1},t["Mod-Shift-p"]=()=>{const{selection:e}=this.editor.state,{from:n,to:r}=e,s=this.editor.state.doc.textBetween(n,r);if(s){const o=s.replace(/\w\S*/g,i=>i.charAt(0).toUpperCase()+i.substr(1).toLowerCase());return this.editor.commands.insertContentAt({from:n,to:r},o)}return!1}),t},addStorage(){return{shortcuts:{},hints:[]}},onCreate(){this.options.showShortcutHints&&(this.storage.shortcuts={},this.storage.hints=[{category:"Text Formatting",shortcuts:[{keys:"Cmd/Ctrl + B",action:"Bold"},{keys:"Cmd/Ctrl + I",action:"Italic"},{keys:"Cmd/Ctrl + U",action:"Underline"},{keys:"Cmd/Ctrl + Shift + X",action:"Strikethrough"},{keys:"Cmd/Ctrl + Shift + H",action:"Highlight"},{keys:"Cmd/Ctrl + E",action:"Inline Code"}]},{category:"Headings",shortcuts:[{keys:"Cmd/Ctrl + Alt + 1-6",action:"Heading 1-6"},{keys:"Cmd/Ctrl + Alt + 0",action:"Paragraph"}]},{category:"Lists",shortcuts:[{keys:"Cmd/Ctrl + Shift + 8",action:"Bullet List"},{keys:"Cmd/Ctrl + Shift + 7",action:"Numbered List"},{keys:"Cmd/Ctrl + Shift + 9",action:"Task List"}]},{category:"Blocks",shortcuts:[{keys:"Cmd/Ctrl + Shift + B",action:"Blockquote"},{keys:"Cmd/Ctrl + Alt + C",action:"Code Block"},{keys:"Cmd/Ctrl + Alt + T",action:"Table"}]},{category:"Navigation",shortcuts:[{keys:"Cmd/Ctrl + A",action:"Select All"},{keys:"Cmd/Ctrl + Home",action:"Go to Start"},{keys:"Cmd/Ctrl + End",action:"Go to End"}]},{category:"Advanced",shortcuts:[{keys:"Cmd/Ctrl + K",action:"Insert Link"},{keys:"Cmd/Ctrl + Shift + I",action:"Insert Image"},{keys:"Cmd/Ctrl + \\",action:"Clear Formatting"}]}])}}),G2=()=>{const[t,e]=C.useState("<p>Start testing...</p>"),[n,r]=C.useState([]),[s,o]=C.useState(!1),[i,l]=C.useState(""),a=w=>({name:w,tests:[],status:"pending"}),c=(w,T)=>{r(k=>k.map(N=>{if(N.name===w){const R=[...N.tests,T],B=R.some(H=>H.status==="fail"),P=R.some(H=>H.status==="warning"),L=R.every(H=>H.status!=="pending");return{...N,tests:R,status:B?"fail":P?"warning":L?"pass":"pending"}}return N}))},u=w=>new Promise(T=>setTimeout(T,w)),d=async()=>{var T,k;const w="Drag and Drop";l(w);try{const N=document.querySelectorAll(".drag-handle, .drag-handle-button");c(w,{name:"Drag Handle Presence",status:N.length>0?"pass":"fail",message:N.length>0?"Drag handles found":"No drag handles detected",details:`Found ${N.length} drag handle elements`});const R=((k=(T=document.querySelector("style"))==null?void 0:T.textContent)==null?void 0:k.includes("drag-handle"))||Array.from(document.styleSheets).some(P=>{try{return Array.from(P.cssRules).some(L=>L.cssText.includes("drag-handle"))}catch{return!1}});c(w,{name:"Drag Handle CSS",status:R?"pass":"warning",message:R?"Drag handle CSS loaded":"Drag handle CSS may not be loaded",details:"Check if drag-handle.css is properly imported"});const B=document.querySelectorAll('[data-draggable="true"]');c(w,{name:"Draggable Nodes",status:B.length>0?"pass":"warning",message:B.length>0?"Draggable nodes found":"No draggable nodes detected",details:`Found ${B.length} draggable nodes`})}catch(N){c(w,{name:"Drag and Drop Test",status:"fail",message:"Test failed with error",details:N instanceof Error?N.message:"Unknown error"})}},h=async()=>{const w="Undo/Redo System";l(w);try{const T=document.querySelectorAll('[aria-label*="Undo"], [title*="Undo"]'),k=document.querySelectorAll('[aria-label*="Redo"], [title*="Redo"]');c(w,{name:"Undo/Redo Buttons",status:T.length>0&&k.length>0?"pass":"fail",message:`Found ${T.length} undo and ${k.length} redo buttons`,details:"Undo/Redo buttons should be present in toolbar"}),e("<p>Test content for undo</p>"),await u(100),c(w,{name:"History State Change",status:"pass",message:"Content change detected",details:"History system should track this change"});const N=typeof document<"u"&&document.addEventListener!==void 0;c(w,{name:"Keyboard Shortcuts",status:N?"pass":"warning",message:"Keyboard event system available",details:"Ctrl+Z and Ctrl+Y shortcuts should work"})}catch(T){c(w,{name:"Undo/Redo Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},f=async()=>{const w="Enhanced Floating Menu";l(w);try{const T=document.querySelectorAll('[aria-label*="Insert"], .enhanced-floating-menu');c(w,{name:"Floating Menu Trigger",status:T.length>0?"pass":"warning",message:T.length>0?"Floating menu trigger found":"No floating menu trigger detected",details:"Should appear on empty paragraphs"});const k=document.querySelectorAll('input[placeholder*="Search"], .search-input');c(w,{name:"Search Functionality",status:k.length>0?"pass":"warning",message:k.length>0?"Search input found":"Search input not visible",details:"Search should be available when menu is open"});const N=document.querySelectorAll("[data-category], .category-button");c(w,{name:"Category Filters",status:N.length>0?"pass":"warning",message:N.length>0?"Category filters found":"Category filters not visible",details:"Should have Basic, Headings, Lists, Media, Advanced categories"})}catch(T){c(w,{name:"Enhanced Floating Menu Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},p=async()=>{const w="Advanced Placeholders";l(w);try{const T=Array.from(document.styleSheets).some(R=>{try{return Array.from(R.cssRules).some(B=>B.cssText.includes("is-empty")||B.cssText.includes("placeholder"))}catch{return!1}});c(w,{name:"Placeholder CSS",status:T?"pass":"warning",message:T?"Placeholder CSS loaded":"Placeholder CSS may not be loaded",details:"Check if advanced-features.css is properly imported"});const k=document.querySelectorAll(".is-empty, .is-editor-empty");c(w,{name:"Empty Node Detection",status:k.length>=0?"pass":"warning",message:`Found ${k.length} empty nodes`,details:"Empty nodes should have placeholder classes"}),e("<p></p>"),await u(100);const N=document.querySelectorAll("[data-placeholder]");c(w,{name:"Placeholder Content",status:N.length>0?"pass":"warning",message:N.length>0?"Placeholder content found":"No placeholder content detected",details:"Should show contextual placeholders for different node types"})}catch(T){c(w,{name:"Advanced Placeholders Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},g=async()=>{const w="Focus Management";l(w);try{const T=document.querySelectorAll(".has-focus, .editor-focused");c(w,{name:"Focus Classes",status:T.length>=0?"pass":"warning",message:`Found ${T.length} focus elements`,details:"Focus classes should be applied to active elements"});const k=document.querySelectorAll(".focus-ring");c(w,{name:"Focus Ring",status:k.length>=0?"pass":"warning",message:`Found ${k.length} focus rings`,details:"Focus rings provide visual feedback"}),c(w,{name:"Selection Highlighting",status:"pass",message:"Selection highlighting system available",details:"Enhanced selection visibility should work"})}catch(T){c(w,{name:"Focus Management Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},y=async()=>{const w="Mobile Experience";l(w);try{const T=document.querySelectorAll('.mobile-toolbar, [class*="mobile"]');c(w,{name:"Mobile Toolbar",status:T.length>0?"pass":"warning",message:T.length>0?"Mobile toolbar found":"Mobile toolbar not detected",details:"Should appear on mobile devices or small screens"});const k=Array.from(document.styleSheets).some(R=>{try{return Array.from(R.cssRules).some(B=>B.cssText.includes("@media")&&B.cssText.includes("768px"))}catch{return!1}});c(w,{name:"Responsive CSS",status:k?"pass":"warning",message:k?"Responsive CSS found":"Responsive CSS may not be loaded",details:"Should have mobile breakpoints"});const N=document.querySelectorAll('[class*="touch"], .toolbar-item');c(w,{name:"Touch-Friendly Elements",status:N.length>0?"pass":"warning",message:N.length>0?"Touch-friendly elements found":"No touch-friendly elements detected",details:"Should have larger touch targets for mobile"})}catch(T){c(w,{name:"Mobile Experience Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},b=async()=>{const w="Keyboard Shortcuts";l(w);try{c(w,{name:"Keyboard Shortcuts Available",status:"pass",message:`${["Ctrl+B","Ctrl+I","Ctrl+U","Ctrl+Shift+X","Ctrl+Shift+H","Ctrl+Alt+1","Ctrl+Alt+2","Ctrl+Alt+3","Ctrl+K","Ctrl+\\"].length} keyboard shortcuts configured`,details:"Text formatting, headings, lists, and advanced shortcuts"});const k=document.querySelectorAll('[title*="Ctrl"], [title*="Cmd"]');c(w,{name:"Shortcut Hints",status:k.length>0?"pass":"warning",message:k.length>0?"Shortcut hints found":"No shortcut hints detected",details:"Tooltips should show keyboard shortcuts"}),c(w,{name:"Conflict Prevention",status:"pass",message:"Keyboard shortcuts use standard patterns",details:"Should not conflict with browser shortcuts"})}catch(T){c(w,{name:"Keyboard Shortcuts Test",status:"fail",message:"Test failed with error",details:T instanceof Error?T.message:"Unknown error"})}},x=async()=>{o(!0),r([a("Drag and Drop"),a("Undo/Redo System"),a("Enhanced Floating Menu"),a("Advanced Placeholders"),a("Focus Management"),a("Mobile Experience"),a("Keyboard Shortcuts")]);try{await d(),await u(500),await h(),await u(500),await f(),await u(500),await p(),await u(500),await g(),await u(500),await y(),await u(500),await b()}catch(w){console.error("Test suite failed:",w)}finally{o(!1),l("")}},E=()=>{r([]),e("<p>Start testing...</p>"),l("")},S=w=>{switch(w){case"pass":return m.jsx(cL,{className:"h-4 w-4 text-green-500"});case"fail":return m.jsx(fL,{className:"h-4 w-4 text-red-500"});case"warning":return m.jsx(qm,{className:"h-4 w-4 text-yellow-500"});default:return m.jsx(qm,{className:"h-4 w-4 text-gray-400"})}},M=w=>{const T={pass:"bg-green-100 text-green-800",fail:"bg-red-100 text-red-800",warning:"bg-yellow-100 text-yellow-800",pending:"bg-gray-100 text-gray-800"};return m.jsx(Yw.Badge,{className:T[w]||T.pending,children:w.toUpperCase()})};return m.jsxs("div",{className:"max-w-6xl mx-auto p-6 space-y-6",children:[m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsx("h1",{className:"text-3xl font-bold",children:"Tiptap v3 Feature Validation"}),m.jsxs("div",{className:"flex gap-2",children:[m.jsxs(ce.Button,{onClick:E,variant:"outline",disabled:s,children:[m.jsx(rI,{className:"h-4 w-4 mr-2"}),"Reset"]}),m.jsxs(ce.Button,{onClick:x,disabled:s,children:[m.jsx(XL,{className:"h-4 w-4 mr-2"}),s?"Running Tests...":"Run All Tests"]})]})]}),s&&i&&m.jsx(ft.Card,{children:m.jsx(ft.CardContent,{className:"pt-6",children:m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),m.jsxs("span",{children:["Running: ",i]})]})})}),m.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[m.jsxs("div",{className:"space-y-4",children:[m.jsx("h2",{className:"text-xl font-semibold",children:"Test Results"}),n.map(w=>m.jsxs(ft.Card,{children:[m.jsx(ft.CardHeader,{className:"pb-3",children:m.jsxs("div",{className:"flex items-center justify-between",children:[m.jsx(ft.CardTitle,{className:"text-lg",children:w.name}),M(w.status)]})}),m.jsxs(ft.CardContent,{className:"space-y-2",children:[w.tests.map((T,k)=>m.jsxs("div",{className:"flex items-start gap-2 p-2 rounded border",children:[S(T.status),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:"font-medium text-sm",children:T.name}),m.jsx("div",{className:"text-xs text-muted-foreground",children:T.message}),T.details&&m.jsx("div",{className:"text-xs text-muted-foreground mt-1 opacity-75",children:T.details})]})]},k)),w.tests.length===0&&w.status==="pending"&&m.jsx("div",{className:"text-sm text-muted-foreground",children:"No tests run yet"})]})]},w.name))]}),m.jsxs("div",{className:"space-y-4",children:[m.jsx("h2",{className:"text-xl font-semibold",children:"Live Editor Test"}),m.jsx(ft.Card,{children:m.jsx(ft.CardContent,{className:"pt-6",children:m.jsx(sc,{content:t,onChange:e,useEnhancedFloatingMenu:!0,showMobileToolbar:!0,enableAdvancedPlaceholders:!0,enableFocusMode:!1,showKeyboardShortcuts:!0,className:"min-h-[400px]"})})}),m.jsxs(ft.Card,{children:[m.jsx(ft.CardHeader,{children:m.jsx(ft.CardTitle,{className:"text-lg",children:"Test Instructions"})}),m.jsxs(ft.CardContent,{className:"text-sm space-y-2",children:[m.jsx("p",{children:"• Try typing in the editor to test placeholders"}),m.jsx("p",{children:"• Create empty paragraphs to test floating menu"}),m.jsx("p",{children:"• Use keyboard shortcuts (Ctrl+B, Ctrl+I, etc.)"}),m.jsx("p",{children:"• Test undo/redo with Ctrl+Z/Ctrl+Y"}),m.jsx("p",{children:"• Hover over elements to see drag handles"}),m.jsx("p",{children:"• Resize window to test mobile toolbar"})]})]})]})]})]})},J2=()=>{const[t,e]=C.useState(`
|
|
473
473
|
<h1>Undo/Redo Test Document</h1>
|
|
474
474
|
<p>This document tests the enhanced undo/redo functionality with various content types.</p>
|
package/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as re from "react";
|
|
2
3
|
import q, { createRef as Qw, memo as e1, createContext as gg, createElement as kl, version as uf, useContext as t1, useRef as st, useState as Q, useDebugValue as yg, useEffect as we, forwardRef as Ta, useLayoutEffect as Na, useImperativeHandle as n1, useCallback as De, useMemo as yd } from "react";
|
|
3
4
|
import * as r1 from "react-dom";
|
|
@@ -36461,7 +36462,8 @@ function Cw({ editor: t, className: e }) {
|
|
|
36461
36462
|
let w = 0;
|
|
36462
36463
|
const M = parseFloat(o);
|
|
36463
36464
|
Number.isFinite(M) ? w = U2(M, E, t) : w = Zh(t);
|
|
36464
|
-
|
|
36465
|
+
const k = V2(w, S, t);
|
|
36466
|
+
let T;
|
|
36465
36467
|
S === "px" || S === "pt" || S === "%" ? T = String(Math.round(k)) : T = String(Math.max(0.01, Math.round(k * 100) / 100)), l(T);
|
|
36466
36468
|
const N = _u(vl(`${T}${S}`));
|
|
36467
36469
|
N && p(N);
|
|
@@ -36810,7 +36812,7 @@ const K2 = [
|
|
|
36810
36812
|
title: "DIV Block",
|
|
36811
36813
|
icon: /* @__PURE__ */ m.jsx(Vr, { className: "h-4 w-4" }),
|
|
36812
36814
|
command: (t) => {
|
|
36813
|
-
const e = window.prompt("Optional class for DIV:", ""), n = window.prompt("Optional inline style for DIV:", ""), r = window.prompt("Optional content for DIV:", "New block"), s = `${e ? ` class="${e}"` : ""}${n ? ` style="${n}"` : ""}`, o = r ? `<p>${((l) => l.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(
|
|
36815
|
+
const e = window.prompt("Optional class for DIV:", ""), n = window.prompt("Optional inline style for DIV:", ""), r = window.prompt("Optional content for DIV:", "New block"), s = `${e ? ` class="${e}"` : ""}${n ? ` style="${n}"` : ""}`, o = r ? `<p>${((l) => l.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"))(r)}</p>` : "<p><br /></p>";
|
|
36814
36816
|
t.chain().focus().insertContent(`<div${s}>${o}</div>`).run();
|
|
36815
36817
|
}
|
|
36816
36818
|
},
|
|
@@ -37351,7 +37353,9 @@ function gd(t, e = 2) {
|
|
|
37351
37353
|
if (!t) return "";
|
|
37352
37354
|
const n = t.replace(/\r\n?/g, `
|
|
37353
37355
|
`).split(/(<[^>]+>)/g).filter(Boolean), r = " ".repeat(e);
|
|
37354
|
-
let s = 0
|
|
37356
|
+
let s = 0;
|
|
37357
|
+
const i = [];
|
|
37358
|
+
let o = null;
|
|
37355
37359
|
for (let l = 0; l < n.length; l++) {
|
|
37356
37360
|
const a = n[l];
|
|
37357
37361
|
if (a.startsWith("<")) {
|
|
@@ -37372,7 +37376,7 @@ function gd(t, e = 2) {
|
|
|
37372
37376
|
for (const d of c)
|
|
37373
37377
|
i.push(d);
|
|
37374
37378
|
} else {
|
|
37375
|
-
|
|
37379
|
+
const c = a.replace(/\s+/g, " ");
|
|
37376
37380
|
if (c.length > 0) {
|
|
37377
37381
|
const d = i.length ? i[i.length - 1] : "";
|
|
37378
37382
|
if (d && !d.endsWith(`
|
|
@@ -38834,7 +38838,8 @@ const Nj = ({ html: t, className: e }) => {
|
|
|
38834
38838
|
s.forEach((o) => {
|
|
38835
38839
|
try {
|
|
38836
38840
|
URL.revokeObjectURL(o);
|
|
38837
|
-
} catch {
|
|
38841
|
+
} catch (l) {
|
|
38842
|
+
process.env.NODE_ENV !== "production" && console.warn("Failed to revoke object URL", o, l);
|
|
38838
38843
|
}
|
|
38839
38844
|
});
|
|
38840
38845
|
};
|