ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
176 lines (155 loc) • 7.4 kB
JavaScript
import { createVNode as _createVNode, isVNode as _isVNode } from "vue";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { inject } from 'vue';
import PropTypes from '../../../../_util/vue-types';
import { createRef } from '../../util';
import generateSelector, { selectorPropTypes } from '../../Base/BaseSelector';
import SearchInput from '../../SearchInput';
import Selection from './Selection';
import { getComponent, getSlot } from '../../../../_util/props-util';
import BaseMixin from '../../../../_util/BaseMixin';
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !_isVNode(s);
}
var TREE_SELECT_EMPTY_VALUE_KEY = 'RC_TREE_SELECT_EMPTY_VALUE_KEY';
var Selector = generateSelector('multiple'); // export const multipleSelectorContextTypes = {
// onMultipleSelectorRemove: PropTypes.func.isRequired,
// }
var MultipleSelector = {
name: 'MultipleSelector',
mixins: [BaseMixin],
inheritAttrs: false,
props: _extends(_extends(_extends({}, selectorPropTypes()), SearchInput.props), {
selectorValueList: PropTypes.array,
disabled: PropTypes.looseBool,
labelInValue: PropTypes.looseBool,
maxTagCount: PropTypes.number,
maxTagPlaceholder: PropTypes.any
}),
setup: function setup() {
return {
vcTreeSelect: inject('vcTreeSelect', {})
};
},
created: function created() {
this.inputRef = createRef();
},
methods: {
onPlaceholderClick: function onPlaceholderClick() {
this.inputRef.current.focus();
},
focus: function focus() {
this.inputRef.current.focus();
},
blur: function blur() {
this.inputRef.current.blur();
},
_renderPlaceholder: function _renderPlaceholder() {
var _this$$props = this.$props,
prefixCls = _this$$props.prefixCls,
placeholder = _this$$props.placeholder,
searchPlaceholder = _this$$props.searchPlaceholder,
searchValue = _this$$props.searchValue,
selectorValueList = _this$$props.selectorValueList;
var currentPlaceholder = placeholder || searchPlaceholder;
if (!currentPlaceholder) return null;
var hidden = searchValue || selectorValueList.length; // [Legacy] Not remove the placeholder
return _createVNode("span", {
"style": {
display: hidden ? 'none' : 'block'
},
"onClick": this.onPlaceholderClick,
"class": "".concat(prefixCls, "-selection-placeholder")
}, _isSlot(currentPlaceholder) ? currentPlaceholder : {
default: function _default() {
return [currentPlaceholder];
}
});
},
onChoiceAnimationLeave: function onChoiceAnimationLeave() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
this.__emit.apply(this, ['choiceAnimationLeave'].concat(args));
},
renderSelection: function renderSelection() {
var _this = this;
var _this$$props2 = this.$props,
selectorValueList = _this$$props2.selectorValueList,
labelInValue = _this$$props2.labelInValue,
maxTagCount = _this$$props2.maxTagCount;
var children = getSlot(this);
var onMultipleSelectorRemove = this.vcTreeSelect.onMultipleSelectorRemove; // Check if `maxTagCount` is set
var myValueList = selectorValueList;
if (maxTagCount >= 0) {
myValueList = selectorValueList.slice(0, maxTagCount);
} // Selector node list
var selectedValueNodes = myValueList.map(function (_ref) {
var label = _ref.label,
value = _ref.value;
return _createVNode(Selection, _objectSpread(_objectSpread({}, _extends(_extends({}, _this.$props), {
label: label,
value: value,
onRemove: onMultipleSelectorRemove
})), {}, {
"key": value || TREE_SELECT_EMPTY_VALUE_KEY
}), _isSlot(children) ? children : {
default: function _default() {
return [children];
}
});
}); // Rest node count
if (maxTagCount >= 0 && maxTagCount < selectorValueList.length) {
var content = "+ ".concat(selectorValueList.length - maxTagCount, " ...");
var maxTagPlaceholder = getComponent(this, 'maxTagPlaceholder', {}, false);
if (typeof maxTagPlaceholder === 'string') {
content = maxTagPlaceholder;
} else if (typeof maxTagPlaceholder === 'function') {
var restValueList = selectorValueList.slice(maxTagCount);
content = maxTagPlaceholder(labelInValue ? restValueList : restValueList.map(function (_ref2) {
var value = _ref2.value;
return value;
}));
}
var restNodeSelect = _createVNode(Selection, _objectSpread(_objectSpread({}, _extends(_extends({}, this.$props), {
label: content,
value: null
})), {}, {
"key": "rc-tree-select-internal-max-tag-counter"
}), _isSlot(children) ? children : {
default: function _default() {
return [children];
}
});
selectedValueNodes.push(restNodeSelect);
}
selectedValueNodes.push(_createVNode(SearchInput, _objectSpread(_objectSpread(_objectSpread({
"key": "SearchInput"
}, this.$props), this.$attrs), {}, {
"ref": this.inputRef
}), _isSlot(children) ? children : {
default: function _default() {
return [children];
}
}));
return selectedValueNodes;
}
},
render: function render() {
var _slot;
return _createVNode(Selector, _extends(_extends(_extends({}, this.$props), this.$attrs), {
tabindex: -1,
showArrow: false,
renderSelection: this.renderSelection,
renderPlaceholder: this._renderPlaceholder
}), _isSlot(_slot = getSlot(this)) ? _slot : {
default: function _default() {
return [_slot];
}
});
}
};
export default MultipleSelector;