@qn-pandora/pandora-component 4.0.3 → 4.0.5
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.json +46 -0
- package/CHANGELOG.md +17 -1
- package/es/components/FileResumable/constants.d.ts +33 -0
- package/es/components/FileResumable/constants.js +0 -0
- package/es/components/FileResumable/index.d.ts +13 -0
- package/es/components/FileResumable/index.js +327 -0
- package/es/components/FileResumable/style.css +777 -0
- package/es/components/FileResumable/style.less +94 -0
- package/es/components/FileResumable/utils.d.ts +1 -0
- package/es/components/FileResumable/utils.js +17 -0
- package/es/components/Menu/Option.d.ts +4 -0
- package/es/components/Table/index.js +4 -1
- package/es/components/Table/style.css +3 -0
- package/es/components/Table/style.less +5 -0
- package/es/components/Transfer/List/index.js +15 -8
- package/es/constants/language/en.js +3 -1
- package/es/constants/language/type.d.ts +2 -0
- package/es/constants/language/upload/en.d.ts +3 -0
- package/es/constants/language/upload/en.js +20 -0
- package/es/constants/language/upload/type.d.ts +20 -0
- package/es/constants/language/upload/type.js +4 -0
- package/es/constants/language/upload/zh.d.ts +3 -0
- package/es/constants/language/upload/zh.js +20 -0
- package/es/constants/language/zh.js +3 -1
- package/es/index.css +5545 -4775
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/index.less +16 -15
- package/es/style/theme.less +1 -0
- package/lib/components/FileResumable/constants.d.ts +33 -0
- package/lib/components/FileResumable/constants.js +2 -0
- package/lib/components/FileResumable/index.d.ts +13 -0
- package/lib/components/FileResumable/index.js +340 -0
- package/lib/components/FileResumable/style.css +777 -0
- package/lib/components/FileResumable/style.less +94 -0
- package/lib/components/FileResumable/utils.d.ts +1 -0
- package/lib/components/FileResumable/utils.js +19 -0
- package/lib/components/Menu/Option.d.ts +4 -0
- package/lib/components/Table/index.js +4 -1
- package/lib/components/Table/style.css +3 -0
- package/lib/components/Table/style.less +5 -0
- package/lib/components/Transfer/List/index.js +14 -7
- package/lib/constants/language/en.js +6 -1
- package/lib/constants/language/type.d.ts +2 -0
- package/lib/constants/language/upload/en.d.ts +3 -0
- package/lib/constants/language/upload/en.js +22 -0
- package/lib/constants/language/upload/type.d.ts +20 -0
- package/lib/constants/language/upload/type.js +9 -0
- package/lib/constants/language/upload/zh.d.ts +3 -0
- package/lib/constants/language/upload/zh.js +22 -0
- package/lib/constants/language/zh.js +6 -1
- package/lib/index.css +4039 -3269
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.less +17 -16
- package/lib/style/theme.less +1 -0
- package/package.json +6 -4
package/CHANGELOG.json
CHANGED
@@ -1,6 +1,52 @@
|
|
1
1
|
{
|
2
2
|
"name": "@qn-pandora/pandora-component",
|
3
3
|
"entries": [
|
4
|
+
{
|
5
|
+
"version": "4.0.5",
|
6
|
+
"tag": "@qn-pandora/pandora-component_v4.0.5",
|
7
|
+
"date": "Wed, 15 Feb 2023 09:26:50 GMT",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"comment": "2023.02.15 发布"
|
12
|
+
}
|
13
|
+
],
|
14
|
+
"dependency": [
|
15
|
+
{
|
16
|
+
"comment": "Updating dependency \"@qn-pandora/pandora-component-icons\" from `^3.0.7` to `^3.0.8`"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"comment": "Updating dependency \"@qn-pandora/app-sdk\" from `^3.0.7` to `^3.0.8`"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"comment": "Updating dependency \"@qn-pandora/pandora-tools\" from `^2.0.6` to `^2.0.7`"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"version": "4.0.4",
|
29
|
+
"tag": "@qn-pandora/pandora-component_v4.0.4",
|
30
|
+
"date": "Wed, 11 Jan 2023 08:25:05 GMT",
|
31
|
+
"comments": {
|
32
|
+
"patch": [
|
33
|
+
{
|
34
|
+
"comment": "2023-01-11 发布"
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"dependency": [
|
38
|
+
{
|
39
|
+
"comment": "Updating dependency \"@qn-pandora/pandora-component-icons\" from `^3.0.6` to `^3.0.7`"
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"comment": "Updating dependency \"@qn-pandora/app-sdk\" from `^3.0.5` to `^3.0.7`"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"comment": "Updating dependency \"@qn-pandora/pandora-tools\" from `^2.0.5` to `^2.0.6`"
|
46
|
+
}
|
47
|
+
]
|
48
|
+
}
|
49
|
+
},
|
4
50
|
{
|
5
51
|
"version": "4.0.3",
|
6
52
|
"tag": "@qn-pandora/pandora-component_v4.0.3",
|
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# Change Log - @qn-pandora/pandora-component
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Wed, 15 Feb 2023 09:26:50 GMT and should not be manually modified.
|
4
|
+
|
5
|
+
## 4.0.5
|
6
|
+
|
7
|
+
Wed, 15 Feb 2023 09:26:50 GMT
|
8
|
+
|
9
|
+
### Patches
|
10
|
+
|
11
|
+
- 2023.02.15 发布
|
12
|
+
|
13
|
+
## 4.0.4
|
14
|
+
|
15
|
+
Wed, 11 Jan 2023 08:25:05 GMT
|
16
|
+
|
17
|
+
### Patches
|
18
|
+
|
19
|
+
- 2023-01-11 发布
|
4
20
|
|
5
21
|
## 4.0.3
|
6
22
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { RcFile, UploadChangeParam } from 'antd/es/upload';
|
3
|
+
export interface IFileResumableProps {
|
4
|
+
target?: string;
|
5
|
+
uploading: boolean;
|
6
|
+
accept: string;
|
7
|
+
chunkSize?: number;
|
8
|
+
forceChunkSize?: boolean;
|
9
|
+
simultaneousUploads?: number;
|
10
|
+
query?: IKeyValues;
|
11
|
+
fileList: UploadChangeParam['fileList'] | [];
|
12
|
+
method?: 'multipart' | 'octet';
|
13
|
+
testChunks?: boolean;
|
14
|
+
maxChunkRetries?: number;
|
15
|
+
maxFiles?: number;
|
16
|
+
withCredentials?: boolean;
|
17
|
+
headers?: IKeyValues;
|
18
|
+
onSuccess?: (message: string) => void;
|
19
|
+
onChange?: (file: RcFile | null) => void;
|
20
|
+
onStop?: () => void;
|
21
|
+
minFileSize?: number;
|
22
|
+
minFileSizeErrorCallback?: (file: RcFile) => void;
|
23
|
+
maxFileSize?: number;
|
24
|
+
maxFileSizeErrorCallback?: (file: RcFile) => void;
|
25
|
+
onError?: (error: string) => void;
|
26
|
+
className?: string;
|
27
|
+
showUploadList?: boolean;
|
28
|
+
mode?: 'image' | 'file';
|
29
|
+
uploadIcon?: React.ReactNode;
|
30
|
+
uploadDesc?: string;
|
31
|
+
disabled?: boolean;
|
32
|
+
defaultImageUrl?: string;
|
33
|
+
}
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
2
|
+
import { IFileResumableProps } from './constants';
|
3
|
+
export interface IIconItem {
|
4
|
+
iconType: any;
|
5
|
+
type: string;
|
6
|
+
text: string;
|
7
|
+
disabled?: boolean;
|
8
|
+
ownIcon?: boolean;
|
9
|
+
onClick?: () => void;
|
10
|
+
}
|
11
|
+
export default function FileResumable(props: PropsWithChildren<IFileResumableProps & {
|
12
|
+
ref?: any;
|
13
|
+
}>): JSX.Element;
|
@@ -0,0 +1,327 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
19
|
+
});
|
20
|
+
};
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
25
|
+
function step(op) {
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
27
|
+
while (_) try {
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
30
|
+
switch (op[0]) {
|
31
|
+
case 0: case 1: t = op; break;
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
35
|
+
default:
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
40
|
+
if (t[2]) _.ops.pop();
|
41
|
+
_.trys.pop(); continue;
|
42
|
+
}
|
43
|
+
op = body.call(thisArg, _);
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
46
|
+
}
|
47
|
+
};
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
49
|
+
var t = {};
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
51
|
+
t[p] = s[p];
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
55
|
+
t[p[i]] = s[p[i]];
|
56
|
+
}
|
57
|
+
return t;
|
58
|
+
};
|
59
|
+
var __read = (this && this.__read) || function (o, n) {
|
60
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
61
|
+
if (!m) return o;
|
62
|
+
var i = m.call(o), r, ar = [], e;
|
63
|
+
try {
|
64
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
65
|
+
}
|
66
|
+
catch (error) { e = { error: error }; }
|
67
|
+
finally {
|
68
|
+
try {
|
69
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
70
|
+
}
|
71
|
+
finally { if (e) throw e.error; }
|
72
|
+
}
|
73
|
+
return ar;
|
74
|
+
};
|
75
|
+
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
76
|
+
import Resumablejs from 'resumablejs';
|
77
|
+
import { Progress, Tooltip, Upload } from 'antd';
|
78
|
+
import { ConfigContext } from 'antd/es/config-provider';
|
79
|
+
import classnames from 'classnames';
|
80
|
+
import { get } from 'lodash';
|
81
|
+
import { CaretRightOutlined, Upload as UploadIcon, StopFill, Pause, PlusOutlined } from '@qn-pandora/pandora-component-icons';
|
82
|
+
import { appEnv } from '@qn-pandora/app-sdk';
|
83
|
+
import { formatString } from '../../utils/language';
|
84
|
+
import { UploadLocale } from '../../constants/language/upload/type';
|
85
|
+
import { SDK_PREFIX } from '../../constants/style';
|
86
|
+
import { isJpgOrPngOrSvg } from './utils';
|
87
|
+
var Dragger = Upload.Dragger;
|
88
|
+
export default function FileResumable(props) {
|
89
|
+
var _a, _b;
|
90
|
+
var _this = this;
|
91
|
+
var resumable = useRef();
|
92
|
+
var _c = __read(useState(0), 2), percent = _c[0], setPercent = _c[1];
|
93
|
+
var _d = __read(useState(true), 2), isPlayDisabled = _d[0], setIsPlayDisabled = _d[1];
|
94
|
+
var _e = __read(useState(true), 2), isPauseDisabled = _e[0], setIsPauseDisabled = _e[1];
|
95
|
+
var _f = __read(useState(true), 2), isStopDisabled = _f[0], setIsStopDisabled = _f[1];
|
96
|
+
var _g = __read(useState(false), 2), showTool = _g[0], setShowTool = _g[1];
|
97
|
+
var _h = __read(useState(''), 2), imageUrl = _h[0], setImageUrl = _h[1];
|
98
|
+
var locale = useContext(ConfigContext).locale;
|
99
|
+
var maxFileSize = props.maxFileSize, minFileSize = props.minFileSize, minFileSizeErrorCallback = props.minFileSizeErrorCallback, maxFileSizeErrorCallback = props.maxFileSizeErrorCallback, onError = props.onError, onChange = props.onChange, query = props.query, onStop = props.onStop, onSuccess = props.onSuccess, accept = props.accept, fileList = props.fileList, uploading = props.uploading, children = props.children, className = props.className, showUploadList = props.showUploadList, mode = props.mode, uploadIcon = props.uploadIcon, uploadDesc = props.uploadDesc, disabled = props.disabled, defaultImageUrl = props.defaultImageUrl, others = __rest(props, ["maxFileSize", "minFileSize", "minFileSizeErrorCallback", "maxFileSizeErrorCallback", "onError", "onChange", "query", "onStop", "onSuccess", "accept", "fileList", "uploading", "children", "className", "showUploadList", "mode", "uploadIcon", "uploadDesc", "disabled", "defaultImageUrl"]);
|
100
|
+
var handleRemove = useCallback(function () {
|
101
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(null);
|
102
|
+
}, [onChange]);
|
103
|
+
var handleStop = useCallback(function () {
|
104
|
+
var _a;
|
105
|
+
onStop === null || onStop === void 0 ? void 0 : onStop();
|
106
|
+
handleRemove();
|
107
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
108
|
+
setShowTool(false);
|
109
|
+
setIsStopDisabled(true);
|
110
|
+
setIsPlayDisabled(true);
|
111
|
+
setIsPauseDisabled(true);
|
112
|
+
}, [
|
113
|
+
onStop,
|
114
|
+
handleRemove,
|
115
|
+
resumable,
|
116
|
+
setIsStopDisabled,
|
117
|
+
setIsPlayDisabled,
|
118
|
+
setIsPauseDisabled
|
119
|
+
]);
|
120
|
+
var runItems = useMemo(function () {
|
121
|
+
var _a, _b, _c;
|
122
|
+
var playItem = {
|
123
|
+
type: 'play',
|
124
|
+
iconType: (React.createElement(CaretRightOutlined, { onClick: function () {
|
125
|
+
var _a;
|
126
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.upload();
|
127
|
+
}, className: classnames(SDK_PREFIX + "-file-resumable-run-container-icon", (_a = {},
|
128
|
+
_a[SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isPlayDisabled,
|
129
|
+
_a)) })),
|
130
|
+
text: formatString(UploadLocale.play, locale)
|
131
|
+
};
|
132
|
+
var pauseItem = {
|
133
|
+
type: 'pause',
|
134
|
+
iconType: (React.createElement(Pause, { onClick: function () {
|
135
|
+
var _a;
|
136
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.pause();
|
137
|
+
setIsPlayDisabled(false);
|
138
|
+
setIsPauseDisabled(true);
|
139
|
+
}, className: classnames(SDK_PREFIX + "-file-resumable-run-container-icon", (_b = {},
|
140
|
+
_b[SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isPauseDisabled,
|
141
|
+
_b)) })),
|
142
|
+
ownIcon: true,
|
143
|
+
text: formatString(UploadLocale.pause, locale),
|
144
|
+
disabled: isPauseDisabled
|
145
|
+
};
|
146
|
+
var stopItem = {
|
147
|
+
type: 'stop',
|
148
|
+
iconType: (React.createElement(StopFill, { onClick: handleStop, className: classnames(SDK_PREFIX + "-file-resumable-run-container-icon", (_c = {},
|
149
|
+
_c[SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isStopDisabled,
|
150
|
+
_c)) })),
|
151
|
+
ownIcon: true,
|
152
|
+
text: formatString(UploadLocale.stop, locale)
|
153
|
+
};
|
154
|
+
return [isPauseDisabled ? playItem : pauseItem, stopItem];
|
155
|
+
}, [
|
156
|
+
resumable,
|
157
|
+
isPlayDisabled,
|
158
|
+
isPauseDisabled,
|
159
|
+
isStopDisabled,
|
160
|
+
locale,
|
161
|
+
handleStop
|
162
|
+
]);
|
163
|
+
var handleReadeImageFile = useCallback(function (file) {
|
164
|
+
var reader = new FileReader();
|
165
|
+
reader.readAsArrayBuffer(file);
|
166
|
+
reader.onloadend = function (e) { return __awaiter(_this, void 0, void 0, function () {
|
167
|
+
var view, first4Byte, hexValue, imageUrl_1;
|
168
|
+
return __generator(this, function (_a) {
|
169
|
+
if (e.target.readyState === FileReader.DONE) {
|
170
|
+
view = new DataView(e.target.result);
|
171
|
+
first4Byte = view.getUint32(0, false);
|
172
|
+
hexValue = Number(first4Byte).toString(16);
|
173
|
+
imageUrl_1 = isJpgOrPngOrSvg(file.type, hexValue)
|
174
|
+
? URL.createObjectURL(file)
|
175
|
+
: '';
|
176
|
+
setImageUrl(imageUrl_1);
|
177
|
+
}
|
178
|
+
return [2 /*return*/];
|
179
|
+
});
|
180
|
+
}); };
|
181
|
+
}, []);
|
182
|
+
var handleBeforeUpload = useCallback(function (file) {
|
183
|
+
var _a;
|
184
|
+
if (file.size === 0) {
|
185
|
+
onError === null || onError === void 0 ? void 0 : onError(formatString(UploadLocale.empty_file_error_msg, locale));
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
if (maxFileSize && file.size > maxFileSize) {
|
189
|
+
if (maxFileSizeErrorCallback) {
|
190
|
+
maxFileSizeErrorCallback(file);
|
191
|
+
}
|
192
|
+
else {
|
193
|
+
onError === null || onError === void 0 ? void 0 : onError("" + formatString(UploadLocale.max_size_error_msg, locale) + maxFileSize + formatString(UploadLocale.byte, locale) + " ");
|
194
|
+
}
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
if (minFileSize && file.size < minFileSize) {
|
198
|
+
if (minFileSizeErrorCallback) {
|
199
|
+
minFileSizeErrorCallback(file);
|
200
|
+
}
|
201
|
+
else {
|
202
|
+
onError === null || onError === void 0 ? void 0 : onError("" + formatString(UploadLocale.min_size_error_msg, locale) + minFileSize + formatString(UploadLocale.byte, locale) + " ");
|
203
|
+
}
|
204
|
+
return;
|
205
|
+
}
|
206
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.addFile(file);
|
207
|
+
if (mode === 'image') {
|
208
|
+
handleReadeImageFile(file);
|
209
|
+
}
|
210
|
+
if (onChange) {
|
211
|
+
onChange(file);
|
212
|
+
}
|
213
|
+
return false;
|
214
|
+
}, [
|
215
|
+
maxFileSize,
|
216
|
+
minFileSize,
|
217
|
+
resumable,
|
218
|
+
maxFileSizeErrorCallback,
|
219
|
+
locale,
|
220
|
+
minFileSizeErrorCallback,
|
221
|
+
onChange,
|
222
|
+
onError,
|
223
|
+
mode,
|
224
|
+
handleReadeImageFile
|
225
|
+
]);
|
226
|
+
var handleStart = useCallback(function () {
|
227
|
+
var _a, _b;
|
228
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.updateQuery(query);
|
229
|
+
(_b = resumable.current) === null || _b === void 0 ? void 0 : _b.upload();
|
230
|
+
setShowTool(true);
|
231
|
+
}, [query, setShowTool]);
|
232
|
+
var handleFileSuccess = useCallback(function (message) {
|
233
|
+
var _a;
|
234
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(message);
|
235
|
+
setIsPlayDisabled(true);
|
236
|
+
setIsPauseDisabled(true);
|
237
|
+
setShowTool(false);
|
238
|
+
setPercent(0);
|
239
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
240
|
+
}, [
|
241
|
+
resumable,
|
242
|
+
onSuccess,
|
243
|
+
setIsPlayDisabled,
|
244
|
+
setIsPauseDisabled,
|
245
|
+
setShowTool,
|
246
|
+
setPercent
|
247
|
+
]);
|
248
|
+
var handleUploadStart = useCallback(function () {
|
249
|
+
setIsPlayDisabled(true);
|
250
|
+
setIsPauseDisabled(false);
|
251
|
+
setIsStopDisabled(false);
|
252
|
+
}, [setIsPlayDisabled, setIsPauseDisabled, setIsStopDisabled]);
|
253
|
+
var handleError = useCallback(function (error) {
|
254
|
+
var _a;
|
255
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
256
|
+
onStop === null || onStop === void 0 ? void 0 : onStop();
|
257
|
+
var errorJson = JSON.parse(error);
|
258
|
+
onError === null || onError === void 0 ? void 0 : onError(get(errorJson, 'Message') || UploadLocale.error);
|
259
|
+
setImageUrl('');
|
260
|
+
handleRemove();
|
261
|
+
setIsPlayDisabled(true);
|
262
|
+
setIsPauseDisabled(true);
|
263
|
+
setShowTool(false);
|
264
|
+
}, [
|
265
|
+
onStop,
|
266
|
+
handleRemove,
|
267
|
+
setIsPlayDisabled,
|
268
|
+
setIsPauseDisabled,
|
269
|
+
setShowTool,
|
270
|
+
onError
|
271
|
+
]);
|
272
|
+
var init = useCallback(function () {
|
273
|
+
var ResumableField = new Resumablejs(__assign(__assign({ permanentErrors: [400, 404, 415, 500, 501, 409] }, others), { target: others.target || appEnv.getApiPrefix() + "/upload/file" }));
|
274
|
+
ResumableField.on('fileSuccess', function (_file, message) {
|
275
|
+
handleFileSuccess(message);
|
276
|
+
});
|
277
|
+
ResumableField.on('error', function (error) {
|
278
|
+
handleError(error);
|
279
|
+
});
|
280
|
+
ResumableField.on('fileProgress', function (resumableField) {
|
281
|
+
var percent = Math.floor(resumableField.progress() * 100);
|
282
|
+
setPercent(percent);
|
283
|
+
});
|
284
|
+
ResumableField.on('uploadStart', function () {
|
285
|
+
handleUploadStart();
|
286
|
+
});
|
287
|
+
resumable.current = ResumableField;
|
288
|
+
}, [handleError, setPercent, handleUploadStart, handleFileSuccess, others]);
|
289
|
+
var renderIcons = useCallback(function (icons) {
|
290
|
+
return icons.map(function (item) {
|
291
|
+
var Icon = item.iconType;
|
292
|
+
return (React.createElement(Tooltip, { key: item.type, title: item.text }, Icon));
|
293
|
+
});
|
294
|
+
}, []);
|
295
|
+
useEffect(function () {
|
296
|
+
setImageUrl(defaultImageUrl || '');
|
297
|
+
}, [defaultImageUrl]);
|
298
|
+
useEffect(function () {
|
299
|
+
init();
|
300
|
+
return function () {
|
301
|
+
var _a;
|
302
|
+
(_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
|
303
|
+
};
|
304
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
305
|
+
}, []);
|
306
|
+
useEffect(function () {
|
307
|
+
if (uploading) {
|
308
|
+
handleStart();
|
309
|
+
}
|
310
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
311
|
+
}, [uploading]);
|
312
|
+
return (React.createElement(React.Fragment, null,
|
313
|
+
React.createElement(Dragger, { name: "file", accept: accept, multiple: false, beforeUpload: handleBeforeUpload, onRemove: handleRemove, fileList: fileList || [], showUploadList: showUploadList, disabled: disabled || uploading, className: classnames(SDK_PREFIX + "-file-resumable", className, (_a = {},
|
314
|
+
_a[SDK_PREFIX + "-file-resumable-img"] = mode === 'image',
|
315
|
+
_a)) }, children ? (children) : mode === 'image' ? (React.createElement("div", { className: SDK_PREFIX + "-file-resumable-img-container" },
|
316
|
+
React.createElement("div", { className: classnames(SDK_PREFIX + "-file-resumable-img-operator", (_b = {},
|
317
|
+
_b[SDK_PREFIX + "-file-resumable-img-hidden-plus-icon"] = !!imageUrl,
|
318
|
+
_b)) }, uploadIcon ? uploadIcon : React.createElement(PlusOutlined, null)),
|
319
|
+
React.createElement("img", { src: imageUrl, className: SDK_PREFIX + "-file-resumable-img-box" }))) : (React.createElement(React.Fragment, null,
|
320
|
+
uploadIcon ? (uploadIcon) : (React.createElement(UploadIcon, { className: SDK_PREFIX + "-file-resumable-upload-icon" })),
|
321
|
+
React.createElement("p", null, uploadDesc
|
322
|
+
? uploadDesc
|
323
|
+
: formatString(UploadLocale.text, locale))))),
|
324
|
+
showTool && (React.createElement(React.Fragment, null,
|
325
|
+
React.createElement(Progress, { percent: percent, size: "small" }),
|
326
|
+
React.createElement("div", { className: SDK_PREFIX + "-file-resumable-run-container" }, renderIcons(runItems))))));
|
327
|
+
}
|