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