@blueking/chat-x 0.0.51-beta.2 → 0.0.51-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat-content/file-content/upload-image-item.vue.d.ts +2 -0
- package/dist/components/chat-content/file-content/upload-spinner.vue.d.ts +3 -0
- package/dist/components/chat-input/chat-input.vue.d.ts +3 -0
- package/dist/index.css +1 -1
- package/dist/index.js +745 -712
- package/dist/index.js.map +1 -1
- package/dist/lang/lang.d.ts +4 -1
- package/dist/mcp/generated/docs/chat-container.md +1 -1
- package/dist/mcp/generated/docs/chat-input.md +3 -2
- package/dist/mcp/generated/docs/file-content.md +27 -10
- package/dist/mcp/generated/index.json +3 -3
- package/dist/mcp/index.js +0 -0
- package/package.json +21 -23
- package/skills/blueking-chat-x/SKILL.md +0 -139
- package/skills/blueking-chat-x/references/_index.md +0 -131
- package/skills/blueking-chat-x/references/components/activity-layout.md +0 -134
- package/skills/blueking-chat-x/references/components/activity-message.md +0 -486
- package/skills/blueking-chat-x/references/components/ai-image.md +0 -230
- package/skills/blueking-chat-x/references/components/ai-loading.md +0 -131
- package/skills/blueking-chat-x/references/components/ai-prompt-list.md +0 -44
- package/skills/blueking-chat-x/references/components/ai-selection.md +0 -439
- package/skills/blueking-chat-x/references/components/ai-skill-list.md +0 -73
- package/skills/blueking-chat-x/references/components/ai-slash-editor.md +0 -43
- package/skills/blueking-chat-x/references/components/ai-slash-input.md +0 -56
- package/skills/blueking-chat-x/references/components/ai-slash-menu.md +0 -42
- package/skills/blueking-chat-x/references/components/animation-text.md +0 -202
- package/skills/blueking-chat-x/references/components/assistant-message.md +0 -498
- package/skills/blueking-chat-x/references/components/chat-container.md +0 -869
- package/skills/blueking-chat-x/references/components/chat-input.md +0 -769
- package/skills/blueking-chat-x/references/components/cite-content.md +0 -142
- package/skills/blueking-chat-x/references/components/code-content.md +0 -211
- package/skills/blueking-chat-x/references/components/common-error-content.md +0 -73
- package/skills/blueking-chat-x/references/components/content-render.md +0 -233
- package/skills/blueking-chat-x/references/components/delete-tool.md +0 -191
- package/skills/blueking-chat-x/references/components/desc-panel.md +0 -162
- package/skills/blueking-chat-x/references/components/detail-section.md +0 -91
- package/skills/blueking-chat-x/references/components/execution-summary.md +0 -128
- package/skills/blueking-chat-x/references/components/file-artifact-panel.md +0 -289
- package/skills/blueking-chat-x/references/components/file-content.md +0 -319
- package/skills/blueking-chat-x/references/components/file-icon.md +0 -109
- package/skills/blueking-chat-x/references/components/file-upload-btn.md +0 -159
- package/skills/blueking-chat-x/references/components/flow-agent-content.md +0 -264
- package/skills/blueking-chat-x/references/components/flow-agent-node-detail.md +0 -236
- package/skills/blueking-chat-x/references/components/highlight-keyword.md +0 -146
- package/skills/blueking-chat-x/references/components/image-content.md +0 -182
- package/skills/blueking-chat-x/references/components/image-preview-group.md +0 -184
- package/skills/blueking-chat-x/references/components/image-preview.md +0 -226
- package/skills/blueking-chat-x/references/components/info-message.md +0 -144
- package/skills/blueking-chat-x/references/components/input-attachment.md +0 -49
- package/skills/blueking-chat-x/references/components/input-info-alert.md +0 -42
- package/skills/blueking-chat-x/references/components/interrupt-message.md +0 -212
- package/skills/blueking-chat-x/references/components/key-value-content.md +0 -128
- package/skills/blueking-chat-x/references/components/knowledge-rag-content.md +0 -122
- package/skills/blueking-chat-x/references/components/latex-content.md +0 -200
- package/skills/blueking-chat-x/references/components/loading-message.md +0 -192
- package/skills/blueking-chat-x/references/components/markdown-content.md +0 -232
- package/skills/blueking-chat-x/references/components/mermaid-content.md +0 -189
- package/skills/blueking-chat-x/references/components/message-container.md +0 -645
- package/skills/blueking-chat-x/references/components/message-loading.md +0 -118
- package/skills/blueking-chat-x/references/components/message-render.md +0 -327
- package/skills/blueking-chat-x/references/components/message-time.md +0 -177
- package/skills/blueking-chat-x/references/components/message-tools.md +0 -416
- package/skills/blueking-chat-x/references/components/model-selector.md +0 -155
- package/skills/blueking-chat-x/references/components/preview-toolbar.md +0 -42
- package/skills/blueking-chat-x/references/components/questions-container.md +0 -85
- package/skills/blueking-chat-x/references/components/reasoning-message.md +0 -232
- package/skills/blueking-chat-x/references/components/reference-content.md +0 -135
- package/skills/blueking-chat-x/references/components/reference-doc-content.md +0 -109
- package/skills/blueking-chat-x/references/components/scroll-btn.md +0 -159
- package/skills/blueking-chat-x/references/components/selection-footer.md +0 -78
- package/skills/blueking-chat-x/references/components/selection-question.md +0 -88
- package/skills/blueking-chat-x/references/components/shortcut-btn.md +0 -204
- package/skills/blueking-chat-x/references/components/shortcut-btns.md +0 -266
- package/skills/blueking-chat-x/references/components/shortcut-render.md +0 -424
- package/skills/blueking-chat-x/references/components/simple-table.md +0 -101
- package/skills/blueking-chat-x/references/components/text-content.md +0 -77
- package/skills/blueking-chat-x/references/components/tool-approval-card.md +0 -183
- package/skills/blueking-chat-x/references/components/tool-btn.md +0 -317
- package/skills/blueking-chat-x/references/components/tool-message.md +0 -235
- package/skills/blueking-chat-x/references/components/toolcall-render.md +0 -348
- package/skills/blueking-chat-x/references/components/user-feedback.md +0 -233
- package/skills/blueking-chat-x/references/components/user-message.md +0 -424
- package/skills/blueking-chat-x/references/components/user-question-answered-card.md +0 -104
- package/skills/blueking-chat-x/references/components/user-question-card.md +0 -231
- package/skills/blueking-chat-x/references/components/user-question-choice.md +0 -105
- package/skills/blueking-chat-x/references/components/user-question-option.md +0 -42
- package/skills/blueking-chat-x/references/components/vnode-renderer.md +0 -122
- package/skills/blueking-chat-x/references/composables/use-animation-text.md +0 -196
- package/skills/blueking-chat-x/references/composables/use-artifact-preview.md +0 -231
- package/skills/blueking-chat-x/references/composables/use-clipboard.md +0 -203
- package/skills/blueking-chat-x/references/composables/use-command-selection.md +0 -150
- package/skills/blueking-chat-x/references/composables/use-container-scroll.md +0 -57
- package/skills/blueking-chat-x/references/composables/use-custom-tab.md +0 -158
- package/skills/blueking-chat-x/references/composables/use-flow-node-actions.md +0 -157
- package/skills/blueking-chat-x/references/composables/use-full-screen.md +0 -112
- package/skills/blueking-chat-x/references/composables/use-global-config.md +0 -148
- package/skills/blueking-chat-x/references/composables/use-menu-keydown.md +0 -163
- package/skills/blueking-chat-x/references/composables/use-message-group.md +0 -247
- package/skills/blueking-chat-x/references/composables/use-observer-visible-list.md +0 -188
- package/skills/blueking-chat-x/references/composables/use-parent-scrolling.md +0 -46
- package/skills/blueking-chat-x/references/theme/theme.md +0 -431
- package/skills/blueking-chat-x/references/types/constants.md +0 -307
- package/skills/blueking-chat-x/references/types/interrupt.md +0 -379
- package/skills/blueking-chat-x/references/types/messages.md +0 -553
- package/skills/blueking-chat-x/references/types/schema.md +0 -91
- package/skills/blueking-chat-x/scripts/generate-references.mjs +0 -314
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
# AiSelection 划词选择
|
|
2
|
-
|
|
3
|
-
> 能力域:输入交互 | 导入:`import { AiSelection } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
-
|
|
5
|
-
监听选中文本并展示快捷操作浮窗。 源码位置:src/components/ai-selection/ai-selection.vue。
|
|
6
|
-
|
|
7
|
-
**关联**:shortcut-btn(弹窗内快捷指令按钮/菜单项由该基础组件渲染)、chat-input(划词结果常回填或触发与输入框联动的快捷指令)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# AiSelection AI 划词选择弹窗
|
|
12
|
-
## 源码事实
|
|
13
|
-
|
|
14
|
-
- **源码位置**:`src/components/ai-selection/ai-selection.vue`
|
|
15
|
-
- **能力域**:输入交互
|
|
16
|
-
- **能力说明**:监听选中文本并展示快捷操作浮窗。
|
|
17
|
-
|
|
18
|
-
> **能力域**:输入交互
|
|
19
|
-
|
|
20
|
-
AI 划词选择组件,监听用户在页面中的文本选区,在选区附近弹出快捷操作菜单。支持自定义快捷指令列表、数量限制、垂直偏移以及完全自定义插槽内容。
|
|
21
|
-
|
|
22
|
-
> **注意**:`AiSelection` 通过 `document.addEventListener` 监听全局事件(`selectionchange`、`mouseup`、`mousedown`、`scroll`),**同一页面中只应挂载一个实例**,避免多实例同时响应导致事件重复和弹窗叠加。
|
|
23
|
-
|
|
24
|
-
## 工作原理
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
用户选中文本
|
|
28
|
-
↓ mouseup(200ms 防抖)/ selectionchange(300ms 防抖)
|
|
29
|
-
获取选区文本 & 坐标 → 计算弹窗位置
|
|
30
|
-
↓
|
|
31
|
-
通过 <Teleport to="body"> 将弹窗渲染到 <body> 末尾
|
|
32
|
-
↓
|
|
33
|
-
用户点击快捷指令 → 触发 selectShortcut 事件 → 关闭弹窗
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
弹窗渲染在 `<body>` 顶层,不受父级 `overflow: hidden` / `z-index` 影响,定位坐标基于视口(`position: fixed`)。
|
|
37
|
-
|
|
38
|
-
## 弹窗关闭时机
|
|
39
|
-
|
|
40
|
-
| 触发条件 | 说明 |
|
|
41
|
-
| ------------------ | -------------------------------- |
|
|
42
|
-
| 点击弹窗外部区域 | `mousedown` 事件,弹窗外任意位置 |
|
|
43
|
-
| 滚动包含选区的容器 | `scroll` 事件捕获阶段 |
|
|
44
|
-
| 窗口大小改变 | `window.resize` |
|
|
45
|
-
| 窗口失去焦点 | `window.blur` |
|
|
46
|
-
| 点击快捷指令 | 触发后立即关闭并清除选区 |
|
|
47
|
-
|
|
48
|
-
## 基础用法
|
|
49
|
-
|
|
50
|
-
不传 `shortcuts` 时,使用内置默认快捷指令"问问小鲸"(`id: 'ai-chat'`):
|
|
51
|
-
|
|
52
|
-
```vue
|
|
53
|
-
<template>
|
|
54
|
-
<AiSelection v-model:visible="selectionVisible" />
|
|
55
|
-
</template>
|
|
56
|
-
|
|
57
|
-
<script setup lang="ts">
|
|
58
|
-
import { ref } from 'vue';
|
|
59
|
-
import { AiSelection } from '@blueking/chat-x';
|
|
60
|
-
|
|
61
|
-
const selectionVisible = ref(false);
|
|
62
|
-
</script>
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**渲染效果**(选中下方文字后弹出快捷操作菜单)
|
|
66
|
-
|
|
67
|
-
## 自定义快捷指令
|
|
68
|
-
|
|
69
|
-
通过 `shortcuts` 属性传入自定义快捷指令列表:
|
|
70
|
-
|
|
71
|
-
```vue
|
|
72
|
-
<template>
|
|
73
|
-
<AiSelection
|
|
74
|
-
v-model:visible="selectionVisible"
|
|
75
|
-
:shortcuts="shortcuts"
|
|
76
|
-
@select-shortcut="handleSelectShortcut"
|
|
77
|
-
@selection-change="handleSelectionChange"
|
|
78
|
-
/>
|
|
79
|
-
</template>
|
|
80
|
-
|
|
81
|
-
<script setup lang="ts">
|
|
82
|
-
import { ref } from 'vue';
|
|
83
|
-
import { AiSelection, type Shortcut } from '@blueking/chat-x';
|
|
84
|
-
|
|
85
|
-
const selectionVisible = ref(false);
|
|
86
|
-
|
|
87
|
-
const shortcuts: Shortcut[] = [
|
|
88
|
-
{ id: 'ai-chat', name: '问问小鲸' },
|
|
89
|
-
{ id: 'translate', name: '翻译' },
|
|
90
|
-
{ id: 'explain', name: '解释' },
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
const handleSelectShortcut = (shortcut: Shortcut, selectedText: string) => {
|
|
94
|
-
console.log('触发指令:', shortcut.name, '选中文本:', selectedText);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const handleSelectionChange = (text: string) => {
|
|
98
|
-
console.log('选区变化:', text);
|
|
99
|
-
};
|
|
100
|
-
</script>
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**渲染效果**(选中文字后弹出 3 个快捷操作按钮)
|
|
104
|
-
|
|
105
|
-
## 快捷指令数量限制
|
|
106
|
-
|
|
107
|
-
当快捷指令数量超过 `maxShortcutCount`(默认 `3`)时,多余的指令会收起到「更多」菜单(点击 `›` 箭头展开)。
|
|
108
|
-
|
|
109
|
-
### `maxShortcutCount = 3`(默认)
|
|
110
|
-
|
|
111
|
-
6 个指令中前 3 个直接展示,其余 3 个收起:
|
|
112
|
-
|
|
113
|
-
```vue
|
|
114
|
-
<template>
|
|
115
|
-
<AiSelection
|
|
116
|
-
v-model:visible="selectionVisible"
|
|
117
|
-
:shortcuts="shortcuts"
|
|
118
|
-
/>
|
|
119
|
-
</template>
|
|
120
|
-
|
|
121
|
-
<script setup lang="ts">
|
|
122
|
-
import { ref } from 'vue';
|
|
123
|
-
import { AiSelection, type Shortcut } from '@blueking/chat-x';
|
|
124
|
-
|
|
125
|
-
const selectionVisible = ref(false);
|
|
126
|
-
|
|
127
|
-
const shortcuts: Shortcut[] = [
|
|
128
|
-
{ id: 'ai-chat', name: '问问小鲸' },
|
|
129
|
-
{ id: 'translate', name: '翻译' },
|
|
130
|
-
{ id: 'explain', name: '解释' },
|
|
131
|
-
{ id: 'summarize', name: '总结' },
|
|
132
|
-
{ id: 'improve', name: '改进' },
|
|
133
|
-
{ id: 'code', name: '生成代码' },
|
|
134
|
-
];
|
|
135
|
-
</script>
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
**渲染效果**(展示 3 个,其余 3 个收起到「更多」菜单)
|
|
139
|
-
|
|
140
|
-
### `maxShortcutCount = 5`
|
|
141
|
-
|
|
142
|
-
前 5 个直接展示,仅最后 1 个收起:
|
|
143
|
-
|
|
144
|
-
```vue
|
|
145
|
-
<AiSelection v-model:visible="selectionVisible" :shortcuts="shortcuts" :max-shortcut-count="5" />
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
**渲染效果**(展示 5 个,仅「生成代码」收起)
|
|
149
|
-
|
|
150
|
-
## 带图标的快捷指令
|
|
151
|
-
|
|
152
|
-
`icon` 属性支持三种形式:
|
|
153
|
-
|
|
154
|
-
| 类型 | 说明 | 示例 |
|
|
155
|
-
| --------------------------------- | --------------- | -------------------------------- |
|
|
156
|
-
| `string`(emoji) | 直接渲染文本 | `'🌐'` |
|
|
157
|
-
| `string`(HTTP URL) | 渲染为 `<img>` | `'https://example.com/icon.svg'` |
|
|
158
|
-
| `VNode \| (c: typeof h) => VNode` | 渲染为 Vue 组件 | `ThinkingIcon`(内置图标组件) |
|
|
159
|
-
|
|
160
|
-
```vue
|
|
161
|
-
<script setup lang="ts">
|
|
162
|
-
import { h } from 'vue';
|
|
163
|
-
import { AiSelection, type Shortcut } from '@blueking/chat-x';
|
|
164
|
-
|
|
165
|
-
const shortcuts: Shortcut[] = [
|
|
166
|
-
{
|
|
167
|
-
id: 'ai-chat',
|
|
168
|
-
name: '问问小鲸',
|
|
169
|
-
// VNode 渲染函数
|
|
170
|
-
icon: c => c('span', { style: 'font-size: 14px;' }, '🐳'),
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
id: 'translate',
|
|
174
|
-
name: '翻译',
|
|
175
|
-
icon: '🌐', // Emoji 字符串
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
id: 'search',
|
|
179
|
-
name: '搜索',
|
|
180
|
-
icon: 'https://example.com/search-icon.svg', // URL(渲染为 img)
|
|
181
|
-
},
|
|
182
|
-
];
|
|
183
|
-
</script>
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## 事件回调
|
|
187
|
-
|
|
188
|
-
`selectShortcut` 在用户点击快捷指令后触发,携带指令对象和选中文本;`selectionChange` 在选区文字内容变化时触发:
|
|
189
|
-
|
|
190
|
-
```vue
|
|
191
|
-
<template>
|
|
192
|
-
<div>
|
|
193
|
-
<p>选中文字后点击快捷指令,观察下方回调信息。</p>
|
|
194
|
-
|
|
195
|
-
<AiSelection
|
|
196
|
-
v-model:visible="selectionVisible"
|
|
197
|
-
:shortcuts="shortcuts"
|
|
198
|
-
@select-shortcut="handleSelectShortcut"
|
|
199
|
-
@selection-change="handleSelectionChange"
|
|
200
|
-
/>
|
|
201
|
-
|
|
202
|
-
<div
|
|
203
|
-
v-if="selectedInfo.shortcut"
|
|
204
|
-
class="callback-info"
|
|
205
|
-
>
|
|
206
|
-
<p>触发指令:{{ selectedInfo.shortcut }}</p>
|
|
207
|
-
<p>选中文本:{{ selectedInfo.text }}</p>
|
|
208
|
-
</div>
|
|
209
|
-
</div>
|
|
210
|
-
</template>
|
|
211
|
-
|
|
212
|
-
<script setup lang="ts">
|
|
213
|
-
import { ref } from 'vue';
|
|
214
|
-
import { AiSelection, type Shortcut } from '@blueking/chat-x';
|
|
215
|
-
|
|
216
|
-
const selectionVisible = ref(false);
|
|
217
|
-
const selectedInfo = ref({ shortcut: '', text: '' });
|
|
218
|
-
|
|
219
|
-
const shortcuts: Shortcut[] = [
|
|
220
|
-
{ id: 'ai-chat', name: '问问小鲸' },
|
|
221
|
-
{ id: 'translate', name: '翻译' },
|
|
222
|
-
{ id: 'explain', name: '解释' },
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
const handleSelectShortcut = (shortcut: Shortcut, selectedText: string) => {
|
|
226
|
-
selectedInfo.value = { shortcut: shortcut.name, text: selectedText };
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const handleSelectionChange = (text: string) => {
|
|
230
|
-
console.log('选区变化:', text);
|
|
231
|
-
};
|
|
232
|
-
</script>
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
**渲染效果**(点击快捷指令后下方显示回调信息)
|
|
236
|
-
|
|
237
|
-
## 自定义垂直偏移
|
|
238
|
-
|
|
239
|
-
`offset` 控制弹窗与选区之间的垂直距离(单位 px),默认 `10`。弹窗优先显示在选区**上方**,空间不足时自动显示在**下方**:
|
|
240
|
-
|
|
241
|
-
```vue
|
|
242
|
-
<!-- 间距 20px -->
|
|
243
|
-
<AiSelection v-model:visible="selectionVisible" :offset="20" />
|
|
244
|
-
|
|
245
|
-
<!-- 紧贴选区(间距 0) -->
|
|
246
|
-
<AiSelection v-model:visible="selectionVisible" :offset="0" />
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## 自定义插槽
|
|
250
|
-
|
|
251
|
-
默认插槽替换整个弹窗内容区,插槽参数 `shortcuts` 为**完整**快捷指令列表(未经 `maxShortcutCount` 截断):
|
|
252
|
-
|
|
253
|
-
```vue
|
|
254
|
-
<template>
|
|
255
|
-
<AiSelection
|
|
256
|
-
v-model:visible="selectionVisible"
|
|
257
|
-
:shortcuts="shortcuts"
|
|
258
|
-
>
|
|
259
|
-
<template #default="{ shortcuts }">
|
|
260
|
-
<div class="my-menu">
|
|
261
|
-
<button
|
|
262
|
-
v-for="shortcut in shortcuts"
|
|
263
|
-
:key="shortcut.id"
|
|
264
|
-
@click="handleClick(shortcut)"
|
|
265
|
-
>
|
|
266
|
-
{{ shortcut.name }}
|
|
267
|
-
</button>
|
|
268
|
-
</div>
|
|
269
|
-
</template>
|
|
270
|
-
</AiSelection>
|
|
271
|
-
</template>
|
|
272
|
-
|
|
273
|
-
<script setup lang="ts">
|
|
274
|
-
import { ref } from 'vue';
|
|
275
|
-
import { AiSelection, type Shortcut } from '@blueking/chat-x';
|
|
276
|
-
|
|
277
|
-
const selectionVisible = ref(false);
|
|
278
|
-
|
|
279
|
-
const shortcuts: Shortcut[] = [
|
|
280
|
-
{ id: 'ai-chat', name: '问问小鲸' },
|
|
281
|
-
{ id: 'translate', name: '翻译' },
|
|
282
|
-
];
|
|
283
|
-
|
|
284
|
-
const handleClick = (shortcut: Shortcut) => {
|
|
285
|
-
const text = window.getSelection()?.toString() || '';
|
|
286
|
-
console.log(shortcut.name, text);
|
|
287
|
-
};
|
|
288
|
-
</script>
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
> **注意**:使用默认插槽后,`maxShortcutCount` 不再生效,「更多」菜单也不会出现,需要自行处理超出逻辑。
|
|
292
|
-
|
|
293
|
-
## 排除区域
|
|
294
|
-
|
|
295
|
-
通过 `excludeSelectors` 指定 CSS 选择器列表,当选区位于这些选择器匹配的元素内部时,弹窗不会弹出。适用于代码块、表单输入等不需要划词弹窗的区域:
|
|
296
|
-
|
|
297
|
-
```vue
|
|
298
|
-
<template>
|
|
299
|
-
<AiSelection
|
|
300
|
-
v-model:visible="selectionVisible"
|
|
301
|
-
:exclude-selectors="['.code-block', '.no-selection']"
|
|
302
|
-
/>
|
|
303
|
-
|
|
304
|
-
<div class="code-block">这里选中文字不会弹出操作菜单</div>
|
|
305
|
-
<div class="no-selection">这里也不会弹出</div>
|
|
306
|
-
<p>这里选中文字正常弹出操作菜单</p>
|
|
307
|
-
</template>
|
|
308
|
-
|
|
309
|
-
<script setup lang="ts">
|
|
310
|
-
import { ref } from 'vue';
|
|
311
|
-
import { AiSelection } from '@blueking/chat-x';
|
|
312
|
-
|
|
313
|
-
const selectionVisible = ref(false);
|
|
314
|
-
</script>
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
## Input / Textarea 支持
|
|
318
|
-
|
|
319
|
-
组件对 `<input>` 和 `<textarea>` 中的选区进行了特殊处理:原生 Range 在这两类元素中无法获取准确坐标,组件会降级使用**输入框自身的 `getBoundingClientRect()`** 作为弹窗位置参考。
|
|
320
|
-
|
|
321
|
-
## 与 ChatBot 联动
|
|
322
|
-
|
|
323
|
-
选中文本后触发快捷指令,自动将选中内容作为上下文发送到聊天窗口:
|
|
324
|
-
|
|
325
|
-
```vue
|
|
326
|
-
<template>
|
|
327
|
-
<div class="page">
|
|
328
|
-
<article>文章内容...</article>
|
|
329
|
-
|
|
330
|
-
<AiSelection
|
|
331
|
-
v-model:visible="selectionVisible"
|
|
332
|
-
:shortcuts="shortcuts"
|
|
333
|
-
@select-shortcut="handleSelectShortcut"
|
|
334
|
-
/>
|
|
335
|
-
|
|
336
|
-
<ChatBot ref="chatBotRef" />
|
|
337
|
-
</div>
|
|
338
|
-
</template>
|
|
339
|
-
|
|
340
|
-
<script setup lang="ts">
|
|
341
|
-
import { ref } from 'vue';
|
|
342
|
-
import { AiSelection, ChatBot, type Shortcut } from '@blueking/chat-x';
|
|
343
|
-
|
|
344
|
-
const selectionVisible = ref(false);
|
|
345
|
-
const chatBotRef = ref();
|
|
346
|
-
|
|
347
|
-
const shortcuts: Shortcut[] = [
|
|
348
|
-
{ id: 'ai-chat', name: '问问小鲸' },
|
|
349
|
-
{ id: 'translate', name: '翻译' },
|
|
350
|
-
{ id: 'explain', name: '解释' },
|
|
351
|
-
];
|
|
352
|
-
|
|
353
|
-
const handleSelectShortcut = (shortcut: Shortcut, selectedText: string) => {
|
|
354
|
-
const prompts: Record<string, string> = {
|
|
355
|
-
translate: `请翻译以下内容:\n${selectedText}`,
|
|
356
|
-
explain: `请解释以下内容:\n${selectedText}`,
|
|
357
|
-
};
|
|
358
|
-
chatBotRef.value?.sendMessage(prompts[shortcut.id] ?? selectedText);
|
|
359
|
-
};
|
|
360
|
-
</script>
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
<!-- 全页唯一的 AiSelection 实例,通过各演示区的 mousedown 切换当前配置 -->
|
|
364
|
-
|
|
365
|
-
<AiSelectionComp
|
|
366
|
-
v-model:visible="selectionVisible"
|
|
367
|
-
:shortcuts="currentConfig.shortcuts"
|
|
368
|
-
:max-shortcut-count="currentConfig.maxShortcutCount"
|
|
369
|
-
@select-shortcut="handleSelectShortcut"
|
|
370
|
-
/>
|
|
371
|
-
|
|
372
|
-
## API
|
|
373
|
-
|
|
374
|
-
### Props
|
|
375
|
-
|
|
376
|
-
| 属性名 | 类型 | 默认值 | 必填 | 说明 |
|
|
377
|
-
| ---------------- | ------------ | ------------------- | ---- | ------------------------------------------------------- |
|
|
378
|
-
| visible | `boolean` | - | ✅ | 控制弹窗显示,必须使用 `v-model:visible` |
|
|
379
|
-
| shortcuts | `Shortcut[]` | `DEFAULT_SHORTCUTS` | - | 快捷指令列表,默认为内置「问问小鲸」 |
|
|
380
|
-
| maxShortcutCount | `number` | `3` | - | 直接展示的最大指令数,超出收起到「更多」菜单 |
|
|
381
|
-
| offset | `number` | `10` | - | 弹窗与选区的垂直间距(px) |
|
|
382
|
-
| excludeSelectors | `string[]` | `[]` | - | 排除的 CSS 选择器数组,选区在这些选择器内部时不显示弹窗 |
|
|
383
|
-
|
|
384
|
-
### Events
|
|
385
|
-
|
|
386
|
-
| 事件名 | 参数 | 说明 |
|
|
387
|
-
| --------------- | ------------------------------------ | --------------------------------------- |
|
|
388
|
-
| selectShortcut | `(shortcut: Shortcut, text: string)` | 点击快捷指令时触发,`text` 为选中的文本 |
|
|
389
|
-
| selectionChange | `(text: string)` | 选区文本内容发生变化时触发 |
|
|
390
|
-
|
|
391
|
-
### Slots
|
|
392
|
-
|
|
393
|
-
| 插槽名 | 参数 | 说明 |
|
|
394
|
-
| ------- | --------------------------- | ---------------------------------------------- |
|
|
395
|
-
| default | `{ shortcuts: Shortcut[] }` | 自定义弹窗内容,`shortcuts` 为完整快捷指令列表 |
|
|
396
|
-
|
|
397
|
-
## 定位逻辑
|
|
398
|
-
|
|
399
|
-
| 方向 | 规则 |
|
|
400
|
-
| -------- | ------------------------------------------------------------------------------------ |
|
|
401
|
-
| 水平方向 | 弹窗居中对齐选区,超出视口左/右边界时自动贴边(保留 8px 间距) |
|
|
402
|
-
| 垂直方向 | 优先显示在选区**上方**,上方空间不足时显示在**下方**;两侧均不足时选择空间较大的一侧 |
|
|
403
|
-
|
|
404
|
-
## 默认快捷指令
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
const DEFAULT_SHORTCUTS: Shortcut[] = [{ id: 'ai-chat', name: '问问小鲸' }];
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
## Shadow DOM 支持
|
|
411
|
-
|
|
412
|
-
组件会递归查找当前 `document.activeElement` 下的 Shadow DOM,兼容 Web Components 场景。若 Shadow DOM 中存在有效文本选区,弹窗同样会正常弹出并定位。
|
|
413
|
-
|
|
414
|
-
## 类型定义
|
|
415
|
-
|
|
416
|
-
```typescript
|
|
417
|
-
import { type Component, type VNode, h } from 'vue';
|
|
418
|
-
|
|
419
|
-
interface Shortcut {
|
|
420
|
-
id: string;
|
|
421
|
-
name: string;
|
|
422
|
-
key?: string;
|
|
423
|
-
icon?: ((c: typeof h) => Component | VNode) | string | VNode;
|
|
424
|
-
components?: ShortcutComponent[];
|
|
425
|
-
// ... 其余字段参见 ShortcutRender 文档
|
|
426
|
-
}
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
## 使用场景
|
|
430
|
-
|
|
431
|
-
- **文章阅读划词**:选中内容后弹出「问问小鲸」「翻译」「解释」等快捷入口
|
|
432
|
-
- **代码解释**:在代码区块中选中代码片段,触发「解释代码」「优化建议」等操作
|
|
433
|
-
- **文本处理**:对选中内容进行翻译、总结、改写等 AI 增强处理
|
|
434
|
-
- **与 ChatBot 联动**:选中文本后将内容作为上下文自动填入聊天输入框
|
|
435
|
-
|
|
436
|
-
## 关联组件
|
|
437
|
-
|
|
438
|
-
- [ShortcutBtn](/components/input/shortcut-btn) — 弹窗内快捷指令按钮单元
|
|
439
|
-
- [ChatInput](/components/input/chat-input) — 选区文本常回填到聊天输入框
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# AiSkillList Skill 列表
|
|
2
|
-
|
|
3
|
-
> 能力域:输入交互 | 导入:`import { AiSkillList } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
-
|
|
5
|
-
/ Skill 选择列表,供 AiSlashInput 插入 Skill 标签。 无 icon 或 icon 加载失败时展示 skill_name 首字母 fallback。 源码位置:src/components/chat-input/ai-slash-input/ai-skill-list/ai-skill-list.vue。
|
|
6
|
-
|
|
7
|
-
**关联**:ai-slash-input(输入 / 时由 AiSlashInput tippy 菜单渲染)、chat-input(经 ChatInput.skills 透传数据源)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# AiSkillList Skill 列表
|
|
12
|
-
|
|
13
|
-
> **能力域**:输入交互
|
|
14
|
-
|
|
15
|
-
## 源码事实
|
|
16
|
-
|
|
17
|
-
- **源码位置**:`src/components/chat-input/ai-slash-input/ai-skill-list/ai-skill-list.vue`
|
|
18
|
-
- **能力说明**:`/` Skill 选择列表,供 `AiSlashInput` 插入 Skill 标签;列表项固定高度且 `flex-shrink: 0`,避免滚动容器内被压缩。
|
|
19
|
-
|
|
20
|
-
## 行为说明
|
|
21
|
-
|
|
22
|
-
- 仅展示 `skill_name`,不展示 `description`
|
|
23
|
-
- 支持键盘上下选择与 Enter 确认(`useMenuKeydown`);`skills` 变化时高亮重置到首项
|
|
24
|
-
- 点击列表项调用 `onSelect(skill)`
|
|
25
|
-
- 图标规则:
|
|
26
|
-
- 有 `icon` 且未加载失败:渲染 `<img>`
|
|
27
|
-
- 无 `icon`,或 `<img>` 触发 `@error`:渲染首字母 fallback(`skill_name[0]` 大写,蓝底白字)
|
|
28
|
-
|
|
29
|
-
## API 摘要
|
|
30
|
-
|
|
31
|
-
### Props
|
|
32
|
-
|
|
33
|
-
| 属性名 | 类型 | 必填 | 说明 |
|
|
34
|
-
| -------- | ---------------------------------- | ---- | ---------------------------- |
|
|
35
|
-
| skills | `ISkillListItem[]` | ✅ | Skill 列表数据 |
|
|
36
|
-
| onSelect | `(skill: ISkillListItem) => void` | ✅ | 选中 Skill 时的回调 |
|
|
37
|
-
|
|
38
|
-
### Emits
|
|
39
|
-
|
|
40
|
-
- 无(选择通过 `onSelect` prop 回调)。
|
|
41
|
-
|
|
42
|
-
### Slots
|
|
43
|
-
|
|
44
|
-
- 无。
|
|
45
|
-
|
|
46
|
-
### Expose
|
|
47
|
-
|
|
48
|
-
- 无。
|
|
49
|
-
|
|
50
|
-
## 类型定义
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
interface ISkillListItem {
|
|
54
|
-
description: string;
|
|
55
|
-
icon: string;
|
|
56
|
-
skill_code: string;
|
|
57
|
-
skill_name: string;
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## 组件依赖
|
|
62
|
-
|
|
63
|
-
- `useMenuKeydown`(键盘导航)
|
|
64
|
-
|
|
65
|
-
## 关联组件
|
|
66
|
-
|
|
67
|
-
- [AiSlashInput](/components/input/ai-slash-input) — 输入 `/` 时渲染本列表
|
|
68
|
-
- [ChatInput](/components/input/chat-input) — 通过 `skills` prop 透传数据
|
|
69
|
-
|
|
70
|
-
## 使用建议
|
|
71
|
-
|
|
72
|
-
- 优先通过 `ChatInput` / `AiSlashInput` 使用;直接使用前确认 `skills` 结构符合 `ISkillListItem`。
|
|
73
|
-
- 上层应对已插入的 Skill 做去重过滤(`AiSlashInput` 已实现)。
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# AiSlashEditor 富文本编辑器
|
|
2
|
-
|
|
3
|
-
> 能力域:输入交互 | 导入:`import { AiSlashEditor } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
-
|
|
5
|
-
旧版富文本编辑器实现,封装 command selection 与提示菜单。 源码位置:src/components/chat-input/ai-slash-editor/ai-slash-editor.vue。
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# AiSlashEditor 富文本编辑器
|
|
10
|
-
|
|
11
|
-
> **能力域**:输入交互
|
|
12
|
-
|
|
13
|
-
## 源码事实
|
|
14
|
-
|
|
15
|
-
- **源码位置**:`src/components/chat-input/ai-slash-editor/ai-slash-editor.vue`
|
|
16
|
-
- **能力说明**:旧版富文本编辑器实现,封装 command selection 与提示菜单。
|
|
17
|
-
|
|
18
|
-
## API 摘要
|
|
19
|
-
|
|
20
|
-
### Props
|
|
21
|
-
|
|
22
|
-
- `{ disabled?: boolean; modelValue?: string; placeholder?: string; prompts?: string[]; }`
|
|
23
|
-
|
|
24
|
-
### Emits
|
|
25
|
-
|
|
26
|
-
- `{ (e: 'update:modelValue', value: string): void; (e: 'focus'): void; (e: 'keydown', event: IKeyboardEvent): void; (e: 'layoutChange', layoutInfo: monacoEditor.EditorLayoutInfo): void; }`
|
|
27
|
-
|
|
28
|
-
### Slots
|
|
29
|
-
|
|
30
|
-
- 无。
|
|
31
|
-
|
|
32
|
-
### Expose
|
|
33
|
-
|
|
34
|
-
- `{ get editor(`
|
|
35
|
-
|
|
36
|
-
## 组件依赖
|
|
37
|
-
|
|
38
|
-
- `AiPromptList`
|
|
39
|
-
- `AiSlashMenu`
|
|
40
|
-
|
|
41
|
-
## 使用建议
|
|
42
|
-
|
|
43
|
-
- 优先通过上层组合组件使用;直接使用前请确认 props 数据结构来自对应类型定义。
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# AiSlashInput 富文本命令输入
|
|
2
|
-
|
|
3
|
-
> 能力域:输入交互 | 导入:`import { AiSlashInput } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
-
|
|
5
|
-
ChatInput 内部富文本输入,支持 / Skill、\ Prompt 与 @ 资源标签。 源码位置:src/components/chat-input/ai-slash-input/ai-slash-input.vue。
|
|
6
|
-
|
|
7
|
-
**关联**:ai-skill-list(输入 / 时渲染 Skill 选择列表)、ai-prompt-list(输入 \ 时渲染 Prompt 选择列表)、ai-slash-menu(输入 @ 时渲染资源选择菜单)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# AiSlashInput 富文本命令输入
|
|
12
|
-
|
|
13
|
-
> **能力域**:输入交互
|
|
14
|
-
|
|
15
|
-
## 源码事实
|
|
16
|
-
|
|
17
|
-
- **源码位置**:`src/components/chat-input/ai-slash-input/ai-slash-input.vue`
|
|
18
|
-
- **能力说明**:ChatInput 内部富文本输入,支持 `/` Skill、`\` Prompt 与 `@` 资源标签。
|
|
19
|
-
|
|
20
|
-
## 触发字符
|
|
21
|
-
|
|
22
|
-
| 字符 | 菜单类型 | 渲染组件 | 数据源 prop |
|
|
23
|
-
| ---- | -------- | -------- | ----------- |
|
|
24
|
-
| `/` | skill | `AiSkillList` | `skills` |
|
|
25
|
-
| `\` | prompt | `AiPromptList` | `prompts` |
|
|
26
|
-
| `@` | slash | `AiSlashMenu` | `resources` |
|
|
27
|
-
|
|
28
|
-
> 输入框触达最大高度后,`.ai-slash-input-wrapper` 以 `min-height:0` 收缩并内部滚动。
|
|
29
|
-
|
|
30
|
-
## API 摘要
|
|
31
|
-
|
|
32
|
-
### Props
|
|
33
|
-
|
|
34
|
-
- `{ modelValue: string | TagSchema; placeholder?: string; prompts?: string[]; resources?: IAiSlashMenuItem[]; skills?: ISkillListItem[]; }`
|
|
35
|
-
|
|
36
|
-
### Emits
|
|
37
|
-
|
|
38
|
-
- `{ (e: 'update:modelValue', value: TagSchema, selectedResourceList: IAiSlashMenuItem[]): void; (e: 'keydown', event: KeyboardEvent & KeyboardPayload): void; (e: 'upload', files: File[]): void; }`
|
|
39
|
-
|
|
40
|
-
### Slots
|
|
41
|
-
|
|
42
|
-
- 无。
|
|
43
|
-
|
|
44
|
-
### Expose
|
|
45
|
-
|
|
46
|
-
- `{ cleanup: (`
|
|
47
|
-
|
|
48
|
-
## 组件依赖
|
|
49
|
-
|
|
50
|
-
- `AiSkillList`
|
|
51
|
-
- `AiPromptList`
|
|
52
|
-
- `AiSlashMenu`
|
|
53
|
-
|
|
54
|
-
## 使用建议
|
|
55
|
-
|
|
56
|
-
- 优先通过上层组合组件使用;直接使用前请确认 props 数据结构来自对应类型定义。
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# AiSlashMenu 资源菜单
|
|
2
|
-
|
|
3
|
-
> 能力域:输入交互 | 导入:`import { AiSlashMenu } from '@blueking/chat-x'` | since 1.0.0
|
|
4
|
-
|
|
5
|
-
@ 资源选择菜单,展示资源项供 AiSlashInput 插入标签。 源码位置:src/components/chat-input/ai-slash-input/ai-slash-menu/ai-slash-menu.vue。
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# AiSlashMenu 资源菜单
|
|
10
|
-
|
|
11
|
-
> **能力域**:输入交互
|
|
12
|
-
|
|
13
|
-
## 源码事实
|
|
14
|
-
|
|
15
|
-
- **源码位置**:`src/components/chat-input/ai-slash-input/ai-slash-menu/ai-slash-menu.vue`
|
|
16
|
-
- **能力说明**:@ 资源选择菜单,展示资源项供 AiSlashInput 插入标签。
|
|
17
|
-
|
|
18
|
-
## API 摘要
|
|
19
|
-
|
|
20
|
-
### Props
|
|
21
|
-
|
|
22
|
-
- `{ onSelect: (item: IAiSlashMenuItem) =`
|
|
23
|
-
|
|
24
|
-
### Emits
|
|
25
|
-
|
|
26
|
-
- 无。
|
|
27
|
-
|
|
28
|
-
### Slots
|
|
29
|
-
|
|
30
|
-
- 无。
|
|
31
|
-
|
|
32
|
-
### Expose
|
|
33
|
-
|
|
34
|
-
- 无。
|
|
35
|
-
|
|
36
|
-
## 组件依赖
|
|
37
|
-
|
|
38
|
-
- 无组件依赖或仅依赖基础库。
|
|
39
|
-
|
|
40
|
-
## 使用建议
|
|
41
|
-
|
|
42
|
-
- 优先通过上层组合组件使用;直接使用前请确认 props 数据结构来自对应类型定义。
|