primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 16.4 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.dialog=function(e,t,n,i,o,a,l,s,r){"use strict";function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var m=d(e),p=d(t),c=d(n),u=d(i),g=d(o),h=d(a),f=d(l),b={name:"Dialog",extends:m.default,inheritAttrs:!1,emits:["update:visible","show","hide","after-hide","maximize","unmaximize","dragend"],props:{header:{type:null,default:null},footer:{type:null,default:null},visible:{type:Boolean,default:!1},modal:{type:Boolean,default:null},contentStyle:{type:null,default:null},contentClass:{type:String,default:null},contentProps:{type:null,default:null},rtl:{type:Boolean,default:null},maximizable:{type:Boolean,default:!1},dismissableMask:{type:Boolean,default:!1},closable:{type:Boolean,default:!0},closeOnEscape:{type:Boolean,default:!0},showHeader:{type:Boolean,default:!0},baseZIndex:{type:Number,default:0},autoZIndex:{type:Boolean,default:!0},position:{type:String,default:"center"},breakpoints:{type:Object,default:null},draggable:{type:Boolean,default:!0},keepInViewport:{type:Boolean,default:!0},minX:{type:Number,default:0},minY:{type:Number,default:0},appendTo:{type:String,default:"body"},closeIcon:{type:String,default:void 0},maximizeIcon:{type:String,default:void 0},minimizeIcon:{type:String,default:void 0},closeButtonProps:{type:null,default:null},_instance:null},provide(){return{dialogRef:r.computed((()=>this._instance))}},data(){return{containerVisible:this.visible,maximized:!1,focusableMax:null,focusableClose:null}},documentKeydownListener:null,container:null,mask:null,content:null,headerContainer:null,footerContainer:null,maximizableButton:null,closeButton:null,styleElement:null,dragging:null,documentDragListener:null,documentDragEndListener:null,lastPageX:null,lastPageY:null,updated(){this.visible&&(this.containerVisible=this.visible)},beforeUnmount(){this.unbindDocumentState(),this.unbindGlobalListeners(),this.destroyStyle(),this.mask&&this.autoZIndex&&s.ZIndexUtils.clear(this.mask),this.container=null,this.mask=null},mounted(){this.breakpoints&&this.createStyle()},methods:{close(){this.$emit("update:visible",!1)},onBeforeEnter(e){e.setAttribute(this.attributeSelector,"")},onEnter(){this.$emit("show"),this.focus(),this.enableDocumentSettings(),this.bindGlobalListeners(),this.autoZIndex&&s.ZIndexUtils.set("modal",this.mask,this.baseZIndex+this.$primevue.config.zIndex.modal)},onBeforeLeave(){this.modal&&s.DomHandler.addClass(this.mask,"p-component-overlay-leave")},onLeave(){this.$emit("hide"),this.focusableClose=null,this.focusableMax=null},onAfterLeave(){this.autoZIndex&&s.ZIndexUtils.clear(this.mask),this.containerVisible=!1,this.unbindDocumentState(),this.unbindGlobalListeners(),this.$emit("after-hide")},onMaskClick(e){this.dismissableMask&&this.modal&&this.mask===e.target&&this.close()},focus(){const e=e=>e.querySelector("[autofocus]");let t=this.$slots.footer&&e(this.footerContainer);t||(t=this.$slots.header&&e(this.headerContainer),t||(t=this.$slots.default&&e(this.content),t||(this.maximizable?(this.focusableMax=!0,t=this.maximizableButton):(this.focusableClose=!0,t=this.closeButton)))),t&&s.DomHandler.focus(t)},maximize(e){this.maximized?(this.maximized=!1,this.$emit("unmaximize",e)):(this.maximized=!0,this.$emit("maximize",e)),this.modal||(this.maximized?s.DomHandler.addClass(document.body,"p-overflow-hidden"):s.DomHandler.removeClass(document.body,"p-overflow-hidden"))},enableDocumentSettings(){(this.modal||this.maximizable&&this.maximized)&&s.DomHandler.addClass(document.body,"p-overflow-hidden")},unbindDocumentState(){(this.modal||this.maximizable&&this.maximized)&&s.DomHandler.removeClass(document.body,"p-overflow-hidden")},onKeyDown(e){"Escape"===e.code&&this.closeOnEscape&&this.close()},bindDocumentKeyDownListener(){this.documentKeydownListener||(this.documentKeydownListener=this.onKeyDown.bind(this),window.document.addEventListener("keydown",this.documentKeydownListener))},unbindDocumentKeyDownListener(){this.documentKeydownListener&&(window.document.removeEventListener("keydown",this.documentKeydownListener),this.documentKeydownListener=null)},getPositionClass(){const e=["left","right","top","topleft","topright","bottom","bottomleft","bottomright"].find((e=>e===this.position));return e?`p-dialog-${e}`:""},containerRef(e){this.container=e},maskRef(e){this.mask=e},contentRef(e){this.content=e},headerContainerRef(e){this.headerContainer=e},footerContainerRef(e){this.footerContainer=e},maximizableRef(e){this.maximizableButton=e},closeButtonRef(e){this.closeButton=e},createStyle(){if(!this.styleElement){this.styleElement=document.createElement("style"),this.styleElement.type="text/css",document.head.appendChild(this.styleElement);let e="";for(let t in this.breakpoints)e+=`\n screen and (max-width: ${t}) {\n .p-dialog[${this.attributeSelector}] {\n width: ${this.breakpoints[t]} !important;\n }\n }\n `;this.styleElement.innerHTML=e}},destroyStyle(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)},initDrag(e){s.DomHandler.hasClass(e.target,"p-dialog-header-icon")||s.DomHandler.hasClass(e.target.parentElement,"p-dialog-header-icon")||this.draggable&&(this.dragging=!0,this.lastPageX=e.pageX,this.lastPageY=e.pageY,this.container.style.margin="0",s.DomHandler.addClass(document.body,"p-unselectable-text"))},bindGlobalListeners(){this.draggable&&(this.bindDocumentDragListener(),this.bindDocumentDragEndListener()),this.closeOnEscape&&this.closable&&this.bindDocumentKeyDownListener()},unbindGlobalListeners(){this.unbindDocumentDragListener(),this.unbindDocumentDragEndListener(),this.unbindDocumentKeyDownListener()},bindDocumentDragListener(){this.documentDragListener=e=>{if(this.dragging){let t=s.DomHandler.getOuterWidth(this.container),n=s.DomHandler.getOuterHeight(this.container),i=e.pageX-this.lastPageX,o=e.pageY-this.lastPageY,a=this.container.getBoundingClientRect(),l=a.left+i,r=a.top+o,d=s.DomHandler.getViewport();this.container.style.position="fixed",this.keepInViewport?(l>=this.minX&&l+t<d.width&&(this.lastPageX=e.pageX,this.container.style.left=l+"px"),r>=this.minY&&r+n<d.height&&(this.lastPageY=e.pageY,this.container.style.top=r+"px")):(this.lastPageX=e.pageX,this.container.style.left=l+"px",this.lastPageY=e.pageY,this.container.style.top=r+"px")}},window.document.addEventListener("mousemove",this.documentDragListener)},unbindDocumentDragListener(){this.documentDragListener&&(window.document.removeEventListener("mousemove",this.documentDragListener),this.documentDragListener=null)},bindDocumentDragEndListener(){this.documentDragEndListener=e=>{this.dragging&&(this.dragging=!1,s.DomHandler.removeClass(document.body,"p-unselectable-text"),this.$emit("dragend",e))},window.document.addEventListener("mouseup",this.documentDragEndListener)},unbindDocumentDragEndListener(){this.documentDragEndListener&&(window.document.removeEventListener("mouseup",this.documentDragEndListener),this.documentDragEndListener=null)}},computed:{maskClass(){return["p-dialog-mask",{"p-component-overlay p-component-overlay-enter":this.modal},this.getPositionClass()]},dialogClass(){return["p-dialog p-component",{"p-dialog-rtl":this.rtl,"p-dialog-maximized":this.maximizable&&this.maximized,"p-input-filled":"filled"===this.$primevue.config.inputStyle,"p-ripple-disabled":!1===this.$primevue.config.ripple}]},maximizeIconComponent(){return this.maximized?this.minimizeIcon?"span":"WindowMinimizeIcon":this.maximizeIcon?"span":"WindowMaximizeIcon"},maximizeIconClass(){return`p-dialog-header-maximize-icon ${this.maximized?this.minimizeIcon:this.maximizeIcon}`},ariaId:()=>s.UniqueComponentId(),ariaLabelledById(){return null!=this.header||null!==this.$attrs["aria-labelledby"]?this.ariaId+"_header":null},closeAriaLabel(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.close:void 0},attributeSelector:()=>s.UniqueComponentId(),contentStyleClass(){return["p-dialog-content",this.contentClass]}},directives:{ripple:f.default,focustrap:p.default},components:{Portal:h.default,WindowMinimizeIcon:g.default,WindowMaximizeIcon:u.default,TimesIcon:c.default}};const v=["aria-labelledby","aria-modal"],y=["id"],x=["autofocus","tabindex"],D=["autofocus","aria-label"];return function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&i.firstChild?i.insertBefore(o,i.firstChild):i.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.p-dialog-mask {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n pointer-events: none;\n}\n.p-dialog-mask.p-component-overlay {\n pointer-events: auto;\n}\n.p-dialog {\n display: flex;\n flex-direction: column;\n pointer-events: auto;\n max-height: 90%;\n transform: scale(1);\n}\n.p-dialog-content {\n overflow-y: auto;\n}\n.p-dialog-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n flex-shrink: 0;\n}\n.p-dialog-footer {\n flex-shrink: 0;\n}\n.p-dialog .p-dialog-header-icons {\n display: flex;\n align-items: center;\n}\n.p-dialog .p-dialog-header-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n overflow: hidden;\n position: relative;\n}\n\n/* Fluid */\n.p-fluid .p-dialog-footer .p-button {\n width: auto;\n}\n\n/* Animation */\n/* Center */\n.p-dialog-enter-active {\n transition: all 150ms cubic-bezier(0, 0, 0.2, 1);\n}\n.p-dialog-leave-active {\n transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);\n}\n.p-dialog-enter-from,\n.p-dialog-leave-to {\n opacity: 0;\n transform: scale(0.7);\n}\n\n/* Top, Bottom, Left, Right, Top* and Bottom* */\n.p-dialog-top .p-dialog,\n.p-dialog-bottom .p-dialog,\n.p-dialog-left .p-dialog,\n.p-dialog-right .p-dialog,\n.p-dialog-topleft .p-dialog,\n.p-dialog-topright .p-dialog,\n.p-dialog-bottomleft .p-dialog,\n.p-dialog-bottomright .p-dialog {\n margin: 0.75rem;\n transform: translate3d(0px, 0px, 0px);\n}\n.p-dialog-top .p-dialog-enter-active,\n.p-dialog-top .p-dialog-leave-active,\n.p-dialog-bottom .p-dialog-enter-active,\n.p-dialog-bottom .p-dialog-leave-active,\n.p-dialog-left .p-dialog-enter-active,\n.p-dialog-left .p-dialog-leave-active,\n.p-dialog-right .p-dialog-enter-active,\n.p-dialog-right .p-dialog-leave-active,\n.p-dialog-topleft .p-dialog-enter-active,\n.p-dialog-topleft .p-dialog-leave-active,\n.p-dialog-topright .p-dialog-enter-active,\n.p-dialog-topright .p-dialog-leave-active,\n.p-dialog-bottomleft .p-dialog-enter-active,\n.p-dialog-bottomleft .p-dialog-leave-active,\n.p-dialog-bottomright .p-dialog-enter-active,\n.p-dialog-bottomright .p-dialog-leave-active {\n transition: all 0.3s ease-out;\n}\n.p-dialog-top .p-dialog-enter-from,\n.p-dialog-top .p-dialog-leave-to {\n transform: translate3d(0px, -100%, 0px);\n}\n.p-dialog-bottom .p-dialog-enter-from,\n.p-dialog-bottom .p-dialog-leave-to {\n transform: translate3d(0px, 100%, 0px);\n}\n.p-dialog-left .p-dialog-enter-from,\n.p-dialog-left .p-dialog-leave-to,\n.p-dialog-topleft .p-dialog-enter-from,\n.p-dialog-topleft .p-dialog-leave-to,\n.p-dialog-bottomleft .p-dialog-enter-from,\n.p-dialog-bottomleft .p-dialog-leave-to {\n transform: translate3d(-100%, 0px, 0px);\n}\n.p-dialog-right .p-dialog-enter-from,\n.p-dialog-right .p-dialog-leave-to,\n.p-dialog-topright .p-dialog-enter-from,\n.p-dialog-topright .p-dialog-leave-to,\n.p-dialog-bottomright .p-dialog-enter-from,\n.p-dialog-bottomright .p-dialog-leave-to {\n transform: translate3d(100%, 0px, 0px);\n}\n\n/* Maximize */\n.p-dialog-maximized {\n -webkit-transition: none;\n transition: none;\n transform: none;\n width: 100vw !important;\n height: 100vh !important;\n top: 0px !important;\n left: 0px !important;\n max-height: 100%;\n height: 100%;\n}\n.p-dialog-maximized .p-dialog-content {\n flex-grow: 1;\n}\n\n/* Position */\n.p-dialog-left {\n justify-content: flex-start;\n}\n.p-dialog-right {\n justify-content: flex-end;\n}\n.p-dialog-top {\n align-items: flex-start;\n}\n.p-dialog-topleft {\n justify-content: flex-start;\n align-items: flex-start;\n}\n.p-dialog-topright {\n justify-content: flex-end;\n align-items: flex-start;\n}\n.p-dialog-bottom {\n align-items: flex-end;\n}\n.p-dialog-bottomleft {\n justify-content: flex-start;\n align-items: flex-end;\n}\n.p-dialog-bottomright {\n justify-content: flex-end;\n align-items: flex-end;\n}\n.p-confirm-dialog .p-dialog-content {\n display: flex;\n align-items: center;\n}\n"),b.render=function(e,t,n,i,o,a){const l=r.resolveComponent("Portal"),s=r.resolveDirective("ripple"),d=r.resolveDirective("focustrap");return r.openBlock(),r.createBlock(l,{appendTo:n.appendTo},{default:r.withCtx((()=>[o.containerVisible?(r.openBlock(),r.createElementBlock("div",r.mergeProps({key:0,ref:a.maskRef,class:a.maskClass,onClick:t[3]||(t[3]=(...e)=>a.onMaskClick&&a.onMaskClick(...e))},e.ptm("mask")),[r.createVNode(r.Transition,{name:"p-dialog",onBeforeEnter:a.onBeforeEnter,onEnter:a.onEnter,onBeforeLeave:a.onBeforeLeave,onLeave:a.onLeave,onAfterLeave:a.onAfterLeave,appear:""},{default:r.withCtx((()=>[n.visible?r.withDirectives((r.openBlock(),r.createElementBlock("div",r.mergeProps({key:0,ref:a.containerRef,class:a.dialogClass,role:"dialog","aria-labelledby":a.ariaLabelledById,"aria-modal":n.modal},{...e.$attrs,...e.ptm("root")}),[n.showHeader?(r.openBlock(),r.createElementBlock("div",r.mergeProps({key:0,ref:a.headerContainerRef,class:"p-dialog-header",onMousedown:t[2]||(t[2]=(...e)=>a.initDrag&&a.initDrag(...e))},e.ptm("header")),[r.renderSlot(e.$slots,"header",{},(()=>[n.header?(r.openBlock(),r.createElementBlock("span",r.mergeProps({key:0,id:a.ariaLabelledById,class:"p-dialog-title"},e.ptm("headerTitle")),r.toDisplayString(n.header),17,y)):r.createCommentVNode("",!0)])),r.createElementVNode("div",r.mergeProps({class:"p-dialog-header-icons"},e.ptm("headerIcons")),[n.maximizable?r.withDirectives((r.openBlock(),r.createElementBlock("button",r.mergeProps({key:0,ref:a.maximizableRef,autofocus:o.focusableMax,class:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:t[0]||(t[0]=(...e)=>a.maximize&&a.maximize(...e)),type:"button",tabindex:n.maximizable?"0":"-1"},e.ptm("maximizableButton")),[r.renderSlot(e.$slots,"maximizeicon",{maximized:o.maximized},(()=>[(r.openBlock(),r.createBlock(r.resolveDynamicComponent(a.maximizeIconComponent),r.mergeProps({class:a.maximizeIconClass},e.ptm("maximizableIcon")),null,16,["class"]))]))],16,x)),[[s]]):r.createCommentVNode("",!0),n.closable?r.withDirectives((r.openBlock(),r.createElementBlock("button",r.mergeProps({key:1,ref:a.closeButtonRef,autofocus:o.focusableClose,class:"p-dialog-header-icon p-dialog-header-close p-link",onClick:t[1]||(t[1]=(...e)=>a.close&&a.close(...e)),"aria-label":a.closeAriaLabel,type:"button"},{...n.closeButtonProps,...e.ptm("closeButton")}),[r.renderSlot(e.$slots,"closeicon",{},(()=>[(r.openBlock(),r.createBlock(r.resolveDynamicComponent(n.closeIcon?"span":"TimesIcon"),r.mergeProps({class:["p-dialog-header-close-icon",n.closeIcon]},e.ptm("closeButtonIcon")),null,16,["class"]))]))],16,D)),[[s]]):r.createCommentVNode("",!0)],16)],16)):r.createCommentVNode("",!0),r.createElementVNode("div",r.mergeProps({ref:a.contentRef,class:a.contentStyleClass,style:n.contentStyle},{...n.contentProps,...e.ptm("content")}),[r.renderSlot(e.$slots,"default")],16),n.footer||e.$slots.footer?(r.openBlock(),r.createElementBlock("div",r.mergeProps({key:1,ref:a.footerContainerRef,class:"p-dialog-footer"},e.ptm("footer")),[r.renderSlot(e.$slots,"footer",{},(()=>[r.createTextVNode(r.toDisplayString(n.footer),1)]))],16)):r.createCommentVNode("",!0)],16,v)),[[d,{disabled:!n.modal}]]):r.createCommentVNode("",!0)])),_:3},8,["onBeforeEnter","onEnter","onBeforeLeave","onLeave","onAfterLeave"])],16)):r.createCommentVNode("",!0)])),_:3},8,["appendTo"])},b}(primevue.basecomponent,primevue.focustrap,primevue.icons.times,primevue.icons.windowmaximize,primevue.icons.windowminimize,primevue.portal,primevue.ripple,primevue.utils,Vue);