Expand all

ve.Document

Constructor

new ve.Document(documentNode) #

Generic document.

Parameters:

Name Type Description
documentNode ve.BranchNode

Document node

Mixes in:
Source:
Generic document.

Methods

getBranchNodeFromOffset(offset) → {ve.Node|null} #

Get a node at an offset.

Parameters:

Name Type Description
offset number

Offset to get node at

Source:

Returns:

Node at offset

Type
ve.Node | null
Get a node at an offset.

getCoveredSiblingGroups(range) → {Array} #

Get groups of sibling nodes covered by the given range.

Parameters:

Name Type Description
range ve.Range
Source:

Returns:

Array of objects. Each object has the following keys:

  • nodes: Array of sibling nodes covered by a part of range
  • parent: Parent of all of these nodes
  • grandparent: parent's parent
Type
Array
Get groups of sibling nodes covered by the given range.

getDocumentNode() → {ve.BranchNode} #

Get the root of the document's node tree.

Source:

Returns:

Root of node tree

Type
ve.BranchNode
Get the root of the document's node tree.

nodeAttached(node) #

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

Parameters:

Name Type Description
node ve.Node

The node attached

Source:

Fires:

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

nodeDetached(node) #

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

Parameters:

Name Type Description
node ve.Node

The node detached

Source:

Fires:

Callback when a node is attached with ve.Node#setDocument

The node and all its children are guaranteed to be attached

rangeInsideOneLeafNode(range) → {boolean} #

Test whether a range lies within a single leaf node.

Parameters:

Name Type Description
range ve.Range

The range to test

Source:

Returns:

Whether the range lies within a single node

Type
boolean
Test whether a range lies within a single leaf node.

selectNodes(range, [mode]) → {Array} #

Gets a list of nodes and the ranges within them that a selection of the document covers.

Parameters:

Name Type Attributes Default Description
range ve.Range

Range within document to select nodes

mode string optional
'leaves'

Type of selection to perform:

  • leaves: Return all leaf nodes in the given range (descends all the way down)
  • branches': Return all branch nodes in the given range
  • covered: Do not descend into nodes that are entirely covered by the range. The result is similar to that of 'leaves' except that if a node is entirely covered, its children aren't returned separately.
  • siblings: Return a set of adjacent siblings covered by the range (descends as long as the range is in a single node)
Source:

Returns:

List of objects describing nodes in the selection and the ranges therein:

  • node: Reference to a ve.Node
  • range: ve.Range, missing if the entire node is covered
  • index: Index of the node in its parent, missing if node has no parent
  • indexInNode: If range is a zero-length range between two children of node, this is set to the index of the child following range (or to node.children.length + 1 if range is between the last child and the end). If range is a zero-length range inside an empty non-content branch node, this is 0. Missing in all other cases.
  • nodeRange: Range covering the inside of the entire node, not including wrapper
  • nodeOuterRange: Range covering the entire node, including wrapper
  • parentOuterRange: Outer range of node's parent. Missing if there is no parent or if indexInNode is set.
Type
Array

Throws:

  • Invalid mode

    Type
    Error
  • Invalid start offset

    Type
    Error
  • Invalid end offset

    Type
    Error
  • Failed to select any nodes

    Type
    Error
Gets a list of nodes and the ranges within them that a selection of the document covers.

Events

nodeAttached(node) #

A node has been attached with ve.Node#setDocument . Its descendants are guaranteed to be attached too (and the event is emitted for descendants first, and for siblings in their order in the children list)

Parameters:

Name Type Description
node ve.Node

The node that has been attached

Source:
A node has been attached with ve.Node#setDocument .

nodeDetached(node) #

A node has been detached with ve.Node#setDocument . Its descendants are guaranteed to be detached too (and the event is emitted for descendants first, and for siblings in their order in the children list)

Parameters:

Name Type Description
node ve.Node

The node that has been detached

Source:
A node has been detached with ve.Node#setDocument .