@chief-editor/ui
Version:
UI Component for chief editor
1 lines • 2.54 kB
JavaScript
;var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)},__rest=this&&this.__rest||function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var react_1=__importDefault(require("react")),react_dom_1=__importDefault(require("react-dom")),Alert_1=require("./Alert"),Confirm_1=require("./Confirm");function wrapFunction(e){return function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{var r=e.apply(void 0,n);return null!=r&&"object"==typeof r&&"function"==typeof r.then?r:Promise.resolve(r)}catch(e){return Promise.reject(e)}}}function wrapManualModal(e){var n,t=e.onOk,r=void 0===t?function(){return null}:t,o=e.onCancel,a=void 0===o?function(){return null}:o,l=wrapFunction(r),u=wrapFunction(a),i=document.createElement("div");document.body.appendChild(i);var c=function(){i.parentNode&&(react_dom_1.default.unmountComponentAtNode(i),document.body.removeChild(i))},f=function(){var e;null===(e=n.ref.current)||void 0===e||e.hide(),setTimeout(c,300)};return n={onOk:function(){l().then(f,(function(){return null}))},onCancel:function(){u().then(f,(function(){return null}))},destroy:c,container:i,ref:{current:null}}}function confirm(e){var n=e.afterClose,t=e.onOk,r=e.onCancel,o=__rest(e,["afterClose","onOk","onCancel"]),a=wrapManualModal({onOk:t,onCancel:r}),l=a.ref,u=a.destroy,i=a.container,c=a.onOk,f=a.onCancel;react_dom_1.default.render(react_1.default.createElement(Confirm_1.Confirm,__assign({},o,{defaultShow:!0,ref:l,afterClose:function(){u(),null==n||n()},onOk:c,onCancel:f})),i)}function alert(e){var n=e.afterClose,t=e.onOk,r=e.onClose,o=__rest(e,["afterClose","onOk","onClose"]),a=wrapManualModal({onOk:t,onCancel:r}),l=a.ref,u=a.destroy,i=a.container,c=a.onOk,f=a.onCancel;react_dom_1.default.render(react_1.default.createElement(Alert_1.Alert,__assign({},o,{defaultShow:!0,ref:l,afterClose:function(){u(),null==n||n()},onOk:c,onClose:f})),i)}exports.confirm=confirm,exports.alert=alert;