feat: workflow add note node (#5164)

This commit is contained in:
zxhlyh 2024-06-14 17:08:11 +08:00 • committed by GitHub
commit c28d709d7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
69 changed files with 2375 additions and 169 deletions

View file

@ -19,10 +19,18 @@ const Icon = () => {
type NodeResizerProps = {
nodeId: string
nodeData: CommonNodeType
icon?: JSX.Element
minWidth?: number
minHeight?: number
maxWidth?: number
}
const NodeResizer = ({
nodeId,
nodeData,
icon = <Icon />,
minWidth = 272,
minHeight = 176,
maxWidth,
}: NodeResizerProps) => {
const { handleNodeResize } = useNodesInteractions()
@ -39,10 +47,11 @@ const NodeResizer = ({
position='bottom-right'
className='!border-none !bg-transparent'
onResize={handleResize}
minWidth={272}
minHeight={176}
minWidth={minWidth}
minHeight={minHeight}
maxWidth={maxWidth}
>
<div className='absolute bottom-[1px] right-[1px]'><Icon /></div>
<div className='absolute bottom-[1px] right-[1px]'>{icon}</div>
</NodeResizeControl>
</div>
)

View file

@ -64,3 +64,5 @@ export const PanelComponentMap: Record<string, ComponentType<any>> = {
[BlockEnum.ParameterExtractor]: ParameterExtractorPanel,
[BlockEnum.Iteration]: IterationPanel,
}
export const CUSTOM_NODE_TYPE = 'custom'

View file

@ -1,6 +1,10 @@
import { memo } from 'react'
import {
memo,
useMemo,
} from 'react'
import type { NodeProps } from 'reactflow'
import type { Node } from '../types'
import { CUSTOM_NODE } from '../constants'
import {
NodeComponentMap,
PanelComponentMap,
@ -23,14 +27,24 @@ const CustomNode = (props: NodeProps) => {
CustomNode.displayName = 'CustomNode'
export const Panel = memo((props: Node) => {
const nodeClass = props.type
const nodeData = props.data
const PanelComponent = PanelComponentMap[nodeData.type]
const PanelComponent = useMemo(() => {
if (nodeClass === CUSTOM_NODE)
return PanelComponentMap[nodeData.type]
return (
<BasePanel key={props.id} {...props}>
<PanelComponent />
</BasePanel>
)
return () => null
}, [nodeClass, nodeData.type])
if (nodeClass === CUSTOM_NODE) {
return (
<BasePanel key={props.id} {...props}>
<PanelComponent />
</BasePanel>
)
}
return null
})
Panel.displayName = 'Panel'