docs(sdk): document attachSync, variable CRUD, and getRootElements/getAllAnimationIds#2108
Conversation
…tAllAnimationIds These SDK reference docs were behind the API surface: PR #2100's attachSync had zero documentation, and PR #2098/#2092's declareVariable, removeVariable, getVariableValue, listVariables, and getRootElements were all missing from composition.mdx despite being real public Composition methods. getAllAnimationIds was also undocumented (pre-existing gap, unrelated to this stack). - composition.mdx: adds getVariableValue, listVariables, declareVariable, removeVariable (Typed edit methods), getRootElements, getAllAnimationIds (Query section) - adapters.mdx: adds attachSync to the PreviewAdapter interface + a ParamField documenting its contract (immediate sync, ongoing patch mirroring, script-patch exclusion, detach semantics) - edit-operations.mdx: adds declareVariable/removeVariable rows + examples to the Variables op table
…ttachSync in canvas guide Follow-up to the previous commit in this PR — found while auditing whether any SDK-surface documentation gaps existed beyond this stack: - types.mdx: EditOp's own union listing was missing declareVariable/ removeVariable (present in edit-operations.mdx's table but not mirrored here). Adds a full CompositionVariable reference section (base fields + all 7 variants) since composition.mdx's new declareVariable/listVariables docs reference it without it being defined anywhere in the type reference. - utilities.mdx: documents 6 exported functions with zero prior docs — resolveScoped, findById, bareId, escapeHfId, isNewHostBoundary (Id & Scope Utilities) and readVariableDefault (Variable Utilities). Pre-existing gaps, unrelated to this stack. - canvas-integration.mdx: adds a "Keeping the preview in sync" section covering attachSync right where the guide already sets up preview + comp — previously the guide never mentioned it despite being exactly the answer to "how do I keep the iframe in sync with edits."
509e234 to
c94de60
Compare
f76eeb5 to
f169d5f
Compare
miga-heygen
left a comment
There was a problem hiding this comment.
LGTM — thorough and accurate docs update.
I cross-checked every documented signature against the current source:
- Composition methods (
getVariableValue,listVariables,declareVariable,removeVariable,getRootElements,getAllAnimationIds): all matchpackages/sdk/src/types.ts. - PreviewAdapter.attachSync: signature matches
adapters/types.ts, behavioral description matchesadapters/iframe.tsimplementation (immediate override sync → patch subscription →/script/*exclusion). - CompositionVariable union in
types.mdx: all seven variants matchpackages/parsers/src/types.tsfield-for-field, includingFontVariable'sdefault_name/default_source. - EditOp additions:
declareVariable/removeVariablematch the source union. - Utility functions: all six verified exported from
sdk/src/index.tswith matching signatures. readVariableDefault: correctly typed asunknown(the raw document-level return), with appropriate guidance to prefer the typedCompositionmethod in session code.
Convention adherence is clean — each file follows its own existing patterns. The canvas-integration.mdx guide section contextualizes attachSync well without duplicating the reference docs.
No accuracy issues, no missing fields, no broken references.
— Miga
james-russo-rames-d-jusso
left a comment
There was a problem hiding this comment.
Reviewed at f76eeb5.
Docs-only, catching up the reference to what the SDK-gap stack shipped. Verified every documented signature/type/export against HEAD — this reads correctly:
- 6
Compositionmethods (getVariableValue,listVariables,declareVariable,removeVariable,getRootElements,getAllAnimationIds) matchpackages/sdk/src/types.ts:397-533verbatim (names, params, return types, JSDoc intent). PreviewAdapter.attachSync(comp: Composition): () => voidmatchespackages/sdk/src/adapters/types.ts:57-87; the guide-side note that it also handles undo/redo (both flow through the samepatchevent) and swap-composition (auto-detach previous) is accurate againstiframe.ts:752-786. The docs' broader/script/*phrasing is actually ahead of the interface's own docstring (which only mentions/script/gsap) — the runtime filter isp.path.startsWith("/script/")atiframe.ts:776, sotypes.ts's docstring is the one that's slightly stale, not this PR.EditOpvariantsdeclareVariable/removeVariablematch the union atpackages/sdk/src/types.ts:120-121.CompositionVariableunion intypes.mdxis a verbatim copy ofpackages/parsers/src/types.ts:153-233(all 7 variants + type-specific fields).- Utility imports all resolve at HEAD:
resolveScoped,findById,bareId,escapeHfId,isNewHostBoundaryroot-exported frompackages/sdk/src/index.ts:29;readVariableDefaultroot-exported at:31. No subpath-imports in code samples to check. removeVariable'sdata-var-*DOM-refs untouched claim incomposition.mdxis lifted verbatim frommutate.ts:924-925's handler docstring — matches semantics.
Nits
- 🟡 PR body scope understates the diff. The "What" section calls out 3 files (
composition.mdx/adapters.mdx/edit-operations.mdx) but the PR also touchestypes.mdx(+101, adds theCompositionVariabletype reference),utilities.mdx(+66, adds id/scope utils +readVariableDefault), andguides/canvas-integration.mdx(+17, adds theattachSyncguide section) — all good additions, worth naming in the body so future-you / follow-up reviewers know the full surface without re-reading the diff.
Questions
- 🟡
findByIdframing. Docs describe it as "thin alias forresolveScopedkept for call-site clarity where 'find' reads better than 'resolve.' Identical behavior." — accurate on behavior, butengine/model.ts:31-37's own comment frames the reason it's kept as a shared surface: patch-replay (undo/redo, override-set apply) and forward dispatch have to resolve ids the SAME way, or they disagree on which duplicate a bare id targets and undo reverts the wrong element. Optional whether that belongs in public-API docs vs. internal comments — flagging in case you want to promote it, since it's the load-bearing invariant behind having two names for the same behavior.
What I didn't verify
- Rendered Mintlify output — verified against source markup only.
- Doc-typecheck harness (if any) that would catch a signature-drift between the docs and the SDK at CI time. If there isn't one, the doc drift that #1817's rubric catches is still a manual-review problem.
CI green. Ready from where I sit.
jrusso1020
left a comment
There was a problem hiding this comment.
Docs-only, verified at head f169d5fa. Independently checked every documented signature against source (the SDK stack I just reviewed at HEAD):
getVariableValue(id): string | number | boolean | FontValue | ImageValue | undefined— matchessession.ts(the tightened union, notunknown).listVariables(): CompositionVariable[],declareVariable(decl: CompositionVariable): void,removeVariable(id: string): void— match.attachSync(comp: Composition): () => void— matches thePreviewAdapterinterface; the/script/*"any future path" phrasing is correct against the runtime'sstartsWith("/script/")(more precise than the interface's own docstring).- Both
EditOpvariants + the 6 root exports (incl.readVariableDefault(...): unknown) — matchindex.ts.
CI clean (Preflight skips as docs-only; only Graphite mergeability pending). RDJ's two nits (PR body scope, findById framing) are optional. LGTM.

What
Fills in three SDK reference-doc gaps that had fallen behind the actual public API:
docs/sdk/reference/composition.mdx: addsgetVariableValue,listVariables,declareVariable,removeVariable(Typed edit methods) andgetRootElements,getAllAnimationIds(Query section).docs/sdk/reference/adapters.mdx: addsattachSyncto thePreviewAdapterinterface listing, plus aParamFielddocumenting its contract — immediate override sync on attach, ongoing patch-event mirroring (including undo/redo), the/script/*exclusion, and detach semantics.docs/sdk/reference/edit-operations.mdx: addsdeclareVariable/removeVariablerows and dispatch examples to the## Variablesop table (previously onlysetVariableValuewas listed).Why
Every doc-facing API this stack shipped was undocumented:
attachSync(this stack, feat(sdk): attachSync mirrors composition edits onto a live document #2100) had zero mentions anywhere in the docs — the entire feature was invisible to anyone reading the SDK reference.declareVariable,removeVariable,getVariableValue,listVariables(feat(sdk): variable CRUD (declare/remove/get/list) + export gaps #2098) were real publicCompositionmethods with no corresponding reference entries.getRootElements(feat(sdk): export getRootElements/isNewHostBoundary/bareId, fix relative data-start #2092) was missing from the Query section.getAllAnimationIdswas also missing — a pre-existing gap unrelated to this stack, filled in while touching the same section.How
Matched each file's existing conventions exactly rather than introducing new patterns:
composition.mdx: same### \methodName`` + signature code block + prose + example pattern as every other method in the file.adapters.mdx: same<ParamField>block style already used forelementAtPoint/applyDraft/etc.edit-operations.mdx: same table-row + dispatch-example pattern as the existingsetVariableValueentry.No code changes — docs only.
Test plan
packages/sdk/src/types.tsComposition/PreviewAdapterinterfaces to ensure accuracy