primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 9.34 kB
JavaScript
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 r,DomHandler as c,ConnectedOverlayScrollHandler as s}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 b,withDirectives as y,createElementBlock as L,renderSlot as g,Fragment as j,resolveDynamicComponent as O,normalizeClass as k,createCommentVNode as w,createElementVNode as C,toDisplayString as S,createSlots as E}from"vue";var P={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&&(r.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||(this.accept(),c.focus(this.target),t.preventDefault())},onRejectKeydown:function(t){"Space"!==t.code&&"Enter"!==t.code||(this.reject(),c.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(),r.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){r.clear(t)},alignOverlay:function(){c.absolutePosition(this.container,this.target);var t=c.getOffset(this.container),e=c.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&&c.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 s(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&&!c.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),c.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}};function A(t){return A="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},A(t)}function $(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function z(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?$(Object(n),!0).forEach((function(e){x(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):$(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function x(t,e,n){return(e=H(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function H(t){var e=R(t,"string");return"symbol"===A(e)?e:String(e)}function R(t,e){if("object"!==A(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!==A(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var K=["aria-modal"];P.render=function(t,e,n,i,o,r){var c=u("CPButton"),s=u("Portal"),a=f("focustrap");return p(),m(s,null,{default:d((function(){return[h(v,b({name:"p-confirm-popup",onEnter:r.onEnter,onAfterEnter:r.onAfterEnter,onLeave:r.onLeave,onAfterLeave:r.onAfterLeave},t.ptm("transition")),{default:d((function(){return[o.visible?y((p(),L("div",b({key:0,ref:r.containerRef,role:"alertdialog",class:t.cx("root"),"aria-modal":o.visible,onClick:e[2]||(e[2]=function(){return r.onOverlayClick&&r.onOverlayClick.apply(r,arguments)}),onKeydown:e[3]||(e[3]=function(){return r.onOverlayKeydown&&r.onOverlayKeydown.apply(r,arguments)})},z(z({},t.$attrs),t.ptm("root"))),[t.$slots.container?g(t.$slots,"container",{key:0,message:o.confirmation,onAccept:r.accept,onReject:r.reject}):(p(),L(j,{key:1},[t.$slots.message?(p(),m(O(t.$slots.message),{key:1,message:o.confirmation},null,8,["message"])):(p(),L("div",b({key:0,class:t.cx("content")},t.ptm("content")),[g(t.$slots,"icon",{},(function(){return[t.$slots.icon?(p(),m(O(t.$slots.icon),{key:0,class:k(t.cx("icon"))},null,8,["class"])):o.confirmation.icon?(p(),L("span",b({key:1,class:t.cx("icon")},t.ptm("icon")),null,16)):w("",!0)]})),C("span",b({class:t.cx("message")},t.ptm("message")),S(o.confirmation.message),17)],16)),C("div",b({class:t.cx("footer")},t.ptm("footer")),[h(c,{label:r.rejectLabel,onClick:e[0]||(e[0]=function(t){return r.reject()}),onKeydown:r.onRejectKeydown,autofocus:o.autoFocusReject,class:k([t.cx("rejectButton"),o.confirmation.rejectClass]),unstyled:t.unstyled,pt:t.ptm("rejectButton"),"data-pc-name":"rejectbutton"},E({_:2},[r.rejectIcon||t.$slots.rejecticon?{name:"icon",fn:d((function(e){return[g(t.$slots,"rejecticon",{},(function(){return[C("span",b({class:[r.rejectIcon,e.class]},t.ptm("rejectButton").icon,{"data-pc-name":"rejectbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"]),h(c,{label:r.acceptLabel,onClick:e[1]||(e[1]=function(t){return r.accept()}),onKeydown:r.onAcceptKeydown,autofocus:o.autoFocusAccept,class:k([t.cx("acceptButton"),o.confirmation.acceptClass]),unstyled:t.unstyled,pt:t.ptm("acceptButton"),"data-pc-name":"acceptbutton"},E({_:2},[r.acceptIcon||t.$slots.accepticon?{name:"icon",fn:d((function(e){return[g(t.$slots,"accepticon",{},(function(){return[C("span",b({class:[r.acceptIcon,e.class]},t.ptm("acceptButton").icon,{"data-pc-name":"acceptbuttonicon"}),null,16)]}))]})),key:"0"}:void 0]),1032,["label","onKeydown","autofocus","class","unstyled","pt"])],16)],64))],16,K)),[[a]]):w("",!0)]})),_:3},16,["onEnter","onAfterEnter","onLeave","onAfterLeave"])]})),_:3})};export{P as default};