@douyinfe/semi-ui 2.27.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.
@@ -16,6 +16,9 @@ export interface DropdownItemProps extends BaseProps {
16
16
  active?: boolean;
17
17
  icon?: React.ReactNode;
18
18
  onKeyDown?: (e: React.KeyboardEvent) => void;
19
+ showTick?: boolean;
20
+ /** internal prop, please do not use */
21
+ hover?: boolean;
19
22
  }
20
23
  declare class DropdownItem extends BaseComponent<DropdownItemProps> {
21
24
  static propTypes: {
@@ -35,6 +38,7 @@ declare class DropdownItem extends BaseComponent<DropdownItemProps> {
35
38
  icon: PropTypes.Requireable<PropTypes.ReactNodeLike>;
36
39
  };
37
40
  static contextType: React.Context<DropdownContextType>;
41
+ static elementType: string;
38
42
  context: DropdownContextType;
39
43
  static defaultProps: {
40
44
  disabled: boolean;
@@ -36,15 +36,18 @@ class DropdownItem extends _baseComponent.default {
36
36
  type,
37
37
  active,
38
38
  icon,
39
- onKeyDown
39
+ onKeyDown,
40
+ showTick,
41
+ hover
40
42
  } = this.props;
41
43
  const {
42
- showTick
44
+ showTick: contextShowTick
43
45
  } = this.context;
44
46
  const itemclass = (0, _classnames.default)(className, {
45
47
  ["".concat(prefixCls, "-item")]: true,
46
48
  ["".concat(prefixCls, "-item-disabled")]: disabled,
47
- ["".concat(prefixCls, "-item-withTick")]: showTick,
49
+ ["".concat(prefixCls, "-item-hover")]: hover,
50
+ ["".concat(prefixCls, "-item-withTick")]: contextShowTick !== null && contextShowTick !== void 0 ? contextShowTick : showTick,
48
51
  ["".concat(prefixCls, "-item-").concat(type)]: type,
49
52
  ["".concat(prefixCls, "-item-active")]: active
50
53
  });
@@ -123,5 +126,6 @@ DropdownItem.defaultProps = {
123
126
  onMouseLeave: _noop2.default,
124
127
  forwardRef: _noop2.default
125
128
  };
129
+ DropdownItem.elementType = 'Dropdown.Item';
126
130
  var _default = DropdownItem;
127
131
  exports.default = _default;
@@ -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); // notNotify is true means that the onChange of the Form does not need to be triggered
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
- return new Promise((resolve, reject) => {
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
- // validation passed
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) => new Promise(resolve => {
232
- let maybePromisedErrors; // let errorThrowSync;
242
+ const _validate = (val, values, callOpts) => {
243
+ const rootPromise = new Promise(resolve => {
244
+ let maybePromisedErrors; // let errorThrowSync;
233
245
 
234
- try {
235
- maybePromisedErrors = validateRef.current(val, values);
236
- } catch (err) {
237
- // error throw by syncValidate
238
- maybePromisedErrors = err;
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
- if (maybePromisedErrors === undefined) {
242
- resolve({});
243
- updateError(undefined, callOpts);
244
- } else if ((0, _isPromise.default)(maybePromisedErrors)) {
245
- maybePromisedErrors.then(result => {
246
- if ((0, _utils.isValid)(result)) {
247
- // validate success,no need to do anything with result
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
- // validate failed
252
- updateError(result, callOpts);
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;
@@ -16,6 +16,9 @@ export interface DropdownItemProps extends BaseProps {
16
16
  active?: boolean;
17
17
  icon?: React.ReactNode;
18
18
  onKeyDown?: (e: React.KeyboardEvent) => void;
19
+ showTick?: boolean;
20
+ /** internal prop, please do not use */
21
+ hover?: boolean;
19
22
  }
20
23
  declare class DropdownItem extends BaseComponent<DropdownItemProps> {
21
24
  static propTypes: {
@@ -35,6 +38,7 @@ declare class DropdownItem extends BaseComponent<DropdownItemProps> {
35
38
  icon: PropTypes.Requireable<PropTypes.ReactNodeLike>;
36
39
  };
37
40
  static contextType: React.Context<DropdownContextType>;
41
+ static elementType: string;
38
42
  context: DropdownContextType;
39
43
  static defaultProps: {
40
44
  disabled: boolean;
@@ -19,15 +19,18 @@ class DropdownItem extends BaseComponent {
19
19
  type,
20
20
  active,
21
21
  icon,
22
- onKeyDown
22
+ onKeyDown,
23
+ showTick,
24
+ hover
23
25
  } = this.props;
24
26
  const {
25
- showTick
27
+ showTick: contextShowTick
26
28
  } = this.context;
27
29
  const itemclass = cls(className, {
28
30
  ["".concat(prefixCls, "-item")]: true,
29
31
  ["".concat(prefixCls, "-item-disabled")]: disabled,
30
- ["".concat(prefixCls, "-item-withTick")]: showTick,
32
+ ["".concat(prefixCls, "-item-hover")]: hover,
33
+ ["".concat(prefixCls, "-item-withTick")]: contextShowTick !== null && contextShowTick !== void 0 ? contextShowTick : showTick,
31
34
  ["".concat(prefixCls, "-item-").concat(type)]: type,
32
35
  ["".concat(prefixCls, "-item-active")]: active
33
36
  });
@@ -106,4 +109,5 @@ DropdownItem.defaultProps = {
106
109
  onMouseLeave: _noop,
107
110
  forwardRef: _noop
108
111
  };
112
+ DropdownItem.elementType = 'Dropdown.Item';
109
113
  export default DropdownItem;
@@ -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); // notNotify is true means that the onChange of the Form does not need to be triggered
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
- return new Promise((resolve, reject) => {
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
- // validation passed
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) => new Promise(resolve => {
207
- let maybePromisedErrors; // let errorThrowSync;
217
+ const _validate = (val, values, callOpts) => {
218
+ const rootPromise = new Promise(resolve => {
219
+ let maybePromisedErrors; // let errorThrowSync;
208
220
 
209
- try {
210
- maybePromisedErrors = validateRef.current(val, values);
211
- } catch (err) {
212
- // error throw by syncValidate
213
- maybePromisedErrors = err;
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
- if (maybePromisedErrors === undefined) {
217
- resolve({});
218
- updateError(undefined, callOpts);
219
- } else if (isPromise(maybePromisedErrors)) {
220
- maybePromisedErrors.then(result => {
221
- if (isValid(result)) {
222
- // validate success,no need to do anything with result
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
- // validate failed
227
- updateError(result, callOpts);
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.0",
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.0",
21
- "@douyinfe/semi-animation-react": "2.27.0",
22
- "@douyinfe/semi-foundation": "2.27.0",
23
- "@douyinfe/semi-icons": "2.27.0",
24
- "@douyinfe/semi-illustrations": "2.27.0",
25
- "@douyinfe/semi-theme-default": "2.27.0",
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": "a7a3f537ef48f75e3824c156e9b25a084e562dd6",
72
+ "gitHead": "a40dba5743af05efae302451a2174a8f22115a47",
73
73
  "devDependencies": {
74
74
  "@babel/plugin-proposal-decorators": "^7.15.8",
75
75
  "@babel/plugin-transform-runtime": "^7.15.8",