feat: let create_component componentize an existing node (fromNodeId)#5
Merged
Conversation
Pass fromNodeId to convert an existing node — e.g. the vectors from an import_svg logo/icon, or a built frame — into a reusable component via figma.createComponentFromNode, then create_instance it. That completes the SVG-to-reusable-icon path: import_svg -> create_component fromNodeId -> create_instance. Omit fromNodeId to create an empty component (behaviour unchanged). createComponentFromNode replaces the node in place, so the component keeps the node's parent/position unless parentId is given. Guarded in batch: fromNodeId consumes the source node and has no faithful inverse, so it is rejected at batch validate time (an empty create stays batchable). Enhancement to an existing tool — tool count unchanged. Full gate green (681 tests).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
create_componentgains an optionalfromNodeId: convert an existing node into a reusable main component (figma.createComponentFromNode) instead of only creating an empty one.Tool count unchanged (enhancement, not a new tool).
Why
Discovered while exploring
import_svg: it drops a frame of raw vectors, but there was no way to turn that (or any built frame) into a reusable component —create_componentonly made an empty one. This closes the loop:import_svg→create_component(fromNodeId) →create_instance= the same structure as the file's own icon components (a COMPONENT + linked instances).Behaviour
fromNodeIdgiven →createComponentFromNodereplaces the node in place, keeping its parent/position unlessparentIdis passed. Rejects PAGE/DOCUMENT/COMPONENT/COMPONENT_SET with a clear error.fromNodeIdomitted → empty component, exactly as before (no regression).Batch faithfulness (the correctness bit)
create_componentstays batchable as an empty create, butfromNodeIdis rejected inside abatch: componentizing consumes the source node, so the generic "undo = remove the created node" would destroy the original — no faithful inverse. Same principle that already excludesdelete_*/swap_componentfrom batch. Rejected at validate time (capture phase), before any mutation.Verification
pnpm typecheck && pnpm lint && pnpm format:check && pnpm knip && pnpm build && pnpm test— green (681 tests / 131 files).fromNodeId(componentizes in place, no reparent; not-found / non-componentizable throw) + batch rejectscreate_component {fromNodeId}at validate time.import_svg→create_component fromNodeId→create_instance→ confirm the instance links back to the new component; confirm abatchwithfromNodeIdis rejected.