2024-04-08 18:51:46 +08:00
|
|
|
import type { FC } from 'react'
|
2024-04-28 17:09:56 +08:00
|
|
|
import { memo } from 'react'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { useNodes } from 'reactflow'
|
|
|
|
import type { CommonNodeType } from '../types'
|
|
|
|
import { Panel as NodePanel } from '../nodes'
|
|
|
|
import { useStore } from '../store'
|
2024-07-22 15:29:39 +08:00
|
|
|
import EnvPanel from './env-panel'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2024-04-08 18:51:46 +08:00
|
|
|
|
2025-04-18 13:59:12 +08:00
|
|
|
export type PanelProps = {
|
|
|
|
components?: {
|
|
|
|
left?: React.ReactNode
|
|
|
|
right?: React.ReactNode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const Panel: FC<PanelProps> = ({
|
|
|
|
components,
|
|
|
|
}) => {
|
2024-04-08 18:51:46 +08:00
|
|
|
const nodes = useNodes<CommonNodeType>()
|
|
|
|
const selectedNode = nodes.find(node => node.data.selected)
|
2024-07-22 15:29:39 +08:00
|
|
|
const showEnvPanel = useStore(s => s.showEnvPanel)
|
2024-04-24 13:05:33 +08:00
|
|
|
const isRestoring = useStore(s => s.isRestoring)
|
2024-04-08 18:51:46 +08:00
|
|
|
|
|
|
|
return (
|
2024-04-25 14:02:06 +08:00
|
|
|
<div
|
|
|
|
tabIndex={-1}
|
2025-03-21 17:41:03 +08:00
|
|
|
className={cn('absolute bottom-2 right-0 top-14 z-10 flex outline-none')}
|
2024-04-25 14:02:06 +08:00
|
|
|
key={`${isRestoring}`}
|
|
|
|
>
|
2024-04-08 18:51:46 +08:00
|
|
|
{
|
2025-04-18 13:59:12 +08:00
|
|
|
components?.left
|
2024-04-08 18:51:46 +08:00
|
|
|
}
|
2024-04-28 17:09:56 +08:00
|
|
|
{
|
|
|
|
!!selectedNode && (
|
|
|
|
<NodePanel {...selectedNode!} />
|
|
|
|
)
|
|
|
|
}
|
2024-04-08 18:51:46 +08:00
|
|
|
{
|
2025-04-18 13:59:12 +08:00
|
|
|
components?.right
|
2024-04-08 18:51:46 +08:00
|
|
|
}
|
2024-07-22 15:29:39 +08:00
|
|
|
{
|
|
|
|
showEnvPanel && (
|
|
|
|
<EnvPanel />
|
|
|
|
)
|
|
|
|
}
|
2024-04-08 18:51:46 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(Panel)
|