Skip to content

docs(sdk): document attachSync, variable CRUD, and getRootElements/getAllAnimationIds#2108

Merged
vanceingalls merged 2 commits into
mainfrom
docs/sdk-attachsync-and-variable-crud
Jul 9, 2026
Merged

docs(sdk): document attachSync, variable CRUD, and getRootElements/getAllAnimationIds#2108
vanceingalls merged 2 commits into
mainfrom
docs/sdk-attachsync-and-variable-crud

Conversation

@vanceingalls

@vanceingalls vanceingalls commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

What

Fills in three SDK reference-doc gaps that had fallen behind the actual public API:

  • docs/sdk/reference/composition.mdx: adds getVariableValue, listVariables, declareVariable, removeVariable (Typed edit methods) and getRootElements, getAllAnimationIds (Query section).
  • docs/sdk/reference/adapters.mdx: adds attachSync to the PreviewAdapter interface listing, plus a ParamField documenting 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: adds declareVariable/removeVariable rows and dispatch examples to the ## Variables op table (previously only setVariableValue was listed).

Why

Every doc-facing API this stack shipped was undocumented:

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 for elementAtPoint/applyDraft/etc.
  • edit-operations.mdx: same table-row + dispatch-example pattern as the existing setVariableValue entry.

No code changes — docs only.

Test plan

  • Verified code-fence balance across all three edited files (no broken/unclosed blocks)
  • Cross-checked every documented signature against the current packages/sdk/src/types.ts Composition/PreviewAdapter interfaces to ensure accuracy
  • Documentation updated (this PR is the documentation update)

…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."
@vanceingalls vanceingalls force-pushed the feat/sdk-live-dom-sync branch from 509e234 to c94de60 Compare July 9, 2026 18:52
@vanceingalls vanceingalls force-pushed the docs/sdk-attachsync-and-variable-crud branch from f76eeb5 to f169d5f Compare July 9, 2026 18:53

@miga-heygen miga-heygen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 match packages/sdk/src/types.ts.
  • PreviewAdapter.attachSync: signature matches adapters/types.ts, behavioral description matches adapters/iframe.ts implementation (immediate override sync → patch subscription → /script/* exclusion).
  • CompositionVariable union in types.mdx: all seven variants match packages/parsers/src/types.ts field-for-field, including FontVariable's default_name/default_source.
  • EditOp additions: declareVariable/removeVariable match the source union.
  • Utility functions: all six verified exported from sdk/src/index.ts with matching signatures.
  • readVariableDefault: correctly typed as unknown (the raw document-level return), with appropriate guidance to prefer the typed Composition method 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 james-russo-rames-d-jusso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Composition methods (getVariableValue, listVariables, declareVariable, removeVariable, getRootElements, getAllAnimationIds) match packages/sdk/src/types.ts:397-533 verbatim (names, params, return types, JSDoc intent).
  • PreviewAdapter.attachSync(comp: Composition): () => void matches packages/sdk/src/adapters/types.ts:57-87; the guide-side note that it also handles undo/redo (both flow through the same patch event) and swap-composition (auto-detach previous) is accurate against iframe.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 is p.path.startsWith("/script/") at iframe.ts:776, so types.ts's docstring is the one that's slightly stale, not this PR.
  • EditOp variants declareVariable / removeVariable match the union at packages/sdk/src/types.ts:120-121.
  • CompositionVariable union in types.mdx is a verbatim copy of packages/parsers/src/types.ts:153-233 (all 7 variants + type-specific fields).
  • Utility imports all resolve at HEAD: resolveScoped, findById, bareId, escapeHfId, isNewHostBoundary root-exported from packages/sdk/src/index.ts:29; readVariableDefault root-exported at :31. No subpath-imports in code samples to check.
  • removeVariable's data-var-* DOM-refs untouched claim in composition.mdx is lifted verbatim from mutate.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 touches types.mdx (+101, adds the CompositionVariable type reference), utilities.mdx (+66, adds id/scope utils + readVariableDefault), and guides/canvas-integration.mdx (+17, adds the attachSync guide 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

  • 🟡 findById framing. Docs describe it as "thin alias for resolveScoped kept for call-site clarity where 'find' reads better than 'resolve.' Identical behavior." — accurate on behavior, but engine/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.

Review by Rames D Jusso

jrusso1020
jrusso1020 previously approved these changes Jul 9, 2026

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — matches session.ts (the tightened union, not unknown).
  • listVariables(): CompositionVariable[], declareVariable(decl: CompositionVariable): void, removeVariable(id: string): void — match.
  • attachSync(comp: Composition): () => void — matches the PreviewAdapter interface; the /script/* "any future path" phrasing is correct against the runtime's startsWith("/script/") (more precise than the interface's own docstring).
  • Both EditOp variants + the 6 root exports (incl. readVariableDefault(...): unknown) — match index.ts.

CI clean (Preflight skips as docs-only; only Graphite mergeability pending). RDJ's two nits (PR body scope, findById framing) are optional. LGTM.

Base automatically changed from feat/sdk-live-dom-sync to main July 9, 2026 18:58
@vanceingalls vanceingalls dismissed jrusso1020’s stale review July 9, 2026 18:58

The base branch was changed.

@vanceingalls vanceingalls merged commit 7acce7e into main Jul 9, 2026
35 checks passed
@vanceingalls vanceingalls deleted the docs/sdk-attachsync-and-variable-crud branch July 9, 2026 18:59
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.

4 participants