tdesign-vue-next
Version:
TDesign Component for vue-next
193 lines (189 loc) • 7.95 kB
JavaScript
/**
* tdesign v1.15.2
* (c) 2025 tdesign
* @license MIT
*/
import { defineComponent, inject, ref, computed, createVNode, Fragment, mergeProps, isVNode } from 'vue';
import { omit } from 'lodash-es';
import _Option from '../option.js';
import _OptionGroup from '../option-group.js';
import props from '../props.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-e604a5ce.js';
import { u as useTNodeJSX, b as useTNodeDefault } from '../../_chunks/dep-1d44782f.js';
import { u as usePrefixClass } from '../../_chunks/dep-79c44a11.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../_chunks/dep-7324137b.js';
import '@babel/runtime/helpers/defineProperty';
import { usePanelVirtualScroll } from '../hooks/usePanelVirtualScroll.js';
import { selectInjectKey } from '../consts/index.js';
import { useConfig } from '../../config-provider/hooks/useConfig.js';
import '../option-props.js';
import '../../checkbox/index.js';
import '../../checkbox/checkbox.js';
import '../../checkbox/props.js';
import '../../_chunks/dep-b9ab7399.js';
import '../../_chunks/dep-5360ac56.js';
import '../../_chunks/dep-41ae8479.js';
import '../../_chunks/dep-7b209207.js';
import '../../_chunks/dep-3ba91e12.js';
import '../../_chunks/dep-34e44a4e.js';
import '../../checkbox/consts/index.js';
import '../../checkbox/hooks/useCheckboxLazyLoad.js';
import '../../_chunks/dep-6f34ddfa.js';
import '../../checkbox/hooks/useKeyboardEvent.js';
import '../../_chunks/dep-01e48141.js';
import '../../_chunks/dep-7fac49fa.js';
import '../../_chunks/dep-1f7ad104.js';
import '../../_chunks/dep-6c13cc0e.js';
import '../../config-provider/utils/context.js';
import '../../_chunks/dep-3b49fbbe.js';
import 'dayjs';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/classCallCheck';
import '../../checkbox/group.js';
import '../../checkbox/checkbox-group-props.js';
import '../../_chunks/dep-0f8c45fe.js';
import '../../_chunks/dep-37a2e7c8.js';
import '../utils/index.js';
import '../option-group-props.js';
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var SelectPanel = defineComponent({
name: "TSelectPanel",
props: {
inputValue: props.inputValue,
panelTopContent: props.panelTopContent,
panelBottomContent: props.panelBottomContent,
empty: props.empty,
creatable: props.creatable,
loading: props.loading,
loadingText: props.loadingText,
multiple: props.multiple,
filterable: props.filterable,
filter: props.filter,
scroll: props.scroll,
keys: props.keys
},
setup: function setup(props, _ref) {
var expose = _ref.expose;
var COMPONENT_NAME = usePrefixClass("select");
var renderTNodeJSX = useTNodeJSX();
var renderDefaultTNode = useTNodeDefault();
var _useConfig = useConfig("select"),
t = _useConfig.t,
globalConfig = _useConfig.globalConfig;
var tSelect = inject(selectInjectKey);
var innerRef = ref(null);
var keys = computed(function () {
return props.keys;
});
var popupContentRef = computed(function () {
return tSelect.value.popupContentRef.value;
});
var showCreateOption = computed(function () {
return props.creatable && props.filterable && props.inputValue;
});
var displayOptions = computed(function () {
return tSelect.value.displayOptions;
});
var _usePanelVirtualScrol = usePanelVirtualScroll({
scroll: props.scroll,
popupContentRef: popupContentRef,
options: displayOptions
}),
trs = _usePanelVirtualScrol.trs,
visibleData = _usePanelVirtualScrol.visibleData,
handleRowMounted = _usePanelVirtualScrol.handleRowMounted,
isVirtual = _usePanelVirtualScrol.isVirtual,
panelStyle = _usePanelVirtualScrol.panelStyle,
cursorStyle = _usePanelVirtualScrol.cursorStyle;
var isEmpty = computed(function () {
return !displayOptions.value.length;
});
var renderCreateOption = function renderCreateOption() {
return createVNode("ul", {
"class": ["".concat(COMPONENT_NAME.value, "__create-option"), "".concat(COMPONENT_NAME.value, "__list")]
}, [createVNode(_Option, {
"value": props.inputValue,
"label": "".concat(props.inputValue),
"createAble": true,
"class": "".concat(COMPONENT_NAME.value, "__create-option--special")
}, null)]);
};
var _renderOptionsContent = function renderOptionsContent(options) {
return createVNode("ul", {
"class": "".concat(COMPONENT_NAME.value, "__list")
}, [options.map(function (item, index) {
var _props$scroll, _props$scroll2;
if (item.children) {
var _slot;
return createVNode(_OptionGroup, {
"label": item.group,
"divider": item.divider
}, _isSlot(_slot = _renderOptionsContent(item.children)) ? _slot : {
"default": function _default() {
return [_slot];
}
});
}
var defaultOmit = ["index", "$index", "className", "tagName"];
var _ref2 = keys.value || {},
value = _ref2.value,
label = _ref2.label,
disabled = _ref2.disabled;
var shouldOmitContent = [value, label, disabled].includes("content");
var option = omit(item, defaultOmit.concat(shouldOmitContent ? "content" : []));
return createVNode(_Option, mergeProps(option, isVirtual.value ? {
rowIndex: item.$index,
trs: trs,
scrollType: (_props$scroll = props.scroll) === null || _props$scroll === void 0 ? void 0 : _props$scroll.type,
isVirtual: isVirtual.value,
bufferSize: (_props$scroll2 = props.scroll) === null || _props$scroll2 === void 0 ? void 0 : _props$scroll2.bufferSize,
key: "".concat(item.$index || "", "_").concat(index, "_").concat(item.value)
} : {
key: "".concat(index, "_").concat(item.value)
}, {
"index": index,
"multiple": props.multiple,
"onRowMounted": handleRowMounted
}), item.slots);
})]);
};
var dropdownInnerSize = computed(function () {
return {
small: "s",
medium: "m",
large: "l"
}[tSelect.value.size];
});
expose({
innerRef: innerRef,
visibleData: visibleData,
isVirtual: isVirtual,
displayOptions: displayOptions
});
var renderPanel = function renderPanel(options, extraStyle) {
return createVNode("div", {
"ref": innerRef,
"class": ["".concat(COMPONENT_NAME.value, "__dropdown-inner"), "".concat(COMPONENT_NAME.value, "__dropdown-inner--size-").concat(dropdownInnerSize.value)],
"style": extraStyle
}, [showCreateOption.value && renderCreateOption(), props.loading && renderDefaultTNode("loadingText", {
defaultNode: createVNode("div", {
"class": "".concat(COMPONENT_NAME.value, "__loading-tips")
}, [t(globalConfig.value.loadingText)])
}), !props.loading && isEmpty.value && !showCreateOption.value && createVNode("div", {
"class": "".concat(COMPONENT_NAME.value, "__empty")
}, [renderTNodeJSX("empty") || t(globalConfig.value.empty)]), !isEmpty.value && _renderOptionsContent(options)]);
};
return function () {
return isVirtual.value ? createVNode(Fragment, null, [renderTNodeJSX("panelTopContent"), createVNode("div", null, [createVNode("div", {
"style": cursorStyle.value
}, null), renderPanel(visibleData.value, panelStyle.value)]), renderTNodeJSX("panelBottomContent")]) : createVNode(Fragment, null, [renderTNodeJSX("panelTopContent"), renderPanel(displayOptions.value), renderTNodeJSX("panelBottomContent")]);
};
}
});
export { SelectPanel as default };
//# sourceMappingURL=select-panel.js.map