mirror of
https://github.com/EthanMarti/infio-copilot.git
synced 2026-01-16 08:21:55 +00:00
fix build error
This commit is contained in:
parent
bde7df8b77
commit
2d418c3cdd
@ -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">
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -121,6 +121,12 @@ describe('parseSmartCopilotSettings', () => {
|
||||
baseUrl: '',
|
||||
useCustomUrl: false,
|
||||
},
|
||||
grokProvider: {
|
||||
name: 'Grok',
|
||||
apiKey: '',
|
||||
baseUrl: '',
|
||||
useCustomUrl: false,
|
||||
},
|
||||
infioProvider: {
|
||||
name: 'Infio',
|
||||
apiKey: '',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user