UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 7.27 kB
{"version":3,"file":"autocomplete.mjs","names":[],"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"],"mappings":";;;;;;;;;;;AA4GA,MAAa,oBAAoB,WAAW;CAC1C,GAAG;CAIH,UAAU;EACR,MAAM;EACN,SAAS;EACV;CAID,YAAY;EACV,MAAM,CAAC,QAAQ,OAAO;EACtB,SAAS;EACV;CAID,UAAU;EACR,MAAM;EACN,SAAS;EACV;CAID,WAAW;EACT,MAAM,eAA0B,OAAO;EACvC,QAAQ;GACN;GACA;GACA;GACA;GACA;GACA;GACD;EACD,SAAS;EACV;CAID,kBAAkB;EAChB,MAAM,eAA6C,CAAC,UAAU,MAAM,CAAC;EACrE,SAAS;EACV;CAID,aAAa,uBAAuB;CAIpC,aAAa,uBAAuB;CAIpC,gBAAgB;EACd,MAAM;EACN,SAAS;EACV;CAID,qBAAqB;CAIrB,aAAa;CAIb,YAAY,uBAAuB;CAInC,UAAU,uBAAuB;CAIjC,oBAAoB;CAIpB,eAAe;CAIf,gBAAgB;EACd,MAAM;EACN,SAAS;EACV;CACF,CAAU;AASX,MAAa,oBAAoB;EAC9B,sBAAsB,UACrB,SAAS,MAAM,IAAI,SAAS,MAAM;EACnC,eAAe,UAA2B,SAAS,MAAM,IAAI,SAAS,MAAM;EAC5E,gBAAgB,UACf,SAAS,MAAM,IAAI,SAAS,MAAM;CACpC,QAAQ,QAAoB,eAAe;CAC3C,OAAO,QAAoB,eAAe;CAC1C,aAAa;CACb,SAAS,SAA8B,SAAS,KAAK;CACtD"}