UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 8.21 kB
{"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 { ExtractPublicPropTypes } from 'vue'\nimport type Autocomplete from './autocomplete.vue'\nimport type { Placement } from '@element-plus/components/popper'\nimport type { Awaitable } from '@element-plus/utils'\nimport type { InputProps } from '@element-plus/components/input'\nimport type { ElTooltipContentProps } from '@element-plus/components/tooltip'\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 type AutocompletePlacement =\n | 'top'\n | 'top-start'\n | 'top-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n\nexport interface AutocompleteProps extends InputProps {\n /**\n * @description key name of the input suggestion object for display\n */\n valueKey?: string\n /**\n * @description binding value\n */\n modelValue?: string | number\n /**\n * @description debounce delay when typing, in milliseconds\n */\n debounce?: number\n /**\n * @description placement of the popup menu\n */\n placement?: AutocompletePlacement\n /**\n * @description a method to fetch input suggestions. When suggestions are ready, invoke `callback(data:[])` to return them to Autocomplete\n */\n fetchSuggestions?: AutocompleteFetchSuggestions\n /**\n * @description custom class name for autocomplete's dropdown\n */\n popperClass?: ElTooltipContentProps['popperClass']\n /**\n * @description custom style for autocomplete's dropdown\n */\n popperStyle?: ElTooltipContentProps['popperStyle']\n /**\n * @description whether show suggestions when input focus\n */\n triggerOnFocus?: boolean\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?: ElTooltipContentProps['teleported']\n /**\n * @description which select dropdown appends to\n */\n appendTo?: ElTooltipContentProps['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?: boolean\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `AutocompleteProps` instead.\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)\n\n/**\n * @deprecated Removed after 3.0.0, Use `AutocompleteProps` instead.\n */\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":";;;;;;;AA4GO,MAAM,oBAAoB,UAAA,CAAW;AAAA,EAC1C,GAAG,UAAA;AAAA;AAAA;AAAA;AAAA,EAIH,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,UAAA,EAAY;AAAA,IACV,IAAA,EAAM,CAAC,MAAA,EAAQ,MAAM,CAAA;AAAA,IACrB,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,MAAA;AAAA,IACN,OAAA,EAAS;AAAA,GACX;AAAA;AAAA;AAAA;AAAA,EAIA,SAAA,EAAW;AAAA,IACT,IAAA,EAAM,eAA0B,MAAM,CAAA;AAAA,IACtC,MAAA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