Options
All
  • Public
  • Public/Protected
  • All
Menu

Module roosterjs-content-model-dom

Index

Variables

Functions

Variables

Const BorderKeys

BorderKeys: (keyof BorderFormat & keyof CSSStyleDeclaration)[] = ...

Keys of border items

Const BulletListType

BulletListType: { Circle: number; Dash: number; Disc: number; DoubleLongArrow: number; Hyphen: number; LongArrow: number; Max: number; Min: number; ShortArrow: number; Square: number; UnfilledArrow: number } = ...

Enum used to control the different types of bullet list

Type declaration

  • Circle: number
  • Dash: number
  • Disc: number
  • DoubleLongArrow: number
  • Hyphen: number
  • LongArrow: number
  • Max: number
  • Min: number
  • ShortArrow: number
  • Square: number
  • UnfilledArrow: number

Const ChangeSource

ChangeSource: { AutoFormat: string; AutoLink: string; CreateLink: string; Cut: string; Drop: string; Format: string; ImageResize: string; InsertEntity: string; Keyboard: string; ListChain: string; Paste: string; SetContent: string; SwitchToDarkMode: string; SwitchToLightMode: string } = ...

Possible change sources. Here are the predefined sources. It can also be other string if the change source can't fall into these sources.

Type declaration

  • AutoFormat: string
  • AutoLink: string
  • CreateLink: string
  • Cut: string
  • Drop: string
  • Format: string
  • ImageResize: string
  • InsertEntity: string
  • Keyboard: string
  • ListChain: string
  • Paste: string
  • SetContent: string
  • SwitchToDarkMode: string
  • SwitchToLightMode: string

Const DeprecatedColors

DeprecatedColors: string[] = ...

List of deprecated colors

Const EmptySegmentFormat

EmptySegmentFormat: Readonly<Required<ContentModelSegmentFormat>> = ...

Provide a default empty instance of segment format with all its properties

Const ListMetadataDefinition

ListMetadataDefinition: ObjectDefinition<ListMetadataFormat> = ...

Metadata definition for List

Const MIN_ALLOWED_TABLE_CELL_HEIGHT

MIN_ALLOWED_TABLE_CELL_HEIGHT: number = 22

Minimum height for a table cell

Const MIN_ALLOWED_TABLE_CELL_WIDTH

MIN_ALLOWED_TABLE_CELL_WIDTH: number = 30

Minimum width for a table cell

Const NumberingListType

NumberingListType: { Decimal: number; DecimalDash: number; DecimalDoubleParenthesis: number; DecimalParenthesis: number; LowerAlpha: number; LowerAlphaDash: number; LowerAlphaDoubleParenthesis: number; LowerAlphaParenthesis: number; LowerRoman: number; LowerRomanDash: number; LowerRomanDoubleParenthesis: number; LowerRomanParenthesis: number; Max: number; Min: number; UpperAlpha: number; UpperAlphaDash: number; UpperAlphaDoubleParenthesis: number; UpperAlphaParenthesis: number; UpperRoman: number; UpperRomanDash: number; UpperRomanDoubleParenthesis: number; UpperRomanParenthesis: number } = ...

Enum used to control the different types of numbering list

Type declaration

  • Decimal: number
  • DecimalDash: number
  • DecimalDoubleParenthesis: number
  • DecimalParenthesis: number
  • LowerAlpha: number
  • LowerAlphaDash: number
  • LowerAlphaDoubleParenthesis: number
  • LowerAlphaParenthesis: number
  • LowerRoman: number
  • LowerRomanDash: number
  • LowerRomanDoubleParenthesis: number
  • LowerRomanParenthesis: number
  • Max: number
  • Min: number
  • UpperAlpha: number
  • UpperAlphaDash: number
  • UpperAlphaDoubleParenthesis: number
  • UpperAlphaParenthesis: number
  • UpperRoman: number
  • UpperRomanDash: number
  • UpperRomanDoubleParenthesis: number
  • UpperRomanParenthesis: number

Const OrderedListStyleMap

OrderedListStyleMap: Record<number, string> = ...

Style map for ordered list

Const TableBorderFormat

TableBorderFormat: { Clear: number; Default: number; EspecialType1: number; EspecialType2: number; EspecialType3: number; FirstColumnHeaderExternal: number; ListWithSideBorders: number; Max: number; Min: number; NoHeaderBorders: number; NoSideBorders: number } = ...

