@para-ui/core 4.0.0-rc.7 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/Button/index.js +1 -1
  2. package/ButtonGroup/index.js +1 -1
  3. package/Cascader/index.js +4 -5
  4. package/ComboSelect/index.js +14 -16
  5. package/ComboSelect/lang/en_US.d.ts +1 -0
  6. package/ComboSelect/lang/index.d.ts +2 -0
  7. package/ComboSelect/lang/zh_CN.d.ts +1 -0
  8. package/CopyText/index.js +8 -6
  9. package/DatePicker/index.js +2 -4
  10. package/Descriptions/index.js +1 -1
  11. package/Desktop/index.js +1 -1
  12. package/Drawer/index.js +1 -1
  13. package/Dropdown/index.js +1 -1
  14. package/DynamicMultiBox/index.js +6 -9
  15. package/Form/index.js +5 -9
  16. package/FormItem/index.js +5 -9
  17. package/FunctionModal/index.js +3 -3
  18. package/InputLang/index.js +1 -1
  19. package/Modal/index.js +1 -1
  20. package/MultiBox/index.js +1 -1
  21. package/OperateBtn/index.js +1 -1
  22. package/PageHeader/index.js +1 -1
  23. package/Pagination/index.js +1 -1
  24. package/PopConfirm/index.js +2 -2
  25. package/Popover/index.js +1 -1
  26. package/QuickReply/index.js +2 -2
  27. package/README.md +6 -105
  28. package/Search/index.d.ts +1 -1
  29. package/Search/index.js +5 -3
  30. package/Select/index.js +3 -2
  31. package/SelectInput/index.js +2 -2
  32. package/Selector/index.js +328 -5
  33. package/SelectorPicker/index.js +3 -4
  34. package/SingleBox/index.js +1 -1
  35. package/Switch/index.js +8 -8
  36. package/Table/index.js +411 -473
  37. package/Tabs/index.js +3 -3
  38. package/Tag/index.js +53 -82
  39. package/TextEditor/index.js +3 -3
  40. package/TextField/index.js +2 -2
  41. package/TimePicker/index.js +2 -4
  42. package/Timeline/index.js +20 -14
  43. package/ToggleButton/index.js +27 -26
  44. package/Tooltip/index.js +27 -26
  45. package/Transfer/index.js +45 -50
  46. package/Tree/index.js +4 -8
  47. package/Upload/index.js +409 -626
  48. package/_verture/{index-f518e244.js → index-00dc302a.js} +1 -1
  49. package/_verture/{index-da9097d3.js → index-389675ab.js} +1 -1
  50. package/_verture/{index-466a3496.js → index-9784b09c.js} +18 -3
  51. package/_verture/{index-3156e3ef.js → index-e3011376.js} +312 -394
  52. package/_verture/{slicedToArray-75fa4188.js → slicedToArray-8223a2ef.js} +1 -1
  53. package/index.js +8 -10
  54. package/locale/en-US.d.ts +1 -0
  55. package/locale/index.d.ts +2 -0
  56. package/locale/index.js +4 -2
  57. package/locale/zh-CN.d.ts +1 -0
  58. package/package.json +3 -2
  59. package/umd/AutoBox.js +1 -1
  60. package/umd/Breadcrumbs.js +1 -1
  61. package/umd/Button.js +1 -1
  62. package/umd/ButtonGroup.js +1 -1
  63. package/umd/ComboSelect.js +2 -2
  64. package/umd/CopyText.js +2 -2
  65. package/umd/DatePicker.js +1 -1
  66. package/umd/Descriptions.js +1 -1
  67. package/umd/Desktop.js +1 -1
  68. package/umd/Drawer.js +1 -1
  69. package/umd/Dropdown.js +1 -1
  70. package/umd/DynamicMultiBox.js +2 -2
  71. package/umd/Form.js +4 -4
  72. package/umd/FormItem.js +2 -2
  73. package/umd/FunctionModal.js +1 -1
  74. package/umd/InputLang.js +1 -1
  75. package/umd/Modal.js +1 -1
  76. package/umd/MultiBox.js +1 -1
  77. package/umd/OperateBtn.js +1 -1
  78. package/umd/PageHeader.js +1 -1
  79. package/umd/Pagination.js +2 -2
  80. package/umd/PopConfirm.js +1 -1
  81. package/umd/Popover.js +1 -1
  82. package/umd/QuickReply.js +1 -1
  83. package/umd/Search.js +2 -2
  84. package/umd/Select.js +2 -2
  85. package/umd/SelectInput.js +2 -2
  86. package/umd/Selector.js +2 -2
  87. package/umd/SelectorPicker.js +2 -2
  88. package/umd/SingleBox.js +1 -1
  89. package/umd/Switch.js +1 -1
  90. package/umd/Table.js +2 -2
  91. package/umd/Tabs.js +1 -1
  92. package/umd/TextField.js +1 -1
  93. package/umd/TimePicker.js +1 -1
  94. package/umd/ToggleButton.js +1 -1
  95. package/umd/Transfer.js +2 -2
  96. package/umd/Upload.js +1 -1
  97. package/umd/locale.js +1 -1
  98. package/_verture/index-d63bd287.js +0 -327
  99. package/_verture/toConsumableArray-c7a8028f.js +0 -19
  100. /package/_verture/{index-d6093d1c.js → index-28a6bc3a.js} +0 -0
  101. /package/_verture/{modalContext-7b512b0c.js → modalContext-ea977824.js} +0 -0
  102. /package/_verture/{typeof-b240b062.js → typeof-c310ee4a.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-c7a8028f.js';
8
- import { _ as _typeof } from '../_verture/typeof-adeedc13.js';
9
- import { _ as _slicedToArray } from '../_verture/slicedToArray-75fa4188.js';
10
- import { r as regenerator } from '../_verture/index-d63bd287.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';
@@ -18,17 +14,17 @@ import Forbid from '@para-ui/icons/Forbid';
18
14
  import { u as useFormatMessage } from '../_verture/useFormatMessage-eb13cf56.js';
19
15
  import EditOutline from '@para-ui/icons/EditOutline';
20
16
  import { Button } from '../Button/index.js';
17
+ import { b as _slicedToArray } from '../_verture/slicedToArray-8223a2ef.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/typeof-b240b062.js';
25
21
  import '@para-ui/core/GlobalContext';
26
22
  import '@para-ui/icons/LoadingF';
27
23
  import '../Tooltip/index.js';
28
24
  import 'rc-tooltip';
29
25
  import 'rc-tooltip/lib/placements';
30
26
  import '@para-ui/icons/Down';
31
- import '../_verture/index-da9097d3.js';
27
+ import '../_verture/index-389675ab.js';
32
28
  import 'rc-dropdown';
33
29
  import '../_verture/usePopupContainer-635f66f4.js';
34
30
  import 'dayjs';
@@ -43,53 +39,44 @@ import '@para-ui/icons/CheckCircleF';
43
39
  import '@para-ui/icons/WarningCircleF';
44
40
  import '@para-ui/icons/CloseCircleF';
45
41
 
46
- 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 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}\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}";
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}";
47
43
  styleInject(css_248z$4);
