@douyinfe/semi-foundation 2.50.1 → 2.51.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.
- package/autoComplete/foundation.ts +10 -6
- package/cascader/constants.ts +3 -1
- package/cascader/foundation.ts +11 -13
- package/cascader/util.ts +21 -10
- package/lib/cjs/autoComplete/foundation.js +10 -5
- package/lib/cjs/cascader/constants.d.ts +1 -0
- package/lib/cjs/cascader/constants.js +4 -2
- package/lib/cjs/cascader/foundation.d.ts +10 -1
- package/lib/cjs/cascader/foundation.js +10 -9
- package/lib/cjs/cascader/util.d.ts +3 -1
- package/lib/cjs/cascader/util.js +20 -8
- package/lib/cjs/table/foundation.js +2 -1
- package/lib/es/autoComplete/foundation.js +10 -5
- package/lib/es/cascader/constants.d.ts +1 -0
- package/lib/es/cascader/constants.js +2 -1
- package/lib/es/cascader/foundation.d.ts +10 -1
- package/lib/es/cascader/foundation.js +11 -10
- package/lib/es/cascader/util.d.ts +3 -1
- package/lib/es/cascader/util.js +18 -8
- package/lib/es/table/foundation.js +2 -1
- package/package.json +3 -3
- package/table/foundation.ts +2 -1
|
@@ -235,7 +235,7 @@ class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> e
|
|
|
235
235
|
|
|
236
236
|
const options = this._generateList(data);
|
|
237
237
|
// Get the option whose value match from options
|
|
238
|
-
let selectedOption: StateOptionItem | Array<StateOptionItem> = options.filter(option => renderSelectedItem(option) === selectedValue);
|
|
238
|
+
let selectedOption: StateOptionItem | Array<StateOptionItem> = options.length ? options.filter(option => renderSelectedItem(option) === selectedValue) : [];
|
|
239
239
|
const canMatchInData = selectedOption.length;
|
|
240
240
|
|
|
241
241
|
const selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === selectedValue);
|
|
@@ -262,11 +262,13 @@ class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> e
|
|
|
262
262
|
|
|
263
263
|
let { data, defaultActiveFirstOption } = this.getProps();
|
|
264
264
|
|
|
265
|
-
let
|
|
266
|
-
|
|
267
|
-
const options = this._generateList(data);
|
|
265
|
+
let selectedOptionIndex = -1;
|
|
268
266
|
|
|
269
|
-
|
|
267
|
+
if (searchValue) {
|
|
268
|
+
let renderSelectedItem = this._getRenderSelectedItem();
|
|
269
|
+
const options = this._generateList(data);
|
|
270
|
+
selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === searchValue);
|
|
271
|
+
}
|
|
270
272
|
|
|
271
273
|
if (selectedOptionIndex === -1 && defaultActiveFirstOption) {
|
|
272
274
|
if (focusIndex !== 0) {
|
|
@@ -288,7 +290,9 @@ class AutoCompleteFoundation<P = Record<string, any>, S = Record<string, any>> e
|
|
|
288
290
|
let { renderSelectedItem } = this.getProps();
|
|
289
291
|
|
|
290
292
|
if (typeof renderSelectedItem === 'undefined') {
|
|
291
|
-
renderSelectedItem = (option: any) =>
|
|
293
|
+
renderSelectedItem = (option: any) => {
|
|
294
|
+
return option?.value;
|
|
295
|
+
};
|
|
292
296
|
} else if (renderSelectedItem && typeof renderSelectedItem === 'function') {
|
|
293
297
|
// do nothing
|
|
294
298
|
}
|
package/cascader/constants.ts
CHANGED
package/cascader/foundation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEqual, get, difference, isUndefined, assign, cloneDeep, isEmpty, isNumber, includes, isFunction } from 'lodash';
|
|
1
|
+
import { isEqual, get, difference, isUndefined, assign, cloneDeep, isEmpty, isNumber, includes, isFunction, isObject } from 'lodash';
|
|
2
2
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
3
3
|
import {
|
|
4
4
|
filter,
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
import { Motion } from '../utils/type';
|
|
13
13
|
import {
|
|
14
14
|
convertDataToEntities,
|
|
15
|
-
findKeysForValues,
|
|
16
15
|
normalizedArr,
|
|
17
16
|
isValid,
|
|
18
|
-
calcMergeType
|
|
17
|
+
calcMergeType,
|
|
18
|
+
getKeysByValuePath
|
|
19
19
|
} from './util';
|
|
20
20
|
import { strings } from './constants';
|
|
21
21
|
import isEnterPress from '../utils/isEnterPress';
|
|
@@ -439,14 +439,14 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
439
439
|
const loadingKeys = this._adapter.getLoadingKeyRefValue();
|
|
440
440
|
const filterable = this._isFilterable();
|
|
441
441
|
const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
|
|
442
|
-
|
|
443
|
-
const valuePath = onChangeWithObject
|
|
444
|
-
const selectedKeys =
|
|
442
|
+
const normalizedValue = normalizedArr(value);
|
|
443
|
+
const valuePath = onChangeWithObject && isObject(normalizedValue[0]) ? normalizedValue.map(i => i.value) : normalizedValue;
|
|
444
|
+
const selectedKeys = getKeysByValuePath(valuePath);
|
|
445
445
|
let updateStates: Partial<BasicCascaderInnerData> = {};
|
|
446
446
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
447
|
+
const selectedKey = selectedKeys.length > 0 ? selectedKeys[0] : undefined;
|
|
448
|
+
const selectedItem = selectedKey ? keyEntities[selectedKey] : undefined;
|
|
449
|
+
if (selectedItem) {
|
|
450
450
|
/**
|
|
451
451
|
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
452
452
|
* the option is considered to be selected, even if the option is disabled
|
|
@@ -874,10 +874,8 @@ export default class CascaderFoundation extends BaseFoundation<CascaderAdapter,
|
|
|
874
874
|
const { keyEntities } = this.getStates();
|
|
875
875
|
const values: (string | number)[] = [];
|
|
876
876
|
keys.forEach(key => {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
values.push(valueItem);
|
|
880
|
-
}
|
|
877
|
+
const valueItem = keyEntities[key]?.data?.value;
|
|
878
|
+
valueItem !== undefined && values.push(valueItem);
|
|
881
879
|
});
|
|
882
880
|
const formatValue: number | string | Array<string | number> = values.length === 1 ?
|
|
883
881
|
values[0] :
|
package/cascader/util.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
isUndefined,
|
|
4
4
|
isEqual
|
|
5
5
|
} from 'lodash';
|
|
6
|
-
import { strings } from './constants';
|
|
6
|
+
import { strings, VALUE_SPLIT } from './constants';
|
|
7
7
|
|
|
8
8
|
function getPosition(level: any, index: any) {
|
|
9
9
|
return `${level}-${index}`;
|
|
@@ -30,7 +30,7 @@ function traverseDataNodes(treeNodes: any, callback: any) {
|
|
|
30
30
|
let item: any = null;
|
|
31
31
|
// Process node if is not root
|
|
32
32
|
if (node) {
|
|
33
|
-
const key = parent ?
|
|
33
|
+
const key = parent ? `${parent.key}${VALUE_SPLIT}${node.value}` : node.value;
|
|
34
34
|
item = {
|
|
35
35
|
data: { ...node },
|
|
36
36
|
ind,
|
|
@@ -55,6 +55,25 @@ function traverseDataNodes(treeNodes: any, callback: any) {
|
|
|
55
55
|
processNode(null);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
export function getKeysByValuePath(valuePath: (string | number)[][] | (string | number)[]) {
|
|
59
|
+
if (valuePath?.length) {
|
|
60
|
+
if (Array.isArray(valuePath[0])) {
|
|
61
|
+
return valuePath.map((item) => getKeyByValuePath(item));
|
|
62
|
+
} else {
|
|
63
|
+
return [getKeyByValuePath(valuePath as (string | number)[])];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getKeyByValuePath(valuePath: (string | number)[]) {
|
|
70
|
+
return valuePath.join(VALUE_SPLIT);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getValuePathByKey(key: string) {
|
|
74
|
+
return key.split(VALUE_SPLIT);
|
|
75
|
+
}
|
|
76
|
+
|
|
58
77
|
export function convertDataToEntities(dataNodes: any) {
|
|
59
78
|
const keyEntities: any = {};
|
|
60
79
|
|
|
@@ -74,14 +93,6 @@ export function convertDataToEntities(dataNodes: any) {
|
|
|
74
93
|
return keyEntities;
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
export function findKeysForValues(value: any, keyEntities: any) {
|
|
78
|
-
const valuePath = normalizedArr(value);
|
|
79
|
-
const res = Object.values(keyEntities)
|
|
80
|
-
.filter((item: any) => isEqual(item.valuePath, valuePath))
|
|
81
|
-
.map((item: any) => item.key);
|
|
82
|
-
return res;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
96
|
export function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string {
|
|
86
97
|
let mergeType: string;
|
|
87
98
|
if (leafOnly) {
|
|
@@ -205,7 +205,7 @@ class AutoCompleteFoundation extends _foundation.default {
|
|
|
205
205
|
let renderSelectedItem = this._getRenderSelectedItem();
|
|
206
206
|
const options = this._generateList(data);
|
|
207
207
|
// Get the option whose value match from options
|
|
208
|
-
let selectedOption = options.filter(option => renderSelectedItem(option) === selectedValue);
|
|
208
|
+
let selectedOption = options.length ? options.filter(option => renderSelectedItem(option) === selectedValue) : [];
|
|
209
209
|
const canMatchInData = selectedOption.length;
|
|
210
210
|
const selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === selectedValue);
|
|
211
211
|
let inputValue = '';
|
|
@@ -235,9 +235,12 @@ class AutoCompleteFoundation extends _foundation.default {
|
|
|
235
235
|
data,
|
|
236
236
|
defaultActiveFirstOption
|
|
237
237
|
} = this.getProps();
|
|
238
|
-
let
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
let selectedOptionIndex = -1;
|
|
239
|
+
if (searchValue) {
|
|
240
|
+
let renderSelectedItem = this._getRenderSelectedItem();
|
|
241
|
+
const options = this._generateList(data);
|
|
242
|
+
selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === searchValue);
|
|
243
|
+
}
|
|
241
244
|
if (selectedOptionIndex === -1 && defaultActiveFirstOption) {
|
|
242
245
|
if (focusIndex !== 0) {
|
|
243
246
|
this._adapter.updateFocusIndex(0);
|
|
@@ -259,7 +262,9 @@ class AutoCompleteFoundation extends _foundation.default {
|
|
|
259
262
|
renderSelectedItem
|
|
260
263
|
} = this.getProps();
|
|
261
264
|
if (typeof renderSelectedItem === 'undefined') {
|
|
262
|
-
renderSelectedItem = option =>
|
|
265
|
+
renderSelectedItem = option => {
|
|
266
|
+
return option === null || option === void 0 ? void 0 : option.value;
|
|
267
|
+
};
|
|
263
268
|
} else if (renderSelectedItem && typeof renderSelectedItem === 'function') {
|
|
264
269
|
// do nothing
|
|
265
270
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.strings = exports.numbers = exports.cssClasses = void 0;
|
|
6
|
+
exports.strings = exports.numbers = exports.cssClasses = exports.VALUE_SPLIT = void 0;
|
|
7
7
|
var _constants = require("../base/constants");
|
|
8
8
|
const cssClasses = {
|
|
9
9
|
PREFIX: `${_constants.BASE_CLASS_PREFIX}-cascader`,
|
|
@@ -24,4 +24,6 @@ const strings = {
|
|
|
24
24
|
};
|
|
25
25
|
exports.strings = strings;
|
|
26
26
|
const numbers = {};
|
|
27
|
-
exports.numbers = numbers;
|
|
27
|
+
exports.numbers = numbers;
|
|
28
|
+
const VALUE_SPLIT = '_SEMI_CASCADER_SPLIT_';
|
|
29
|
+
exports.VALUE_SPLIT = VALUE_SPLIT;
|
|
@@ -239,7 +239,16 @@ 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>;
|
|
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
|
+
*/
|
|
243
252
|
halfCheckedKeys: Set<string>;
|
|
244
253
|
};
|
|
245
254
|
handleInputChange(sugInput: string): void;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
|
|
7
8
|
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
|
|
8
9
|
var _includes2 = _interopRequireDefault(require("lodash/includes"));
|
|
9
10
|
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
@@ -227,12 +228,13 @@ class CascaderFoundation extends _foundation.default {
|
|
|
227
228
|
const loadingKeys = this._adapter.getLoadingKeyRefValue();
|
|
228
229
|
const filterable = this._isFilterable();
|
|
229
230
|
const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
|
|
230
|
-
const
|
|
231
|
-
const
|
|
231
|
+
const normalizedValue = (0, _util.normalizedArr)(value);
|
|
232
|
+
const valuePath = onChangeWithObject && (0, _isObject2.default)(normalizedValue[0]) ? normalizedValue.map(i => i.value) : normalizedValue;
|
|
233
|
+
const selectedKeys = (0, _util.getKeysByValuePath)(valuePath);
|
|
232
234
|
let updateStates = {};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
const selectedKey = selectedKeys.length > 0 ? selectedKeys[0] : undefined;
|
|
236
|
+
const selectedItem = selectedKey ? keyEntities[selectedKey] : undefined;
|
|
237
|
+
if (selectedItem) {
|
|
236
238
|
/**
|
|
237
239
|
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
238
240
|
* the option is considered to be selected, even if the option is disabled
|
|
@@ -692,10 +694,9 @@ class CascaderFoundation extends _foundation.default {
|
|
|
692
694
|
} = this.getStates();
|
|
693
695
|
const values = [];
|
|
694
696
|
keys.forEach(key => {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
697
|
+
var _a, _b;
|
|
698
|
+
const valueItem = (_b = (_a = keyEntities[key]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.value;
|
|
699
|
+
valueItem !== undefined && values.push(valueItem);
|
|
699
700
|
});
|
|
700
701
|
const formatValue = values.length === 1 ? values[0] : values;
|
|
701
702
|
this._adapter.notifySelect(formatValue);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare function isValid(val: any): boolean;
|
|
2
2
|
export declare function normalizedArr(val: any): any[];
|
|
3
|
+
export declare function getKeysByValuePath(valuePath: (string | number)[][] | (string | number)[]): string[];
|
|
4
|
+
export declare function getKeyByValuePath(valuePath: (string | number)[]): string;
|
|
5
|
+
export declare function getValuePathByKey(key: string): string[];
|
|
3
6
|
export declare function convertDataToEntities(dataNodes: any): any;
|
|
4
|
-
export declare function findKeysForValues(value: any, keyEntities: any): any[];
|
|
5
7
|
export declare function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string;
|
package/lib/cjs/cascader/util.js
CHANGED
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.calcMergeType = calcMergeType;
|
|
7
7
|
exports.convertDataToEntities = convertDataToEntities;
|
|
8
|
-
exports.
|
|
8
|
+
exports.getKeyByValuePath = getKeyByValuePath;
|
|
9
|
+
exports.getKeysByValuePath = getKeysByValuePath;
|
|
10
|
+
exports.getValuePathByKey = getValuePathByKey;
|
|
9
11
|
exports.isValid = isValid;
|
|
10
12
|
exports.normalizedArr = normalizedArr;
|
|
11
|
-
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
12
13
|
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
13
14
|
var _isNull2 = _interopRequireDefault(require("lodash/isNull"));
|
|
14
15
|
var _constants = require("./constants");
|
|
@@ -35,7 +36,7 @@ function traverseDataNodes(treeNodes, callback) {
|
|
|
35
36
|
let item = null;
|
|
36
37
|
// Process node if is not root
|
|
37
38
|
if (node) {
|
|
38
|
-
const key = parent ?
|
|
39
|
+
const key = parent ? `${parent.key}${_constants.VALUE_SPLIT}${node.value}` : node.value;
|
|
39
40
|
item = {
|
|
40
41
|
data: Object.assign({}, node),
|
|
41
42
|
ind,
|
|
@@ -56,6 +57,22 @@ function traverseDataNodes(treeNodes, callback) {
|
|
|
56
57
|
};
|
|
57
58
|
processNode(null);
|
|
58
59
|
}
|
|
60
|
+
function getKeysByValuePath(valuePath) {
|
|
61
|
+
if (valuePath === null || valuePath === void 0 ? void 0 : valuePath.length) {
|
|
62
|
+
if (Array.isArray(valuePath[0])) {
|
|
63
|
+
return valuePath.map(item => getKeyByValuePath(item));
|
|
64
|
+
} else {
|
|
65
|
+
return [getKeyByValuePath(valuePath)];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
function getKeyByValuePath(valuePath) {
|
|
71
|
+
return valuePath.join(_constants.VALUE_SPLIT);
|
|
72
|
+
}
|
|
73
|
+
function getValuePathByKey(key) {
|
|
74
|
+
return key.split(_constants.VALUE_SPLIT);
|
|
75
|
+
}
|
|
59
76
|
function convertDataToEntities(dataNodes) {
|
|
60
77
|
const keyEntities = {};
|
|
61
78
|
traverseDataNodes(dataNodes, data => {
|
|
@@ -74,11 +91,6 @@ function convertDataToEntities(dataNodes) {
|
|
|
74
91
|
});
|
|
75
92
|
return keyEntities;
|
|
76
93
|
}
|
|
77
|
-
function findKeysForValues(value, keyEntities) {
|
|
78
|
-
const valuePath = normalizedArr(value);
|
|
79
|
-
const res = Object.values(keyEntities).filter(item => (0, _isEqual2.default)(item.valuePath, valuePath)).map(item => item.key);
|
|
80
|
-
return res;
|
|
81
|
-
}
|
|
82
94
|
function calcMergeType(autoMergeValue, leafOnly) {
|
|
83
95
|
let mergeType;
|
|
84
96
|
if (leafOnly) {
|
|
@@ -198,7 +198,7 @@ class AutoCompleteFoundation extends BaseFoundation {
|
|
|
198
198
|
let renderSelectedItem = this._getRenderSelectedItem();
|
|
199
199
|
const options = this._generateList(data);
|
|
200
200
|
// Get the option whose value match from options
|
|
201
|
-
let selectedOption = options.filter(option => renderSelectedItem(option) === selectedValue);
|
|
201
|
+
let selectedOption = options.length ? options.filter(option => renderSelectedItem(option) === selectedValue) : [];
|
|
202
202
|
const canMatchInData = selectedOption.length;
|
|
203
203
|
const selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === selectedValue);
|
|
204
204
|
let inputValue = '';
|
|
@@ -228,9 +228,12 @@ class AutoCompleteFoundation extends BaseFoundation {
|
|
|
228
228
|
data,
|
|
229
229
|
defaultActiveFirstOption
|
|
230
230
|
} = this.getProps();
|
|
231
|
-
let
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
let selectedOptionIndex = -1;
|
|
232
|
+
if (searchValue) {
|
|
233
|
+
let renderSelectedItem = this._getRenderSelectedItem();
|
|
234
|
+
const options = this._generateList(data);
|
|
235
|
+
selectedOptionIndex = options.findIndex(option => renderSelectedItem(option) === searchValue);
|
|
236
|
+
}
|
|
234
237
|
if (selectedOptionIndex === -1 && defaultActiveFirstOption) {
|
|
235
238
|
if (focusIndex !== 0) {
|
|
236
239
|
this._adapter.updateFocusIndex(0);
|
|
@@ -252,7 +255,9 @@ class AutoCompleteFoundation extends BaseFoundation {
|
|
|
252
255
|
renderSelectedItem
|
|
253
256
|
} = this.getProps();
|
|
254
257
|
if (typeof renderSelectedItem === 'undefined') {
|
|
255
|
-
renderSelectedItem = option =>
|
|
258
|
+
renderSelectedItem = option => {
|
|
259
|
+
return option === null || option === void 0 ? void 0 : option.value;
|
|
260
|
+
};
|
|
256
261
|
} else if (renderSelectedItem && typeof renderSelectedItem === 'function') {
|
|
257
262
|
// do nothing
|
|
258
263
|
}
|
|
@@ -239,7 +239,16 @@ 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>;
|
|
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
|
+
*/
|
|
243
252
|
halfCheckedKeys: Set<string>;
|
|
244
253
|
};
|
|
245
254
|
handleInputChange(sugInput: string): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _isObject from "lodash/isObject";
|
|
1
2
|
import _isFunction from "lodash/isFunction";
|
|
2
3
|
import _includes from "lodash/includes";
|
|
3
4
|
import _isNumber from "lodash/isNumber";
|
|
@@ -10,7 +11,7 @@ import _get from "lodash/get";
|
|
|
10
11
|
import _isEqual from "lodash/isEqual";
|
|
11
12
|
import BaseFoundation from '../base/foundation';
|
|
12
13
|
import { filter, findAncestorKeys, calcCheckedKeysForUnchecked, calcCheckedKeysForChecked, calcCheckedKeys, findDescendantKeys, normalizeKeyList } from '../tree/treeUtil';
|
|
13
|
-
import { convertDataToEntities,
|
|
14
|
+
import { convertDataToEntities, normalizedArr, isValid, calcMergeType, getKeysByValuePath } from './util';
|
|
14
15
|
import { strings } from './constants';
|
|
15
16
|
import isEnterPress from '../utils/isEnterPress';
|
|
16
17
|
export default class CascaderFoundation extends BaseFoundation {
|
|
@@ -220,12 +221,13 @@ export default class CascaderFoundation extends BaseFoundation {
|
|
|
220
221
|
const loadingKeys = this._adapter.getLoadingKeyRefValue();
|
|
221
222
|
const filterable = this._isFilterable();
|
|
222
223
|
const loadingActive = [...activeKeys].filter(i => loadingKeys.has(i));
|
|
223
|
-
const
|
|
224
|
-
const
|
|
224
|
+
const normalizedValue = normalizedArr(value);
|
|
225
|
+
const valuePath = onChangeWithObject && _isObject(normalizedValue[0]) ? normalizedValue.map(i => i.value) : normalizedValue;
|
|
226
|
+
const selectedKeys = getKeysByValuePath(valuePath);
|
|
225
227
|
let updateStates = {};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
228
|
+
const selectedKey = selectedKeys.length > 0 ? selectedKeys[0] : undefined;
|
|
229
|
+
const selectedItem = selectedKey ? keyEntities[selectedKey] : undefined;
|
|
230
|
+
if (selectedItem) {
|
|
229
231
|
/**
|
|
230
232
|
* When changeOnSelect is turned on, or the target option is a leaf option,
|
|
231
233
|
* the option is considered to be selected, even if the option is disabled
|
|
@@ -685,10 +687,9 @@ export default class CascaderFoundation extends BaseFoundation {
|
|
|
685
687
|
} = this.getStates();
|
|
686
688
|
const values = [];
|
|
687
689
|
keys.forEach(key => {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
690
|
+
var _a, _b;
|
|
691
|
+
const valueItem = (_b = (_a = keyEntities[key]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.value;
|
|
692
|
+
valueItem !== undefined && values.push(valueItem);
|
|
692
693
|
});
|
|
693
694
|
const formatValue = values.length === 1 ? values[0] : values;
|
|
694
695
|
this._adapter.notifySelect(formatValue);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare function isValid(val: any): boolean;
|
|
2
2
|
export declare function normalizedArr(val: any): any[];
|
|
3
|
+
export declare function getKeysByValuePath(valuePath: (string | number)[][] | (string | number)[]): string[];
|
|
4
|
+
export declare function getKeyByValuePath(valuePath: (string | number)[]): string;
|
|
5
|
+
export declare function getValuePathByKey(key: string): string[];
|
|
3
6
|
export declare function convertDataToEntities(dataNodes: any): any;
|
|
4
|
-
export declare function findKeysForValues(value: any, keyEntities: any): any[];
|
|
5
7
|
export declare function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string;
|
package/lib/es/cascader/util.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import _isEqual from "lodash/isEqual";
|
|
2
1
|
import _isUndefined from "lodash/isUndefined";
|
|
3
2
|
import _isNull from "lodash/isNull";
|
|
4
|
-
import { strings } from './constants';
|
|
3
|
+
import { strings, VALUE_SPLIT } from './constants';
|
|
5
4
|
function getPosition(level, index) {
|
|
6
5
|
return `${level}-${index}`;
|
|
7
6
|
}
|
|
@@ -24,7 +23,7 @@ function traverseDataNodes(treeNodes, callback) {
|
|
|
24
23
|
let item = null;
|
|
25
24
|
// Process node if is not root
|
|
26
25
|
if (node) {
|
|
27
|
-
const key = parent ?
|
|
26
|
+
const key = parent ? `${parent.key}${VALUE_SPLIT}${node.value}` : node.value;
|
|
28
27
|
item = {
|
|
29
28
|
data: Object.assign({}, node),
|
|
30
29
|
ind,
|
|
@@ -45,6 +44,22 @@ function traverseDataNodes(treeNodes, callback) {
|
|
|
45
44
|
};
|
|
46
45
|
processNode(null);
|
|
47
46
|
}
|
|
47
|
+
export function getKeysByValuePath(valuePath) {
|
|
48
|
+
if (valuePath === null || valuePath === void 0 ? void 0 : valuePath.length) {
|
|
49
|
+
if (Array.isArray(valuePath[0])) {
|
|
50
|
+
return valuePath.map(item => getKeyByValuePath(item));
|
|
51
|
+
} else {
|
|
52
|
+
return [getKeyByValuePath(valuePath)];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
export function getKeyByValuePath(valuePath) {
|
|
58
|
+
return valuePath.join(VALUE_SPLIT);
|
|
59
|
+
}
|
|
60
|
+
export function getValuePathByKey(key) {
|
|
61
|
+
return key.split(VALUE_SPLIT);
|
|
62
|
+
}
|
|
48
63
|
export function convertDataToEntities(dataNodes) {
|
|
49
64
|
const keyEntities = {};
|
|
50
65
|
traverseDataNodes(dataNodes, data => {
|
|
@@ -63,11 +78,6 @@ export function convertDataToEntities(dataNodes) {
|
|
|
63
78
|
});
|
|
64
79
|
return keyEntities;
|
|
65
80
|
}
|
|
66
|
-
export function findKeysForValues(value, keyEntities) {
|
|
67
|
-
const valuePath = normalizedArr(value);
|
|
68
|
-
const res = Object.values(keyEntities).filter(item => _isEqual(item.valuePath, valuePath)).map(item => item.key);
|
|
69
|
-
return res;
|
|
70
|
-
}
|
|
71
81
|
export function calcMergeType(autoMergeValue, leafOnly) {
|
|
72
82
|
let mergeType;
|
|
73
83
|
if (leafOnly) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.51.0-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
7
7
|
"prepublishOnly": "npm run build:lib"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@douyinfe/semi-animation": "2.
|
|
10
|
+
"@douyinfe/semi-animation": "2.51.0-beta.0",
|
|
11
11
|
"async-validator": "^3.5.0",
|
|
12
12
|
"classnames": "^2.2.6",
|
|
13
13
|
"date-fns": "^2.29.3",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"*.scss",
|
|
24
24
|
"*.css"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "35dcd5c5793fbe9c564eeac62486a402b84f4075",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
29
29
|
"@babel/preset-env": "^7.15.8",
|
package/table/foundation.ts
CHANGED
|
@@ -989,7 +989,8 @@ class TableFoundation<RecordType> extends BaseFoundation<TableAdapter<RecordType
|
|
|
989
989
|
}
|
|
990
990
|
return true;
|
|
991
991
|
} else {
|
|
992
|
-
|
|
992
|
+
const isAllSelected = allKeys.every(rowKey => selectedRowKeysSet.has(rowKey));
|
|
993
|
+
return isAllSelected || false;
|
|
993
994
|
}
|
|
994
995
|
}
|
|
995
996
|
|