Table format border

Type declaration

  • Clear: number
  • Default: number
  • EspecialType1: number
  • EspecialType2: number
  • EspecialType3: number
  • FirstColumnHeaderExternal: number
  • ListWithSideBorders: number
  • Max: number
  • Min: number
  • NoHeaderBorders: number
  • NoSideBorders: number

Const UnorderedListStyleMap

UnorderedListStyleMap: Record<number, string> = ...

Style map for unordered list

Functions

addBlock

addCode

addDelimiters

addLink

addSegment

addTextSegment

applyTableFormat

areSameFormats

  • areSameFormats<T>(f1: T, f2: T): boolean

buildSelectionMarker

cacheGetEventData

  • cacheGetEventData<T, E>(event: E, key: string, getter: (event: E) => T): T
  • Gets the cached event data by cache key from event object if there is already one. Otherwise, call getter function to create one, and cache it.

    Type parameters

    Parameters

    • event: E

      The event object

    • key: string

      Cache key string, need to be unique

    • getter: (event: E) => T

      Getter function to get the object when it is not in cache yet

        • (event: E): T
        • Parameters

          • event: E

          Returns T

    Returns T

Const childProcessor

cloneModel

combineBorderValue

  • combineBorderValue(value: Border): string

contentModelToDom

  • Create DOM tree fragment from Content Model document

    Parameters

    • doc: Document

      Document object of the target DOM tree

    • root: Node

      Target node that will become the container of new DOM tree. When a DOM node with existing node is passed, it will be merged with content model so that unchanged blocks won't be touched.

    • model: ContentModelDocument

      The content model document to generate DOM tree from

    • context: ModelToDomContext

      The context object for Content Model to DOM conversion

    Returns DOMSelection | null

    The selection range created in DOM tree from this model, or null when there is no selection

contentModelToText

createBr

createContentModelDocument

createDivider

createDomToModelConfig

createDomToModelContext

createDomToModelContextWithConfig

createEmptyModel

createEntity

createFormatContainer

createGeneralBlock

createGeneralSegment

createImage

createListItem

createListLevel

createModelToDomConfig

createModelToDomContext

createModelToDomContextWithConfig

createParagraph

createParagraphDecorator

createSelectionMarker

createTable

createTableCell

createTableRow

createText

Const defaultGenerateColorKey

  • defaultGenerateColorKey(lightColor: string, baseLValue?: number, colorType?: "text" | "border" | "background", element?: HTMLElement): string

deleteBlock

deleteSegment

deleteSelection

domToContentModel

Const entityProcessor

extractBorderValues

  • extractBorderValues(combinedBorder?: string): Border

extractClipboardItems

  • extractClipboardItems(items: DataTransferItem[], allowedCustomPasteType?: string[]): Promise<ClipboardData>
  • Extract clipboard items to be a ClipboardData object for IE

    Parameters

    • items: DataTransferItem[]

      The clipboard items retrieve from a DataTransfer object

    • Optional allowedCustomPasteType: string[]

      Allowed custom content type when paste besides text/plain, text/html and images Only text types are supported, and do not add "text/" prefix to the type values

    Returns Promise<ClipboardData>

findClosestBlockEntityContainer

  • findClosestBlockEntityContainer(node: Node, domHelper: DOMHelper): HTMLElement | null

findClosestEntityWrapper

  • findClosestEntityWrapper(startNode: Node, domHelper: DOMHelper): HTMLElement | null

generateEntityClassNames

getAllEntityWrappers

  • getAllEntityWrappers(root: HTMLElement): HTMLElement[]

getAutoListStyleType

  • getAutoListStyleType(listType: "OL" | "UL", metadata: ListMetadataFormat, depth: number, existingStyleType?: string): number | undefined
  • Get automatic list style of a list item according to its lis type and metadata.

    Parameters

    • listType: "OL" | "UL"

      The list type, either OL or UL

    • metadata: ListMetadataFormat

      Metadata of this list item from list item model

    • depth: number

      Depth of list level, start from 0

    • Optional existingStyleType: string

      Existing list style type in format, if any

    Returns number | undefined

    A number to represent list style type. This will be the value of either NumberingListType (when listType is OL) or BulletListType (when listType is UL). When there is a specified list style in its metadata, return this value, otherwise When specified "applyListStyleFromLevel" in metadata, calculate auto list type from its depth, otherwise When there is already listStyleType in list level format, find a related style type index, otherwise return undefined

