@douyinfe/semi-foundation 2.24.1-alpha.0 → 2.24.2

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.
@@ -3,27 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.calcCheckedKeys = calcCheckedKeys;
7
- exports.calcCheckedKeysForChecked = calcCheckedKeysForChecked;
8
- exports.calcCheckedKeysForUnchecked = calcCheckedKeysForUnchecked;
9
- exports.calcDisabledKeys = calcDisabledKeys;
10
6
  exports.calcMergeType = calcMergeType;
11
7
  exports.convertDataToEntities = convertDataToEntities;
12
- exports.findAncestorKeys = findAncestorKeys;
13
- exports.findChildKeys = findChildKeys;
14
- exports.findDescendantKeys = findDescendantKeys;
15
8
  exports.findKeysForValues = findKeysForValues;
16
- exports.findSiblingKeys = findSiblingKeys;
17
9
  exports.isValid = isValid;
18
- exports.normalizeKeyList = normalizeKeyList;
19
10
  exports.normalizedArr = normalizedArr;
20
11
 
21
- var _max2 = _interopRequireDefault(require("lodash/max"));
22
-
23
- var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
24
-
25
- var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
26
-
27
12
  var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
28
13
 
29
14
  var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
@@ -32,21 +17,8 @@ var _isNull2 = _interopRequireDefault(require("lodash/isNull"));
32
17
 
33
18
  var _constants = require("./constants");
34
19
 
35
- var _treeUtil = require("../tree/treeUtil");
36
-
37
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
21
 
39
- var __rest = void 0 && (void 0).__rest || function (s, e) {
40
- var t = {};
41
-
42
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
43
-
44
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
46
- }
47
- return t;
48
- };
49
-
50
22
  function getPosition(level, index) {
51
23
  return "".concat(level, "-").concat(index);
52
24
  }
