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