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