feat: update vc-tree-select to 2.5.4
parent
9b1fba6650
commit
019650db05
|
@ -1,5 +1,5 @@
|
||||||
// export this package's api
|
// export this package's api
|
||||||
// base 2.4.4
|
// base 2.5.4
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import TreeSelect from './src';
|
import TreeSelect from './src';
|
||||||
import ref from 'vue-ref';
|
import ref from 'vue-ref';
|
||||||
|
|
|
@ -21,7 +21,7 @@ function getDerivedStateFromProps(nextProps, prevState) {
|
||||||
keyEntities,
|
keyEntities,
|
||||||
treeExpandedKeys,
|
treeExpandedKeys,
|
||||||
filteredTreeNodes,
|
filteredTreeNodes,
|
||||||
searchValue,
|
upperSearchValue,
|
||||||
} = nextProps;
|
} = nextProps;
|
||||||
|
|
||||||
const newState = {
|
const newState = {
|
||||||
|
@ -47,9 +47,9 @@ function getDerivedStateFromProps(nextProps, prevState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache `expandedKeyList` when filter set
|
// Cache `expandedKeyList` when filter set
|
||||||
if (searchValue && !prevProps.searchValue) {
|
if (upperSearchValue && !prevProps.upperSearchValue) {
|
||||||
newState._cachedExpandedKeyList = expandedKeyList;
|
newState._cachedExpandedKeyList = expandedKeyList;
|
||||||
} else if (!searchValue && prevProps.searchValue && !treeExpandedKeys) {
|
} else if (!upperSearchValue && prevProps.upperSearchValue && !treeExpandedKeys) {
|
||||||
newState._expandedKeyList = cachedExpandedKeyList || [];
|
newState._expandedKeyList = cachedExpandedKeyList || [];
|
||||||
newState._cachedExpandedKeyList = [];
|
newState._cachedExpandedKeyList = [];
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ const BasePopup = {
|
||||||
searchValue: PropTypes.string,
|
searchValue: PropTypes.string,
|
||||||
treeNodes: PropTypes.any,
|
treeNodes: PropTypes.any,
|
||||||
filteredTreeNodes: PropTypes.any,
|
filteredTreeNodes: PropTypes.any,
|
||||||
notFoundContent: PropTypes.string,
|
notFoundContent: PropTypes.any,
|
||||||
|
|
||||||
ariaId: PropTypes.string,
|
ariaId: PropTypes.string,
|
||||||
switcherIcon: PropTypes.any,
|
switcherIcon: PropTypes.any,
|
||||||
|
@ -154,8 +154,8 @@ const BasePopup = {
|
||||||
* Not pass `loadData` when searching. To avoid loop ajax call makes browser crash.
|
* Not pass `loadData` when searching. To avoid loop ajax call makes browser crash.
|
||||||
*/
|
*/
|
||||||
getLoadData() {
|
getLoadData() {
|
||||||
const { loadData, searchValue } = this.$props;
|
const { loadData, upperSearchValue } = this.$props;
|
||||||
if (searchValue) return null;
|
if (upperSearchValue) return null;
|
||||||
return loadData;
|
return loadData;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const selectorPropTypes = () => ({
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
open: PropTypes.bool,
|
open: PropTypes.bool,
|
||||||
valueList: PropTypes.array, // Name as valueList to diff the single value
|
selectorValueList: PropTypes.array,
|
||||||
allowClear: PropTypes.bool,
|
allowClear: PropTypes.bool,
|
||||||
showArrow: PropTypes.bool,
|
showArrow: PropTypes.bool,
|
||||||
// onClick: PropTypes.func,
|
// onClick: PropTypes.func,
|
||||||
|
@ -89,12 +89,12 @@ export default function(modeName) {
|
||||||
},
|
},
|
||||||
|
|
||||||
renderClear() {
|
renderClear() {
|
||||||
const { prefixCls, allowClear, valueList } = this.$props;
|
const { prefixCls, allowClear, selectorValueList } = this.$props;
|
||||||
const {
|
const {
|
||||||
vcTreeSelect: { onSelectorClear },
|
vcTreeSelect: { onSelectorClear },
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
if (!allowClear || !valueList.length || !valueList[0].value) {
|
if (!allowClear || !selectorValueList.length || !selectorValueList[0].value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const clearIcon = getComponentFromProp(this, 'clearIcon');
|
const clearIcon = getComponentFromProp(this, 'clearIcon');
|
||||||
|
|
|
@ -93,7 +93,7 @@ const Select = {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
labelInValue: PropTypes.bool,
|
labelInValue: PropTypes.bool,
|
||||||
maxTagCount: PropTypes.number,
|
maxTagCount: PropTypes.number,
|
||||||
maxTagPlaceholder: PropTypes.any,
|
maxTagPlaceholder: PropTypes.oneOfType([PropTypes.any, PropTypes.func]),
|
||||||
maxTagTextLength: PropTypes.number,
|
maxTagTextLength: PropTypes.number,
|
||||||
showCheckedStrategy: PropTypes.oneOf([SHOW_ALL, SHOW_PARENT, SHOW_CHILD]),
|
showCheckedStrategy: PropTypes.oneOf([SHOW_ALL, SHOW_PARENT, SHOW_CHILD]),
|
||||||
dropdownClassName: PropTypes.string,
|
dropdownClassName: PropTypes.string,
|
||||||
|
@ -104,7 +104,7 @@ const Select = {
|
||||||
treeDataSimpleMode: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
treeDataSimpleMode: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
||||||
treeNodeFilterProp: PropTypes.string,
|
treeNodeFilterProp: PropTypes.string,
|
||||||
treeNodeLabelProp: PropTypes.string,
|
treeNodeLabelProp: PropTypes.string,
|
||||||
treeCheckable: PropTypes.any,
|
treeCheckable: PropTypes.oneOfType([PropTypes.bool, PropTypes.any]),
|
||||||
treeCheckStrictly: PropTypes.bool,
|
treeCheckStrictly: PropTypes.bool,
|
||||||
treeIcon: PropTypes.bool,
|
treeIcon: PropTypes.bool,
|
||||||
treeLine: PropTypes.bool,
|
treeLine: PropTypes.bool,
|
||||||
|
@ -653,7 +653,7 @@ const Select = {
|
||||||
// Clean up `searchValue` when this prop is set
|
// Clean up `searchValue` when this prop is set
|
||||||
if (autoClearSearchValue || inputValue === null) {
|
if (autoClearSearchValue || inputValue === null) {
|
||||||
// Clean state `searchValue` if uncontrolled
|
// Clean state `searchValue` if uncontrolled
|
||||||
if (!this.isSearchValueControlled()) {
|
if (!this.isSearchValueControlled() && (multiple || treeCheckable)) {
|
||||||
this.setUncontrolledState({
|
this.setUncontrolledState({
|
||||||
_searchValue: '',
|
_searchValue: '',
|
||||||
_filteredTreeNodes: null,
|
_filteredTreeNodes: null,
|
||||||
|
@ -773,6 +773,17 @@ const Select = {
|
||||||
// ==================== Trigger =====================
|
// ==================== Trigger =====================
|
||||||
|
|
||||||
onDropdownVisibleChange(open) {
|
onDropdownVisibleChange(open) {
|
||||||
|
const { multiple, treeCheckable } = this.$props;
|
||||||
|
const { _searchValue } = this;
|
||||||
|
|
||||||
|
// When set open success and single mode,
|
||||||
|
// we will reset the input content.
|
||||||
|
if (open && !multiple && !treeCheckable && _searchValue) {
|
||||||
|
this.setUncontrolledState({
|
||||||
|
_searchValue: '',
|
||||||
|
_filteredTreeNodes: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.setOpenState(open, true);
|
this.setOpenState(open, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -796,7 +807,9 @@ const Select = {
|
||||||
const upperSearchValue = String(value).toUpperCase();
|
const upperSearchValue = String(value).toUpperCase();
|
||||||
|
|
||||||
let filterTreeNodeFn = filterTreeNode;
|
let filterTreeNodeFn = filterTreeNode;
|
||||||
if (!filterTreeNodeFn) {
|
if (filterTreeNode === false) {
|
||||||
|
filterTreeNodeFn = () => true;
|
||||||
|
} else if (!filterTreeNodeFn) {
|
||||||
filterTreeNodeFn = (_, node) => {
|
filterTreeNodeFn = (_, node) => {
|
||||||
const nodeValue = String(getPropsData(node)[treeNodeFilterProp]).toUpperCase();
|
const nodeValue = String(getPropsData(node)[treeNodeFilterProp]).toUpperCase();
|
||||||
return nodeValue.indexOf(upperSearchValue) !== -1;
|
return nodeValue.indexOf(upperSearchValue) !== -1;
|
||||||
|
@ -908,7 +921,11 @@ const Select = {
|
||||||
* 2. Fire `onChange` event to user.
|
* 2. Fire `onChange` event to user.
|
||||||
*/
|
*/
|
||||||
triggerChange(missValueList, valueList, extraInfo = {}) {
|
triggerChange(missValueList, valueList, extraInfo = {}) {
|
||||||
const { _valueEntities: valueEntities, _searchValue: searchValue } = this.$data;
|
const {
|
||||||
|
_valueEntities: valueEntities,
|
||||||
|
_searchValue: searchValue,
|
||||||
|
_selectorValueList: prevSelectorValueList,
|
||||||
|
} = this.$data;
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
const { disabled, treeCheckable, treeCheckStrictly } = props;
|
const { disabled, treeCheckable, treeCheckStrictly } = props;
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
|
@ -916,7 +933,7 @@ const Select = {
|
||||||
// Trigger
|
// Trigger
|
||||||
const extra = {
|
const extra = {
|
||||||
// [Legacy] Always return as array contains label & value
|
// [Legacy] Always return as array contains label & value
|
||||||
preValue: this.$data._selectorValueList.map(({ label, value }) => ({ label, value })),
|
preValue: prevSelectorValueList.map(({ label, value }) => ({ label, value })),
|
||||||
...extraInfo,
|
...extraInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ export function toTitle(title) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toArray(data) {
|
export function toArray(data) {
|
||||||
if (!data) return [];
|
if (data === undefined || data === null) return [];
|
||||||
|
|
||||||
return Array.isArray(data) ? data : [data];
|
return Array.isArray(data) ? data : [data];
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ export function parseSimpleTreeData(treeData, { id, pId, rootPId }) {
|
||||||
const rootNodeList = [];
|
const rootNodeList = [];
|
||||||
|
|
||||||
// Fill in the map
|
// Fill in the map
|
||||||
const nodeList = treeData.map(node => {
|
const nodeList = treeData.map((node) => {
|
||||||
const clone = { ...node };
|
const clone = { ...node };
|
||||||
const key = clone[id];
|
const key = clone[id];
|
||||||
keyNodes[key] = clone;
|
keyNodes[key] = clone;
|
||||||
|
@ -203,7 +203,9 @@ export function getFilterTree(h, treeNodes, searchValue, filterFunc, valueEntiti
|
||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
const $slots = getSlots(node);
|
const $slots = getSlots(node);
|
||||||
const children = ($slots.default || []).map(mapFilteredNodeToData).filter(n => n);
|
const children = toNodeArray($slots.default)
|
||||||
|
.map(mapFilteredNodeToData)
|
||||||
|
.filter(n => n);
|
||||||
delete $slots.default;
|
delete $slots.default;
|
||||||
const slotsKey = Object.keys($slots);
|
const slotsKey = Object.keys($slots);
|
||||||
if (children.length || match) {
|
if (children.length || match) {
|
||||||
|
@ -237,7 +239,7 @@ export function formatInternalValue(value, props) {
|
||||||
|
|
||||||
// Parse label in value
|
// Parse label in value
|
||||||
if (isLabelInValue(props)) {
|
if (isLabelInValue(props)) {
|
||||||
return valueList.map(val => {
|
return valueList.map((val) => {
|
||||||
if (typeof val !== 'object' || !val) {
|
if (typeof val !== 'object' || !val) {
|
||||||
return {
|
return {
|
||||||
value: '',
|
value: '',
|
||||||
|
|
Loading…
Reference in New Issue