getClosestAncestorBlockGroupIndex

getColor

  • getColor(element: HTMLElement, isBackground: boolean, isDarkMode: boolean, darkColorHandler?: DarkColorHandler): string | undefined
  • Get color from given HTML element

    Parameters

    • element: HTMLElement

      The element to get color from

    • isBackground: boolean

      True to get background color, false to get text color

    • isDarkMode: boolean

      Whether element is in dark mode now

    • Optional darkColorHandler: DarkColorHandler

      @optional The dark color handler object to help manager dark mode color

    Returns string | undefined

getDOMInsertPointRect

getFirstSelectedListItem

getFirstSelectedTable

getImageMetadata

getListMetadata

getListStyleTypeFromString

  • getListStyleTypeFromString(listType: "OL" | "UL", bullet: string): number

getMetadata

getObjectKeys

  • getObjectKeys<T>(obj: Record<T, any> | Partial<Record<T, any>>): T[]

getOperationalBlocks

getOrderedListNumberStr

  • getOrderedListNumberStr(styleType: number, listNumber: number): string
  • Get the list number for a list item according to list style type and its index number

    Parameters

    • styleType: number

      The list style number, should be a value of NumberingListType type

    • listNumber: number

      List number, start from 1

    Returns string

    A string for this list item. For example, when pass in NumberingListType.LowerAlpha and 2, it returns "b"

getRegularSelectionOffsets

  • getRegularSelectionOffsets(context: DomToModelContext, currentContainer: Node): [number, number]
  • Get offset numbers of a regular (range based) selection. If the selection start/end position is not in the given node, it will return -1 for the related value

    Parameters

    • context: DomToModelContext

      DOM to Content Model context used for retrieve the selection

    • currentContainer: Node

      The container node to check

    Returns [number, number]

    a tuple of start and end offsets. -1 means selection is not directly under the given node

getSafeIdSelector

  • getSafeIdSelector(id: string): string

getSegmentTextFormat

getSelectedCells

getSelectedParagraphs

getSelectedSegments

getSelectedSegmentsAndParagraphs

getSelectionRootNode

  • getSelectionRootNode(selection: DOMSelection | undefined): Node | undefined

getTableCellMetadata

getTableMetadata

handleRegularSelection

hasMetadata

hasSelectionInBlock

hasSelectionInBlockGroup

hasSelectionInSegment

isBlockElement

  • isBlockElement(element: HTMLElement): boolean

isBlockEntityContainer

  • isBlockEntityContainer(element: HTMLElement): boolean

isBlockGroupOfType

isBold

  • isBold(boldStyle?: string): boolean

isCharacterValue

  • isCharacterValue(event: KeyboardEvent): boolean
  • Returns true when the event was fired from a key that produces a character value, otherwise false This detection is not 100% accurate. event.key is not fully supported by all browsers, and in some browsers (e.g. IE), event.key is longer than 1 for num pad input. But here we just want to improve performance as much as possible. So if we missed some case here it is still acceptable.

    Parameters

    • event: KeyboardEvent

      The keyboard event object

    Returns boolean

isCursorMovingKey

  • isCursorMovingKey(event: KeyboardEvent): boolean
  • Returns true if the given event is a cursor moving event (Left, Right, Up, Down, Home, End, Page Up, Page Down). This does not check modifier keys (Ctrl, Alt, Meta). So if there are modifier keys pressed, it can still return true if one of the modifier key is pressed

    Parameters

    • event: KeyboardEvent

      The keyboard event to check

    Returns boolean

isElementOfType

  • isElementOfType<Tag>(element: HTMLElement, tag: Tag): element is HTMLElementTagNameMap[Tag]
  • Check if the given element is of the type that we are checking according to its tag name

    Type parameters

    • Tag: keyof HTMLElementTagNameMap

    Parameters

    • element: HTMLElement

      The element to check

    • tag: Tag

      The HTML tag name to check

    Returns element is HTMLElementTagNameMap[Tag]

    True if the element has the given tag, otherwise false

isEmpty

