Skip to content

feat(ui): pass routed editor to custom-command execute (SD-2844)#3039

Merged
caio-pizzol merged 1 commit intomainfrom
caio/sd-2844-custom-cmd-typed-editor
Apr 30, 2026
Merged

feat(ui): pass routed editor to custom-command execute (SD-2844)#3039
caio-pizzol merged 1 commit intomainfrom
caio/sd-2844-custom-cmd-typed-editor

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

Custom commands previously reached the Document API through a structural cast on `superdoc.activeEditor`. The `execute` callback now receives a third argument:

```ts
execute: ({ payload, superdoc, editor }) => {
if (!editor) return false;
return editor.doc?.insert?.({ ... })?.success === true;
}
```

`editor` is typed as `SuperDocEditorLike | null` and resolved late-bound at execute time, so it tracks header/footer focus the same way every other `ui.*` mutation does.

  • `SuperDocEditorLike.doc` widens to include a typed `insert(input: InsertInput, options?: unknown): SDMutationReceipt` signature, matching the doc-api shape. Other doc-API mutation methods stay loose (`unknown` in / `unknown` out) unless a comparable BYO-UI pattern lands.
  • Demo's `InsertClauseButton` drops the structural cast.
  • New test asserts the routed editor is passed: planted child story editor flows through to `execute` instead of whichever was active at register time.
  • Existing tests update to assert `{ payload, superdoc, editor }` shape.

Review: backwards-compatibility β€” `execute` callbacks that destructure `{ payload, superdoc }` ignore `editor`, so this is additive. Worth confirming the `SDMutationReceipt` choice (`Receipt` would also fit; the doc-api uses `SDMutationReceipt` for `insert` specifically).
Verified: 158/158 super-editor UI tests; superdoc + @superdoc-dev/react builds clean; BYO-UI demo builds clean.

Once merged, the BYO-UI docs PR (#3034) drops the structural-cast snippet on `custom-commands.mdx` in favor of `editor.doc?.insert?.(...)`.

Custom commands previously had to reach the Document API through a
structural cast on superdoc.activeEditor. The execute callback now
receives a third argument β€” editor β€” typed as SuperDocEditorLike
and resolved late-bound at execute time so it tracks header/footer
focus the same way every other ui.* mutation does.

Also widens SuperDocEditorLike.doc to include a typed insert(input,
options) signature. The BYO-UI custom-command pattern (Insert
clause, AI-generated text) is the immediate use case; other doc-API
mutation methods stay loose unless a similar pattern lands.

Drops the structural cast from the BYO-UI demo's InsertClauseButton.
The canonical custom-commands docs snippet can simplify the same way
once this lands and ships in a patch.
@caio-pizzol caio-pizzol requested a review from a team as a code owner April 30, 2026 22:57
@linear
Copy link
Copy Markdown

linear Bot commented Apr 30, 2026

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.

πŸ“’ Thoughts on this report? Let us know!

@caio-pizzol caio-pizzol merged commit 1b9325d into main Apr 30, 2026
73 checks passed
@caio-pizzol caio-pizzol deleted the caio/sd-2844-custom-cmd-typed-editor branch April 30, 2026 23:49
@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in vscode-ext v2.3.0-next.70

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in @superdoc-dev/mcp v0.3.0-next.25

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in @superdoc-dev/react v1.2.0-next.68

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in superdoc v1.30.0-next.27

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in superdoc-cli v0.8.0-next.43

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

πŸŽ‰ This PR is included in superdoc-sdk v1.8.0-next.29

caio-pizzol added a commit that referenced this pull request May 1, 2026
…, #3040

Three workarounds drop now that the controller surface covers them:

- comments.mdx: post a reply via ui.comments.reply(parentId, { text })
  instead of useSuperDocHost() + editor.doc.comments.create.
- custom-commands.mdx: drop the structural cast on superdoc.activeEditor;
  use the typed editor argument that execute({ payload, superdoc, editor })
  now provides. Pattern B's chain-command cast narrowed and called out.
- document-control.mdx: drop the transaction-listener snippet; use
  useSuperDocDocument().dirty directly. Includes the export-button
  example pattern. Trade-offs trimmed accordingly.

API reference updated: useSuperDocDocument now returns dirty;
ui.commands.register() execute receives editor; ui.comments.reply
listed in the comments handle block.
caio-pizzol added a commit that referenced this pull request May 1, 2026
…, #3040

Three workarounds drop now that the controller surface covers them:

- comments.mdx: post a reply via ui.comments.reply(parentId, { text })
  instead of useSuperDocHost() + editor.doc.comments.create.
- custom-commands.mdx: drop the structural cast on superdoc.activeEditor;
  use the typed editor argument that execute({ payload, superdoc, editor })
  now provides. Pattern B's chain-command cast narrowed and called out.
- document-control.mdx: drop the transaction-listener snippet; use
  useSuperDocDocument().dirty directly. Includes the export-button
  example pattern. Trade-offs trimmed accordingly.

API reference updated: useSuperDocDocument now returns dirty;
ui.commands.register() execute receives editor; ui.comments.reply
listed in the comments handle block.
caio-pizzol added a commit that referenced this pull request May 1, 2026
Fixes stale correctness issues and lays out the layer model so
existing docs route customers to the right path.

Stage 1 β€” correctness fixes on BYO pages
- bring-your-own-ui/reference-demo: drop the 'demo reaches through
  useSuperDocHost()' prose; replies and custom commands now use the
  typed surface after #3035 and #3039 shipped.
- bring-your-own-ui/custom-commands: Pattern B (override) reframed
  as an advanced escape hatch with a Warning, since override truly
  replaces and consumers shouldn't trust the built-in to still run.
- modules/track-changes: drop 'merged comments + changes feed' from
  the BYO callout; the merged-feed pattern moved to reference-demo
  as an app-level composition.

Stage 2 β€” toolbar IA cleanup
- modules/toolbar/overview: replace the two-path table with a
  three-path decision: Built-in / Bring Your Own UI / Headless
  toolbar. Recommendation: new React apps reach for BYO first;
  headless stays supported for non-React and existing integrations.
- modules/toolbar/headless: promote the BYO redirect from a Tip to
  a 'Using React?' section with the supported-vs-recommended framing.
- modules/toolbar/examples: drop the React + shadcn and React + MUI
  examples; redirect React readers to BYO. Vue / Svelte / vanilla
  examples stay.

Stage 3 β€” onboarding links
- getting-started/frameworks/react: add BYO card to Next steps.
- getting-started/quickstart: add BYO link inline under the React
  scenario plus a card in 'What's next'.

Stage 4 β€” authoring guidance + LLM context
- AGENTS.md: new 'Layer model' section with explicit recommendation
  order (Document API > superdoc/ui > Modules > Core). API naming
  marks superdoc.activeEditor.commands.* as legacy/compat. Source
  file table extended with the doc-api contract and superdoc/ui.
- llms.txt: add Bring Your Own UI link plus a Layer Model section
  so agents recommend the right surface.

Stage 5 β€” disambiguate track-changes pages without URL renames
- modules/track-changes: title 'Track changes module',
  sidebarTitle 'Track changes module'.
- bring-your-own-ui/track-changes: title 'Custom track changes UI',
  sidebarTitle stays 'Track changes' for nav consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants