Skip to content

Type Editor


Type Editor / @type-editor/viewdesc / TextViewDesc / TextViewDesc

Class: TextViewDesc

Defined in: TextViewDesc.ts:15

View description for text nodes. Text nodes are leaf nodes that contain only text content and no children. They can be wrapped by mark decorations but don't have their own content DOM.

Extends

Constructors

Constructor

ts
new TextViewDesc(
   parent,
   node,
   outerDeco,
   innerDeco,
   dom,
   nodeDOM): TextViewDesc;

Defined in: TextViewDesc.ts:29

Creates a new TextViewDesc.

Parameters

ParameterTypeDescription
parentViewDescThe parent view description
nodeNode_2The text node
outerDecoreadonly PmDecoration[]Outer decorations (typically marks)
innerDecoDecorationSourceInner decorations (unused for text nodes)
domNodeThe outer DOM node (may include mark wrappers)
nodeDOMNodeThe actual text DOM node

Returns

TextViewDesc

Overrides

NodeViewDesc.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_childrenprotectedViewDesc[]undefinedNodeViewDesc._childrenViewDesc.ts:28
_contentDOMreadonlyHTMLElementundefinedNodeViewDesc._contentDOMViewDesc.ts:24
_dirtyprotectedViewDirtyStateViewDirtyState.NOT_DIRTYNodeViewDesc._dirtyViewDesc.ts:25
_domprotectedNodeundefinedNodeViewDesc._domViewDesc.ts:29
_innerDecoprotectedDecorationSourcenullNodeViewDesc._innerDecoNodeViewDesc.ts:22
_nodeprotectedNode_2undefinedNodeViewDesc._nodeViewDesc.ts:26
_nodeDOMreadonlyNodeundefinedNodeViewDesc._nodeDOMNodeViewDesc.ts:20
_outerDecoprotectedreadonly PmDecoration[]nullNodeViewDesc._outerDecoNodeViewDesc.ts:21
_parentprotectedViewDescundefinedNodeViewDesc._parentViewDesc.ts:27

Accessors

border

Get Signature

ts
get border(): number;

Defined in: NodeViewDesc.ts:77

For block nodes, this represents the space taken up by their start/end tokens.

Returns

number

Inherited from

NodeViewDesc.border


children

Get Signature

ts
get children(): ViewDesc[];

Defined in: ViewDesc.ts:88

The child view descriptions of this view.

Returns

ViewDesc[]

Set Signature

ts
set children(children): void;

Defined in: ViewDesc.ts:92

Parameters
ParameterType
childrenViewDesc[]
Returns

void

Inherited from

WidgetViewDesc.children


contentDOM

Get Signature

ts
get contentDOM(): HTMLElement;

Defined in: ViewDesc.ts:106

The DOM node that contains child content, if any.

Returns

HTMLElement

Inherited from

NodeViewDesc.contentDOM


contentLost

Get Signature

ts
get contentLost(): boolean;

Defined in: ViewDesc.ts:134

Checks if the content DOM has been detached from the main DOM.

Returns

boolean

Inherited from

NodeViewDesc.contentLost


dirty

Get Signature

ts
get dirty(): ViewDirtyState;

Defined in: ViewDesc.ts:59

The dirty state of this description. Can be NOT_DIRTY, CHILD_DIRTY, CONTENT_DIRTY, or NODE_DIRTY.

Returns

ViewDirtyState

Set Signature

ts
set dirty(dirty): void;

Defined in: ViewDesc.ts:63

Parameters
ParameterType
dirtyViewDirtyState
Returns

void

Inherited from

NodeViewDesc.dirty


dom

Get Signature

ts
get dom(): Node;

Defined in: ViewDesc.ts:99

The DOM node this description represents.

Returns

Node

Inherited from

NodeViewDesc.dom


domAtom

Get Signature

ts
get domAtom(): boolean;

Defined in: TextViewDesc.ts:38

Whether this description represents an atomic node that should be treated as a single unit.

Returns

boolean

Overrides

NodeViewDesc.domAtom


ignoreForCoords

Get Signature

ts
get ignoreForCoords(): boolean;

Defined in: ViewDesc.ts:120

Whether this view should be ignored when determining coordinates.

Returns

boolean

Inherited from

NodeViewDesc.ignoreForCoords


ignoreForSelection

Get Signature

ts
get ignoreForSelection(): boolean;

Defined in: ViewDesc.ts:127

Whether this view should be ignored for selection purposes.

Returns

boolean

Inherited from

NodeViewDesc.ignoreForSelection


innerDeco

Get Signature

ts
get innerDeco(): DecorationSource;

Defined in: NodeViewDesc.ts:61

The decoration source for decorations inside this node. Provides access to decorations that should be applied to child content.

Returns

DecorationSource

Inherited from

NodeViewDesc.innerDeco


