element-plus
Version:
A Component Library for Vue 3
1 lines • 5.78 kB
Source Map (JSON)
{"version":3,"file":"autocomplete.mjs","sources":["../../../../../../packages/components/autocomplete/src/autocomplete.ts"],"sourcesContent":["import {\n NOOP,\n buildProps,\n definePropType,\n isNumber,\n isObject,\n isString,\n} from '@element-plus/utils'\nimport { useTooltipContentProps } from '@element-plus/components/tooltip'\nimport {\n CHANGE_EVENT,\n INPUT_EVENT,\n UPDATE_MODEL_EVENT,\n} from '@element-plus/constants'\nimport { inputProps } from '@element-plus/components/input'\n\nimport type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'\nimport type Autocomplete from './autocomplete.vue'\nimport type { Placement } from '@element-plus/components/popper'\nimport type { Awaitable } from '@element-plus/utils'\n\nexport type AutocompleteData = Record<string, any>[]\nexport type AutocompleteFetchSuggestionsCallback = (\n data: AutocompleteData\n) => void\nexport type AutocompleteFetchSuggestions =\n | ((\n queryString: string,\n cb: AutocompleteFetchSuggestionsCallback\n ) => Awaitable<AutocompleteData> | void)\n | AutocompleteData\n\nexport const autocompleteProps = buildProps({\n ...inputProps,\n /**\n * @description key name of the input suggestion object for display\n */\n valueKey: {\n type: String,\n default: 'value',\n },\n /**\n * @description binding value\n */\n modelValue: {\n type: [String, Number],\n default: '',\n },\n /**\n * @description debounce delay when typing, in milliseconds\n */\n debounce: {\n type: Number,\n default: 300,\n },\n /**\n * @description placement of the popup menu\n */\n placement: {\n type: definePropType<Placement>(String),\n values: [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n ],\n default: 'bottom-start',\n },\n /**\n * @description a method to fetch input suggestions. When suggestions are ready, invoke `callback(data:[])` to return them to Autocomplete\n */\n fetchSuggestions: {\n type: definePropType<AutocompleteFetchSuggestions>([Function, Array]),\n default: NOOP,\n },\n /**\n * @description custom class name for autocomplete's dropdown\n */\n popperClass: useTooltipContentProps.popperClass,\n /**\n * @description custom style for autocomplete's dropdown\n */\n popperStyle: useTooltipContentProps.popperStyle,\n /**\n * @description whether show suggestions when input focus\n */\n triggerOnFocus: {\n type: Boolean,\n default: true,\n },\n /**\n * @description whether to emit a `select` event on enter when there is no autocomplete match\n */\n selectWhenUnmatched: Boolean,\n /**\n * @description whether to hide the loading icon in remote search\n */\n hideLoading: Boolean,\n /**\n * @description whether select dropdown is teleported to the body\n */\n teleported: useTooltipContentProps.teleported,\n /**\n * @description which select dropdown appends to\n */\n appendTo: useTooltipContentProps.appendTo,\n /**\n * @description whether to highlight first item in remote search suggestions by default\n */\n highlightFirstItem: Boolean,\n /**\n * @description whether the width of the dropdown is the same as the input\n */\n fitInputWidth: Boolean,\n /**\n * @description whether keyboard navigation loops from end to start\n */\n loopNavigation: {\n type: Boolean,\n default: true,\n },\n} as const)\nexport type AutocompleteProps = ExtractPropTypes<typeof autocompleteProps>\nexport type AutocompletePropsPublic = ExtractPublicPropTypes<\n typeof autocompleteProps\n>\n\nexport const autocompleteEmits = {\n [UPDATE_MODEL_EVENT]: (value: string | number) =>\n isString(value) || isNumber(value),\n [INPUT_EVENT]: (value: string | number) => isString(value) || isNumber(value),\n [CHANGE_EVENT]: (value: string | number) =>\n isString(value) || isNumber(value),\n focus: (evt: FocusEvent) => evt instanceof FocusEvent,\n blur: (evt: FocusEvent) => evt instanceof FocusEvent,\n clear: () => true,\n select: (item: Record<string, any>) => isObject(item),\n}\nexport type AutocompleteEmits = typeof autocompleteEmits\n\nexport type AutocompleteInstance = InstanceType<typeof Autocomplete> & unknown\n"],"names":[],"mappings":";;;;;;;AAgCO,MAAM,oBAAoB,UAAW,CAAA;AAAA,EAC1C,GAAG,UAAA;AAAA,EAIH,QAAU,EAAA;AAAA,IACR,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA,OAAA;AAAA,GACX;AAAA,EAIA,UAAY,EAAA;AAAA,IACV,IAAA,EAAM,CAAC,MAAA,EAAQ,MAAM,CAAA;AAAA,IACrB,OAAS,EAAA,EAAA;AAAA,GACX;AAAA,EAIA,QAAU,E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