@douyinfe/semi-ui 2.27.1-alpha.0 → 2.27.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.
- package/dist/umd/semi-ui.js +247 -227
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/lib/cjs/carousel/index.d.ts +1 -1
- package/lib/cjs/dropdown/dropdownItem.d.ts +1 -1
- package/lib/cjs/form/hoc/withField.js +51 -31
- package/lib/es/carousel/index.d.ts +1 -1
- package/lib/es/dropdown/dropdownItem.d.ts +1 -1
- package/lib/es/form/hoc/withField.js +51 -31
- package/package.json +8 -8
|
@@ -14,7 +14,7 @@ export interface CarouselState {
|
|
|
14
14
|
declare class Carousel extends BaseComponent<CarouselProps, CarouselState> {
|
|
15
15
|
static propTypes: {
|
|
16
16
|
activeIndex: PropTypes.Requireable<number>;
|
|
17
|
-
animation: PropTypes.Requireable<"
|
|
17
|
+
animation: PropTypes.Requireable<"slide" | "fade">;
|
|
18
18
|
arrowProps: PropTypes.Requireable<object>;
|
|
19
19
|
autoPlay: PropTypes.Requireable<NonNullable<boolean | object>>;
|
|
20
20
|
className: PropTypes.Requireable<string>;
|
|
@@ -17,7 +17,7 @@ export interface DropdownItemProps extends BaseProps {
|
|
|
17
17
|
icon?: React.ReactNode;
|
|
18
18
|
onKeyDown?: (e: React.KeyboardEvent) => void;
|
|
19
19
|
showTick?: boolean;
|
|
20
|
-
/**
|
|
20
|
+
/** internal prop, please do not use */
|
|
21
21
|
hover?: boolean;
|
|
22
22
|
}
|
|
23
23
|
declare class DropdownItem extends BaseComponent<DropdownItemProps> {
|
|
@@ -133,7 +133,8 @@ function withField(Component, opts) {
|
|
|
133
133
|
const [status, setStatus] = (0, _react.useState)(validateStatus); // use props.validateStatus to init
|
|
134
134
|
|
|
135
135
|
const rulesRef = (0, _react.useRef)(rules);
|
|
136
|
-
const validateRef = (0, _react.useRef)(validate);
|
|
136
|
+
const validateRef = (0, _react.useRef)(validate);
|
|
137
|
+
const validatePromise = (0, _react.useRef)(null); // notNotify is true means that the onChange of the Form does not need to be triggered
|
|
137
138
|
// notUpdate is true means that this operation does not need to trigger the forceUpdate
|
|
138
139
|
|
|
139
140
|
const updateTouched = (isTouched, callOpts) => {
|
|
@@ -187,16 +188,24 @@ function withField(Component, opts) {
|
|
|
187
188
|
const model = {
|
|
188
189
|
[field]: val
|
|
189
190
|
};
|
|
190
|
-
|
|
191
|
+
const rootPromise = new Promise((resolve, reject) => {
|
|
191
192
|
validator.validate(model, {
|
|
192
193
|
first: stopValidateWithError
|
|
193
194
|
}, // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
194
195
|
(errors, fields) => {}).then(res => {
|
|
195
|
-
|
|
196
|
+
if (validatePromise.current !== rootPromise) {
|
|
197
|
+
return;
|
|
198
|
+
} // validation passed
|
|
199
|
+
|
|
200
|
+
|
|
196
201
|
setStatus('success');
|
|
197
202
|
updateError(undefined, callOpts);
|
|
198
203
|
resolve({});
|
|
199
204
|
}).catch(err => {
|
|
205
|
+
if (validatePromise.current !== rootPromise) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
200
209
|
let {
|
|
201
210
|
errors,
|
|
202
211
|
fields
|
|
@@ -225,44 +234,55 @@ function withField(Component, opts) {
|
|
|
225
234
|
}
|
|
226
235
|
});
|
|
227
236
|
});
|
|
237
|
+
validatePromise.current = rootPromise;
|
|
238
|
+
return rootPromise;
|
|
228
239
|
}; // execute custom validate function
|
|
229
240
|
|
|
230
241
|
|
|
231
|
-
const _validate = (val, values, callOpts) =>
|
|
232
|
-
|
|
242
|
+
const _validate = (val, values, callOpts) => {
|
|
243
|
+
const rootPromise = new Promise(resolve => {
|
|
244
|
+
let maybePromisedErrors; // let errorThrowSync;
|
|
233
245
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
246
|
+
try {
|
|
247
|
+
maybePromisedErrors = validateRef.current(val, values);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
// error throw by syncValidate
|
|
250
|
+
maybePromisedErrors = err;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (maybePromisedErrors === undefined) {
|
|
254
|
+
resolve({});
|
|
255
|
+
updateError(undefined, callOpts);
|
|
256
|
+
} else if ((0, _isPromise.default)(maybePromisedErrors)) {
|
|
257
|
+
maybePromisedErrors.then(result => {
|
|
258
|
+
// If the async validate is outdated (a newer validate occurs), the result should be discarded
|
|
259
|
+
if (validatePromise.current !== rootPromise) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
240
262
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
263
|
+
if ((0, _utils.isValid)(result)) {
|
|
264
|
+
// validate success,no need to do anything with result
|
|
265
|
+
updateError(undefined, callOpts);
|
|
266
|
+
resolve(null);
|
|
267
|
+
} else {
|
|
268
|
+
// validate failed
|
|
269
|
+
updateError(result, callOpts);
|
|
270
|
+
resolve(result);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
if ((0, _utils.isValid)(maybePromisedErrors)) {
|
|
248
275
|
updateError(undefined, callOpts);
|
|
249
276
|
resolve(null);
|
|
250
277
|
} else {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
resolve(result);
|
|
278
|
+
updateError(maybePromisedErrors, callOpts);
|
|
279
|
+
resolve(maybePromisedErrors);
|
|
254
280
|
}
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
if ((0, _utils.isValid)(maybePromisedErrors)) {
|
|
258
|
-
updateError(undefined, callOpts);
|
|
259
|
-
resolve(null);
|
|
260
|
-
} else {
|
|
261
|
-
updateError(maybePromisedErrors, callOpts);
|
|
262
|
-
resolve(maybePromisedErrors);
|
|
263
281
|
}
|
|
264
|
-
}
|
|
265
|
-
|
|
282
|
+
});
|
|
283
|
+
validatePromise.current = rootPromise;
|
|
284
|
+
return rootPromise;
|
|
285
|
+
};
|
|
266
286
|
|
|
267
287
|
const fieldValidate = (val, callOpts) => {
|
|
268
288
|
let finalVal = val;
|
|
@@ -14,7 +14,7 @@ export interface CarouselState {
|
|
|
14
14
|
declare class Carousel extends BaseComponent<CarouselProps, CarouselState> {
|
|
15
15
|
static propTypes: {
|
|
16
16
|
activeIndex: PropTypes.Requireable<number>;
|
|
17
|
-
animation: PropTypes.Requireable<"
|
|
17
|
+
animation: PropTypes.Requireable<"slide" | "fade">;
|
|
18
18
|
arrowProps: PropTypes.Requireable<object>;
|
|
19
19
|
autoPlay: PropTypes.Requireable<NonNullable<boolean | object>>;
|
|
20
20
|
className: PropTypes.Requireable<string>;
|
|
@@ -17,7 +17,7 @@ export interface DropdownItemProps extends BaseProps {
|
|
|
17
17
|
icon?: React.ReactNode;
|
|
18
18
|
onKeyDown?: (e: React.KeyboardEvent) => void;
|
|
19
19
|
showTick?: boolean;
|
|
20
|
-
/**
|
|
20
|
+
/** internal prop, please do not use */
|
|
21
21
|
hover?: boolean;
|
|
22
22
|
}
|
|
23
23
|
declare class DropdownItem extends BaseComponent<DropdownItemProps> {
|
|
@@ -108,7 +108,8 @@ function withField(Component, opts) {
|
|
|
108
108
|
const [status, setStatus] = useState(validateStatus); // use props.validateStatus to init
|
|
109
109
|
|
|
110
110
|
const rulesRef = useRef(rules);
|
|
111
|
-
const validateRef = useRef(validate);
|
|
111
|
+
const validateRef = useRef(validate);
|
|
112
|
+
const validatePromise = useRef(null); // notNotify is true means that the onChange of the Form does not need to be triggered
|
|
112
113
|
// notUpdate is true means that this operation does not need to trigger the forceUpdate
|
|
113
114
|
|
|
114
115
|
const updateTouched = (isTouched, callOpts) => {
|
|
@@ -162,16 +163,24 @@ function withField(Component, opts) {
|
|
|
162
163
|
const model = {
|
|
163
164
|
[field]: val
|
|
164
165
|
};
|
|
165
|
-
|
|
166
|
+
const rootPromise = new Promise((resolve, reject) => {
|
|
166
167
|
validator.validate(model, {
|
|
167
168
|
first: stopValidateWithError
|
|
168
169
|
}, // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
169
170
|
(errors, fields) => {}).then(res => {
|
|
170
|
-
|
|
171
|
+
if (validatePromise.current !== rootPromise) {
|
|
172
|
+
return;
|
|
173
|
+
} // validation passed
|
|
174
|
+
|
|
175
|
+
|
|
171
176
|
setStatus('success');
|
|
172
177
|
updateError(undefined, callOpts);
|
|
173
178
|
resolve({});
|
|
174
179
|
}).catch(err => {
|
|
180
|
+
if (validatePromise.current !== rootPromise) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
175
184
|
let {
|
|
176
185
|
errors,
|
|
177
186
|
fields
|
|
@@ -200,44 +209,55 @@ function withField(Component, opts) {
|
|
|
200
209
|
}
|
|
201
210
|
});
|
|
202
211
|
});
|
|
212
|
+
validatePromise.current = rootPromise;
|
|
213
|
+
return rootPromise;
|
|
203
214
|
}; // execute custom validate function
|
|
204
215
|
|
|
205
216
|
|
|
206
|
-
const _validate = (val, values, callOpts) =>
|
|
207
|
-
|
|
217
|
+
const _validate = (val, values, callOpts) => {
|
|
218
|
+
const rootPromise = new Promise(resolve => {
|
|
219
|
+
let maybePromisedErrors; // let errorThrowSync;
|
|
208
220
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
221
|
+
try {
|
|
222
|
+
maybePromisedErrors = validateRef.current(val, values);
|
|
223
|
+
} catch (err) {
|
|
224
|
+
// error throw by syncValidate
|
|
225
|
+
maybePromisedErrors = err;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (maybePromisedErrors === undefined) {
|
|
229
|
+
resolve({});
|
|
230
|
+
updateError(undefined, callOpts);
|
|
231
|
+
} else if (isPromise(maybePromisedErrors)) {
|
|
232
|
+
maybePromisedErrors.then(result => {
|
|
233
|
+
// If the async validate is outdated (a newer validate occurs), the result should be discarded
|
|
234
|
+
if (validatePromise.current !== rootPromise) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
215
237
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
238
|
+
if (isValid(result)) {
|
|
239
|
+
// validate success,no need to do anything with result
|
|
240
|
+
updateError(undefined, callOpts);
|
|
241
|
+
resolve(null);
|
|
242
|
+
} else {
|
|
243
|
+
// validate failed
|
|
244
|
+
updateError(result, callOpts);
|
|
245
|
+
resolve(result);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
if (isValid(maybePromisedErrors)) {
|
|
223
250
|
updateError(undefined, callOpts);
|
|
224
251
|
resolve(null);
|
|
225
252
|
} else {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
resolve(result);
|
|
253
|
+
updateError(maybePromisedErrors, callOpts);
|
|
254
|
+
resolve(maybePromisedErrors);
|
|
229
255
|
}
|
|
230
|
-
});
|
|
231
|
-
} else {
|
|
232
|
-
if (isValid(maybePromisedErrors)) {
|
|
233
|
-
updateError(undefined, callOpts);
|
|
234
|
-
resolve(null);
|
|
235
|
-
} else {
|
|
236
|
-
updateError(maybePromisedErrors, callOpts);
|
|
237
|
-
resolve(maybePromisedErrors);
|
|
238
256
|
}
|
|
239
|
-
}
|
|
240
|
-
|
|
257
|
+
});
|
|
258
|
+
validatePromise.current = rootPromise;
|
|
259
|
+
return rootPromise;
|
|
260
|
+
};
|
|
241
261
|
|
|
242
262
|
const fieldValidate = (val, callOpts) => {
|
|
243
263
|
let finalVal = val;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-ui",
|
|
3
|
-
"version": "2.27.1
|
|
3
|
+
"version": "2.27.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es/index.js",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"lib/*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@douyinfe/semi-animation": "2.27.1
|
|
21
|
-
"@douyinfe/semi-animation-react": "2.27.1
|
|
22
|
-
"@douyinfe/semi-foundation": "2.27.1
|
|
23
|
-
"@douyinfe/semi-icons": "2.27.1
|
|
24
|
-
"@douyinfe/semi-illustrations": "2.27.1
|
|
25
|
-
"@douyinfe/semi-theme-default": "2.27.1
|
|
20
|
+
"@douyinfe/semi-animation": "2.27.1",
|
|
21
|
+
"@douyinfe/semi-animation-react": "2.27.1",
|
|
22
|
+
"@douyinfe/semi-foundation": "2.27.1",
|
|
23
|
+
"@douyinfe/semi-icons": "2.27.1",
|
|
24
|
+
"@douyinfe/semi-illustrations": "2.27.1",
|
|
25
|
+
"@douyinfe/semi-theme-default": "2.27.1",
|
|
26
26
|
"async-validator": "^3.5.0",
|
|
27
27
|
"classnames": "^2.2.6",
|
|
28
28
|
"copy-text-to-clipboard": "^2.1.1",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
],
|
|
70
70
|
"author": "",
|
|
71
71
|
"license": "MIT",
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "a40dba5743af05efae302451a2174a8f22115a47",
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/plugin-proposal-decorators": "^7.15.8",
|
|
75
75
|
"@babel/plugin-transform-runtime": "^7.15.8",
|