feat(web): 优化节点编辑性能
This commit is contained in:
@@ -15,33 +15,33 @@
|
|||||||
"@ant-design/x": "^1.4.0",
|
"@ant-design/x": "^1.4.0",
|
||||||
"@echofly/fetch-event-source": "^3.0.2",
|
"@echofly/fetch-event-source": "^3.0.2",
|
||||||
"@fortawesome/fontawesome-free": "^6.7.2",
|
"@fortawesome/fontawesome-free": "^6.7.2",
|
||||||
"@lightenna/react-mermaid-diagram": "^1.0.20",
|
"@lightenna/react-mermaid-diagram": "^1.0.21",
|
||||||
"@xyflow/react": "^12.7.1",
|
"@xyflow/react": "^12.8.1",
|
||||||
"ahooks": "^3.8.5",
|
"ahooks": "^3.9.0",
|
||||||
"amis": "^6.12.0",
|
"amis": "^6.12.0",
|
||||||
"antd": "^5.26.2",
|
"antd": "^5.26.3",
|
||||||
"axios": "^1.10.0",
|
"axios": "^1.10.0",
|
||||||
"chart.js": "^4.5.0",
|
"chart.js": "^4.5.0",
|
||||||
"echarts-for-react": "^3.0.2",
|
"echarts-for-react": "^3.0.2",
|
||||||
"licia": "^1.48.0",
|
"licia": "^1.48.0",
|
||||||
"mermaid": "^11.7.0",
|
"mermaid": "^11.8.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-chartjs-2": "^5.3.0",
|
"react-chartjs-2": "^5.3.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
"react-router": "^7.6.2",
|
"react-router": "^7.6.3",
|
||||||
"styled-components": "^6.1.19",
|
"styled-components": "^6.1.19",
|
||||||
"yocto-queue": "^1.2.1",
|
"yocto-queue": "^1.2.1",
|
||||||
"zustand": "^5.0.5"
|
"zustand": "^5.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^18.3.23",
|
"@types/react": "^18.3.23",
|
||||||
"@types/react-dom": "^18.3.7",
|
"@types/react-dom": "^18.3.7",
|
||||||
"@vitejs/plugin-react-swc": "^3.10.2",
|
"@vitejs/plugin-react-swc": "^3.10.2",
|
||||||
"globals": "^16.2.0",
|
"globals": "^16.3.0",
|
||||||
"sass": "^1.89.2",
|
"sass": "^1.89.2",
|
||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"vite": "^7.0.0",
|
"vite": "^7.0.2",
|
||||||
"vite-plugin-javascript-obfuscator": "^3.1.0",
|
"vite-plugin-javascript-obfuscator": "^3.1.0",
|
||||||
"vitest": "^3.2.4"
|
"vitest": "^3.2.4"
|
||||||
}
|
}
|
||||||
|
|||||||
603
service-web/client/pnpm-lock.yaml
generated
603
service-web/client/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -7,25 +7,25 @@ import {
|
|||||||
MiniMap,
|
MiniMap,
|
||||||
type Node,
|
type Node,
|
||||||
type NodeProps,
|
type NodeProps,
|
||||||
ReactFlow
|
ReactFlow,
|
||||||
} from '@xyflow/react'
|
} from '@xyflow/react'
|
||||||
import type {Schema} from 'amis'
|
import type {Schema} from 'amis'
|
||||||
import {Button, Drawer, Dropdown, message, Popconfirm, Space} from 'antd'
|
import {Button, Drawer, Dropdown, message, Popconfirm, Space} from 'antd'
|
||||||
import {arrToMap, find, isEqual, isNil, randomId} from 'licia'
|
import {arrToMap, find, isEqual, isNil, randomId} from 'licia'
|
||||||
import {type JSX, type MemoExoticComponent, useEffect, useState} from 'react'
|
import {type JSX, type MemoExoticComponent, useEffect, useState} from 'react'
|
||||||
|
import {useNavigate} from 'react-router'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import '@xyflow/react/dist/style.css'
|
import '@xyflow/react/dist/style.css'
|
||||||
|
import {useShallow} from 'zustand/react/shallow'
|
||||||
import {amisRender, commonInfo, horizontalFormOptions} from '../../util/amis.tsx'
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../util/amis.tsx'
|
||||||
import {checkAddConnection, checkAddNode, checkSave} from './FlowChecker.tsx'
|
import {checkAddConnection, checkAddNode, checkSave} from './FlowChecker.tsx'
|
||||||
import CodeNode from './node/CodeNode.tsx'
|
import CodeNode from './node/CodeNode.tsx'
|
||||||
import OutputNode from './node/OutputNode.tsx'
|
|
||||||
import KnowledgeNode from './node/KnowledgeNode.tsx'
|
import KnowledgeNode from './node/KnowledgeNode.tsx'
|
||||||
import LlmNode from './node/LlmNode.tsx'
|
import LlmNode from './node/LlmNode.tsx'
|
||||||
|
import OutputNode from './node/OutputNode.tsx'
|
||||||
import SwitchNode from './node/SwitchNode.tsx'
|
import SwitchNode from './node/SwitchNode.tsx'
|
||||||
import {useDataStore} from './store/DataStore.ts'
|
import {useDataStore} from './store/DataStore.ts'
|
||||||
import {useFlowStore} from './store/FlowStore.ts'
|
import {useFlowStore} from './store/FlowStore.ts'
|
||||||
import {useNavigate} from 'react-router'
|
|
||||||
import {useShallow} from 'zustand/react/shallow'
|
|
||||||
|
|
||||||
const FlowableDiv = styled.div`
|
const FlowableDiv = styled.div`
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -114,7 +114,7 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
setData: state.setData,
|
setData: state.setData,
|
||||||
getDataById: state.getDataById,
|
getDataById: state.getDataById,
|
||||||
setDataById: state.setDataById,
|
setDataById: state.setDataById,
|
||||||
}))
|
})),
|
||||||
)
|
)
|
||||||
const {
|
const {
|
||||||
nodes,
|
nodes,
|
||||||
@@ -138,7 +138,7 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
setEdges: state.setEdges,
|
setEdges: state.setEdges,
|
||||||
onEdgesChange: state.onEdgesChange,
|
onEdgesChange: state.onEdgesChange,
|
||||||
onConnect: state.onConnect,
|
onConnect: state.onConnect,
|
||||||
}))
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
const [currentNodeForm, setCurrentNodeForm] = useState<JSX.Element>()
|
const [currentNodeForm, setCurrentNodeForm] = useState<JSX.Element>()
|
||||||
@@ -167,7 +167,7 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
{
|
{
|
||||||
...context.props.data,
|
...context.props.data,
|
||||||
finished: true,
|
finished: true,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
},
|
},
|
||||||
@@ -220,7 +220,7 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
// 用于透传node操作到主流程
|
// 用于透传node操作到主流程
|
||||||
const initialNodeHandlers = {
|
const initialNodeHandlers = {
|
||||||
// getInputSchema: () => props.inputSchema,
|
// getInputSchema: () => props.inputSchema,
|
||||||
editNode
|
editNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -329,7 +329,6 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
nodeDef.map(def => def.key),
|
nodeDef.map(def => def.key),
|
||||||
key => find(nodeDef, def => isEqual(key, def.key))!.component)
|
key => find(nodeDef, def => isEqual(key, def.key))!.component)
|
||||||
}
|
}
|
||||||
fitView
|
|
||||||
>
|
>
|
||||||
<Controls/>
|
<Controls/>
|
||||||
<MiniMap/>
|
<MiniMap/>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import {CopyFilled, DeleteFilled, EditFilled} from '@ant-design/icons'
|
||||||
import {
|
import {
|
||||||
type Edge,
|
type Edge,
|
||||||
Handle,
|
Handle,
|
||||||
@@ -5,15 +6,16 @@ import {
|
|||||||
type Node,
|
type Node,
|
||||||
type NodeProps,
|
type NodeProps,
|
||||||
Position,
|
Position,
|
||||||
useNodeConnections
|
useNodeConnections,
|
||||||
} from '@xyflow/react'
|
} from '@xyflow/react'
|
||||||
import type {Schema} from 'amis'
|
import type {Schema} from 'amis'
|
||||||
import {Button, Card} from 'antd'
|
import {Button, Card} from 'antd'
|
||||||
import {isEmpty, isEqual, isNil} from 'licia'
|
import {isEmpty, isEqual, isNil} from 'licia'
|
||||||
import {type JSX, useMemo} from 'react'
|
import {type JSX} from 'react'
|
||||||
|
import styled from 'styled-components'
|
||||||
import {horizontalFormOptions} from '../../../util/amis.tsx'
|
import {horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
import {useDataStore} from '../store/DataStore.ts'
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
import {EditFilled} from '@ant-design/icons'
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
|
||||||
export type AmisNodeType = 'normal' | 'start' | 'end'
|
export type AmisNodeType = 'normal' | 'start' | 'end'
|
||||||
|
|
||||||
@@ -122,6 +124,16 @@ type AmisNodeProps = {
|
|||||||
columnSchema?: (props: ColumnsSchemaProps) => Schema[]
|
columnSchema?: (props: ColumnsSchemaProps) => Schema[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AmisNodeContainerDiv = styled.div`
|
||||||
|
.ant-card {
|
||||||
|
.ant-card-actions {
|
||||||
|
& > li {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
||||||
nodeProps,
|
nodeProps,
|
||||||
type,
|
type,
|
||||||
@@ -131,43 +143,43 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
|||||||
handlers,
|
handlers,
|
||||||
columnSchema,
|
columnSchema,
|
||||||
}) => {
|
}) => {
|
||||||
// const {
|
const {
|
||||||
// removeNode,
|
removeNode,
|
||||||
// getNodes,
|
getNodes,
|
||||||
// getEdges
|
getEdges,
|
||||||
// } = useFlowStore()
|
} = useFlowStore()
|
||||||
const {getDataById} = useDataStore()
|
const {getDataById} = useDataStore()
|
||||||
|
|
||||||
const {id, data} = nodeProps
|
const {id, data} = nodeProps
|
||||||
const {editNode} = data
|
const {editNode} = data
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const nodeData = useMemo(() => {
|
const nodeData = getDataById(id)
|
||||||
return getDataById(id)
|
|
||||||
}, [id])
|
|
||||||
const nodeName = isEmpty(nodeData?.node?.name) ? defaultNodeName : nodeData.node.name
|
const nodeName = isEmpty(nodeData?.node?.name) ? defaultNodeName : nodeData.node.name
|
||||||
const nodeDescription = isEmpty(nodeData?.node?.description) ? defaultNodeDescription : nodeData.node?.description
|
const nodeDescription = isEmpty(nodeData?.node?.description) ? defaultNodeDescription : nodeData.node?.description
|
||||||
return (
|
return (
|
||||||
<div className="w-64">
|
<AmisNodeContainerDiv className="w-64">
|
||||||
{/* className="card-container"
|
<Card
|
||||||
trigger={['contextMenu']}
|
className="node-card"
|
||||||
menu={{
|
title={nodeName}
|
||||||
items: [
|
extra={<span className="text-gray-300 text-xs">{id}</span>}
|
||||||
{
|
size="small"
|
||||||
key: 'edit',
|
actions={[
|
||||||
label: '编辑',
|
<Button
|
||||||
icon: <EditFilled className="text-gray-600 hover:text-blue-500"/>,
|
className="text-secondary"
|
||||||
},
|
disabled
|
||||||
{
|
type="text"
|
||||||
key: 'remove',
|
size="small"
|
||||||
label: '删除',
|
icon={<CopyFilled/>}
|
||||||
icon: <DeleteFilled className="text-red-500 hover:text-red-500"/>,
|
block
|
||||||
},
|
/>,
|
||||||
],
|
<Button
|
||||||
onClick: menu => {
|
className="text-secondary"
|
||||||
switch (menu.key) {
|
type="text"
|
||||||
case 'edit':
|
size="small"
|
||||||
|
icon={<EditFilled/>}
|
||||||
|
block
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
editNode(
|
onClick={() => editNode(
|
||||||
id,
|
id,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -198,21 +210,17 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
|||||||
}) ?? []
|
}) ?? []
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)}
|
||||||
break
|
/>,
|
||||||
case 'remove':
|
<Button
|
||||||
// @ts-ignore
|
className="text-secondary"
|
||||||
removeNode(id)
|
type="text"
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>*/}
|
|
||||||
<Card
|
|
||||||
className="node-card"
|
|
||||||
title={nodeName}
|
|
||||||
extra={<span className="text-gray-300 text-xs">{id}</span>}
|
|
||||||
size="small"
|
size="small"
|
||||||
|
icon={<DeleteFilled/>}
|
||||||
|
block
|
||||||
|
onClick={() => removeNode(id)}
|
||||||
|
/>,
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<div className="card-description p-2 text-secondary text-sm">
|
<div className="card-description p-2 text-secondary text-sm">
|
||||||
{nodeDescription}
|
{nodeDescription}
|
||||||
@@ -227,7 +235,7 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
|||||||
? <Handle type="target" position={Position.Left} id="target"/> : undefined}
|
? <Handle type="target" position={Position.Left} id="target"/> : undefined}
|
||||||
</>
|
</>
|
||||||
: handlers?.(nodeData)}
|
: handlers?.(nodeData)}
|
||||||
</div>
|
</AmisNodeContainerDiv>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const useDataStore = create<DataStoreState>((set, get) => ({
|
|||||||
data: {},
|
data: {},
|
||||||
getData: () => get().data,
|
getData: () => get().data,
|
||||||
setData: (data) => set({
|
setData: (data) => set({
|
||||||
data: data
|
data: data,
|
||||||
}),
|
}),
|
||||||
getDataById: id => get().data[id],
|
getDataById: id => get().data[id],
|
||||||
setDataById: (id, data) => {
|
setDataById: (id, data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user