|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 BadLabs |
| 3 | + * |
| 4 | + * Use of this software is governed by the Business Source License 1.1 included in the file LICENSE.txt. |
| 5 | + * |
| 6 | + * As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0. |
| 7 | + */ |
| 8 | + |
| 9 | +import type { |
| 10 | + PortContextValue, |
| 11 | +} from '@/components/flow/nodes/ChaingraphNode/ports/context/PortContext' |
| 12 | +/* |
| 13 | + * Copyright (c) 2025 BadLabs |
| 14 | + * |
| 15 | + * Use of this software is governed by the Business Source License 1.1 included in the file LICENSE.txt. |
| 16 | + * |
| 17 | + * As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0. |
| 18 | + */ |
| 19 | +import type { INode, IPort, StreamPortConfig } from '@badaitech/chaingraph-types' |
| 20 | +import { cn } from '@/lib/utils' |
| 21 | +import { memo } from 'react' |
| 22 | +import { PortHandle } from '../ui/PortHandle' |
| 23 | +import { PortTitle } from '../ui/PortTitle' |
| 24 | + |
| 25 | +export interface StreamPortProps { |
| 26 | + node: INode |
| 27 | + port: IPort<StreamPortConfig> |
| 28 | + context: PortContextValue |
| 29 | +} |
| 30 | + |
| 31 | +function StreamPortComponent(props: StreamPortProps) { |
| 32 | + const { port, context } = props |
| 33 | + |
| 34 | + const config = port.getConfig() |
| 35 | + const ui = config.ui |
| 36 | + const title = config.title || config.key |
| 37 | + |
| 38 | + if (ui?.hidden) |
| 39 | + return null |
| 40 | + |
| 41 | + return ( |
| 42 | + <div |
| 43 | + key={config.id} |
| 44 | + className={cn( |
| 45 | + 'relative flex gap-2 group/port', |
| 46 | + config.direction === 'output' ? 'justify-end' : 'justify-start', |
| 47 | + )} |
| 48 | + > |
| 49 | + {config.direction === 'input' && <PortHandle port={port} />} |
| 50 | + |
| 51 | + <div className={cn( |
| 52 | + 'flex flex-col', |
| 53 | + config.direction === 'output' ? 'items-end' : 'items-start', |
| 54 | + 'truncate', |
| 55 | + )} |
| 56 | + > |
| 57 | + <PortTitle> |
| 58 | + {title} |
| 59 | + </PortTitle> |
| 60 | + </div> |
| 61 | + |
| 62 | + {config.direction === 'output' && <PortHandle port={port} />} |
| 63 | + </div> |
| 64 | + ) |
| 65 | +} |
| 66 | + |
| 67 | +// Export a memoized version of the component to prevent unnecessary re-renders |
| 68 | +export const StreamPort = memo(StreamPortComponent) |
0 commit comments