@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.
@@ -1,23 +1,7 @@
1
- import _max from "lodash/max";
2
- import _isEmpty from "lodash/isEmpty";
3
- import _uniq from "lodash/uniq";
4
1
  import _isEqual from "lodash/isEqual";
5
2
  import _isUndefined from "lodash/isUndefined";
6
3
  import _isNull from "lodash/isNull";
7
-
8
- var __rest = this && this.__rest || function (s, e) {
9
- var t = {};
10
-
11
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
12
-
13
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
14
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
15
- }
16
- return t;
17
- };
18
-
19
4
  import { strings } from './constants';
20
- import { getSortedKeyList } from '../tree/treeUtil';
21
5
 
22
6
  function getPosition(level, index) {
23
7
  return "".concat(level, "-").concat(index);
@@ -44,14 +28,8 @@ function traverseDataNodes(treeNodes, callback) {
44
28
 
45
29
  if (node) {
46
30
  const key = parent ? getPosition(parent.key, ind) : "".concat(ind);
47
-
48
- const {
49
- children
50
- } = node,
51
- resetInfo = __rest(node, ["children"]);
52
-
53
31
  item = {
54
- data: Object.assign({}, resetInfo),
32
+ data: Object.assign({}, node),
55
33
  ind,
56
34
  key,
57
35
  level: parent ? parent.level + 1 : 0,
@@ -82,19 +60,12 @@ export function convertDataToEntities(dataNodes) {
82
60
  } = data;
83
61
  const entity = Object.assign({}, data);
84
62
  keyEntities[key] = entity; // Fill children
85
- // entity.parent = keyEntities[parentKey];
86
- // if (entity.parent) {
87
- // entity.parent.children = entity.parent.children || [];
88
- // entity.parent.children.push(entity);
89
- // }
90
63
 
91
- const entityParent = keyEntities[parentKey];
64
+ entity.parent = keyEntities[parentKey];
92
65
 
93
- if (entityParent) {
94
- // entityParent.children = entityParent.children || [];
95
- // entityParent.children.push(entity);
96
- entityParent.childrenKeys = entityParent.childrenKeys || [];
97
- entityParent.childrenKeys.push(key);
66
+ if (entity.parent) {
67
+ entity.parent.children = entity.parent.children || [];
68
+ entity.parent.children.push(entity);
98
69
  }
99
70
  });
100
71
  return keyEntities;
@@ -116,304 +87,4 @@ export function calcMergeType(autoMergeValue, leafOnly) {
116
87
  }
117
88
 
118
89
  return mergeType;
119
- }
120
- export function findChildKeys(keys, options) {
121
- let omitKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
122
- const res = [];
123
- keys && keys.forEach(key => {
124
- const opts = options[key]; // opts &&
125
- // opts.children &&
126
- // opts.children.forEach((child: any) => {
127
- // if (!omitKeys.length || !omitKeys.includes(child.key)) {
128
- // res.push(child.key);
129
- // }
130
- // });
131
-
132
- opts && opts.childrenKeys && opts.childrenKeys.forEach(child => {
133
- if (!omitKeys.length || !omitKeys.includes(child.key)) {
134
- res.push(child.key);
135
- }
136
- });
137
- });
138
- return res;
139
- }
140
- export function findSiblingKeys(selectedKeys, options) {
141
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
142
- const par = []; // selectedKeys.forEach(item => {
143
- // if (options[item] && options[item].parent) {
144
- // par.push(options[item].parent.key);
145
- // }
146
- // });
147
-
148
- selectedKeys.forEach(item => {
149
- if (options[item] && options[item].parentKey) {
150
- par.push(options[item].parentKey);
151
- }
152
- });
153
- const res = findChildKeys(_uniq(par), options, self ? [] : selectedKeys);
154
- return res;
155
- }
156
- export function findAncestorKeys(selectedKeys, options) {
157
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
158
- const res = []; // Recursively find the parent element
159
- // const findPar = (item: any) => {
160
- // if (item.parent) {
161
- // res.push(item.parent.key);
162
- // findPar(item.parent);
163
- // }
164
- // };
165
-
166
- const findPar = item => {
167
- if (item.parentKey) {
168
- res.push(item.parentKey);
169
- findPar(options[item.parentKey]);
170
- }
171
- };
172
-
173
- selectedKeys.forEach(item => {
174
- options[item] && findPar(options[item]);
175
-
176
- if (self) {
177
- res.push(item);
178
- }
179
- });
180
- return res;
181
- }
182
- export function calcCheckedKeysForUnchecked(key, keyEntities, checkedKeys, halfCheckedKeys) {
183
- const descendantKeys = findDescendantKeys([key], keyEntities, true);
184
- const nodeItem = keyEntities[key];
185
- descendantKeys.forEach(descendantKey => {
186
- if (checkedKeys.has(descendantKey)) {
187
- checkedKeys.delete(descendantKey);
188
- }
189
-
190
- if (halfCheckedKeys.has(descendantKey)) {
191
- halfCheckedKeys.delete(descendantKey);
192
- }
193
- });
194
-
195
- const calcCurrLevel = node => {
196
- // const par = node.parent;
197
- const par = keyEntities[node.parentKey]; // no parent
198
-
199
- if (!par) {
200
- return;
201
- } // Has a parent node, and the parent node is not checked or halfChecked
202
-
203
-
204
- if (!checkedKeys.has(par.key) && !halfCheckedKeys.has(par.key)) {
205
- return;
206
- } // Has a parent node, and the parent node is checked or halfChecked
207
- // eslint-disable-next-line @typescript-eslint/no-shadow
208
-
209
-
210
- const {
211
- key
212
- } = node;
213
- const siblingKeys = findSiblingKeys([key], keyEntities); // eslint-disable-next-line @typescript-eslint/no-shadow
214
-
215
- const anyChecked = siblingKeys.some(key => checkedKeys.has(key) || halfCheckedKeys.has(key));
216
- 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
217
-
218
- if (anyChecked) {
219
- ancestorKeys.forEach(itemKey => {
220
- if (checkedKeys.has(itemKey)) {
221
- checkedKeys.delete(itemKey);
222
- halfCheckedKeys.add(itemKey);
223
- }
224
- }); // If there is no checked or halfChecked in the sibling node, you need to change the parent node to unchecked
225
- } else {
226
- if (checkedKeys.has(par.key)) {
227
- checkedKeys.delete(par.key);
228
- }
229
-
230
- if (halfCheckedKeys.has(par.key)) {
231
- halfCheckedKeys.delete(par.key);
232
- }
233
-
234
- calcCurrLevel(par);
235
- }
236
- };
237
-
238
- calcCurrLevel(nodeItem);
239
- return {
240
- checkedKeys,
241
- halfCheckedKeys
242
- };
243
- }
244
- export function calcCheckedKeysForChecked(key, keyEntities, checkedKeys, halfCheckedKeys) {
245
- const descendantKeys = findDescendantKeys([key], keyEntities, true);
246
- const nodeItem = keyEntities[key];
247
- checkedKeys = new Set([...checkedKeys, key]);
248
-
249
- const calcCurrLevel = node => {
250
- // if (!node.parent) {
251
- // return;
252
- // }
253
- const par = keyEntities[node.parentKey];
254
-
255
- if (!par) {
256
- return;
257
- } // eslint-disable-next-line @typescript-eslint/no-shadow
258
-
259
-
260
- const {
261
- key
262
- } = node;
263
- const siblingKeys = findSiblingKeys([key], keyEntities); // eslint-disable-next-line @typescript-eslint/no-shadow
264
-
265
- const allChecked = siblingKeys.every(key => checkedKeys.has(key));
266
-
267
- if (!allChecked) {
268
- const ancestorKeys = findAncestorKeys([key], keyEntities, false);
269
- halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
270
- } else {
271
- // const par = node.parent;
272
- checkedKeys.add(par.key);
273
- calcCurrLevel(par);
274
- }
275
- };
276
-
277
- calcCurrLevel(nodeItem);
278
- return {
279
- checkedKeys: new Set([...checkedKeys, ...descendantKeys]),
280
- halfCheckedKeys
281
- };
282
- }
283
- export function calcCheckedKeys(values, keyEntities) {
284
- const keyList = Array.isArray(values) ? values : [values];
285
- const descendantKeys = findDescendantKeys(keyList, keyEntities, true);
286
- /**
287
- * Recursively find the parent element. Because the incoming nodes are all checked,
288
- * their descendants must be checked. That is to say, if the descendant nodes have
289
- * disabled+unchecked nodes, their ancestor nodes will definitely not be checked
290
- */
291
-
292
- const checkedKeys = new Set([...descendantKeys]);
293
- let halfCheckedKeys = new Set([]);
294
- let visited = [];
295
- const levelMap = getSortedKeyList(keyList, keyEntities);
296
-
297
- const calcCurrLevel = node => {
298
- // const { key, parent, level } = node;
299
- const {
300
- key,
301
- parentKey,
302
- level
303
- } = node;
304
- 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
305
-
306
- if (!parent || visited.includes(key)) {
307
- return;
308
- }
309
-
310
- const siblingKeys = findSiblingKeys([key], keyEntities); // visited for caching to avoid double counting
311
-
312
- visited = [...visited, ...siblingKeys];
313
- const allChecked = siblingKeys.every(siblingKey => checkedKeys.has(siblingKey));
314
-
315
- if (!allChecked) {
316
- const ancestorKeys = findAncestorKeys([key], keyEntities, false);
317
- halfCheckedKeys = new Set([...halfCheckedKeys, ...ancestorKeys]);
318
- } else {
319
- 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
320
-
321
- if (level - 1 in levelMap && level) {
322
- levelMap[level - 1].push(parent.key);
323
- } else {
324
- levelMap[level - 1] = [parent.key];
325
- }
326
- }
327
- }; // Loop keyList from deepest Level to topLevel, bottom up
328
-
329
-
330
- while (!_isEmpty(levelMap)) {
331
- const maxLevel = _max(Object.keys(levelMap).map(key => Number(key)));
332
-
333
- levelMap[maxLevel].forEach(key => calcCurrLevel(keyEntities[key]));
334
- delete levelMap[maxLevel];
335
- }
336
-
337
- return {
338
- checkedKeys,
339
- halfCheckedKeys
340
- };
341
- }
342
- export function findDescendantKeys(selectedKeys, options) {
343
- let self = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
344
- const res = [];
345
-
346
- const findChild = item => {
347
- if (!item) {
348
- return;
349
- } // const { children } = item;
350
- // const hasChildren = isValid(children);
351
- // if (hasChildren) {
352
- // children.forEach((child: any) => {
353
- // res.push(child.key);
354
- // findChild(options[child.key]);
355
- // });
356
- // }
357
-
358
-
359
- const {
360
- childrenKeys
361
- } = item;
362
- const hasChildren = isValid(childrenKeys);
363
-
364
- if (hasChildren) {
365
- childrenKeys.forEach(childKey => {
366
- res.push(childKey);
367
- findChild(options[childKey]);
368
- });
369
- }
370
- };
371
-
372
- selectedKeys.forEach(item => {
373
- if (self) {
374
- res.push(item);
375
- }
376
-
377
- findChild(options[item]);
378
- });
379
- return res;
380
- }
381
- export function normalizeKeyList(keyList, keyEntities) {
382
- let leafOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
383
- const res = [];
384
- const keyListSet = new Set(keyList);
385
-
386
- if (!leafOnly) {
387
- keyList.forEach(key => {
388
- if (!keyEntities[key]) {
389
- return;
390
- }
391
-
392
- const {
393
- parentKey
394
- } = keyEntities[key];
395
-
396
- if (parentKey && keyListSet.has(parentKey)) {
397
- return;
398
- }
399
-
400
- res.push(key);
401
- });
402
- } else {
403
- keyList.forEach(key => {
404
- // if (keyEntities[key] && !isValid(keyEntities[key].children)) {
405
- if (keyEntities[key] && !isValid(keyEntities[key].childrenKeys)) {
406
- res.push(key);
407
- }
408
- });
409
- }
410
-
411
- return res;
412
- }
413
- export function calcDisabledKeys(keyEntities) {
414
- const disabledKeys = Object.keys(keyEntities).filter(key => keyEntities[key].data.disabled);
415
- const {
416
- checkedKeys
417
- } = calcCheckedKeys(disabledKeys, keyEntities);
418
- return checkedKeys;
419
90
  }
@@ -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>;
@@ -294,7 +294,8 @@ export function findAncestorKeys(selectedKeys, options) {
294
294
  });
295
295
  return res;
296
296
  }
