Skip to content

feat(ui-plugins): add Design To Components (design-to-components) - #245

Open
ppppp2005-p wants to merge 10 commits into
zai-org:mainfrom
ppppp2005-p:feat/design-to-components
Open

ppppp2005-p wants to merge 10 commits into
zai-org:mainfrom
ppppp2005-p:feat/design-to-components

Conversation

@ppppp2005-p

Copy link
Copy Markdown

Plugin type (required) / 插件类型(必填)

  • UI Plugin / 是 UI 插件 — provides MCP Apps interactive pages / 提供 MCP Apps 交互页面
  • Standard plugin / 普通插件(非 UI)
  • Not applicable / 不适用

Affected plugin name(s) / 涉及的插件名称:design-to-components (UI Plugin, new)

What / 改动内容

New community UI plugin Design To Components / 设计稿转组件库: design → design tokens + a component checklist → React TSX components written by the agent → type-checked, rendered per state next to the design, and bundled into an interactive catalog.

Tools:

  • dc_new, dc_tokens, dc_plan, dc_write, dc_build.
  • App-only: dc_state, dc_file, dc_design, workspace_images.

Pipeline (run on every write):

  • TypeScript type-check (typescript 6, bundled): runs in memory with strict mode, react-jsx and bundler resolution. React 19 types (@types/react + csstype) and TS lib .d.ts files are shipped in dist/types. *.css imports are declared.
  • esbuild-wasm (shipped as a package in dist/node_modules, marked external) does two bundles from a virtual file system:
    • An SSR bundle (cjs, React external).
    • A browser catalog bundle (iife, minified). React comes from a prebuilt vendor/react.js (production) via globalThis.__dc, and CSS imports are bundled.
    • Imports other than react/react-dom or kit files are errors.
  • Rendering: the SSR bundle is evaluated in node:vm with timeouts, and every examples[i].render() goes through renderToStaticMarkup. Render errors are reported per example.
  • Convention checks:
    • src/<Name>.tsx must export <Name>, and examples should exist.
    • Each planned state needs an example.
    • Hard-coded hex/rgb colours in .css/.tsx are flagged (var() is ignored).
  • Outputs: tokens.css / tokens.ts (from tokens.json, validated: names, colours, lengths), index.ts barrel, and a self-contained catalog/index.html that works from file://, with a dark-background toggle.

Panel:

  • Design image | static preview (sandboxed srcdoc, no scripts) with code tabs | checklist (✓ / ✗ / ○ and example counts), problems (file:line links open the code), and a token editor with colour pickers.

Size: the server bundle is ~12.6 MB (TypeScript), plus esbuild-wasm (~14 MB, mostly the wasm), React types / TS libs (~4 MB) and the React vendor bundle (220 KB).

Network / API / side effects: none. No API keys. Writes ui-kit/<name>/ and .design-to-components/project.json. No hooks.

Third-party: react, react-dom, @types/react, csstype, typescript (Apache-2.0), esbuild-wasm, MCP SDK / ext-apps, zod (all MIT unless noted).

Tests: the sample is a fictional "Fieldnote UI" design (HTML mock → PNG) with agent files for tokens, Button / TextField / Badge / Card, and a first-draft Button with planted errors.

  • vitest:
    • Token CSS / TS generation and validation.
    • The type-checker accepts hooks and catches onClik and the wrong prop type with line numbers.
    • Full flow:
      • The first draft gives 2 TS errors, missing-state warnings and the hard-coded colour.
      • The final kit has 0 issues: plan all done, 4/2/3/2 examples, SSR markup with aria attributes, CSS bundled, catalog with vendor React and tokens, and the index barrel.
      • Bad package import, render exception and missing export are each reported; delete works; a path escape is refused.
      • A token update reaches the preview; an invalid colour is refused.
  • Chrome e2e (bundled server; official AppBridge host):
    1. The user creates the kit from the design.
    2. The agent sets tokens and the plan, and writes the bad Button: 2 errors are shown, and clicking an error opens the code.
    3. The agent writes all components: "compiles", the preview shows every state with the token colour (computed style checked), and 4 ✓.
    4. The user changes the primary colour token, and the preview colour changes.
    5. The catalog opened from file:// is interactive (typing, dark toggle) with no errors.
    6. The panel has no console errors.
  • validate.py, build_dist.py, git diff --check and tsc pass.

A ZCode Desktop demo recording is attached in the comments. / ZCode 桌面版演示录屏见评论。

Self-check / 自查清单

  • Plugin name is unique kebab-case; new external plugin directory is external_plugins/<name>/
  • Usage category is set (productivity)
  • Plugin type and affected names are declared above
  • version 0.1.0 in both plugin.json and marketplace.json
  • README.md (EN) and README_CN.md (中文) both provided and equivalent
  • description_i18n has both en and zh-CN
  • No secrets, machine-specific paths, or private dependencies
  • Model/API/network dependencies documented
  • python3 scripts/validate.py and python3 scripts/build_dist.py pass locally
  • Exercised in ZCode Desktop (ZCode 4.0.0, macOS arm64: installed from a local marketplace, installed from a local marketplace, dc_new from a design image → panel → dc_tokens → dc_plan (Button/TextField/Card/Badge with states) → dc_write into src/ + tokens.css/ts + catalog → dc_build: compiled, 4/4 components; demo video in the comments; demo video in the comments)

@ppppp2005-p

Copy link
Copy Markdown
Author

ZCode desktop demo (ZCode 4.0.0, macOS arm64)

design-to-components-demo.mp4

Flow shown:

  1. Installed design-to-components from a local marketplace built from this PR's branch.
  2. Asked ZCode to build a React component library "fieldnote" from the design image components/fieldnote-design.png: extract design tokens, plan Button, TextField, Card and Badge, write them straight into src/, preview, and report the output folder and check result.
  3. The agent called dc_new (side panel: library name and folder, compile status, "compare with design", component checklist, editable design tokens), recorded the 9 colours annotated in the design with dc_tokens, then measured the remaining values from the image (badge/disabled/loading colours, sizes, padding) and planned the four components and their states with dc_plan (Button: primary / secondary / disabled / loading; TextField: default / error; Card; Badge: success / warning / neutral). This measuring took most of the 33-minute run.
  4. dc_write wrote src/Button.tsx / .css, TextField, Card and Badge, plus tokens.json → tokens.css / tokens.ts (16 colours, 5 font sizes, 12 spacing steps, 3 shadows), index.ts and catalog/index.html, and dc_build compiled everything: all four components ticked and the panel shows "编译通过". The agent also removed preset tokens that the design doesn't use. The last card shows the design next to the panel.

演示流程:本地 marketplace 安装 → dc_new 打开面板 → dc_tokens 提取设计令牌 → dc_plan 规划 4 个组件及状态 → dc_write 写入 src/ → dc_build 编译通过。

@panda920

Copy link
Copy Markdown
Collaborator

✅ Internal validation passed. A ZCode maintainer will review the change next; after acceptance, release checks run separately and this PR is closed automatically.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants