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) • 10.1 kB
JavaScript
"use strict";var e=require("primevue/focustrap"),t=require("primevue/icons/times"),n=require("primevue/overlayeventbus"),i=require("primevue/portal"),o=require("primevue/ripple"),r=require("primevue/utils"),s=require("primevue/basecomponent"),l=require("primevue/overlaypanel/style"),c=require("vue");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(e),d=a(t),h=a(n),f=a(i),p=a(o),v={name:"OverlayPanel",extends:{name:"BaseOverlayPanel",extends:a(s).default,props:{dismissable:{type:Boolean,default:!0},showCloseIcon:{type:Boolean,default:!1},appendTo:{type:String,default:"body"},baseZIndex:{type:Number,default:0},autoZIndex:{type:Boolean,default:!0},breakpoints:{type:Object,default:null},closeIcon:{type:String,default:void 0},closeOnEscape:{type:Boolean,default:!0}},style:a(l).default,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,emits:["show","hide"],data:function(){return{visible:!1}},watch:{dismissable:{immediate:!0,handler:function(e){e?this.bindOutsideClickListener():this.unbindOutsideClickListener()}}},selfClick:!1,target:null,eventTarget:null,outsideClickListener:null,scrollHandler:null,resizeListener:null,container:null,styleElement:null,overlayEventListener:null,documentKeydownListener:null,beforeUnmount:function(){this.dismissable&&this.unbindOutsideClickListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.destroyStyle(),this.unbindResizeListener(),this.target=null,this.container&&this.autoZIndex&&r.ZIndexUtils.clear(this.container),this.overlayEventListener&&(h.default.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null),this.container=null},mounted:function(){this.breakpoints&&this.createStyle()},methods:{toggle:function(e,t){this.visible?this.hide():this.show(e,t)},show:function(e,t){this.visible=!0,this.eventTarget=e.currentTarget,this.target=t||e.currentTarget},hide:function(){this.visible=!1},onContentClick:function(){this.selfClick=!0},onEnter:function(e){var t=this;this.container.setAttribute(this.attributeSelector,""),r.DomHandler.addStyles(e,{position:"absolute",top:"0",left:"0"}),this.alignOverlay(),this.dismissable&&this.bindOutsideClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.autoZIndex&&r.ZIndexUtils.set("overlay",e,this.baseZIndex+this.$primevue.config.zIndex.overlay),this.overlayEventListener=function(e){t.container.contains(e.target)&&(t.selfClick=!0)},this.focus(),h.default.on("overlay-click",this.overlayEventListener),this.$emit("show"),this.closeOnEscape&&this.bindDocumentKeyDownListener()},onLeave:function(){this.unbindOutsideClickListener(),this.unbindScrollListener(),this.unbindResizeListener(),this.unbindDocumentKeyDownListener(),h.default.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null,this.$emit("hide")},onAfterLeave:function(e){this.autoZIndex&&r.ZIndexUtils.clear(e)},alignOverlay:function(){r.DomHandler.absolutePosition(this.container,this.target);var e=r.DomHandler.getOffset(this.container),t=r.DomHandler.getOffset(this.target),n=0;e.left<t.left&&(n=t.left-e.left),this.container.style.setProperty("--overlayArrowLeft","".concat(n,"px")),e.top<t.top&&(this.container.setAttribute("data-p-overlaypanel-flipped","true"),!this.isUnstyled&&r.DomHandler.addClass(this.container,"p-overlaypanel-flipped"))},onContentKeydown:function(e){"Escape"===e.code&&this.closeOnEscape&&(this.hide(),r.DomHandler.focus(this.target))},onButtonKeydown:function(e){switch(e.code){case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":e.preventDefault()}},focus:function(){var e=this.container.querySelector("[autofocus]");e&&e.focus()},onKeyDown:function(e){"Escape"===e.code&&this.closeOnEscape&&(this.visible=!1)},bindDocumentKeyDownListener:function(){this.documentKeydownListener||(this.documentKeydownListener=this.onKeyDown.bind(this),window.document.addEventListener("keydown",this.documentKeydownListener))},unbindDocumentKeyDownListener:function(){this.documentKeydownListener&&(window.document.removeEventListener("keydown",this.documentKeydownListener),this.documentKeydownListener=null)},bindOutsideClickListener:function(){var e=this;!this.outsideClickListener&&r.DomHandler.isClient()&&(this.outsideClickListener=function(t){!e.visible||e.selfClick||e.isTargetClicked(t)||(e.visible=!1),e.selfClick=!1},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null,this.selfClick=!1)},bindScrollListener:function(){var e=this;this.scrollHandler||(this.scrollHandler=new r.ConnectedOverlayScrollHandler(this.target,(function(){e.visible&&(e.visible=!1)}))),this.scrollHandler.bindScrollListener()},unbindScrollListener:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.visible&&!r.DomHandler.isTouchDevice()&&(e.visible=!1)},window.addEventListener("resize",this.resizeListener))},unbindResizeListener:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},isTargetClicked:function(e){return this.eventTarget&&(this.eventTarget===e.target||this.eventTarget.contains(e.target))},containerRef:function(e){this.container=e},createStyle:function(){if(!this.styleElement&&!this.isUnstyled){var e;this.styleElement=document.createElement("style"),this.styleElement.type="text/css",r.DomHandler.setAttribute(this.styleElement,"nonce",null===(e=this.$primevue)||void 0===e||null===(e=e.config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce),document.head.appendChild(this.styleElement);var t="";for(var n in this.breakpoints)t+="\n @media screen and (max-width: ".concat(n,") {\n .p-overlaypanel[").concat(this.attributeSelector,"] {\n width: ").concat(this.breakpoints[n]," !important;\n }\n }\n ");this.styleElement.innerHTML=t}},destroyStyle:function(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)},onOverlayClick:function(e){h.default.emit("overlay-click",{originalEvent:e,target:this.target})}},computed:{attributeSelector:function(){return r.UniqueComponentId()},closeAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.close:void 0}},directives:{focustrap:u.default,ripple:p.default},components:{Portal:f.default,TimesIcon:d.default}};function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function m(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?m(Object(n),!0).forEach((function(t){L(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function L(e,t,n){var i;return(t="symbol"==y(i=w(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function w(e,t){if("object"!=y(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=y(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var k=["aria-modal"],C=["aria-label"];v.render=function(e,t,n,i,o,r){var s=c.resolveComponent("Portal"),l=c.resolveDirective("ripple"),a=c.resolveDirective("focustrap");return c.openBlock(),c.createBlock(s,{appendTo:e.appendTo},{default:c.withCtx((function(){return[c.createVNode(c.Transition,c.mergeProps({name:"p-overlaypanel",onEnter:r.onEnter,onLeave:r.onLeave,onAfterLeave:r.onAfterLeave},e.ptm("transition")),{default:c.withCtx((function(){return[o.visible?c.withDirectives((c.openBlock(),c.createElementBlock("div",c.mergeProps({key:0,ref:r.containerRef,role:"dialog","aria-modal":o.visible,onClick:t[5]||(t[5]=function(){return r.onOverlayClick&&r.onOverlayClick.apply(r,arguments)}),class:e.cx("root")},b(b({},e.$attrs),e.ptm("root"))),[e.$slots.container?c.renderSlot(e.$slots,"container",{key:0,onClose:r.hide,onKeydown:function(e){return r.onButtonKeydown(e)},closeCallback:r.hide,keydownCallback:function(e){return r.onButtonKeydown(e)}}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createElementVNode("div",c.mergeProps({class:e.cx("content"),onClick:t[0]||(t[0]=function(){return r.onContentClick&&r.onContentClick.apply(r,arguments)}),onMousedown:t[1]||(t[1]=function(){return r.onContentClick&&r.onContentClick.apply(r,arguments)}),onKeydown:t[2]||(t[2]=function(){return r.onContentKeydown&&r.onContentKeydown.apply(r,arguments)})},e.ptm("content")),[c.renderSlot(e.$slots,"default")],16),e.showCloseIcon?c.withDirectives((c.openBlock(),c.createElementBlock("button",c.mergeProps({key:0,class:e.cx("closeButton"),"aria-label":r.closeAriaLabel,type:"button",autofocus:"",onClick:t[3]||(t[3]=function(){return r.hide&&r.hide.apply(r,arguments)}),onKeydown:t[4]||(t[4]=function(){return r.onButtonKeydown&&r.onButtonKeydown.apply(r,arguments)})},e.ptm("closeButton")),[c.renderSlot(e.$slots,"closeicon",{},(function(){return[(c.openBlock(),c.createBlock(c.resolveDynamicComponent(e.closeIcon?"span":"TimesIcon"),c.mergeProps({class:[e.cx("closeIcon"),e.closeIcon]},e.ptm("closeIcon")),null,16,["class"]))]}))],16,C)),[[l]]):c.createCommentVNode("",!0)],64))],16,k)),[[a]]):c.createCommentVNode("",!0)]})),_:3},16,["onEnter","onLeave","onAfterLeave"])]})),_:3},8,["appendTo"])},module.exports=v;