feat: update vc-tree-select to 2.5.4

pull/666/head
wangxueliang 2019-03-04 19:42:40 +08:00
parent 9b1fba6650
commit 019650db05
5 changed files with 39 additions and 20 deletions

View File

@ -1,5 +1,5 @@
// export this package's api
// base 2.4.4
// base 2.5.4
import Vue from 'vue';
import TreeSelect from './src';
import ref from 'vue-ref';

View File

@ -21,7 +21,7 @@ function getDerivedStateFromProps(nextProps, prevState) {
keyEntities,
treeExpandedKeys,
filteredTreeNodes,
searchValue,
upperSearchValue,
} = nextProps;
const newState = {
@ -47,9 +47,9 @@ function getDerivedStateFromProps(nextProps, prevState) {
}
// Cache `expandedKeyList` when filter set
if (searchValue && !prevProps.searchValue) {
if (upperSearchValue && !prevProps.upperSearchValue) {
newState._cachedExpandedKeyList = expandedKeyList;
} else if (!searchValue && prevProps.searchValue && !treeExpandedKeys) {
} else if (!upperSearchValue && prevProps.upperSearchValue && !treeExpandedKeys) {
newState._expandedKeyList = cachedExpandedKeyList || [];
newState._cachedExpandedKeyList = [];
}
@ -90,7 +90,7 @@ const BasePopup = {
searchValue: PropTypes.string,
treeNodes: PropTypes.any,
filteredTreeNodes: PropTypes.any,
notFoundContent: PropTypes.string,
notFoundContent: PropTypes.any,
ariaId: PropTypes.string,
switcherIcon: PropTypes.any,
@ -154,8 +154,8 @@ const BasePopup = {
* Not pass `loadData` when searching. To avoid loop ajax call makes browser crash.
*/
getLoadData() {
const { loadData, searchValue } = this.$props;
if (searchValue) return null;
const { loadData, upperSearchValue } = this.$props;
if (upperSearchValue) return null;
return loadData;
},

View File

@ -14,7 +14,7 @@ export const selectorPropTypes = () => ({
prefixCls: PropTypes.string,
className: PropTypes.string,
open: PropTypes.bool,
valueList: PropTypes.array, // Name as valueList to diff the single value
selectorValueList: PropTypes.array,
allowClear: PropTypes.bool,
showArrow: PropTypes.bool,
// onClick: PropTypes.func,
@ -89,12 +89,12 @@ export default function(modeName) {
},
renderClear() {
const { prefixCls, allowClear, valueList } = this.$props;
const { prefixCls, allowClear, selectorValueList } = this.$props;
const {
vcTreeSelect: { onSelectorClear },
} = this;
if (!allowClear || !valueList.length || !valueList[0].value) {
if (!allowClear || !selectorValueList.length || !selectorValueList[0].value) {
return null;
}
const clearIcon = getComponentFromProp(this, 'clearIcon');

View File

@ -93,7 +93,7 @@ const Select = {
children: PropTypes.any,
labelInValue: PropTypes.bool,
maxTagCount: PropTypes.number,
maxTagPlaceholder: PropTypes.any,
maxTagPlaceholder: PropTypes.oneOfType([PropTypes.any, PropTypes.func]),
maxTagTextLength: PropTypes.number,
showCheckedStrategy: PropTypes.oneOf([SHOW_ALL, SHOW_PARENT, SHOW_CHILD]),
dropdownClassName: PropTypes.string,
@ -104,7 +104,7 @@ const Select = {
treeDataSimpleMode: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
treeNodeFilterProp: PropTypes.string,
treeNodeLabelProp: PropTypes.string,
treeCheckable: PropTypes.any,
treeCheckable: PropTypes.oneOfType([PropTypes.bool, PropTypes.any]),
treeCheckStrictly: PropTypes.bool,
treeIcon: PropTypes.bool,
treeLine: PropTypes.bool,
@ -653,7 +653,7 @@ const Select = {
// Clean up `searchValue` when this prop is set
if (autoClearSearchValue || inputValue === null) {
// Clean state `searchValue` if uncontrolled
if (!this.isSearchValueControlled()) {
if (!this.isSearchValueControlled() && (multiple || treeCheckable)) {
this.setUncontrolledState({
_searchValue: '',
_filteredTreeNodes: null,
@ -773,6 +773,17 @@ const Select = {
// ==================== Trigger =====================
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);
},
@ -796,7 +807,9 @@ const Select = {
const upperSearchValue = String(value).toUpperCase();
let filterTreeNodeFn = filterTreeNode;
if (!filterTreeNodeFn) {
if (filterTreeNode === false) {
filterTreeNodeFn = () => true;
} else if (!filterTreeNodeFn) {
filterTreeNodeFn = (_, node) => {
const nodeValue = String(getPropsData(node)[treeNodeFilterProp]).toUpperCase();
return nodeValue.indexOf(upperSearchValue) !== -1;
@ -908,7 +921,11 @@ const Select = {
* 2. Fire `onChange` event to user.
*/
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 { disabled, treeCheckable, treeCheckStrictly } = props;
if (disabled) return;
@ -916,7 +933,7 @@ const Select = {
// Trigger
const extra = {
// [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,
};

View File

@ -20,7 +20,7 @@ export function toTitle(title) {
}
export function toArray(data) {
if (!data) return [];
if (data === undefined || data === null) return [];
return Array.isArray(data) ? data : [data];
}
@ -118,7 +118,7 @@ export function parseSimpleTreeData(treeData, { id, pId, rootPId }) {
const rootNodeList = [];
// Fill in the map
const nodeList = treeData.map(node => {
const nodeList = treeData.map((node) => {
const clone = { ...node };
const key = clone[id];
keyNodes[key] = clone;
@ -203,7 +203,9 @@ export function getFilterTree(h, treeNodes, searchValue, filterFunc, valueEntiti
match = true;
}
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;
const slotsKey = Object.keys($slots);
if (children.length || match) {
@ -237,7 +239,7 @@ export function formatInternalValue(value, props) {
// Parse label in value
if (isLabelInValue(props)) {
return valueList.map(val => {
return valueList.map((val) => {
if (typeof val !== 'object' || !val) {
return {
value: '',