UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 6.62 kB
{"version":3,"file":"mention.mjs","sources":["../../../../../../packages/components/mention/src/mention.ts"],"sourcesContent":["import {\n buildProps,\n definePropType,\n isFunction,\n isObject,\n isString,\n} from '@element-plus/utils'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { inputProps } from '@element-plus/components/input'\nimport { filterOption } from './helper'\nimport { useTooltipContentProps } from '@element-plus/components/tooltip'\n\nimport type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue'\nimport type Mention from './mention.vue'\nimport type { MentionOption } from './types'\nimport type { Options } from '@element-plus/components/popper'\n\nexport const mentionProps = buildProps({\n ...inputProps,\n /**\n * @description mention options list\n */\n options: {\n type: definePropType<MentionOption[]>(Array),\n default: () => [],\n },\n /**\n * @description prefix character to trigger mentions. The string length must be exactly 1.\n */\n prefix: {\n type: definePropType<string | string[]>([String, Array]),\n default: '@',\n validator: (val: string | string[]) => {\n if (isString(val)) return val.length === 1\n return val.every((v) => isString(v) && v.length === 1)\n },\n },\n /**\n * @description character to split mentions. The string length must be exactly 1.\n */\n split: {\n type: String,\n default: ' ',\n validator: (val: string) => val.length === 1,\n },\n /**\n * @description customize filter option logic.\n */\n filterOption: {\n type: definePropType<false | typeof filterOption>([Boolean, Function]),\n default: () => filterOption,\n validator: (val) => {\n if (val === false) return true\n return isFunction(val)\n },\n },\n /**\n * @description set popup placement\n */\n placement: {\n type: definePropType<'bottom' | 'top'>(String),\n default: 'bottom',\n },\n /**\n * @description whether the dropdown panel has an arrow\n */\n showArrow: Boolean,\n /**\n * @description offset of the dropdown panel\n */\n offset: {\n type: Number,\n default: 0,\n },\n /**\n * @description when backspace is pressed to delete, whether the mention content is deleted as a whole\n */\n whole: Boolean,\n /**\n * @description when backspace is pressed to delete, check if the mention is a whole\n */\n checkIsWhole: {\n type: definePropType<(pattern: string, prefix: string) => boolean>(\n Function\n ),\n },\n /**\n * @description input value\n */\n modelValue: String,\n /**\n * @description whether the dropdown panel of mentions is in a loading state.\n */\n loading: Boolean,\n /**\n * @description custom class name for dropdown panel\n */\n popperClass: useTooltipContentProps.popperClass,\n /**\n * @description custom style for dropdown panel\n */\n popperStyle: useTooltipContentProps.popperStyle,\n /**\n * @description [popper.js](https://popper.js.org/docs/v2/) parameters\n */\n popperOptions: {\n type: definePropType<Partial<Options>>(Object),\n default: () => ({}) as Partial<Options>,\n },\n /**\n * @description configuration options\n */\n props: {\n type: definePropType<MentionOptionProps>(Object),\n default: () => mentionDefaultProps,\n },\n})\n\nexport const mentionEmits = {\n [UPDATE_MODEL_EVENT]: (value: string) => isString(value),\n 'whole-remove': (pattern: string, prefix: string) =>\n isString(pattern) && isString(prefix),\n input: (value: string) => isString(value),\n search: (pattern: string, prefix: string) =>\n isString(pattern) && isString(prefix),\n select: (option: MentionOption, prefix: string) =>\n isObject(option) && isString(prefix),\n focus: (evt: FocusEvent) => evt instanceof FocusEvent,\n blur: (evt: FocusEvent) => evt instanceof FocusEvent,\n}\n\nexport type MentionEmits = typeof mentionEmits\nexport type MentionProps = ExtractPropTypes<typeof mentionProps>\nexport type MentionPropsPublic = ExtractPublicPropTypes<typeof mentionProps>\nexport type MentionInstance = InstanceType<typeof Mention> & unknown\n\nexport type { MentionOption } from './types'\n\nexport type MentionOptionProps = {\n value?: string\n label?: string\n disabled?: string\n [key: string]: string | undefined\n}\n\nexport const mentionDefaultProps: Required<MentionOptionProps> = {\n value: 'value',\n label: 'label',\n disabled: 'disabled',\n}\n"],"names":[],"mappings":";;;;;;;AAiBO,MAAM,eAAe,UAAW,CAAA;AAAA,EACrC,GAAG,UAAA;AAAA,EAIH,OAAS,EAAA;AAAA,IACP,IAAA,EAAM,eAAgC,KAAK,CAAA;AAAA,IAC3C,OAAA,EAAS,MAAM,EAAC;AAAA,GAClB;AAAA,EAIA,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,cAAA,CAAkC,CAAC,MAAA,EAAQ,KAAK,CAAC,CAAA;AAAA,IACvD,OA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