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

2 lines
9.6 KiB
JavaScript

import e,{Component as t}from"react";import n from"react-dom";import{DomHandler as i,ConnectedOverlayScrollHandler as r,ZIndexUtils as o,ObjectUtils as s,IconUtils as c,classNames as l}from"primereact/utils";import{Button as a}from"primereact/button";import{CSSTransition as p}from"primereact/csstransition";import u,{localeOption as f}from"primereact/api";import{OverlayService as h}from"primereact/overlayservice";import{Portal as d}from"primereact/portal";function v(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function y(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 k(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 E(e){return E="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},E(e)}function L(e,t){if(t&&("object"===E(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 j(e){return j=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},j(e)}function C(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function O(){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}}function g(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 R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){C(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function w(t){var r=t.appendTo||document.body,o=document.createDocumentFragment();i.appendChild(o,r),t=R(R({},t),{visible:void 0===t.visible||t.visible});var s=e.createElement(P,t);n.render(s,o);var c=function(i){t=R(R({},t),i),n.render(e.cloneElement(s,t),o)};return{_destroy:function(){n.unmountComponentAtNode(o)},show:function(){c({visible:!0,onHide:function(){c({visible:!1})}})},hide:function(){c({visible:!1})},update:function(e){c(e)}}}var P=function(n){k(P,t);var b,E,C,g,R,w=(b=P,E=O(),function(){var e,t=j(b);if(E){var n=j(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return L(this,e)});function P(t){var n;return v(this,P),(n=w.call(this,t)).state={visible:!1},n.reject=n.reject.bind(y(n)),n.accept=n.accept.bind(y(n)),n.hide=n.hide.bind(y(n)),n.onCloseClick=n.onCloseClick.bind(y(n)),n.onPanelClick=n.onPanelClick.bind(y(n)),n.onEnter=n.onEnter.bind(y(n)),n.onEntered=n.onEntered.bind(y(n)),n.onExit=n.onExit.bind(y(n)),n.onExited=n.onExited.bind(y(n)),n.overlayRef=e.createRef(),n.acceptBtnRef=e.createRef(),n}return C=P,(g=[{key:"acceptLabel",value:function(){return this.props.acceptLabel||f("accept")}},{key:"rejectLabel",value:function(){return this.props.rejectLabel||f("reject")}},{key:"bindDocumentClickListener",value:function(){var e=this;!this.documentClickListener&&this.props.dismissable&&(this.documentClickListener=function(t){!e.isPanelClicked&&e.isOutsideClicked(t.target)&&e.hide(),e.isPanelClicked=!1},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new r(this.props.target,(function(){e.state.visible&&e.hide()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.visible&&!i.isTouchDevice()&&e.hide()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.overlayRef&&this.overlayRef.current&&!(this.overlayRef.current.isSameNode(e)||this.overlayRef.current.contains(e))}},{key:"onCloseClick",value:function(e){this.hide(),e.preventDefault()}},{key:"onPanelClick",value:function(e){this.isPanelClicked=!0,h.emit("overlay-click",{originalEvent:e,target:this.props.target})}},{key:"accept",value:function(){this.props.accept&&this.props.accept(),this.hide("accept")}},{key:"reject",value:function(){this.props.reject&&this.props.reject(),this.hide("reject")}},{key:"show",value:function(){var e=this;this.setState({visible:!0},(function(){e.overlayEventListener=function(t){e.isOutsideClicked(t.target)||(e.isPanelClicked=!0)},h.on("overlay-click",e.overlayEventListener)}))}},{key:"hide",value:function(e){var t=this;this.setState({visible:!1},(function(){h.off("overlay-click",t.overlayEventListener),t.overlayEventListener=null,t.props.onHide&&t.props.onHide(e)}))}},{key:"onEnter",value:function(){o.set("overlay",this.overlayRef.current,u.autoZIndex,u.zIndex.overlay),this.align()}},{key:"onEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.acceptBtnRef&&this.acceptBtnRef.current&&this.acceptBtnRef.current.focus(),this.props.onShow&&this.props.onShow()}},{key:"onExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onExited",value:function(){o.clear(this.overlayRef.current)}},{key:"align",value:function(){if(this.props.target){i.absolutePosition(this.overlayRef.current,this.props.target);var e=i.getOffset(this.overlayRef.current),t=i.getOffset(this.props.target),n=0;e.left<t.left&&(n=t.left-e.left),this.overlayRef.current.style.setProperty("--overlayArrowLeft","".concat(n,"px")),e.top<t.top&&i.addClass(this.overlayRef.current,"p-confirm-popup-flipped")}}},{key:"componentDidMount",value:function(){this.props.visible&&this.setState({visible:!0})}},{key:"componentDidUpdate",value:function(e){e.visible!==this.props.visible&&this.setState({visible:this.props.visible})}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.overlayEventListener&&(h.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null),o.clear(this.overlayRef.current)}},{key:"renderContent",value:function(){var t=s.getJSXElement(this.props.message,this.props);return e.createElement("div",{className:"p-confirm-popup-content"},c.getJSXIcon(this.props.icon,{className:"p-confirm-popup-icon"},{props:this.props}),e.createElement("span",{className:"p-confirm-popup-message"},t))}},{key:"renderFooter",value:function(){var t=l("p-confirm-popup-accept p-button-sm",this.props.acceptClassName),n=l("p-confirm-popup-reject p-button-sm",{"p-button-text":!this.props.rejectClassName},this.props.rejectClassName),i=e.createElement("div",{className:"p-confirm-popup-footer"},e.createElement(a,{label:this.rejectLabel(),icon:this.props.rejectIcon,className:n,onClick:this.reject}),e.createElement(a,{ref:this.acceptBtnRef,label:this.acceptLabel(),icon:this.props.acceptIcon,className:t,onClick:this.accept}));if(this.props.footer){var r={accept:this.accept,reject:this.reject,className:"p-confirm-popup-footer",acceptClassName:t,rejectClassName:n,acceptLabel:this.acceptLabel(),rejectLabel:this.rejectLabel(),element:i,props:this.props};return s.getJSXElement(this.props.footer,r)}return i}},{key:"renderElement",value:function(){var t=l("p-confirm-popup p-component",this.props.className),n=this.renderContent(),i=this.renderFooter();return e.createElement(p,{nodeRef:this.overlayRef,classNames:"p-connected-overlay",in:this.state.visible,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExit:this.onExit,onExited:this.onExited},e.createElement("div",{ref:this.overlayRef,id:this.props.id,className:t,style:this.props.style,onClick:this.onPanelClick},n,i))}},{key:"render",value:function(){var t=this.renderElement();return e.createElement(d,{element:t,appendTo:this.props.appendTo,visible:this.props.visible})}}])&&m(C.prototype,g),R&&m(C,R),Object.defineProperty(C,"prototype",{writable:!1}),P}();C(P,"defaultProps",{target:null,visible:!1,message:null,rejectLabel:null,acceptLabel:null,icon:null,rejectIcon:null,acceptIcon:null,rejectClassName:null,acceptClassName:null,className:null,style:null,appendTo:null,dismissable:!0,footer:null,onShow:null,onHide:null,accept:null,reject:null,transitionOptions:null});export{P as ConfirmPopup,w as confirmPopup};