isEntityDelimiter

  • isEntityDelimiter(element: HTMLElement, isBefore?: boolean): boolean
  • Checks whether the node provided is a Entity delimiter

    Parameters

    • element: HTMLElement
    • Optional isBefore: boolean

      True to match delimiter before entity only, false to match delimiter after entity, or undefined means match both

    Returns boolean

    true if it is a delimiter

isEntityElement

  • isEntityElement(node: Node): boolean

isGeneralSegment

isModifierKey

  • isModifierKey(event: KeyboardEvent): boolean

isNodeOfType

  • isNodeOfType<T>(node: Node | null | undefined, expectedType: T): node is NodeTypeMap[T]

isPunctuation

  • isPunctuation(char: string): boolean

isSpace

  • isSpace(char: string): boolean
  • Check if the give character is a space. A space can be normal ASCII pace (32) or non-break space (160) or other kinds of spaces such as ZeroWidthSpace, ...

    Parameters

    • char: string

      The character to check

    Returns boolean

isWhiteSpacePreserved

  • isWhiteSpacePreserved(whiteSpace: string | undefined): boolean

iterateSelections

mergeModel

mergeTextSegments

moveChildNodes

  • moveChildNodes(target: Node, source?: Node, keepExistingChildren?: boolean): void
  • Replace all child nodes of the given target node to the child nodes of source node.

    Parameters

    • target: Node

      Target node, all child nodes of this node will be removed if keepExistingChildren is not set to true

    • Optional source: Node

      (Optional) source node, all child nodes of this node will be move to target node

    • Optional keepExistingChildren: boolean

      (Optional) When set to true, all existing child nodes of target will be kept

    Returns void

mutateBlock

mutateSegment

mutateSegments

normalizeContentModel

  • For a given content model, normalize it to make the model be consistent. This process includes:

    • For a list item without any list level, unwrap the list item
    • For a paragraph, make sure it has BR at the end if it is an empty paragraph
    • For text segments under paragraph, make sure its space values are correct (use nbsp to replace space when necessary)
    • For an empty block, remove it

    Parameters

    Returns void

normalizeParagraph

normalizeRect

  • normalizeRect(clientRect: DOMRect): Rect | null
  • A ClientRect of all 0 is possible. i.e. chrome returns a ClientRect of 0 when the cursor is on an empty p We validate that and only return a rect when the passed in ClientRect is valid

    Parameters

    • clientRect: DOMRect

      Client rect object normally retrieved from getBoundingClientRect function

    Returns Rect | null

normalizeSingleSegment

normalizeTable

normalizeText

  • normalizeText(txt: string, isForward: boolean): string
  • Normalize spaces of the given string. After normalization, all leading (for forward) or trailing (for backward) spaces will be replaces with non-break space (160)

    Parameters

    • txt: string

      The string to normalize

    • isForward: boolean

      Whether normalize forward or backward

    Returns string

parseColor

  • parseColor(color: string): [number, number, number] | null
  • Parse color string to r/g/b value. If the given color is not in a recognized format, return null

    Parameters

    • color: string

      The source color to parse

    Returns [number, number, number] | null

    An array of Red/Green/Blue value, or null if fail to parse

parseEntityFormat

parseFormat

parseTableCells

  • parseTableCells(table: HTMLTableElement): ParsedTable

parseValueWithUnit

  • parseValueWithUnit(value?: string, currentSizePxOrElement?: number | HTMLElement, resultUnit?: "px" | "pt"): number
  • Parse unit value with its unit

    Parameters

    • value: string = ''

      The source value to parse

    • Optional currentSizePxOrElement: number | HTMLElement

      The source element which has this unit value, or current font size (in px) from context.

    • resultUnit: "px" | "pt" = 'px'

      Unit for result, can be px or pt. @default px

    Returns number

processChildNode

readFile

  • readFile(file: File, callback: (dataUrl: string | null) => void): void
  • Read a file object and invoke a callback function with the data url of this file

    Parameters

    • file: File

      The file to read

    • callback: (dataUrl: string | null) => void

      the callback to invoke with data url of the file. If fail to read, dataUrl will be null

        • (dataUrl: string | null): void
        • Parameters

          • dataUrl: string | null

          Returns void

    Returns void

retrieveModelFormatState