node

Get Signature

ts
get node(): Node_2;

Defined in: ViewDesc.ts:70

The ProseMirror node this description represents, if any.

Returns

Node_2

Inherited from

NodeViewDesc.node


nodeDOM

Get Signature

ts
get nodeDOM(): Node;

Defined in: NodeViewDesc.ts:69

The DOM node that directly represents this ProseMirror node. May differ from dom if outer decorations wrap it.

Returns

Node

Inherited from

NodeViewDesc.nodeDOM


outerDeco

Get Signature

ts
get outerDeco(): readonly PmDecoration[];

Defined in: NodeViewDesc.ts:53

The decorations that wrap this node from the outside. These might add attributes, classes, or wrapper elements around the node.

Returns

readonly PmDecoration[]

Inherited from

NodeViewDesc.outerDeco


parent

Get Signature

ts
get parent(): ViewDesc;

Defined in: ViewDesc.ts:77

The parent view description in the tree.

Returns

ViewDesc

Set Signature

ts
set parent(parent): void;

Defined in: ViewDesc.ts:81

Parameters
ParameterType
parentViewDesc
Returns

void

Inherited from

WidgetViewDesc.parent


posAfter

Get Signature

ts
get posAfter(): number;

Defined in: ViewDesc.ts:155

The document position just after this view.

Returns

number

Inherited from

NodeViewDesc.posAfter


posAtEnd

Get Signature

ts
get posAtEnd(): number;

Defined in: ViewDesc.ts:162

The document position at the end of this view's content.

Returns

number

Inherited from

NodeViewDesc.posAtEnd


posAtStart

Get Signature

ts
get posAtStart(): number;

Defined in: ViewDesc.ts:148

The document position at the start of this view's content.

Returns

number

Inherited from

NodeViewDesc.posAtStart


posBefore

Get Signature

ts
get posBefore(): number;

Defined in: ViewDesc.ts:141

The document position just before this view.

Returns

number

Inherited from

NodeViewDesc.posBefore


side

Get Signature

ts
get side(): number;

Defined in: ViewDesc.ts:185

Gets the side value which determines positioning behavior of the view.

  • Negative values: positioned before content
  • Zero: neutral positioning
  • Positive values: positioned after content
Returns

number

Inherited from

NodeViewDesc.side


size

Get Signature

ts
get size(): number;

Defined in: NodeViewDesc.ts:73

The size of the content represented by this desc.

Returns

number

Inherited from

NodeViewDesc.size

Methods

descAt()

ts
descAt(pos): ViewDesc;

Defined in: ViewDesc.ts:371

Find the desc for the node after the given pos, if any. (When a parent node overrode rendering, there might not be one.)

Parameters

ParameterTypeDescription
posnumberThe document position to search for

Returns

ViewDesc

The view description at that position, or undefined

Inherited from

NodeViewDesc.descAt


deselectNode()

ts
deselectNode(): void;

Defined in: NodeViewDesc.ts:499

Remove selected node marking from this node.

Returns

void

Inherited from

NodeViewDesc.deselectNode


destroy()

ts
destroy(): void;

Defined in: ViewDesc.ts:265

Destroys this view description and all its children, cleaning up references.

This method ensures proper cleanup even if exceptions occur during child destruction.

Returns

void

Inherited from

NodeViewDesc.destroy


domAfterPos()

ts
domAfterPos(pos): Node;

Defined in: ViewDesc.ts:468

Gets the DOM node immediately after a given document position.

Parameters

ParameterTypeDescription
posnumberThe document position

Returns

Node

The DOM node after the position

Throws

RangeError if there's no node after the position

Inherited from

NodeViewDesc.domAfterPos


domFromPos()

ts
domFromPos(pos): {
  node: Node;
  offset: number;
};

Defined in: TextViewDesc.ts:114

Converts a document position to a DOM position within the text node.

Parameters

ParameterTypeDescription
posnumberThe position offset within this text node

Returns

ts
{
  node: Node;
  offset: number;
}

The text DOM node and offset

NameTypeDefined in
nodeNodeTextViewDesc.ts:114
offsetnumberTextViewDesc.ts:114

Overrides

NodeViewDesc.domFromPos


emptyChildAt()

ts
emptyChildAt(side): boolean;

Defined in: ViewDesc.ts:452

Checks if there's an empty child at the start or end of this view.

Parameters

ParameterTypeDescription
sidenumberDirection to check (-1 for start, 1 for end)

Returns

boolean

True if there's an empty child at the specified side

Inherited from

NodeViewDesc.emptyChildAt


getDesc()

ts
getDesc(dom): ViewDesc;

Defined in: ViewDesc.ts:333

Gets a view description from a DOM node if it's a descendant of this description.

Parameters

ParameterTypeDescription
domNodeThe DOM node to check

Returns

ViewDesc

