Nutrient Web SDK
    Preparing search index...

    Interface ContentEditor

    The instance.contentEditor namespace exposes the headless APIs that let a custom toolbar read state from and write state to the live UI content editor session.

    Session save/discard/dirty-flag/export and starting a programmatic session stay on Instance itself — see Instance#saveContentEditingSession, Instance#discardContentEditingSession, Instance#hasUnsavedContentEditingChanges, Instance#exportContentEditorPDF, and Instance#beginContentEditingSession. This namespace fills the gaps those methods do not cover.

    The read methods expose the live session — UI or programmatic, whichever is currently active. UI state methods such as selection, focus, text styling, undo, redo, and layout changes require an active UI session. Programmatic sessions should use the ContentEditing.Session returned by Instance#beginContentEditingSession for mutations.

    Subscribe to "contentEditor.stateChange" to keep a custom toolbar in sync with state changes.

    interface ContentEditor {
        canUndo(): boolean;
        createTextBlock(
            input: { anchor: { x: number; y: number }; pageIndex: number },
        ): Promise<string>;
        deleteActiveBlock(): Promise<void>;
        deleteBlock(id: string): Promise<void>;
        enterCreateMode(): void;
        exitCreateMode(): void;
        focusBlock(id: string | null): void;
        getActiveBlock(): string | null;
        getAvailableFonts(): readonly AvailableFontFace[];
        getBlock(id: string): TextBlockSummary | null;
        getBlocks(pageIndex?: number): readonly TextBlockSummary[];
        getCurrentStyle(): CurrentStyle | null;
        getFontMismatches(): readonly FontMismatch[];
        getSelectedBlock(): string | null;
        getSubsetFonts(): readonly SubsetFontInfo[];
        insertText(text: string): void;
        isActive(): boolean;
        isInCreateMode(): boolean;
        redo(): void;
        selectAllText(id: string): Promise<void>;
        selectBlock(id: string | null): void;
        setLayout(id: string, layout: LayoutInput): Promise<void>;
        setListFormatting(formatting: ListFormatting): Promise<void>;
        setTextSelection(
            id: string,
            range: { begin: number; end: number } | null,
        ): Promise<void>;
        setTextStyle(style: TextStyle): void;
        undo(): void;
    }
    Index

    Methods

    • Whether an active text block can receive an undo command. Today the undo stack is text-input scoped and lives inside core — granular emptiness is not exposed, so this returns true iff a text block is active. A canRedo counterpart is intentionally not exposed until core reports actual stack emptiness; it could not answer differently from this method.

      Returns boolean

    • Create a new text block at the given anchor. Resolves with the id of the new block, which can immediately be passed to focusBlock or selectAllText.

      Parameters

      • input: { anchor: { x: number; y: number }; pageIndex: number }

      Returns Promise<string>

    • Delete the currently active or selected block.

      Returns Promise<void>

    • Delete a block by id, regardless of type.

      Parameters

      • id: string

      Returns Promise<void>

    • Enter "add a new text block" mode — the next pointer down on the page creates a block.

      Returns void

    • Exit create mode, returning to plain edit mode.

      Returns void

    • Put the given block into Active state (cursor inside, edit mode). Pass null to clear.

      Parameters

      • id: string | null

      Returns void

    • Returns string | null

    • Synchronous read of a single block by id. Narrow on block.type.

      Parameters

      • id: string

      Returns TextBlockSummary | null

    • Synchronous read of all blocks (or the blocks on one page). Narrow on block.type.

      Parameters

      • OptionalpageIndex: number

      Returns readonly TextBlockSummary[]

    • Style at the cursor / selection inside the active block, or null if no block is active.

      Returns CurrentStyle | null

    • Fonts referenced by detected text blocks that could not be matched to an available face. Populates as blocks are interacted with — paragraphs that have not yet been touched are not yet inspected.

      Returns readonly FontMismatch[]

    • Returns string | null

    • Insert text at the current cursor / over the current selection inside the active block. Mirrors what typing does, but driven from a custom toolbar.

      Parameters

      • text: string

      Returns void

    • Whether the session is currently in create mode.

      Returns boolean

    • Redo the last undone change in the active text block.

      Returns void

    • Select every character in the given text block. Await the returned promise before calling setTextStyle; the style then applies to the entire block.

      Parameters

      • id: string

      Returns Promise<void>

    • Put the given block into Selected state (clicked, but not in edit mode). Pass null to clear.

      Parameters

      • id: string | null

      Returns void

    • Apply layout properties to a specific text block in the active UI session.

      Parameters

      Returns Promise<void>

    • Apply list formatting to the selected text in the active block. If no text is selected, the operation applies to the whole active block. Use "none" to remove list markers.

      Parameters

      Returns Promise<void>

    • Select a character range inside the given block. The block must already be active (in edit mode). Pass null to clear the selection. Character indices map to the plain-text content returned by getBlock(id).text.

      Parameters

      • id: string
      • range: { begin: number; end: number } | null

      Returns Promise<void>

    • Apply style to the current UI selection (or to the cursor for next-typed text).

      Parameters

      Returns void

    • Undo the last change in the active text block (text-input scoped today).

      Returns void