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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import _mergeJSXProps from 'babel-helper-vue-jsx-merge-props';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _extends from 'babel-runtime/helpers/extends';
import classNames from 'classnames';
import PropTypes from '../_util/vue-types';
import { isValidElement, initDefaultProps } from '../_util/props-util';
import BaseMixin from '../_util/BaseMixin';
import getTransitionProps from '../_util/getTransitionProps';
import Checkbox from '../checkbox';
import Search from './search';
import Item from './item';
import triggerEvent from '../_util/triggerEvent';
import addEventListener from '../_util/Dom/addEventListener';
function noop() {}
var TransferItem = {
key: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
disabled: PropTypes.bool
};
function isRenderResultPlainObject(result) {
return result && !isValidElement(result) && Object.prototype.toString.call(result) === '[object Object]';
}
export var TransferListProps = {
prefixCls: PropTypes.string,
titleText: PropTypes.string,
dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose),
filter: PropTypes.string,
filterOption: PropTypes.func,
checkedKeys: PropTypes.arrayOf(PropTypes.string),
handleFilter: PropTypes.func,
handleSelect: PropTypes.func,
handleSelectAll: PropTypes.func,
handleClear: PropTypes.func,
renderItem: PropTypes.func,
showSearch: PropTypes.bool,
searchPlaceholder: PropTypes.string,
notFoundContent: PropTypes.any,
itemUnit: PropTypes.string,
itemsUnit: PropTypes.string,
body: PropTypes.any,
footer: PropTypes.any,
lazy: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
disabled: PropTypes.bool
};
export default {
name: 'TransferList',
mixins: [BaseMixin],
props: initDefaultProps(TransferListProps, {
dataSource: [],
titleText: '',
showSearch: false,
renderItem: noop,
lazy: {}
}),
data: function data() {
this.timer = null;
this.triggerScrollTimer = null;
return {
mounted: false
};
},
mounted: function mounted() {
var _this = this;
this.timer = setTimeout(function () {
_this.setState({
mounted: true
});
}, 0);
this.$nextTick(function () {
if (_this.$refs.listContentWrapper) {
var listContentWrapperDom = _this.$refs.listContentWrapper.$el;
_this.scrollEvent = addEventListener(listContentWrapperDom, 'scroll', _this.handleScroll);
}
});
},
beforeDestroy: function beforeDestroy() {
clearTimeout(this.timer);
clearTimeout(this.triggerScrollTimer);
if (this.scrollEvent) {
this.scrollEvent.remove();
}
},
updated: function updated() {
var _this2 = this;
this.$nextTick(function () {
if (_this2.scrollEvent) {
_this2.scrollEvent.remove();
}
if (_this2.$refs.listContentWrapper) {
var listContentWrapperDom = _this2.$refs.listContentWrapper.$el;
_this2.scrollEvent = addEventListener(listContentWrapperDom, 'scroll', _this2.handleScroll);
}
});
},
methods: {
handleScroll: function handleScroll(e) {
this.$emit('scroll', e);
},
getCheckStatus: function getCheckStatus(filteredDataSource) {
var checkedKeys = this.$props.checkedKeys;
if (checkedKeys.length === 0) {
return 'none';
} else if (filteredDataSource.every(function (item) {
return checkedKeys.indexOf(item.key) >= 0;
})) {
return 'all';
}
return 'part';
},
_handleSelect: function _handleSelect(selectedItem) {
var checkedKeys = this.$props.checkedKeys;
var result = checkedKeys.some(function (key) {
return key === selectedItem.key;
});
this.handleSelect(selectedItem, !result);
},
_handleFilter: function _handleFilter(e) {
var _this3 = this;
this.handleFilter(e);
if (!e.target.value) {
return;
}
// Manually trigger scroll event for lazy search bug
// https://github.com/ant-design/ant-design/issues/5631
this.triggerScrollTimer = setTimeout(function () {
var transferNode = _this3.$el;
var listNode = transferNode.querySelectorAll('.ant-transfer-list-content')[0];
if (listNode) {
triggerEvent(listNode, 'scroll');
}
}, 0);
},
_handleClear: function _handleClear(e) {
this.handleClear(e);
},
matchFilter: function matchFilter(text, item) {
var _$props = this.$props,
filter = _$props.filter,
filterOption = _$props.filterOption;
if (filterOption) {
return filterOption(filter, item);
}
return text.indexOf(filter) >= 0;
},
renderItemHtml: function renderItemHtml(item) {
var _$props$renderItem = this.$props.renderItem,
renderItem = _$props$renderItem === undefined ? noop : _$props$renderItem;
var renderResult = renderItem(item);
var isRenderResultPlain = isRenderResultPlainObject(renderResult);
return {
renderedText: isRenderResultPlain ? renderResult.value : renderResult,
renderedEl: isRenderResultPlain ? renderResult.label : renderResult
};
},
filterNull: function filterNull(arr) {
return arr.filter(function (item) {
return item !== null;
});
}
},
render: function render() {
var _this4 = this;
var h = arguments[0];
var _$props2 = this.$props,
prefixCls = _$props2.prefixCls,
dataSource = _$props2.dataSource,
titleText = _$props2.titleText,
checkedKeys = _$props2.checkedKeys,
lazy = _$props2.lazy,
disabled = _$props2.disabled,
body = _$props2.body,
footer = _$props2.footer,
showSearch = _$props2.showSearch,
filter = _$props2.filter,
searchPlaceholder = _$props2.searchPlaceholder,
notFoundContent = _$props2.notFoundContent,
itemUnit = _$props2.itemUnit,
itemsUnit = _$props2.itemsUnit;
// Custom Layout
var footerDom = footer && footer(_extends({}, this.$props));
var bodyDom = body && body(_extends({}, this.$props));
var listCls = classNames(prefixCls, _defineProperty({}, prefixCls + '-with-footer', !!footerDom));
var filteredDataSource = [];
var totalDataSource = [];
var showItems = dataSource.map(function (item) {
var _renderItemHtml = _this4.renderItemHtml(item),
renderedText = _renderItemHtml.renderedText,
renderedEl = _renderItemHtml.renderedEl;
if (filter && filter.trim() && !_this4.matchFilter(renderedText, item)) {
return null;
}
// all show items
totalDataSource.push(item);
if (!item.disabled) {
// response to checkAll items
filteredDataSource.push(item);
}
var checked = checkedKeys.indexOf(item.key) >= 0;
return h(Item, {
attrs: {
disabled: disabled,
item: item,
lazy: lazy,
renderedText: renderedText,
renderedEl: renderedEl,
checked: checked,
prefixCls: prefixCls
},
key: item.key, on: {
'click': _this4._handleSelect
}
});
});
var unit = dataSource.length > 1 ? itemsUnit : itemUnit;
var search = showSearch ? h(
'div',
{ 'class': prefixCls + '-body-search-wrapper' },
[h(Search, {
attrs: {
prefixCls: prefixCls + '-search',
handleClear: this.handleClear,
placeholder: searchPlaceholder,
value: filter,
disabled: disabled
},
on: {
'change': this._handleFilter
}
})]
) : null;
var transitionName = this.mounted ? prefixCls + '-content-item-highlight' : '';
var transitionProps = getTransitionProps(transitionName, {
leave: noop
});
var searchNotFound = showItems.every(function (item) {
return item === null;
}) && h(
'div',
{ 'class': prefixCls + '-body-not-found' },
[notFoundContent]
);
var listBody = bodyDom || h(
'div',
{
'class': classNames(showSearch ? prefixCls + '-body ' + prefixCls + '-body-with-search' : prefixCls + '-body')
},
[search, h(
'transition-group',
_mergeJSXProps([transitionProps, {
attrs: {
tag: 'ul'
},
'class': prefixCls + '-content',
ref: 'listContentWrapper'
}]),
[showItems]
), searchNotFound]
);
var listFooter = footerDom ? h(
'div',
{ 'class': prefixCls + '-footer' },
[footerDom]
) : null;
var checkStatus = this.getCheckStatus(filteredDataSource);
var checkedAll = checkStatus === 'all';
var checkAllCheckbox = h(Checkbox, {
ref: 'checkbox',
attrs: { disabled: disabled,
checked: checkedAll,
indeterminate: checkStatus === 'part'
},
on: {
'change': function change() {
_this4.handleSelectAll(filteredDataSource, checkedAll);
}
}
});
return h(
'div',
{ 'class': listCls },
[h(
'div',
{ 'class': prefixCls + '-header' },
[checkAllCheckbox, h(
'span',
{ 'class': prefixCls + '-header-selected' },
[h('span', [(checkedKeys.length > 0 ? checkedKeys.length + '/' : '') + totalDataSource.length, ' ', unit]), h(
'span',
{ 'class': prefixCls + '-header-title' },
[titleText]
)]
)]
), listBody, listFooter]
);
}
};