@trycourier/courier-ui-toast 2.2.1 → 2.3.0
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.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +13 -3
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@trycourier/courier-ui-core"),require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-ui-core","@trycourier/courier-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CourierUIToast={},t.CourierUICore,t.CourierJS)}(this,(function(t,e,s){"use strict";var i=Object.defineProperty,o=(t,e,s)=>((t,e,s)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);const n={item:{backgroundColor:e.CourierColors.white[500],hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],shadow:`0px 4px 8px -2px ${e.CourierColors.black[50020]}`,border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.black[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[600]},icon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400],actions:{backgroundColor:"transparent",hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:e.CourierColors.black[500],size:"14px"}}}},r={item:{backgroundColor:e.CourierColors.black[500],hoverBackgroundColor:e.CourierColors.gray[800],activeBackgroundColor:e.CourierColors.gray[700],shadow:`0px 4px 8px -2px ${e.CourierColors.gray[400]}`,border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.white[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[500]},icon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400],actions:{backgroundColor:e.CourierColors.black[400],hoverBackgroundColor:e.CourierColors.white[50010],activeBackgroundColor:e.CourierColors.white[50020],border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${e.CourierColors.white[50010]}`,font:{color:e.CourierColors.white[500],size:"14px"}}}},a=(t,e)=>{var s,i,o,a,l,d,u,h;const m="light"===t?n:r;return{item:{...m.item,...e.item,title:{...null==(s=m.item)?void 0:s.title,...null==(i=e.item)?void 0:i.title},body:{...null==(o=m.item)?void 0:o.body,...null==(a=e.item)?void 0:a.body},icon:{...null==(l=m.item)?void 0:l.icon,...null==(d=e.item)?void 0:d.icon},dismissIcon:{...null==(u=m.item)?void 0:u.dismissIcon,...null==(h=e.item)?void 0:h.dismissIcon}}}};class l extends e.CourierThemeManager{constructor(t){super(t),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return r}mergeTheme(t,e){return a(t,e)}subscribe(t){return{...super.subscribe(t),manager:this}}}class d{constructor(t,e){o(this,"_callback"),o(this,"_remainingMs"),o(this,"_timerId",null),o(this,"_startedAt",0),o(this,"_isPaused",!1),o(this,"_isDone",!1),this._callback=t,this._remainingMs=e}get isPaused(){return this._isPaused}start(){this._isDone||(this.clear(),this._isPaused=!1,this._startedAt=Date.now(),this._timerId=setTimeout((()=>{this._timerId=null,this._isDone=!0,this._callback()}),this._remainingMs))}pause(){this._isDone||this._isPaused||null===this._timerId||(this._remainingMs=Math.max(0,this._remainingMs-(Date.now()-this._startedAt)),this._isPaused=!0,this.clear())}resume(){!this._isDone&&this._isPaused&&this.start()}cancel(){this._isPaused=!1,this._isDone=!0,this.clear()}clear(){null!==this._timerId&&(clearTimeout(this._timerId),this._timerId=null)}}const u=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_message"),o(this,"_customToastItemContent"),o(this,"_autoDismiss"),o(this,"_autoDismissTimeoutMs"),o(this,"_autoDismissTimeout",null),o(this,"_autoDismissBar",null),o(this,"_onItemDismissedCallback",null),o(this,"_onToastItemClickCallback",null),o(this,"_onToastItemActionClickCallback",null),this._message=t.message,this._autoDismiss=t.autoDismiss,this._autoDismissTimeoutMs=t.autoDismissTimeoutMs,this._themeManager=t.themeManager,this._themeSubscription=this._themeManager.subscribe((t=>{this.render()}))}onItemDismissed(t){this._onItemDismissedCallback=t}onToastItemClick(t){this._onToastItemClickCallback=t,this.render()}onToastItemActionClick(t){this._onToastItemActionClickCallback=t,this.render()}setToastItemContent(t){this._customToastItemContent=t}dismiss(e=t.dismissAnimationTimeoutMs){var s;null==(s=this._autoDismissTimeout)||s.cancel(),this.classList.add("dismissing"),setTimeout((()=>{this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})}),e)}pauseAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.pause(),this.syncAutoDismissBarPlayState()}resumeAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.resume(),this.syncAutoDismissBarPlayState()}syncAutoDismissBarPlayState(){var t;this._autoDismissBar&&(this._autoDismissBar.style.animationPlayState=(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)?"paused":"running")}onComponentMounted(){this.render(),this._autoDismiss&&(this._autoDismissTimeout=new d((()=>this.dismiss()),this._autoDismissTimeoutMs),this._autoDismissTimeout.start())}onComponentUnmounted(){var t;this._themeSubscription.unsubscribe(),null==(t=this._autoDismissTimeout)||t.cancel()}get theme(){return this._themeManager.getTheme()}static get id(){return"courier-toast-item"}static get observedAttributes(){return[]}render(){for(var t,s,i,o,n;this.firstChild;)this.removeChild(this.firstChild);this.removeEventListener("click",this.onClick);const r=document.createElement("div");if(r.classList.add("overflow-hidden-container"),this.appendChild(r),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)&&(e.style.animationPlayState="paused"),r.append(e),this._autoDismissBar=e}this._customToastItemContent?r.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):r.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const a=new e.CourierIcon(null==(i=null==(s=this.theme.item)?void 0:s.dismissIcon)?void 0:i.color,null==(n=null==(o=this.theme.item)?void 0:o.dismissIcon)?void 0:n.svg);a.classList.add("dismiss"),a.addEventListener("click",(t=>{t.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(a)}createDefaultContent(){var t,s;const i=document.createElement("div");i.classList.add("content"),this.append(i);const o=null==(t=this.theme.item)?void 0:t.icon;if(!1!==(null==o?void 0:o.visible)){const t=new e.CourierIcon(null==o?void 0:o.color,null==o?void 0:o.svg);t.classList.add("icon"),i.appendChild(t)}const n=document.createElement("div");n.classList.add("text-content"),i.appendChild(n);const r=document.createElement("p");r.classList.add("title"),r.textContent=this._message.title??"",n.appendChild(r);const a=document.createElement("p");if(a.classList.add("body"),a.textContent=this._message.preview??this._message.body??"",n.appendChild(a),this.messageHasActions){const t=document.createElement("div");t.classList.add("actions-container"),n.appendChild(t),null==(s=this._message.actions)||s.forEach((e=>{const s=this.createActionButton(e);t.appendChild(s)}))}return i}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(t){var s,i,o,n,r;const a=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new e.CourierButton({mode:this._themeManager.mode,text:t.content,variant:"secondary",backgroundColor:null==a?void 0:a.backgroundColor,hoverBackgroundColor:null==a?void 0:a.hoverBackgroundColor,activeBackgroundColor:null==a?void 0:a.activeBackgroundColor,border:null==a?void 0:a.border,borderRadius:null==a?void 0:a.borderRadius,shadow:null==a?void 0:a.shadow,fontFamily:null==(i=null==a?void 0:a.font)?void 0:i.family,fontSize:null==(o=null==a?void 0:a.font)?void 0:o.size,fontWeight:null==(n=null==a?void 0:a.font)?void 0:n.weight,textColor:null==(r=null==a?void 0:a.font)?void 0:r.color,onClick:()=>{this._onToastItemActionClickCallback&&this._onToastItemActionClickCallback({message:this._message,action:t})}})}onClick(t){t.stopPropagation(),this._onToastItemClickCallback&&this._onToastItemClickCallback({message:this._message})}};o(u,"dismissAnimationTimeoutMs",300);let h=u;e.registerElement(h);const m=class t{constructor(){o(this,"_dataset",[]),o(this,"_datastoreListeners",[]),o(this,"_removeMessageEventListener")}static get shared(){return t.instance||(t.instance=new t),t.instance}addDatastoreListener(t){this._datastoreListeners.push(t)}removeDatastoreListener(t){this._datastoreListeners=this._datastoreListeners.filter((e=>e!==t))}async listenForMessages(){var t,e,i,o,n,r,a;try{const a=null==(t=s.Courier.shared.client)?void 0:t.inbox.socket;if(!a)return void(null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)||i.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=a.addMessageEventListener((t=>{if(t.event===s.InboxMessageEvent.NewMessage){const e=t.data;this.addMessage(e)}})),a.isConnecting||a.isOpen)return void(null==(r=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||r.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await a.connect()}catch(l){null==(a=s.Courier.shared.client)||a.options.logger.error("Error listening for messages:",l),this._datastoreListeners.forEach((t=>{var e,s;null==(s=(e=t.events).onError)||s.call(e,l)}))}}toastIndexOfMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));return e<0?e:this._dataset.length-e-1}addMessage(t){this._dataset.push(t),this._datastoreListeners.forEach((e=>{e.events.onMessageAdd&&e.events.onMessageAdd(t)}))}removeMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));e<0||(this._dataset.splice(e,1),this._datastoreListeners.forEach((e=>{e.events.onMessageRemove&&e.events.onMessageRemove(t)})))}};o(m,"instance");let c=m;class g{constructor(t){this.events=t}remove(){c.shared.removeDatastoreListener(this)}}const C=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_toastStyle"),o(this,"_authListener"),o(this,"_datastoreListener"),o(this,"_isHovered",!1),o(this,"_customItemAutoDismissTimeouts",new WeakMap),o(this,"_autoDismiss",!1),o(this,"_autoDismissTimeoutMs",5e3),o(this,"_dismissButtonOption","auto"),o(this,"_customToastItem"),o(this,"_customToastItemContent"),o(this,"_onItemClick"),o(this,"_onItemActionClick"),o(this,"_defaultLayoutProps",{position:"fixed",width:"380px",top:"30px",right:"30px",zIndex:999}),o(this,"onMouseEnter",(()=>{this._isHovered=!0,this.refreshAutoDismissCountdowns()})),o(this,"onMouseLeave",(()=>{this._isHovered=!1,this.refreshAutoDismissCountdowns()})),this._themeManager=(null==t?void 0:t.themeManager)??new l(n),this._themeSubscription=this._themeManager.subscribe((t=>{this.refreshStyles()})),this._datastoreListener=new g({onMessageAdd:this.datastoreAddMessageListener.bind(this),onMessageRemove:this.datastoreRemoveMessageListener.bind(this)})}onToastItemClick(t){this._onItemClick=t}onToastItemActionClick(t){this._onItemActionClick=t}enableAutoDismiss(){this._autoDismiss=!0}disableAutoDismiss(){this._autoDismiss=!1}setAutoDismissTimeoutMs(t){this._autoDismissTimeoutMs=t}setLightTheme(t){this._themeManager.setLightTheme(t)}setDarkTheme(t){this._themeManager.setDarkTheme(t)}setDismissButton(t){this._dismissButtonOption=t,this.refreshStyles()}setMode(t){this._themeManager.setMode(t)}setToastItem(t){this._customToastItem=t}setToastItemContent(t){this._customToastItemContent=t}dismissToastForMessage(t){this.childNodes.forEach((e=>{var s;e.dataset.courierMessageId===t.messageId&&(e instanceof h?e.dismiss():(null==(s=this._customItemAutoDismissTimeouts.get(e))||s.cancel(),e.remove(),this.refreshAutoDismissCountdowns()))}))}onComponentMounted(){this._toastStyle=e.injectGlobalStyle(t.id,this.getStyles(this.theme)),this.addEventListener("mouseenter",this.onMouseEnter),this.addEventListener("mouseleave",this.onMouseLeave),c.shared.addDatastoreListener(this._datastoreListener),s.Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this)),c.shared.listenForMessages()}onComponentUnmounted(){var t,e;this.removeEventListener("mouseenter",this.onMouseEnter),this.removeEventListener("mouseleave",this.onMouseLeave),this._datastoreListener.remove(),null==(t=this._authListener)||t.remove(),null==(e=this._toastStyle)||e.remove(),this._themeManager.cleanup(),this._themeSubscription.unsubscribe()}refreshAutoDismissCountdowns(){const t=Array.from(this.children),e=t[t.length-1];t.forEach((t=>{this.setItemAutoDismissPaused(t,this._isHovered||t!==e)}))}setItemAutoDismissPaused(t,e){if(t instanceof h)return void(e?t.pauseAutoDismiss():t.resumeAutoDismiss());const s=this._customItemAutoDismissTimeouts.get(t);e?null==s||s.pause():null==s||s.resume()}attributeChangedCallback(e,s,i){switch(e){case"auto-dismiss":"false"===i?this.disableAutoDismiss():this.enableAutoDismiss();break;case"auto-dismiss-timeout-ms":this.setAutoDismissTimeoutMs(parseInt(i,10));break;case"dismiss-button":i&&t.isDismissButtonOption(i)?this.setDismissButton(i):this.setDismissButton("auto");break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}get theme(){return this._themeManager.getTheme()}refreshStyles(){this._toastStyle&&(this._toastStyle.textContent=this.getStyles(this.theme))}authChangedCallback(){this.removeAllItems(),c.shared.listenForMessages()}removeAllItems(){for(var t;this.firstChild;)null==(t=this._customItemAutoDismissTimeouts.get(this.firstChild))||t.cancel(),this.removeChild(this.firstChild)}addToastItem(t){const e=this.createToastItem(t);return e.dataset.courierMessageId=t.messageId,this.appendChild(e),this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns(),e}createToastItem(t){return this._customToastItem?this.createCustomToastItem(t):this.createDefaultToastItem(t)}createDefaultToastItem(t){const e=new h({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs,themeManager:this._themeManager});return e.onItemDismissed((t=>{this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns()})),this._customToastItemContent&&e.setToastItemContent(this._customToastItemContent),this._onItemClick&&e.onToastItemClick(this._onItemClick),this._onItemActionClick&&e.onToastItemActionClick(this._onItemActionClick),e}createCustomToastItem(t){if(!this._customToastItem)throw Error("Attempted to create customToastItem, but none is set");const e=this._customToastItem({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs});if(this._autoDismiss){const t=new d((()=>{e.remove(),this.refreshAutoDismissCountdowns()}),this._autoDismissTimeoutMs);this._customItemAutoDismissTimeouts.set(e,t),t.start()}return e.addEventListener("click",(()=>{this._onItemClick&&this._onItemClick({message:t})})),e}datastoreAddMessageListener(t){this.addToastItem(t)}datastoreRemoveMessageListener(t){this.dismissToastForMessage(t)}getStyles(e){var s,i,o,n,r,a;const l=e.item;return[`\n ${t.id} {\n position: ${this._defaultLayoutProps.position};\n z-index: ${this._defaultLayoutProps.zIndex};\n top: ${this._defaultLayoutProps.top};\n right: ${this._defaultLayoutProps.right};\n width: ${this._defaultLayoutProps.width};\n }\n `,`\n ${h.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${h.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${h.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${h.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${h.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `,`\n ${h.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${null==l?void 0:l.backgroundColor};\n box-shadow: ${null==l?void 0:l.shadow};\n border: ${null==l?void 0:l.border};\n border-radius: ${null==l?void 0:l.borderRadius};\n transition: 0.2s ease-in-out;\n cursor: default;\n\n opacity: 0;\n transform: translate(0, -10px) scaleX(var(--scale, 1));\n animation: courier-toast-show 0.3s ease-in-out forwards;\n }\n\n ${h.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${null==l?void 0:l.borderRadius};\n overflow: hidden;\n }\n\n ${h.id}.dismissing {\n animation: courier-toast-hide 300ms ease-out forwards;\n }\n\n @keyframes courier-toast-show {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n /* Lift the toast back out the way it came in rather than blinking it out\n in place, which reads as the toast leaving instead of vanishing. The\n toast is anchored to the top of the viewport, so "out" is up: a full\n translateY of its own height, eased so most of the travel happens\n early and the tail is imperceptible. */\n /* Shrink the toast slightly as it fades so it reads as receding rather\n than blinking out, but keep it where it sits — moving it competes with\n the toast underneath sliding up to take its place. The stack's own\n horizontal scale is preserved so a toast dismissed from behind the top\n one doesn't jump to full width on its way out. */\n @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scale(1) scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scale(0.92) scaleX(var(--scale, 1));\n }\n }\n\n ${h.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${h.id}.clickable:last-child:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id}.clickable:last-child:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `,`\n ${h.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${null==l?void 0:l.backgroundColor};\n border: ${null==l?void 0:l.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${null==l?void 0:l.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${h.id} > .dismiss:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id} > .dismiss:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}:last-child${this.showDismissOnHover?":hover":""} > .dismiss {\n visibility: ${this.showDismiss?"visible":"hidden"};\n opacity: 100%;\n transition: 0.2s ease-in-out;\n }\n `,`\n ${h.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${null==l?void 0:l.autoDismissBarColor};\n animation: courier-toast-auto-dismiss ${this._autoDismissTimeoutMs}ms linear forwards;\n }\n\n @keyframes courier-toast-auto-dismiss {\n 100% {\n width: 0px;\n }\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content {\n display: flex;\n gap: 12px;\n align-items: center;\n align-self: stretch;\n box-sizing: border-box;\n padding: 12px;\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n /* Keep room for the dismiss button, which overhangs this corner. */\n padding-right: 16px;\n font-weight: ${null==(s=null==l?void 0:l.title)?void 0:s.weight};\n font-size: ${null==(i=null==l?void 0:l.title)?void 0:i.size};\n color: ${null==(o=null==l?void 0:l.title)?void 0:o.color};\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${null==(n=null==l?void 0:l.body)?void 0:n.weight};\n font-size: ${null==(r=null==l?void 0:l.body)?void 0:r.size};\n line-height: 150%;\n color: ${null==(a=null==l?void 0:l.body)?void 0:a.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `].join("")}get topStackItemHeight(){if(this.lastChild){return`${this.lastChild.getBoundingClientRect().height}px`}return"0px"}resizeContainerToHeight(t){this.style.height=t}get showDismissOnHover(){return!(!this._autoDismiss||"auto"!==this._dismissButtonOption)||"hover"===this._dismissButtonOption}get showDismiss(){return"hidden"!==this._dismissButtonOption}static get id(){return"courier-toast"}static isDismissButtonOption(t){return["visible","hidden","hover","auto"].includes(t)}};o(C,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let v=C;e.registerElement(v);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.2.1",Object.defineProperty(t,"Courier",{enumerable:!0,get:()=>s.Courier}),Object.defineProperty(t,"DEFAULT_COURIER_API_URLS",{enumerable:!0,get:()=>s.DEFAULT_COURIER_API_URLS}),Object.defineProperty(t,"EU_COURIER_API_URLS",{enumerable:!0,get:()=>s.EU_COURIER_API_URLS}),Object.defineProperty(t,"getCourierApiUrls",{enumerable:!0,get:()=>s.getCourierApiUrls}),Object.defineProperty(t,"getCourierApiUrlsForRegion",{enumerable:!0,get:()=>s.getCourierApiUrlsForRegion}),t.CourierToast=v,t.CourierToastDatastore=c,t.CourierToastDatastoreEvents=class{onMessageAdd(t){}onMessageRemove(t){}onError(t){}},t.CourierToastDatastoreListener=g,t.CourierToastItem=h,t.CourierToastThemeManager=l,t.defaultDarkTheme=r,t.defaultLightTheme=n,t.mergeTheme=a,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@trycourier/courier-ui-core"),require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-ui-core","@trycourier/courier-js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CourierUIToast={},t.CourierUICore,t.CourierJS)}(this,(function(t,e,s){"use strict";var i=Object.defineProperty,o=(t,e,s)=>((t,e,s)=>e in t?i(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s);const n={item:{backgroundColor:e.CourierColors.white[500],hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],shadow:`0px 4px 8px -2px ${e.CourierColors.black[50020]}`,border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.black[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[600]},icon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.black[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400],actions:{backgroundColor:"transparent",hoverBackgroundColor:e.CourierColors.gray[200],activeBackgroundColor:e.CourierColors.gray[500],border:`1px solid ${e.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:e.CourierColors.black[500],size:"14px"}}}},r={item:{backgroundColor:e.CourierColors.black[500],hoverBackgroundColor:e.CourierColors.gray[800],activeBackgroundColor:e.CourierColors.gray[700],shadow:`0px 4px 8px -2px ${e.CourierColors.gray[400]}`,border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"8px",title:{size:"11pt",weight:"400",color:e.CourierColors.white[500]},body:{size:"11pt",weight:"400",color:e.CourierColors.gray[500]},icon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.inbox},dismissIcon:{color:e.CourierColors.white[500],svg:e.CourierIconSVGs.remove},autoDismissBarColor:e.CourierColors.blue[400],actions:{backgroundColor:e.CourierColors.black[400],hoverBackgroundColor:e.CourierColors.white[50010],activeBackgroundColor:e.CourierColors.white[50020],border:`1px solid ${e.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${e.CourierColors.white[50010]}`,font:{color:e.CourierColors.white[500],size:"14px"}}}},a=(t,e)=>{var s,i,o,a,l,d,u,h;const m="light"===t?n:r;return{item:{...m.item,...e.item,title:{...null==(s=m.item)?void 0:s.title,...null==(i=e.item)?void 0:i.title},body:{...null==(o=m.item)?void 0:o.body,...null==(a=e.item)?void 0:a.body},icon:{...null==(l=m.item)?void 0:l.icon,...null==(d=e.item)?void 0:d.icon},dismissIcon:{...null==(u=m.item)?void 0:u.dismissIcon,...null==(h=e.item)?void 0:h.dismissIcon}}}};class l extends e.CourierThemeManager{constructor(t){super(t),o(this,"THEME_CHANGE_EVENT","courier_toast_theme_change")}getDefaultLightTheme(){return n}getDefaultDarkTheme(){return r}mergeTheme(t,e){return a(t,e)}subscribe(t){return{...super.subscribe(t),manager:this}}}class d{constructor(t,e){o(this,"_callback"),o(this,"_remainingMs"),o(this,"_timerId",null),o(this,"_startedAt",0),o(this,"_isPaused",!1),o(this,"_isDone",!1),this._callback=t,this._remainingMs=e}get isPaused(){return this._isPaused}start(){this._isDone||(this.clear(),this._isPaused=!1,this._startedAt=Date.now(),this._timerId=setTimeout((()=>{this._timerId=null,this._isDone=!0,this._callback()}),this._remainingMs))}pause(){this._isDone||this._isPaused||null===this._timerId||(this._remainingMs=Math.max(0,this._remainingMs-(Date.now()-this._startedAt)),this._isPaused=!0,this.clear())}resume(){!this._isDone&&this._isPaused&&this.start()}cancel(){this._isPaused=!1,this._isDone=!0,this.clear()}clear(){null!==this._timerId&&(clearTimeout(this._timerId),this._timerId=null)}}const u=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_message"),o(this,"_customToastItemContent"),o(this,"_autoDismiss"),o(this,"_autoDismissTimeoutMs"),o(this,"_autoDismissTimeout",null),o(this,"_autoDismissBar",null),o(this,"_onItemDismissedCallback",null),o(this,"_onToastItemClickCallback",null),o(this,"_onToastItemActionClickCallback",null),this._message=t.message,this._autoDismiss=t.autoDismiss,this._autoDismissTimeoutMs=t.autoDismissTimeoutMs,this._themeManager=t.themeManager,this._themeSubscription=this._themeManager.subscribe((t=>{this.render()}))}onItemDismissed(t){this._onItemDismissedCallback=t}onToastItemClick(t){this._onToastItemClickCallback=t,this.render()}onToastItemActionClick(t){this._onToastItemActionClickCallback=t,this.render()}setToastItemContent(t){this._customToastItemContent=t}dismiss(e=t.dismissAnimationTimeoutMs){var s;null==(s=this._autoDismissTimeout)||s.cancel(),this.classList.add("dismissing"),setTimeout((()=>{this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})}),e)}pauseAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.pause(),this.syncAutoDismissBarPlayState()}resumeAutoDismiss(){var t;null==(t=this._autoDismissTimeout)||t.resume(),this.syncAutoDismissBarPlayState()}syncAutoDismissBarPlayState(){var t;this._autoDismissBar&&(this._autoDismissBar.style.animationPlayState=(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)?"paused":"running")}onComponentMounted(){this.render(),this._autoDismiss&&(this._autoDismissTimeout=new d((()=>this.dismiss()),this._autoDismissTimeoutMs),this._autoDismissTimeout.start())}onComponentUnmounted(){var t;this._themeSubscription.unsubscribe(),null==(t=this._autoDismissTimeout)||t.cancel()}get theme(){return this._themeManager.getTheme()}static get id(){return"courier-toast-item"}static get observedAttributes(){return[]}render(){for(var t,s,i,o,n;this.firstChild;)this.removeChild(this.firstChild);this.removeEventListener("click",this.onClick);const r=document.createElement("div");if(r.classList.add("overflow-hidden-container"),this.appendChild(r),this._autoDismiss){const e=document.createElement("div");e.classList.add("auto-dismiss"),(null==(t=this._autoDismissTimeout)?void 0:t.isPaused)&&(e.style.animationPlayState="paused"),r.append(e),this._autoDismissBar=e}this._customToastItemContent?r.appendChild(this._customToastItemContent({message:this._message,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs})):r.appendChild(this.createDefaultContent()),this._onToastItemClickCallback&&this.classList.add("clickable"),this.addEventListener("click",this.onClick);const a=new e.CourierIcon(null==(i=null==(s=this.theme.item)?void 0:s.dismissIcon)?void 0:i.color,null==(n=null==(o=this.theme.item)?void 0:o.dismissIcon)?void 0:n.svg);a.classList.add("dismiss"),a.addEventListener("click",(t=>{t.stopPropagation(),this.remove(),this._onItemDismissedCallback&&this._onItemDismissedCallback({message:this._message})})),this.appendChild(a)}createDefaultContent(){var t,s;const i=document.createElement("div");i.classList.add("content"),this.append(i);const o=null==(t=this.theme.item)?void 0:t.icon;if(!1!==(null==o?void 0:o.visible)){const t=new e.CourierIcon(null==o?void 0:o.color,null==o?void 0:o.svg);t.classList.add("icon"),i.appendChild(t)}const n=document.createElement("div");n.classList.add("text-content"),i.appendChild(n);const r=document.createElement("p");r.classList.add("title"),r.textContent=this._message.title??"",n.appendChild(r);const a=document.createElement("p");if(a.classList.add("body"),a.textContent=this._message.preview??this._message.body??"",n.appendChild(a),this.messageHasActions){const t=document.createElement("div");t.classList.add("actions-container"),n.appendChild(t),null==(s=this._message.actions)||s.forEach((e=>{const s=this.createActionButton(e);t.appendChild(s)}))}return i}get messageHasActions(){return this._message.actions&&this._message.actions.length>0}createActionButton(t){var s,i,o,n,r;const a=null==(s=this._themeManager.getTheme().item)?void 0:s.actions;return new e.CourierButton({mode:this._themeManager.mode,text:t.content,variant:"secondary",backgroundColor:null==a?void 0:a.backgroundColor,hoverBackgroundColor:null==a?void 0:a.hoverBackgroundColor,activeBackgroundColor:null==a?void 0:a.activeBackgroundColor,border:null==a?void 0:a.border,borderRadius:null==a?void 0:a.borderRadius,shadow:null==a?void 0:a.shadow,fontFamily:null==(i=null==a?void 0:a.font)?void 0:i.family,fontSize:null==(o=null==a?void 0:a.font)?void 0:o.size,fontWeight:null==(n=null==a?void 0:a.font)?void 0:n.weight,textColor:null==(r=null==a?void 0:a.font)?void 0:r.color,onClick:()=>{this._onToastItemActionClickCallback&&this._onToastItemActionClickCallback({message:this._message,action:t})}})}onClick(t){t.stopPropagation(),this._onToastItemClickCallback&&this._onToastItemClickCallback({message:this._message})}};o(u,"dismissAnimationTimeoutMs",300);let h=u;e.registerElement(h);const m=class t{constructor(){o(this,"_dataset",[]),o(this,"_datastoreListeners",[]),o(this,"_removeMessageEventListener")}static get shared(){return t.instance||(t.instance=new t),t.instance}addDatastoreListener(t){this._datastoreListeners.push(t)}removeDatastoreListener(t){this._datastoreListeners=this._datastoreListeners.filter((e=>e!==t))}async listenForMessages(){var t,e,i,o,n,r,a;try{const a=null==(t=s.Courier.shared.client)?void 0:t.inbox.socket;if(!a)return void(null==(i=null==(e=s.Courier.shared.client)?void 0:e.options.logger)||i.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=a.addMessageEventListener((t=>{if(t.event===s.InboxMessageEvent.NewMessage){const e=t.data;this.addMessage(e)}})),a.isConnecting||a.isOpen)return void(null==(r=null==(o=s.Courier.shared.client)?void 0:o.options.logger)||r.info(`Inbox socket already connecting or open for client ID: [${null==(n=s.Courier.shared.client)?void 0:n.options.connectionId}]`));await a.connect()}catch(l){null==(a=s.Courier.shared.client)||a.options.logger.error("Error listening for messages:",l),this._datastoreListeners.forEach((t=>{var e,s;null==(s=(e=t.events).onError)||s.call(e,l)}))}}toastIndexOfMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));return e<0?e:this._dataset.length-e-1}addMessage(t){this._dataset.push(t),this._datastoreListeners.forEach((e=>{e.events.onMessageAdd&&e.events.onMessageAdd(t)}))}removeMessage(t){const e=this._dataset.findIndex((e=>e.messageId===t.messageId));e<0||(this._dataset.splice(e,1),this._datastoreListeners.forEach((e=>{e.events.onMessageRemove&&e.events.onMessageRemove(t)})))}};o(m,"instance");let c=m;class g{constructor(t){this.events=t}remove(){c.shared.removeDatastoreListener(this)}}const C=class t extends e.CourierBaseElement{constructor(t){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_toastStyle"),o(this,"_authListener"),o(this,"_datastoreListener"),o(this,"_isHovered",!1),o(this,"_customItemAutoDismissTimeouts",new WeakMap),o(this,"_autoDismiss",!1),o(this,"_autoDismissTimeoutMs",5e3),o(this,"_dismissButtonOption","auto"),o(this,"_customToastItem"),o(this,"_customToastItemContent"),o(this,"_onItemClick"),o(this,"_onItemActionClick"),o(this,"_defaultLayoutProps",{position:"fixed",width:"380px",top:"30px",right:"30px",zIndex:999}),o(this,"onMouseEnter",(()=>{this._isHovered=!0,this.refreshAutoDismissCountdowns()})),o(this,"onMouseLeave",(()=>{this._isHovered=!1,this.refreshAutoDismissCountdowns()})),this._themeManager=(null==t?void 0:t.themeManager)??new l(n),this._themeSubscription=this._themeManager.subscribe((t=>{this.refreshStyles()})),this._datastoreListener=new g({onMessageAdd:this.datastoreAddMessageListener.bind(this),onMessageRemove:this.datastoreRemoveMessageListener.bind(this)})}onToastItemClick(t){this._onItemClick=t}onToastItemActionClick(t){this._onItemActionClick=t}enableAutoDismiss(){this._autoDismiss=!0}disableAutoDismiss(){this._autoDismiss=!1}setAutoDismissTimeoutMs(t){this._autoDismissTimeoutMs=t}setLightTheme(t){this._themeManager.setLightTheme(t)}setDarkTheme(t){this._themeManager.setDarkTheme(t)}setDismissButton(t){this._dismissButtonOption=t,this.refreshStyles()}setMode(t){this._themeManager.setMode(t)}setToastItem(t){this._customToastItem=t}setToastItemContent(t){this._customToastItemContent=t}dismissToastForMessage(t){this.childNodes.forEach((e=>{var s;e.dataset.courierMessageId===t.messageId&&(e instanceof h?e.dismiss():(null==(s=this._customItemAutoDismissTimeouts.get(e))||s.cancel(),e.remove(),this.refreshAutoDismissCountdowns()))}))}onComponentMounted(){this._toastStyle=e.injectGlobalStyle(t.id,this.getStyles(this.theme)),this.addEventListener("mouseenter",this.onMouseEnter),this.addEventListener("mouseleave",this.onMouseLeave),c.shared.addDatastoreListener(this._datastoreListener),s.Courier.shared.addAuthenticationListener(this.authChangedCallback.bind(this)),c.shared.listenForMessages()}onComponentUnmounted(){var t,e;this.removeEventListener("mouseenter",this.onMouseEnter),this.removeEventListener("mouseleave",this.onMouseLeave),this._datastoreListener.remove(),null==(t=this._authListener)||t.remove(),null==(e=this._toastStyle)||e.remove(),this._themeManager.cleanup(),this._themeSubscription.unsubscribe()}refreshAutoDismissCountdowns(){const t=Array.from(this.children),e=t[t.length-1];t.forEach((t=>{this.setItemAutoDismissPaused(t,this._isHovered||t!==e)}))}setItemAutoDismissPaused(t,e){if(t instanceof h)return void(e?t.pauseAutoDismiss():t.resumeAutoDismiss());const s=this._customItemAutoDismissTimeouts.get(t);e?null==s||s.pause():null==s||s.resume()}attributeChangedCallback(e,s,i){switch(e){case"auto-dismiss":"false"===i?this.disableAutoDismiss():this.enableAutoDismiss();break;case"auto-dismiss-timeout-ms":this.setAutoDismissTimeoutMs(parseInt(i,10));break;case"dismiss-button":i&&t.isDismissButtonOption(i)?this.setDismissButton(i):this.setDismissButton("auto");break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}get theme(){return this._themeManager.getTheme()}refreshStyles(){this._toastStyle&&(this._toastStyle.textContent=this.getStyles(this.theme))}authChangedCallback(){this.removeAllItems(),c.shared.listenForMessages()}removeAllItems(){for(var t;this.firstChild;)null==(t=this._customItemAutoDismissTimeouts.get(this.firstChild))||t.cancel(),this.removeChild(this.firstChild)}addToastItem(t){const e=this.createToastItem(t);return e.dataset.courierMessageId=t.messageId,this.appendChild(e),this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns(),e}createToastItem(t){return this._customToastItem?this.createCustomToastItem(t):this.createDefaultToastItem(t)}createDefaultToastItem(t){const e=new h({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs,themeManager:this._themeManager});return e.onItemDismissed((t=>{this.resizeContainerToHeight(this.topStackItemHeight),this.refreshAutoDismissCountdowns()})),this._customToastItemContent&&e.setToastItemContent(this._customToastItemContent),this._onItemClick&&e.onToastItemClick(this._onItemClick),this._onItemActionClick&&e.onToastItemActionClick(this._onItemActionClick),e}createCustomToastItem(t){if(!this._customToastItem)throw Error("Attempted to create customToastItem, but none is set");const e=this._customToastItem({message:t,autoDismiss:this._autoDismiss,autoDismissTimeoutMs:this._autoDismissTimeoutMs});if(this._autoDismiss){const t=new d((()=>{e.remove(),this.refreshAutoDismissCountdowns()}),this._autoDismissTimeoutMs);this._customItemAutoDismissTimeouts.set(e,t),t.start()}return e.addEventListener("click",(()=>{this._onItemClick&&this._onItemClick({message:t})})),e}datastoreAddMessageListener(t){this.addToastItem(t)}datastoreRemoveMessageListener(t){this.dismissToastForMessage(t)}getStyles(e){var s,i,o,n,r,a;const l=e.item;return[`\n ${t.id} {\n position: ${this._defaultLayoutProps.position};\n z-index: ${this._defaultLayoutProps.zIndex};\n top: ${this._defaultLayoutProps.top};\n right: ${this._defaultLayoutProps.right};\n width: ${this._defaultLayoutProps.width};\n }\n `,`\n ${h.id}:last-child {\n top: 0;\n right: 0;\n }\n\n ${h.id}:nth-last-child(2) {\n top: 12px;\n bottom: -12px;\n --scale: 0.95\n }\n\n ${h.id}:nth-last-child(3) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n }\n\n ${h.id}:nth-last-child(n+4) {\n top: 24px;\n bottom: -24px;\n --scale: 0.9;\n visibility: hidden;\n }\n\n ${h.id}:nth-last-child(n+2) > .overflow-hidden-container {\n opacity: 0;\n }\n `,`\n ${h.id} {\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n background-color: ${null==l?void 0:l.backgroundColor};\n box-shadow: ${null==l?void 0:l.shadow};\n border: ${null==l?void 0:l.border};\n border-radius: ${null==l?void 0:l.borderRadius};\n transition: 0.2s ease-in-out;\n cursor: default;\n\n opacity: 0;\n transform: translate(0, -10px) scaleX(var(--scale, 1));\n animation: courier-toast-show 0.3s ease-in-out forwards;\n }\n\n ${h.id} > .overflow-hidden-container {\n height: 100%;\n width: 100%;\n border-radius: ${null==l?void 0:l.borderRadius};\n overflow: hidden;\n }\n\n ${h.id}.dismissing {\n animation: courier-toast-hide 300ms ease-out forwards;\n }\n\n @keyframes courier-toast-show {\n 0% {\n opacity: 0;\n }\n\n 100% {\n opacity: 1;\n transform: scaleX(var(--scale, 1));\n }\n }\n\n /* Lift the toast back out the way it came in rather than blinking it out\n in place, which reads as the toast leaving instead of vanishing. The\n toast is anchored to the top of the viewport, so "out" is up: a full\n translateY of its own height, eased so most of the travel happens\n early and the tail is imperceptible. */\n /* Shrink the toast slightly as it fades so it reads as receding rather\n than blinking out, but keep it where it sits — moving it competes with\n the toast underneath sliding up to take its place. The stack's own\n horizontal scale is preserved so a toast dismissed from behind the top\n one doesn't jump to full width on its way out. */\n @keyframes courier-toast-hide {\n 0% {\n opacity: 1;\n transform: scale(1) scaleX(var(--scale, 1));\n }\n\n 100% {\n opacity: 0;\n transform: scale(0.92) scaleX(var(--scale, 1));\n }\n }\n\n ${h.id}.clickable:last-child {\n cursor: pointer;\n }\n\n ${h.id}.clickable:last-child:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id}.clickable:last-child:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}.clickable:nth-last-child(n+2) {\n pointer-events: none;\n }\n `,`\n ${h.id} > .dismiss {\n position: absolute;\n visibility: hidden;\n opacity: 0%;\n top: -10px;\n right: -10px;\n background-color: ${null==l?void 0:l.backgroundColor};\n border: ${null==l?void 0:l.border};\n padding: 3px;\n border-radius: 50%;\n font-size: 12pt;\n box-shadow: ${null==l?void 0:l.shadow};\n cursor: pointer;\n transition: 0.2s ease-in-out;\n }\n\n ${h.id} > .dismiss:hover {\n background-color: ${null==l?void 0:l.hoverBackgroundColor};\n }\n\n ${h.id} > .dismiss:active {\n background-color: ${null==l?void 0:l.activeBackgroundColor};\n }\n\n ${h.id}:last-child${this.showDismissOnHover?":hover":""} > .dismiss {\n visibility: ${this.showDismiss?"visible":"hidden"};\n opacity: 100%;\n transition: 0.2s ease-in-out;\n }\n `,`\n ${h.id} > .overflow-hidden-container > .auto-dismiss {\n width: 100%;\n height: 5px;\n background-color: ${null==l?void 0:l.autoDismissBarColor};\n animation: courier-toast-auto-dismiss ${this._autoDismissTimeoutMs}ms linear forwards;\n }\n\n @keyframes courier-toast-auto-dismiss {\n 100% {\n width: 0px;\n }\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content {\n display: flex;\n gap: 12px;\n align-items: center;\n align-self: stretch;\n box-sizing: border-box;\n padding: 12px;\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .icon {\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .title {\n margin: 0;\n /* Keep room for the dismiss button, which overhangs this corner. */\n padding-right: 16px;\n font-weight: ${null==(s=null==l?void 0:l.title)?void 0:s.weight};\n font-size: ${null==(i=null==l?void 0:l.title)?void 0:i.size};\n color: ${null==(o=null==l?void 0:l.title)?void 0:o.color};\n }\n\n ${h.id} > .overflow-hidden-container > .content > .text-content > .body {\n margin: 8px 0 0 0;\n font-weight: ${null==(n=null==l?void 0:l.body)?void 0:n.weight};\n font-size: ${null==(r=null==l?void 0:l.body)?void 0:r.size};\n line-height: 150%;\n color: ${null==(a=null==l?void 0:l.body)?void 0:a.color};\n }\n `,`\n ${h.id} > .overflow-hidden-container > .content > .text-content > .actions-container {\n display: flex;\n gap: 8px;\n margin-top: 12px;\n }\n `].join("")}get topStackItemHeight(){if(this.lastChild){return`${this.lastChild.getBoundingClientRect().height}px`}return"0px"}resizeContainerToHeight(t){this.style.height=t}get showDismissOnHover(){return!(!this._autoDismiss||"auto"!==this._dismissButtonOption)||"hover"===this._dismissButtonOption}get showDismiss(){return"hidden"!==this._dismissButtonOption}static get id(){return"courier-toast"}static isDismissButtonOption(t){return["visible","hidden","hover","auto"].includes(t)}};o(C,"observedAttributes",["auto-dismiss","auto-dismiss-timeout-ms","dismiss-button","light-theme","dark-theme","mode"]);let v=C;e.registerElement(v);s.Courier.shared.courierUserAgentName="courier-ui-toast",s.Courier.shared.courierUserAgentVersion="2.3.0",Object.defineProperty(t,"Courier",{enumerable:!0,get:()=>s.Courier}),Object.defineProperty(t,"DEFAULT_COURIER_API_URLS",{enumerable:!0,get:()=>s.DEFAULT_COURIER_API_URLS}),Object.defineProperty(t,"EU_COURIER_API_URLS",{enumerable:!0,get:()=>s.EU_COURIER_API_URLS}),Object.defineProperty(t,"getCourierApiUrls",{enumerable:!0,get:()=>s.getCourierApiUrls}),Object.defineProperty(t,"getCourierApiUrlsForRegion",{enumerable:!0,get:()=>s.getCourierApiUrlsForRegion}),t.CourierToast=v,t.CourierToastDatastore=c,t.CourierToastDatastoreEvents=class{onMessageAdd(t){}onMessageRemove(t){}onError(t){}},t.CourierToastDatastoreListener=g,t.CourierToastItem=h,t.CourierToastThemeManager=l,t.defaultDarkTheme=r,t.defaultLightTheme=n,t.mergeTheme=a,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -1262,7 +1262,7 @@ class CourierToastDatastoreEvents {
|
|
|
1262
1262
|
}
|
|
1263
1263
|
}
|
|
1264
1264
|
Courier.shared.courierUserAgentName = "courier-ui-toast";
|
|
1265
|
-
Courier.shared.courierUserAgentVersion = "2.
|
|
1265
|
+
Courier.shared.courierUserAgentVersion = "2.3.0";
|
|
1266
1266
|
export {
|
|
1267
1267
|
Courier2 as Courier,
|
|
1268
1268
|
CourierToast,
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier-ui-toast",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Toast components for the Courier web UI",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.mjs",
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./dist/*": "./dist/*",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
5
15
|
"main": "dist/index.js",
|
|
6
16
|
"module": "dist/index.mjs",
|
|
7
17
|
"types": "dist/index.d.ts",
|
|
@@ -31,8 +41,8 @@
|
|
|
31
41
|
"dist"
|
|
32
42
|
],
|
|
33
43
|
"dependencies": {
|
|
34
|
-
"@trycourier/courier-js": "3.
|
|
35
|
-
"@trycourier/courier-ui-core": "2.
|
|
44
|
+
"@trycourier/courier-js": "3.6.0",
|
|
45
|
+
"@trycourier/courier-ui-core": "2.4.0"
|
|
36
46
|
},
|
|
37
47
|
"devDependencies": {
|
|
38
48
|
"@types/jest": "29.5.14",
|