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
33 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, useAttrs as useAttrs$1, ref, computed, onBeforeUnmount, onMounted, openBlock, createBlock, unref, withCtx, createElementVNode, normalizeClass, normalizeStyle, createVNode, createElementBlock, renderSlot, Fragment, renderList, createTextVNode, toDisplayString, mergeProps, withKeys, withModifiers, createSlots } from 'vue';\nimport { debounce } from 'lodash-unified';\nimport { onClickOutside } from '@vueuse/core';\nimport { Loading } from '@element-plus/icons-vue';\nimport { ElInput } from '../../input/index.mjs';\nimport { ElScrollbar } from '../../scrollbar/index.mjs';\nimport { ElTooltip } from '../../tooltip/index.mjs';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { autocompleteProps, autocompleteEmits } from './autocomplete.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useAttrs } from '../../../hooks/use-attrs/index.mjs';\nimport { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useId } from '../../../hooks/use-id/index.mjs';\nimport { isArray } from '@vue/shared';\nimport { INPUT_EVENT, UPDATE_MODEL_EVENT, CHANGE_EVENT } from '../../../constants/event.mjs';\nimport { throwError } from '../../../utils/error.mjs';\nconst COMPONENT_NAME = \"ElAutocomplete\";\nconst __default__ = defineComponent({\n name: COMPONENT_NAME,\n inheritAttrs: false\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: autocompleteProps,\n emits: autocompleteEmits,\n setup(__props, {\n expose,\n emit\n }) {\n const props = __props;\n const attrs = useAttrs();\n const rawAttrs = useAttrs$1();\n const disabled = useFormDisabled();\n const ns = useNamespace(\"autocomplete\");\n const inputRef = ref();\n const regionRef = ref();\n const popperRef = ref();\n const listboxRef = ref();\n let readonly = false;\n let ignoreFocusEvent = false;\n const suggestions = ref([]);\n const highlightedIndex = ref(-1);\n const dropdownWidth = ref(\"\");\n const activated = ref(false);\n const suggestionDisabled = ref(false);\n const loading = ref(false);\n const listboxId = useId();\n const styles = computed(() => rawAttrs.style);\n const suggestionVisible = computed(() => {\n const isValidData = suggestions.value.length > 0;\n return (isValidData || loading.value) && activated.value;\n });\n const suggestionLoading = computed(() => !props.hideLoading && loading.value);\n const refInput = computed(() => {\n if (inputRef.value) {\n return Array.from(inputRef.value.$el.querySelectorAll(\"input\"));\n }\n return [];\n });\n const onSuggestionShow = () => {\n if (suggestionVisible.value) {\n dropdownWidth.value = `${inputRef.value.$el.offsetWidth}px`;\n }\n };\n const onHide = () => {\n highlightedIndex.value = -1;\n };\n const getData = async queryString => {\n if (suggestionDisabled.value) return;\n const cb = suggestionList => {\n loading.value = false;\n if (suggestionDisabled.value) return;\n if (isArray(suggestionList)) {\n suggestions.value = suggestionList;\n highlightedIndex.value = props.highlightFirstItem ? 0 : -1;\n } else {\n throwError(COMPONENT_NAME, \"autocomplete suggestions must be an array\");\n }\n };\n loading.value = true;\n if (isArray(props.fetchSuggestions)) {\n cb(props.fetchSuggestions);\n } else {\n const result = await props.fetchSuggestions(queryString, cb);\n if (isArray(result)) cb(result);\n }\n };\n const debouncedGetData = debounce(getData, props.debounce);\n const handleInput = value => {\n const valuePresented = !!value;\n emit(INPUT_EVENT, value);\n emit(UPDATE_MODEL_EVENT, value);\n suggestionDisabled.value = false;\n activated.value || (activated.value = valuePresented);\n if (!props.trigg