feat: add editorial diagram component (diagram-design port, 27 kinds) - #9
feat: add editorial diagram component (diagram-design port, 27 kinds)#9yeruizhi wants to merge 2 commits into
diagram component (diagram-design port, 27 kinds)#9Conversation
Port the diagram-design editorial design system into a first-class dsh-genui component: 27 visual kinds rendered as inline SVG with the constraints hard-coded in the renderer. - spec.ts: GenuiDiagram node types + DIAGRAM_KINDS (27 kinds) - guard.ts: complexity budget (<=9 nodes / <=12 edges), 4px-grid rounding, kind whitelist, node/edge cleaning, theme color safety - blocks/diagram/: semantic-token theme, orthogonal-connector geometry, layout engine (coordinate + rule kinds), SVG renderer with a11y shell - render-node.tsx: `diagram` case in the white-list dispatcher - plugin/index.ts + SKILL.md: model teaching for the new component - tests: guard (8) + rendering (7) — all 27 kinds render, zero regression Design doc: docs/diagram-component-design.md PR notes: docs/diagram-pr.md
测试与构建说明(供 reviewer)Diagram 测试(15/15 通过),以 全量测试差异(本地 Node 26 环境):
失败集中在 说明: 本 PR 只改 src 与文档,不含 lib/ 构建产物—— |
…gend Bring the renderer visually in line with the diagram-design editorial system: - dotted-paper ground pattern behind every diagram - zone containers (hairline dashed rect + mono eyebrow label), max 3 - 64px node ramp with tag / name / sublabel / index numeral - legend strip at the bottom with treatment swatches - accent arrows drawn heavier (1.4) as the focal signal - spec gains GenuiDiagramZone (guarded + validated)
v2 更新:编辑级渲染升级根据视觉对比反馈,将渲染器升级到与 diagram-design 原版对齐:
测试 17/17 通过(新增 zone/legend、dotted-paper 断言)。请重新 review 最新提交 b8e8519。 |
taekchef
left a comment
There was a problem hiding this comment.
@yeruizhi 先说结论:产品上我们拍板了——diagram 走核心白名单组件路线是对的,这个 PR 值得合。注册组件路线只覆盖契约线宿主、且拿不到 guard 安检,核心路线才能让原版 DSH 用户也用上、并白赚流式渲染/自愈/面板预算。代码质量和测试都不错,本地全套 285 passed / 102 skipped 全绿 ✅
合之前请补 4 项(都不大):
-
补完整构建产物:CI 现在是挂在「lib 与 src 不一致」这道门上的——
src/plugin/index.ts、src/client/spec.ts、src/client/guard.ts变了,但lib/types/*.d.ts没重跑。请运行pnpm run build,把lib/client.js、lib/index.js、lib/types/**的全部变更一起提交。 -
版本号 + CHANGELOG:仓库惯例是每个要发布的 PR 都动版本并写 changelog。这是新增组件,建议版本 0.9.0,在 CHANGELOG 顶部加一条
[0.9.0]:新增diagram组件(27 种 kind、正交连接器、语义 token、复杂度预算、light/dark/editorial)。 -
删掉
docs/diagram-pr.md:那是 PR 说明文档,一般不进仓库正文;docs/diagram-component-design.md的设计文档保留即可。PR 描述里已经有对应内容,不会丢。 -
修一下 a11y 的重复 id:
DiagramNode里标题存在时,<figcaption id={titleId}>和 SVG 里的<title id={titleId}>会同时出现两个相同 id。建议 figcaption 用${uid}-caption(或干脆不给 figcaption 设 id),SVG<title>继续用${uid}-title,让aria-labelledby稳定指向<title>。
另外 main 刚合入 #14(issue #13),lib/client.js 有冲突,麻烦顺手 rebase 到最新 main 再推。
补完这 4 项我们立刻合,辛苦啦 🙏
PR: 新增
diagram组件——编辑级品牌图(diagram-design 移植)1. 概述
新增
diagram组件:让模型在 ```dsh-ui 围栏里直接输出编辑级品牌图——27 种视觉类型(架构图、流程图、时序图、状态机、ER、泳道、雷达、循环、
树、层叠、维恩、金字塔、甘特、散点、数据流、安全矩阵等),由浏览器端
渲染器按 diagram-design 的编辑级规范生成内联 SVG。
与现有
mermaid的分工:mermaid= 自动布局的通用图(模型只给源码,引擎排版);diagram= 编辑级排版(正交连接器、语义 token、焦点色预算、复杂度预算全部由渲染器强制,模型无法产出"AI slop"示意图)。
2. 改动面
src/client/spec.tsGenuiDiagram/GenuiDiagramNode/GenuiDiagramEdge/GenuiDiagramTheme类型与DIAGRAM_KINDS(27 种)常量;并入GenuiNode联合src/client/guard.tsmaxDiagramNodes=9等);repairGenuiSpec的diagram分支(4px 网格取整、kind 白名单、节点/边清洗、主题色安全过滤);validateGenuiSpec校验src/client/blocks/diagram/theme.tstheme覆盖;节点类型→填充/描边;边语义→颜色src/client/blocks/diagram/geometry.tssrc/client/blocks/diagram/layout.tssrc/client/blocks/diagram/index.tsxDiagramNodeReact 组件:SVG 渲染、a11y 外壳(role="img"+aria-labelledby+aria-describedby)、焦点预算、z-ordersrc/client/blocks/render-node.tsxcase 'diagram'接入渲染分发src/plugin/index.tsGENUI_SECTION_TEXT增加diagram教学行;组件选择规则更新SKILL.mddiagram组件规范、kind 表、与 mermaid 的分工tests/genui-diagram-guard.spec.tstests/genui-diagram.spec.tsxdocs/diagram-component-design.md3. 设计决策
3.1 为什么是核心白名单组件而非插件注册组件
dsh-genui 提供
registerGenuiComponent协议(插件注册自定义类型),但:diagram自动获得 guard 清洗、流式渲染、持久化、自愈;结论:走核心路径(spec.ts + render-node switch),与
mermaid/plot同级。3.2 声明式 spec:模型给数据,渲染器给设计
模型不写 SVG path,只声明节点(坐标或数据)+ 边。布局与样式全部编码进
渲染器——这正是 diagram-design "规则由系统强制"理念的移植:模型无法选择
斜线连接器、无法把 accent 用到 4 个节点、无法超过复杂度预算。
3.3 双布局模式
data-flow / dp-integration):模型给 x/y/w/h,渲染器正交连线。
(column / row / layer / tree / grid)。
v1 的规则类布局是"最小可用"泛化布局;每种 kind 的精细排版(swimlane 分栏、
sequence 激活条、radar 网格等)留到 v2(见 §7)。
3.4 编辑级约束全部硬编码
正交连接器、4px 网格、语义 token、焦点 ≤2、复杂度预算、z-order、边标签
6-10px 间隙、无阴影无发光——全部是渲染器行为,spec 无法绕过。设计文档
§6 列出了完整的强制清单。
4. 测试
<svg role="img">不抛错。5. 回归与已知环境问题
本 PR 在本地以
DSH_ROOT=/Users/xpeng/deepseek-harness运行:失败测试(genui-panel / panel-append / dom-fence 等)在本 PR 之前已存在,
根因是 Node ≥22 的
localStorage实验性行为(--localstorage-file未提供时localStorage为 undefined),与diagram无关。CI 若在 Node LTS(≤20)下运行不受影响;建议上游在 CI 或测试 setup 中为 jsdom 补 localStorage polyfill。
6. 使用示例
7. 范围与后续迭代(v2,不在本 PR)
gantt 时间轴、venn 圆交叠计算、quadrant 象限定位)。
editorial变体精修、sketchy/terminal皮肤。scripts/*.py)。8. 上游致谢
设计系统移植自 cathrynlavery/diagram-design
(MIT, v2.4)。组件名、kind 枚举、语义 token 与强制规则均对齐其 SKILL.md 与
references/规范,以便双向同步。