diff --git a/web/src/components/prompt-editor/index.tsx b/web/src/components/prompt-editor/index.tsx index ba20e62f2..99d9988e9 100644 --- a/web/src/components/prompt-editor/index.tsx +++ b/web/src/components/prompt-editor/index.tsx @@ -9,14 +9,19 @@ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin'; import { HeadingNode, QuoteNode } from '@lexical/rich-text'; import { $getRoot, + $getSelection, $nodesOfType, EditorState, Klass, LexicalNode, } from 'lexical'; -import { useCallback } from 'react'; +import { cn } from '@/lib/utils'; +import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; +import { Variable } from 'lucide-react'; +import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'; import theme from './theme'; import { VariableNode } from './variable-node'; import { VariableOnChangePlugin } from './variable-on-change-plugin'; @@ -42,6 +47,58 @@ type IProps = { onChange?: (value?: string) => void; }; +function PromptContent() { + const [editor] = useLexicalComposerContext(); + const [isBlur, setIsBlur] = useState(false); + const { t } = useTranslation(); + + const insertTextAtCursor = useCallback(() => { + editor.update(() => { + const selection = $getSelection(); + + if (selection !== null) { + selection.insertText(' /'); + } + }); + }, [editor]); + + const handleVariableIconClick = useCallback(() => { + insertTextAtCursor(); + }, [insertTextAtCursor]); + + const handleBlur = useCallback(() => { + setIsBlur(true); + }, []); + + const handleFocus = useCallback(() => { + setIsBlur(false); + }, []); + + return ( + + + + + + + + + + {t('flow.insertVariableTip')} + + + + + + ); +} + export function PromptEditor({ value, onChange }: IProps) { const { t } = useTranslation(); const initialConfig: InitialConfigType = { @@ -69,9 +126,7 @@ export function PromptEditor({ value, onChange }: IProps) { return ( - } + contentEditable={} placeholder={ {t('common.pleaseInput')} } diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index 7e2d7b28a..1d3a7bc3e 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -1179,6 +1179,7 @@ This delimiter is used to split the input text into several text pieces echo of addCategory: 'Add category', categoryName: 'Category name', nextStep: 'Next step', + insertVariableTip: `Enter / Insert variables`, }, footer: { profile: 'All rights reserved @ React', diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts index b228b5fa5..31d7ab955 100644 --- a/web/src/locales/zh-traditional.ts +++ b/web/src/locales/zh-traditional.ts @@ -1111,6 +1111,7 @@ export default { addCategory: '新增分類', categoryName: '分類名稱', nextStep: '下一步', + insertVariableTip: `輸入 / 插入變數`, }, footer: { profile: '“保留所有權利 @ react”', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index eb8675b29..8eab8274f 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -1152,6 +1152,7 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于 addCategory: '新增分类', categoryName: '分类名称', nextStep: '下一步', + insertVariableTip: `输入 / 插入变量`, }, footer: { profile: 'All rights reserved @ React',
{t('flow.insertVariableTip')}