Latest updates from IceHrmPro
This commit is contained in:
289
web/node_modules/rc-upload/es/AjaxUploader.js
generated
vendored
Normal file
289
web/node_modules/rc-upload/es/AjaxUploader.js
generated
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
import _extends from 'babel-runtime/helpers/extends';
|
||||
import _defineProperty from 'babel-runtime/helpers/defineProperty';
|
||||
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
||||
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
||||
import _createClass from 'babel-runtime/helpers/createClass';
|
||||
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
||||
import _inherits from 'babel-runtime/helpers/inherits';
|
||||
/* eslint react/no-is-mounted:0,react/sort-comp:0,react/prop-types:0 */
|
||||
import React, { Component } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import defaultRequest from './request';
|
||||
import getUid from './uid';
|
||||
import attrAccept from './attr-accept';
|
||||
import traverseFileTree from './traverseFileTree';
|
||||
|
||||
var dataOrAriaAttributeProps = function dataOrAriaAttributeProps(props) {
|
||||
return Object.keys(props).reduce(function (acc, key) {
|
||||
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') {
|
||||
acc[key] = props[key];
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
var AjaxUploader = function (_Component) {
|
||||
_inherits(AjaxUploader, _Component);
|
||||
|
||||
function AjaxUploader() {
|
||||
var _ref;
|
||||
|
||||
var _temp, _this, _ret;
|
||||
|
||||
_classCallCheck(this, AjaxUploader);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = AjaxUploader.__proto__ || Object.getPrototypeOf(AjaxUploader)).call.apply(_ref, [this].concat(args))), _this), _this.state = { uid: getUid() }, _this.reqs = {}, _this.onChange = function (e) {
|
||||
var files = e.target.files;
|
||||
_this.uploadFiles(files);
|
||||
_this.reset();
|
||||
}, _this.onClick = function () {
|
||||
var el = _this.fileInput;
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
var children = _this.props.children;
|
||||
|
||||
if (children && children.type === 'button') {
|
||||
el.parentNode.focus();
|
||||
el.parentNode.querySelector('button').blur();
|
||||
}
|
||||
el.click();
|
||||
}, _this.onKeyDown = function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
_this.onClick();
|
||||
}
|
||||
}, _this.onFileDrop = function (e) {
|
||||
var multiple = _this.props.multiple;
|
||||
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if (e.type === 'dragover') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_this.props.directory) {
|
||||
traverseFileTree(e.dataTransfer.items, _this.uploadFiles, function (_file) {
|
||||
return attrAccept(_file, _this.props.accept);
|
||||
});
|
||||
} else {
|
||||
var files = Array.prototype.slice.call(e.dataTransfer.files).filter(function (file) {
|
||||
return attrAccept(file, _this.props.accept);
|
||||
});
|
||||
|
||||
if (multiple === false) {
|
||||
files = files.slice(0, 1);
|
||||
}
|
||||
|
||||
_this.uploadFiles(files);
|
||||
}
|
||||
}, _this.uploadFiles = function (files) {
|
||||
var postFiles = Array.prototype.slice.call(files);
|
||||
postFiles.map(function (file) {
|
||||
file.uid = getUid();
|
||||
return file;
|
||||
}).forEach(function (file) {
|
||||
_this.upload(file, postFiles);
|
||||
});
|
||||
}, _this.saveFileInput = function (node) {
|
||||
_this.fileInput = node;
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
}
|
||||
|
||||
_createClass(AjaxUploader, [{
|
||||
key: 'componentDidMount',
|
||||
value: function componentDidMount() {
|
||||
this._isMounted = true;
|
||||
}
|
||||
}, {
|
||||
key: 'componentWillUnmount',
|
||||
value: function componentWillUnmount() {
|
||||
this._isMounted = false;
|
||||
this.abort();
|
||||
}
|
||||
}, {
|
||||
key: 'upload',
|
||||
value: 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);
|
||||
}
|
||||
|
||||
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]') {
|
||||
return _this2.post(processedFile);
|
||||
}
|
||||
return _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: 'post',
|
||||
value: function post(file) {
|
||||
var _this3 = this;
|
||||
|
||||
if (!this._isMounted) {
|
||||
return;
|
||||
}
|
||||
var props = this.props;
|
||||
var data = props.data;
|
||||
var onStart = props.onStart,
|
||||
onProgress = props.onProgress,
|
||||
_props$transformFile = props.transformFile,
|
||||
transformFile = _props$transformFile === undefined ? function (originFile) {
|
||||
return originFile;
|
||||
} : _props$transformFile;
|
||||
|
||||
|
||||
new Promise(function (resolve) {
|
||||
var action = props.action;
|
||||
|
||||
if (typeof action === 'function') {
|
||||
return resolve(action(file));
|
||||
}
|
||||
resolve(action);
|
||||
}).then(function (action) {
|
||||
var uid = file.uid;
|
||||
|
||||
var request = props.customRequest || defaultRequest;
|
||||
var transform = Promise.resolve(transformFile(file))['catch'](function (e) {
|
||||
console.error(e); // eslint-disable-line no-console
|
||||
});
|
||||
|
||||
transform.then(function (transformedFile) {
|
||||
if (typeof data === 'function') {
|
||||
data = data(file);
|
||||
}
|
||||
|
||||
var requestOption = {
|
||||
action: action,
|
||||
filename: props.name,
|
||||
data: data,
|
||||
file: transformedFile,
|
||||
headers: props.headers,
|
||||
withCredentials: props.withCredentials,
|
||||
method: props.method || 'post',
|
||||
onProgress: onProgress ? function (e) {
|
||||
onProgress(e, file);
|
||||
} : null,
|
||||
onSuccess: function onSuccess(ret, xhr) {
|
||||
delete _this3.reqs[uid];
|
||||
props.onSuccess(ret, file, xhr);
|
||||
},
|
||||
onError: function onError(err, ret) {
|
||||
delete _this3.reqs[uid];
|
||||
props.onError(err, ret, file);
|
||||
}
|
||||
};
|
||||
_this3.reqs[uid] = request(requestOption);
|
||||
onStart(file);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'reset',
|
||||
value: function reset() {
|
||||
this.setState({
|
||||
uid: getUid()
|
||||
});
|
||||
}
|
||||
}, {
|
||||
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) {
|
||||
reqs[uid].abort();
|
||||
}
|
||||
delete reqs[uid];
|
||||
} else {
|
||||
Object.keys(reqs).forEach(function (uid) {
|
||||
if (reqs[uid] && reqs[uid].abort) {
|
||||
reqs[uid].abort();
|
||||
}
|
||||
delete reqs[uid];
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
value: function render() {
|
||||
var _classNames;
|
||||
|
||||
var _props = this.props,
|
||||
Tag = _props.component,
|
||||
prefixCls = _props.prefixCls,
|
||||
className = _props.className,
|
||||
disabled = _props.disabled,
|
||||
id = _props.id,
|
||||
style = _props.style,
|
||||
multiple = _props.multiple,
|
||||
accept = _props.accept,
|
||||
children = _props.children,
|
||||
directory = _props.directory,
|
||||
openFileDialogOnClick = _props.openFileDialogOnClick,
|
||||
otherProps = _objectWithoutProperties(_props, ['component', 'prefixCls', 'className', 'disabled', 'id', 'style', 'multiple', 'accept', 'children', 'directory', 'openFileDialogOnClick']);
|
||||
|
||||
var cls = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, prefixCls + '-disabled', disabled), _defineProperty(_classNames, className, className), _classNames));
|
||||
var events = disabled ? {} : {
|
||||
onClick: openFileDialogOnClick ? this.onClick : function () {},
|
||||
onKeyDown: openFileDialogOnClick ? this.onKeyDown : function () {},
|
||||
onDrop: this.onFileDrop,
|
||||
onDragOver: this.onFileDrop,
|
||||
tabIndex: '0'
|
||||
};
|
||||
return React.createElement(
|
||||
Tag,
|
||||
_extends({}, events, {
|
||||
className: cls,
|
||||
role: 'button',
|
||||
style: style
|
||||
}),
|
||||
React.createElement('input', _extends({}, dataOrAriaAttributeProps(otherProps), {
|
||||
id: id,
|
||||
type: 'file',
|
||||
ref: this.saveFileInput,
|
||||
onClick: function onClick(e) {
|
||||
return e.stopPropagation();
|
||||
} // https://github.com/ant-design/ant-design/issues/19948
|
||||
, key: this.state.uid,
|
||||
style: { display: 'none' },
|
||||
accept: accept,
|
||||
directory: directory ? 'directory' : null,
|
||||
webkitdirectory: directory ? 'webkitdirectory' : null,
|
||||
multiple: multiple,
|
||||
onChange: this.onChange
|
||||
})),
|
||||
children
|
||||
);
|
||||
}
|
||||
}]);
|
||||
|
||||
return AjaxUploader;
|
||||
}(Component);
|
||||
|
||||
export default AjaxUploader;
|
||||
70
web/node_modules/rc-upload/es/Upload.js
generated
vendored
Normal file
70
web/node_modules/rc-upload/es/Upload.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import _extends from 'babel-runtime/helpers/extends';
|
||||
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
||||
import _createClass from 'babel-runtime/helpers/createClass';
|
||||
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
||||
import _inherits from 'babel-runtime/helpers/inherits';
|
||||
/* eslint react/prop-types:0 */
|
||||
import React, { Component } from 'react';
|
||||
import AjaxUpload from './AjaxUploader';
|
||||
|
||||
function empty() {}
|
||||
|
||||
var Upload = function (_Component) {
|
||||
_inherits(Upload, _Component);
|
||||
|
||||
function Upload() {
|
||||
var _ref;
|
||||
|
||||
var _temp, _this, _ret;
|
||||
|
||||
_classCallCheck(this, Upload);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Upload.__proto__ || Object.getPrototypeOf(Upload)).call.apply(_ref, [this].concat(args))), _this), _this.saveUploader = function (node) {
|
||||
_this.uploader = node;
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
}
|
||||
|
||||
_createClass(Upload, [{
|
||||
key: 'componentDidMount',
|
||||
value: function componentDidMount() {
|
||||
this.props.onReady();
|
||||
}
|
||||
}, {
|
||||
key: 'abort',
|
||||
value: function abort(file) {
|
||||
this.uploader.abort(file);
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
value: function render() {
|
||||
return React.createElement(AjaxUpload, _extends({}, this.props, { ref: this.saveUploader }));
|
||||
}
|
||||
}]);
|
||||
|
||||
return Upload;
|
||||
}(Component);
|
||||
|
||||
Upload.defaultProps = {
|
||||
component: 'span',
|
||||
prefixCls: 'rc-upload',
|
||||
data: {},
|
||||
headers: {},
|
||||
name: 'file',
|
||||
multipart: false,
|
||||
onReady: empty,
|
||||
onStart: empty,
|
||||
onError: empty,
|
||||
onSuccess: empty,
|
||||
multiple: false,
|
||||
beforeUpload: null,
|
||||
customRequest: null,
|
||||
withCredentials: false,
|
||||
openFileDialogOnClick: true
|
||||
};
|
||||
|
||||
|
||||
export default Upload;
|
||||
24
web/node_modules/rc-upload/es/attr-accept.js
generated
vendored
Normal file
24
web/node_modules/rc-upload/es/attr-accept.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
function endsWith(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
export default (function (file, acceptedFiles) {
|
||||
if (file && acceptedFiles) {
|
||||
var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
|
||||
var fileName = file.name || '';
|
||||
var mimeType = file.type || '';
|
||||
var baseMimeType = mimeType.replace(/\/.*$/, '');
|
||||
|
||||
return acceptedFilesArray.some(function (type) {
|
||||
var validType = type.trim();
|
||||
if (validType.charAt(0) === '.') {
|
||||
return endsWith(fileName.toLowerCase(), validType.toLowerCase());
|
||||
} else if (/\/\*$/.test(validType)) {
|
||||
// This is something like a image/* mime type
|
||||
return baseMimeType === validType.replace(/\/.*$/, '');
|
||||
}
|
||||
return mimeType === validType;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
4
web/node_modules/rc-upload/es/index.js
generated
vendored
Normal file
4
web/node_modules/rc-upload/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
// export this package's api
|
||||
import Upload from './Upload';
|
||||
|
||||
export default Upload;
|
||||
112
web/node_modules/rc-upload/es/request.js
generated
vendored
Normal file
112
web/node_modules/rc-upload/es/request.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
function getError(option, xhr) {
|
||||
var msg = 'cannot ' + option.method + ' ' + option.action + ' ' + xhr.status + '\'';
|
||||
var err = new Error(msg);
|
||||
err.status = xhr.status;
|
||||
err.method = option.method;
|
||||
err.url = option.action;
|
||||
return err;
|
||||
}
|
||||
|
||||
function getBody(xhr) {
|
||||
var text = xhr.responseText || xhr.response;
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (e) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
// option {
|
||||
// onProgress: (event: { percent: number }): void,
|
||||
// onError: (event: Error, body?: Object): void,
|
||||
// onSuccess: (body: Object): void,
|
||||
// data: Object,
|
||||
// filename: String,
|
||||
// file: File,
|
||||
// withCredentials: Boolean,
|
||||
// action: String,
|
||||
// headers: Object,
|
||||
// }
|
||||
export default function upload(option) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
if (option.onProgress && xhr.upload) {
|
||||
xhr.upload.onprogress = function progress(e) {
|
||||
if (e.total > 0) {
|
||||
e.percent = e.loaded / e.total * 100;
|
||||
}
|
||||
option.onProgress(e);
|
||||
};
|
||||
}
|
||||
|
||||
var formData = new FormData();
|
||||
|
||||
if (option.data) {
|
||||
Object.keys(option.data).forEach(function (key) {
|
||||
var value = option.data[key];
|
||||
// support key-value array data
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(function (item) {
|
||||
// { list: [ 11, 22 ] }
|
||||
// formData.append('list[]', 11);
|
||||
formData.append(key + '[]', item);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
formData.append(key, option.data[key]);
|
||||
});
|
||||
}
|
||||
|
||||
if (option.file instanceof Blob) {
|
||||
formData.append(option.filename, option.file, option.file.name);
|
||||
} else {
|
||||
formData.append(option.filename, option.file);
|
||||
}
|
||||
|
||||
xhr.onerror = function error(e) {
|
||||
option.onError(e);
|
||||
};
|
||||
|
||||
xhr.onload = function onload() {
|
||||
// allow success when 2xx status
|
||||
// see https://github.com/react-component/upload/issues/34
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
return option.onError(getError(option, xhr), getBody(xhr));
|
||||
}
|
||||
|
||||
option.onSuccess(getBody(xhr), xhr);
|
||||
};
|
||||
|
||||
xhr.open(option.method, option.action, true);
|
||||
|
||||
// Has to be after `.open()`. See https://github.com/enyo/dropzone/issues/179
|
||||
if (option.withCredentials && 'withCredentials' in xhr) {
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
|
||||
var headers = option.headers || {};
|
||||
|
||||
// when set headers['X-Requested-With'] = null , can close default XHR header
|
||||
// see https://github.com/react-component/upload/issues/33
|
||||
if (headers['X-Requested-With'] !== null) {
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
for (var h in headers) {
|
||||
if (headers.hasOwnProperty(h) && headers[h] !== null) {
|
||||
xhr.setRequestHeader(h, headers[h]);
|
||||
}
|
||||
}
|
||||
xhr.send(formData);
|
||||
|
||||
return {
|
||||
abort: function abort() {
|
||||
xhr.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
81
web/node_modules/rc-upload/es/traverseFileTree.js
generated
vendored
Normal file
81
web/node_modules/rc-upload/es/traverseFileTree.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
function loopFiles(item, callback) {
|
||||
var dirReader = item.createReader();
|
||||
var fileList = [];
|
||||
|
||||
function sequence() {
|
||||
dirReader.readEntries(function (entries) {
|
||||
var entryList = Array.prototype.slice.apply(entries);
|
||||
fileList = fileList.concat(entryList);
|
||||
|
||||
// Check if all the file has been viewed
|
||||
var isFinished = !entryList.length;
|
||||
|
||||
if (isFinished) {
|
||||
callback(fileList);
|
||||
} else {
|
||||
sequence();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sequence();
|
||||
}
|
||||
|
||||
var traverseFileTree = function traverseFileTree(files, callback, isAccepted) {
|
||||
var _traverseFileTree = function _traverseFileTree(item, path) {
|
||||
path = path || '';
|
||||
if (item.isFile) {
|
||||
item.file(function (file) {
|
||||
if (isAccepted(file)) {
|
||||
// https://github.com/ant-design/ant-design/issues/16426
|
||||
if (item.fullPath && !file.webkitRelativePath) {
|
||||
Object.defineProperties(file, {
|
||||
webkitRelativePath: {
|
||||
writable: true
|
||||
}
|
||||
});
|
||||
file.webkitRelativePath = item.fullPath.replace(/^\//, '');
|
||||
Object.defineProperties(file, {
|
||||
webkitRelativePath: {
|
||||
writable: false
|
||||
}
|
||||
});
|
||||
}
|
||||
callback([file]);
|
||||
}
|
||||
});
|
||||
} else if (item.isDirectory) {
|
||||
loopFiles(item, function (entries) {
|
||||
entries.forEach(function (entryItem) {
|
||||
_traverseFileTree(entryItem, '' + path + item.name + '/');
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var file = _step.value;
|
||||
|
||||
_traverseFileTree(file.webkitGetAsEntry());
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator['return']) {
|
||||
_iterator['return']();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default traverseFileTree;
|
||||
6
web/node_modules/rc-upload/es/uid.js
generated
vendored
Normal file
6
web/node_modules/rc-upload/es/uid.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
var now = +new Date();
|
||||
var index = 0;
|
||||
|
||||
export default function uid() {
|
||||
return "rc-upload-" + now + "-" + ++index;
|
||||
}
|
||||
Reference in New Issue
Block a user