@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.
Files changed (57) hide show
  1. package/CHANGELOG.json +46 -0
  2. package/CHANGELOG.md +17 -1
  3. package/es/components/FileResumable/constants.d.ts +33 -0
  4. package/es/components/FileResumable/constants.js +0 -0
  5. package/es/components/FileResumable/index.d.ts +13 -0
  6. package/es/components/FileResumable/index.js +327 -0
  7. package/es/components/FileResumable/style.css +777 -0
  8. package/es/components/FileResumable/style.less +94 -0
  9. package/es/components/FileResumable/utils.d.ts +1 -0
  10. package/es/components/FileResumable/utils.js +17 -0
  11. package/es/components/Menu/Option.d.ts +4 -0
  12. package/es/components/Table/index.js +4 -1
  13. package/es/components/Table/style.css +3 -0
  14. package/es/components/Table/style.less +5 -0
  15. package/es/components/Transfer/List/index.js +15 -8
  16. package/es/constants/language/en.js +3 -1
  17. package/es/constants/language/type.d.ts +2 -0
  18. package/es/constants/language/upload/en.d.ts +3 -0
  19. package/es/constants/language/upload/en.js +20 -0
  20. package/es/constants/language/upload/type.d.ts +20 -0
  21. package/es/constants/language/upload/type.js +4 -0
  22. package/es/constants/language/upload/zh.d.ts +3 -0
  23. package/es/constants/language/upload/zh.js +20 -0
  24. package/es/constants/language/zh.js +3 -1
  25. package/es/index.css +5545 -4775
  26. package/es/index.d.ts +1 -0
  27. package/es/index.js +1 -0
  28. package/es/index.less +16 -15
  29. package/es/style/theme.less +1 -0
  30. package/lib/components/FileResumable/constants.d.ts +33 -0
  31. package/lib/components/FileResumable/constants.js +2 -0
  32. package/lib/components/FileResumable/index.d.ts +13 -0
  33. package/lib/components/FileResumable/index.js +340 -0
  34. package/lib/components/FileResumable/style.css +777 -0
  35. package/lib/components/FileResumable/style.less +94 -0
  36. package/lib/components/FileResumable/utils.d.ts +1 -0
  37. package/lib/components/FileResumable/utils.js +19 -0
  38. package/lib/components/Menu/Option.d.ts +4 -0
  39. package/lib/components/Table/index.js +4 -1
  40. package/lib/components/Table/style.css +3 -0
  41. package/lib/components/Table/style.less +5 -0
  42. package/lib/components/Transfer/List/index.js +14 -7
  43. package/lib/constants/language/en.js +6 -1
  44. package/lib/constants/language/type.d.ts +2 -0
  45. package/lib/constants/language/upload/en.d.ts +3 -0
  46. package/lib/constants/language/upload/en.js +22 -0
  47. package/lib/constants/language/upload/type.d.ts +20 -0
  48. package/lib/constants/language/upload/type.js +9 -0
  49. package/lib/constants/language/upload/zh.d.ts +3 -0
  50. package/lib/constants/language/upload/zh.js +22 -0
  51. package/lib/constants/language/zh.js +6 -1
  52. package/lib/index.css +4039 -3269
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +2 -0
  55. package/lib/index.less +17 -16
  56. package/lib/style/theme.less +1 -0
  57. package/package.json +6 -4
package/es/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export { default as AutoComplete, AutoSelectValue } from './components/AutoCompl
28
28
  export { default as Checkbox } from './components/Checkbox';
29
29
  export { default as CheckboxList, ICheckboxListProps, CheckboxValueType, IOptionItem as ICheckOptionItem } from './components/CheckboxList';
30
30
  export { default as Breadcrumb, IBreadcrumbProps } from './components/Breadcrumb';
31
+ export { default as FileResumable } from './components/FileResumable';
31
32
  export { default as Drawer } from './components/Drawer';
32
33
  export { default as KeyValuePair, IKeyValuePairProps } from './components/KeyValuePair';
33
34
  export { default as NameExplainTooltip, INameExplainTooltip } from './components/NameExplainTooltip';
package/es/index.js CHANGED
@@ -28,6 +28,7 @@ export { default as AutoComplete } from './components/AutoComplete';
28
28
  export { default as Checkbox } from './components/Checkbox';
29
29
  export { default as CheckboxList } from './components/CheckboxList';
30
30
  export { default as Breadcrumb } from './components/Breadcrumb';
31
+ export { default as FileResumable } from './components/FileResumable';
31
32
  export { default as Drawer } from './components/Drawer';
32
33
  export { default as KeyValuePair } from './components/KeyValuePair';
