1 line
8.9 KiB
JSON
1 line
8.9 KiB
JSON
{"ast":null,"code":"'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = undefined;\n\nvar _createClass = function () {\n function defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n }\n\n return function (Constructor, protoProps, staticProps) {\n if (protoProps) defineProperties(Constructor.prototype, protoProps);\n if (staticProps) defineProperties(Constructor, staticProps);\n return Constructor;\n };\n}();\n\nvar _class, _temp2;\n\nexports.confirmAlert = confirmAlert;\n\nvar _react = require('react');\n\nvar _react2 = _interopRequireDefault(_react);\n\nvar _propTypes = require('prop-types');\n\nvar _propTypes2 = _interopRequireDefault(_propTypes);\n\nvar _reactDom = require('react-dom');\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n\nfunction _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nfunction _possibleConstructorReturn(self, call) {\n if (!self) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self;\n}\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass);\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;\n}\n\nvar ReactConfirmAlert = (_temp2 = _class = function (_Component) {\n _inherits(ReactConfirmAlert, _Component);\n\n function ReactConfirmAlert() {\n var _ref;\n\n var _temp, _this, _ret;\n\n _classCallCheck(this, ReactConfirmAlert);\n\n for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ReactConfirmAlert.__proto__ || Object.getPrototypeOf(ReactConfirmAlert)).call.apply(_ref, [this].concat(args))), _this), _this.handleClickButton = function (button) {\n if (button.onClick) button.onClick();\n\n _this.close();\n }, _this.handleClickOverlay = function (e) {\n var _this$props = _this.props,\n closeOnClickOutside = _this$props.closeOnClickOutside,\n onClickOutside = _this$props.onClickOutside;\n var isClickOutside = e.target === _this.overlay;\n\n if (closeOnClickOutside && isClickOutside) {\n onClickOutside();\n\n _this.close();\n }\n }, _this.close = function () {\n removeBodyClass();\n removeElementReconfirm();\n removeSVGBlurReconfirm();\n }, _this.keyboardClose = function (event) {\n var _this$props2 = _this.props,\n closeOnEscape = _this$props2.closeOnEscape,\n onKeypressEscape = _this$props2.onKeypressEscape;\n var isKeyCodeEscape = event.keyCode === 27;\n\n if (closeOnEscape && isKeyCodeEscape) {\n onKeypressEscape(event);\n\n _this.close();\n }\n }, _this.componentDidMount = function () {\n document.addEventListener('keydown', _this.keyboardClose, false);\n }, _this.componentWillUnmount = function () {\n document.removeEventListener('keydown', _this.keyboardClose, false);\n\n _this.props.willUnmount();\n }, _this.renderCustomUI = function () {\n var _this$props3 = _this.props,\n title = _this$props3.title,\n message = _this$props3.message,\n customUI = _this$props3.customUI;\n var dataCustomUI = {\n title: title,\n message: message,\n onClose: _this.close\n };\n return customUI(dataCustomUI);\n }, _temp), _possibleConstructorReturn(_this, _ret);\n }\n\n _createClass(ReactConfirmAlert, [{\n key: 'render',\n value: function render() {\n var _this2 = this;\n\n var _props = this.props,\n title = _props.title,\n message = _props.message,\n buttons = _props.buttons,\n childrenElement = _props.childrenElement,\n customUI = _props.customUI;\n return _react2.default.createElement('div', {\n className: 'react-confirm-alert-overlay',\n ref: function ref(dom) {\n return _this2.overlay = dom;\n },\n onClick: this.handleClickOverlay\n }, _react2.default.createElement('div', {\n className: 'react-confirm-alert'\n }, customUI ? this.renderCustomUI() : _react2.default.createElement('div', {\n className: 'react-confirm-alert-body'\n }, title && _react2.default.createElement('h1', null, title), message, childrenElement(), _react2.default.createElement('div', {\n className: 'react-confirm-alert-button-group'\n }, buttons.map(function (button, i) {\n return _react2.default.createElement('button', {\n key: i,\n onClick: function onClick() {\n return _this2.handleClickButton(button);\n }\n }, button.label);\n })))));\n }\n }]);\n\n return ReactConfirmAlert;\n}(_react.Component), _class.propTypes = {\n title: _propTypes2.default.string,\n message: _propTypes2.default.string,\n buttons: _propTypes2.default.array.isRequired,\n childrenElement: _propTypes2.default.func,\n customUI: _propTypes2.default.func,\n closeOnClickOutside: _propTypes2.default.bool,\n closeOnEscape: _propTypes2.default.bool,\n willUnmount: _propTypes2.default.func,\n onClickOutside: _propTypes2.default.func,\n onKeypressEscape: _propTypes2.default.func\n}, _class.defaultProps = {\n buttons: [{\n label: 'Cancel',\n onClick: function onClick() {\n return null;\n }\n }, {\n label: 'Confirm',\n onClick: function onClick() {\n return null;\n }\n }],\n childrenElement: function childrenElement() {\n return null;\n },\n closeOnClickOutside: true,\n closeOnEscape: true,\n willUnmount: function willUnmount() {\n return null;\n },\n onClickOutside: function onClickOutside() {\n return null;\n },\n onKeypressEscape: function onKeypressEscape() {\n return null;\n }\n}, _temp2);\nexports.default = ReactConfirmAlert;\n\nfunction createSVGBlurReconfirm() {\n // If has svg ignore to create the svg\n var svg = document.getElementById('react-confirm-alert-firm-svg');\n if (svg) return;\n var svgNS = 'http://www.w3.org/2000/svg';\n var feGaussianBlur = document.createElementNS(svgNS, 'feGaussianBlur');\n feGaussianBlur.setAttribute('stdDeviation', '0.3');\n var filter = document.createElementNS(svgNS, 'filter');\n filter.setAttribute('id', 'gaussian-blur');\n filter.appendChild(feGaussianBlur);\n var svgElem = document.createElementNS(svgNS, 'svg');\n svgElem.setAttribute('id', 'react-confirm-alert-firm-svg');\n svgElem.setAttribute('class', 'react-confirm-alert-svg');\n svgElem.appendChild(filter);\n document.body.appendChild(svgElem);\n}\n\nfunction removeSVGBlurReconfirm() {\n var svg = document.getElementById('react-confirm-alert-firm-svg');\n svg.parentNode.removeChild(svg);\n document.body.children[0].classList.remove('react-confirm-alert-blur');\n}\n\nfunction createElementReconfirm(properties) {\n var divTarget = document.getElementById('react-confirm-alert');\n\n if (divTarget) {\n // Rerender - the mounted ReactConfirmAlert\n (0, _reactDom.render)(_react2.default.createElement(ReactConfirmAlert, properties), divTarget);\n } else {\n // Mount the ReactConfirmAlert component\n document.body.children[0].classList.add('react-confirm-alert-blur');\n divTarget = document.createElement('div');\n divTarget.id = 'react-confirm-alert';\n document.body.appendChild(divTarget);\n (0, _reactDom.render)(_react2.default.createElement(ReactConfirmAlert, properties), divTarget);\n }\n}\n\nfunction removeElementReconfirm() {\n var target = document.getElementById('react-confirm-alert');\n (0, _reactDom.unmountComponentAtNode)(target);\n target.parentNode.removeChild(target);\n}\n\nfunction addBodyClass() {\n document.body.classList.add('react-confirm-alert-body-element');\n}\n\nfunction removeBodyClass() {\n document.body.classList.remove('react-confirm-alert-body-element');\n}\n\nfunction confirmAlert(properties) {\n addBodyClass();\n createSVGBlurReconfirm();\n createElementReconfirm(properties);\n}","map":null,"metadata":{},"sourceType":"script"} |