@vuu-ui/vuu-popups 0.8.13 → 0.8.14-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 +2 -2
- package/esm/index.js +1973 -1
- package/esm/index.js.map +2 -2
- package/index.css +424 -1
- package/index.css.map +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -201
package/cjs/index.js
CHANGED
|
@@ -1,2 +1,1987 @@
|
|
|
1
|
-
"use strict";var Yt=Object.create;var de=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var jt=Object.getPrototypeOf,_t=Object.prototype.hasOwnProperty;var eo=(e,o)=>{for(var t in o)de(e,t,{get:o[t],enumerable:!0})},je=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of Zt(o))!_t.call(e,r)&&r!==t&&de(e,r,{get:()=>o[r],enumerable:!(n=Qt(o,r))||n.enumerable});return e};var k=(e,o,t)=>(t=e!=null?Yt(jt(e)):{},je(o||!e||!e.__esModule?de(t,"default",{value:e,enumerable:!0}):t,e)),to=e=>je(de({},"__esModule",{value:!0}),e);var _o={};eo(_o,{ContextMenu:()=>ye,ContextMenuContext:()=>ie,ContextMenuProvider:()=>Ro,Dialog:()=>Ae,DialogHeader:()=>Ie,DialogService:()=>ue,MenuItem:()=>re,MenuItemGroup:()=>ne,MenuList:()=>be,NotificationLevel:()=>Gt,NotificationsContext:()=>ze,NotificationsProvider:()=>Zo,PopupComponent:()=>$e,PopupMenu:()=>Fo,PopupService:()=>I,Portal:()=>W,Prompt:()=>Go,Separator:()=>De,ToastNotification:()=>Vt,Tooltip:()=>Uo,createContainer:()=>Io,isMenuItemLabel:()=>he,reasonIsClickAway:()=>We,reasonIsMenuAction:()=>Fe,renderPortal:()=>Ke,useAnchoredPosition:()=>le,useContextMenu:()=>qe,useDialog:()=>so,useNotifications:()=>jo,useTooltip:()=>Xo});module.exports=to(_o);var ot=require("@salt-ds/lab"),nt=k(require("classnames")),fe=require("react");var _e=require("@vuu-ui/vuu-shell"),z=require("react"),et=require("react-dom");function oo(e){return typeof e=="function"?e():e}var no="vuu-portal-root",W=({children:e,container:o=document.body,id:t=no,onRender:n,open:r=!0,themeAttributes:s})=>{var g;let[i,d]=(0,z.useState)(!1),c=(0,z.useRef)(null),a=(g=oo(o))!=null?g:document.body,[u,l,p]=(0,_e.useThemeAttributes)(s);return(0,z.useLayoutEffect)(()=>{let v=document.getElementById(t);v?c.current=v:(c.current=document.createElement("div"),c.current.id=t);let M=c.current;a.contains(M)||a.appendChild(M),M.classList.add(u,l),M.dataset.mode=p,d(!0)},[t,a,u,l,p]),(0,z.useLayoutEffect)(()=>{requestAnimationFrame(()=>{n==null||n()})},[n]),r&&i&&c.current&&e?(0,et.createPortal)(e,c.current):null};var me=require("@salt-ds/core"),tt=k(require("classnames"));var oe=require("react/jsx-runtime"),ro="vuuDialogHeader",Ie=({hideCloseButton:e=!1,title:o,onClose:t,...n})=>(0,oe.jsxs)("div",{...n,className:(0,tt.default)(ro,"vuuToolbarProxy"),children:[(0,oe.jsx)(me.Text,{className:"dialogHeader",children:o}),!e&&(0,oe.jsx)(me.Button,{onClick:t,"data-align":"end","data-icon":"close",variant:"secondary"},"close")]});var Y=require("react/jsx-runtime"),ke="vuuDialog",Ae=({children:e,className:o,isOpen:t=!1,onClose:n,title:r,hideCloseButton:s=!1,...i})=>{let d=(0,fe.useRef)(null),c=(0,fe.useCallback)(()=>{n==null||n()},[n]);return t?(0,Y.jsx)(W,{children:(0,Y.jsx)(ot.Scrim,{className:`${ke}-scrim`,open:t,autoFocusRef:d,children:(0,Y.jsxs)("div",{...i,className:(0,nt.default)(ke,o),ref:d,children:[(0,Y.jsx)(Ie,{hideCloseButton:s,onClose:c,title:r}),(0,Y.jsx)("div",{className:`${ke}-body`,children:e})]})})}):null};var ge=require("react");var rt=require("react/jsx-runtime"),so=()=>{let[e,o]=(0,ge.useState)(),t=(0,ge.useCallback)(()=>{o(void 0)},[]);return{dialog:e?(0,rt.jsx)(Ae,{className:"vuDialog",isOpen:!0,onClose:t,style:{maxHeight:500},title:e.title,hideCloseButton:e.hideCloseButton,children:e.content}):null,setDialogState:o}};var Z=require("react");var G=k(require("react")),Se=k(require("classnames")),mt=require("@vuu-ui/vuu-layout");var S=require("react");var st=e=>e.closest("[data-root='true']")!==null,it=(e,o)=>{var t;return e.ariaHasPopup==="true"&&((t=e.dataset)==null?void 0:t.idx)===`${o}`||e.querySelector(`:scope > [data-index='${o}'][aria-haspopup='true']`)!==null};function io(e,...o){let t=new Set(e);for(let n of o)for(let r of n)t.add(r);return t}var uo="Enter";var ao="Delete",lo=new Set([uo,ao]),co=new Set(["Tab"]),po=new Set(["ArrowRight","ArrowLeft"]),ut=new Set(["Home","End","ArrowDown","ArrowUp"]),at=new Set(["Home","End","ArrowRight","ArrowLeft"]),mo=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),In=io(lo,at,ut,po,mo,co);var lt=({key:e},o="vertical")=>(o==="vertical"?ut:at).has(e);var Me=require("@vuu-ui/vuu-utils"),ct=({autoHighlightFirstItem:e=!1,count:o,defaultHighlightedIdx:t,highlightedIndex:n,onActivate:r,onHighlight:s,onCloseMenu:i,onOpenMenu:d})=>{var E;if((0,Me.isValidNumber)(n)&&(0,Me.isValidNumber)(t))throw Error("useKeyboardNavigation do not pass values for both highlightedIndex and defaultHighlightedIdx");let c=(0,Me.isValidNumber)(n),a=(0,S.useRef)((E=t!=null?t:n)!=null?E:e?0:-1),[,u]=(0,S.useState)(null),l=(0,S.useCallback)(b=>{a.current=b,s==null||s(b),u({})},[s]),p=(0,S.useCallback)(b=>{b!==a.current&&(c||l(b))},[c,l]),g=(0,S.useRef)(!0),v=(0,S.useRef)(!1),M=b=>v.current=b,P=c?n:a.current,C=(0,S.useCallback)(b=>{let h=fo(o,b.key,a.current);h!==a.current&&p(h)},[o,p]),w=(0,S.useCallback)(b=>{if(lt(b))b.preventDefault(),b.stopPropagation(),g.current=!0,C(b);else if((b.key==="ArrowRight"||b.key==="Enter")&&it(b.target,P)){let m=b.target.querySelector(`:scope > [data-index='${P}']`);m&&(d==null||d(m,!0))}else b.key==="ArrowLeft"&&!st(b.target)?i(P):b.key==="Enter"?(b.preventDefault(),b.stopPropagation(),r&&r(P)):b.key==="Tab"&&i(-1)},[P,C,r,i,d]),R=(0,S.useMemo)(()=>({onFocus:()=>{P===-1&&l(0)},onKeyDown:w,onMouseDownCapture:()=>{g.current=!1,M(!0)},onMouseMove:()=>{g.current&&(g.current=!1)},onMouseLeave:()=>{g.current=!0,M(!1),p(-1)}}),[w,P,l,p]);return{focusVisible:g.current?P:-1,controlledHighlighting:c,highlightedIndex:P,setHighlightedIndex:p,listProps:R,setIgnoreFocus:M}};function fo(e,o,t){return o==="ArrowUp"?t>0?t-1:t:t===null?0:t===e-1?t:t+1}var Q=k(require("react"));var Ne=e=>e.type===ne||!!e.props["data-group"],go=e=>{if(Array.isArray(e)&&he(e[0]))return e[0]},Mo=(e,o,t,n=!1)=>{let{props:{children:r}}=e;return{childWithId:Q.default.cloneElement(e,{hasSeparator:n,id:`${o}`,key:o,children:t?go(r):r}),grandChildren:t?r:void 0}},pt=(e,o)=>{let t=(0,Q.useCallback)(()=>{let s=(i,d=o,c={},a={})=>{let u=c[d]=[],l=0,p=!1;return Q.default.Children.forEach(i,g=>{if(!he(g))if(g.type===De)p=!0;else{let v=Ne(g),M=`${d}-${l}`,{props:{action:P,options:C}}=g,{childWithId:w,grandChildren:R}=Mo(g,M,v,p);u.push(w),R?s(R,M,c,a):a[M]={action:P,options:C},l+=1,p=!1}}),[c,a]};return s(e)},[o,e]),[n,r]=(0,Q.useMemo)(()=>t(),[t]);return[n,r]};var q=require("react/jsx-runtime"),dt="vuuMenuList",De=()=>(0,q.jsx)("li",{className:"vuuMenuItem-divider"}),ne=()=>null,re=({children:e,idx:o,options:t,...n})=>(0,q.jsx)("div",{...n,children:e}),ft=({children:e})=>(0,q.jsx)(q.Fragment,{children:e});ft.displayName="MenuItemLabel";re.Label=ft;var ho=e=>G.default.isValidElement(e)&&typeof e.type!="string"&&"displayName"in e.type?e.type.displayName:void 0,he=e=>ho(e)==="MenuItemLabel",bo=e=>e.props["data-icon"],be=({activatedByKeyboard:e,childMenuShowing:o,children:t,className:n,defaultHighlightedIdx:r,highlightedIdx:s,id:i,isRoot:d,listItemProps:c,onHighlightMenuItem:a,onActivate:u,onCloseMenu:l,openMenu:p,...g})=>{let v=(0,mt.useId)(i),M=(0,G.useRef)(null),P=(0,G.useMemo)(()=>new Map,[]),C=f=>{var x;let y=(x=M.current)==null?void 0:x.querySelector(`:scope > [data-index='${f}']`);y!=null&&y.id&&(u==null||u(y.id))},{focusVisible:w,highlightedIndex:R,listProps:E}=ct({count:G.default.Children.count(t),defaultHighlightedIdx:r,highlightedIndex:s,onActivate:C,onHighlight:a,onOpenMenu:p,onCloseMenu:l}),b=o==null?w:-1;(0,G.useLayoutEffect)(()=>{var f;o===void 0&&e&&((f=M.current)==null||f.focus())},[e,o]);let h=()=>R===void 0||R===-1?void 0:P.get(R);function m(){let f={...c,role:"menuitem"},y=(A,T,D)=>T?[(0,q.jsx)("span",{className:"vuuIconContainer","data-icon":D},"icon")].concat(A):A;function x(A,T,D,F){var Ze;let{children:X,className:Ut,"data-icon":Ye,id:pe,hasSeparator:Xt,label:Le,...Jt}=T.props,He=Ne(T),Qe=He&&o===pe,zt=Qe?`${v}-${pe}`:void 0;A.push((0,q.jsx)(re,{...Jt,...f,...yo(pe,D,(Ze=T.key)!=null?Ze:pe,R,b,Ut,Xt),"aria-controls":zt,"aria-haspopup":He||void 0,"aria-expanded":Qe||void 0,children:y(He&&Le!=null?Le:X,F,Ye)}))}let H=[];if(t.length>0){let A=t.some(bo);t.forEach((T,D)=>{x(H,T,D,A)})}return H}return(0,q.jsx)("div",{...g,...E,"aria-activedescendant":h(),className:(0,Se.default)(dt,n,{[`${dt}-childMenuShowing`]:o!==void 0}),"data-root":d||void 0,id:v,ref:M,role:"menu",children:m()})},yo=(e,o,t,n,r,s,i)=>({id:`menuitem-${e}`,key:t!=null?t:o,"data-index":o,"data-highlighted":o===n||void 0,className:(0,Se.default)("vuuMenuItem",s,{"vuuMenuItem-separator":i,focusVisible:r===o})});be.displayName="MenuList";var L=require("react");var Be=e=>e==null?void 0:e.closest("[data-index],[aria-posinset]");var Mt=(e,o,t)=>e.map((n,r)=>r===e.length-1?{...n,[t]:n[t]-o}:n),Co=(e,o)=>Mt(e,o,"left"),Po=(e,o)=>Mt(e,o,"top"),xo=(e,o)=>{let[t,n]=o.slice(-2),r=document.getElementById(`${e}-${n.id}`);if(r===null)throw Error(`useCascade.flipSides element with id ${n.id} not found`);let{width:s}=r.getBoundingClientRect();return o.map(i=>i===n?{...i,left:t.left-(s-2)}:i)},vo=(e,o)=>{let[{left:t,top:n}]=o.slice(-1),{offsetWidth:r,offsetTop:s}=e;return{left:t+r,top:s+n}},ht=(e,o)=>{let t=e.lastIndexOf("-");return e.startsWith("menuitem")?t>-1?e.slice(9,t):o:t>-1?e.slice(0,t):o},Eo=e=>e.slice(9),gt=({ariaExpanded:e,ariaHasPopup:o,id:t},n)=>{if(t.startsWith("menuitem"))return{hostMenuId:ht(t,n),targetMenuId:Eo(t),menuItemId:t,isGroup:o==="true",isOpen:e==="true"};throw Error(`getMenuItemDetails #${t} is not a menuitem`)},bt=({id:e,onActivate:o,onMouseEnterItem:t,position:{x:n,y:r}})=>{let[,s]=(0,L.useState)({}),i=(0,L.useRef)([{id:e,left:n,top:r}]),d=(0,L.useCallback)(h=>i.current.findIndex(m=>m.id===h)!==-1,[]),c=(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)(),l=(0,L.useRef)(),p=(0,L.useRef)({[e]:"no-popup"}),g=(0,L.useCallback)((h=e,m,f=null)=>{if(h===e&&f===null)a([{id:e,left:n,top:r}]);else{p.current[h]="popup-open";let y=document.getElementById(f);if(y!==null){let{left:x,top:H}=vo(y,i.current);a(i.current.concat({id:m,left:x,top:H}))}else throw Error(`openMenu no menuItem ${f}`)}},[e,n,r,a]),v=(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]),M=(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 x=ht(y,e);m.pop(),p.current[y]="no-popup",p.current[x]="no-popup",{id:y}=m[m.length-1]}m.length<i.current.length&&a(m)},[e,a]),P=(0,L.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=void 0)},[]),C=(0,L.useCallback)((h,m,f,y=300)=>{P(),u.current=window.setTimeout(()=>{M(f),p.current[h]="popup-open",p.current[m]="no-popup",g(h,m,f)},y)},[P,M,g]),w=(0,L.useCallback)((h,m,f)=>{p.current[m]="pending-close",l.current=window.setTimeout(()=>{M(f)},400)},[M]),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:x}=f.getBoundingClientRect(),{clientHeight:H,clientWidth:A}=document.body;if(y>A){let T=h.length>1?xo(e,h):Co(h,y-A);a(T)}else if(x>H){let T=Po(h,x-H);a(T)}typeof f.tabIndex=="number"&&f.focus()}},[e,a]),E=(0,L.useCallback)((h,m=!1)=>{let{hostMenuId:f,targetMenuId:y,menuItemId:x,isGroup:H,isOpen:A}=gt(h,e),{current:{[f]:T}}=p,D=m?0:void 0;if(T==="no-popup"&&H)p.current[f]="popup-pending",C(f,y,x,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),C(f,y,x,D);else if(T==="popup-open")if(d(y)){let F=c(y);switch(M(x),F){case"pending-close":clearTimeout(l.current),l.current=void 0,p.current[y]="no-popup",P();break;default:}}else{let[F,X]=i.current.slice(-2);F.id===f&&p.current[X.id]!=="pending-close"?(w(f,X.id,x),H&&!A&&C(f,y,x,D)):F.id===f&&H&&x!==X.id&&p.current[X.id]==="pending-close"||H?C(f,y,x,D):p.current[X.id]!=="pending-close"&&M(x)}T==="pending-close"&&(P(),clearTimeout(l.current),l.current=void 0,p.current[f]="popup-open")},[P,M,c,d,e,w,C]),b=(0,L.useMemo)(()=>({onMouseEnter:h=>{let m=Be(h.target);E(m),t(h,m.id)},onClick:h=>{let m=Be(h.target),{isGroup:f,menuItemId:y}=gt(m,e);f?E(m):o(y)}}),[o,t,e,E]);return{closeMenu:v,handleRender:R,listItemProps:b,openMenu:E,openMenus:i.current}};var yt=require("@vuu-ui/vuu-layout");var se=require("react/jsx-runtime"),Oe=require("react"),wo=()=>{},ye=({PortalProps:e,activatedByKeyboard:o,children:t,className:n,id:r,onClose:s=()=>{},position:i={x:0,y:0},style:d,...c})=>{let a=(0,Z.useRef)(s);a.current=s;let u=(0,yt.useId)(r),l=(0,Z.useRef)(wo),[p,g]=pt(t,u),v=(0,Z.useRef)(o),M=(0,Z.useCallback)(()=>{v.current=!1},[]),P=(0,Z.useCallback)(x=>{let H=x.slice(9),{action:A,options:T}=g[H];l.current(u),s({type:"menu-action",menuId:A,options:T})},[g,u,s]),{closeMenu:C,listItemProps:w,openMenu:R,openMenus:E,handleRender:b}=bt({id:`${u}`,onActivate:P,onMouseEnterItem:M,position:i});l.current=C;let h=()=>{v.current=!0,C()},m=()=>{},f=E.length-1,y=x=>{if(!(x>=f)){let{id:H}=E[x+1];return H}};return(0,se.jsx)(se.Fragment,{children:E.map(({id:x,left:H,top:A},T,D)=>{let F=y(T);return(0,Oe.createElement)(W,{...e,key:T,onRender:b},(0,se.jsx)($e,{anchorElement:{current:document.body},placement:"absolute",position:{left:H,top:A},children:(0,Oe.createElement)(be,{...c,activatedByKeyboard:v.current,childMenuShowing:F,className:n,id:x,isRoot:T===0,key:T,listItemProps:w,onActivate:P,onHighlightMenuItem:m,onCloseMenu:h,openMenu:R,style:d,tabIndex:T===D.length-1?0:void 0},p[x])}))})})};ye.displayName="ContextMenu";var _=require("react"),Ce=require("react/jsx-runtime"),ie=(0,_.createContext)(null),To=({children:e,context:o,menuActionHandler:t,menuBuilder:n})=>{let r=(0,_.useMemo)(()=>o!=null&&o.menuBuilders&&n?o.menuBuilders.concat(n):n?[n]:(o==null?void 0:o.menuBuilders)||[],[o,n]),s=(0,_.useCallback)(i=>{var d;if(t!=null&&t(i)||(d=o==null?void 0:o.menuActionHandler)!=null&&d.call(o,i))return!0},[o,t]);return(0,Ce.jsx)(ie.Provider,{value:{menuActionHandler:s,menuBuilders:r},children:e})},Ro=({children:e,label:o,menuActionHandler:t,menuBuilder:n})=>(0,Ce.jsx)(ie.Consumer,{children:r=>(0,Ce.jsx)(To,{context:r,label:o,menuActionHandler:t,menuBuilder:n,children:e})});var Ht=require("@vuu-ui/vuu-utils"),K=require("react");var xt=k(require("classnames")),ae=k(require("react")),ee=k(require("react-dom"));var Ct=k(require("react-dom")),Pt=k(require("classnames")),Lo=1,Ho=({className:e,dataMode:o,x:t=0,y:n=0,win:r=window})=>{let s=r.document.createElement("div");return s.className=(0,Pt.default)(`vuuPopup ${Lo++}`,e),s.style.cssText=`left:${t}px; top:${n}px;`,o&&(s.dataset.mode=o),r.document.body.appendChild(s),s},Io=e=>Ho(e),Ke=(e,o,t,n,r)=>{o.style.cssText=`left:${t}px; top:${n}px;position: absolute;`,Ct.render(e,o,r)};var j=!1,B=[],Fe=e=>(e==null?void 0:e.type)==="menu-action",We=e=>(e==null?void 0:e.type)==="click-away";function Pe(e){if(e.key==="Esc"){if(B.length)Et();else if(j){let o=document.body.querySelector(".vuuDialog");o&&ee.default.unmountComponentAtNode(o)}}}function vt(e){if(B.length){let o=document.body.querySelectorAll(".vuuPopup,#vuu-portal-root");for(let t=0;t<o.length;t++)if(o[t].contains(e.target))return;Et({mouseEvt:e,type:"click-away"})}}function Et(e){if(B.length===1)I.hidePopup(e,"anon","all");else if(B.length){let o=document.body.querySelectorAll(".vuuPopup");for(let t=0;t<o.length;t++)ee.default.unmountComponentAtNode(o[t]);wt("*")}}function ko(){j===!1&&(j=!0,window.addEventListener("keydown",Pe,!0))}function Ao(){j&&(j=!1,window.removeEventListener("keydown",Pe,!0))}function No(e){B.indexOf(e)===-1&&(B.push(e),j===!1&&(window.addEventListener("keydown",Pe,!0),window.addEventListener("click",vt,!0)))}function wt(e){if(B.length){if(e==="*")B.length=0;else{let o=B.indexOf(e);o!==-1&&B.splice(o,1)}B.length===0&&j===!1&&(window.removeEventListener("keydown",Pe,!0),window.removeEventListener("click",vt,!0))}}var Do=({children:e,position:o,style:t})=>{let n=(0,xt.default)("hwPopup","hwPopupContainer",o);return(0,ae.createElement)("div",{className:n,style:t},e)},So=1,I=class{static showPopup({group:o="all",name:t="anon",left:n=0,position:r="",right:s="auto",top:i=0,width:d="auto",component:c}){if(!c)throw Error("PopupService showPopup, no component supplied");typeof c.props.onClose=="function"?I.onClose=c.props.onClose:I.onClose=void 0,No(t),document.addEventListener("keydown",I.escapeKeyListener,!0);let a=document.body.querySelector(".vuuPopup."+o);a===null&&(a=document.createElement("div"),a.className="vuuPopup "+o,document.body.appendChild(a));let u={width:d};Ke((0,ae.createElement)(Do,{key:So++,position:r,style:u},c),a,n,i,()=>{I.keepWithinThePage(a,s)})}static escapeKeyListener(o){o.key==="Escape"&&I.hidePopup({type:"escape",event:o})}static hidePopup(o,t="anon",n="all"){var r;if(B.indexOf(t)!==-1){wt(t);let s=document.body.querySelector(`.vuuPopup.${n}`);s&&ee.default.unmountComponentAtNode(s)}document.removeEventListener("keydown",I.escapeKeyListener,!0),(r=I==null?void 0:I.onClose)==null||r.call(I,o)}static keepWithinThePage(o,t="auto"){let n=o.querySelector(".vuuPopupContainer > *");if(n){let{top:r,left:s,width:i,height:d,right:c}=n.getBoundingClientRect(),a=window.innerWidth,l=window.innerHeight-(r+d);l<0&&(n.style.top=Math.round(r)+l+"px");let p=a-(s+i);if(p<0&&(n.style.left=Math.round(s)+p+"px"),typeof t=="number"&&t!==c){let g=t-c;n.style.left=s+g+"px"}}}},ue=class{static showDialog(o){let t=".vuuDialog",n=o.props.onClose;ko(),ee.default.render(ae.default.cloneElement(o,{container:t,onClose:()=>{ue.closeDialog(),n&&n()}}),document.body.querySelector(t))}static closeDialog(){Ao();let o=document.body.querySelector(".vuuDialog");o&&ee.default.unmountComponentAtNode(o)}};var Rt=k(require("classnames"));var J=require("react"),Tt=(e,o,t,n,r,s)=>{let{bottom:i,height:d,left:c,right:a,top:u,width:l}=e.getBoundingClientRect();switch(o){case"below":return{left:c+t,top:i+n};case"right":return{left:a+t,top:u+n};case"below-center":return{left:c+l/2+t,top:i+n};case"below-right":return{left:c,minWidth:r,top:i+n};case"below-full-width":return{left:c+t,minWidth:r,top:i+n,width:l};case"center":return s?{left:l/2-s.width/2+t,top:d/2-s.height/2+n,visibility:"visible"}:{left:l/2+t,top:d/2+n,visibility:"hidden"};default:throw Error("Popup getPositionRelativeToAnchor only supported placement values are below and right")}},le=({anchorElement:e,minWidth:o,offsetLeft:t=0,offsetTop:n=0,placement:r,position:s})=>{let i=(0,J.useRef)(null),[d,c]=(0,J.useState)(s);(0,J.useLayoutEffect)(()=>{if(r==="absolute"&&s)c(s);else if(e.current){let u=i.current===null?void 0:i.current.getBoundingClientRect(),l=Tt(e.current,r,t,n,o,u);c(l)}},[e,o,t,n,r,s]);let a=(0,J.useCallback)(u=>{if(i.current=u,u&&r==="center"&&e.current){let{height:l,width:p}=u.getBoundingClientRect();c(Tt(e.current,r,t,n,void 0,{height:l,width:p}))}},[e,t,n,r]);return{position:d,popupRef:r==="center"?a:void 0}};var Lt=require("react/jsx-runtime"),$e=({children:e,className:o,anchorElement:t,minWidth:n,placement:r,position:s})=>{let{popupRef:i,position:d}=le({anchorElement:t,minWidth:n,placement:r,position:s});return d===void 0?null:(0,Lt.jsx)("div",{className:(0,Rt.default)("vuuPortal",o),ref:i,style:d,children:e})};var It=require("@vuu-ui/vuu-shell"),xe=require("react/jsx-runtime"),qe=(e,o)=>{let t=(0,K.useContext)(ie),[n,r,s]=(0,It.useThemeAttributes)(),i=(0,K.useMemo)(()=>({themeClass:n,densityClass:r,dataMode:s}),[s,r,n]),d=(0,K.useCallback)((u,l,p)=>{let g=[];for(let v of u)g=g.concat(v(l,p));return g},[]),c=(0,K.useCallback)((u,l,{ContextMenuProps:p,contextMenu:g,...v})=>{var P,C;if((P=u.stopPropagation)==null||P.call(u),(C=u.preventDefault)==null||C.call(u),g)return Oo({x:u.clientX,y:u.clientY},g);let M=[];if(e&&M.push(e),t&&Array.isArray(t==null?void 0:t.menuBuilders)&&t.menuBuilders.length>0&&M.push(...t.menuBuilders),M.length>0){let w=d(M,l,v),R=E=>(o==null?void 0:o(E))===!0?!0:t==null?void 0:t.menuActionHandler(E);w.length&&R&&$o(u,w,R,{PortalProps:{themeAttributes:i},...p})}else console.warn("useContextMenu, no menuBuilders configured. These should be supplied via the ContextMenuProvider(s)")},[d,t,o,e,i]),a=(0,K.useCallback)(()=>{console.log("hide context menu")},[]);return[c,a]},Bo={},Oo=(e,o)=>{I.showPopup({focus:!0,left:0,top:0,component:(0,K.cloneElement)(o,{position:e})})},$o=(e,o,t,{position:n,...r}=Bo)=>{let s=a=>{let u=(l,p)=>(0,Ht.isGroupMenuItemDescriptor)(l)?(0,xe.jsx)(ne,{label:l.label,children:l.children.map(u)},p):(0,xe.jsx)(re,{action:l.action,className:l.className,"data-icon":l.icon,options:l.options,children:l.label},p);return a.map(u)},i=a=>{var u;Fe(a)&&(t(a),I.hidePopup()),(u=r==null?void 0:r.onClose)==null||u.call(r,a)},d=n!=null?n:{x:e.clientX,y:e.clientY},c=(0,xe.jsx)(ye,{...r,onClose:i,position:d,children:s(o)});I.showPopup({left:0,top:0,component:c,focus:!0})};var V=require("react");var kt=k(require("classnames")),At=require("@salt-ds/core"),Nt=require("@vuu-ui/vuu-layout");var Dt=require("react/jsx-runtime"),Ge="vuuPopupMenu",Ko=e=>{if(e){let{bottom:o,left:t}=e.getBoundingClientRect();return{x:t,y:o+6}}},Fo=({className:e,label:o,icon:t=o?"chevron-down":"more-vert",id:n,menuActionHandler:r,menuBuilder:s,menuLocation:i="header",menuOptions:d,onMenuClose:c,tabIndex:a=0,...u})=>{let l=(0,V.useRef)(null),p=(0,V.useRef)(!1),[g,v]=(0,V.useState)(!1),M=(0,Nt.useId)(n),[P]=qe(s,r),C=(0,V.useCallback)(E=>{console.log("menu Open ",{el:E})},[]),w=(0,V.useCallback)(E=>{v(!1),We(E)?E.mouseEvt.target===l.current&&(p.current=!0):requestAnimationFrame(()=>{var b;c==null||c(E),a!==-1&&((b=l.current)==null||b.focus())})},[c,a]),R=(0,V.useCallback)(E=>{p.current?p.current=!1:(v(!0),P(E,i,{ContextMenuProps:{id:`${M}-menu`,onClose:w,openMenu:C,position:Ko(l.current)},...d}))},[w,C,M,i,d,P]);return(0,Dt.jsx)(At.Button,{...u,"aria-controls":`${M}-menu-root`,"aria-expanded":g,"aria-haspopup":"menu",className:(0,kt.default)(Ge,e,{[`${Ge}-withCaption`]:o!==void 0,[`${Ge}-open`]:g}),"data-icon":t,id:M,onClick:R,ref:l,tabIndex:a,variant:"secondary",children:o})};var St=require("@vuu-ui/vuu-shell"),Ve=require("@salt-ds/core"),Bt=k(require("classnames")),ce=require("react");var U=require("react/jsx-runtime"),te="vuuPrompt",Wo={current:document.body},qo={},Go=({PopupProps:e=qo,cancelButtonLabel:o="Cancel",confirmButtonLabel:t="Confirm",icon:n,onCancel:r,onConfirm:s,style:i,text:d,title:c,variant:a="info",...u})=>{let{anchorElement:l=Wo,offsetLeft:p=0,offsetTop:g=0,placement:v="below"}=e,[M,P,C]=(0,St.useThemeAttributes)(),{position:w}=le({anchorElement:l,offsetLeft:p,offsetTop:g,placement:v}),R=(0,ce.useRef)(null),E=(0,ce.useRef)(null);return(0,ce.useLayoutEffect)(()=>{if(R.current&&(R.current.showModal(),E.current&&E.current.focus(),v.endsWith("center"))){let{width:b}=R.current.getBoundingClientRect();R.current.style.marginLeft=`-${b/2}px`}},[v]),(0,U.jsx)("dialog",{...u,className:(0,Bt.default)(te,`${te}-${a}`,M),"data-mode":C,ref:R,style:{...i,...w},children:(0,U.jsxs)("form",{className:`${te}-form`,children:[(0,U.jsx)("div",{className:`${te}-header`,"data-icon":n,children:c}),(0,U.jsx)("div",{className:`${te}-text`,children:d}),(0,U.jsxs)("div",{className:`${te}-buttonBar`,children:[(0,U.jsx)(Ve.Button,{onClick:r,variant:"secondary",children:o}),(0,U.jsx)(Ve.Button,{onClick:s,ref:E,value:"default",children:t})]})]})})};var ve=require("react"),Vo=(e,o,t,n)=>{let{bottom:r,height:s,left:i,right:d,top:c,width:a}=e.getBoundingClientRect(),u=i+a/2,l=c+s/2;switch(o){case"above":return{left:u+t,top:c+n};case"below":return{left:u+t,top:r+n};case"right":return{left:d+t,top:l+t};case"left":return{left:i+t,top:l+t};default:throw Error("Tooltip getPositionRelativeToAnchor only supported placement values are left, right, below and right")}},Ot=({anchorElement:e,offsetLeft:o=0,offsetTop:t=0,placement:n})=>{let[r,s]=(0,ve.useState)();return(0,ve.useLayoutEffect)(()=>{if(e.current){let i=Vo(e.current,n,o,t);s(i)}},[e,o,t,n]),r};var $t=k(require("classnames"));var Ee=require("react/jsx-runtime"),Ue="vuuTooltip",Uo=({anchorElement:e,children:o,id:t,onMouseEnter:n,onMouseLeave:r,placement:s,status:i})=>{let d=Ot({anchorElement:e,placement:s});return d===void 0?null:(0,Ee.jsx)(W,{children:(0,Ee.jsx)("div",{className:(0,$t.default)(Ue,{[`${Ue}-error`]:i==="error"}),"data-align":s,id:t,style:d,children:(0,Ee.jsx)("span",{className:`${Ue}-content`,onMouseEnter:n,onMouseLeave:r,children:o})})})};var N=require("react"),Kt=require("@vuu-ui/vuu-layout"),Xo=({id:e,placement:o="right",tooltipContent:t})=>{let n=(0,N.useRef)(),r=(0,N.useRef)(null),s=(0,N.useRef)(),i=(0,N.useRef)(),[d,c]=(0,N.useState)(),a=(0,Kt.useId)(e),u=(0,N.useCallback)(C=>{var w;C.key==="Escape"&&((w=n.current)==null||w.call(n))},[]);n.current=(0,N.useCallback)(()=>{c(void 0),document.removeEventListener("keydown",u)},[u]);let l=(0,N.useCallback)(()=>{window.clearTimeout(i.current)},[]),p=(0,N.useCallback)(()=>{var C;(C=n.current)==null||C.call(n)},[]),g=(0,N.useCallback)(()=>{let{current:C}=r;C&&(c({anchorElement:r,children:t,id:`${a}-tooltip`,onMouseEnter:l,onMouseLeave:p,placement:o}),document.addEventListener("keydown",u)),s.current=void 0},[u,l,p,a,o,t]),v=(0,N.useCallback)(C=>{let w=C.target;w&&(r.current=w,s.current=window.setTimeout(g,800))},[g]),M=(0,N.useCallback)(()=>{r.current&&(s.current?(window.clearTimeout(s.current),s.current=void 0):n.current&&(i.current=window.setTimeout(n.current,200)))},[]);return{anchorProps:{"aria-describedby":`${a}-tooltip`,onMouseEnter:v,onMouseLeave:M},tooltipProps:d}};var $=k(require("react")),Xe=k(require("classnames")),Ft=require("@vuu-ui/vuu-utils");var O=require("react/jsx-runtime"),Jo=60,Wt=6e3,Je=1e3,zo=300,qt=56,Te=300,Yo=10,Qo=10,Re=50,we="vuuToastNotifications",Gt=(r=>(r.Info="info",r.Success="success",r.Warning="warning",r.Error="error",r))(Gt||{}),ze=$.default.createContext({notify:()=>"have you forgotten to provide a NotificationProvider?"}),Zo=e=>{let[o,t]=(0,$.useState)([]),n=(0,$.useCallback)(r=>{let s={...r,id:(0,Ft.getUniqueId)()};t(i=>[...i,s]),setTimeout(()=>{t(i=>i.filter(d=>d!==s))},Wt+Je*2)},[]);return(0,O.jsxs)(ze.Provider,{value:{notify:n},children:[(0,O.jsx)("div",{style:{width:Te+Re+Qo},children:o.map((r,s)=>(0,O.jsx)(Vt,{top:Jo+(qt+Yo)*s,notification:r},r.id))}),e.children]})},jo=()=>(0,$.useContext)(ze),Vt=e=>{let{top:o,notification:t,animated:n=!0}=e,[r,s]=(0,$.useState)(-Te-Re);return(0,$.useEffect)(()=>{setTimeout(()=>s(Re)),n&&setTimeout(()=>s(-Te-Re),Wt+Je)},[n]),(0,O.jsx)(W,{children:(0,O.jsxs)("div",{className:(0,Xe.default)(`${we}-toast`,t.type),style:{height:qt,right:r,width:Te,top:o,transition:n?`right ${Je}ms, top ${zo}ms `:"none"},children:[(0,O.jsx)("div",{className:(0,Xe.default)(`${we}-toastIcon`,`${t.type}-icon`)}),(0,O.jsxs)("div",{className:`${we}-toastContent`,children:[(0,O.jsx)("strong",{className:`${we}-toastHeader`,children:t.header}),(0,O.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
|