33
34
  export { default as NameExplainTooltip } from './components/NameExplainTooltip';
package/es/index.less CHANGED
@@ -2,48 +2,49 @@
2
2
  @import './style\theme.less';
3
3
  @import './components\AutoComplete\style.less';
4
4
  @import './components\Breadcrumb\style.less';
5
- @import './components\Card\style.less';
6
5
  @import './components\Button\style.less';
7
6
  @import './components\Checkbox\style.less';
8
- @import './components\CheckTransformList\style.less';
9
- @import './components\CheckboxList\style.less';
7
+ @import './components\Card\style.less';
10
8
  @import './components\Collapse\style.less';
9
+ @import './components\CheckboxList\style.less';
10
+ @import './components\CheckTransformList\style.less';
11
11
  @import './components\CollapsiblePanel\style.less';
12
+ @import './components\FileResumable\style.less';
12
13
  @import './components\Drawer\style.less';
13
14
  @import './components\DateTimePicker\style.less';
14
15
  @import './components\Input\style.less';
15
16
  @import './components\KeyValuePair\style.less';
16
17
  @import './components\Menu\style.less';
17
- @import './components\Modal\style.less';
18
18
  @import './components\NameExplainTooltip\style.less';
19
- @import './components\NameLimiter\style.less';
19
+ @import './components\Modal\style.less';
20
+ @import './components\OptionList\style.less';
20
21
  @import './components\RangeInput\style.less';
22
+ @import './components\NameLimiter\style.less';
21
23
  @import './components\RadioGroup\style.less';
22
- @import './components\OptionList\style.less';
23
- @import './components\RemarkName\style.less';
24
24
  @import './components\Selector\style.less';
25
+ @import './components\RemarkName\style.less';
25
26
  @import './components\Spin\style.less';
26
27
  @import './components\Steps\style.less';
27
- @import './components\Table\style.less';
28
28
  @import './components\TagList\style.less';
29
29
  @import './components\Tabs\style.less';
30
+ @import './components\Table\style.less';
30
31
  @import './components\Transfer\style.less';
31
32
  @import './components\Timeline\style.less';
32
33
  @import './components\TreeSelector\style.less';
33
- @import './components\Card\RowExtra\style.less';
34
34
  @import './components\Card\SearchInput\style.less';
35
- @import './components\DateTimePicker\BaseMobile\style.less';
35
+ @import './components\Card\RowExtra\style.less';
36
36
  @import './components\DateTimePicker\Base\style.less';
37
+ @import './components\DateTimePicker\BaseMobile\style.less';
37
38
  @import './components\DateTimePicker\DisplayInput\style.less';
38
- @import './components\OptionList\OptionItem\style.less';
39
39
  @import './components\OptionList\InlineOptionList\style.less';
40
+ @import './components\OptionList\OptionItem\style.less';
40
41
  @import './components\OptionList\PopoverOptionList\style.less';
41
42
  @import './components\Steps\ControlButton\style.less';
42
- @import './components\Table\ColumnTag\style.less';
43
43
  @import './components\TagList\TagSwitch\style.less';
44
44
  @import './components\TagList\Tag\style.less';
45
- @import './components\Transfer\ListBody\style.less';
45
+ @import './components\Table\ColumnTag\style.less';
46
46
  @import './components\Transfer\List\style.less';
47
+ @import './components\Transfer\ListBody\style.less';
47
48
  @import './components\Timeline\TimelineItem\style.less';
48
- @import './components\DateTimePicker\BaseMobile\Absolute\style.less';
49
- @import './components\DateTimePicker\Collapse\Panel\style.less';
49
+ @import './components\DateTimePicker\Collapse\Panel\style.less';
50
+ @import './components\DateTimePicker\BaseMobile\Absolute\style.less';
@@ -387,3 +387,4 @@
387
387
  @editor-nav-background-color: #f5f5f5;
388
388
  @editor_nav_border_color: #d8d8d8;
389
389
  @editor_nav_line_color: #fcce72;