48
44
 
49
- 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; } } }; }
50
- 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); }
51
- 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; }
52
45
  //UploadList
53
- var UploadList = function UploadList(props) {
54
- var _props$listType = props.listType,
55
- listType = _props$listType === void 0 ? 'text' : _props$listType,
56
- _props$items = props.items,
57
- items = _props$items === void 0 ? [] : _props$items,
58
- onRemove = props.onRemove,
59
- _props$showRemoveIcon = props.showRemoveIcon,
60
- showRemoveIcon = _props$showRemoveIcon === void 0 ? true : _props$showRemoveIcon,
61
- removeIcon = props.removeIcon,
62
- itemRender = props.itemRender,
63
- readonly = props.readonly;
64
- var _useState = useState([]),
65
- _useState2 = _slicedToArray(_useState, 2),
66
- uploadList = _useState2[0],
67
- 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([]);
68
57
  //处理删除
69
- var handleRemove = function handleRemove(file, evt) {
58
+ const handleRemove = (file, evt) => {
70
59
  evt.stopPropagation();
71
60
  onRemove === null || onRemove === void 0 ? void 0 : onRemove(file);
72
61
  };
73
62
  //渲染列表actions
74
- var renderActions = function renderActions(file) {
63
+ const renderActions = file => {
75
64
  return showRemoveIcon && !readonly && jsx("span", Object.assign({
76
65
  className: 'upload-list-actions',
77
- onClick: function onClick(evt) {
78
- return handleRemove(file, evt);
79
- }
66
+ onClick: evt => handleRemove(file, evt)
80
67
  }, {
81
68
  children: removeIcon || jsx(Delete, {})
82
69
  }));
83
70
  };
84
71
  //文件列表 text
85
- var renderFileListText = function renderFileListText() {
72
+ const renderFileListText = () => {
86
73
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
87
- return uploadList.map(function (file, idx) {
74
+ return uploadList.map((file, idx) => {
88
75
  var _a;
89
76
  if (itemRender)
90
77
  //自定义渲染
91
78
  return itemRender(file, uploadList);
92
- 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/'));
93
80
  return jsx("div", Object.assign({
94
81
  className: 'upload-list-item'
95
82
  }, {
@@ -114,9 +101,9 @@ var UploadList = function UploadList(props) {
114
101
  });
115
102
  };
116
103
  //文件列表 picture-card
117
- var renderFileListPicture = function renderFileListPicture() {
104
+ const renderFileListPicture = () => {
118
105
  if (!(uploadList === null || uploadList === void 0 ? void 0 : uploadList.length)) return null;
119
- return uploadList.map(function (file, idx) {
106
+ return uploadList.map((file, idx) => {
120
107
  if (itemRender)
121
108
  //自定义渲染
122
109
  return itemRender(file, uploadList);
@@ -136,84 +123,31 @@ var UploadList = function UploadList(props) {
136
123
  });
137
124
  };
138
125
  //处理文件
139
- var handleFileFormat = function handleFileFormat() {
140
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
141
- var readerFileAsDataUrl, _iterator, _step, file, dataUrl;
142
- return regenerator.wrap(function _callee2$(_context2) {
143
- while (1) switch (_context2.prev = _context2.next) {
144
- case 0:
145
- if (items === null || items === void 0 ? void 0 : items.length) {
146
- _context2.next = 2;
147
- break;
148
- }
149
- return _context2.abrupt("return", setUploadList([]));
150
- case 2:
151
- //读取file as DataUrl
152
- readerFileAsDataUrl = function readerFileAsDataUrl(file) {
153
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
154
- return regenerator.wrap(function _callee$(_context) {
155
- while (1) switch (_context.prev = _context.next) {
156
- case 0:
157
- return _context.abrupt("return", new Promise(function (resolve) {
158
- var fileReader = new FileReader();
159
- if (file.originFileObj) {
160
- fileReader.onload = function () {
161
- resolve(fileReader.result);
162
- };
163
- fileReader.readAsDataURL(file.originFileObj);
164
- } else resolve('');
165
- }));
166
- case 1:
167
- case "end":
168
- return _context.stop();
169
- }
170
- }, _callee);
171
- }));
172
- };
173
- _iterator = _createForOfIteratorHelper(items);
174
- _context2.prev = 4;
175
- _iterator.s();
176
- case 6:
177
- if ((_step = _iterator.n()).done) {
178
- _context2.next = 15;
179
- break;
180
- }
181
- file = _step.value;
182
- if (!file.originFileObj) {
183
- _context2.next = 13;
184
- break;
185
- }
186
- _context2.next = 11;
187
- return readerFileAsDataUrl(file);
188
- case 11:
189
- dataUrl = _context2.sent;
190
- file.dataUrl = dataUrl;
191
- case 13:
192
- _context2.next = 6;
193
- break;
194
- case 15:
195
- _context2.next = 20;
196
- break;
197
- case 17:
198
- _context2.prev = 17;
199
- _context2.t0 = _context2["catch"](4);
200
- _iterator.e(_context2.t0);
201
- case 20:
202
- _context2.prev = 20;
203
- _iterator.f();
204
- return _context2.finish(20);
205
- case 23:
206
- setUploadList(_toConsumableArray(items));
207
- case 24:
208
- case "end":
209
- return _context2.stop();
210
- }
211
- }, _callee2, null, [[4, 17, 20, 23]]);
212
- }));
213
- };
214
- useEffect(function () {
215
- if (listType === 'picture-card') handleFileFormat();else setUploadList(function (pre) {
216
- 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];
217
151
  return pre;
218
152
  });
219
153
  }, [items]);
@@ -234,7 +168,7 @@ var css_248z$3 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/11/15
234
168
  styleInject(css_248z$3);
235
169
 
236
170
  //error tip
237
- var ErrorTip = function ErrorTip(props) {
171
+ const ErrorTip = props => {
238
172
  return jsxs("div", Object.assign({
239
173
  className: clsx("".concat($prefixCls, "-upload-error"), props.className)
240
174
  }, {
@@ -267,144 +201,99 @@ var zh = {
267
201
  };
268
202
 
269
203
  var localeJson = {
270
- zh: zh,
271
- en: en
204
+ zh,
205
+ en
272
206
  };
273
207
 
274
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}";
275
209
  styleInject(css_248z$2);
276
210
 
277
211
  //ImageUpload
278
- var ImageUpload = function ImageUpload(props) {
279
- var className = props.className,
280
- style = props.style,
281
- _onStart = props.onStart,
282
- _onSuccess = props.onSuccess,
283
- _onError = props.onError,
284
- _onProgress = props.onProgress,
285
- onRemove = props.onRemove,
286
- _beforeUpload = props.beforeUpload,
287
- onChange = props.onChange,
288
- _props$defaultFileLis = props.defaultFileList,
289
- defaultFileList = _props$defaultFileLis === void 0 ? [] : _props$defaultFileLis,
290
- fileList = props.fileList,
291
- _props$showUploadList = props.showUploadList,
292
- showUploadList = _props$showUploadList === void 0 ? true : _props$showUploadList,
293
- maxCount = props.maxCount,
294
- _props$children = props.children,
295
- children = _props$children === void 0 ? null : _props$children,
296
- itemRender = props.itemRender,
297
- _props$showUploadErro = props.showUploadError,
298
- showUploadError = _props$showUploadErro === void 0 ? true : _props$showUploadErro,
299
- _props$stash = props.stash,
300
- stash = _props$stash === void 0 ? false : _props$stash,
301
- _props$uploading = props.uploading,
302
- uploading = _props$uploading === void 0 ? true : _props$uploading,
303
- _props$loading = props.loading,
304
- loading = _props$loading === void 0 ? false : _props$loading,
305
- _props$showLoading = props.showLoading,
306
- showLoadingProp = _props$showLoading === void 0 ? false : _props$showLoading,
307
- defaultImage = props.defaultImage,
308
- 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,
309
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"]);
310
- var intl = useFormatMessage('Upload', localeJson);
311
- var _useState = useState(defaultFileList),
312
- _useState2 = _slicedToArray(_useState, 2),
313
- uploadFileList = _useState2[0],
314
- setUploadFileList = _useState2[1]; //文件列表
315
- var _useState3 = useState(false),
316
- _useState4 = _slicedToArray(_useState3, 2),
317
- showLoading = _useState4[0],
318
- setShowLoading = _useState4[1]; //upload loading
319
- var _useState5 = useState(false),
320
- _useState6 = _slicedToArray(_useState5, 2),
321
- errTip = _useState6[0],
322
- setErrTip = _useState6[1]; //upload error tip
323
- var _useState7 = useState({
324
- imageUrl: ''
325
- }),
326
- _useState8 = _slicedToArray(_useState7, 2),
327
- avatar = _useState8[0],
328
- setAvatar = _useState8[1]; //不显示列表时上传头像
329
- var _ref = typeof showUploadList === 'boolean' ? {} : showUploadList,
330
- showRemoveIcon = _ref.showRemoveIcon,
331
- removeIcon = _ref.removeIcon; //显示上传列表
332
- var _ref2 = typeof showUploadError === 'boolean' ? {} : showUploadError,
333
- _ref2$uploadErrorMsg = _ref2.uploadErrorMsg,
334
- 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({
335
251
  id: 'uploadError'
336
- }) : _ref2$uploadErrorMsg,
337
- _ref2$leaveDelay = _ref2.leaveDelay,
338
- leaveDelay = _ref2$leaveDelay === void 0 ? 2000 : _ref2$leaveDelay; //错误信息提示
339
- var cropFileRef = useRef(); //裁剪文件
340
- useEffect(function () {
252
+ }),
253
+ leaveDelay = 2000
254
+ } = typeof showUploadError === 'boolean' ? {} : showUploadError; //错误信息提示
255
+ const cropFileRef = useRef(); //裁剪文件
256
+ useEffect(() => {
341
257
  setShowLoading(loading);
342
258
  }, [loading]);
343
259
  //复写属性
344
- var overrideProps = Object.assign(Object.assign({
260
+ const overrideProps = Object.assign(Object.assign({
345
261
  accept: 'image/*'
346
262
  }, restProps), {
347
- beforeUpload: function beforeUpload(file, fileList) {
348
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
349
- var result;
350
- return regenerator.wrap(function _callee$(_context) {
351
- while (1) switch (_context.prev = _context.next) {
352
- case 0:
353
- if (restProps.action && showLoadingProp && uploading) setShowLoading(true);
354
- _context.next = 3;
355
- return _beforeUpload === null || _beforeUpload === void 0 ? void 0 : _beforeUpload(file, fileList);
356
- case 3:
357
- result = _context.sent;
358
- if (!(result === false)) {
359
- _context.next = 9;
360
- break;
361
- }
362
- setShowLoading(false);
363
- return _context.abrupt("return", false);
364
- case 9:
365
- if (!(_typeof(result) === 'object' && result)) {
366
- _context.next = 16;
367
- break;
368
- }
369
- if (!(result instanceof File || result instanceof Blob)) {
370
- _context.next = 12;
371
- break;
372
- }
373
- return _context.abrupt("return", result);
374
- case 12:
375
- cropFileRef.current = result.cropFile;
376
- return _context.abrupt("return", result.isUpload);
377
- case 16:
378
- return _context.abrupt("return", true);
379
- case 17:
380
- case "end":
381
- return _context.stop();
382
- }
383
- }, _callee);
384
- }));
385
- },
386
- onStart: function onStart(file) {
387
- _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);
388
277
  },
389
- onSuccess: function onSuccess(response, file, xhr) {
278
+ onSuccess(response, file, xhr) {
390
279
  setShowLoading(false);
391
280
  errTip && showErrTip(false);
392
- var nextFileList = updateFileList(file);
281
+ const nextFileList = updateFileList(file);
393
282
  onInternalChange(nextFileList);
394
- _onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(response, file, xhr);
283
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response, file, xhr);
395
284
  },
396
- onError: function onError(error, response, file) {
285
+ onError(error, response, file) {
397
286
  setShowLoading(false);
398
287
  showErrTip(!!showUploadError);
399
- _onError === null || _onError === void 0 ? void 0 : _onError(error, response, file);
288
+ onError === null || onError === void 0 ? void 0 : onError(error, response, file);
400
289
  },
401
- onProgress: function onProgress(e, file) {
402
- _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);
403
292
  },
404
- onBatchStart: function onBatchStart(fileList) {
293
+ onBatchStart(fileList) {
405
294
  if (stash) {
406
295
  if (cropFileRef.current) {
407
- var idx = fileList.findIndex(function (_) {
296
+ const idx = fileList.findIndex(_ => {
408
297
  var _a;
409
298
  return _.file.uid === ((_a = cropFileRef.current) === null || _a === void 0 ? void 0 : _a.uid);
410
299
  });
@@ -415,62 +304,40 @@ var ImageUpload = function ImageUpload(props) {
415
304
  });
416
305
  }
417
306
  }
418
- var arr = fileList.map(function (_) {
419
- return _.parsedFile || _.file;
420
- });
421
- var mList = mergedFileList(arr);
307
+ const arr = fileList.map(_ => _.parsedFile || _.file);
308
+ const mList = mergedFileList(arr);
422
309
  onInternalChange(mList);
423
310
  }
424
311
  }
425
312
  });
426
313
  //内部变化
427
- var onInternalChange = function onInternalChange(changedFileList) {
428
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
429
- var cloneList, file, imageUrl;
430
- return regenerator.wrap(function _callee2$(_context2) {
431
- while (1) switch (_context2.prev = _context2.next) {
432
- case 0:
433
- cloneList = _toConsumableArray(changedFileList);
434
- if (showUploadList) {
435
- _context2.next = 13;
436
- break;
437
- }
438
- //不显示上传列表
439
- file = cloneList.slice(-1)[0];
440
- if (!file) {
441
- _context2.next = 11;
442
- break;
443
- }
444
- _context2.next = 6;
445
- return readerFileAsDataUrl(file);
446
- case 6:
447
- imageUrl = _context2.sent;
448
- file.dataUrl = imageUrl;
449
- avatar.imageUrl = imageUrl;
450
- avatar.imageName = file.name;
451
- setAvatar(Object.assign({}, avatar));
452
- case 11:
453
- onChange === null || onChange === void 0 ? void 0 : onChange([file]);
454
- return _context2.abrupt("return");
455
- case 13:
456
- if (maxCount === 1) {
457
- cloneList = cloneList.slice(-1);
458
- } else if (maxCount) {
459
- cloneList = cloneList.slice(0, maxCount);
460
- }
461
- onChange === null || onChange === void 0 ? void 0 : onChange(cloneList);
462
- setUploadFileList(cloneList);
463
- case 16:
464
- case "end":
465
- return _context2.stop();
466
- }
467
- }, _callee2);
468
- }));
469
- };
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
+ });
470
337
  //更新文件列表
471
- var updateFileList = function updateFileList(file) {
472
- var cloneList = _toConsumableArray(uploadFileList);
473
- var fileObj = Object.assign(Object.assign({}, file), {
338
+ const updateFileList = file => {
339
+ const cloneList = [...uploadFileList];
340
+ const fileObj = Object.assign(Object.assign({}, file), {
474
341
  lastModified: file.lastModified,
475
342
  lastModifiedDate: file.lastModifiedDate,
476
343
  name: file.name,
@@ -482,9 +349,9 @@ var ImageUpload = function ImageUpload(props) {
482
349
  return cloneList.concat(fileObj);
483
350
  };
484
351
  //合并文件列表
485
- var mergedFileList = function mergedFileList(fileList) {
486
- var cloneList = _toConsumableArray(uploadFileList);
487
- var newFileList = fileList.map(function (file) {
352
+ const mergedFileList = fileList => {
353
+ const cloneList = [...uploadFileList];
354
+ const newFileList = fileList.map(file => {
488
355
  return Object.assign(Object.assign({}, file), {
489
356
  lastModified: file.lastModified,
490
357
  lastModifiedDate: file.lastModifiedDate,
@@ -498,71 +365,57 @@ var ImageUpload = function ImageUpload(props) {
498
365
  return cloneList.concat(newFileList);
499
366
  };
500
367
  //删除文件
501
- var handleRemove = function handleRemove(file) {
502
- 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 => {
503
370
  // Prevent removing file
504
371
  if (ret === false) return;
505
- var idx = uploadFileList.findIndex(function (_) {
506
- return _.uid === file.uid;
507
- });
372
+ const idx = uploadFileList.findIndex(_ => _.uid === file.uid);
508
373
  if (idx > -1) uploadFileList.splice(idx, 1);
509
374
  onInternalChange(uploadFileList);
510
375
  });
511
376
  };
512
377
  //读取dataUrl
513
- var readerFileAsDataUrl = function readerFileAsDataUrl(file) {
514
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
515
- return regenerator.wrap(function _callee3$(_context3) {
516
- while (1) switch (_context3.prev = _context3.next) {
517
- case 0:
518
- return _context3.abrupt("return", new Promise(function (resolve) {
519
- var fileReader = new FileReader();
520
- if (file.originFileObj) {
521
- fileReader.onload = function () {
522
- resolve(fileReader.result);
523
- };
524
- fileReader.readAsDataURL(file.originFileObj);
525
- } else resolve('');
526
- }));
527
- case 1:
528
- case "end":
529
- return _context3.stop();
530
- }
531
- }, _callee3);
532
- }));
533
- };
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
+ });
534
389
  //显示错误提示
535
- var showErrTip = function showErrTip(flag) {
390
+ const showErrTip = flag => {
536
391
  setErrTip(flag);
537
392
  if (leaveDelay < 0) return;
538
- setTimeout(function () {
393
+ setTimeout(() => {
539
394
  setErrTip(false);
540
395
  }, leaveDelay);
541
396
  };
542
- useEffect(function () {
397
+ useEffect(() => {
543
398
  if (fileList) {
544
- setUploadFileList(_toConsumableArray(fileList));
399
+ setUploadFileList([...fileList]);
545
400
  }
546
401
  }, [fileList]);
547
- useEffect(function () {
402
+ useEffect(() => {
548
403
  if (defaultImage) {
549
404
  setAvatar(Object.assign({}, defaultImage));
550
405
  }
551
406
  }, [defaultImage]);
552
407
  //渲染上传列表
553
- var renderUploadList = function renderUploadList() {
554
- return showUploadList && jsx(UploadList, {
555
- listType: 'picture-card',
556
- readonly: readonly,
557
- items: uploadFileList,
558
- showRemoveIcon: showRemoveIcon,
559
- removeIcon: removeIcon,
560
- onRemove: handleRemove,
561
- itemRender: itemRender
562
- });
563
- };
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
+ });
564
417
  //渲染内容
565
- var renderUploadContent = function renderUploadContent() {
418
+ const renderUploadContent = () => {
566
419
  var _a;
567
420
  if (!showUploadList && avatar.imageUrl && !showLoading) {
568
421
  return jsxs("div", Object.assign({
@@ -597,7 +450,7 @@ var ImageUpload = function ImageUpload(props) {
597
450
  });
598
451
  };
599
452
  //渲染上传控件
600
- var renderUploadSelector = function renderUploadSelector() {
453
+ const renderUploadSelector = () => {
601
454
  if (readonly) return null;
602
455
  return jsxs("div", Object.assign({
603
456
  className: clsx('upload-image-select', showLoading && 'upload-image-select-loading')
@@ -625,7 +478,7 @@ var ImageUpload = function ImageUpload(props) {
625
478
  };
626
479
 
627
480
  //Dragger upload
628
- var Dragger = function Dragger(props) {
481
+ const Dragger = props => {
629
482
  return jsx(Upload, Object.assign({}, props, {
630
483
  type: 'drag'
631
484
  }));
@@ -790,336 +643,266 @@ var css_248z$1 = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/4/20
790
643
  styleInject(css_248z$1);
791
644
 
792
645
  //图片裁剪组件
793
- var ImgCrop = /*#__PURE__*/forwardRef(function (props, ref) {
794
- var _props$aspect = props.aspect,
795
- aspect = _props$aspect === void 0 ? 1 : _props$aspect,
796
- _props$shape = props.shape,
797
- shape = _props$shape === void 0 ? 'rect' : _props$shape,
798
- _props$grid = props.grid,
799
- grid = _props$grid === void 0 ? false : _props$grid,
800
- _props$quality = props.quality,
801
- quality = _props$quality === void 0 ? 0.4 : _props$quality,
802
- _props$fillColor = props.fillColor,
803
- fillColor = _props$fillColor === void 0 ? 'transparent' : _props$fillColor,
804
- _props$zoom = props.zoom,
805
- zoom = _props$zoom === void 0 ? true : _props$zoom,
806
- _props$rotate = props.rotate,
807
- rotate = _props$rotate === void 0 ? false : _props$rotate,
808
- _props$minZoom = props.minZoom,
809
- minZoom = _props$minZoom === void 0 ? 1 : _props$minZoom,
810
- _props$maxZoom = props.maxZoom,
811
- maxZoom = _props$maxZoom === void 0 ? 3 : _props$maxZoom,
812
- modalTitle = props.modalTitle,
813
- modalWidth = props.modalWidth,
814
- modalOk = props.modalOk,
815
- modalCancel = props.modalCancel,
816
- onModalOk = props.onModalOk,
817
- onModalCancel = props.onModalCancel,
818
- beforeCrop = props.beforeCrop,
819
- onUploadFail = props.onUploadFail,
820
- cropperProps = props.cropperProps,
821
- children = props.children,
822
- _props$fixedCropSize = props.fixedCropSize,
823
- 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 = {
824
668
  width: 120,
825
669
  height: 120
826
- } : _props$fixedCropSize;
827
- var intl = useFormatMessage('Upload', localeJson);
828
- var _useState = useState(''),
829
- _useState2 = _slicedToArray(_useState, 2),
830
- image = _useState2[0],
831
- setImage = _useState2[1];
832
- var fileRef = useRef();
833
- var beforeUploadRef = useRef();
834
- var resolveRef = useRef();
835
- 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();
836
678
  //存储回调
837
- var cbRef = useRef({});
679
+ const cbRef = useRef({});
838
680
  cbRef.current.onModalOk = onModalOk;
839
681
  cbRef.current.onModalCancel = onModalCancel;
840
682
  cbRef.current.beforeCrop = beforeCrop;
841
683
  cbRef.current.onUploadFail = onUploadFail;
842
- var easyCropRef = useRef({});
684
+ const easyCropRef = useRef({});
843
685
  //上传组件
844
- var uploadComponent = useMemo(function () {
845
- var upload = Array.isArray(children) ? children[0] : children;
846
- var _a = upload.props,
847
- beforeUpload = _a.beforeUpload,
848
- 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,
849
693
  restUploadProps = __rest(_a, ["beforeUpload", "accept"]);
850
694
  beforeUploadRef.current = beforeUpload;
851
695
  return Object.assign(Object.assign({}, upload), {
852
696
  props: Object.assign(Object.assign({}, restUploadProps), {
853
697
  accept: accept || 'image/*',
854
- beforeUpload: function beforeUpload(file, fileList) {
855
- return new Promise(function (resolve, reject) {
856
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee() {
857
- var reader;
858
- return regenerator.wrap(function _callee$(_context) {
859
- while (1) switch (_context.prev = _context.next) {
860
- case 0:
861
- _context.t0 = cbRef.current.beforeCrop;
862
- if (!_context.t0) {
863
- _context.next = 5;
864
- break;
865
- }
866
- _context.next = 4;
867
- return cbRef.current.beforeCrop(file, fileList);
868
- case 4:
869
- _context.t0 = !_context.sent;
870
- case 5:
871
- if (!_context.t0) {
872
- _context.next = 8;
873
- break;
874
- }
875
- reject();
876
- return _context.abrupt("return");
877
- case 8:
878
- fileRef.current = file;
879
- resolveRef.current = function (newFile) {
880
- var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
881
- var _a, _b;
882
- (_b = (_a = cbRef.current).onModalOk) === null || _b === void 0 ? void 0 : _b.call(_a, newFile);
883
- if (!flag) return resolve({
884
- cropFile: newFile,
885
- isUpload: flag
886
- });
887
- resolve(newFile);
888
- };
889
- rejectRef.current = function (uploadErr) {
890
- var _a, _b;
891
- (_b = (_a = cbRef.current).onUploadFail) === null || _b === void 0 ? void 0 : _b.call(_a, uploadErr);
892
- reject(uploadErr);
893
- };
894
- reader = new FileReader();
895
- reader.addEventListener('load', function () {
896
- return typeof reader.result === 'string' && setImage(reader.result);
897
- });
898
- reader.readAsDataURL(file);
899
- case 14:
900
- case "end":
901
- return _context.stop();
902
- }
903
- }, _callee);
904
- }));
905
- });
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
+ }));
906
724
  }
907
725
  })
908
726
  });
909
727
  }, [children]);
910
728
  //modal 关闭后操作
911
- var onClose = function onClose() {
729
+ const onClose = () => {
912
730
  setImage('');
913
731
  easyCropRef.current.setZoomVal(INIT_ZOOM);
914
732
  easyCropRef.current.setRotateVal(INIT_ROTATE);
915
733
  };
916
734
  //modal cancel
917
- var onCancel = useCallback(function () {
735
+ const onCancel = useCallback(() => {
918
736
  var _a, _b;
919
737
  (_b = (_a = cbRef.current).onModalCancel) === null || _b === void 0 ? void 0 : _b.call(_a);
920
738
  onClose();
921
739
  }, []);
922
740
  //modal ok
923
- var onOk = useCallback(function () {
924
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee3() {
925
- 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;
926
- return regenerator.wrap(function _callee3$(_context3) {
927
- while (1) switch (_context3.prev = _context3.next) {
928
- case 0:
929
- onClose();
930
- canvas = document.createElement('canvas');
931
- ctx = canvas.getContext('2d');
932
- imgSource = document.querySelector(".".concat(PREFIX, "-media"));
933
- _easyCropRef$current$ = easyCropRef.current.cropPixelsRef.current, cropWidth = _easyCropRef$current$.width, cropHeight = _easyCropRef$current$.height, cropX = _easyCropRef$current$.x, cropY = _easyCropRef$current$.y;
934
- if (rotate && easyCropRef.current.rotateVal !== INIT_ROTATE) {
935
- imgWidth = imgSource.naturalWidth, imgHeight = imgSource.naturalHeight;
936
- angle = easyCropRef.current.rotateVal * (Math.PI / 180); // get container for rotated image
937
- sine = Math.abs(Math.sin(angle));
938
- cosine = Math.abs(Math.cos(angle));
939
- squareWidth = imgWidth * cosine + imgHeight * sine;
940
- squareHeight = imgHeight * cosine + imgWidth * sine;
941
- canvas.width = squareWidth;
942
- canvas.height = squareHeight;
943
- ctx.fillStyle = fillColor;
944
- ctx.fillRect(0, 0, squareWidth, squareHeight);
945
- // rotate container
946
- squareHalfWidth = squareWidth / 2;
947
- squareHalfHeight = squareHeight / 2;
948
- ctx.translate(squareHalfWidth, squareHalfHeight);
949
- ctx.rotate(angle);
950
- ctx.translate(-squareHalfWidth, -squareHalfHeight);
951
- // draw rotated image
952
- imgX = (squareWidth - imgWidth) / 2;
953
- imgY = (squareHeight - imgHeight) / 2;
954
- ctx.drawImage(imgSource, 0, 0, imgWidth, imgHeight, imgX, imgY, imgWidth, imgHeight);
955
- // crop rotated image
956
- imgData = ctx.getImageData(0, 0, squareWidth, squareHeight);
957
- canvas.width = cropWidth;
958
- canvas.height = cropHeight;
959
- ctx.putImageData(imgData, -cropX, -cropY);
960
- } else {
961
- canvas.width = cropWidth;
962
- canvas.height = cropHeight;
963
- ctx.fillStyle = fillColor;
964
- ctx.fillRect(0, 0, cropWidth, cropHeight);
965
- ctx.drawImage(imgSource, cropX, cropY, cropWidth, cropHeight, 0, 0, cropWidth, cropHeight);
966
- }
967
- //裁剪之后改变图片大小
968
- changeImageSizeAfterCrop = function changeImageSizeAfterCrop(newFile) {
969
- return new Promise(function (resolve) {
970
- var name = newFile.name,
971
- type = newFile.type,
972
- uid = newFile.uid;
973
- var width = fixedCropSize.width,
974
- height = fixedCropSize.height; //固定裁剪大小
975
- var changeCanvas = document.createElement('canvas');
976
- var changeCtx = changeCanvas.getContext('2d');
977
- var img = new Image();
978
- img.onload = function () {
979
- changeCanvas.width = width;
980
- changeCanvas.height = height;
981
- changeCtx.drawImage(img, 0, 0, width, height);
982
- changeCanvas.toBlob(function (cBlob) {
983
- var changeFile = Object.assign(new File([cBlob], name, {
984
- type: type
985
- }), {
986
- uid: uid
987
- });
988
- resolve(changeFile);
989
- }, type, quality);
990
- };
991
- img.onerror = function () {
992
- resolve(newFile);
993
- };
994
- var fileReader = new FileReader();
995
- fileReader.onload = function () {
996
- img.src = fileReader.result;
997
- };
998
- fileReader.onerror = function () {
999
- resolve(newFile);
1000
- };
1001
- fileReader.readAsDataURL(newFile);
1002
- });
1003
- }; // get the new image
1004
- _fileRef$current = fileRef.current, type = _fileRef$current.type, name = _fileRef$current.name, uid = _fileRef$current.uid;
1005
- if (/svg/gi.test(type)) {
1006
- //svg 转为 png
1007
- type = 'image/png';
1008
- idx = name.lastIndexOf('.');
1009
- if (idx > -1) name = "".concat(name.substring(0, idx), ".png");
1010
- }
1011
- //转为blob
1012
- onBlob = function onBlob(blob) {
1013
- return __awaiter(void 0, void 0, void 0, /*#__PURE__*/regenerator.mark(function _callee2() {
1014
- var _a, _b, _c, _d, _e, _f, newFile, changeFile, res, passedFile;
1015
- return regenerator.wrap(function _callee2$(_context2) {
1016
- while (1) switch (_context2.prev = _context2.next) {
1017
- case 0:
1018
- newFile = Object.assign(new File([blob], name, {
1019
- type: type
1020
- }), {
1021
- uid: uid
1022
- });
1023
- _context2.next = 3;
1024
- return changeImageSizeAfterCrop(newFile);
1025
- case 3:
1026
- changeFile = _context2.sent;
1027
- if (!(typeof beforeUploadRef.current !== 'function')) {
1028
- _context2.next = 6;
1029
- break;
1030
- }
1031
- return _context2.abrupt("return", (_a = resolveRef.current) === null || _a === void 0 ? void 0 : _a.call(resolveRef, changeFile));
1032
- case 6:
1033
- res = beforeUploadRef.current(changeFile, [changeFile]);
1034
- if (!(typeof res !== 'boolean' && !res)) {
1035
- _context2.next = 10;
1036
- break;
1037
- }
1038
- console.error('beforeUpload must return a boolean or Promise');
1039
- return _context2.abrupt("return");
1040
- case 10:
1041
- if (!(res === true)) {
1042
- _context2.next = 12;
1043
- break;
1044
- }
1045
- return _context2.abrupt("return", (_b = resolveRef.current) === null || _b === void 0 ? void 0 : _b.call(resolveRef, changeFile));
1046
- case 12:
1047
- if (!(res === false)) {
1048
- _context2.next = 14;
1049
- break;
1050
- }
1051
- return _context2.abrupt("return", (_c = resolveRef.current) === null || _c === void 0 ? void 0 : _c.call(resolveRef, changeFile, false));
1052
- case 14:
1053
- if (!(res && res instanceof Promise)) {
1054
- _context2.next = 27;
1055
- break;
1056
- }
1057
- _context2.prev = 15;
1058
- _context2.next = 18;
1059
- return res;
1060
- case 18:
1061
- passedFile = _context2.sent;
1062
- if (!(passedFile instanceof File || passedFile instanceof Blob)) {
1063
- _context2.next = 21;
1064
- break;
1065
- }
1066
- return _context2.abrupt("return", (_d = resolveRef.current) === null || _d === void 0 ? void 0 : _d.call(resolveRef, passedFile));
1067
- case 21:
1068
- (_e = resolveRef.current) === null || _e === void 0 ? void 0 : _e.call(resolveRef, changeFile, passedFile);
1069
- _context2.next = 27;
1070
- break;
1071
- case 24:
1072
- _context2.prev = 24;
1073
- _context2.t0 = _context2["catch"](15);
1074
- (_f = rejectRef.current) === null || _f === void 0 ? void 0 : _f.call(rejectRef, _context2.t0);
1075
- case 27:
1076
- case "end":
1077
- return _context2.stop();
1078
- }
1079
- }, _callee2, null, [[15, 24]]);
1080
- }));
1081
- };
1082
- canvas.toBlob(onBlob, type, quality);
1083
- case 11:
1084
- case "end":
1085
- 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);
1086
870
  }
1087
- }, _callee3);
1088
- }));
1089
- }, [fillColor, quality, rotate]);
1090
- //img crop 组件
1091
- var getComponent = function getComponent(titleOfModal) {
1092
- return jsxs(Fragment, {
1093
- children: [uploadComponent, image && jsx(Modal, Object.assign({
1094
- open: true,
1095
- className: "".concat(PREFIX, "-modal"),
1096
- size: 'md',
1097
- title: titleOfModal !== null && titleOfModal !== void 0 ? titleOfModal : intl({
1098
- id: 'editImage'
1099
- }),
1100
- onOk: onOk,
1101
- onCancel: onCancel,
1102
- okText: modalOk,
1103
- cancelText: modalCancel,
1104
- contentWidth: modalWidth
1105
- }, {
1106
- children: jsx(EasyCrop$1, {
1107
- ref: easyCropRef,
1108
- cropperRef: ref,
1109
- image: image,
1110
- aspect: aspect,
1111
- shape: shape,
1112
- grid: grid,
1113
- zoom: zoom,
1114
- rotate: rotate,
1115
- minZoom: minZoom,
1116
- maxZoom: maxZoom,
1117
- fixedCropSize: fixedCropSize,
1118
- cropperProps: cropperProps
1119
- })
1120
- }))]
871
+ }
1121
872
  });
1122
- };
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
+ });
1123
906
  return jsx(Fragment, {
1124
907
  children: getComponent(modalTitle)
1125
908
  });