{"version":3,"file":"select-dropdown.mjs","sources":["../../../../../../packages/components/select-v2/src/select-dropdown.tsx"],"sourcesContent":["import {\n computed,\n defineComponent,\n inject,\n ref,\n toRaw,\n unref,\n watch,\n} from 'vue'\nimport { get } from 'lodash-unified'\nimport { isObject, isUndefined } from '@element-plus/utils'\nimport {\n DynamicSizeList,\n FixedSizeList,\n} from '@element-plus/components/virtual-list'\nimport { useNamespace } from '@element-plus/hooks'\nimport { EVENT_CODE } from '@element-plus/constants'\nimport GroupItem from './group-item.vue'\nimport OptionItem from './option-item.vue'\nimport { useProps } from './useProps'\n\nimport { selectV2InjectionKey } from './token'\n\nimport type {\n DynamicSizeListInstance,\n FixedSizeListInstance,\n ItemProps,\n} from '@element-plus/components/virtual-list'\nimport type { Option, OptionItemProps } from './select.types'\nimport type {\n ComponentPublicInstance,\n ComputedRef,\n ExtractPropTypes,\n Ref,\n} from 'vue'\n\nconst props = {\n loading: Boolean,\n data: {\n type: Array,\n required: true as const,\n },\n hoveringIndex: Number,\n width: Number,\n}\ninterface SelectDropdownExposed {\n listRef: Ref\n isSized: ComputedRef\n isItemDisabled: (modelValue: any[] | any, selected: boolean) => boolean\n isItemHovering: (target: number) => boolean\n isItemSelected: (modelValue: any[] | any, target: Option) => boolean\n scrollToItem: (index: number) => void\n resetScrollTop: () => void\n}\nexport type SelectDropdownInstance = ComponentPublicInstance<\n ExtractPropTypes,\n SelectDropdownExposed\n>\nexport default defineComponent({\n name: 'ElSelectDropdown',\n props,\n setup(props, { slots, expose }) {\n const select = inject(selectV2InjectionKey)!\n const ns = useNamespace('select')\n const { getLabel, getValue, getDisabled } = useProps(select.props)\n\n const cachedHeights = ref>([])\n\n const listRef = ref()\n\n const size = computed(() => props.data.length)\n watch(\n () => size.value,\n () => {\n select.tooltipRef.value!.updatePopper?.()\n }\n )\n\n const isSized = computed(() =>\n isUndefined(select.props.estimatedOptionHeight)\n )\n const listProps = computed(() => {\n if (isSized.value) {\n return {\n itemSize: select.props.itemHeight,\n }\n }\n\n return {\n estimatedSize: select.props.estimatedOptionHeight,\n itemSize: (idx: number) => cachedHeights.value[idx],\n }\n })\n\n const contains = (arr: Array = [], target: any) => {\n const {\n props: { valueKey },\n } = select\n\n if (!isObject(target)) {\n return arr.includes(target)\n }\n\n return (\n arr &&\n arr.some((item) => {\n return toRaw(get(item, valueKey)) === get(target, valueKey)\n })\n )\n }\n const isEqual = (selected: unknown, target: unknown) => {\n if (!isObject(target)) {\n return selected === target\n } else {\n const { valueKey } = select.props\n return get(selected, valueKey) === get(target, valueKey)\n }\n }\n\n const isItemSelected: SelectDropdownExposed['isItemSelected'] = (\n modelValue,\n target\n ) => {\n if (select.props.multiple) {\n return contains(modelValue, getValue(target))\n }\n return isEqual(modelValue, getValue(target))\n }\n\n const isItemDisabled: SelectDropdownExposed['isItemDisabled'] = (\n modelValue,\n selected\n ) => {\n const { disabled, multiple, multipleLimit } = select.props\n return (\n disabled ||\n (!selected &&\n (multiple\n ? multipleLimit > 0 && modelValue.length >= multipleLimit\n : false))\n )\n }\n\n const isItemHovering: SelectDropdownExposed['isItemHovering'] = (target) =>\n props.hoveringIndex === target\n\n const scrollToItem: SelectDropdownExposed['scrollToItem'] = (index) => {\n const list = listRef.value\n if (list) {\n list.scrollToItem(index)\n }\n }\n\n const resetScrollTop: SelectDropdownExposed['resetScrollTop'] = () => {\n const list = listRef.value\n if (list) {\n list.resetScrollTop()\n }\n }\n const exposed: SelectDropdownExposed = {\n listRef,\n isSized,\n\n isItemDisabled,\n isItemHovering,\n isItemSelected,\n scrollToItem,\n resetScrollTop,\n }\n expose(exposed)\n\n const Item = (itemProps: ItemProps) => {\n const { index, data, style } = itemProps\n const sized = unref(isSized)\n const { itemSize, estimatedSize } = unref(listProps)\n const { modelValue } = select.props\n const { onSelect, onHover } = select\n const item = data[index]\n if (item.type === 'Group') {\n return (\n \n )\n }\n\n const isSelected = isItemSelected(modelValue, item)\n const isDisabled = isItemDisabled(modelValue, isSelected)\n const isHovering = isItemHovering(index)\n return (\n \n {{\n default: (props: OptionItemProps) =>\n slots.default?.(props) || {getLabel(item)},\n }}\n \n )\n }\n\n // computed\n const { onKeyboardNavigate, onKeyboardSelect } = select\n\n const onForward = () => {\n onKeyboardNavigate('forward')\n }\n\n const onBackward = () => {\n onKeyboardNavigate('backward')\n }\n\n const onEscOrTab = () => {\n // The following line actually doesn't work. Fixing it may introduce a small breaking change for some users, so just comment it out for now.\n // select.expanded = false\n }\n\n const onKeydown = (e: KeyboardEvent) => {\n const { code } = e\n const { tab, esc, down, up, enter } = EVENT_CODE\n if (code !== tab) {\n e.preventDefault()\n e.stopPropagation()\n }\n\n switch (code) {\n case tab:\n case esc: {\n onEscOrTab()\n break\n }\n case down: {\n onForward()\n break\n }\n case up: {\n onBackward()\n break\n }\n case enter: {\n onKeyboardSelect()\n break\n }\n }\n }\n\n return () => {\n const { data, width } = props\n const { height, multiple, scrollbarAlwaysOn } = select.props\n\n const List = unref(isSized) ? FixedSizeList : DynamicSizeList\n\n return (\n \n {slots.header?.()}\n {slots.loading?.() || slots.empty?.() || (\n \n {{\n default: (props: ItemProps) => ,\n }}\n \n )}\n {slots.footer?.()}\n \n )\n }\n },\n})\n"],"names":["props","loading","Boolean","data","type","Array","required","hoveringIndex","Number","width","defineComponent","name","slots","expose","select","ns","getLabel","getValue","getDisabled","cachedHeights","ref","listRef","size","computed","watch","tooltipRef","value","isSized","isUndefined","estimatedOptionHeight","listProps","itemSize","itemHeight","estimatedSize","contains","valueKey","isObject","target","arr","item","isEqual","selected","get","isItemSelected","modelValue","isItemDisabled","multipleLimit","isItemHovering","scrollToItem","resetScrollTop","list","Item","itemProps","style","_createVNode","unref","_mergeProps","onSelect","onHover","sized","default","onKeyboardSelect","onForward","onBackward","onEscOrTab","onKeydown","code","up","enter","EVENT_CODE","e","tab"],"mappings":";;;;;;;;;;;;;;;;;AAoCA,MAAMA,KAAK,GAAG;AACZC,EAAAA,OAAO,EAAEC,OADG;AAEZC,EAAAA,IAAI,EAAE;AACJC,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