The view description if it's a descendant, undefined otherwise

Inherited from

NodeViewDesc.getDesc


getType()

ts
getType(): ViewDescType;

Defined in: TextViewDesc.ts:175

Returns

ViewDescType

Overrides

NodeViewDesc.getType


ignoreMutation()

ts
ignoreMutation(mutation): boolean;

Defined in: TextViewDesc.ts:139

Text nodes only care about character data and selection changes.

Parameters

ParameterTypeDescription
mutationViewMutationRecordThe mutation to check

Returns

boolean

True if mutation should be ignored

Overrides

NodeViewDesc.ignoreMutation


inParent()

ts
inParent(): boolean;

Defined in: TextViewDesc.ts:99

Checks if this text node is still in its parent's content DOM.

Returns

boolean

True if the text node is properly attached


isText()

ts
isText(text): boolean;

Defined in: TextViewDesc.ts:171

Checks if this view represents text with a specific content.

Parameters

ParameterTypeDescription
textstringThe text content to check against

Returns

boolean

True if this is a text view with the given content

Overrides

NodeViewDesc.isText


localPosFromDOM()

ts
localPosFromDOM(
   dom,
   offset,
   bias): number;

Defined in: TextViewDesc.ts:126

Converts a DOM position to a document position within the text node.

Parameters

ParameterTypeDescription
domNodeThe DOM node
offsetnumberThe offset within the DOM node
biasnumberDirection bias (unused for text nodes)

Returns

number

The document position

Overrides

NodeViewDesc.localPosFromDOM


markDirty()

ts
markDirty(from, to): void;

Defined in: TextViewDesc.ts:163

Marks a range as dirty. If the entire text or boundaries are affected, marks for full node recreation.

Parameters

ParameterTypeDescription
fromnumberStart position
tonumberEnd position

Returns

void

Overrides

NodeViewDesc.markDirty


markParentsDirty()

ts
markParentsDirty(): void;

Defined in: ViewDesc.ts:557

Marks this description and its parents as dirty, propagating the dirty state up the tree. Sets the dirty level to CONTENT_DIRTY for the immediate parent and CHILD_DIRTY for ancestors.

Returns

void

Inherited from

NodeViewDesc.markParentsDirty


matchesHack()

ts
matchesHack(_nodeName): boolean;

Defined in: ViewDesc.ts:236

Checks if this description matches a hack node with a specific name.

Parameters

ParameterTypeDescription
_nodeNamestringThe node name to check against

Returns

boolean

True if this is a hack node with the given name

Inherited from

NodeViewDesc.matchesHack


matchesMark()

ts
matchesMark(_mark): boolean;

Defined in: ViewDesc.ts:214

Checks if this description matches a given mark.

Parameters

ParameterTypeDescription
_markMarkThe mark to check against

Returns

boolean

True if this description represents the given mark

Inherited from

NodeViewDesc.matchesMark


matchesNode()

ts
matchesNode(
   node,
   outerDeco,
   innerDeco): boolean;

Defined in: NodeViewDesc.ts:434

Checks if this description matches a given node with decorations.

Parameters

ParameterTypeDescription
nodeNode_2The node to check against
outerDecoreadonly PmDecoration[]The outer decorations to check
innerDecoDecorationSourceThe inner decoration source to check

Returns

boolean

True if this description represents the given node with matching decorations

Inherited from

NodeViewDesc.matchesNode


matchesWidget()

ts
matchesWidget(_widget): boolean;

Defined in: ViewDesc.ts:199

Checks if this description matches a given widget decoration.

Parameters

ParameterTypeDescription
_widgetPmDecorationThe widget decoration to check against

Returns

boolean

True if this description represents the given widget

Inherited from

NodeViewDesc.matchesWidget


parseRange()

ts
parseRange(
   from,
   to,
   base?): {
  from: number;
  fromOffset: number;
  node: Node;
  to: number;
  toOffset: number;
};

Defined in: ViewDesc.ts:435

Finds a DOM range in a single parent for a given changed range.

This method maps document positions to DOM child indices, which is needed for parsing changed content. It tries to optimize by recursing into a single child when the entire range fits inside it.

Parameters

ParameterTypeDefault valueDescription
fromnumberundefinedStart position of the range
tonumberundefinedEnd position of the range
basenumber0Base offset for position calculations (default: 0)

Returns

ts
{
  from: number;
  fromOffset: number;
  node: Node;
  to: number;
  toOffset: number;
}

Object containing the DOM node and offsets for the range

NameTypeDefined in
fromnumberViewDesc.ts:437
fromOffsetnumberViewDesc.ts:437
nodeNodeViewDesc.ts:437
tonumberViewDesc.ts:437
toOffsetnumberViewDesc.ts:437

Inherited from

NodeViewDesc.parseRange


parseRule()

