Files
AgentLab/frontend/src/canvas/VersionsSheet.tsx
T
ThearchyHelios 35583ba1d8 口径召回前端(W4-a):版本用量加问数回答和召回、发布弹窗预告召回规模、版本历史看召回批次、recall 待办卡、时间线认两个新事件
为什么:前三波召回只有接口;这一波收口,口径升版之后谁的答案受影响、重算了几组、数变没变、怎么处置都要在界面上走得通。

- canvas/versionUsage:使用情况那一行加问数回答、导出、定时任务、召回(老服务端不给就不写)
- canvas/RecallPanel(新):发布弹窗「召回」一行——旧版本被谁用过、按参数去重几组、发布后自动重算几组、超出上限几组(可在
  版本历史接着算)、上限为 0 时只列不算、不能重算的原因;版本历史展开一版——每组结论(数变了 / 没变 / 无法重算:原因 /
  重算失败 / 正在重算 / 未重算)、变了的指标、开了几条待办、召回运行链接,「另有 M 组未重算」+ 接着算
- run/RecallTask(新)+ TaskCard:recall 待办卡——旧口径、新口径、两版之差一行一个指标,每个数点得开召回卡的指标链;每个答案
  当时的值点得开(正式运行的口径卡、问数回答的查询快照),问数回答链回对话;「按新版重新出具」(不能时停用并写服务端给的
  原因)、「知道了」;遮罩值写已遮罩、点不开;目录有变、表结构变了两种只有「知道了」
- run/decode:ledger.recalled(已按 vN 核对,不影响;召回核对数变没变;试算结果)、ledger.basis_changed(依据有变、依据的
  表结构已变);缺字段不猜
- 文案进 lib/termsRecall.ts;接口 api/recall.ts、形状 typesRecall.ts;TaskKind 加 recall
- 检查:check-inbox 加 recall 卡两段,check-publish 加召回预告和召回批次两段(版本历史、发布弹窗都在这里测;check-versions
  测的是上传表格的版本页,和召回无关),check-decode 加两个新事件的夹具,check-capabilities 的可订阅事件跟上 ledger.recall
2026-10-16 20:05:24 +08:00

