@douyinfe/semi-foundation 2.45.2 → 2.45.3-alpha.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.
@@ -230,7 +230,11 @@ export interface CascaderAdapter extends DefaultAdapter<BasicCascaderProps, Basi
230
230
  notifyListScroll: (e: any, panel: BasicScrollPanelProps) => void;
231
231
  notifyOnExceed: (data: BasicEntity[]) => void;
232
232
  toggleInputShow: (show: boolean, cb: () => void) => void;
233
- updateFocusState: (focus: boolean) => void
233
+ updateFocusState: (focus: boolean) => void;
234
+ updateLoadingKeyRefValue: (keys: Set<string>) => void;
235
+ getLoadingKeyRefValue: () => Set<string>;
236
+ updateLoadedKeyRefValue: (keys: Set<string>) => void;
237
+ getLoadedKeyRefValue: () => Set<string>
234
238
  }
235
239
 
236
240
  export default class CascaderFoundation extends BaseFoundation<CascaderAdapter, BasicCascaderProps, BasicCascaderInnerData> {
@@ -242,6 +246,8 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
242
246
  init() {
243
247
  const isOpen = this.getProp('open') || this.getProp('defaultOpen');
244
248
  this.collectOptions(true);
249
+ this._adapter.updateLoadingKeyRefValue(new Set());
250
+ this._adapter.updateLoadedKeyRefValue(new Set());
245
251
 
246
252
  if (isOpen && !this._isDisabled()) {
247
253
  this.open();
@@ -426,11 +432,11 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
426
432
  const { changeOnSelect, onChangeWithObject, multiple } = this.getProps();
427
433
  const {
428
434
  activeKeys,
429
- loadingKeys,
430
435
  loading,
431
436
  keyEntities: keyEntityState,
432
437
  selectedKeys: selectedKeysState
433
438
  } = this.getStates();
439
+ const loadingKeys = this._adapter.getLoadingKeyRefValue();
434
440
  const filterable = this._isFilterable();
435
441
  const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
436
442
 
@@ -672,18 +678,19 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
672
678
 
673
679
  handleNodeLoad(item: BasicEntity | BasicData) {
674
680
  const { data, key } = item;
675
- const {
676
- loadedKeys: prevLoadedKeys,
677
- loadingKeys: prevLoadingKeys
678
- } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
681
+ const prevLoadingKeys = cloneDeep(this._adapter.getLoadingKeyRefValue());
682
+ const prevLoadedKeys = cloneDeep(this._adapter.getLoadedKeyRefValue());
679
683
  const newLoadedKeys = prevLoadedKeys.add(key);
680
684
  const newLoadingKeys = new Set([...prevLoadingKeys]);
681
685
  newLoadingKeys.delete(key);
682
686
 
683
687
  // onLoad should trigger before internal setState to avoid `loadData` trigger twice.
684
688
  this._adapter.notifyOnLoad(newLoadedKeys, data);
689
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
690
+ this._adapter.updateLoadedKeyRefValue(newLoadedKeys);
685
691
  this._adapter.updateStates({
686
692
  loadingKeys: newLoadingKeys,
693
+ loadedKeys: newLoadedKeys
687
694
  });
688
695
  }
689
696
 
@@ -691,14 +698,17 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
691
698
  const { data, key } = item;
692
699
  this._adapter.updateStates({ loading: false });
693
700
  if (!data.isLeaf && !data.children && this.getProp('loadData')) {
694
- const { loadedKeys, loadingKeys } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
701
+ const loadedKeys = this._adapter.getLoadedKeyRefValue();
702
+ const loadingKeys = cloneDeep(this._adapter.getLoadingKeyRefValue());
695
703
  if (loadedKeys.has(key) || loadingKeys.has(key)) {
696
704
  return;
697
705
  }
698
706
  this._adapter.updateStates({ loading: true });
699
707
  const { keyEntities } = this.getStates();
700
708
  const optionPath = this.getItemPropPath(key, [], keyEntities);
701
- this._adapter.updateStates({ loadingKeys: loadingKeys.add(key) });
709
+ const newLoadingKeys = loadingKeys.add(key);
710
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
711
+ this._adapter.updateStates({ loadingKeys: newLoadingKeys });
702
712
  this._adapter.notifyLoadData(optionPath, this.handleNodeLoad.bind(this, item));
703
713
  }
704
714
  }
@@ -176,6 +176,10 @@ export interface CascaderAdapter extends DefaultAdapter<BasicCascaderProps, Basi
176
176
  notifyOnExceed: (data: BasicEntity[]) => void;
177
177
  toggleInputShow: (show: boolean, cb: () => void) => void;
178
178
  updateFocusState: (focus: boolean) => void;
179
+ updateLoadingKeyRefValue: (keys: Set<string>) => void;
180
+ getLoadingKeyRefValue: () => Set<string>;
181
+ updateLoadedKeyRefValue: (keys: Set<string>) => void;
182
+ getLoadedKeyRefValue: () => Set<string>;
179
183
  }
180
184
  export default class CascaderFoundation extends BaseFoundation<CascaderAdapter, BasicCascaderProps, BasicCascaderInnerData> {
181
185
  constructor(adapter: CascaderAdapter);
@@ -235,7 +239,10 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
235
239
  * @param {boolean} curCheckedStatus checked status of node
236
240
  */
237
241
  calcCheckedKeys(key: string, curCheckedStatus: boolean): {
238
- checkedKeys: Set<string>;
242
+ checkedKeys: Set<string>; /**
243
+ * When changeOnSelect is turned on, or the target option is a leaf option,
244
+ * the option is considered to be selected, even if the option is disabled
245
+ */
239
246
  halfCheckedKeys: Set<string>;
240
247
  };
241
248
  handleInputChange(sugInput: string): void;
@@ -32,6 +32,8 @@ class CascaderFoundation extends _foundation.default {
32
32
  init() {
33
33
  const isOpen = this.getProp('open') || this.getProp('defaultOpen');
34
34
  this.collectOptions(true);
35
+ this._adapter.updateLoadingKeyRefValue(new Set());
36
+ this._adapter.updateLoadedKeyRefValue(new Set());
35
37
  if (isOpen && !this._isDisabled()) {
36
38
  this.open();
37
39
  }
@@ -218,11 +220,11 @@ class CascaderFoundation extends _foundation.default {
218
220
  } = this.getProps();
219
221
  const {
220
222
  activeKeys,
221
- loadingKeys,
222
223
  loading,
223
224
  keyEntities: keyEntityState,
224
225
  selectedKeys: selectedKeysState
225
226
  } = this.getStates();
227
+ const loadingKeys = this._adapter.getLoadingKeyRefValue();
226
228
  const filterable = this._isFilterable();
227
229
  const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
228
230
  const valuePath = onChangeWithObject ? (0, _util.normalizedArr)(value).map(i => i.value) : (0, _util.normalizedArr)(value);
@@ -470,17 +472,18 @@ class CascaderFoundation extends _foundation.default {
470
472
  data,
471
473
  key
472
474
  } = item;
473
- const {
474
- loadedKeys: prevLoadedKeys,
475
- loadingKeys: prevLoadingKeys
476
- } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
475
+ const prevLoadingKeys = (0, _cloneDeep2.default)(this._adapter.getLoadingKeyRefValue());
476
+ const prevLoadedKeys = (0, _cloneDeep2.default)(this._adapter.getLoadedKeyRefValue());
477
477
  const newLoadedKeys = prevLoadedKeys.add(key);
478
478
  const newLoadingKeys = new Set([...prevLoadingKeys]);
479
479
  newLoadingKeys.delete(key);
480
480
  // onLoad should trigger before internal setState to avoid `loadData` trigger twice.
481
481
  this._adapter.notifyOnLoad(newLoadedKeys, data);
482
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
483
+ this._adapter.updateLoadedKeyRefValue(newLoadedKeys);
482
484
  this._adapter.updateStates({
483
- loadingKeys: newLoadingKeys
485
+ loadingKeys: newLoadingKeys,
486
+ loadedKeys: newLoadedKeys
484
487
  });
485
488
  }
486
489
  notifyIfLoadData(item) {
@@ -492,10 +495,8 @@ class CascaderFoundation extends _foundation.default {
492
495
  loading: false
493
496
  });
494
497
  if (!data.isLeaf && !data.children && this.getProp('loadData')) {
495
- const {
496
- loadedKeys,
497
- loadingKeys
498
- } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
498
+ const loadedKeys = this._adapter.getLoadedKeyRefValue();
499
+ const loadingKeys = (0, _cloneDeep2.default)(this._adapter.getLoadingKeyRefValue());
499
500
  if (loadedKeys.has(key) || loadingKeys.has(key)) {
500
501
  return;
501
502
  }
@@ -506,8 +507,10 @@ class CascaderFoundation extends _foundation.default {
506
507
  keyEntities
507
508
  } = this.getStates();
508
509
  const optionPath = this.getItemPropPath(key, [], keyEntities);
510
+ const newLoadingKeys = loadingKeys.add(key);
511
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
509
512
  this._adapter.updateStates({
510
- loadingKeys: loadingKeys.add(key)
513
+ loadingKeys: newLoadingKeys
511
514
  });
512
515
  this._adapter.notifyLoadData(optionPath, this.handleNodeLoad.bind(this, item));
513
516
  }
@@ -176,6 +176,10 @@ export interface CascaderAdapter extends DefaultAdapter<BasicCascaderProps, Basi
176
176
  notifyOnExceed: (data: BasicEntity[]) => void;
177
177
  toggleInputShow: (show: boolean, cb: () => void) => void;
178
178
  updateFocusState: (focus: boolean) => void;
179
+ updateLoadingKeyRefValue: (keys: Set<string>) => void;
180
+ getLoadingKeyRefValue: () => Set<string>;
181
+ updateLoadedKeyRefValue: (keys: Set<string>) => void;
182
+ getLoadedKeyRefValue: () => Set<string>;
179
183
  }
180
184
  export default class CascaderFoundation extends BaseFoundation<CascaderAdapter, BasicCascaderProps, BasicCascaderInnerData> {
181
185
  constructor(adapter: CascaderAdapter);
@@ -235,7 +239,10 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
235
239
  * @param {boolean} curCheckedStatus checked status of node
236
240
  */
237
241
  calcCheckedKeys(key: string, curCheckedStatus: boolean): {
238
- checkedKeys: Set<string>;
242
+ checkedKeys: Set<string>; /**
243
+ * When changeOnSelect is turned on, or the target option is a leaf option,
244
+ * the option is considered to be selected, even if the option is disabled
245
+ */
239
246
  halfCheckedKeys: Set<string>;
240
247
  };
241
248
  handleInputChange(sugInput: string): void;
@@ -25,6 +25,8 @@ export default class CascaderFoundation extends BaseFoundation {
25
25
  init() {
26
26
  const isOpen = this.getProp('open') || this.getProp('defaultOpen');
27
27
  this.collectOptions(true);
28
+ this._adapter.updateLoadingKeyRefValue(new Set());
29
+ this._adapter.updateLoadedKeyRefValue(new Set());
28
30
  if (isOpen && !this._isDisabled()) {
29
31
  this.open();
30
32
  }
@@ -211,11 +213,11 @@ export default class CascaderFoundation extends BaseFoundation {
211
213
  } = this.getProps();
212
214
  const {
213
215
  activeKeys,
214
- loadingKeys,
215
216
  loading,
216
217
  keyEntities: keyEntityState,
217
218
  selectedKeys: selectedKeysState
218
219
  } = this.getStates();
220
+ const loadingKeys = this._adapter.getLoadingKeyRefValue();
219
221
  const filterable = this._isFilterable();
220
222
  const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
221
223
  const valuePath = onChangeWithObject ? normalizedArr(value).map(i => i.value) : normalizedArr(value);
@@ -463,17 +465,18 @@ export default class CascaderFoundation extends BaseFoundation {
463
465
  data,
464
466
  key
465
467
  } = item;
466
- const {
467
- loadedKeys: prevLoadedKeys,
468
- loadingKeys: prevLoadingKeys
469
- } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
468
+ const prevLoadingKeys = _cloneDeep(this._adapter.getLoadingKeyRefValue());
469
+ const prevLoadedKeys = _cloneDeep(this._adapter.getLoadedKeyRefValue());
470
470
  const newLoadedKeys = prevLoadedKeys.add(key);
471
471
  const newLoadingKeys = new Set([...prevLoadingKeys]);
472
472
  newLoadingKeys.delete(key);
473
473
  // onLoad should trigger before internal setState to avoid `loadData` trigger twice.
474
474
  this._adapter.notifyOnLoad(newLoadedKeys, data);
475
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
476
+ this._adapter.updateLoadedKeyRefValue(newLoadedKeys);
475
477
  this._adapter.updateStates({
476
- loadingKeys: newLoadingKeys
478
+ loadingKeys: newLoadingKeys,
479
+ loadedKeys: newLoadedKeys
477
480
  });
478
481
  }
479
482
  notifyIfLoadData(item) {
@@ -485,10 +488,8 @@ export default class CascaderFoundation extends BaseFoundation {
485
488
  loading: false
486
489
  });
487
490
  if (!data.isLeaf && !data.children && this.getProp('loadData')) {
488
- const {
489
- loadedKeys,
490
- loadingKeys
491
- } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
491
+ const loadedKeys = this._adapter.getLoadedKeyRefValue();
492
+ const loadingKeys = _cloneDeep(this._adapter.getLoadingKeyRefValue());
492
493
  if (loadedKeys.has(key) || loadingKeys.has(key)) {
493
494
  return;
494
495
  }
@@ -499,8 +500,10 @@ export default class CascaderFoundation extends BaseFoundation {
499
500
  keyEntities
500
501
  } = this.getStates();
501
502
  const optionPath = this.getItemPropPath(key, [], keyEntities);
503
+ const newLoadingKeys = loadingKeys.add(key);
504
+ this._adapter.updateLoadingKeyRefValue(newLoadingKeys);
502
505
  this._adapter.updateStates({
503
- loadingKeys: loadingKeys.add(key)
506
+ loadingKeys: newLoadingKeys
504
507
  });
505
508
  this._adapter.notifyLoadData(optionPath, this.handleNodeLoad.bind(this, item));
506
509
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.45.2",
3
+ "version": "2.45.3-alpha.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
7
7
  "prepublishOnly": "npm run build:lib"
8
8
  },
9
9
  "dependencies": {
10
- "@douyinfe/semi-animation": "2.45.2",
10
+ "@douyinfe/semi-animation": "2.45.3-alpha.1",
11
11
  "async-validator": "^3.5.0",
12
12
  "classnames": "^2.2.6",
13
13
  "date-fns": "^2.29.3",
@@ -23,7 +23,7 @@
23
23
  "*.scss",
24
24
  "*.css"
25
25
  ],
26
- "gitHead": "0ee1eb3aa058462c8fa23973c994c454ce9511d2",
26
+ "gitHead": "b8f3f83731e2b875db1796ff906d01c3cab8c7c9",
27
27
  "devDependencies": {
28
28
  "@babel/plugin-transform-runtime": "^7.15.8",
29
29
  "@babel/preset-env": "^7.15.8",