import { Subject } from "rxjs"; import { type Padding } from "blocky-common/es/dom"; import { EditorState } from "../model"; import { AttributesObject, BlockDataElement, BlockyDocument, CursorState, ChangesetApplyOptions } from "../data"; import Delta from "quill-delta-es"; import { BlockRegistry } from "../registry/blockRegistry"; import { PluginRegistry, type IPlugin } from "../registry/pluginRegistry"; import { SpanRegistry } from "../registry/spanRegistry"; import { EmbedRegistry } from "../registry/embedRegistry"; import { type ToolbarFactory } from "./toolbarDelegate"; import { type IdGenerator } from "../helper/idHelper"; import { type CollaborativeCursorFactory } from "./collaborativeCursors"; import { Editor } from "./editor"; import { type FollowerWidget } from "./followerWidget"; import type { ThemeData } from "../model/theme"; export declare function makeDefaultEditorPlugins(): IPlugin[]; export interface IEditorControllerOptions { /** * The title is used to create the document * * If document is passed, this field is ignored. */ title?: string; pluginRegistry?: PluginRegistry; /** * The document to create the state * * If this is empty, the controller will create a new one. */ document?: BlockyDocument; /** * The initial version of the state * * Default: 0 */ initVersion?: number; /** * * Specify the plugins. * The plugins will be loaded by the editor * */ plugins?: IPlugin[]; spanRegistry?: SpanRegistry; blockRegistry?: BlockRegistry; embedRegistry?: EmbedRegistry; idGenerator?: IdGenerator; toolbarFactory?: ToolbarFactory; /** * The inner padding of the editor */ padding?: Partial; collaborativeCursorFactory?: CollaborativeCursorFactory; emptyPlaceholder?: string; /** * If this is set to false, the spellcheck of the browser * will be disabled. * * Default: true */ spellcheck?: boolean; /** * Define whether the title is editable * * Default: true */ titleEditable?: boolean; /** * The method used to open external links */ urlLauncher?: (url: string) => void; /** * The internal error. * Some data went wrong when this method is called. * The editor should refresh itself. */ onError?: (err: unknown) => void; } export interface IInsertOptions { autoFocus?: boolean; noRender?: boolean; } export type NextTickFn = () => void; export declare class CursorChangedEvent { readonly id: string; readonly state: CursorState | null; constructor(id: string, state: CursorState | null); } /** * The {@link EditorController} is focused on the data manipulation. * It doesn't cared about the changes on UI. * * The UI details are handled in {@link Editor} class. * If you want to modify the state easily, use the {@link EditorController}. * * Another use of {@link EditorController} is to manipulate the document * before the Editor is created. * For example, insert text to the document before * the editor is created. */ export declare class EditorController { #private; readonly userId: string; options?: IEditorControllerOptions | undefined; editor: Editor | undefined; readonly pluginRegistry: PluginRegistry; readonly spanRegistry: SpanRegistry; readonly embedRegistry: EmbedRegistry; readonly blockRegistry: BlockRegistry; readonly idGenerator: IdGenerator; readonly state: EditorState; readonly cursorChanged: Subject; readonly beforeApplyCursorChanged: Subject; readonly emptyPlaceholder: string; /** * A class to control the behavior in the editor */ constructor(userId: string, options?: IEditorControllerOptions | undefined); get themeData(): ThemeData | undefined; set themeData(themeData: ThemeData | undefined); /** * Apply cursor changed event from another users. * The renderer will draw the collaborative cursor * from another user. */ applyCursorChangedEvent(evt: CursorChangedEvent): void; focus(): void; /** * Apply the delta if the cursor is pointing at a * TextBlock. This method will auto set the cursor for you. */ applyDeltaAtCursor(deltaGen: (offset: number) => Delta, options?: Partial): void; mount(editor: Editor): void; /** * Insert a block in a element after id. * This method will apply a changeset to the state and * trigger the rendering process of the editor. */ insertBlockAfterId(element: BlockDataElement, afterId: string, options?: IInsertOptions): string; __emitNextTicks(): void; enqueueNextTick(fn: NextTickFn): void; formatTextOnCursor(cursorState: CursorState, attribs?: AttributesObject): void; formatTextOnSelectedText(attribs?: AttributesObject): void; /** * Delete the block by id */ deleteBlock(id: string): void; /** * Use the API provided by the browser to parse the html for the bundle size. * Maybe use an external library is better for unit tests. But it will increase * the size of the bundles. */ pasteHTMLAtCursor(html: string): void; deleteContentInsideInSelection(cursorState: CursorState): CursorState | null; pasteElementsAtCursor(elements: BlockDataElement[]): void; /** * Calculate the attributes from the dom. * It's used for pasting text, and to recognize the dom created by the browser. */ getAttributesBySpan(span: HTMLElement): AttributesObject; /** * Force set the cursor state. * * Using the changeset is a recommended way to update the cursor. */ setCursorState(cursorState: CursorState | null): void; /** * Insert the {@link FollowerWidget} at the position of the current cursor. */ insertFollowerWidget(widget: FollowerWidget): void; getBlockElementAtCursor(): BlockDataElement | null; dispose(): void; }