@douyinfe/semi-foundation 2.52.0-beta.1 → 2.53.0-beta.0

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 (64) hide show
  1. package/cascader/foundation.ts +24 -24
  2. package/cascader/util.ts +43 -0
  3. package/datePicker/foundation.ts +3 -0
  4. package/datePicker/inputFoundation.ts +4 -3
  5. package/datePicker/yearAndMonthFoundation.ts +4 -4
  6. package/dropdown/dropdown.scss +1 -0
  7. package/form/utils.ts +3 -2
  8. package/image/previewInnerFoundation.ts +4 -0
  9. package/lib/cjs/cascader/foundation.d.ts +4 -12
  10. package/lib/cjs/cascader/foundation.js +31 -34
  11. package/lib/cjs/cascader/util.d.ts +6 -0
  12. package/lib/cjs/cascader/util.js +42 -0
  13. package/lib/cjs/datePicker/foundation.js +3 -0
  14. package/lib/cjs/datePicker/inputFoundation.js +3 -3
  15. package/lib/cjs/datePicker/yearAndMonthFoundation.js +4 -4
  16. package/lib/cjs/dropdown/dropdown.css +1 -0
  17. package/lib/cjs/dropdown/dropdown.scss +1 -0
  18. package/lib/cjs/form/utils.js +2 -2
  19. package/lib/cjs/image/previewInnerFoundation.js +3 -0
  20. package/lib/cjs/overflowList/foundation.js +3 -3
  21. package/lib/cjs/select/foundation.js +2 -0
  22. package/lib/cjs/select/select.scss +3 -4
  23. package/lib/cjs/select/variables.scss +7 -6
  24. package/lib/cjs/tooltip/foundation.js +11 -0
  25. package/lib/cjs/tree/foundation.d.ts +0 -1
  26. package/lib/cjs/tree/foundation.js +7 -23
  27. package/lib/cjs/tree/treeUtil.d.ts +1 -2
  28. package/lib/cjs/tree/treeUtil.js +2 -3
  29. package/lib/cjs/treeSelect/foundation.d.ts +0 -1
  30. package/lib/cjs/treeSelect/foundation.js +8 -28
  31. package/lib/cjs/utils/getMotionObjFromProps.js +2 -2
  32. package/lib/es/cascader/foundation.d.ts +4 -12
  33. package/lib/es/cascader/foundation.js +33 -36
  34. package/lib/es/cascader/util.d.ts +6 -0
  35. package/lib/es/cascader/util.js +40 -0
  36. package/lib/es/datePicker/foundation.js +3 -0
  37. package/lib/es/datePicker/inputFoundation.js +3 -3
  38. package/lib/es/datePicker/yearAndMonthFoundation.js +4 -4
  39. package/lib/es/dropdown/dropdown.css +1 -0
  40. package/lib/es/dropdown/dropdown.scss +1 -0
  41. package/lib/es/form/utils.js +2 -2
  42. package/lib/es/image/previewInnerFoundation.js +3 -0
  43. package/lib/es/overflowList/foundation.js +3 -3
  44. package/lib/es/select/foundation.js +2 -0
  45. package/lib/es/select/select.scss +3 -4
  46. package/lib/es/select/variables.scss +7 -6
  47. package/lib/es/tooltip/foundation.js +11 -0
  48. package/lib/es/tree/foundation.d.ts +0 -1
  49. package/lib/es/tree/foundation.js +7 -23
  50. package/lib/es/tree/treeUtil.d.ts +1 -2
  51. package/lib/es/tree/treeUtil.js +2 -3
  52. package/lib/es/treeSelect/foundation.d.ts +0 -1
  53. package/lib/es/treeSelect/foundation.js +9 -29
  54. package/lib/es/utils/getMotionObjFromProps.js +2 -2
  55. package/overflowList/foundation.ts +5 -3
  56. package/package.json +4 -3
  57. package/select/foundation.ts +2 -0
  58. package/select/select.scss +3 -4
  59. package/select/variables.scss +7 -6
  60. package/tooltip/foundation.ts +12 -2
  61. package/tree/foundation.ts +8 -17
  62. package/tree/treeUtil.ts +2 -3
  63. package/treeSelect/foundation.ts +9 -21
  64. package/utils/getMotionObjFromProps.ts +3 -2
