forked from Stock-control-supervisors/awesome-go
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
8490-9d8be909c2deefd4.js.download
1 lines (1 loc) · 11.3 KB
/
8490-9d8be909c2deefd4.js.download
1
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8490],{8490:function(e,t,r){r.d(t,{Dx:function(){return z},VW:function(){return R},dk:function(){return B},fC:function(){return Y},gD:function(){return Z},l_:function(){return q}});var n=r(99503),o=r(91710),a=r(99719),i=r(62283),s=r(37321),l=r(20469),u=r(5382),c=r(46876),d=r(1781),p=r(73093),f=r(24744),w=r(44266),v=r(32574),m=r(26141),E=r(56998);let T="ToastProvider",[y,g,b]=(0,l.B)("Toast"),[x,h]=(0,u.b)("Toast",[b]),[C,P]=x(T),R=e=>{let{__scopeToast:t,label:r="Notification",duration:n=5e3,swipeDirection:a="right",swipeThreshold:i=50,children:s}=e,[l,u]=(0,o.useState)(null),[c,d]=(0,o.useState)(0),p=(0,o.useRef)(!1),f=(0,o.useRef)(!1);return(0,o.createElement)(y.Provider,{scope:t},(0,o.createElement)(C,{scope:t,label:r,duration:n,swipeDirection:a,swipeThreshold:i,toastCount:c,viewport:l,onViewportChange:u,onToastAdd:(0,o.useCallback)(()=>d(e=>e+1),[]),onToastRemove:(0,o.useCallback)(()=>d(e=>e-1),[]),isFocusedToastEscapeKeyDownRef:p,isClosePausedRef:f},s))};R.propTypes={label:e=>e.label&&"string"==typeof e.label&&!e.label.trim()?Error("Invalid prop `label` supplied to `".concat(T,"`. Expected non-empty `string`.")):null};let _=["F8"],D="toast.viewportPause",L="toast.viewportResume",M=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,hotkey:a=_,label:i="Notifications ({hotkey})",...l}=e,u=P("ToastViewport",r),d=g(r),p=(0,o.useRef)(null),w=(0,o.useRef)(null),v=(0,o.useRef)(null),m=(0,o.useRef)(null),E=(0,s.e)(t,m,u.onViewportChange),T=a.join("+").replace(/Key/g,"").replace(/Digit/g,""),b=u.toastCount>0;(0,o.useEffect)(()=>{let e=e=>{var t;a.every(t=>e[t]||e.code===t)&&(null===(t=m.current)||void 0===t||t.focus())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]),(0,o.useEffect)(()=>{let e=p.current,t=m.current;if(b&&e&&t){let r=()=>{if(!u.isClosePausedRef.current){let e=new CustomEvent(D);t.dispatchEvent(e),u.isClosePausedRef.current=!0}},n=()=>{if(u.isClosePausedRef.current){let e=new CustomEvent(L);t.dispatchEvent(e),u.isClosePausedRef.current=!1}},o=t=>{e.contains(t.relatedTarget)||n()},a=()=>{e.contains(document.activeElement)||n()};return e.addEventListener("focusin",r),e.addEventListener("focusout",o),e.addEventListener("pointermove",r),e.addEventListener("pointerleave",a),window.addEventListener("blur",r),window.addEventListener("focus",n),()=>{e.removeEventListener("focusin",r),e.removeEventListener("focusout",o),e.removeEventListener("pointermove",r),e.removeEventListener("pointerleave",a),window.removeEventListener("blur",r),window.removeEventListener("focus",n)}}},[b,u.isClosePausedRef]);let x=(0,o.useCallback)(e=>{let{tabbingDirection:t}=e,r=d().map(e=>{let r=e.ref.current,n=[r,...function(e){let t=[],r=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;r.nextNode();)t.push(r.currentNode);return t}(r)];return"forwards"===t?n:n.reverse()});return("forwards"===t?r.reverse():r).flat()},[d]);return(0,o.useEffect)(()=>{let e=m.current;if(e){let t=t=>{let r=t.altKey||t.ctrlKey||t.metaKey;if("Tab"===t.key&&!r){var n,o,a;let r=document.activeElement,i=t.shiftKey;if(t.target===e&&i){null===(n=w.current)||void 0===n||n.focus();return}let s=x({tabbingDirection:i?"backwards":"forwards"}),l=s.findIndex(e=>e===r);j(s.slice(l+1))?t.preventDefault():i?null===(o=w.current)||void 0===o||o.focus():null===(a=v.current)||void 0===a||a.focus()}};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)}},[d,x]),(0,o.createElement)(c.I0,{ref:p,role:"region","aria-label":i.replace("{hotkey}",T),tabIndex:-1,style:{pointerEvents:b?void 0:"none"}},b&&(0,o.createElement)(S,{ref:w,onFocusFromOutsideViewport:()=>{j(x({tabbingDirection:"forwards"}))}}),(0,o.createElement)(y.Slot,{scope:r},(0,o.createElement)(f.WV.ol,(0,n.Z)({tabIndex:-1},l,{ref:E}))),b&&(0,o.createElement)(S,{ref:v,onFocusFromOutsideViewport:()=>{j(x({tabbingDirection:"backwards"}))}}))}),S=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,onFocusFromOutsideViewport:a,...i}=e,s=P("ToastFocusProxy",r);return(0,o.createElement)(E.T,(0,n.Z)({"aria-hidden":!0,tabIndex:0},i,{ref:t,style:{position:"fixed"},onFocus:e=>{var t;let r=e.relatedTarget;null!==(t=s.viewport)&&void 0!==t&&t.contains(r)||a()}}))}),k="Toast",F=(0,o.forwardRef)((e,t)=>{let{forceMount:r,open:a,defaultOpen:s,onOpenChange:l,...u}=e,[c=!0,d]=(0,v.T)({prop:a,defaultProp:s,onChange:l});return(0,o.createElement)(p.z,{present:r||c},(0,o.createElement)(A,(0,n.Z)({open:c},u,{ref:t,onClose:()=>d(!1),onPause:(0,w.W)(e.onPause),onResume:(0,w.W)(e.onResume),onSwipeStart:(0,i.M)(e.onSwipeStart,e=>{e.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:(0,i.M)(e.onSwipeMove,e=>{let{x:t,y:r}=e.detail.delta;e.currentTarget.setAttribute("data-swipe","move"),e.currentTarget.style.setProperty("--radix-toast-swipe-move-x","".concat(t,"px")),e.currentTarget.style.setProperty("--radix-toast-swipe-move-y","".concat(r,"px"))}),onSwipeCancel:(0,i.M)(e.onSwipeCancel,e=>{e.currentTarget.setAttribute("data-swipe","cancel"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),e.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:(0,i.M)(e.onSwipeEnd,e=>{let{x:t,y:r}=e.detail.delta;e.currentTarget.setAttribute("data-swipe","end"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),e.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),e.currentTarget.style.setProperty("--radix-toast-swipe-end-x","".concat(t,"px")),e.currentTarget.style.setProperty("--radix-toast-swipe-end-y","".concat(r,"px")),d(!1)})})))}),[I,N]=x(k,{onClose(){}}),A=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,type:l="foreground",duration:u,open:d,onClose:p,onEscapeKeyDown:v,onPause:m,onResume:E,onSwipeStart:T,onSwipeMove:g,onSwipeCancel:b,onSwipeEnd:x,...h}=e,C=P(k,r),[R,_]=(0,o.useState)(null),M=(0,s.e)(t,e=>_(e)),S=(0,o.useRef)(null),F=(0,o.useRef)(null),N=u||C.duration,A=(0,o.useRef)(0),V=(0,o.useRef)(N),W=(0,o.useRef)(0),{onToastAdd:Z,onToastRemove:O}=C,H=(0,w.W)(()=>{var e;(null==R?void 0:R.contains(document.activeElement))&&(null===(e=C.viewport)||void 0===e||e.focus()),p()}),j=(0,o.useCallback)(e=>{e&&e!==1/0&&(window.clearTimeout(W.current),A.current=new Date().getTime(),W.current=window.setTimeout(H,e))},[H]);(0,o.useEffect)(()=>{let e=C.viewport;if(e){let t=()=>{j(V.current),null==E||E()},r=()=>{let e=new Date().getTime()-A.current;V.current=V.current-e,window.clearTimeout(W.current),null==m||m()};return e.addEventListener(D,r),e.addEventListener(L,t),()=>{e.removeEventListener(D,r),e.removeEventListener(L,t)}}},[C.viewport,N,m,E,j]),(0,o.useEffect)(()=>{d&&!C.isClosePausedRef.current&&j(N)},[d,N,C.isClosePausedRef,j]),(0,o.useEffect)(()=>(Z(),()=>O()),[Z,O]);let q=(0,o.useMemo)(()=>R?function e(t){let r=[];return Array.from(t.childNodes).forEach(t=>{if(t.nodeType===t.TEXT_NODE&&t.textContent&&r.push(t.textContent),t.nodeType===t.ELEMENT_NODE){let n=t.ariaHidden||t.hidden||"none"===t.style.display,o=""===t.dataset.radixToastAnnounceExclude;if(!n){if(o){let e=t.dataset.radixToastAnnounceAlt;e&&r.push(e)}else r.push(...e(t))}}}),r}(R):null,[R]);return C.viewport?(0,o.createElement)(o.Fragment,null,q&&(0,o.createElement)(K,{__scopeToast:r,role:"status","aria-live":"foreground"===l?"assertive":"polite","aria-atomic":!0},q),(0,o.createElement)(I,{scope:r,onClose:H},(0,a.createPortal)((0,o.createElement)(y.ItemSlot,{scope:r},(0,o.createElement)(c.fC,{asChild:!0,onEscapeKeyDown:(0,i.M)(v,()=>{C.isFocusedToastEscapeKeyDownRef.current||H(),C.isFocusedToastEscapeKeyDownRef.current=!1})},(0,o.createElement)(f.WV.li,(0,n.Z)({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":d?"open":"closed","data-swipe-direction":C.swipeDirection},h,{ref:M,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:(0,i.M)(e.onKeyDown,e=>{"Escape"!==e.key||(null==v||v(e.nativeEvent),e.nativeEvent.defaultPrevented||(C.isFocusedToastEscapeKeyDownRef.current=!0,H()))}),onPointerDown:(0,i.M)(e.onPointerDown,e=>{0===e.button&&(S.current={x:e.clientX,y:e.clientY})}),onPointerMove:(0,i.M)(e.onPointerMove,e=>{if(!S.current)return;let t=e.clientX-S.current.x,r=e.clientY-S.current.y,n=!!F.current,o=["left","right"].includes(C.swipeDirection),a=["left","up"].includes(C.swipeDirection)?Math.min:Math.max,i=o?a(0,t):0,s=o?0:a(0,r),l="touch"===e.pointerType?10:2,u={x:i,y:s},c={originalEvent:e,delta:u};n?(F.current=u,U("toast.swipeMove",g,c,{discrete:!1})):X(u,C.swipeDirection,l)?(F.current=u,U("toast.swipeStart",T,c,{discrete:!1}),e.target.setPointerCapture(e.pointerId)):(Math.abs(t)>l||Math.abs(r)>l)&&(S.current=null)}),onPointerUp:(0,i.M)(e.onPointerUp,e=>{let t=F.current,r=e.target;if(r.hasPointerCapture(e.pointerId)&&r.releasePointerCapture(e.pointerId),F.current=null,S.current=null,t){let r=e.currentTarget,n={originalEvent:e,delta:t};X(t,C.swipeDirection,C.swipeThreshold)?U("toast.swipeEnd",x,n,{discrete:!0}):U("toast.swipeCancel",b,n,{discrete:!0}),r.addEventListener("click",e=>e.preventDefault(),{once:!0})}})})))),C.viewport))):null});A.propTypes={type:e=>e.type&&!["foreground","background"].includes(e.type)?Error("Invalid prop `type` supplied to `".concat(k,"`. Expected `foreground | background`.")):null};let K=e=>{let{__scopeToast:t,children:r,...n}=e,a=P(k,t),[i,s]=(0,o.useState)(!1),[l,u]=(0,o.useState)(!1);return function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:()=>{},t=(0,w.W)(e);(0,m.b)(()=>{let e=0,r=0;return e=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(e),window.cancelAnimationFrame(r)}},[t])}(()=>s(!0)),(0,o.useEffect)(()=>{let e=window.setTimeout(()=>u(!0),1e3);return()=>window.clearTimeout(e)},[]),l?null:(0,o.createElement)(d.h,{asChild:!0},(0,o.createElement)(E.T,n,i&&(0,o.createElement)(o.Fragment,null,a.label," ",r)))},V=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,...a}=e;return(0,o.createElement)(f.WV.div,(0,n.Z)({},a,{ref:t}))}),W=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,...a}=e;return(0,o.createElement)(f.WV.div,(0,n.Z)({},a,{ref:t}))}),Z=(0,o.forwardRef)((e,t)=>{let{altText:r,...a}=e;return r?(0,o.createElement)(H,{altText:r,asChild:!0},(0,o.createElement)(O,(0,n.Z)({},a,{ref:t}))):null});Z.propTypes={altText:e=>e.altText?null:Error("Missing prop `altText` expected on `".concat("ToastAction","`"))};let O=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,...a}=e,s=N("ToastClose",r);return(0,o.createElement)(H,{asChild:!0},(0,o.createElement)(f.WV.button,(0,n.Z)({type:"button"},a,{ref:t,onClick:(0,i.M)(e.onClick,s.onClose)})))}),H=(0,o.forwardRef)((e,t)=>{let{__scopeToast:r,altText:a,...i}=e;return(0,o.createElement)(f.WV.div,(0,n.Z)({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":a||void 0},i,{ref:t}))});function U(e,t,r,n){let{discrete:o}=n,a=r.originalEvent.currentTarget,i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:r});t&&a.addEventListener(e,t,{once:!0}),o?(0,f.jH)(a,i):a.dispatchEvent(i)}let X=function(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,n=Math.abs(e.x),o=Math.abs(e.y),a=n>o;return"left"===t||"right"===t?a&&n>r:!a&&o>r};function j(e){let t=document.activeElement;return e.some(e=>e===t||(e.focus(),document.activeElement!==t))}let q=M,Y=F,z=V,B=W}}]);