@para-ui/core 4.0.18 → 4.0.19-aplha2

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 (125) hide show
  1. package/Breadcrumbs/index.js +2 -2
  2. package/Button/SplitButton.d.ts +1 -1
  3. package/Button/index.js +2 -2
  4. package/ButtonGroup/index.js +2 -2
  5. package/Cascader/OptionList/Column.d.ts +1 -1
  6. package/Cascader/index.js +4 -4
  7. package/ColorPicker/chromePicker/index.d.ts +1 -2
  8. package/ColorPicker/compactPicker/index.d.ts +1 -2
  9. package/ColorPicker/sketchPicker/index.d.ts +1 -2
  10. package/ColorPicker/swatchesPicker/index.d.ts +1 -2
  11. package/ComboSelect/index.js +4 -4
  12. package/Container/index.d.ts +1 -1
  13. package/CopyText/index.js +2 -2
  14. package/CycleSelector/index.js +3 -2
  15. package/DatePicker/PickerButton.d.ts +1 -2
  16. package/DatePicker/PickerTag.d.ts +1 -2
  17. package/DatePicker/index.js +2 -2
  18. package/Descriptions/index.js +2 -2
  19. package/Desktop/index.js +3 -3
  20. package/DragVerify/index.js +3 -2
  21. package/Drawer/index.js +2 -2
  22. package/DynamicMultiBox/formItem.d.ts +1 -2
  23. package/DynamicMultiBox/index.js +4 -4
  24. package/DynamicMultiBox/interface.d.ts +1 -1
  25. package/DynamicMultiBox/rowForm.d.ts +1 -1
  26. package/Empty/images/index.d.ts +2 -3
  27. package/Empty/index.js +4 -3
  28. package/Form/index.js +5 -5
  29. package/FormItem/index.js +5 -5
  30. package/FunctionModal/index.js +4 -5
  31. package/FunctionModal/modalContext.d.ts +1 -2
  32. package/GlobalContext/index.js +3 -39
  33. package/InputLang/index.js +3 -3
  34. package/Message/index.d.ts +1 -1
  35. package/Modal/index.js +3 -4
  36. package/MultiBox/index.js +3 -3
  37. package/OperateBtn/index.js +2 -2
  38. package/PageHeader/index.js +2 -2
  39. package/Pagination/index.js +4 -4
  40. package/ParauiProvider/index.d.ts +2 -2
  41. package/ParauiProvider/index.js +3 -3
  42. package/PopConfirm/index.js +2 -2
  43. package/Prompt/index.d.ts +1 -1
  44. package/Querying/images/index.d.ts +2 -3
  45. package/Querying/index.js +4 -3
  46. package/QuickReply/index.js +3 -3
  47. package/README.md +4 -0
  48. package/Search/index.js +2 -2
  49. package/Select/index.js +4 -4
  50. package/SelectInput/index.js +4 -4
  51. package/Selector/index.js +328 -5
  52. package/SelectorPicker/index.js +3 -4
  53. package/SingleBox/index.js +3 -3
  54. package/Switch/index.js +3 -2
  55. package/Table/index.js +3 -3
  56. package/Tabs/index.js +2 -2
  57. package/TextEditor/index.js +2 -2
  58. package/TextField/index.js +2 -2
  59. package/TimePicker/index.js +2 -2
  60. package/Timeline/TimelineItem.d.ts +1 -1
  61. package/ToggleButton/index.js +2 -2
  62. package/Tooltip/utils.d.ts +1 -1
  63. package/Transfer/box.d.ts +1 -1
  64. package/Transfer/index.d.ts +1 -1
  65. package/Transfer/index.js +3 -3
  66. package/Tree/index.js +5 -5
  67. package/Tree/utils/treeUtil.d.ts +1 -1
  68. package/Upload/index.js +411 -629
  69. package/_verture/{index-10792f39.js → index-543781c9.js} +1 -1
  70. package/_verture/{index-02b7a0b7.js → index-c77ccb98.js} +1 -1
  71. package/_verture/{intl-f2f27722.js → index-ca413216.js} +54 -1
  72. package/_verture/{index-cc76d8d5.js → index-cb218775.js} +1 -1
  73. package/_verture/{useFormatMessage-eb13cf56.js → useFormatMessage-1fc7c957.js} +1 -1
  74. package/_verture/{useGlobalProps-1e416658.js → useGlobalProps-4ae1a007.js} +1 -1
  75. package/index.js +8 -11
  76. package/package.json +12 -16
  77. package/umd/Breadcrumbs.js +7 -7
  78. package/umd/Button.js +2 -2
  79. package/umd/ButtonGroup.js +4 -4
  80. package/umd/Carousel.js +3 -3
  81. package/umd/Cascader.js +1 -1
  82. package/umd/ColorPicker.js +1 -1
  83. package/umd/ComboSelect.js +5 -5
  84. package/umd/CopyText.js +7 -7
  85. package/umd/CycleSelector.js +5 -5
  86. package/umd/DatePicker.js +2 -2
  87. package/umd/Descriptions.js +7 -7
  88. package/umd/Desktop.js +2 -2
  89. package/umd/DragVerify.js +3 -3
  90. package/umd/Drawer.js +2 -2
  91. package/umd/DynamicMultiBox.js +3 -3
  92. package/umd/Empty.js +1 -1
  93. package/umd/Form.js +3 -3
  94. package/umd/FormItem.js +3 -3
  95. package/umd/FunctionModal.js +7 -7
  96. package/umd/GlobalContext.js +1 -1
  97. package/umd/InputLang.js +2 -2
  98. package/umd/Modal.js +2 -2
  99. package/umd/MultiBox.js +5 -5
  100. package/umd/OperateBtn.js +2 -2
  101. package/umd/PageHeader.js +4 -4
  102. package/umd/Pagination.js +3 -3
  103. package/umd/ParauiProvider.js +1 -1
  104. package/umd/PopConfirm.js +5 -5
  105. package/umd/Querying.js +1 -1
  106. package/umd/QuickReply.js +2 -2
  107. package/umd/Search.js +2 -2
  108. package/umd/Select.js +3 -3
  109. package/umd/SelectInput.js +3 -3
  110. package/umd/Selector.js +2 -2
  111. package/umd/SelectorPicker.js +4 -4
  112. package/umd/SingleBox.js +2 -2
  113. package/umd/Switch.js +2 -2
  114. package/umd/Table.js +5 -5
  115. package/umd/Tabs.js +2 -2
  116. package/umd/TextEditor.js +3 -3
  117. package/umd/TextField.js +2 -2
  118. package/umd/TimePicker.js +2 -2
  119. package/umd/ToggleButton.js +2 -2
  120. package/umd/Transfer.js +8 -8
  121. package/umd/Tree.js +4 -4
  122. package/umd/Upload.js +7 -7
  123. package/_verture/index-287ae1b3.js +0 -327
  124. package/_verture/index-c568f272.js +0 -18
  125. /package/_verture/{modalContext-3ba6ca8f.js → modalContext-c8cc3107.js} +0 -0
