sonner 2.0.0-beta.1 → 2.0.0-beta.2
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/dist/index.d.mts +156 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1142 -3
- package/dist/index.mjs +1133 -3
- package/dist/styles.css +25 -15
- package/package.json +14 -7
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,1142 @@
|
|
|
1
|
-
"use client";var ne=Object.create;var pt=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var de=(s,e)=>{for(var t in e)pt(s,t,{get:e[t],enumerable:!0})},$t=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ie(e))!ce.call(s,l)&&l!==t&&pt(s,l,{get:()=>e[l],enumerable:!(a=re(e,l))||a.enumerable});return s};var et=(s,e,t)=>(t=s!=null?ne(le(s)):{},$t(e||!s||!s.__esModule?pt(t,"default",{value:s,enumerable:!0}):t,s)),ue=s=>$t(pt({},"__esModule",{value:!0}),s);var He={};de(He,{Toaster:()=>Me,toast:()=>Kt,useSonner:()=>Ie});module.exports=ue(He);var o=et(require("react")),mt=et(require("react-dom"));var S=et(require("react")),Ft=s=>{switch(s){case"success":return pe;case"info":return ge;case"warning":return me;case"error":return he;default:return null}},fe=Array(12).fill(0),Wt=({visible:s,className:e})=>S.default.createElement("div",{className:["sonner-loading-wrapper",e].filter(Boolean).join(" "),"data-visible":s},S.default.createElement("div",{className:"sonner-spinner"},fe.map((t,a)=>S.default.createElement("div",{className:"sonner-loading-bar",key:`spinner-bar-${a}`})))),pe=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",clipRule:"evenodd"})),me=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",clipRule:"evenodd"})),ge=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",clipRule:"evenodd"})),he=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",height:"20",width:"20"},S.default.createElement("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})),_t=S.default.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},S.default.createElement("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),S.default.createElement("line",{x1:"6",y1:"6",x2:"18",y2:"18"}));var Tt=et(require("react")),Vt=()=>{let[s,e]=Tt.default.useState(document.hidden);return Tt.default.useEffect(()=>{let t=()=>{e(document.hidden)};return document.addEventListener("visibilitychange",t),()=>window.removeEventListener("visibilitychange",t)},[]),s};var Ut=et(require("react")),wt=1,St=class{constructor(){this.subscribe=e=>(this.subscribers.push(e),()=>{let t=this.subscribers.indexOf(e);this.subscribers.splice(t,1)});this.publish=e=>{this.subscribers.forEach(t=>t(e))};this.addToast=e=>{this.publish(e),this.toasts=[...this.toasts,e]};this.create=e=>{var R;let{message:t,...a}=e,l=typeof(e==null?void 0:e.id)=="number"||((R=e.id)==null?void 0:R.length)>0?e.id:wt++,f=this.toasts.find(g=>g.id===l),x=e.dismissible===void 0?!0:e.dismissible;return this.dismissedToasts.has(l)&&this.dismissedToasts.delete(l),f?this.toasts=this.toasts.map(g=>g.id===l?(this.publish({...g,...e,id:l,title:t}),{...g,...e,id:l,dismissible:x,title:t}):g):this.addToast({title:t,...a,dismissible:x,id:l}),l};this.dismiss=e=>(this.dismissedToasts.add(e),e||this.toasts.forEach(t=>{this.subscribers.forEach(a=>a({id:t.id,dismiss:!0}))}),requestAnimationFrame(()=>this.subscribers.forEach(t=>t({id:e,dismiss:!0}))),e);this.message=(e,t)=>this.create({...t,message:e});this.error=(e,t)=>this.create({...t,message:e,type:"error"});this.success=(e,t)=>this.create({...t,type:"success",message:e});this.info=(e,t)=>this.create({...t,type:"info",message:e});this.warning=(e,t)=>this.create({...t,type:"warning",message:e});this.loading=(e,t)=>this.create({...t,type:"loading",message:e});this.promise=(e,t)=>{if(!t)return;let a;t.loading!==void 0&&(a=this.create({...t,promise:e,type:"loading",message:t.loading,description:typeof t.description!="function"?t.description:void 0}));let l=Promise.resolve(e instanceof Function?e():e),f=a!==void 0,x,R=l.then(async i=>{if(x=["resolve",i],Ut.default.isValidElement(i))f=!1,this.create({id:a,type:"default",message:i});else if(ye(i)&&!i.ok){f=!1;let w=typeof t.error=="function"?await t.error(`HTTP error! status: ${i.status}`):t.error,F=typeof t.description=="function"?await t.description(`HTTP error! status: ${i.status}`):t.description;this.create({id:a,type:"error",message:w,description:F})}else if(t.success!==void 0){f=!1;let w=typeof t.success=="function"?await t.success(i):t.success,F=typeof t.description=="function"?await t.description(i):t.description;this.create({id:a,type:"success",message:w,description:F})}}).catch(async i=>{if(x=["reject",i],t.error!==void 0){f=!1;let D=typeof t.error=="function"?await t.error(i):t.error,w=typeof t.description=="function"?await t.description(i):t.description;this.create({id:a,type:"error",message:D,description:w})}}).finally(()=>{var i;f&&(this.dismiss(a),a=void 0),(i=t.finally)==null||i.call(t)}),g=()=>new Promise((i,D)=>R.then(()=>x[0]==="reject"?D(x[1]):i(x[1])).catch(D));return typeof a!="string"&&typeof a!="number"?{unwrap:g}:Object.assign(a,{unwrap:g})};this.custom=(e,t)=>{let a=(t==null?void 0:t.id)||wt++;return this.create({jsx:e(a),id:a,...t}),a};this.getActiveToasts=()=>this.toasts.filter(e=>!this.dismissedToasts.has(e.id));this.subscribers=[],this.toasts=[],this.dismissedToasts=new Set}},T=new St,be=(s,e)=>{let t=(e==null?void 0:e.id)||wt++;return T.addToast({title:s,...e,id:t}),t},ye=s=>s&&typeof s=="object"&&"ok"in s&&typeof s.ok=="boolean"&&"status"in s&&typeof s.status=="number",xe=be,ve=()=>T.toasts,Te=()=>T.getActiveToasts(),Kt=Object.assign(xe,{success:T.success,info:T.info,warning:T.warning,error:T.error,custom:T.custom,message:T.message,promise:T.promise,dismiss:T.dismiss,loading:T.loading},{getHistory:ve,getToasts:Te});function Rt(s,{insertAt:e}={}){if(!s||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",e==="top"&&t.firstChild?t.insertBefore(a,t.firstChild):t.appendChild(a),a.styleSheet?a.styleSheet.cssText=s:a.appendChild(document.createTextNode(s))}Rt(`html[dir=ltr],[data-sonner-toaster][dir=ltr]{--toast-icon-margin-start: -3px;--toast-icon-margin-end: 4px;--toast-svg-margin-start: -1px;--toast-svg-margin-end: 0px;--toast-button-margin-start: auto;--toast-button-margin-end: 0;--toast-close-button-start: 0;--toast-close-button-end: unset;--toast-close-button-transform: translate(-35%, -35%)}html[dir=rtl],[data-sonner-toaster][dir=rtl]{--toast-icon-margin-start: 4px;--toast-icon-margin-end: -3px;--toast-svg-margin-start: 0px;--toast-svg-margin-end: -1px;--toast-button-margin-start: 0;--toast-button-margin-end: auto;--toast-close-button-start: unset;--toast-close-button-end: 0;--toast-close-button-transform: translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1: hsl(0, 0%, 99%);--gray2: hsl(0, 0%, 97.3%);--gray3: hsl(0, 0%, 95.1%);--gray4: hsl(0, 0%, 93%);--gray5: hsl(0, 0%, 90.9%);--gray6: hsl(0, 0%, 88.7%);--gray7: hsl(0, 0%, 85.8%);--gray8: hsl(0, 0%, 78%);--gray9: hsl(0, 0%, 56.1%);--gray10: hsl(0, 0%, 52.3%);--gray11: hsl(0, 0%, 43.5%);--gray12: hsl(0, 0%, 9%);--border-radius: 8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:999999999;transition:transform .4s ease}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translate(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y: translateY(100%);--lift-amount: calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast][data-y-position=top]{top:0;--y: translateY(-100%);--lift: 1;--lift-amount: calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y: translateY(100%);--lift: -1;--lift-amount: calc(var(--lift) * var(--gap))}[data-sonner-toast] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast] [data-icon]>*{flex-shrink:0}[data-sonner-toast] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:none;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast] [data-button]:focus-visible{box-shadow:0 0 0 2px #0006}[data-sonner-toast] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast] [data-close-button]:focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}[data-sonner-toast] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]:before{content:"";position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]:before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]:before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]:before{content:"";position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]:after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y: translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale: var(--toasts-before) * .05 + 1;--y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y: translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y: translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]:before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y, 0px)) translate(var(--swipe-amount-x, 0px));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{0%{transform:var(--y) translate(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translate(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{0%{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width: 600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg: #fff;--normal-border: var(--gray4);--normal-text: var(--gray12);--success-bg: hsl(143, 85%, 96%);--success-border: hsl(145, 92%, 87%);--success-text: hsl(140, 100%, 27%);--info-bg: hsl(208, 100%, 97%);--info-border: hsl(221, 91%, 93%);--info-text: hsl(210, 92%, 45%);--warning-bg: hsl(49, 100%, 97%);--warning-border: hsl(49, 91%, 84%);--warning-text: hsl(31, 92%, 45%);--error-bg: hsl(359, 100%, 97%);--error-border: hsl(359, 100%, 94%);--error-text: hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg: #000;--normal-border: hsl(0, 0%, 20%);--normal-text: var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg: #fff;--normal-border: var(--gray3);--normal-text: var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg: #000;--normal-bg-hover: hsl(0, 0%, 12%);--normal-border: hsl(0, 0%, 20%);--normal-border-hover: hsl(0, 0%, 25%);--normal-text: var(--gray1);--success-bg: hsl(150, 100%, 6%);--success-border: hsl(147, 100%, 12%);--success-text: hsl(150, 86%, 65%);--info-bg: hsl(215, 100%, 6%);--info-border: hsl(223, 43%, 17%);--info-text: hsl(216, 87%, 65%);--warning-bg: hsl(64, 100%, 6%);--warning-border: hsl(60, 100%, 9%);--warning-text: hsl(46, 87%, 65%);--error-bg: hsl(358, 76%, 10%);--error-border: hsl(357, 89%, 16%);--error-text: hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success],[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info],[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning],[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error],[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size: 16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:nth-child(1){animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}to{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}to{opacity:.15}}@media (prefers-reduced-motion){[data-sonner-toast],[data-sonner-toast]>*,.sonner-loading-bar{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}
|
|
2
|
-
`);function ot(s){return s.label!==void 0}var we=3,Se="24px",Re="16px",Xt=5e3,Ee=356,De=14,Pe=20,Ne=200;function M(...s){return s.filter(Boolean).join(" ")}function Be(s){let[e,t]=s.split("-"),a=[];return e&&a.push(e),t&&a.push(t),a}var Ce=s=>{var Bt,Ct,kt,It,Mt,Ht,At,Lt,zt,jt,Yt;let{invert:e,toast:t,unstyled:a,interacting:l,setHeights:f,visibleToasts:x,heights:R,index:g,toasts:i,expanded:D,removeToast:w,defaultRichColors:F,closeButton:at,style:gt,cancelButtonStyle:ht,actionButtonStyle:c,className:st="",descriptionClassName:nt="",duration:X,position:rt,gap:bt,loadingIcon:it,expandByDefault:P,classNames:n,icons:B,closeButtonAriaLabel:lt="Close toast",pauseWhenPageIsHidden:ct}=s,[Y,k]=o.default.useState(null),[dt,J]=o.default.useState(null),[W,H]=o.default.useState(!1),[A,yt]=o.default.useState(!1),[L,z]=o.default.useState(!1),[ut,u]=o.default.useState(!1),[h,y]=o.default.useState(!1),[E,j]=o.default.useState(0),[p,_]=o.default.useState(0),O=o.default.useRef(t.duration||X||Xt),q=o.default.useRef(null),N=o.default.useRef(null),qt=g===0,Gt=g+1<=x,C=t.type,V=t.dismissible!==!1,Qt=t.className||"",Zt=t.descriptionClassName||"",ft=o.default.useMemo(()=>R.findIndex(r=>r.toastId===t.id)||0,[R,t.id]),te=o.default.useMemo(()=>{var r;return(r=t.closeButton)!=null?r:at},[t.closeButton,at]),Et=o.default.useMemo(()=>t.duration||X||Xt,[t.duration,X]),xt=o.default.useRef(0),U=o.default.useRef(0),Dt=o.default.useRef(0),K=o.default.useRef(null),[ee,oe]=rt.split("-"),Pt=o.default.useMemo(()=>R.reduce((r,m,d)=>d>=ft?r:r+m.height,0),[R,ft]),Nt=Vt(),ae=t.invert||e,vt=C==="loading";U.current=o.default.useMemo(()=>ft*bt+Pt,[ft,Pt]),o.default.useEffect(()=>{O.current=Et},[Et]),o.default.useEffect(()=>{H(!0)},[]),o.default.useEffect(()=>{let r=N.current;if(r){let m=r.getBoundingClientRect().height;return _(m),f(d=>[{toastId:t.id,height:m,position:t.position},...d]),()=>f(d=>d.filter(b=>b.toastId!==t.id))}},[f,t.id]),o.default.useLayoutEffect(()=>{if(!W)return;let r=N.current,m=r.style.height;r.style.height="auto";let d=r.getBoundingClientRect().height;r.style.height=m,_(d),f(b=>b.find(v=>v.toastId===t.id)?b.map(v=>v.toastId===t.id?{...v,height:d}:v):[{toastId:t.id,height:d,position:t.position},...b])},[W,t.title,t.description,f,t.id]);let $=o.default.useCallback(()=>{yt(!0),j(U.current),f(r=>r.filter(m=>m.toastId!==t.id)),setTimeout(()=>{w(t)},Ne)},[t,w,f,U]);o.default.useEffect(()=>{if(t.promise&&C==="loading"||t.duration===1/0||t.type==="loading")return;let r;return D||l||ct&&Nt?(()=>{if(Dt.current<xt.current){let b=new Date().getTime()-xt.current;O.current=O.current-b}Dt.current=new Date().getTime()})():(()=>{O.current!==1/0&&(xt.current=new Date().getTime(),r=setTimeout(()=>{var b;(b=t.onAutoClose)==null||b.call(t,t),$()},O.current))})(),()=>clearTimeout(r)},[D,l,t,C,ct,Nt,$]),o.default.useEffect(()=>{t.delete&&$()},[$,t.delete]);function se(){var r,m,d;return B!=null&&B.loading?o.default.createElement("div",{className:M(n==null?void 0:n.loader,(r=t==null?void 0:t.classNames)==null?void 0:r.loader,"sonner-loader"),"data-visible":C==="loading"},B.loading):it?o.default.createElement("div",{className:M(n==null?void 0:n.loader,(m=t==null?void 0:t.classNames)==null?void 0:m.loader,"sonner-loader"),"data-visible":C==="loading"},it):o.default.createElement(Wt,{className:M(n==null?void 0:n.loader,(d=t==null?void 0:t.classNames)==null?void 0:d.loader),visible:C==="loading"})}return o.default.createElement("li",{tabIndex:0,ref:N,className:M(st,Qt,n==null?void 0:n.toast,(Bt=t==null?void 0:t.classNames)==null?void 0:Bt.toast,n==null?void 0:n.default,n==null?void 0:n[C],(Ct=t==null?void 0:t.classNames)==null?void 0:Ct[C]),"data-sonner-toast":"","data-rich-colors":(kt=t.richColors)!=null?kt:F,"data-styled":!(t.jsx||t.unstyled||a),"data-mounted":W,"data-promise":!!t.promise,"data-swiped":h,"data-removed":A,"data-visible":Gt,"data-y-position":ee,"data-x-position":oe,"data-index":g,"data-front":qt,"data-swiping":L,"data-dismissible":V,"data-type":C,"data-invert":ae,"data-swipe-out":ut,"data-swipe-direction":dt,"data-expanded":!!(D||P&&W),style:{"--index":g,"--toasts-before":g,"--z-index":i.length-g,"--offset":`${A?E:U.current}px`,"--initial-height":P?"auto":`${p}px`,...gt,...t.style},onDragEnd:()=>{z(!1),k(null),K.current=null},onPointerDown:r=>{vt||!V||(q.current=new Date,j(U.current),r.target.setPointerCapture(r.pointerId),r.target.tagName!=="BUTTON"&&(z(!0),K.current={x:r.clientX,y:r.clientY}))},onPointerUp:()=>{var v,G,Q,Z,tt,Ot;if(ut||!V)return;K.current=null;let r=Number(((v=N.current)==null?void 0:v.style.getPropertyValue("--swipe-amount-x").replace("px",""))||0),m=Number(((G=N.current)==null?void 0:G.style.getPropertyValue("--swipe-amount-y").replace("px",""))||0),d=new Date().getTime()-((Q=q.current)==null?void 0:Q.getTime()),b=Y==="x"?r:m,I=Math.abs(b)/d;if(Math.abs(b)>=Pe||I>.11){j(U.current),(Z=t.onDismiss)==null||Z.call(t,t),J(Y==="x"?r>0?"right":"left":m>0?"down":"up"),$(),u(!0),y(!1);return}else(tt=N.current)==null||tt.style.setProperty("--swipe-amount-x","0px"),(Ot=N.current)==null||Ot.style.setProperty("--swipe-amount-y","0px");z(!1),k(null)},onPointerMove:r=>{var G,Q,Z,tt;if(!K.current||!V||((G=window.getSelection())==null?void 0:G.toString().length)>0)return;let d=r.clientY-K.current.y,b=r.clientX-K.current.x,I=(Q=s.swipeDirections)!=null?Q:Be(rt);!Y&&(Math.abs(b)>1||Math.abs(d)>1)&&k(Math.abs(b)>Math.abs(d)?"x":"y");let v={x:0,y:0};Y==="y"?(I.includes("top")||I.includes("bottom"))&&(I.includes("top")&&d<0||I.includes("bottom")&&d>0)&&(v.y=d):Y==="x"&&(I.includes("left")||I.includes("right"))&&(I.includes("left")&&b<0||I.includes("right")&&b>0)&&(v.x=b),(Math.abs(v.x)>0||Math.abs(v.y)>0)&&y(!0),(Z=N.current)==null||Z.style.setProperty("--swipe-amount-x",`${v.x}px`),(tt=N.current)==null||tt.style.setProperty("--swipe-amount-y",`${v.y}px`)}},te&&!t.jsx?o.default.createElement("button",{"aria-label":lt,"data-disabled":vt,"data-close-button":!0,onClick:vt||!V?()=>{}:()=>{var r;$(),(r=t.onDismiss)==null||r.call(t,t)},className:M(n==null?void 0:n.closeButton,(It=t==null?void 0:t.classNames)==null?void 0:It.closeButton)},(Mt=B==null?void 0:B.close)!=null?Mt:_t):null,C||t.icon||t.promise?o.default.createElement("div",{"data-icon":"",className:M(n==null?void 0:n.icon,(Ht=t==null?void 0:t.classNames)==null?void 0:Ht.icon)},t.promise||t.type==="loading"&&!t.icon?t.icon||se():null,t.type!=="loading"?t.icon||(B==null?void 0:B[C])||Ft(C):null):null,o.default.createElement("div",{"data-content":"",className:M(n==null?void 0:n.content,(At=t==null?void 0:t.classNames)==null?void 0:At.content)},o.default.createElement("div",{"data-title":"",className:M(n==null?void 0:n.title,(Lt=t==null?void 0:t.classNames)==null?void 0:Lt.title)},t.jsx?t.jsx:typeof t.title=="function"?t.title():t.title),t.description?o.default.createElement("div",{"data-description":"",className:M(nt,Zt,n==null?void 0:n.description,(zt=t==null?void 0:t.classNames)==null?void 0:zt.description)},typeof t.description=="function"?t.description():t.description):null),(0,o.isValidElement)(t.cancel)?t.cancel:t.cancel&&ot(t.cancel)?o.default.createElement("button",{"data-button":!0,"data-cancel":!0,style:t.cancelButtonStyle||ht,onClick:r=>{var m,d;ot(t.cancel)&&V&&((d=(m=t.cancel).onClick)==null||d.call(m,r),$())},className:M(n==null?void 0:n.cancelButton,(jt=t==null?void 0:t.classNames)==null?void 0:jt.cancelButton)},t.cancel.label):null,(0,o.isValidElement)(t.action)?t.action:t.action&&ot(t.action)?o.default.createElement("button",{"data-button":!0,"data-action":!0,style:t.actionButtonStyle||c,onClick:r=>{var m,d;ot(t.action)&&((d=(m=t.action).onClick)==null||d.call(m,r),!r.defaultPrevented&&$())},className:M(n==null?void 0:n.actionButton,(Yt=t==null?void 0:t.classNames)==null?void 0:Yt.actionButton)},t.action.label):null)};function Jt(){if(typeof window=="undefined"||typeof document=="undefined")return"ltr";let s=document.documentElement.getAttribute("dir");return s==="auto"||!s?window.getComputedStyle(document.documentElement).direction:s}function ke(s,e){let t={};return[s,e].forEach((a,l)=>{let f=l===1,x=f?"--mobile-offset":"--offset",R=f?Re:Se;function g(i){["top","right","bottom","left"].forEach(D=>{t[`${x}-${D}`]=typeof i=="number"?`${i}px`:i})}typeof a=="number"||typeof a=="string"?g(a):typeof a=="object"?["top","right","bottom","left"].forEach(i=>{a[i]===void 0?t[`${x}-${i}`]=R:t[`${x}-${i}`]=typeof a[i]=="number"?`${a[i]}px`:a[i]}):g(R)}),t}function Ie(){let[s,e]=o.default.useState([]);return o.default.useEffect(()=>T.subscribe(t=>{if(t.dismiss){setTimeout(()=>{mt.default.flushSync(()=>{e(a=>a.filter(l=>l.id!==t.id))})});return}setTimeout(()=>{mt.default.flushSync(()=>{e(a=>{let l=a.findIndex(f=>f.id===t.id);return l!==-1?[...a.slice(0,l),{...a[l],...t},...a.slice(l+1)]:[t,...a]})})})}),[]),{toasts:s}}var Me=(0,o.forwardRef)(function(e,t){let{invert:a,position:l="bottom-right",hotkey:f=["altKey","KeyT"],expand:x,closeButton:R,className:g,offset:i,mobileOffset:D,theme:w="light",richColors:F,duration:at,style:gt,visibleToasts:ht=we,toastOptions:c,dir:st=Jt(),gap:nt=De,loadingIcon:X,icons:rt,containerAriaLabel:bt="Notifications",pauseWhenPageIsHidden:it}=e,[P,n]=o.default.useState([]),B=o.default.useMemo(()=>Array.from(new Set([l].concat(P.filter(u=>u.position).map(u=>u.position)))),[P,l]),[lt,ct]=o.default.useState([]),[Y,k]=o.default.useState(!1),[dt,J]=o.default.useState(!1),[W,H]=o.default.useState(w!=="system"?w:typeof window!="undefined"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),A=o.default.useRef(null),yt=f.join("+").replace(/Key/g,"").replace(/Digit/g,""),L=o.default.useRef(null),z=o.default.useRef(!1),ut=o.default.useCallback(u=>{n(h=>{var y;return(y=h.find(E=>E.id===u.id))!=null&&y.delete||T.dismiss(u.id),h.filter(({id:E})=>E!==u.id)})},[]);return o.default.useEffect(()=>T.subscribe(u=>{if(u.dismiss){let h=P.map(y=>y.id===u.id?{...y,delete:!0}:y);n(h);return}setTimeout(()=>{mt.default.flushSync(()=>{n(h=>{let y=h.findIndex(E=>E.id===u.id);return y!==-1?[...h.slice(0,y),{...h[y],...u},...h.slice(y+1)]:[u,...h]})})})}),[P]),o.default.useEffect(()=>{if(w!=="system"){H(w);return}if(w==="system"&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?H("dark"):H("light")),typeof window=="undefined")return;let u=window.matchMedia("(prefers-color-scheme: dark)");try{u.addEventListener("change",({matches:h})=>{H(h?"dark":"light")})}catch(h){u.addListener(({matches:y})=>{try{H(y?"dark":"light")}catch(E){console.error(E)}})}},[w]),o.default.useEffect(()=>{P.length<=1&&k(!1)},[P]),o.default.useEffect(()=>{let u=h=>{var E,j;f.every(p=>h[p]||h.code===p)&&(k(!0),(E=A.current)==null||E.focus()),h.code==="Escape"&&(document.activeElement===A.current||(j=A.current)!=null&&j.contains(document.activeElement))&&k(!1)};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[f]),o.default.useEffect(()=>{if(A.current)return()=>{L.current&&(L.current.focus({preventScroll:!0}),L.current=null,z.current=!1)}},[A.current]),o.default.createElement("section",{ref:t,"aria-label":`${bt} ${yt}`,tabIndex:-1,"aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false",suppressHydrationWarning:!0},B.map((u,h)=>{var j;let[y,E]=u.split("-");return P.length?o.default.createElement("ol",{key:u,dir:st==="auto"?Jt():st,tabIndex:-1,ref:A,className:g,"data-sonner-toaster":!0,"data-sonner-theme":W,"data-y-position":y,"data-lifted":Y&&P.length>1&&!x,"data-x-position":E,style:{"--front-toast-height":`${((j=lt[0])==null?void 0:j.height)||0}px`,"--width":`${Ee}px`,"--gap":`${nt}px`,...gt,...ke(i,D)},onBlur:p=>{z.current&&!p.currentTarget.contains(p.relatedTarget)&&(z.current=!1,L.current&&(L.current.focus({preventScroll:!0}),L.current=null))},onFocus:p=>{p.target instanceof HTMLElement&&p.target.dataset.dismissible==="false"||z.current||(z.current=!0,L.current=p.relatedTarget)},onMouseEnter:()=>k(!0),onMouseMove:()=>k(!0),onMouseLeave:()=>{dt||k(!1)},onDragEnd:()=>k(!1),onPointerDown:p=>{p.target instanceof HTMLElement&&p.target.dataset.dismissible==="false"||J(!0)},onPointerUp:()=>J(!1)},P.filter(p=>!p.position&&h===0||p.position===u).map((p,_)=>{var O,q;return o.default.createElement(Ce,{key:p.id,icons:rt,index:_,toast:p,defaultRichColors:F,duration:(O=c==null?void 0:c.duration)!=null?O:at,className:c==null?void 0:c.className,descriptionClassName:c==null?void 0:c.descriptionClassName,invert:a,visibleToasts:ht,closeButton:(q=c==null?void 0:c.closeButton)!=null?q:R,interacting:dt,position:u,style:c==null?void 0:c.style,unstyled:c==null?void 0:c.unstyled,classNames:c==null?void 0:c.classNames,cancelButtonStyle:c==null?void 0:c.cancelButtonStyle,actionButtonStyle:c==null?void 0:c.actionButtonStyle,removeToast:ut,toasts:P.filter(N=>N.position==p.position),heights:lt.filter(N=>N.position==p.position),setHeights:ct,expandByDefault:x,gap:nt,loadingIcon:X,expanded:Y,pauseWhenPageIsHidden:it,swipeDirections:e.swipeDirections})})):null}))});0&&(module.exports={Toaster,toast,useSonner});
|
|
3
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
function __insertCSS(code) {
|
|
3
|
+
if (!code || typeof document == 'undefined') return
|
|
4
|
+
let head = document.head || document.getElementsByTagName('head')[0]
|
|
5
|
+
let style = document.createElement('style')
|
|
6
|
+
style.type = 'text/css'
|
|
7
|
+
head.appendChild(style)
|
|
8
|
+
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
12
|
+
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var ReactDOM = require('react-dom');
|
|
15
|
+
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
19
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefault(ReactDOM);
|
|
20
|
+
|
|
21
|
+
const getAsset = (type)=>{
|
|
22
|
+
switch(type){
|
|
23
|
+
case 'success':
|
|
24
|
+
return SuccessIcon;
|
|
25
|
+
case 'info':
|
|
26
|
+
return InfoIcon;
|
|
27
|
+
case 'warning':
|
|
28
|
+
return WarningIcon;
|
|
29
|
+
case 'error':
|
|
30
|
+
return ErrorIcon;
|
|
31
|
+
default:
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const bars = Array(12).fill(0);
|
|
36
|
+
const Loader = ({ visible, className })=>{
|
|
37
|
+
return /*#__PURE__*/ React__default.default.createElement("div", {
|
|
38
|
+
className: [
|
|
39
|
+
'sonner-loading-wrapper',
|
|
40
|
+
className
|
|
41
|
+
].filter(Boolean).join(' '),
|
|
42
|
+
"data-visible": visible
|
|
43
|
+
}, /*#__PURE__*/ React__default.default.createElement("div", {
|
|
44
|
+
className: "sonner-spinner"
|
|
45
|
+
}, bars.map((_, i)=>/*#__PURE__*/ React__default.default.createElement("div", {
|
|
46
|
+
className: "sonner-loading-bar",
|
|
47
|
+
key: `spinner-bar-${i}`
|
|
48
|
+
}))));
|
|
49
|
+
};
|
|
50
|
+
const SuccessIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
|
|
51
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
52
|
+
viewBox: "0 0 20 20",
|
|
53
|
+
fill: "currentColor",
|
|
54
|
+
height: "20",
|
|
55
|
+
width: "20"
|
|
56
|
+
}, /*#__PURE__*/ React__default.default.createElement("path", {
|
|
57
|
+
fillRule: "evenodd",
|
|
58
|
+
d: "M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z",
|
|
59
|
+
clipRule: "evenodd"
|
|
60
|
+
}));
|
|
61
|
+
const WarningIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
|
|
62
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
63
|
+
viewBox: "0 0 24 24",
|
|
64
|
+
fill: "currentColor",
|
|
65
|
+
height: "20",
|
|
66
|
+
width: "20"
|
|
67
|
+
}, /*#__PURE__*/ React__default.default.createElement("path", {
|
|
68
|
+
fillRule: "evenodd",
|
|
69
|
+
d: "M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003zM12 8.25a.75.75 0 01.75.75v3.75a.75.75 0 01-1.5 0V9a.75.75 0 01.75-.75zm0 8.25a.75.75 0 100-1.5.75.75 0 000 1.5z",
|
|
70
|
+
clipRule: "evenodd"
|
|
71
|
+
}));
|
|
72
|
+
const InfoIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
|
|
73
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
74
|
+
viewBox: "0 0 20 20",
|
|
75
|
+
fill: "currentColor",
|
|
76
|
+
height: "20",
|
|
77
|
+
width: "20"
|
|
78
|
+
}, /*#__PURE__*/ React__default.default.createElement("path", {
|
|
79
|
+
fillRule: "evenodd",
|
|
80
|
+
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z",
|
|
81
|
+
clipRule: "evenodd"
|
|
82
|
+
}));
|
|
83
|
+
const ErrorIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
|
|
84
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
85
|
+
viewBox: "0 0 20 20",
|
|
86
|
+
fill: "currentColor",
|
|
87
|
+
height: "20",
|
|
88
|
+
width: "20"
|
|
89
|
+
}, /*#__PURE__*/ React__default.default.createElement("path", {
|
|
90
|
+
fillRule: "evenodd",
|
|
91
|
+
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z",
|
|
92
|
+
clipRule: "evenodd"
|
|
93
|
+
}));
|
|
94
|
+
const CloseIcon = /*#__PURE__*/ React__default.default.createElement("svg", {
|
|
95
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
96
|
+
width: "12",
|
|
97
|
+
height: "12",
|
|
98
|
+
viewBox: "0 0 24 24",
|
|
99
|
+
fill: "none",
|
|
100
|
+
stroke: "currentColor",
|
|
101
|
+
strokeWidth: "1.5",
|
|
102
|
+
strokeLinecap: "round",
|
|
103
|
+
strokeLinejoin: "round"
|
|
104
|
+
}, /*#__PURE__*/ React__default.default.createElement("line", {
|
|
105
|
+
x1: "18",
|
|
106
|
+
y1: "6",
|
|
107
|
+
x2: "6",
|
|
108
|
+
y2: "18"
|
|
109
|
+
}), /*#__PURE__*/ React__default.default.createElement("line", {
|
|
110
|
+
x1: "6",
|
|
111
|
+
y1: "6",
|
|
112
|
+
x2: "18",
|
|
113
|
+
y2: "18"
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
const useIsDocumentHidden = ()=>{
|
|
117
|
+
const [isDocumentHidden, setIsDocumentHidden] = React__default.default.useState(document.hidden);
|
|
118
|
+
React__default.default.useEffect(()=>{
|
|
119
|
+
const callback = ()=>{
|
|
120
|
+
setIsDocumentHidden(document.hidden);
|
|
121
|
+
};
|
|
122
|
+
document.addEventListener('visibilitychange', callback);
|
|
123
|
+
return ()=>window.removeEventListener('visibilitychange', callback);
|
|
124
|
+
}, []);
|
|
125
|
+
return isDocumentHidden;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
let toastsCounter = 1;
|
|
129
|
+
class Observer {
|
|
130
|
+
constructor(){
|
|
131
|
+
// We use arrow functions to maintain the correct `this` reference
|
|
132
|
+
this.subscribe = (subscriber)=>{
|
|
133
|
+
this.subscribers.push(subscriber);
|
|
134
|
+
return ()=>{
|
|
135
|
+
const index = this.subscribers.indexOf(subscriber);
|
|
136
|
+
this.subscribers.splice(index, 1);
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
this.publish = (data)=>{
|
|
140
|
+
this.subscribers.forEach((subscriber)=>subscriber(data));
|
|
141
|
+
};
|
|
142
|
+
this.addToast = (data)=>{
|
|
143
|
+
this.publish(data);
|
|
144
|
+
this.toasts = [
|
|
145
|
+
...this.toasts,
|
|
146
|
+
data
|
|
147
|
+
];
|
|
148
|
+
};
|
|
149
|
+
this.create = (data)=>{
|
|
150
|
+
var _data_id;
|
|
151
|
+
const { message, ...rest } = data;
|
|
152
|
+
const id = typeof (data == null ? void 0 : data.id) === 'number' || ((_data_id = data.id) == null ? void 0 : _data_id.length) > 0 ? data.id : toastsCounter++;
|
|
153
|
+
const alreadyExists = this.toasts.find((toast)=>{
|
|
154
|
+
return toast.id === id;
|
|
155
|
+
});
|
|
156
|
+
const dismissible = data.dismissible === undefined ? true : data.dismissible;
|
|
157
|
+
if (this.dismissedToasts.has(id)) {
|
|
158
|
+
this.dismissedToasts.delete(id);
|
|
159
|
+
}
|
|
160
|
+
if (alreadyExists) {
|
|
161
|
+
this.toasts = this.toasts.map((toast)=>{
|
|
162
|
+
if (toast.id === id) {
|
|
163
|
+
this.publish({
|
|
164
|
+
...toast,
|
|
165
|
+
...data,
|
|
166
|
+
id,
|
|
167
|
+
title: message
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
...toast,
|
|
171
|
+
...data,
|
|
172
|
+
id,
|
|
173
|
+
dismissible,
|
|
174
|
+
title: message
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return toast;
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
this.addToast({
|
|
181
|
+
title: message,
|
|
182
|
+
...rest,
|
|
183
|
+
dismissible,
|
|
184
|
+
id
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return id;
|
|
188
|
+
};
|
|
189
|
+
this.dismiss = (id)=>{
|
|
190
|
+
this.dismissedToasts.add(id);
|
|
191
|
+
if (!id) {
|
|
192
|
+
this.toasts.forEach((toast)=>{
|
|
193
|
+
this.subscribers.forEach((subscriber)=>subscriber({
|
|
194
|
+
id: toast.id,
|
|
195
|
+
dismiss: true
|
|
196
|
+
}));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
requestAnimationFrame(()=>this.subscribers.forEach((subscriber)=>subscriber({
|
|
200
|
+
id,
|
|
201
|
+
dismiss: true
|
|
202
|
+
})));
|
|
203
|
+
return id;
|
|
204
|
+
};
|
|
205
|
+
this.message = (message, data)=>{
|
|
206
|
+
return this.create({
|
|
207
|
+
...data,
|
|
208
|
+
message
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
this.error = (message, data)=>{
|
|
212
|
+
return this.create({
|
|
213
|
+
...data,
|
|
214
|
+
message,
|
|
215
|
+
type: 'error'
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
this.success = (message, data)=>{
|
|
219
|
+
return this.create({
|
|
220
|
+
...data,
|
|
221
|
+
type: 'success',
|
|
222
|
+
message
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
this.info = (message, data)=>{
|
|
226
|
+
return this.create({
|
|
227
|
+
...data,
|
|
228
|
+
type: 'info',
|
|
229
|
+
message
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
this.warning = (message, data)=>{
|
|
233
|
+
return this.create({
|
|
234
|
+
...data,
|
|
235
|
+
type: 'warning',
|
|
236
|
+
message
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
this.loading = (message, data)=>{
|
|
240
|
+
return this.create({
|
|
241
|
+
...data,
|
|
242
|
+
type: 'loading',
|
|
243
|
+
message
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
this.promise = (promise, data)=>{
|
|
247
|
+
if (!data) {
|
|
248
|
+
// Nothing to show
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
let id = undefined;
|
|
252
|
+
if (data.loading !== undefined) {
|
|
253
|
+
id = this.create({
|
|
254
|
+
...data,
|
|
255
|
+
promise,
|
|
256
|
+
type: 'loading',
|
|
257
|
+
message: data.loading,
|
|
258
|
+
description: typeof data.description !== 'function' ? data.description : undefined
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const p = Promise.resolve(promise instanceof Function ? promise() : promise);
|
|
262
|
+
let shouldDismiss = id !== undefined;
|
|
263
|
+
let result;
|
|
264
|
+
const originalPromise = p.then(async (response)=>{
|
|
265
|
+
result = [
|
|
266
|
+
'resolve',
|
|
267
|
+
response
|
|
268
|
+
];
|
|
269
|
+
const isReactElementResponse = React__default.default.isValidElement(response);
|
|
270
|
+
if (isReactElementResponse) {
|
|
271
|
+
shouldDismiss = false;
|
|
272
|
+
this.create({
|
|
273
|
+
id,
|
|
274
|
+
type: 'default',
|
|
275
|
+
message: response
|
|
276
|
+
});
|
|
277
|
+
} else if (isHttpResponse(response) && !response.ok) {
|
|
278
|
+
shouldDismiss = false;
|
|
279
|
+
const message = typeof data.error === 'function' ? await data.error(`HTTP error! status: ${response.status}`) : data.error;
|
|
280
|
+
const description = typeof data.description === 'function' ? await data.description(`HTTP error! status: ${response.status}`) : data.description;
|
|
281
|
+
this.create({
|
|
282
|
+
id,
|
|
283
|
+
type: 'error',
|
|
284
|
+
message,
|
|
285
|
+
description
|
|
286
|
+
});
|
|
287
|
+
} else if (data.success !== undefined) {
|
|
288
|
+
shouldDismiss = false;
|
|
289
|
+
const message = typeof data.success === 'function' ? await data.success(response) : data.success;
|
|
290
|
+
const description = typeof data.description === 'function' ? await data.description(response) : data.description;
|
|
291
|
+
this.create({
|
|
292
|
+
id,
|
|
293
|
+
type: 'success',
|
|
294
|
+
message,
|
|
295
|
+
description
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}).catch(async (error)=>{
|
|
299
|
+
result = [
|
|
300
|
+
'reject',
|
|
301
|
+
error
|
|
302
|
+
];
|
|
303
|
+
if (data.error !== undefined) {
|
|
304
|
+
shouldDismiss = false;
|
|
305
|
+
const message = typeof data.error === 'function' ? await data.error(error) : data.error;
|
|
306
|
+
const description = typeof data.description === 'function' ? await data.description(error) : data.description;
|
|
307
|
+
this.create({
|
|
308
|
+
id,
|
|
309
|
+
type: 'error',
|
|
310
|
+
message,
|
|
311
|
+
description
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}).finally(()=>{
|
|
315
|
+
if (shouldDismiss) {
|
|
316
|
+
// Toast is still in load state (and will be indefinitely — dismiss it)
|
|
317
|
+
this.dismiss(id);
|
|
318
|
+
id = undefined;
|
|
319
|
+
}
|
|
320
|
+
data.finally == null ? void 0 : data.finally.call(data);
|
|
321
|
+
});
|
|
322
|
+
const unwrap = ()=>new Promise((resolve, reject)=>originalPromise.then(()=>result[0] === 'reject' ? reject(result[1]) : resolve(result[1])).catch(reject));
|
|
323
|
+
if (typeof id !== 'string' && typeof id !== 'number') {
|
|
324
|
+
// cannot Object.assign on undefined
|
|
325
|
+
return {
|
|
326
|
+
unwrap
|
|
327
|
+
};
|
|
328
|
+
} else {
|
|
329
|
+
return Object.assign(id, {
|
|
330
|
+
unwrap
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
this.custom = (jsx, data)=>{
|
|
335
|
+
const id = (data == null ? void 0 : data.id) || toastsCounter++;
|
|
336
|
+
this.create({
|
|
337
|
+
jsx: jsx(id),
|
|
338
|
+
id,
|
|
339
|
+
...data
|
|
340
|
+
});
|
|
341
|
+
return id;
|
|
342
|
+
};
|
|
343
|
+
this.getActiveToasts = ()=>{
|
|
344
|
+
return this.toasts.filter((toast)=>!this.dismissedToasts.has(toast.id));
|
|
345
|
+
};
|
|
346
|
+
this.subscribers = [];
|
|
347
|
+
this.toasts = [];
|
|
348
|
+
this.dismissedToasts = new Set();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const ToastState = new Observer();
|
|
352
|
+
// bind this to the toast function
|
|
353
|
+
const toastFunction = (message, data)=>{
|
|
354
|
+
const id = (data == null ? void 0 : data.id) || toastsCounter++;
|
|
355
|
+
ToastState.addToast({
|
|
356
|
+
title: message,
|
|
357
|
+
...data,
|
|
358
|
+
id
|
|
359
|
+
});
|
|
360
|
+
return id;
|
|
361
|
+
};
|
|
362
|
+
const isHttpResponse = (data)=>{
|
|
363
|
+
return data && typeof data === 'object' && 'ok' in data && typeof data.ok === 'boolean' && 'status' in data && typeof data.status === 'number';
|
|
364
|
+
};
|
|
365
|
+
const basicToast = toastFunction;
|
|
366
|
+
const getHistory = ()=>ToastState.toasts;
|
|
367
|
+
const getToasts = ()=>ToastState.getActiveToasts();
|
|
368
|
+
// We use `Object.assign` to maintain the correct types as we would lose them otherwise
|
|
369
|
+
const toast = Object.assign(basicToast, {
|
|
370
|
+
success: ToastState.success,
|
|
371
|
+
info: ToastState.info,
|
|
372
|
+
warning: ToastState.warning,
|
|
373
|
+
error: ToastState.error,
|
|
374
|
+
custom: ToastState.custom,
|
|
375
|
+
message: ToastState.message,
|
|
376
|
+
promise: ToastState.promise,
|
|
377
|
+
dismiss: ToastState.dismiss,
|
|
378
|
+
loading: ToastState.loading
|
|
379
|
+
}, {
|
|
380
|
+
getHistory,
|
|
381
|
+
getToasts
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
__insertCSS("[data-sonner-toaster][dir=ltr],html[dir=ltr]{--toast-icon-margin-start:-3px;--toast-icon-margin-end:4px;--toast-svg-margin-start:-1px;--toast-svg-margin-end:0px;--toast-button-margin-start:auto;--toast-button-margin-end:0;--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}[data-sonner-toaster][dir=rtl],html[dir=rtl]{--toast-icon-margin-start:4px;--toast-icon-margin-end:-3px;--toast-svg-margin-start:0px;--toast-svg-margin-end:-1px;--toast-button-margin-start:0;--toast-button-margin-end:auto;--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}[data-sonner-toaster]{position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:0;z-index:999999999;transition:transform .4s ease}[data-sonner-toaster][data-lifted=true]{transform:translateY(-8px)}@media (hover:none) and (pointer:coarse){[data-sonner-toaster][data-lifted=true]{transform:none}}[data-sonner-toaster][data-x-position=right]{right:var(--offset-right)}[data-sonner-toaster][data-x-position=left]{left:var(--offset-left)}[data-sonner-toaster][data-x-position=center]{left:50%;transform:translateX(-50%)}[data-sonner-toaster][data-y-position=top]{top:var(--offset-top)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--offset-bottom)}[data-sonner-toast]{--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:0;overflow-wrap:anywhere}[data-sonner-toast][data-styled=true]{padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px rgba(0,0,0,.1);width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}[data-sonner-toast]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-y-position=top]{top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}[data-sonner-toast][data-y-position=bottom]{bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}[data-sonner-toast][data-styled=true] [data-description]{font-weight:400;line-height:1.4;color:#3f3f3f}[data-sonner-toaster][data-sonner-theme=dark] [data-description]{color:#e8e8e8}[data-sonner-toast][data-styled=true] [data-title]{font-weight:500;line-height:1.5;color:inherit}[data-sonner-toast][data-styled=true] [data-icon]{display:flex;height:16px;width:16px;position:relative;justify-content:flex-start;align-items:center;flex-shrink:0;margin-left:var(--toast-icon-margin-start);margin-right:var(--toast-icon-margin-end)}[data-sonner-toast][data-promise=true] [data-icon]>svg{opacity:0;transform:scale(.8);transform-origin:center;animation:sonner-fade-in .3s ease forwards}[data-sonner-toast][data-styled=true] [data-icon]>*{flex-shrink:0}[data-sonner-toast][data-styled=true] [data-icon] svg{margin-left:var(--toast-svg-margin-start);margin-right:var(--toast-svg-margin-end)}[data-sonner-toast][data-styled=true] [data-content]{display:flex;flex-direction:column;gap:2px}[data-sonner-toast][data-styled=true] [data-button]{border-radius:4px;padding-left:8px;padding-right:8px;height:24px;font-size:12px;color:var(--normal-bg);background:var(--normal-text);margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end);border:none;font-weight:500;cursor:pointer;outline:0;display:flex;align-items:center;flex-shrink:0;transition:opacity .4s,box-shadow .2s}[data-sonner-toast][data-styled=true] [data-button]:focus-visible{box-shadow:0 0 0 2px rgba(0,0,0,.4)}[data-sonner-toast][data-styled=true] [data-button]:first-of-type{margin-left:var(--toast-button-margin-start);margin-right:var(--toast-button-margin-end)}[data-sonner-toast][data-styled=true] [data-cancel]{color:var(--normal-text);background:rgba(0,0,0,.08)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-styled=true] [data-cancel]{background:rgba(255,255,255,.3)}[data-sonner-toast][data-styled=true] [data-close-button]{position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;color:var(--gray12);background:var(--normal-bg);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}[data-sonner-toast][data-styled=true] [data-close-button]:focus-visible{box-shadow:0 4px 12px rgba(0,0,0,.1),0 0 0 2px rgba(0,0,0,.2)}[data-sonner-toast][data-styled=true] [data-disabled=true]{cursor:not-allowed}[data-sonner-toast][data-styled=true]:hover [data-close-button]:hover{background:var(--gray2);border-color:var(--gray5)}[data-sonner-toast][data-swiping=true]::before{content:'';position:absolute;left:-100%;right:-100%;height:100%;z-index:-1}[data-sonner-toast][data-y-position=top][data-swiping=true]::before{bottom:50%;transform:scaleY(3) translateY(50%)}[data-sonner-toast][data-y-position=bottom][data-swiping=true]::before{top:50%;transform:scaleY(3) translateY(-50%)}[data-sonner-toast][data-swiping=false][data-removed=true]::before{content:'';position:absolute;inset:0;transform:scaleY(2)}[data-sonner-toast]::after{content:'';position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}[data-sonner-toast][data-mounted=true]{--y:translateY(0);opacity:1}[data-sonner-toast][data-expanded=false][data-front=false]{--scale:var(--toasts-before) * 0.05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}[data-sonner-toast]>*{transition:opacity .4s}[data-sonner-toast][data-x-position=right]{right:0}[data-sonner-toast][data-x-position=left]{left:0}[data-sonner-toast][data-expanded=false][data-front=false][data-styled=true]>*{opacity:0}[data-sonner-toast][data-visible=false]{opacity:0;pointer-events:none}[data-sonner-toast][data-mounted=true][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}[data-sonner-toast][data-removed=true][data-front=true][data-swipe-out=false]{--y:translateY(calc(var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=true]{--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}[data-sonner-toast][data-removed=true][data-front=false][data-swipe-out=false][data-expanded=false]{--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}[data-sonner-toast][data-removed=true][data-front=false]::before{height:calc(var(--initial-height) + 20%)}[data-sonner-toast][data-swiping=true]{transform:var(--y) translateY(var(--swipe-amount-y,0)) translateX(var(--swipe-amount-x,0));transition:none}[data-sonner-toast][data-swiped=true]{user-select:none}[data-sonner-toast][data-swipe-out=true][data-y-position=bottom],[data-sonner-toast][data-swipe-out=true][data-y-position=top]{animation-duration:.2s;animation-timing-function:ease-out;animation-fill-mode:forwards}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=left]{animation-name:swipe-out-left}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=right]{animation-name:swipe-out-right}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=up]{animation-name:swipe-out-up}[data-sonner-toast][data-swipe-out=true][data-swipe-direction=down]{animation-name:swipe-out-down}@keyframes swipe-out-left{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) - 100%));opacity:0}}@keyframes swipe-out-right{from{transform:var(--y) translateX(var(--swipe-amount-x));opacity:1}to{transform:var(--y) translateX(calc(var(--swipe-amount-x) + 100%));opacity:0}}@keyframes swipe-out-up{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) - 100%));opacity:0}}@keyframes swipe-out-down{from{transform:var(--y) translateY(var(--swipe-amount-y));opacity:1}to{transform:var(--y) translateY(calc(var(--swipe-amount-y) + 100%));opacity:0}}@media (max-width:600px){[data-sonner-toaster]{position:fixed;right:var(--mobile-offset-right);left:var(--mobile-offset-left);width:100%}[data-sonner-toaster][dir=rtl]{left:calc(var(--mobile-offset-left) * -1)}[data-sonner-toaster] [data-sonner-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset-left) * 2)}[data-sonner-toaster][data-x-position=left]{left:var(--mobile-offset-left)}[data-sonner-toaster][data-y-position=bottom]{bottom:var(--mobile-offset-bottom)}[data-sonner-toaster][data-y-position=top]{top:var(--mobile-offset-top)}[data-sonner-toaster][data-x-position=center]{left:var(--mobile-offset-left);right:var(--mobile-offset-right);transform:none}}[data-sonner-toaster][data-sonner-theme=light]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 87%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 93%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 84%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}[data-sonner-toaster][data-sonner-theme=light] [data-sonner-toast][data-invert=true]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast][data-invert=true]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}[data-sonner-toaster][data-sonner-theme=dark]{--normal-bg:#000;--normal-bg-hover:hsl(0, 0%, 12%);--normal-border:hsl(0, 0%, 20%);--normal-border-hover:hsl(0, 0%, 25%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 43%, 17%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 9%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]{background:var(--normal-bg);border-color:var(--normal-border);color:var(--normal-text)}[data-sonner-toaster][data-sonner-theme=dark] [data-sonner-toast] [data-close-button]:hover{background:var(--normal-bg-hover);border-color:var(--normal-border-hover)}[data-rich-colors=true][data-sonner-toast][data-type=success]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=success] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}[data-rich-colors=true][data-sonner-toast][data-type=info]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=info] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=warning] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}[data-rich-colors=true][data-sonner-toast][data-type=error]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}[data-rich-colors=true][data-sonner-toast][data-type=error] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}.sonner-loading-wrapper{--size:16px;height:var(--size);width:var(--size);position:absolute;inset:0;z-index:10}.sonner-loading-wrapper[data-visible=false]{transform-origin:center;animation:sonner-fade-out .2s ease forwards}.sonner-spinner{position:relative;top:50%;left:50%;height:var(--size);width:var(--size)}.sonner-loading-bar{animation:sonner-spin 1.2s linear infinite;background:var(--gray11);border-radius:6px;height:8%;left:-10%;position:absolute;top:-3.9%;width:24%}.sonner-loading-bar:first-child{animation-delay:-1.2s;transform:rotate(.0001deg) translate(146%)}.sonner-loading-bar:nth-child(2){animation-delay:-1.1s;transform:rotate(30deg) translate(146%)}.sonner-loading-bar:nth-child(3){animation-delay:-1s;transform:rotate(60deg) translate(146%)}.sonner-loading-bar:nth-child(4){animation-delay:-.9s;transform:rotate(90deg) translate(146%)}.sonner-loading-bar:nth-child(5){animation-delay:-.8s;transform:rotate(120deg) translate(146%)}.sonner-loading-bar:nth-child(6){animation-delay:-.7s;transform:rotate(150deg) translate(146%)}.sonner-loading-bar:nth-child(7){animation-delay:-.6s;transform:rotate(180deg) translate(146%)}.sonner-loading-bar:nth-child(8){animation-delay:-.5s;transform:rotate(210deg) translate(146%)}.sonner-loading-bar:nth-child(9){animation-delay:-.4s;transform:rotate(240deg) translate(146%)}.sonner-loading-bar:nth-child(10){animation-delay:-.3s;transform:rotate(270deg) translate(146%)}.sonner-loading-bar:nth-child(11){animation-delay:-.2s;transform:rotate(300deg) translate(146%)}.sonner-loading-bar:nth-child(12){animation-delay:-.1s;transform:rotate(330deg) translate(146%)}@keyframes sonner-fade-in{0%{opacity:0;transform:scale(.8)}100%{opacity:1;transform:scale(1)}}@keyframes sonner-fade-out{0%{opacity:1;transform:scale(1)}100%{opacity:0;transform:scale(.8)}}@keyframes sonner-spin{0%{opacity:1}100%{opacity:.15}}@media (prefers-reduced-motion){.sonner-loading-bar,[data-sonner-toast],[data-sonner-toast]>*{transition:none!important;animation:none!important}}.sonner-loader{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);transform-origin:center;transition:opacity .2s,transform .2s}.sonner-loader[data-visible=false]{opacity:0;transform:scale(.8) translate(-50%,-50%)}");
|
|
385
|
+
|
|
386
|
+
function isAction(action) {
|
|
387
|
+
return action.label !== undefined;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Visible toasts amount
|
|
391
|
+
const VISIBLE_TOASTS_AMOUNT = 3;
|
|
392
|
+
// Viewport padding
|
|
393
|
+
const VIEWPORT_OFFSET = '24px';
|
|
394
|
+
// Mobile viewport padding
|
|
395
|
+
const MOBILE_VIEWPORT_OFFSET = '16px';
|
|
396
|
+
// Default lifetime of a toasts (in ms)
|
|
397
|
+
const TOAST_LIFETIME = 4000;
|
|
398
|
+
// Default toast width
|
|
399
|
+
const TOAST_WIDTH = 356;
|
|
400
|
+
// Default gap between toasts
|
|
401
|
+
const GAP = 14;
|
|
402
|
+
// Threshold to dismiss a toast
|
|
403
|
+
const SWIPE_THRESHOLD = 20;
|
|
404
|
+
// Equal to exit animation duration
|
|
405
|
+
const TIME_BEFORE_UNMOUNT = 200;
|
|
406
|
+
function cn(...classes) {
|
|
407
|
+
return classes.filter(Boolean).join(' ');
|
|
408
|
+
}
|
|
409
|
+
function getDefaultSwipeDirections(position) {
|
|
410
|
+
const [y, x] = position.split('-');
|
|
411
|
+
const directions = [];
|
|
412
|
+
if (y) {
|
|
413
|
+
directions.push(y);
|
|
414
|
+
}
|
|
415
|
+
if (x) {
|
|
416
|
+
directions.push(x);
|
|
417
|
+
}
|
|
418
|
+
return directions;
|
|
419
|
+
}
|
|
420
|
+
const Toast = (props)=>{
|
|
421
|
+
var _toast_classNames, _toast_classNames1, _toast_classNames2, _toast_classNames3, _toast_classNames4, _toast_classNames5, _toast_classNames6, _toast_classNames7, _toast_classNames8;
|
|
422
|
+
const { invert: ToasterInvert, toast, unstyled, interacting, setHeights, visibleToasts, heights, index, toasts, expanded, removeToast, defaultRichColors, closeButton: closeButtonFromToaster, style, cancelButtonStyle, actionButtonStyle, className = '', descriptionClassName = '', duration: durationFromToaster, position, gap, loadingIcon: loadingIconProp, expandByDefault, classNames, icons, closeButtonAriaLabel = 'Close toast', pauseWhenPageIsHidden } = props;
|
|
423
|
+
const [swipeDirection, setSwipeDirection] = React__default.default.useState(null);
|
|
424
|
+
const [swipeOutDirection, setSwipeOutDirection] = React__default.default.useState(null);
|
|
425
|
+
const [mounted, setMounted] = React__default.default.useState(false);
|
|
426
|
+
const [removed, setRemoved] = React__default.default.useState(false);
|
|
427
|
+
const [swiping, setSwiping] = React__default.default.useState(false);
|
|
428
|
+
const [swipeOut, setSwipeOut] = React__default.default.useState(false);
|
|
429
|
+
const [isSwiped, setIsSwiped] = React__default.default.useState(false);
|
|
430
|
+
const [offsetBeforeRemove, setOffsetBeforeRemove] = React__default.default.useState(0);
|
|
431
|
+
const [initialHeight, setInitialHeight] = React__default.default.useState(0);
|
|
432
|
+
const remainingTime = React__default.default.useRef(toast.duration || durationFromToaster || TOAST_LIFETIME);
|
|
433
|
+
const dragStartTime = React__default.default.useRef(null);
|
|
434
|
+
const toastRef = React__default.default.useRef(null);
|
|
435
|
+
const isFront = index === 0;
|
|
436
|
+
const isVisible = index + 1 <= visibleToasts;
|
|
437
|
+
const toastType = toast.type;
|
|
438
|
+
const dismissible = toast.dismissible !== false;
|
|
439
|
+
const toastClassname = toast.className || '';
|
|
440
|
+
const toastDescriptionClassname = toast.descriptionClassName || '';
|
|
441
|
+
// Height index is used to calculate the offset as it gets updated before the toast array, which means we can calculate the new layout faster.
|
|
442
|
+
const heightIndex = React__default.default.useMemo(()=>heights.findIndex((height)=>height.toastId === toast.id) || 0, [
|
|
443
|
+
heights,
|
|
444
|
+
toast.id
|
|
445
|
+
]);
|
|
446
|
+
const closeButton = React__default.default.useMemo(()=>{
|
|
447
|
+
var _toast_closeButton;
|
|
448
|
+
return (_toast_closeButton = toast.closeButton) != null ? _toast_closeButton : closeButtonFromToaster;
|
|
449
|
+
}, [
|
|
450
|
+
toast.closeButton,
|
|
451
|
+
closeButtonFromToaster
|
|
452
|
+
]);
|
|
453
|
+
const duration = React__default.default.useMemo(()=>toast.duration || durationFromToaster || TOAST_LIFETIME, [
|
|
454
|
+
toast.duration,
|
|
455
|
+
durationFromToaster
|
|
456
|
+
]);
|
|
457
|
+
const closeTimerStartTimeRef = React__default.default.useRef(0);
|
|
458
|
+
const offset = React__default.default.useRef(0);
|
|
459
|
+
const lastCloseTimerStartTimeRef = React__default.default.useRef(0);
|
|
460
|
+
const pointerStartRef = React__default.default.useRef(null);
|
|
461
|
+
const [y, x] = position.split('-');
|
|
462
|
+
const toastsHeightBefore = React__default.default.useMemo(()=>{
|
|
463
|
+
return heights.reduce((prev, curr, reducerIndex)=>{
|
|
464
|
+
// Calculate offset up until current toast
|
|
465
|
+
if (reducerIndex >= heightIndex) {
|
|
466
|
+
return prev;
|
|
467
|
+
}
|
|
468
|
+
return prev + curr.height;
|
|
469
|
+
}, 0);
|
|
470
|
+
}, [
|
|
471
|
+
heights,
|
|
472
|
+
heightIndex
|
|
473
|
+
]);
|
|
474
|
+
const isDocumentHidden = useIsDocumentHidden();
|
|
475
|
+
const invert = toast.invert || ToasterInvert;
|
|
476
|
+
const disabled = toastType === 'loading';
|
|
477
|
+
offset.current = React__default.default.useMemo(()=>heightIndex * gap + toastsHeightBefore, [
|
|
478
|
+
heightIndex,
|
|
479
|
+
toastsHeightBefore
|
|
480
|
+
]);
|
|
481
|
+
React__default.default.useEffect(()=>{
|
|
482
|
+
remainingTime.current = duration;
|
|
483
|
+
}, [
|
|
484
|
+
duration
|
|
485
|
+
]);
|
|
486
|
+
React__default.default.useEffect(()=>{
|
|
487
|
+
// Trigger enter animation without using CSS animation
|
|
488
|
+
setMounted(true);
|
|
489
|
+
}, []);
|
|
490
|
+
React__default.default.useEffect(()=>{
|
|
491
|
+
const toastNode = toastRef.current;
|
|
492
|
+
if (toastNode) {
|
|
493
|
+
const height = toastNode.getBoundingClientRect().height;
|
|
494
|
+
// Add toast height to heights array after the toast is mounted
|
|
495
|
+
setInitialHeight(height);
|
|
496
|
+
setHeights((h)=>[
|
|
497
|
+
{
|
|
498
|
+
toastId: toast.id,
|
|
499
|
+
height,
|
|
500
|
+
position: toast.position
|
|
501
|
+
},
|
|
502
|
+
...h
|
|
503
|
+
]);
|
|
504
|
+
return ()=>setHeights((h)=>h.filter((height)=>height.toastId !== toast.id));
|
|
505
|
+
}
|
|
506
|
+
}, [
|
|
507
|
+
setHeights,
|
|
508
|
+
toast.id
|
|
509
|
+
]);
|
|
510
|
+
React__default.default.useLayoutEffect(()=>{
|
|
511
|
+
if (!mounted) return;
|
|
512
|
+
const toastNode = toastRef.current;
|
|
513
|
+
const originalHeight = toastNode.style.height;
|
|
514
|
+
toastNode.style.height = 'auto';
|
|
515
|
+
const newHeight = toastNode.getBoundingClientRect().height;
|
|
516
|
+
toastNode.style.height = originalHeight;
|
|
517
|
+
setInitialHeight(newHeight);
|
|
518
|
+
setHeights((heights)=>{
|
|
519
|
+
const alreadyExists = heights.find((height)=>height.toastId === toast.id);
|
|
520
|
+
if (!alreadyExists) {
|
|
521
|
+
return [
|
|
522
|
+
{
|
|
523
|
+
toastId: toast.id,
|
|
524
|
+
height: newHeight,
|
|
525
|
+
position: toast.position
|
|
526
|
+
},
|
|
527
|
+
...heights
|
|
528
|
+
];
|
|
529
|
+
} else {
|
|
530
|
+
return heights.map((height)=>height.toastId === toast.id ? {
|
|
531
|
+
...height,
|
|
532
|
+
height: newHeight
|
|
533
|
+
} : height);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}, [
|
|
537
|
+
mounted,
|
|
538
|
+
toast.title,
|
|
539
|
+
toast.description,
|
|
540
|
+
setHeights,
|
|
541
|
+
toast.id
|
|
542
|
+
]);
|
|
543
|
+
const deleteToast = React__default.default.useCallback(()=>{
|
|
544
|
+
// Save the offset for the exit swipe animation
|
|
545
|
+
setRemoved(true);
|
|
546
|
+
setOffsetBeforeRemove(offset.current);
|
|
547
|
+
setHeights((h)=>h.filter((height)=>height.toastId !== toast.id));
|
|
548
|
+
setTimeout(()=>{
|
|
549
|
+
removeToast(toast);
|
|
550
|
+
}, TIME_BEFORE_UNMOUNT);
|
|
551
|
+
}, [
|
|
552
|
+
toast,
|
|
553
|
+
removeToast,
|
|
554
|
+
setHeights,
|
|
555
|
+
offset
|
|
556
|
+
]);
|
|
557
|
+
React__default.default.useEffect(()=>{
|
|
558
|
+
if (toast.promise && toastType === 'loading' || toast.duration === Infinity || toast.type === 'loading') return;
|
|
559
|
+
let timeoutId;
|
|
560
|
+
// Pause the timer on each hover
|
|
561
|
+
const pauseTimer = ()=>{
|
|
562
|
+
if (lastCloseTimerStartTimeRef.current < closeTimerStartTimeRef.current) {
|
|
563
|
+
// Get the elapsed time since the timer started
|
|
564
|
+
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
|
|
565
|
+
remainingTime.current = remainingTime.current - elapsedTime;
|
|
566
|
+
}
|
|
567
|
+
lastCloseTimerStartTimeRef.current = new Date().getTime();
|
|
568
|
+
};
|
|
569
|
+
const startTimer = ()=>{
|
|
570
|
+
// setTimeout(, Infinity) behaves as if the delay is 0.
|
|
571
|
+
// As a result, the toast would be closed immediately, giving the appearance that it was never rendered.
|
|
572
|
+
// See: https://github.com/denysdovhan/wtfjs?tab=readme-ov-file#an-infinite-timeout
|
|
573
|
+
if (remainingTime.current === Infinity) return;
|
|
574
|
+
closeTimerStartTimeRef.current = new Date().getTime();
|
|
575
|
+
// Let the toast know it has started
|
|
576
|
+
timeoutId = setTimeout(()=>{
|
|
577
|
+
toast.onAutoClose == null ? void 0 : toast.onAutoClose.call(toast, toast);
|
|
578
|
+
deleteToast();
|
|
579
|
+
}, remainingTime.current);
|
|
580
|
+
};
|
|
581
|
+
if (expanded || interacting || pauseWhenPageIsHidden && isDocumentHidden) {
|
|
582
|
+
pauseTimer();
|
|
583
|
+
} else {
|
|
584
|
+
startTimer();
|
|
585
|
+
}
|
|
586
|
+
return ()=>clearTimeout(timeoutId);
|
|
587
|
+
}, [
|
|
588
|
+
expanded,
|
|
589
|
+
interacting,
|
|
590
|
+
toast,
|
|
591
|
+
toastType,
|
|
592
|
+
pauseWhenPageIsHidden,
|
|
593
|
+
isDocumentHidden,
|
|
594
|
+
deleteToast
|
|
595
|
+
]);
|
|
596
|
+
React__default.default.useEffect(()=>{
|
|
597
|
+
if (toast.delete) {
|
|
598
|
+
deleteToast();
|
|
599
|
+
}
|
|
600
|
+
}, [
|
|
601
|
+
deleteToast,
|
|
602
|
+
toast.delete
|
|
603
|
+
]);
|
|
604
|
+
function getLoadingIcon() {
|
|
605
|
+
var _toast_classNames;
|
|
606
|
+
if (icons == null ? void 0 : icons.loading) {
|
|
607
|
+
var _toast_classNames1;
|
|
608
|
+
return /*#__PURE__*/ React__default.default.createElement("div", {
|
|
609
|
+
className: cn(classNames == null ? void 0 : classNames.loader, toast == null ? void 0 : (_toast_classNames1 = toast.classNames) == null ? void 0 : _toast_classNames1.loader, 'sonner-loader'),
|
|
610
|
+
"data-visible": toastType === 'loading'
|
|
611
|
+
}, icons.loading);
|
|
612
|
+
}
|
|
613
|
+
if (loadingIconProp) {
|
|
614
|
+
var _toast_classNames2;
|
|
615
|
+
return /*#__PURE__*/ React__default.default.createElement("div", {
|
|
616
|
+
className: cn(classNames == null ? void 0 : classNames.loader, toast == null ? void 0 : (_toast_classNames2 = toast.classNames) == null ? void 0 : _toast_classNames2.loader, 'sonner-loader'),
|
|
617
|
+
"data-visible": toastType === 'loading'
|
|
618
|
+
}, loadingIconProp);
|
|
619
|
+
}
|
|
620
|
+
return /*#__PURE__*/ React__default.default.createElement(Loader, {
|
|
621
|
+
className: cn(classNames == null ? void 0 : classNames.loader, toast == null ? void 0 : (_toast_classNames = toast.classNames) == null ? void 0 : _toast_classNames.loader),
|
|
622
|
+
visible: toastType === 'loading'
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
var _toast_richColors, _icons_close;
|
|
626
|
+
return /*#__PURE__*/ React__default.default.createElement("li", {
|
|
627
|
+
tabIndex: 0,
|
|
628
|
+
ref: toastRef,
|
|
629
|
+
className: cn(className, toastClassname, classNames == null ? void 0 : classNames.toast, toast == null ? void 0 : (_toast_classNames = toast.classNames) == null ? void 0 : _toast_classNames.toast, classNames == null ? void 0 : classNames.default, classNames == null ? void 0 : classNames[toastType], toast == null ? void 0 : (_toast_classNames1 = toast.classNames) == null ? void 0 : _toast_classNames1[toastType]),
|
|
630
|
+
"data-sonner-toast": "",
|
|
631
|
+
"data-rich-colors": (_toast_richColors = toast.richColors) != null ? _toast_richColors : defaultRichColors,
|
|
632
|
+
"data-styled": !Boolean(toast.jsx || toast.unstyled || unstyled),
|
|
633
|
+
"data-mounted": mounted,
|
|
634
|
+
"data-promise": Boolean(toast.promise),
|
|
635
|
+
"data-swiped": isSwiped,
|
|
636
|
+
"data-removed": removed,
|
|
637
|
+
"data-visible": isVisible,
|
|
638
|
+
"data-y-position": y,
|
|
639
|
+
"data-x-position": x,
|
|
640
|
+
"data-index": index,
|
|
641
|
+
"data-front": isFront,
|
|
642
|
+
"data-swiping": swiping,
|
|
643
|
+
"data-dismissible": dismissible,
|
|
644
|
+
"data-type": toastType,
|
|
645
|
+
"data-invert": invert,
|
|
646
|
+
"data-swipe-out": swipeOut,
|
|
647
|
+
"data-swipe-direction": swipeOutDirection,
|
|
648
|
+
"data-expanded": Boolean(expanded || expandByDefault && mounted),
|
|
649
|
+
style: {
|
|
650
|
+
'--index': index,
|
|
651
|
+
'--toasts-before': index,
|
|
652
|
+
'--z-index': toasts.length - index,
|
|
653
|
+
'--offset': `${removed ? offsetBeforeRemove : offset.current}px`,
|
|
654
|
+
'--initial-height': expandByDefault ? 'auto' : `${initialHeight}px`,
|
|
655
|
+
...style,
|
|
656
|
+
...toast.style
|
|
657
|
+
},
|
|
658
|
+
onDragEnd: ()=>{
|
|
659
|
+
setSwiping(false);
|
|
660
|
+
setSwipeDirection(null);
|
|
661
|
+
pointerStartRef.current = null;
|
|
662
|
+
},
|
|
663
|
+
onPointerDown: (event)=>{
|
|
664
|
+
if (disabled || !dismissible) return;
|
|
665
|
+
dragStartTime.current = new Date();
|
|
666
|
+
setOffsetBeforeRemove(offset.current);
|
|
667
|
+
// Ensure we maintain correct pointer capture even when going outside of the toast (e.g. when swiping)
|
|
668
|
+
event.target.setPointerCapture(event.pointerId);
|
|
669
|
+
if (event.target.tagName === 'BUTTON') return;
|
|
670
|
+
setSwiping(true);
|
|
671
|
+
pointerStartRef.current = {
|
|
672
|
+
x: event.clientX,
|
|
673
|
+
y: event.clientY
|
|
674
|
+
};
|
|
675
|
+
},
|
|
676
|
+
onPointerUp: ()=>{
|
|
677
|
+
var _toastRef_current, _toastRef_current1, _dragStartTime_current;
|
|
678
|
+
if (swipeOut || !dismissible) return;
|
|
679
|
+
pointerStartRef.current = null;
|
|
680
|
+
const swipeAmountX = Number(((_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.getPropertyValue('--swipe-amount-x').replace('px', '')) || 0);
|
|
681
|
+
const swipeAmountY = Number(((_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.getPropertyValue('--swipe-amount-y').replace('px', '')) || 0);
|
|
682
|
+
const timeTaken = new Date().getTime() - ((_dragStartTime_current = dragStartTime.current) == null ? void 0 : _dragStartTime_current.getTime());
|
|
683
|
+
const swipeAmount = swipeDirection === 'x' ? swipeAmountX : swipeAmountY;
|
|
684
|
+
const velocity = Math.abs(swipeAmount) / timeTaken;
|
|
685
|
+
if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > 0.11) {
|
|
686
|
+
setOffsetBeforeRemove(offset.current);
|
|
687
|
+
toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
|
|
688
|
+
if (swipeDirection === 'x') {
|
|
689
|
+
setSwipeOutDirection(swipeAmountX > 0 ? 'right' : 'left');
|
|
690
|
+
} else {
|
|
691
|
+
setSwipeOutDirection(swipeAmountY > 0 ? 'down' : 'up');
|
|
692
|
+
}
|
|
693
|
+
deleteToast();
|
|
694
|
+
setSwipeOut(true);
|
|
695
|
+
setIsSwiped(false);
|
|
696
|
+
return;
|
|
697
|
+
} else {
|
|
698
|
+
var _toastRef_current2, _toastRef_current3;
|
|
699
|
+
(_toastRef_current2 = toastRef.current) == null ? void 0 : _toastRef_current2.style.setProperty('--swipe-amount-x', `0px`);
|
|
700
|
+
(_toastRef_current3 = toastRef.current) == null ? void 0 : _toastRef_current3.style.setProperty('--swipe-amount-y', `0px`);
|
|
701
|
+
}
|
|
702
|
+
setSwiping(false);
|
|
703
|
+
setSwipeDirection(null);
|
|
704
|
+
},
|
|
705
|
+
onPointerMove: (event)=>{
|
|
706
|
+
var _window_getSelection, // Apply transform using both x and y values
|
|
707
|
+
_toastRef_current, _toastRef_current1;
|
|
708
|
+
if (!pointerStartRef.current || !dismissible) return;
|
|
709
|
+
const isHighlighted = ((_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString().length) > 0;
|
|
710
|
+
if (isHighlighted) return;
|
|
711
|
+
const yDelta = event.clientY - pointerStartRef.current.y;
|
|
712
|
+
const xDelta = event.clientX - pointerStartRef.current.x;
|
|
713
|
+
var _props_swipeDirections;
|
|
714
|
+
const swipeDirections = (_props_swipeDirections = props.swipeDirections) != null ? _props_swipeDirections : getDefaultSwipeDirections(position);
|
|
715
|
+
// Determine swipe direction if not already locked
|
|
716
|
+
if (!swipeDirection && (Math.abs(xDelta) > 1 || Math.abs(yDelta) > 1)) {
|
|
717
|
+
setSwipeDirection(Math.abs(xDelta) > Math.abs(yDelta) ? 'x' : 'y');
|
|
718
|
+
}
|
|
719
|
+
let swipeAmount = {
|
|
720
|
+
x: 0,
|
|
721
|
+
y: 0
|
|
722
|
+
};
|
|
723
|
+
// Only apply swipe in the locked direction
|
|
724
|
+
if (swipeDirection === 'y') {
|
|
725
|
+
// Handle vertical swipes
|
|
726
|
+
if (swipeDirections.includes('top') || swipeDirections.includes('bottom')) {
|
|
727
|
+
if (swipeDirections.includes('top') && yDelta < 0) {
|
|
728
|
+
swipeAmount.y = yDelta;
|
|
729
|
+
} else if (swipeDirections.includes('bottom') && yDelta > 0) {
|
|
730
|
+
swipeAmount.y = yDelta;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
} else if (swipeDirection === 'x') {
|
|
734
|
+
// Handle horizontal swipes
|
|
735
|
+
if (swipeDirections.includes('left') || swipeDirections.includes('right')) {
|
|
736
|
+
if (swipeDirections.includes('left') && xDelta < 0) {
|
|
737
|
+
swipeAmount.x = xDelta;
|
|
738
|
+
} else if (swipeDirections.includes('right') && xDelta > 0) {
|
|
739
|
+
swipeAmount.x = xDelta;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (Math.abs(swipeAmount.x) > 0 || Math.abs(swipeAmount.y) > 0) {
|
|
744
|
+
setIsSwiped(true);
|
|
745
|
+
}
|
|
746
|
+
(_toastRef_current = toastRef.current) == null ? void 0 : _toastRef_current.style.setProperty('--swipe-amount-x', `${swipeAmount.x}px`);
|
|
747
|
+
(_toastRef_current1 = toastRef.current) == null ? void 0 : _toastRef_current1.style.setProperty('--swipe-amount-y', `${swipeAmount.y}px`);
|
|
748
|
+
}
|
|
749
|
+
}, closeButton && !toast.jsx ? /*#__PURE__*/ React__default.default.createElement("button", {
|
|
750
|
+
"aria-label": closeButtonAriaLabel,
|
|
751
|
+
"data-disabled": disabled,
|
|
752
|
+
"data-close-button": true,
|
|
753
|
+
onClick: disabled || !dismissible ? ()=>{} : ()=>{
|
|
754
|
+
deleteToast();
|
|
755
|
+
toast.onDismiss == null ? void 0 : toast.onDismiss.call(toast, toast);
|
|
756
|
+
},
|
|
757
|
+
className: cn(classNames == null ? void 0 : classNames.closeButton, toast == null ? void 0 : (_toast_classNames2 = toast.classNames) == null ? void 0 : _toast_classNames2.closeButton)
|
|
758
|
+
}, (_icons_close = icons == null ? void 0 : icons.close) != null ? _icons_close : CloseIcon) : null, toastType || toast.icon || toast.promise ? /*#__PURE__*/ React__default.default.createElement("div", {
|
|
759
|
+
"data-icon": "",
|
|
760
|
+
className: cn(classNames == null ? void 0 : classNames.icon, toast == null ? void 0 : (_toast_classNames3 = toast.classNames) == null ? void 0 : _toast_classNames3.icon)
|
|
761
|
+
}, toast.promise || toast.type === 'loading' && !toast.icon ? toast.icon || getLoadingIcon() : null, toast.type !== 'loading' ? toast.icon || (icons == null ? void 0 : icons[toastType]) || getAsset(toastType) : null) : null, /*#__PURE__*/ React__default.default.createElement("div", {
|
|
762
|
+
"data-content": "",
|
|
763
|
+
className: cn(classNames == null ? void 0 : classNames.content, toast == null ? void 0 : (_toast_classNames4 = toast.classNames) == null ? void 0 : _toast_classNames4.content)
|
|
764
|
+
}, /*#__PURE__*/ React__default.default.createElement("div", {
|
|
765
|
+
"data-title": "",
|
|
766
|
+
className: cn(classNames == null ? void 0 : classNames.title, toast == null ? void 0 : (_toast_classNames5 = toast.classNames) == null ? void 0 : _toast_classNames5.title)
|
|
767
|
+
}, toast.jsx ? toast.jsx : typeof toast.title === 'function' ? toast.title() : toast.title), toast.description ? /*#__PURE__*/ React__default.default.createElement("div", {
|
|
768
|
+
"data-description": "",
|
|
769
|
+
className: cn(descriptionClassName, toastDescriptionClassname, classNames == null ? void 0 : classNames.description, toast == null ? void 0 : (_toast_classNames6 = toast.classNames) == null ? void 0 : _toast_classNames6.description)
|
|
770
|
+
}, typeof toast.description === 'function' ? toast.description() : toast.description) : null), /*#__PURE__*/ React__default.default.isValidElement(toast.cancel) ? toast.cancel : toast.cancel && isAction(toast.cancel) ? /*#__PURE__*/ React__default.default.createElement("button", {
|
|
771
|
+
"data-button": true,
|
|
772
|
+
"data-cancel": true,
|
|
773
|
+
style: toast.cancelButtonStyle || cancelButtonStyle,
|
|
774
|
+
onClick: (event)=>{
|
|
775
|
+
// We need to check twice because typescript
|
|
776
|
+
if (!isAction(toast.cancel)) return;
|
|
777
|
+
if (!dismissible) return;
|
|
778
|
+
toast.cancel.onClick == null ? void 0 : toast.cancel.onClick.call(toast.cancel, event);
|
|
779
|
+
deleteToast();
|
|
780
|
+
},
|
|
781
|
+
className: cn(classNames == null ? void 0 : classNames.cancelButton, toast == null ? void 0 : (_toast_classNames7 = toast.classNames) == null ? void 0 : _toast_classNames7.cancelButton)
|
|
782
|
+
}, toast.cancel.label) : null, /*#__PURE__*/ React__default.default.isValidElement(toast.action) ? toast.action : toast.action && isAction(toast.action) ? /*#__PURE__*/ React__default.default.createElement("button", {
|
|
783
|
+
"data-button": true,
|
|
784
|
+
"data-action": true,
|
|
785
|
+
style: toast.actionButtonStyle || actionButtonStyle,
|
|
786
|
+
onClick: (event)=>{
|
|
787
|
+
// We need to check twice because typescript
|
|
788
|
+
if (!isAction(toast.action)) return;
|
|
789
|
+
toast.action.onClick == null ? void 0 : toast.action.onClick.call(toast.action, event);
|
|
790
|
+
if (event.defaultPrevented) return;
|
|
791
|
+
deleteToast();
|
|
792
|
+
},
|
|
793
|
+
className: cn(classNames == null ? void 0 : classNames.actionButton, toast == null ? void 0 : (_toast_classNames8 = toast.classNames) == null ? void 0 : _toast_classNames8.actionButton)
|
|
794
|
+
}, toast.action.label) : null);
|
|
795
|
+
};
|
|
796
|
+
function getDocumentDirection() {
|
|
797
|
+
if (typeof window === 'undefined') return 'ltr';
|
|
798
|
+
if (typeof document === 'undefined') return 'ltr'; // For Fresh purpose
|
|
799
|
+
const dirAttribute = document.documentElement.getAttribute('dir');
|
|
800
|
+
if (dirAttribute === 'auto' || !dirAttribute) {
|
|
801
|
+
return window.getComputedStyle(document.documentElement).direction;
|
|
802
|
+
}
|
|
803
|
+
return dirAttribute;
|
|
804
|
+
}
|
|
805
|
+
function assignOffset(defaultOffset, mobileOffset) {
|
|
806
|
+
const styles = {};
|
|
807
|
+
[
|
|
808
|
+
defaultOffset,
|
|
809
|
+
mobileOffset
|
|
810
|
+
].forEach((offset, index)=>{
|
|
811
|
+
const isMobile = index === 1;
|
|
812
|
+
const prefix = isMobile ? '--mobile-offset' : '--offset';
|
|
813
|
+
const defaultValue = isMobile ? MOBILE_VIEWPORT_OFFSET : VIEWPORT_OFFSET;
|
|
814
|
+
function assignAll(offset) {
|
|
815
|
+
[
|
|
816
|
+
'top',
|
|
817
|
+
'right',
|
|
818
|
+
'bottom',
|
|
819
|
+
'left'
|
|
820
|
+
].forEach((key)=>{
|
|
821
|
+
styles[`${prefix}-${key}`] = typeof offset === 'number' ? `${offset}px` : offset;
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
if (typeof offset === 'number' || typeof offset === 'string') {
|
|
825
|
+
assignAll(offset);
|
|
826
|
+
} else if (typeof offset === 'object') {
|
|
827
|
+
[
|
|
828
|
+
'top',
|
|
829
|
+
'right',
|
|
830
|
+
'bottom',
|
|
831
|
+
'left'
|
|
832
|
+
].forEach((key)=>{
|
|
833
|
+
if (offset[key] === undefined) {
|
|
834
|
+
styles[`${prefix}-${key}`] = defaultValue;
|
|
835
|
+
} else {
|
|
836
|
+
styles[`${prefix}-${key}`] = typeof offset[key] === 'number' ? `${offset[key]}px` : offset[key];
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
} else {
|
|
840
|
+
assignAll(defaultValue);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
return styles;
|
|
844
|
+
}
|
|
845
|
+
function useSonner() {
|
|
846
|
+
const [activeToasts, setActiveToasts] = React__default.default.useState([]);
|
|
847
|
+
React__default.default.useEffect(()=>{
|
|
848
|
+
return ToastState.subscribe((toast)=>{
|
|
849
|
+
if (toast.dismiss) {
|
|
850
|
+
setTimeout(()=>{
|
|
851
|
+
ReactDOM__default.default.flushSync(()=>{
|
|
852
|
+
setActiveToasts((toasts)=>toasts.filter((t)=>t.id !== toast.id));
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
// Prevent batching, temp solution.
|
|
858
|
+
setTimeout(()=>{
|
|
859
|
+
ReactDOM__default.default.flushSync(()=>{
|
|
860
|
+
setActiveToasts((toasts)=>{
|
|
861
|
+
const indexOfExistingToast = toasts.findIndex((t)=>t.id === toast.id);
|
|
862
|
+
// Update the toast if it already exists
|
|
863
|
+
if (indexOfExistingToast !== -1) {
|
|
864
|
+
return [
|
|
865
|
+
...toasts.slice(0, indexOfExistingToast),
|
|
866
|
+
{
|
|
867
|
+
...toasts[indexOfExistingToast],
|
|
868
|
+
...toast
|
|
869
|
+
},
|
|
870
|
+
...toasts.slice(indexOfExistingToast + 1)
|
|
871
|
+
];
|
|
872
|
+
}
|
|
873
|
+
return [
|
|
874
|
+
toast,
|
|
875
|
+
...toasts
|
|
876
|
+
];
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
}, []);
|
|
882
|
+
return {
|
|
883
|
+
toasts: activeToasts
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
const Toaster = /*#__PURE__*/ React__default.default.forwardRef(function Toaster(props, ref) {
|
|
887
|
+
const { invert, position = 'bottom-right', hotkey = [
|
|
888
|
+
'altKey',
|
|
889
|
+
'KeyT'
|
|
890
|
+
], expand, closeButton, className, offset, mobileOffset, theme = 'light', richColors, duration, style, visibleToasts = VISIBLE_TOASTS_AMOUNT, toastOptions, dir = getDocumentDirection(), gap = GAP, loadingIcon, icons, containerAriaLabel = 'Notifications', pauseWhenPageIsHidden } = props;
|
|
891
|
+
const [toasts, setToasts] = React__default.default.useState([]);
|
|
892
|
+
const possiblePositions = React__default.default.useMemo(()=>{
|
|
893
|
+
return Array.from(new Set([
|
|
894
|
+
position
|
|
895
|
+
].concat(toasts.filter((toast)=>toast.position).map((toast)=>toast.position))));
|
|
896
|
+
}, [
|
|
897
|
+
toasts,
|
|
898
|
+
position
|
|
899
|
+
]);
|
|
900
|
+
const [heights, setHeights] = React__default.default.useState([]);
|
|
901
|
+
const [expanded, setExpanded] = React__default.default.useState(false);
|
|
902
|
+
const [interacting, setInteracting] = React__default.default.useState(false);
|
|
903
|
+
const [actualTheme, setActualTheme] = React__default.default.useState(theme !== 'system' ? theme : typeof window !== 'undefined' ? window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' : 'light');
|
|
904
|
+
const listRef = React__default.default.useRef(null);
|
|
905
|
+
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
|
|
906
|
+
const lastFocusedElementRef = React__default.default.useRef(null);
|
|
907
|
+
const isFocusWithinRef = React__default.default.useRef(false);
|
|
908
|
+
const removeToast = React__default.default.useCallback((toastToRemove)=>{
|
|
909
|
+
setToasts((toasts)=>{
|
|
910
|
+
var _toasts_find;
|
|
911
|
+
if (!((_toasts_find = toasts.find((toast)=>toast.id === toastToRemove.id)) == null ? void 0 : _toasts_find.delete)) {
|
|
912
|
+
ToastState.dismiss(toastToRemove.id);
|
|
913
|
+
}
|
|
914
|
+
return toasts.filter(({ id })=>id !== toastToRemove.id);
|
|
915
|
+
});
|
|
916
|
+
}, []);
|
|
917
|
+
React__default.default.useEffect(()=>{
|
|
918
|
+
return ToastState.subscribe((toast)=>{
|
|
919
|
+
if (toast.dismiss) {
|
|
920
|
+
const map = toasts.map((t)=>t.id === toast.id ? {
|
|
921
|
+
...t,
|
|
922
|
+
delete: true
|
|
923
|
+
} : t);
|
|
924
|
+
// Prevent batching of other state updates
|
|
925
|
+
requestAnimationFrame(()=>{
|
|
926
|
+
setToasts(map);
|
|
927
|
+
});
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
// Prevent batching, temp solution.
|
|
931
|
+
ReactDOM__default.default.flushSync(()=>{
|
|
932
|
+
setToasts((toasts)=>{
|
|
933
|
+
const indexOfExistingToast = toasts.findIndex((t)=>t.id === toast.id);
|
|
934
|
+
// Update the toast if it already exists
|
|
935
|
+
if (indexOfExistingToast !== -1) {
|
|
936
|
+
return [
|
|
937
|
+
...toasts.slice(0, indexOfExistingToast),
|
|
938
|
+
{
|
|
939
|
+
...toasts[indexOfExistingToast],
|
|
940
|
+
...toast
|
|
941
|
+
},
|
|
942
|
+
...toasts.slice(indexOfExistingToast + 1)
|
|
943
|
+
];
|
|
944
|
+
}
|
|
945
|
+
return [
|
|
946
|
+
toast,
|
|
947
|
+
...toasts
|
|
948
|
+
];
|
|
949
|
+
});
|
|
950
|
+
});
|
|
951
|
+
});
|
|
952
|
+
}, [
|
|
953
|
+
toasts
|
|
954
|
+
]);
|
|
955
|
+
React__default.default.useEffect(()=>{
|
|
956
|
+
if (theme !== 'system') {
|
|
957
|
+
setActualTheme(theme);
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
if (theme === 'system') {
|
|
961
|
+
// check if current preference is dark
|
|
962
|
+
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
963
|
+
// it's currently dark
|
|
964
|
+
setActualTheme('dark');
|
|
965
|
+
} else {
|
|
966
|
+
// it's not dark
|
|
967
|
+
setActualTheme('light');
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (typeof window === 'undefined') return;
|
|
971
|
+
const darkMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
972
|
+
try {
|
|
973
|
+
// Chrome & Firefox
|
|
974
|
+
darkMediaQuery.addEventListener('change', ({ matches })=>{
|
|
975
|
+
if (matches) {
|
|
976
|
+
setActualTheme('dark');
|
|
977
|
+
} else {
|
|
978
|
+
setActualTheme('light');
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
} catch (error) {
|
|
982
|
+
// Safari < 14
|
|
983
|
+
darkMediaQuery.addListener(({ matches })=>{
|
|
984
|
+
try {
|
|
985
|
+
if (matches) {
|
|
986
|
+
setActualTheme('dark');
|
|
987
|
+
} else {
|
|
988
|
+
setActualTheme('light');
|
|
989
|
+
}
|
|
990
|
+
} catch (e) {
|
|
991
|
+
console.error(e);
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
}, [
|
|
996
|
+
theme
|
|
997
|
+
]);
|
|
998
|
+
React__default.default.useEffect(()=>{
|
|
999
|
+
// Ensure expanded is always false when no toasts are present / only one left
|
|
1000
|
+
if (toasts.length <= 1) {
|
|
1001
|
+
setExpanded(false);
|
|
1002
|
+
}
|
|
1003
|
+
}, [
|
|
1004
|
+
toasts
|
|
1005
|
+
]);
|
|
1006
|
+
React__default.default.useEffect(()=>{
|
|
1007
|
+
const handleKeyDown = (event)=>{
|
|
1008
|
+
var _listRef_current;
|
|
1009
|
+
const isHotkeyPressed = hotkey.every((key)=>event[key] || event.code === key);
|
|
1010
|
+
if (isHotkeyPressed) {
|
|
1011
|
+
var _listRef_current1;
|
|
1012
|
+
setExpanded(true);
|
|
1013
|
+
(_listRef_current1 = listRef.current) == null ? void 0 : _listRef_current1.focus();
|
|
1014
|
+
}
|
|
1015
|
+
if (event.code === 'Escape' && (document.activeElement === listRef.current || ((_listRef_current = listRef.current) == null ? void 0 : _listRef_current.contains(document.activeElement)))) {
|
|
1016
|
+
setExpanded(false);
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
1020
|
+
return ()=>document.removeEventListener('keydown', handleKeyDown);
|
|
1021
|
+
}, [
|
|
1022
|
+
hotkey
|
|
1023
|
+
]);
|
|
1024
|
+
React__default.default.useEffect(()=>{
|
|
1025
|
+
if (listRef.current) {
|
|
1026
|
+
return ()=>{
|
|
1027
|
+
if (lastFocusedElementRef.current) {
|
|
1028
|
+
lastFocusedElementRef.current.focus({
|
|
1029
|
+
preventScroll: true
|
|
1030
|
+
});
|
|
1031
|
+
lastFocusedElementRef.current = null;
|
|
1032
|
+
isFocusWithinRef.current = false;
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
}, [
|
|
1037
|
+
listRef.current
|
|
1038
|
+
]);
|
|
1039
|
+
return(// Remove item from normal navigation flow, only available via hotkey
|
|
1040
|
+
/*#__PURE__*/ React__default.default.createElement("section", {
|
|
1041
|
+
ref: ref,
|
|
1042
|
+
"aria-label": `${containerAriaLabel} ${hotkeyLabel}`,
|
|
1043
|
+
tabIndex: -1,
|
|
1044
|
+
"aria-live": "polite",
|
|
1045
|
+
"aria-relevant": "additions text",
|
|
1046
|
+
"aria-atomic": "false",
|
|
1047
|
+
suppressHydrationWarning: true
|
|
1048
|
+
}, possiblePositions.map((position, index)=>{
|
|
1049
|
+
var _heights_;
|
|
1050
|
+
const [y, x] = position.split('-');
|
|
1051
|
+
if (!toasts.length) return null;
|
|
1052
|
+
return /*#__PURE__*/ React__default.default.createElement("ol", {
|
|
1053
|
+
key: position,
|
|
1054
|
+
dir: dir === 'auto' ? getDocumentDirection() : dir,
|
|
1055
|
+
tabIndex: -1,
|
|
1056
|
+
ref: listRef,
|
|
1057
|
+
className: className,
|
|
1058
|
+
"data-sonner-toaster": true,
|
|
1059
|
+
"data-sonner-theme": actualTheme,
|
|
1060
|
+
"data-y-position": y,
|
|
1061
|
+
"data-lifted": expanded && toasts.length > 1 && !expand,
|
|
1062
|
+
"data-x-position": x,
|
|
1063
|
+
style: {
|
|
1064
|
+
'--front-toast-height': `${((_heights_ = heights[0]) == null ? void 0 : _heights_.height) || 0}px`,
|
|
1065
|
+
'--width': `${TOAST_WIDTH}px`,
|
|
1066
|
+
'--gap': `${gap}px`,
|
|
1067
|
+
...style,
|
|
1068
|
+
...assignOffset(offset, mobileOffset)
|
|
1069
|
+
},
|
|
1070
|
+
onBlur: (event)=>{
|
|
1071
|
+
if (isFocusWithinRef.current && !event.currentTarget.contains(event.relatedTarget)) {
|
|
1072
|
+
isFocusWithinRef.current = false;
|
|
1073
|
+
if (lastFocusedElementRef.current) {
|
|
1074
|
+
lastFocusedElementRef.current.focus({
|
|
1075
|
+
preventScroll: true
|
|
1076
|
+
});
|
|
1077
|
+
lastFocusedElementRef.current = null;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
onFocus: (event)=>{
|
|
1082
|
+
const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === 'false';
|
|
1083
|
+
if (isNotDismissible) return;
|
|
1084
|
+
if (!isFocusWithinRef.current) {
|
|
1085
|
+
isFocusWithinRef.current = true;
|
|
1086
|
+
lastFocusedElementRef.current = event.relatedTarget;
|
|
1087
|
+
}
|
|
1088
|
+
},
|
|
1089
|
+
onMouseEnter: ()=>setExpanded(true),
|
|
1090
|
+
onMouseMove: ()=>setExpanded(true),
|
|
1091
|
+
onMouseLeave: ()=>{
|
|
1092
|
+
// Avoid setting expanded to false when interacting with a toast, e.g. swiping
|
|
1093
|
+
if (!interacting) {
|
|
1094
|
+
setExpanded(false);
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
onDragEnd: ()=>setExpanded(false),
|
|
1098
|
+
onPointerDown: (event)=>{
|
|
1099
|
+
const isNotDismissible = event.target instanceof HTMLElement && event.target.dataset.dismissible === 'false';
|
|
1100
|
+
if (isNotDismissible) return;
|
|
1101
|
+
setInteracting(true);
|
|
1102
|
+
},
|
|
1103
|
+
onPointerUp: ()=>setInteracting(false)
|
|
1104
|
+
}, toasts.filter((toast)=>!toast.position && index === 0 || toast.position === position).map((toast, index)=>{
|
|
1105
|
+
var _toastOptions_duration, _toastOptions_closeButton;
|
|
1106
|
+
return /*#__PURE__*/ React__default.default.createElement(Toast, {
|
|
1107
|
+
key: toast.id,
|
|
1108
|
+
icons: icons,
|
|
1109
|
+
index: index,
|
|
1110
|
+
toast: toast,
|
|
1111
|
+
defaultRichColors: richColors,
|
|
1112
|
+
duration: (_toastOptions_duration = toastOptions == null ? void 0 : toastOptions.duration) != null ? _toastOptions_duration : duration,
|
|
1113
|
+
className: toastOptions == null ? void 0 : toastOptions.className,
|
|
1114
|
+
descriptionClassName: toastOptions == null ? void 0 : toastOptions.descriptionClassName,
|
|
1115
|
+
invert: invert,
|
|
1116
|
+
visibleToasts: visibleToasts,
|
|
1117
|
+
closeButton: (_toastOptions_closeButton = toastOptions == null ? void 0 : toastOptions.closeButton) != null ? _toastOptions_closeButton : closeButton,
|
|
1118
|
+
interacting: interacting,
|
|
1119
|
+
position: position,
|
|
1120
|
+
style: toastOptions == null ? void 0 : toastOptions.style,
|
|
1121
|
+
unstyled: toastOptions == null ? void 0 : toastOptions.unstyled,
|
|
1122
|
+
classNames: toastOptions == null ? void 0 : toastOptions.classNames,
|
|
1123
|
+
cancelButtonStyle: toastOptions == null ? void 0 : toastOptions.cancelButtonStyle,
|
|
1124
|
+
actionButtonStyle: toastOptions == null ? void 0 : toastOptions.actionButtonStyle,
|
|
1125
|
+
removeToast: removeToast,
|
|
1126
|
+
toasts: toasts.filter((t)=>t.position == toast.position),
|
|
1127
|
+
heights: heights.filter((h)=>h.position == toast.position),
|
|
1128
|
+
setHeights: setHeights,
|
|
1129
|
+
expandByDefault: expand,
|
|
1130
|
+
gap: gap,
|
|
1131
|
+
loadingIcon: loadingIcon,
|
|
1132
|
+
expanded: expanded,
|
|
1133
|
+
pauseWhenPageIsHidden: pauseWhenPageIsHidden,
|
|
1134
|
+
swipeDirections: props.swipeDirections
|
|
1135
|
+
});
|
|
1136
|
+
}));
|
|
1137
|
+
})));
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
exports.Toaster = Toaster;
|
|
1141
|
+
exports.toast = toast;
|
|
1142
|
+
exports.useSonner = useSonner;
|