2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),i=require("primereact/csstransition"),n=require("primereact/ripple"),o=require("primereact/portal"),s=require("primereact/api");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=r(e),l=r(s);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function u(e){if(Array.isArray(e))return d(e)}function c(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function p(e,t){if(e){if("string"==typeof e)return d(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?d(e,t):void 0}}function m(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function g(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e,t){return b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},b(e,t)}function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&b(e,t)}function v(e){return v="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},v(e)}function E(e,t){if(t&&("object"===v(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return f(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function D(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var z,x,w,S=function(s){y(w,e.Component);var r,d,b,v,z,x=(r=w,d=D(),function(){var e,t=k(r);if(d){var i=k(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return E(this,e)});function w(e){var i;return h(this,w),(i=x.call(this,e)).state={id:e.id,maskVisible:!1,visible:!1},i.props.onMaximize||(i.state.maximized=e.maximized),i.onClose=i.onClose.bind(f(i)),i.toggleMaximize=i.toggleMaximize.bind(f(i)),i.onDragStart=i.onDragStart.bind(f(i)),i.onResizeStart=i.onResizeStart.bind(f(i)),i.onMaskClick=i.onMaskClick.bind(f(i)),i.onEnter=i.onEnter.bind(f(i)),i.onEntered=i.onEntered.bind(f(i)),i.onExiting=i.onExiting.bind(f(i)),i.onExited=i.onExited.bind(f(i)),i.attributeSelector=t.UniqueComponentId(),i.dialogRef=a.default.createRef(),i}return b=w,(v=[{key:"onClose",value:function(e){this.props.onHide(),e.preventDefault()}},{key:"focus",value:function(){var e=document.activeElement;!(e&&this.dialogRef&&this.dialogRef.current.contains(e))&&this.props.closable&&this.props.showHeader&&this.closeElement.focus()}},{key:"onMaskClick",value:function(e){this.props.dismissableMask&&this.props.modal&&this.mask===e.target&&this.onClose(e),this.props.onMaskClick&&this.props.onMaskClick(e)}},{key:"toggleMaximize",value:function(e){var t=!this.maximized;this.props.onMaximize?this.props.onMaximize({originalEvent:e,maximized:t}):this.setState({maximized:t},this.changeScrollOnMaximizable),e.preventDefault()}},{key:"onDragStart",value:function(e){t.DomHandler.hasClass(e.target,"p-dialog-header-icon")||t.DomHandler.hasClass(e.target.parentElement,"p-dialog-header-icon")||this.props.draggable&&(this.dragging=!0,this.lastPageX=e.pageX,this.lastPageY=e.pageY,this.dialogEl.style.margin="0",t.DomHandler.addClass(document.body,"p-unselectable-text"),this.props.onDragStart&&this.props.onDragStart(e))}},{key:"onDrag",value:function(e){if(this.dragging){var i=t.DomHandler.getOuterWidth(this.dialogEl),n=t.DomHandler.getOuterHeight(this.dialogEl),o=e.pageX-this.lastPageX,s=e.pageY-this.lastPageY,r=this.dialogEl.getBoundingClientRect(),a=r.left+o,l=r.top+s,d=t.DomHandler.getViewport();this.dialogEl.style.position="fixed",this.props.keepInViewport?(a>=this.props.minX&&a+i<d.width&&(this.lastPageX=e.pageX,this.dialogEl.style.left=a+"px"),l>=this.props.minY&&l+n<d.height&&(this.lastPageY=e.pageY,this.dialogEl.style.top=l+"px")):(this.lastPageX=e.pageX,this.dialogEl.style.left=a+"px",this.lastPageY=e.pageY,this.dialogEl.style.top=l+"px"),this.props.onDrag&&this.props.onDrag(e)}}},{key:"onDragEnd",value:function(e){this.dragging&&(this.dragging=!1,t.DomHandler.removeClass(document.body,"p-unselectable-text"),this.props.onDragEnd&&this.props.onDragEnd(e))}},{key:"onResizeStart",value:function(e){this.props.resizable&&(this.resizing=!0,this.lastPageX=e.pageX,this.lastPageY=e.pageY,t.DomHandler.addClass(document.body,"p-unselectable-text"),this.props.onResizeStart&&this.props.onResizeStart(e))}},{key:"convertToPx",value:function(e,i,n){!n&&(n=t.DomHandler.getViewport());var o=parseInt(e);return/^(\d+|(\.\d+))(\.\d+)?%$/.test(e)?o*(n[i]/100):o}},{key:"onResize",value:function(e){if(this.resizing){var i=e.pageX-this.lastPageX,n=e.pageY-this.lastPageY,o=t.DomHandler.getOuterWidth(this.dialogEl),s=t.DomHandler.getOuterHeight(this.dialogEl),r=this.dialogEl.getBoundingClientRect(),a=t.DomHandler.getViewport(),l=o+i,d=s+n,u=this.convertToPx(this.dialogEl.style.minWidth,"width",a),c=this.convertToPx(this.dialogEl.style.minHeight,"height",a);(!parseInt(this.dialogEl.style.top)||!parseInt(this.dialogEl.style.left))&&(l+=i,d+=n),(!u||l>u)&&r.left+l<a.width&&(this.dialogEl.style.width=l+"px"),(!c||d>c)&&r.top+d<a.height&&(this.dialogEl.style.height=d+"px"),this.lastPageX=e.pageX,this.lastPageY=e.pageY,this.props.onResize&&this.props.onResize(e)}}},{key:"onResizeEnd",value:function(e){this.resizing&&(this.resizing=!1,t.DomHandler.removeClass(document.body,"p-unselectable-text"),this.props.onResizeEnd&&this.props.onResizeEnd(e))}},{key:"resetPosition",value:function(){this.dialogEl.style.position="",this.dialogEl.style.left="",this.dialogEl.style.top="",this.dialogEl.style.margin=""}},{key:"getPositionClass",value:function(){var e=this,t=["center","left","right","top","top-left","top-right","bottom","bottom-left","bottom-right"].find((function(t){return t===e.props.position||t.replace("-","")===e.props.position}));return t?"p-dialog-".concat(t):""}},{key:"maximized",get:function(){return this.props.onMaximize?this.props.maximized:this.state.maximized}},{key:"dialogEl",get:function(){return this.dialogRef.current}},{key:"onEnter",value:function(){this.dialogEl.setAttribute(this.attributeSelector,"")}},{key:"onEntered",value:function(){this.props.onShow&&this.props.onShow(),this.props.focusOnShow&&this.focus(),this.enableDocumentSettings()}},{key:"onExiting",value:function(){this.props.modal&&t.DomHandler.addClass(this.mask,"p-component-overlay-leave")}},{key:"onExited",value:function(){this.dragging=!1,t.ZIndexUtils.clear(this.mask),this.setState({maskVisible:!1}),this.disableDocumentSettings()}},{key:"enableDocumentSettings",value:function(){this.bindGlobalListeners(),(this.props.blockScroll||this.props.maximizable&&this.maximized)&&t.DomHandler.addClass(document.body,"p-overflow-hidden")}},{key:"disableDocumentSettings",value:function(){this.unbindGlobalListeners(),this.props.modal?document.primeDialogParams&&document.primeDialogParams.some((function(e){return e.hasBlockScroll}))||t.DomHandler.removeClass(document.body,"p-overflow-hidden"):(this.props.blockScroll||this.props.maximizable&&this.maximized)&&t.DomHandler.removeClass(document.body,"p-overflow-hidden")}},{key:"bindGlobalListeners",value:function(){this.props.draggable&&this.bindDocumentDragListener(),this.props.resizable&&this.bindDocumentResizeListeners(),this.props.closable&&this.bindDocumentKeyDownListener()}},{key:"unbindGlobalListeners",value:function(){this.unbindDocumentDragListener(),this.unbindDocumentResizeListeners(),this.unbindDocumentKeyDownListener()}},{key:"bindDocumentDragListener",value:function(){this.documentDragListener=this.onDrag.bind(this),this.documentDragEndListener=this.onDragEnd.bind(this),window.document.addEventListener("mousemove",this.documentDragListener),window.document.addEventListener("mouseup",this.documentDragEndListener)}},{key:"unbindDocumentDragListener",value:function(){this.documentDragListener&&this.documentDragEndListener&&(window.document.removeEventListener("mousemove",this.documentDragListener),window.document.removeEventListener("mouseup",this.documentDragEndListener),this.documentDragListener=null,this.documentDragEndListener=null)}},{key:"bindDocumentResizeListeners",value:function(){this.documentResizeListener=this.onResize.bind(this),this.documentResizeEndListener=this.onResizeEnd.bind(this),window.document.addEventListener("mousemove",this.documentResizeListener),window.document.addEventListener("mouseup",this.documentResizeEndListener)}},{key:"unbindDocumentResizeListeners",value:function(){this.documentResizeListener&&this.documentResizeEndListener&&(window.document.removeEventListener("mousemove",this.documentResizeListener),window.document.removeEventListener("mouseup",this.documentResizeEndListener),this.documentResizeListener=null,this.documentResizeEndListener=null)}},{key:"bindDocumentKeyDownListener",value:function(){var e=this;this.documentKeyDownListener=function(i){var n=i.currentTarget;if(n&&n.primeDialogParams){var o=n.primeDialogParams,s=o.length,r=o[s-1]?o[s-1].id:void 0;if(r===e.state.id&&e.props.closeOnEscape){var a=document.getElementById(r);if(27===i.which)e.onClose(i),i.stopImmediatePropagation(),o.splice(s-1,1);else if(9===i.which){i.preventDefault();var l=t.DomHandler.getFocusableElements(a);if(l&&l.length>0)if(document.activeElement){var d=l.indexOf(document.activeElement);i.shiftKey?-1===d||0===d?l[l.length-1].focus():l[d-1].focus():-1===d||d===l.length-1?l[0].focus():l[d+1].focus()}else l[0].focus()}}}};var i,n={id:this.state.id,hasBlockScroll:this.props.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(u(i=document.primeDialogParams)||c(i)||p(i)||m(),[n]):[n],document.addEventListener("keydown",this.documentKeyDownListener)}},{key:"unbindDocumentKeyDownListener",value:function(){var e=this;this.documentKeyDownListener&&(document.removeEventListener("keydown",this.documentKeyDownListener),document.primeDialogParams=document.primeDialogParams&&document.primeDialogParams.filter((function(t){return t.id!==e.state.id})),this.documentKeyDownListener=null)}},{key:"createStyle",value:function(){if(!this.styleElement){this.styleElement=t.DomHandler.createInlineStyle(l.default.nonce);var e="";for(var i in this.props.breakpoints)e+="\n @media screen and (max-width: ".concat(i,") {\n .p-dialog[").concat(this.attributeSelector,"] {\n width: ").concat(this.props.breakpoints[i]," !important;\n }\n }\n ");this.styleElement.innerHTML=e}}},{key:"componentDidMount",value:function(){var e=this;this.state.id||this.setState({id:t.UniqueComponentId()}),this.props.visible&&this.setState({maskVisible:!0},(function(){t.ZIndexUtils.set("modal",e.mask,l.default.autoZIndex,e.props.baseZIndex||l.default.zIndex.modal),e.setState({visible:!0})})),this.props.breakpoints&&this.createStyle()}},{key:"componentDidUpdate",value:function(e){var i=this;this.props.visible&&!this.state.maskVisible&&this.setState({maskVisible:!0},(function(){t.ZIndexUtils.set("modal",i.mask,l.default.autoZIndex,i.props.baseZIndex||l.default.zIndex.modal)})),this.props.visible!==this.state.visible&&this.state.maskVisible&&this.setState({visible:this.props.visible}),e.maximized!==this.props.maximized&&this.props.onMaximize&&this.changeScrollOnMaximizable()}},{key:"changeScrollOnMaximizable",value:function(){this.props.blockScroll||t.DomHandler[this.maximized?"addClass":"removeClass"](document.body,"p-overflow-hidden")}},{key:"componentWillUnmount",value:function(){this.disableDocumentSettings(),this.styleElement=t.DomHandler.removeInlineStyle(this.styleElement),t.ZIndexUtils.clear(this.mask)}},{key:"renderCloseIcon",value:function(){var e=this;return this.props.closable?a.default.createElement("button",{ref:function(t){return e.closeElement=t},type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":this.props.ariaCloseIconLabel,onClick:this.onClose},a.default.createElement("span",{className:"p-dialog-header-close-icon pi pi-times"}),a.default.createElement(n.Ripple,null)):null}},{key:"renderMaximizeIcon",value:function(){var e=t.classNames("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!this.maximized,"pi-window-minimize":this.maximized});return this.props.maximizable?a.default.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:this.toggleMaximize},a.default.createElement("span",{className:e}),a.default.createElement(n.Ripple,null)):null}},{key:"renderHeader",value:function(){var e=this;if(this.props.showHeader){var i=this.renderCloseIcon(),n=this.renderMaximizeIcon(),o=t.ObjectUtils.getJSXElement(this.props.icons,this.props),s=t.ObjectUtils.getJSXElement(this.props.header,this.props);return a.default.createElement("div",{ref:function(t){return e.headerEl=t},className:"p-dialog-header",onMouseDown:this.onDragStart},a.default.createElement("div",{id:this.state.id+"_header",className:"p-dialog-title"},s),a.default.createElement("div",{className:"p-dialog-header-icons"},o,n,i))}return null}},{key:"renderContent",value:function(){var e=this,i=t.classNames("p-dialog-content",this.props.contentClassName);return a.default.createElement("div",{id:this.state.id+"_content",ref:function(t){return e.contentEl=t},className:i,style:this.props.contentStyle},this.props.children)}},{key:"renderFooter",value:function(){var e=this,i=t.ObjectUtils.getJSXElement(this.props.footer,this.props);return i&&a.default.createElement("div",{ref:function(t){return e.footerElement=t},className:"p-dialog-footer"},i)}},{key:"renderResizer",value:function(){return this.props.resizable?a.default.createElement("div",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:this.onResizeStart}):null}},{key:"renderElement",value:function(){var e=this,n=t.classNames("p-dialog p-component",this.props.className,{"p-dialog-rtl":this.props.rtl,"p-dialog-maximized":this.maximized}),o=t.classNames("p-dialog-mask",{"p-component-overlay p-component-overlay-enter":this.props.modal,"p-dialog-visible":this.state.maskVisible,"p-dialog-draggable":this.props.draggable,"p-dialog-resizable":this.props.resizable},this.props.maskClassName,this.getPositionClass()),s=this.renderHeader(),r=this.renderContent(),l=this.renderFooter(),d=this.renderResizer();return a.default.createElement("div",{ref:function(t){return e.mask=t},style:this.props.maskStyle,className:o,onClick:this.onMaskClick},a.default.createElement(i.CSSTransition,{nodeRef:this.dialogRef,classNames:"p-dialog",timeout:{enter:"center"===this.props.position?150:300,exit:"center"===this.props.position?150:300},in:this.state.visible,options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExiting:this.onExiting,onExited:this.onExited},a.default.createElement("div",{ref:this.dialogRef,id:this.state.id,className:n,style:this.props.style,onClick:this.props.onClick,role:"dialog","aria-labelledby":this.state.id+"_header","aria-describedby":this.state.id+"_content","aria-modal":this.props.modal},s,r,l,d)))}},{key:"render",value:function(){if(this.state.maskVisible){var e=this.renderElement();return a.default.createElement(o.Portal,{element:e,appendTo:this.props.appendTo,visible:!0})}return null}}])&&g(b.prototype,v),z&&g(b,z),Object.defineProperty(b,"prototype",{writable:!1}),w}();w={id:null,header:null,footer:null,visible:!1,position:"center",draggable:!0,resizable:!0,modal:!0,onHide:null,onShow:null,contentStyle:null,contentClassName:null,closeOnEscape:!0,dismissableMask:!1,rtl:!1,closable:!0,style:null,className:null,maskStyle:null,maskClassName:null,showHeader:!0,appendTo:null,baseZIndex:0,maximizable:!1,blockScroll:!1,icons:null,ariaCloseIconLabel:"Close",focusOnShow:!0,minX:0,minY:0,keepInViewport:!0,maximized:!1,breakpoints:null,transitionOptions:null,onMaximize:null,onDragStart:null,onDrag:null,onDragEnd:null,onResizeStart:null,onResize:null,onResizeEnd:null,onClick:null,onMaskClick:null},(x="defaultProps")in(z=S)?Object.defineProperty(z,x,{value:w,enumerable:!0,configurable:!0,writable:!0}):z[x]=w,exports.Dialog=S;
|