katoikia-app/web-ui/web-react/node_modules/primereact/dialog/dialog.esm.min.js

2 lines
16 KiB
JavaScript

import e,{Component as t}from"react";import{UniqueComponentId as i,DomHandler as n,ZIndexUtils as o,classNames as s,ObjectUtils as r}from"primereact/utils";import{CSSTransition as a}from"primereact/csstransition";import{Ripple as l}from"primereact/ripple";import{Portal as d}from"primereact/portal";import c from"primereact/api";function p(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 p(e)}function m(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function h(e,t){if(e){if("string"==typeof e)return p(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)?p(e,t):void 0}}function g(){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 f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function b(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 y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){return v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},v(e,t)}function E(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&&v(e,t)}function k(e){return k="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},k(e)}function z(e,t){if(t&&("object"===k(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return y(e)}function x(e){return x=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},x(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 w,S,L,R=function(p){E(C,t);var v,k,w,S,L,R=(v=C,k=D(),function(){var e,t=x(v);if(k){var i=x(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return z(this,e)});function C(t){var n;return f(this,C),(n=R.call(this,t)).state={id:t.id,maskVisible:!1,visible:!1},n.props.onMaximize||(n.state.maximized=t.maximized),n.onClose=n.onClose.bind(y(n)),n.toggleMaximize=n.toggleMaximize.bind(y(n)),n.onDragStart=n.onDragStart.bind(y(n)),n.onResizeStart=n.onResizeStart.bind(y(n)),n.onMaskClick=n.onMaskClick.bind(y(n)),n.onEnter=n.onEnter.bind(y(n)),n.onEntered=n.onEntered.bind(y(n)),n.onExiting=n.onExiting.bind(y(n)),n.onExited=n.onExited.bind(y(n)),n.attributeSelector=i(),n.dialogRef=e.createRef(),n}return w=C,(S=[{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){n.hasClass(e.target,"p-dialog-header-icon")||n.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",n.addClass(document.body,"p-unselectable-text"),this.props.onDragStart&&this.props.onDragStart(e))}},{key:"onDrag",value:function(e){if(this.dragging){var t=n.getOuterWidth(this.dialogEl),i=n.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=n.getViewport();this.dialogEl.style.position="fixed",this.props.keepInViewport?(a>=this.props.minX&&a+t<d.width&&(this.lastPageX=e.pageX,this.dialogEl.style.left=a+"px"),l>=this.props.minY&&l+i<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,n.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,n.addClass(document.body,"p-unselectable-text"),this.props.onResizeStart&&this.props.onResizeStart(e))}},{key:"convertToPx",value:function(e,t,i){!i&&(i=n.getViewport());var o=parseInt(e);return/^(\d+|(\.\d+))(\.\d+)?%$/.test(e)?o*(i[t]/100):o}},{key:"onResize",value:function(e){if(this.resizing){var t=e.pageX-this.lastPageX,i=e.pageY-this.lastPageY,o=n.getOuterWidth(this.dialogEl),s=n.getOuterHeight(this.dialogEl),r=this.dialogEl.getBoundingClientRect(),a=n.getViewport(),l=o+t,d=s+i,c=this.convertToPx(this.dialogEl.style.minWidth,"width",a),p=this.convertToPx(this.dialogEl.style.minHeight,"height",a);(!parseInt(this.dialogEl.style.top)||!parseInt(this.dialogEl.style.left))&&(l+=t,d+=i),(!c||l>c)&&r.left+l<a.width&&(this.dialogEl.style.width=l+"px"),(!p||d>p)&&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,n.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&&n.addClass(this.mask,"p-component-overlay-leave")}},{key:"onExited",value:function(){this.dragging=!1,o.clear(this.mask),this.setState({maskVisible:!1}),this.disableDocumentSettings()}},{key:"enableDocumentSettings",value:function(){this.bindGlobalListeners(),(this.props.blockScroll||this.props.maximizable&&this.maximized)&&n.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}))||n.removeClass(document.body,"p-overflow-hidden"):(this.props.blockScroll||this.props.maximizable&&this.maximized)&&n.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(t){var i=t.currentTarget;if(i&&i.primeDialogParams){var o=i.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===t.which)e.onClose(t),t.stopImmediatePropagation(),o.splice(s-1,1);else if(9===t.which){t.preventDefault();var l=n.getFocusableElements(a);if(l&&l.length>0)if(document.activeElement){var d=l.indexOf(document.activeElement);t.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 t,i={id:this.state.id,hasBlockScroll:this.props.blockScroll};document.primeDialogParams=document.primeDialogParams?[].concat(u(t=document.primeDialogParams)||m(t)||h(t)||g(),[i]):[i],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=n.createInlineStyle(c.nonce);var e="";for(var t in this.props.breakpoints)e+="\n @media screen and (max-width: ".concat(t,") {\n .p-dialog[").concat(this.attributeSelector,"] {\n width: ").concat(this.props.breakpoints[t]," !important;\n }\n }\n ");this.styleElement.innerHTML=e}}},{key:"componentDidMount",value:function(){var e=this;this.state.id||this.setState({id:i()}),this.props.visible&&this.setState({maskVisible:!0},(function(){o.set("modal",e.mask,c.autoZIndex,e.props.baseZIndex||c.zIndex.modal),e.setState({visible:!0})})),this.props.breakpoints&&this.createStyle()}},{key:"componentDidUpdate",value:function(e){var t=this;this.props.visible&&!this.state.maskVisible&&this.setState({maskVisible:!0},(function(){o.set("modal",t.mask,c.autoZIndex,t.props.baseZIndex||c.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||n[this.maximized?"addClass":"removeClass"](document.body,"p-overflow-hidden")}},{key:"componentWillUnmount",value:function(){this.disableDocumentSettings(),this.styleElement=n.removeInlineStyle(this.styleElement),o.clear(this.mask)}},{key:"renderCloseIcon",value:function(){var t=this;return this.props.closable?e.createElement("button",{ref:function(e){return t.closeElement=e},type:"button",className:"p-dialog-header-icon p-dialog-header-close p-link","aria-label":this.props.ariaCloseIconLabel,onClick:this.onClose},e.createElement("span",{className:"p-dialog-header-close-icon pi pi-times"}),e.createElement(l,null)):null}},{key:"renderMaximizeIcon",value:function(){var t=s("p-dialog-header-maximize-icon pi",{"pi-window-maximize":!this.maximized,"pi-window-minimize":this.maximized});return this.props.maximizable?e.createElement("button",{type:"button",className:"p-dialog-header-icon p-dialog-header-maximize p-link",onClick:this.toggleMaximize},e.createElement("span",{className:t}),e.createElement(l,null)):null}},{key:"renderHeader",value:function(){var t=this;if(this.props.showHeader){var i=this.renderCloseIcon(),n=this.renderMaximizeIcon(),o=r.getJSXElement(this.props.icons,this.props),s=r.getJSXElement(this.props.header,this.props);return e.createElement("div",{ref:function(e){return t.headerEl=e},className:"p-dialog-header",onMouseDown:this.onDragStart},e.createElement("div",{id:this.state.id+"_header",className:"p-dialog-title"},s),e.createElement("div",{className:"p-dialog-header-icons"},o,n,i))}return null}},{key:"renderContent",value:function(){var t=this,i=s("p-dialog-content",this.props.contentClassName);return e.createElement("div",{id:this.state.id+"_content",ref:function(e){return t.contentEl=e},className:i,style:this.props.contentStyle},this.props.children)}},{key:"renderFooter",value:function(){var t=this,i=r.getJSXElement(this.props.footer,this.props);return i&&e.createElement("div",{ref:function(e){return t.footerElement=e},className:"p-dialog-footer"},i)}},{key:"renderResizer",value:function(){return this.props.resizable?e.createElement("div",{className:"p-resizable-handle",style:{zIndex:90},onMouseDown:this.onResizeStart}):null}},{key:"renderElement",value:function(){var t=this,i=s("p-dialog p-component",this.props.className,{"p-dialog-rtl":this.props.rtl,"p-dialog-maximized":this.maximized}),n=s("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()),o=this.renderHeader(),r=this.renderContent(),l=this.renderFooter(),d=this.renderResizer();return e.createElement("div",{ref:function(e){return t.mask=e},style:this.props.maskStyle,className:n,onClick:this.onMaskClick},e.createElement(a,{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},e.createElement("div",{ref:this.dialogRef,id:this.state.id,className:i,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},o,r,l,d)))}},{key:"render",value:function(){if(this.state.maskVisible){var t=this.renderElement();return e.createElement(d,{element:t,appendTo:this.props.appendTo,visible:!0})}return null}}])&&b(w.prototype,S),L&&b(w,L),Object.defineProperty(w,"prototype",{writable:!1}),C}();L={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},(S="defaultProps")in(w=R)?Object.defineProperty(w,S,{value:L,enumerable:!0,configurable:!0,writable:!0}):w[S]=L;export{R as Dialog};