Files
hqland-app/public/js/filament/notifications/notifications.js

2 lines
5.8 KiB
JavaScript

(()=>{function c(s,t=()=>{}){let i=!1;return function(){i?t.apply(this,arguments):(i=!0,s.apply(this,arguments))}}var d=s=>{s.data("notificationComponent",({notification:t})=>({isShown:!1,computedStyle:null,transitionDuration:null,transitionEasing:null,unsubscribeLivewireHook:null,init(){this.computedStyle=window.getComputedStyle(this.$el),this.transitionDuration=parseFloat(this.computedStyle.transitionDuration)*1e3,this.transitionEasing=this.computedStyle.transitionTimingFunction,this.configureTransitions(),this.configureAnimations(),t.duration&&t.duration!=="persistent"&&setTimeout(()=>{if(!this.$el.matches(":hover")){this.close();return}this.$el.addEventListener("mouseleave",()=>this.close())},t.duration),this.isShown=!0},configureTransitions(){let i=this.computedStyle.display,e=()=>{s.mutateDom(()=>{this.$el.style.setProperty("display",i),this.$el.style.setProperty("visibility","visible")}),this.$el._x_isShown=!0},o=()=>{s.mutateDom(()=>{this.$el._x_isShown?this.$el.style.setProperty("visibility","hidden"):this.$el.style.setProperty("display","none")})},r=c(n=>n?e():o(),n=>{this.$el._x_toggleAndCascadeWithTransitions(this.$el,n,e,o)});s.effect(()=>r(this.isShown))},configureAnimations(){let i;this.unsubscribeLivewireHook=Livewire.interceptMessage(({onFinish:e,onSuccess:o})=>{requestAnimationFrame(()=>{let r=()=>this.$el.getBoundingClientRect().top,n=r();e(()=>{i=()=>{this.isShown&&this.$el.animate([{transform:`translateY(${n-r()}px)`},{transform:"translateY(0px)"}],{duration:this.transitionDuration,easing:this.transitionEasing})},this.$el.getAnimations().forEach(l=>l.finish())}),o(({payload:l})=>{l?.snapshot?.data?.isFilamentNotificationsComponent&&typeof i=="function"&&i()})})})},close(){this.isShown=!1,setTimeout(()=>window.dispatchEvent(new CustomEvent("notificationClosed",{detail:{id:t.id}})),this.transitionDuration)},markAsRead(){window.dispatchEvent(new CustomEvent("markedNotificationAsRead",{detail:{id:t.id}}))},markAsUnread(){window.dispatchEvent(new CustomEvent("markedNotificationAsUnread",{detail:{id:t.id}}))},destroy(){this.unsubscribeLivewireHook?.()}}))};var h=class{constructor(){return this.id(crypto.randomUUID?.()??"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(+t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>+t/4).toString(16))),this}id(t){return this._id=t,this}title(t){return this._title=t,this}body(t){return this._body=t,this}actions(t){return this._actions=t,this}status(t){return this._status=t,this}color(t){return this._color=t,this}icon(t){return this._icon=t,this}iconColor(t){return this._iconColor=t,this}duration(t){return this._duration=t,this}seconds(t){return this.duration(t*1e3),this}persistent(){return this.duration("persistent"),this}danger(){return this.status("danger"),this}info(){return this.status("info"),this}success(){return this.status("success"),this}warning(){return this.status("warning"),this}view(t){return this._view=t,this}viewData(t){return this._viewData=t,this}toJSON(){return{id:this._id,title:this._title,body:this._body,actions:this._actions?.map(t=>t.toJSON()),status:this._status,color:this._color,icon:this._icon,iconColor:this._iconColor,duration:this._duration,view:this._view,viewData:this._viewData}}send(){return window.dispatchEvent(new CustomEvent("notificationSent",{detail:{notification:this.toJSON()}})),this}},a=class{constructor(t){return this.name(t),this}name(t){return this._name=t,this}color(t){return this._color=t,this}dispatch(t,i){return this.event(t),this.eventData(i),this}dispatchSelf(t,i){return this.dispatch(t,i),this._dispatchDirection="self",this}dispatchTo(t,i,e){return this.dispatch(i,e),this._dispatchDirection="to",this._dispatchToComponent=t,this}emit(t,i){return this.dispatch(t,i),this}emitSelf(t,i){return this.dispatchSelf(t,i),this}emitTo(t,i,e){return this.dispatchTo(t,i,e),this}dispatchDirection(t){return this._dispatchDirection=t,this}dispatchToComponent(t){return this._dispatchToComponent=t,this}event(t){return this._event=t,this}eventData(t){return this._eventData=t,this}extraAttributes(t){return this._extraAttributes=t,this}icon(t){return this._icon=t,this}iconPosition(t){return this._iconPosition=t,this}outlined(t=!0){return this._isOutlined=t,this}disabled(t=!0){return this._isDisabled=t,this}label(t){return this._label=t,this}close(t=!0){return this._shouldClose=t,this}openUrlInNewTab(t=!0){return this._shouldOpenUrlInNewTab=t,this}size(t){return this._size=t,this}url(t){return this._url=t,this}view(t){return this._view=t,this}button(){return this.view("filament::components.button.index"),this}grouped(){return this.view("filament::components.dropdown.list.item"),this}iconButton(){return this.view("filament::components.icon-button"),this}link(){return this.view("filament::components.link"),this}toJSON(){return{name:this._name,color:this._color,event:this._event,eventData:this._eventData,dispatchDirection:this._dispatchDirection,dispatchToComponent:this._dispatchToComponent,extraAttributes:this._extraAttributes,icon:this._icon,iconPosition:this._iconPosition,isOutlined:this._isOutlined,isDisabled:this._isDisabled,label:this._label,shouldClose:this._shouldClose,shouldOpenUrlInNewTab:this._shouldOpenUrlInNewTab,size:this._size,url:this._url,view:this._view}}},u=class{constructor(t){return this.actions(t),this}actions(t){return this._actions=t.map(i=>i.grouped()),this}color(t){return this._color=t,this}icon(t){return this._icon=t,this}iconPosition(t){return this._iconPosition=t,this}label(t){return this._label=t,this}tooltip(t){return this._tooltip=t,this}toJSON(){return{actions:this._actions?.map(t=>t.toJSON()),color:this._color,icon:this._icon,iconPosition:this._iconPosition,label:this._label,tooltip:this._tooltip}}};window.FilamentNotificationAction=a;window.FilamentNotificationActionGroup=u;window.FilamentNotification=h;document.addEventListener("alpine:init",()=>{window.Alpine.plugin(d)});})();