UNPKG

primevue

Version:

PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc

2 lines (1 loc) 8.13 kB
import t from"primevue/button";import e from"primevue/confirmationeventbus";import n from"primevue/focustrap";import i from"primevue/overlayeventbus";import o from"primevue/portal";import{ZIndexUtils as c,DomHandler as s,ConnectedOverlayScrollHandler as r}from"primevue/utils";import a from"primevue/basecomponent";import l from"primevue/confirmpopup/style";import{resolveComponent as u,resolveDirective as f,openBlock as p,createBlock as m,withCtx as d,createVNode as h,Transition as v,mergeProps as L,withDirectives as b,createElementBlock as y,renderSlot as g,Fragment as k,resolveDynamicComponent as j,normalizeClass as C,createCommentVNode as w,createElementVNode as A,toDisplayString as E,createSlots as O}from"vue";var z={name:"ConfirmPopup",extends:{name:"BaseConfirmPopup",extends:a,props:{group:String},style:l,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,data:function(){return{visible:!1,confirmation:null,autoFocusAccept:null,autoFocusReject:null}},target:null,outsideClickListener:null,scrollHandler:null,resizeListener:null,container:null,confirmListener:null,closeListener:null,mounted:function(){var t=this;this.confirmListener=function(e){e&&e.group===t.group&&(t.confirmation=e,t.target=e.target,t.confirmation.onShow&&t.confirmation.onShow(),t.visible=!0)},this.closeListener=function(){t.visible=!1,t.confirmation=null},e.on("confirm",this.confirmListener),e.on("close",this.closeListener)},beforeUnmount:function(){e.off("confirm",this.confirmListener),e.off("close",this.closeListener),this.unbindOutsideClickListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.unbindResizeListener(),this.container&&(c.clear(this.container),this.container=null),this.target=null,this.confirmation=null},methods:{accept:function(){this.confirmation.accept&&this.confirmation.accept(),this.visible=!1},reject:function(){this.confirmation.reject&&this.confirmation.reject(),this.visible=!1},onHide:function(){this.confirmation.onHide&&this.confirmation.onHide(),this.visible=!1},onAcceptKeydown:function(t){"Space"!==t.code&&"Enter"!==t.code&&"NumpadEnter"!==t.code||(this.accept(),s.focus(this.target),t.preventDefault())},onRejectKeydown:function(t){"Space"!==t.code&&"Enter"!==t.code&&"NumpadEnter"!==t.code||(this.reject(),s.focus(this.target),t.preventDefault())},onEnter:function(t){this.autoFocusAccept=void 0===this.confirmation.defaultFocus||"accept"===this.confirmation.defaultFocus,this.autoFocusReject="reject"===this.confirmation.defaultFocus,this.bindOutsideClickListener(),this.bindScrollListener(),this.bindResizeListener(),c.set("overlay",t,this.$primevue.config.zIndex.overlay)},onAfterEnter:function(){this.focus()},onLeave:function(){this.autoFocusAccept=null,this.autoFocusReject=null,this.unbindOutsideClickListener(),this.unbindScrollListener(),this.unbindResizeListener()},onAfterLeave:function(t){c.clear(t)},alignOverlay:function(){s.absolutePosition(this.container,this.target,!1);var t=s.getOffset(this.container),e=s.getOffset(this.target),n=0;t.left<e.left&&(n=e.left-t.left),this.container.style.setProperty("--overlayArrowLeft","".concat(n,"px")),t.top<e.top&&(this.container.setAttribute("data-p-confirm-popup-flipped","true"),!this.isUnstyled&&s.addClass(this.container,"p-confirm-popup-flipped"))},bindOutsideClickListener:function(){var t=this;this.outsideClickListener||(this.outsideClickListener=function(e){t.visible&&t.container&&!t.container.contains(e.target)&&!t.isTargetClicked(e)?(t.confirmation.onHide&&t.confirmation.onHide(),t.visible=!1):t.alignOverlay()},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null)},bindScrollListener:function(){var t=this;this.scrollHandler||(this.scrollHandler=new r(this.target,(function(){t.visible&&(t.visible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener:function(){var t=this;this.resizeListener||(this.resizeListener=function(){t.visible&&!s.isTouchDevice()&&(t.visible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},focus:function(){var t=this.container.querySelector("[autofocus]");t&&t.focus({preventScroll:!0})},isTargetClicked:function(t){return this.target&&(this.target===t.target||this.target.contains(t.target))},containerRef:function(t){this.container=t},onOverlayClick:function(t){i.emit("overlay-click",{originalEvent:t,target:this.target})},onOverlayKeydown:function(t){"Escape"===t.code&&(e.emit("close",this.closeListener),s.focus(this.target))},getCXOptions:function(t,e){return{contenxt:{icon:t,iconClass:e.class}}}},computed:{message:function(){return this.confirmation?this.confirmation.message:null},acceptLabel:function(){return this.confirmation?this.confirmation.acceptLabel||this.$primevue.config.locale.accept:null},rejectLabel:function(){return this.confirmation?this.confirmation.rejectLabel||this.$primevue.config.locale.reject:null},acceptIcon:function(){return this.confirmation?this.confirmation.acceptIcon:null},rejectIcon:function(){return this.confirmation?this.confirmation.rejectIcon:null}},components:{CPButton:t,Portal:o},directives:{focustrap:n}},$=["aria-modal"];z.render=function(t,e,n,i,o,c){var s=u("CPButton"),r=u("Portal"),a=f("focustrap");return p(),m(r,null,{default:d((function(){return[h(v,L({name:"p-confirm-popup",onEnter:c.onEnter,onAfterEnter:c.onAfterEnter,onLeave:c.onLeave,onAfterLeave:c.onAfterLeave},t.ptm("transition")),{default:d((function(){return[o.visible?b((p(),y("div",L({key:0,ref:c.containerRef,role:"alertdialog",class:t.cx("root"),"aria-modal":o.visible,onClick:e[2]||(e[2]=function(){return c.onOverlayClick&&c.onOverlayClick.apply(c,arguments)}),onKeydown:e[3]||(e[3]=function(){return c.onOverlayKeydown&&c.onOverlayKeydown.apply(c,arguments)})},t.ptmi("root")),[t.$slots.container?g(t.$slots,"container",{key:0,message:o.confirmation,onAccept:c.accept,onReject:c.reject,acceptCallback:c.accept,rejectCallback:c.reject}):(p(),y(k,{key:1},[t.$slots.message?(p(),m(j(t.$slots.message),{key:1,message:o.confirmation},null,8,["message"])):(p(),y("div",L({key:0,class:t.cx("content")},t.ptm("content")),[g(t.$slots,"icon",{},(function(){return[t.$slots.icon?(p(),m(j(t.$slots.icon),{key:0,class:C(t.cx("icon"))},null,8,["class"])):o.confirmation.icon?(p(),y("span",L({key:1,class:[o.confirmation.icon,t.cx("icon")]},t.ptm("icon")),null,16)):w("",!0)]})),A("span",L({class:t.cx("message")},t.ptm("message")),E(o.confirmation.message),17)],16)),A("div",L({class:t.cx("footer")},t.ptm("footer")),[h(s,{label:c.rejectLabel,onClick:e[0]||(e[0]=function(t){return c.reject()}),onKeydown:c.onRejectKeydown,autofocus:o.autoFocusReject,class:C([t.cx("rejectButton"),o.confirmation.rejectClass]),unstyled:t.unstyled,pt:t.ptm("rejectButton")},O({_:2},[c.rejectIcon||t.$slots.rejecticon?{name:"icon",fn:d((function(e){return[g(t.$slots,"rejecticon",{},(function(){return[A("span",L({class:[c.rejectIcon,e.class]},t.ptm("rejectButton").icon,{"data-pc-section":"rejectbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"]),h(s,{label:c.acceptLabel,onClick:e[1]||(e[1]=function(t){return c.accept()}),onKeydown:c.onAcceptKeydown,autofocus:o.autoFocusAccept,class:C([t.cx("acceptButton"),o.confirmation.acceptClass]),unstyled:t.unstyled,pt:t.ptm("acceptButton")},O({_:2},[c.acceptIcon||t.$slots.accepticon?{name:"icon",fn:d((function(e){return[g(t.$slots,"accepticon",{},(function(){return[A("span",L({class:[c.acceptIcon,e.class]},t.ptm("acceptButton").icon,{"data-pc-section":"acceptbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"])],16)],64))],16,$)),[[a]]):w("",!0)]})),_:3},16,["onEnter","onAfterEnter","onLeave","onAfterLeave"])]})),_:3})};export{z as default};