You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
20 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, inject, ref, computed, watch, unref, createVNode, mergeProps, toRaw } from 'vue';\nimport { get } from 'lodash-unified';\nimport GroupItem from './group-item.mjs';\nimport OptionItem from './option-item.mjs';\nimport { useProps } from './useProps.mjs';\nimport { selectV2InjectionKey } from './token.mjs';\nimport FixedSizeList from '../../virtual-list/src/components/fixed-size-list.mjs';\nimport DynamicSizeList from '../../virtual-list/src/components/dynamic-size-list.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { isUndefined } from '../../../utils/types.mjs';\nimport { EVENT_CODE } from '../../../constants/aria.mjs';\nimport { isObject } from '@vue/shared';\nconst props = {\n loading: Boolean,\n data: {\n type: Array,\n required: true\n },\n hoveringIndex: Number,\n width: Number\n};\nvar ElSelectMenu = defineComponent({\n name: \"ElSelectDropdown\",\n props,\n setup(props2, {\n slots,\n expose\n }) {\n const select = inject(selectV2InjectionKey);\n const ns = useNamespace(\"select\");\n const {\n getLabel,\n getValue,\n getDisabled\n } = useProps(select.props);\n const cachedHeights = ref([]);\n const listRef = ref();\n const size = computed(() => props2.data.length);\n watch(() => size.value, () => {\n var _a, _b;\n (_b = (_a = select.tooltipRef.value).updatePopper) == null ? void 0 : _b.call(_a);\n });\n const isSized = computed(() => isUndefined(select.props.estimatedOptionHeight));\n const listProps = computed(() => {\n if (isSized.value) {\n return {\n itemSize: select.props.itemHeight\n };\n }\n return {\n estimatedSize: select.props.estimatedOptionHeight,\n itemSize: idx => cachedHeights.value[idx]\n };\n });\n const contains = (arr = [], target) => {\n const {\n props: {\n valueKey\n }\n } = select;\n if (!isObject(target)) {\n return arr.includes(target);\n }\n return arr && arr.some(item => {\n return toRaw(get(item, valueKey)) === get(target, valueKey);\n });\n };\n const isEqual = (selected, target) => {\n if (!isObject(target)) {\n return selected === target;\n } else {\n const {\n valueKey\n } = select.props;\n return get(selected, valueKey) === get(target, valueKey);\n }\n };\n const isItemSelected = (modelValue, target) => {\n if (select.props.multiple) {\n return contains(modelValue, getValue(target));\n }\n return isEqual(modelValue, getValue(target));\n };\n const isItemDisabled = (modelValue, selected) => {\n const {\n disabled,\n multiple,\n multipleLimit\n } = select.props;\n return disabled || !selected && (multiple ? multipleLimit > 0 && modelValue.length >= multipleLimit : false);\n };\n const isItemHovering = target => props2.hoveringIndex === target;\n const scrollToItem = index => {\n const list = listRef.value;\n if (list) {\n list.scrollToItem(index);\n }\n };\n const resetScrollTop = () => {\n const list = listRef.value;\n if (list) {\n list.resetScrollTop();\n }\n };\n const exposed = {\n listRef,\n isSized,\n isItemDisabled,\n isItemHovering,\n isItemSelected,\n scrollToItem,\n resetScrollTop\n };\n expose(exposed);\n const Item = itemProps => {\n const {\n index,\n data,\n style\n } = itemProps;\n const sized = unref(isSized);\n const {\n itemSize,\n estimatedSize\n } = unref(listProps);\n const {\n modelValue\n } = select.props;\n const {\n onSelect,\n onHover\n } = select;\n const item = data[index];\n if (item.type === \"Group\") {\n return createVNode(GroupItem, {\n \"item\": item,\n \"style\": style,\n \"height\": s