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