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