UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

170 lines (169 loc) 6.46 kB
import type { ButtonProps, TextAreaProps } from "ant-design-vue"; import { Input } from "ant-design-vue"; import type { ConfigProviderProps } from "ant-design-vue"; import type { CSSProperties, VNode } from "vue"; import type { AllowSpeech } from "./useSpeech"; import type { AvoidValidation } from '../type-utility'; import SendButton from "./components/SendButton.vue"; import ClearButton from "./components/ClearButton.vue"; import LoadingButton from "./components/LoadingButton.vue"; import SpeechButton from "./components/SpeechButton/index.vue"; import type { SkillType, SlotConfigType, SlotTextAreaRef } from './slot-types'; export type { SkillType, SlotConfigType, InsertPosition, SlotTextAreaRef } from './slot-types'; export type SubmitType = 'enter' | 'shiftEnter' | false; export type KeyboardEventHandler = (e: KeyboardEvent) => void; export type ClipboardEventHandler = (e: ClipboardEvent) => void; export type ChangeEvent = Event & { target: { value?: string | undefined; }; }; export interface SenderComponents { input?: typeof Input.TextArea; } /** Align React Sender SemanticType (plus legacy `actions`). */ export type SenderSemanticType = 'root' | 'prefix' | 'input' | 'suffix' | 'footer' | 'switch' | 'content'; export type ActionsComponents = { SendButton: typeof SendButton; ClearButton: typeof ClearButton; LoadingButton: typeof LoadingButton; SpeechButton: typeof SpeechButton; }; export type ActionsRender = (ori: VNode, info: { components: ActionsComponents; }) => VNode; /** Alias of ActionsRender — aligned with React `@ant-design/x` `suffix`. */ export type SuffixRender = ActionsRender; export type FooterRender = (info: { components: ActionsComponents; }) => VNode; export interface SenderProps { onKeyPress?: KeyboardEventHandler; onFocus?: TextAreaProps['onFocus']; onBlur?: TextAreaProps['onBlur']; prefixCls?: string; defaultValue?: string; value?: string; loading?: boolean; placeholder?: TextAreaProps['placeholder']; readOnly?: boolean; submitType?: SubmitType; disabled?: boolean; sendDisabled?: boolean; slotConfig?: Readonly<SlotConfigType[]>; skill?: SkillType; onSubmit?: (message: string, slotConfig?: SlotConfigType[], skill?: SkillType) => void; onChange?: (value: string, event?: ChangeEvent, slotConfig?: SlotConfigType[], skill?: SkillType) => void; onCancel?: VoidFunction; onKeyDown?: KeyboardEventHandler; onPaste?: ClipboardEventHandler; onPasteFile?: (firstFile: File, files: FileList) => void; components?: SenderComponents; styles?: Partial<Record<SenderSemanticType, CSSProperties>> & { /** @deprecated Use `suffix` — kept for backward compatibility */ actions?: CSSProperties; }; rootClassName?: string; classNames?: Partial<Record<SenderSemanticType, string>> & { /** @deprecated Use `suffix` — kept for backward compatibility */ actions?: string; }; style?: CSSProperties; className?: string; /** * Custom action area (send / speech / loading). Set `false` to hide. * Prefer `suffix` (React 2.x name); `actions` remains as alias. * @deprecated Use `suffix` */ actions?: VNode | ActionsRender | false; /** Custom action area — React `@ant-design/x` 2.x API name. */ suffix?: VNode | SuffixRender | false; allowSpeech?: AvoidValidation<AllowSpeech>; prefix?: VNode | (() => VNode); footer?: VNode | FooterRender; header?: VNode | (() => VNode); autoSize?: AvoidValidation<boolean | { minRows?: number; maxRows?: number; }>; } export interface InputFocusOptions extends FocusOptions { cursor?: 'start' | 'end' | 'all' | 'slot'; key?: string; } export type SenderRef = { nativeElement: HTMLDivElement; /** Native textarea (plain) or SlotTextArea root (slot mode). */ inputElement: HTMLElement | null; focus: (options?: InputFocusOptions) => void; blur: () => void; /** * Plain mode: insert text into the textarea. * Slot mode: insert(string) as text slot, or insert(slotConfig[], …). */ insert: { (value: string): void; (slotConfig: import('./slot-types').SlotConfigType[], position?: import('./slot-types').InsertPosition, replaceCharacters?: string, preventScroll?: boolean): void; }; clear?: SlotTextAreaRef['clear']; getValue?: SlotTextAreaRef['getValue']; }; export interface SenderHeaderContextProps { prefixCls?: ConfigProviderProps['prefixCls']; } export type SemanticType = 'header' | 'content'; export interface SenderHeaderProps { forceRender?: boolean; open?: boolean; onOpenChange?: (open: boolean) => void; title?: VNode | string; children?: VNode; className?: string; style?: CSSProperties; classNames?: Partial<Record<SemanticType, string>>; styles?: Partial<Record<SemanticType, CSSProperties>>; closable?: boolean; } export interface RecordingIconProps { className?: string; audioIcon?: ButtonProps['icon']; audioDisabledIcon?: ButtonProps['icon']; audioRecordingIcon?: ButtonProps['icon']; } export interface ActionButtonContextProps { prefixCls?: ConfigProviderProps['prefixCls']; onSend?: VoidFunction; onSendDisabled?: boolean; onClear?: VoidFunction; onClearDisabled?: boolean; onCancel?: VoidFunction; onCancelDisabled?: boolean; onSpeech?: VoidFunction; onSpeechDisabled?: boolean; speechRecording?: boolean; disabled?: boolean; } export interface AntdButtonProps { prefixCls?: ButtonProps['prefixCls']; type?: ButtonProps['type']; htmlType?: ButtonProps['htmlType']; shape?: ButtonProps['shape']; size?: ButtonProps['size']; loading?: ButtonProps['loading']; disabled?: ButtonProps['disabled']; ghost?: ButtonProps['ghost']; block?: ButtonProps['block']; danger?: ButtonProps['danger']; icon?: ButtonProps['icon']; href?: ButtonProps['href']; target?: ButtonProps['target']; title?: ButtonProps['title']; onClick?: ButtonProps['onClick']; onMousedown?: ButtonProps['onMousedown']; audioIcon?: ButtonProps['icon'] | VNode; audioDisabledIcon?: ButtonProps['icon'] | VNode; audioRecordingIcon?: ButtonProps['icon'] | VNode; } export interface ActionButtonProps extends AntdButtonProps { action: 'onSend' | 'onClear' | 'onCancel' | 'onSpeech'; }