assui 3.1.55 → 3.1.57

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 (35) hide show
  1. package/es/index.d.ts +2 -0
  2. package/es/index.js +2 -1
  3. package/es/label-select/index.d.ts +1 -0
  4. package/es/label-select/index.js +14 -3
  5. package/es/label-select/style/index.css +1 -0
  6. package/es/label-select/style/index.less +1 -0
  7. package/es/multipart-upload/getMultipartUploadHandler.d.ts +2 -0
  8. package/es/multipart-upload/getMultipartUploadHandler.js +38 -0
  9. package/es/multipart-upload/index.d.ts +43 -0
  10. package/es/multipart-upload/index.js +220 -0
  11. package/es/multipart-upload/parse2RegexOption.d.ts +13 -0
  12. package/es/multipart-upload/parse2RegexOption.js +46 -0
  13. package/es/multipart-upload/style/index.css +1323 -0
  14. package/es/multipart-upload/style/index.d.ts +2 -0
  15. package/es/multipart-upload/style/index.js +2 -0
  16. package/es/multipart-upload/style/index.less +102 -0
  17. package/es/style/variables.less +6 -0
  18. package/lib/index.d.ts +2 -0
  19. package/lib/index.js +8 -1
  20. package/lib/label-select/index.d.ts +1 -0
  21. package/lib/label-select/index.js +14 -3
  22. package/lib/label-select/style/index.css +1 -0
  23. package/lib/label-select/style/index.less +1 -0
  24. package/lib/multipart-upload/getMultipartUploadHandler.d.ts +2 -0
  25. package/lib/multipart-upload/getMultipartUploadHandler.js +43 -0
  26. package/lib/multipart-upload/index.d.ts +43 -0
  27. package/lib/multipart-upload/index.js +263 -0
  28. package/lib/multipart-upload/parse2RegexOption.d.ts +13 -0
  29. package/lib/multipart-upload/parse2RegexOption.js +56 -0
  30. package/lib/multipart-upload/style/index.css +1323 -0
  31. package/lib/multipart-upload/style/index.d.ts +2 -0
  32. package/lib/multipart-upload/style/index.js +7 -0
  33. package/lib/multipart-upload/style/index.less +102 -0
  34. package/lib/style/variables.less +6 -0
  35. package/package.json +2 -2
package/es/index.d.ts CHANGED
@@ -80,3 +80,5 @@ export type { FlexProps } from './flex';
80
80
  export { default as Flex } from './flex';
81
81
  export type { LabelConditionSelectInputProps } from './label-condition-select-input';
82
82
  export { default as LabelConditionSelectInput } from './label-condition-select-input';
83
+ export type { MultipartUploadProps } from './multipart-upload';
84
+ export { default as MultipartUpload } from './multipart-upload';
package/es/index.js CHANGED
@@ -40,4 +40,5 @@ export { default as RichTextEditor } from './rich-text-editor';
40
40
  export { default as BeautifulDnd } from './beautiful-dnd';
41
41
  export { default as Resizable } from './resizable';
42
42
  export { default as Flex } from './flex';
43
- export { default as LabelConditionSelectInput } from './label-condition-select-input';
43
+ export { default as LabelConditionSelectInput } from './label-condition-select-input';
44
+ export { default as MultipartUpload } from './multipart-upload';
@@ -4,6 +4,7 @@ declare const Option: import("rc-select/lib/Option").OptionFC;
4
4
  export { Option };
5
5
  export interface LabelSelectProps extends SelectProps {
6
6
  label?: React.ReactNode;
7
+ onBlur?: (value: SelectProps['value']) => void;
7
8
  }
8
9
  declare const ForwardRefLabelSelect: React.ForwardRefExoticComponent<LabelSelectProps & React.RefAttributes<unknown>>;
9
10
  export default ForwardRefLabelSelect;
