rsuite 5.15.0 → 5.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/cjs/Uploader/Uploader.d.ts +2 -0
- package/cjs/Uploader/Uploader.js +6 -2
- package/cjs/utils/ajaxUpload.d.ts +1 -0
- package/cjs/utils/ajaxUpload.js +3 -1
- package/dist/rsuite.js +2 -2
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Uploader/Uploader.d.ts +2 -0
- package/esm/Uploader/Uploader.js +6 -2
- package/esm/utils/ajaxUpload.d.ts +1 -0
- package/esm/utils/ajaxUpload.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [5.15.1](https://github.com/rsuite/rsuite/compare/v5.15.0...v5.15.1) (2022-06-16)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- **Uploader:** support `method` on `<Uploader>` ([#2541](https://github.com/rsuite/rsuite/issues/2541)) ([d3b821a](https://github.com/rsuite/rsuite/commit/d3b821a8f2acbd3162ec965ffdbaac07af23a727))
|
|
6
|
+
|
|
1
7
|
# [5.15.0](https://github.com/rsuite/rsuite/compare/v5.14.0...v5.15.0) (2022-06-09)
|
|
2
8
|
|
|
3
9
|
### Features
|
|
@@ -71,6 +71,8 @@ export interface UploaderProps extends WithAsProps {
|
|
|
71
71
|
draggable?: boolean;
|
|
72
72
|
/** Custom locale */
|
|
73
73
|
locale?: UploaderLocale;
|
|
74
|
+
/** The http method of upload request */
|
|
75
|
+
method?: string;
|
|
74
76
|
/** Allow the queue to be updated. After you select a file, update the checksum function before the upload file queue, and return false to not update */
|
|
75
77
|
shouldQueueUpdate?: (fileList: FileType[], newFile: FileType[] | FileType) => boolean | Promise<boolean>;
|
|
76
78
|
/** Allow uploading of files. Check function before file upload, return false without uploading */
|
package/cjs/Uploader/Uploader.js
CHANGED
|
@@ -140,6 +140,8 @@ var Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
140
140
|
removable = _props$removable === void 0 ? true : _props$removable,
|
|
141
141
|
disabledFileItem = props.disabledFileItem,
|
|
142
142
|
maxPreviewFileSize = props.maxPreviewFileSize,
|
|
143
|
+
_props$method = props.method,
|
|
144
|
+
method = _props$method === void 0 ? 'POST' : _props$method,
|
|
143
145
|
_props$autoUpload = props.autoUpload,
|
|
144
146
|
autoUpload = _props$autoUpload === void 0 ? true : _props$autoUpload,
|
|
145
147
|
action = props.action,
|
|
@@ -163,7 +165,7 @@ var Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
163
165
|
onError = props.onError,
|
|
164
166
|
onProgress = props.onProgress,
|
|
165
167
|
onReupload = props.onReupload,
|
|
166
|
-
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "listType", "defaultFileList", "fileList", "fileListVisible", "locale", "style", "draggable", "name", "multiple", "disabled", "readOnly", "plaintext", "accept", "children", "toggleAs", "removable", "disabledFileItem", "maxPreviewFileSize", "autoUpload", "action", "headers", "withCredentials", "disableMultipart", "timeout", "data", "onRemove", "onUpload", "shouldUpload", "shouldQueueUpdate", "renderFileInfo", "renderThumbnail", "onPreview", "onChange", "onSuccess", "onError", "onProgress", "onReupload"]);
|
|
168
|
+
rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "classPrefix", "className", "listType", "defaultFileList", "fileList", "fileListVisible", "locale", "style", "draggable", "name", "multiple", "disabled", "readOnly", "plaintext", "accept", "children", "toggleAs", "removable", "disabledFileItem", "maxPreviewFileSize", "method", "autoUpload", "action", "headers", "withCredentials", "disableMultipart", "timeout", "data", "onRemove", "onUpload", "shouldUpload", "shouldQueueUpdate", "renderFileInfo", "renderThumbnail", "onPreview", "onChange", "onSuccess", "onError", "onProgress", "onReupload"]);
|
|
167
169
|
|
|
168
170
|
var _useClassNames = (0, _utils.useClassNames)(classPrefix),
|
|
169
171
|
merge = _useClassNames.merge,
|
|
@@ -267,6 +269,7 @@ var Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
267
269
|
timeout: timeout,
|
|
268
270
|
headers: headers,
|
|
269
271
|
data: data,
|
|
272
|
+
method: method,
|
|
270
273
|
withCredentials: withCredentials,
|
|
271
274
|
disableMultipart: disableMultipart,
|
|
272
275
|
file: file.blobFile,
|
|
@@ -287,7 +290,7 @@ var Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
287
290
|
}
|
|
288
291
|
|
|
289
292
|
onUpload === null || onUpload === void 0 ? void 0 : onUpload(file, uploadData, xhr);
|
|
290
|
-
}, [
|
|
293
|
+
}, [name, timeout, headers, data, method, withCredentials, disableMultipart, action, handleAjaxUploadError, handleAjaxUploadSuccess, handleAjaxUploadProgress, updateFileStatus, onUpload]);
|
|
291
294
|
var handleAjaxUpload = (0, _react.useCallback)(function () {
|
|
292
295
|
fileList.current.forEach(function (file) {
|
|
293
296
|
var checkState = shouldUpload === null || shouldUpload === void 0 ? void 0 : shouldUpload(file);
|
|
@@ -481,6 +484,7 @@ Uploader.propTypes = {
|
|
|
481
484
|
onProgress: _propTypes.default.func,
|
|
482
485
|
onRemove: _propTypes.default.func,
|
|
483
486
|
maxPreviewFileSize: _propTypes.default.number,
|
|
487
|
+
method: _propTypes.default.string,
|
|
484
488
|
style: _propTypes.default.object,
|
|
485
489
|
renderFileInfo: _propTypes.default.func,
|
|
486
490
|
renderThumbnail: _propTypes.default.func,
|
|
@@ -11,6 +11,7 @@ interface Options {
|
|
|
11
11
|
headers?: any;
|
|
12
12
|
file: File;
|
|
13
13
|
url: string;
|
|
14
|
+
method?: string;
|
|
14
15
|
onError: (status: ErrorStatus, event: ProgressEvent, xhr: XMLHttpRequest) => void;
|
|
15
16
|
onSuccess: (response: any, event: ProgressEvent, xhr: XMLHttpRequest) => void;
|
|
16
17
|
onProgress: (percent: number, event: ProgressEvent, xhr: XMLHttpRequest) => void;
|
package/cjs/utils/ajaxUpload.js
CHANGED
|
@@ -24,6 +24,8 @@ function ajaxUpload(options) {
|
|
|
24
24
|
headers = _options$headers === void 0 ? {} : _options$headers,
|
|
25
25
|
_options$data = options.data,
|
|
26
26
|
data = _options$data === void 0 ? {} : _options$data,
|
|
27
|
+
_options$method = options.method,
|
|
28
|
+
method = _options$method === void 0 ? 'POST' : _options$method,
|
|
27
29
|
onError = options.onError,
|
|
28
30
|
onSuccess = options.onSuccess,
|
|
29
31
|
onProgress = options.onProgress,
|
|
@@ -33,7 +35,7 @@ function ajaxUpload(options) {
|
|
|
33
35
|
disableMultipart = options.disableMultipart;
|
|
34
36
|
var xhr = new XMLHttpRequest();
|
|
35
37
|
var sendableData;
|
|
36
|
-
xhr.open(
|
|
38
|
+
xhr.open(method, url, true);
|
|
37
39
|
|
|
38
40
|
if (!disableMultipart) {
|
|
39
41
|
sendableData = new FormData();
|
package/dist/rsuite.js
CHANGED
|
@@ -5048,7 +5048,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
|
|
|
5048
5048
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
5049
5049
|
|
|
5050
5050
|
"use strict";
|
|
5051
|
-
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\n\nvar _interopRequireWildcard = __webpack_require__(/*! @babel/runtime/helpers/interopRequireWildcard */ \"./node_modules/@babel/runtime/helpers/interopRequireWildcard.js\");\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\n\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\n\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\n\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\n\nvar _find = _interopRequireDefault(__webpack_require__(/*! lodash/find */ \"./node_modules/lodash/find.js\"));\n\nvar _UploadFileItem = _interopRequireDefault(__webpack_require__(/*! ./UploadFileItem */ \"./src/Uploader/UploadFileItem.tsx\"));\n\nvar _UploadTrigger = _interopRequireDefault(__webpack_require__(/*! ./UploadTrigger */ \"./src/Uploader/UploadTrigger.tsx\"));\n\nvar _utils = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n\nvar _Plaintext = _interopRequireDefault(__webpack_require__(/*! ../Plaintext */ \"./src/Plaintext/index.tsx\"));\n\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/Uploader.tsx\",\n _this = void 0;\n\nvar getFiles = function getFiles(event) {\n if (typeof (event === null || event === void 0 ? void 0 : event['dataTransfer']) === 'object') {\n var _event$dataTransfer;\n\n return event === null || event === void 0 ? void 0 : (_event$dataTransfer = event['dataTransfer']) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files;\n }\n\n if (event.target) {\n return event.target['files'];\n }\n\n return [];\n};\n\nvar createFile = function createFile(file) {\n var fileKey = file.fileKey;\n return (0, _extends2.default)({}, file, {\n fileKey: fileKey || (0, _utils.guid)(),\n progress: 0\n });\n};\n\nfunction fileListReducer(files, action) {\n var _action$files;\n\n switch (action.type) {\n // Add one or more files\n case 'push':\n return [].concat(files, action.files);\n // Remove a file by `fileKey`\n\n case 'remove':\n return files.filter(function (f) {\n return f.fileKey !== action.fileKey;\n });\n // Update a file\n\n case 'updateFile':\n return files.map(function (file) {\n return file.fileKey === action.file.fileKey ? action.file : file;\n });\n // Initialization file list\n\n case 'init':\n return ((_action$files = action.files) === null || _action$files === void 0 ? void 0 : _action$files.map(function (file) {\n // The state of the file needs to be preserved when the `fileList` is controlled.\n return files.find(function (f) {\n return f.fileKey === file.fileKey;\n }) || createFile(file);\n })) || [];\n\n default:\n throw new Error();\n }\n}\n\nvar useFileList = function useFileList(defaultFileList) {\n if (defaultFileList === void 0) {\n defaultFileList = [];\n }\n\n var fileListRef = (0, _react.useRef)(defaultFileList.map(createFile));\n var fileListUpdateCallback = (0, _react.useRef)();\n\n var _useReducer = (0, _react.useReducer)(fileListReducer, fileListRef.current),\n fileList = _useReducer[0],\n dispatch = _useReducer[1];\n\n fileListRef.current = fileList;\n (0, _react.useEffect)(function () {\n var _fileListUpdateCallba;\n\n (_fileListUpdateCallba = fileListUpdateCallback.current) === null || _fileListUpdateCallba === void 0 ? void 0 : _fileListUpdateCallba.call(fileListUpdateCallback, fileList);\n fileListUpdateCallback.current = null;\n }, [fileList]);\n (0, _utils.useWillUnmount)(function () {\n fileListUpdateCallback.current = null;\n });\n var dispatchCallback = (0, _react.useCallback)(function (action, callback) {\n dispatch(action);\n fileListUpdateCallback.current = callback;\n }, []);\n return [fileListRef, dispatchCallback];\n};\n\nvar Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _props$as = props.as,\n Component = _props$as === void 0 ? 'div' : _props$as,\n _props$classPrefix = props.classPrefix,\n classPrefix = _props$classPrefix === void 0 ? 'uploader' : _props$classPrefix,\n className = props.className,\n _props$listType = props.listType,\n listType = _props$listType === void 0 ? 'text' : _props$listType,\n defaultFileList = props.defaultFileList,\n fileListProp = props.fileList,\n _props$fileListVisibl = props.fileListVisible,\n fileListVisible = _props$fileListVisibl === void 0 ? true : _props$fileListVisibl,\n localeProp = props.locale,\n style = props.style,\n draggable = props.draggable,\n _props$name = props.name,\n name = _props$name === void 0 ? 'file' : _props$name,\n _props$multiple = props.multiple,\n multiple = _props$multiple === void 0 ? false : _props$multiple,\n _props$disabled = props.disabled,\n disabled = _props$disabled === void 0 ? false : _props$disabled,\n readOnly = props.readOnly,\n plaintext = props.plaintext,\n accept = props.accept,\n children = props.children,\n toggleAs = props.toggleAs,\n _props$removable = props.removable,\n removable = _props$removable === void 0 ? true : _props$removable,\n disabledFileItem = props.disabledFileItem,\n maxPreviewFileSize = props.maxPreviewFileSize,\n _props$autoUpload = props.autoUpload,\n autoUpload = _props$autoUpload === void 0 ? true : _props$autoUpload,\n action = props.action,\n headers = props.headers,\n _props$withCredential = props.withCredentials,\n withCredentials = _props$withCredential === void 0 ? false : _props$withCredential,\n disableMultipart = props.disableMultipart,\n _props$timeout = props.timeout,\n timeout = _props$timeout === void 0 ? 0 : _props$timeout,\n _props$data = props.data,\n data = _props$data === void 0 ? {} : _props$data,\n onRemove = props.onRemove,\n onUpload = props.onUpload,\n shouldUpload = props.shouldUpload,\n shouldQueueUpdate = props.shouldQueueUpdate,\n renderFileInfo = props.renderFileInfo,\n renderThumbnail = props.renderThumbnail,\n onPreview = props.onPreview,\n onChange = props.onChange,\n onSuccess = props.onSuccess,\n onError = props.onError,\n onProgress = props.onProgress,\n onReupload = props.onReupload,\n rest = (0, _objectWithoutPropertiesLoose2.default)(props, [\"as\", \"classPrefix\", \"className\", \"listType\", \"defaultFileList\", \"fileList\", \"fileListVisible\", \"locale\", \"style\", \"draggable\", \"name\", \"multiple\", \"disabled\", \"readOnly\", \"plaintext\", \"accept\", \"children\", \"toggleAs\", \"removable\", \"disabledFileItem\", \"maxPreviewFileSize\", \"autoUpload\", \"action\", \"headers\", \"withCredentials\", \"disableMultipart\", \"timeout\", \"data\", \"onRemove\", \"onUpload\", \"shouldUpload\", \"shouldQueueUpdate\", \"renderFileInfo\", \"renderThumbnail\", \"onPreview\", \"onChange\", \"onSuccess\", \"onError\", \"onProgress\", \"onReupload\"]);\n\n var _useClassNames = (0, _utils.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n\n var classes = merge(className, withClassPrefix(listType, {\n draggable: draggable\n }));\n\n var _useCustom = (0, _utils.useCustom)('Uploader', localeProp),\n locale = _useCustom.locale;\n\n var rootRef = (0, _react.useRef)();\n var xhrs = (0, _react.useRef)({});\n var trigger = (0, _react.useRef)();\n\n var _useFileList = useFileList(fileListProp || defaultFileList),\n fileList = _useFileList[0],\n dispatch = _useFileList[1];\n\n (0, _react.useEffect)(function () {\n if (typeof fileListProp !== 'undefined') {\n // Force reset fileList in reducer, when `fileListProp` is updated\n dispatch({\n type: 'init',\n files: fileListProp\n });\n }\n }, [dispatch, fileListProp]);\n var updateFileStatus = (0, _react.useCallback)(function (nextFile) {\n dispatch({\n type: 'updateFile',\n file: nextFile\n });\n }, [dispatch]);\n /**\n * Clear the value in input.\n */\n\n var cleanInputValue = (0, _react.useCallback)(function () {\n var _trigger$current;\n\n (_trigger$current = trigger.current) === null || _trigger$current === void 0 ? void 0 : _trigger$current.clearInput();\n }, []);\n /**\n * Callback for successful file upload.\n * @param file\n * @param response\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadSuccess = (0, _react.useCallback)(function (file, response, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'finished',\n progress: 100\n });\n updateFileStatus(nextFile);\n onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, nextFile, event, xhr);\n }, [onSuccess, updateFileStatus]);\n /**\n * Callback for file upload error.\n * @param file\n * @param status\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadError = (0, _react.useCallback)(function (file, status, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'error'\n });\n updateFileStatus(nextFile);\n onError === null || onError === void 0 ? void 0 : onError(status, nextFile, event, xhr);\n }, [onError, updateFileStatus]);\n /**\n * Callback for file upload progress update.\n * @param file\n * @param percent\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadProgress = (0, _react.useCallback)(function (file, percent, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'uploading',\n progress: percent\n });\n updateFileStatus(nextFile);\n onProgress === null || onProgress === void 0 ? void 0 : onProgress(percent, nextFile, event, xhr);\n }, [onProgress, updateFileStatus]);\n /**\n * Upload a single file.\n * @param file\n */\n\n var handleUploadFile = (0, _react.useCallback)(function (file) {\n var _ajaxUpload = (0, _utils.ajaxUpload)({\n name: name,\n timeout: timeout,\n headers: headers,\n data: data,\n withCredentials: withCredentials,\n disableMultipart: disableMultipart,\n file: file.blobFile,\n url: action,\n onError: handleAjaxUploadError.bind(null, file),\n onSuccess: handleAjaxUploadSuccess.bind(null, file),\n onProgress: handleAjaxUploadProgress.bind(null, file)\n }),\n xhr = _ajaxUpload.xhr,\n uploadData = _ajaxUpload.data;\n\n updateFileStatus((0, _extends2.default)({}, file, {\n status: 'uploading'\n }));\n\n if (file.fileKey) {\n xhrs.current[file.fileKey] = xhr;\n }\n\n onUpload === null || onUpload === void 0 ? void 0 : onUpload(file, uploadData, xhr);\n }, [action, data, handleAjaxUploadError, handleAjaxUploadProgress, handleAjaxUploadSuccess, headers, name, onUpload, timeout, updateFileStatus, withCredentials, disableMultipart]);\n var handleAjaxUpload = (0, _react.useCallback)(function () {\n fileList.current.forEach(function (file) {\n var checkState = shouldUpload === null || shouldUpload === void 0 ? void 0 : shouldUpload(file);\n\n if (checkState instanceof Promise) {\n checkState.then(function (res) {\n if (res) {\n handleUploadFile(file);\n }\n });\n return;\n } else if (checkState === false) {\n return;\n }\n\n if (file.status === 'inited') {\n handleUploadFile(file);\n }\n });\n cleanInputValue();\n }, [cleanInputValue, fileList, handleUploadFile, shouldUpload]);\n\n var handleUploadTriggerChange = function handleUploadTriggerChange(event) {\n var files = getFiles(event);\n var newFileList = [];\n Array.from(files).forEach(function (file) {\n newFileList.push({\n blobFile: file,\n name: file.name,\n status: 'inited',\n fileKey: (0, _utils.guid)()\n });\n });\n var nextFileList = [].concat(fileList.current, newFileList);\n var checkState = shouldQueueUpdate === null || shouldQueueUpdate === void 0 ? void 0 : shouldQueueUpdate(nextFileList, newFileList);\n\n if (checkState === false) {\n cleanInputValue();\n return;\n }\n\n var upload = function upload() {\n onChange === null || onChange === void 0 ? void 0 : onChange(nextFileList);\n dispatch({\n type: 'push',\n files: newFileList\n }, function () {\n autoUpload && handleAjaxUpload();\n });\n };\n\n if (checkState instanceof Promise) {\n checkState.then(function (res) {\n res && upload();\n });\n return;\n }\n\n upload();\n };\n\n var handleRemoveFile = function handleRemoveFile(fileKey) {\n var _xhrs$current, _xhrs$current$file$fi;\n\n var file = (0, _find.default)(fileList.current, function (f) {\n return f.fileKey === fileKey;\n });\n var nextFileList = fileList.current.filter(function (f) {\n return f.fileKey !== fileKey;\n });\n\n if (((_xhrs$current = xhrs.current) === null || _xhrs$current === void 0 ? void 0 : (_xhrs$current$file$fi = _xhrs$current[file.fileKey]) === null || _xhrs$current$file$fi === void 0 ? void 0 : _xhrs$current$file$fi.readyState) !== 4) {\n var _xhrs$current$file$fi2;\n\n (_xhrs$current$file$fi2 = xhrs.current[file.fileKey]) === null || _xhrs$current$file$fi2 === void 0 ? void 0 : _xhrs$current$file$fi2.abort();\n }\n\n dispatch({\n type: 'remove',\n fileKey: fileKey\n });\n onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);\n onChange === null || onChange === void 0 ? void 0 : onChange(nextFileList);\n cleanInputValue();\n };\n\n var handleReupload = function handleReupload(file) {\n autoUpload && handleUploadFile(file);\n onReupload === null || onReupload === void 0 ? void 0 : onReupload(file);\n }; // public API\n\n\n var start = function start(file) {\n if (file) {\n handleUploadFile(file);\n return;\n }\n\n handleAjaxUpload();\n };\n\n (0, _react.useImperativeHandle)(ref, function () {\n return {\n root: rootRef.current,\n start: start\n };\n });\n var renderList = [/*#__PURE__*/_react.default.createElement(_UploadTrigger.default, (0, _extends2.default)({}, rest, {\n locale: locale,\n name: name,\n key: \"trigger\",\n multiple: multiple,\n draggable: draggable,\n disabled: disabled,\n readOnly: readOnly,\n accept: accept,\n ref: trigger,\n onChange: handleUploadTriggerChange,\n as: toggleAs,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 518,\n columnNumber: 5\n }\n }), children)];\n\n if (fileListVisible) {\n renderList.push( /*#__PURE__*/_react.default.createElement(\"div\", {\n key: \"items\",\n className: prefix('file-items'),\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 538,\n columnNumber: 7\n }\n }, fileList.current.map(function (file, index) {\n return /*#__PURE__*/_react.default.createElement(_UploadFileItem.default, {\n locale: locale,\n key: file.fileKey || index,\n file: file,\n maxPreviewFileSize: maxPreviewFileSize,\n listType: listType,\n disabled: disabledFileItem,\n onPreview: onPreview,\n onReupload: handleReupload,\n onCancel: handleRemoveFile,\n renderFileInfo: renderFileInfo,\n renderThumbnail: renderThumbnail,\n removable: removable && !readOnly && !plaintext,\n allowReupload: !readOnly && !plaintext,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 540,\n columnNumber: 11\n }\n });\n })));\n }\n\n if (plaintext) {\n return /*#__PURE__*/_react.default.createElement(_Plaintext.default, {\n localeKey: \"notUploaded\",\n className: withClassPrefix(listType),\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 562,\n columnNumber: 7\n }\n }, fileList.current.length ? renderList[1] : null);\n }\n\n if (listType === 'picture') {\n renderList.reverse();\n }\n\n return /*#__PURE__*/_react.default.createElement(Component, {\n ref: rootRef,\n className: classes,\n style: style,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 573,\n columnNumber: 5\n }\n }, renderList);\n});\n\nUploader.displayName = 'Uploader';\nUploader.propTypes = {\n action: _propTypes.default.string.isRequired,\n accept: _propTypes.default.string,\n autoUpload: _propTypes.default.bool,\n children: _propTypes.default.node,\n className: _propTypes.default.string,\n classPrefix: _propTypes.default.string,\n defaultFileList: _propTypes.default.array,\n fileList: _propTypes.default.array,\n data: _propTypes.default.object,\n multiple: _propTypes.default.bool,\n disabled: _propTypes.default.bool,\n disabledFileItem: _propTypes.default.bool,\n name: _propTypes.default.string,\n timeout: _propTypes.default.number,\n withCredentials: _propTypes.default.bool,\n headers: _propTypes.default.object,\n locale: _propTypes.default.any,\n listType: _propTypes.default.oneOf(['text', 'picture-text', 'picture']),\n shouldQueueUpdate: _propTypes.default.func,\n shouldUpload: _propTypes.default.func,\n onChange: _propTypes.default.func,\n onUpload: _propTypes.default.func,\n onReupload: _propTypes.default.func,\n onPreview: _propTypes.default.func,\n onError: _propTypes.default.func,\n onSuccess: _propTypes.default.func,\n onProgress: _propTypes.default.func,\n onRemove: _propTypes.default.func,\n maxPreviewFileSize: _propTypes.default.number,\n style: _propTypes.default.object,\n renderFileInfo: _propTypes.default.func,\n renderThumbnail: _propTypes.default.func,\n removable: _propTypes.default.bool,\n fileListVisible: _propTypes.default.bool,\n draggable: _propTypes.default.bool,\n disableMultipart: _propTypes.default.bool\n};\nvar _default = Uploader;\nexports.default = _default;\n\n//# sourceURL=webpack://rsuite/./src/Uploader/Uploader.tsx?");
|
|
5051
|
+
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\n\nvar _interopRequireWildcard = __webpack_require__(/*! @babel/runtime/helpers/interopRequireWildcard */ \"./node_modules/@babel/runtime/helpers/interopRequireWildcard.js\");\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\n\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\n\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\n\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\n\nvar _find = _interopRequireDefault(__webpack_require__(/*! lodash/find */ \"./node_modules/lodash/find.js\"));\n\nvar _UploadFileItem = _interopRequireDefault(__webpack_require__(/*! ./UploadFileItem */ \"./src/Uploader/UploadFileItem.tsx\"));\n\nvar _UploadTrigger = _interopRequireDefault(__webpack_require__(/*! ./UploadTrigger */ \"./src/Uploader/UploadTrigger.tsx\"));\n\nvar _utils = __webpack_require__(/*! ../utils */ \"./src/utils/index.ts\");\n\nvar _Plaintext = _interopRequireDefault(__webpack_require__(/*! ../Plaintext */ \"./src/Plaintext/index.tsx\"));\n\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/Uploader.tsx\",\n _this = void 0;\n\nvar getFiles = function getFiles(event) {\n if (typeof (event === null || event === void 0 ? void 0 : event['dataTransfer']) === 'object') {\n var _event$dataTransfer;\n\n return event === null || event === void 0 ? void 0 : (_event$dataTransfer = event['dataTransfer']) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files;\n }\n\n if (event.target) {\n return event.target['files'];\n }\n\n return [];\n};\n\nvar createFile = function createFile(file) {\n var fileKey = file.fileKey;\n return (0, _extends2.default)({}, file, {\n fileKey: fileKey || (0, _utils.guid)(),\n progress: 0\n });\n};\n\nfunction fileListReducer(files, action) {\n var _action$files;\n\n switch (action.type) {\n // Add one or more files\n case 'push':\n return [].concat(files, action.files);\n // Remove a file by `fileKey`\n\n case 'remove':\n return files.filter(function (f) {\n return f.fileKey !== action.fileKey;\n });\n // Update a file\n\n case 'updateFile':\n return files.map(function (file) {\n return file.fileKey === action.file.fileKey ? action.file : file;\n });\n // Initialization file list\n\n case 'init':\n return ((_action$files = action.files) === null || _action$files === void 0 ? void 0 : _action$files.map(function (file) {\n // The state of the file needs to be preserved when the `fileList` is controlled.\n return files.find(function (f) {\n return f.fileKey === file.fileKey;\n }) || createFile(file);\n })) || [];\n\n default:\n throw new Error();\n }\n}\n\nvar useFileList = function useFileList(defaultFileList) {\n if (defaultFileList === void 0) {\n defaultFileList = [];\n }\n\n var fileListRef = (0, _react.useRef)(defaultFileList.map(createFile));\n var fileListUpdateCallback = (0, _react.useRef)();\n\n var _useReducer = (0, _react.useReducer)(fileListReducer, fileListRef.current),\n fileList = _useReducer[0],\n dispatch = _useReducer[1];\n\n fileListRef.current = fileList;\n (0, _react.useEffect)(function () {\n var _fileListUpdateCallba;\n\n (_fileListUpdateCallba = fileListUpdateCallback.current) === null || _fileListUpdateCallba === void 0 ? void 0 : _fileListUpdateCallba.call(fileListUpdateCallback, fileList);\n fileListUpdateCallback.current = null;\n }, [fileList]);\n (0, _utils.useWillUnmount)(function () {\n fileListUpdateCallback.current = null;\n });\n var dispatchCallback = (0, _react.useCallback)(function (action, callback) {\n dispatch(action);\n fileListUpdateCallback.current = callback;\n }, []);\n return [fileListRef, dispatchCallback];\n};\n\nvar Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _props$as = props.as,\n Component = _props$as === void 0 ? 'div' : _props$as,\n _props$classPrefix = props.classPrefix,\n classPrefix = _props$classPrefix === void 0 ? 'uploader' : _props$classPrefix,\n className = props.className,\n _props$listType = props.listType,\n listType = _props$listType === void 0 ? 'text' : _props$listType,\n defaultFileList = props.defaultFileList,\n fileListProp = props.fileList,\n _props$fileListVisibl = props.fileListVisible,\n fileListVisible = _props$fileListVisibl === void 0 ? true : _props$fileListVisibl,\n localeProp = props.locale,\n style = props.style,\n draggable = props.draggable,\n _props$name = props.name,\n name = _props$name === void 0 ? 'file' : _props$name,\n _props$multiple = props.multiple,\n multiple = _props$multiple === void 0 ? false : _props$multiple,\n _props$disabled = props.disabled,\n disabled = _props$disabled === void 0 ? false : _props$disabled,\n readOnly = props.readOnly,\n plaintext = props.plaintext,\n accept = props.accept,\n children = props.children,\n toggleAs = props.toggleAs,\n _props$removable = props.removable,\n removable = _props$removable === void 0 ? true : _props$removable,\n disabledFileItem = props.disabledFileItem,\n maxPreviewFileSize = props.maxPreviewFileSize,\n _props$method = props.method,\n method = _props$method === void 0 ? 'POST' : _props$method,\n _props$autoUpload = props.autoUpload,\n autoUpload = _props$autoUpload === void 0 ? true : _props$autoUpload,\n action = props.action,\n headers = props.headers,\n _props$withCredential = props.withCredentials,\n withCredentials = _props$withCredential === void 0 ? false : _props$withCredential,\n disableMultipart = props.disableMultipart,\n _props$timeout = props.timeout,\n timeout = _props$timeout === void 0 ? 0 : _props$timeout,\n _props$data = props.data,\n data = _props$data === void 0 ? {} : _props$data,\n onRemove = props.onRemove,\n onUpload = props.onUpload,\n shouldUpload = props.shouldUpload,\n shouldQueueUpdate = props.shouldQueueUpdate,\n renderFileInfo = props.renderFileInfo,\n renderThumbnail = props.renderThumbnail,\n onPreview = props.onPreview,\n onChange = props.onChange,\n onSuccess = props.onSuccess,\n onError = props.onError,\n onProgress = props.onProgress,\n onReupload = props.onReupload,\n rest = (0, _objectWithoutPropertiesLoose2.default)(props, [\"as\", \"classPrefix\", \"className\", \"listType\", \"defaultFileList\", \"fileList\", \"fileListVisible\", \"locale\", \"style\", \"draggable\", \"name\", \"multiple\", \"disabled\", \"readOnly\", \"plaintext\", \"accept\", \"children\", \"toggleAs\", \"removable\", \"disabledFileItem\", \"maxPreviewFileSize\", \"method\", \"autoUpload\", \"action\", \"headers\", \"withCredentials\", \"disableMultipart\", \"timeout\", \"data\", \"onRemove\", \"onUpload\", \"shouldUpload\", \"shouldQueueUpdate\", \"renderFileInfo\", \"renderThumbnail\", \"onPreview\", \"onChange\", \"onSuccess\", \"onError\", \"onProgress\", \"onReupload\"]);\n\n var _useClassNames = (0, _utils.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n\n var classes = merge(className, withClassPrefix(listType, {\n draggable: draggable\n }));\n\n var _useCustom = (0, _utils.useCustom)('Uploader', localeProp),\n locale = _useCustom.locale;\n\n var rootRef = (0, _react.useRef)();\n var xhrs = (0, _react.useRef)({});\n var trigger = (0, _react.useRef)();\n\n var _useFileList = useFileList(fileListProp || defaultFileList),\n fileList = _useFileList[0],\n dispatch = _useFileList[1];\n\n (0, _react.useEffect)(function () {\n if (typeof fileListProp !== 'undefined') {\n // Force reset fileList in reducer, when `fileListProp` is updated\n dispatch({\n type: 'init',\n files: fileListProp\n });\n }\n }, [dispatch, fileListProp]);\n var updateFileStatus = (0, _react.useCallback)(function (nextFile) {\n dispatch({\n type: 'updateFile',\n file: nextFile\n });\n }, [dispatch]);\n /**\n * Clear the value in input.\n */\n\n var cleanInputValue = (0, _react.useCallback)(function () {\n var _trigger$current;\n\n (_trigger$current = trigger.current) === null || _trigger$current === void 0 ? void 0 : _trigger$current.clearInput();\n }, []);\n /**\n * Callback for successful file upload.\n * @param file\n * @param response\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadSuccess = (0, _react.useCallback)(function (file, response, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'finished',\n progress: 100\n });\n updateFileStatus(nextFile);\n onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, nextFile, event, xhr);\n }, [onSuccess, updateFileStatus]);\n /**\n * Callback for file upload error.\n * @param file\n * @param status\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadError = (0, _react.useCallback)(function (file, status, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'error'\n });\n updateFileStatus(nextFile);\n onError === null || onError === void 0 ? void 0 : onError(status, nextFile, event, xhr);\n }, [onError, updateFileStatus]);\n /**\n * Callback for file upload progress update.\n * @param file\n * @param percent\n * @param event\n * @param xhr\n */\n\n var handleAjaxUploadProgress = (0, _react.useCallback)(function (file, percent, event, xhr) {\n var nextFile = (0, _extends2.default)({}, file, {\n status: 'uploading',\n progress: percent\n });\n updateFileStatus(nextFile);\n onProgress === null || onProgress === void 0 ? void 0 : onProgress(percent, nextFile, event, xhr);\n }, [onProgress, updateFileStatus]);\n /**\n * Upload a single file.\n * @param file\n */\n\n var handleUploadFile = (0, _react.useCallback)(function (file) {\n var _ajaxUpload = (0, _utils.ajaxUpload)({\n name: name,\n timeout: timeout,\n headers: headers,\n data: data,\n method: method,\n withCredentials: withCredentials,\n disableMultipart: disableMultipart,\n file: file.blobFile,\n url: action,\n onError: handleAjaxUploadError.bind(null, file),\n onSuccess: handleAjaxUploadSuccess.bind(null, file),\n onProgress: handleAjaxUploadProgress.bind(null, file)\n }),\n xhr = _ajaxUpload.xhr,\n uploadData = _ajaxUpload.data;\n\n updateFileStatus((0, _extends2.default)({}, file, {\n status: 'uploading'\n }));\n\n if (file.fileKey) {\n xhrs.current[file.fileKey] = xhr;\n }\n\n onUpload === null || onUpload === void 0 ? void 0 : onUpload(file, uploadData, xhr);\n }, [name, timeout, headers, data, method, withCredentials, disableMultipart, action, handleAjaxUploadError, handleAjaxUploadSuccess, handleAjaxUploadProgress, updateFileStatus, onUpload]);\n var handleAjaxUpload = (0, _react.useCallback)(function () {\n fileList.current.forEach(function (file) {\n var checkState = shouldUpload === null || shouldUpload === void 0 ? void 0 : shouldUpload(file);\n\n if (checkState instanceof Promise) {\n checkState.then(function (res) {\n if (res) {\n handleUploadFile(file);\n }\n });\n return;\n } else if (checkState === false) {\n return;\n }\n\n if (file.status === 'inited') {\n handleUploadFile(file);\n }\n });\n cleanInputValue();\n }, [cleanInputValue, fileList, handleUploadFile, shouldUpload]);\n\n var handleUploadTriggerChange = function handleUploadTriggerChange(event) {\n var files = getFiles(event);\n var newFileList = [];\n Array.from(files).forEach(function (file) {\n newFileList.push({\n blobFile: file,\n name: file.name,\n status: 'inited',\n fileKey: (0, _utils.guid)()\n });\n });\n var nextFileList = [].concat(fileList.current, newFileList);\n var checkState = shouldQueueUpdate === null || shouldQueueUpdate === void 0 ? void 0 : shouldQueueUpdate(nextFileList, newFileList);\n\n if (checkState === false) {\n cleanInputValue();\n return;\n }\n\n var upload = function upload() {\n onChange === null || onChange === void 0 ? void 0 : onChange(nextFileList);\n dispatch({\n type: 'push',\n files: newFileList\n }, function () {\n autoUpload && handleAjaxUpload();\n });\n };\n\n if (checkState instanceof Promise) {\n checkState.then(function (res) {\n res && upload();\n });\n return;\n }\n\n upload();\n };\n\n var handleRemoveFile = function handleRemoveFile(fileKey) {\n var _xhrs$current, _xhrs$current$file$fi;\n\n var file = (0, _find.default)(fileList.current, function (f) {\n return f.fileKey === fileKey;\n });\n var nextFileList = fileList.current.filter(function (f) {\n return f.fileKey !== fileKey;\n });\n\n if (((_xhrs$current = xhrs.current) === null || _xhrs$current === void 0 ? void 0 : (_xhrs$current$file$fi = _xhrs$current[file.fileKey]) === null || _xhrs$current$file$fi === void 0 ? void 0 : _xhrs$current$file$fi.readyState) !== 4) {\n var _xhrs$current$file$fi2;\n\n (_xhrs$current$file$fi2 = xhrs.current[file.fileKey]) === null || _xhrs$current$file$fi2 === void 0 ? void 0 : _xhrs$current$file$fi2.abort();\n }\n\n dispatch({\n type: 'remove',\n fileKey: fileKey\n });\n onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);\n onChange === null || onChange === void 0 ? void 0 : onChange(nextFileList);\n cleanInputValue();\n };\n\n var handleReupload = function handleReupload(file) {\n autoUpload && handleUploadFile(file);\n onReupload === null || onReupload === void 0 ? void 0 : onReupload(file);\n }; // public API\n\n\n var start = function start(file) {\n if (file) {\n handleUploadFile(file);\n return;\n }\n\n handleAjaxUpload();\n };\n\n (0, _react.useImperativeHandle)(ref, function () {\n return {\n root: rootRef.current,\n start: start\n };\n });\n var renderList = [/*#__PURE__*/_react.default.createElement(_UploadTrigger.default, (0, _extends2.default)({}, rest, {\n locale: locale,\n name: name,\n key: \"trigger\",\n multiple: multiple,\n draggable: draggable,\n disabled: disabled,\n readOnly: readOnly,\n accept: accept,\n ref: trigger,\n onChange: handleUploadTriggerChange,\n as: toggleAs,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 524,\n columnNumber: 5\n }\n }), children)];\n\n if (fileListVisible) {\n renderList.push( /*#__PURE__*/_react.default.createElement(\"div\", {\n key: \"items\",\n className: prefix('file-items'),\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 544,\n columnNumber: 7\n }\n }, fileList.current.map(function (file, index) {\n return /*#__PURE__*/_react.default.createElement(_UploadFileItem.default, {\n locale: locale,\n key: file.fileKey || index,\n file: file,\n maxPreviewFileSize: maxPreviewFileSize,\n listType: listType,\n disabled: disabledFileItem,\n onPreview: onPreview,\n onReupload: handleReupload,\n onCancel: handleRemoveFile,\n renderFileInfo: renderFileInfo,\n renderThumbnail: renderThumbnail,\n removable: removable && !readOnly && !plaintext,\n allowReupload: !readOnly && !plaintext,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 546,\n columnNumber: 11\n }\n });\n })));\n }\n\n if (plaintext) {\n return /*#__PURE__*/_react.default.createElement(_Plaintext.default, {\n localeKey: \"notUploaded\",\n className: withClassPrefix(listType),\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 568,\n columnNumber: 7\n }\n }, fileList.current.length ? renderList[1] : null);\n }\n\n if (listType === 'picture') {\n renderList.reverse();\n }\n\n return /*#__PURE__*/_react.default.createElement(Component, {\n ref: rootRef,\n className: classes,\n style: style,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 579,\n columnNumber: 5\n }\n }, renderList);\n});\n\nUploader.displayName = 'Uploader';\nUploader.propTypes = {\n action: _propTypes.default.string.isRequired,\n accept: _propTypes.default.string,\n autoUpload: _propTypes.default.bool,\n children: _propTypes.default.node,\n className: _propTypes.default.string,\n classPrefix: _propTypes.default.string,\n defaultFileList: _propTypes.default.array,\n fileList: _propTypes.default.array,\n data: _propTypes.default.object,\n multiple: _propTypes.default.bool,\n disabled: _propTypes.default.bool,\n disabledFileItem: _propTypes.default.bool,\n name: _propTypes.default.string,\n timeout: _propTypes.default.number,\n withCredentials: _propTypes.default.bool,\n headers: _propTypes.default.object,\n locale: _propTypes.default.any,\n listType: _propTypes.default.oneOf(['text', 'picture-text', 'picture']),\n shouldQueueUpdate: _propTypes.default.func,\n shouldUpload: _propTypes.default.func,\n onChange: _propTypes.default.func,\n onUpload: _propTypes.default.func,\n onReupload: _propTypes.default.func,\n onPreview: _propTypes.default.func,\n onError: _propTypes.default.func,\n onSuccess: _propTypes.default.func,\n onProgress: _propTypes.default.func,\n onRemove: _propTypes.default.func,\n maxPreviewFileSize: _propTypes.default.number,\n method: _propTypes.default.string,\n style: _propTypes.default.object,\n renderFileInfo: _propTypes.default.func,\n renderThumbnail: _propTypes.default.func,\n removable: _propTypes.default.bool,\n fileListVisible: _propTypes.default.bool,\n draggable: _propTypes.default.bool,\n disableMultipart: _propTypes.default.bool\n};\nvar _default = Uploader;\nexports.default = _default;\n\n//# sourceURL=webpack://rsuite/./src/Uploader/Uploader.tsx?");
|
|
5052
5052
|
|
|
5053
5053
|
/***/ }),
|
|
5054
5054
|
|
|
@@ -5180,7 +5180,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
|
|
|
5180
5180
|
/***/ (function(__unused_webpack_module, exports) {
|
|
5181
5181
|
|
|
5182
5182
|
"use strict";
|
|
5183
|
-
eval("\n\nexports.__esModule = true;\nexports.default = ajaxUpload;\n\nfunction getResponse(xhr) {\n var text = xhr.responseText || xhr.response;\n\n if (!text) {\n return text;\n }\n\n try {\n return JSON.parse(text);\n } catch (e) {\n return text;\n }\n}\n\nfunction ajaxUpload(options) {\n var name = options.name,\n timeout = options.timeout,\n _options$headers = options.headers,\n headers = _options$headers === void 0 ? {} : _options$headers,\n _options$data = options.data,\n data = _options$data === void 0 ? {} : _options$data,\n onError = options.onError,\n onSuccess = options.onSuccess,\n onProgress = options.onProgress,\n file = options.file,\n url = options.url,\n withCredentials = options.withCredentials,\n disableMultipart = options.disableMultipart;\n var xhr = new XMLHttpRequest();\n var sendableData;\n xhr.open(
|
|
5183
|
+
eval("\n\nexports.__esModule = true;\nexports.default = ajaxUpload;\n\nfunction getResponse(xhr) {\n var text = xhr.responseText || xhr.response;\n\n if (!text) {\n return text;\n }\n\n try {\n return JSON.parse(text);\n } catch (e) {\n return text;\n }\n}\n\nfunction ajaxUpload(options) {\n var name = options.name,\n timeout = options.timeout,\n _options$headers = options.headers,\n headers = _options$headers === void 0 ? {} : _options$headers,\n _options$data = options.data,\n data = _options$data === void 0 ? {} : _options$data,\n _options$method = options.method,\n method = _options$method === void 0 ? 'POST' : _options$method,\n onError = options.onError,\n onSuccess = options.onSuccess,\n onProgress = options.onProgress,\n file = options.file,\n url = options.url,\n withCredentials = options.withCredentials,\n disableMultipart = options.disableMultipart;\n var xhr = new XMLHttpRequest();\n var sendableData;\n xhr.open(method, url, true);\n\n if (!disableMultipart) {\n sendableData = new FormData();\n sendableData.append(name, file, file.name);\n\n for (var key in data) {\n sendableData.append(key, data[key]);\n }\n } else {\n sendableData = file;\n }\n\n Object.keys(headers).forEach(function (key) {\n if (headers[key] !== null) {\n xhr.setRequestHeader(key, headers[key]);\n }\n });\n\n if (headers['X-Requested-With'] !== null) {\n xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');\n }\n\n if (timeout) {\n xhr.timeout = timeout;\n\n xhr.ontimeout = function (event) {\n onError === null || onError === void 0 ? void 0 : onError({\n type: 'timeout'\n }, event, xhr);\n };\n }\n\n if (withCredentials && 'withCredentials' in xhr) {\n xhr.withCredentials = true;\n }\n\n xhr.onload = function (event) {\n var resp = getResponse(xhr);\n\n if (xhr.status < 200 || xhr.status >= 300) {\n onError === null || onError === void 0 ? void 0 : onError({\n type: 'server_error',\n response: resp\n }, event, xhr);\n return;\n }\n\n onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(resp, event, xhr);\n };\n\n if (xhr.upload) {\n xhr.upload.onprogress = function (event) {\n var percent = 0;\n\n if (event.lengthComputable) {\n percent = event.loaded / event.total * 100;\n }\n\n onProgress === null || onProgress === void 0 ? void 0 : onProgress(percent, event, xhr);\n };\n }\n\n xhr.onerror = function (event) {\n onError === null || onError === void 0 ? void 0 : onError({\n type: 'xhr_error'\n }, event, xhr);\n };\n\n xhr.send(sendableData);\n return {\n xhr: xhr,\n data: sendableData\n };\n}\n\n//# sourceURL=webpack://rsuite/./src/utils/ajaxUpload.ts?");
|
|
5184
5184
|
|
|
5185
5185
|
/***/ }),
|
|
5186
5186
|
|