2 lines
6.1 KiB
JavaScript
2 lines
6.1 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-dom"),r=require("primereact/utils"),n=require("primereact/dialog"),o=require("primereact/button"),i=require("primereact/api"),c=require("primereact/portal");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=a(e),s=a(t);function p(){return p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},p.apply(this,arguments)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function b(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function h(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&&d(e,t)}function m(e){return m="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},m(e)}function y(e,t){if(t&&("object"===m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return b(e)}function v(e){return v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},v(e)}function j(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,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 r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function w(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?g(Object(r),!0).forEach((function(t){j(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):g(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var P=function(t){h(w,e.Component);var a,s,d,m,j,g=(a=w,s=O(),function(){var e,t=v(a);if(s){var r=v(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return y(this,e)});function w(e){var t;return u(this,w),(t=g.call(this,e)).state={visible:e.visible},t.reject=t.reject.bind(b(t)),t.accept=t.accept.bind(b(t)),t.hide=t.hide.bind(b(t)),t}return d=w,(m=[{key:"acceptLabel",value:function(){return this.props.acceptLabel||i.localeOption("accept")}},{key:"rejectLabel",value:function(){return this.props.rejectLabel||i.localeOption("reject")}},{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(){this.setState({visible:!0})}},{key:"hide",value:function(e){var t=this;this.setState({visible:!1},(function(){t.props.onHide&&t.props.onHide(e)}))}},{key:"componentDidUpdate",value:function(e){e.visible!==this.props.visible&&this.setState({visible:this.props.visible})}},{key:"renderFooter",value:function(){var e=r.classNames("p-confirm-dialog-accept",this.props.acceptClassName),t=r.classNames("p-confirm-dialog-reject",{"p-button-text":!this.props.rejectClassName},this.props.rejectClassName),n=l.default.createElement(l.default.Fragment,null,l.default.createElement(o.Button,{label:this.rejectLabel(),icon:this.props.rejectIcon,className:t,onClick:this.reject}),l.default.createElement(o.Button,{label:this.acceptLabel(),icon:this.props.acceptIcon,className:e,onClick:this.accept,autoFocus:!0}));if(this.props.footer){var i={accept:this.accept,reject:this.reject,acceptClassName:e,rejectClassName:t,acceptLabel:this.acceptLabel(),rejectLabel:this.rejectLabel(),element:n,props:this.props};return r.ObjectUtils.getJSXElement(this.props.footer,i)}return n}},{key:"renderElement",value:function(){var e=r.classNames("p-confirm-dialog",this.props.className),t=r.ObjectUtils.findDiffKeys(this.props,w.defaultProps),o=r.ObjectUtils.getJSXElement(this.props.message,this.props),i=this.renderFooter();return l.default.createElement(n.Dialog,p({visible:this.state.visible},t,{className:e,footer:i,onHide:this.hide,breakpoints:this.props.breakpoints}),r.IconUtils.getJSXIcon(this.props.icon,{className:"p-confirm-dialog-icon"},{props:this.props}),l.default.createElement("span",{className:"p-confirm-dialog-message"},o))}},{key:"render",value:function(){var e=this.renderElement();return l.default.createElement(c.Portal,{element:e,appendTo:this.props.appendTo})}}])&&f(d.prototype,m),j&&f(d,j),Object.defineProperty(d,"prototype",{writable:!1}),w}();j(P,"defaultProps",{visible:!1,message:null,rejectLabel:null,acceptLabel:null,icon:null,rejectIcon:null,acceptIcon:null,rejectClassName:null,acceptClassName:null,className:null,appendTo:null,footer:null,breakpoints:null,onHide:null,accept:null,reject:null}),exports.ConfirmDialog=P,exports.confirmDialog=function(e){var t=e.appendTo||document.body,n=document.createDocumentFragment();r.DomHandler.appendChild(n,t),e=w(w({},e),{visible:void 0===e.visible||e.visible});var o=l.default.createElement(P,e);s.default.render(o,n);var i=function(t){e=w(w({},e),t),s.default.render(l.default.cloneElement(o,e),n)};return{_destroy:function(){s.default.unmountComponentAtNode(n)},show:function(){i({visible:!0,onHide:function(){i({visible:!1})}})},hide:function(){i({visible:!1})},update:function(e){i(e)}}};
|