From d3dfadbd9b27e68aa6924696168c52ceae238c5a Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 5 Mar 2024 17:37:20 +0800 Subject: [PATCH] feat: add code editor --- .../(commonLayout)/workflow/nodes/page.tsx | 5 ++-- .../nodes/_base/components/editor/base.tsx | 2 +- .../_base/components/editor/code-editor.tsx | 29 ++++++++++++++----- .../components/workflow/nodes/code/panel.tsx | 2 ++ .../workflow/nodes/code/use-config.ts | 4 +-- web/package.json | 1 + web/yarn.lock | 26 ++++++++++++++++- 7 files changed, 55 insertions(+), 14 deletions(-) diff --git a/web/app/(commonLayout)/workflow/nodes/page.tsx b/web/app/(commonLayout)/workflow/nodes/page.tsx index 3179a48032..83086233fa 100644 --- a/web/app/(commonLayout)/workflow/nodes/page.tsx +++ b/web/app/(commonLayout)/workflow/nodes/page.tsx @@ -32,8 +32,8 @@ const allMockData = { [BlockEnum.End]: EndNodeMock, } const nodes = [ - BlockEnum.Start/* 1 */, BlockEnum.QuestionClassifier/* 5 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, - BlockEnum.IfElse/* 6 */, BlockEnum.Code/* 7 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */, + BlockEnum.Code/* 7 */, BlockEnum.Start/* 1 */, BlockEnum.QuestionClassifier/* 5 */, BlockEnum.DirectAnswer/* 2 */, BlockEnum.LLM/* 3 */, BlockEnum.KnowledgeRetrieval/* 4 */, + BlockEnum.IfElse/* 6 */, BlockEnum.TemplateTransform/* 8 */, BlockEnum.HttpRequest/* 9 */, BlockEnum.Tool/* 10 */, BlockEnum.VariableAssigner/* 11 */, BlockEnum.End/* 12 */, ].map((item, i) => { const payload = allMockData[item] @@ -78,7 +78,6 @@ const Page: FC = () => { ) diff --git a/web/app/components/workflow/nodes/_base/components/editor/base.tsx b/web/app/components/workflow/nodes/_base/components/editor/base.tsx index 09f004c44c..3f3f8d5f9c 100644 --- a/web/app/components/workflow/nodes/_base/components/editor/base.tsx +++ b/web/app/components/workflow/nodes/_base/components/editor/base.tsx @@ -40,7 +40,7 @@ const Base: FC = ({ }, [isExpanded]) return ( -
+
{title}
diff --git a/web/app/components/workflow/nodes/_base/components/editor/code-editor.tsx b/web/app/components/workflow/nodes/_base/components/editor/code-editor.tsx index d8e819c118..a593961442 100644 --- a/web/app/components/workflow/nodes/_base/components/editor/code-editor.tsx +++ b/web/app/components/workflow/nodes/_base/components/editor/code-editor.tsx @@ -1,13 +1,15 @@ 'use client' import type { FC } from 'react' +import Editor from '@monaco-editor/react' import React from 'react' import Base from './base' +import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' type Props = { value: string onChange: (value: string) => void title: JSX.Element - language?: string + language: CodeLanguage headerRight?: JSX.Element } @@ -16,9 +18,13 @@ const CodeEditor: FC = ({ onChange, title, headerRight, + language, }) => { const [isFocus, setIsFocus] = React.useState(false) + const handleEditorChange = (value: string | undefined) => { + onChange(value || '') + } return (
= ({ value={value} headerRight={headerRight} isFocus={isFocus} - minHeight={86} + minHeight={200} > -