import { ComputedRef, MaybeRefOrGetter, ShallowRef } from 'vue'; import { SliceSource } from './slice-source.js'; import { BorrowedSuperDocUI, CommandExecutionResult, CommandState, CommentsSlice, ContentControlsSlice, DocumentSlice, FontFamilyOption, FontSizeOption, SelectionSlice, Subscribable, SuperDocLike, ToolbarSnapshotSlice, TrackChangesSlice, ZoomSlice } from './types.js'; /** The raw SuperDoc instance (or host stub) handed to the provider. */ export type SuperDocHost = SuperDocLike; /** * What {@link provideSuperDocUI} publishes to descendants and returns to its * caller. The refs are typed read-only: the provider is the only writer. */ export interface SuperDocUIBinding { /** The bound controller, or `null` until a SuperDoc instance is bound. */ ui: Readonly>; /** The raw bound SuperDoc host, or `null` until one is bound. */ host: Readonly>; /** Bind a running SuperDoc instance. Stable function identity. */ setSuperDoc: (superdoc: SuperDocHost) => void; /** * Unbind `expectedHost`, returning whether it was still the bound one. The * host is required: teardown races with rebinding, so an unconditional clear * could unbind a newer editor that has already bound. */ clearSuperDoc: (expectedHost: SuperDocHost) => boolean; } /** * Root provider composable. Call it once in an ancestor component's `setup()`. * In the editor-mount component, capture the setter during `setup()` * (`const setSuperDoc = useSetSuperDoc()`) and call that function from the * editor's ready callback to bind a running SuperDoc instance; the composables * below then read that instance's own controller (`superdoc.ui`). * * Capture during `setup()` is required, not stylistic: {@link useSetSuperDoc} * resolves the binding through `inject()`, which only sees the provider while * a component instance is active. Calling it from the ready callback itself * throws the "must be used under" error even with a provider in the tree. * * The provider is a consumer, not an owner. SuperDoc creates the controller * and destroys it in `superdoc.destroy()`, so disposing or rebinding the * provider leaves it running for the built-in toolbar and any other consumer * of the same instance. Every composable therefore observes the same command * state the rest of the application sees. * * Returns the binding it provided, so the providing component can also read * `ui`/`host`, bind from ready, and clear the expected host during teardown * without injecting. */ export declare function provideSuperDocUI(): SuperDocUIBinding; /** * Read the controller ref; its value is `null` until a SuperDoc instance is * bound. * * Borrowed: the bound instance owns teardown, so the value type omits * `destroy()`. A provider-built fallback controller is disposed by the provider. */ export declare function useSuperDocUI(): Readonly>; /** Read the raw bound SuperDoc host ref; `null` until one is bound. */ export declare function useSuperDocHost(): Readonly>; /** * Get the stable function used to bind a running SuperDoc instance. Call this * from `setup()` and keep the returned function; it stays callable from a * later ready callback, whereas this composable itself injects and so only * resolves while a component instance is active. */ export declare function useSetSuperDoc(): (superdoc: SuperDocHost) => void; /** * Get the stable function used to unbind an instance during editor teardown, * for the case the provider outlives the editor: a `v-if`'d or replaced editor * leaves `useSuperDocHost()` reporting a destroyed instance until something * rebinds, and if the replacement never becomes ready, indefinitely. * * Pass the instance being torn down. It is required, so a late teardown * returns `false` instead of unbinding a newer instance that already bound. * Capture this during `setup()` like {@link useSetSuperDoc}. */ export declare function useClearSuperDoc(): (expectedHost: SuperDocHost) => boolean; /** * Subscribe to a derived slice of controller state. `pick` selects a value * source from the controller: a domain handle / snapshot source * ({@link SliceSource}) or a raw `ui.select(...)` {@link Subscribable}, both * normalized via {@link toSliceSource}. The returned ref holds `initial` until * the controller is bound, and re-subscribes when the controller identity * changes. Call from `setup()` (or an active effect scope) so the * subscription is released with the scope. */ export declare function useSuperDocSlice(pick: (ui: BorrowedSuperDocUI) => SliceSource | Subscribable, initial: T): Readonly>; /** Subscribe to the selection slice. */ export declare function useSuperDocSelection(): Readonly>; /** Subscribe to the comments slice. */ export declare function useSuperDocComments(): Readonly>; /** Subscribe to the content-controls slice. */ export declare function useSuperDocContentControls(): Readonly>; /** Subscribe to the track-changes slice. */ export declare function useSuperDocTrackChanges(): Readonly>; /** Subscribe to the toolbar snapshot slice. */ export declare function useSuperDocToolbar(): Readonly>; /** Reactive state and execution methods for one SuperDoc command. */ export interface UseSuperDocCommandResult { /** Complete command state. */ state: Readonly>; /** Whether the command can run in the current editor state. */ enabled: Readonly>; /** Whether the command is active for the current selection. */ active: Readonly>; /** Whether the bound editor supports the command. */ supported: Readonly>; /** Run the command against the currently bound editor. */ execute: (payload?: unknown) => CommandExecutionResult; /** Run the command and await the routed operation's settled result. */ executeAsync: (payload?: unknown) => Promise; } /** * Subscribe to and execute a single command. Accepts a plain id, a ref, or a * getter; a reactive id re-subscribes and routes execution to the new command. */ export declare function useSuperDocCommand(id: MaybeRefOrGetter): UseSuperDocCommandResult; /** Subscribe to the document slice. */ export declare function useSuperDocDocument(): Readonly>; /** Subscribe to available font-family options. */ export declare function useSuperDocFontOptions(): Readonly>; /** Subscribe to available font-size options. */ export declare function useSuperDocFontSizeOptions(): Readonly>; /** Subscribe to the zoom slice. */ export declare function useSuperDocZoom(): Readonly>;