Tree is a CRDT-based tree structure that is used to represent the document tree of text-based editor such as ProseMirror.

Constructors

Properties

context?: ChangeContext<Indexable>
initialRoot?: ElementNode
tree?: CRDTTree

Methods

  • buildRoot builds the root of this tree with the given initial root which set by the user.

    Parameters

    Returns CRDTTreeNode

  • edit edits this tree with the given nodes.

    Parameters

    • fromIdx: number
    • toIdx: number
    • Optional content: TreeNode
    • splitLevel: number = 0

    Returns boolean

  • editBulk edits this tree with the given nodes.

    Parameters

    • fromIdx: number
    • toIdx: number
    • contents: TreeNode[]
    • splitLevel: number = 0

    Returns boolean

  • editBulkByPath edits this tree with the given node and path.

    Parameters

    • fromPath: number[]
    • toPath: number[]
    • contents: TreeNode[]
    • splitLevel: number = 0

    Returns boolean

  • editByPath edits this tree with the given node and path.

    Parameters

    • fromPath: number[]
    • toPath: number[]
    • Optional content: TreeNode
    • splitLevel: number = 0

    Returns boolean

  • Parameters

    • fromPos: CRDTTreePos
    • toPos: CRDTTreePos
    • contents: TreeNode[]
    • splitLevel: number = 0

    Returns boolean

  • getIndexTree returns the index tree of this tree.

    Returns IndexTree<CRDTTreeNode>

  • indexToPath returns the path of the given index.

    Parameters

    • index: number

    Returns number[]

  • Internal

    initialize initialize this tree with context and internal tree.

    Parameters

    • context: ChangeContext<Indexable>
    • tree: CRDTTree

    Returns void

  • pathToIndex returns the index of given path.

    Parameters

    • path: number[]

    Returns number

  • posRangeToPathRange converts the position range into the path range.

    Parameters

    Returns [number[], number[]]

  • removeStyle removes the attributes to the elements of the given range.

    Parameters

    • fromIdx: number
    • toIdx: number
    • attributesToRemove: string[]

    Returns void

  • style sets the attributes to the elements of the given range.

    Parameters

    • fromIdx: number
    • toIdx: number
    • attributes: {
          [key: string]: any;
      }
      • [key: string]: any

    Returns void

  • styleByPath sets the attributes to the elements of the given path.

    Parameters

    • path: number[]
    • attributes: {
          [key: string]: any;
      }
      • [key: string]: any

    Returns void