UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

206 lines (202 loc) 7.9 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { defineComponent, inject, ref, computed, createVNode, Fragment, mergeProps, isVNode } from 'vue'; import omit from 'lodash/omit'; import _Option from './option.js'; import _OptionGroup from './optionGroup.js'; import props from './props.js'; import { useTNodeJSX, useTNodeDefault } from '../hooks/tnode.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { usePanelVirtualScroll } from './hooks/usePanelVirtualScroll.js'; import { selectInjectKey } from './helper.js'; import { useConfig } from '../config-provider/useConfig.js'; import '@babel/runtime/helpers/defineProperty'; import './option-props.js'; import '../checkbox/index.js'; import '../checkbox/checkbox.js'; import '@babel/runtime/helpers/slicedToArray'; import '../checkbox/props.js'; import '../hooks/useVModel.js'; import 'lodash/kebabCase'; import '../hooks/useRipple.js'; import '../hooks/useKeepAnimation.js'; import '../config-provider/context.js'; import 'lodash/mergeWith'; import 'lodash/merge'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/en_US.js'; import '../_chunks/dep-3a1cce9f.js'; import 'lodash/isArray'; import '../utils/set-style.js'; import 'lodash/isFunction'; import 'lodash/cloneDeep'; import 'lodash/isString'; import '../checkbox/constants.js'; import '../checkbox/hooks/useCheckboxLazyLoad.js'; import '../_common/js/utils/observe.js'; import '../checkbox/hooks/useKeyboard.js'; import '../hooks/useDisabled.js'; import 'lodash/isBoolean'; import 'lodash/camelCase'; import '../utils/render-tnode.js'; import 'lodash/isEmpty'; import 'lodash/isObject'; import '../checkbox/group.js'; import '@babel/runtime/helpers/typeof'; import '@babel/runtime/helpers/toConsumableArray'; import 'lodash/intersection'; import 'lodash/isUndefined'; import '../checkbox/checkbox-group-props.js'; import '../hooks/slot.js'; import '../utils/withInstall.js'; import '../form/hooks.js'; import './option-group-props.js'; import '../hooks/useVirtualScroll.js'; function _isSlot(s) { return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s); } var SelectPanel = defineComponent({ name: "XSelectPanel", 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, options: { type: Array, "default": function _default() { return []; } }, scroll: props.scroll, size: props.size }, 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 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.group) { var _slot; return createVNode(_OptionGroup, { "label": item.group, "divider": item.divider }, _isSlot(_slot = renderOptionsContent(item.children)) ? _slot : { "default": function _default() { return [_slot]; } }); } return createVNode(_Option, mergeProps(omit(item, "$index", "className", "tagName"), 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) } : { key: "".concat(index, "_").concat(item.value) }, { "multiple": props.multiple, "onRowMounted": handleRowMounted }), item.slots); })]); }; var dropdownInnerSize = computed(function () { return { small: "s", medium: "m", large: "l" }[tSelect.value.size]; }); expose({ innerRef: innerRef }); 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)], "onClick": function onClick(e) { return e.stopPropagation(); }, "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 && renderDefaultTNode("empty", { defaultNode: createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__empty") }, [t(globalConfig.value.empty)]) }), !isEmpty.value && !props.loading && renderOptionsContent(options)]); }; return { renderPanel: renderPanel, panelStyle: panelStyle, cursorStyle: cursorStyle, isVirtual: isVirtual, displayOptions: displayOptions, visibleData: visibleData, renderTNodeJSX: renderTNodeJSX }; }, render: function render() { return this.isVirtual ? createVNode(Fragment, null, [this.renderTNodeJSX("panelTopContent"), createVNode("div", null, [createVNode("div", { "style": this.cursorStyle }, null), this.renderPanel(this.visibleData, this.panelStyle)]), this.renderTNodeJSX("panelBottomContent")]) : createVNode(Fragment, null, [this.renderTNodeJSX("panelTopContent"), this.renderPanel(this.displayOptions), this.renderTNodeJSX("panelBottomContent")]); } }); export { SelectPanel as default }; //# sourceMappingURL=select-panel.js.map