@xfe-repo/web-components 1.8.7 → 1.8.8

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.
package/dist/index.d.mts CHANGED
@@ -13,7 +13,7 @@ import * as antd_es__util_type from 'antd/es/_util/type';
13
13
  import { ColumnProps } from 'antd/es/table';
14
14
  import { DragEndEvent } from '@dnd-kit/core';
15
15
  import * as _ant_design_icons_lib_components_IconFont from '@ant-design/icons/lib/components/IconFont';
16
- import { UploadFile, UploadListType } from 'antd/es/upload/interface';
16
+ import { UploadFile, UploadListType, UploadProps } from 'antd/es/upload/interface';
17
17
  import { DrawerProps } from 'antd/lib/drawer';
18
18
  import { ModalProps } from 'antd/lib/modal';
19
19
  import dayjs, { Dayjs } from 'dayjs';
@@ -799,6 +799,7 @@ type FileUploadProps = {
799
799
  remote?: boolean;
800
800
  pastable?: boolean;
801
801
  deleteConfirm?: boolean;
802
+ beforeUpload?: UploadProps['beforeUpload'];
802
803
  };
803
804
  declare const FileUpload: (props: FileUploadProps) => react_jsx_runtime.JSX.Element;
804
805
 
@@ -982,6 +983,7 @@ type EffectFileUploadProps = {
982
983
  remote?: boolean;
983
984
  pastable?: boolean;
984
985
  deleteConfirm?: boolean;
986
+ beforeUpload?: UploadProps['beforeUpload'];
985
987
  disabled?: boolean;
986
988
  needSave?: boolean;
987
989
  uploadOnAdd?: boolean;
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ import * as antd_es__util_type from 'antd/es/_util/type';
13
13
  import { ColumnProps } from 'antd/es/table';
14
14
  import { DragEndEvent } from '@dnd-kit/core';
15
15
  import * as _ant_design_icons_lib_components_IconFont from '@ant-design/icons/lib/components/IconFont';
16
- import { UploadFile, UploadListType } from 'antd/es/upload/interface';
16
+ import { UploadFile, UploadListType, UploadProps } from 'antd/es/upload/interface';
17
17
  import { DrawerProps } from 'antd/lib/drawer';
18
18
  import { ModalProps } from 'antd/lib/modal';
19
19
  import dayjs, { Dayjs } from 'dayjs';
@@ -799,6 +799,7 @@ type FileUploadProps = {
799
799
  remote?: boolean;
800
800
  pastable?: boolean;
801
801
  deleteConfirm?: boolean;
802
+ beforeUpload?: UploadProps['beforeUpload'];
802
803
  };
803
804
  declare const FileUpload: (props: FileUploadProps) => react_jsx_runtime.JSX.Element;
804
805
 
@@ -982,6 +983,7 @@ type EffectFileUploadProps = {
982
983
  remote?: boolean;
983
984
  pastable?: boolean;
984
985
  deleteConfirm?: boolean;
986
+ beforeUpload?: UploadProps['beforeUpload'];
985
987
  disabled?: boolean;
986
988
  needSave?: boolean;
987
989
  uploadOnAdd?: boolean;
package/dist/index.js CHANGED
@@ -3419,16 +3419,20 @@ var UploadGroup = (0, import_react29.memo)(function(props) {
3419
3419
  // src/EffectFileUpload/index.tsx
3420
3420
  var import_jsx_runtime27 = require("react/jsx-runtime");
3421
3421
  var _EffectFileUpload = (0, import_react30.memo)((0, import_react30.forwardRef)(function(props, ref) {
3422
- var value = props.value, defaultValue = props.defaultValue, files = props.files, needSave = props.needSave, extFormData = props.extFormData, max = props.max, accept = props.accept, disabled = props.disabled, className = props.className, name = props.name, remote = props.remote, pastable = props.pastable, deleteConfirm = props.deleteConfirm;
3422
+ var value = props.value, defaultValue = props.defaultValue, files = props.files, needSave = props.needSave, extFormData = props.extFormData, disabled = props.disabled, name = props.name, pastable = props.pastable, restProps = _object_without_properties(props, [
3423
+ "value",
3424
+ "defaultValue",
3425
+ "files",
3426
+ "needSave",
3427
+ "extFormData",
3428
+ "disabled",
3429
+ "name",
3430
+ "pastable"
3431
+ ]);
3423
3432
  var onChange = props.onChange, onFileChange = props.onFileChange, onUpload = props.onUpload, onUploadDone = props.onUploadDone, uploadOnAdd = props.uploadOnAdd;
3424
- var passProps = {
3425
- max: max,
3426
- accept: accept,
3427
- className: className,
3428
- remote: remote,
3429
- pastable: pastable,
3430
- deleteConfirm: deleteConfirm
3431
- };
3433
+ var passProps = _object_spread({
3434
+ pastable: pastable
3435
+ }, restProps);
3432
3436
  var _ref = _sliced_to_array((0, import_react30.useState)(files || transformSimpleFile2UploadFile(value)), 2), uploadFiles = _ref[0], setUploadFiles = _ref[1];
3433
3437
  var _ref1 = _sliced_to_array((0, import_react30.useState)(value || defaultValue || []), 2), simpleFiles = _ref1[0], setSimpleFiles = _ref1[1];
3434
3438
  var uploadTasksRef = (0, import_react30.useRef)([]);
@@ -3946,7 +3950,7 @@ var previewImage = function previewImage(file) {
3946
3950
  };
3947
3951
  var FileUpload = function FileUpload(props) {
3948
3952
  var _props_value = props.value, value = _props_value === void 0 ? [] : _props_value, defaultValue = props.defaultValue, onChange = props.onChange, disabled = props.disabled, classNames2 = props.classNames, children = props.children, accept = props.accept, _props_max = props.max, max = _props_max === void 0 ? 9 : _props_max, deleteConfirm = props.deleteConfirm;
3949
- var remote = props.remote, pastable = props.pastable, _props_multiple = props.multiple, multiple = _props_multiple === void 0 ? true : _props_multiple, _props_type = props.type, type = _props_type === void 0 ? "picture-card" : _props_type;
3953
+ var remote = props.remote, pastable = props.pastable, _props_multiple = props.multiple, multiple = _props_multiple === void 0 ? true : _props_multiple, _props_type = props.type, type = _props_type === void 0 ? "picture-card" : _props_type, beforeUpload = props.beforeUpload;
3950
3954
  var _ref = _sliced_to_array((0, import_react34.useState)(-1), 2), previewImageIndex = _ref[0], setPreviewImageIndex = _ref[1];
3951
3955
  var _ref1 = _sliced_to_array((0, import_react34.useState)(defaultValue || value || []), 2), fileList = _ref1[0], setFileList = _ref1[1];
3952
3956
  var _ref2 = _sliced_to_array((0, import_react34.useState)(), 2), bufferAddFile = _ref2[0], setBufferAddFile = _ref2[1];
@@ -4058,10 +4062,131 @@ var FileUpload = function FileUpload(props) {
4058
4062
  });
4059
4063
  })();
4060
4064
  }, []);
4061
- var handleBeforeUpload = (0, import_react34.useCallback)(function(_, files) {
4062
- void handleAdd(files);
4065
+ var handleBeforeUpload = (0, import_react34.useCallback)(function(file, files) {
4066
+ if (file !== files[0]) return false;
4067
+ if (!beforeUpload) {
4068
+ void handleAdd(files);
4069
+ return false;
4070
+ }
4071
+ var processFiles = function processFiles() {
4072
+ return _async_to_generator(function() {
4073
+ var processedFiles, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, originFile, result, processedFile, error, err;
4074
+ return _ts_generator(this, function(_state) {
4075
+ switch(_state.label){
4076
+ case 0:
4077
+ processedFiles = [];
4078
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
4079
+ _state.label = 1;
4080
+ case 1:
4081
+ _state.trys.push([
4082
+ 1,
4083
+ 8,
4084
+ 9,
4085
+ 10
4086
+ ]);
4087
+ _iterator = files[Symbol.iterator]();
4088
+ _state.label = 2;
4089
+ case 2:
4090
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
4091
+ 3,
4092
+ 7
4093
+ ];
4094
+ originFile = _step.value;
4095
+ _state.label = 3;
4096
+ case 3:
4097
+ _state.trys.push([
4098
+ 3,
4099
+ 5,
4100
+ ,
4101
+ 6
4102
+ ]);
4103
+ return [
4104
+ 4,
4105
+ beforeUpload(originFile, files)
4106
+ ];
4107
+ case 4:
4108
+ result = _state.sent();
4109
+ if (result === false || result === import_antd21.Upload.LIST_IGNORE) return [
4110
+ 3,
4111
+ 6
4112
+ ];
4113
+ if (_instanceof(result, Blob)) {
4114
+ processedFile = _instanceof(result, File) ? result : new File([
4115
+ result
4116
+ ], originFile.name, {
4117
+ type: result.type || originFile.type,
4118
+ lastModified: originFile.lastModified
4119
+ });
4120
+ Object.assign(processedFile, {
4121
+ uid: originFile.uid
4122
+ });
4123
+ processedFiles.push(processedFile);
4124
+ } else {
4125
+ processedFiles.push(originFile);
4126
+ }
4127
+ return [
4128
+ 3,
4129
+ 6
4130
+ ];
4131
+ case 5:
4132
+ error = _state.sent();
4133
+ console.error(error);
4134
+ return [
4135
+ 3,
4136
+ 6
4137
+ ];
4138
+ case 6:
4139
+ _iteratorNormalCompletion = true;
4140
+ return [
4141
+ 3,
4142
+ 2
4143
+ ];
4144
+ case 7:
4145
+ return [
4146
+ 3,
4147
+ 10
4148
+ ];
4149
+ case 8:
4150
+ err = _state.sent();
4151
+ _didIteratorError = true;
4152
+ _iteratorError = err;
4153
+ return [
4154
+ 3,
4155
+ 10
4156
+ ];
4157
+ case 9:
4158
+ try {
4159
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
4160
+ _iterator.return();
4161
+ }
4162
+ } finally{
4163
+ if (_didIteratorError) {
4164
+ throw _iteratorError;
4165
+ }
4166
+ }
4167
+ return [
4168
+ 7
4169
+ ];
4170
+ case 10:
4171
+ return [
4172
+ 4,
4173
+ handleAdd(processedFiles)
4174
+ ];
4175
+ case 11:
4176
+ _state.sent();
4177
+ return [
4178
+ 2
4179
+ ];
4180
+ }
4181
+ });
4182
+ })();
4183
+ };
4184
+ void processFiles();
4063
4185
  return false;
4064
- }, []);
4186
+ }, [
4187
+ beforeUpload,
4188
+ handleAdd
4189
+ ]);
4065
4190
  var handlePreview = function handlePreview(file) {
4066
4191
  return _async_to_generator(function() {
4067
4192
  var preview, isImageUrl, previewIndex;
package/dist/index.mjs CHANGED
@@ -3137,16 +3137,20 @@ var UploadGroup = memo18(function(props) {
3137
3137
  // src/EffectFileUpload/index.tsx
3138
3138
  import { jsx as jsx27 } from "react/jsx-runtime";
3139
3139
  var _EffectFileUpload = memo19(forwardRef2(function(props, ref) {
3140
- var value = props.value, defaultValue = props.defaultValue, files = props.files, needSave = props.needSave, extFormData = props.extFormData, max = props.max, accept = props.accept, disabled = props.disabled, className = props.className, name = props.name, remote = props.remote, pastable = props.pastable, deleteConfirm = props.deleteConfirm;
3140
+ var value = props.value, defaultValue = props.defaultValue, files = props.files, needSave = props.needSave, extFormData = props.extFormData, disabled = props.disabled, name = props.name, pastable = props.pastable, restProps = _object_without_properties(props, [
3141
+ "value",
3142
+ "defaultValue",
3143
+ "files",
3144
+ "needSave",
3145
+ "extFormData",
3146
+ "disabled",
3147
+ "name",
3148
+ "pastable"
3149
+ ]);
3141
3150
  var onChange = props.onChange, onFileChange = props.onFileChange, onUpload = props.onUpload, onUploadDone = props.onUploadDone, uploadOnAdd = props.uploadOnAdd;
3142
- var passProps = {
3143
- max: max,
3144
- accept: accept,
3145
- className: className,
3146
- remote: remote,
3147
- pastable: pastable,
3148
- deleteConfirm: deleteConfirm
3149
- };
3151
+ var passProps = _object_spread({
3152
+ pastable: pastable
3153
+ }, restProps);
3150
3154
  var _useState11 = _sliced_to_array(useState11(files || transformSimpleFile2UploadFile(value)), 2), uploadFiles = _useState11[0], setUploadFiles = _useState11[1];
3151
3155
  var _useState111 = _sliced_to_array(useState11(value || defaultValue || []), 2), simpleFiles = _useState111[0], setSimpleFiles = _useState111[1];
3152
3156
  var uploadTasksRef = useRef8([]);
@@ -3664,7 +3668,7 @@ var previewImage = function previewImage(file) {
3664
3668
  };
3665
3669
  var FileUpload = function FileUpload(props) {
3666
3670
  var _props_value = props.value, value = _props_value === void 0 ? [] : _props_value, defaultValue = props.defaultValue, onChange = props.onChange, disabled = props.disabled, classNames2 = props.classNames, children = props.children, accept = props.accept, _props_max = props.max, max = _props_max === void 0 ? 9 : _props_max, deleteConfirm = props.deleteConfirm;
3667
- var remote = props.remote, pastable = props.pastable, _props_multiple = props.multiple, multiple = _props_multiple === void 0 ? true : _props_multiple, _props_type = props.type, type = _props_type === void 0 ? "picture-card" : _props_type;
3671
+ var remote = props.remote, pastable = props.pastable, _props_multiple = props.multiple, multiple = _props_multiple === void 0 ? true : _props_multiple, _props_type = props.type, type = _props_type === void 0 ? "picture-card" : _props_type, beforeUpload = props.beforeUpload;
3668
3672
  var _useState14 = _sliced_to_array(useState14(-1), 2), previewImageIndex = _useState14[0], setPreviewImageIndex = _useState14[1];
3669
3673
  var _useState141 = _sliced_to_array(useState14(defaultValue || value || []), 2), fileList = _useState141[0], setFileList = _useState141[1];
3670
3674
  var _useState142 = _sliced_to_array(useState14(), 2), bufferAddFile = _useState142[0], setBufferAddFile = _useState142[1];
@@ -3776,10 +3780,131 @@ var FileUpload = function FileUpload(props) {
3776
3780
  });
3777
3781
  })();
3778
3782
  }, []);
3779
- var handleBeforeUpload = useCallback14(function(_, files) {
3780
- void handleAdd(files);
3783
+ var handleBeforeUpload = useCallback14(function(file, files) {
3784
+ if (file !== files[0]) return false;
3785
+ if (!beforeUpload) {
3786
+ void handleAdd(files);
3787
+ return false;
3788
+ }
3789
+ var processFiles = function processFiles() {
3790
+ return _async_to_generator(function() {
3791
+ var processedFiles, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, originFile, result, processedFile, error, err;
3792
+ return _ts_generator(this, function(_state) {
3793
+ switch(_state.label){
3794
+ case 0:
3795
+ processedFiles = [];
3796
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3797
+ _state.label = 1;
3798
+ case 1:
3799
+ _state.trys.push([
3800
+ 1,
3801
+ 8,
3802
+ 9,
3803
+ 10
3804
+ ]);
3805
+ _iterator = files[Symbol.iterator]();
3806
+ _state.label = 2;
3807
+ case 2:
3808
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3809
+ 3,
3810
+ 7
3811
+ ];
3812
+ originFile = _step.value;
3813
+ _state.label = 3;
3814
+ case 3:
3815
+ _state.trys.push([
3816
+ 3,
3817
+ 5,
3818
+ ,
3819
+ 6
3820
+ ]);
3821
+ return [
3822
+ 4,
3823
+ beforeUpload(originFile, files)
3824
+ ];
3825
+ case 4:
3826
+ result = _state.sent();
3827
+ if (result === false || result === Upload.LIST_IGNORE) return [
3828
+ 3,
3829
+ 6
3830
+ ];
3831
+ if (_instanceof(result, Blob)) {
3832
+ processedFile = _instanceof(result, File) ? result : new File([
3833
+ result
3834
+ ], originFile.name, {
3835
+ type: result.type || originFile.type,
3836
+ lastModified: originFile.lastModified
3837
+ });
3838
+ Object.assign(processedFile, {
3839
+ uid: originFile.uid
3840
+ });
3841
+ processedFiles.push(processedFile);
3842
+ } else {
3843
+ processedFiles.push(originFile);
3844
+ }
3845
+ return [
3846
+ 3,
3847
+ 6
3848
+ ];
3849
+ case 5:
3850
+ error = _state.sent();
3851
+ console.error(error);
3852
+ return [
3853
+ 3,
3854
+ 6
3855
+ ];
3856
+ case 6:
3857
+ _iteratorNormalCompletion = true;
3858
+ return [
3859
+ 3,
3860
+ 2
3861
+ ];
3862
+ case 7:
3863
+ return [
3864
+ 3,
3865
+ 10
3866
+ ];
3867
+ case 8:
3868
+ err = _state.sent();
3869
+ _didIteratorError = true;
3870
+ _iteratorError = err;
3871
+ return [
3872
+ 3,
3873
+ 10
3874
+ ];
3875
+ case 9:
3876
+ try {
3877
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3878
+ _iterator.return();
3879
+ }
3880
+ } finally{
3881
+ if (_didIteratorError) {
3882
+ throw _iteratorError;
3883
+ }
3884
+ }
3885
+ return [
3886
+ 7
3887
+ ];
3888
+ case 10:
3889
+ return [
3890
+ 4,
3891
+ handleAdd(processedFiles)
3892
+ ];
3893
+ case 11:
3894
+ _state.sent();
3895
+ return [
3896
+ 2
3897
+ ];
3898
+ }
3899
+ });
3900
+ })();
3901
+ };
3902
+ void processFiles();
3781
3903
  return false;
3782
- }, []);
3904
+ }, [
3905
+ beforeUpload,
3906
+ handleAdd
3907
+ ]);
3783
3908
  var handlePreview = function handlePreview(file) {
3784
3909
  return _async_to_generator(function() {
3785
3910
  var preview, isImageUrl, previewIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-components",
3
- "version": "1.8.7",
3
+ "version": "1.8.8",
4
4
  "module": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": [
@@ -52,8 +52,8 @@
52
52
  "esbuild-plugin-less": "^1.3.9",
53
53
  "eslint": "8.57.1",
54
54
  "vitest": "^4.0.14",
55
- "@xfe-repo/eslint-config": "1.6.0",
56
- "@xfe-repo/typescript-config": "1.6.1"
55
+ "@xfe-repo/typescript-config": "1.6.2",
56
+ "@xfe-repo/eslint-config": "1.6.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@ant-design/icons": "^5.0.0",
@@ -64,9 +64,9 @@
64
64
  "react-use": "^17.5.1",
65
65
  "swr": "^2.2.5",
66
66
  "@xfe-repo/web-micro": "1.7.0",
67
+ "@xfe-repo/web-utils": "1.6.2",
67
68
  "@xfe-repo/web-router": "1.6.1",
68
- "@xfe-repo/web-service": "1.6.0",
69
- "@xfe-repo/web-utils": "1.6.2"
69
+ "@xfe-repo/web-service": "1.6.0"
70
70
  },
71
71
  "publishConfig": {
72
72
  "registry": "https://registry.npmjs.org/"