@@ -37,7 +37,9 @@ var __read = this && this.__read || function (o, n) {
37
37
  import React from 'react';
38
38
  import useControllableValue from "ahooks/es/useControllableValue";
39
39
  import Select from "antd/es/select";
40
- import { isUndefined, isNull } from 'lodash';
40
+ import isArray from 'lodash/isArray';
41
+ import isUndefined from 'lodash/isUndefined';
42
+ import isNull from 'lodash/isNull';
41
43
  import classNames from 'classnames';
42
44
  import ArrowDropDownFilled from "a-icons/es/ArrowDropDownFilled";
43
45
  import omit from 'lodash/omit';
@@ -45,7 +47,8 @@ var Option = Select.Option;
45
47
  export { Option };
46
48
  var LabelSelect = function LabelSelect(props, ref) {
47
49
  var className = props.className,
48
- label = props.label;
50
+ label = props.label,
51
+ onBlur = props.onBlur;
49
52
  var selectRef = React.useRef(null);
50
53
  var _a = __read(useControllableValue(props, {
51
54
  valuePropName: 'open',
@@ -71,10 +74,13 @@ var LabelSelect = function LabelSelect(props, ref) {
71
74
  var onDropdownVisibleChange = function onDropdownVisibleChange(nextOpen) {
72
75
  setOpen(nextOpen);
73
76
  };
77
+ var handleBlur = function handleBlur() {
78
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(value);
79
+ };
74
80
  return /*#__PURE__*/React.createElement("div", {
75
81
  className: classNames({
76
82
  'label-select': true,
77
- 'label-select-label-scale': open || !isUndefined(value) && !isNull(value)
83
+ 'label-select-label-scale': open || !isArray(value) && !isUndefined(value) && !isNull(value) || isArray(value) && value.length
78
84
  }, className)
79
85
  }, /*#__PURE__*/React.createElement(Select, __assign({
80
86
  maxTagCount: 3,
@@ -85,6 +91,11 @@ var LabelSelect = function LabelSelect(props, ref) {
85
91
  size: "large",
86
92
  className: "label-select-selector",
87
93
  onChange: handleChange,
94
+ onBlur: handleBlur,
95
+ onDeselect: function onDeselect() {
96
+ var _a;
97
+ (_a = selectRef.current) === null || _a === void 0 ? void 0 : _a.focus();
98
+ },
88
99
  onDropdownVisibleChange: onDropdownVisibleChange,
89
100
  suffixIcon: /*#__PURE__*/React.createElement(ArrowDropDownFilled, null)
90
101
  })), /*#__PURE__*/React.createElement("label", {
@@ -1256,6 +1256,7 @@ html {
1256
1256
  .label-select .ant-select-multiple .ant-select-selection-overflow {
1257
1257
  display: flex;
1258
1258
  width: 100%;
1259
+ height: 36px;
1259
1260
  transform: translateY(8px);
1260
1261
  }
1261
1262
  .label-select .ant-select-multiple .ant-select-selection-overflow-item {
@@ -30,6 +30,7 @@
30
30
  .@{ant-prefix}-select-selection-overflow {
31
31
  display: flex;
32
32
  width: 100%;
33
+ height: 36px;
33
34
  transform: translateY(8px);
34
35
  }
35
36
 
@@ -0,0 +1,2 @@
1
+ declare const getMultipartUploadHandler: (resultUrl: string) => (file: Blob, progress: (v: number) => any) => Promise<unknown>;
2
+ export default getMultipartUploadHandler;
@@ -0,0 +1,38 @@
1
+ /* eslint-disable prefer-promise-reject-errors */
2
+ import { localStorage } from 'aa-utils';
3
+ var getMultipartUploadHandler = function getMultipartUploadHandler(resultUrl) {
4
+ var multipartUploadHandler = function multipartUploadHandler(file, progress) {
5
+ return new Promise(function (resolve, reject) {
6
+ var xhr = new XMLHttpRequest();
7
+ xhr.open('POST', resultUrl);
8
+ xhr.setRequestHeader('token', localStorage.get('token') || '');
9
+ xhr.upload.onprogress = function (e) {
10
+ progress && progress(e.loaded / e.total * 100);
11
+ };
12
+ xhr.onload = function () {
13
+ if (xhr.status === 403) {
14
+ reject("HTTP Error: ".concat(xhr.status));
15
+ return;
16
+ }
17
+ if (xhr.status < 200 || xhr.status >= 300) {
18
+ reject("HTTP Error: ".concat(xhr.status));
19
+ return;
20
+ }
21
+ var json = JSON.parse(xhr.responseText);
22
+ if (!json || json.header.code !== 200) {
23
+ reject("Invalid JSON: ".concat(xhr.responseText));
24
+ return;
25
+ }
26
+ resolve(json.body);
27
+ };
28
+ xhr.onerror = function () {
29
+ reject("Image upload failed due to a XHR Transport error. Code: ".concat(xhr.status));
30
+ };
31
+ var formData = new FormData();
32
+ formData.append('file', file);
33
+ xhr.send(formData);
34
+ });
35
+ };
36
+ return multipartUploadHandler;
37
+ };
38
+ export default getMultipartUploadHandler;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import type { UploadProps } from 'rc-upload';
3
+ export interface RcFile extends File {
4
+ uid: string;
5
+ }
6
+ export interface UploadProgressEvent extends ProgressEvent {
7
+ percent: number;
8
+ }
9
+ export interface MultipartUploadProps extends Omit<UploadProps, 'onSuccess'> {
10
+ value?: string;
11
+ wrapperClassName?: string;
12
+ className?: string;
13
+ fileName?: string;
14
+ /** 上传文字 */
15
+ uploadText?: string;
16
+ onSuccess?: (res: string, fileName: string) => void;
17
+ uploadIcon: React.ReactElement;
18
+ cancelUpload?: () => void;
19
+ /** 分片大小 */
20
+ chunkSize?: number;
21
+ /** 第一步 获取ID */
22
+ getInitUploadIdAPI: ({ fileName }: {
23
+ fileName: string;
24
+ }) => Promise<string>;
25
+ /** 第二步 获取url 进行分片上传 */
26
+ getInProgressUploadUrl: ({ fileName, partNumber, uploadId, }: {
27
+ fileName: string;
28
+ partNumber: number;
29
+ uploadId: string;
30
+ }) => string;
31
+ /** 第三步 合并上传文件 完成上传 */
32
+ completeRequest: ({ fileName, uploadId, list, }: {
33
+ fileName: string;
34
+ uploadId: string;
35
+ list: string[];
36
+ }) => Promise<string>;
37
+ errorCatch?: (error: any) => void;
38
+ }
39
+ declare const MultipartUpload: {
40
+ (props: MultipartUploadProps): JSX.Element;
41
+ displayName: string;
42
+ };
43
+ export default MultipartUpload;
@@ -0,0 +1,220 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) {
6
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
7
+ }
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = this && this.__rest || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) {
16
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
17
+ }
18
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ var __read = this && this.__read || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o),
27
+ r,
28
+ ar = [],
29
+ e;
30
+ try {
31
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
32
+ ar.push(r.value);
33
+ }
34
+ } catch (error) {
35
+ e = {
36
+ error: error
37
+ };
38
+ } finally {
39
+ try {
40
+ if (r && !r.done && (m = i["return"])) m.call(i);
41
+ } finally {
42
+ if (e) throw e.error;
43
+ }
44
+ }
45
+ return ar;
46
+ };
47
+ import React, { useState, useRef } from 'react';
48
+ import Upload from 'rc-upload';
49
+ import { useMount, useUpdateEffect } from 'ahooks';
50
+ import classNames from 'classnames';
51
+ import { Progress } from 'antd';
52
+ import { CloseOutlined, CirclePlusFilled } from 'a-icons';
53
+ import getMultipartUploadHandler from './getMultipartUploadHandler';
54
+ var MultipartUpload = function MultipartUpload(props) {
55
+ var className = props.className,
56
+ wrapperClassName = props.wrapperClassName,
57
+ accept = props.accept,
58
+ method = props.method,
59
+ _a = props.fileName,
60
+ fileName = _a === void 0 ? '' : _a,
61
+ onSuccess = props.onSuccess,
62
+ onError = props.onError,
63
+ onStart = props.onStart,
64
+ cancelUpload = props.cancelUpload,
65
+ uploadIcon = props.uploadIcon,
66
+ disabled = props.disabled,
67
+ getInProgressUploadUrl = props.getInProgressUploadUrl,
68
+ getInitUploadIdAPI = props.getInitUploadIdAPI,
69
+ completeRequest = props.completeRequest,
70
+ chunkSize = props.chunkSize,
71
+ uploadText = props.uploadText,
72
+ customRequest = props.customRequest,
73
+ value = props.value,
74
+ errorCatch = props.errorCatch,
75
+ restProps = __rest(props, ["className", "wrapperClassName", "accept", "method", "fileName", "onSuccess", "onError", "onStart", "cancelUpload", "uploadIcon", "disabled", "getInProgressUploadUrl", "getInitUploadIdAPI", "completeRequest", "chunkSize", "uploadText", "customRequest", "value", "errorCatch"]);
76
+ var fileNameRef = useRef('');
77
+ var uploadRef = useRef();
78
+ var fileRef = useRef();
79
+ var uploadIdRef = useRef('');
80
+ var _b = __read(useState('init'), 2),
81
+ uploadStatus = _b[0],
82
+ setUploadStatus = _b[1];
83
+ var _c = __read(useState(0), 2),
84
+ uploadPercent = _c[0],
85
+ setUploadPercent = _c[1];
86
+ var resChunkSize = chunkSize || 1024 * 1024 * 50; // 50MB
87
+ var currentChunk = 0;
88
+ var totalChunks = 0;
89
+ var uploadList = [];
90
+ useUpdateEffect(function () {
91
+ if (value) {
92
+ setUploadStatus('done');
93
+ } else {
94
+ setUploadStatus('init');
95
+ }
96
+ }, [value]);
97
+ useMount(function () {
98
+ fileNameRef.current = fileName;
99
+ });
100
+ useUpdateEffect(function () {
101
+ fileNameRef.current = fileName;
102
+ }, [fileName]);
103
+ var handleStart = function handleStart(file) {
104
+ fileRef.current = file;
105
+ setUploadPercent(0);
106
+ fileNameRef.current = file.name;
107
+ totalChunks = Math.ceil(fileRef.current.size / resChunkSize);
108
+ setUploadStatus('uploading');
109
+ onStart && onStart(file);
110
+ };
111
+ var handleError = function handleError(error, ret, file) {
112
+ setUploadStatus('init');
113
+ onError && onError(error, ret, file);
114
+ };
115
+ var uploadCls = classNames(className, {
116
+ 'not-upload-init': uploadStatus !== 'init'
117
+ });
118
+ var handleCancelUpload = function handleCancelUpload() {
119
+ var _a;
120
+ if (fileRef.current) {
121
+ (_a = uploadRef.current) === null || _a === void 0 ? void 0 : _a.abort(fileRef.current);
122
+ setUploadStatus('init');
123
+ cancelUpload && cancelUpload();
124
+ }
125
+ };
126
+ var progress = function progress(progressNumber) {
127
+ var currentProgressNumber = parseInt("".concat(progressNumber * (currentChunk + 1) / totalChunks), 10);
128
+ if (currentProgressNumber >= currentChunk / totalChunks * 100) {
129
+ setUploadPercent(currentProgressNumber);
130
+ }
131
+ };
132
+ var uploadNextChunk = function uploadNextChunk() {
133
+ /** 第二步 获取url 进行分片上传 */
134
+ if (fileRef.current) {
135
+ var resultUrl = getInProgressUploadUrl({
136
+ fileName: fileNameRef.current,
137
+ partNumber: currentChunk + 1,
138
+ uploadId: uploadIdRef.current
139
+ });
140
+ var multipartUploadHandler = getMultipartUploadHandler(resultUrl);
141
+ var start = currentChunk * resChunkSize;
142
+ var end = Math.min(fileRef.current.size, start + resChunkSize);
143
+ var chunk = fileRef.current.slice(start, end);
144
+ multipartUploadHandler(chunk, progress).then(function (res) {
145
+ uploadList.push(res);
146
+ currentChunk += 1;
147
+ if (currentChunk < totalChunks) {
148
+ uploadNextChunk();
149
+ } else {
150
+ /** 分片上传完成 进行文件合并 上传完成 */
151
+ completeRequest({
152
+ fileName: fileNameRef.current,
153
+ uploadId: uploadIdRef.current,
154
+ list: uploadList
155
+ }).then(function (fileUrl) {
156
+ setUploadStatus('done');
157
+ onSuccess && onSuccess(fileUrl, fileNameRef.current);
158
+ });
159
+ }
160
+ })["catch"](function (error) {
161
+ errorCatch && errorCatch(error);
162
+ });
163
+ }
164
+ };
165
+ var customMultipartRequest = function customMultipartRequest() {
166
+ if (fileRef.current) {
167
+ totalChunks = Math.ceil(fileRef.current.size / resChunkSize);
168
+ /** 第一步 获取ID */
169
+ getInitUploadIdAPI({
170
+ fileName: fileNameRef.current
171
+ }).then(function (id) {
172
+ uploadIdRef.current = id;
173
+ uploadNextChunk();
174
+ });
175
+ }
176
+ };
177
+ return /*#__PURE__*/React.createElement("div", {
178
+ className: classNames('multipart-upload-container', wrapperClassName)
179
+ }, uploadStatus === 'uploading' && /*#__PURE__*/React.createElement("div", {
180
+ className: "multipart-uploading-container"
181
+ }, /*#__PURE__*/React.createElement("div", {
182
+ className: "multipart-package-icon-files"
183
+ }, uploadIcon, /*#__PURE__*/React.createElement("div", {
184
+ className: "multipart-upload-file-name",
185
+ title: fileNameRef.current
186
+ }, fileNameRef.current)), /*#__PURE__*/React.createElement(Progress, {
187
+ className: "multipart-upload-progress",
188
+ percent: uploadPercent,
189
+ size: "small",
190
+ status: "active"
191
+ }), /*#__PURE__*/React.createElement("div", {
192
+ className: "multipart-package-upload-close-button",
193
+ onClick: handleCancelUpload
194
+ }, /*#__PURE__*/React.createElement(CloseOutlined, null))), uploadStatus === 'done' && /*#__PURE__*/React.createElement("div", {
195
+ className: "multipart-upload-container"
196
+ }, /*#__PURE__*/React.createElement("div", {
197
+ className: "multipart-upload-icon-files"
198
+ }, uploadIcon, /*#__PURE__*/React.createElement("div", {
199
+ className: "multipart-upload-file-name",
200
+ title: fileNameRef.current
201
+ }, fileNameRef.current))), /*#__PURE__*/React.createElement(Upload, __assign({
202
+ ref: function ref(uploader) {
203
+ uploadRef.current = uploader;
204
+ },
205
+ name: "file",
206
+ accept: accept,
207
+ disabled: disabled,
208
+ method: method,
209
+ className: uploadCls,
210
+ onStart: handleStart,
211
+ onError: handleError,
212
+ customRequest: customMultipartRequest
213
+ }, restProps), uploadStatus === 'init' && /*#__PURE__*/React.createElement("div", {
214
+ className: classNames('multipart-uploading-file-container', {
215
+ 'multipart-uploading-file-container-disabled': disabled
216
+ })
217
+ }, /*#__PURE__*/React.createElement(CirclePlusFilled, null), /*#__PURE__*/React.createElement("span", null, uploadText))));
218
+ };
219
+ MultipartUpload.displayName = 'MultipartUpload';
220
+ export default MultipartUpload;
@@ -0,0 +1,13 @@
1
+ export interface RegexOptionType {
2
+ isValid: boolean;
3
+ replacement: string;
4
+ }
5
+ declare type regexParamsType = RegExp | string | {
6
+ pattern: RegExp;
7
+ replacement?: string;
8
+ };
9
+ export interface ResultType extends RegexOptionType {
10
+ pattern: RegExp;
11
+ }
12
+ declare const parse2RegexOption: (regex: regexParamsType) => ResultType;
13
+ export default parse2RegexOption;
@@ -0,0 +1,46 @@
1
+ var __assign = this && this.__assign || function () {
2
+ __assign = Object.assign || function (t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) {
6
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
7
+ }
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ import isRegExp from 'lodash/isRegExp';
14
+ import isString from 'lodash/isString';
15
+ import isObject from 'lodash/isObject';
16
+ var defaultOptionValues = {
17
+ isValid: true,
18
+ replacement: ''
19
+ };
20
+ var parseRegex2RegexOption = function parseRegex2RegexOption(regex, options) {
21
+ return __assign(__assign(__assign({}, defaultOptionValues), {
22
+ pattern: regex
23
+ }), options);
24
+ };
25
+ var parseString2RegexOption = function parseString2RegexOption(regexString, options) {
26
+ return parseRegex2RegexOption(new RegExp(regexString), options);
27
+ };
28
+ var parse2RegexOption = function parse2RegexOption(regex) {
29
+ if (isRegExp(regex)) {
30
+ return parseRegex2RegexOption(regex);
31
+ }
32
+ if (isString(regex)) {
33
+ return parseString2RegexOption(regex);
34
+ }
35
+ if (isObject(regex)) {
36
+ return __assign(__assign(__assign({}, defaultOptionValues), {
37
+ isValid: !!regex.pattern
38
+ }), regex);
39
+ }
40
+ return {
41
+ isValid: false,
42
+ replacement: '',
43
+ pattern: /./
44
+ };
45
+ };
46
+ export default parse2RegexOption;