1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _extends from 'babel-runtime/helpers/extends';
import VcTreeSelect, { TreeNode, SHOW_ALL, SHOW_PARENT, SHOW_CHILD } from '../vc-tree-select';
import classNames from 'classnames';
import { TreeSelectProps } from './interface';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import warning from '../_util/warning';
import { initDefaultProps, getOptionProps, getComponentFromProp, filterEmpty, isValidElement } from '../_util/props-util';
export { TreeData, TreeSelectProps } from './interface';
import Icon from '../icon';
import omit from 'omit.js';
import { cloneElement } from '../_util/vnode';
var TreeSelect = {
TreeNode: _extends({}, TreeNode, { name: 'ATreeSelectNode' }),
SHOW_ALL: SHOW_ALL,
SHOW_PARENT: SHOW_PARENT,
SHOW_CHILD: SHOW_CHILD,
name: 'ATreeSelect',
props: initDefaultProps(TreeSelectProps(), {
prefixCls: 'ant-select',
transitionName: 'slide-up',
choiceTransitionName: 'zoom',
showSearch: false
}),
model: {
prop: 'value',
event: 'change'
},
inject: {
configProvider: { 'default': function _default() {
return {};
} }
},
created: function created() {
warning(this.multiple !== false || !this.treeCheckable, '`multiple` will alway be `true` when `treeCheckable` is true');
},
methods: {
focus: function focus() {
this.$refs.vcTreeSelect.focus();
},
blur: function blur() {
this.$refs.vcTreeSelect.blur();
},
renderSwitcherIcon: function renderSwitcherIcon(_ref) {
var isLeaf = _ref.isLeaf,
loading = _ref.loading;
var h = this.$createElement;
var prefixCls = this.$props.prefixCls;
if (loading) {
return h(Icon, {
attrs: { type: 'loading' },
'class': prefixCls + '-switcher-loading-icon' });
}
if (isLeaf) {
return null;
}
return h(Icon, {
attrs: { type: 'caret-down' },
'class': prefixCls + '-switcher-icon' });
},
onChange: function onChange() {
this.$emit.apply(this, ['change'].concat(Array.prototype.slice.call(arguments)));
},
updateTreeData: function updateTreeData() {
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
for (var i = 0, len = list.length; i < len; i++) {
var _list$i = list[i],
label = _list$i.label,
title = _list$i.title,
_list$i$scopedSlots = _list$i.scopedSlots,
scopedSlots = _list$i$scopedSlots === undefined ? {} : _list$i$scopedSlots,
children = _list$i.children;
var $scopedSlots = this.$scopedSlots;
var newLabel = typeof label === 'function' ? label(this.$createElement) : label;
var newTitle = typeof title === 'function' ? title(this.$createElement) : title;
if (!newLabel && scopedSlots.label && $scopedSlots[scopedSlots.label]) {
newLabel = $scopedSlots.label(list[i]);
}
if (!newTitle && scopedSlots.title && $scopedSlots[scopedSlots.title]) {
newTitle = $scopedSlots.title(list[i]);
}
var item = {
// label: newLabel,
title: newTitle || newLabel
};
this.updateTreeData(children || []);
_extends(list[i], item);
}
},
renderTreeSelect: function renderTreeSelect(locale) {
var _cls;
var h = this.$createElement;
var props = getOptionProps(this);
var prefixCls = props.prefixCls,
size = props.size,
notFoundContent = props.notFoundContent,
dropdownStyle = props.dropdownStyle,
dropdownClassName = props.dropdownClassName,
getPopupContainer = props.getPopupContainer,
restProps = _objectWithoutProperties(props, ['prefixCls', 'size', 'notFoundContent', 'dropdownStyle', 'dropdownClassName', 'getPopupContainer']);
var getContextPopupContainer = this.configProvider.getPopupContainer;
var rest = omit(restProps, ['inputIcon', 'removeIcon', 'clearIcon', 'switcherIcon', 'suffixIcon']);
var suffixIcon = getComponentFromProp(this, 'suffixIcon');
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
this.updateTreeData(props.treeData || []);
var cls = (_cls = {}, _defineProperty(_cls, prefixCls + '-lg', size === 'large'), _defineProperty(_cls, prefixCls + '-sm', size === 'small'), _cls);
var checkable = getComponentFromProp(this, 'treeCheckable');
if (checkable) {
checkable = h('span', { 'class': prefixCls + '-tree-checkbox-inner' });
}
var inputIcon = suffixIcon && (isValidElement(suffixIcon) ? cloneElement(suffixIcon) : suffixIcon) || h(Icon, {
attrs: { type: 'down' },
'class': prefixCls + '-arrow-icon' });
var removeIcon = h(Icon, {
attrs: { type: 'close' },
'class': prefixCls + '-remove-icon' });
var clearIcon = h(Icon, {
attrs: { type: 'close-circle', theme: 'filled' },
'class': prefixCls + '-clear-icon' });
var VcTreeSelectProps = {
props: _extends({
switcherIcon: this.renderSwitcherIcon,
inputIcon: inputIcon,
removeIcon: removeIcon,
clearIcon: clearIcon
}, rest, {
getPopupContainer: getPopupContainer || getContextPopupContainer,
dropdownClassName: classNames(dropdownClassName, prefixCls + '-tree-dropdown'),
prefixCls: prefixCls,
dropdownStyle: _extends({ maxHeight: '100vh', overflow: 'auto' }, dropdownStyle),
treeCheckable: checkable,
notFoundContent: notFoundContent || locale.notFoundContent,
__propsSymbol__: Symbol()
}),
'class': cls,
on: _extends({}, this.$listeners, { change: this.onChange }),
ref: 'vcTreeSelect',
scopedSlots: this.$scopedSlots
};
return h(
VcTreeSelect,
VcTreeSelectProps,
[filterEmpty(this.$slots['default'])]
);
}
},
render: function render() {
var h = arguments[0];
return h(LocaleReceiver, {
attrs: {
componentName: 'Select',
defaultLocale: {}
},
scopedSlots: { 'default': this.renderTreeSelect }
});
}
};
/* istanbul ignore next */
TreeSelect.install = function (Vue) {
Vue.component(TreeSelect.name, TreeSelect);
Vue.component(TreeSelect.TreeNode.name, TreeSelect.TreeNode);
};
export default TreeSelect;