fix build error

This commit is contained in:
duanfuxiang 2025-04-15 23:32:29 +08:00
parent bde7df8b77
commit 2d418c3cdd
4 changed files with 52 additions and 13 deletions

View File

@ -4,7 +4,7 @@ import { InitialEditorStateType } from '@lexical/react/LexicalComposer'
import { $getRoot, $insertNodes, LexicalEditor } from 'lexical'
import { Pencil, Search, Trash2 } from 'lucide-react'
import { Notice } from 'obsidian'
import { useCallback, useEffect, useRef, useState } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
// import { v4 as uuidv4 } from 'uuid'
import { lexicalNodeToPlainText } from '../../components/chat-view/chat-input/utils/editor-state-to-plain-text'
@ -65,7 +65,44 @@ const CommandsView = (
const nameInputRefs = useRef<Map<string, HTMLInputElement>>(new Map())
const contentEditorRefs = useRef<Map<string, LexicalEditor>>(new Map())
const contentEditableRefs = useRef<Map<string, HTMLDivElement>>(new Map())
// 为每个正在编辑的命令创建refs
const commandEditRefs = useRef<Map<string, {
editorRef: React.RefObject<LexicalEditor>,
contentEditableRef: React.RefObject<HTMLDivElement>
}>>(new Map());
// 获取或创建命令编辑refs
const getCommandEditRefs = useCallback((id: string) => {
if (!commandEditRefs.current.has(id)) {
commandEditRefs.current.set(id, {
editorRef: React.createRef<LexicalEditor>(),
contentEditableRef: React.createRef<HTMLDivElement>()
});
}
// 由于之前的if语句确保了值存在所以这里不会返回undefined
const refs = commandEditRefs.current.get(id);
if (!refs) {
// 添加保险逻辑创建一个新的refs对象
const newRefs = {
editorRef: React.createRef<LexicalEditor>(),
contentEditableRef: React.createRef<HTMLDivElement>()
};
commandEditRefs.current.set(id, newRefs);
return newRefs;
}
return refs;
}, []);
// 当编辑状态改变时更新refs
useEffect(() => {
if (editingCommandId) {
const refs = getCommandEditRefs(editingCommandId);
if (refs.editorRef.current) {
contentEditorRefs.current.set(editingCommandId, refs.editorRef.current);
}
}
}, [editingCommandId, getCommandEditRefs]);
// new command content's editor state
const initialEditorState: InitialEditorStateType = (
@ -80,9 +117,9 @@ const CommandsView = (
})
}
// new command content's editor
const editorRef = useRef<LexicalEditor | null>(null)
const editorRef = useRef<LexicalEditor>(null)
// new command content's editable
const contentEditableRef = useRef<HTMLDivElement | null>(null)
const contentEditableRef = useRef<HTMLDivElement>(null)
// Create new command
const handleAddCommand = async () => {
@ -233,12 +270,8 @@ const CommandsView = (
<div className="infio-commands-textarea">
<LexicalContentEditable
initialEditorState={getCommandEditorState(command.content)}
editorRef={(editor: LexicalEditor) => {
if (editor) contentEditorRefs.current.set(command.id, editor)
}}
contentEditableRef={(el: HTMLDivElement) => {
if (el) contentEditableRefs.current.set(command.id, el)
}}
editorRef={getCommandEditRefs(command.id).editorRef}
contentEditableRef={getCommandEditRefs(command.id).contentEditableRef}
/>
</div>
<div className="infio-commands-actions">

View File

@ -50,8 +50,8 @@ export class CommandManager {
}
async searchCommands(query: string): Promise<SelectTemplate[]> {
const templates = await this.findAllCommands()
const results = fuzzysort.go(query, templates, {
const commands = await this.findAllCommands()
const results = fuzzysort.go(query, commands, {
keys: ['name'],
threshold: 0.2,
limit: 20,

View File

@ -31,7 +31,7 @@ export class CommandRepository {
if (!this.db) {
throw new DatabaseNotInitializedException()
}
const result = await this.db.liveQuery<SelectTemplate>(
const result = await this.db.query<SelectTemplate>(
`SELECT * FROM "template"`
)
return result.rows

View File

@ -121,6 +121,12 @@ describe('parseSmartCopilotSettings', () => {
baseUrl: '',
useCustomUrl: false,
},
grokProvider: {
name: 'Grok',
apiKey: '',
baseUrl: '',
useCustomUrl: false,
},
infioProvider: {
name: 'Infio',
apiKey: '',