@@ -1,7 +1,6 @@
1
- import { isEqual, get, difference, isUndefined, assign, cloneDeep, isEmpty, isNumber, includes, isFunction, isObject } from 'lodash';
1
+ import { isEqual, get, difference, isUndefined, assign, isEmpty, isNumber, includes, isFunction, isObject } from 'lodash';
2
2
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
3
3
  import {
4
- filter,
5
4
  findAncestorKeys,
6
5
  calcCheckedKeysForUnchecked,
7
6
  calcCheckedKeysForChecked,
@@ -11,11 +10,13 @@ import {
11
10
  } from '../tree/treeUtil';
12
11
  import { Motion } from '../utils/type';
13
12
  import {
13
+ filter,
14
14
  convertDataToEntities,
15
15
  normalizedArr,
16
16
  isValid,
17
17
  calcMergeType,
18
- getKeysByValuePath
18
+ getKeysByValuePath,
19
+ getKeyByPos
19
20
  } from './util';
20
21
  import { strings } from './constants';
21
22
  import isEnterPress from '../utils/isEnterPress';
@@ -56,6 +57,8 @@ export interface BasicEntity {
56
57
  parentKey?: string;
57
58
  /* key path */
58
59
  path: Array<string>;
60
+ /* pos in treeData */
61
+ pos: string;
59
62
  /* value path */
60
63
  valuePath: Array<string>
61
64
  }
@@ -314,14 +317,6 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
314
317
  return isDisabled;
315
318
  }
316
319
 
317
- getCopyFromState(items: string | string[]) {
318
- const res: Partial<BasicCascaderInnerData> = {};
319
- normalizedArr(items).forEach(key => {
320
- res[key] = cloneDeep(this.getState(key));
321
- });
322
- return res;
323
- }
324
-
325
320
  // prop: is array, return all data