package/Upload/index.js CHANGED
@@ -4,10 +4,6 @@ import { useState, useEffect, useRef, memo, forwardRef, useCallback, useImperati
4
4
  import RcUpload from 'rc-upload';
5
5
  import UploadIcon from '@para-ui/icons/UploadFile';
6
6
  import LoadingIcon from '@para-ui/icons/Loading';
7
- import { _ as _toConsumableArray } from '../_verture/toConsumableArray-8f4c9589.js';
8
- import { _ as _typeof } from '../_verture/typeof-adeedc13.js';
9
- import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
10
- import { r as regenerator } from '../_verture/index-287ae1b3.js';
11
7
  import Delete from '@para-ui/icons/Delete';
12
8
  import TextIcon from '@para-ui/icons/Text';
13
9
  import PhotoIcon from '@para-ui/icons/Photo';
@@ -15,15 +11,15 @@ import clsx from 'clsx';
15
11
  import { $ as $prefixCls, a as $rcPrefixCls } from '../_verture/constant-5317fc89.js';
16
12
  import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
17
13
  import Forbid from '@para-ui/icons/Forbid';
18
- import { u as useFormatMessage } from '../_verture/useFormatMessage-eb13cf56.js';
14
+ import { u as useFormatMessage } from '../_verture/useFormatMessage-1fc7c957.js';
19
15
  import EditOutline from '@para-ui/icons/EditOutline';
20
16
  import { Button } from '../Button/index.js';
17
+ import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
21
18
  import { Slider } from '../Slider/index.js';
22
19
  import Cropper from 'react-easy-crop';
23
20
  import { Modal } from '../Modal/index.js';
24
- import '../_verture/unsupportedIterableToArray-cb478f24.js';
25
- import '../_verture/typeof-6ec38efd.js';
26
- import '@para-ui/core/GlobalContext';
21
+ import '../_verture/index-ca413216.js';
22
+ import '@paraview/lib';
27
23
  import '@para-ui/icons/LoadingF';
28
24
  import '../Tooltip/index.js';
29
25
  import 'rc-tooltip';
@@ -33,12 +29,11 @@ import '../_verture/index-389675ab.js';
33
29
  import 'rc-dropdown';
34
30
  import '../_verture/usePopupContainer-635f66f4.js';
35
31
  import 'dayjs';
36
- import '@paraview/lib';
37
32
  import '../AutoTips/index.js';
33
+ import '../_verture/unsupportedIterableToArray-cb478f24.js';
38
34
  import 'rc-slider';
39
35
  import 'rc-dialog';
40
36
  import '@para-ui/icons/Close';
41
- import '../_verture/index-c568f272.js';
42
37
  import 'react-dom';
43
38
  import '@para-ui/icons/CheckCircleF';
44
39
  import '@para-ui/icons/WarningCircleF';
@@ -47,50 +42,41 @@ import '@para-ui/icons/CloseCircleF';
47
42
  var css_248z$4 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/11 下午3:08\n* @description\n*/\n/**\n* @author linhd\n* @date 2023/4/11 14:16\n* @description 最新色卡\n*/\n.paraui-v4-upload-list-text .upload-list-item {\n margin-top: 8px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info {\n display: flex;\n align-items: center;\n padding: 0 8px;\n line-height: 28px;\n font-size: 14px;\n color: rgb(29, 33, 38);\n border-radius: 4px;\n transition: background-color 0.3s;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text {\n position: relative;\n display: inline-flex;\n align-items: center;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-fileicon {\n line-height: 0;\n opacity: 1;\n transition: opacity 0.3s;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-fileicon svg {\n color: inherit;\n font-size: inherit;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text-name {\n margin-left: 10px;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions {\n position: absolute;\n left: 0;\n top: 50%;\n transform: translateY(-50%);\n z-index: -1;\n opacity: 0;\n visibility: hidden;\n line-height: 0;\n transition: opacity 0.3s;\n cursor: pointer;\n}\n.paraui-v4-upload-list-text .upload-list-item-info .upload-list-text .upload-list-actions svg {\n color: rgb(244, 66, 66);\n font-size: inherit;\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover {\n background-color: rgb(247, 248, 250);\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover .upload-list-text .upload-list-actions {\n visibility: visible;\n opacity: 1;\n z-index: 1;\n}\n.paraui-v4-upload-list-text .upload-list-item-info:hover .upload-list-text .upload-list-fileicon-active {\n opacity: 0;\n}\n.paraui-v4-upload-list-picture {\n display: inline-flex;\n align-items: center;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item {\n position: relative;\n display: inline-block;\n width: 100px;\n height: 100px;\n margin-right: 16px;\n border-radius: 4px;\n cursor: default;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item::before {\n content: \" \";\n position: absolute;\n left: 0;\n right: 0;\n bottom: 0;\n top: 0;\n background-color: rgb(29, 33, 38);\n border-radius: 4px;\n opacity: 0;\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item img {\n width: 100%;\n height: 100%;\n border-radius: 4px;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-picture-name {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n padding: 0 10px;\n font-size: 12px;\n line-height: 24px;\n text-align: center;\n text-overflow: ellipsis;\n overflow: hidden;\n white-space: nowrap;\n background-color: rgb(29, 33, 38);\n border-radius: 0 0 4px 4px;\n color: rgb(255, 255, 255);\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-actions {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n opacity: 0;\n line-height: 0;\n cursor: pointer;\n transition: 0.3s;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item .upload-list-actions svg {\n color: rgb(255, 255, 255);\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly)::before {\n opacity: 1;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly) .upload-list-actions {\n opacity: 1;\n}\n.paraui-v4-upload-list-picture .upload-list-picture-item:hover:not(.upload-list-picture-item-readonly) .upload-list-picture-name {\n opacity: 0;\n}";
48
43
  styleInject(css_248z$4);
49
44
 
50
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
51
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
52
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
53
45
  //UploadList
54
- var UploadList = function UploadList(props) {
55
- var _props$listType = props.listType,
56
- listType = _props$listType === void 0 ? 'text' : _props$listType,
57
- _props$items = props.items,
58
- items = _props$items === void 0 ? [] : _props$items,
59
- onRemove = props.onRemove,
60
- _props$showRemoveIcon = props.showRemoveIcon,
61
- showRemoveIcon = _props$showRemoveIcon === void 0 ? true : _props$showRemoveIcon,
62
- removeIcon = props.removeIcon,
63
- itemRender = props.itemRender,
64
- readonly = props.readonly;
65
- var _useState = useState([]),
66
- _useState2 = _slicedToArray(_useState, 2),
67
- uploadList = _useState2[0],
68
- setUploadList = _useState2[1];
46
+ const UploadList = props => {
47
+ const {
48
+ listType = 'text',
49
+ items = [],
50
+ onRemove,
51
+ showRemoveIcon = true,
52
+ removeIcon,
53
+ itemRender,
54
+ readonly
55
+ } = props;
56
+ const [uploadList, setUploadList] = useState([]);
69
57
  //处理删除
70
- var handleRemove = function handleRemove(file, evt) {
58
+ const handleRemove = (file, evt) => {
71
59
  evt.stopPropagation();
72
60
  onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
73
61
  };
74
62
  //渲染列表actions
75
- var renderActions = function renderActions(file) {
63
+ const renderActions = file => {
76
64
  return showRemoveIcon && !readonly && jsx("span", Object.assign({
77
65
  className: 'upload-list-actions',
78
- onClick: function onClick(evt) {
79
- return handleRemove(file, evt);
80
- }
66
+ onClick: evt => handleRemove(file, evt)
81
67
  }, {
82
68
  children: removeIcon || jsx(Delete, {})
83
69
  }));
84
70
  };
85
71
  //文件列表 text
86
- var renderFileListText = function renderFileListText() {
72
+ const renderFileListText = () => {
87
73
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
88
- return uploadList.map(function (file, idx) {
74
+ return uploadList.map((file, idx) => {
89
75
  var _a;
90
76
  if (itemRender)
91
77
  //自定义渲染
92
78
  return itemRender(file, uploadList);
93
- var isImage = !!((_a = file.type) === null || _a === void 0 ? void 0 : _a.includes('image/'));
79
+ const isImage = !!((_a = file.type) === null || _a === void 0 ? void 0 : _a.includes('image/'));
94
80
  return jsx("div", Object.assign({
95
81
  className: 'upload-list-item'
96
82
  }, {
@@ -115,9 +101,9 @@ var UploadList = function UploadList(props) {
115
101
  });
116
102
  };
117
103
  //文件列表 picture-card
118
- var renderFileListPicture = function renderFileListPicture() {
104
+ const renderFileListPicture = () => {
119
105
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
120
- return uploadList.map(function (file, idx) {
106
+ return uploadList.map((file, idx) => {
121
107
  if (itemRender)
122
108
  //自定义渲染
123
109
  return itemRender(file, uploadList);
@@ -137,84 +123,31 @@ var UploadList = function UploadList(props) {
137
123
  });
138
124
  };
139
125
  //处理文件
140
- var handleFileFormat = function handleFileFormat() {
141
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
142
- var readerFileAsDataUrl, _iterator, _step, file, dataUrl;
143
- return regenerator.wrap(function _callee2$(_context2) {
144
- while (1) switch (_context2.prev = _context2.next) {
145
- case 0:
146
- if (items === null || items === void 0 ? void 0 : items.length) {
147
- _context2.next = 2;
148
- break;
149
- }
150
- return _context2.abrupt("return", setUploadList([]));
151
- case 2:
152
- //读取file as DataUrl
153
- readerFileAsDataUrl = function readerFileAsDataUrl(file) {
154
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
155
- return regenerator.wrap(function _callee$(_context) {
156
- while (1) switch (_context.prev = _context.next) {
157
- case 0:
158
- return _context.abrupt("return", new Promise(function (resolve) {
159
- var fileReader = new FileReader();
160
- if (file.originFileObj) {
161
- fileReader.onload = function () {
162
- resolve(fileReader.result);
163
- };
164
- fileReader.readAsDataURL(file.originFileObj);
165
- } else resolve('');
166
- }));
167
- case 1:
168
- case "end":
169
- return _context.stop();
170
- }
171
- }, _callee);
172
- }));
173
- };
174
- _iterator = _createForOfIteratorHelper(items);
175
- _context2.prev = 4;
176
- _iterator.s();
177
- case 6:
178
- if ((_step = _iterator.n()).done) {
179
- _context2.next = 15;
180
- break;
181
- }
182
- file = _step.value;
183
- if (!file.originFileObj) {
184
- _context2.next = 13;
185
- break;
186
- }
187
- _context2.next = 11;
188
- return readerFileAsDataUrl(file);
189
- case 11:
190
- dataUrl = _context2.sent;
191
- file.dataUrl = dataUrl;
192
- case 13:
193
- _context2.next = 6;
194
- break;
195
- case 15:
196
- _context2.next = 20;
197
- break;
198
- case 17:
199
- _context2.prev = 17;
200
- _context2.t0 = _context2["catch"](4);
201
- _iterator.e(_context2.t0);
202
- case 20:
203
- _context2.prev = 20;
204
- _iterator.f();
205
- return _context2.finish(20);
206
- case 23:
207
- setUploadList(_toConsumableArray(items));
208
- case 24:
209
- case "end":
210
- return _context2.stop();
211
- }
212
- }, _callee2, null, [[4, 17, 20, 23]]);
213
- }));
214
- };
215
- useEffect(function () {
216
- if (listType === 'picture-card') handleFileFormat();else setUploadList(function (pre) {
217
- if (items) return _toConsumableArray(items);
126
+ const handleFileFormat = () => __awaiter(void 0, void 0, void 0, function* () {
127
+ if (!(items === null || items === void 0 ? void 0 : items.length)) return setUploadList([]);
128
+ //读取file as DataUrl
129
+ const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
130
+ return new Promise(resolve => {
131
+ const fileReader = new FileReader();
132
+ if (file.originFileObj) {
133
+ fileReader.onload = () => {
134
+ resolve(fileReader.result);
135
+ };
136
+ fileReader.readAsDataURL(file.originFileObj);
137
+ } else resolve('');
138
+ });
139
+ });
140
+ for (const file of items) {
141
+ if (file.originFileObj) {
142
+ const dataUrl = yield readerFileAsDataUrl(file);
143
+ file.dataUrl = dataUrl;
144
+ }
145
+ }
146
+ setUploadList([...items]);
147
+ });
148
+ useEffect(() => {
149
+ if (listType === 'picture-card') handleFileFormat();else setUploadList(pre => {
150
+ if (items) return [...items];
218
151
  return pre;
219
152
  });
220
153
  }, [items]);
@@ -235,7 +168,7 @@ var css_248z$3 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/15
235
168
  styleInject(css_248z$3);
236
169
 
237
170
  //error tip
238
- var ErrorTip = function ErrorTip(props) {
171
+ const ErrorTip = props => {
239
172
  return jsxs("div", Object.assign({
240
173
  className: clsx("".concat($prefixCls, "-upload-error"), props.className)
241
174
  }, {
@@ -268,144 +201,99 @@ var zh = {
268
201
  };
269
202
 
270
203
  var localeJson = {
271
- zh: zh,
272
- en: en
204
+ zh,
205
+ en
273
206
  };
274
207
 
275
208
  var css_248z$2 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/11 下午7:31\n* @description\n*/\n/**\n* @author linhd\n* @date 2023/4/11 14:16\n* @description 最新色卡\n*/\n.paraui-v4-upload-image {\n display: inline-flex;\n align-items: center;\n /* &-border {\n .upload-image-select{\n border: 2px dashed $NA1;\n\n &:hover {\n border: 2px dashed $NPT8;\n }\n }\n } */\n}\n.paraui-v4-upload-image .upload-image-select {\n position: relative;\n width: 100px;\n height: 100px;\n cursor: pointer;\n background-color: rgb(247, 248, 250);\n border-radius: 4px;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-select-loading {\n pointer-events: none;\n}\n.paraui-v4-upload-image .upload-image-select .component-upload {\n display: inline-block;\n width: 100%;\n height: 100%;\n}\n.paraui-v4-upload-image .upload-image-select:hover .upload-image-picture-card {\n color: rgb(46, 101, 230);\n}\n.paraui-v4-upload-image .upload-image-picture-card {\n display: inline-flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: 100%;\n font-size: 14px;\n color: rgb(29, 33, 38);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper {\n position: relative;\n width: 100%;\n height: 100%;\n cursor: default;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper img {\n width: 100%;\n height: 100%;\n border-radius: 4px;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper::before {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n content: \" \";\n background-color: rgb(29, 33, 38);\n border-radius: 4px;\n opacity: 0;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-name {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n padding: 0 10px;\n overflow: hidden;\n font-size: 12px;\n line-height: 24px;\n color: rgb(255, 255, 255);\n text-align: center;\n text-overflow: ellipsis;\n white-space: nowrap;\n background-color: rgb(29, 33, 38);\n border-radius: 0 0 4px 4px;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-action {\n position: absolute;\n top: 50%;\n left: 50%;\n line-height: 0;\n cursor: pointer;\n opacity: 0;\n transition: 0.3s;\n transform: translate(-50%, -50%);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper-action svg {\n color: rgb(255, 255, 255);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover::before {\n opacity: 1;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover .upload-img-wrapper-name {\n opacity: 0;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-img-wrapper:hover .upload-img-wrapper-action {\n opacity: 1;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-icon {\n font-size: 30px;\n color: rgb(46, 101, 230);\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-loading {\n font-size: 30px;\n color: rgb(46, 101, 230);\n animation: imageLoadingCircle 1s infinite linear;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-text {\n margin-top: 6px;\n color: inherit;\n text-align: center;\n transition: 0.3s;\n}\n.paraui-v4-upload-image .upload-image-picture-card .upload-image-text-loading {\n color: rgb(46, 101, 230);\n}\n@keyframes imageLoadingCircle {\n 100% {\n transform: rotate(360deg);\n }\n}";
276
209
  styleInject(css_248z$2);
277
210
 
278
211
  //ImageUpload
279
- var ImageUpload = function ImageUpload(props) {
280
- var className = props.className,
281
- style = props.style,
282
- _onStart = props.onStart,
283
- _onSuccess = props.onSuccess,
284
- _onError = props.onError,
285
- _onProgress = props.onProgress,
286
- onRemove = props.onRemove,
287
- _beforeUpload = props.beforeUpload,
288
- onChange = props.onChange,
289
- _props$defaultFileLis = props.defaultFileList,
290
- defaultFileList = _props$defaultFileLis === void 0 ? [] : _props$defaultFileLis,
291
- fileList = props.fileList,
292
- _props$showUploadList = props.showUploadList,
293
- showUploadList = _props$showUploadList === void 0 ? true : _props$showUploadList,
294
- maxCount = props.maxCount,
295
- _props$children = props.children,
296
- children = _props$children === void 0 ? null : _props$children,
297
- itemRender = props.itemRender,
298
- _props$showUploadErro = props.showUploadError,
299
- showUploadError = _props$showUploadErro === void 0 ? true : _props$showUploadErro,
300
- _props$stash = props.stash,
301
- stash = _props$stash === void 0 ? false : _props$stash,
302
- _props$uploading = props.uploading,
303
- uploading = _props$uploading === void 0 ? true : _props$uploading,
304
- _props$loading = props.loading,
305
- loading = _props$loading === void 0 ? false : _props$loading,
306
- _props$showLoading = props.showLoading,
307
- showLoadingProp = _props$showLoading === void 0 ? false : _props$showLoading,
308
- defaultImage = props.defaultImage,
309
- readonly = props.readonly,
212
+ const ImageUpload = props => {
213
+ const {
214
+ className,
215
+ style,
216
+ onStart,
217
+ onSuccess,
218
+ onError,
219
+ onProgress,
220
+ onRemove,
221
+ beforeUpload,
222
+ onChange,
223
+ defaultFileList = [],
224
+ fileList,
225
+ showUploadList = true,
226
+ maxCount,
227
+ children = null,
228
+ itemRender,
229
+ showUploadError = true,
230
+ stash = false,
231
+ uploading = true,
232
+ loading = false,
233
+ showLoading: showLoadingProp = false,
234
+ defaultImage,
235
+ readonly
236
+ } = props,
310
237
  restProps = __rest(props, ["className", "style", "onStart", "onSuccess", "onError", "onProgress", "onRemove", "beforeUpload", "onChange", "defaultFileList", "fileList", "showUploadList", "maxCount", "children", "itemRender", "showUploadError", "stash", "uploading", "loading", "showLoading", "defaultImage", "readonly"]);
311
- var intl = useFormatMessage('Upload', localeJson);
312
- var _useState = useState(defaultFileList),
313
- _useState2 = _slicedToArray(_useState, 2),
314
- uploadFileList = _useState2[0],
315
- setUploadFileList = _useState2[1]; //文件列表
316
- var _useState3 = useState(false),
317
- _useState4 = _slicedToArray(_useState3, 2),
318
- showLoading = _useState4[0],
319
- setShowLoading = _useState4[1]; //upload loading
320
- var _useState5 = useState(false),
321
- _useState6 = _slicedToArray(_useState5, 2),
322
- errTip = _useState6[0],
323
- setErrTip = _useState6[1]; //upload error tip
324
- var _useState7 = useState({
325
- imageUrl: ''
326
- }),
327
- _useState8 = _slicedToArray(_useState7, 2),
328
- avatar = _useState8[0],
329
- setAvatar = _useState8[1]; //不显示列表时上传头像
330
- var _ref = typeof showUploadList === 'boolean' ? {} : showUploadList,
331
- showRemoveIcon = _ref.showRemoveIcon,
332
- removeIcon = _ref.removeIcon; //显示上传列表
333
- var _ref2 = typeof showUploadError === 'boolean' ? {} : showUploadError,
334
- _ref2$uploadErrorMsg = _ref2.uploadErrorMsg,
335
- uploadErrorMsg = _ref2$uploadErrorMsg === void 0 ? intl({
238
+ const intl = useFormatMessage('Upload', localeJson);
239
+ const [uploadFileList, setUploadFileList] = useState(defaultFileList); //文件列表
240
+ const [showLoading, setShowLoading] = useState(false); //upload loading
241
+ const [errTip, setErrTip] = useState(false); //upload error tip
242
+ const [avatar, setAvatar] = useState({
243
+ imageUrl: ''
244
+ }); //不显示列表时上传头像
245
+ const {
246
+ showRemoveIcon,
247
+ removeIcon
248
+ } = typeof showUploadList === 'boolean' ? {} : showUploadList; //显示上传列表
249
+ const {
250
+ uploadErrorMsg = intl({
336
251
  id: 'uploadError'
337
- }) : _ref2$uploadErrorMsg,
338
- _ref2$leaveDelay = _ref2.leaveDelay,
339
- leaveDelay = _ref2$leaveDelay === void 0 ? 2000 : _ref2$leaveDelay; //错误信息提示
340
- var cropFileRef = useRef(); //裁剪文件
341
- useEffect(function () {
252
+ }),
253
+ leaveDelay = 2000
254
+ } = typeof showUploadError === 'boolean' ? {} : showUploadError; //错误信息提示
255
+ const cropFileRef = useRef(); //裁剪文件
256
+ useEffect(() => {
342
257
  setShowLoading(loading);
343
258
  }, [loading]);
344
259
  //复写属性
345
- var overrideProps = Object.assign(Object.assign({
260
+ const overrideProps = Object.assign(Object.assign({
346
261
  accept: 'image/*'
347
262
  }, restProps), {
348
- beforeUpload: function beforeUpload(file, fileList) {
349
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
350
- var result;
351
- return regenerator.wrap(function _callee$(_context) {
352
- while (1) switch (_context.prev = _context.next) {
353
- case 0:
354
- if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
355
- _context.next = 3;
356
- return _beforeUpload === null || _beforeUpload === void 0 ? void 0 : _beforeUpload(file, fileList);
357
- case 3:
358
- result = _context.sent;
359
- if (!(result === false)) {
360
- _context.next = 9;
361
- break;
362
- }
363
- setShowLoading(false);
364
- return _context.abrupt("return", false);
365
- case 9:
366
- if (!(_typeof(result) === 'object' && result)) {
367
- _context.next = 16;
368
- break;
369
- }
370
- if (!(result instanceof File || result instanceof Blob)) {
371
- _context.next = 12;
372
- break;
373
- }
374
- return _context.abrupt("return", result);
375
- case 12:
376
- cropFileRef.current = result.cropFile;
377
- return _context.abrupt("return", result.isUpload);
378
- case 16:
379
- return _context.abrupt("return", true);
380
- case 17:
381
- case "end":
382
- return _context.stop();
383
- }
384
- }, _callee);
385
- }));
386
- },
387
- onStart: function onStart(file) {
388
- _onStart === null || _onStart === void 0 ? void 0 : _onStart(file);
263
+ beforeUpload: (file, fileList) => __awaiter(void 0, void 0, void 0, function* () {
264
+ if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
265
+ const result = yield beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(file, fileList);
266
+ if (result === false) {
267
+ setShowLoading(false);
268
+ return false;
269
+ } else if (typeof result === 'object' && result) {
270
+ if (result instanceof File || result instanceof Blob) return result;
271
+ cropFileRef.current = result.cropFile;
272
+ return result.isUpload;
273
+ } else return true;
274
+ }),
275
+ onStart(file) {
276
+ onStart === null || onStart === void 0 ? void 0 : onStart(file);
389
277
  },
390
- onSuccess: function onSuccess(response, file, xhr) {
278
+ onSuccess(response, file, xhr) {
391
279
  setShowLoading(false);
392
280
  errTip && showErrTip(false);
393
- var nextFileList = updateFileList(file);
281
+ const nextFileList = updateFileList(file);
394
282
  onInternalChange(nextFileList);
395
- _onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(response, file, xhr);
283
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
396
284
  },
397
- onError: function onError(error, response, file) {
285
+ onError(error, response, file) {
398
286
  setShowLoading(false);
399
287
  showErrTip(!!showUploadError);
400
- _onError === null || _onError === void 0 ? void 0 : _onError(error, response, file);
288
+ onError === null || onError === void 0 ? void 0 : onError(error, response, file);
401
289
  },
402
- onProgress: function onProgress(e, file) {
403
- _onProgress === null || _onProgress === void 0 ? void 0 : _onProgress(e, file);
290
+ onProgress(e, file) {
291
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(e, file);
404
292
  },
405
- onBatchStart: function onBatchStart(fileList) {
293
+ onBatchStart(fileList) {
406
294
  if (stash) {
407
295
  if (cropFileRef.current) {
408
- var idx = fileList.findIndex(function (_) {
296
+ const idx = fileList.findIndex(_ => {
409
297
  var _a;
410
298
  return _.file.uid === ((_a = cropFileRef.current) === null || _a === void 0 ? void 0 : _a.uid);
411
299
  });
@@ -416,62 +304,40 @@ var ImageUpload = function ImageUpload(props) {
416
304
  });
417
305
  }
418
306
  }
419
- var arr = fileList.map(function (_) {
420
- return _.parsedFile || _.file;
421
- });
422
- var mList = mergedFileList(arr);
307
+ const arr = fileList.map(_ => _.parsedFile || _.file);
308
+ const mList = mergedFileList(arr);
423
309
  onInternalChange(mList);
424
310
  }
425
311
  }
426
312
  });
427
313
  //内部变化
428
- var onInternalChange = function onInternalChange(changedFileList) {
429
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
430
- var cloneList, file, imageUrl;
431
- return regenerator.wrap(function _callee2$(_context2) {
432
- while (1) switch (_context2.prev = _context2.next) {
433
- case 0:
434
- cloneList = _toConsumableArray(changedFileList);
435
- if (showUploadList) {
436
- _context2.next = 13;
437
- break;
438
- }
439
- //不显示上传列表
440
- file = cloneList.slice(-1)[0];
441
- if (!file) {
442
- _context2.next = 11;
443
- break;
444
- }
445
- _context2.next = 6;
446
- return readerFileAsDataUrl(file);
447
- case 6:
448
- imageUrl = _context2.sent;
449
- file.dataUrl = imageUrl;
450
- avatar.imageUrl = imageUrl;
451
- avatar.imageName = file.name;
452
- setAvatar(Object.assign({}, avatar));
453
- case 11:
454
- onChange === null || onChange === void 0 ? void 0 : onChange([file]);
455
- return _context2.abrupt("return");
456
- case 13:
457
- if (maxCount === 1) {
458
- cloneList = cloneList.slice(-1);
459
- } else if (maxCount) {
460
- cloneList = cloneList.slice(0, maxCount);
461
- }
462
- onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
463
- setUploadFileList(cloneList);
464
- case 16:
465
- case "end":
466
- return _context2.stop();
467
- }
468
- }, _callee2);
469
- }));
470
- };
314
+ const onInternalChange = changedFileList => __awaiter(void 0, void 0, void 0, function* () {
315
+ let cloneList = [...changedFileList];
316
+ if (!showUploadList) {
317
+ //不显示上传列表
318
+ const file = cloneList.slice(-1)[0];
319
+ if (file) {
320
+ const imageUrl = yield readerFileAsDataUrl(file);
321
+ file.dataUrl = imageUrl;
322
+ avatar.imageUrl = imageUrl;
323
+ avatar.imageName = file.name;
324
+ setAvatar(Object.assign({}, avatar));
325
+ }
326
+ onChange === null || onChange === void 0 ? void 0 : onChange([file]);
327
+ return;
328
+ }
329
+ if (maxCount === 1) {
330
+ cloneList = cloneList.slice(-1);
331
+ } else if (maxCount) {
332
+ cloneList = cloneList.slice(0, maxCount);
333
+ }
334
+ onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
335
+ setUploadFileList(cloneList);
336
+ });
471
337
  //更新文件列表
472
- var updateFileList = function updateFileList(file) {
473
- var cloneList = _toConsumableArray(uploadFileList);
474
- var fileObj = Object.assign(Object.assign({}, file), {
338
+ const updateFileList = file => {
339
+ const cloneList = [...uploadFileList];
340
+ const fileObj = Object.assign(Object.assign({}, file), {
475
341
  lastModified: file.lastModified,
476
342
  lastModifiedDate: file.lastModifiedDate,
477
343
  name: file.name,
@@ -483,9 +349,9 @@ var ImageUpload = function ImageUpload(props) {
483
349
  return cloneList.concat(fileObj);
484
350
  };
485
351
  //合并文件列表
486
- var mergedFileList = function mergedFileList(fileList) {
487
- var cloneList = _toConsumableArray(uploadFileList);
488
- var newFileList = fileList.map(function (file) {
352
+ const mergedFileList = fileList => {
353
+ const cloneList = [...uploadFileList];
354
+ const newFileList = fileList.map(file => {
489
355
  return Object.assign(Object.assign({}, file), {
490
356
  lastModified: file.lastModified,
491
357
  lastModifiedDate: file.lastModifiedDate,
@@ -499,71 +365,57 @@ var ImageUpload = function ImageUpload(props) {
499
365
  return cloneList.concat(newFileList);
500
366
  };
501
367
  //删除文件
502
- var handleRemove = function handleRemove(file) {
503
- Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(function (ret) {
368
+ const handleRemove = file => {
369
+ Promise.resolve(typeof onRemove === 'function' ? onRemove(file) : onRemove).then(ret => {
504
370
  // Prevent removing file
505
371
  if (ret === false) return;
506
- var idx = uploadFileList.findIndex(function (_) {
507
- return _.uid === file.uid;
508
- });
372
+ const idx = uploadFileList.findIndex(_ => _.uid === file.uid);
509
373
  if (idx > -1) uploadFileList.splice(idx, 1);
510
374
  onInternalChange(uploadFileList);
511
375
  });
512
376
  };
513
377
  //读取dataUrl
514
- var readerFileAsDataUrl = function readerFileAsDataUrl(file) {
515
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
516
- return regenerator.wrap(function _callee3$(_context3) {
517
- while (1) switch (_context3.prev = _context3.next) {
518
- case 0:
519
- return _context3.abrupt("return", new Promise(function (resolve) {
520
- var fileReader = new FileReader();
521
- if (file.originFileObj) {
522
- fileReader.onload = function () {
523
- resolve(fileReader.result);
524
- };
525
- fileReader.readAsDataURL(file.originFileObj);
526
- } else resolve('');
527
- }));
528
- case 1:
529
- case "end":
530
- return _context3.stop();
531
- }
532
- }, _callee3);
533
- }));
534
- };
378
+ const readerFileAsDataUrl = file => __awaiter(void 0, void 0, void 0, function* () {
379
+ return new Promise(resolve => {
380
+ const fileReader = new FileReader();
381
+ if (file.originFileObj) {
382
+ fileReader.onload = () => {
383
+ resolve(fileReader.result);
384
+ };
385
+ fileReader.readAsDataURL(file.originFileObj);
386
+ } else resolve('');
387
+ });
388
+ });
535
389
  //显示错误提示
536
- var showErrTip = function showErrTip(flag) {
390
+ const showErrTip = flag => {
537
391
  setErrTip(flag);
538
392
  if (leaveDelay < 0) return;
539
- setTimeout(function () {
393
+ setTimeout(() => {
540
394
  setErrTip(false);
541
395
  }, leaveDelay);
542
396
  };
543
- useEffect(function () {
397
+ useEffect(() => {
544
398
  if (fileList) {
545
- setUploadFileList(_toConsumableArray(fileList));
399
+ setUploadFileList([...fileList]);
546
400
  }
547
401
  }, [fileList]);
548
- useEffect(function () {
402
+ useEffect(() => {
549
403
  if (defaultImage) {
550
404
  setAvatar(Object.assign({}, defaultImage));
551
405
  }
552
406
  }, [defaultImage]);
553
407
  //渲染上传列表
554
- var renderUploadList = function renderUploadList() {
555
- return showUploadList && jsx(UploadList, {
556
- listType: 'picture-card',
557
- readonly: readonly,
558
- items: uploadFileList,
559
- showRemoveIcon: showRemoveIcon,
560
- removeIcon: removeIcon,
561
- onRemove: handleRemove,
562
- itemRender: itemRender
563
- });
564
- };
408
+ const renderUploadList = () => showUploadList && jsx(UploadList, {
409
+ listType: 'picture-card',
410
+ readonly: readonly,
411
+ items: uploadFileList,
412
+ showRemoveIcon: showRemoveIcon,
413
+ removeIcon: removeIcon,
414
+ onRemove: handleRemove,
415
+ itemRender: itemRender
416
+ });
565
417
  //渲染内容
566
- var renderUploadContent = function renderUploadContent() {
418
+ const renderUploadContent = () => {
567
419
  var _a;
568
420
  if (!showUploadList && avatar.imageUrl && !showLoading) {
569
421
  return jsxs("div", Object.assign({
@@ -598,7 +450,7 @@ var ImageUpload = function ImageUpload(props) {
598
450
  });
599
451
  };
600
452
  //渲染上传控件
601
- var renderUploadSelector = function renderUploadSelector() {
453
+ const renderUploadSelector = () => {
602
454
  if (readonly) return null;
603
455
  return jsxs("div", Object.assign({
604
456
  className: clsx('upload-image-select', showLoading && 'upload-image-select-loading')
@@ -626,7 +478,7 @@ var ImageUpload = function ImageUpload(props) {
626
478
  };
627
479
 
628
480
  //Dragger upload
629
- var Dragger = function Dragger(props) {
481
+ const Dragger = props => {
630
482
  return jsx(Upload, Object.assign({}, props, {
631
483
  type: 'drag'
632
484
  }));
@@ -791,336 +643,266 @@ var css_248z$1 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/4/20
791
643
  styleInject(css_248z$1);
792
644
 
793
645
  //图片裁剪组件
794
- var ImgCrop = /*#__PURE__*/forwardRef(function (props, ref) {
795
- var _props$aspect = props.aspect,
796
- aspect = _props$aspect === void 0 ? 1 : _props$aspect,
797
- _props$shape = props.shape,
798
- shape = _props$shape === void 0 ? 'rect' : _props$shape,
799
- _props$grid = props.grid,
800
- grid = _props$grid === void 0 ? false : _props$grid,
801
- _props$quality = props.quality,
802
- quality = _props$quality === void 0 ? 0.4 : _props$quality,
803
- _props$fillColor = props.fillColor,
804
- fillColor = _props$fillColor === void 0 ? 'transparent' : _props$fillColor,
805
- _props$zoom = props.zoom,
806
- zoom = _props$zoom === void 0 ? true : _props$zoom,
807
- _props$rotate = props.rotate,
808
- rotate = _props$rotate === void 0 ? false : _props$rotate,
809
- _props$minZoom = props.minZoom,
810
- minZoom = _props$minZoom === void 0 ? 1 : _props$minZoom,
811
- _props$maxZoom = props.maxZoom,
812
- maxZoom = _props$maxZoom === void 0 ? 3 : _props$maxZoom,
813
- modalTitle = props.modalTitle,
814
- modalWidth = props.modalWidth,
815
- modalOk = props.modalOk,
816
- modalCancel = props.modalCancel,
817
- onModalOk = props.onModalOk,
818
- onModalCancel = props.onModalCancel,
819
- beforeCrop = props.beforeCrop,
820
- onUploadFail = props.onUploadFail,
821
- cropperProps = props.cropperProps,
822
- children = props.children,
823
- _props$fixedCropSize = props.fixedCropSize,
824
- fixedCropSize = _props$fixedCropSize === void 0 ? {
646
+ const ImgCrop = /*#__PURE__*/forwardRef((props, ref) => {
647
+ const {
648
+ aspect = 1,
649
+ shape = 'rect',
650
+ grid = false,
651
+ quality = 0.4,
652
+ fillColor = 'transparent',
653
+ zoom = true,
654
+ rotate = false,
655
+ minZoom = 1,
656
+ maxZoom = 3,
657
+ modalTitle,
658
+ modalWidth,
659
+ modalOk,
660
+ modalCancel,
661
+ onModalOk,
662
+ onModalCancel,
663
+ beforeCrop,
664
+ onUploadFail,
665
+ cropperProps,
666
+ children,
667
+ fixedCropSize = {
825
668
  width: 120,
826
669
  height: 120
827
- } : _props$fixedCropSize;
828
- var intl = useFormatMessage('Upload', localeJson);
829
- var _useState = useState(''),
830
- _useState2 = _slicedToArray(_useState, 2),
831
- image = _useState2[0],
832
- setImage = _useState2[1];
833
- var fileRef = useRef();
834
- var beforeUploadRef = useRef();
835
- var resolveRef = useRef();
836
- var rejectRef = useRef();
670
+ }
671
+ } = props;
672
+ const intl = useFormatMessage('Upload', localeJson);
673
+ const [image, setImage] = useState('');
674
+ const fileRef = useRef();
675
+ const beforeUploadRef = useRef();
676
+ const resolveRef = useRef();
677
+ const rejectRef = useRef();
837
678
  //存储回调
838
- var cbRef = useRef({});
679
+ const cbRef = useRef({});
839
680
  cbRef.current.onModalOk = onModalOk;
840
681
  cbRef.current.onModalCancel = onModalCancel;
841
682
  cbRef.current.beforeCrop = beforeCrop;
842
683
  cbRef.current.onUploadFail = onUploadFail;
843
- var easyCropRef = useRef({});
684
+ const easyCropRef = useRef({});
844
685
  //上传组件
845
- var uploadComponent = useMemo(function () {
846
- var upload = Array.isArray(children) ? children[0] : children;
847
- var _a = upload.props,
848
- beforeUpload = _a.beforeUpload,
849
- accept = _a.accept,
686
+ const uploadComponent = useMemo(() => {
687
+ const upload = Array.isArray(children) ? children[0] : children;
688
+ const _a = upload.props,
689
+ {
690
+ beforeUpload,
691
+ accept
692
+ } = _a,
850
693
  restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
851
694
  beforeUploadRef.current = beforeUpload;
852
695
  return Object.assign(Object.assign({}, upload), {
853
696
  props: Object.assign(Object.assign({}, restUploadProps), {
854
697
  accept: accept || 'image/*',
855
- beforeUpload: function beforeUpload(file, fileList) {
856
- return new Promise(function (resolve, reject) {
857
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
858
- var reader;
859
- return regenerator.wrap(function _callee$(_context) {
860
- while (1) switch (_context.prev = _context.next) {
861
- case 0:
862
- _context.t0 = cbRef.current.beforeCrop;
863
- if (!_context.t0) {
864
- _context.next = 5;
865
- break;
866
- }
867
- _context.next = 4;
868
- return cbRef.current.beforeCrop(file, fileList);
869
- case 4:
870
- _context.t0 = !_context.sent;
871
- case 5:
872
- if (!_context.t0) {
873
- _context.next = 8;
874
- break;
875
- }
876
- reject();
877
- return _context.abrupt("return");
878
- case 8:
879
- fileRef.current = file;
880
- resolveRef.current = function (newFile) {
881
- var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
882
- var _a, _b;
883
- (_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
884
- if (!flag) return resolve({
885
- cropFile: newFile,
886
- isUpload: flag
887
- });
888
- resolve(newFile);
889
- };
890
- rejectRef.current = function (uploadErr) {
891
- var _a, _b;
892
- (_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
893
- reject(uploadErr);
894
- };
895
- reader = new FileReader();
896
- reader.addEventListener('load', function () {
897
- return typeof reader.result === 'string' && setImage(reader.result);
898
- });
899
- reader.readAsDataURL(file);
900
- case 14:
901
- case "end":
902
- return _context.stop();
903
- }
904
- }, _callee);
905
- }));
906
- });
698
+ beforeUpload: (file, fileList) => {
699
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
700
+ if (cbRef.current.beforeCrop && !(yield cbRef.current.beforeCrop(file, fileList))) {
701
+ reject();
702
+ return;
703
+ }
704
+ fileRef.current = file;
705
+ resolveRef.current = function (newFile) {
706
+ let flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
707
+ var _a, _b;
708
+ (_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
709
+ if (!flag) return resolve({
710
+ cropFile: newFile,
711
+ isUpload: flag
712
+ });
713
+ resolve(newFile);
714
+ };
715
+ rejectRef.current = uploadErr => {
716
+ var _a, _b;
717
+ (_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
718
+ reject(uploadErr);
719
+ };
720
+ const reader = new FileReader();
721
+ reader.addEventListener('load', () => typeof reader.result === 'string' && setImage(reader.result));
722
+ reader.readAsDataURL(file);
723
+ }));
907
724
  }
908
725
  })
909
726
  });
910
727
  }, [children]);
911
728
  //modal 关闭后操作
912
- var onClose = function onClose() {
729
+ const onClose = () => {
913
730
  setImage('');
914
731
  easyCropRef.current.setZoomVal(INIT_ZOOM);
915
732
  easyCropRef.current.setRotateVal(INIT_ROTATE);
916
733
  };
917
734
  //modal cancel
918
- var onCancel = useCallback(function () {
735
+ const onCancel = useCallback(() => {
919
736
  var _a, _b;
920
737
  (_b = (_a = cbRef.current).onModalCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
921
738
  onClose();
922
739
  }, []);
923
740
  //modal ok
924
- var onOk = useCallback(function () {
925
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
926
- var canvas, ctx, imgSource, _easyCropRef$current$, cropWidth, cropHeight, cropX, cropY, imgWidth, imgHeight, angle, sine, cosine, squareWidth, squareHeight, squareHalfWidth, squareHalfHeight, imgX, imgY, imgData, changeImageSizeAfterCrop, _fileRef$current, type, name, uid, idx, onBlob;
927
- return regenerator.wrap(function _callee3$(_context3) {
928
- while (1) switch (_context3.prev = _context3.next) {
929
- case 0:
930
- onClose();
931
- canvas = document.createElement('canvas');
932
- ctx = canvas.getContext('2d');
933
- imgSource = document.querySelector(".".concat(PREFIX, "-media"));
934
- _easyCropRef$current$ = easyCropRef.current.cropPixelsRef.current, cropWidth = _easyCropRef$current$.width, cropHeight = _easyCropRef$current$.height, cropX = _easyCropRef$current$.x, cropY = _easyCropRef$current$.y;
935
- if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
936
- imgWidth = imgSource.naturalWidth, imgHeight = imgSource.naturalHeight;
937
- angle = easyCropRef.current.rotateVal * (Math.PI / 180); // get container for rotated image
938
- sine = Math.abs(Math.sin(angle));
939
- cosine = Math.abs(Math.cos(angle));
940
- squareWidth = imgWidth * cosine + imgHeight * sine;
941
- squareHeight = imgHeight * cosine + imgWidth * sine;
942
- canvas.width = squareWidth;
943
- canvas.height = squareHeight;
944
- ctx.fillStyle = fillColor;
945
- ctx.fillRect(0, 0, squareWidth, squareHeight);
946
- // rotate container
947
- squareHalfWidth = squareWidth / 2;
948
- squareHalfHeight = squareHeight / 2;
949
- ctx.translate(squareHalfWidth, squareHalfHeight);
950
- ctx.rotate(angle);
951
- ctx.translate(-squareHalfWidth, -squareHalfHeight);
952
- // draw rotated image
953
- imgX = (squareWidth - imgWidth) / 2;
954
- imgY = (squareHeight - imgHeight) / 2;
955
- ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
956
- // crop rotated image
957
- imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
958
- canvas.width = cropWidth;
959
- canvas.height = cropHeight;
960
- ctx.putImageData(imgData, -cropX, -cropY);
961
- } else {
962
- canvas.width = cropWidth;
963
- canvas.height = cropHeight;
964
- ctx.fillStyle = fillColor;
965
- ctx.fillRect(0, 0, cropWidth, cropHeight);
966
- ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
967
- }
968
- //裁剪之后改变图片大小
969
- changeImageSizeAfterCrop = function changeImageSizeAfterCrop(newFile) {
970
- return new Promise(function (resolve) {
971
- var name = newFile.name,
972
- type = newFile.type,
973
- uid = newFile.uid;
974
- var width = fixedCropSize.width,
975
- height = fixedCropSize.height; //固定裁剪大小
976
- var changeCanvas = document.createElement('canvas');
977
- var changeCtx = changeCanvas.getContext('2d');
978
- var img = new Image();
979
- img.onload = function () {
980
- changeCanvas.width = width;
981
- changeCanvas.height = height;
982
- changeCtx.drawImage(img, 0, 0, width, height);
983
- changeCanvas.toBlob(function (cBlob) {
984
- var changeFile = Object.assign(new File([cBlob], name, {
985
- type: type
986
- }), {
987
- uid: uid
988
- });
989
- resolve(changeFile);
990
- }, type, quality);
991
- };
992
- img.onerror = function () {
993
- resolve(newFile);
994
- };
995
- var fileReader = new FileReader();
996
- fileReader.onload = function () {
997
- img.src = fileReader.result;
998
- };
999
- fileReader.onerror = function () {
1000
- resolve(newFile);
1001
- };
1002
- fileReader.readAsDataURL(newFile);
1003
- });
1004
- }; // get the new image
1005
- _fileRef$current = fileRef.current, type = _fileRef$current.type, name = _fileRef$current.name, uid = _fileRef$current.uid;
1006
- if (/svg/gi.test(type)) {
1007
- //svg 转为 png
1008
- type = 'image/png';
1009
- idx = name.lastIndexOf('.');
1010
- if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
1011
- }
1012
- //转为blob
1013
- onBlob = function onBlob(blob) {
1014
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1015
- var _a, _b, _c, _d, _e, _f, newFile, changeFile, res, passedFile;
1016
- return regenerator.wrap(function _callee2$(_context2) {
1017
- while (1) switch (_context2.prev = _context2.next) {
1018
- case 0:
1019
- newFile = Object.assign(new File([blob], name, {
1020
- type: type
1021
- }), {
1022
- uid: uid
1023
- });
1024
- _context2.next = 3;
1025
- return changeImageSizeAfterCrop(newFile);
1026
- case 3:
1027
- changeFile = _context2.sent;
1028
- if (!(typeof beforeUploadRef.current !== 'function')) {
1029
- _context2.next = 6;
1030
- break;
1031
- }
1032
- return _context2.abrupt("return", (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile));
1033
- case 6:
1034
- res = beforeUploadRef.current(changeFile, [changeFile]);
1035
- if (!(typeof res !== 'boolean' && !res)) {
1036
- _context2.next = 10;
1037
- break;
1038
- }
1039
- console.error('beforeUpload must return a boolean or Promise');
1040
- return _context2.abrupt("return");
1041
- case 10:
1042
- if (!(res === true)) {
1043
- _context2.next = 12;
1044
- break;
1045
- }
1046
- return _context2.abrupt("return", (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile));
1047
- case 12:
1048
- if (!(res === false)) {
1049
- _context2.next = 14;
1050
- break;
1051
- }
1052
- return _context2.abrupt("return", (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false));
1053
- case 14:
1054
- if (!(res && res instanceof Promise)) {
1055
- _context2.next = 27;
1056
- break;
1057
- }
1058
- _context2.prev = 15;
1059
- _context2.next = 18;
1060
- return res;
1061
- case 18:
1062
- passedFile = _context2.sent;
1063
- if (!(passedFile instanceof File || passedFile instanceof Blob)) {
1064
- _context2.next = 21;
1065
- break;
1066
- }
1067
- return _context2.abrupt("return", (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile));
1068
- case 21:
1069
- (_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
1070
- _context2.next = 27;
1071
- break;
1072
- case 24:
1073
- _context2.prev = 24;
1074
- _context2.t0 = _context2["catch"](15);
1075
- (_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, _context2.t0);
1076
- case 27:
1077
- case "end":
1078
- return _context2.stop();
1079
- }
1080
- }, _callee2, null, [[15, 24]]);
1081
- }));
1082
- };
1083
- canvas.toBlob(onBlob, type, quality);
1084
- case 11:
1085
- case "end":
1086
- return _context3.stop();
741
+ const onOk = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
742
+ onClose();
743
+ const canvas = document.createElement('canvas');
744
+ const ctx = canvas.getContext('2d');
745
+ const imgSource = document.querySelector(".".concat(PREFIX, "-media"));
746
+ const {
747
+ width: cropWidth,
748
+ height: cropHeight,
749
+ x: cropX,
750
+ y: cropY
751
+ } = easyCropRef.current.cropPixelsRef.current;
752
+ if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
753
+ const {
754
+ naturalWidth: imgWidth,
755
+ naturalHeight: imgHeight
756
+ } = imgSource;
757
+ const angle = easyCropRef.current.rotateVal * (Math.PI / 180);
758
+ // get container for rotated image
759
+ const sine = Math.abs(Math.sin(angle));
760
+ const cosine = Math.abs(Math.cos(angle));
761
+ const squareWidth = imgWidth * cosine + imgHeight * sine;
762
+ const squareHeight = imgHeight * cosine + imgWidth * sine;
763
+ canvas.width = squareWidth;
764
+ canvas.height = squareHeight;
765
+ ctx.fillStyle = fillColor;
766
+ ctx.fillRect(0, 0, squareWidth, squareHeight);
767
+ // rotate container
768
+ const squareHalfWidth = squareWidth / 2;
769
+ const squareHalfHeight = squareHeight / 2;
770
+ ctx.translate(squareHalfWidth, squareHalfHeight);
771
+ ctx.rotate(angle);
772
+ ctx.translate(-squareHalfWidth, -squareHalfHeight);
773
+ // draw rotated image
774
+ const imgX = (squareWidth - imgWidth) / 2;
775
+ const imgY = (squareHeight - imgHeight) / 2;
776
+ ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
777
+ // crop rotated image
778
+ const imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
779
+ canvas.width = cropWidth;
780
+ canvas.height = cropHeight;
781
+ ctx.putImageData(imgData, -cropX, -cropY);
782
+ } else {
783
+ canvas.width = cropWidth;
784
+ canvas.height = cropHeight;
785
+ ctx.fillStyle = fillColor;
786
+ ctx.fillRect(0, 0, cropWidth, cropHeight);
787
+ ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
788
+ }
789
+ //裁剪之后改变图片大小
790
+ const changeImageSizeAfterCrop = newFile => {
791
+ return new Promise(resolve => {
792
+ const {
793
+ name,
794
+ type,
795
+ uid
796
+ } = newFile;
797
+ const {
798
+ width,
799
+ height
800
+ } = fixedCropSize; //固定裁剪大小
801
+ const changeCanvas = document.createElement('canvas');
802
+ const changeCtx = changeCanvas.getContext('2d');
803
+ const img = new Image();
804
+ img.onload = () => {
805
+ changeCanvas.width = width;
806
+ changeCanvas.height = height;
807
+ changeCtx.drawImage(img, 0, 0, width, height);
808
+ changeCanvas.toBlob(cBlob => {
809
+ const changeFile = Object.assign(new File([cBlob], name, {
810
+ type
811
+ }), {
812
+ uid
813
+ });
814
+ resolve(changeFile);
815
+ }, type, quality);
816
+ };
817
+ img.onerror = () => {
818
+ resolve(newFile);
819
+ };
820
+ const fileReader = new FileReader();
821
+ fileReader.onload = () => {
822
+ img.src = fileReader.result;
823
+ };
824
+ fileReader.onerror = () => {
825
+ resolve(newFile);
826
+ };
827
+ fileReader.readAsDataURL(newFile);
828
+ });
829
+ };
830
+ // get the new image
831
+ let {
832
+ type,
833
+ name,
834
+ uid
835
+ } = fileRef.current;
836
+ if (/svg/gi.test(type)) {
837
+ //svg 转为 png
838
+ type = 'image/png';
839
+ const idx = name.lastIndexOf('.');
840
+ if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
841
+ }
842
+ //转为blob
843
+ const onBlob = blob => __awaiter(void 0, void 0, void 0, function* () {
844
+ var _a, _b, _c, _d, _e, _f;
845
+ const newFile = Object.assign(new File([blob], name, {
846
+ type
847
+ }), {
848
+ uid
849
+ });
850
+ const changeFile = yield changeImageSizeAfterCrop(newFile);
851
+ if (typeof beforeUploadRef.current !== 'function') {
852
+ return (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile);
853
+ }
854
+ const res = beforeUploadRef.current(changeFile, [changeFile]);
855
+ if (typeof res !== 'boolean' && !res) {
856
+ console.error('beforeUpload must return a boolean or Promise');
857
+ return;
858
+ }
859
+ if (res === true) return (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile);
860
+ if (res === false) return (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false);
861
+ if (res && res instanceof Promise) {
862
+ try {
863
+ const passedFile = yield res;
864
+ if (passedFile instanceof File || passedFile instanceof Blob) {
865
+ return (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile);
866
+ }
867
+ (_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
868
+ } catch (err) {
869
+ (_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, err);
1087
870
  }
1088
- }, _callee3);
1089
- }));
1090
- }, [fillColor, quality, rotate]);
1091
- //img crop 组件
1092
- var getComponent = function getComponent(titleOfModal) {
1093
- return jsxs(Fragment, {
1094
- children: [uploadComponent, image && jsx(Modal, Object.assign({
1095
- open: true,
1096
- className: "".concat(PREFIX, "-modal"),
1097
- size: 'md',
1098
- title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
1099
- id: 'editImage'
1100
- }),
1101
- onOk: onOk,
1102
- onCancel: onCancel,
1103
- okText: modalOk,
1104
- cancelText: modalCancel,
1105
- contentWidth: modalWidth
1106
- }, {
1107
- children: jsx(EasyCrop$1, {
1108
- ref: easyCropRef,
1109
- cropperRef: ref,
1110
- image: image,
1111
- aspect: aspect,
1112
- shape: shape,
1113
- grid: grid,
1114
- zoom: zoom,
1115
- rotate: rotate,
1116
- minZoom: minZoom,
1117
- maxZoom: maxZoom,
1118
- fixedCropSize: fixedCropSize,
1119
- cropperProps: cropperProps
1120
- })
1121
- }))]
871
+ }
1122
872
  });
1123
- };
873
+ canvas.toBlob(onBlob, type, quality);
874
+ }), [fillColor, quality, rotate]);
875
+ //img crop 组件
876
+ const getComponent = titleOfModal => jsxs(Fragment, {
877
+ children: [uploadComponent, image && jsx(Modal, Object.assign({
878
+ open: true,
879
+ className: "".concat(PREFIX, "-modal"),
880
+ size: 'md',
881
+ title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
882
+ id: 'editImage'
883
+ }),
884
+ onOk: onOk,
885
+ onCancel: onCancel,
886
+ okText: modalOk,
887
+ cancelText: modalCancel,
888
+ contentWidth: modalWidth
889
+ }, {
890
+ children: jsx(EasyCrop$1, {
891
+ ref: easyCropRef,
892
+ cropperRef: ref,
893
+ image: image,
894
+ aspect: aspect,
895
+ shape: shape,
896
+ grid: grid,
897
+ zoom: zoom,
898
+ rotate: rotate,
899
+ minZoom: minZoom,
900
+ maxZoom: maxZoom,
901
+ fixedCropSize: fixedCropSize,
902
+ cropperProps: cropperProps
903
+ })
904
+ }))]
905
+ });
1124
906
  return jsx(Fragment, {
1125
907
  children: getComponent(modalTitle)
1126
908
  });