297
- export function getSortedKeyList(keyList, keyEntities) {
297
+
298
+ function getSortedKeyList(keyList, keyEntities) {
298
299
  const levelMap = {};
299
300
  keyList.forEach(key => {
300
301
  if (!keyEntities[key]) {
@@ -313,6 +314,7 @@ export function getSortedKeyList(keyList, keyEntities) {
313
314
  });
314
315
  return levelMap;
315
316
  }
317
+
316
318
  export function calcCheckedKeys(values, keyEntities) {
317
319
  const keyList = Array.isArray(values) ? values : [values];
318
320
  const descendantKeys = findDescendantKeys(keyList, keyEntities, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-foundation",
3
- "version": "2.24.1-alpha.0",
3
+ "version": "2.24.2",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build:lib": "node ./scripts/compileLib.js",
@@ -23,7 +23,7 @@
23
23
  "*.scss",
24
24
  "*.css"
25
25
  ],
26
- "gitHead": "199105285d4ce2c2572968aeaf31e0a16c4b47f5",
26
+ "gitHead": "41831fb74dbc194221e9be7034dbcf93e4a35aa5",
27
27
  "devDependencies": {
28
28
  "@babel/plugin-transform-runtime": "^7.15.8",
29
29
  "@babel/preset-env": "^7.15.8",
package/tree/treeUtil.ts CHANGED
@@ -286,7 +286,7 @@ export function findAncestorKeys(selectedKeys: string[], options: any, self = tr
286
286
  return res;
287
287
  }
288
288
 
289
- export function getSortedKeyList(keyList: any[], keyEntities: KeyEntities) {
289
+ function getSortedKeyList(keyList: any[], keyEntities: KeyEntities) {
290
290
  const levelMap = {};
291
291
  keyList.forEach(key => {
292
292
  if (!keyEntities[key]) {