466 lines
25 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useMemo, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { Archive, ChevronLeft, History, LayoutGrid, RotateCcw, ShieldCheck } from 'lucide-react'
import clsx from 'clsx'
import { api } from '../api/client'
import {
EDIT_LOCK_TEXT, diffGraphs, toFlow, useEditLock, useStudio, type EditLock, type FlowNode, type GraphDiff,
} from '../store/studio'
import { ErrorState, Skeleton, toast } from '../components/ui'
import { useDatasources } from '../store/catalog'
import { formatDateTime, formatTime } from '../lib/format'
import { CATALOG_DRIFT_TEXT, VERSION_USAGE_TEXT, WORKFLOW_STATUS_LABEL, publishedLevelOf } from '../lib/terms'
import { useAtLeast } from '../store/auth'
import { RetiredNote, VersionUsageLine, retireBlocked, retireVersion, useVersionUsage } from './versionUsage'
import { RecallBatches } from './RecallPanel'
import { hintOf } from './shortcuts'
import { newAppPath } from '../pages/apps/shared'
import type { Edge } from '@xyflow/react'
import type { CatalogDriftTable, CatalogVersions as CatalogVersionsRecord, GraphSpec, Workflow, WorkflowVersion } from '../types'
/**
* 版本历史。盖在右栏上的一层,和属性面板同一种「临时造访」。
*
* 后端每次保存都认真记了一版、还带着说明(「叙述 prompt 禁止元话语数字」),界面上
* 却无处可看;误删一个节点、助手一次改坏,只能靠「不保存再刷新」挽回。
*
* 选一版就拿它和画布比:缩略图上标出恢复之后会多出来的、会被拿掉的、会被改掉的
* 节点。「恢复这一版」不调后端的 restore——那个接口不会把受管 / 已发布退回草稿,
* 一张受管工作流恢复成未过闸的旧图,工具栏会照样显示「受管」。这里把旧版放上画布,
* 作为一次可撤销的改动;保存时走普通的保存,状态按规矩退回草稿,说明写「回滚到 vN」。
*/
export function VersionsSheet({ workflow, onClose }: { workflow: Workflow; onClose: () => void }) {
const [list, setList] = useState<WorkflowVersion[] | null>(null)
const [error, setError] = useState<unknown>(null)
// 选中的版本记着是哪张工作流的:版本历史开着时换了工作流,上一张选的 v2 不能拿去请求这一张(没有这一版就是 404)
const [pickedOf, setPickedOf] = useState<{ wf: string; v: number } | null>(null)
const picked = pickedOf?.wf === workflow.id ? pickedOf.v : null
const setPicked = (v: number | null) => setPickedOf(v == null ? null : { wf: workflow.id, v })
const [detail, setDetail] = useState<{ v: number; graph: GraphSpec; version: WorkflowVersion } | { v: number; error: unknown } | null>(null)
const nodes = useStudio((s) => s.nodes)
const edges = useStudio((s) => s.edges)
const dirty = useStudio((s) => s.dirty)
// 助手在改、正式运行在跑:恢复旧版也是改图,一样拦下
const lock = useEditLock()
const restoreVersion = useStudio((s) => s.restoreVersion)
const undo = useStudio((s) => s.undo)
const load = () => {
setError(null)
setList(null)
api.workflows.versions(workflow.id).then(setList).catch(setError)
}
// 保存一次就多一版:跟着 workflow.version 重新取
useEffect(load, [workflow.id, workflow.version])
// Esc 收起,和属性面板一样
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== 'Escape' || e.defaultPrevented) return
const el = document.activeElement
if (el instanceof HTMLElement && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA')) return
onClose()
}
window.addEventListener('keydown', onKey)
return () => window.removeEventListener('keydown', onKey)
}, [onClose])
useEffect(() => {
if (picked == null) return
let alive = true
setDetail(null)
api.workflows.version(workflow.id, picked)
.then((v) => { if (alive) setDetail({ v: picked, graph: v.graph ?? { nodes: [], edges: [] }, version: v }) })
.catch((e) => { if (alive) setDetail({ v: picked, error: e }) })
return () => { alive = false }
}, [workflow.id, picked])
const graph = detail && 'graph' in detail ? detail.graph : null
const target = useMemo(() => (graph ? toFlow(graph) : null), [graph])
const diff = useMemo(() => (target ? diffGraphs({ nodes, edges }, target) : null), [target, nodes, edges])
const restore = () => {
if (!graph || picked == null) return
restoreVersion(picked, graph)
toast(`已将 v${picked} 恢复到画布,保存后生效`, 'ok', {
key: 'studio:restore', duration: 8000, action: { label: '撤销', onClick: () => undo() },
})
onClose()
}
return (
<div className="sheet-in absolute inset-0 z-30 flex flex-col bg-panel"
style={{ boxShadow: 'var(--elev-3)' }} role="dialog" aria-label="版本历史">
<div className="flex items-center gap-1.5 border-b px-2 py-2">
<button
type="button"
className="flex items-center gap-0.5 rounded-md px-1 py-1 text-faint transition-colors hover:bg-hover hover:text-fg"
title="返回(Esc)" onClick={onClose}
>
<ChevronLeft size={14} />
<span className="text-2xs">助手</span>
</button>
<span className="mx-0.5 h-3.5 w-px shrink-0" style={{ background: 'var(--border)' }} />
<History size={13} className="shrink-0 text-faint" />
<span className="flex-1 truncate text-xs font-semibold" title={hintOf('版本历史', 'history')}>版本历史</span>
<span className="tnum text-2xs text-faint">{list ? `共 ${list.length} 个版本` : ''}</span>
</div>
<div className="min-h-0 flex-1 overflow-y-auto">
{error ? <ErrorState error={error} onRetry={load} compact className="m-3" />
: !list ? <div className="p-3"><Skeleton rows={4} height={30} /></div>
: (
<ol className="p-1.5" aria-label="版本">
{list.map((v) => {
const current = v.version === workflow.version
const published = v.version === workflow.published_version
const open = picked === v.version
return (
<li key={v.id} className="mb-0.5">
<button
type="button"
aria-expanded={open}
onClick={() => setPicked(open ? null : v.version)}
className={clsx('flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors',
open ? 'bg-hover' : 'hover:bg-hover')}
>
<span className="mono tnum mt-px w-7 shrink-0 text-xs font-semibold">v{v.version}</span>
<span className="min-w-0 flex-1">
<span className={clsx('block truncate text-xs', v.note ? 'text-fg' : 'text-faint')}>
{v.note || '(无说明)'}
</span>
<span className="mt-0.5 flex flex-wrap items-center gap-1 text-2xs text-faint">
<span title={formatDateTime(v.created_at)}>{formatTime(v.created_at)}</span>
{current && <span className="chip">{dirty ? '画布基于此版本' : '当前画布版本'}</span>}
{published && (
// 按这一版自己的级别写:画布上改过之后 status 回到草稿,受管发布版照实写「受管」。老数据没记级别的
// 退回看工作流当前发布版的级别
<span className="chip" style={{ color: 'var(--ok)', borderColor: 'var(--ok)' }}
data-version-published={v.level ?? publishedLevelOf(workflow)}>
<ShieldCheck size={9} />
{WORKFLOW_STATUS_LABEL[v.level ?? publishedLevelOf(workflow)]}
</span>
)}
{!published && v.level && !v.retired_at && (
<span className="chip" data-version-level={v.level}>{WORKFLOW_STATUS_LABEL[v.level]}</span>
)}
{v.retired_at && (
<span className="chip" style={{ color: 'var(--st-waiting)' }} data-version-retired-chip="">
{VERSION_USAGE_TEXT.retired}
</span>
)}
</span>
{/* 谁、什么时候退的,退役时写的说明:列表上直接看得到,不用逐个点开 */}
{v.retired_at && (
<span className="mt-0.5 block">
<RetiredNote by={v.retired_by} at={v.retired_at} note={v.retire_note} />
</span>
)}
</span>
</button>
{open && (
<div className="fade-up mx-2 mb-2 mt-1 rounded-md border bg-bg p-2">
{!detail ? <Skeleton rows={3} height={12} />
: 'error' in detail ? <ErrorState error={detail.error} compact />
: target && diff && (
<>
<VersionPreview version={v.version} target={target} diff={diff}
lock={lock} onRestore={restore} />
{detail.version.catalog_versions && (
<CatalogVersions versions={detail.version.catalog_versions}
changes={detail.version.catalog_changes ?? []} />
)}
<VersionLifecycle workflowId={workflow.id} version={detail.version}
current={v.version === workflow.published_version}
onRetired={() => { load(); setPicked(null) }} />
</>
)}
</div>
)}
</li>
)
})}
</ol>
)}
</div>
<div className="border-t px-3 py-2 text-2xs leading-relaxed text-faint">
恢复操作仅将旧版本载入画布,可撤销;保存后才会生成新版本。
{workflow.published_version != null && '已发布的版本不受影响,正式运行仍使用该版本。'}
</div>
</div>
)
}
function VersionPreview({ version, target, diff, lock, onRestore }: {
version: number; target: { nodes: FlowNode[]; edges: Edge[] }; diff: GraphDiff
lock: EditLock; onRestore: () => void
}) {
const current = useStudio((s) => s.nodes)
const same = diff.total === 0
const label = (id: string, pool: FlowNode[]) => pool.find((n) => n.id === id)?.data.label || id
const lines = [
...diff.added.map((id) => ({ kind: 'add' as const, text: label(id, target.nodes) })),
...diff.removed.map((id) => ({ kind: 'del' as const, text: label(id, current) })),
...diff.changed.map((id) => ({ kind: 'mod' as const, text: label(id, target.nodes) })),
]
return (
<div>
<MiniGraph target={target} current={current} diff={diff} />
{same ? (
<div className="mt-2 text-2xs text-faint">与当前画布相同(节点位置可能不同)</div>
) : (
<>
<div className="mt-2 text-2xs text-dim">恢复后与当前画布相比:</div>
<ul className="mt-1 space-y-0.5 text-2xs">
{lines.slice(0, 8).map((l, i) => (
<li key={i} className="flex items-center gap-1.5">
<span className="mono w-3 shrink-0 text-center" style={{ color: DIFF_COLOR[l.kind] }}>
{l.kind === 'add' ? '+' : l.kind === 'del' ? '−' : '~'}
</span>
<span className="min-w-0 flex-1 truncate">{l.text}</span>
<span className="shrink-0 text-faint">{l.kind === 'add' ? '将恢复' : l.kind === 'del' ? '将移除' : '配置不同'}</span>
</li>
))}
{lines.length > 8 && <li className="text-faint">还有 {lines.length - 8} 处…</li>}
{(diff.edgesAdded > 0 || diff.edgesRemoved > 0) && (
<li className="text-faint">
连线 {diff.edgesAdded ? `+${diff.edgesAdded}` : ''}{diff.edgesAdded && diff.edgesRemoved ? ' ' : ''}{diff.edgesRemoved ? `−${diff.edgesRemoved}` : ''}
</li>
)}
</ul>
</>
)}
<button type="button" className="btn btn-sm mt-2 w-full justify-center" disabled={same || lock != null}
title={lock ? EDIT_LOCK_TEXT[lock] : undefined} onClick={onRestore}>
<RotateCcw size={11} /> 恢复 v{version} 到画布
</button>
</div>
)
}
const DIFF_COLOR = { add: 'var(--ok)', del: 'var(--err)', mod: 'var(--warn)' } as const
/**
* 发布过的版本:被哪些应用固定、生效记录和正式运行各有多少(L4),问数回答、导出、召回(next-round 02 做法 8),口径升到
* 这一版之后的召回批次,做成应用,以及退役(A1)。草稿版本都没有,不画。
* 退役之后这一版不能再发起正式运行,也不能再做成应用(应用只能固定已发布且未退役的版本);固定它的应用标「需升级」,
* 进行中的实例照常走完。退役的人、时间和说明写在列表那一行上,这里不再重复
*/
function VersionLifecycle({ workflowId, version, current, onRetired }: {
workflowId: string; version: WorkflowVersion; current: boolean; onRetired: () => void
}) {
const navigate = useNavigate()
const publishedLevel = !!version.level || current
const usage = useVersionUsage(workflowId, publishedLevel ? version.version : null)
// 退役只给管理员(Q8);关登录时所有人等同管理员。做成应用给搭建者及以上(同应用首页的「新建应用」)
const admin = useAtLeast('admin')
const builder = useAtLeast('builder')
if (!publishedLevel) return null
const blocked = retireBlocked({ current, publishedLevel, retired: !!version.retired_at, admin })
return (
<div className="mt-3 border-t pt-2 text-2xs" data-version-lifecycle={version.version}>
<div className="font-medium text-dim">{VERSION_USAGE_TEXT.usage}</div>
<div className="mt-1">
{usage ? <VersionUsageLine usage={usage} /> : <span className="text-faint">…</span>}
</div>
{/* 口径升到这一版之后的召回批次:每组的结论、「另有 M 组未重算」、接着算(next-round 02 做法 7) */}
<RecallBatches workflowId={workflowId} version={version.version} />
{!version.retired_at && (
<>
{builder && (
<button type="button" className="btn btn-sm mt-2 w-full justify-center" title={VERSION_USAGE_TEXT.makeAppHint}
data-version-make-app={version.version}
onClick={() => navigate(newAppPath({ workflow: workflowId, version: version.version }))}>
<LayoutGrid size={11} aria-hidden /> {VERSION_USAGE_TEXT.makeApp}
</button>
)}
<button type="button" className="btn btn-sm mt-2 w-full justify-center" disabled={!!blocked}
title={blocked ?? undefined} data-version-retire={version.version}
onClick={async () => { if (await retireVersion(workflowId, version.version, usage)) onRetired() }}>
<Archive size={11} aria-hidden /> {VERSION_USAGE_TEXT.retire}
</button>
{blocked && <div className="mt-1 text-faint">{blocked}</div>}
</>
)}
</div>
)
}
/**
* 发布时的目录版本:这一版用到的表在发布时是数据目录的第几版,之后改过的标出来——下次从这一版发起正式运行时会
* 提醒「数据目录有变化」,这里先让人看到是哪几张表。
*
* 每张表和运行横幅同一个写法:「数据源」中文名(表名)。发布记录里只有数据源名和表名,中文名按数据源的目录清单补
* (变了的表服务端带着现在的中文名);取不到清单时只写表名。
*
* 两组分开列:SQL 里写着的表在前;Agent 可能查询的表(Agent 绑定了数据源的查询工具,发布时记下数据源中所有有
* 目录的表)在小标题下面。可能涉及的数据源里发布之后新建了目录的表,记录里没有它,按变化里给的补进来(发布时
* 「尚无目录」)
*/
function CatalogVersions({ versions, changes }: { versions: CatalogVersionsRecord; changes: CatalogDriftTable[] }) {
const labelOf = useCatalogLabels(versions, changes)
// 老后端给的变化没有 impact:按直接引用
const impactOf = (c: CatalogDriftTable) => (c.impact === 'possible' ? 'possible' : 'direct')
const changed = new Map(changes.map((c) => [`${impactOf(c)}/${c.source}/${c.table}`, c]))
const rowsOf = (impact: CatalogDriftTable['impact']) => {
const recorded = Object.entries(versions[impact] ?? {}).flatMap(([source, tables]) =>
Object.entries(tables).map(([table, v]) => ({ source, table, v: v as number | null })))
const known = new Set(recorded.map((r) => `${r.source}/${r.table}`))
const added = changes.filter((c) => impactOf(c) === impact && !known.has(`${c.source}/${c.table}`))
.map((c) => ({ source: c.source, table: c.table, v: c.published }))
return [...recorded, ...added]
}
const direct = rowsOf('direct')
const possible = rowsOf('possible')
const bare = Object.entries(versions.possible ?? {})
.filter(([source, tables]) => !Object.keys(tables).length && !possible.some((r) => r.source === source))
.map(([source]) => source)
const list = (impact: CatalogDriftTable['impact'], rows: typeof direct) => (
<ul className="mt-1 space-y-0.5 text-2xs">
{rows.map(({ source, table, v }) => {
const c = changed.get(`${impact}/${source}/${table}`)
return (
<li key={`${source}/${table}`} className="flex min-w-0 flex-wrap items-baseline gap-x-1.5"
data-version-catalog-table={table} data-impact={impact} data-changed={c ? 'true' : undefined}>
<span className="min-w-0 break-words" title={`${source} · ${table}`} data-version-catalog-name="">
「{source}」{CATALOG_DRIFT_TEXT.table(labelOf(source, table) ?? c?.label ?? null, table)}
</span>
<span className="shrink-0 text-faint">{CATALOG_DRIFT_TEXT.version(v)}</span>
{c && (
<span className="shrink-0" style={{ color: 'var(--st-waiting)' }}>
{CATALOG_DRIFT_TEXT.changedSince(CATALOG_DRIFT_TEXT.version(c.current))}
</span>
)}
</li>
)
})}
</ul>
)
const empty = !direct.length && !possible.length && !bare.length
return (
<div className="mt-3 border-t pt-2" data-version-catalog={changes.length}>
<div className="text-2xs font-medium text-dim" title={CATALOG_DRIFT_TEXT.sectionHint}>{CATALOG_DRIFT_TEXT.section}</div>
{empty ? <div className="mt-1 text-2xs text-faint">{CATALOG_DRIFT_TEXT.empty}</div> : (
<>
{direct.length > 0 && list('direct', direct)}
{(possible.length > 0 || bare.length > 0) && (
<div className="mt-1.5" data-version-catalog-possible={possible.length}>
<div className="text-2xs text-dim" title={CATALOG_DRIFT_TEXT.possibleHint}>{CATALOG_DRIFT_TEXT.possibleHead}</div>
{possible.length > 0 && list('possible', possible)}
{bare.map((source) => (
<div key={source} className="mt-0.5 text-2xs text-faint">{CATALOG_DRIFT_TEXT.possibleNone(source)}</div>
))}
</div>
)}
<div className="mt-1 text-2xs" style={{ color: changes.length ? 'var(--st-waiting)' : undefined }}>
<span className={changes.length ? undefined : 'text-faint'}>
{changes.length ? CATALOG_DRIFT_TEXT.changedCount(changes.length) : CATALOG_DRIFT_TEXT.unchanged}
</span>
</div>
</>
)}
</div>
)
}
/** 数据源 id → 表名 → 中文名。几个版本、几次展开共用,同一个数据源只取一次清单 */
const labelCache = new Map<string, Promise<Record<string, string | null>>>()
/**
* 发布记录里各表现在的中文名:按数据源名找到 id(变化里带着 source_id,否则查数据源列表),取那个数据源的目录清单。
* 取不到(数据源删了、没权限、断网)就只写表名,不报错——这一栏是附带的说明
*/
function useCatalogLabels(versions: CatalogVersionsRecord, changes: CatalogDriftTable[]): (source: string, table: string) => string | null {
const { list: sources } = useDatasources()
const [labels, setLabels] = useState<Record<string, Record<string, string | null>>>({})
const got = useRef(labels)
got.current = labels
const names = useMemo(() => [...new Set([...Object.keys(versions.direct ?? {}), ...Object.keys(versions.possible ?? {}),
...changes.map((c) => c.source)])], [versions, changes])
useEffect(() => {
let alive = true
for (const name of names) {
const id = changes.find((c) => c.source === name && c.source_id)?.source_id ?? sources.find((x) => x.name === name)?.id
if (!id || got.current[name]) continue
let pending = labelCache.get(id)
if (!pending) {
pending = api.dataCatalog.list(id).then((d) => Object.fromEntries(d.tables.map((t) => [t.table_name, t.label])))
labelCache.set(id, pending)
// 清单会变(有人补了中文名):只缓存这一阵子,失败的不缓存
pending.then(() => setTimeout(() => labelCache.delete(id), 60_000), () => labelCache.delete(id))
}
pending.then((m) => { if (alive) setLabels((cur) => ({ ...cur, [name]: m })) }, () => {})
}
return () => { alive = false }
}, [names, changes, sources])
return (source, table) => labels[source]?.[table] ?? null
}
/**
* 缩略图:这一版的节点按真实坐标缩进一个小框,类型色填充;恢复后会被拿掉的
* (只在画布上有)画成红色虚框叠在同一个坐标系里,改过配置的描琥珀边
*/
function MiniGraph({ target, current, diff }: {
target: { nodes: FlowNode[]; edges: Edge[] }; current: FlowNode[]; diff: GraphDiff
}) {
const W = 280
const H = 120
const ghosts = current.filter((n) => diff.removed.includes(n.id))
const all = [...target.nodes, ...ghosts]
if (!all.length) return <div className="py-4 text-center text-2xs text-faint">此版本为空</div>
const nw = 238
const nh = 80
const x0 = Math.min(...all.map((n) => n.position.x))
const y0 = Math.min(...all.map((n) => n.position.y))
const x1 = Math.max(...all.map((n) => n.position.x + nw))
const y1 = Math.max(...all.map((n) => n.position.y + nh))
const k = Math.min((W - 8) / Math.max(1, x1 - x0), (H - 8) / Math.max(1, y1 - y0))
const ox = (W - (x1 - x0) * k) / 2
const oy = (H - (y1 - y0) * k) / 2
const pos = (n: FlowNode) => ({ x: ox + (n.position.x - x0) * k, y: oy + (n.position.y - y0) * k })
const byId = new Map(target.nodes.map((n) => [n.id, n]))
const added = new Set(diff.added)
const changed = new Set(diff.changed)
return (
<svg viewBox={`0 0 ${W} ${H}`} className="block w-full" role="img"
aria-label={`缩略图:${target.nodes.length} 个节点`} style={{ background: 'var(--bg-panel)', borderRadius: 4 }}>
{target.edges.map((e, i) => {
const a = byId.get(e.source)
const b = byId.get(e.target)
if (!a || !b) return null
const p = pos(a)
const q = pos(b)
const sx = p.x + nw * k
const sy = p.y + (nh * k) / 2
const tx = q.x
const ty = q.y + (nh * k) / 2
const mx = (sx + tx) / 2
return <path key={i} d={`M${sx},${sy} H${mx} V${ty} H${tx}`} fill="none" strokeWidth={0.8}
style={{ stroke: 'var(--border-strong)' }} />
})}
{target.nodes.map((n) => {
const p = pos(n)
const tone = added.has(n.id) ? DIFF_COLOR.add : changed.has(n.id) ? DIFF_COLOR.mod : null
return (
// 颜色走 style:SVG 的呈现属性不认 var()
<rect key={n.id} x={p.x} y={p.y} width={nw * k} height={nh * k} rx={2}
className={`nt-${n.data.nodeType}`} strokeWidth={tone ? 1.4 : 0.6}
style={{ fill: 'color-mix(in srgb, var(--nt) 30%, var(--bg))',
stroke: tone ?? 'color-mix(in srgb, var(--nt) 60%, transparent)' }}>
<title>{n.data.label || n.id}</title>
</rect>
)
})}
{ghosts.map((n) => {
const p = pos(n)
return (
<rect key={`g-${n.id}`} x={p.x} y={p.y} width={nw * k} height={nh * k} rx={2}
fill="none" strokeWidth={1.2} strokeDasharray="3 2" style={{ stroke: DIFF_COLOR.del }}>
<title>{`恢复后将移除:${n.data.label || n.id}`}</title>
</rect>
)
})}
</svg>
)
}