326
321
  getItemPropPath(selectedKey: string, prop: string | any[], keyEntities?: BasicEntities) {
327
322
  const searchMap = keyEntities || this.getState('keyEntities');
@@ -678,8 +673,8 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
678
673
 
679
674
  handleNodeLoad(item: BasicEntity | BasicData) {
680
675
  const { data, key } = item;
681
- const prevLoadingKeys = cloneDeep(this._adapter.getLoadingKeyRefValue());
682
- const prevLoadedKeys = cloneDeep(this._adapter.getLoadedKeyRefValue());
676
+ const prevLoadingKeys = new Set(this._adapter.getLoadingKeyRefValue());
677
+ const prevLoadedKeys = new Set(this._adapter.getLoadedKeyRefValue());
683
678
  const newLoadedKeys = prevLoadedKeys.add(key);
684
679
  const newLoadingKeys = new Set([...prevLoadingKeys]);
685
680
  newLoadingKeys.delete(key);
@@ -699,7 +694,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
699
694
  this._adapter.updateStates({ loading: false });
700
695
  if (!data.isLeaf && !data.children && this.getProp('loadData')) {
701
696
  const loadedKeys = this._adapter.getLoadedKeyRefValue();
702
- const loadingKeys = cloneDeep(this._adapter.getLoadingKeyRefValue());
697
+ const loadingKeys = new Set(this._adapter.getLoadingKeyRefValue());
703
698
  if (loadedKeys.has(key) || loadingKeys.has(key)) {
704
699
  return;
705
700
  }
@@ -841,7 +836,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
841
836
 
842
837
  calcNonDisabledCheckedKeys(eventKey: string, targetStatus: boolean) {
843
838
  const { keyEntities, disabledKeys } = this.getStates();
844
- const { checkedKeys } = this.getCopyFromState(['checkedKeys']);
839
+ const checkedKeys = new Set(this.getState('checkedKeys'));
845
840
  const descendantKeys = normalizeKeyList(findDescendantKeys([eventKey], keyEntities, false), keyEntities, true);
846
841
  const hasDisabled = descendantKeys.some(key => disabledKeys.has(key));
847
842
  if (!hasDisabled) {
@@ -890,7 +885,8 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
890
885
  */
891
886
  calcCheckedKeys(key: string, curCheckedStatus: boolean) {
892
887
  const { keyEntities } = this.getStates();
893
- const { checkedKeys, halfCheckedKeys } = this.getCopyFromState(['checkedKeys', 'halfCheckedKeys']);
888
+ const checkedKeys = new Set(this.getState('checkedKeys')) as Set<string>;
889
+ const halfCheckedKeys = new Set(this.getState('halfCheckedKeys')) as Set<string>;
894
890
  return curCheckedStatus ?
895
891
  calcCheckedKeysForChecked(key, keyEntities, checkedKeys, halfCheckedKeys) :
896
892
  calcCheckedKeysForUnchecked(key, keyEntities, checkedKeys, halfCheckedKeys);
@@ -908,8 +904,8 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
908
904
  if (_notExist) {
909
905
  return false;
910
906
  }
911
- const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join();
912
- return filter(sugInput, data, filterTreeNode, false, filteredPath);
907
+ const filteredPath = this.getItemPropPath(key, treeNodeFilterProp);
908
+ return filter(sugInput, data, filterTreeNode, filteredPath);
913
909
  })
914
910
  .filter(
915
911
  item => (filterTreeNode && !filterLeafOnly) ||
@@ -932,6 +928,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
932
928
  const isControlled = this._isControlledComponent();
933
929
  const newState: Partial<BasicCascaderInnerData> = {};
934
930
  if (multiple) {
931
+ newState.isSearching = false;
935
932
  this._adapter.updateInputValue('');
936
933
  this._adapter.notifyOnSearch('');
937
934
  newState.checkedKeys = new Set([]);
@@ -1026,17 +1023,20 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
1026
1023
  this._adapter.notifyListScroll(e, { panelIndex: ind, activeNode: data });
1027
1024
  }
1028
1025
 
1029
- handleTagRemove(e: any, tagValuePath: string[]) {
1026
+ handleTagRemoveByKey = (key: string) => {
1030
1027
  const { keyEntities } = this.getStates();
1031
1028
  const { disabled } = this.getProps();
1032
1029
  if (disabled) {
1033
1030
  /* istanbul ignore next */
1034
1031
  return;
1035
1032
  }
1036
- const removedItem = (Object.values(keyEntities) as BasicEntity[])
1037
- .filter(item => isEqual(item.valuePath, tagValuePath))[0];
1038
- !isEmpty(removedItem) &&
1039
- !removedItem.data.disabled &&
1040
- this._handleMultipleSelect(removedItem);
1033
+ const removedItem = keyEntities[key] ?? {};
1034
+ !removedItem?.data?.disable && this._handleMultipleSelect(removedItem);
1035
+ }
1036
+
1037
+ handleTagRemoveInTrigger = (pos: string) => {
1038
+ const { treeData } = this.getStates();
1039
+ const key = getKeyByPos(pos, treeData);
1040
+ this.handleTagRemoveByKey(key);
1041
1041
  }
1042
1042
  }
package/cascader/util.ts CHANGED
@@ -21,6 +21,36 @@ export function normalizedArr(val: any) {
21
21
  }
22
22
  }
23
23
 
24
+ /**
25
+ * @returns whether option includes sugInput.
26
+ * When filterTreeNode is a function,returns the result of filterTreeNode which called with (sugInput, target, option).
27
+ */
28
+ export function filter(sugInput: string, option: any, filterTreeNode: any, filteredPath?: string[]) {
29
+ if (!filterTreeNode) {
30
+ return true;
31
+ }
32
+ let filterFn = filterTreeNode;
33
+ let target: string;
34
+ if (typeof filterTreeNode === 'boolean') {
35
+ filterFn = (targetVal: string, val: string) => {
36
+ const input = targetVal.toLowerCase();
37
+ return val
38
+ .toLowerCase()
39
+ .includes(input);
40
+ };
41
+ // 当 filterTreeNode 是 bool 类型时,由 Cascader 内部判断是否符合筛选条件,使用 join('') 修复搜索英文逗号导致所有数据被匹配问题
42
+ // When the type of of filterTreeNode is bool, Cascader internally determines whether it meets the filtering conditions.
43
+ // Use join('') to fix the problem that searching for English commas causes all data to be matched.
44
+ target = filteredPath.join('');
45
+ } else {
46
+ // 当 filterTreeNode 为函数类型时,由用户判断是否符合筛选条件,使用 join(), 和原来保持一致
47
+ // When the type of of filterTreeNode is function, the user determines whether it meets the filtering conditions,
48
+ // uses join() to be consistent with the previous version.
49
+ target = filteredPath.join();
50
+ }
51
+ return filterFn(sugInput, target, option);
52
+ }
53
+
24
54
  /**
25
55
  * Traverse all the data by `treeData`.
26
56
  */
@@ -31,10 +61,12 @@ function traverseDataNodes(treeNodes: any, callback: any) {
31
61
  // Process node if is not root
32
62
  if (node) {
33
63
  const key = parent ? `${parent.key}${VALUE_SPLIT}${node.value}` : node.value;
64
+ const pos = parent ? getPosition(parent.pos, ind) : `${ind}`;
34
65
  item = {
35
66
  data: { ...node },
36
67
  ind,
37
68
  key,
69
+ pos,
38
70
  level: parent ? parent.level + 1 : 0,
39
71
  parentKey: parent ? parent.key : null,
40
72
  path: parent ? [...parent.path, key] : [key],
@@ -74,6 +106,17 @@ export function getValuePathByKey(key: string) {
74
106
  return key.split(VALUE_SPLIT);
75
107
  }
76
108
 
109
+ export function getKeyByPos(pos: string, treeData: any) {
110
+ const posArr = pos.split('-').map(item => Number(item));
111
+ let resultData = treeData;
112
+ let valuePath = [];
113
+ posArr.forEach((item, index) => {
114
+ resultData = index === 0 ? resultData[item] : resultData?.children?.[item];
115
+ valuePath.push(resultData?.value);
116
+ });
117
+ return getKeyByValuePath(valuePath);
118
+ }
119
+
77
120
  export function convertDataToEntities(dataNodes: any) {
78
121
  const keyEntities: any = {};
79
122
 
@@ -18,6 +18,7 @@ import type { Type, DateInputFoundationProps, InsetInputValue } from './inputFou
18
18
  import type { MonthsGridFoundationProps } from './monthsGridFoundation';
19
19
  import type { WeekStartNumber } from './_utils/getMonthTable';
20
20
  import isValidTimeZone from './_utils/isValidTimeZone';
21
+ import warning from '../utils/warning';
21
22
 
22
23
  export type ValidateStatus = ArrayElement<typeof strings.STATUS>;
23
24
  export type InputSize = ArrayElement<typeof strings.SIZE_SET>;
@@ -292,6 +293,8 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
292
293
  parsedV = zonedTimeToUtc(parsedV, prevTimeZone);
293
294
  }
294
295
  result.push(isValidTimeZone(timeZone) ? utcToZonedTime(parsedV, timeZone) : parsedV);
296
+ } else {
297
+ warning(true, `[Semi DatePicker] value cannot be parsed, value: ${String(v)}`);
295
298
  }
296
299
  }
297
300
  }
@@ -1,4 +1,4 @@
1
- import { cloneDeep, isObject, set, get } from 'lodash';
1
+ import { isObject, set, get } from 'lodash';
2
2
  import { format as formatFn } from 'date-fns';
3
3
 
4
4
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
@@ -11,6 +11,7 @@ import { strings } from './constants';
11
11
  import getDefaultPickerDate from './_utils/getDefaultPickerDate';
12
12
  import { compatibleParse } from './_utils/parser';
13
13
  import { isValidDate } from './_utils';
14
+ import copy from 'fast-copy';
14
15
 
15
16
  const KEY_CODE_ENTER = 'Enter';
16
17
  const KEY_CODE_TAB = 'Tab';
@@ -191,7 +192,7 @@ export default class InputFoundation extends BaseFoundation<DateInputAdapter> {
191
192
  const { value, valuePath, insetInputValue } = options;
192
193
  const { format, type, rangeSeparator } = this._adapter.getProps();
193
194
  const insetFormatToken = getInsetInputFormatToken({ type, format });
194
- const newInsetInputValue = set(cloneDeep(insetInputValue), valuePath, value);
195
+ const newInsetInputValue = set(copy(insetInputValue), valuePath, value);
195
196
  const insetInputStr = this.concatInsetInputValue({ insetInputValue: newInsetInputValue });
196
197
  const parsedInsetInputValueFromInputStr = getInsetInputValueFromInsetInputStr({ inputValue: insetInputStr, type, rangeSeparator });
197
198
  const filledTimeInsetInputValue = this._autoFillTimeToInsetInputValue({ insetInputValue: parsedInsetInputValueFromInputStr, valuePath, format: insetFormatToken });
@@ -202,7 +203,7 @@ export default class InputFoundation extends BaseFoundation<DateInputAdapter> {
202
203
  _autoFillTimeToInsetInputValue(options: { insetInputValue: InsetInputValue; format: string; valuePath: string}) {
203
204
  const { valuePath, insetInputValue, format } = options;
204
205
  const { type, defaultPickerValue, dateFnsLocale } = this._adapter.getProps();
205
- const insetInputValueWithTime = cloneDeep(insetInputValue);
206
+ const insetInputValueWithTime = copy(insetInputValue);
206
207
  const { nowDate, nextDate } = getDefaultPickerDate({ defaultPickerValue, format, dateFnsLocale });
207
208
 
208
209
  if (type.includes('Time')) {
@@ -4,7 +4,7 @@ import { PresetPosition } from './foundation';
4
4
  import { ArrayElement } from '../utils/type';
5
5
  import { strings } from './constants';
6
6
  import { PanelType } from './monthsGridFoundation';
7
- import { cloneDeep } from 'lodash';
7
+ import copy from 'fast-copy';
8
8
 
9
9
  type Type = ArrayElement<typeof strings.TYPE_SET>;
10
10
 
@@ -76,7 +76,7 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
76
76
  const left = strings.PANEL_TYPE_LEFT;
77
77
  const right = strings.PANEL_TYPE_RIGHT;
78
78
 
79
- const year = cloneDeep(currentYear);
79
+ const year = copy(currentYear);
80
80
  year[panelType] = item.value;
81
81
 
82
82
  // make sure the right panel time is always less than the left panel time
@@ -102,7 +102,7 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
102
102
  const left = strings.PANEL_TYPE_LEFT;
103
103
  const right = strings.PANEL_TYPE_RIGHT;
104
104
 
105
- const month = cloneDeep(currentMonth);
105
+ const month = copy(currentMonth);
106
106
  month[panelType] = item.month;
107
107
 
108
108
  // make sure the right panel time is always less than the left panel time
@@ -132,7 +132,7 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
132
132
  validMonth = months.slice(0, currentIndex).find(({ month }) => !disabledDate(setMonth(currentDate, month - 1)));
133
133
  }
134
134
  if (validMonth) {
135
- const month = cloneDeep(currentMonth);
135
+ const month = copy(currentMonth);
136
136
  month[panelType] = validMonth.month;
137
137
 
138
138
  // change year and month same time
@@ -7,6 +7,7 @@ $module: #{$prefix}-dropdown;
7
7
  .#{$module} {
8
8
  @include font-size-regular;
9
9
  &-wrapper {
10
+ overflow-y:auto; // prevent flow out of the radius limit area
10
11
  @include shadow-elevated;
11
12
  position: relative;
12
13
  z-index: $z-dropdown;
package/form/utils.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import AsyncValidator from 'async-validator';
2
- import { cloneDeep, toPath, isUndefined } from 'lodash';
2
+ import { toPath, isUndefined } from 'lodash';
3
3
  import { FieldValidateTriggerType, BasicTriggerType, ComponentProps, WithFieldOption } from './interface';
4
4
  import { strings } from './constants';
5
+ import copy from 'fast-copy';
5
6
 
6
7
  /**
7
8
  *
@@ -172,7 +173,7 @@ export function mergeProps(props: any) {
172
173
  delete rest.checked;
173
174
 
174
175
  if (typeof initValue !== 'undefined') {
175
- initValue = cloneDeep(initValue);
176
+ initValue = copy(initValue);
176
177
  }
177
178
 
178
179
  const required = isRequired(rules);
@@ -226,6 +226,10 @@ export default class PreviewInnerFoundation<P = Record<string, any>, S = Record<
226
226
  }
227
227
 
228
228
  const preloadImages = getPreloadImagArr(imgSrc, currentIndex, preLoadGap, infinite);
229
+ if (preloadImages.length === 0) {
230
+ return;
231
+ }
232
+
229
233
  const Img = new Image();
230
234
  let index = 0;
231
235
  function callback(e: any) {
@@ -24,6 +24,7 @@ export interface BasicEntity {
24
24
  parent?: BasicEntity;
25
25
  parentKey?: string;
26
26
  path: Array<string>;
27
+ pos: string;
27
28
  valuePath: Array<string>;
28
29
  }
29
30
  export interface BasicCascaderData {
@@ -193,7 +194,6 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
193
194
  _notifyBlur(e: any): void;
194
195
  _notifyFocus(e: any): void;
195
196
  _isOptionDisabled(key: string, keyEntities: BasicEntities): boolean;
196
- getCopyFromState(items: string | string[]): Partial<BasicCascaderInnerData>;
197
197
  getItemPropPath(selectedKey: string, prop: string | any[], keyEntities?: BasicEntities): any[];
198
198
  _getCacheValue(keyEntities: BasicEntities): any;
199
199
  collectOptions(init?: boolean): void;
@@ -239,16 +239,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
239
239
  * @param {boolean} curCheckedStatus checked status of node
240
240
  */
241
241
  calcCheckedKeys(key: string, curCheckedStatus: boolean): {
242
- checkedKeys: Set<string>; /**
243
- * If selectedKeys does not meet the update conditions,
244
- * and state.selectedKeys is the same as selectedKeys
245
- * at this time, state.selectedKeys should be cleared.
246
- * A typical scenario is:
247
- * The originally selected node is the leaf node, but
248
- * after props.treeData is dynamically updated, the node
249
- * is a non-leaf node. At this point, selectedKeys should
250
- * be cleared.
251
- */
242
+ checkedKeys: Set<string>;
252
243
  halfCheckedKeys: Set<string>;
253
244
  };
254
245
  handleInputChange(sugInput: string): void;
@@ -260,5 +251,6 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
260
251
  getRenderData(): BasicEntity[] | BasicData[];
261
252
  getFilteredData(): BasicData[];
262
253
  handleListScroll(e: any, ind: number): void;
263
- handleTagRemove(e: any, tagValuePath: string[]): void;
254
+ handleTagRemoveByKey: (key: string) => void;
255
+ handleTagRemoveInTrigger: (pos: string) => void;
264
256
  }
@@ -9,7 +9,6 @@ var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
9
9
  var _includes2 = _interopRequireDefault(require("lodash/includes"));
10
10
  var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
11
11
  var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
12
- var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
13
12
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
14
13
  var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
15
14
  var _difference2 = _interopRequireDefault(require("lodash/difference"));
@@ -29,6 +28,28 @@ class CascaderFoundation extends _foundation.default {
29
28
  isSearching: false
30
29
  });
31
30
  };
31
+ this.handleTagRemoveByKey = key => {
32
+ var _a, _b;
33
+ const {
34
+ keyEntities
35
+ } = this.getStates();
36
+ const {
37
+ disabled
38
+ } = this.getProps();
39
+ if (disabled) {
40
+ /* istanbul ignore next */
41
+ return;
42
+ }
43
+ const removedItem = (_a = keyEntities[key]) !== null && _a !== void 0 ? _a : {};
44
+ !((_b = removedItem === null || removedItem === void 0 ? void 0 : removedItem.data) === null || _b === void 0 ? void 0 : _b.disable) && this._handleMultipleSelect(removedItem);
45
+ };
46
+ this.handleTagRemoveInTrigger = pos => {
47
+ const {
48
+ treeData
49
+ } = this.getStates();
50
+ const key = (0, _util.getKeyByPos)(pos, treeData);
51
+ this.handleTagRemoveByKey(key);
52
+ };
32
53
  }
33
54
  init() {
34
55
  const isOpen = this.getProp('open') || this.getProp('defaultOpen');
@@ -91,13 +112,6 @@ class CascaderFoundation extends _foundation.default {
91
112
  const isDisabled = (0, _treeUtil.findAncestorKeys)([key], keyEntities, true).some(item => keyEntities[item].data.disabled);
92
113
  return isDisabled;
93
114
  }
94
- getCopyFromState(items) {
95
- const res = {};
96
- (0, _util.normalizedArr)(items).forEach(key => {
97
- res[key] = (0, _cloneDeep2.default)(this.getState(key));
98
- });
99
- return res;
100
- }
101
115
  // prop: is array, return all data
102
116
  getItemPropPath(selectedKey, prop, keyEntities) {
103
117
  const searchMap = keyEntities || this.getState('keyEntities');
@@ -474,8 +488,8 @@ class CascaderFoundation extends _foundation.default {
474
488
  data,
475
489
  key
476
490
  } = item;
477
- const prevLoadingKeys = (0, _cloneDeep2.default)(this._adapter.getLoadingKeyRefValue());
478
- const prevLoadedKeys = (0, _cloneDeep2.default)(this._adapter.getLoadedKeyRefValue());
491
+ const prevLoadingKeys = new Set(this._adapter.getLoadingKeyRefValue());
492
+ const prevLoadedKeys = new Set(this._adapter.getLoadedKeyRefValue());
479
493
  const newLoadedKeys = prevLoadedKeys.add(key);
480
494
  const newLoadingKeys = new Set([...prevLoadingKeys]);
481
495
  newLoadingKeys.delete(key);
@@ -498,7 +512,7 @@ class CascaderFoundation extends _foundation.default {
498
512
  });
499
513
  if (!data.isLeaf && !data.children && this.getProp('loadData')) {
500
514
  const loadedKeys = this._adapter.getLoadedKeyRefValue();
501
- const loadingKeys = (0, _cloneDeep2.default)(this._adapter.getLoadingKeyRefValue());
515
+ const loadingKeys = new Set(this._adapter.getLoadingKeyRefValue());
502
516
  if (loadedKeys.has(key) || loadingKeys.has(key)) {
503
517
  return;
504
518
  }
@@ -658,9 +672,7 @@ class CascaderFoundation extends _foundation.default {
658
672
  keyEntities,
659
673
  disabledKeys
660
674
  } = this.getStates();
661
- const {
662
- checkedKeys
663
- } = this.getCopyFromState(['checkedKeys']);
675
+ const checkedKeys = new Set(this.getState('checkedKeys'));
664
676
  const descendantKeys = (0, _treeUtil.normalizeKeyList)((0, _treeUtil.findDescendantKeys)([eventKey], keyEntities, false), keyEntities, true);
665
677
  const hasDisabled = descendantKeys.some(key => disabledKeys.has(key));
666
678
  if (!hasDisabled) {
@@ -710,10 +722,8 @@ class CascaderFoundation extends _foundation.default {
710
722
  const {
711
723
  keyEntities
712
724
  } = this.getStates();
713
- const {
714
- checkedKeys,
715
- halfCheckedKeys
716
- } = this.getCopyFromState(['checkedKeys', 'halfCheckedKeys']);
725
+ const checkedKeys = new Set(this.getState('checkedKeys'));
726
+ const halfCheckedKeys = new Set(this.getState('halfCheckedKeys'));
717
727
  return curCheckedStatus ? (0, _treeUtil.calcCheckedKeysForChecked)(key, keyEntities, checkedKeys, halfCheckedKeys) : (0, _treeUtil.calcCheckedKeysForUnchecked)(key, keyEntities, checkedKeys, halfCheckedKeys);
718
728
  }
719
729
  handleInputChange(sugInput) {
@@ -737,8 +747,8 @@ class CascaderFoundation extends _foundation.default {
737
747
  if (_notExist) {
738
748
  return false;
739
749
  }
740
- const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join();
741
- return (0, _treeUtil.filter)(sugInput, data, filterTreeNode, false, filteredPath);
750
+ const filteredPath = this.getItemPropPath(key, treeNodeFilterProp);
751
+ return (0, _util.filter)(sugInput, data, filterTreeNode, filteredPath);
742
752
  }).filter(item => filterTreeNode && !filterLeafOnly || this._isLeaf(item)).map(item => item.key);
743
753
  }
744
754
  this._adapter.updateStates({
@@ -760,6 +770,7 @@ class CascaderFoundation extends _foundation.default {
760
770
  const isControlled = this._isControlledComponent();
761
771
  const newState = {};
762
772
  if (multiple) {
773
+ newState.isSearching = false;
763
774
  this._adapter.updateInputValue('');
764
775
  this._adapter.notifyOnSearch('');
765
776
  newState.checkedKeys = new Set([]);
@@ -862,19 +873,5 @@ class CascaderFoundation extends _foundation.default {
862
873
  activeNode: data
863
874
  });
864
875
  }
865
- handleTagRemove(e, tagValuePath) {
866
- const {
867
- keyEntities
868
- } = this.getStates();
869
- const {
870
- disabled
871
- } = this.getProps();
872
- if (disabled) {
873
- /* istanbul ignore next */
874
- return;
875
- }
876
- const removedItem = Object.values(keyEntities).filter(item => (0, _isEqual2.default)(item.valuePath, tagValuePath))[0];
877
- !(0, _isEmpty2.default)(removedItem) && !removedItem.data.disabled && this._handleMultipleSelect(removedItem);
878
- }
879
876
  }
880
877
  exports.default = CascaderFoundation;
@@ -1,7 +1,13 @@
1
1
  export declare function isValid(val: any): boolean;
2
2
  export declare function normalizedArr(val: any): any[];
3
+ /**
4
+ * @returns whether option includes sugInput.
5
+ * When filterTreeNode is a function,returns the result of filterTreeNode which called with (sugInput, target, option).
6
+ */
7
+ export declare function filter(sugInput: string, option: any, filterTreeNode: any, filteredPath?: string[]): any;
3
8
  export declare function getKeysByValuePath(valuePath: (string | number)[][] | (string | number)[]): string[];
4
9
  export declare function getKeyByValuePath(valuePath: (string | number)[]): string;
5
10
  export declare function getValuePathByKey(key: string): string[];
11
+ export declare function getKeyByPos(pos: string, treeData: any): string;
6
12
  export declare function convertDataToEntities(dataNodes: any): any;
7
13
  export declare function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string;
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.calcMergeType = calcMergeType;
7
7
  exports.convertDataToEntities = convertDataToEntities;
8
+ exports.filter = filter;
9
+ exports.getKeyByPos = getKeyByPos;
8
10
  exports.getKeyByValuePath = getKeyByValuePath;
9
11
  exports.getKeysByValuePath = getKeysByValuePath;
10
12
  exports.getValuePathByKey = getValuePathByKey;
@@ -27,6 +29,33 @@ function normalizedArr(val) {
27
29
  return val;
28
30
  }
29
31
  }
32
+ /**
33
+ * @returns whether option includes sugInput.
34
+ * When filterTreeNode is a function,returns the result of filterTreeNode which called with (sugInput, target, option).
35
+ */
36
+ function filter(sugInput, option, filterTreeNode, filteredPath) {
37
+ if (!filterTreeNode) {
38
+ return true;
39
+ }
40
+ let filterFn = filterTreeNode;
41
+ let target;
42
+ if (typeof filterTreeNode === 'boolean') {
43
+ filterFn = (targetVal, val) => {
44
+ const input = targetVal.toLowerCase();
45
+ return val.toLowerCase().includes(input);
46
+ };
47
+ // 当 filterTreeNode 是 bool 类型时,由 Cascader 内部判断是否符合筛选条件,使用 join('') 修复搜索英文逗号导致所有数据被匹配问题
48
+ // When the type of of filterTreeNode is bool, Cascader internally determines whether it meets the filtering conditions.
49
+ // Use join('') to fix the problem that searching for English commas causes all data to be matched.
50
+ target = filteredPath.join('');
51
+ } else {
52
+ // 当 filterTreeNode 为函数类型时,由用户判断是否符合筛选条件,使用 join(), 和原来保持一致
53
+ // When the type of of filterTreeNode is function, the user determines whether it meets the filtering conditions,
54
+ // uses join() to be consistent with the previous version.
55
+ target = filteredPath.join();
56
+ }
57
+ return filterFn(sugInput, target, option);
58
+ }
30
59
  /**
31
60
  * Traverse all the data by `treeData`.
32
61
  */
@@ -37,10 +66,12 @@ function traverseDataNodes(treeNodes, callback) {
37
66
  // Process node if is not root
38
67
  if (node) {
39
68
  const key = parent ? `${parent.key}${_constants.VALUE_SPLIT}${node.value}` : node.value;
69
+ const pos = parent ? getPosition(parent.pos, ind) : `${ind}`;
40
70
  item = {
41
71
  data: Object.assign({}, node),
42
72
  ind,
43
73
  key,
74
+ pos,
44
75
  level: parent ? parent.level + 1 : 0,
45
76
  parentKey: parent ? parent.key : null,
46
77
  path: parent ? [...parent.path, key] : [key],
@@ -73,6 +104,17 @@ function getKeyByValuePath(valuePath) {
73
104
  function getValuePathByKey(key) {
74
105
  return key.split(_constants.VALUE_SPLIT);
75
106
  }
107
+ function getKeyByPos(pos, treeData) {
108
+ const posArr = pos.split('-').map(item => Number(item));
109
+ let resultData = treeData;
110
+ let valuePath = [];
111
+ posArr.forEach((item, index) => {
112
+ var _a;
113
+ resultData = index === 0 ? resultData[item] : (_a = resultData === null || resultData === void 0 ? void 0 : resultData.children) === null || _a === void 0 ? void 0 : _a[item];
114
+ valuePath.push(resultData === null || resultData === void 0 ? void 0 : resultData.value);
115
+ });
116
+ return getKeyByValuePath(valuePath);
117
+ }
76
118
  function convertDataToEntities(dataNodes) {
77
119
  const keyEntities = {};
78
120
  traverseDataNodes(dataNodes, data => {
@@ -21,6 +21,7 @@ var _constants2 = require("../input/constants");
21
21
  var _getInsetInputFormatToken = _interopRequireDefault(require("./_utils/getInsetInputFormatToken"));
22
22
  var _getInsetInputValueFromInsetInputStr = _interopRequireDefault(require("./_utils/getInsetInputValueFromInsetInputStr"));
23
23
  var _isValidTimeZone = _interopRequireDefault(require("./_utils/isValidTimeZone"));
24
+ var _warning = _interopRequireDefault(require("../utils/warning"));
24
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26
  /**
26
27
  * The datePicker foundation.js is responsible for maintaining the date value and the input box value, as well as the callback of both
@@ -125,6 +126,8 @@ class DatePickerFoundation extends _foundation.default {
125
126
  parsedV = (0, _dateFnsExtra.zonedTimeToUtc)(parsedV, prevTimeZone);
126
127
  }
127
128
  result.push((0, _isValidTimeZone.default)(timeZone) ? (0, _dateFnsExtra.utcToZonedTime)(parsedV, timeZone) : parsedV);
129
+ } else {
130
+ (0, _warning.default)(true, `[Semi DatePicker] value cannot be parsed, value: ${String(v)}`);
128
131
  }
129
132
  }
130
133
  }
@@ -7,7 +7,6 @@ exports.default = void 0;
7
7
  var _get2 = _interopRequireDefault(require("lodash/get"));
8
8
  var _set2 = _interopRequireDefault(require("lodash/set"));
9
9
  var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
10
- var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
11
10
  var _dateFns = require("date-fns");
12
11
  var _foundation = _interopRequireDefault(require("../base/foundation"));
13
12
  var _formatter = require("./_utils/formatter");
@@ -18,6 +17,7 @@ var _constants = require("./constants");
18
17
  var _getDefaultPickerDate = _interopRequireDefault(require("./_utils/getDefaultPickerDate"));
19
18
  var _parser = require("./_utils/parser");
20
19
  var _utils = require("./_utils");
20
+ var _fastCopy = _interopRequireDefault(require("fast-copy"));
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
  const KEY_CODE_ENTER = 'Enter';
23
23
  const KEY_CODE_TAB = 'Tab';
@@ -120,7 +120,7 @@ class InputFoundation extends _foundation.default {
120
120
  type,
121
121
  format
122
122
  });
123
- const newInsetInputValue = (0, _set2.default)((0, _cloneDeep2.default)(insetInputValue), valuePath, value);
123
+ const newInsetInputValue = (0, _set2.default)((0, _fastCopy.default)(insetInputValue), valuePath, value);
124
124
  const insetInputStr = this.concatInsetInputValue({
125
125
  insetInputValue: newInsetInputValue
126
126
  });
@@ -154,7 +154,7 @@ class InputFoundation extends _foundation.default {
154
154
  defaultPickerValue,
155
155
  dateFnsLocale
156
156
  } = this._adapter.getProps();
157
- const insetInputValueWithTime = (0, _cloneDeep2.default)(insetInputValue);
157
+ const insetInputValueWithTime = (0, _fastCopy.default)(insetInputValue);
158
158
  const {
159
159
  nowDate,
160
160
  nextDate