Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface of roosterjs editor object

Hierarchy

  • IEditor

Implemented by

Index

Methods

addContentEditFeature

addDomEventHandler

  • addDomEventHandler(eventName: string, handler: DOMEventHandler<Event>): () => void
  • addDomEventHandler(handlerMap: Record<string, DOMEventHandler<Event>>): () => void
  • Add a custom DOM event handler to handle events not handled by roosterjs. Caller need to take the responsibility to dispose the handler properly

    Parameters

    • eventName: string

      DOM event name to handle

    • handler: DOMEventHandler<Event>

      Handler callback

    Returns () => void

    A dispose function. Call the function to dispose this event handler

      • (): void
      • Returns void

  • Add a bunch of custom DOM event handler to handle events not handled by roosterjs. Caller need to take the responsibility to dispose the handler properly

    Parameters

    • handlerMap: Record<string, DOMEventHandler<Event>>

      A event name => event handler map

    Returns () => void

    A dispose function. Call the function to dispose all event handlers added by this function

      • (): void
      • Returns void

addUndoSnapshot

  • Add undo snapshot, and execute a format callback function, then add another undo snapshot, then trigger ContentChangedEvent with given change source. If this function is called nested, undo snapshot will only be added in the outside one

    Parameters

    • Optional callback: (start: NodePosition, end: NodePosition) => any

      The callback function to perform formatting, returns a data object which will be used as the data field in ContentChangedEvent if changeSource is not null.

    • Optional changeSource: string

      The change source to use when fire ContentChangedEvent. When the value is not null, a ContentChangedEvent will be fired with change source equal to this value

    • Optional canUndoByBackspace: boolean

      True if this action can be undone when user presses Backspace key (aka Auto Complete).

    • Optional additionalData: ContentChangedData

      Optional parameter to provide additional data related to the ContentChanged Event.

    Returns void

collapseNodes

  • collapseNodes(start: Node, end: Node, canSplitParent: boolean): Node[]
  • Collapse nodes within the given start and end nodes to their common ancestor node, split parent nodes if necessary

    Parameters

    • start: Node

      The start node

    • end: Node

      The end node

    • canSplitParent: boolean

      True to allow split parent node there are nodes before start or after end under the same parent and the returned nodes will be all nodes from start through end after splitting False to disallow split parent

    Returns Node[]

    When canSplitParent is true, returns all node from start through end after splitting, otherwise just return start and end

contains

  • contains(node: Node): boolean
  • contains(range: Range): boolean

deleteNode

  • deleteNode(node: Node): boolean

deleteSelectedContent

dispose

  • dispose(): void

ensureTypeInContainer

  • ensureTypeInContainer(position: NodePosition, keyboardEvent?: KeyboardEvent): void
  • Ensure user will type into a container element rather than into the editor content DIV directly

    Parameters

    • position: NodePosition

      The position that user is about to type to

    • Optional keyboardEvent: KeyboardEvent

      Optional keyboard event object

    Returns void

focus

  • focus(): void

getBlockElementAtNode

getBlockTraverser

getBodyTraverser

getContent

getContentSearcherOfCursor

getCustomData

  • getCustomData<T>(key: string, getter?: () => T, disposer?: (value: T) => void): T
  • Get custom data related to this editor

    Type parameters

    • T

    Parameters

    • key: string

      Key of the custom data

    • Optional getter: () => T

      Getter function. If custom data for the given key doesn't exist, call this function to get one and store it if it is specified. Otherwise return undefined

        • (): T
        • Returns T

    • Optional disposer: (value: T) => void

      An optional disposer function to dispose this custom data when dispose editor.

        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns T

getDarkColorHandler

getDefaultFormat

getDocument

  • getDocument(): Document

getEditorDomAttribute

  • getEditorDomAttribute(name: string): string

getElementAtCursor

  • getElementAtCursor(selector?: string, startFrom?: Node, event?: PluginEvent): HTMLElement
  • Get an HTML element from current cursor position. When expectedTags is not specified, return value is the current node (if it is HTML element) or its parent node (if current node is a Text node). When expectedTags is specified, return value is the first ancestor of current node which has one of the expected tags. If no element found within editor by the given tag, return null.

    Parameters

    • Optional selector: string

      Optional, an HTML selector to find HTML element with.

    • Optional startFrom: Node

      Optional, start search from this node. If not specified, start from current focused position

    • Optional event: PluginEvent

      Optional, if specified, editor will try to get cached result from the event object first. If it is not cached before, query from DOM and cache the result into the event object

    Returns HTMLElement

