Options
All
  • Public
  • Public/Protected
  • All
Menu

Editor for Content Model.

Hierarchy

Implements

Index

Constructors

constructor

Methods

addContentEditFeature

addDomEventHandler

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 press Backspace key (aka Auto Complete).

    • Optional additionalData: ContentChangedData

    Returns void

announce

attachDomEvent

  • attachDomEvent(eventMap: Record<string, DOMEventRecord<Event>>): () => 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(arg: Node | Range): boolean

deleteNode

  • deleteNode(node: Node): boolean

deleteSelectedContent

dispose

  • dispose(): void

ensureTypeInContainer

  • ensureTypeInContainer(position: NodePosition, keyboardEvent?: KeyboardEvent): void

focus

  • focus(): void

formatContentModel

getBlockElementAtNode

getBlockTraverser

getBodyTraverser

getColorManager

getContent

getContentModelCopy

  • Create Content Model from DOM tree in this editor

    Parameters

    • mode: "connected" | "disconnected" | "clean"

      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

    Returns ContentModelDocument

getContentSearcherOfCursor

Protected getCore

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

getDOMHelper

getDOMSelection

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

      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

getEnvironment

getFocusedPosition

getPendableFormatState

getPendingFormat

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

    • tryGetFromCache: boolean = true

      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

getSnapshotsManager

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

isDarkMode

  • isDarkMode(): boolean

isDisposed

  • isDisposed(): boolean

isEmpty

  • isEmpty(trim?: boolean): boolean

isFeatureEnabled

isInIME

  • isInIME(): boolean

isInShadowEdit

  • isInShadowEdit(): boolean

isPositionAtBeginning

paste

  • paste(clipboardData: ClipboardData, pasteAsText?: boolean, applyCurrentFormat?: boolean, pasteAsImage?: boolean): void

queryElements

  • queryElements(selector: string, scopeOrCallback?: QueryScope | CompatibleQueryScope | ((node: Node) => any), callback?: (node: Node) => any): HTMLElement[]

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

restoreSnapshot

  • restoreSnapshot(snapshot: Snapshot): void

runAsync

select

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

    • triggerContentChangedEvent: boolean = true

      True to trigger a ContentChanged event. Default value is true

    Returns void

setDOMSelection

setDarkModeState

  • setDarkModeState(isDarkMode?: boolean): void

setEditorDomAttribute

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

setEditorStyle

  • setEditorStyle(key: string, cssRule: string, subSelectors?: string[] | "before" | "after"): void
  • Add CSS rules for editor

    Parameters

    • key: string

      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.

    • cssRule: string

      The CSS rule string, must be a valid CSS rule string, or browser may throw exception. Pass null to clear existing rules

    • Optional subSelectors: string[] | "before" | "after"

      @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.

    Returns void

setLogicalRoot

  • setLogicalRoot(logicalRoot: HTMLDivElement): 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

      The new scale number to set. It should be positive number and no greater than 10, otherwise it will be ignored.

    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

takeSnapshot

transformToDarkColor

triggerContentChangedEvent

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

triggerEvent

  • 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

    • broadcast: boolean = false

      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

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

    • broadcast: boolean = false

      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