Skip to content

feat(superdoc/ui): ui.document surface for export, mode, ready (SD-2816)#3015

Merged
caio-pizzol merged 1 commit into
mainfrom
caio/sd-2816-ui-document-surface
Apr 30, 2026
Merged

feat(superdoc/ui): ui.document surface for export, mode, ready (SD-2816)#3015
caio-pizzol merged 1 commit into
mainfrom
caio/sd-2816-ui-document-surface

Conversation

@caio-pizzol
Copy link
Copy Markdown
Contributor

A custom toolbar's Export button, document-mode toggle, and ready-state guard previously had to reach for the host SuperDoc instance. The React provider in SD-2813 exposed a `SuperDocHost` interface as an escape hatch for that single use case (export); `ui.document` removes the need for it.

Adds `ui.document` with:

  • `getSnapshot()` / `subscribe()` over `{ ready, mode }`. Memoized so typing-only transactions don't re-fire the listener.
  • `setMode(mode)` forwards to `superdoc.setDocumentMode`. No-op when the host stub omits the setter; logs to `console.error` if the host throws.
  • `export(options)` forwards to `superdoc.export` and propagates the result / rejection. Throws a clear error when the host stub omits `export()` instead of silently returning `undefined` (consumers wired to a button deserve a real error to handle).

Dirty / unsaved-changes is intentionally not on this slice. SuperDoc has no host-side dirty primitive today, and inventing one (transaction listener + reset semantics) is a separate ticket.

Re-exports `DocumentSlice` / `DocumentHandle` / `DocumentExportInput` through `superdoc/ui` and `packages/superdoc/src/ui.d.ts` so consumers can type their toolbar bindings from one entrypoint.

Stacked on #3014 (SD-2815). Once that merges, this rebases against main.

Resolves SD-2816.

Verified: `pnpm --filter @superdoc/super-editor test src/ui/` -> 140 passed (12 new); `pnpm --filter superdoc build:es` -> ensure-types + bundle audit clean.

@caio-pizzol caio-pizzol requested a review from a team as a code owner April 29, 2026 21:38
@linear
Copy link
Copy Markdown

linear Bot commented Apr 29, 2026

Base automatically changed from caio/sd-2815-re-export-public-types to caio/sd-2812-selection-target-alignment April 29, 2026 21:48
Base automatically changed from caio/sd-2812-selection-target-alignment to main April 29, 2026 22:32
A custom toolbar's Export button, document-mode toggle, and
ready-state guard previously had to reach for the host SuperDoc
instance. The React provider exposed a SuperDocHost interface as an
escape hatch for that single use case (export); ui.document removes
the need for it.

Adds ui.document with:
- getSnapshot() / subscribe() over { ready, mode } memoized so
  typing-only transactions don't re-fire the listener.
- setMode(mode) that forwards to superdoc.setDocumentMode.
- export(options) that forwards to superdoc.export and propagates
  the result / rejection. Throws a clear error when the host stub
  omits export() instead of silently returning undefined.

Dirty / unsaved-changes tracking is intentionally not on this slice:
SuperDoc has no host-side dirty primitive today, and inventing one
(transaction listener + reset semantics) is a separate ticket.

Re-exports DocumentSlice / DocumentHandle / DocumentExportInput
through superdoc/ui and packages/superdoc/src/ui.d.ts so consumers
can type their own toolbar bindings without reaching into the
internal ui types module.

12 new tests cover snapshot / subscribe memoization / setMode (with
host omission and host throwing) / export forwarding / export
missing / export rejection. 140 ui tests pass; bundle audit clean.
@caio-pizzol caio-pizzol force-pushed the caio/sd-2816-ui-document-surface branch from 0337c8e to c201f87 Compare April 30, 2026 13:41
@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 6438ddc into main Apr 30, 2026
59 checks passed
@caio-pizzol caio-pizzol deleted the caio/sd-2816-ui-document-surface branch April 30, 2026 13:54
@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.15

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 vscode-ext v2.3.0-next.60

@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.58

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.33

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.19

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented Apr 30, 2026

🎉 This PR is included in superdoc v1.30.0-next.18

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-cli v0.8.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc-sdk v1.8.0

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in @superdoc-dev/mcp v0.3.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 1, 2026

🎉 This PR is included in superdoc v1.31.0

The release is available on GitHub release

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 5, 2026

🎉 This PR is included in vscode-ext v2.3.0

@superdoc-bot
Copy link
Copy Markdown
Contributor

superdoc-bot Bot commented May 7, 2026

🎉 This PR is included in @superdoc-dev/react v1.3.0

The release is available on GitHub release

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