390
+ @image-operator-hover-bg: rgba(51, 51, 51, 0.7);
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,340 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ var __read = (this && this.__read) || function (o, n) {
61
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
62
+ if (!m) return o;
63
+ var i = m.call(o), r, ar = [], e;
64
+ try {
65
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
+ }
67
+ catch (error) { e = { error: error }; }
68
+ finally {
69
+ try {
70
+ if (r && !r.done && (m = i["return"])) m.call(i);
71
+ }
72
+ finally { if (e) throw e.error; }
73
+ }
74
+ return ar;
75
+ };
76
+ var __importStar = (this && this.__importStar) || function (mod) {
77
+ if (mod && mod.__esModule) return mod;
78
+ var result = {};
79
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
80
+ result["default"] = mod;
81
+ return result;
82
+ };
83
+ var __importDefault = (this && this.__importDefault) || function (mod) {
84
+ return (mod && mod.__esModule) ? mod : { "default": mod };
85
+ };
86
+ Object.defineProperty(exports, "__esModule", { value: true });
87
+ var react_1 = __importStar(require("react"));
88
+ var resumablejs_1 = __importDefault(require("resumablejs"));
89
+ var antd_1 = require("antd");
90
+ var config_provider_1 = require("antd/es/config-provider");
91
+ var classnames_1 = __importDefault(require("classnames"));
92
+ var lodash_1 = require("lodash");
93
+ var pandora_component_icons_1 = require("@qn-pandora/pandora-component-icons");
94
+ var app_sdk_1 = require("@qn-pandora/app-sdk");
95
+ var language_1 = require("../../utils/language");
96
+ var type_1 = require("../../constants/language/upload/type");
97
+ var style_1 = require("../../constants/style");
98
+ var utils_1 = require("./utils");
99
+ var Dragger = antd_1.Upload.Dragger;
100
+ function FileResumable(props) {
101
+ var _a, _b;
102
+ var _this = this;
103
+ var resumable = react_1.useRef();
104
+ var _c = __read(react_1.useState(0), 2), percent = _c[0], setPercent = _c[1];
105
+ var _d = __read(react_1.useState(true), 2), isPlayDisabled = _d[0], setIsPlayDisabled = _d[1];
106
+ var _e = __read(react_1.useState(true), 2), isPauseDisabled = _e[0], setIsPauseDisabled = _e[1];
107
+ var _f = __read(react_1.useState(true), 2), isStopDisabled = _f[0], setIsStopDisabled = _f[1];
108
+ var _g = __read(react_1.useState(false), 2), showTool = _g[0], setShowTool = _g[1];
109
+ var _h = __read(react_1.useState(''), 2), imageUrl = _h[0], setImageUrl = _h[1];
110
+ var locale = react_1.useContext(config_provider_1.ConfigContext).locale;
111
+ 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"]);
112
+ var handleRemove = react_1.useCallback(function () {
113
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
114
+ }, [onChange]);
115
+ var handleStop = react_1.useCallback(function () {
116
+ var _a;
117
+ onStop === null || onStop === void 0 ? void 0 : onStop();
118
+ handleRemove();
119
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
120
+ setShowTool(false);
121
+ setIsStopDisabled(true);
122
+ setIsPlayDisabled(true);
123
+ setIsPauseDisabled(true);
124
+ }, [
125
+ onStop,
126
+ handleRemove,
127
+ resumable,
128
+ setIsStopDisabled,
129
+ setIsPlayDisabled,
130
+ setIsPauseDisabled
131
+ ]);
132
+ var runItems = react_1.useMemo(function () {
133
+ var _a, _b, _c;
134
+ var playItem = {
135
+ type: 'play',
136
+ iconType: (react_1.default.createElement(pandora_component_icons_1.CaretRightOutlined, { onClick: function () {
137
+ var _a;
138
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.upload();
139
+ }, className: classnames_1.default(style_1.SDK_PREFIX + "-file-resumable-run-container-icon", (_a = {},
140
+ _a[style_1.SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isPlayDisabled,
141
+ _a)) })),
142
+ text: language_1.formatString(type_1.UploadLocale.play, locale)
143
+ };
144
+ var pauseItem = {
145
+ type: 'pause',
146
+ iconType: (react_1.default.createElement(pandora_component_icons_1.Pause, { onClick: function () {
147
+ var _a;
148
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.pause();
149
+ setIsPlayDisabled(false);
150
+ setIsPauseDisabled(true);
151
+ }, className: classnames_1.default(style_1.SDK_PREFIX + "-file-resumable-run-container-icon", (_b = {},
152
+ _b[style_1.SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isPauseDisabled,
153
+ _b)) })),
154
+ ownIcon: true,
155
+ text: language_1.formatString(type_1.UploadLocale.pause, locale),
156
+ disabled: isPauseDisabled
157
+ };
158
+ var stopItem = {
159
+ type: 'stop',
160
+ iconType: (react_1.default.createElement(pandora_component_icons_1.StopFill, { onClick: handleStop, className: classnames_1.default(style_1.SDK_PREFIX + "-file-resumable-run-container-icon", (_c = {},
161
+ _c[style_1.SDK_PREFIX + "-file-resumable-run-container-icon-disabled"] = isStopDisabled,
162
+ _c)) })),
163
+ ownIcon: true,
164
+ text: language_1.formatString(type_1.UploadLocale.stop, locale)
165
+ };
166
+ return [isPauseDisabled ? playItem : pauseItem, stopItem];
167
+ }, [
168
+ resumable,
169
+ isPlayDisabled,
170
+ isPauseDisabled,
171
+ isStopDisabled,
172
+ locale,
173
+ handleStop
174
+ ]);
175
+ var handleReadeImageFile = react_1.useCallback(function (file) {
176
+ var reader = new FileReader();
177
+ reader.readAsArrayBuffer(file);
178
+ reader.onloadend = function (e) { return __awaiter(_this, void 0, void 0, function () {
179
+ var view, first4Byte, hexValue, imageUrl_1;
180
+ return __generator(this, function (_a) {
181
+ if (e.target.readyState === FileReader.DONE) {
182
+ view = new DataView(e.target.result);
183
+ first4Byte = view.getUint32(0, false);
184
+ hexValue = Number(first4Byte).toString(16);
185
+ imageUrl_1 = utils_1.isJpgOrPngOrSvg(file.type, hexValue)
186
+ ? URL.createObjectURL(file)
187
+ : '';
188
+ setImageUrl(imageUrl_1);
189
+ }
190
+ return [2 /*return*/];
191
+ });
192
+ }); };
193
+ }, []);
194
+ var handleBeforeUpload = react_1.useCallback(function (file) {
195
+ var _a;
196
+ if (file.size === 0) {
197
+ onError === null || onError === void 0 ? void 0 : onError(language_1.formatString(type_1.UploadLocale.empty_file_error_msg, locale));
198
+ return;
199
+ }
200
+ if (maxFileSize && file.size > maxFileSize) {
201
+ if (maxFileSizeErrorCallback) {
202
+ maxFileSizeErrorCallback(file);
203
+ }
204
+ else {
205
+ onError === null || onError === void 0 ? void 0 : onError("" + language_1.formatString(type_1.UploadLocale.max_size_error_msg, locale) + maxFileSize + language_1.formatString(type_1.UploadLocale.byte, locale) + " ");
206
+ }
207
+ return;
208
+ }
209
+ if (minFileSize && file.size < minFileSize) {
210
+ if (minFileSizeErrorCallback) {
211
+ minFileSizeErrorCallback(file);
212
+ }
213
+ else {
214
+ onError === null || onError === void 0 ? void 0 : onError("" + language_1.formatString(type_1.UploadLocale.min_size_error_msg, locale) + minFileSize + language_1.formatString(type_1.UploadLocale.byte, locale) + " ");
215
+ }
216
+ return;
217
+ }
218
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.addFile(file);
219
+ if (mode === 'image') {
220
+ handleReadeImageFile(file);
221
+ }
222
+ if (onChange) {
223
+ onChange(file);
224
+ }
225
+ return false;
226
+ }, [
227
+ maxFileSize,
228
+ minFileSize,
229
+ resumable,
230
+ maxFileSizeErrorCallback,
231
+ locale,
232
+ minFileSizeErrorCallback,
233
+ onChange,
234
+ onError,
235
+ mode,
236
+ handleReadeImageFile
237
+ ]);
238
+ var handleStart = react_1.useCallback(function () {
239
+ var _a, _b;
240
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.updateQuery(query);
241
+ (_b = resumable.current) === null || _b === void 0 ? void 0 : _b.upload();
242
+ setShowTool(true);
243
+ }, [query, setShowTool]);
244
+ var handleFileSuccess = react_1.useCallback(function (message) {
245
+ var _a;
246
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(message);
247
+ setIsPlayDisabled(true);
248
+ setIsPauseDisabled(true);
249
+ setShowTool(false);
250
+ setPercent(0);
251
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
252
+ }, [
253
+ resumable,
254
+ onSuccess,
255
+ setIsPlayDisabled,
256
+ setIsPauseDisabled,
257
+ setShowTool,
258
+ setPercent
259
+ ]);
260
+ var handleUploadStart = react_1.useCallback(function () {
261
+ setIsPlayDisabled(true);
262
+ setIsPauseDisabled(false);
263
+ setIsStopDisabled(false);
264
+ }, [setIsPlayDisabled, setIsPauseDisabled, setIsStopDisabled]);
265
+ var handleError = react_1.useCallback(function (error) {
266
+ var _a;
267
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
268
+ onStop === null || onStop === void 0 ? void 0 : onStop();
269
+ var errorJson = JSON.parse(error);
270
+ onError === null || onError === void 0 ? void 0 : onError(lodash_1.get(errorJson, 'Message') || type_1.UploadLocale.error);
271
+ setImageUrl('');
272
+ handleRemove();
273
+ setIsPlayDisabled(true);
274
+ setIsPauseDisabled(true);
275
+ setShowTool(false);
276
+ }, [
277
+ onStop,
278
+ handleRemove,
279
+ setIsPlayDisabled,
280
+ setIsPauseDisabled,
281
+ setShowTool,
282
+ onError
283
+ ]);
284
+ var init = react_1.useCallback(function () {
285
+ var ResumableField = new resumablejs_1.default(__assign(__assign({ permanentErrors: [400, 404, 415, 500, 501, 409] }, others), { target: others.target || app_sdk_1.appEnv.getApiPrefix() + "/upload/file" }));
286
+ ResumableField.on('fileSuccess', function (_file, message) {
287
+ handleFileSuccess(message);
288
+ });
289
+ ResumableField.on('error', function (error) {
290
+ handleError(error);
291
+ });
292
+ ResumableField.on('fileProgress', function (resumableField) {
293
+ var percent = Math.floor(resumableField.progress() * 100);
294
+ setPercent(percent);
295
+ });
296
+ ResumableField.on('uploadStart', function () {
297
+ handleUploadStart();
298
+ });
299
+ resumable.current = ResumableField;
300
+ }, [handleError, setPercent, handleUploadStart, handleFileSuccess, others]);
301
+ var renderIcons = react_1.useCallback(function (icons) {
302
+ return icons.map(function (item) {
303
+ var Icon = item.iconType;
304
+ return (react_1.default.createElement(antd_1.Tooltip, { key: item.type, title: item.text }, Icon));
305
+ });
306
+ }, []);
307
+ react_1.useEffect(function () {
308
+ setImageUrl(defaultImageUrl || '');
309
+ }, [defaultImageUrl]);
310
+ react_1.useEffect(function () {
311
+ init();
312
+ return function () {
313
+ var _a;
314
+ (_a = resumable.current) === null || _a === void 0 ? void 0 : _a.cancel();
315
+ };
316
+ // eslint-disable-next-line react-hooks/exhaustive-deps
317
+ }, []);
318
+ react_1.useEffect(function () {
319
+ if (uploading) {
320
+ handleStart();
321
+ }
322
+ // eslint-disable-next-line react-hooks/exhaustive-deps
323
+ }, [uploading]);
324
+ return (react_1.default.createElement(react_1.default.Fragment, null,
325
+ react_1.default.createElement(Dragger, { name: "file", accept: accept, multiple: false, beforeUpload: handleBeforeUpload, onRemove: handleRemove, fileList: fileList || [], showUploadList: showUploadList, disabled: disabled || uploading, className: classnames_1.default(style_1.SDK_PREFIX + "-file-resumable", className, (_a = {},
326
+ _a[style_1.SDK_PREFIX + "-file-resumable-img"] = mode === 'image',
327
+ _a)) }, children ? (children) : mode === 'image' ? (react_1.default.createElement("div", { className: style_1.SDK_PREFIX + "-file-resumable-img-container" },
328
+ react_1.default.createElement("div", { className: classnames_1.default(style_1.SDK_PREFIX + "-file-resumable-img-operator", (_b = {},
329
+ _b[style_1.SDK_PREFIX + "-file-resumable-img-hidden-plus-icon"] = !!imageUrl,
330
+ _b)) }, uploadIcon ? uploadIcon : react_1.default.createElement(pandora_component_icons_1.PlusOutlined, null)),
331
+ react_1.default.createElement("img", { src: imageUrl, className: style_1.SDK_PREFIX + "-file-resumable-img-box" }))) : (react_1.default.createElement(react_1.default.Fragment, null,
332
+ uploadIcon ? (uploadIcon) : (react_1.default.createElement(pandora_component_icons_1.Upload, { className: style_1.SDK_PREFIX + "-file-resumable-upload-icon" })),
333
+ react_1.default.createElement("p", null, uploadDesc
334
+ ? uploadDesc
335
+ : language_1.formatString(type_1.UploadLocale.text, locale))))),
336
+ showTool && (react_1.default.createElement(react_1.default.Fragment, null,
337
+ react_1.default.createElement(antd_1.Progress, { percent: percent, size: "small" }),
338
+ react_1.default.createElement("div", { className: style_1.SDK_PREFIX + "-file-resumable-run-container" }, renderIcons(runItems))))));
339
+ }
340
+ exports.default = FileResumable;