mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
feat: Copy and paste tokens across projects (#6660)
Closes #5727 Copy a design token from its menu and paste it into another project or the style source input. Paste creates and attaches a new numbered token (for example, `Button copy 1`). It carries all breakpoint styles, referenced CSS variables, images, and fonts, and creates missing breakpoints. MCP offers the same copy and paste commands; `instanceId` attaches the token when supplied. The clipboard format is CSS with one `@webstudio/token-css/v1` comment. The old JSON format is removed. HTML and CSS use the same Webstudio pragma parser, and token CSS reuses the existing CSS declaration parser. Builder and MCP share token copy, parsing, paste, fragment asset import, and asset reference remapping. The latest cleanup also reuses the existing copy-name helper. Repeated Builder pastes reuse the existing content-hash asset deduplication path, including SVG and fonts. The source bytes still download and hash on each paste. MCP downloads and uploads asset bytes on each paste, using the upload path's deduplication; both projects must use the same Webstudio origin for assets. - [x] Implement CSS token copy and paste in Builder and MCP, including selection attachment and numbered names. - [x] Preserve breakpoint styles, variable dependencies, image and font assets, and missing breakpoints. - [x] Detect token CSS pasted into the style source input. - [x] Remove the JSON transfer format and update Builder and MCP documentation. - [x] Reuse CSS parsing, asset transfer, naming, and existing upload deduplication paths. - [x] Resolve review findings, including shorthand variables and selector state positions. - [x] Verify focused tests, typechecks, lint, formatting, package boundaries, and the approved Storybook visual check. - [x] Trace existing CSS editor and HTML paste flows; reuse their parser, declaration mapper, and CSS variable reference collector. - [x] Preserve breakpoint cascade order when copying equal media conditions; add a regression and resolve the review thread. - [x] Share CSS variable traversal between collection and renaming; preserve nested fallbacks and resolve the review comment. - [x] Discover and remap image URLs inside raw variable fallbacks; share the CSS value traversal and resolve the review comment. - [x] Preserve fallback variables in mixed shorthands and custom non-pixel breakpoint styles; add regressions and resolve review threads. - [x] Preserve combined width and custom media conditions in token CSS; add a regression and resolve the review thread. - [x] Preserve range-syntax custom breakpoints in token CSS; add a regression and resolve the review thread. - [x] Preserve negated custom and width media conditions; add regressions and resolve the review thread. - [x] Preserve boolean operators between width conditions; add a regression and resolve the review thread. - [x] Monitor required CI checks for the latest commit. - [x] Reuse the existing asset usage collector for copied token image and font dependencies; verify token and asset usage tests. - [x] Review documentation impact of this internal refactor (none; no user-facing behavior or contract changed). The reuse audit traced CSS editor, HTML paste, instance/page paste, asset usage, and MCP from input to state change. Token copy now uses the existing asset usage collector for image and variable-backed font dependencies. CSS parsing, declaration mapping, variable traversal, breakpoint matching, asset import/remapping, copy naming, and Builder/MCP token mutation also have shared owners. Fragment insertion may reuse tokens and merge overflow breakpoints; token paste must always create a numbered copy and report overflow. The regex-based rename path remains for arbitrary authored text; token transfer uses syntax-aware rewriting to avoid changing text outside `var()`. The asset collector refactor changes no user-facing behavior. The follow-up parser fixes keep fallback variables, non-pixel breakpoint styles, and combined media conditions, range syntax, negation, and width-condition operators intact when copied. No documentation or fixture inputs changed. Focused token, asset usage, HTML, and CSS parser tests, affected typechecks, lint, formatting, package boundaries, and `git diff --check` passed. Agent evaluations were offered and declined.
This commit is contained in:
1 parent
ee277769ff
commit
1b9ae61fa1
51 files changed
+3825
-267
No files matched your search
@@ -63,6 +63,10 @@ If an imported name conflicts with an existing token, choose how to continue:
|
||||
Review imported tokens and CSS variables before applying them throughout the
|
||||
Project, especially when the source contains multiple modes or aliases.
|
||||
|
||||
## Copy tokens between projects
|
||||
|
||||
Open a token’s menu and choose Copy. Select an instance in another project, then paste. Webstudio attaches a new token named “Button copy 1” (or the next available number) to that instance, with the source token’s breakpoint styles, referenced CSS variables, image assets, and fonts. Missing breakpoints are created.
|
||||
|
||||
## How to use tokens <a href="#how-to-use-tokens-in-webstudio" id="how-to-use-tokens-in-webstudio"></a>
|
||||
|
||||
The workflow for styling Tokens in Webstudio is nearly the same as styling classes in Webflow, except better.
|
||||
|
||||
@@ -62,6 +62,10 @@ While the server is running, stdout is reserved for MCP JSON-RPC messages. Do no
|
||||
|
||||
## One-Shot Tool Calls
|
||||
|
||||
### Token transfer
|
||||
|
||||
Use `copy-design-token` with `tokenId` to get a transfer payload. Pass that payload as `data` to `paste-design-token` in the target project. Set `instanceId` to attach the new token to an instance; without it, paste creates the token without attaching it. Each paste creates the next numbered copy. Image and font assets transfer when both projects use the same Webstudio origin.
|
||||
|
||||
### Native Form actions
|
||||
|
||||
A native Form (`ResourceForm`) selects Resources through a data source. Create
|
||||
|
||||
Reference in new issue
Block a user