@@ -74,14 +46,8 @@ function traverseDataNodes(treeNodes, callback) {
74
46
 
75
47
  if (node) {
76
48
  const key = parent ? getPosition(parent.key, ind) : "".concat(ind);
77
-
78
- const {
79
- children
80
- } = node,
81
- resetInfo = __rest(node, ["children"]);
82
-
83
49
  item = {
84
- data: Object.assign({}, resetInfo),
50
+ data: Object.assign({}, node),
85
51
  ind,
86
52
  key,
87
53
  level: parent ? parent.level + 1 : 0,
@@ -112,19 +78,12 @@ function convertDataToEntities(dataNodes) {
112
78
  } = data;
113
79
  const entity = Object.assign({}, data);
114
80
  keyEntities[key] = entity; // Fill children
115
- // entity.parent = keyEntities[parentKey];
116
- // if (entity.parent) {
117
- // entity.parent.children = entity.parent.children || [];
118
- // entity.parent.children.push(entity);
119
- // }
120
81
 
121
- const entityParent = keyEntities[parentKey];
82
+ entity.parent = keyEntities[parentKey];
122
83
 
123
- if (entityParent) {
124
- // entityParent.children = entityParent.children || [];
125
- // entityParent.children.push(entity);
126
- entityParent.childrenKeys = entityParent.childrenKeys || [];
127
- entityParent.childrenKeys.push(key);
84
+ if (entity.parent) {
85
+ entity.parent.children = entity.parent.children || [];
86
+ entity.parent.children.push(entity);
128
87
  }
129
88
  });
130
89
  return keyEntities;
@@ -148,312 +107,4 @@ function calcMergeType(autoMergeValue, leafOnly) {
148
107
  }
149
108
 
150
109
  return mergeType;
151
- }
152
-
153
- function findChildKeys(keys, options) {
154
- let omitKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
155
- const res = [];
156
- keys && keys.forEach(key => {
157
- const opts = options[key]; // opts &&
158
- // opts.children &&
159
- // opts.children.forEach((child: any) => {
160
- // if (!omitKeys.length || !omitKeys.includes(child.key)) {
161
- // res.push(child.key);
162
- // }
163
- // });
164
-
165
- opts && opts.childrenKeys && opts.childrenKeys.forEach(child => {
166
- if (!omitKeys.length || !omitKeys.includes(child.key)) {
167
- res.push(child.key);
168
- }
169
- });
170
- });
171
- return res;
172
- }
173
-
174
- function findSiblingKeys(selectedKeys, options) {
175
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
176
- const par = []; // selectedKeys.forEach(item => {
177
- // if (options[item] && options[item].parent) {
178
- // par.push(options[item].parent.key);
179
- // }
180
- // });
181
-
182
- selectedKeys.forEach(item => {
183
- if (options[item] && options[item].parentKey) {
184
- par.push(options[item].parentKey);
185
- }
186
- });
187
- const res = findChildKeys((0, _uniq2.default)(par), options, self ? [] : selectedKeys);
188
- return res;
189
- }
190
-
191
- function findAncestorKeys(selectedKeys, options) {
192
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
193
- const res = []; // Recursively find the parent element
194
- // const findPar = (item: any) => {
195
- // if (item.parent) {
196
- // res.push(item.parent.key);
197
- // findPar(item.parent);
198
- // }
199
- // };
200
-
201
- const findPar = item => {
202
- if (item.parentKey) {
203
- res.push(item.parentKey);
204
- findPar(options[item.parentKey]);
205
- }
206
- };
207
-
208
- selectedKeys.forEach(item => {
209
- options[item] && findPar(options[item]);
210
-
211
- if (self) {
212
- res.push(item);
213
- }
214
- });
215
- return res;
216
- }
217
-
218
- function calcCheckedKeysForUnchecked(key, keyEntities, checkedKeys, halfCheckedKeys) {
219
- const descendantKeys = findDescendantKeys([key], keyEntities, true);
220
- const nodeItem = keyEntities[key];
221
- descendantKeys.forEach(descendantKey => {
222
- if (checkedKeys.has(descendantKey)) {
223
- checkedKeys.delete(descendantKey);
224
- }
225
-
226
- if (halfCheckedKeys.has(descendantKey)) {
227
- halfCheckedKeys.delete(descendantKey);
228
- }
229
- });
230
-
231
- const calcCurrLevel = node => {
232
- // const par = node.parent;
233
- const par = keyEntities[node.parentKey]; // no parent
234
-
235
- if (!par) {
236
- return;
237
- } // Has a parent node, and the parent node is not checked or halfChecked
238
-
239
-
240
- if (!checkedKeys.has(par.key) && !halfCheckedKeys.has(par.key)) {
241
- return;
242
- } // Has a parent node, and the parent node is checked or halfChecked
243
- // eslint-disable-next-line @typescript-eslint/no-shadow
244
-
245
-
246
- const {
247
- key
248
- } = node;
249
- const siblingKeys = findSiblingKeys([key], keyEntities); // eslint-disable-next-line @typescript-eslint/no-shadow
250
-
251
- const anyChecked = siblingKeys.some(key => checkedKeys.has(key) || halfCheckedKeys.has(key));
252
- const ancestorKeys = findAncestorKeys([key], keyEntities, false); // If there is checked or halfChecked in the sibling node, you need to change the parent node to halfChecked
253
-
254
- if (anyChecked) {
255
- ancestorKeys.forEach(itemKey => {
256
- if (checkedKeys.has(itemKey)) {
257
- checkedKeys.delete(itemKey);
258
- halfCheckedKeys.add(itemKey);
259
- }
260
- }); // If there is no checked or halfChecked in the sibling node, you need to change the parent node to unchecked
261
- } else {
262
- if (checkedKeys.has(par.key)) {
263
- checkedKeys.delete(par.key);
264
- }
265
-
266
- if (halfCheckedKeys.has(par.key)) {
267
- halfCheckedKeys.delete(par.key);
268
- }
269
-
270
- calcCurrLevel(par);
271
- }
272
- };
273
-
274
- calcCurrLevel(nodeItem);
275
- return {
276
- checkedKeys,
277
- halfCheckedKeys
278
- };
279
- }
280
-
281
- function calcCheckedKeysForChecked(key, keyEntities, checkedKeys, halfCheckedKeys) {
282
- const descendantKeys = findDescendantKeys([key], keyEntities, true);
283
- const nodeItem = keyEntities[key];
284
- checkedKeys = new Set([...checkedKeys, key]);
285
-
286
- const calcCurrLevel = node => {
287
- // if (!node.parent) {
288
- // return;
289
- // }
290
- const par = keyEntities[node.parentKey];
291
-
292
- if (!par) {
293
- return;
294
- } // eslint-disable-next-line @typescript-eslint/no-shadow
295
-
296
-
297
- const {
298
- key
299
- } = node;
300
- const siblingKeys = findSiblingKeys([key], keyEntities); // eslint-disable-next-line @typescript-eslint/no-shadow
301
-
302
- const allChecked = siblingKeys.every(key => checkedKeys.has(key));
303
-
304
- if (!allChecked) {
305
- const ancestorKeys = findAncestorKeys([key], keyEntities, false);
306
- halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
307
- } else {
308
- // const par = node.parent;
309
- checkedKeys.add(par.key);
310
- calcCurrLevel(par);
311
- }
312
- };
313
-
314
- calcCurrLevel(nodeItem);
315
- return {
316
- checkedKeys: new Set([...checkedKeys, ...descendantKeys]),
317
- halfCheckedKeys
318
- };
319
- }
320
-
321
- function calcCheckedKeys(values, keyEntities) {
322
- const keyList = Array.isArray(values) ? values : [values];
323
- const descendantKeys = findDescendantKeys(keyList, keyEntities, true);
324
- /**
325
- * Recursively find the parent element. Because the incoming nodes are all checked,
326
- * their descendants must be checked. That is to say, if the descendant nodes have
327
- * disabled+unchecked nodes, their ancestor nodes will definitely not be checked
328
- */
329
-
330
- const checkedKeys = new Set([...descendantKeys]);
331
- let halfCheckedKeys = new Set([]);
332
- let visited = [];
333
- const levelMap = (0, _treeUtil.getSortedKeyList)(keyList, keyEntities);
334
-
335
- const calcCurrLevel = node => {
336
- // const { key, parent, level } = node;
337
- const {
338
- key,
339
- parentKey,
340
- level
341
- } = node;
342
- const parent = keyEntities[parentKey]; // If the node does not have a parent node, or the node has been processed just now, no processing is done
343
-
344
- if (!parent || visited.includes(key)) {
345
- return;
346
- }
347
-
348
- const siblingKeys = findSiblingKeys([key], keyEntities); // visited for caching to avoid double counting
349
-
350
- visited = [...visited, ...siblingKeys];
351
- const allChecked = siblingKeys.every(siblingKey => checkedKeys.has(siblingKey));
352
-
353
- if (!allChecked) {
354
- const ancestorKeys = findAncestorKeys([key], keyEntities, false);
355
- halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
356
- } else {
357
- checkedKeys.add(parent.key); // IMPORTANT! parent level may not exist in original level map; if add to the end directly may destroy the hierarchical order
358
-
359
- if (level - 1 in levelMap && level) {
360
- levelMap[level - 1].push(parent.key);
361
- } else {
362
- levelMap[level - 1] = [parent.key];
363
- }
364
- }
365
- }; // Loop keyList from deepest Level to topLevel, bottom up
366
-
367
-
368
- while (!(0, _isEmpty2.default)(levelMap)) {
369
- const maxLevel = (0, _max2.default)(Object.keys(levelMap).map(key => Number(key)));
370
- levelMap[maxLevel].forEach(key => calcCurrLevel(keyEntities[key]));
371
- delete levelMap[maxLevel];
372
- }
373
-
374
- return {
375
- checkedKeys,
376
- halfCheckedKeys
377
- };
378
- }
379
-
380
- function findDescendantKeys(selectedKeys, options) {
381
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
382
- const res = [];
383
-
384
- const findChild = item => {
385
- if (!item) {
386
- return;
387
- } // const { children } = item;
388
- // const hasChildren = isValid(children);
389
- // if (hasChildren) {
390
- // children.forEach((child: any) => {
391
- // res.push(child.key);
392
- // findChild(options[child.key]);
393
- // });
394
- // }
395
-
396
-
397
- const {
398
- childrenKeys
399
- } = item;
400
- const hasChildren = isValid(childrenKeys);
401
-
402
- if (hasChildren) {
403
- childrenKeys.forEach(childKey => {
404
- res.push(childKey);
405
- findChild(options[childKey]);
406
- });
407
- }
408
- };
409
-
410
- selectedKeys.forEach(item => {
411
- if (self) {
412
- res.push(item);
413
- }
414
-
415
- findChild(options[item]);
416
- });
417
- return res;
418
- }
419
-
420
- function normalizeKeyList(keyList, keyEntities) {
421
- let leafOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
422
- const res = [];
423
- const keyListSet = new Set(keyList);
424
-
425
- if (!leafOnly) {
426
- keyList.forEach(key => {
427
- if (!keyEntities[key]) {
428
- return;
429
- }
430
-
431
- const {
432
- parentKey
433
- } = keyEntities[key];
434
-
435
- if (parentKey && keyListSet.has(parentKey)) {
436
- return;
437
- }
438
-
439
- res.push(key);
440
- });
441
- } else {
442
- keyList.forEach(key => {
443
- // if (keyEntities[key] && !isValid(keyEntities[key].children)) {
444
- if (keyEntities[key] && !isValid(keyEntities[key].childrenKeys)) {
445
- res.push(key);
446
- }
447
- });
448
- }
449
-
450
- return res;
451
- }
452
-
453
- function calcDisabledKeys(keyEntities) {
454
- const disabledKeys = Object.keys(keyEntities).filter(key => keyEntities[key].data.disabled);
455
- const {
456
- checkedKeys
457
- } = calcCheckedKeys(disabledKeys, keyEntities);
458
- return checkedKeys;
459
110
  }
@@ -38,7 +38,6 @@ export declare function findChildKeys(keys: string[], options: any, omitKeys?: a
38
38
  export declare function findLeafKeys(keys: string[], options: any): any[];
39
39
  export declare function findSiblingKeys(selectedKeys: string[], options: any, self?: boolean): any[];
40
40
  export declare function findAncestorKeys(selectedKeys: string[], options: any, self?: boolean): any[];
41
- export declare function getSortedKeyList(keyList: any[], keyEntities: KeyEntities): {};
42
41
  export declare function calcCheckedKeys(values: any, keyEntities: KeyEntities): {
43
42
  checkedKeys: Set<string>;
44
43
  halfCheckedKeys: Set<any>;
@@ -25,7 +25,6 @@ exports.findSiblingKeys = findSiblingKeys;
25
25
  exports.flattenTreeData = flattenTreeData;
26
26
  exports.getDragNodesKeys = getDragNodesKeys;
27
27
  exports.getMotionKeys = getMotionKeys;
28
- exports.getSortedKeyList = getSortedKeyList;
29
28
  exports.getValueOrKey = getValueOrKey;
30
29
  exports.normalizeKeyList = normalizeKeyList;
31
30
  exports.normalizeValue = normalizeValue;
@@ -4,7 +4,6 @@ export interface BasicData {
4
4
  disabled: boolean;
5
5
  key: string;
6
6
  searchText: any[];
7
- childrenKeys?: string[];
8
7
  }
9
8
  export interface BasicEntities {
10
9
  [idx: string]: BasicEntity;
@@ -12,7 +11,6 @@ export interface BasicEntities {
12
11
  export interface BasicEntity {
13
12
  _notExist?: boolean;
14
13
  children?: Array<BasicEntity>;
15
- childrenKeys?: string[];
16
14
  data: BasicCascaderData;
17
15
  ind: number;
18
16
  key: string;
@@ -30,7 +28,6 @@ export interface BasicCascaderData {
30
28
  isLeaf?: boolean;
31
29
  loading?: boolean;
32
30
  children?: BasicCascaderData[];
33
- childrenKeys?: string[];
34
31
  }
35
32
  export declare type CascaderType = 'large' | 'small' | 'default';
36
33
  export declare type BasicSimpleValueType = string | number | BasicCascaderData;
@@ -174,7 +171,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
174
171
  _isDisabled(): any;
175
172
  _isFilterable(): boolean;
176
173
  _notifyChange(item: BasicEntity | BasicData | Set<string>): void;
177
- _isLeaf(item: BasicEntity | BasicData): boolean;
174
+ _isLeaf(item: BasicCascaderData): boolean;
178
175
  _clearInput(): void;
179
176
  _notifyBlur(e: any): void;
180
177
  _notifyFocus(e: any): void;
@@ -8,8 +8,8 @@ import _difference from "lodash/difference";
8
8
  import _get from "lodash/get";
9
9
  import _isEqual from "lodash/isEqual";
10
10
  import BaseFoundation from '../base/foundation';
11
- import { filter } from '../tree/treeUtil';
12
- import { convertDataToEntities, findKeysForValues, normalizedArr, isValid, calcMergeType, findAncestorKeys, calcCheckedKeysForUnchecked, calcCheckedKeysForChecked, calcCheckedKeys, findDescendantKeys, normalizeKeyList } from './util';
11
+ import { filter, findAncestorKeys, calcCheckedKeysForUnchecked, calcCheckedKeysForChecked, calcCheckedKeys, findDescendantKeys, normalizeKeyList } from '../tree/treeUtil';
12
+ import { convertDataToEntities, findKeysForValues, normalizedArr, isValid, calcMergeType } from './util';
13
13
  import { strings } from './constants';
14
14
  import isEnterPress from '../utils/isEnterPress'; // eslint-disable-next-line max-len
15
15
 
@@ -67,25 +67,14 @@ export default class CascaderFoundation extends BaseFoundation {
67
67
 
68
68
  this._adapter.notifyChange(valuePath);
69
69
  }
70
- } // _isLeaf(item: BasicCascaderData) {
71
- // if (this.getProp('loadData')) {
72
- // return Boolean(item.isLeaf);
73
- // }
74
- // return !item.children || !item.children.length;
75
- // }
76
-
70
+ }
77
71
 
78
72
  _isLeaf(item) {
79
- const {
80
- data,
81
- childrenKeys
82
- } = item;
83
-
84
73
  if (this.getProp('loadData')) {
85
- return Boolean(data.isLeaf);
74
+ return Boolean(item.isLeaf);
86
75
  }
87
76
 
88
- return !childrenKeys || !childrenKeys;
77
+ return !item.children || !item.children.length;
89
78
  }
90
79
 
91
80
  _clearInput() {
@@ -280,9 +269,8 @@ export default class CascaderFoundation extends BaseFoundation {
280
269
  * When changeOnSelect is turned on, or the target option is a leaf option,
281
270
  * the option is considered to be selected, even if the option is disabled
282
271
  */
283
- // if (changeOnSelect || this._isLeaf(selectedItem.data)) {
284
272
 
285
- if (changeOnSelect || this._isLeaf(selectedItem)) {
273
+ if (changeOnSelect || this._isLeaf(selectedItem.data)) {
286
274
  updateStates.selectedKeys = new Set([selectedKey]);
287
275
 
288
276
  if (!loadingActive.length) {
@@ -473,7 +461,7 @@ export default class CascaderFoundation extends BaseFoundation {
473
461
  key
474
462
  } = item;
475
463
 
476
- const isLeaf = this._isLeaf(item);
464
+ const isLeaf = this._isLeaf(data);
477
465
 
478
466
  const activeKeys = keyEntities[key].path;
479
467
 
@@ -579,10 +567,9 @@ export default class CascaderFoundation extends BaseFoundation {
579
567
 
580
568
  this._adapter.updateStates({
581
569
  loading: false
582
- }); // if (!data.isLeaf && !data.children && this.getProp('loadData')) {
583
-
570
+ });
584
571
 
585
- if (!data.isLeaf && !data.childrenKeys && this.getProp('loadData')) {
572
+ if (!data.isLeaf && !data.children && this.getProp('loadData')) {
586
573
  const {
587
574
  loadedKeys,
588
575
  loadingKeys
@@ -627,9 +614,9 @@ export default class CascaderFoundation extends BaseFoundation {
627
614
  const {
628
615
  data,
629
616
  key
630
- } = item; // const isLeaf = this._isLeaf(data);
617
+ } = item;
631
618
 
632
- const isLeaf = this._isLeaf(item);
619
+ const isLeaf = this._isLeaf(data);
633
620
 
634
621
  const activeKeys = keyEntities[key].path;
635
622
  const selectedKey = [key];
@@ -874,8 +861,7 @@ export default class CascaderFoundation extends BaseFoundation {
874
861
 
875
862
  const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join();
876
863
  return filter(sugInput, filteredPath, filterTreeNode, false);
877
- }).filter(item => filterTreeNode && !filterLeafOnly || // this._isLeaf(item.data)
878
- this._isLeaf(item)).map(item => item.key);
864
+ }).filter(item => filterTreeNode && !filterLeafOnly || this._isLeaf(item)).map(item => item.key);
879
865
  }
880
866
 
881
867
  this._adapter.updateStates({
@@ -1004,8 +990,7 @@ export default class CascaderFoundation extends BaseFoundation {
1004
990
  data: item.data,
1005
991
  key,
1006
992
  disabled: isDisabled,
1007
- searchText: itemSearchPath,
1008
- childrenKeys: item.childrenKeys
993
+ searchText: itemSearchPath
1009
994
  });
1010
995
  });
1011
996
  return filteredList;
@@ -1,24 +1,5 @@
1
- import { KeyEntities } from '../tree/treeUtil';
2
1
  export declare function isValid(val: any): boolean;
3
2
  export declare function normalizedArr(val: any): any[];
4
3
  export declare function convertDataToEntities(dataNodes: any): any;
5
4
  export declare function findKeysForValues(value: any, keyEntities: any): any[];
6
5
  export declare function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string;
7
- export declare function findChildKeys(keys: string[], options: any, omitKeys?: any[]): any[];
8
- export declare function findSiblingKeys(selectedKeys: string[], options: any, self?: boolean): any[];
9
- export declare function findAncestorKeys(selectedKeys: string[], options: any, self?: boolean): any[];
10
- export declare function calcCheckedKeysForUnchecked(key: string, keyEntities: KeyEntities, checkedKeys: Set<string>, halfCheckedKeys: Set<string>): {
11
- checkedKeys: Set<string>;
12
- halfCheckedKeys: Set<string>;
13
- };
14
- export declare function calcCheckedKeysForChecked(key: string, keyEntities: KeyEntities, checkedKeys: Set<string>, halfCheckedKeys: Set<string>): {
15
- checkedKeys: Set<string>;
16
- halfCheckedKeys: Set<string>;
17
- };
18
- export declare function calcCheckedKeys(values: any, keyEntities: KeyEntities): {
19
- checkedKeys: Set<string>;
20
- halfCheckedKeys: Set<any>;
21
- };
22
- export declare function findDescendantKeys(selectedKeys: string[], options: KeyEntities, self?: boolean): string[];
23
- export declare function normalizeKeyList(keyList: any, keyEntities: KeyEntities, leafOnly?: boolean): string[];
24
- export declare function calcDisabledKeys(keyEntities: KeyEntities): Set<string>;