@opensumi/ide-ai-native 3.8.3-next-1741747748.0 → 3.8.3-next-1741752385.0
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/lib/browser/chat/chat-agent.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-agent.service.js +4 -4
- package/lib/browser/chat/chat-agent.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +2 -2
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +1 -18
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +16 -46
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/{chat-context/context-selector.d.ts → ChatContext/ContextSelector.d.ts} +1 -1
- package/lib/browser/components/ChatContext/ContextSelector.d.ts.map +1 -0
- package/lib/browser/components/{chat-context/context-selector.js → ChatContext/ContextSelector.js} +1 -1
- package/lib/browser/components/ChatContext/ContextSelector.js.map +1 -0
- package/lib/browser/components/ChatContext/index.d.ts.map +1 -0
- package/lib/browser/components/{chat-context → ChatContext}/index.js +2 -2
- package/lib/browser/components/ChatContext/index.js.map +1 -0
- package/lib/browser/components/ChatReply.d.ts.map +1 -1
- package/lib/browser/components/ChatReply.js +17 -35
- package/lib/browser/components/ChatReply.js.map +1 -1
- package/lib/browser/components/ChatThinking.js +1 -1
- package/lib/browser/components/ChatThinking.js.map +1 -1
- package/lib/browser/components/WelcomeMsg.js +1 -1
- package/lib/browser/components/WelcomeMsg.js.map +1 -1
- package/lib/browser/components/components.module.less +0 -25
- package/lib/browser/context/llm-context.service.d.ts +2 -10
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +2 -71
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/contrib/inline-completions/prompt/matcher.js +2 -2
- package/lib/browser/contrib/inline-completions/prompt/similarSnippets.d.ts +1 -1
- package/lib/browser/contrib/inline-completions/prompt/similarSnippets.js +2 -2
- package/lib/browser/contrib/intelligent-completions/view/default.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/view/default.js.map +1 -1
- package/lib/browser/mcp/config/components/mcp-config.view.d.ts.map +1 -1
- package/lib/browser/mcp/config/components/mcp-config.view.js +18 -28
- package/lib/browser/mcp/config/components/mcp-config.view.js.map +1 -1
- package/lib/browser/mcp/config/components/mcp-server-form.d.ts.map +1 -1
- package/lib/browser/mcp/config/components/mcp-server-form.js +25 -33
- package/lib/browser/mcp/config/components/mcp-server-form.js.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
- package/lib/browser/mcp/tools/components/ExpandableFileList.d.ts.map +1 -1
- package/lib/browser/mcp/tools/components/ExpandableFileList.js +1 -3
- package/lib/browser/mcp/tools/components/ExpandableFileList.js.map +1 -1
- package/lib/browser/mcp/tools/components/Terminal.d.ts.map +1 -1
- package/lib/browser/mcp/tools/components/Terminal.js +5 -6
- package/lib/browser/mcp/tools/components/Terminal.js.map +1 -1
- package/lib/browser/mcp/tools/components/index.module.less +5 -8
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +0 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
- package/lib/browser/mcp/tools/editFile.d.ts.map +1 -1
- package/lib/browser/mcp/tools/editFile.js +0 -1
- package/lib/browser/mcp/tools/editFile.js.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.js +0 -1
- package/lib/browser/mcp/tools/fileSearch.js.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.d.ts.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js +1 -2
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.d.ts.map +1 -1
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js +0 -2
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.js +0 -1
- package/lib/browser/mcp/tools/grepSearch.js.map +1 -1
- package/lib/browser/mcp/tools/listDir.d.ts.map +1 -1
- package/lib/browser/mcp/tools/listDir.js +0 -1
- package/lib/browser/mcp/tools/listDir.js.map +1 -1
- package/lib/browser/mcp/tools/readFile.d.ts.map +1 -1
- package/lib/browser/mcp/tools/readFile.js +0 -1
- package/lib/browser/mcp/tools/readFile.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.d.ts.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js +0 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/types.d.ts +0 -1
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-manager.d.ts.map +1 -1
- package/lib/browser/widget/inline-diff/inline-diff-manager.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js +5 -10
- package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
- package/lib/common/llm-context.d.ts +1 -15
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +21 -26
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js +0 -6
- package/lib/node/base-language-model.js.map +1 -1
- package/package.json +23 -24
- package/src/browser/chat/chat-agent.service.ts +4 -4
- package/src/browser/chat/chat-model.ts +2 -19
- package/src/browser/chat/chat.view.tsx +19 -47
- package/src/browser/components/{chat-context → ChatContext}/index.tsx +1 -1
- package/src/browser/components/ChatReply.tsx +18 -61
- package/src/browser/components/ChatThinking.tsx +1 -1
- package/src/browser/components/WelcomeMsg.tsx +1 -1
- package/src/browser/components/components.module.less +0 -25
- package/src/browser/context/llm-context.service.ts +3 -83
- package/src/browser/contrib/inline-completions/prompt/matcher.ts +2 -2
- package/src/browser/contrib/inline-completions/prompt/similarSnippets.ts +2 -2
- package/src/browser/contrib/intelligent-completions/view/default.ts +1 -0
- package/src/browser/mcp/config/components/mcp-config.view.tsx +12 -23
- package/src/browser/mcp/config/components/mcp-server-form.tsx +54 -68
- package/src/browser/mcp/mcp-server.feature.registry.ts +1 -1
- package/src/browser/mcp/tools/components/ExpandableFileList.tsx +1 -4
- package/src/browser/mcp/tools/components/Terminal.tsx +6 -4
- package/src/browser/mcp/tools/components/index.module.less +5 -8
- package/src/browser/mcp/tools/createNewFileWithText.ts +0 -1
- package/src/browser/mcp/tools/editFile.ts +0 -1
- package/src/browser/mcp/tools/fileSearch.ts +0 -1
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -2
- package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +0 -2
- package/src/browser/mcp/tools/grepSearch.ts +0 -1
- package/src/browser/mcp/tools/listDir.ts +0 -1
- package/src/browser/mcp/tools/readFile.ts +0 -1
- package/src/browser/mcp/tools/runTerminalCmd.ts +0 -1
- package/src/browser/types.ts +0 -1
- package/src/browser/widget/inline-diff/inline-diff-manager.tsx +1 -0
- package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +5 -9
- package/src/common/llm-context.ts +1 -16
- package/src/common/prompts/context-prompt-provider.ts +24 -31
- package/src/node/base-language-model.ts +0 -5
- package/lib/browser/components/ChatMentionInput.d.ts +0 -25
- package/lib/browser/components/ChatMentionInput.d.ts.map +0 -1
- package/lib/browser/components/ChatMentionInput.js +0 -221
- package/lib/browser/components/ChatMentionInput.js.map +0 -1
- package/lib/browser/components/chat-context/context-selector.d.ts.map +0 -1
- package/lib/browser/components/chat-context/context-selector.js.map +0 -1
- package/lib/browser/components/chat-context/index.d.ts.map +0 -1
- package/lib/browser/components/chat-context/index.js.map +0 -1
- package/lib/browser/components/mention-input/mention-input.d.ts +0 -5
- package/lib/browser/components/mention-input/mention-input.d.ts.map +0 -1
- package/lib/browser/components/mention-input/mention-input.js +0 -734
- package/lib/browser/components/mention-input/mention-input.js.map +0 -1
- package/lib/browser/components/mention-input/mention-input.module.less +0 -309
- package/lib/browser/components/mention-input/mention-item.d.ts +0 -10
- package/lib/browser/components/mention-input/mention-item.d.ts.map +0 -1
- package/lib/browser/components/mention-input/mention-item.js +0 -16
- package/lib/browser/components/mention-input/mention-item.js.map +0 -1
- package/lib/browser/components/mention-input/mention-panel.d.ts +0 -15
- package/lib/browser/components/mention-input/mention-panel.d.ts.map +0 -1
- package/lib/browser/components/mention-input/mention-panel.js +0 -49
- package/lib/browser/components/mention-input/mention-panel.js.map +0 -1
- package/lib/browser/components/mention-input/types.d.ts +0 -74
- package/lib/browser/components/mention-input/types.d.ts.map +0 -1
- package/lib/browser/components/mention-input/types.js +0 -16
- package/lib/browser/components/mention-input/types.js.map +0 -1
- package/lib/browser/mcp/tools/components/computeAnsiLogString.d.ts +0 -4
- package/lib/browser/mcp/tools/components/computeAnsiLogString.d.ts.map +0 -1
- package/lib/browser/mcp/tools/components/computeAnsiLogString.js +0 -22
- package/lib/browser/mcp/tools/components/computeAnsiLogString.js.map +0 -1
- package/lib/browser/mcp/tools/components/filterEraseMultipleLine.d.ts +0 -18
- package/lib/browser/mcp/tools/components/filterEraseMultipleLine.d.ts.map +0 -1
- package/lib/browser/mcp/tools/components/filterEraseMultipleLine.js +0 -69
- package/lib/browser/mcp/tools/components/filterEraseMultipleLine.js.map +0 -1
- package/src/browser/components/ChatMentionInput.tsx +0 -267
- package/src/browser/components/mention-input/mention-input.module.less +0 -309
- package/src/browser/components/mention-input/mention-input.tsx +0 -913
- package/src/browser/components/mention-input/mention-item.tsx +0 -24
- package/src/browser/components/mention-input/mention-panel.tsx +0 -89
- package/src/browser/components/mention-input/types.ts +0 -79
- package/src/browser/mcp/tools/components/computeAnsiLogString.ts +0 -24
- package/src/browser/mcp/tools/components/filterEraseMultipleLine.ts +0 -71
- /package/lib/browser/components/{chat-context → ChatContext}/index.d.ts +0 -0
- /package/lib/browser/components/{chat-context → ChatContext}/style.module.less +0 -0
- /package/src/browser/components/{chat-context/context-selector.tsx → ChatContext/ContextSelector.tsx} +0 -0
- /package/src/browser/components/{chat-context → ChatContext}/style.module.less +0 -0
|
@@ -1,734 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MentionInput = exports.WHITE_SPACE_TEXT = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
6
|
-
const React = tslib_1.__importStar(require("react"));
|
|
7
|
-
const components_1 = require("@opensumi/ide-core-browser/lib/components");
|
|
8
|
-
const ai_native_1 = require("@opensumi/ide-core-browser/lib/components/ai-native");
|
|
9
|
-
const mention_input_module_less_1 = tslib_1.__importDefault(require("./mention-input.module.less"));
|
|
10
|
-
const mention_panel_1 = require("./mention-panel");
|
|
11
|
-
const types_1 = require("./types");
|
|
12
|
-
exports.WHITE_SPACE_TEXT = ' ';
|
|
13
|
-
const MentionInput = ({ mentionItems = [], onSend, onStop, loading = false, mentionKeyword = types_1.MENTION_KEYWORD, onSelectionChange, placeholder = 'Ask anything, @ to mention', footerConfig = {
|
|
14
|
-
buttons: [],
|
|
15
|
-
showModelSelector: false,
|
|
16
|
-
}, }) => {
|
|
17
|
-
const editorRef = React.useRef(null);
|
|
18
|
-
const [mentionState, setMentionState] = React.useState({
|
|
19
|
-
active: false,
|
|
20
|
-
startPos: null,
|
|
21
|
-
filter: '',
|
|
22
|
-
position: { top: 0, left: 0 },
|
|
23
|
-
activeIndex: 0,
|
|
24
|
-
level: 0, // 0: 一级菜单, 1: 二级菜单
|
|
25
|
-
parentType: null, // 二级菜单的父类型
|
|
26
|
-
secondLevelFilter: '', // 二级菜单的筛选文本
|
|
27
|
-
inlineSearchActive: false, // 是否在输入框中进行二级搜索
|
|
28
|
-
inlineSearchStartPos: null, // 内联搜索的起始位置
|
|
29
|
-
loading: false, // 添加加载状态
|
|
30
|
-
});
|
|
31
|
-
// 添加模型选择状态
|
|
32
|
-
const [selectedModel, setSelectedModel] = React.useState(footerConfig.defaultModel || '');
|
|
33
|
-
// 添加缓存状态,用于存储二级菜单项
|
|
34
|
-
const [secondLevelCache, setSecondLevelCache] = React.useState({});
|
|
35
|
-
// 添加历史记录状态
|
|
36
|
-
const [history, setHistory] = React.useState([]);
|
|
37
|
-
const [historyIndex, setHistoryIndex] = React.useState(-1);
|
|
38
|
-
const [currentInput, setCurrentInput] = React.useState('');
|
|
39
|
-
const [isNavigatingHistory, setIsNavigatingHistory] = React.useState(false);
|
|
40
|
-
// 获取当前菜单项
|
|
41
|
-
const getCurrentItems = () => {
|
|
42
|
-
if (mentionState.level === 0) {
|
|
43
|
-
return mentionItems;
|
|
44
|
-
}
|
|
45
|
-
else if (mentionState.parentType) {
|
|
46
|
-
// 如果正在加载,返回缓存的项目
|
|
47
|
-
if (mentionState.loading) {
|
|
48
|
-
return secondLevelCache[mentionState.parentType] || [];
|
|
49
|
-
}
|
|
50
|
-
// 返回缓存的项目
|
|
51
|
-
return secondLevelCache[mentionState.parentType] || [];
|
|
52
|
-
}
|
|
53
|
-
return [];
|
|
54
|
-
};
|
|
55
|
-
// 添加防抖函数
|
|
56
|
-
const useDebounce = (value, delay) => {
|
|
57
|
-
const [debouncedValue, setDebouncedValue] = React.useState(value);
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
const handler = setTimeout(() => {
|
|
60
|
-
setDebouncedValue(value);
|
|
61
|
-
}, delay);
|
|
62
|
-
return () => {
|
|
63
|
-
clearTimeout(handler);
|
|
64
|
-
};
|
|
65
|
-
}, [value, delay]);
|
|
66
|
-
return debouncedValue;
|
|
67
|
-
};
|
|
68
|
-
// 使用防抖处理搜索文本
|
|
69
|
-
const debouncedSecondLevelFilter = useDebounce(mentionState.secondLevelFilter, 300);
|
|
70
|
-
// 监听搜索文本变化,实时更新二级菜单
|
|
71
|
-
React.useEffect(() => {
|
|
72
|
-
if (mentionState.level === 1 && mentionState.parentType && debouncedSecondLevelFilter !== undefined) {
|
|
73
|
-
// 查找父级菜单项
|
|
74
|
-
const parentItem = mentionItems.find((item) => item.id === mentionState.parentType);
|
|
75
|
-
if (!parentItem) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// 设置加载状态
|
|
79
|
-
setMentionState((prev) => ({ ...prev, loading: true }));
|
|
80
|
-
// 异步加载
|
|
81
|
-
const fetchItems = async () => {
|
|
82
|
-
try {
|
|
83
|
-
// 首先显示高优先级项目(如果有)
|
|
84
|
-
const items = [];
|
|
85
|
-
if (parentItem.getHighestLevelItems) {
|
|
86
|
-
const highestLevelItems = parentItem.getHighestLevelItems();
|
|
87
|
-
for (const item of highestLevelItems) {
|
|
88
|
-
if (!items.some((i) => i.id === item.id)) {
|
|
89
|
-
items.push(item);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// 立即更新缓存,显示高优先级项目
|
|
93
|
-
setSecondLevelCache((prev) => ({
|
|
94
|
-
...prev,
|
|
95
|
-
[mentionState.parentType]: highestLevelItems,
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
// 然后异步加载更多项目
|
|
99
|
-
if (parentItem.getItems) {
|
|
100
|
-
try {
|
|
101
|
-
// 获取子菜单项
|
|
102
|
-
const newItems = await parentItem.getItems(debouncedSecondLevelFilter);
|
|
103
|
-
// 去重合并
|
|
104
|
-
const combinedItems = [...items];
|
|
105
|
-
for (const item of newItems) {
|
|
106
|
-
if (!combinedItems.some((i) => i.id === item.id)) {
|
|
107
|
-
combinedItems.push(item);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// 更新缓存
|
|
111
|
-
setSecondLevelCache((prev) => ({
|
|
112
|
-
...prev,
|
|
113
|
-
[mentionState.parentType]: combinedItems,
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
// 如果异步加载失败,至少保留高优先级项目
|
|
118
|
-
setMentionState((prev) => ({ ...prev, loading: false }));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// 最后清除加载状态
|
|
122
|
-
setMentionState((prev) => ({ ...prev, loading: false }));
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
setMentionState((prev) => ({ ...prev, loading: false }));
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
fetchItems();
|
|
129
|
-
}
|
|
130
|
-
}, [debouncedSecondLevelFilter, mentionState.level, mentionState.parentType]);
|
|
131
|
-
// 获取光标位置
|
|
132
|
-
const getCursorPosition = (element) => {
|
|
133
|
-
const selection = window.getSelection();
|
|
134
|
-
if (!selection || !selection.rangeCount) {
|
|
135
|
-
return 0;
|
|
136
|
-
}
|
|
137
|
-
const range = selection.getRangeAt(0);
|
|
138
|
-
const preCaretRange = range.cloneRange();
|
|
139
|
-
preCaretRange.selectNodeContents(element);
|
|
140
|
-
preCaretRange.setEnd(range.endContainer, range.endOffset);
|
|
141
|
-
return preCaretRange.toString().length;
|
|
142
|
-
};
|
|
143
|
-
// 处理输入事件
|
|
144
|
-
const handleInput = () => {
|
|
145
|
-
// 如果用户开始输入,退出历史导航模式
|
|
146
|
-
if (isNavigatingHistory) {
|
|
147
|
-
setIsNavigatingHistory(false);
|
|
148
|
-
setHistoryIndex(-1);
|
|
149
|
-
}
|
|
150
|
-
const selection = window.getSelection();
|
|
151
|
-
if (!selection || !selection.rangeCount || !editorRef.current) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const text = editorRef.current.textContent || '';
|
|
155
|
-
const cursorPos = getCursorPosition(editorRef.current);
|
|
156
|
-
// 判断是否刚输入了 @
|
|
157
|
-
if (text[cursorPos - 1] === mentionKeyword && !mentionState.active && !mentionState.inlineSearchActive) {
|
|
158
|
-
setMentionState({
|
|
159
|
-
active: true,
|
|
160
|
-
startPos: cursorPos,
|
|
161
|
-
filter: mentionKeyword,
|
|
162
|
-
position: { top: 0, left: 0 }, // 固定位置,不再需要动态计算
|
|
163
|
-
activeIndex: 0,
|
|
164
|
-
level: 0,
|
|
165
|
-
parentType: null,
|
|
166
|
-
secondLevelFilter: '',
|
|
167
|
-
inlineSearchActive: false,
|
|
168
|
-
inlineSearchStartPos: null,
|
|
169
|
-
loading: false,
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
// 如果已激活提及面板且在一级菜单,更新过滤内容
|
|
173
|
-
if (mentionState.active && mentionState.level === 0 && mentionState.startPos !== null) {
|
|
174
|
-
if (cursorPos < mentionState.startPos) {
|
|
175
|
-
// 如果光标移到了 @ 之前,关闭面板
|
|
176
|
-
setMentionState((prev) => ({ ...prev, active: false }));
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
const newFilter = text.substring(mentionState.startPos - 1, cursorPos);
|
|
180
|
-
setMentionState((prev) => ({
|
|
181
|
-
...prev,
|
|
182
|
-
filter: newFilter,
|
|
183
|
-
activeIndex: 0,
|
|
184
|
-
}));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// 如果在输入框中进行二级搜索
|
|
188
|
-
if (mentionState.inlineSearchActive && mentionState.inlineSearchStartPos !== null && mentionState.parentType) {
|
|
189
|
-
// 获取父级类型
|
|
190
|
-
const parentItem = mentionItems.find((i) => i.id === mentionState.parentType);
|
|
191
|
-
if (!parentItem) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
// 检查光标是否在 @type: 之后
|
|
195
|
-
const typePrefix = `@${parentItem.type}:`;
|
|
196
|
-
const prefixPos = mentionState.inlineSearchStartPos - typePrefix.length;
|
|
197
|
-
if (prefixPos >= 0 && cursorPos > prefixPos + typePrefix.length) {
|
|
198
|
-
// 提取搜索文本
|
|
199
|
-
const searchText = text.substring(prefixPos + typePrefix.length, cursorPos);
|
|
200
|
-
// 只有当搜索文本变化时才更新状态
|
|
201
|
-
if (searchText !== mentionState.secondLevelFilter) {
|
|
202
|
-
setMentionState((prev) => ({
|
|
203
|
-
...prev,
|
|
204
|
-
secondLevelFilter: searchText,
|
|
205
|
-
active: true,
|
|
206
|
-
activeIndex: 0,
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else if (cursorPos <= prefixPos) {
|
|
211
|
-
// 如果光标移到了 @type: 之前,关闭内联搜索
|
|
212
|
-
setMentionState((prev) => ({
|
|
213
|
-
...prev,
|
|
214
|
-
inlineSearchActive: false,
|
|
215
|
-
active: false,
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// 检查输入框高度,如果超过最大高度则添加滚动条
|
|
220
|
-
if (editorRef.current) {
|
|
221
|
-
const editorHeight = editorRef.current.scrollHeight;
|
|
222
|
-
if (editorHeight > 120) {
|
|
223
|
-
editorRef.current.style.overflowY = 'auto';
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
editorRef.current.style.overflowY = 'hidden';
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
// 检查编辑器内容,处理只有 <br> 标签的情况
|
|
230
|
-
if (editorRef.current) {
|
|
231
|
-
const content = editorRef.current.innerHTML;
|
|
232
|
-
// 如果内容为空或只有 <br> 标签
|
|
233
|
-
if (content === '' || content === '<br>' || content === '<br/>') {
|
|
234
|
-
// 清空编辑器内容
|
|
235
|
-
editorRef.current.innerHTML = '';
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
// 处理键盘事件
|
|
240
|
-
const handleKeyDown = (e) => {
|
|
241
|
-
// 如果按下ESC键且提及面板处于活动状态或内联搜索处于活动状态
|
|
242
|
-
if (e.key === 'Escape' && (mentionState.active || mentionState.inlineSearchActive)) {
|
|
243
|
-
// 如果在二级菜单,返回一级菜单
|
|
244
|
-
if (mentionState.level > 0) {
|
|
245
|
-
setMentionState((prev) => ({
|
|
246
|
-
...prev,
|
|
247
|
-
level: 0,
|
|
248
|
-
activeIndex: 0,
|
|
249
|
-
secondLevelFilter: '',
|
|
250
|
-
inlineSearchActive: false,
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
// 如果在一级菜单,完全关闭面板
|
|
255
|
-
setMentionState((prev) => ({
|
|
256
|
-
...prev,
|
|
257
|
-
active: false,
|
|
258
|
-
inlineSearchActive: false,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
e.preventDefault();
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
// 添加对 @ 键的监听,支持在任意位置触发菜单
|
|
265
|
-
if (e.key === types_1.MENTION_KEYWORD && !mentionState.active && !mentionState.inlineSearchActive && editorRef.current) {
|
|
266
|
-
const cursorPos = getCursorPosition(editorRef.current);
|
|
267
|
-
// 立即设置菜单状态,不等待 handleInput
|
|
268
|
-
setMentionState({
|
|
269
|
-
active: true,
|
|
270
|
-
startPos: cursorPos + 1, // +1 因为 @ 还没有被插入
|
|
271
|
-
filter: mentionKeyword,
|
|
272
|
-
position: { top: 0, left: 0 }, // 固定位置
|
|
273
|
-
activeIndex: 0,
|
|
274
|
-
level: 0,
|
|
275
|
-
parentType: null,
|
|
276
|
-
secondLevelFilter: '',
|
|
277
|
-
inlineSearchActive: false,
|
|
278
|
-
inlineSearchStartPos: null,
|
|
279
|
-
loading: false,
|
|
280
|
-
});
|
|
281
|
-
// 不要阻止默认行为,让 @ 正常输入到编辑器中
|
|
282
|
-
}
|
|
283
|
-
// 添加对 Enter 键的处理,只有在按下 Shift+Enter 时才允许换行
|
|
284
|
-
if (e.key === 'Enter') {
|
|
285
|
-
// 检查是否是输入法的回车键
|
|
286
|
-
// isComposing 属性表示是否正在进行输入法组合输入
|
|
287
|
-
if (e.nativeEvent.isComposing) {
|
|
288
|
-
return; // 如果是输入法组合输入过程中的回车,不做任何处理
|
|
289
|
-
}
|
|
290
|
-
if (!e.shiftKey) {
|
|
291
|
-
e.preventDefault();
|
|
292
|
-
if (!mentionState.active) {
|
|
293
|
-
handleSend();
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
// 处理上下方向键导航历史记录
|
|
299
|
-
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
300
|
-
// 只有在非提及面板激活状态下才处理历史导航
|
|
301
|
-
if (!mentionState.active && !mentionState.inlineSearchActive && editorRef.current) {
|
|
302
|
-
e.preventDefault();
|
|
303
|
-
// 如果是第一次按上下键,保存当前输入
|
|
304
|
-
if (!isNavigatingHistory) {
|
|
305
|
-
setCurrentInput(editorRef.current.innerHTML);
|
|
306
|
-
setIsNavigatingHistory(true);
|
|
307
|
-
}
|
|
308
|
-
// 计算新的历史索引
|
|
309
|
-
let newIndex = historyIndex;
|
|
310
|
-
if (e.key === 'ArrowUp') {
|
|
311
|
-
// 向上导航到较早的历史记录
|
|
312
|
-
newIndex = Math.min(history.length - 1, historyIndex + 1);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
// 向下导航到较新的历史记录
|
|
316
|
-
newIndex = Math.max(-1, historyIndex - 1);
|
|
317
|
-
}
|
|
318
|
-
setHistoryIndex(newIndex);
|
|
319
|
-
// 更新编辑器内容
|
|
320
|
-
if (newIndex === -1) {
|
|
321
|
-
// 恢复到当前输入
|
|
322
|
-
editorRef.current.innerHTML = currentInput;
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
// 显示历史记录
|
|
326
|
-
editorRef.current.innerHTML = history[history.length - 1 - newIndex];
|
|
327
|
-
}
|
|
328
|
-
// 将光标移到末尾
|
|
329
|
-
const range = document.createRange();
|
|
330
|
-
range.selectNodeContents(editorRef.current);
|
|
331
|
-
range.collapse(false);
|
|
332
|
-
const selection = window.getSelection();
|
|
333
|
-
if (selection) {
|
|
334
|
-
selection.removeAllRanges();
|
|
335
|
-
selection.addRange(range);
|
|
336
|
-
}
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
else if (isNavigatingHistory && e.key !== 'ArrowUp' && e.key !== 'ArrowDown') {
|
|
341
|
-
// 如果用户在浏览历史记录后开始输入,退出历史导航模式
|
|
342
|
-
setIsNavigatingHistory(false);
|
|
343
|
-
setHistoryIndex(-1);
|
|
344
|
-
}
|
|
345
|
-
// 如果提及面板未激活,不处理其他键盘事件
|
|
346
|
-
if (!mentionState.active) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
// 获取当前过滤后的项目
|
|
350
|
-
let filteredItems = getCurrentItems();
|
|
351
|
-
// 一级菜单过滤
|
|
352
|
-
if (mentionState.level === 0 && mentionState.filter && mentionState.filter.length > 1) {
|
|
353
|
-
const searchText = mentionState.filter.substring(1).toLowerCase();
|
|
354
|
-
filteredItems = filteredItems.filter((item) => item.text.toLowerCase().includes(searchText));
|
|
355
|
-
}
|
|
356
|
-
// 二级菜单过滤已经在 getCurrentItems 中处理
|
|
357
|
-
if (filteredItems.length === 0) {
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (e.key === 'ArrowDown') {
|
|
361
|
-
// 向下导航
|
|
362
|
-
setMentionState((prev) => ({
|
|
363
|
-
...prev,
|
|
364
|
-
activeIndex: (prev.activeIndex + 1) % filteredItems.length,
|
|
365
|
-
}));
|
|
366
|
-
e.preventDefault();
|
|
367
|
-
}
|
|
368
|
-
else if (e.key === 'ArrowUp') {
|
|
369
|
-
// 向上导航
|
|
370
|
-
setMentionState((prev) => ({
|
|
371
|
-
...prev,
|
|
372
|
-
activeIndex: (prev.activeIndex - 1 + filteredItems.length) % filteredItems.length,
|
|
373
|
-
}));
|
|
374
|
-
e.preventDefault();
|
|
375
|
-
}
|
|
376
|
-
else if (e.key === 'Enter' || e.key === 'Tab') {
|
|
377
|
-
// 确认选择
|
|
378
|
-
if (filteredItems.length > 0) {
|
|
379
|
-
handleSelectItem(filteredItems[mentionState.activeIndex]);
|
|
380
|
-
e.preventDefault();
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
// 处理 Backspace 键,检查是否需要清空编辑器
|
|
384
|
-
if (e.key === 'Backspace' && editorRef.current) {
|
|
385
|
-
const content = editorRef.current.innerHTML;
|
|
386
|
-
if (content === '<br>' || content === '<br/>') {
|
|
387
|
-
editorRef.current.innerHTML = '';
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
// 添加对输入法事件的处理
|
|
392
|
-
const handleCompositionEnd = () => {
|
|
393
|
-
// 输入法输入完成后的处理
|
|
394
|
-
// 这里可以添加额外的逻辑,如果需要的话
|
|
395
|
-
};
|
|
396
|
-
// 初始化编辑器
|
|
397
|
-
React.useEffect(() => {
|
|
398
|
-
if (editorRef.current) {
|
|
399
|
-
// 设置初始占位符
|
|
400
|
-
if (placeholder && !editorRef.current.textContent) {
|
|
401
|
-
editorRef.current.setAttribute('data-placeholder', placeholder);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
}, [placeholder]);
|
|
405
|
-
// 处理点击事件
|
|
406
|
-
const handleDocumentClick = (e) => {
|
|
407
|
-
var _a;
|
|
408
|
-
if (mentionState.active && !((_a = document.querySelector(`.${mention_input_module_less_1.default.mention_panel}`)) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
409
|
-
setMentionState((prev) => ({
|
|
410
|
-
...prev,
|
|
411
|
-
active: false,
|
|
412
|
-
inlineSearchActive: false,
|
|
413
|
-
}));
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
// 添加和移除全局点击事件监听器
|
|
417
|
-
React.useEffect(() => {
|
|
418
|
-
document.addEventListener('click', handleDocumentClick, true);
|
|
419
|
-
return () => {
|
|
420
|
-
document.removeEventListener('click', handleDocumentClick, true);
|
|
421
|
-
};
|
|
422
|
-
}, [mentionState.active]);
|
|
423
|
-
// 选择提及项目
|
|
424
|
-
const handleSelectItem = (item, isTriggerByClick = false) => {
|
|
425
|
-
var _a;
|
|
426
|
-
if (!editorRef.current) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
// 如果项目有子菜单,进入二级菜单
|
|
430
|
-
if (item.getItems) {
|
|
431
|
-
const selection = window.getSelection();
|
|
432
|
-
if (!selection || !selection.rangeCount) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
// 如果是从一级菜单选择了带子菜单的项目
|
|
436
|
-
if (mentionState.level === 0 && mentionState.startPos !== null) {
|
|
437
|
-
// 更安全地处理文本替换
|
|
438
|
-
let textNode;
|
|
439
|
-
let startOffset;
|
|
440
|
-
let endOffset;
|
|
441
|
-
// 找到包含 @ 符号的文本节点
|
|
442
|
-
const walker = document.createTreeWalker(editorRef.current, NodeFilter.SHOW_TEXT);
|
|
443
|
-
let charCount = 0;
|
|
444
|
-
let node;
|
|
445
|
-
while ((node = walker.nextNode())) {
|
|
446
|
-
const nodeLength = ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
447
|
-
// 检查 @ 符号是否在这个节点中
|
|
448
|
-
if (mentionState.startPos - 1 >= charCount && mentionState.startPos - 1 < charCount + nodeLength) {
|
|
449
|
-
textNode = node;
|
|
450
|
-
startOffset = mentionState.startPos - 1 - charCount;
|
|
451
|
-
// 确保不会超出节点范围
|
|
452
|
-
const cursorPos = isTriggerByClick
|
|
453
|
-
? mentionState.startPos + mentionState.filter.length - 1
|
|
454
|
-
: getCursorPosition(editorRef.current);
|
|
455
|
-
endOffset = Math.min(cursorPos - charCount, nodeLength);
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
charCount += nodeLength;
|
|
459
|
-
}
|
|
460
|
-
if (textNode) {
|
|
461
|
-
// 创建一个新的范围来替换文本
|
|
462
|
-
const tempRange = document.createRange();
|
|
463
|
-
tempRange.setStart(textNode, startOffset);
|
|
464
|
-
tempRange.setEnd(textNode, endOffset);
|
|
465
|
-
// 替换为 @type:
|
|
466
|
-
tempRange.deleteContents();
|
|
467
|
-
const typePrefix = document.createTextNode(`${mentionKeyword}${item.type}:`);
|
|
468
|
-
tempRange.insertNode(typePrefix);
|
|
469
|
-
// 将光标移到 @type: 后面
|
|
470
|
-
const newRange = document.createRange();
|
|
471
|
-
newRange.setStartAfter(typePrefix);
|
|
472
|
-
newRange.setEndAfter(typePrefix);
|
|
473
|
-
selection.removeAllRanges();
|
|
474
|
-
selection.addRange(newRange);
|
|
475
|
-
// 激活内联搜索模式
|
|
476
|
-
setMentionState((prev) => ({
|
|
477
|
-
...prev,
|
|
478
|
-
active: true,
|
|
479
|
-
level: 1,
|
|
480
|
-
parentType: item.id,
|
|
481
|
-
inlineSearchActive: true,
|
|
482
|
-
inlineSearchStartPos: getCursorPosition(editorRef.current),
|
|
483
|
-
secondLevelFilter: '',
|
|
484
|
-
activeIndex: 0,
|
|
485
|
-
}));
|
|
486
|
-
editorRef.current.focus();
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
const selection = window.getSelection();
|
|
493
|
-
if (!selection || !selection.rangeCount) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
// 如果是在内联搜索模式下选择项目
|
|
497
|
-
if (mentionState.inlineSearchActive && mentionState.parentType && mentionState.inlineSearchStartPos !== null) {
|
|
498
|
-
// 找到 @type: 的位置
|
|
499
|
-
const parentItem = mentionItems.find((i) => i.id === mentionState.parentType);
|
|
500
|
-
if (!parentItem) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
const typePrefix = `${mentionKeyword}${parentItem.type}:`;
|
|
504
|
-
const prefixPos = mentionState.inlineSearchStartPos - typePrefix.length;
|
|
505
|
-
if (prefixPos >= 0) {
|
|
506
|
-
// 创建一个带样式的提及标签
|
|
507
|
-
const mentionTag = document.createElement('span');
|
|
508
|
-
mentionTag.className = mention_input_module_less_1.default.mention_tag;
|
|
509
|
-
mentionTag.dataset.id = item.id;
|
|
510
|
-
mentionTag.dataset.type = item.type;
|
|
511
|
-
mentionTag.dataset.contextId = item.contextId || '';
|
|
512
|
-
mentionTag.contentEditable = 'false';
|
|
513
|
-
mentionTag.textContent = mentionKeyword + item.text;
|
|
514
|
-
// 创建一个范围从 @type: 开始到当前光标
|
|
515
|
-
const tempRange = document.createRange();
|
|
516
|
-
// 定位到 @type: 的位置
|
|
517
|
-
let charIndex = 0;
|
|
518
|
-
let foundStart = false;
|
|
519
|
-
const textNodes = [];
|
|
520
|
-
function findPosition(node) {
|
|
521
|
-
if (node.nodeType === 3) {
|
|
522
|
-
// 文本节点
|
|
523
|
-
textNodes.push({
|
|
524
|
-
node,
|
|
525
|
-
start: charIndex,
|
|
526
|
-
end: charIndex + node.textContent.length,
|
|
527
|
-
});
|
|
528
|
-
charIndex += node.textContent.length;
|
|
529
|
-
}
|
|
530
|
-
else if (node.nodeType === 1) {
|
|
531
|
-
// 元素节点
|
|
532
|
-
const children = node.childNodes || [];
|
|
533
|
-
for (const child of Array.from(children)) {
|
|
534
|
-
findPosition(child);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
findPosition(editorRef.current);
|
|
539
|
-
for (const textNode of textNodes) {
|
|
540
|
-
if (prefixPos >= textNode.start && prefixPos <= textNode.end) {
|
|
541
|
-
const startOffset = prefixPos - textNode.start;
|
|
542
|
-
tempRange.setStart(textNode.node, startOffset);
|
|
543
|
-
foundStart = true;
|
|
544
|
-
}
|
|
545
|
-
if (foundStart) {
|
|
546
|
-
// 如果是点击触发,使用过滤文本的长度来确定结束位置
|
|
547
|
-
const cursorPos = isTriggerByClick
|
|
548
|
-
? prefixPos + typePrefix.length + mentionState.secondLevelFilter.length
|
|
549
|
-
: getCursorPosition(editorRef.current);
|
|
550
|
-
if (cursorPos >= textNode.start && cursorPos <= textNode.end) {
|
|
551
|
-
const endOffset = cursorPos - textNode.start;
|
|
552
|
-
tempRange.setEnd(textNode.node, endOffset);
|
|
553
|
-
break;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (foundStart) {
|
|
558
|
-
tempRange.deleteContents();
|
|
559
|
-
tempRange.insertNode(mentionTag);
|
|
560
|
-
// 将光标移到提及标签后面
|
|
561
|
-
const newRange = document.createRange();
|
|
562
|
-
newRange.setStartAfter(mentionTag);
|
|
563
|
-
newRange.setEndAfter(mentionTag);
|
|
564
|
-
selection.removeAllRanges();
|
|
565
|
-
selection.addRange(newRange);
|
|
566
|
-
// 添加一个空格,增加间隔
|
|
567
|
-
const spaceNode = document.createTextNode('\u00A0'); // 使用不间断空格
|
|
568
|
-
newRange.insertNode(spaceNode);
|
|
569
|
-
newRange.setStartAfter(spaceNode);
|
|
570
|
-
newRange.setEndAfter(spaceNode);
|
|
571
|
-
selection.removeAllRanges();
|
|
572
|
-
selection.addRange(newRange);
|
|
573
|
-
}
|
|
574
|
-
setMentionState((prev) => ({
|
|
575
|
-
...prev,
|
|
576
|
-
active: false,
|
|
577
|
-
inlineSearchActive: false,
|
|
578
|
-
}));
|
|
579
|
-
editorRef.current.focus();
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
// 原有的处理逻辑(用于非内联搜索情况)
|
|
584
|
-
// 创建一个带样式的提及标签
|
|
585
|
-
const mentionTag = document.createElement('span');
|
|
586
|
-
mentionTag.className = mention_input_module_less_1.default.mention_tag;
|
|
587
|
-
mentionTag.dataset.id = item.id;
|
|
588
|
-
mentionTag.dataset.type = item.type;
|
|
589
|
-
mentionTag.dataset.contextId = item.contextId || '';
|
|
590
|
-
mentionTag.contentEditable = 'false';
|
|
591
|
-
mentionTag.textContent = mentionKeyword + item.text;
|
|
592
|
-
// 定位到 @ 符号的位置
|
|
593
|
-
let charIndex = 0;
|
|
594
|
-
let foundStart = false;
|
|
595
|
-
const textNodes = [];
|
|
596
|
-
function findPosition(node) {
|
|
597
|
-
if (node.nodeType === 3) {
|
|
598
|
-
// 文本节点
|
|
599
|
-
textNodes.push({
|
|
600
|
-
node,
|
|
601
|
-
start: charIndex,
|
|
602
|
-
end: charIndex + node.textContent.length,
|
|
603
|
-
});
|
|
604
|
-
charIndex += node.textContent.length;
|
|
605
|
-
}
|
|
606
|
-
else if (node.nodeType === 1) {
|
|
607
|
-
// 元素节点
|
|
608
|
-
const children = node.childNodes;
|
|
609
|
-
for (const child of Array.from(children)) {
|
|
610
|
-
findPosition(child);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
findPosition(editorRef.current);
|
|
615
|
-
const tempRange = document.createRange();
|
|
616
|
-
if (mentionState.startPos !== null) {
|
|
617
|
-
for (const textNode of textNodes) {
|
|
618
|
-
if (mentionState.startPos - 1 >= textNode.start && mentionState.startPos - 1 <= textNode.end) {
|
|
619
|
-
const startOffset = mentionState.startPos - 1 - textNode.start;
|
|
620
|
-
tempRange.setStart(textNode.node, startOffset);
|
|
621
|
-
foundStart = true;
|
|
622
|
-
}
|
|
623
|
-
if (foundStart) {
|
|
624
|
-
// 如果是点击触发,使用过滤文本的长度来确定结束位置
|
|
625
|
-
const cursorPos = isTriggerByClick
|
|
626
|
-
? mentionState.startPos + mentionState.filter.length - 1
|
|
627
|
-
: getCursorPosition(editorRef.current);
|
|
628
|
-
if (cursorPos >= textNode.start && cursorPos <= textNode.end) {
|
|
629
|
-
const endOffset = cursorPos - textNode.start;
|
|
630
|
-
tempRange.setEnd(textNode.node, endOffset);
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
if (foundStart) {
|
|
637
|
-
tempRange.deleteContents();
|
|
638
|
-
tempRange.insertNode(mentionTag);
|
|
639
|
-
// 将光标移到提及标签后面
|
|
640
|
-
const newRange = document.createRange();
|
|
641
|
-
newRange.setStartAfter(mentionTag);
|
|
642
|
-
newRange.setEndAfter(mentionTag);
|
|
643
|
-
selection.removeAllRanges();
|
|
644
|
-
selection.addRange(newRange);
|
|
645
|
-
// 添加一个空格,增加间隔
|
|
646
|
-
const spaceNode = document.createTextNode('\u00A0'); // 使用不间断空格
|
|
647
|
-
newRange.insertNode(spaceNode);
|
|
648
|
-
newRange.setStartAfter(spaceNode);
|
|
649
|
-
newRange.setEndAfter(spaceNode);
|
|
650
|
-
selection.removeAllRanges();
|
|
651
|
-
selection.addRange(newRange);
|
|
652
|
-
}
|
|
653
|
-
setMentionState((prev) => ({ ...prev, active: false }));
|
|
654
|
-
editorRef.current.focus();
|
|
655
|
-
};
|
|
656
|
-
// 处理模型选择变更
|
|
657
|
-
const handleModelChange = React.useCallback((value) => {
|
|
658
|
-
setSelectedModel(value);
|
|
659
|
-
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(value);
|
|
660
|
-
}, [selectedModel, onSelectionChange]);
|
|
661
|
-
// 修改 handleSend 函数
|
|
662
|
-
const handleSend = () => {
|
|
663
|
-
if (!editorRef.current) {
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
// 获取原始HTML内容
|
|
667
|
-
const rawContent = editorRef.current.innerHTML;
|
|
668
|
-
if (!rawContent) {
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
// 创建一个临时元素来处理内容
|
|
672
|
-
const tempDiv = document.createElement('div');
|
|
673
|
-
tempDiv.innerHTML = rawContent;
|
|
674
|
-
// 查找所有提及标签并替换为对应的contextId
|
|
675
|
-
const mentionTags = tempDiv.querySelectorAll(`.${mention_input_module_less_1.default.mention_tag}`);
|
|
676
|
-
mentionTags.forEach((tag) => {
|
|
677
|
-
var _a;
|
|
678
|
-
const contextId = tag.getAttribute('data-context-id');
|
|
679
|
-
if (contextId) {
|
|
680
|
-
// 替换为contextId
|
|
681
|
-
const replacement = document.createTextNode(`{{${mentionKeyword}${tag.getAttribute('data-type')}:${contextId}}}`);
|
|
682
|
-
// 替换内容
|
|
683
|
-
(_a = tag.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(replacement, tag);
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
// 获取处理后的内容
|
|
687
|
-
let processedContent = tempDiv.innerHTML;
|
|
688
|
-
processedContent = processedContent.trim().replaceAll(exports.WHITE_SPACE_TEXT, ' ');
|
|
689
|
-
// 添加到历史记录
|
|
690
|
-
if (rawContent) {
|
|
691
|
-
setHistory((prev) => [...prev, rawContent]);
|
|
692
|
-
// 重置历史导航状态
|
|
693
|
-
setHistoryIndex(-1);
|
|
694
|
-
setIsNavigatingHistory(false);
|
|
695
|
-
}
|
|
696
|
-
if (onSend) {
|
|
697
|
-
// 传递当前选择的模型和其他配置信息
|
|
698
|
-
onSend(processedContent, {
|
|
699
|
-
model: selectedModel,
|
|
700
|
-
...footerConfig,
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
editorRef.current.innerHTML = '';
|
|
704
|
-
// 重置编辑器高度和滚动条
|
|
705
|
-
if (editorRef.current) {
|
|
706
|
-
editorRef.current.style.overflowY = 'hidden';
|
|
707
|
-
editorRef.current.style.height = 'auto';
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
const handleStop = React.useCallback(() => {
|
|
711
|
-
if (onStop) {
|
|
712
|
-
onStop();
|
|
713
|
-
}
|
|
714
|
-
}, [onStop]);
|
|
715
|
-
// 渲染自定义按钮
|
|
716
|
-
const renderButtons = React.useCallback((position) => (footerConfig.buttons || [])
|
|
717
|
-
.filter((button) => button.position === position)
|
|
718
|
-
.map((button) => (React.createElement(components_1.Popover, { key: button.id, overlayClassName: mention_input_module_less_1.default.popover_icon, id: `ai-chat-${button.id}`, position: components_1.PopoverPosition.top, title: button.title },
|
|
719
|
-
React.createElement(ai_native_1.EnhanceIcon, { className: (0, classnames_1.default)((0, components_1.getIcon)(button.icon), mention_input_module_less_1.default[`${button.id}_logo`]), tabIndex: 0, role: 'button', ariaLabel: button.title, onClick: button.onClick })))), [footerConfig.buttons]);
|
|
720
|
-
return (React.createElement("div", { className: mention_input_module_less_1.default.input_container },
|
|
721
|
-
mentionState.active && (React.createElement("div", { className: mention_input_module_less_1.default.mention_panel_container },
|
|
722
|
-
React.createElement(mention_panel_1.MentionPanel, { items: getCurrentItems(), activeIndex: mentionState.activeIndex, onSelectItem: (item) => handleSelectItem(item, true), position: { top: 0, left: 0 }, filter: mentionState.level === 0 ? mentionState.filter : mentionState.secondLevelFilter, visible: true, level: mentionState.level, loading: mentionState.loading }))),
|
|
723
|
-
React.createElement("div", { className: mention_input_module_less_1.default.editor_area },
|
|
724
|
-
React.createElement("div", { ref: editorRef, className: mention_input_module_less_1.default.editor, contentEditable: true, onInput: handleInput, onKeyDown: handleKeyDown, onCompositionEnd: handleCompositionEnd })),
|
|
725
|
-
React.createElement("div", { className: mention_input_module_less_1.default.footer },
|
|
726
|
-
React.createElement("div", { className: mention_input_module_less_1.default.left_control },
|
|
727
|
-
footerConfig.showModelSelector && (React.createElement(components_1.Select, { options: footerConfig.modelOptions || [], value: selectedModel, onChange: handleModelChange, className: mention_input_module_less_1.default.model_selector, size: 'small' })),
|
|
728
|
-
renderButtons(types_1.FooterButtonPosition.LEFT)),
|
|
729
|
-
React.createElement("div", { className: mention_input_module_less_1.default.right_control },
|
|
730
|
-
renderButtons(types_1.FooterButtonPosition.RIGHT),
|
|
731
|
-
React.createElement(components_1.Popover, { overlayClassName: mention_input_module_less_1.default.popover_icon, id: 'ai-chat-send', position: components_1.PopoverPosition.top, title: !loading ? 'Send' : 'Stop' }, !loading ? (React.createElement(ai_native_1.EnhanceIcon, { wrapperClassName: mention_input_module_less_1.default.send_logo, className: (0, classnames_1.default)((0, components_1.getIcon)('send-outlined'), mention_input_module_less_1.default.send_logo_icon), tabIndex: 0, role: 'button', onClick: handleSend, ariaLabel: 'Send' })) : (React.createElement(ai_native_1.EnhanceIcon, { wrapperClassName: mention_input_module_less_1.default.stop_logo, className: (0, classnames_1.default)((0, components_1.getIcon)('stop'), mention_input_module_less_1.default.stop_logo_icon), tabIndex: 0, role: 'button', ariaLabel: 'Stop', onClick: handleStop })))))));
|
|
732
|
-
};
|
|
733
|
-
exports.MentionInput = MentionInput;
|
|
734
|
-
//# sourceMappingURL=mention-input.js.map
|