import type { ContentModelDocument, ContentModelFormatter, ContentModelSegmentFormat, DarkColorHandler, DOMEventRecord, DOMHelper, DOMSelection, EditorEnvironment, FormatContentModelOptions, IEditor, PluginEventData, PluginEventFromType, PluginEventType, Snapshot, SnapshotsManager, EditorCore, EditorOptions, Rect, EntityState, DomToModelOptionForCreateModel, AnnounceData, ExperimentalFeature, LegacyTrustedHTMLHandler, DOMCreator } from 'roosterjs-content-model-types'; /** * The main editor class based on Content Model */ export declare class Editor implements IEditor { private core; /** * Creates an instance of Editor * @param contentDiv The DIV HTML element which will be the container element of editor * @param options An optional options object to customize the editor */ constructor(contentDiv: HTMLDivElement, options?: EditorOptions); /** * Dispose this editor, dispose all plugins and custom data */ dispose(): void; /** * Get whether this editor is disposed * @returns True if editor is disposed, otherwise false */ isDisposed(): boolean; /** * Create Content Model from DOM tree in this editor * @param mode What kind of Content Model we want. Currently we support the following values: * - disconnected: Returns a disconnected clone of Content Model from editor which you can do any change on it and it won't impact the editor content. * If there is any entity in editor, the returned object will contain cloned copy of entity wrapper element. * If editor is in dark mode, the cloned entity will be converted back to light mode. * - clean: Similar with disconnected, this will return a disconnected model, the difference is "clean" mode will not include any selection info. * This is usually used for exporting content */ getContentModelCopy(mode: 'connected' | 'disconnected' | 'clean'): ContentModelDocument; /** * Get current running environment, such as if editor is running on Mac */ getEnvironment(): EditorEnvironment; /** * Get current DOM selection */ getDOMSelection(): DOMSelection | null; /** * Set DOMSelection into editor content. * @param selection The selection to set */ setDOMSelection(selection: DOMSelection | null): void; /** * Set a new logical root (most likely due to focus change) * @param logicalRoot The new logical root (has to be child of physicalRoot) */ setLogicalRoot(logicalRoot: HTMLDivElement): void; /** * The general API to do format change with Content Model * It will grab a Content Model for current editor content, and invoke a callback function * to do format change. Then according to the return value, write back the modified content model into editor. * If there is cached model, it will be used and updated. * @param formatter Formatter function, see ContentModelFormatter * @param options More options, see FormatContentModelOptions */ formatContentModel(formatter: ContentModelFormatter, options?: FormatContentModelOptions, domToModelOptions?: DomToModelOptionForCreateModel): void; /** * Get pending format of editor if any, or return null */ getPendingFormat(): ContentModelSegmentFormat | null; /** * Get a DOM Helper object to help access DOM tree in editor */ getDOMHelper(): DOMHelper; /** * Add a single undo snapshot to undo stack * @param entityState @optional State for entity if we want to add entity state for this snapshot */ takeSnapshot(entityState?: EntityState): Snapshot | null; /** * Restore an undo snapshot into editor * @param snapshot The snapshot to restore */ restoreSnapshot(snapshot: Snapshot): void; /** * Get document which contains this editor * @returns The HTML document which contains this editor */ getDocument(): Document; /** * Focus to this editor, the selection was restored to where it was before, no unexpected scroll. */ focus(): void; /** * Check if focus is in editor now * @returns true if focus is in editor, otherwise false */ hasFocus(): boolean; /** * Trigger an event to be dispatched to all plugins * @param eventType Type of the event * @param data data of the event with given type, this is the rest part of PluginEvent with the given type * @param broadcast indicates if the event needs to be dispatched to all plugins * True means to all, false means to allow exclusive handling from one plugin unless no one wants that * @returns the event object which is really passed into plugins. Some plugin may modify the event object so * the result of this function provides a chance to read the modified result */ triggerEvent(eventType: T, data: PluginEventData, broadcast?: boolean): PluginEventFromType; /** * Attach a DOM event to the editor content DIV * @param eventMap A map from event name to its handler */ attachDomEvent(eventMap: Record): () => void; /** * Get undo snapshots manager */ getSnapshotsManager(): SnapshotsManager; /** * Check if the editor is in dark mode * @returns True if the editor is in dark mode, otherwise false */ isDarkMode(): boolean; /** * Set the dark mode state and transforms the content to match the new state. * @param isDarkMode The next status of dark mode. True if the editor should be in dark mode, false if not. */ setDarkModeState(isDarkMode?: boolean): void; /** * Check if editor is in Shadow Edit mode */ isInShadowEdit(): boolean; /** * Make the editor in "Shadow Edit" mode. * In Shadow Edit mode, all format change will finally be ignored. * This can be used for building a live preview feature for format button, to allow user * see format result without really apply it. * This function can be called repeated. If editor is already in shadow edit mode, we can still * use this function to do more shadow edit operation. */ startShadowEdit(): void; /** * Leave "Shadow Edit" mode, all changes made during shadow edit will be discarded */ stopShadowEdit(): void; /** * Get a color manager object for this editor. */ getColorManager(): DarkColorHandler; /** * @deprecated * Get a function to convert HTML string to trusted HTML string. * By default it will just return the input HTML directly. To override this behavior, * pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types */ getTrustedHTMLHandler(): LegacyTrustedHTMLHandler; /** * Get a function to convert HTML string to a trust Document. * By default it will just convert the original HTML string into a Document object directly. * To override, pass your own trusted HTML handler to EditorOptions.trustedHTMLHandler * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/trusted-types */ getDOMCreator(): DOMCreator; /** * Get the scroll container of the editor */ getScrollContainer(): HTMLElement; /** * Retrieves the rect of the visible viewport of the editor. */ getVisibleViewport(): Rect | null; /** * Add CSS rules for editor * @param key A string to identify the CSS rule type. When set CSS rules with the same key again, existing rules with the same key will be replaced. * @param cssRule The CSS rule string, must be a valid CSS rule string, or browser may throw exception. Pass null to clear existing rules * @param subSelectors @optional If the rule is used for child element under editor, use this parameter to specify the child elements. Each item will be * combined with root selector together to build a separate rule. */ setEditorStyle(key: string, cssRule: string | null, subSelectors?: 'before' | 'after' | string[]): void; /** * Announce the given data * @param announceData Data to announce */ announce(announceData: AnnounceData): void; /** * Check if a given feature is enabled * @param featureName The name of feature to check */ isExperimentalFeatureEnabled(featureName: ExperimentalFeature | string): boolean; /** * @returns the current EditorCore object * @throws a standard Error if there's no core object */ protected getCore(): EditorCore; private cloneOptionCallback; }