import { ReactNode } from 'react'; import { Subscribable, SuperDocUI } from '../types.js'; /** * Minimal structural type for the host SuperDoc instance — exposed * through {@link useSuperDocHost} so components can call methods that * aren't on the controller surface (currently: `export({...})`). * * Most components should never reach for the host; prefer * {@link useSuperDocUI} and the domain hooks. The host is only here * for the small set of operations the controller doesn't yet bridge. */ export interface SuperDocHost { export(options: { exportType: string[]; commentsType?: 'internal' | 'external'; triggerDownload?: boolean; }): Promise; } /** * React context wrapping the `superdoc/ui` browser controller. * * Construction is deferred until SuperDoc reports ready — the editor * mount path calls `setSuperDoc(instance)` once the wrapper dispatches * `onReady`, and this provider creates exactly one * `createSuperDocUI({ superdoc })` and stores it in state. Re-renders * never recreate the controller; unmount calls `ui.destroy()` so every * subscriber is torn down deterministically. * * ```tsx * * * setSuperDoc(superdoc)} /> * * * ``` * * Implementation note: the unmount cleanup uses a ref to the latest * controller. Doing the obvious `useEffect(() => () => ui?.destroy(), * [])` would capture the initial null value (controllers are created * on `onReady`, after the first render), and changing the deps to * `[ui]` would destroy the controller every time it's created. The * ref sidesteps both pitfalls. */ export declare function SuperDocUIProvider({ children }: { children: ReactNode; }): import("react").JSX.Element; /** * Read the controller from context. Returns `null` until the editor * reports ready — components either wait for non-null or render a * pending state. */ export declare function useSuperDocUI(): SuperDocUI | null; /** * Read the host SuperDoc instance from context. Reach for * {@link useSuperDocUI} first — host access is reserved for * operations that aren't on the controller surface today * (e.g. `export()`). */ export declare function useSuperDocHost(): SuperDocHost | null; /** * Setter exposed for the editor mount component that owns the React * wrapper's `onReady` callback. Most components do NOT need this — * use {@link useSuperDocUI} to read the controller instead. */ export declare function useSetSuperDoc(): (instance: unknown) => void; /** * Bind a React component to a slice of controller state. * * ```tsx * const toolbar = useSuperDocSlice( * (ui) => ui.select((state) => state.toolbar, shallowEqual), * { context: null, commands: {} }, * ); * ``` * * The selector returns a `Subscribable`; pass anything from * `ui.select(...)` (the canonical substrate) or any other API on the * controller that exposes the same shape. * * Domain handles (`ui.toolbar.subscribe`, `ui.comments.subscribe`, * etc.) emit a `{ snapshot }` event instead of the raw value — prefer * `ui.select(...)` when you need a single field, or use the typed * domain hooks (`useSuperDocSelection`, `useSuperDocComments`, * `useSuperDocTrackChanges`). * * The hook re-emits the most recent value on every change. While the * controller is null (before the editor reports ready), the hook * returns the `initial` value so the first render is coherent. */ export declare function useSuperDocSlice(pickSubscribable: (ui: SuperDocUI) => Subscribable, initial: T): T; //# sourceMappingURL=provider.d.ts.map