@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.
- package/cascader/foundation.ts +20 -39
- package/cascader/util.ts +6 -288
- package/lib/cjs/cascader/foundation.d.ts +1 -4
- package/lib/cjs/cascader/foundation.js +18 -33
- package/lib/cjs/cascader/util.d.ts +0 -19
- package/lib/cjs/cascader/util.js +5 -354
- package/lib/cjs/tree/treeUtil.d.ts +0 -1
- package/lib/cjs/tree/treeUtil.js +0 -1
- package/lib/es/cascader/foundation.d.ts +1 -4
- package/lib/es/cascader/foundation.js +13 -28
- package/lib/es/cascader/util.d.ts +0 -19
- package/lib/es/cascader/util.js +5 -334
- package/lib/es/tree/treeUtil.d.ts +0 -1
- package/lib/es/tree/treeUtil.js +3 -1
- package/package.json +2 -2
- package/tree/treeUtil.ts +1 -1
package/cascader/foundation.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { isEqual, get, difference, isUndefined, assign, cloneDeep, isEmpty, isNumber, includes } from 'lodash';
|
|
2
2
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
3
|
-
import { filter } from '../tree/treeUtil';
|
|
4
|
-
import { Motion } from '../utils/type';
|
|
5
3
|
import {
|
|
6
|
-
|
|
7
|
-
findKeysForValues,
|
|
8
|
-
normalizedArr,
|
|
9
|
-
isValid,
|
|
10
|
-
calcMergeType,
|
|
4
|
+
filter,
|
|
11
5
|
findAncestorKeys,
|
|
12
|
-
|
|
13
6
|
calcCheckedKeysForUnchecked,
|
|
14
|
-
|
|
15
7
|
calcCheckedKeysForChecked,
|
|
16
|
-
|
|
17
8
|
calcCheckedKeys,
|
|
18
|
-
|
|
19
9
|
findDescendantKeys,
|
|
20
10
|
normalizeKeyList
|
|
11
|
+
} from '../tree/treeUtil';
|
|
12
|
+
import { Motion } from '../utils/type';
|
|
13
|
+
import {
|
|
14
|
+
convertDataToEntities,
|
|
15
|
+
findKeysForValues,
|
|
16
|
+
normalizedArr,
|
|
17
|
+
isValid,
|
|
18
|
+
calcMergeType
|
|
21
19
|
} from './util';
|
|
22
20
|
import { strings } from './constants';
|
|
23
21
|
import isEnterPress from '../utils/isEnterPress';
|
|
@@ -26,8 +24,7 @@ export interface BasicData {
|
|
|
26
24
|
data: BasicCascaderData;
|
|
27
25
|
disabled: boolean;
|
|
28
26
|
key: string;
|
|
29
|
-
searchText: any[]
|
|
30
|
-
childrenKeys?: string[]
|
|
27
|
+
searchText: any[]
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
export interface BasicEntities {
|
|
@@ -38,7 +35,6 @@ export interface BasicEntity {
|
|
|
38
35
|
_notExist?: boolean;
|
|
39
36
|
/* children list */
|
|
40
37
|
children?: Array<BasicEntity>;
|
|
41
|
-
childrenKeys?: string[];
|
|
42
38
|
/* treedata */
|
|
43
39
|
data: BasicCascaderData;
|
|
44
40
|
/* index */
|
|
@@ -64,8 +60,7 @@ export interface BasicCascaderData {
|
|
|
64
60
|
disabled?: boolean;
|
|
65
61
|
isLeaf?: boolean;
|
|
66
62
|
loading?: boolean;
|
|
67
|
-
children?: BasicCascaderData[]
|
|
68
|
-
childrenKeys?: string[]
|
|
63
|
+
children?: BasicCascaderData[]
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
export type CascaderType = 'large' | 'small' | 'default';
|
|
@@ -267,19 +262,11 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
267
262
|
}
|
|
268
263
|
}
|
|
269
264
|
|
|
270
|
-
|
|
271
|
-
// if (this.getProp('loadData')) {
|
|
272
|
-
// return Boolean(item.isLeaf);
|
|
273
|
-
// }
|
|
274
|
-
// return !item.children || !item.children.length;
|
|
275
|
-
// }
|
|
276
|
-
|
|
277
|
-
_isLeaf(item: BasicEntity | BasicData) {
|
|
278
|
-
const { data, childrenKeys } = item;
|
|
265
|
+
_isLeaf(item: BasicCascaderData) {
|
|
279
266
|
if (this.getProp('loadData')) {
|
|
280
|
-
return Boolean(
|
|
267
|
+
return Boolean(item.isLeaf);
|
|
281
268
|
}
|
|
282
|
-
return !
|
|
269
|
+
return !item.children || !item.children.length;
|
|
283
270
|
}
|
|
284
271
|
|
|
285
272
|
_clearInput() {
|
|
@@ -443,8 +430,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
443
430
|
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
444
431
|
* the option is considered to be selected, even if the option is disabled
|
|
445
432
|
*/
|
|
446
|
-
|
|
447
|
-
if (changeOnSelect || this._isLeaf(selectedItem)) {
|
|
433
|
+
if (changeOnSelect || this._isLeaf(selectedItem.data)) {
|
|
448
434
|
updateStates.selectedKeys = new Set([selectedKey]);
|
|
449
435
|
if (!loadingActive.length) {
|
|
450
436
|
updateStates.activeKeys = new Set(selectedItem.path);
|
|
@@ -588,7 +574,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
588
574
|
handleShowNextByHover(item: BasicEntity) {
|
|
589
575
|
const { keyEntities } = this.getStates();
|
|
590
576
|
const { data, key } = item;
|
|
591
|
-
const isLeaf = this._isLeaf(
|
|
577
|
+
const isLeaf = this._isLeaf(data);
|
|
592
578
|
const activeKeys = keyEntities[key].path;
|
|
593
579
|
this._adapter.updateStates({
|
|
594
580
|
activeKeys: new Set(activeKeys)
|
|
@@ -671,8 +657,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
671
657
|
notifyIfLoadData(item: BasicEntity | BasicData) {
|
|
672
658
|
const { data, key } = item;
|
|
673
659
|
this._adapter.updateStates({ loading: false });
|
|
674
|
-
|
|
675
|
-
if (!data.isLeaf && !data.childrenKeys && this.getProp('loadData')) {
|
|
660
|
+
if (!data.isLeaf && !data.children && this.getProp('loadData')) {
|
|
676
661
|
const { loadedKeys, loadingKeys } = this.getCopyFromState(['loadedKeys', 'loadingKeys']);
|
|
677
662
|
if (loadedKeys.has(key) || loadingKeys.has(key)) {
|
|
678
663
|
return;
|
|
@@ -691,8 +676,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
691
676
|
const filterable = this._isFilterable();
|
|
692
677
|
const { data, key } = item;
|
|
693
678
|
|
|
694
|
-
|
|
695
|
-
const isLeaf = this._isLeaf(item);
|
|
679
|
+
const isLeaf = this._isLeaf(data);
|
|
696
680
|
|
|
697
681
|
const activeKeys = keyEntities[key].path;
|
|
698
682
|
const selectedKey = [key];
|
|
@@ -888,8 +872,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
888
872
|
})
|
|
889
873
|
.filter(
|
|
890
874
|
item => (filterTreeNode && !filterLeafOnly) ||
|
|
891
|
-
|
|
892
|
-
this._isLeaf(item)
|
|
875
|
+
this._isLeaf(item as unknown as BasicCascaderData)
|
|
893
876
|
)
|
|
894
877
|
.map(item => item.key);
|
|
895
878
|
}
|
|
@@ -959,7 +942,6 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
959
942
|
if (isSearching && isFilterable) {
|
|
960
943
|
return this.getFilteredData();
|
|
961
944
|
}
|
|
962
|
-
|
|
963
945
|
return (Object.values(keyEntities) as BasicEntity[])
|
|
964
946
|
.filter(item => item.parentKey === null && !item._notExist)
|
|
965
947
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -983,8 +965,7 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
983
965
|
data: item.data,
|
|
984
966
|
key,
|
|
985
967
|
disabled: isDisabled,
|
|
986
|
-
searchText: itemSearchPath
|
|
987
|
-
childrenKeys: item.childrenKeys,
|
|
968
|
+
searchText: itemSearchPath
|
|
988
969
|
});
|
|
989
970
|
});
|
|
990
971
|
return filteredList;
|
package/cascader/util.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isNull,
|
|
3
3
|
isUndefined,
|
|
4
|
-
isEqual
|
|
5
|
-
uniq,
|
|
6
|
-
isEmpty,
|
|
7
|
-
max
|
|
4
|
+
isEqual
|
|
8
5
|
} from 'lodash';
|
|
9
6
|
import { strings } from './constants';
|
|
10
7
|
|
|
11
|
-
import { KeyEntities, getSortedKeyList } from '../tree/treeUtil';
|
|
12
|
-
|
|
13
8
|
function getPosition(level: any, index: any) {
|
|
14
9
|
return `${level}-${index}`;
|
|
15
10
|
}
|
|
@@ -36,9 +31,8 @@ function traverseDataNodes(treeNodes: any, callback: any) {
|
|
|
36
31
|
// Process node if is not root
|
|
37
32
|
if (node) {
|
|
38
33
|
const key = parent ? getPosition(parent.key, ind) : `${ind}`;
|
|
39
|
-
const { children, ...resetInfo } = node;
|
|
40
34
|
item = {
|
|
41
|
-
data: { ...
|
|
35
|
+
data: { ...node },
|
|
42
36
|
ind,
|
|
43
37
|
key,
|
|
44
38
|
level: parent ? parent.level + 1 : 0,
|
|
@@ -71,17 +65,10 @@ export function convertDataToEntities(dataNodes: any) {
|
|
|
71
65
|
keyEntities[key] = entity;
|
|
72
66
|
|
|
73
67
|
// Fill children
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// }
|
|
79
|
-
const entityParent = keyEntities[parentKey];
|
|
80
|
-
if (entityParent) {
|
|
81
|
-
// entityParent.children = entityParent.children || [];
|
|
82
|
-
// entityParent.children.push(entity);
|
|
83
|
-
entityParent.childrenKeys = entityParent.childrenKeys || [];
|
|
84
|
-
entityParent.childrenKeys.push(key);
|
|
68
|
+
entity.parent = keyEntities[parentKey];
|
|
69
|
+
if (entity.parent) {
|
|
70
|
+
entity.parent.children = entity.parent.children || [];
|
|
71
|
+
entity.parent.children.push(entity);
|
|
85
72
|
}
|
|
86
73
|
});
|
|
87
74
|
return keyEntities;
|
|
@@ -105,273 +92,4 @@ export function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): strin
|
|
|
105
92
|
mergeType = strings.NONE_MERGE_TYPE;
|
|
106
93
|
}
|
|
107
94
|
return mergeType;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function findChildKeys(keys: string[], options: any, omitKeys: any[] = []) {
|
|
111
|
-
const res: any[] = [];
|
|
112
|
-
keys &&
|
|
113
|
-
keys.forEach(key => {
|
|
114
|
-
const opts = options[key];
|
|
115
|
-
// opts &&
|
|
116
|
-
// opts.children &&
|
|
117
|
-
// opts.children.forEach((child: any) => {
|
|
118
|
-
// if (!omitKeys.length || !omitKeys.includes(child.key)) {
|
|
119
|
-
// res.push(child.key);
|
|
120
|
-
// }
|
|
121
|
-
// });
|
|
122
|
-
opts &&
|
|
123
|
-
opts.childrenKeys &&
|
|
124
|
-
opts.childrenKeys.forEach((child: any) => {
|
|
125
|
-
if (!omitKeys.length || !omitKeys.includes(child.key)) {
|
|
126
|
-
res.push(child.key);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
return res;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function findSiblingKeys(selectedKeys: string[], options: any, self = true) {
|
|
134
|
-
const par: any[] = [];
|
|
135
|
-
// selectedKeys.forEach(item => {
|
|
136
|
-
// if (options[item] && options[item].parent) {
|
|
137
|
-
// par.push(options[item].parent.key);
|
|
138
|
-
// }
|
|
139
|
-
// });
|
|
140
|
-
selectedKeys.forEach(item => {
|
|
141
|
-
if (options[item] && options[item].parentKey) {
|
|
142
|
-
par.push(options[item].parentKey);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const res = findChildKeys(uniq(par), options, self ? [] : selectedKeys);
|
|
148
|
-
return res;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function findAncestorKeys(selectedKeys: string[], options: any, self = true) {
|
|
152
|
-
const res: any[] = [];
|
|
153
|
-
// Recursively find the parent element
|
|
154
|
-
// const findPar = (item: any) => {
|
|
155
|
-
// if (item.parent) {
|
|
156
|
-
// res.push(item.parent.key);
|
|
157
|
-
// findPar(item.parent);
|
|
158
|
-
// }
|
|
159
|
-
// };
|
|
160
|
-
const findPar = (item: any) => {
|
|
161
|
-
if (item.parentKey) {
|
|
162
|
-
res.push(item.parentKey);
|
|
163
|
-
findPar(options[item.parentKey]);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
selectedKeys.forEach(item => {
|
|
167
|
-
options[item] && findPar(options[item]);
|
|
168
|
-
if (self) {
|
|
169
|
-
res.push(item);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
return res;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function calcCheckedKeysForUnchecked(key: string, keyEntities: KeyEntities, checkedKeys: Set<string>, halfCheckedKeys: Set<string>) {
|
|
176
|
-
const descendantKeys = findDescendantKeys([key], keyEntities, true);
|
|
177
|
-
const nodeItem = keyEntities[key];
|
|
178
|
-
descendantKeys.forEach(descendantKey => {
|
|
179
|
-
if (checkedKeys.has(descendantKey)) {
|
|
180
|
-
checkedKeys.delete(descendantKey);
|
|
181
|
-
}
|
|
182
|
-
if (halfCheckedKeys.has(descendantKey)) {
|
|
183
|
-
halfCheckedKeys.delete(descendantKey);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
const calcCurrLevel = (node: any) => {
|
|
187
|
-
// const par = node.parent;
|
|
188
|
-
const par = keyEntities[node.parentKey];
|
|
189
|
-
// no parent
|
|
190
|
-
if (!par) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
// Has a parent node, and the parent node is not checked or halfChecked
|
|
194
|
-
if (!checkedKeys.has(par.key) && !halfCheckedKeys.has(par.key)) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
// Has a parent node, and the parent node is checked or halfChecked
|
|
198
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
199
|
-
const { key } = node;
|
|
200
|
-
const siblingKeys = findSiblingKeys([key], keyEntities);
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
202
|
-
const anyChecked = siblingKeys.some(key => checkedKeys.has(key) || halfCheckedKeys.has(key));
|
|
203
|
-
const ancestorKeys = findAncestorKeys([key], keyEntities, false);
|
|
204
|
-
// If there is checked or halfChecked in the sibling node, you need to change the parent node to halfChecked
|
|
205
|
-
if (anyChecked) {
|
|
206
|
-
ancestorKeys.forEach(itemKey => {
|
|
207
|
-
if (checkedKeys.has(itemKey)) {
|
|
208
|
-
checkedKeys.delete(itemKey);
|
|
209
|
-
halfCheckedKeys.add(itemKey);
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
// If there is no checked or halfChecked in the sibling node, you need to change the parent node to unchecked
|
|
213
|
-
} else {
|
|
214
|
-
if (checkedKeys.has(par.key)) {
|
|
215
|
-
checkedKeys.delete(par.key);
|
|
216
|
-
}
|
|
217
|
-
if (halfCheckedKeys.has(par.key)) {
|
|
218
|
-
halfCheckedKeys.delete(par.key);
|
|
219
|
-
}
|
|
220
|
-
calcCurrLevel(par);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
calcCurrLevel(nodeItem);
|
|
224
|
-
return {
|
|
225
|
-
checkedKeys,
|
|
226
|
-
halfCheckedKeys,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export function calcCheckedKeysForChecked(key: string, keyEntities: KeyEntities, checkedKeys: Set<string>, halfCheckedKeys: Set<string>) {
|
|
231
|
-
const descendantKeys = findDescendantKeys([key], keyEntities, true);
|
|
232
|
-
const nodeItem = keyEntities[key];
|
|
233
|
-
checkedKeys = new Set([...checkedKeys, key]);
|
|
234
|
-
const calcCurrLevel = (node: any) => {
|
|
235
|
-
// if (!node.parent) {
|
|
236
|
-
// return;
|
|
237
|
-
// }
|
|
238
|
-
const par = keyEntities[node.parentKey];
|
|
239
|
-
if (!par) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
243
|
-
const { key } = node;
|
|
244
|
-
const siblingKeys = findSiblingKeys([key], keyEntities);
|
|
245
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
246
|
-
const allChecked = siblingKeys.every(key => checkedKeys.has(key));
|
|
247
|
-
if (!allChecked) {
|
|
248
|
-
const ancestorKeys = findAncestorKeys([key], keyEntities, false);
|
|
249
|
-
halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
|
|
250
|
-
} else {
|
|
251
|
-
// const par = node.parent;
|
|
252
|
-
checkedKeys.add(par.key);
|
|
253
|
-
calcCurrLevel(par);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
calcCurrLevel(nodeItem);
|
|
257
|
-
return {
|
|
258
|
-
checkedKeys: new Set([...checkedKeys, ...descendantKeys]),
|
|
259
|
-
halfCheckedKeys,
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function calcCheckedKeys(values: any, keyEntities: KeyEntities) {
|
|
264
|
-
const keyList = Array.isArray(values) ? values : [values];
|
|
265
|
-
const descendantKeys = findDescendantKeys(keyList, keyEntities, true);
|
|
266
|
-
/**
|
|
267
|
-
* Recursively find the parent element. Because the incoming nodes are all checked,
|
|
268
|
-
* their descendants must be checked. That is to say, if the descendant nodes have
|
|
269
|
-
* disabled+unchecked nodes, their ancestor nodes will definitely not be checked
|
|
270
|
-
*/
|
|
271
|
-
const checkedKeys = new Set([...descendantKeys]);
|
|
272
|
-
let halfCheckedKeys = new Set([]);
|
|
273
|
-
let visited: any[] = [];
|
|
274
|
-
|
|
275
|
-
const levelMap:{[key: number]: string[]} = getSortedKeyList(keyList, keyEntities);
|
|
276
|
-
|
|
277
|
-
const calcCurrLevel = (node: any) => {
|
|
278
|
-
// const { key, parent, level } = node;
|
|
279
|
-
const { key, parentKey, level } = node;
|
|
280
|
-
const parent = keyEntities[parentKey];
|
|
281
|
-
// If the node does not have a parent node, or the node has been processed just now, no processing is done
|
|
282
|
-
if (!parent || visited.includes(key)) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const siblingKeys = findSiblingKeys([key], keyEntities);
|
|
287
|
-
// visited for caching to avoid double counting
|
|
288
|
-
visited = [...visited, ...siblingKeys];
|
|
289
|
-
const allChecked = siblingKeys.every((siblingKey: string) => checkedKeys.has(siblingKey));
|
|
290
|
-
if (!allChecked) {
|
|
291
|
-
const ancestorKeys = findAncestorKeys([key], keyEntities, false);
|
|
292
|
-
halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
|
|
293
|
-
} else {
|
|
294
|
-
checkedKeys.add(parent.key);
|
|
295
|
-
// IMPORTANT! parent level may not exist in original level map; if add to the end directly may destroy the hierarchical order
|
|
296
|
-
if (level - 1 in levelMap && level) {
|
|
297
|
-
levelMap[level - 1].push(parent.key);
|
|
298
|
-
} else {
|
|
299
|
-
levelMap[level - 1] = [parent.key];
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
// Loop keyList from deepest Level to topLevel, bottom up
|
|
304
|
-
while (!isEmpty(levelMap)) {
|
|
305
|
-
const maxLevel = max(Object.keys(levelMap).map(key => Number(key)));
|
|
306
|
-
levelMap[maxLevel].forEach((key: string) => calcCurrLevel(keyEntities[key]));
|
|
307
|
-
delete levelMap[maxLevel];
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return {
|
|
311
|
-
checkedKeys,
|
|
312
|
-
halfCheckedKeys,
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export function findDescendantKeys(selectedKeys: string[], options: KeyEntities, self = true) {
|
|
317
|
-
const res: string[] = [];
|
|
318
|
-
const findChild = (item: any) => {
|
|
319
|
-
if (!item) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
// const { children } = item;
|
|
323
|
-
// const hasChildren = isValid(children);
|
|
324
|
-
// if (hasChildren) {
|
|
325
|
-
// children.forEach((child: any) => {
|
|
326
|
-
// res.push(child.key);
|
|
327
|
-
// findChild(options[child.key]);
|
|
328
|
-
// });
|
|
329
|
-
// }
|
|
330
|
-
const { childrenKeys } = item;
|
|
331
|
-
const hasChildren = isValid(childrenKeys);
|
|
332
|
-
if (hasChildren) {
|
|
333
|
-
childrenKeys.forEach((childKey: any) => {
|
|
334
|
-
res.push(childKey);
|
|
335
|
-
findChild(options[childKey]);
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
selectedKeys.forEach(item => {
|
|
340
|
-
if (self) {
|
|
341
|
-
res.push(item);
|
|
342
|
-
}
|
|
343
|
-
findChild(options[item]);
|
|
344
|
-
});
|
|
345
|
-
return res;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export function normalizeKeyList(keyList: any, keyEntities: KeyEntities, leafOnly = false) {
|
|
349
|
-
const res: string[] = [];
|
|
350
|
-
const keyListSet = new Set(keyList);
|
|
351
|
-
if (!leafOnly) {
|
|
352
|
-
keyList.forEach((key: string) => {
|
|
353
|
-
if (!keyEntities[key]) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
const { parentKey } = keyEntities[key];
|
|
357
|
-
if (parentKey && keyListSet.has(parentKey)) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
res.push(key);
|
|
361
|
-
});
|
|
362
|
-
} else {
|
|
363
|
-
keyList.forEach(key => {
|
|
364
|
-
// if (keyEntities[key] && !isValid(keyEntities[key].children)) {
|
|
365
|
-
if (keyEntities[key] && !isValid(keyEntities[key].childrenKeys)) {
|
|
366
|
-
res.push(key);
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
return res;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function calcDisabledKeys(keyEntities: KeyEntities) {
|
|
374
|
-
const disabledKeys = Object.keys(keyEntities).filter(key => keyEntities[key].data.disabled);
|
|
375
|
-
const { checkedKeys } = calcCheckedKeys(disabledKeys, keyEntities);
|
|
376
|
-
return checkedKeys;
|
|
377
95
|
}
|
|
@@ -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:
|
|
174
|
+
_isLeaf(item: BasicCascaderData): boolean;
|
|
178
175
|
_clearInput(): void;
|
|
179
176
|
_notifyBlur(e: any): void;
|
|
180
177
|
_notifyFocus(e: any): void;
|
|
@@ -90,25 +90,14 @@ class CascaderFoundation extends _foundation.default {
|
|
|
90
90
|
|
|
91
91
|
this._adapter.notifyChange(valuePath);
|
|
92
92
|
}
|
|
93
|
-
}
|
|
94
|
-
// if (this.getProp('loadData')) {
|
|
95
|
-
// return Boolean(item.isLeaf);
|
|
96
|
-
// }
|
|
97
|
-
// return !item.children || !item.children.length;
|
|
98
|
-
// }
|
|
99
|
-
|
|
93
|
+
}
|
|
100
94
|
|
|
101
95
|
_isLeaf(item) {
|
|
102
|
-
const {
|
|
103
|
-
data,
|
|
104
|
-
childrenKeys
|
|
105
|
-
} = item;
|
|
106
|
-
|
|
107
96
|
if (this.getProp('loadData')) {
|
|
108
|
-
return Boolean(
|
|
97
|
+
return Boolean(item.isLeaf);
|
|
109
98
|
}
|
|
110
99
|
|
|
111
|
-
return !
|
|
100
|
+
return !item.children || !item.children.length;
|
|
112
101
|
}
|
|
113
102
|
|
|
114
103
|
_clearInput() {
|
|
@@ -128,7 +117,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
128
117
|
}
|
|
129
118
|
|
|
130
119
|
_isOptionDisabled(key, keyEntities) {
|
|
131
|
-
const isDisabled = (0,
|
|
120
|
+
const isDisabled = (0, _treeUtil.findAncestorKeys)([key], keyEntities, true).some(item => keyEntities[item].data.disabled);
|
|
132
121
|
return isDisabled;
|
|
133
122
|
}
|
|
134
123
|
|
|
@@ -303,9 +292,8 @@ class CascaderFoundation extends _foundation.default {
|
|
|
303
292
|
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
304
293
|
* the option is considered to be selected, even if the option is disabled
|
|
305
294
|
*/
|
|
306
|
-
// if (changeOnSelect || this._isLeaf(selectedItem.data)) {
|
|
307
295
|
|
|
308
|
-
if (changeOnSelect || this._isLeaf(selectedItem)) {
|
|
296
|
+
if (changeOnSelect || this._isLeaf(selectedItem.data)) {
|
|
309
297
|
updateStates.selectedKeys = new Set([selectedKey]);
|
|
310
298
|
|
|
311
299
|
if (!loadingActive.length) {
|
|
@@ -496,7 +484,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
496
484
|
key
|
|
497
485
|
} = item;
|
|
498
486
|
|
|
499
|
-
const isLeaf = this._isLeaf(
|
|
487
|
+
const isLeaf = this._isLeaf(data);
|
|
500
488
|
|
|
501
489
|
const activeKeys = keyEntities[key].path;
|
|
502
490
|
|
|
@@ -602,10 +590,9 @@ class CascaderFoundation extends _foundation.default {
|
|
|
602
590
|
|
|
603
591
|
this._adapter.updateStates({
|
|
604
592
|
loading: false
|
|
605
|
-
});
|
|
606
|
-
|
|
593
|
+
});
|
|
607
594
|
|
|
608
|
-
if (!data.isLeaf && !data.
|
|
595
|
+
if (!data.isLeaf && !data.children && this.getProp('loadData')) {
|
|
609
596
|
const {
|
|
610
597
|
loadedKeys,
|
|
611
598
|
loadingKeys
|
|
@@ -650,9 +637,9 @@ class CascaderFoundation extends _foundation.default {
|
|
|
650
637
|
const {
|
|
651
638
|
data,
|
|
652
639
|
key
|
|
653
|
-
} = item;
|
|
640
|
+
} = item;
|
|
654
641
|
|
|
655
|
-
const isLeaf = this._isLeaf(
|
|
642
|
+
const isLeaf = this._isLeaf(data);
|
|
656
643
|
|
|
657
644
|
const activeKeys = keyEntities[key].path;
|
|
658
645
|
const selectedKey = [key];
|
|
@@ -744,7 +731,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
744
731
|
const mergeType = (0, _util.calcMergeType)(autoMergeValue, leafOnly);
|
|
745
732
|
const isLeafOnlyMerge = mergeType === _constants.strings.LEAF_ONLY_MERGE_TYPE;
|
|
746
733
|
const isNoneMerge = mergeType === _constants.strings.NONE_MERGE_TYPE;
|
|
747
|
-
const curResolvedCheckedKeys = new Set((0,
|
|
734
|
+
const curResolvedCheckedKeys = new Set((0, _treeUtil.normalizeKeyList)(curCheckedKeys, keyEntities, isLeafOnlyMerge));
|
|
748
735
|
const curRealCheckedKeys = isNoneMerge ? curCheckedKeys : curResolvedCheckedKeys;
|
|
749
736
|
|
|
750
737
|
if ((0, _isNumber2.default)(max)) {
|
|
@@ -804,7 +791,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
804
791
|
const {
|
|
805
792
|
checkedKeys
|
|
806
793
|
} = this.getCopyFromState(['checkedKeys']);
|
|
807
|
-
const descendantKeys = (0,
|
|
794
|
+
const descendantKeys = (0, _treeUtil.normalizeKeyList)((0, _treeUtil.findDescendantKeys)([eventKey], keyEntities, false), keyEntities, true);
|
|
808
795
|
const hasDisabled = descendantKeys.some(key => disabledKeys.has(key));
|
|
809
796
|
|
|
810
797
|
if (!hasDisabled) {
|
|
@@ -812,8 +799,8 @@ class CascaderFoundation extends _foundation.default {
|
|
|
812
799
|
}
|
|
813
800
|
|
|
814
801
|
const nonDisabled = descendantKeys.filter(key => !disabledKeys.has(key));
|
|
815
|
-
const newCheckedKeys = targetStatus ? [...nonDisabled, ...checkedKeys] : (0, _difference2.default)((0,
|
|
816
|
-
return (0,
|
|
802
|
+
const newCheckedKeys = targetStatus ? [...nonDisabled, ...checkedKeys] : (0, _difference2.default)((0, _treeUtil.normalizeKeyList)([...checkedKeys], keyEntities, true), nonDisabled);
|
|
803
|
+
return (0, _treeUtil.calcCheckedKeys)(newCheckedKeys, keyEntities);
|
|
817
804
|
}
|
|
818
805
|
|
|
819
806
|
calcCheckedStatus(targetStatus, eventKey) {
|
|
@@ -826,7 +813,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
826
813
|
keyEntities,
|
|
827
814
|
disabledKeys
|
|
828
815
|
} = this.getStates();
|
|
829
|
-
const descendantKeys = (0,
|
|
816
|
+
const descendantKeys = (0, _treeUtil.normalizeKeyList)((0, _treeUtil.findDescendantKeys)([eventKey], keyEntities, false), keyEntities, true);
|
|
830
817
|
const hasDisabled = descendantKeys.some(key => disabledKeys.has(key));
|
|
831
818
|
|
|
832
819
|
if (!hasDisabled) {
|
|
@@ -868,7 +855,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
868
855
|
checkedKeys,
|
|
869
856
|
halfCheckedKeys
|
|
870
857
|
} = this.getCopyFromState(['checkedKeys', 'halfCheckedKeys']);
|
|
871
|
-
return curCheckedStatus ? (0,
|
|
858
|
+
return curCheckedStatus ? (0, _treeUtil.calcCheckedKeysForChecked)(key, keyEntities, checkedKeys, halfCheckedKeys) : (0, _treeUtil.calcCheckedKeysForUnchecked)(key, keyEntities, checkedKeys, halfCheckedKeys);
|
|
872
859
|
}
|
|
873
860
|
|
|
874
861
|
handleInputChange(sugInput) {
|
|
@@ -897,8 +884,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
897
884
|
|
|
898
885
|
const filteredPath = this.getItemPropPath(key, treeNodeFilterProp).join();
|
|
899
886
|
return (0, _treeUtil.filter)(sugInput, filteredPath, filterTreeNode, false);
|
|
900
|
-
}).filter(item => filterTreeNode && !filterLeafOnly ||
|
|
901
|
-
this._isLeaf(item)).map(item => item.key);
|
|
887
|
+
}).filter(item => filterTreeNode && !filterLeafOnly || this._isLeaf(item)).map(item => item.key);
|
|
902
888
|
}
|
|
903
889
|
|
|
904
890
|
this._adapter.updateStates({
|
|
@@ -1027,8 +1013,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
1027
1013
|
data: item.data,
|
|
1028
1014
|
key,
|
|
1029
1015
|
disabled: isDisabled,
|
|
1030
|
-
searchText: itemSearchPath
|
|
1031
|
-
childrenKeys: item.childrenKeys
|
|
1016
|
+
searchText: itemSearchPath
|
|
1032
1017
|
});
|
|
1033
1018
|
});
|
|
1034
1019
|
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>;
|