@chaomingd/design 0.0.68

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 (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +23 -0
  3. package/dist/esm/CheckGroup/context.d.ts +9 -0
  4. package/dist/esm/CheckGroup/context.js +6 -0
  5. package/dist/esm/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
  6. package/dist/esm/CheckGroup/hooks/useCheckGroup.js +180 -0
  7. package/dist/esm/CheckGroup/index.d.ts +9 -0
  8. package/dist/esm/CheckGroup/index.js +79 -0
  9. package/dist/esm/CheckGroup/type.d.ts +28 -0
  10. package/dist/esm/CheckGroup/type.js +1 -0
  11. package/dist/esm/Grid/index.d.ts +15 -0
  12. package/dist/esm/Grid/index.js +64 -0
  13. package/dist/esm/Grid/index.less +7 -0
  14. package/dist/esm/KaTeXRenderer/index.d.ts +9 -0
  15. package/dist/esm/KaTeXRenderer/index.js +33 -0
  16. package/dist/esm/KaTeXRenderer/index.less +0 -0
  17. package/dist/esm/PixelPlayer/index.d.ts +28 -0
  18. package/dist/esm/PixelPlayer/index.js +118 -0
  19. package/dist/esm/PixelPlayer/index.less +29 -0
  20. package/dist/esm/PixelPlayer/lib/peer-stream.d.ts +62 -0
  21. package/dist/esm/PixelPlayer/lib/peer-stream.js +876 -0
  22. package/dist/esm/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
  23. package/dist/esm/PixelPlayer/useAutoLayoutContainer.js +53 -0
  24. package/dist/esm/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
  25. package/dist/esm/PixelPlayer/useVideoWithCustomEvent.js +37 -0
  26. package/dist/esm/Resizer/index.d.ts +17 -0
  27. package/dist/esm/Resizer/index.js +73 -0
  28. package/dist/esm/Resizer/index.less +73 -0
  29. package/dist/esm/SetupAntApp/index.d.ts +1 -0
  30. package/dist/esm/SetupAntApp/index.js +10 -0
  31. package/dist/esm/Transition/index.d.ts +4 -0
  32. package/dist/esm/Transition/index.js +132 -0
  33. package/dist/esm/Transition/type.d.ts +33 -0
  34. package/dist/esm/Transition/type.js +12 -0
  35. package/dist/esm/Transition/utils.d.ts +6 -0
  36. package/dist/esm/Transition/utils.js +15 -0
  37. package/dist/esm/UploadFile/components/IconButton/index.d.ts +11 -0
  38. package/dist/esm/UploadFile/components/IconButton/index.js +26 -0
  39. package/dist/esm/UploadFile/components/IconButton/index.less +58 -0
  40. package/dist/esm/UploadFile/components/Slash.d.ts +2 -0
  41. package/dist/esm/UploadFile/components/Slash.js +15 -0
  42. package/dist/esm/UploadFile/components/SvgIcons.d.ts +11 -0
  43. package/dist/esm/UploadFile/components/SvgIcons.js +141 -0
  44. package/dist/esm/UploadFile/hooks/useUploadModel.d.ts +16 -0
  45. package/dist/esm/UploadFile/hooks/useUploadModel.js +376 -0
  46. package/dist/esm/UploadFile/index.d.ts +4 -0
  47. package/dist/esm/UploadFile/index.js +277 -0
  48. package/dist/esm/UploadFile/index.less +274 -0
  49. package/dist/esm/UploadFile/type.d.ts +63 -0
  50. package/dist/esm/UploadFile/type.js +1 -0
  51. package/dist/esm/UploadFile/utils/formatBitString.d.ts +1 -0
  52. package/dist/esm/UploadFile/utils/formatBitString.js +9 -0
  53. package/dist/esm/UploadFile/utils/getExt.d.ts +1 -0
  54. package/dist/esm/UploadFile/utils/getExt.js +6 -0
  55. package/dist/esm/UploadFile/utils/isImage.d.ts +1 -0
  56. package/dist/esm/UploadFile/utils/isImage.js +8 -0
  57. package/dist/esm/UploadFile/utils/normalizeExt.d.ts +1 -0
  58. package/dist/esm/UploadFile/utils/normalizeExt.js +4 -0
  59. package/dist/esm/UploadFile/utils/validateFileTypes.d.ts +13 -0
  60. package/dist/esm/UploadFile/utils/validateFileTypes.js +83 -0
  61. package/dist/esm/UploadFile/utils/validateRule.d.ts +3 -0
  62. package/dist/esm/UploadFile/utils/validateRule.js +22 -0
  63. package/dist/esm/UploadFile/utils/validateUpload.d.ts +5 -0
  64. package/dist/esm/UploadFile/utils/validateUpload.js +35 -0
  65. package/dist/esm/constant/index.d.ts +7 -0
  66. package/dist/esm/constant/index.js +18 -0
  67. package/dist/esm/constants/cssPrefix.d.ts +1 -0
  68. package/dist/esm/constants/cssPrefix.js +1 -0
  69. package/dist/esm/getAntApp/index.d.ts +8 -0
  70. package/dist/esm/getAntApp/index.js +17 -0
  71. package/dist/esm/index.d.ts +10 -0
  72. package/dist/esm/index.js +10 -0
  73. package/dist/esm/interface.d.ts +1 -0
  74. package/dist/esm/interface.js +1 -0
  75. package/dist/esm/styles/cssVar.less +28 -0
  76. package/dist/esm/styles/reset.css +3 -0
  77. package/dist/esm/styles/var.d.ts +1 -0
  78. package/dist/esm/styles/var.js +1 -0
  79. package/dist/esm/styles/var.less +2 -0
  80. package/dist/esm/variable.less +52 -0
  81. package/dist/lib/CheckGroup/context.d.ts +9 -0
  82. package/dist/lib/CheckGroup/context.js +12 -0
  83. package/dist/lib/CheckGroup/hooks/useCheckGroup.d.ts +21 -0
  84. package/dist/lib/CheckGroup/hooks/useCheckGroup.js +164 -0
  85. package/dist/lib/CheckGroup/index.d.ts +9 -0
  86. package/dist/lib/CheckGroup/index.js +93 -0
  87. package/dist/lib/CheckGroup/type.d.ts +28 -0
  88. package/dist/lib/CheckGroup/type.js +5 -0
  89. package/dist/lib/Grid/index.d.ts +15 -0
  90. package/dist/lib/Grid/index.js +77 -0
  91. package/dist/lib/Grid/index.less +7 -0
  92. package/dist/lib/KaTeXRenderer/index.d.ts +9 -0
  93. package/dist/lib/KaTeXRenderer/index.js +41 -0
  94. package/dist/lib/KaTeXRenderer/index.less +0 -0
  95. package/dist/lib/PixelPlayer/index.d.ts +28 -0
  96. package/dist/lib/PixelPlayer/index.js +108 -0
  97. package/dist/lib/PixelPlayer/index.less +29 -0
  98. package/dist/lib/PixelPlayer/lib/peer-stream.d.ts +62 -0
  99. package/dist/lib/PixelPlayer/lib/peer-stream.js +707 -0
  100. package/dist/lib/PixelPlayer/useAutoLayoutContainer.d.ts +2 -0
  101. package/dist/lib/PixelPlayer/useAutoLayoutContainer.js +60 -0
  102. package/dist/lib/PixelPlayer/useVideoWithCustomEvent.d.ts +5 -0
  103. package/dist/lib/PixelPlayer/useVideoWithCustomEvent.js +35 -0
  104. package/dist/lib/Resizer/index.d.ts +17 -0
  105. package/dist/lib/Resizer/index.js +75 -0
  106. package/dist/lib/Resizer/index.less +73 -0
  107. package/dist/lib/SetupAntApp/index.d.ts +1 -0
  108. package/dist/lib/SetupAntApp/index.js +16 -0
  109. package/dist/lib/Transition/index.d.ts +4 -0
  110. package/dist/lib/Transition/index.js +128 -0
  111. package/dist/lib/Transition/type.d.ts +33 -0
  112. package/dist/lib/Transition/type.js +18 -0
  113. package/dist/lib/Transition/utils.d.ts +6 -0
  114. package/dist/lib/Transition/utils.js +22 -0
  115. package/dist/lib/UploadFile/components/IconButton/index.d.ts +11 -0
  116. package/dist/lib/UploadFile/components/IconButton/index.js +29 -0
  117. package/dist/lib/UploadFile/components/IconButton/index.less +58 -0
  118. package/dist/lib/UploadFile/components/Slash.d.ts +2 -0
  119. package/dist/lib/UploadFile/components/Slash.js +22 -0
  120. package/dist/lib/UploadFile/components/SvgIcons.d.ts +11 -0
  121. package/dist/lib/UploadFile/components/SvgIcons.js +158 -0
  122. package/dist/lib/UploadFile/hooks/useUploadModel.d.ts +16 -0
  123. package/dist/lib/UploadFile/hooks/useUploadModel.js +306 -0
  124. package/dist/lib/UploadFile/index.d.ts +4 -0
  125. package/dist/lib/UploadFile/index.js +280 -0
  126. package/dist/lib/UploadFile/index.less +274 -0
  127. package/dist/lib/UploadFile/type.d.ts +63 -0
  128. package/dist/lib/UploadFile/type.js +5 -0
  129. package/dist/lib/UploadFile/utils/formatBitString.d.ts +1 -0
  130. package/dist/lib/UploadFile/utils/formatBitString.js +15 -0
  131. package/dist/lib/UploadFile/utils/getExt.d.ts +1 -0
  132. package/dist/lib/UploadFile/utils/getExt.js +12 -0
  133. package/dist/lib/UploadFile/utils/isImage.d.ts +1 -0
  134. package/dist/lib/UploadFile/utils/isImage.js +14 -0
  135. package/dist/lib/UploadFile/utils/normalizeExt.d.ts +1 -0
  136. package/dist/lib/UploadFile/utils/normalizeExt.js +10 -0
  137. package/dist/lib/UploadFile/utils/validateFileTypes.d.ts +13 -0
  138. package/dist/lib/UploadFile/utils/validateFileTypes.js +87 -0
  139. package/dist/lib/UploadFile/utils/validateRule.d.ts +3 -0
  140. package/dist/lib/UploadFile/utils/validateRule.js +28 -0
  141. package/dist/lib/UploadFile/utils/validateUpload.d.ts +5 -0
  142. package/dist/lib/UploadFile/utils/validateUpload.js +31 -0
  143. package/dist/lib/constant/index.d.ts +7 -0
  144. package/dist/lib/constant/index.js +24 -0
  145. package/dist/lib/constants/cssPrefix.d.ts +1 -0
  146. package/dist/lib/constants/cssPrefix.js +7 -0
  147. package/dist/lib/getAntApp/index.d.ts +8 -0
  148. package/dist/lib/getAntApp/index.js +27 -0
  149. package/dist/lib/index.d.ts +10 -0
  150. package/dist/lib/index.js +69 -0
  151. package/dist/lib/interface.d.ts +1 -0
  152. package/dist/lib/interface.js +5 -0
  153. package/dist/lib/styles/cssVar.less +28 -0
  154. package/dist/lib/styles/reset.css +3 -0
  155. package/dist/lib/styles/var.d.ts +1 -0
  156. package/dist/lib/styles/var.js +7 -0
  157. package/dist/lib/styles/var.less +2 -0
  158. package/dist/lib/variable.less +52 -0
  159. package/package.json +54 -0
@@ -0,0 +1,277 @@
1
+ import { Image, Typography } from 'antd';
2
+ import classNames from 'classnames';
3
+ import React, { useMemo, useRef } from 'react';
4
+ import IconButton from "./components/IconButton";
5
+ import "./index.less";
6
+ import SlashSvg from "./components/Slash";
7
+ import { CloseSvg, DeleteSvg, RarSvg, ZipSvg, TxtSvg, PdfSvg, DocSvg } from "./components/SvgIcons";
8
+ import { useUploadModel } from "./hooks/useUploadModel";
9
+ import { getExt } from "./utils/getExt";
10
+ import { isImage } from "./utils/isImage";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ var EXT_SVG = {
14
+ zip: ZipSvg,
15
+ rar: RarSvg,
16
+ txt: TxtSvg,
17
+ pdf: PdfSvg,
18
+ doc: DocSvg,
19
+ docx: DocSvg
20
+ };
21
+ var preCls = '@chaomingd/upload-file';
22
+ var TextBtn = function TextBtn(_ref) {
23
+ var children = _ref.children,
24
+ onClick = _ref.onClick;
25
+ return /*#__PURE__*/_jsx("div", {
26
+ className: "".concat(preCls, "-text-btn"),
27
+ onClick: onClick,
28
+ children: children
29
+ });
30
+ };
31
+ var UploadFile = function UploadFile(props) {
32
+ var accepts = props.accepts,
33
+ multiple = props.multiple,
34
+ _props$maxCount = props.maxCount,
35
+ maxCount = _props$maxCount === void 0 ? 1 : _props$maxCount,
36
+ children = props.children,
37
+ id = props.id,
38
+ getIcon = props.getIcon,
39
+ _props$acceptsJoinCha = props.acceptsJoinCharacter,
40
+ acceptsJoinCharacter = _props$acceptsJoinCha === void 0 ? '、' : _props$acceptsJoinCha;
41
+ var inputFileRef = useRef(null);
42
+ var inputFileReplaceRef = useRef(null);
43
+ var inputRelaceId = useRef('');
44
+ var _useUploadModel = useUploadModel(props),
45
+ model = _useUploadModel.model,
46
+ onDragOver = _useUploadModel.onDragOver,
47
+ handleUploadFiles = _useUploadModel.handleUploadFiles,
48
+ onDeleteFileList = _useUploadModel.onDeleteFileList;
49
+ var _model$useGetState = model.useGetState(),
50
+ dragEnter = _model$useGetState.dragEnter,
51
+ fileList = _model$useGetState.value;
52
+
53
+ // input accept 属性
54
+ var _useMemo = useMemo(function () {
55
+ if (!accepts) return {
56
+ accept: '',
57
+ extstr: ''
58
+ };
59
+ var exts = accepts.map(function (ext) {
60
+ if (ext[0] === '.') {
61
+ return ext;
62
+ }
63
+ return ".".concat(ext);
64
+ });
65
+ return {
66
+ accept: exts.join(','),
67
+ extstr: exts.map(function (ext) {
68
+ return ext.slice(1);
69
+ }).join(acceptsJoinCharacter)
70
+ };
71
+ }, [accepts, acceptsJoinCharacter]),
72
+ accept = _useMemo.accept,
73
+ extstr = _useMemo.extstr;
74
+ var openFileDialog = function openFileDialog() {
75
+ var _inputFileRef$current;
76
+ (_inputFileRef$current = inputFileRef.current) === null || _inputFileRef$current === void 0 || _inputFileRef$current.click();
77
+ };
78
+ var handleReUpload = function handleReUpload(uid) {
79
+ var _inputFileReplaceRef$;
80
+ inputRelaceId.current = uid;
81
+ (_inputFileReplaceRef$ = inputFileReplaceRef.current) === null || _inputFileReplaceRef$ === void 0 || _inputFileReplaceRef$.click();
82
+ };
83
+ var renderDragger = function renderDragger() {
84
+ return /*#__PURE__*/_jsx("div", {
85
+ onDragOver: onDragOver,
86
+ onDrop: function onDrop(e) {
87
+ e.preventDefault();
88
+ handleUploadFiles(e.dataTransfer.files || []);
89
+ },
90
+ className: classNames("".concat(preCls, "-dragger-container"), fileList.length && "".concat(preCls, "-dragger-container-has-file-list")),
91
+ onClick: openFileDialog,
92
+ children: children ? children : /*#__PURE__*/_jsx("div", {
93
+ className: "".concat(preCls, "-dragger"),
94
+ children: dragEnter ? /*#__PURE__*/_jsx("div", {
95
+ className: "".concat(preCls, "-dragger-tip"),
96
+ children: "\u91CA\u653E\u9F20\u6807"
97
+ }) : /*#__PURE__*/_jsxs("div", {
98
+ className: "".concat(preCls, "-dragger-inner"),
99
+ children: [/*#__PURE__*/_jsxs("div", {
100
+ className: "".concat(preCls, "-dragger-top"),
101
+ children: [/*#__PURE__*/_jsx(TextBtn, {
102
+ children: "\u70B9\u51FB\u4E0A\u4F20"
103
+ }), /*#__PURE__*/_jsx("div", {
104
+ className: "".concat(preCls, "-split"),
105
+ children: /*#__PURE__*/_jsx(SlashSvg, {})
106
+ }), /*#__PURE__*/_jsx("div", {
107
+ className: "".concat(preCls, "-drag-text"),
108
+ children: "\u62D6\u62FD\u5230\u6B64\u533A\u57DF"
109
+ })]
110
+ }), extstr && /*#__PURE__*/_jsxs("div", {
111
+ className: "".concat(preCls, "-support-ext"),
112
+ children: ["\u652F\u6301\u6269\u5C55\u540D\uFF1A", extstr]
113
+ })]
114
+ })
115
+ })
116
+ });
117
+ };
118
+ var getProgress = function getProgress(fileListItem) {
119
+ if (!fileListItem.status || fileListItem.status === 'error' || fileListItem.status === 'done') {
120
+ return '100%';
121
+ }
122
+ if (fileListItem.percent) {
123
+ return "".concat(+Math.min(fileListItem.percent, 99.9).toFixed(2), "%");
124
+ }
125
+ return '0%';
126
+ };
127
+ var renderValidation = function renderValidation(fileListItem) {
128
+ var validateText = '';
129
+ if (fileListItem.validationStatus === 'validating') {
130
+ if (typeof fileListItem.validationPercent !== 'number') {
131
+ validateText = '校验中...';
132
+ } else {
133
+ validateText = "\u6821\u9A8C\u4E2D ".concat(Math.min(+fileListItem.validationPercent.toFixed(2), 99.99), "%");
134
+ }
135
+ }
136
+ if (fileListItem.validationStatus === 'error') {
137
+ var _fileListItem$validat;
138
+ validateText = ((_fileListItem$validat = fileListItem.validationError) === null || _fileListItem$validat === void 0 ? void 0 : _fileListItem$validat.message) || '校验出错';
139
+ }
140
+ if (fileListItem.validationStatus === 'success') {
141
+ validateText = '校验成功';
142
+ }
143
+ return /*#__PURE__*/_jsx("div", {
144
+ className: classNames("".concat(preCls, "-file-item-validate"), "".concat(preCls, "-validate-status--").concat(fileListItem.validationStatus || 'success')),
145
+ children: validateText
146
+ });
147
+ };
148
+ var renderIcon = function renderIcon(fileListItem) {
149
+ var _fileListItem$file;
150
+ var ext = getExt(fileListItem.name);
151
+ if (isImage(ext, fileListItem.type || ((_fileListItem$file = fileListItem.file) === null || _fileListItem$file === void 0 ? void 0 : _fileListItem$file.type) || '')) {
152
+ return /*#__PURE__*/_jsx("div", {
153
+ className: "".concat(preCls, "-file-item-left"),
154
+ children: /*#__PURE__*/_jsx(Image, {
155
+ width: 66,
156
+ height: 66,
157
+ src: fileListItem.blobUrl || fileListItem.url || ''
158
+ })
159
+ });
160
+ }
161
+ var ExtSvgIcon = EXT_SVG[ext];
162
+ var iconNode = getIcon ? getIcon(ext, fileListItem) : null;
163
+ return (ExtSvgIcon !== undefined || iconNode) && /*#__PURE__*/_jsx("div", {
164
+ className: "".concat(preCls, "-file-item-left"),
165
+ children: /*#__PURE__*/_jsx("div", {
166
+ className: "".concat(preCls, "-ext-svg"),
167
+ children: iconNode ? iconNode : /*#__PURE__*/_jsx(ExtSvgIcon, {})
168
+ })
169
+ });
170
+ };
171
+ var renderFileListItem = function renderFileListItem(fileListItem) {
172
+ var progress = getProgress(fileListItem);
173
+ var orignalNode = /*#__PURE__*/_jsxs("div", {
174
+ className: classNames("".concat(preCls, "-file-item"), "".concat(preCls, "-file-item-status-").concat(fileListItem.status || 'done')),
175
+ children: [renderIcon(fileListItem), /*#__PURE__*/_jsxs("div", {
176
+ className: "".concat(preCls, "-file-item-right"),
177
+ children: [/*#__PURE__*/_jsxs("div", {
178
+ className: "".concat(preCls, "-file-item-header"),
179
+ children: [/*#__PURE__*/_jsx(Typography.Text, {
180
+ ellipsis: {
181
+ tooltip: {
182
+ title: fileListItem.name,
183
+ showArrow: false,
184
+ // @ts-ignore
185
+ arrow: false
186
+ }
187
+ },
188
+ className: "".concat(preCls, "-file-item-name"),
189
+ children: fileListItem.name
190
+ }), /*#__PURE__*/_jsxs("div", {
191
+ className: "".concat(preCls, "-file-item-extra"),
192
+ children: [/*#__PURE__*/_jsx(TextBtn, {
193
+ onClick: function onClick() {
194
+ handleReUpload(fileListItem.uid);
195
+ },
196
+ children: "\u91CD\u65B0\u4E0A\u4F20"
197
+ }), /*#__PURE__*/_jsx(IconButton, {
198
+ type: fileListItem.status === 'uploading' ? 'primary' : 'danger',
199
+ size: "small",
200
+ icon: fileListItem.status === 'uploading' ? /*#__PURE__*/_jsx(CloseSvg, {
201
+ onClick: function onClick() {
202
+ onDeleteFileList(fileListItem.uid);
203
+ }
204
+ }) : /*#__PURE__*/_jsx(DeleteSvg, {
205
+ onClick: function onClick() {
206
+ onDeleteFileList(fileListItem.uid);
207
+ }
208
+ }),
209
+ className: "".concat(preCls, "-file-item-action-btn")
210
+ })]
211
+ })]
212
+ }), /*#__PURE__*/_jsx("div", {
213
+ className: "".concat(preCls, "-progress"),
214
+ children: /*#__PURE__*/_jsx("div", {
215
+ className: "".concat(preCls, "-progress-bar"),
216
+ style: {
217
+ width: progress
218
+ }
219
+ })
220
+ }), /*#__PURE__*/_jsxs("div", {
221
+ className: "".concat(preCls, "-file-item-feedback"),
222
+ children: [/*#__PURE__*/_jsx("div", {
223
+ className: "".concat(preCls, "-file-item-percent"),
224
+ children: progress
225
+ }), props.validation && renderValidation(fileListItem)]
226
+ })]
227
+ })]
228
+ }, fileListItem.uid);
229
+ if (props.itemRender) {
230
+ return props.itemRender({
231
+ remove: onDeleteFileList,
232
+ reUpload: handleReUpload,
233
+ fileItem: fileListItem,
234
+ orignalNode: orignalNode
235
+ });
236
+ }
237
+ return orignalNode;
238
+ };
239
+ return /*#__PURE__*/_jsxs("div", {
240
+ className: preCls,
241
+ onDrop: function onDrop(e) {
242
+ e.preventDefault();
243
+ },
244
+ id: id,
245
+ children: [/*#__PURE__*/_jsx("input", {
246
+ accept: accept,
247
+ type: "file",
248
+ style: {
249
+ display: 'none'
250
+ },
251
+ multiple: multiple,
252
+ ref: inputFileRef,
253
+ onChange: function onChange(e) {
254
+ handleUploadFiles(e.target.files || []);
255
+ e.target.value = '';
256
+ }
257
+ }), /*#__PURE__*/_jsx("input", {
258
+ accept: accept,
259
+ type: "file",
260
+ style: {
261
+ display: 'none'
262
+ },
263
+ ref: inputFileReplaceRef,
264
+ onChange: function onChange(e) {
265
+ handleUploadFiles(e.target.files || [], {
266
+ replace: true,
267
+ replaceId: inputRelaceId.current
268
+ });
269
+ inputRelaceId.current = '';
270
+ e.target.value = '';
271
+ }
272
+ }), maxCount > 0 && fileList.length < maxCount && renderDragger(), fileList.map(function (fileListItem) {
273
+ return renderFileListItem(fileListItem);
274
+ })]
275
+ });
276
+ };
277
+ export default UploadFile;
@@ -0,0 +1,274 @@
1
+ @import '../styles/var.less';
2
+
3
+ @preCls: ~'@{prefix}-upload-file';
4
+
5
+ // 主色
6
+ @upload-file-color-primary: var(--cm-upload-file-color-primary, #126bf1);
7
+ @upload-file-color-primary-hover: var(--cm-upload-file-color-primary-hover, #3b90ff);
8
+ @upload-file-color-primary-active: var(--cm-upload-file-color-primary-active, #3b90ff);
9
+ @upload-file-color-error: var(--cm-upload-file-color-error, #e04667);
10
+ @upload-file-color-split: var(--cm-upload-file-color-split, #777f93);
11
+ @upload-file-color-validating: var(--cm-upload-file-color-validating, #049a6d);
12
+ @upload-file-color-validating-success: var(--cm-upload-file-color-validating-success, #049a6d);
13
+ @upload-file-color-validating-error: var(
14
+ --cm-upload-file-color-validating-error,
15
+ @upload-file-color-error
16
+ );
17
+
18
+ // 背景
19
+ @upload-file-bg-color: var(--cm-upload-file-bg-color, #fff);
20
+
21
+ // border
22
+ @upload-file-border-color: var(--cm-upload-file-border-color, #d5d8dc);
23
+ @upload-file-border-color-hover: var(
24
+ --cm-upload-file-border-color-hover,
25
+ @upload-file-color-primary
26
+ );
27
+ @upload-file-border-color-active: var(
28
+ --cm-upload-file-border-color-active,
29
+ @upload-file-color-primary-active
30
+ );
31
+
32
+ // 上传按钮
33
+ @upload-file-btn-color: var(--cm-upload-file-btn-color, @upload-file-color-primary);
34
+ @upload-file-btn-color-hover: var(
35
+ --cm-upload-file-btn-color-hover,
36
+ @upload-file-color-primary-hover
37
+ );
38
+ @upload-file-btn-color-active: var(
39
+ --cm-upload-file-btn-color-active,
40
+ @upload-file-color-primary-active
41
+ );
42
+
43
+ // 文字颜色
44
+ @upload-file-text-color1: var(--cm-upload-file-text-color-1, #777f93);
45
+ @upload-file-text-color2: var(--cm-upload-file-text-color-2, #777f93);
46
+ @upload-file-text-color3: var(--cm-upload-file-text-color-3, #777f93);
47
+
48
+ // 文件列表
49
+ @upload-file-item-bg-color: var(--cm-upload-file-item-bg-color, @upload-file-bg-color);
50
+ @upload-file-item-border-color: var(--cm-upload-file-item-border-color, @upload-file-border-color);
51
+ @upload-file-item-progress-bg-color: var(--cm-upload-file-item-progress-bg-color, transparent);
52
+ @upload-file-item-progress-color: var(
53
+ --cm-upload-file-item-progress-color,
54
+ @upload-file-color-primary
55
+ );
56
+ @upload-file-item-progress-color-error: var(
57
+ --cm-upload-file-item-progress-color-error,
58
+ @upload-file-color-error
59
+ );
60
+
61
+ // 操作按钮
62
+ @upload-file-action-icon-color: var(--cm-upload-file-action-icon-color, #9a9c9e);
63
+
64
+ .@{preCls} {
65
+ position: relative;
66
+ box-sizing: border-box;
67
+
68
+ svg {
69
+ display: block;
70
+ }
71
+
72
+ &-dragger-container {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ height: 144px;
77
+ background-color: @upload-file-bg-color;
78
+
79
+ &-has-file-list {
80
+ margin-bottom: 8px;
81
+ }
82
+
83
+ border: 1px dashed @upload-file-border-color;
84
+ border-radius: 4px;
85
+ cursor: pointer;
86
+
87
+ &:hover {
88
+ border-color: @upload-file-border-color-hover;
89
+ }
90
+
91
+ &:active {
92
+ border-color: @upload-file-border-color-active;
93
+ }
94
+ }
95
+
96
+ &-dragger-top {
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: center;
100
+ }
101
+
102
+ &-text-btn {
103
+ flex: 0 0 auto;
104
+ font-size: 14px;
105
+ line-height: 22px;
106
+ color: @upload-file-btn-color;
107
+ cursor: pointer;
108
+ user-select: none;
109
+
110
+ &:hover {
111
+ color: @upload-file-btn-color-hover;
112
+ }
113
+
114
+ &:active {
115
+ color: @upload-file-btn-color-active;
116
+ }
117
+ }
118
+
119
+ &-split {
120
+ color: @upload-file-color-split;
121
+ font-size: 16px;
122
+ margin: 0 4px;
123
+ }
124
+
125
+ &-drag-text {
126
+ font-size: 14px;
127
+ color: @upload-file-text-color2;
128
+ }
129
+
130
+ &-support-ext {
131
+ text-align: center;
132
+ font-size: 14px;
133
+ line-height: 22px;
134
+ color: @upload-file-text-color3;
135
+ margin-top: 8px;
136
+ }
137
+
138
+ &-dragger-tip {
139
+ font-size: 14px;
140
+ line-height: 22px;
141
+ color: @upload-file-text-color2;
142
+ }
143
+
144
+ &-file-item {
145
+ display: flex;
146
+ align-items: center;
147
+ justify-content: space-between;
148
+ height: 120px;
149
+ padding: 0 32px;
150
+ border-radius: 4px;
151
+ border: 1px solid @upload-file-border-color;
152
+ box-sizing: border-box;
153
+ background-color: @upload-file-item-bg-color;
154
+
155
+ &-status-error {
156
+ border-style: dashed;
157
+ border-color: @upload-file-item-progress-color-error;
158
+
159
+ .@{preCls}-progress-bar {
160
+ background-color: @upload-file-item-progress-color-error;
161
+ }
162
+ }
163
+
164
+ &:not(:last-child) {
165
+ margin-bottom: 8px;
166
+ }
167
+
168
+ &-left {
169
+ flex: 0 0 auto;
170
+ margin-right: 23px;
171
+ }
172
+
173
+ &-right {
174
+ flex: 1;
175
+ }
176
+
177
+ &-name {
178
+ display: block;
179
+ flex: 1;
180
+ width: 0;
181
+ min-width: 0;
182
+ margin-right: 16px;
183
+ font-size: 16px;
184
+ line-height: 22px;
185
+ color: @upload-file-text-color1;
186
+ }
187
+
188
+ &-feedback {
189
+ display: flex;
190
+ align-items: center;
191
+ justify-content: space-between;
192
+ }
193
+
194
+ &-percent {
195
+ font-size: 14px;
196
+ line-height: 20px;
197
+ color: @upload-file-text-color2;
198
+ }
199
+
200
+ &-header {
201
+ display: flex;
202
+ align-items: center;
203
+ justify-content: space-between;
204
+ }
205
+
206
+ &-extra {
207
+ flex: 0 0 auto;
208
+ display: flex;
209
+ align-items: center;
210
+ }
211
+
212
+ &-action-btn {
213
+ --cm-icon-btn-primary-color: @upload-file-action-icon-color;
214
+
215
+ width: 16px;
216
+ flex: 0 0 auto;
217
+ margin-left: 18px;
218
+ cursor: pointer;
219
+ }
220
+ }
221
+
222
+ &-file-item-validate {
223
+ font-size: 14px;
224
+ font-style: normal;
225
+ font-weight: 400;
226
+ line-height: 20px;
227
+ }
228
+
229
+ &-validate-status--error {
230
+ color: @upload-file-color-validating-error;
231
+ }
232
+
233
+ &-validate-status--validating {
234
+ color: @upload-file-color-validating;
235
+ }
236
+
237
+ &-validate-status--success {
238
+ color: @upload-file-color-validating-success;
239
+ }
240
+
241
+ &-ext-svg {
242
+ width: 66px;
243
+ height: auto;
244
+ color: @upload-file-color-primary;
245
+ }
246
+
247
+ .ant-image {
248
+ width: 66px;
249
+ height: 66px;
250
+ border: 1px solid @upload-file-border-color;
251
+ border-radius: 4px;
252
+
253
+ img {
254
+ display: block;
255
+ width: 100%;
256
+ height: 100%;
257
+ object-fit: cover;
258
+ }
259
+ }
260
+
261
+ &-progress {
262
+ height: 8px;
263
+ border-radius: 4px;
264
+ background-color: @upload-file-item-progress-bg-color;
265
+ overflow: hidden;
266
+ margin: 8px 0;
267
+
268
+ &-bar {
269
+ height: 100%;
270
+ background-color: @upload-file-item-progress-color;
271
+ transition: all 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
272
+ }
273
+ }
274
+ }
@@ -0,0 +1,63 @@
1
+ import { UploadFile } from 'antd';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { ReactNode } from 'react';
4
+ export interface FileListItemProps extends UploadFile {
5
+ file?: File;
6
+ abort?: () => any;
7
+ validationStatus?: 'validating' | 'success' | 'error';
8
+ validationPercent?: number;
9
+ validationError?: Error;
10
+ validationAbort?: () => any;
11
+ blobUrl?: string;
12
+ }
13
+ export interface UploadFileProps {
14
+ uploadConcurrency?: number;
15
+ id?: string;
16
+ name?: string;
17
+ accepts?: string[];
18
+ acceptsJoinCharacter?: string;
19
+ data?: Record<string, any>;
20
+ value?: FileListItemProps[];
21
+ onRemove?: (fileItem: FileListItemProps) => any;
22
+ onChange?: (fileList: FileListItemProps[]) => any;
23
+ beforeUpload?: (file: File) => Promise<any>;
24
+ customRequest?: (options: {
25
+ onProgress: (event: {
26
+ percent: number;
27
+ }) => any;
28
+ onError: (e: Error, body?: any) => any;
29
+ onSuccess: (body: any) => any;
30
+ file: File;
31
+ fileItem: FileListItemProps;
32
+ signal: AbortSignal;
33
+ }) => {
34
+ abort: () => any;
35
+ } | void;
36
+ uploadRequest?: (formData: FormData, options: AxiosRequestConfig, fileItem: FileListItemProps) => Promise<string | {
37
+ url?: string;
38
+ [key: string]: any;
39
+ }>;
40
+ itemRender?: (options: {
41
+ remove: (uid: string) => any;
42
+ reUpload: (uid: string) => any;
43
+ fileItem: FileListItemProps;
44
+ orignalNode: ReactNode;
45
+ }) => ReactNode;
46
+ getIcon?: (ext: string, fileItem: FileListItemProps) => ReactNode;
47
+ maxCount?: number;
48
+ maxFileSize?: number;
49
+ multiple?: boolean;
50
+ dragable?: boolean;
51
+ children?: ReactNode | ReactNode[];
52
+ validation?: {
53
+ validateRequest: (options: {
54
+ onProgress: (percent: number) => void;
55
+ onSuccess: () => void;
56
+ onError: (e: Error) => void;
57
+ axiosRequestConfig: AxiosRequestConfig;
58
+ fileItem: FileListItemProps;
59
+ }) => {
60
+ abort: () => any;
61
+ } | void;
62
+ };
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function formatBitString(bit: number): string;
@@ -0,0 +1,9 @@
1
+ export function formatBitString(bit) {
2
+ var units = ['B', 'K', 'M', 'G'];
3
+ var base = 1024;
4
+ for (var i = 0; i < units.length; i++) {
5
+ var n = Math.pow(base, i + 1);
6
+ if (bit < n) return "".concat(+(bit / (n / 1024)).toFixed(2), " ").concat(units[i]);
7
+ }
8
+ return "".concat(+(bit / Math.pow(1024, 3)).toFixed(2), " T");
9
+ }
@@ -0,0 +1 @@
1
+ export declare function getExt(fileName: string): string;
@@ -0,0 +1,6 @@
1
+ export function getExt(fileName) {
2
+ if (!fileName) return '';
3
+ var lastIndex = fileName.lastIndexOf('.');
4
+ if (lastIndex === -1) return '';
5
+ return fileName.slice(lastIndex + 1);
6
+ }
@@ -0,0 +1 @@
1
+ export declare function isImage(ext: string, type: string): boolean;
@@ -0,0 +1,8 @@
1
+ var imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
2
+ var imageMimeTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp', 'image/bmp', 'image/svg+xml'];
3
+ export function isImage(ext, type) {
4
+ if (imageExtensions.includes(ext)) {
5
+ return true;
6
+ }
7
+ return imageMimeTypes.includes(type);
8
+ }
@@ -0,0 +1 @@
1
+ export declare function normalizeExt(ext: string): string;
@@ -0,0 +1,4 @@
1
+ export function normalizeExt(ext) {
2
+ if (ext[0] === '.') return ext;
3
+ return '.' + ext;
4
+ }
@@ -0,0 +1,13 @@
1
+ export declare function validateFileTypes(file: File, types: string[]): Promise<{
2
+ isValid: boolean;
3
+ fileInfo: {
4
+ extension: string;
5
+ mimeType: string;
6
+ description: string;
7
+ };
8
+ }>;
9
+ export declare function getFileInfo(file: File): Promise<{
10
+ extension: string;
11
+ mimeType: string;
12
+ description: string;
13
+ }>;