feat: meaningful labels by status
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import type React from 'react'
|
||||
import type { ConnectionStatus } from './connectionStatus'
|
||||
import { registerSourceRenderingLogic } from './sourceRenderingLogic'
|
||||
import type { SourceRenderingLogic } from './sourceRenderingLogic'
|
||||
|
||||
@@ -44,8 +45,8 @@ export type NodeTypeDescriptor = {
|
||||
getDefaultData?: (newId?: string) => Record<string, unknown>
|
||||
/** Optional: data for Reset action; if omitted, getDefaultData(nodeId) or defaultData is used. */
|
||||
getResetData?: (nodeId?: string) => Record<string, unknown>
|
||||
/** Optional: label shown on edge when this type is the target (e.g. "render", "add input"). */
|
||||
connectionLabel?: string
|
||||
/** Optional: label per connection status shown on edge when this type is the target. */
|
||||
connectionLabelByStatus?: Partial<Record<ConnectionStatus, string>>
|
||||
/** When true, double-clicking the node header opens a fullscreen dialog for this node. */
|
||||
supportsFullscreen?: boolean
|
||||
/**
|
||||
@@ -157,9 +158,21 @@ export function isConnectionAllowed(
|
||||
return true
|
||||
}
|
||||
|
||||
/** Edge label when target is of this type (for AnimatedEdge). */
|
||||
/** Edge label when target is of this type (default status only; for edge data fallback). */
|
||||
export function getConnectionLabelForTarget(targetType: string): string | undefined {
|
||||
return getNodeType(targetType)?.connectionLabel
|
||||
return getNodeType(targetType)?.connectionLabelByStatus?.['default']
|
||||
}
|
||||
|
||||
/** Edge label for target type and connection status; falls back to default when status not in map. */
|
||||
export function getConnectionLabelForTargetAndStatus(
|
||||
targetType: string,
|
||||
status: ConnectionStatus
|
||||
): string | undefined {
|
||||
const desc = getNodeType(targetType)
|
||||
if (!desc?.connectionLabelByStatus) return undefined
|
||||
const byStatus = desc.connectionLabelByStatus[status]
|
||||
if (byStatus !== undefined) return byStatus
|
||||
return desc.connectionLabelByStatus['default']
|
||||
}
|
||||
|
||||
/** Help entry for a node type. Use in NodeHelpPopover. */
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
import type React from 'react'
|
||||
import type { ConnectionStatus } from './connectionStatus'
|
||||
import type { NodeTypeDescriptor, NodeClassification, NodeHelpEntry } from './nodeRegistry'
|
||||
import type { SourceRenderingLogic } from './sourceRenderingLogic'
|
||||
|
||||
@@ -97,8 +98,8 @@ export class NodeTypeBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
connectionLabel(label: string): this {
|
||||
this.partial.connectionLabel = label
|
||||
connectionLabelByStatus(partial: Partial<Record<ConnectionStatus, string>>): this {
|
||||
this.partial.connectionLabelByStatus = partial
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user