2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-dom"),n=require("primereact/utils"),r=require("primereact/button"),i=require("primereact/csstransition"),o=require("primereact/api"),s=require("primereact/overlayservice"),l=require("primereact/portal");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=c(e),u=c(t),p=c(o);function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(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 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&&v(e,t)}function b(e){return b="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},b(e)}function m(e,t){if(t&&("object"===b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return h(e)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function E(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function L(){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 j(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function O(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?j(Object(n),!0).forEach((function(t){E(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var C=function(t){y(O,e.Component);var c,u,v,b,E,j=(c=O,u=L(),function(){var e,t=k(c);if(u){var n=k(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return m(this,e)});function O(e){var t;return f(this,O),(t=j.call(this,e)).state={visible:!1},t.reject=t.reject.bind(h(t)),t.accept=t.accept.bind(h(t)),t.hide=t.hide.bind(h(t)),t.onCloseClick=t.onCloseClick.bind(h(t)),t.onPanelClick=t.onPanelClick.bind(h(t)),t.onEnter=t.onEnter.bind(h(t)),t.onEntered=t.onEntered.bind(h(t)),t.onExit=t.onExit.bind(h(t)),t.onExited=t.onExited.bind(h(t)),t.overlayRef=a.default.createRef(),t.acceptBtnRef=a.default.createRef(),t}return v=O,(b=[{key:"acceptLabel",value:function(){return this.props.acceptLabel||o.localeOption("accept")}},{key:"rejectLabel",value:function(){return this.props.rejectLabel||o.localeOption("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 n.ConnectedOverlayScrollHandler(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&&!n.DomHandler.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,s.OverlayService.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)},s.OverlayService.on("overlay-click",e.overlayEventListener)}))}},{key:"hide",value:function(e){var t=this;this.setState({visible:!1},(function(){s.OverlayService.off("overlay-click",t.overlayEventListener),t.overlayEventListener=null,t.props.onHide&&t.props.onHide(e)}))}},{key:"onEnter",value:function(){n.ZIndexUtils.set("overlay",this.overlayRef.current,p.default.autoZIndex,p.default.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(){n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"align",value:function(){if(this.props.target){n.DomHandler.absolutePosition(this.overlayRef.current,this.props.target);var e=n.DomHandler.getOffset(this.overlayRef.current),t=n.DomHandler.getOffset(this.props.target),r=0;e.left<t.left&&(r=t.left-e.left),this.overlayRef.current.style.setProperty("--overlayArrowLeft","".concat(r,"px")),e.top<t.top&&n.DomHandler.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&&(s.OverlayService.off("overlay-click",this.overlayEventListener),this.overlayEventListener=null),n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderContent",value:function(){var e=n.ObjectUtils.getJSXElement(this.props.message,this.props);return a.default.createElement("div",{className:"p-confirm-popup-content"},n.IconUtils.getJSXIcon(this.props.icon,{className:"p-confirm-popup-icon"},{props:this.props}),a.default.createElement("span",{className:"p-confirm-popup-message"},e))}},{key:"renderFooter",value:function(){var e=n.classNames("p-confirm-popup-accept p-button-sm",this.props.acceptClassName),t=n.classNames("p-confirm-popup-reject p-button-sm",{"p-button-text":!this.props.rejectClassName},this.props.rejectClassName),i=a.default.createElement("div",{className:"p-confirm-popup-footer"},a.default.createElement(r.Button,{label:this.rejectLabel(),icon:this.props.rejectIcon,className:t,onClick:this.reject}),a.default.createElement(r.Button,{ref:this.acceptBtnRef,label:this.acceptLabel(),icon:this.props.acceptIcon,className:e,onClick:this.accept}));if(this.props.footer){var o={accept:this.accept,reject:this.reject,className:"p-confirm-popup-footer",acceptClassName:e,rejectClassName:t,acceptLabel:this.acceptLabel(),rejectLabel:this.rejectLabel(),element:i,props:this.props};return n.ObjectUtils.getJSXElement(this.props.footer,o)}return i}},{key:"renderElement",value:function(){var e=n.classNames("p-confirm-popup p-component",this.props.className),t=this.renderContent(),r=this.renderFooter();return a.default.createElement(i.CSSTransition,{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},a.default.createElement("div",{ref:this.overlayRef,id:this.props.id,className:e,style:this.props.style,onClick:this.onPanelClick},t,r))}},{key:"render",value:function(){var e=this.renderElement();return a.default.createElement(l.Portal,{element:e,appendTo:this.props.appendTo,visible:this.props.visible})}}])&&d(v.prototype,b),E&&d(v,E),Object.defineProperty(v,"prototype",{writable:!1}),O}();E(C,"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}),exports.ConfirmPopup=C,exports.confirmPopup=function(e){var t=e.appendTo||document.body,r=document.createDocumentFragment();n.DomHandler.appendChild(r,t),e=O(O({},e),{visible:void 0===e.visible||e.visible});var i=a.default.createElement(C,e);u.default.render(i,r);var o=function(t){e=O(O({},e),t),u.default.render(a.default.cloneElement(i,e),r)};return{_destroy:function(){u.default.unmountComponentAtNode(r)},show:function(){o({visible:!0,onHide:function(){o({visible:!1})}})},hide:function(){o({visible:!1})},update:function(e){o(e)}}};
|