getFocusedPosition

getPendableFormatState

  • Get the pendable format state from the current selection, including formats as underline, bold, italics

    Parameters

    • Optional forceGetStateFromDOM: boolean

      If set to true, will not consider the cached format and will get the format state directly from DOM tree

    Returns PendableFormatState

    The pending format state of editor.

getRelativeDistanceToEditor

  • getRelativeDistanceToEditor(element: HTMLElement, addScroll?: boolean): number[]
  • deprecated

    Use getVisibleViewport() instead

    Get current relative distance from top-left corner of the given element to top-left corner of editor content DIV.

    Parameters

    • element: HTMLElement

      The element to calculate from. If the given element is not in editor, return value will be null

    • Optional addScroll: boolean

      When pass true, The return value will also add scrollLeft and scrollTop if any. So the value may be different than what user is seeing from the view. When pass false, scroll position will be ignored.

    Returns number[]

    An [x, y] array which contains the left and top distances, or null if the given element is not in editor.

getScrollContainer

  • getScrollContainer(): HTMLElement

getSelectedRegions

getSelectionPath

getSelectionRange

  • getSelectionRange(tryGetFromCache?: boolean): Range
  • Get current selection range from Editor. It does a live pull on the selection, if nothing retrieved, return whatever we have in cache.

    Parameters

    • Optional tryGetFromCache: boolean

      Set to true to retrieve the selection range from cache if editor doesn't own the focus now. Default value is true

    Returns Range

    current selection range, or null if editor never got focus before

getSelectionRangeEx

getSelectionTraverser

getSizeTransformer

getStyleBasedFormatState

getTrustedHTMLHandler

getUndoState

getVisibleViewport

  • getVisibleViewport(): Rect

getZoomScale

  • getZoomScale(): number
  • Get current zoom scale, default value is 1 When editor is put under a zoomed container, need to pass the zoom scale number using EditorOptions.zoomScale to let editor behave correctly especially for those mouse drag/drop behaviors

    Returns number

    current zoom scale number

hasFocus

  • hasFocus(): boolean

insertContent

  • insertContent(content: string, option?: InsertOption): void

insertNode

  • Insert node into editor

    Parameters

    • node: Node

      The node to insert

    • Optional option: InsertOption

      Insert options. Default value is: position: ContentPosition.SelectionStart updateCursor: true replaceSelection: true insertOnNewLine: false

    Returns boolean

    true if node is inserted. Otherwise false

isDarkMode

  • isDarkMode(): boolean

isDisposed

  • isDisposed(): boolean

isEmpty

  • isEmpty(trim?: boolean): boolean
  • Check whether the editor contains any visible content

    Parameters

    • Optional trim: boolean

      Whether trim the content string before check. Default is false

    Returns boolean

    True if there's no visible content, otherwise false

isFeatureEnabled

isInIME

  • isInIME(): boolean

isInShadowEdit

  • isInShadowEdit(): boolean

isPositionAtBeginning

  • Check if this position is at beginning of the editor. This will return true if all nodes between the beginning of target node and the position are empty.

    Parameters

    Returns boolean

    True if position is at beginning of the editor, otherwise false

paste

  • paste(clipboardData: ClipboardData, pasteAsText?: boolean, applyCurrentFormat?: boolean, pasteAsImage?: boolean): void
  • Paste into editor using a clipboardData object

    Parameters

    • clipboardData: ClipboardData

      Clipboard data retrieved from clipboard

    • Optional pasteAsText: boolean

      Force pasting as plain text. Default value is false

    • Optional applyCurrentFormat: boolean
    • Optional pasteAsImage: boolean

    Returns void

