"use strict";const a=require("./jsx-runtime-Dszzpdy0.cjs"),t=require("./css-HnNQMUzV.cjs"),c=require("react"),R=require("react-dom"),C=require("./Animated-Ck-9v2gm.cjs"),m=require("./Box-BvqALodh.cjs");require("./Button-C3dvpk52.cjs");require("./Text-DECnk5vG.cjs");require("./Editable-BXFY3-UW.cjs");require("./types-D-yz1qsT.cjs");require("./Provider-575hnWmi.cjs");require("./provider-lNhTlIWj.cjs");const E={visible:!1,position:t.Q.ZERO,cursor:t.Q.ZERO,keys:[]},O=t.CSS.BE("menu-context","container"),_=n=>{let e=n;for(;!e.classList.contains(C.CONTEXT_TARGET);){if(e.classList.contains(O)||e.parentElement==null)return n;e=e.parentElement}return e.classList.contains(C.CONTEXT_TARGET)?e:n},M=n=>{const e=_(n);if(e==null)return[];const r=Array.from(e.parentElement?.querySelectorAll(`.${C.CONTEXT_SELECTED}`)??[]);return r.includes(e)?r:[e]},q=[{targetCorner:t.K.BOTTOM_RIGHT,dialogCorner:t.K.TOP_LEFT},{targetCorner:t.K.BOTTOM_LEFT,dialogCorner:t.K.TOP_RIGHT},{targetCorner:t.K.TOP_RIGHT,dialogCorner:t.K.BOTTOM_LEFT},{targetCorner:t.K.TOP_LEFT,dialogCorner:t.K.BOTTOM_RIGHT}],N=()=>{const n=c.useRef(null),[e,r]=c.useState(E),l=c.useCallback((s,o)=>{const i=t.Q.construct(s);if(typeof s=="object"&&"preventDefault"in s){s.preventDefault(),s.stopPropagation();const d=M(s.target);o??=t.c.unique(d.map(x=>x.id).filter(x=>x.length>0))}else o=[];r({visible:!0,keys:o,position:i,cursor:i})},[]),T=c.useCallback(s=>{n.current=s,s!=null&&r(o=>{if(!o.visible)return o;const{adjustedDialog:i}=C.position({container:t.jt.construct(0,0,window.innerWidth,window.innerHeight),dialog:t.jt.construct(s),target:t.jt.construct(o.cursor,0,0),prefer:q}),d=t.jt.topLeft(i);return t.Q.equals(o.position,d)?o:{...o,position:d}})},[]),u=()=>r(E);return C.useClickOutside({ref:n,onClickOutside:u}),{...e,close:u,open:l,ref:T,className:O}},b=({ref:n,menu:e,visible:r,open:l,close:T,position:u,keys:s,className:o,cursor:i,style:d,onClick:x,...p})=>r?R.createPortal(a.jsxRuntimeExports.jsx(m.Box$1,{className:t.CSS(C.CONTEXT_MENU_CLASS,t.CSS.bordered()),ref:n,style:{...t.Q.css(u),...d},onClick:j=>{T(),x?.(j)},gap:"tiny",...p,children:e?.({keys:s,visible:r,position:u,cursor:i})}),document.body):null,g=({menu:n,children:e,...r})=>a.jsxRuntimeExports.jsxs(a.jsxRuntimeExports.Fragment,{children:[a.jsxRuntimeExports.jsx(b,{menu:n,...r}),e]}),f=({className:n,padded:e=!1,color:r,...l})=>(e===!0&&(e="center"),a.jsxRuntimeExports.jsx(m.Box$1,{className:t.CSS(t.CSS.B("divider"),e!==!1&&t.CSS.BM("divider","padded"),typeof e=="string"&&t.CSS.loc(e),n),borderColor:r,color:r,...l})),D=Object.freeze(Object.defineProperty({__proto__:null,Divider:f},Symbol.toStringTag,{value:"Module"})),S=c.createContext({onClick:()=>{},selected:""}),L=()=>c.use(S),v=({children:n,onChange:e,level:r,gap:l,background:T,value:u=""})=>{const s=c.useCallback(i=>{typeof e=="function"?e(i):e&&i in e&&e[i](i)},[e]),o=c.useMemo(()=>({onClick:s,selected:u,level:r,gap:l,background:T}),[u,s,r,l,T]);return a.jsxRuntimeExports.jsx(S,{value:o,children:n})},B=()=>a.jsxRuntimeExports.jsx(f,{x:!0,padded:!0});exports.ContextMenu=g;exports.Divider=B;exports.Divider$1=f;exports.Divider$2=D;exports.Menu=v;exports.useContext=L;exports.useContextMenu=N;
