@blueking/chat-x 0.0.51-beta.5 → 0.0.52-dev.1

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.
Files changed (198) hide show
  1. package/README.md +15 -8
  2. package/dist/ag-ui/types/contents.d.ts +2 -0
  3. package/dist/ag-ui/types/messages.d.ts +6 -1
  4. package/dist/common/constants.d.ts +2 -0
  5. package/dist/components/ai-buttons/add-menu-btn/add-menu-btn.vue.d.ts +24 -0
  6. package/dist/components/chat-content/collapsible-content/collapsible-content.vue.d.ts +28 -0
  7. package/dist/components/chat-content/file-content/upload-file-item.vue.d.ts +5 -2
  8. package/dist/components/chat-content/file-content/upload-image-item.vue.d.ts +1 -0
  9. package/dist/components/chat-content/flow-agent-content/use-flow-node-actions.d.ts +1 -1
  10. package/dist/components/chat-input/ai-slash-input/ai-slash-input.vue.d.ts +21 -10
  11. package/dist/components/chat-input/ai-slash-input/command.d.ts +6 -3
  12. package/dist/components/chat-input/ai-slash-input/constants.d.ts +2 -0
  13. package/dist/components/chat-input/ai-slash-input/use-menu-trigger.d.ts +17 -0
  14. package/dist/components/chat-input/build-default-placeholder.d.ts +9 -3
  15. package/dist/components/chat-input/chat-input.vue.d.ts +30 -18
  16. package/dist/components/chat-input/input-menu/constants.d.ts +60 -0
  17. package/dist/components/chat-input/input-menu/index.d.ts +4 -0
  18. package/dist/components/chat-input/input-menu/input-menu-option.vue.d.ts +14 -0
  19. package/dist/components/chat-input/input-menu/input-menu-panel.vue.d.ts +17 -0
  20. package/dist/components/chat-input/input-menu/use-input-menu.d.ts +22 -0
  21. package/dist/components/chat-input/model-selector/types.d.ts +3 -2
  22. package/dist/components/chat-message/message-container/message-container.vue.d.ts +1 -1
  23. package/dist/components/chat-message/user-message/user-message.vue.d.ts +1 -1
  24. package/dist/components/mention/create-mention-tippy.d.ts +27 -0
  25. package/dist/components/mention/index.d.ts +4 -0
  26. package/dist/components/{chat-input/ai-slash-input/ai-prompt-list/ai-prompt-list.vue.d.ts → mention/mention-popover.vue.d.ts} +3 -2
  27. package/dist/components/{chat-input/ai-slash-input/ai-skill-list/ai-skill-list.vue.d.ts → mention/mention-tag.vue.d.ts} +7 -3
  28. package/dist/components/{chat-input/ai-slash-input/ai-slash-menu/ai-slash-menu.vue.d.ts → mention/mention-text.vue.d.ts} +3 -3
  29. package/dist/components/resource-icon/index.d.ts +1 -0
  30. package/dist/components/resource-icon/resource-icon.vue.d.ts +11 -0
  31. package/dist/composables/index.d.ts +1 -0
  32. package/dist/composables/use-artifact-preview.d.ts +5 -2
  33. package/dist/composables/use-common.d.ts +0 -9
  34. package/dist/composables/use-global-config.d.ts +4 -0
  35. package/dist/composables/use-input-mention.d.ts +13 -0
  36. package/dist/composables/use-message-group.d.ts +1011 -72
  37. package/dist/icons/index.d.ts +1 -0
  38. package/dist/icons/input.d.ts +21 -0
  39. package/dist/icons/menu-item.d.ts +22 -0
  40. package/dist/index.css +1 -1
  41. package/dist/index.js +4953 -4429
  42. package/dist/index.js.map +1 -1
  43. package/dist/lang/lang.d.ts +13 -3
  44. package/dist/mcp/generated/docs/activity-message.md +3 -3
  45. package/dist/mcp/generated/docs/add-menu-btn.md +91 -0
  46. package/dist/mcp/generated/docs/ai-slash-input.md +72 -26
  47. package/dist/mcp/generated/docs/assistant-message.md +7 -1
  48. package/dist/mcp/generated/docs/chat-container.md +45 -6
  49. package/dist/mcp/generated/docs/chat-input.md +327 -483
  50. package/dist/mcp/generated/docs/collapsible-content.md +78 -0
  51. package/dist/mcp/generated/docs/constants.md +36 -3
  52. package/dist/mcp/generated/docs/execution-summary.md +1 -23
  53. package/dist/mcp/generated/docs/file-artifact-panel.md +24 -5
  54. package/dist/mcp/generated/docs/file-content.md +4 -0
  55. package/dist/mcp/generated/docs/file-upload-btn.md +15 -12
  56. package/dist/mcp/generated/docs/flow-agent-content.md +10 -12
  57. package/dist/mcp/generated/docs/input-menu-panel.md +166 -0
  58. package/dist/mcp/generated/docs/mention-tag.md +83 -0
  59. package/dist/mcp/generated/docs/mention-text.md +86 -0
  60. package/dist/mcp/generated/docs/message-container.md +1 -1
  61. package/dist/mcp/generated/docs/message-render.md +1 -1
  62. package/dist/mcp/generated/docs/message-tools.md +15 -4
  63. package/dist/mcp/generated/docs/messages.md +3 -0
  64. package/dist/mcp/generated/docs/model-selector.md +4 -2
  65. package/dist/mcp/generated/docs/overflow-tips.md +3 -3
  66. package/dist/mcp/generated/docs/resource-icon.md +102 -0
  67. package/dist/mcp/generated/docs/text-content.md +7 -3
  68. package/dist/mcp/generated/docs/theme.md +27 -35
  69. package/dist/mcp/generated/docs/use-artifact-preview.md +7 -3
  70. package/dist/mcp/generated/docs/use-command-selection.md +1 -1
  71. package/dist/mcp/generated/docs/use-container-scroll.md +2 -1
  72. package/dist/mcp/generated/docs/use-flow-node-actions.md +8 -15
  73. package/dist/mcp/generated/docs/use-global-config.md +11 -4
  74. package/dist/mcp/generated/docs/use-input-mention.md +119 -0
  75. package/dist/mcp/generated/docs/use-menu-keydown.md +15 -16
  76. package/dist/mcp/generated/docs/use-message-group.md +3 -6
  77. package/dist/mcp/generated/docs/user-message.md +39 -17
  78. package/dist/mcp/generated/index.json +233 -81
  79. package/dist/types/editor.d.ts +0 -29
  80. package/dist/types/index.d.ts +1 -0
  81. package/dist/types/input-menu.d.ts +46 -0
  82. package/dist/utils/artifact-tags.d.ts +36 -0
  83. package/dist/utils/collect-message-artifacts.d.ts +14 -0
  84. package/dist/utils/file.d.ts +3 -3
  85. package/dist/utils/index.d.ts +2 -1
  86. package/dist/utils/upload-file.d.ts +6 -1
  87. package/package.json +3 -2
  88. package/skills/blueking-chat-x/SKILL.md +143 -0
  89. package/skills/blueking-chat-x/references/_index.md +153 -0
  90. package/skills/blueking-chat-x/references/components/activity-layout.md +134 -0
  91. package/skills/blueking-chat-x/references/components/activity-message.md +486 -0
  92. package/skills/blueking-chat-x/references/components/add-menu-btn.md +88 -0
  93. package/skills/blueking-chat-x/references/components/ai-image.md +230 -0
  94. package/skills/blueking-chat-x/references/components/ai-loading.md +131 -0
  95. package/skills/blueking-chat-x/references/components/ai-selection.md +439 -0
  96. package/skills/blueking-chat-x/references/components/ai-slash-input.md +102 -0
  97. package/skills/blueking-chat-x/references/components/animation-text.md +202 -0
  98. package/skills/blueking-chat-x/references/components/assistant-message.md +504 -0
  99. package/skills/blueking-chat-x/references/components/chat-container.md +912 -0
  100. package/skills/blueking-chat-x/references/components/chat-input.md +614 -0
  101. package/skills/blueking-chat-x/references/components/cite-content.md +142 -0
  102. package/skills/blueking-chat-x/references/components/code-content.md +211 -0
  103. package/skills/blueking-chat-x/references/components/collapsible-content.md +76 -0
  104. package/skills/blueking-chat-x/references/components/common-error-content.md +73 -0
  105. package/skills/blueking-chat-x/references/components/content-render.md +233 -0
  106. package/skills/blueking-chat-x/references/components/delete-tool.md +191 -0
  107. package/skills/blueking-chat-x/references/components/desc-panel.md +162 -0
  108. package/skills/blueking-chat-x/references/components/detail-section.md +91 -0
  109. package/skills/blueking-chat-x/references/components/execution-summary.md +150 -0
  110. package/skills/blueking-chat-x/references/components/file-artifact-panel.md +307 -0
  111. package/skills/blueking-chat-x/references/components/file-content.md +340 -0
  112. package/skills/blueking-chat-x/references/components/file-icon.md +109 -0
  113. package/skills/blueking-chat-x/references/components/file-upload-btn.md +162 -0
  114. package/skills/blueking-chat-x/references/components/flow-agent-content.md +266 -0
  115. package/skills/blueking-chat-x/references/components/flow-agent-node-detail.md +236 -0
  116. package/skills/blueking-chat-x/references/components/highlight-keyword.md +146 -0
  117. package/skills/blueking-chat-x/references/components/image-content.md +182 -0
  118. package/skills/blueking-chat-x/references/components/image-preview-group.md +184 -0
  119. package/skills/blueking-chat-x/references/components/image-preview.md +226 -0
  120. package/skills/blueking-chat-x/references/components/info-message.md +144 -0
  121. package/skills/blueking-chat-x/references/components/input-attachment.md +49 -0
  122. package/skills/blueking-chat-x/references/components/input-info-alert.md +42 -0
  123. package/skills/blueking-chat-x/references/components/input-menu-panel.md +162 -0
  124. package/skills/blueking-chat-x/references/components/interrupt-message.md +212 -0
  125. package/skills/blueking-chat-x/references/components/key-value-content.md +128 -0
  126. package/skills/blueking-chat-x/references/components/knowledge-rag-content.md +122 -0
  127. package/skills/blueking-chat-x/references/components/latex-content.md +200 -0
  128. package/skills/blueking-chat-x/references/components/loading-message.md +192 -0
  129. package/skills/blueking-chat-x/references/components/markdown-content.md +232 -0
  130. package/skills/blueking-chat-x/references/components/mention-tag.md +79 -0
  131. package/skills/blueking-chat-x/references/components/mention-text.md +83 -0
  132. package/skills/blueking-chat-x/references/components/mermaid-content.md +189 -0
  133. package/skills/blueking-chat-x/references/components/message-container.md +645 -0
  134. package/skills/blueking-chat-x/references/components/message-loading.md +118 -0
  135. package/skills/blueking-chat-x/references/components/message-render.md +327 -0
  136. package/skills/blueking-chat-x/references/components/message-time.md +177 -0
  137. package/skills/blueking-chat-x/references/components/message-tools.md +427 -0
  138. package/skills/blueking-chat-x/references/components/model-selector.md +157 -0
  139. package/skills/blueking-chat-x/references/components/preview-toolbar.md +42 -0
  140. package/skills/blueking-chat-x/references/components/questions-container.md +85 -0
  141. package/skills/blueking-chat-x/references/components/reasoning-message.md +232 -0
  142. package/skills/blueking-chat-x/references/components/reference-content.md +135 -0
  143. package/skills/blueking-chat-x/references/components/reference-doc-content.md +109 -0
  144. package/skills/blueking-chat-x/references/components/resource-icon.md +98 -0
  145. package/skills/blueking-chat-x/references/components/scroll-btn.md +159 -0
  146. package/skills/blueking-chat-x/references/components/selection-footer.md +78 -0
  147. package/skills/blueking-chat-x/references/components/selection-question.md +88 -0
  148. package/skills/blueking-chat-x/references/components/shortcut-btn.md +204 -0
  149. package/skills/blueking-chat-x/references/components/shortcut-btns.md +266 -0
  150. package/skills/blueking-chat-x/references/components/shortcut-render.md +424 -0
  151. package/skills/blueking-chat-x/references/components/simple-table.md +101 -0
  152. package/skills/blueking-chat-x/references/components/text-content.md +80 -0
  153. package/skills/blueking-chat-x/references/components/tool-approval-card.md +183 -0
  154. package/skills/blueking-chat-x/references/components/tool-btn.md +317 -0
  155. package/skills/blueking-chat-x/references/components/tool-message.md +235 -0
  156. package/skills/blueking-chat-x/references/components/toolcall-render.md +348 -0
  157. package/skills/blueking-chat-x/references/components/user-feedback.md +233 -0
  158. package/skills/blueking-chat-x/references/components/user-message.md +444 -0
  159. package/skills/blueking-chat-x/references/components/user-question-answered-card.md +104 -0
  160. package/skills/blueking-chat-x/references/components/user-question-card.md +231 -0
  161. package/skills/blueking-chat-x/references/components/user-question-choice.md +105 -0
  162. package/skills/blueking-chat-x/references/components/user-question-option.md +42 -0
  163. package/skills/blueking-chat-x/references/components/vnode-renderer.md +122 -0
  164. package/skills/blueking-chat-x/references/composables/use-animation-text.md +196 -0
  165. package/skills/blueking-chat-x/references/composables/use-artifact-preview.md +235 -0
  166. package/skills/blueking-chat-x/references/composables/use-clipboard.md +203 -0
  167. package/skills/blueking-chat-x/references/composables/use-command-selection.md +150 -0
  168. package/skills/blueking-chat-x/references/composables/use-container-scroll.md +57 -0
  169. package/skills/blueking-chat-x/references/composables/use-custom-tab.md +158 -0
  170. package/skills/blueking-chat-x/references/composables/use-flow-node-actions.md +164 -0
  171. package/skills/blueking-chat-x/references/composables/use-full-screen.md +112 -0
  172. package/skills/blueking-chat-x/references/composables/use-global-config.md +155 -0
  173. package/skills/blueking-chat-x/references/composables/use-input-mention.md +115 -0
  174. package/skills/blueking-chat-x/references/composables/use-menu-keydown.md +161 -0
  175. package/skills/blueking-chat-x/references/composables/use-message-group.md +244 -0
  176. package/skills/blueking-chat-x/references/composables/use-observer-visible-list.md +188 -0
  177. package/skills/blueking-chat-x/references/composables/use-parent-scrolling.md +46 -0
  178. package/skills/blueking-chat-x/references/directives/index.md +61 -0
  179. package/skills/blueking-chat-x/references/directives/overflow-tips.md +205 -0
  180. package/skills/blueking-chat-x/references/icons/index.md +185 -0
  181. package/skills/blueking-chat-x/references/plugins/index.md +56 -0
  182. package/skills/blueking-chat-x/references/plugins/markdown-container.md +55 -0
  183. package/skills/blueking-chat-x/references/plugins/markdown-latex.md +205 -0
  184. package/skills/blueking-chat-x/references/plugins/markdown-mermaid.md +247 -0
  185. package/skills/blueking-chat-x/references/theme/theme.md +423 -0
  186. package/skills/blueking-chat-x/references/types/constants.md +340 -0
  187. package/skills/blueking-chat-x/references/types/index.md +120 -0
  188. package/skills/blueking-chat-x/references/types/interrupt.md +379 -0
  189. package/skills/blueking-chat-x/references/types/messages.md +556 -0
  190. package/skills/blueking-chat-x/references/types/schema.md +91 -0
  191. package/skills/blueking-chat-x/references/utils/index.md +196 -0
  192. package/skills/blueking-chat-x/scripts/generate-references.mjs +536 -0
  193. package/dist/components/chat-input/ai-slash-editor/ai-slash-editor.vue.d.ts +0 -28
  194. package/dist/components/chat-input/ai-slash-editor/theme.d.ts +0 -24
  195. package/dist/mcp/generated/docs/ai-prompt-list.md +0 -45
  196. package/dist/mcp/generated/docs/ai-skill-list.md +0 -75
  197. package/dist/mcp/generated/docs/ai-slash-editor.md +0 -43
  198. package/dist/mcp/generated/docs/ai-slash-menu.md +0 -42
