rc-upload
Advanced tools
Comparing version 2.3.5 to 2.3.7
@@ -19,2 +19,6 @@ 'use strict'; | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
@@ -48,11 +52,13 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var AjaxUploader = function (_Component) { | ||
(0, _inherits3["default"])(AjaxUploader, _Component); | ||
(0, _inherits3['default'])(AjaxUploader, _Component); | ||
function AjaxUploader() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3["default"])(this, AjaxUploader); | ||
(0, _classCallCheck3['default'])(this, AjaxUploader); | ||
@@ -63,3 +69,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3["default"])(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { uid: (0, _uid2["default"])() }, _this.reqs = {}, _this.onChange = function (e) { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = AjaxUploader.__proto__ || Object.getPrototypeOf(AjaxUploader)).call.apply(_ref, [this].concat(args))), _this), _this.state = { uid: (0, _uid2['default'])() }, _this.reqs = {}, _this.onChange = function (e) { | ||
var files = e.target.files; | ||
@@ -88,164 +94,173 @@ _this.uploadFiles(files); | ||
e.preventDefault(); | ||
}, _temp), (0, _possibleConstructorReturn3["default"])(_this, _ret); | ||
}, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret); | ||
} | ||
AjaxUploader.prototype.componentDidMount = function componentDidMount() { | ||
this._isMounted = true; | ||
}; | ||
AjaxUploader.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this._isMounted = false; | ||
this.abort(); | ||
}; | ||
AjaxUploader.prototype.uploadFiles = function uploadFiles(files) { | ||
var postFiles = Array.prototype.slice.call(files); | ||
var len = postFiles.length; | ||
for (var i = 0; i < len; i++) { | ||
var file = postFiles[i]; | ||
file.uid = (0, _uid2["default"])(); | ||
this.upload(file, postFiles); | ||
(0, _createClass3['default'])(AjaxUploader, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
this._isMounted = true; | ||
} | ||
}; | ||
AjaxUploader.prototype.upload = function upload(file, fileList) { | ||
var _this2 = this; | ||
var props = this.props; | ||
if (!props.beforeUpload) { | ||
// always async in case use react state to keep fileList | ||
return setTimeout(function () { | ||
return _this2.post(file); | ||
}, 0); | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this._isMounted = false; | ||
this.abort(); | ||
} | ||
var before = props.beforeUpload(file, fileList); | ||
if (before && before.then) { | ||
before.then(function (processedFile) { | ||
var processedFileType = Object.prototype.toString.call(processedFile); | ||
if (processedFileType === '[object File]' || processedFileType === '[object Blob]') { | ||
_this2.post(processedFile); | ||
} else { | ||
_this2.post(file); | ||
} | ||
})["catch"](function (e) { | ||
console && console.log(e); // eslint-disable-line | ||
}); | ||
} else if (before !== false) { | ||
setTimeout(function () { | ||
return _this2.post(file); | ||
}, 0); | ||
}, { | ||
key: 'uploadFiles', | ||
value: function uploadFiles(files) { | ||
var postFiles = Array.prototype.slice.call(files); | ||
var len = postFiles.length; | ||
for (var i = 0; i < len; i++) { | ||
var file = postFiles[i]; | ||
file.uid = (0, _uid2['default'])(); | ||
this.upload(file, postFiles); | ||
} | ||
} | ||
}; | ||
}, { | ||
key: 'upload', | ||
value: function upload(file, fileList) { | ||
var _this2 = this; | ||
AjaxUploader.prototype.post = function post(file) { | ||
var _this3 = this; | ||
var props = this.props; | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
var props = this.props; | ||
var data = props.data; | ||
var onStart = props.onStart, | ||
onProgress = props.onProgress; | ||
if (!props.beforeUpload) { | ||
// always async in case use react state to keep fileList | ||
return setTimeout(function () { | ||
return _this2.post(file); | ||
}, 0); | ||
} | ||
if (typeof data === 'function') { | ||
data = data(file); | ||
var before = props.beforeUpload(file, fileList); | ||
if (before && before.then) { | ||
before.then(function (processedFile) { | ||
var processedFileType = Object.prototype.toString.call(processedFile); | ||
if (processedFileType === '[object File]' || processedFileType === '[object Blob]') { | ||
_this2.post(processedFile); | ||
} else { | ||
_this2.post(file); | ||
} | ||
})['catch'](function (e) { | ||
console && console.log(e); // eslint-disable-line | ||
}); | ||
} else if (before !== false) { | ||
setTimeout(function () { | ||
return _this2.post(file); | ||
}, 0); | ||
} | ||
} | ||
var uid = file.uid; | ||
}, { | ||
key: 'post', | ||
value: function post(file) { | ||
var _this3 = this; | ||
var request = props.customRequest || _request2["default"]; | ||
this.reqs[uid] = request({ | ||
action: props.action, | ||
filename: props.name, | ||
file: file, | ||
data: data, | ||
headers: props.headers, | ||
withCredentials: props.withCredentials, | ||
onProgress: onProgress ? function (e) { | ||
onProgress(e, file); | ||
} : null, | ||
onSuccess: function onSuccess(ret) { | ||
delete _this3.reqs[uid]; | ||
props.onSuccess(ret, file); | ||
}, | ||
onError: function onError(err, ret) { | ||
delete _this3.reqs[uid]; | ||
props.onError(err, ret, file); | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
}); | ||
onStart(file); | ||
}; | ||
var props = this.props; | ||
var data = props.data; | ||
var onStart = props.onStart, | ||
onProgress = props.onProgress; | ||
AjaxUploader.prototype.reset = function reset() { | ||
this.setState({ | ||
uid: (0, _uid2["default"])() | ||
}); | ||
}; | ||
if (typeof data === 'function') { | ||
data = data(file); | ||
} | ||
var uid = file.uid; | ||
AjaxUploader.prototype.abort = function abort(file) { | ||
var reqs = this.reqs; | ||
var request = props.customRequest || _request2['default']; | ||
this.reqs[uid] = request({ | ||
action: props.action, | ||
filename: props.name, | ||
file: file, | ||
data: data, | ||
headers: props.headers, | ||
withCredentials: props.withCredentials, | ||
onProgress: onProgress ? function (e) { | ||
onProgress(e, file); | ||
} : null, | ||
onSuccess: function onSuccess(ret) { | ||
delete _this3.reqs[uid]; | ||
props.onSuccess(ret, file); | ||
}, | ||
onError: function onError(err, ret) { | ||
delete _this3.reqs[uid]; | ||
props.onError(err, ret, file); | ||
} | ||
}); | ||
onStart(file); | ||
} | ||
}, { | ||
key: 'reset', | ||
value: function reset() { | ||
this.setState({ | ||
uid: (0, _uid2['default'])() | ||
}); | ||
} | ||
}, { | ||
key: 'abort', | ||
value: function abort(file) { | ||
var reqs = this.reqs; | ||
if (file) { | ||
var uid = file; | ||
if (file && file.uid) { | ||
uid = file.uid; | ||
} | ||
if (reqs[uid]) { | ||
reqs[uid].abort(); | ||
delete reqs[uid]; | ||
} | ||
} else { | ||
Object.keys(reqs).forEach(function (uid) { | ||
if (file) { | ||
var uid = file; | ||
if (file && file.uid) { | ||
uid = file.uid; | ||
} | ||
if (reqs[uid]) { | ||
reqs[uid].abort(); | ||
delete reqs[uid]; | ||
} | ||
} else { | ||
Object.keys(reqs).forEach(function (uid) { | ||
if (reqs[uid]) { | ||
reqs[uid].abort(); | ||
} | ||
delete reqs[uid]; | ||
}); | ||
delete reqs[uid]; | ||
}); | ||
} | ||
} | ||
}; | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _classNames; | ||
AjaxUploader.prototype.render = function render() { | ||
var _classNames; | ||
var _props = this.props, | ||
Tag = _props.component, | ||
prefixCls = _props.prefixCls, | ||
className = _props.className, | ||
disabled = _props.disabled, | ||
style = _props.style, | ||
multiple = _props.multiple, | ||
accept = _props.accept, | ||
children = _props.children; | ||
var _props = this.props, | ||
Tag = _props.component, | ||
prefixCls = _props.prefixCls, | ||
className = _props.className, | ||
disabled = _props.disabled, | ||
style = _props.style, | ||
multiple = _props.multiple, | ||
accept = _props.accept, | ||
children = _props.children; | ||
var cls = (0, _classnames2["default"])((_classNames = {}, (0, _defineProperty3["default"])(_classNames, prefixCls, true), (0, _defineProperty3["default"])(_classNames, prefixCls + '-disabled', disabled), (0, _defineProperty3["default"])(_classNames, className, className), _classNames)); | ||
var events = disabled ? {} : { | ||
onClick: this.onClick, | ||
onKeyDown: this.onKeyDown, | ||
onDrop: this.onFileDrop, | ||
onDragOver: this.onFileDrop, | ||
tabIndex: '0' | ||
}; | ||
return _react2["default"].createElement( | ||
Tag, | ||
(0, _extends3["default"])({}, events, { | ||
className: cls, | ||
role: 'button', | ||
style: style | ||
}), | ||
_react2["default"].createElement('input', { | ||
type: 'file', | ||
ref: 'file', | ||
key: this.state.uid, | ||
style: { display: 'none' }, | ||
accept: accept, | ||
multiple: multiple, | ||
onChange: this.onChange | ||
}), | ||
children | ||
); | ||
}; | ||
var cls = (0, _classnames2['default'])((_classNames = {}, (0, _defineProperty3['default'])(_classNames, prefixCls, true), (0, _defineProperty3['default'])(_classNames, prefixCls + '-disabled', disabled), (0, _defineProperty3['default'])(_classNames, className, className), _classNames)); | ||
var events = disabled ? {} : { | ||
onClick: this.onClick, | ||
onKeyDown: this.onKeyDown, | ||
onDrop: this.onFileDrop, | ||
onDragOver: this.onFileDrop, | ||
tabIndex: '0' | ||
}; | ||
return _react2['default'].createElement( | ||
Tag, | ||
(0, _extends3['default'])({}, events, { | ||
className: cls, | ||
role: 'button', | ||
style: style | ||
}), | ||
_react2['default'].createElement('input', { | ||
type: 'file', | ||
ref: 'file', | ||
key: this.state.uid, | ||
style: { display: 'none' }, | ||
accept: accept, | ||
multiple: multiple, | ||
onChange: this.onChange | ||
}), | ||
children | ||
); | ||
} | ||
}]); | ||
return AjaxUploader; | ||
@@ -255,19 +270,19 @@ }(_react.Component); /* eslint react/no-is-mounted:0 react/sort-comp:0 */ | ||
AjaxUploader.propTypes = { | ||
component: _propTypes2["default"].string, | ||
style: _propTypes2["default"].object, | ||
prefixCls: _propTypes2["default"].string, | ||
className: _propTypes2["default"].string, | ||
multiple: _propTypes2["default"].bool, | ||
disabled: _propTypes2["default"].bool, | ||
accept: _propTypes2["default"].string, | ||
children: _propTypes2["default"].any, | ||
onStart: _propTypes2["default"].func, | ||
data: _propTypes2["default"].oneOfType([_propTypes2["default"].object, _propTypes2["default"].func]), | ||
headers: _propTypes2["default"].object, | ||
beforeUpload: _propTypes2["default"].func, | ||
customRequest: _propTypes2["default"].func, | ||
onProgress: _propTypes2["default"].func, | ||
withCredentials: _propTypes2["default"].bool | ||
component: _propTypes2['default'].string, | ||
style: _propTypes2['default'].object, | ||
prefixCls: _propTypes2['default'].string, | ||
className: _propTypes2['default'].string, | ||
multiple: _propTypes2['default'].bool, | ||
disabled: _propTypes2['default'].bool, | ||
accept: _propTypes2['default'].string, | ||
children: _propTypes2['default'].any, | ||
onStart: _propTypes2['default'].func, | ||
data: _propTypes2['default'].oneOfType([_propTypes2['default'].object, _propTypes2['default'].func]), | ||
headers: _propTypes2['default'].object, | ||
beforeUpload: _propTypes2['default'].func, | ||
customRequest: _propTypes2['default'].func, | ||
onProgress: _propTypes2['default'].func, | ||
withCredentials: _propTypes2['default'].bool | ||
}; | ||
exports["default"] = AjaxUploader; | ||
exports['default'] = AjaxUploader; | ||
module.exports = exports['default']; |
@@ -19,2 +19,6 @@ 'use strict'; | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
@@ -52,3 +56,3 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -68,8 +72,10 @@ /* eslint react/sort-comp:0 */ | ||
var IframeUploader = function (_Component) { | ||
(0, _inherits3["default"])(IframeUploader, _Component); | ||
(0, _inherits3['default'])(IframeUploader, _Component); | ||
function IframeUploader() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3["default"])(this, IframeUploader); | ||
(0, _classCallCheck3['default'])(this, IframeUploader); | ||
@@ -80,3 +86,3 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3["default"])(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { uploading: false }, _this.file = {}, _this.onLoad = function () { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = IframeUploader.__proto__ || Object.getPrototypeOf(IframeUploader)).call.apply(_ref, [this].concat(args))), _this), _this.state = { uploading: false }, _this.file = {}, _this.onLoad = function () { | ||
if (!_this.state.uploading) { | ||
@@ -99,3 +105,3 @@ return; | ||
} catch (err) { | ||
(0, _warning2["default"])(false, 'cross domain error for Upload. Maybe server should return document.domain script. see Note from https://github.com/react-component/upload'); | ||
(0, _warning2['default'])(false, 'cross domain error for Upload. Maybe server should return document.domain script. see Note from https://github.com/react-component/upload'); | ||
response = 'cross-domain'; | ||
@@ -110,3 +116,3 @@ props.onError(err, null, file); | ||
var file = _this.file = { | ||
uid: (0, _uid2["default"])(), | ||
uid: (0, _uid2['default'])(), | ||
name: target.value | ||
@@ -133,168 +139,186 @@ }; | ||
} | ||
}, _temp), (0, _possibleConstructorReturn3["default"])(_this, _ret); | ||
}, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret); | ||
} | ||
IframeUploader.prototype.componentDidMount = function componentDidMount() { | ||
this.updateIframeWH(); | ||
this.initIframe(); | ||
}; | ||
IframeUploader.prototype.componentDidUpdate = function componentDidUpdate() { | ||
this.updateIframeWH(); | ||
}; | ||
IframeUploader.prototype.getIframeNode = function getIframeNode() { | ||
return this.refs.iframe; | ||
}; | ||
IframeUploader.prototype.getIframeDocument = function getIframeDocument() { | ||
return this.getIframeNode().contentDocument; | ||
}; | ||
IframeUploader.prototype.getFormNode = function getFormNode() { | ||
return this.getIframeDocument().getElementById('form'); | ||
}; | ||
IframeUploader.prototype.getFormInputNode = function getFormInputNode() { | ||
return this.getIframeDocument().getElementById('input'); | ||
}; | ||
IframeUploader.prototype.getFormDataNode = function getFormDataNode() { | ||
return this.getIframeDocument().getElementById('data'); | ||
}; | ||
IframeUploader.prototype.getFileForMultiple = function getFileForMultiple(file) { | ||
return this.props.multiple ? [file] : file; | ||
}; | ||
IframeUploader.prototype.getIframeHTML = function getIframeHTML(domain) { | ||
var domainScript = ''; | ||
var domainInput = ''; | ||
if (domain) { | ||
var script = 'script'; | ||
domainScript = '<' + script + '>document.domain="' + domain + '";</' + script + '>'; | ||
domainInput = '<input name="_documentDomain" value="' + domain + '" />'; | ||
(0, _createClass3['default'])(IframeUploader, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
this.updateIframeWH(); | ||
this.initIframe(); | ||
} | ||
return '\n <!DOCTYPE html>\n <html>\n <head>\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <style>\n body,html {padding:0;margin:0;border:0;overflow:hidden;}\n </style>\n ' + domainScript + '\n </head>\n <body>\n <form method="post"\n encType="multipart/form-data"\n action="' + this.props.action + '" id="form"\n style="display:block;height:9999px;position:relative;overflow:hidden;">\n <input id="input" type="file"\n name="' + this.props.name + '"\n style="position:absolute;top:0;right:0;height:9999px;font-size:9999px;cursor:pointer;"/>\n ' + domainInput + '\n <span id="data"></span>\n </form>\n </body>\n </html>\n '; | ||
}; | ||
IframeUploader.prototype.initIframeSrc = function initIframeSrc() { | ||
if (this.domain) { | ||
this.getIframeNode().src = 'javascript:void((function(){\n var d = document;\n d.open();\n d.domain=\'' + this.domain + '\';\n d.write(\'\');\n d.close();\n })())'; | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate() { | ||
this.updateIframeWH(); | ||
} | ||
}; | ||
IframeUploader.prototype.initIframe = function initIframe() { | ||
var iframeNode = this.getIframeNode(); | ||
var win = iframeNode.contentWindow; | ||
var doc = void 0; | ||
this.domain = this.domain || ''; | ||
this.initIframeSrc(); | ||
try { | ||
doc = win.document; | ||
} catch (e) { | ||
this.domain = document.domain; | ||
}, { | ||
key: 'getIframeNode', | ||
value: function getIframeNode() { | ||
return this.refs.iframe; | ||
} | ||
}, { | ||
key: 'getIframeDocument', | ||
value: function getIframeDocument() { | ||
return this.getIframeNode().contentDocument; | ||
} | ||
}, { | ||
key: 'getFormNode', | ||
value: function getFormNode() { | ||
return this.getIframeDocument().getElementById('form'); | ||
} | ||
}, { | ||
key: 'getFormInputNode', | ||
value: function getFormInputNode() { | ||
return this.getIframeDocument().getElementById('input'); | ||
} | ||
}, { | ||
key: 'getFormDataNode', | ||
value: function getFormDataNode() { | ||
return this.getIframeDocument().getElementById('data'); | ||
} | ||
}, { | ||
key: 'getFileForMultiple', | ||
value: function getFileForMultiple(file) { | ||
return this.props.multiple ? [file] : file; | ||
} | ||
}, { | ||
key: 'getIframeHTML', | ||
value: function getIframeHTML(domain) { | ||
var domainScript = ''; | ||
var domainInput = ''; | ||
if (domain) { | ||
var script = 'script'; | ||
domainScript = '<' + script + '>document.domain="' + domain + '";</' + script + '>'; | ||
domainInput = '<input name="_documentDomain" value="' + domain + '" />'; | ||
} | ||
return '\n <!DOCTYPE html>\n <html>\n <head>\n <meta http-equiv="X-UA-Compatible" content="IE=edge" />\n <style>\n body,html {padding:0;margin:0;border:0;overflow:hidden;}\n </style>\n ' + domainScript + '\n </head>\n <body>\n <form method="post"\n encType="multipart/form-data"\n action="' + this.props.action + '" id="form"\n style="display:block;height:9999px;position:relative;overflow:hidden;">\n <input id="input" type="file"\n name="' + this.props.name + '"\n style="position:absolute;top:0;right:0;height:9999px;font-size:9999px;cursor:pointer;"/>\n ' + domainInput + '\n <span id="data"></span>\n </form>\n </body>\n </html>\n '; | ||
} | ||
}, { | ||
key: 'initIframeSrc', | ||
value: function initIframeSrc() { | ||
if (this.domain) { | ||
this.getIframeNode().src = 'javascript:void((function(){\n var d = document;\n d.open();\n d.domain=\'' + this.domain + '\';\n d.write(\'\');\n d.close();\n })())'; | ||
} | ||
} | ||
}, { | ||
key: 'initIframe', | ||
value: function initIframe() { | ||
var iframeNode = this.getIframeNode(); | ||
var win = iframeNode.contentWindow; | ||
var doc = void 0; | ||
this.domain = this.domain || ''; | ||
this.initIframeSrc(); | ||
win = iframeNode.contentWindow; | ||
doc = win.document; | ||
try { | ||
doc = win.document; | ||
} catch (e) { | ||
this.domain = document.domain; | ||
this.initIframeSrc(); | ||
win = iframeNode.contentWindow; | ||
doc = win.document; | ||
} | ||
doc.open('text/html', 'replace'); | ||
doc.write(this.getIframeHTML(this.domain)); | ||
doc.close(); | ||
this.getFormInputNode().onchange = this.onChange; | ||
} | ||
doc.open('text/html', 'replace'); | ||
doc.write(this.getIframeHTML(this.domain)); | ||
doc.close(); | ||
this.getFormInputNode().onchange = this.onChange; | ||
}; | ||
IframeUploader.prototype.endUpload = function endUpload() { | ||
if (this.state.uploading) { | ||
this.file = {}; | ||
// hack avoid batch | ||
this.state.uploading = false; | ||
this.setState({ | ||
uploading: false | ||
}); | ||
this.initIframe(); | ||
}, { | ||
key: 'endUpload', | ||
value: function endUpload() { | ||
if (this.state.uploading) { | ||
this.file = {}; | ||
// hack avoid batch | ||
this.state.uploading = false; | ||
this.setState({ | ||
uploading: false | ||
}); | ||
this.initIframe(); | ||
} | ||
} | ||
}; | ||
IframeUploader.prototype.startUpload = function startUpload() { | ||
if (!this.state.uploading) { | ||
this.state.uploading = true; | ||
this.setState({ | ||
uploading: true | ||
}); | ||
}, { | ||
key: 'startUpload', | ||
value: function startUpload() { | ||
if (!this.state.uploading) { | ||
this.state.uploading = true; | ||
this.setState({ | ||
uploading: true | ||
}); | ||
} | ||
} | ||
}; | ||
IframeUploader.prototype.updateIframeWH = function updateIframeWH() { | ||
var rootNode = _reactDom2["default"].findDOMNode(this); | ||
var iframeNode = this.getIframeNode(); | ||
iframeNode.style.height = rootNode.offsetHeight + 'px'; | ||
iframeNode.style.width = rootNode.offsetWidth + 'px'; | ||
}; | ||
IframeUploader.prototype.abort = function abort(file) { | ||
if (file) { | ||
var uid = file; | ||
if (file && file.uid) { | ||
uid = file.uid; | ||
} | ||
if (uid === this.file.uid) { | ||
}, { | ||
key: 'updateIframeWH', | ||
value: function updateIframeWH() { | ||
var rootNode = _reactDom2['default'].findDOMNode(this); | ||
var iframeNode = this.getIframeNode(); | ||
iframeNode.style.height = rootNode.offsetHeight + 'px'; | ||
iframeNode.style.width = rootNode.offsetWidth + 'px'; | ||
} | ||
}, { | ||
key: 'abort', | ||
value: function abort(file) { | ||
if (file) { | ||
var uid = file; | ||
if (file && file.uid) { | ||
uid = file.uid; | ||
} | ||
if (uid === this.file.uid) { | ||
this.endUpload(); | ||
} | ||
} else { | ||
this.endUpload(); | ||
} | ||
} else { | ||
this.endUpload(); | ||
} | ||
}; | ||
}, { | ||
key: 'post', | ||
value: function post(file) { | ||
var formNode = this.getFormNode(); | ||
var dataSpan = this.getFormDataNode(); | ||
var data = this.props.data; | ||
var onStart = this.props.onStart; | ||
IframeUploader.prototype.post = function post(file) { | ||
var formNode = this.getFormNode(); | ||
var dataSpan = this.getFormDataNode(); | ||
var data = this.props.data; | ||
var onStart = this.props.onStart; | ||
if (typeof data === 'function') { | ||
data = data(file); | ||
} | ||
var inputs = []; | ||
for (var key in data) { | ||
if (data.hasOwnProperty(key)) { | ||
inputs.push('<input name="' + key + '" value="' + data[key] + '"/>'); | ||
if (typeof data === 'function') { | ||
data = data(file); | ||
} | ||
var inputs = []; | ||
for (var key in data) { | ||
if (data.hasOwnProperty(key)) { | ||
inputs.push('<input name="' + key + '" value="' + data[key] + '"/>'); | ||
} | ||
} | ||
dataSpan.innerHTML = inputs.join(''); | ||
formNode.submit(); | ||
dataSpan.innerHTML = ''; | ||
onStart(file); | ||
} | ||
dataSpan.innerHTML = inputs.join(''); | ||
formNode.submit(); | ||
dataSpan.innerHTML = ''; | ||
onStart(file); | ||
}; | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _classNames; | ||
IframeUploader.prototype.render = function render() { | ||
var _classNames; | ||
var _props = this.props, | ||
Tag = _props.component, | ||
disabled = _props.disabled, | ||
className = _props.className, | ||
prefixCls = _props.prefixCls, | ||
children = _props.children, | ||
style = _props.style; | ||
var _props = this.props, | ||
Tag = _props.component, | ||
disabled = _props.disabled, | ||
className = _props.className, | ||
prefixCls = _props.prefixCls, | ||
children = _props.children, | ||
style = _props.style; | ||
var iframeStyle = (0, _extends3["default"])({}, IFRAME_STYLE, { | ||
display: this.state.uploading || disabled ? 'none' : '' | ||
}); | ||
var cls = (0, _classnames2["default"])((_classNames = {}, (0, _defineProperty3["default"])(_classNames, prefixCls, true), (0, _defineProperty3["default"])(_classNames, prefixCls + '-disabled', disabled), (0, _defineProperty3["default"])(_classNames, className, className), _classNames)); | ||
return _react2["default"].createElement( | ||
Tag, | ||
{ | ||
className: cls, | ||
style: (0, _extends3["default"])({ position: 'relative', zIndex: 0 }, style) | ||
}, | ||
_react2["default"].createElement('iframe', { | ||
ref: 'iframe', | ||
onLoad: this.onLoad, | ||
style: iframeStyle | ||
}), | ||
children | ||
); | ||
}; | ||
var iframeStyle = (0, _extends3['default'])({}, IFRAME_STYLE, { | ||
display: this.state.uploading || disabled ? 'none' : '' | ||
}); | ||
var cls = (0, _classnames2['default'])((_classNames = {}, (0, _defineProperty3['default'])(_classNames, prefixCls, true), (0, _defineProperty3['default'])(_classNames, prefixCls + '-disabled', disabled), (0, _defineProperty3['default'])(_classNames, className, className), _classNames)); | ||
return _react2['default'].createElement( | ||
Tag, | ||
{ | ||
className: cls, | ||
style: (0, _extends3['default'])({ position: 'relative', zIndex: 0 }, style) | ||
}, | ||
_react2['default'].createElement('iframe', { | ||
ref: 'iframe', | ||
onLoad: this.onLoad, | ||
style: iframeStyle | ||
}), | ||
children | ||
); | ||
} | ||
}]); | ||
return IframeUploader; | ||
@@ -304,16 +328,16 @@ }(_react.Component); | ||
IframeUploader.propTypes = { | ||
component: _propTypes2["default"].string, | ||
style: _propTypes2["default"].object, | ||
disabled: _propTypes2["default"].bool, | ||
prefixCls: _propTypes2["default"].string, | ||
className: _propTypes2["default"].string, | ||
accept: _propTypes2["default"].string, | ||
onStart: _propTypes2["default"].func, | ||
multiple: _propTypes2["default"].bool, | ||
children: _propTypes2["default"].any, | ||
data: _propTypes2["default"].oneOfType([_propTypes2["default"].object, _propTypes2["default"].func]), | ||
action: _propTypes2["default"].string, | ||
name: _propTypes2["default"].string | ||
component: _propTypes2['default'].string, | ||
style: _propTypes2['default'].object, | ||
disabled: _propTypes2['default'].bool, | ||
prefixCls: _propTypes2['default'].string, | ||
className: _propTypes2['default'].string, | ||
accept: _propTypes2['default'].string, | ||
onStart: _propTypes2['default'].func, | ||
multiple: _propTypes2['default'].bool, | ||
children: _propTypes2['default'].any, | ||
data: _propTypes2['default'].oneOfType([_propTypes2['default'].object, _propTypes2['default'].func]), | ||
action: _propTypes2['default'].string, | ||
name: _propTypes2['default'].string | ||
}; | ||
exports["default"] = IframeUploader; | ||
exports['default'] = IframeUploader; | ||
module.exports = exports['default']; |
@@ -11,6 +11,6 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
exports["default"] = _Upload2["default"]; // export this package's api | ||
exports['default'] = _Upload2['default']; // export this package's api | ||
module.exports = exports['default']; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports["default"] = upload; | ||
exports['default'] = upload; | ||
function getError(option, xhr) { | ||
@@ -9,0 +9,0 @@ var msg = 'cannot post ' + option.action + ' ' + xhr.status + '\''; |
@@ -15,2 +15,6 @@ 'use strict'; | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
@@ -40,3 +44,3 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
@@ -46,8 +50,10 @@ function empty() {} | ||
var Upload = function (_Component) { | ||
(0, _inherits3["default"])(Upload, _Component); | ||
(0, _inherits3['default'])(Upload, _Component); | ||
function Upload() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3["default"])(this, Upload); | ||
(0, _classCallCheck3['default'])(this, Upload); | ||
@@ -58,36 +64,41 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3["default"])(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.state = { | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3['default'])(this, (_ref = Upload.__proto__ || Object.getPrototypeOf(Upload)).call.apply(_ref, [this].concat(args))), _this), _this.state = { | ||
Component: null | ||
}, _temp), (0, _possibleConstructorReturn3["default"])(_this, _ret); | ||
}, _temp), (0, _possibleConstructorReturn3['default'])(_this, _ret); | ||
} | ||
Upload.prototype.componentDidMount = function componentDidMount() { | ||
if (this.props.supportServerRender) { | ||
/* eslint react/no-did-mount-set-state:0 */ | ||
this.setState({ | ||
Component: this.getComponent() | ||
}, this.props.onReady); | ||
(0, _createClass3['default'])(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); | ||
} | ||
} | ||
}; | ||
Upload.prototype.getComponent = function getComponent() { | ||
return typeof FormData !== 'undefined' ? _AjaxUploader2["default"] : _IframeUploader2["default"]; | ||
}; | ||
Upload.prototype.abort = function abort(file) { | ||
this.refs.inner.abort(file); | ||
}; | ||
Upload.prototype.render = function render() { | ||
if (this.props.supportServerRender) { | ||
var _ComponentUploader = this.state.Component; | ||
if (_ComponentUploader) { | ||
return _react2["default"].createElement(_ComponentUploader, (0, _extends3["default"])({}, this.props, { ref: 'inner' })); | ||
}, { | ||
key: 'getComponent', | ||
value: function getComponent() { | ||
return typeof FormData !== 'undefined' ? _AjaxUploader2['default'] : _IframeUploader2['default']; | ||
} | ||
}, { | ||
key: 'abort', | ||
value: function abort(file) { | ||
this.refs.inner.abort(file); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
if (this.props.supportServerRender) { | ||
var _ComponentUploader = this.state.Component; | ||
if (_ComponentUploader) { | ||
return _react2['default'].createElement(_ComponentUploader, (0, _extends3['default'])({}, this.props, { ref: 'inner' })); | ||
} | ||
return null; | ||
} | ||
return null; | ||
var ComponentUploader = this.getComponent(); | ||
return _react2['default'].createElement(ComponentUploader, (0, _extends3['default'])({}, this.props, { ref: 'inner' })); | ||
} | ||
var ComponentUploader = this.getComponent(); | ||
return _react2["default"].createElement(ComponentUploader, (0, _extends3["default"])({}, this.props, { ref: 'inner' })); | ||
}; | ||
}]); | ||
return Upload; | ||
@@ -97,22 +108,22 @@ }(_react.Component); | ||
Upload.propTypes = { | ||
component: _propTypes2["default"].string, | ||
style: _propTypes2["default"].object, | ||
prefixCls: _propTypes2["default"].string, | ||
action: _propTypes2["default"].string, | ||
name: _propTypes2["default"].string, | ||
multipart: _propTypes2["default"].bool, | ||
onError: _propTypes2["default"].func, | ||
onSuccess: _propTypes2["default"].func, | ||
onProgress: _propTypes2["default"].func, | ||
onStart: _propTypes2["default"].func, | ||
data: _propTypes2["default"].oneOfType([_propTypes2["default"].object, _propTypes2["default"].func]), | ||
headers: _propTypes2["default"].object, | ||
accept: _propTypes2["default"].string, | ||
multiple: _propTypes2["default"].bool, | ||
disabled: _propTypes2["default"].bool, | ||
beforeUpload: _propTypes2["default"].func, | ||
customRequest: _propTypes2["default"].func, | ||
onReady: _propTypes2["default"].func, | ||
withCredentials: _propTypes2["default"].bool, | ||
supportServerRender: _propTypes2["default"].bool | ||
component: _propTypes2['default'].string, | ||
style: _propTypes2['default'].object, | ||
prefixCls: _propTypes2['default'].string, | ||
action: _propTypes2['default'].string, | ||
name: _propTypes2['default'].string, | ||
multipart: _propTypes2['default'].bool, | ||
onError: _propTypes2['default'].func, | ||
onSuccess: _propTypes2['default'].func, | ||
onProgress: _propTypes2['default'].func, | ||
onStart: _propTypes2['default'].func, | ||
data: _propTypes2['default'].oneOfType([_propTypes2['default'].object, _propTypes2['default'].func]), | ||
headers: _propTypes2['default'].object, | ||
accept: _propTypes2['default'].string, | ||
multiple: _propTypes2['default'].bool, | ||
disabled: _propTypes2['default'].bool, | ||
beforeUpload: _propTypes2['default'].func, | ||
customRequest: _propTypes2['default'].func, | ||
onReady: _propTypes2['default'].func, | ||
withCredentials: _propTypes2['default'].bool, | ||
supportServerRender: _propTypes2['default'].bool | ||
}; | ||
@@ -136,3 +147,3 @@ Upload.defaultProps = { | ||
}; | ||
exports["default"] = Upload; | ||
exports['default'] = Upload; | ||
module.exports = exports['default']; |
{ | ||
"name": "rc-upload", | ||
"version": "2.3.5", | ||
"version": "2.3.7", | ||
"description": "upload ui component for react", | ||
@@ -21,5 +21,7 @@ "keywords": [ | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"es" | ||
], | ||
"main": "./lib/index", | ||
"module": "./es/index", | ||
"config": { | ||
@@ -32,17 +34,16 @@ "port": 8020 | ||
"start": "node server", | ||
"compile": "rc-tools run compile --babel-runtime", | ||
"pub": "rc-tools run pub --babel-runtime", | ||
"lint": "rc-tools run lint", | ||
"karma": "rc-tools run karma", | ||
"saucelabs": "rc-tools run saucelabs", | ||
"test": "rc-tools run test", | ||
"chrome-test": "rc-tools run chrome-test", | ||
"coverage": "rc-tools run coverage" | ||
"test": "jest", | ||
"coverage": "jest --coverage && cat ./coverage/lcov.info | coveralls" | ||
}, | ||
"devDependencies": { | ||
"co-busboy": "^1.3.0", | ||
"coveralls": "^2.13.1", | ||
"expect.js": "0.3.x", | ||
"jest": "^20.0.1", | ||
"pre-commit": "1.x", | ||
"rc-tools": "5.x", | ||
"rc-tools": "6.x", | ||
"react": "15.x", | ||
"react-addons-test-utils": "15.x", | ||
"react-dom": "15.x", | ||
@@ -59,3 +60,15 @@ "sinon": "2.0.0-pre.2" | ||
"prop-types": "^15.5.7" | ||
}, | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"src/*" | ||
], | ||
"coveragePathIgnorePatterns": [ | ||
"src/IframeUploader.jsx" | ||
], | ||
"transform": { | ||
"\\.tsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js", | ||
"\\.jsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js" | ||
} | ||
} | ||
} |
@@ -63,3 +63,3 @@ # rc-upload | ||
|onReady | function | | only call when supportServerRender is true, upload is rendered completely | | ||
|action| string | | from action url | | ||
|action| string | | form action url | | ||
|data| object/function(file) | | other data object to post or a function which returns a data object | | ||
@@ -66,0 +66,0 @@ |headers| object | {} | http headers to post, available in modern browsers | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57167
15
1437
9
1