Files
simstudioai--sim/apps/docs/components/workflow-preview/docs-block-node.tsx
T
wehub-resource-sync d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

146 lines
4.8 KiB
TypeScript

'use client'
import { type ComponentType, memo } from 'react'
import { SubBlockRowView, WorkflowBlockView } from '@sim/workflow-renderer'
import { m } from 'framer-motion'
import type { NodeProps } from 'reactflow'
import { resolveIcon } from '@/components/workflow-preview/block-icons'
import {
BLOCK_STAGGER,
EASE_OUT,
type PreviewTool,
} from '@/components/workflow-preview/workflow-data'
/** Renders the colored square with no glyph when a block type has no registered icon. */
const EMPTY_ICON: ComponentType<{ className?: string }> = () => null
const RING_STYLES = 'ring-[1.75px] ring-[var(--brand-secondary)]'
interface DocsBlockData {
name: string
blockType: string
bgColor: string
rows: Array<{ title: string; value: string }>
branches?: Array<{ id: string; label: string; value?: string }>
tools?: PreviewTool[]
hideTargetHandle?: boolean
index?: number
animate?: boolean
isHighlighted?: boolean
isDimmed?: boolean
}
/**
* Docs adapter for workflow block nodes: maps the static preview data to the
* shared {@link WorkflowBlockView}'s props. Carries no stores, hooks, or
* queries — it only reshapes data into View props and wraps the result in the
* dim/stagger motion used by the rest of the diagram (the parent
* `WorkflowPreview` provides the `LazyMotion` feature set). The block's ring is
* driven by `hasRing`/`ringStyles` inside the View.
*/
export const DocsBlockNode = memo(function DocsBlockNode({ id, data }: NodeProps<DocsBlockData>) {
const {
name,
blockType,
bgColor,
rows: dataRows,
branches,
tools,
hideTargetHandle = false,
index = 0,
animate = false,
isHighlighted = false,
isDimmed = false,
} = data
/** The View gates router handle topology on `type === 'router_v2'`. */
const type = blockType === 'router' ? 'router_v2' : blockType
const Icon = resolveIcon(blockType) ?? EMPTY_ICON
const delay = animate ? index * BLOCK_STAGGER : 0
const hasBranches = Boolean(branches && branches.length > 0)
const hasTools = Boolean(tools && tools.length > 0)
/** The View renders the default target/source/error handles (and the error row) for non-trigger blocks; mirror that gate. */
const shouldShowDefaultHandles = !hideTargetHandle
const hasContentBelowHeader =
dataRows.length > 0 || hasBranches || hasTools || shouldShowDefaultHandles
/**
* Strip the app's `condition-`/`router-` handle prefixes — the View
* regenerates them, so passing them through would double-prefix the handle id.
* Branch + router-context values render through the editor's `getDisplayValue`,
* which shows `-` for a blank value (e.g. an `else` branch); mirror that.
*/
const conditionRows =
type === 'condition'
? (branches ?? []).map((branch) => ({
id: branch.id.replace(/^condition-/, ''),
title: branch.label,
value: branch.value || '-',
}))
: []
const routerRows =
type === 'router_v2'
? (branches ?? []).map((branch) => ({
id: branch.id.replace(/^router-/, ''),
value: branch.value || '-',
}))
: []
/** The View renders the router's leading Context row from this prop, not `rows`. */
const routerContextValue =
type === 'router_v2' ? dataRows.find((row) => row.title === 'Context')?.value || '-' : undefined
/**
* Non-branch content only — the View renders condition/router/error rows from
* the conditionRows/routerRows it receives, so their order stays locked to its
* handle geometry in one place.
*/
const rows =
type === 'condition' || type === 'router_v2' ? null : (
<>
{dataRows.map((row) => (
<SubBlockRowView key={row.title} title={row.title} displayValue={row.value} />
))}
{hasTools && (
<SubBlockRowView
title='Tools'
displayValue={tools?.map((tool) => tool.name).join(', ')}
/>
)}
</>
)
return (
<m.div
className='relative transition-opacity duration-300'
style={{ opacity: isDimmed ? 0.35 : 1 }}
initial={animate ? { opacity: 0 } : false}
animate={{ opacity: isDimmed ? 0.35 : 1 }}
transition={{ duration: 0.45, delay, ease: EASE_OUT }}
>
<WorkflowBlockView
id={id}
type={type}
name={name}
isEnabled
isLocked={false}
hasRing={Boolean(isHighlighted)}
ringStyles={RING_STYLES}
Icon={Icon}
iconBgColor={bgColor}
horizontalHandles
shouldShowDefaultHandles={shouldShowDefaultHandles}
hasContentBelowHeader={hasContentBelowHeader}
conditionRows={conditionRows}
routerRows={routerRows}
routerContextValue={routerContextValue}
wouldCreateConnectionCycle={() => false}
onSelect={() => {}}
rows={rows}
/>
</m.div>
)
})