@vuu-ui/vuu-popups 0.8.23 → 0.8.24-debug

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/cjs/index.js CHANGED
@@ -1,2 +1,2154 @@
1
- "use strict";var Jt=Object.create;var me=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,Zt=Object.prototype.hasOwnProperty;var _t=(e,o)=>{for(var t in o)me(e,t,{get:o[t],enumerable:!0})},_e=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of jt(o))!Zt.call(e,r)&&r!==t&&me(e,r,{get:()=>o[r],enumerable:!(n=Yt(o,r))||n.enumerable});return e};var A=(e,o,t)=>(t=e!=null?Jt(Qt(e)):{},_e(o||!e||!e.__esModule?me(t,"default",{value:e,enumerable:!0}):t,e)),eo=e=>_e(me({},"__esModule",{value:!0}),e);var en={};_t(en,{ContextMenu:()=>Me,ContextMenuContext:()=>pe,ContextMenuProvider:()=>Oo,Dialog:()=>Oe,DialogHeader:()=>Ie,DialogService:()=>Ne,MenuItem:()=>ae,MenuItemGroup:()=>ue,MenuList:()=>xe,NotificationLevel:()=>Wt,NotificationsContext:()=>Ye,NotificationsProvider:()=>Zo,PopupComponent:()=>Be,PopupMenu:()=>Fo,PopupService:()=>G,Portal:()=>Q,Prompt:()=>Go,Separator:()=>Ke,ToastNotification:()=>qt,Tooltip:()=>Uo,createContainer:()=>ro,isMenuItemLabel:()=>he,reasonIsClickAway:()=>Se,reasonIsMenuAction:()=>De,renderPortal:()=>Ae,useAnchoredPosition:()=>J,useContextMenu:()=>qe,useDialog:()=>mo,useNotifications:()=>_o,useTooltip:()=>Xo});module.exports=eo(en);var pt=A(require("clsx")),ct=require("@vuu-ui/vuu-utils"),Y=require("react");var fe=require("@salt-ds/core"),et=A(require("clsx"));var re=require("react/jsx-runtime"),to="vuuDialogHeader",Ie=({hideCloseButton:e=!1,title:o,onClose:t,...n})=>(0,re.jsxs)("div",{...n,className:(0,et.default)(to,"vuuToolbarProxy"),children:[(0,re.jsx)(fe.Text,{className:"dialogHeader",children:o}),!e&&(0,re.jsx)(fe.Button,{onClick:t,"data-align":"end","data-icon":"close",variant:"secondary"},"close")]});var nt=A(require("clsx")),ie=A(require("react")),ee=A(require("react-dom"));var tt=A(require("react-dom")),ot=A(require("clsx")),oo=1,no=({className:e,dataMode:o,x:t=0,y:n=0,win:r=window})=>{let i=r.document.createElement("div");return i.className=(0,ot.default)(`vuuPopup ${oo++}`,e),i.style.cssText=`left:${t}px; top:${n}px;`,o&&(i.dataset.mode=o),r.document.body.appendChild(i),i},ro=e=>no(e),Ae=(e,o,t,n,r)=>{o.style.cssText=`left:${t}px; top:${n}px;position: absolute;`,tt.render(e,o,r)};var X=!1,S=[],De=e=>(e==null?void 0:e.type)==="menu-action",Se=e=>(e==null?void 0:e.type)==="click-away";function ge(e){if(e.key==="Esc"){if(S.length)it();else if(X){let o=document.body.querySelector(".vuuDialog");o&&ee.default.unmountComponentAtNode(o)}}}function rt(e){if(S.length){let o=document.body.querySelectorAll(".vuuPopup,#vuu-portal-root");for(let t=0;t<o.length;t++)if(o[t].contains(e.target))return;it({mouseEvt:e,type:"click-away"})}}function it(e){if(S.length===1)G.hidePopup(e,"anon","all");else if(S.length){let o=document.body.querySelectorAll(".vuuPopup");for(let t=0;t<o.length;t++)ee.default.unmountComponentAtNode(o[t]);st("*")}}function io(){X===!1&&(X=!0,window.addEventListener("keydown",ge,!0))}function so(){X&&(X=!1,window.removeEventListener("keydown",ge,!0))}function uo(e){S.indexOf(e)===-1&&(S.push(e),X===!1&&(window.addEventListener("keydown",ge,!0),window.addEventListener("click",rt,!0)))}function st(e){if(S.length){if(e==="*")S.length=0;else{let o=S.indexOf(e);o!==-1&&S.splice(o,1)}S.length===0&&X===!1&&(window.removeEventListener("keydown",ge,!0),window.removeEventListener("click",rt,!0))}}var ao=({children:e,position:o,style:t})=>{let n=(0,nt.default)("hwPopup","hwPopupContainer",o);return(0,ie.createElement)("div",{className:n,style:t},e)},lo=1,G=class e{static showPopup({group:o="all",name:t="anon",left:n=0,position:r="",right:i="auto",top:s=0,width:m="auto",component:p}){if(!p)throw Error("PopupService showPopup, no component supplied");typeof p.props.onClose=="function"?e.onClose=p.props.onClose:e.onClose=void 0,uo(t),document.addEventListener("keydown",e.escapeKeyListener,!0);let a=document.body.querySelector(".vuuPopup."+o);a===null&&(a=document.createElement("div"),a.className="vuuPopup "+o,document.body.appendChild(a));let u={width:m};Ae((0,ie.createElement)(ao,{key:lo++,position:r,style:u},p),a,n,s,()=>{e.keepWithinThePage(a,i)})}static escapeKeyListener(o){o.key==="Escape"&&e.hidePopup({type:"escape",event:o})}static hidePopup(o,t="anon",n="all"){var r;if(S.indexOf(t)!==-1){st(t);let i=document.body.querySelector(`.vuuPopup.${n}`);i&&ee.default.unmountComponentAtNode(i)}document.removeEventListener("keydown",e.escapeKeyListener,!0),(r=e==null?void 0:e.onClose)==null||r.call(e,o?{...o,closedBy:"popup-service"}:void 0)}static keepWithinThePage(o,t="auto"){let n=o.querySelector(".vuuPopupContainer > *");if(n){let{top:r,left:i,width:s,height:m,right:p}=n.getBoundingClientRect(),a=window.innerWidth,l=window.innerHeight-(r+m);l<0&&(n.style.top=Math.round(r)+l+"px");let c=a-(i+s);if(c<0&&(n.style.left=Math.round(i)+c+"px"),typeof t=="number"&&t!==p){let f=t-p;n.style.left=i+f+"px"}}}},Ne=class e{static showDialog(o){let t=".vuuDialog",n=o.props.onClose;io(),ee.default.render(ie.default.cloneElement(o,{container:t,onClose:()=>{e.closeDialog(),n&&n()}}),document.body.querySelector(t))}static closeDialog(){so();let o=document.body.querySelector(".vuuDialog");o&&ee.default.unmountComponentAtNode(o)}};var ut=A(require("clsx"));var V=require("react");var se=(e,o,t,n,r,i)=>{let{bottom:s,height:m,left:p,right:a,top:u,width:l}=e.getBoundingClientRect();switch(console.log({top:u}),o){case"below":return{left:p+t,top:s+n};case"right":return{left:a+t,top:u+n};case"below-center":return{left:p+l/2+t,top:s+n};case"below-right":return{left:p,minWidth:r,top:s+n};case"below-full-width":return{left:p+t,minWidth:r,top:s+n,width:l};case"center":return i?{left:l/2-i.width/2+t,top:m/2-i.height/2+n,visibility:"visible"}:{left:l/2+t,top:m/2+n,visibility:"hidden"};default:throw Error(`Popup getPositionRelativeToAnchor non-supported placement value ${o}`)}};var J=({anchorElement:e,minWidth:o,offsetLeft:t=0,offsetTop:n=0,placement:r,position:i})=>{let s=(0,V.useRef)(null),[m,p]=(0,V.useState)(i);(0,V.useLayoutEffect)(()=>{if(r==="absolute"&&i)p(i);else if(e.current&&r!=="auto"){let u=s.current===null?void 0:s.current.getBoundingClientRect(),l=se(e.current,r,t,n,o,u);p(l)}},[e,o,t,n,r,i]);let a=(0,V.useCallback)(u=>{if(s.current=u,u&&r==="center"&&e.current){let{height:l,width:c}=u.getBoundingClientRect();p(se(e.current,r,t,n,void 0,{height:l,width:c}))}},[e,t,n,r]);return{position:m,popupRef:r==="center"?a:void 0}};var at=require("react/jsx-runtime"),Be=({children:e,className:o,anchorElement:t,minWidth:n,placement:r,position:i})=>{let{popupRef:s,position:m}=J({anchorElement:t,minWidth:n,placement:r,position:i});return m===void 0?null:(0,at.jsx)("div",{className:(0,ut.default)("vuuPortal",o),ref:s,style:m,children:e})};var te=require("react/jsx-runtime"),lt="vuuDialog",po={current:document.body},co={},Oe=({PopupProps:e=co,children:o,className:t,isOpen:n=!1,onClose:r,style:i,title:s,hideCloseButton:m=!1,...p})=>{let{anchorElement:a=po,offsetLeft:u=0,offsetTop:l=0,placement:c="auto"}=e,f=(0,Y.useRef)(null),C=(0,Y.useRef)(null),[v,P,y]=(0,ct.useThemeAttributes)(),{position:E}=J({anchorElement:a,offsetLeft:u,offsetTop:l,placement:c}),w=(0,Y.useCallback)(()=>{r==null||r()},[r]);return(0,Y.useLayoutEffect)(()=>{if(f.current){if(n){f.current.showModal();let{left:T,top:b}=f.current.getBoundingClientRect();C.current&&(C.current.style.cssText=`left:-${T}px;position:absolute;top:-${b}px;`)}else f.current.close();if(c.endsWith("center")){let{width:T}=f.current.getBoundingClientRect();f.current.style.marginLeft=`-${T/2}px`}}},[n,c]),(0,te.jsxs)("dialog",{...p,className:(0,pt.default)(lt,v),"data-mode":y,onClose:w,id:"vuu-dialog",ref:f,style:{...i,...E},children:[(0,te.jsx)(Ie,{hideCloseButton:m,onClose:w,title:s}),(0,te.jsx)("div",{className:`${lt}-body`,children:o}),(0,te.jsx)("div",{id:"vuu-dialog-portal-root",ref:C})]})};var ve=require("react");var dt=require("react/jsx-runtime"),mo=()=>{let[e,o]=(0,ve.useState)(),t=(0,ve.useCallback)(()=>{o(void 0)},[]);return{dialog:e?(0,dt.jsx)(Oe,{className:"vuDialog",isOpen:!0,onClose:t,style:{maxHeight:500},title:e.title,hideCloseButton:e.hideCloseButton,children:e.content}):null,setDialogState:o}};var Lt=require("@vuu-ui/vuu-utils"),_=require("react");var mt=require("@vuu-ui/vuu-utils"),j=require("react"),ft=require("react-dom");function fo(e){return typeof e=="function"?e():e}var go=["vuu-dialog-portal-root","vuu-portal-root"],vo=e=>{if(Array.isArray(e))for(let o of e){let t=document.getElementById(o);if(t)return t}else return document.getElementById(e);return null},Q=({children:e,container:o=document.body,id:t=go,onRender:n,open:r=!0,themeAttributes:i})=>{var f;let[s,m]=(0,j.useState)(!1),p=(0,j.useRef)(null),a=(f=fo(o))!=null?f:document.body,[u,l,c]=(0,mt.useThemeAttributes)(i);return(0,j.useLayoutEffect)(()=>{let C=vo(t);C?p.current=C:(p.current=document.createElement("div"),p.current.id=typeof t=="string"?t:t.length>0?t.at(-1):"vuu-portal-root");let v=p.current;a.contains(v)||a.appendChild(v),v.classList.add(u,l),v.dataset.mode=c,m(!0)},[t,a,u,l,c]),(0,j.useLayoutEffect)(()=>{requestAnimationFrame(()=>{n==null||n()})},[n]),r&&s&&p.current&&e?(0,ft.createPortal)(e,p.current):null};var ze=A(require("clsx")),F=A(require("react")),wt=require("@vuu-ui/vuu-utils");var Z=A(require("react"));var $e=e=>e.type===ue||!!e.props["data-group"],ho=e=>{if(Array.isArray(e)&&he(e[0]))return e[0]},bo=(e,o,t,n=!1)=>{let{props:{children:r}}=e;return{childWithId:Z.default.cloneElement(e,{hasSeparator:n,id:`${o}`,key:o,children:t?ho(r):r}),grandChildren:t?r:void 0}},gt=(e,o)=>{let t=(0,Z.useCallback)(()=>{let i=(s,m=o,p={},a={})=>{let u=p[m]=[],l=0,c=!1;return Z.default.Children.forEach(s,f=>{if(!he(f))if(f.type===Ke)c=!0;else{let C=$e(f),v=`${m}-${l}`,{props:{action:P,options:y}}=f,{childWithId:E,grandChildren:w}=bo(f,v,C,c);u.push(E),w?i(w,v,p,a):a[v]={action:P,options:y},l+=1,c=!1}}),[p,a]};return i(e)},[o,e]),[n,r]=(0,Z.useMemo)(()=>t(),[t]);return[n,r]};var D=require("react");var vt=e=>e.closest("[data-root='true']")!==null,ht=(e,o)=>{var t;return e.ariaHasPopup==="true"&&((t=e.dataset)==null?void 0:t.idx)===`${o}`||e.querySelector(`:scope > [data-index='${o}'][aria-haspopup='true']`)!==null};function xo(e,...o){let t=new Set(e);for(let n of o)for(let r of n)t.add(r);return t}var Mo="Enter";var yo="Delete",Po=new Set([Mo,yo]),wo=new Set(["Tab"]),Co=new Set(["ArrowRight","ArrowLeft"]),bt=new Set(["Home","End","ArrowDown","ArrowUp"]),xt=new Set(["Home","End","ArrowRight","ArrowLeft"]),Eo=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),Jn=xo(Po,xt,bt,Co,Eo,wo);var Mt=({key:e},o="vertical")=>(o==="vertical"?bt:xt).has(e);var be=require("@vuu-ui/vuu-utils"),yt=({autoHighlightFirstItem:e=!1,count:o,defaultHighlightedIdx:t,highlightedIndex:n,onActivate:r,onHighlight:i,onCloseMenu:s,onOpenMenu:m})=>{var T;if((0,be.isValidNumber)(n)&&(0,be.isValidNumber)(t))throw Error("useKeyboardNavigation do not pass values for both highlightedIndex and defaultHighlightedIdx");let p=(0,be.isValidNumber)(n),a=(0,D.useRef)((T=t!=null?t:n)!=null?T:e?0:-1),[,u]=(0,D.useState)(null),l=(0,D.useCallback)(b=>{a.current=b,i==null||i(b),u({})},[i]),c=(0,D.useCallback)(b=>{b!==a.current&&(p||l(b))},[p,l]),f=(0,D.useRef)(!0),C=(0,D.useRef)(!1),v=b=>C.current=b,P=p?n:a.current,y=(0,D.useCallback)(b=>{let x=To(o,b.key,a.current);x!==a.current&&c(x)},[o,c]),E=(0,D.useCallback)(b=>{if(Mt(b))b.preventDefault(),b.stopPropagation(),f.current=!0,y(b);else if((b.key==="ArrowRight"||b.key==="Enter")&&ht(b.target,P)){let g=b.target.querySelector(`:scope > [data-index='${P}']`);g&&(m==null||m(g,!0))}else b.key==="ArrowLeft"&&!vt(b.target)?s(b,"close-child-menu"):b.key==="Enter"?(b.preventDefault(),b.stopPropagation(),r&&r(P)):b.key==="Tab"&&s(b,"tab-away")},[P,y,r,s,m]),w=(0,D.useMemo)(()=>({onFocus:()=>{P===-1&&l(0)},onKeyDown:E,onMouseDownCapture:()=>{f.current=!1,v(!0)},onMouseMove:()=>{f.current&&(f.current=!1)},onMouseLeave:()=>{f.current=!0,v(!1),c(-1)}}),[E,P,l,c]);return{focusVisible:f.current?P:-1,controlledHighlighting:p,highlightedIndex:P,setHighlightedIndex:c,listProps:w,setIgnoreFocus:v}};function To(e,o,t){return o==="ArrowUp"?t>0?t-1:t:t===null?0:t===e-1?t:t+1}var z=require("react/jsx-runtime"),Pt="vuuMenuList",Ke=()=>(0,z.jsx)("li",{className:"vuuMenuItem-divider"}),ue=()=>null,ae=({children:e,idx:o,options:t,...n})=>(0,z.jsx)("div",{...n,children:e}),Ct=({children:e})=>(0,z.jsx)(z.Fragment,{children:e});Ct.displayName="MenuItemLabel";ae.Label=Ct;var ko=e=>F.default.isValidElement(e)&&typeof e.type!="string"&&"displayName"in e.type?e.type.displayName:void 0,he=e=>ko(e)==="MenuItemLabel",Ro=e=>e.props["data-icon"],xe=({activatedByKeyboard:e,childMenuShowing:o,children:t,className:n,defaultHighlightedIdx:r,highlightedIdx:i,id:s,isRoot:m,listItemProps:p,onHighlightMenuItem:a,onActivate:u,onCloseMenu:l,openMenu:c,...f})=>{let C=(0,wt.useId)(s),v=(0,F.useRef)(null),P=(0,F.useMemo)(()=>new Map,[]),y=h=>{var M;let d=(M=v.current)==null?void 0:M.querySelector(`:scope > [data-index='${h}']`);d!=null&&d.id&&(u==null||u(d.id))},{focusVisible:E,highlightedIndex:w,listProps:T}=yt({count:F.default.Children.count(t),defaultHighlightedIdx:r,highlightedIndex:i,onActivate:y,onHighlight:a,onOpenMenu:c,onCloseMenu:l}),b=o==null?E:-1;(0,F.useLayoutEffect)(()=>{var h;o===void 0&&e&&((h=v.current)==null||h.focus())},[e,o]);let x=()=>w===void 0||w===-1?void 0:P.get(w);function g(){let h={...p,role:"menuitem"},d=(R,L,I)=>L?[(0,z.jsx)("span",{className:"vuuIconContainer","data-icon":I},"icon")].concat(R):R;function M(R,L,I,U){var Ze;let{children:q,className:Gt,"data-icon":je,id:de,hasSeparator:Vt,label:Le,...Ut}=L.props,He=$e(L),Qe=He&&o===de,Xt=Qe?`${C}-${de}`:void 0;R.push((0,z.jsx)(ae,{...Ut,...h,...Lo(de,I,(Ze=L.key)!=null?Ze:de,w,b,Gt,Vt),"aria-controls":Xt,"aria-haspopup":He||void 0,"aria-expanded":Qe||void 0,children:d(He&&Le!=null?Le:q,U,je)}))}let k=[];if(t.length>0){let R=t.some(Ro);t.forEach((L,I)=>{M(k,L,I,R)})}return k}return(0,z.jsx)("div",{...f,...T,"aria-activedescendant":x(),className:(0,ze.default)(Pt,n,{[`${Pt}-childMenuShowing`]:o!==void 0}),"data-root":m||void 0,id:C,ref:v,role:"menu",children:g()})},Lo=(e,o,t,n,r,i,s)=>({id:`menuitem-${e}`,key:t!=null?t:o,"data-index":o,"data-highlighted":o===n||void 0,className:(0,ze.default)("vuuMenuItem",i,{"vuuMenuItem-separator":s,focusVisible:r===o})});xe.displayName="MenuList";var H=require("react");var Fe=e=>e==null?void 0:e.closest("[data-index],[aria-posinset]");var Tt=(e,o,t)=>e.map((n,r)=>r===e.length-1?{...n,[t]:n[t]-o}:n),Ho=(e,o)=>Tt(e,o,"left"),Io=(e,o)=>Tt(e,o,"top"),Ao=(e,o)=>{let[t,n]=o.slice(-2),r=document.getElementById(`${e}-${n.id}`);if(r===null)throw Error(`useCascade.flipSides element with id ${n.id} not found`);let{width:i}=r.getBoundingClientRect();return o.map(s=>s===n?{...s,left:t.left-(i-2)}:s)},No=(e,o)=>{let[{left:t,top:n}]=o.slice(-1),{offsetWidth:r,offsetTop:i}=e;return{left:t+r,top:i+n}},kt=(e,o)=>{let t=e.lastIndexOf("-");return e.startsWith("menuitem")?t>-1?e.slice(9,t):o:t>-1?e.slice(0,t):o},Do=e=>e.slice(9),Et=({ariaExpanded:e,ariaHasPopup:o,id:t},n)=>{if(t.startsWith("menuitem"))return{hostMenuId:kt(t,n),targetMenuId:Do(t),menuItemId:t,isGroup:o==="true",isOpen:e==="true"};throw Error(`getMenuItemDetails #${t} is not a menuitem`)},Rt=({id:e,onActivate:o,onMouseEnterItem:t,position:{x:n,y:r}})=>{let[,i]=(0,H.useState)({}),s=(0,H.useRef)([{id:e,left:n,top:r}]),m=(0,H.useCallback)(x=>s.current.findIndex(g=>g.id===x)!==-1,[]),p=(0,H.useCallback)(x=>{let g=c.current[x];if(g===void 0)throw Error(`getOpenMenuState no entry for menu ${x}`);return g},[]),a=(0,H.useCallback)(x=>{s.current=x,i({})},[]),u=(0,H.useRef)(),l=(0,H.useRef)(),c=(0,H.useRef)({[e]:"no-popup"}),f=(0,H.useCallback)((x=e,g,h=null)=>{if(x===e&&h===null)a([{id:e,left:n,top:r}]);else{c.current[x]="popup-open";let d=document.getElementById(h);if(d!==null){let{left:M,top:k}=No(d,s.current);a(s.current.concat({id:g,left:M,top:k}))}else throw Error(`openMenu no menuItem ${h}`)}},[e,n,r,a]),C=(0,H.useCallback)(x=>{if(x===e)a([]);else{let g=s.current.slice(),h=g.pop();c.current[h.id]="no-popup";let d=g.at(-1);d&&(c.current[d.id]="no-popup"),a(g)}},[e,a]),v=(0,H.useCallback)(x=>{let g=s.current.slice(),h=x.slice(9),{id:d}=g.at(-1);for(;g.length>1&&!h.startsWith(d);){let M=kt(d,e);g.pop(),c.current[d]="no-popup",c.current[M]="no-popup",{id:d}=g[g.length-1]}g.length<s.current.length&&a(g)},[e,a]),P=(0,H.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=void 0)},[]),y=(0,H.useCallback)((x,g,h,d=300)=>{P(),u.current=window.setTimeout(()=>{v(h),c.current[x]="popup-open",c.current[g]="no-popup",f(x,g,h)},d)},[P,v,f]),E=(0,H.useCallback)((x,g,h)=>{c.current[g]="pending-close",l.current=window.setTimeout(()=>{v(h)},400)},[v]),w=(0,H.useCallback)(()=>{let{current:x}=s,g=x.at(-1),h=g?document.getElementById(g.id):void 0;if(h){let{right:d,bottom:M}=h.getBoundingClientRect(),{clientHeight:k,clientWidth:R}=document.body;if(d>R){let L=x.length>1?Ao(e,x):Ho(x,d-R);a(L)}else if(M>k){let L=Io(x,M-k);a(L)}typeof h.tabIndex=="number"&&h.focus()}},[e,a]),T=(0,H.useCallback)((x,g=!1)=>{let{hostMenuId:h,targetMenuId:d,menuItemId:M,isGroup:k,isOpen:R}=Et(x,e),{current:{[h]:L}}=c,I=g?0:void 0;if(L==="no-popup"&&k)c.current[h]="popup-pending",y(h,d,M,I);else if(L==="popup-pending"&&!k)c.current[h]="no-popup",clearTimeout(u.current),u.current=void 0;else if(L==="popup-pending"&&k)clearTimeout(u.current),y(h,d,M,I);else if(L==="popup-open")if(m(d)){let U=p(d);switch(v(M),U){case"pending-close":clearTimeout(l.current),l.current=void 0,c.current[d]="no-popup",P();break;default:}}else{let[U,q]=s.current.slice(-2);U.id===h&&c.current[q.id]!=="pending-close"?(E(h,q.id,M),k&&!R&&y(h,d,M,I)):U.id===h&&k&&M!==q.id&&c.current[q.id]==="pending-close"||k?y(h,d,M,I):c.current[q.id]!=="pending-close"&&v(M)}L==="pending-close"&&(P(),clearTimeout(l.current),l.current=void 0,c.current[h]="popup-open")},[P,v,p,m,e,E,y]),b=(0,H.useMemo)(()=>({onMouseEnter:x=>{let g=Fe(x.target);T(g),t(x,g.id)},onClick:x=>{let g=Fe(x.target),{isGroup:h,menuItemId:d}=Et(g,e);h?T(g):o(d)}}),[o,t,e,T]);return{closeMenu:C,handleRender:w,listItemProps:b,openMenu:T,openMenus:s.current}};var le=require("react/jsx-runtime"),We=require("react"),So=()=>{},Me=({PortalProps:e,activatedByKeyboard:o,children:t,className:n,id:r,onClose:i=()=>{},position:s={x:0,y:0},style:m,...p})=>{let a=(0,Lt.useId)(r),u=(0,_.useRef)(So),[l,c]=gt(t,a),f=(0,_.useRef)(o),C=(0,_.useCallback)(()=>{f.current=!1},[]),v=(0,_.useCallback)(d=>{let M=d.slice(9),{action:k,options:R}=c[M];u.current(a),i({type:"menu-action",menuId:k,options:R})},[c,a,i]),{closeMenu:P,listItemProps:y,openMenu:E,openMenus:w,handleRender:T}=Rt({id:`${a}`,onActivate:v,onMouseEnterItem:C,position:s});u.current=P;let b=(0,_.useCallback)((d,M)=>{f.current=!0,P(),M==="tab-away"&&i({event:d,type:"tab-away"})},[P,i]),x=()=>{},g=w.length-1,h=d=>{if(!(d>=g)){let{id:M}=w[d+1];return M}};return(0,le.jsx)(le.Fragment,{children:w.map(({id:d,left:M,top:k},R,L)=>{let I=h(R);return(0,We.createElement)(Q,{...e,key:R,onRender:T},(0,le.jsx)(Be,{anchorElement:{current:document.body},placement:"absolute",position:{left:M,top:k},children:(0,We.createElement)(xe,{...p,activatedByKeyboard:f.current,childMenuShowing:I,className:n,id:d,isRoot:R===0,key:R,listItemProps:y,onActivate:v,onHighlightMenuItem:x,onCloseMenu:b,openMenu:E,style:m,tabIndex:R===L.length-1?0:void 0},l[d])}))})})};Me.displayName="ContextMenu";var oe=require("react"),ye=require("react/jsx-runtime"),pe=(0,oe.createContext)(null),Bo=({children:e,context:o,menuActionHandler:t,menuBuilder:n})=>{let r=(0,oe.useMemo)(()=>o!=null&&o.menuBuilders&&n?o.menuBuilders.concat(n):n?[n]:(o==null?void 0:o.menuBuilders)||[],[o,n]),i=(0,oe.useCallback)(s=>{var m;if(t!=null&&t(s)||(m=o==null?void 0:o.menuActionHandler)!=null&&m.call(o,s))return!0},[o,t]);return(0,ye.jsx)(pe.Provider,{value:{menuActionHandler:i,menuBuilders:r},children:e})},Oo=({children:e,label:o,menuActionHandler:t,menuBuilder:n})=>(0,ye.jsx)(pe.Consumer,{children:r=>(0,ye.jsx)(Bo,{context:r,label:o,menuActionHandler:t,menuBuilder:n,children:e})});var we=require("@vuu-ui/vuu-utils"),$=require("react");var Pe=require("react/jsx-runtime"),qe=(e,o)=>{let t=(0,$.useContext)(pe),[n,r,i]=(0,we.useThemeAttributes)(),s=(0,$.useMemo)(()=>({themeClass:n,densityClass:r,dataMode:i}),[i,r,n]),m=(0,$.useCallback)((u,l,c)=>{let f=[];for(let C of u)f=f.concat(C(l,c));return f},[]),p=(0,$.useCallback)((u,l,{ContextMenuProps:c,contextMenu:f,...C})=>{var P,y;if((P=u.stopPropagation)==null||P.call(u),(y=u.preventDefault)==null||y.call(u),f)return Ko({x:u.clientX,y:u.clientY},f);let v=[];if(e&&v.push(e),t&&Array.isArray(t==null?void 0:t.menuBuilders)&&t.menuBuilders.length>0&&v.push(...t.menuBuilders),v.length>0){let E=m(v,l,C),w=T=>(o==null?void 0:o(T))===!0?!0:t==null?void 0:t.menuActionHandler(T);E.length&&w&&zo(u,E,w,{PortalProps:{themeAttributes:s},...c})}else console.warn("useContextMenu, no menuBuilders configured. These should be supplied via the ContextMenuProvider(s)")},[m,t,o,e,s]),a=(0,$.useCallback)(()=>{console.log("hide context menu")},[]);return[p,a]},$o={},Ko=(e,o)=>{G.showPopup({focus:!0,left:0,top:0,component:(0,$.cloneElement)(o,{position:e})})},zo=(e,o,t,{position:n,...r}=$o)=>{let i=a=>{let u=(l,c)=>(0,we.isGroupMenuItemDescriptor)(l)?(0,Pe.jsx)(ue,{label:l.label,children:l.children.map(u)},c):(0,Pe.jsx)(ae,{action:l.action,className:l.className,"data-icon":l.icon,options:l.options,children:l.label},c);return a.map(u)},s=a=>{var u;if(De(a)){if((a==null?void 0:a.closedBy)==="popup-service")return;t(a),G.hidePopup(a)}(u=r==null?void 0:r.onClose)==null||u.call(r,a)},m=n!=null?n:{x:e.clientX,y:e.clientY},p=(0,Pe.jsx)(Me,{...r,onClose:s,position:m,children:i(o)});G.showPopup({left:0,top:0,component:p,focus:!0})};var Ht=require("@vuu-ui/vuu-utils"),It=require("@salt-ds/core"),At=A(require("clsx")),K=require("react");var Nt=require("react/jsx-runtime"),Ge="vuuPopupMenu",Fo=({anchorElement:e,className:o,label:t,icon:n=t?"chevron-down":"more-vert",id:r,menuActionHandler:i,menuBuilder:s,menuClassName:m,menuLocation:p="header",menuOptions:a,onMenuClose:u,onMenuOpen:l,popupPlacement:c="below-right",tabIndex:f=0,...C})=>{let v=(0,K.useRef)(null),P=(0,K.useRef)(!1),[y,E]=(0,K.useState)(!1),w=(0,Ht.useId)(r),[T]=qe(s,i),b=(0,K.useCallback)(d=>{E(d),d&&(l==null||l())},[l]),x=(0,K.useCallback)(d=>{console.log("menu Open ",{el:d})},[]),g=(0,K.useCallback)(d=>{console.log("onClose"),b(!1),Se(d)?(d.mouseEvt.target===v.current&&(P.current=!0),u==null||u(d)):requestAnimationFrame(()=>{var M;u==null||u(d),f!==-1&&(d==null?void 0:d.type)!=="tab-away"&&((M=v.current)==null||M.focus())})},[u,b,f]),h=(0,K.useCallback)(d=>{var M;if(P.current)P.current=!1;else{let k=(M=e==null?void 0:e.current)!=null?M:v.current;if(k){let{left:R,top:L,width:I}=se(k,c,0,0);b(!0),T(d,p,{ContextMenuProps:{className:m,id:`${w}-menu`,onClose:g,openMenu:x,position:{x:R,y:L},style:{width:I?I-2:void 0}},...a})}}},[e,g,x,w,m,p,a,c,b,T]);return(0,Nt.jsx)(It.Button,{...C,"aria-controls":y?`${w}-menu`:void 0,"aria-expanded":y,"aria-haspopup":"menu",className:(0,At.default)(Ge,o,{[`${Ge}-withCaption`]:t!==void 0,[`${Ge}-open`]:y}),"data-icon":n,id:w,onClick:h,ref:v,tabIndex:f,variant:"secondary",children:t})};var Dt=require("@vuu-ui/vuu-utils"),Ve=require("@salt-ds/core"),St=A(require("clsx")),ce=require("react");var W=require("react/jsx-runtime"),ne="vuuPrompt",Wo={current:document.body},qo={},Go=({PopupProps:e=qo,cancelButtonLabel:o="Cancel",confirmButtonLabel:t="Confirm",icon:n,onCancel:r,onConfirm:i,style:s,text:m,title:p,variant:a="info",...u})=>{let{anchorElement:l=Wo,offsetLeft:c=0,offsetTop:f=0,placement:C="below"}=e,[v,P,y]=(0,Dt.useThemeAttributes)(),{position:E}=J({anchorElement:l,offsetLeft:c,offsetTop:f,placement:C}),w=(0,ce.useRef)(null),T=(0,ce.useRef)(null);return(0,ce.useLayoutEffect)(()=>{if(w.current&&(w.current.showModal(),T.current&&T.current.focus(),C.endsWith("center"))){let{width:b}=w.current.getBoundingClientRect();w.current.style.marginLeft=`-${b/2}px`}},[C]),(0,W.jsx)("dialog",{...u,className:(0,St.default)(ne,`${ne}-${a}`,v),"data-mode":y,ref:w,style:{...s,...E},children:(0,W.jsxs)("form",{className:`${ne}-form`,children:[(0,W.jsx)("div",{className:`${ne}-header`,"data-icon":n,children:p}),(0,W.jsx)("div",{className:`${ne}-text`,children:m}),(0,W.jsxs)("div",{className:`${ne}-buttonBar`,children:[(0,W.jsx)(Ve.Button,{onClick:r,variant:"secondary",children:o}),(0,W.jsx)(Ve.Button,{onClick:i,ref:T,value:"default",children:t})]})]})})};var Ce=require("react"),Vo=(e,o,t,n)=>{let{bottom:r,height:i,left:s,right:m,top:p,width:a}=e.getBoundingClientRect(),u=s+a/2,l=p+i/2;switch(o){case"above":return{left:u+t,top:p+n};case"below":return{left:u+t,top:r+n};case"right":return{left:m+t,top:l+t};case"left":return{left:s+t,top:l+t};default:throw Error("Tooltip getPositionRelativeToAnchor only supported placement values are left, right, below and right")}},Bt=({anchorElement:e,offsetLeft:o=0,offsetTop:t=0,placement:n})=>{let[r,i]=(0,Ce.useState)();return(0,Ce.useLayoutEffect)(()=>{if(e.current){let s=Vo(e.current,n,o,t);i(s)}},[e,o,t,n]),r};var Ot=A(require("clsx"));var Ee=require("react/jsx-runtime"),Ue="vuuTooltip",Uo=({anchorElement:e,children:o,id:t,onMouseEnter:n,onMouseLeave:r,placement:i,status:s,style:m})=>{let p=Bt({anchorElement:e,placement:i});return p===void 0?null:(0,Ee.jsx)(Q,{children:(0,Ee.jsx)("div",{className:(0,Ot.default)(Ue,{[`${Ue}-error`]:s==="error"}),"data-align":i,id:t,style:{...m,...p},children:(0,Ee.jsx)("span",{className:`${Ue}-content`,onMouseEnter:n,onMouseLeave:r,children:o})})})};var $t=require("@vuu-ui/vuu-utils"),N=require("react"),Xo=({id:e,placement:o="right",tooltipContent:t})=>{let n=(0,N.useRef)(),r=(0,N.useRef)(null),i=(0,N.useRef)(),s=(0,N.useRef)(),[m,p]=(0,N.useState)(),a=(0,$t.useId)(e),u=(0,N.useCallback)(y=>{var E;y.key==="Escape"&&((E=n.current)==null||E.call(n))},[]);n.current=(0,N.useCallback)(()=>{p(void 0),document.removeEventListener("keydown",u)},[u]);let l=(0,N.useCallback)(()=>{window.clearTimeout(s.current)},[]),c=(0,N.useCallback)(()=>{var y;(y=n.current)==null||y.call(n)},[]),f=(0,N.useCallback)(()=>{let{current:y}=r;y&&(p({anchorElement:r,children:t,id:`${a}-tooltip`,onMouseEnter:l,onMouseLeave:c,placement:o}),document.addEventListener("keydown",u)),i.current=void 0},[u,l,c,a,o,t]),C=(0,N.useCallback)(y=>{let E=y.target;E&&(r.current=E,i.current=window.setTimeout(f,800))},[f]),v=(0,N.useCallback)(()=>{r.current&&(i.current?(window.clearTimeout(i.current),i.current=void 0):n.current&&(s.current=window.setTimeout(n.current,200)))},[]);return{anchorProps:{"aria-describedby":`${a}-tooltip`,onMouseEnter:C,onMouseLeave:v},tooltipProps:m}};var O=A(require("react")),Xe=A(require("clsx")),Kt=require("@vuu-ui/vuu-utils");var B=require("react/jsx-runtime"),Jo=60,zt=6e3,Je=1e3,Yo=300,Ft=56,ke=300,jo=10,Qo=10,Re=50,Te="vuuToastNotifications",Wt=(r=>(r.Info="info",r.Success="success",r.Warning="warning",r.Error="error",r))(Wt||{}),Ye=O.default.createContext({notify:()=>"have you forgotten to provide a NotificationProvider?"}),Zo=e=>{let[o,t]=(0,O.useState)([]),n=(0,O.useCallback)(r=>{let i={...r,id:(0,Kt.getUniqueId)()};t(s=>[...s,i]),setTimeout(()=>{t(s=>s.filter(m=>m!==i))},zt+Je*2)},[]);return(0,B.jsxs)(Ye.Provider,{value:{notify:n},children:[(0,B.jsx)("div",{style:{width:ke+Re+Qo},children:o.map((r,i)=>(0,B.jsx)(qt,{top:Jo+(Ft+jo)*i,notification:r},r.id))}),e.children]})},_o=()=>(0,O.useContext)(Ye),qt=e=>{let{top:o,notification:t,animated:n=!0}=e,[r,i]=(0,O.useState)(-ke-Re);return(0,O.useEffect)(()=>{setTimeout(()=>i(Re)),n&&setTimeout(()=>i(-ke-Re),zt+Je)},[n]),(0,B.jsx)(Q,{children:(0,B.jsxs)("div",{className:(0,Xe.default)(`${Te}-toast`,t.type),style:{height:Ft,right:r,width:ke,top:o,transition:n?`right ${Je}ms, top ${Yo}ms `:"none"},children:[(0,B.jsx)("div",{className:(0,Xe.default)(`${Te}-toastIcon`,`${t.type}-icon`)}),(0,B.jsxs)("div",{className:`${Te}-toastContent`,children:[(0,B.jsx)("strong",{className:`${Te}-toastHeader`,children:t.header}),(0,B.jsx)("div",{children:t.body})]})]})})};
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ContextMenu: () => ContextMenu,
34
+ ContextMenuContext: () => ContextMenuContext,
35
+ ContextMenuProvider: () => ContextMenuProvider,
36
+ Dialog: () => Dialog,
37
+ DialogHeader: () => DialogHeader,
38
+ DialogService: () => DialogService,
39
+ MenuItem: () => MenuItem,
40
+ MenuItemGroup: () => MenuItemGroup,
41
+ MenuList: () => MenuList,
42
+ NotificationLevel: () => NotificationLevel,
43
+ NotificationsContext: () => NotificationsContext,
44
+ NotificationsProvider: () => NotificationsProvider,
45
+ PopupComponent: () => PopupComponent2,
46
+ PopupMenu: () => PopupMenu,
47
+ PopupService: () => PopupService,
48
+ Portal: () => Portal,
49
+ Prompt: () => Prompt,
50
+ Separator: () => Separator,
51
+ ToastNotification: () => ToastNotification,
52
+ Tooltip: () => Tooltip,
53
+ createContainer: () => createContainer,
54
+ isMenuItemLabel: () => isMenuItemLabel,
55
+ reasonIsClickAway: () => reasonIsClickAway,
56
+ reasonIsMenuAction: () => reasonIsMenuAction,
57
+ renderPortal: () => renderPortal,
58
+ useAnchoredPosition: () => useAnchoredPosition,
59
+ useContextMenu: () => useContextMenu,
60
+ useDialog: () => useDialog,
61
+ useNotifications: () => useNotifications,
62
+ useTooltip: () => useTooltip
63
+ });
64
+ module.exports = __toCommonJS(src_exports);
65
+
66
+ // src/dialog/Dialog.tsx
67
+ var import_clsx5 = __toESM(require("clsx"));
68
+ var import_vuu_utils = require("@vuu-ui/vuu-utils");
69
+ var import_react3 = require("react");
70
+
71
+ // src/dialog-header/DialogHeader.tsx
72
+ var import_core = require("@salt-ds/core");
73
+ var import_clsx = __toESM(require("clsx"));
74
+ var import_jsx_runtime = require("react/jsx-runtime");
75
+ var classBase = "vuuDialogHeader";
76
+ var DialogHeader = ({
77
+ hideCloseButton = false,
78
+ title,
79
+ onClose,
80
+ ...htmlAttributes
81
+ }) => {
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...htmlAttributes, className: (0, import_clsx.default)(classBase, "vuuToolbarProxy"), children: [
83
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Text, { className: "dialogHeader", children: title }),
84
+ !hideCloseButton && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
85
+ import_core.Button,
86
+ {
87
+ onClick: onClose,
88
+ "data-align": "end",
89
+ "data-icon": "close",
90
+ variant: "secondary"
91
+ },
92
+ "close"
93
+ )
94
+ ] });
95
+ };
96
+
97
+ // src/popup/popup-service.ts
98
+ var import_clsx3 = __toESM(require("clsx"));
99
+ var import_react = __toESM(require("react"));
100
+ var import_react_dom = __toESM(require("react-dom"));
101
+
102
+ // src/portal-deprecated/render-portal.tsx
103
+ var ReactDOM = __toESM(require("react-dom"));
104
+ var import_clsx2 = __toESM(require("clsx"));
105
+ var containerId = 1;
106
+ var getPortalContainer = ({
107
+ className,
108
+ dataMode,
109
+ x = 0,
110
+ y = 0,
111
+ win = window
112
+ }) => {
113
+ const el = win.document.createElement("div");
114
+ el.className = (0, import_clsx2.default)(`vuuPopup ${containerId++}`, className);
115
+ el.style.cssText = `left:${x}px; top:${y}px;`;
116
+ if (dataMode) {
117
+ el.dataset.mode = dataMode;
118
+ }
119
+ win.document.body.appendChild(el);
120
+ return el;
121
+ };
122
+ var createContainer = (props) => getPortalContainer(props);
123
+ var renderPortal = (component, container, x, y, onRender) => {
124
+ container.style.cssText = `left:${x}px; top:${y}px;position: absolute;`;
125
+ ReactDOM.render(component, container, onRender);
126
+ };
127
+
128
+ // src/popup/popup-service.ts
129
+ var _dialogOpen = false;
130
+ var _popups = [];
131
+ var reasonIsMenuAction = (reason) => (reason == null ? void 0 : reason.type) === "menu-action";
132
+ var reasonIsClickAway = (reason) => (reason == null ? void 0 : reason.type) === "click-away";
133
+ function specialKeyHandler(e) {
134
+ if (e.key === "Esc") {
135
+ if (_popups.length) {
136
+ closeAllPopups();
137
+ } else if (_dialogOpen) {
138
+ const dialogRoot = document.body.querySelector(".vuuDialog");
139
+ if (dialogRoot) {
140
+ import_react_dom.default.unmountComponentAtNode(dialogRoot);
141
+ }
142
+ }
143
+ }
144
+ }
145
+ function outsideClickHandler(e) {
146
+ if (_popups.length) {
147
+ const popupContainers = document.body.querySelectorAll(
148
+ ".vuuPopup,#vuu-portal-root"
149
+ );
150
+ for (let i = 0; i < popupContainers.length; i++) {
151
+ if (popupContainers[i].contains(e.target)) {
152
+ return;
153
+ }
154
+ }
155
+ closeAllPopups({ mouseEvt: e, type: "click-away" });
156
+ }
157
+ }
158
+ function closeAllPopups(reason) {
159
+ if (_popups.length === 1) {
160
+ PopupService.hidePopup(reason, "anon", "all");
161
+ } else if (_popups.length) {
162
+ const popupContainers = document.body.querySelectorAll(".vuuPopup");
163
+ for (let i = 0; i < popupContainers.length; i++) {
164
+ import_react_dom.default.unmountComponentAtNode(popupContainers[i]);
165
+ }
166
+ popupClosed("*");
167
+ }
168
+ }
169
+ function dialogOpened() {
170
+ if (_dialogOpen === false) {
171
+ _dialogOpen = true;
172
+ window.addEventListener("keydown", specialKeyHandler, true);
173
+ }
174
+ }
175
+ function dialogClosed() {
176
+ if (_dialogOpen) {
177
+ _dialogOpen = false;
178
+ window.removeEventListener("keydown", specialKeyHandler, true);
179
+ }
180
+ }
181
+ function popupOpened(name) {
182
+ if (_popups.indexOf(name) === -1) {
183
+ _popups.push(name);
184
+ if (_dialogOpen === false) {
185
+ window.addEventListener("keydown", specialKeyHandler, true);
186
+ window.addEventListener("click", outsideClickHandler, true);
187
+ }
188
+ }
189
+ }
190
+ function popupClosed(name) {
191
+ if (_popups.length) {
192
+ if (name === "*") {
193
+ _popups.length = 0;
194
+ } else {
195
+ const pos = _popups.indexOf(name);
196
+ if (pos !== -1) {
197
+ _popups.splice(pos, 1);
198
+ }
199
+ }
200
+ if (_popups.length === 0 && _dialogOpen === false) {
201
+ window.removeEventListener("keydown", specialKeyHandler, true);
202
+ window.removeEventListener("click", outsideClickHandler, true);
203
+ }
204
+ }
205
+ }
206
+ var PopupComponent = ({
207
+ children,
208
+ position,
209
+ style
210
+ }) => {
211
+ const className = (0, import_clsx3.default)("hwPopup", "hwPopupContainer", position);
212
+ return (0, import_react.createElement)("div", { className, style }, children);
213
+ };
214
+ var incrementingKey = 1;
215
+ var PopupService = class _PopupService {
216
+ static showPopup({
217
+ group = "all",
218
+ name = "anon",
219
+ left = 0,
220
+ position = "",
221
+ right = "auto",
222
+ top = 0,
223
+ width = "auto",
224
+ component
225
+ }) {
226
+ if (!component) {
227
+ throw Error(`PopupService showPopup, no component supplied`);
228
+ }
229
+ if (typeof component.props.onClose === "function") {
230
+ _PopupService.onClose = component.props.onClose;
231
+ } else {
232
+ _PopupService.onClose = void 0;
233
+ }
234
+ popupOpened(name);
235
+ document.addEventListener("keydown", _PopupService.escapeKeyListener, true);
236
+ let el = document.body.querySelector(".vuuPopup." + group);
237
+ if (el === null) {
238
+ el = document.createElement("div");
239
+ el.className = "vuuPopup " + group;
240
+ document.body.appendChild(el);
241
+ }
242
+ const style = { width };
243
+ renderPortal(
244
+ (0, import_react.createElement)(
245
+ PopupComponent,
246
+ { key: incrementingKey++, position, style },
247
+ component
248
+ ),
249
+ el,
250
+ left,
251
+ top,
252
+ () => {
253
+ _PopupService.keepWithinThePage(el, right);
254
+ }
255
+ );
256
+ }
257
+ static escapeKeyListener(evt) {
258
+ if (evt.key === "Escape") {
259
+ _PopupService.hidePopup({ type: "escape", event: evt });
260
+ }
261
+ }
262
+ static hidePopup(reason, name = "anon", group = "all") {
263
+ var _a;
264
+ if (_popups.indexOf(name) !== -1) {
265
+ popupClosed(name);
266
+ const popupRoot = document.body.querySelector(`.vuuPopup.${group}`);
267
+ if (popupRoot) {
268
+ import_react_dom.default.unmountComponentAtNode(popupRoot);
269
+ }
270
+ }
271
+ document.removeEventListener(
272
+ "keydown",
273
+ _PopupService.escapeKeyListener,
274
+ true
275
+ );
276
+ (_a = _PopupService == null ? void 0 : _PopupService.onClose) == null ? void 0 : _a.call(
277
+ _PopupService,
278
+ reason ? {
279
+ ...reason,
280
+ closedBy: "popup-service"
281
+ } : void 0
282
+ );
283
+ }
284
+ static keepWithinThePage(el, right = "auto") {
285
+ const target = el.querySelector(".vuuPopupContainer > *");
286
+ if (target) {
287
+ const {
288
+ top,
289
+ left,
290
+ width,
291
+ height,
292
+ right: currentRight
293
+ } = target.getBoundingClientRect();
294
+ const w = window.innerWidth;
295
+ const h = window.innerHeight;
296
+ const overflowH = h - (top + height);
297
+ if (overflowH < 0) {
298
+ target.style.top = Math.round(top) + overflowH + "px";
299
+ }
300
+ const overflowW = w - (left + width);
301
+ if (overflowW < 0) {
302
+ target.style.left = Math.round(left) + overflowW + "px";
303
+ }
304
+ if (typeof right === "number" && right !== currentRight) {
305
+ const adjustment = right - currentRight;
306
+ target.style.left = left + adjustment + "px";
307
+ }
308
+ }
309
+ }
310
+ };
311
+ var DialogService = class _DialogService {
312
+ static showDialog(dialog) {
313
+ const containerEl = ".vuuDialog";
314
+ const onClose = dialog.props.onClose;
315
+ dialogOpened();
316
+ import_react_dom.default.render(
317
+ import_react.default.cloneElement(dialog, {
318
+ container: containerEl,
319
+ onClose: () => {
320
+ _DialogService.closeDialog();
321
+ if (onClose) {
322
+ onClose();
323
+ }
324
+ }
325
+ }),
326
+ document.body.querySelector(containerEl)
327
+ );
328
+ }
329
+ static closeDialog() {
330
+ dialogClosed();
331
+ const dialogRoot = document.body.querySelector(".vuuDialog");
332
+ if (dialogRoot) {
333
+ import_react_dom.default.unmountComponentAtNode(dialogRoot);
334
+ }
335
+ }
336
+ };
337
+
338
+ // src/popup/Popup.tsx
339
+ var import_clsx4 = __toESM(require("clsx"));
340
+
341
+ // src/popup/useAnchoredPosition.ts
342
+ var import_react2 = require("react");
343
+
344
+ // src/popup/getPositionRelativeToAnchor.ts
345
+ var getPositionRelativeToAnchor = (anchorElement, placement, offsetLeft, offsetTop, minWidth, dimensions) => {
346
+ const { bottom, height, left, right, top, width } = anchorElement.getBoundingClientRect();
347
+ switch (placement) {
348
+ case "below":
349
+ return { left: left + offsetLeft, top: bottom + offsetTop };
350
+ case "right":
351
+ return { left: right + offsetLeft, top: top + offsetTop };
352
+ case "below-center":
353
+ return { left: left + width / 2 + offsetLeft, top: bottom + offsetTop };
354
+ case "below-right":
355
+ return { left, minWidth, top: bottom + offsetTop };
356
+ case "below-full-width":
357
+ return {
358
+ left: left + offsetLeft,
359
+ minWidth,
360
+ top: bottom + offsetTop,
361
+ width
362
+ };
363
+ case "center":
364
+ if (dimensions) {
365
+ return {
366
+ left: width / 2 - dimensions.width / 2 + offsetLeft,
367
+ top: height / 2 - dimensions.height / 2 + offsetTop,
368
+ visibility: "visible"
369
+ };
370
+ } else {
371
+ return {
372
+ left: width / 2 + offsetLeft,
373
+ top: height / 2 + offsetTop,
374
+ visibility: "hidden"
375
+ };
376
+ }
377
+ default:
378
+ throw Error(
379
+ `Popup getPositionRelativeToAnchor non-supported placement value ${placement}`
380
+ );
381
+ }
382
+ };
383
+
384
+ // src/popup/useAnchoredPosition.ts
385
+ var useAnchoredPosition = ({
386
+ anchorElement,
387
+ minWidth,
388
+ offsetLeft = 0,
389
+ offsetTop = 0,
390
+ placement,
391
+ position: positionProp
392
+ }) => {
393
+ const popupRef = (0, import_react2.useRef)(null);
394
+ const [position, setPosition] = (0, import_react2.useState)(positionProp);
395
+ (0, import_react2.useLayoutEffect)(() => {
396
+ if (placement === "absolute" && positionProp) {
397
+ setPosition(positionProp);
398
+ } else if (anchorElement.current && placement !== "auto") {
399
+ const dimensions = popupRef.current === null ? void 0 : popupRef.current.getBoundingClientRect();
400
+ const position2 = getPositionRelativeToAnchor(
401
+ anchorElement.current,
402
+ placement,
403
+ offsetLeft,
404
+ offsetTop,
405
+ minWidth,
406
+ dimensions
407
+ );
408
+ setPosition(position2);
409
+ }
410
+ }, [anchorElement, minWidth, offsetLeft, offsetTop, placement, positionProp]);
411
+ const popupCallbackRef = (0, import_react2.useCallback)(
412
+ (el) => {
413
+ popupRef.current = el;
414
+ if (el && placement === "center" && anchorElement.current) {
415
+ const { height, width } = el.getBoundingClientRect();
416
+ setPosition(
417
+ getPositionRelativeToAnchor(
418
+ anchorElement.current,
419
+ placement,
420
+ offsetLeft,
421
+ offsetTop,
422
+ void 0,
423
+ { height, width }
424
+ )
425
+ );
426
+ }
427
+ },
428
+ [anchorElement, offsetLeft, offsetTop, placement]
429
+ );
430
+ return {
431
+ position,
432
+ popupRef: placement === "center" ? popupCallbackRef : void 0
433
+ };
434
+ };
435
+
436
+ // src/popup/Popup.tsx
437
+ var import_jsx_runtime2 = require("react/jsx-runtime");
438
+ var PopupComponent2 = ({
439
+ children,
440
+ className,
441
+ anchorElement,
442
+ minWidth,
443
+ placement,
444
+ position: positionProp
445
+ }) => {
446
+ const { popupRef, position } = useAnchoredPosition({
447
+ anchorElement,
448
+ minWidth,
449
+ placement,
450
+ position: positionProp
451
+ });
452
+ return position === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: (0, import_clsx4.default)(`vuuPortal`, className), ref: popupRef, style: position, children });
453
+ };
454
+
455
+ // src/dialog/Dialog.tsx
456
+ var import_jsx_runtime3 = require("react/jsx-runtime");
457
+ var classBase2 = "vuuDialog";
458
+ var AnchorBody = { current: document.body };
459
+ var EMPTY_PROPS = {};
460
+ var Dialog = ({
461
+ PopupProps = EMPTY_PROPS,
462
+ children,
463
+ className,
464
+ isOpen = false,
465
+ onClose,
466
+ style,
467
+ title,
468
+ hideCloseButton = false,
469
+ ...htmlAttributes
470
+ }) => {
471
+ const {
472
+ anchorElement = AnchorBody,
473
+ offsetLeft = 0,
474
+ offsetTop = 0,
475
+ placement = "auto"
476
+ } = PopupProps;
477
+ const rootRef = (0, import_react3.useRef)(null);
478
+ const portalRef = (0, import_react3.useRef)(null);
479
+ const [themeClass, _, dataMode] = (0, import_vuu_utils.useThemeAttributes)();
480
+ const { position } = useAnchoredPosition({
481
+ anchorElement,
482
+ offsetLeft,
483
+ offsetTop,
484
+ placement
485
+ });
486
+ const close = (0, import_react3.useCallback)(() => {
487
+ onClose == null ? void 0 : onClose();
488
+ }, [onClose]);
489
+ (0, import_react3.useLayoutEffect)(() => {
490
+ if (rootRef.current) {
491
+ if (isOpen) {
492
+ rootRef.current.showModal();
493
+ const { left, top } = rootRef.current.getBoundingClientRect();
494
+ if (portalRef.current) {
495
+ portalRef.current.style.cssText = `left:-${left}px;position:absolute;top:-${top}px;`;
496
+ }
497
+ } else {
498
+ rootRef.current.close();
499
+ }
500
+ if (placement.endsWith("center")) {
501
+ const { width } = rootRef.current.getBoundingClientRect();
502
+ rootRef.current.style.marginLeft = `-${width / 2}px`;
503
+ }
504
+ }
505
+ }, [isOpen, placement]);
506
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
507
+ "dialog",
508
+ {
509
+ ...htmlAttributes,
510
+ className: (0, import_clsx5.default)(classBase2, themeClass),
511
+ "data-mode": dataMode,
512
+ onClose: close,
513
+ id: "vuu-dialog",
514
+ ref: rootRef,
515
+ style: { ...style, ...position },
516
+ children: [
517
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
518
+ DialogHeader,
519
+ {
520
+ hideCloseButton,
521
+ onClose: close,
522
+ title
523
+ }
524
+ ),
525
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `${classBase2}-body`, children }),
526
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { id: "vuu-dialog-portal-root", ref: portalRef })
527
+ ]
528
+ }
529
+ );
530
+ };
531
+
532
+ // src/dialog/useDialog.tsx
533
+ var import_react4 = require("react");
534
+ var import_jsx_runtime4 = require("react/jsx-runtime");
535
+ var useDialog = () => {
536
+ const [dialogState, setDialogState] = (0, import_react4.useState)();
537
+ const handleClose = (0, import_react4.useCallback)(() => {
538
+ setDialogState(void 0);
539
+ }, []);
540
+ const dialog = dialogState ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
541
+ Dialog,
542
+ {
543
+ className: "vuDialog",
544
+ isOpen: true,
545
+ onClose: handleClose,
546
+ style: { maxHeight: 500 },
547
+ title: dialogState.title,
548
+ hideCloseButton: dialogState.hideCloseButton,
549
+ children: dialogState.content
550
+ }
551
+ ) : null;
552
+ return {
553
+ dialog,
554
+ setDialogState
555
+ };
556
+ };
557
+
558
+ // src/menu/ContextMenu.tsx
559
+ var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
560
+ var import_react10 = require("react");
561
+
562
+ // src/portal/Portal.tsx
563
+ var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
564
+ var import_react5 = require("react");
565
+ var import_react_dom2 = require("react-dom");
566
+ function getContainer(container) {
567
+ return typeof container === "function" ? container() : container;
568
+ }
569
+ var DEFAULT_ID = ["vuu-dialog-portal-root", "vuu-portal-root"];
570
+ var getFirstAvailableElementById = (id) => {
571
+ if (Array.isArray(id)) {
572
+ for (const i of id) {
573
+ const element = document.getElementById(i);
574
+ if (element) {
575
+ return element;
576
+ }
577
+ }
578
+ } else {
579
+ return document.getElementById(id);
580
+ }
581
+ return null;
582
+ };
583
+ var Portal = ({
584
+ children,
585
+ container: containerProp = document.body,
586
+ id = DEFAULT_ID,
587
+ onRender,
588
+ open = true,
589
+ themeAttributes
590
+ }) => {
591
+ var _a;
592
+ const [mounted, setMounted] = (0, import_react5.useState)(false);
593
+ const portalRef = (0, import_react5.useRef)(null);
594
+ const container = (_a = getContainer(containerProp)) != null ? _a : document.body;
595
+ const [themeClass, densityClass, dataMode] = (0, import_vuu_utils2.useThemeAttributes)(themeAttributes);
596
+ (0, import_react5.useLayoutEffect)(() => {
597
+ const root = getFirstAvailableElementById(id);
598
+ if (root) {
599
+ portalRef.current = root;
600
+ } else {
601
+ portalRef.current = document.createElement("div");
602
+ portalRef.current.id = typeof id === "string" ? id : id.length > 0 ? id.at(-1) : "vuu-portal-root";
603
+ }
604
+ const el = portalRef.current;
605
+ if (!container.contains(el)) {
606
+ container.appendChild(el);
607
+ }
608
+ el.classList.add(themeClass, densityClass);
609
+ el.dataset.mode = dataMode;
610
+ setMounted(true);
611
+ }, [id, container, themeClass, densityClass, dataMode]);
612
+ (0, import_react5.useLayoutEffect)(() => {
613
+ requestAnimationFrame(() => {
614
+ onRender == null ? void 0 : onRender();
615
+ });
616
+ }, [onRender]);
617
+ if (open && mounted && portalRef.current && children) {
618
+ return (0, import_react_dom2.createPortal)(children, portalRef.current);
619
+ }
620
+ return null;
621
+ };
622
+
623
+ // src/menu/MenuList.tsx
624
+ var import_clsx6 = __toESM(require("clsx"));
625
+ var import_react8 = __toESM(require("react"));
626
+ var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
627
+
628
+ // src/menu/use-items-with-ids-next.ts
629
+ var import_react6 = __toESM(require("react"));
630
+ var isMenuItemGroup = (child) => child.type === MenuItemGroup || !!child.props["data-group"];
631
+ var getLabelFromChildren = (children) => {
632
+ if (Array.isArray(children) && isMenuItemLabel(children[0])) {
633
+ return children[0];
634
+ }
635
+ };
636
+ var assignId = (child, path, group, hasSeparator = false) => {
637
+ const {
638
+ props: { children }
639
+ } = child;
640
+ return {
641
+ childWithId: import_react6.default.cloneElement(child, {
642
+ hasSeparator,
643
+ id: `${path}`,
644
+ key: path,
645
+ children: group ? getLabelFromChildren(children) : children
646
+ }),
647
+ grandChildren: group ? children : void 0
648
+ };
649
+ };
650
+ var useItemsWithIdsNext = (childrenProp, rootId) => {
651
+ const normalizeChildren = (0, import_react6.useCallback)(() => {
652
+ const collectChildren = (children, path = rootId, menus2 = {}, actions2 = {}) => {
653
+ const list = menus2[path] = [];
654
+ let idx = 0;
655
+ let hasSeparator = false;
656
+ import_react6.default.Children.forEach(children, (child) => {
657
+ if (isMenuItemLabel(child)) {
658
+ } else if (child.type === Separator) {
659
+ hasSeparator = true;
660
+ } else {
661
+ const hasChildItems = isMenuItemGroup(child);
662
+ const childPath = `${path}-${idx}`;
663
+ const {
664
+ props: { action, options }
665
+ } = child;
666
+ const { childWithId, grandChildren } = assignId(
667
+ child,
668
+ childPath,
669
+ hasChildItems,
670
+ hasSeparator
671
+ );
672
+ list.push(childWithId);
673
+ if (grandChildren) {
674
+ collectChildren(grandChildren, childPath, menus2, actions2);
675
+ } else {
676
+ actions2[childPath] = { action, options };
677
+ }
678
+ idx += 1;
679
+ hasSeparator = false;
680
+ }
681
+ });
682
+ return [menus2, actions2];
683
+ };
684
+ return collectChildren(childrenProp);
685
+ }, [rootId, childrenProp]);
686
+ const [menus, actions] = (0, import_react6.useMemo)(
687
+ () => normalizeChildren(),
688
+ [normalizeChildren]
689
+ );
690
+ return [menus, actions];
691
+ };
692
+
693
+ // src/menu/use-keyboard-navigation.ts
694
+ var import_react7 = require("react");
695
+
696
+ // src/menu/utils.ts
697
+ var isRoot = (el) => el.closest(`[data-root='true']`) !== null;
698
+ var hasPopup = (el, idx) => {
699
+ var _a;
700
+ return el.ariaHasPopup === "true" && ((_a = el.dataset) == null ? void 0 : _a.idx) === `${idx}` || el.querySelector(`:scope > [data-index='${idx}'][aria-haspopup='true']`) !== null;
701
+ };
702
+
703
+ // src/menu/key-code.ts
704
+ function union(set1, ...sets) {
705
+ const result = new Set(set1);
706
+ for (const set of sets) {
707
+ for (const element of set) {
708
+ result.add(element);
709
+ }
710
+ }
711
+ return result;
712
+ }
713
+ var Enter = "Enter";
714
+ var Delete = "Delete";
715
+ var actionKeys = /* @__PURE__ */ new Set([Enter, Delete]);
716
+ var focusKeys = /* @__PURE__ */ new Set(["Tab"]);
717
+ var arrowLeftRightKeys = /* @__PURE__ */ new Set(["ArrowRight", "ArrowLeft"]);
718
+ var verticalNavigationKeys = /* @__PURE__ */ new Set(["Home", "End", "ArrowDown", "ArrowUp"]);
719
+ var horizontalNavigationKeys = /* @__PURE__ */ new Set([
720
+ "Home",
721
+ "End",
722
+ "ArrowRight",
723
+ "ArrowLeft"
724
+ ]);
725
+ var functionKeys = /* @__PURE__ */ new Set([
726
+ "F1",
727
+ "F2",
728
+ "F3",
729
+ "F4",
730
+ "F5",
731
+ "F6",
732
+ "F7",
733
+ "F8",
734
+ "F9",
735
+ "F10",
736
+ "F11",
737
+ "F12"
738
+ ]);
739
+ var specialKeys = union(
740
+ actionKeys,
741
+ horizontalNavigationKeys,
742
+ verticalNavigationKeys,
743
+ arrowLeftRightKeys,
744
+ functionKeys,
745
+ focusKeys
746
+ );
747
+ var isNavigationKey = ({ key }, orientation = "vertical") => {
748
+ const navigationKeys = orientation === "vertical" ? verticalNavigationKeys : horizontalNavigationKeys;
749
+ return navigationKeys.has(key);
750
+ };
751
+
752
+ // src/menu/use-keyboard-navigation.ts
753
+ var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
754
+ var useKeyboardNavigation = ({
755
+ autoHighlightFirstItem = false,
756
+ count,
757
+ defaultHighlightedIdx,
758
+ highlightedIndex: highlightedIndexProp,
759
+ onActivate,
760
+ onHighlight,
761
+ // onKeyDown,
762
+ onCloseMenu,
763
+ onOpenMenu
764
+ }) => {
765
+ var _a;
766
+ if ((0, import_vuu_utils3.isValidNumber)(highlightedIndexProp) && (0, import_vuu_utils3.isValidNumber)(defaultHighlightedIdx)) {
767
+ throw Error(
768
+ "useKeyboardNavigation do not pass values for both highlightedIndex and defaultHighlightedIdx"
769
+ );
770
+ }
771
+ const controlledHighlighting = (0, import_vuu_utils3.isValidNumber)(highlightedIndexProp);
772
+ const highlightedIndexRef = (0, import_react7.useRef)(
773
+ (_a = defaultHighlightedIdx != null ? defaultHighlightedIdx : highlightedIndexProp) != null ? _a : autoHighlightFirstItem ? 0 : -1
774
+ );
775
+ const [, forceRender] = (0, import_react7.useState)(null);
776
+ const setHighlightedIdx = (0, import_react7.useCallback)(
777
+ (idx) => {
778
+ highlightedIndexRef.current = idx;
779
+ onHighlight == null ? void 0 : onHighlight(idx);
780
+ forceRender({});
781
+ },
782
+ [onHighlight]
783
+ );
784
+ const setHighlightedIndex = (0, import_react7.useCallback)(
785
+ (idx) => {
786
+ if (idx !== highlightedIndexRef.current) {
787
+ if (!controlledHighlighting) {
788
+ setHighlightedIdx(idx);
789
+ }
790
+ }
791
+ },
792
+ [controlledHighlighting, setHighlightedIdx]
793
+ );
794
+ const keyBoardNavigation = (0, import_react7.useRef)(true);
795
+ const ignoreFocus = (0, import_react7.useRef)(false);
796
+ const setIgnoreFocus = (value) => ignoreFocus.current = value;
797
+ const highlightedIndex = controlledHighlighting ? highlightedIndexProp : highlightedIndexRef.current;
798
+ const navigateChildldItems = (0, import_react7.useCallback)(
799
+ (e) => {
800
+ const nextIdx = nextItemIdx(count, e.key, highlightedIndexRef.current);
801
+ if (nextIdx !== highlightedIndexRef.current) {
802
+ setHighlightedIndex(nextIdx);
803
+ }
804
+ },
805
+ [count, setHighlightedIndex]
806
+ );
807
+ const handleKeyDown = (0, import_react7.useCallback)(
808
+ (e) => {
809
+ if (isNavigationKey(e)) {
810
+ e.preventDefault();
811
+ e.stopPropagation();
812
+ keyBoardNavigation.current = true;
813
+ navigateChildldItems(e);
814
+ } else if ((e.key === "ArrowRight" || e.key === "Enter") && hasPopup(e.target, highlightedIndex)) {
815
+ const menuEl = e.target;
816
+ const menuItemEl = menuEl.querySelector(
817
+ `:scope > [data-index='${highlightedIndex}']`
818
+ );
819
+ if (menuItemEl) {
820
+ onOpenMenu == null ? void 0 : onOpenMenu(menuItemEl, true);
821
+ }
822
+ } else if (e.key === "ArrowLeft" && !isRoot(e.target)) {
823
+ onCloseMenu(e, "close-child-menu");
824
+ } else if (e.key === "Enter") {
825
+ e.preventDefault();
826
+ e.stopPropagation();
827
+ onActivate && onActivate(highlightedIndex);
828
+ } else if (e.key === "Tab") {
829
+ onCloseMenu(e, "tab-away");
830
+ }
831
+ },
832
+ [
833
+ highlightedIndex,
834
+ navigateChildldItems,
835
+ onActivate,
836
+ onCloseMenu,
837
+ onOpenMenu
838
+ ]
839
+ );
840
+ const listProps = (0, import_react7.useMemo)(
841
+ () => ({
842
+ onFocus: () => {
843
+ if (highlightedIndex === -1) {
844
+ setHighlightedIdx(0);
845
+ }
846
+ },
847
+ onKeyDown: handleKeyDown,
848
+ onMouseDownCapture: () => {
849
+ keyBoardNavigation.current = false;
850
+ setIgnoreFocus(true);
851
+ },
852
+ // onMouseEnter would seem less expensive but it misses some cases
853
+ onMouseMove: () => {
854
+ if (keyBoardNavigation.current) {
855
+ keyBoardNavigation.current = false;
856
+ }
857
+ },
858
+ onMouseLeave: () => {
859
+ keyBoardNavigation.current = true;
860
+ setIgnoreFocus(false);
861
+ setHighlightedIndex(-1);
862
+ }
863
+ }),
864
+ [handleKeyDown, highlightedIndex, setHighlightedIdx, setHighlightedIndex]
865
+ );
866
+ return {
867
+ focusVisible: keyBoardNavigation.current ? highlightedIndex : -1,
868
+ controlledHighlighting,
869
+ highlightedIndex,
870
+ setHighlightedIndex,
871
+ // keyBoardNavigation,
872
+ listProps,
873
+ setIgnoreFocus
874
+ };
875
+ };
876
+ function nextItemIdx(count, key, idx) {
877
+ if (key === "ArrowUp") {
878
+ if (idx > 0) {
879
+ return idx - 1;
880
+ } else {
881
+ return idx;
882
+ }
883
+ } else {
884
+ if (idx === null) {
885
+ return 0;
886
+ } else if (idx === count - 1) {
887
+ return idx;
888
+ } else {
889
+ return idx + 1;
890
+ }
891
+ }
892
+ }
893
+
894
+ // src/menu/MenuList.tsx
895
+ var import_jsx_runtime5 = require("react/jsx-runtime");
896
+ var classBase3 = "vuuMenuList";
897
+ var Separator = () => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "vuuMenuItem-divider" });
898
+ var MenuItemGroup = () => null;
899
+ var MenuItem = ({
900
+ children,
901
+ idx,
902
+ options,
903
+ ...props
904
+ }) => {
905
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ...props, children });
906
+ };
907
+ var MenuItemLabel = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children });
908
+ MenuItemLabel.displayName = "MenuItemLabel";
909
+ MenuItem.Label = MenuItemLabel;
910
+ var getDisplayName = (item) => import_react8.default.isValidElement(item) && typeof item.type !== "string" && "displayName" in item.type ? item.type.displayName : void 0;
911
+ var isMenuItemLabel = (item) => getDisplayName(item) === "MenuItemLabel";
912
+ var hasIcon = (child) => child.props["data-icon"];
913
+ var MenuList = ({
914
+ activatedByKeyboard,
915
+ childMenuShowing,
916
+ children,
917
+ className,
918
+ defaultHighlightedIdx,
919
+ highlightedIdx: highlightedIdxProp,
920
+ id: idProp,
921
+ isRoot: isRoot2,
922
+ listItemProps,
923
+ onHighlightMenuItem,
924
+ onActivate,
925
+ onCloseMenu,
926
+ openMenu: onOpenMenu,
927
+ ...props
928
+ }) => {
929
+ const id = (0, import_vuu_utils4.useId)(idProp);
930
+ const root = (0, import_react8.useRef)(null);
931
+ const mapIdxToId = (0, import_react8.useMemo)(() => /* @__PURE__ */ new Map(), []);
932
+ const handleActivate = (idx) => {
933
+ var _a;
934
+ const el = (_a = root.current) == null ? void 0 : _a.querySelector(`:scope > [data-index='${idx}']`);
935
+ (el == null ? void 0 : el.id) && (onActivate == null ? void 0 : onActivate(el.id));
936
+ };
937
+ const { focusVisible, highlightedIndex, listProps } = useKeyboardNavigation({
938
+ count: import_react8.default.Children.count(children),
939
+ defaultHighlightedIdx,
940
+ highlightedIndex: highlightedIdxProp,
941
+ onActivate: handleActivate,
942
+ onHighlight: onHighlightMenuItem,
943
+ onOpenMenu,
944
+ onCloseMenu
945
+ });
946
+ const appliedFocusVisible = childMenuShowing == void 0 ? focusVisible : -1;
947
+ (0, import_react8.useLayoutEffect)(() => {
948
+ var _a;
949
+ if (childMenuShowing === void 0 && activatedByKeyboard) {
950
+ (_a = root.current) == null ? void 0 : _a.focus();
951
+ }
952
+ }, [activatedByKeyboard, childMenuShowing]);
953
+ const getActiveDescendant = () => highlightedIndex === void 0 || highlightedIndex === -1 ? void 0 : mapIdxToId.get(highlightedIndex);
954
+ function renderContent() {
955
+ const propsCommonToAllListItems = {
956
+ ...listItemProps,
957
+ role: "menuitem"
958
+ };
959
+ const maybeIcon = (childElement, withIcon, iconName) => withIcon ? [
960
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
961
+ "span",
962
+ {
963
+ className: "vuuIconContainer",
964
+ "data-icon": iconName
965
+ },
966
+ "icon"
967
+ )
968
+ ].concat(childElement) : childElement;
969
+ function addClonedChild(list, child, idx, withIcon) {
970
+ var _a;
971
+ const {
972
+ children: children2,
973
+ className: className2,
974
+ "data-icon": iconName,
975
+ id: itemId,
976
+ hasSeparator,
977
+ label,
978
+ ...props2
979
+ } = child.props;
980
+ const hasSubMenu = isMenuItemGroup(child);
981
+ const subMenuShowing = hasSubMenu && childMenuShowing === itemId;
982
+ const ariaControls = subMenuShowing ? `${id}-${itemId}` : void 0;
983
+ list.push(
984
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
985
+ MenuItem,
986
+ {
987
+ ...props2,
988
+ ...propsCommonToAllListItems,
989
+ ...getMenuItemProps(
990
+ itemId,
991
+ idx,
992
+ (_a = child.key) != null ? _a : itemId,
993
+ highlightedIndex,
994
+ appliedFocusVisible,
995
+ className2,
996
+ hasSeparator
997
+ ),
998
+ "aria-controls": ariaControls,
999
+ "aria-haspopup": hasSubMenu || void 0,
1000
+ "aria-expanded": subMenuShowing || void 0,
1001
+ children: hasSubMenu ? maybeIcon(label != null ? label : children2, withIcon, iconName) : maybeIcon(children2, withIcon, iconName)
1002
+ }
1003
+ )
1004
+ );
1005
+ }
1006
+ const listItems = [];
1007
+ if (children.length > 0) {
1008
+ const withIcon = children.some(hasIcon);
1009
+ children.forEach((child, idx) => {
1010
+ addClonedChild(listItems, child, idx, withIcon);
1011
+ });
1012
+ }
1013
+ return listItems;
1014
+ }
1015
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1016
+ "div",
1017
+ {
1018
+ ...props,
1019
+ ...listProps,
1020
+ "aria-activedescendant": getActiveDescendant(),
1021
+ className: (0, import_clsx6.default)(classBase3, className, {
1022
+ [`${classBase3}-childMenuShowing`]: childMenuShowing !== void 0
1023
+ }),
1024
+ "data-root": isRoot2 || void 0,
1025
+ id,
1026
+ ref: root,
1027
+ role: "menu",
1028
+ children: renderContent()
1029
+ }
1030
+ );
1031
+ };
1032
+ var getMenuItemProps = (itemId, idx, key, highlightedIdx, focusVisible, className, hasSeparator) => ({
1033
+ id: `menuitem-${itemId}`,
1034
+ key: key != null ? key : idx,
1035
+ "data-index": idx,
1036
+ "data-highlighted": idx === highlightedIdx || void 0,
1037
+ className: (0, import_clsx6.default)("vuuMenuItem", className, {
1038
+ "vuuMenuItem-separator": hasSeparator,
1039
+ focusVisible: focusVisible === idx
1040
+ })
1041
+ });
1042
+ MenuList.displayName = "MenuList";
1043
+
1044
+ // src/menu/use-cascade.ts
1045
+ var import_react9 = require("react");
1046
+
1047
+ // src/menu/list-dom-utils.ts
1048
+ var closestListItem = (el) => el == null ? void 0 : el.closest("[data-index],[aria-posinset]");
1049
+
1050
+ // src/menu/use-cascade.ts
1051
+ var nudge = (menus, distance, pos) => {
1052
+ return menus.map(
1053
+ (m, i) => i === menus.length - 1 ? {
1054
+ ...m,
1055
+ [pos]: m[pos] - distance
1056
+ } : m
1057
+ );
1058
+ };
1059
+ var nudgeLeft = (menus, distance) => nudge(menus, distance, "left");
1060
+ var nudgeUp = (menus, distance) => nudge(menus, distance, "top");
1061
+ var flipSides = (id, menus) => {
1062
+ const [parentMenu, menu] = menus.slice(-2);
1063
+ const el = document.getElementById(`${id}-${menu.id}`);
1064
+ if (el === null) {
1065
+ throw Error(`useCascade.flipSides element with id ${menu.id} not found`);
1066
+ }
1067
+ const { width } = el.getBoundingClientRect();
1068
+ return menus.map(
1069
+ (m) => m === menu ? {
1070
+ ...m,
1071
+ left: parentMenu.left - (width - 2)
1072
+ } : m
1073
+ );
1074
+ };
1075
+ var getPosition = (el, openMenus) => {
1076
+ const [{ left, top: menuTop }] = openMenus.slice(-1);
1077
+ const { offsetWidth: width, offsetTop: top } = el;
1078
+ return { left: left + width, top: top + menuTop };
1079
+ };
1080
+ var getHostMenuId = (id, rootId) => {
1081
+ const pos = id.lastIndexOf("-");
1082
+ if (id.startsWith("menuitem")) {
1083
+ return pos > -1 ? id.slice(9, pos) : rootId;
1084
+ } else {
1085
+ return pos > -1 ? id.slice(0, pos) : rootId;
1086
+ }
1087
+ };
1088
+ var getTargetMenuId = (id) => id.slice(9);
1089
+ var getMenuItemDetails = ({ ariaExpanded, ariaHasPopup, id }, rootId) => {
1090
+ if (id.startsWith("menuitem")) {
1091
+ return {
1092
+ hostMenuId: getHostMenuId(id, rootId),
1093
+ targetMenuId: getTargetMenuId(id),
1094
+ menuItemId: id,
1095
+ isGroup: ariaHasPopup === "true",
1096
+ isOpen: ariaExpanded === "true"
1097
+ };
1098
+ } else {
1099
+ throw Error(`getMenuItemDetails #${id} is not a menuitem`);
1100
+ }
1101
+ };
1102
+ var useCascade = ({
1103
+ id: rootId,
1104
+ onActivate,
1105
+ onMouseEnterItem,
1106
+ position: { x: posX, y: posY }
1107
+ }) => {
1108
+ const [, forceRefresh] = (0, import_react9.useState)({});
1109
+ const openMenus = (0, import_react9.useRef)([
1110
+ { id: rootId, left: posX, top: posY }
1111
+ ]);
1112
+ const menuIsOpen = (0, import_react9.useCallback)(
1113
+ (menuId) => openMenus.current.findIndex((menu) => menu.id === menuId) !== -1,
1114
+ []
1115
+ );
1116
+ const getOpenMenuStatus = (0, import_react9.useCallback)((menuId) => {
1117
+ const state = menuState.current[menuId];
1118
+ if (state === void 0) {
1119
+ throw Error(`getOpenMenuState no entry for menu ${menuId}`);
1120
+ }
1121
+ return state;
1122
+ }, []);
1123
+ const setOpenMenus = (0, import_react9.useCallback)((menus) => {
1124
+ openMenus.current = menus;
1125
+ forceRefresh({});
1126
+ }, []);
1127
+ const menuOpenPendingTimeout = (0, import_react9.useRef)();
1128
+ const menuClosePendingTimeout = (0, import_react9.useRef)();
1129
+ const menuState = (0, import_react9.useRef)({ [rootId]: "no-popup" });
1130
+ const openMenu = (0, import_react9.useCallback)(
1131
+ (hostMenuId = rootId, targetMenuId, itemId = null) => {
1132
+ if (hostMenuId === rootId && itemId === null) {
1133
+ setOpenMenus([{ id: rootId, left: posX, top: posY }]);
1134
+ } else {
1135
+ menuState.current[hostMenuId] = "popup-open";
1136
+ const el = document.getElementById(itemId);
1137
+ if (el !== null) {
1138
+ const { left, top } = getPosition(el, openMenus.current);
1139
+ setOpenMenus(
1140
+ openMenus.current.concat({ id: targetMenuId, left, top })
1141
+ );
1142
+ } else {
1143
+ throw Error(`openMenu no menuItem ${itemId}`);
1144
+ }
1145
+ }
1146
+ },
1147
+ [rootId, posX, posY, setOpenMenus]
1148
+ );
1149
+ const closeMenu = (0, import_react9.useCallback)(
1150
+ (menuId) => {
1151
+ if (menuId === rootId) {
1152
+ setOpenMenus([]);
1153
+ } else {
1154
+ const menus = openMenus.current.slice();
1155
+ const lastMenu = menus.pop();
1156
+ menuState.current[lastMenu.id] = "no-popup";
1157
+ const parentMenu = menus.at(-1);
1158
+ if (parentMenu) {
1159
+ menuState.current[parentMenu.id] = "no-popup";
1160
+ }
1161
+ setOpenMenus(menus);
1162
+ }
1163
+ },
1164
+ [rootId, setOpenMenus]
1165
+ );
1166
+ const closeMenus = (0, import_react9.useCallback)(
1167
+ (menuItemId) => {
1168
+ const menus = openMenus.current.slice();
1169
+ const menuItemMenuId = menuItemId.slice(9);
1170
+ let { id: lastMenuId } = menus.at(-1);
1171
+ while (menus.length > 1 && !menuItemMenuId.startsWith(lastMenuId)) {
1172
+ const parentMenuId = getHostMenuId(lastMenuId, rootId);
1173
+ menus.pop();
1174
+ menuState.current[lastMenuId] = "no-popup";
1175
+ menuState.current[parentMenuId] = "no-popup";
1176
+ ({ id: lastMenuId } = menus[menus.length - 1]);
1177
+ }
1178
+ if (menus.length < openMenus.current.length) {
1179
+ setOpenMenus(menus);
1180
+ }
1181
+ },
1182
+ [rootId, setOpenMenus]
1183
+ );
1184
+ const clearAnyScheduledOpenTasks = (0, import_react9.useCallback)(() => {
1185
+ if (menuOpenPendingTimeout.current) {
1186
+ clearTimeout(menuOpenPendingTimeout.current);
1187
+ menuOpenPendingTimeout.current = void 0;
1188
+ }
1189
+ }, []);
1190
+ const scheduleOpen = (0, import_react9.useCallback)(
1191
+ (hostMenuId, targetMenuId, menuItemId, delay = 300) => {
1192
+ clearAnyScheduledOpenTasks();
1193
+ menuOpenPendingTimeout.current = window.setTimeout(() => {
1194
+ closeMenus(menuItemId);
1195
+ menuState.current[hostMenuId] = "popup-open";
1196
+ menuState.current[targetMenuId] = "no-popup";
1197
+ openMenu(hostMenuId, targetMenuId, menuItemId);
1198
+ }, delay);
1199
+ },
1200
+ [clearAnyScheduledOpenTasks, closeMenus, openMenu]
1201
+ );
1202
+ const scheduleClose = (0, import_react9.useCallback)(
1203
+ (hostMenuId, openMenuId, itemId) => {
1204
+ menuState.current[openMenuId] = "pending-close";
1205
+ menuClosePendingTimeout.current = window.setTimeout(() => {
1206
+ closeMenus(itemId);
1207
+ }, 400);
1208
+ },
1209
+ [closeMenus]
1210
+ );
1211
+ const handleRender = (0, import_react9.useCallback)(() => {
1212
+ const { current: menus } = openMenus;
1213
+ const menu = menus.at(-1);
1214
+ const el = menu ? document.getElementById(menu.id) : void 0;
1215
+ if (el) {
1216
+ const { right, bottom } = el.getBoundingClientRect();
1217
+ const { clientHeight, clientWidth } = document.body;
1218
+ if (right > clientWidth) {
1219
+ const newMenus = menus.length > 1 ? flipSides(rootId, menus) : nudgeLeft(menus, right - clientWidth);
1220
+ setOpenMenus(newMenus);
1221
+ } else if (bottom > clientHeight) {
1222
+ const newMenus = nudgeUp(menus, bottom - clientHeight);
1223
+ setOpenMenus(newMenus);
1224
+ }
1225
+ if (typeof el.tabIndex === "number") {
1226
+ el.focus();
1227
+ }
1228
+ }
1229
+ }, [rootId, setOpenMenus]);
1230
+ const triggerChildMenu = (0, import_react9.useCallback)(
1231
+ (menuItemEl, immediate = false) => {
1232
+ const { hostMenuId, targetMenuId, menuItemId, isGroup, isOpen } = getMenuItemDetails(menuItemEl, rootId);
1233
+ const {
1234
+ current: { [hostMenuId]: state }
1235
+ } = menuState;
1236
+ const delay = immediate ? 0 : void 0;
1237
+ if (state === "no-popup" && isGroup) {
1238
+ menuState.current[hostMenuId] = "popup-pending";
1239
+ scheduleOpen(hostMenuId, targetMenuId, menuItemId, delay);
1240
+ } else if (state === "popup-pending" && !isGroup) {
1241
+ menuState.current[hostMenuId] = "no-popup";
1242
+ clearTimeout(menuOpenPendingTimeout.current);
1243
+ menuOpenPendingTimeout.current = void 0;
1244
+ } else if (state === "popup-pending" && isGroup) {
1245
+ clearTimeout(menuOpenPendingTimeout.current);
1246
+ scheduleOpen(hostMenuId, targetMenuId, menuItemId, delay);
1247
+ } else if (state === "popup-open") {
1248
+ if (menuIsOpen(targetMenuId)) {
1249
+ const menuStatus = getOpenMenuStatus(targetMenuId);
1250
+ closeMenus(menuItemId);
1251
+ switch (menuStatus) {
1252
+ case "pending-close":
1253
+ clearTimeout(menuClosePendingTimeout.current);
1254
+ menuClosePendingTimeout.current = void 0;
1255
+ menuState.current[targetMenuId] = "no-popup";
1256
+ clearAnyScheduledOpenTasks();
1257
+ break;
1258
+ default:
1259
+ }
1260
+ } else {
1261
+ const [parentOfLastOpenedMenu, lastOpenedMenu] = openMenus.current.slice(-2);
1262
+ if (parentOfLastOpenedMenu.id === hostMenuId && menuState.current[lastOpenedMenu.id] !== "pending-close") {
1263
+ scheduleClose(hostMenuId, lastOpenedMenu.id, menuItemId);
1264
+ if (isGroup && !isOpen) {
1265
+ scheduleOpen(hostMenuId, targetMenuId, menuItemId, delay);
1266
+ }
1267
+ } else if (parentOfLastOpenedMenu.id === hostMenuId && isGroup && menuItemId !== lastOpenedMenu.id && menuState.current[lastOpenedMenu.id] === "pending-close") {
1268
+ scheduleOpen(hostMenuId, targetMenuId, menuItemId, delay);
1269
+ } else if (isGroup) {
1270
+ scheduleOpen(hostMenuId, targetMenuId, menuItemId, delay);
1271
+ } else if (!(menuState.current[lastOpenedMenu.id] === "pending-close")) {
1272
+ closeMenus(menuItemId);
1273
+ }
1274
+ }
1275
+ }
1276
+ if (state === "pending-close") {
1277
+ clearAnyScheduledOpenTasks();
1278
+ clearTimeout(menuClosePendingTimeout.current);
1279
+ menuClosePendingTimeout.current = void 0;
1280
+ menuState.current[hostMenuId] = "popup-open";
1281
+ }
1282
+ },
1283
+ [
1284
+ clearAnyScheduledOpenTasks,
1285
+ closeMenus,
1286
+ getOpenMenuStatus,
1287
+ menuIsOpen,
1288
+ rootId,
1289
+ scheduleClose,
1290
+ scheduleOpen
1291
+ ]
1292
+ );
1293
+ const listItemProps = (0, import_react9.useMemo)(
1294
+ () => ({
1295
+ onMouseEnter: (evt) => {
1296
+ const menuItemEl = closestListItem(evt.target);
1297
+ triggerChildMenu(menuItemEl);
1298
+ onMouseEnterItem(evt, menuItemEl.id);
1299
+ },
1300
+ onClick: (evt) => {
1301
+ const listItemEl = closestListItem(evt.target);
1302
+ const { isGroup, menuItemId } = getMenuItemDetails(listItemEl, rootId);
1303
+ if (isGroup) {
1304
+ triggerChildMenu(listItemEl);
1305
+ } else {
1306
+ onActivate(menuItemId);
1307
+ }
1308
+ }
1309
+ }),
1310
+ [onActivate, onMouseEnterItem, rootId, triggerChildMenu]
1311
+ );
1312
+ return {
1313
+ closeMenu,
1314
+ handleRender,
1315
+ listItemProps,
1316
+ openMenu: triggerChildMenu,
1317
+ openMenus: openMenus.current
1318
+ };
1319
+ };
1320
+
1321
+ // src/menu/ContextMenu.tsx
1322
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1323
+ var import_react11 = require("react");
1324
+ var noop = () => void 0;
1325
+ var ContextMenu = ({
1326
+ PortalProps: PortalProps2,
1327
+ activatedByKeyboard,
1328
+ children: childrenProp,
1329
+ className,
1330
+ id: idProp,
1331
+ onClose = () => void 0,
1332
+ position = { x: 0, y: 0 },
1333
+ style,
1334
+ ...menuListProps
1335
+ }) => {
1336
+ const id = (0, import_vuu_utils5.useId)(idProp);
1337
+ const closeMenuRef = (0, import_react10.useRef)(noop);
1338
+ const [menus, actions] = useItemsWithIdsNext(childrenProp, id);
1339
+ const navigatingWithKeyboard = (0, import_react10.useRef)(activatedByKeyboard);
1340
+ const handleMouseEnterItem = (0, import_react10.useCallback)(() => {
1341
+ navigatingWithKeyboard.current = false;
1342
+ }, []);
1343
+ const handleActivate = (0, import_react10.useCallback)(
1344
+ (menuItemId) => {
1345
+ const actionId = menuItemId.slice(9);
1346
+ const { action, options } = actions[actionId];
1347
+ closeMenuRef.current(id);
1348
+ onClose({
1349
+ type: "menu-action",
1350
+ menuId: action,
1351
+ options
1352
+ });
1353
+ },
1354
+ [actions, id, onClose]
1355
+ );
1356
+ const {
1357
+ closeMenu,
1358
+ listItemProps,
1359
+ openMenu: onOpenMenu,
1360
+ openMenus,
1361
+ handleRender
1362
+ } = useCascade({
1363
+ // FIXME
1364
+ id: `${id}`,
1365
+ onActivate: handleActivate,
1366
+ onMouseEnterItem: handleMouseEnterItem,
1367
+ position
1368
+ });
1369
+ closeMenuRef.current = closeMenu;
1370
+ const handleCloseMenu = (0, import_react10.useCallback)(
1371
+ (evt, reason) => {
1372
+ navigatingWithKeyboard.current = true;
1373
+ closeMenu();
1374
+ if (reason === "tab-away") {
1375
+ onClose({
1376
+ event: evt,
1377
+ type: "tab-away"
1378
+ });
1379
+ }
1380
+ },
1381
+ [closeMenu, onClose]
1382
+ );
1383
+ const handleHighlightMenuItem = () => {
1384
+ };
1385
+ const lastMenu = openMenus.length - 1;
1386
+ const getChildMenuId = (i) => {
1387
+ if (i >= lastMenu) {
1388
+ return void 0;
1389
+ } else {
1390
+ const { id: id2 } = openMenus[i + 1];
1391
+ return id2;
1392
+ }
1393
+ };
1394
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: openMenus.map(({ id: menuId, left, top }, i, all) => {
1395
+ const childMenuId = getChildMenuId(i);
1396
+ return /* @__PURE__ */ (0, import_react11.createElement)(Portal, { ...PortalProps2, key: i, onRender: handleRender }, /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1397
+ PopupComponent2,
1398
+ {
1399
+ anchorElement: { current: document.body },
1400
+ placement: "absolute",
1401
+ position: { left, top },
1402
+ children: /* @__PURE__ */ (0, import_react11.createElement)(
1403
+ MenuList,
1404
+ {
1405
+ ...menuListProps,
1406
+ activatedByKeyboard: navigatingWithKeyboard.current,
1407
+ childMenuShowing: childMenuId,
1408
+ className,
1409
+ id: menuId,
1410
+ isRoot: i === 0,
1411
+ key: i,
1412
+ listItemProps,
1413
+ onActivate: handleActivate,
1414
+ onHighlightMenuItem: handleHighlightMenuItem,
1415
+ onCloseMenu: handleCloseMenu,
1416
+ openMenu: onOpenMenu,
1417
+ style,
1418
+ tabIndex: i === all.length - 1 ? 0 : void 0
1419
+ },
1420
+ menus[menuId]
1421
+ )
1422
+ }
1423
+ ));
1424
+ }) });
1425
+ };
1426
+ ContextMenu.displayName = "ContextMenu";
1427
+
1428
+ // src/menu/context-menu-provider.tsx
1429
+ var import_react12 = require("react");
1430
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1431
+ var ContextMenuContext = (0, import_react12.createContext)(
1432
+ null
1433
+ );
1434
+ var Provider = ({
1435
+ children,
1436
+ context,
1437
+ menuActionHandler,
1438
+ menuBuilder
1439
+ }) => {
1440
+ const menuBuilders = (0, import_react12.useMemo)(() => {
1441
+ if ((context == null ? void 0 : context.menuBuilders) && menuBuilder) {
1442
+ return context.menuBuilders.concat(menuBuilder);
1443
+ } else if (menuBuilder) {
1444
+ return [menuBuilder];
1445
+ } else {
1446
+ return (context == null ? void 0 : context.menuBuilders) || [];
1447
+ }
1448
+ }, [context, menuBuilder]);
1449
+ const handleMenuAction = (0, import_react12.useCallback)(
1450
+ (reason) => {
1451
+ var _a;
1452
+ if (menuActionHandler == null ? void 0 : menuActionHandler(reason)) {
1453
+ return true;
1454
+ }
1455
+ if ((_a = context == null ? void 0 : context.menuActionHandler) == null ? void 0 : _a.call(context, reason)) {
1456
+ return true;
1457
+ }
1458
+ },
1459
+ [context, menuActionHandler]
1460
+ );
1461
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1462
+ ContextMenuContext.Provider,
1463
+ {
1464
+ value: {
1465
+ menuActionHandler: handleMenuAction,
1466
+ menuBuilders
1467
+ },
1468
+ children
1469
+ }
1470
+ );
1471
+ };
1472
+ var ContextMenuProvider = ({
1473
+ children,
1474
+ label,
1475
+ menuActionHandler,
1476
+ menuBuilder
1477
+ }) => {
1478
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ContextMenuContext.Consumer, { children: (parentContext) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1479
+ Provider,
1480
+ {
1481
+ context: parentContext,
1482
+ label,
1483
+ menuActionHandler,
1484
+ menuBuilder,
1485
+ children
1486
+ }
1487
+ ) });
1488
+ };
1489
+
1490
+ // src/menu/useContextMenu.tsx
1491
+ var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
1492
+ var import_react13 = require("react");
1493
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1494
+ var useContextMenu = (menuBuilder, menuActionHandler) => {
1495
+ const ctx = (0, import_react13.useContext)(ContextMenuContext);
1496
+ const [themeClass, densityClass, dataMode] = (0, import_vuu_utils6.useThemeAttributes)();
1497
+ const themeAttributes = (0, import_react13.useMemo)(
1498
+ () => ({
1499
+ themeClass,
1500
+ densityClass,
1501
+ dataMode
1502
+ }),
1503
+ [dataMode, densityClass, themeClass]
1504
+ );
1505
+ const buildMenuOptions = (0, import_react13.useCallback)(
1506
+ (menuBuilders, location, options) => {
1507
+ let results = [];
1508
+ for (const menuBuilder2 of menuBuilders) {
1509
+ results = results.concat(menuBuilder2(location, options));
1510
+ }
1511
+ return results;
1512
+ },
1513
+ []
1514
+ );
1515
+ const handleShowContextMenu = (0, import_react13.useCallback)(
1516
+ (e, location, { ContextMenuProps: ContextMenuProps2, contextMenu, ...options }) => {
1517
+ var _a, _b;
1518
+ (_a = e.stopPropagation) == null ? void 0 : _a.call(e);
1519
+ (_b = e.preventDefault) == null ? void 0 : _b.call(e);
1520
+ if (contextMenu) {
1521
+ return showContextMenuComponent(
1522
+ {
1523
+ x: e.clientX,
1524
+ y: e.clientY
1525
+ },
1526
+ contextMenu
1527
+ );
1528
+ }
1529
+ const menuBuilders = [];
1530
+ if (menuBuilder) {
1531
+ menuBuilders.push(menuBuilder);
1532
+ }
1533
+ if (ctx && Array.isArray(ctx == null ? void 0 : ctx.menuBuilders) && ctx.menuBuilders.length > 0) {
1534
+ menuBuilders.push(...ctx.menuBuilders);
1535
+ }
1536
+ if (menuBuilders.length > 0) {
1537
+ const menuItemDescriptors = buildMenuOptions(
1538
+ menuBuilders,
1539
+ location,
1540
+ options
1541
+ );
1542
+ const menuHandler = (action) => {
1543
+ if ((menuActionHandler == null ? void 0 : menuActionHandler(action)) === true) {
1544
+ return true;
1545
+ } else {
1546
+ return ctx == null ? void 0 : ctx.menuActionHandler(action);
1547
+ }
1548
+ };
1549
+ if (menuItemDescriptors.length && menuHandler) {
1550
+ showContextMenu(e, menuItemDescriptors, menuHandler, {
1551
+ PortalProps: {
1552
+ themeAttributes
1553
+ },
1554
+ ...ContextMenuProps2
1555
+ });
1556
+ }
1557
+ } else {
1558
+ console.warn(
1559
+ "useContextMenu, no menuBuilders configured. These should be supplied via the ContextMenuProvider(s)"
1560
+ );
1561
+ }
1562
+ },
1563
+ [buildMenuOptions, ctx, menuActionHandler, menuBuilder, themeAttributes]
1564
+ );
1565
+ const hideContextMenu = (0, import_react13.useCallback)(() => {
1566
+ console.log("hide context menu");
1567
+ }, []);
1568
+ return [handleShowContextMenu, hideContextMenu];
1569
+ };
1570
+ var NO_OPTIONS = {};
1571
+ var showContextMenuComponent = (position, contextMenu) => {
1572
+ PopupService.showPopup({
1573
+ focus: true,
1574
+ left: 0,
1575
+ top: 0,
1576
+ component: (0, import_react13.cloneElement)(contextMenu, { position })
1577
+ });
1578
+ };
1579
+ var showContextMenu = (e, menuDescriptors, handleContextMenuAction, {
1580
+ position: positionProp,
1581
+ ...contextMenuProps
1582
+ } = NO_OPTIONS) => {
1583
+ const menuItems = (menuDescriptors2) => {
1584
+ const fromDescriptor = (menuItem, i) => (0, import_vuu_utils6.isGroupMenuItemDescriptor)(menuItem) ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MenuItemGroup, { label: menuItem.label, children: menuItem.children.map(fromDescriptor) }, i) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1585
+ MenuItem,
1586
+ {
1587
+ action: menuItem.action,
1588
+ className: menuItem.className,
1589
+ "data-icon": menuItem.icon,
1590
+ options: menuItem.options,
1591
+ children: menuItem.label
1592
+ },
1593
+ i
1594
+ );
1595
+ return menuDescriptors2.map(fromDescriptor);
1596
+ };
1597
+ const handleClose = (reason) => {
1598
+ var _a;
1599
+ if (reasonIsMenuAction(reason)) {
1600
+ if ((reason == null ? void 0 : reason.closedBy) === "popup-service") {
1601
+ return;
1602
+ }
1603
+ handleContextMenuAction(reason);
1604
+ PopupService.hidePopup(reason);
1605
+ }
1606
+ (_a = contextMenuProps == null ? void 0 : contextMenuProps.onClose) == null ? void 0 : _a.call(contextMenuProps, reason);
1607
+ };
1608
+ const position = positionProp != null ? positionProp : {
1609
+ x: e.clientX,
1610
+ y: e.clientY
1611
+ };
1612
+ const component = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1613
+ ContextMenu,
1614
+ {
1615
+ ...contextMenuProps,
1616
+ onClose: handleClose,
1617
+ position,
1618
+ children: menuItems(menuDescriptors)
1619
+ }
1620
+ );
1621
+ PopupService.showPopup({ left: 0, top: 0, component, focus: true });
1622
+ };
1623
+
1624
+ // src/popup-menu/PopupMenu.tsx
1625
+ var import_vuu_ui_controls = require("@vuu-ui/vuu-ui-controls");
1626
+ var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
1627
+ var import_core2 = require("@salt-ds/core");
1628
+ var import_clsx7 = __toESM(require("clsx"));
1629
+
1630
+ // src/popup-menu/usePopupMenu.ts
1631
+ var import_react14 = require("react");
1632
+ var usePopupMenu = ({
1633
+ anchorElement,
1634
+ id,
1635
+ menuActionHandler,
1636
+ menuBuilder,
1637
+ menuClassName,
1638
+ menuLocation,
1639
+ menuOptions,
1640
+ onMenuClose,
1641
+ onMenuOpen,
1642
+ popupPlacement,
1643
+ tabIndex
1644
+ }) => {
1645
+ const [menuOpen, _setMenuOpen] = (0, import_react14.useState)(false);
1646
+ const suppressShowMenuRef = (0, import_react14.useRef)(false);
1647
+ const rootRef = (0, import_react14.useRef)(null);
1648
+ const setMenuOpen = (0, import_react14.useCallback)(
1649
+ (isOpen) => {
1650
+ _setMenuOpen(isOpen);
1651
+ if (isOpen) {
1652
+ onMenuOpen == null ? void 0 : onMenuOpen();
1653
+ }
1654
+ },
1655
+ [onMenuOpen]
1656
+ );
1657
+ const [showContextMenu2] = useContextMenu(menuBuilder, menuActionHandler);
1658
+ const handleOpenMenu = (0, import_react14.useCallback)((el) => {
1659
+ console.log(`menu Open `, {
1660
+ el
1661
+ });
1662
+ }, []);
1663
+ const handleMenuClose = (0, import_react14.useCallback)(
1664
+ (reason) => {
1665
+ console.log("onClose");
1666
+ setMenuOpen(false);
1667
+ if (reasonIsClickAway(reason)) {
1668
+ const target = reason.mouseEvt.target;
1669
+ if (target === rootRef.current) {
1670
+ suppressShowMenuRef.current = true;
1671
+ }
1672
+ onMenuClose == null ? void 0 : onMenuClose(reason);
1673
+ } else {
1674
+ requestAnimationFrame(() => {
1675
+ var _a;
1676
+ onMenuClose == null ? void 0 : onMenuClose(reason);
1677
+ if (tabIndex !== -1 && (reason == null ? void 0 : reason.type) !== "tab-away") {
1678
+ (_a = rootRef.current) == null ? void 0 : _a.focus();
1679
+ }
1680
+ });
1681
+ }
1682
+ },
1683
+ [onMenuClose, setMenuOpen, tabIndex]
1684
+ );
1685
+ const showMenu = (0, import_react14.useCallback)(
1686
+ (e) => {
1687
+ var _a;
1688
+ if (suppressShowMenuRef.current) {
1689
+ suppressShowMenuRef.current = false;
1690
+ } else {
1691
+ const anchorEl = (_a = anchorElement == null ? void 0 : anchorElement.current) != null ? _a : rootRef.current;
1692
+ if (anchorEl) {
1693
+ const {
1694
+ left: x,
1695
+ top: y,
1696
+ width
1697
+ } = getPositionRelativeToAnchor(anchorEl, popupPlacement, 0, 0);
1698
+ setMenuOpen(true);
1699
+ showContextMenu2(e, menuLocation, {
1700
+ ContextMenuProps: {
1701
+ className: menuClassName,
1702
+ id: `${id}-menu`,
1703
+ onClose: handleMenuClose,
1704
+ openMenu: handleOpenMenu,
1705
+ position: {
1706
+ x,
1707
+ y
1708
+ },
1709
+ style: { width: width ? width - 2 : void 0 }
1710
+ },
1711
+ ...menuOptions
1712
+ });
1713
+ }
1714
+ }
1715
+ },
1716
+ [
1717
+ anchorElement,
1718
+ handleMenuClose,
1719
+ handleOpenMenu,
1720
+ id,
1721
+ menuClassName,
1722
+ menuLocation,
1723
+ menuOptions,
1724
+ popupPlacement,
1725
+ setMenuOpen,
1726
+ showContextMenu2
1727
+ ]
1728
+ );
1729
+ const ariaAttributes = {
1730
+ "aria-controls": menuOpen ? `${id}-menu` : void 0,
1731
+ "aria-expanded": menuOpen,
1732
+ "aria-haspopup": "menu"
1733
+ };
1734
+ const buttonProps = {
1735
+ id,
1736
+ onClick: showMenu,
1737
+ tabIndex
1738
+ };
1739
+ return { ariaAttributes, buttonProps, menuOpen, rootRef };
1740
+ };
1741
+
1742
+ // src/popup-menu/PopupMenu.tsx
1743
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1744
+ var classBase4 = "vuuPopupMenu";
1745
+ var PopupMenu = ({
1746
+ anchorElement,
1747
+ className,
1748
+ disabled = false,
1749
+ label,
1750
+ icon = label ? "chevron-down" : "more-vert",
1751
+ id: idProp,
1752
+ menuActionHandler,
1753
+ menuBuilder,
1754
+ menuClassName,
1755
+ menuLocation = "header",
1756
+ menuOptions,
1757
+ onMenuClose,
1758
+ onMenuOpen,
1759
+ popupPlacement = "below-right",
1760
+ tabIndex = 0,
1761
+ variant = "secondary",
1762
+ ...htmlAttributes
1763
+ }) => {
1764
+ const id = (0, import_vuu_utils7.useId)(idProp);
1765
+ const { ariaAttributes, buttonProps, menuOpen, rootRef } = usePopupMenu({
1766
+ anchorElement,
1767
+ id,
1768
+ menuActionHandler,
1769
+ menuBuilder,
1770
+ menuClassName,
1771
+ menuLocation,
1772
+ onMenuClose,
1773
+ onMenuOpen,
1774
+ menuOptions,
1775
+ popupPlacement,
1776
+ tabIndex
1777
+ });
1778
+ if (label) {
1779
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1780
+ import_core2.Button,
1781
+ {
1782
+ ...htmlAttributes,
1783
+ ...ariaAttributes,
1784
+ ...buttonProps,
1785
+ className: (0, import_clsx7.default)(classBase4, className, `${classBase4}-withCaption`, {
1786
+ "saltButton-active": menuOpen
1787
+ }),
1788
+ disabled,
1789
+ ref: rootRef,
1790
+ variant: "secondary",
1791
+ children: [
1792
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_vuu_ui_controls.Icon, { name: icon }) : null,
1793
+ label
1794
+ ]
1795
+ }
1796
+ );
1797
+ } else if (icon) {
1798
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1799
+ import_vuu_ui_controls.IconButton,
1800
+ {
1801
+ ...htmlAttributes,
1802
+ ...ariaAttributes,
1803
+ ...buttonProps,
1804
+ className: (0, import_clsx7.default)(classBase4, className, {
1805
+ "saltButton-active": menuOpen
1806
+ }),
1807
+ disabled,
1808
+ icon,
1809
+ ref: rootRef,
1810
+ variant
1811
+ }
1812
+ );
1813
+ } else {
1814
+ console.error("PopupMenu must have a label or an icon (or both)");
1815
+ return null;
1816
+ }
1817
+ };
1818
+
1819
+ // src/prompt/Prompt.tsx
1820
+ var import_vuu_utils8 = require("@vuu-ui/vuu-utils");
1821
+ var import_core3 = require("@salt-ds/core");
1822
+ var import_clsx8 = __toESM(require("clsx"));
1823
+ var import_react15 = require("react");
1824
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1825
+ var classBase5 = "vuuPrompt";
1826
+ var AnchorBody2 = { current: document.body };
1827
+ var EMPTY_PROPS2 = {};
1828
+ var Prompt = ({
1829
+ PopupProps = EMPTY_PROPS2,
1830
+ cancelButtonLabel = "Cancel",
1831
+ confirmButtonLabel = "Confirm",
1832
+ icon,
1833
+ onCancel,
1834
+ onConfirm,
1835
+ style,
1836
+ text,
1837
+ title,
1838
+ variant = "info",
1839
+ ...htmlAttributes
1840
+ }) => {
1841
+ const {
1842
+ anchorElement = AnchorBody2,
1843
+ offsetLeft = 0,
1844
+ offsetTop = 0,
1845
+ placement = "below"
1846
+ } = PopupProps;
1847
+ const [themeClass, _, dataMode] = (0, import_vuu_utils8.useThemeAttributes)();
1848
+ const { position } = useAnchoredPosition({
1849
+ anchorElement,
1850
+ offsetLeft,
1851
+ offsetTop,
1852
+ placement
1853
+ });
1854
+ const rootRef = (0, import_react15.useRef)(null);
1855
+ const confirmRef = (0, import_react15.useRef)(null);
1856
+ (0, import_react15.useLayoutEffect)(() => {
1857
+ if (rootRef.current) {
1858
+ rootRef.current.showModal();
1859
+ if (confirmRef.current) {
1860
+ confirmRef.current.focus();
1861
+ }
1862
+ if (placement.endsWith("center")) {
1863
+ const { width } = rootRef.current.getBoundingClientRect();
1864
+ rootRef.current.style.marginLeft = `-${width / 2}px`;
1865
+ }
1866
+ }
1867
+ }, [placement]);
1868
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1869
+ "dialog",
1870
+ {
1871
+ ...htmlAttributes,
1872
+ className: (0, import_clsx8.default)(classBase5, `${classBase5}-${variant}`, themeClass),
1873
+ "data-mode": dataMode,
1874
+ ref: rootRef,
1875
+ style: { ...style, ...position },
1876
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("form", { className: `${classBase5}-form`, children: [
1877
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: `${classBase5}-header`, "data-icon": icon, children: title }),
1878
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: `${classBase5}-text`, children: text }),
1879
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `${classBase5}-buttonBar`, children: [
1880
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core3.Button, { onClick: onCancel, variant: "secondary", children: cancelButtonLabel }),
1881
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core3.Button, { onClick: onConfirm, ref: confirmRef, value: "default", children: confirmButtonLabel })
1882
+ ] })
1883
+ ] })
1884
+ }
1885
+ );
1886
+ };
1887
+
1888
+ // src/tooltip/useAnchoredPosition.ts
1889
+ var import_react16 = require("react");
1890
+ var getPositionRelativeToAnchor2 = (anchorElement, placement, offsetLeft, offsetTop) => {
1891
+ const { bottom, height, left, right, top, width } = anchorElement.getBoundingClientRect();
1892
+ const midX = left + width / 2;
1893
+ const midY = top + height / 2;
1894
+ switch (placement) {
1895
+ case "above":
1896
+ return { left: midX + offsetLeft, top: top + offsetTop };
1897
+ case "below":
1898
+ return { left: midX + offsetLeft, top: bottom + offsetTop };
1899
+ case "right":
1900
+ return { left: right + offsetLeft, top: midY + offsetLeft };
1901
+ case "left":
1902
+ return { left: left + offsetLeft, top: midY + offsetLeft };
1903
+ default:
1904
+ throw Error(
1905
+ "Tooltip getPositionRelativeToAnchor only supported placement values are left, right, below and right"
1906
+ );
1907
+ }
1908
+ };
1909
+ var useAnchoredPosition2 = ({
1910
+ anchorElement,
1911
+ offsetLeft = 0,
1912
+ offsetTop = 0,
1913
+ placement
1914
+ }) => {
1915
+ const [position, setPosition] = (0, import_react16.useState)();
1916
+ (0, import_react16.useLayoutEffect)(() => {
1917
+ if (anchorElement.current) {
1918
+ const position2 = getPositionRelativeToAnchor2(
1919
+ anchorElement.current,
1920
+ placement,
1921
+ offsetLeft,
1922
+ offsetTop
1923
+ );
1924
+ setPosition(position2);
1925
+ }
1926
+ }, [anchorElement, offsetLeft, offsetTop, placement]);
1927
+ return position;
1928
+ };
1929
+
1930
+ // src/tooltip/Tooltip.tsx
1931
+ var import_clsx9 = __toESM(require("clsx"));
1932
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1933
+ var classBase6 = "vuuTooltip";
1934
+ var Tooltip = ({
1935
+ anchorElement,
1936
+ children,
1937
+ id,
1938
+ onMouseEnter,
1939
+ onMouseLeave,
1940
+ placement,
1941
+ status,
1942
+ style: styleProp
1943
+ }) => {
1944
+ const position = useAnchoredPosition2({ anchorElement, placement });
1945
+ if (position === void 0) {
1946
+ return null;
1947
+ }
1948
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1949
+ "div",
1950
+ {
1951
+ className: (0, import_clsx9.default)(classBase6, {
1952
+ [`${classBase6}-error`]: status === "error"
1953
+ }),
1954
+ "data-align": placement,
1955
+ id,
1956
+ style: { ...styleProp, ...position },
1957
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1958
+ "span",
1959
+ {
1960
+ className: `${classBase6}-content`,
1961
+ onMouseEnter,
1962
+ onMouseLeave,
1963
+ children
1964
+ }
1965
+ )
1966
+ }
1967
+ ) });
1968
+ };
1969
+
1970
+ // src/tooltip/useTooltip.ts
1971
+ var import_vuu_utils9 = require("@vuu-ui/vuu-utils");
1972
+ var import_react17 = require("react");
1973
+ var useTooltip = ({
1974
+ id: idProp,
1975
+ placement = "right",
1976
+ tooltipContent
1977
+ }) => {
1978
+ const hideTooltipRef = (0, import_react17.useRef)();
1979
+ const anchorElementRef = (0, import_react17.useRef)(null);
1980
+ const mouseEnterTimerRef = (0, import_react17.useRef)();
1981
+ const mouseLeaveTimerRef = (0, import_react17.useRef)();
1982
+ const [tooltipProps, setTooltipProps] = (0, import_react17.useState)();
1983
+ const id = (0, import_vuu_utils9.useId)(idProp);
1984
+ const escapeListener = (0, import_react17.useCallback)((evt) => {
1985
+ var _a;
1986
+ if (evt.key === "Escape") {
1987
+ (_a = hideTooltipRef.current) == null ? void 0 : _a.call(hideTooltipRef);
1988
+ }
1989
+ }, []);
1990
+ hideTooltipRef.current = (0, import_react17.useCallback)(() => {
1991
+ setTooltipProps(void 0);
1992
+ document.removeEventListener("keydown", escapeListener);
1993
+ }, [escapeListener]);
1994
+ const handleMouseEnterTooltip = (0, import_react17.useCallback)(() => {
1995
+ window.clearTimeout(mouseLeaveTimerRef.current);
1996
+ }, []);
1997
+ const handleMouseLeaveTooltip = (0, import_react17.useCallback)(() => {
1998
+ var _a;
1999
+ (_a = hideTooltipRef.current) == null ? void 0 : _a.call(hideTooltipRef);
2000
+ }, []);
2001
+ const showTooltip = (0, import_react17.useCallback)(() => {
2002
+ const { current: anchorEl } = anchorElementRef;
2003
+ if (anchorEl) {
2004
+ setTooltipProps({
2005
+ anchorElement: anchorElementRef,
2006
+ children: tooltipContent,
2007
+ id: `${id}-tooltip`,
2008
+ onMouseEnter: handleMouseEnterTooltip,
2009
+ onMouseLeave: handleMouseLeaveTooltip,
2010
+ placement
2011
+ });
2012
+ document.addEventListener("keydown", escapeListener);
2013
+ }
2014
+ mouseEnterTimerRef.current = void 0;
2015
+ }, [
2016
+ escapeListener,
2017
+ handleMouseEnterTooltip,
2018
+ handleMouseLeaveTooltip,
2019
+ id,
2020
+ placement,
2021
+ tooltipContent
2022
+ ]);
2023
+ const handleMouseEnter = (0, import_react17.useCallback)(
2024
+ (evt) => {
2025
+ const el = evt.target;
2026
+ if (el) {
2027
+ anchorElementRef.current = el;
2028
+ mouseEnterTimerRef.current = window.setTimeout(showTooltip, 800);
2029
+ }
2030
+ },
2031
+ [showTooltip]
2032
+ );
2033
+ const handleMouseLeave = (0, import_react17.useCallback)(() => {
2034
+ if (anchorElementRef.current)
2035
+ if (mouseEnterTimerRef.current) {
2036
+ window.clearTimeout(mouseEnterTimerRef.current);
2037
+ mouseEnterTimerRef.current = void 0;
2038
+ } else {
2039
+ if (hideTooltipRef.current) {
2040
+ mouseLeaveTimerRef.current = window.setTimeout(
2041
+ hideTooltipRef.current,
2042
+ 200
2043
+ );
2044
+ }
2045
+ }
2046
+ }, []);
2047
+ const anchorProps = {
2048
+ "aria-describedby": `${id}-tooltip`,
2049
+ onMouseEnter: handleMouseEnter,
2050
+ onMouseLeave: handleMouseLeave
2051
+ };
2052
+ return {
2053
+ anchorProps,
2054
+ tooltipProps
2055
+ };
2056
+ };
2057
+
2058
+ // src/notifications/NotificationsProvider.tsx
2059
+ var import_react18 = __toESM(require("react"));
2060
+ var import_clsx10 = __toESM(require("clsx"));
2061
+ var import_vuu_utils10 = require("@vuu-ui/vuu-utils");
2062
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2063
+ var toastOffsetTop = 60;
2064
+ var toastDisplayDuration = 6e3;
2065
+ var horizontalTransitionDuration = 1e3;
2066
+ var verticalTransitionDuration = 300;
2067
+ var toastHeight = 56;
2068
+ var toastWidth = 300;
2069
+ var toastContainerContentGap = 10;
2070
+ var toastContainerLeftPadding = 10;
2071
+ var toastContainerRightPadding = 50;
2072
+ var classBase7 = "vuuToastNotifications";
2073
+ var NotificationLevel = /* @__PURE__ */ ((NotificationLevel2) => {
2074
+ NotificationLevel2["Info"] = "info";
2075
+ NotificationLevel2["Success"] = "success";
2076
+ NotificationLevel2["Warning"] = "warning";
2077
+ NotificationLevel2["Error"] = "error";
2078
+ return NotificationLevel2;
2079
+ })(NotificationLevel || {});
2080
+ var NotificationsContext = import_react18.default.createContext({
2081
+ notify: () => "have you forgotten to provide a NotificationProvider?"
2082
+ });
2083
+ var NotificationsProvider = (props) => {
2084
+ const [notifications, setNotifications] = (0, import_react18.useState)([]);
2085
+ const notify = (0, import_react18.useCallback)((notification) => {
2086
+ const newNotification = { ...notification, id: (0, import_vuu_utils10.getUniqueId)() };
2087
+ setNotifications((prev) => [...prev, newNotification]);
2088
+ setTimeout(() => {
2089
+ setNotifications((prev) => prev.filter((n) => n !== newNotification));
2090
+ }, toastDisplayDuration + horizontalTransitionDuration * 2);
2091
+ }, []);
2092
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(NotificationsContext.Provider, { value: { notify }, children: [
2093
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2094
+ "div",
2095
+ {
2096
+ style: {
2097
+ width: toastWidth + toastContainerRightPadding + toastContainerLeftPadding
2098
+ },
2099
+ children: notifications.map((notification, i) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2100
+ ToastNotification,
2101
+ {
2102
+ top: toastOffsetTop + (toastHeight + toastContainerContentGap) * i,
2103
+ notification
2104
+ },
2105
+ notification.id
2106
+ ))
2107
+ }
2108
+ ),
2109
+ props.children
2110
+ ] });
2111
+ };
2112
+ var useNotifications = () => (0, import_react18.useContext)(NotificationsContext);
2113
+ var ToastNotification = (props) => {
2114
+ const { top, notification, animated = true } = props;
2115
+ const [right, setRight] = (0, import_react18.useState)(-toastWidth - toastContainerRightPadding);
2116
+ (0, import_react18.useEffect)(() => {
2117
+ setTimeout(() => setRight(toastContainerRightPadding));
2118
+ if (animated) {
2119
+ setTimeout(
2120
+ () => setRight(-toastWidth - toastContainerRightPadding),
2121
+ toastDisplayDuration + horizontalTransitionDuration
2122
+ );
2123
+ }
2124
+ }, [animated]);
2125
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
2126
+ "div",
2127
+ {
2128
+ className: (0, import_clsx10.default)(`${classBase7}-toast`, notification.type),
2129
+ style: {
2130
+ height: toastHeight,
2131
+ right,
2132
+ width: toastWidth,
2133
+ top,
2134
+ transition: animated ? `right ${horizontalTransitionDuration}ms, top ${verticalTransitionDuration}ms ` : "none"
2135
+ },
2136
+ children: [
2137
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2138
+ "div",
2139
+ {
2140
+ className: (0, import_clsx10.default)(
2141
+ `${classBase7}-toastIcon`,
2142
+ `${notification.type}-icon`
2143
+ )
2144
+ }
2145
+ ),
2146
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: `${classBase7}-toastContent`, children: [
2147
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { className: `${classBase7}-toastHeader`, children: notification.header }),
2148
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { children: notification.body })
2149
+ ] })
2150
+ ]
2151
+ }
2152
+ ) });
2153
+ };
2
2154
  //# sourceMappingURL=index.js.map