reuseCachedElement

  • reuseCachedElement(parent: Node, element: Node, refNode: Node | null, context?: RewriteFromModel): Node | null
  • When set a DOM tree into editor, reuse the existing element in editor and no need to change it

    Parameters

    • parent: Node

      Parent node of the reused element

    • element: Node

      The element to keep in parent node

    • refNode: Node | null

      Reference node, it is point to current node that is being processed. It must be a child of parent node, or null. We will start processing from this node, if it is not the same with element, remove it and keep processing its next sibling, until we see an element that is the same with the passed in element or null.

    • Optional context: RewriteFromModel

    Returns Node | null

    The new reference element

runEditSteps

setColor

  • setColor(element: HTMLElement, color: string | null | undefined, isBackground: boolean, isDarkMode: boolean, darkColorHandler?: DarkColorHandler): void
  • Set color to given HTML element

    Parameters

    • element: HTMLElement

      The element to set color to

    • color: string | null | undefined

      The color to set, always pass in color in light mode

    • isBackground: boolean

      True to set background color, false to set text color

    • isDarkMode: boolean

      Whether element is in dark mode now

    • Optional darkColorHandler: DarkColorHandler

      @optional The dark color handler object to help manager dark mode color

    Returns void

setFirstColumnFormatBorders

setParagraphNotImplicit

setSelection

setTableCellBackgroundColor

Const tableProcessor

  • Content Model Element Processor for table

    For Table with merged/splitted cells, HTML uses colSpan and rowSpan attributes to specify how it should be rendered. To make it easier to edit a table, we will use a different way to describe table.

    1. For a m * n table (m rows, n columns), we always create a m * n array for the cells.
    2. For a regular table cell, it is mapped to one item of this array
    3. For a merged/splitted table cell, it will has colSpan/rowSpan value. We also created TableCell model for those spanned cells, and use "spanLeft" and "spanAbove" to mark its state
    4. When edit table, we always edit on this mapped m * n array because it always has an item for each cell
    5. When write back to DOM, we create TD/TH elements for those non-spanned cells, and mark its colSpan/rowSpan value according its neighbour cell's spanLeft/spanAbove attribute

    Parameters

    Returns void

toArray

  • toArray(collection: NamedNodeMap): Attr[]
  • toArray(collection: DataTransferItemList): DataTransferItem[]
  • toArray<T>(collection: NodeListOf<T>): T[]
  • toArray<T>(collection: HTMLCollectionOf<T>): T[]
  • toArray<T>(array: readonly T[]): T[]

transformColor

  • transformColor(rootNode: Node, includeSelf: boolean, direction: "lightToDark" | "darkToLight", darkColorHandler?: DarkColorHandler): void
  • Edit and transform color of elements between light mode and dark mode

    Parameters

    • rootNode: Node

      The root DOM node to transform

    • includeSelf: boolean

      True to transform the root node as well, otherwise false

    • direction: "lightToDark" | "darkToLight"

      To specify the transform direction, light to dark, or dark to light

    • Optional darkColorHandler: DarkColorHandler

      The dark color handler object to help do color transformation

    Returns void

unwrap

  • unwrap(node: Node): Node | null

unwrapBlock

updateImageMetadata

updateListMetadata

updateMetadata

updateTableCellMetadata

updateTableMetadata

wrap

  • wrap<T>(doc: Document, node: Node, wrapperTag: T): HTMLElementTagNameMap[T]
  • Wrap the given node with a new element, put the wrapper node under the parent of the first node and return the wrapper element.

    Type parameters

    • T: keyof HTMLElementTagNameMap

    Parameters

    • doc: Document

      Parent document object

    • node: Node

      The node to wrap

    • wrapperTag: T

      The tag of wrapper HTML element

    Returns HTMLElementTagNameMap[T]

    The wrapper element

wrapAllChildNodes

  • wrapAllChildNodes<T>(parent: HTMLElement, tagName: T): HTMLElementTagNameMap[T]
  • Wrap all child nodes of the given parent element using a new element with the given tag name

    Type parameters

    • T: keyof HTMLElementTagNameMap

    Parameters

    • parent: HTMLElement

      The parent element

    • tagName: T

      The tag name of new wrapper

    Returns HTMLElementTagNameMap[T]

    New wrapper element

Generated using TypeDoc