UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 7.5 kB
{"version":3,"file":"mention.mjs","names":[],"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 { ExtractPublicPropTypes } from 'vue'\nimport type Mention from './mention.vue'\nimport type { MentionOption } from './types'\nimport type { Options } from '@element-plus/components/popper'\nimport type { InputProps } from '@element-plus/components/input'\nimport type { ElTooltipContentProps } from '@element-plus/components/tooltip'\n\nexport interface MentionProps extends InputProps {\n /**\n * @description mention options list\n */\n options?: MentionOption[]\n /**\n * @description prefix character to trigger mentions. The string length must be exactly 1.\n */\n prefix?: string | string[]\n /**\n * @description character to split mentions. The string length must be exactly 1.\n */\n split?: string\n /**\n * @description customize filter option logic.\n */\n filterOption?: false | typeof filterOption\n /**\n * @description set popup placement\n */\n placement?: 'bottom' | 'top'\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?: number\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?: (pattern: string, prefix: string) => boolean\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?: ElTooltipContentProps['popperClass']\n /**\n * @description custom style for dropdown panel\n */\n popperStyle?: ElTooltipContentProps['popperStyle']\n /**\n * @description [popper.js](https://popper.js.org/docs/v2/) parameters\n */\n popperOptions?: Partial<Options>\n /**\n * @description configuration options\n */\n props?: MentionOptionProps\n}\n\n/**\n * @deprecated Removed after 3.0.0, Use `MentionProps` instead.\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\n\n/**\n * @deprecated Removed after 3.0.0, Use `MentionProps` instead.\n */\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"],"mappings":";;;;;;;;;;;AAqFA,MAAa,eAAe,WAAW;CACrC,GAAG;CAIH,SAAS;EACP,MAAM,eAAgC,MAAM;EAC5C,eAAe,EAAE;EAClB;CAID,QAAQ;EACN,MAAM,eAAkC,CAAC,QAAQ,MAAM,CAAC;EACxD,SAAS;EACT,YAAY,QAA2B;AACrC,OAAI,SAAS,IAAI,CAAE,QAAO,IAAI,WAAW;AACzC,UAAO,IAAI,OAAO,MAAM,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE;;EAEzD;CAID,OAAO;EACL,MAAM;EACN,SAAS;EACT,YAAY,QAAgB,IAAI,WAAW;EAC5C;CAID,cAAc;EACZ,MAAM,eAA4C,CAAC,SAAS,SAAS,CAAC;EACtE,eAAe;EACf,YAAY,QAAQ;AAClB,OAAI,QAAQ,MAAO,QAAO;AAC1B,UAAO,WAAW,IAAI;;EAEzB;CAID,WAAW;EACT,MAAM,eAAiC,OAAO;EAC9C,SAAS;EACV;CAID,WAAW;CAIX,QAAQ;EACN,MAAM;EACN,SAAS;EACV;CAID,OAAO;CAIP,cAAc,E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