UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

165 lines (139 loc) 4.44 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } return function () { var Super = _getPrototypeOf(Derived), result; if (isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import AjaxUpload from './AjaxUploader'; import IframeUpload from './IframeUploader'; function empty() {} var Upload = /*#__PURE__*/ function (_Component) { _inherits(Upload, _Component); var _super = _createSuper(Upload); function Upload() { var _this; _classCallCheck(this, Upload); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "state", { Component: null }); _defineProperty(_assertThisInitialized(_this), "saveUploader", function (node) { _this.uploader = node; }); return _this; } _createClass(Upload, [{ key: "componentDidMount", value: function componentDidMount() { if (this.props.supportServerRender) { /* eslint react/no-did-mount-set-state:0 */ this.setState({ Component: this.getComponent() }, this.props.onReady); } } }, { key: "getComponent", value: function getComponent() { return typeof File !== 'undefined' ? AjaxUpload : IframeUpload; } }, { key: "abort", value: function abort(file) { this.uploader.abort(file); } }, { key: "render", value: function render() { if (this.props.supportServerRender) { var _ComponentUploader = this.state.Component; if (_ComponentUploader) { return React.createElement(_ComponentUploader, _extends({}, this.props, { ref: this.saveUploader })); } return null; } var ComponentUploader = this.getComponent(); return React.createElement(ComponentUploader, _extends({}, this.props, { ref: this.saveUploader })); } }]); return Upload; }(Component); _defineProperty(Upload, "propTypes", { component: PropTypes.string, style: PropTypes.object, prefixCls: PropTypes.string, action: PropTypes.string, name: PropTypes.string, multipart: PropTypes.bool, onError: PropTypes.func, onSuccess: PropTypes.func, onProgress: PropTypes.func, onStart: PropTypes.func, data: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), headers: PropTypes.object, accept: PropTypes.string, multiple: PropTypes.bool, disabled: PropTypes.bool, beforeUpload: PropTypes.func, customRequest: PropTypes.func, onReady: PropTypes.func, withCredentials: PropTypes.bool, supportServerRender: PropTypes.bool, requestFileKeys: PropTypes.oneOfType([PropTypes.array, PropTypes.string]) }); _defineProperty(Upload, "defaultProps", { component: 'span', prefixCls: 'rc-upload', data: {}, headers: {}, name: 'file', multipart: false, onReady: empty, onStart: empty, onError: empty, onSuccess: empty, supportServerRender: false, multiple: false, beforeUpload: null, customRequest: null, withCredentials: false }); export default Upload; //# sourceMappingURL=Upload.js.map