@@ -0,0 +1,439 @@
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) — 选区文本常回填到聊天输入框
@@ -0,0 +1,102 @@
1
+ # AiSlashInput 富文本命令输入
2
+
3
+ > 能力域:输入交互 | 未从包入口导出:内部组件,请通过上层组件使用 | since 1.0.0
4
+
5
+ ChatInput 内部富文本编辑区,基于 edix 编辑器渲染「文本 + 资源标签」文档。 自身不渲染菜单,只把触发方式与过滤关键字通过 menuChange 抛给上层,并暴露插入 / 替换 / 关闭菜单等命令。 源码位置:src/components/chat-input/ai-slash-input/ai-slash-input.vue。
6
+
7
+ **关联**:chat-input(上层输入区,持有菜单状态并调用本组件的 expose 方法)、input-menu-panel(由 menuChange 驱动的菜单面板,选中后回调插入方法)、mention-tag(文档中的 tag 节点由 MentionTag 渲染)
8
+
9
+ ---
10
+
11
+ # AiSlashInput 富文本命令输入
12
+
13
+ > **能力域**:输入交互
14
+
15
+ ## 源码事实
16
+
17
+ - **源码位置**:`src/components/chat-input/ai-slash-input/ai-slash-input.vue`
18
+ - **能力说明**:基于 [edix](/edix/) 的 `contenteditable` 编辑区,文档结构为 `TagSchema`(二维数组:行 → 节点,节点为 `text` 或 `tag`)。
19
+ - **职责边界**:只管「编辑 + 触发态识别 + 插入」,**不渲染菜单**。菜单的数据、分组、显隐都在 [ChatInput](/components/input/chat-input) 与 [InputMenuPanel](/components/input/input-menu-panel) 中。
20
+
21
+ ## 触发状态机
22
+
23
+ 触发状态由 `use-menu-trigger.ts` 维护,对外统一为 `{ trigger, keyword }`:
24
+
25
+ | 触发方式 | 唤起时机 | 过滤关键字来源 | 选中时消费的字符 |
26
+ | -------------------- | ----------------------- | ------------------------------------------ | --------------------- |
27
+ | `/` `@` `\`(字符) | `keydown` 命中触发字符 | 触发符 → 光标之间的非空白文本 | 关键字 + 触发符 |
28
+ | `plus` | 上层调用 `openPlusMenu` | 唤起瞬间光标位置 → 当前光标之间的文本 | 仅关键字 |
29
+
30
+ - 内容或光标变化后延迟 16ms 重算触发态(等 DOM 应用本次输入),上下文失效(如光标移到触发符之前)时自动关闭。
31
+ - `plus` 唤起时若编辑器还没有文本节点(空输入框),关键字保持为空。
32
+ - 每次 `trigger` / `keyword` 变化都会 emit `menuChange`。
33
+
34
+ ## 文档与标签
35
+
36
+ 标签是 edix 的 void 节点,识别依据是 `contenteditable="false"` 且带 `data-tag-type` 属性;节点数据全部落在 DOM 属性上,因此文档可以脱离 `menuSources` 独立还原(消息回显与 hover 气泡都依赖这点):
37
+
38
+ | 节点数据 | 来源 | DOM 属性 |
39
+ | ------------- | ----------------------------- | --------------------- |
40
+ | `label` | `item.name` | `data-tag-label` |
41
+ | `value` | `item.id` | `data-tag-value` |
42
+ | `type` | `item.type` | `data-tag-type` |
43
+ | `icon` | `item.icon`(仅字符串 URL) | `data-tag-icon` |
44
+ | `description` | `item.description` | `data-tag-description` |
45
+
46
+ 序列化为纯文本时,`skill` 输出 `/<value>`,其余类型输出 `@<label>`(见 `constants.ts` 的 `tagSchemaToMessageString`)。
47
+
48
+ ## 与 modelValue 的同步
49
+
50
+ `modelValue` 支持 `string` 与 `TagSchema` 两种形态:传字符串时经 `stringToDoc` 转成文档。当 `modelValue` 由外部异步更新(历史会话回填、父组件重置、编辑态回填)且与编辑器当前内容不一致时,组件通过 `GetDocSnapshot` 读取快照并与 `docToString(modelValue)` 比对,必要时执行 `ReplaceAll` 同步,避免内外状态脱节。
51
+
52
+ ## 粘贴与换行
53
+
54
+ - 粘贴内容中包含文件时阻止默认行为并 emit `upload`,交由上层走上传流程;纯文本粘贴保持编辑器默认行为。
55
+ - `Enter` 阻止编辑器默认换行(发送与否由上层判断),`Shift + Enter` 正常换行。
56
+ - 编辑区默认保持 4 行高度,避免输入后 placeholder 消失导致高度抖动;父级触达 `max-height` 后由本组件内部滚动。
57
+
58
+ ## API
59
+
60
+ ### Props
61
+
62
+ | 属性名 | 类型 | 默认值 | 必填 | 说明 |
63
+ | ----------- | --------------------- | -------------------------- | ---- | -------------------------- |
64
+ | modelValue | `string \| TagSchema` | - | ✅ | 编辑器文档 |
65
+ | placeholder | `string` | `请输入内容` / `Please enter content` | - | 占位文案,经 `aria-placeholder` 渲染,支持 `\n` 多行 |
66
+
67
+ ### Emits
68
+
69
+ | 事件名 | 参数 | 触发时机 |
70
+ | ----------------- | ------------------------------------------------------- | ------------------------------ |
71
+ | update:modelValue | `(value: TagSchema)` | 编辑器内容变化 |
72
+ | keydown | `(event: KeyboardEvent & KeyboardPayload)` | 编辑器按键(上层据此判断发送) |
73
+ | upload | `(files: File[])` | 粘贴内容中含文件 |
74
+ | menuChange | `(payload: { keyword: string; trigger: MenuTrigger \| null })` | 触发方式或过滤关键字变化 |
75
+
76
+ ### Expose
77
+
78
+ | 方法名 | 类型 | 说明 |
79
+ | -------------------- | ---------------------------------------- | ---------------------------------------------------------------- |
80
+ | insertMenuItem | `(item: IInputMenuItem) => void` | 消费「触发符 + 关键字」后在光标处插入标签并补一个空格 |
81
+ | appendMention | `(item: IInputMenuItem) => void` | 在文档末尾追加标签(位置由文档算出,不读光标,供外部无焦点时调用) |
82
+ | replaceAll | `(value: string) => void` | 整体替换文档内容(Prompt 选中走此路径) |
83
+ | consumeTriggerText | `() => [number, number]` | 仅删除「触发符 + 关键字」,返回删除后的 `[line, column]` |
84
+ | closeMenu | `() => void` | 关闭触发态 |
85
+ | cleanup | `() => void` | 清空文档并关闭触发态(发送后调用) |
86
+ | focus | `() => void` | 聚焦编辑器并把光标置于末尾 |
87
+ | openPlusMenu | `() => void` | 唤起 `plus` 聚合菜单;光标已在编辑器内时保持原位 |
88
+
89
+ ::: tip 为什么 appendMention 不读光标
90
+ 外部调用(如文件产物面板点「引用」)时编辑器通常没有焦点,而 DOM 选区与编辑器内部选区是异步同步的,依赖光标会把标签插到错误位置,因此位置直接由文档末尾算出。
91
+ :::
92
+
93
+ ## 使用建议
94
+
95
+ 直接使用本组件需要自行实现菜单与插入调度,通常应通过 [ChatInput](/components/input/chat-input) 使用。若确需单独接入,最小闭环是:监听 `menuChange` 决定菜单显隐与数据 → 用户选中后调用 `insertMenuItem` / `replaceAll` → 发送后调用 `cleanup`。
96
+
97
+ ## 关联组件
98
+
99
+ - [ChatInput](/components/input/chat-input) — 上层输入区
100
+ - [InputMenuPanel](/components/input/input-menu-panel) — 菜单面板与分组逻辑
101
+ - [MentionTag](/components/rendering/mention-tag) — 标签渲染
102
+ - [Edix 编辑器引擎](/edix/) — 文档模型与命令机制