queryElements

  • queryElements<T>(tag: T, forEachCallback?: (node: HTMLElementTagNameMap[T]) => any): HTMLElementTagNameMap[T][]
  • queryElements<T>(selector: string, forEachCallback?: (node: T) => any): T[]
  • queryElements<T>(tag: T, scope: QueryScope | CompatibleQueryScope, forEachCallback?: (node: HTMLElementTagNameMap[T]) => any): HTMLElementTagNameMap[T][]
  • queryElements<T>(selector: string, scope: QueryScope | CompatibleQueryScope, forEachCallback?: (node: T) => any): T[]
  • Query HTML elements in editor by tag name

    Type parameters

    • T: keyof HTMLElementTagNameMap

    Parameters

    • tag: T

      Tag name of the element to query

    • Optional forEachCallback: (node: HTMLElementTagNameMap[T]) => any

      An optional callback to be invoked on each element in query result

        • (node: HTMLElementTagNameMap[T]): any
        • Parameters

          • node: HTMLElementTagNameMap[T]

          Returns any

    Returns HTMLElementTagNameMap[T][]

    HTML Element array of the query result

  • Query HTML elements in editor by a selector string

    Type parameters

    • T: HTMLElement = HTMLElement

    Parameters

    • selector: string

      Selector string to query

    • Optional forEachCallback: (node: T) => any

      An optional callback to be invoked on each node in query result

        • (node: T): any
        • Parameters

          • node: T

          Returns any

    Returns T[]

    HTML Element array of the query result

  • Query HTML elements with the given scope by tag name

    Type parameters

    • T: keyof HTMLElementTagNameMap

    Parameters

    • tag: T

      Tag name of the element to query

    • scope: QueryScope | CompatibleQueryScope

      The scope of the query, default value is QueryScope.Body

    • Optional forEachCallback: (node: HTMLElementTagNameMap[T]) => any

      An optional callback to be invoked on each element in query result

        • (node: HTMLElementTagNameMap[T]): any
        • Parameters

          • node: HTMLElementTagNameMap[T]

          Returns any

    Returns HTMLElementTagNameMap[T][]

    HTML Element list of the query result

  • Query HTML elements with the given scope by a selector string

    Type parameters

    • T: HTMLElement = HTMLElement

    Parameters

    • selector: string

      Selector string to query

    • scope: QueryScope | CompatibleQueryScope

      The scope of the query, default value is QueryScope.Body

    • Optional forEachCallback: (node: T) => any

      An optional callback to be invoked on each element in query result

        • (node: T): any
        • Parameters

          • node: T

          Returns any

    Returns T[]

    HTML Element array of the query result

redo

  • redo(): void

removeContentEditFeature

replaceNode

  • replaceNode(existingNode: Node, toNode: Node, transformColorForDarkMode?: boolean): boolean
  • Replace a node in editor content with another node

    Parameters

    • existingNode: Node

      The existing node to be replaced

    • toNode: Node

      node to replace to

    • Optional transformColorForDarkMode: boolean

      (optional) Whether to transform new node to dark mode. Default is false

    Returns boolean

    true if node is replaced. Otherwise false

runAsync

  • runAsync(callback: (editor: IEditor) => void): () => void

select

  • select(range: Range): boolean
  • select(position: NodePosition): boolean
  • select(start: NodePosition, end: NodePosition): boolean
  • select(node: Node): boolean
  • select(node: Node, offset: number): boolean
  • select(startNode: Node, startOffset: number, endNode: Node, endOffset: number): boolean
  • select(path: SelectionPath): boolean
  • select(table: HTMLTableElement, coordinates: TableSelection): boolean
  • select(rangeEx: SelectionRangeEx): boolean

setContent

  • setContent(content: string, triggerContentChangedEvent?: boolean): void
  • Set HTML content to this editor. All existing content will be replaced. A ContentChanged event will be triggered

    Parameters

    • content: string

      HTML content to set in

    • Optional triggerContentChangedEvent: boolean

      True to trigger a ContentChanged event. Default value is true

    Returns void

setDarkModeState

  • setDarkModeState(nextDarkMode?: boolean): void
  • Set the dark mode state and transforms the content to match the new state.

    Parameters

    • Optional nextDarkMode: boolean

      The next status of dark mode. True if the editor should be in dark mode, false if not.

    Returns void

setEditorDomAttribute

  • setEditorDomAttribute(name: string, value: string): void

setZoomScale

  • setZoomScale(scale: number): void
  • Set current zoom scale, default value is 1 When editor is put under a zoomed container, need to pass the zoom scale number using EditorOptions.zoomScale to let editor behave correctly especially for those mouse drag/drop behaviors

    Parameters

    • scale: number

    Returns void

startShadowEdit

  • startShadowEdit(): void
  • 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.

    Returns void

stopShadowEdit

  • stopShadowEdit(): void

transformToDarkColor

triggerContentChangedEvent

  • triggerContentChangedEvent(source?: string, data?: any): void

triggerPluginEvent

  • Trigger an event to be dispatched to all plugins

    Type parameters

    Parameters

    • eventType: T

      Type of the event

    • data: PluginEventData<T>

      data of the event with given type, this is the rest part of PluginEvent with the given type

    • Optional broadcast: boolean

      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 PluginEventFromType<T>

    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

undo

  • undo(): void

Generated using TypeDoc