ts
parseRule(): {
  skip: boolean | ParentNode;
};

Defined in: TextViewDesc.ts:47

Returns a parse rule that skips any decoration wrappers around the text node.

Returns

ts
{
  skip: boolean | ParentNode;
}

Parse rule with skip set to the first non-decoration parent

NameTypeDefined in
skipboolean | ParentNodeTextViewDesc.ts:47

Overrides

NodeViewDesc.parseRule


posBeforeChild()

ts
posBeforeChild(child): number;

Defined in: ViewDesc.ts:293

Calculates the document position just before a given child view.

Parameters

ParameterTypeDescription
childPmViewDescThe child view to locate

Returns

number

The document position before the child

Inherited from

NodeViewDesc.posBeforeChild


posFromDOM()

ts
posFromDOM(
   dom,
   offset,
   bias): number;

Defined in: ViewDesc.ts:354

Converts a DOM position to a document position.

Parameters

ParameterTypeDescription
domNodeThe DOM node containing the position
offsetnumberThe offset within the DOM node
biasnumberDirection bias for ambiguous positions

Returns

number

The document position, or -1 if not found

Inherited from

NodeViewDesc.posFromDOM


selectNode()

ts
selectNode(): void;

Defined in: NodeViewDesc.ts:487

Mark this node as being the selected node.

Returns

void

Inherited from

NodeViewDesc.selectNode


setDomNode()

ts
protected setDomNode(dom): void;

Defined in: ViewDesc.ts:575

Sets the DOM node for this description and establishes the bidirectional link.

Parameters

ParameterTypeDescription
domNodeThe DOM node to associate with this description

Returns

void

Inherited from

NodeViewDesc.setDomNode


setSelection()

ts
setSelection(
   anchor,
   head,
   view,
   force?): void;

Defined in: ViewDesc.ts:492

Sets a selection within this view description or delegates to a child.

View descs are responsible for setting selections that fall entirely inside them, allowing custom node views to implement specialized selection behavior.

Strategy:

  1. If selection is entirely within a child → delegate to that child
  2. Otherwise → convert positions to DOM and apply selection

Parameters

ParameterTypeDefault valueDescription
anchornumberundefinedThe anchor position of the selection
headnumberundefinedThe head position of the selection
viewPmEditorViewundefinedThe editor view
forcebooleanfalseWhether to force the selection update even if it appears unchanged

Returns

void

Inherited from

NodeViewDesc.setSelection


slice()

ts
slice(from, to): TextViewDesc;

Defined in: TextViewDesc.ts:150

Creates a sliced copy of this text node.

Parameters

ParameterTypeDescription
fromnumberStart position of the slice
tonumberEnd position of the slice

Returns

TextViewDesc

A new TextViewDesc with sliced content


stopEvent()

ts
stopEvent(_event): boolean;

Defined in: ViewDesc.ts:256

Used by the editor's event handler to ignore events that come from certain descs.

Parameters

ParameterTypeDescription
_eventEventThe DOM event to check

Returns

boolean

True if the event should be stopped/ignored

Inherited from

NodeViewDesc.stopEvent


update()

ts
update(
   node,
   outerDeco,
   _innerDeco,
   view): boolean;

Defined in: TextViewDesc.ts:68

Updates this text node with new content and decorations.

Parameters

ParameterTypeDescription
nodeNode_2The new text node
outerDecoreadonly PmDecoration[]New outer decorations
_innerDecoDecorationSourceInner decorations (unused for text)
viewPmEditorViewThe editor view

Returns

boolean

True if update succeeded, false if node needs recreation


updateInner()

ts
updateInner(
   node,
   outerDeco,
   innerDeco): void;

Defined in: NodeViewDesc.ts:450

Updates the internal state of this node view with new node and decorations.

Parameters

ParameterTypeDescription
nodeNode_2The new node
outerDecoreadonly PmDecoration[]New outer decorations
innerDecoDecorationSourceNew inner decorations

Returns

void

Inherited from

NodeViewDesc.updateInner


updateOuterDeco()

ts
updateOuterDeco(outerDeco): void;

Defined in: NodeViewDesc.ts:463

Updates the outer decorations on this node, patching the DOM as needed.

Parameters

ParameterTypeDescription
outerDecoreadonly PmDecoration[]The new array of outer decorations

Returns

void

Inherited from

NodeViewDesc.updateOuterDeco


applyOuterDeco()

ts
static applyOuterDeco(
   dom,
   deco,
   node): Node;

Defined in: NodeViewDesc.ts:93

Apply outer decorations to a DOM node.

Parameters

ParameterTypeDescription
domNodeThe DOM node to decorate
decoreadonly PmDecoration[]Array of decorations to apply
nodeNode_2The ProseMirror node

Returns

Node

The decorated DOM node

Inherited from

NodeViewDesc.applyOuterDeco