Files
Emir KarabegandWaleed Latif 7860fbe8cc feat(docs): rebuild documentation with the shared Sim design system (#9459)
* feat(docs): rebuild documentation with the Paper design system

* fix(docs): verify nested tabs and fresh-checkout CI setup

* chore(docs): refresh preservation evidence against latest staging

* fix(docs): align shared navigation and controls with Paper

* fix(docs): share active heading across responsive outlines

* fix(docs): track the final section at the end of the page

* fix(docs): preserve sidebar scroll in a persistent layout

* fix(docs): restore live screenshot backgrounds and framing

* fix(docs): finish layout polish and clean implementation references

* fix(docs): align shared dark theme and overlay states

* fix(docs): remove dark borders from platform screenshots

* test(docs): benchmark production navigation and image delivery in CI

* fix(docs): preserve machine content and production reading contracts

* fix(docs): retain readable tabs without JavaScript and verify current staging

* fix(docs): expose root response schemas and generate clean-checkout types

* fix(docs): resolve no-script tabs in the preflight cascade layer

* perf(docs): import only the search schema constructors

* fix(docs): preserve retrieval excerpts and reduce reading overhead

* fix(docs): reuse in-flight intent prefetches during navigation

* docs: record production readiness evidence and release requirements

* docs: clarify optimizer measurement provenance

* docs: preserve latest staging Search assets and compatibility evidence

* fix(docs): polish responsive controls and keep search indexing current

* test(docs): select the visible API example in browser checks

* test(docs): execute native examples against streaming and binary responses

* fix(docs): stream native API responses without buffering

* test(docs): cover review regressions through public interfaces

* fix(docs): preserve accessible examples and gate index publication

* fix(docs): finish accessible controls and cached content validation

* fix(docs): validate integration parents and report partial search failures

* fix(docs): refine navigation and compact sample controls

* fix(docs): isolate synchronous corpus validation from HTTP readers

* fix(docs): restore Paper interaction styling and verify responsive controls

* fix(docs): score each search page once per retrieval source

* fix(docs): attribute benchmark metrics to their source document

---------

Co-authored-by: Waleed Latif <walif6@gmail.com>
2026-10-30 17:06:09 -07:00

187 lines
6.2 KiB
TypeScript

'use client'
import { type ComponentType, memo, useContext } from 'react'
import {
type CanvasSentenceSegment,
CanvasSentenceView,
SubBlockRowView,
WorkflowBlockView,
} from '@sim/workflow-renderer'
import type { Node, NodeProps } from '@xyflow/react'
import { m } from 'framer-motion'
import { cn } from '@/components/docs/classnames'
import { normalizeBlockType, resolveIcon } from '@/components/workflow-preview/block-icons'
import { PreviewSelectionContext } from '@/components/workflow-preview/preview-selection-context'
import {
BLOCK_STAGGER,
DIMMED_PREVIEW_CLASS,
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.5px] ring-[var(--text-secondary)]'
export interface DocsBlockData extends Record<string, unknown> {
name: string
blockType: string
bgColor: string
rows: Array<{ title: string; value: string }>
sentence?: readonly CanvasSentenceSegment[]
typeLabel?: string
isIntegration?: boolean
triggerMode?: boolean
hasErrorConnection?: boolean
branches?: Array<{ id: string; label: string; value?: string }>
tools?: PreviewTool[]
hideTargetHandle?: boolean
index?: number
animate?: boolean
isHighlighted?: boolean
isDimmed?: boolean
}
export type DocsBlockNodeType = Node<DocsBlockData, 'previewBlock'>
/**
* Docs adapter for workflow block nodes: maps the static preview data to the
* shared {@link WorkflowBlockView}'s props. Carries no stores or
* queries — it only reshapes data into View props and wraps the result in the
* 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<DocsBlockNodeType>) {
const selectBlock = useContext(PreviewSelectionContext)
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 = normalizeBlockType(blockType, data.triggerMode)
const Icon = resolveIcon(type) ?? 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 =
Boolean(data.sentence) ||
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={cn('relative transition-opacity duration-300', isDimmed && DIMMED_PREVIEW_CLASS)}
initial={animate ? { opacity: 0 } : false}
animate={{ opacity: 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}
typeLabel={data.typeLabel}
isIntegration={data.isIntegration}
horizontalHandles
shouldShowDefaultHandles={shouldShowDefaultHandles}
hasContentBelowHeader={hasContentBelowHeader}
conditionRows={conditionRows}
routerRows={routerRows}
routerContextValue={routerContextValue}
wouldCreateConnectionCycle={() => false}
cursorConnectionsEnabled={false}
hasErrorConnection={data.hasErrorConnection}
errorOutputEnabled={data.hasErrorConnection}
onSelect={selectBlock ? () => selectBlock(id) : undefined}
sentence={
data.sentence && (
<CanvasSentenceView
segments={data.sentence}
renderChip={(title) => {
const value =
dataRows.find((row) => row.title === title)?.value ??
(title === 'Tools' ? tools?.map((tool) => tool.name).join(', ') : undefined)
if (!value || value === '-') return null
return <SubBlockRowView title={title} displayValue={value} variant='inline-value' />
}}
/>
)
}
rows={rows}
/>
</m.div>
)
})