rsuite 5.78.0 → 5.78.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 +9 -0
- package/cjs/Uploader/UploadTrigger.d.ts +1 -1
- package/cjs/Uploader/UploadTrigger.js +13 -9
- package/cjs/Uploader/Uploader.d.ts +1 -1
- package/cjs/Uploader/Uploader.js +1 -1
- package/dist/rsuite.js +4 -4
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Uploader/UploadTrigger.d.ts +1 -1
- package/esm/Uploader/UploadTrigger.js +13 -9
- package/esm/Uploader/Uploader.d.ts +1 -1
- package/esm/Uploader/Uploader.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [5.78.1](https://github.com/rsuite/rsuite/compare/v5.78.0...v5.78.1) (2025-03-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **Uploader:** refine children prop type and improve class handling ([#4175](https://github.com/rsuite/rsuite/issues/4175)) ([58d3eea](https://github.com/rsuite/rsuite/commit/58d3eea86e186590586a14068773a8418fb5f3f9))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
# [5.78.0](https://github.com/rsuite/rsuite/compare/v5.77.1...v5.78.0) (2025-02-21)
|
|
2
11
|
|
|
3
12
|
|
|
@@ -11,7 +11,7 @@ export interface UploadTriggerProps extends ButtonProps {
|
|
|
11
11
|
accept?: string;
|
|
12
12
|
classPrefix?: string;
|
|
13
13
|
className?: string;
|
|
14
|
-
children?: React.
|
|
14
|
+
children?: React.ReactElement;
|
|
15
15
|
locale?: UploaderLocale;
|
|
16
16
|
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
|
17
17
|
onDragEnter?: React.DragEventHandler<HTMLInputElement>;
|
|
@@ -15,6 +15,7 @@ var _excluded = ["as", "name", "accept", "multiple", "disabled", "readOnly", "ch
|
|
|
15
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
17
|
var UploadTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
18
|
+
var _children$props;
|
|
18
19
|
var _props$as = props.as,
|
|
19
20
|
Component = _props$as === void 0 ? _Button.default : _props$as,
|
|
20
21
|
name = props.name,
|
|
@@ -103,18 +104,21 @@ var UploadTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref)
|
|
|
103
104
|
clearInput: handleClearInput
|
|
104
105
|
};
|
|
105
106
|
});
|
|
107
|
+
|
|
108
|
+
// Prepare button props with event handlers conditionally applied
|
|
106
109
|
var buttonProps = (0, _extends2.default)({}, rest, {
|
|
107
110
|
disabled: disabled,
|
|
108
111
|
className: prefix('btn')
|
|
112
|
+
}, !disabled && !readOnly && {
|
|
113
|
+
onClick: handleClick,
|
|
114
|
+
onDragEnter: handleDragEnter,
|
|
115
|
+
onDragLeave: handleDragLeave,
|
|
116
|
+
onDragOver: handleDragOver,
|
|
117
|
+
onDrop: handleDrop
|
|
109
118
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
buttonProps.onDragLeave = handleDragLeave;
|
|
114
|
-
buttonProps.onDragOver = handleDragOver;
|
|
115
|
-
buttonProps.onDrop = handleDrop;
|
|
116
|
-
}
|
|
117
|
-
var trigger = children ? (/*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(children), buttonProps)) : /*#__PURE__*/_react.default.createElement(Component, buttonProps, locale === null || locale === void 0 ? void 0 : locale.upload);
|
|
119
|
+
var trigger = children ? (/*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(children), (0, _extends2.default)({}, buttonProps, {
|
|
120
|
+
className: merge((_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.className, prefix('btn'))
|
|
121
|
+
}))) : /*#__PURE__*/_react.default.createElement(Component, buttonProps, locale === null || locale === void 0 ? void 0 : locale.upload);
|
|
118
122
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
119
123
|
ref: rootRef,
|
|
120
124
|
className: classes
|
|
@@ -140,7 +144,7 @@ UploadTrigger.propTypes = {
|
|
|
140
144
|
onChange: _propTypes.default.func,
|
|
141
145
|
classPrefix: _propTypes.default.string,
|
|
142
146
|
className: _propTypes.default.string,
|
|
143
|
-
children: _propTypes.default.
|
|
147
|
+
children: _propTypes.default.element,
|
|
144
148
|
draggable: _propTypes.default.bool,
|
|
145
149
|
onDragEnter: _propTypes.default.func,
|
|
146
150
|
onDragLeave: _propTypes.default.func,
|
|
@@ -29,7 +29,7 @@ export interface UploaderProps extends WithAsProps, Omit<UploadTriggerProps, 'on
|
|
|
29
29
|
/** Automatically upload files after selecting them */
|
|
30
30
|
autoUpload?: boolean;
|
|
31
31
|
/** Primary content */
|
|
32
|
-
children?: React.
|
|
32
|
+
children?: React.ReactElement;
|
|
33
33
|
/** List of uploaded files */
|
|
34
34
|
defaultFileList?: FileType[];
|
|
35
35
|
/** List of uploaded files (Controlled) */
|
package/cjs/Uploader/Uploader.js
CHANGED
|
@@ -420,7 +420,7 @@ Uploader.propTypes = {
|
|
|
420
420
|
action: _propTypes.default.string.isRequired,
|
|
421
421
|
accept: _propTypes.default.string,
|
|
422
422
|
autoUpload: _propTypes.default.bool,
|
|
423
|
-
children: _propTypes.default.
|
|
423
|
+
children: _propTypes.default.element,
|
|
424
424
|
className: _propTypes.default.string,
|
|
425
425
|
classPrefix: _propTypes.default.string,
|
|
426
426
|
defaultFileList: _propTypes.default.array,
|
package/dist/rsuite.js
CHANGED
|
@@ -5966,7 +5966,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
|
|
|
5966
5966
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
5967
5967
|
|
|
5968
5968
|
"use strict";
|
|
5969
|
-
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\nvar _Button = _interopRequireDefault(__webpack_require__(/*! ../Button */ \"./src/Button/index.tsx\"));\nvar _hooks = __webpack_require__(/*! ../internals/hooks */ \"./src/internals/hooks/index.ts\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _excluded = [\"as\", \"name\", \"accept\", \"multiple\", \"disabled\", \"readOnly\", \"children\", \"classPrefix\", \"className\", \"draggable\", \"locale\", \"onChange\", \"onDragEnter\", \"onDragLeave\", \"onDragOver\", \"onDrop\"];\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/UploadTrigger.tsx\",\n _this = void 0;\nfunction _getRequireWildcardCache(e) { if (\"function\" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }\nfunction _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || \"object\" != typeof e && \"function\" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if (\"default\" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }\nvar UploadTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _props$as = props.as,\n Component = _props$as === void 0 ? _Button.default : _props$as,\n name = props.name,\n accept = props.accept,\n multiple = props.multiple,\n disabled = props.disabled,\n readOnly = props.readOnly,\n children = props.children,\n _props$classPrefix = props.classPrefix,\n classPrefix = _props$classPrefix === void 0 ? 'uploader-trigger' : _props$classPrefix,\n className = props.className,\n draggable = props.draggable,\n locale = props.locale,\n onChange = props.onChange,\n onDragEnter = props.onDragEnter,\n onDragLeave = props.onDragLeave,\n onDragOver = props.onDragOver,\n onDrop = props.onDrop,\n rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);\n var rootRef = (0, _react.useRef)(null);\n var _useState = (0, _react.useState)(false),\n dragOver = _useState[0],\n setDragOver = _useState[1];\n var inputRef = (0, _react.useRef)(null);\n var _useClassNames = (0, _hooks.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n var classes = merge(className, withClassPrefix({\n disabled: disabled,\n customize: children,\n 'drag-over': dragOver\n }));\n var handleClick = (0, _react.useCallback)(function () {\n var _inputRef$current;\n (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.click();\n }, []);\n var handleClearInput = (0, _react.useCallback)(function () {\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }, []);\n var handleDragEnter = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(true);\n }\n onDragEnter === null || onDragEnter === void 0 || onDragEnter(event);\n }, [draggable, onDragEnter]);\n var handleDragLeave = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(false);\n }\n onDragLeave === null || onDragLeave === void 0 || onDragLeave(event);\n }, [draggable, onDragLeave]);\n var handleDragOver = (0, _react.useCallback)(function (event) {\n draggable && event.preventDefault();\n onDragOver === null || onDragOver === void 0 || onDragOver(event);\n }, [draggable, onDragOver]);\n var handleDrop = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(false);\n onChange === null || onChange === void 0 || onChange(event);\n }\n onDrop === null || onDrop === void 0 || onDrop(event);\n }, [draggable, onChange, onDrop]);\n var handleChange = (0, _react.useCallback)(function (event) {\n if ((0, _utils.isIE11)()) {\n var _event$target;\n /**\n * IE11 triggers onChange event of file input when element.value is assigned\n * https://github.com/facebook/react/issues/8793\n */\n if (((_event$target = event.target) === null || _event$target === void 0 || (_event$target = _event$target.files) === null || _event$target === void 0 ? void 0 : _event$target.length) > 0) {\n onChange === null || onChange === void 0 || onChange(event);\n }\n return;\n }\n onChange === null || onChange === void 0 || onChange(event);\n }, [onChange]);\n (0, _react.useImperativeHandle)(ref, function () {\n return {\n root: rootRef.current,\n clearInput: handleClearInput\n };\n });\n var buttonProps = (0, _extends2.default)({}, rest, {\n disabled: disabled,\n className: prefix('btn')\n }
|
|
5969
|
+
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\nvar _Button = _interopRequireDefault(__webpack_require__(/*! ../Button */ \"./src/Button/index.tsx\"));\nvar _hooks = __webpack_require__(/*! ../internals/hooks */ \"./src/internals/hooks/index.ts\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _excluded = [\"as\", \"name\", \"accept\", \"multiple\", \"disabled\", \"readOnly\", \"children\", \"classPrefix\", \"className\", \"draggable\", \"locale\", \"onChange\", \"onDragEnter\", \"onDragLeave\", \"onDragOver\", \"onDrop\"];\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/UploadTrigger.tsx\",\n _this = void 0;\nfunction _getRequireWildcardCache(e) { if (\"function\" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }\nfunction _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || \"object\" != typeof e && \"function\" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if (\"default\" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }\nvar UploadTrigger = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _children$props;\n var _props$as = props.as,\n Component = _props$as === void 0 ? _Button.default : _props$as,\n name = props.name,\n accept = props.accept,\n multiple = props.multiple,\n disabled = props.disabled,\n readOnly = props.readOnly,\n children = props.children,\n _props$classPrefix = props.classPrefix,\n classPrefix = _props$classPrefix === void 0 ? 'uploader-trigger' : _props$classPrefix,\n className = props.className,\n draggable = props.draggable,\n locale = props.locale,\n onChange = props.onChange,\n onDragEnter = props.onDragEnter,\n onDragLeave = props.onDragLeave,\n onDragOver = props.onDragOver,\n onDrop = props.onDrop,\n rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);\n var rootRef = (0, _react.useRef)(null);\n var _useState = (0, _react.useState)(false),\n dragOver = _useState[0],\n setDragOver = _useState[1];\n var inputRef = (0, _react.useRef)(null);\n var _useClassNames = (0, _hooks.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n var classes = merge(className, withClassPrefix({\n disabled: disabled,\n customize: children,\n 'drag-over': dragOver\n }));\n var handleClick = (0, _react.useCallback)(function () {\n var _inputRef$current;\n (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.click();\n }, []);\n var handleClearInput = (0, _react.useCallback)(function () {\n if (inputRef.current) {\n inputRef.current.value = '';\n }\n }, []);\n var handleDragEnter = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(true);\n }\n onDragEnter === null || onDragEnter === void 0 || onDragEnter(event);\n }, [draggable, onDragEnter]);\n var handleDragLeave = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(false);\n }\n onDragLeave === null || onDragLeave === void 0 || onDragLeave(event);\n }, [draggable, onDragLeave]);\n var handleDragOver = (0, _react.useCallback)(function (event) {\n draggable && event.preventDefault();\n onDragOver === null || onDragOver === void 0 || onDragOver(event);\n }, [draggable, onDragOver]);\n var handleDrop = (0, _react.useCallback)(function (event) {\n if (draggable) {\n event.preventDefault();\n setDragOver(false);\n onChange === null || onChange === void 0 || onChange(event);\n }\n onDrop === null || onDrop === void 0 || onDrop(event);\n }, [draggable, onChange, onDrop]);\n var handleChange = (0, _react.useCallback)(function (event) {\n if ((0, _utils.isIE11)()) {\n var _event$target;\n /**\n * IE11 triggers onChange event of file input when element.value is assigned\n * https://github.com/facebook/react/issues/8793\n */\n if (((_event$target = event.target) === null || _event$target === void 0 || (_event$target = _event$target.files) === null || _event$target === void 0 ? void 0 : _event$target.length) > 0) {\n onChange === null || onChange === void 0 || onChange(event);\n }\n return;\n }\n onChange === null || onChange === void 0 || onChange(event);\n }, [onChange]);\n (0, _react.useImperativeHandle)(ref, function () {\n return {\n root: rootRef.current,\n clearInput: handleClearInput\n };\n });\n\n // Prepare button props with event handlers conditionally applied\n var buttonProps = (0, _extends2.default)({}, rest, {\n disabled: disabled,\n className: prefix('btn')\n }, !disabled && !readOnly && {\n onClick: handleClick,\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop\n });\n var trigger = children ? (/*#__PURE__*/_react.default.cloneElement(_react.default.Children.only(children), (0, _extends2.default)({}, buttonProps, {\n className: merge((_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props.className, prefix('btn'))\n }))) : /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, buttonProps, {\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 158,\n columnNumber: 5\n }\n }), locale === null || locale === void 0 ? void 0 : locale.upload);\n return /*#__PURE__*/_react.default.createElement(\"div\", {\n ref: rootRef,\n className: classes,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 162,\n columnNumber: 5\n }\n }, /*#__PURE__*/_react.default.createElement(\"input\", {\n type: \"file\",\n name: name,\n multiple: multiple,\n disabled: disabled,\n readOnly: readOnly,\n accept: accept,\n ref: inputRef,\n onChange: handleChange,\n __self: _this,\n __source: {\n fileName: _jsxFileName,\n lineNumber: 163,\n columnNumber: 7\n }\n }), trigger);\n});\nUploadTrigger.displayName = 'UploadTrigger';\nUploadTrigger.propTypes = {\n locale: _propTypes.default.any,\n name: _propTypes.default.string,\n multiple: _propTypes.default.bool,\n disabled: _propTypes.default.bool,\n readOnly: _propTypes.default.bool,\n accept: _propTypes.default.string,\n onChange: _propTypes.default.func,\n classPrefix: _propTypes.default.string,\n className: _propTypes.default.string,\n children: _propTypes.default.element,\n draggable: _propTypes.default.bool,\n onDragEnter: _propTypes.default.func,\n onDragLeave: _propTypes.default.func,\n onDragOver: _propTypes.default.func,\n onDrop: _propTypes.default.func\n};\nvar _default = exports[\"default\"] = UploadTrigger;\n\n//# sourceURL=webpack://rsuite/./src/Uploader/UploadTrigger.tsx?");
|
|
5970
5970
|
|
|
5971
5971
|
/***/ }),
|
|
5972
5972
|
|
|
@@ -5977,7 +5977,7 @@ eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/he
|
|
|
5977
5977
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
5978
5978
|
|
|
5979
5979
|
"use strict";
|
|
5980
|
-
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\nvar _find = _interopRequireDefault(__webpack_require__(/*! lodash/find */ \"./node_modules/lodash/find.js\"));\nvar _UploadFileItem = _interopRequireDefault(__webpack_require__(/*! ./UploadFileItem */ \"./src/Uploader/UploadFileItem.tsx\"));\nvar _Plaintext = _interopRequireDefault(__webpack_require__(/*! ../internals/Plaintext */ \"./src/internals/Plaintext/index.tsx\"));\nvar _ajaxUpload2 = _interopRequireDefault(__webpack_require__(/*! ./utils/ajaxUpload */ \"./src/Uploader/utils/ajaxUpload.ts\"));\nvar _UploadTrigger = _interopRequireDefault(__webpack_require__(/*! ./UploadTrigger */ \"./src/Uploader/UploadTrigger.tsx\"));\nvar _hooks = __webpack_require__(/*! ../internals/hooks */ \"./src/internals/hooks/index.ts\");\nvar _CustomProvider = __webpack_require__(/*! ../CustomProvider */ \"./src/CustomProvider/index.tsx\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _propTypes2 = __webpack_require__(/*! ../internals/propTypes */ \"./src/internals/propTypes/index.ts\");\nvar _excluded = [\"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\"];\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/Uploader.tsx\",\n _this = void 0;\nfunction _getRequireWildcardCache(e) { if (\"function\" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }\nfunction _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || \"object\" != typeof e && \"function\" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if (\"default\" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }\n// Define several states of the file during the upload process.\n\nvar getFiles = function getFiles(event) {\n if (typeof (event === null || event === void 0 ? void 0 : event['dataTransfer']) === 'object') {\n var _event$dataTransfer;\n return event === null || event === void 0 || (_event$dataTransfer = event['dataTransfer']) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files;\n }\n if (event.target) {\n return event.target['files'];\n }\n return [];\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};\nfunction fileListReducer(files, action) {\n var _action$files;\n switch (action.type) {\n // Add one or more files\n case 'push':\n return [].concat(files, action.files);\n\n // Remove a file by `fileKey`\n case 'remove':\n return files.filter(function (f) {\n return f.fileKey !== action.fileKey;\n });\n\n // Update a file\n case 'updateFile':\n return files.map(function (file) {\n return file.fileKey === action.file.fileKey ? action.file : file;\n });\n\n // Initialization file list\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 default:\n throw new Error();\n }\n}\nvar useFileList = function useFileList(defaultFileList) {\n if (defaultFileList === void 0) {\n defaultFileList = [];\n }\n var fileListRef = (0, _react.useRef)(defaultFileList.map(createFile));\n var fileListUpdateCallback = (0, _react.useRef)();\n var _useReducer = (0, _react.useReducer)(fileListReducer, fileListRef.current),\n fileList = _useReducer[0],\n dispatch = _useReducer[1];\n fileListRef.current = fileList;\n (0, _react.useEffect)(function () {\n var _fileListUpdateCallba;\n (_fileListUpdateCallba = fileListUpdateCallback.current) === null || _fileListUpdateCallba === void 0 || _fileListUpdateCallba.call(fileListUpdateCallback, fileList);\n fileListUpdateCallback.current = null;\n }, [fileList]);\n (0, _hooks.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\n/**\n * The `Uploader` component is used to upload files.\n *\n * @see https://rsuitejs.com/components/uploader\n */\nvar Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _useCustom = (0, _CustomProvider.useCustom)('Uploader', props),\n propsWithDefaults = _useCustom.propsWithDefaults;\n var _propsWithDefaults$as = propsWithDefaults.as,\n Component = _propsWithDefaults$as === void 0 ? 'div' : _propsWithDefaults$as,\n _propsWithDefaults$cl = propsWithDefaults.classPrefix,\n classPrefix = _propsWithDefaults$cl === void 0 ? 'uploader' : _propsWithDefaults$cl,\n className = propsWithDefaults.className,\n _propsWithDefaults$li = propsWithDefaults.listType,\n listType = _propsWithDefaults$li === void 0 ? 'text' : _propsWithDefaults$li,\n defaultFileList = propsWithDefaults.defaultFileList,\n fileListProp = propsWithDefaults.fileList,\n _propsWithDefaults$fi = propsWithDefaults.fileListVisible,\n fileListVisible = _propsWithDefaults$fi === void 0 ? true : _propsWithDefaults$fi,\n locale = propsWithDefaults.locale,\n style = propsWithDefaults.style,\n draggable = propsWithDefaults.draggable,\n _propsWithDefaults$na = propsWithDefaults.name,\n name = _propsWithDefaults$na === void 0 ? 'file' : _propsWithDefaults$na,\n _propsWithDefaults$mu = propsWithDefaults.multiple,\n multiple = _propsWithDefaults$mu === void 0 ? false : _propsWithDefaults$mu,\n _propsWithDefaults$di = propsWithDefaults.disabled,\n disabled = _propsWithDefaults$di === void 0 ? false : _propsWithDefaults$di,\n readOnly = propsWithDefaults.readOnly,\n plaintext = propsWithDefaults.plaintext,\n accept = propsWithDefaults.accept,\n children = propsWithDefaults.children,\n toggleAs = propsWithDefaults.toggleAs,\n _propsWithDefaults$re = propsWithDefaults.removable,\n removable = _propsWithDefaults$re === void 0 ? true : _propsWithDefaults$re,\n disabledFileItem = propsWithDefaults.disabledFileItem,\n maxPreviewFileSize = propsWithDefaults.maxPreviewFileSize,\n _propsWithDefaults$me = propsWithDefaults.method,\n method = _propsWithDefaults$me === void 0 ? 'POST' : _propsWithDefaults$me,\n _propsWithDefaults$au = propsWithDefaults.autoUpload,\n autoUpload = _propsWithDefaults$au === void 0 ? true : _propsWithDefaults$au,\n action = propsWithDefaults.action,\n headers = propsWithDefaults.headers,\n _propsWithDefaults$wi = propsWithDefaults.withCredentials,\n withCredentials = _propsWithDefaults$wi === void 0 ? false : _propsWithDefaults$wi,\n disableMultipart = propsWithDefaults.disableMultipart,\n _propsWithDefaults$ti = propsWithDefaults.timeout,\n timeout = _propsWithDefaults$ti === void 0 ? 0 : _propsWithDefaults$ti,\n _propsWithDefaults$da = propsWithDefaults.data,\n data = _propsWithDefaults$da === void 0 ? {} : _propsWithDefaults$da,\n onRemove = propsWithDefaults.onRemove,\n onUpload = propsWithDefaults.onUpload,\n shouldUpload = propsWithDefaults.shouldUpload,\n shouldQueueUpdate = propsWithDefaults.shouldQueueUpdate,\n renderFileInfo = propsWithDefaults.renderFileInfo,\n renderThumbnail = propsWithDefaults.renderThumbnail,\n onPreview = propsWithDefaults.onPreview,\n onChange = propsWithDefaults.onChange,\n onSuccess = propsWithDefaults.onSuccess,\n onError = propsWithDefaults.onError,\n onProgress = propsWithDefaults.onProgress,\n onReupload = propsWithDefaults.onReupload,\n rest = (0, _objectWithoutPropertiesLoose2.default)(propsWithDefaults, _excluded);\n var _useClassNames = (0, _hooks.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n var classes = merge(className, withClassPrefix(listType, {\n draggable: draggable\n }));\n var rootRef = (0, _react.useRef)();\n var xhrs = (0, _react.useRef)({});\n var trigger = (0, _react.useRef)();\n var _useFileList = useFileList(fileListProp || defaultFileList),\n fileList = _useFileList[0],\n dispatch = _useFileList[1];\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 /**\n * Clear the value in input.\n */\n var cleanInputValue = (0, _react.useCallback)(function () {\n var _trigger$current;\n (_trigger$current = trigger.current) === null || _trigger$current === void 0 || _trigger$current.clearInput();\n }, []);\n\n /**\n * Callback for successful file upload.\n * @param file\n * @param response\n * @param event\n * @param xhr\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 || onSuccess(response, nextFile, event, xhr);\n }, [onSuccess, updateFileStatus]);\n\n /**\n * Callback for file upload error.\n * @param file\n * @param status\n * @param event\n * @param xhr\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 || onError(status, nextFile, event, xhr);\n }, [onError, updateFileStatus]);\n\n /**\n * Callback for file upload progress update.\n * @param file\n * @param percent\n * @param event\n * @param xhr\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 || onProgress(percent, nextFile, event, xhr);\n }, [onProgress, updateFileStatus]);\n\n /**\n * Upload a single file.\n * @param file\n */\n var handleUploadFile = (0, _react.useCallback)(function (file) {\n var _ajaxUpload = (0, _ajaxUpload2.default)({\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 updateFileStatus((0, _extends2.default)({}, file, {\n status: 'uploading'\n }));\n if (file.fileKey) {\n xhrs.current[file.fileKey] = xhr;\n }\n onUpload === null || onUpload === 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 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 if (file.status === 'inited') {\n handleUploadFile(file);\n }\n });\n cleanInputValue();\n }, [cleanInputValue, fileList, handleUploadFile, shouldUpload]);\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 if (checkState === false) {\n cleanInputValue();\n return;\n }\n var upload = function upload() {\n onChange === null || onChange === void 0 || onChange(nextFileList, event);\n if (rootRef.current) {\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 upload();\n };\n var handleRemoveFile = function handleRemoveFile(fileKey, event) {\n var _xhrs$current;\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 if (((_xhrs$current = xhrs.current) === null || _xhrs$current === void 0 || (_xhrs$current = _xhrs$current[file.fileKey]) === null || _xhrs$current === void 0 ? void 0 : _xhrs$current.readyState) !== 4) {\n var _xhrs$current$file$fi;\n (_xhrs$current$file$fi = xhrs.current[file.fileKey]) === null || _xhrs$current$file$fi === void 0 || _xhrs$current$file$fi.abort();\n }\n dispatch({\n type: 'remove',\n fileKey: fileKey\n });\n onRemove === null || onRemove === void 0 || onRemove(file);\n onChange === null || onChange === void 0 || onChange(nextFileList, event);\n cleanInputValue();\n };\n var handleReupload = function handleReupload(file) {\n autoUpload && handleUploadFile(file);\n onReupload === null || onReupload === void 0 || onReupload(file);\n };\n\n // public API\n var start = function start(file) {\n if (file) {\n handleUploadFile(file);\n return;\n }\n handleAjaxUpload();\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: 544,\n columnNumber: 5\n }\n }), children)];\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: 564,\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: 566,\n columnNumber: 11\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: 588,\n columnNumber: 7\n }\n }, fileList.current.length ? renderList[1] : null);\n }\n if (listType === 'picture') {\n renderList.reverse();\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: 599,\n columnNumber: 5\n }\n }, renderList);\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: (0, _propTypes2.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 = exports[\"default\"] = Uploader;\n\n//# sourceURL=webpack://rsuite/./src/Uploader/Uploader.tsx?");
|
|
5980
|
+
eval("\n\nvar _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ \"./node_modules/@babel/runtime/helpers/interopRequireDefault.js\");\nexports.__esModule = true;\nexports[\"default\"] = void 0;\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/objectWithoutPropertiesLoose */ \"./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js\"));\nvar _extends2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/extends */ \"./node_modules/@babel/runtime/helpers/extends.js\"));\nvar _react = _interopRequireWildcard(__webpack_require__(/*! react */ \"react\"));\nvar _propTypes = _interopRequireDefault(__webpack_require__(/*! prop-types */ \"./node_modules/prop-types/index.js\"));\nvar _find = _interopRequireDefault(__webpack_require__(/*! lodash/find */ \"./node_modules/lodash/find.js\"));\nvar _UploadFileItem = _interopRequireDefault(__webpack_require__(/*! ./UploadFileItem */ \"./src/Uploader/UploadFileItem.tsx\"));\nvar _Plaintext = _interopRequireDefault(__webpack_require__(/*! ../internals/Plaintext */ \"./src/internals/Plaintext/index.tsx\"));\nvar _ajaxUpload2 = _interopRequireDefault(__webpack_require__(/*! ./utils/ajaxUpload */ \"./src/Uploader/utils/ajaxUpload.ts\"));\nvar _UploadTrigger = _interopRequireDefault(__webpack_require__(/*! ./UploadTrigger */ \"./src/Uploader/UploadTrigger.tsx\"));\nvar _hooks = __webpack_require__(/*! ../internals/hooks */ \"./src/internals/hooks/index.ts\");\nvar _CustomProvider = __webpack_require__(/*! ../CustomProvider */ \"./src/CustomProvider/index.tsx\");\nvar _utils = __webpack_require__(/*! ../internals/utils */ \"./src/internals/utils/index.ts\");\nvar _propTypes2 = __webpack_require__(/*! ../internals/propTypes */ \"./src/internals/propTypes/index.ts\");\nvar _excluded = [\"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\"];\nvar _jsxFileName = \"/home/runner/work/rsuite/rsuite/src/Uploader/Uploader.tsx\",\n _this = void 0;\nfunction _getRequireWildcardCache(e) { if (\"function\" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }\nfunction _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || \"object\" != typeof e && \"function\" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if (\"default\" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }\n// Define several states of the file during the upload process.\n\nvar getFiles = function getFiles(event) {\n if (typeof (event === null || event === void 0 ? void 0 : event['dataTransfer']) === 'object') {\n var _event$dataTransfer;\n return event === null || event === void 0 || (_event$dataTransfer = event['dataTransfer']) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files;\n }\n if (event.target) {\n return event.target['files'];\n }\n return [];\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};\nfunction fileListReducer(files, action) {\n var _action$files;\n switch (action.type) {\n // Add one or more files\n case 'push':\n return [].concat(files, action.files);\n\n // Remove a file by `fileKey`\n case 'remove':\n return files.filter(function (f) {\n return f.fileKey !== action.fileKey;\n });\n\n // Update a file\n case 'updateFile':\n return files.map(function (file) {\n return file.fileKey === action.file.fileKey ? action.file : file;\n });\n\n // Initialization file list\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 default:\n throw new Error();\n }\n}\nvar useFileList = function useFileList(defaultFileList) {\n if (defaultFileList === void 0) {\n defaultFileList = [];\n }\n var fileListRef = (0, _react.useRef)(defaultFileList.map(createFile));\n var fileListUpdateCallback = (0, _react.useRef)();\n var _useReducer = (0, _react.useReducer)(fileListReducer, fileListRef.current),\n fileList = _useReducer[0],\n dispatch = _useReducer[1];\n fileListRef.current = fileList;\n (0, _react.useEffect)(function () {\n var _fileListUpdateCallba;\n (_fileListUpdateCallba = fileListUpdateCallback.current) === null || _fileListUpdateCallba === void 0 || _fileListUpdateCallba.call(fileListUpdateCallback, fileList);\n fileListUpdateCallback.current = null;\n }, [fileList]);\n (0, _hooks.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\n/**\n * The `Uploader` component is used to upload files.\n *\n * @see https://rsuitejs.com/components/uploader\n */\nvar Uploader = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {\n var _useCustom = (0, _CustomProvider.useCustom)('Uploader', props),\n propsWithDefaults = _useCustom.propsWithDefaults;\n var _propsWithDefaults$as = propsWithDefaults.as,\n Component = _propsWithDefaults$as === void 0 ? 'div' : _propsWithDefaults$as,\n _propsWithDefaults$cl = propsWithDefaults.classPrefix,\n classPrefix = _propsWithDefaults$cl === void 0 ? 'uploader' : _propsWithDefaults$cl,\n className = propsWithDefaults.className,\n _propsWithDefaults$li = propsWithDefaults.listType,\n listType = _propsWithDefaults$li === void 0 ? 'text' : _propsWithDefaults$li,\n defaultFileList = propsWithDefaults.defaultFileList,\n fileListProp = propsWithDefaults.fileList,\n _propsWithDefaults$fi = propsWithDefaults.fileListVisible,\n fileListVisible = _propsWithDefaults$fi === void 0 ? true : _propsWithDefaults$fi,\n locale = propsWithDefaults.locale,\n style = propsWithDefaults.style,\n draggable = propsWithDefaults.draggable,\n _propsWithDefaults$na = propsWithDefaults.name,\n name = _propsWithDefaults$na === void 0 ? 'file' : _propsWithDefaults$na,\n _propsWithDefaults$mu = propsWithDefaults.multiple,\n multiple = _propsWithDefaults$mu === void 0 ? false : _propsWithDefaults$mu,\n _propsWithDefaults$di = propsWithDefaults.disabled,\n disabled = _propsWithDefaults$di === void 0 ? false : _propsWithDefaults$di,\n readOnly = propsWithDefaults.readOnly,\n plaintext = propsWithDefaults.plaintext,\n accept = propsWithDefaults.accept,\n children = propsWithDefaults.children,\n toggleAs = propsWithDefaults.toggleAs,\n _propsWithDefaults$re = propsWithDefaults.removable,\n removable = _propsWithDefaults$re === void 0 ? true : _propsWithDefaults$re,\n disabledFileItem = propsWithDefaults.disabledFileItem,\n maxPreviewFileSize = propsWithDefaults.maxPreviewFileSize,\n _propsWithDefaults$me = propsWithDefaults.method,\n method = _propsWithDefaults$me === void 0 ? 'POST' : _propsWithDefaults$me,\n _propsWithDefaults$au = propsWithDefaults.autoUpload,\n autoUpload = _propsWithDefaults$au === void 0 ? true : _propsWithDefaults$au,\n action = propsWithDefaults.action,\n headers = propsWithDefaults.headers,\n _propsWithDefaults$wi = propsWithDefaults.withCredentials,\n withCredentials = _propsWithDefaults$wi === void 0 ? false : _propsWithDefaults$wi,\n disableMultipart = propsWithDefaults.disableMultipart,\n _propsWithDefaults$ti = propsWithDefaults.timeout,\n timeout = _propsWithDefaults$ti === void 0 ? 0 : _propsWithDefaults$ti,\n _propsWithDefaults$da = propsWithDefaults.data,\n data = _propsWithDefaults$da === void 0 ? {} : _propsWithDefaults$da,\n onRemove = propsWithDefaults.onRemove,\n onUpload = propsWithDefaults.onUpload,\n shouldUpload = propsWithDefaults.shouldUpload,\n shouldQueueUpdate = propsWithDefaults.shouldQueueUpdate,\n renderFileInfo = propsWithDefaults.renderFileInfo,\n renderThumbnail = propsWithDefaults.renderThumbnail,\n onPreview = propsWithDefaults.onPreview,\n onChange = propsWithDefaults.onChange,\n onSuccess = propsWithDefaults.onSuccess,\n onError = propsWithDefaults.onError,\n onProgress = propsWithDefaults.onProgress,\n onReupload = propsWithDefaults.onReupload,\n rest = (0, _objectWithoutPropertiesLoose2.default)(propsWithDefaults, _excluded);\n var _useClassNames = (0, _hooks.useClassNames)(classPrefix),\n merge = _useClassNames.merge,\n withClassPrefix = _useClassNames.withClassPrefix,\n prefix = _useClassNames.prefix;\n var classes = merge(className, withClassPrefix(listType, {\n draggable: draggable\n }));\n var rootRef = (0, _react.useRef)();\n var xhrs = (0, _react.useRef)({});\n var trigger = (0, _react.useRef)();\n var _useFileList = useFileList(fileListProp || defaultFileList),\n fileList = _useFileList[0],\n dispatch = _useFileList[1];\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 /**\n * Clear the value in input.\n */\n var cleanInputValue = (0, _react.useCallback)(function () {\n var _trigger$current;\n (_trigger$current = trigger.current) === null || _trigger$current === void 0 || _trigger$current.clearInput();\n }, []);\n\n /**\n * Callback for successful file upload.\n * @param file\n * @param response\n * @param event\n * @param xhr\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 || onSuccess(response, nextFile, event, xhr);\n }, [onSuccess, updateFileStatus]);\n\n /**\n * Callback for file upload error.\n * @param file\n * @param status\n * @param event\n * @param xhr\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 || onError(status, nextFile, event, xhr);\n }, [onError, updateFileStatus]);\n\n /**\n * Callback for file upload progress update.\n * @param file\n * @param percent\n * @param event\n * @param xhr\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 || onProgress(percent, nextFile, event, xhr);\n }, [onProgress, updateFileStatus]);\n\n /**\n * Upload a single file.\n * @param file\n */\n var handleUploadFile = (0, _react.useCallback)(function (file) {\n var _ajaxUpload = (0, _ajaxUpload2.default)({\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 updateFileStatus((0, _extends2.default)({}, file, {\n status: 'uploading'\n }));\n if (file.fileKey) {\n xhrs.current[file.fileKey] = xhr;\n }\n onUpload === null || onUpload === 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 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 if (file.status === 'inited') {\n handleUploadFile(file);\n }\n });\n cleanInputValue();\n }, [cleanInputValue, fileList, handleUploadFile, shouldUpload]);\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 if (checkState === false) {\n cleanInputValue();\n return;\n }\n var upload = function upload() {\n onChange === null || onChange === void 0 || onChange(nextFileList, event);\n if (rootRef.current) {\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 upload();\n };\n var handleRemoveFile = function handleRemoveFile(fileKey, event) {\n var _xhrs$current;\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 if (((_xhrs$current = xhrs.current) === null || _xhrs$current === void 0 || (_xhrs$current = _xhrs$current[file.fileKey]) === null || _xhrs$current === void 0 ? void 0 : _xhrs$current.readyState) !== 4) {\n var _xhrs$current$file$fi;\n (_xhrs$current$file$fi = xhrs.current[file.fileKey]) === null || _xhrs$current$file$fi === void 0 || _xhrs$current$file$fi.abort();\n }\n dispatch({\n type: 'remove',\n fileKey: fileKey\n });\n onRemove === null || onRemove === void 0 || onRemove(file);\n onChange === null || onChange === void 0 || onChange(nextFileList, event);\n cleanInputValue();\n };\n var handleReupload = function handleReupload(file) {\n autoUpload && handleUploadFile(file);\n onReupload === null || onReupload === void 0 || onReupload(file);\n };\n\n // public API\n var start = function start(file) {\n if (file) {\n handleUploadFile(file);\n return;\n }\n handleAjaxUpload();\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: 544,\n columnNumber: 5\n }\n }), children)];\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: 564,\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: 566,\n columnNumber: 11\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: 588,\n columnNumber: 7\n }\n }, fileList.current.length ? renderList[1] : null);\n }\n if (listType === 'picture') {\n renderList.reverse();\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: 599,\n columnNumber: 5\n }\n }, renderList);\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.element,\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: (0, _propTypes2.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 = exports[\"default\"] = Uploader;\n\n//# sourceURL=webpack://rsuite/./src/Uploader/Uploader.tsx?");
|
|
5981
5981
|
|
|
5982
5982
|
/***/ }),
|
|
5983
5983
|
|
|
@@ -10763,9 +10763,9 @@ eval("var memoizeCapped = __webpack_require__(/*! ./_memoizeCapped */ \"./node_m
|
|
|
10763
10763
|
/*!***************************************!*\
|
|
10764
10764
|
!*** ./node_modules/lodash/_toKey.js ***!
|
|
10765
10765
|
\***************************************/
|
|
10766
|
-
/***/ (function(module
|
|
10766
|
+
/***/ (function(module) {
|
|
10767
10767
|
|
|
10768
|
-
eval("
|
|
10768
|
+
eval("/**\n * This method returns the first argument it receives.\n *\n * @static\n * @since 0.1.0\n * @memberOf _\n * @category Util\n * @param {*} value Any value.\n * @returns {*} Returns `value`.\n * @example\n *\n * var object = { 'a': 1 };\n *\n * console.log(_.identity(object) === object);\n * // => true\n */\nfunction identity(value) {\n return value;\n}\n\nmodule.exports = identity;\n\n\n//# sourceURL=webpack://rsuite/./node_modules/lodash/_toKey.js?");
|
|
10769
10769
|
|
|
10770
10770
|
/***/ }),
|
|
10771
10771
|
|