Skip to content

Commit 6b1fdbb

Browse files
committed
refactor(sender-compat): consolidate type definitions and remove redundant clear action
1 parent a404ff6 commit 6b1fdbb

3 files changed

Lines changed: 22 additions & 70 deletions

File tree

packages/components/src/sender-compat/index.type.ts

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,12 @@
44
*/
55

66
import type { VNode, Component } from 'vue'
7+
import type { InputMode, SubmitTrigger, AutoSize } from '../sender/types/base'
8+
import type { SpeechConfig } from '../sender-actions/voice-button/speech.types'
79

810
// 主题类型
911
export type ThemeType = 'light' | 'dark'
1012

11-
// 输入模式类型
12-
export type InputMode = 'single' | 'multiple'
13-
14-
// 提交触发方式
15-
export type SubmitTrigger = 'enter' | 'ctrlEnter' | 'shiftEnter'
16-
17-
// 语音回调函数集合
18-
export interface SpeechCallbacks {
19-
onStart: () => void
20-
onInterim: (transcript: string) => void
21-
onFinal: (transcript: string) => void
22-
onEnd: (transcript?: string) => void
23-
onError: (error: Error) => void
24-
}
25-
26-
// 语音处理器接口
27-
export interface SpeechHandler {
28-
start: (callbacks: SpeechCallbacks) => Promise<void> | void
29-
stop: () => Promise<void> | void
30-
isSupported: () => boolean
31-
}
32-
33-
// 语音识别配置
34-
export interface SpeechConfig {
35-
customHandler?: SpeechHandler
36-
lang?: string
37-
continuous?: boolean
38-
interimResults?: boolean
39-
autoReplace?: boolean
40-
onVoiceButtonClick?: (isRecording: boolean, preventDefault: () => void) => void | Promise<void>
41-
}
42-
43-
export type AutoSize = boolean | { minRows: number; maxRows: number }
44-
4513
export type TooltipRender = () => VNode | string
4614

4715
export interface ControlState {
@@ -78,6 +46,11 @@ export interface ButtonGroupConfig {
7846
voice?: VoiceButtonConfig
7947
}
8048

49+
// ============================================
50+
// 建议项相关类型(旧版兼容层专用)
51+
// 注意:这些类型与新版 sender 的 SuggestionItem 不同,仅用于兼容旧版 API
52+
// ============================================
53+
8154
// 高亮片段类型
8255
export interface SuggestionTextPart {
8356
text: string
@@ -138,21 +111,27 @@ export type SenderEmits = {
138111
(e: 'files-selected', files: File[]): void
139112
}
140113

141-
// UserItem 相关类型
142-
export interface TextItem {
114+
// ============================================
115+
// UserItem 相关类型(旧版兼容层专用)
116+
// 注意:这些类型与新版 sender 的 TemplateItem 不同,仅用于兼容旧版 API
117+
// ============================================
118+
119+
export interface CompatTextItem {
143120
id: string
144121
type: 'text'
145122
content: string
146123
}
147124

148-
export interface TemplateItem {
125+
export interface CompatTemplateItem {
149126
id: string
150127
type: 'template' | 'block'
151128
content: string
152129
}
153130

154-
export type UserTextItem = Omit<TextItem, 'id'> & { id?: TextItem['id'] }
131+
export type UserTextItem = Omit<CompatTextItem, 'id'> & { id?: CompatTextItem['id'] }
155132

156-
export type UserTemplateItem = Omit<Pick<TemplateItem, 'type' | 'content'>, 'id'> & { id?: TemplateItem['id'] }
133+
export type UserTemplateItem = Omit<Pick<CompatTemplateItem, 'type' | 'content'>, 'id'> & {
134+
id?: CompatTemplateItem['id']
135+
}
157136

158137
export type UserItem = UserTextItem | UserTemplateItem

packages/components/src/sender-compat/index.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ const defaultActions = computed(() => {
6969
actions.submit = props.buttonGroup.submit
7070
}
7171
72-
if (props.buttonGroup?.file) {
73-
actions.clear = {
74-
disabled: props.buttonGroup.file.disabled,
75-
tooltip: props.buttonGroup.file.disabled ? '无法清空' : '清空输入',
76-
}
77-
}
78-
7972
return Object.keys(actions).length > 0 ? actions : undefined
8073
})
8174

packages/components/src/sender/extensions/template/types.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,11 @@
33
*/
44

55
import type { Ref } from 'vue'
6-
import type { TemplateItem } from '../../index.type'
6+
import type { TemplateItem, SelectOption } from '../../index.type'
77
import '@tiptap/core'
88

9-
// 重新导出 TemplateItem 以便外部使用
10-
export type { TemplateItem }
11-
12-
/**
13-
* 选择器选项
14-
*/
15-
export interface SelectOption {
16-
/**
17-
* 显示文本
18-
*/
19-
label: string
20-
21-
/**
22-
* 选择后的值
23-
*/
24-
value: string
25-
26-
/**
27-
* 自定义数据(可选)
28-
*/
29-
data?: string
30-
}
9+
// 重新导出 TemplateItem 和 SelectOption 以便外部使用
10+
export type { TemplateItem, SelectOption }
3111

3212
/**
3313
* TemplateSelect 节点属性
@@ -99,7 +79,7 @@ export interface TemplateOptions {
9979
* })
10080
* ```
10181
*/
102-
items?: TemplateItem[] | Ref<TemplateItem[], TemplateItem[]>
82+
items?: TemplateItem[] | Ref<TemplateItem[]>
10383

10484
/**
10585
* HTML 属性

0 commit comments

Comments
 (0)