Skip to content

Type Editor


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

Class: MarkViewDesc

Defined in: MarkViewDesc.ts:20

A mark desc represents a mark. May have multiple children, depending on how the mark is split. Note that marks are drawn using a fixed nesting order, for simplicity and predictability, so in some cases they will be split more often than would appear necessary.

Marks wrap inline content to apply styling or semantic meaning (e.g., bold, italic, links). A mark view desc can contain both text nodes and other mark view descs (for nested marks).

Extends

Constructors

Constructor

ts
new MarkViewDesc(
   parent,
   mark,
   dom,
   contentDOM,
   spec): MarkViewDesc;

Defined in: MarkViewDesc.ts:34

Creates a new MarkViewDesc.

Parameters

ParameterTypeDescription
parentViewDescThe parent view description
markMarkThe ProseMirror mark this represents
domNodeThe outer DOM element for this mark
contentDOMHTMLElementThe DOM element that holds the mark's content
specMarkViewThe mark view specification (may include custom handlers)

Returns

MarkViewDesc

Overrides

ViewDesc.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
_childrenprotectedViewDesc[]undefinedViewDesc._childrenViewDesc.ts:28
_contentDOMreadonlyHTMLElementundefinedViewDesc._contentDOMViewDesc.ts:24
_dirtyprotectedViewDirtyStateViewDirtyState.NOT_DIRTYViewDesc._dirtyViewDesc.ts:25
_domprotectedNodeundefinedViewDesc._domViewDesc.ts:29
_nodeprotectedNode_2undefinedViewDesc._nodeViewDesc.ts:26
_parentprotectedViewDescundefinedViewDesc._parentViewDesc.ts:27

Accessors

border

Get Signature

ts
get border(): number;

Defined in: ViewDesc.ts:181

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

Returns

number

Inherited from

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

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

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

ViewDesc.dirty


dom

Get Signature

ts
get dom(): Node;

Defined in: ViewDesc.ts:99

The DOM node this description represents.

Returns

Node

Inherited from

ViewDesc.dom


domAtom

Get Signature

ts
get domAtom(): boolean;

Defined in: ViewDesc.ts:113

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

Returns

boolean

Inherited from

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

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

ViewDesc.ignoreForSelection


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

ViewDesc.node


nodeDOM

Get Signature

ts
get nodeDOM(): Node;

Defined in: AbstractViewDesc.ts:22

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

Returns

Node

The node DOM element, or null if this view doesn't have a direct node representation

Inherited from

ViewDesc.nodeDOM


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

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

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

ViewDesc.posAtStart


posBefore

Get Signature

ts
get posBefore(): number;

Defined in: ViewDesc.ts:141

The document position just before this view.

Returns

number

Inherited from

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

ViewDesc.side


size

Get Signature

ts
get size(): number;

Defined in: ViewDesc.ts:169

The size of the content represented by this desc.

Returns

number

Inherited from

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

ViewDesc.descAt


destroy()

ts
destroy(): void;

Defined in: MarkViewDesc.ts:167

Cleans up this mark view by calling custom destroy handler if defined.

Returns

void

Overrides

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

ViewDesc.domAfterPos


domFromPos()

ts
domFromPos(pos, side): {
  atom?: number;
  node: Node;
  offset: number;
};

Defined in: ViewDesc.ts:408

Converts a document position to a DOM position.

The algorithm:

  1. For leaf nodes: return the DOM node itself with atom marker
  2. For container nodes: find which child contains the position
  3. If inside a child: recurse into that child
  4. If at boundary: adjust for zero-width widgets and find DOM position

Parameters

ParameterTypeDescription
posnumberThe document position (relative to this view's start)
sidenumberDirection to favor (-1 for before, 0 for neutral, 1 for after)

Returns

ts
{
  atom?: number;
  node: Node;
  offset: number;
}

Object containing the DOM node, offset, and optionally an atom marker

NameTypeDefined in
atom?numberViewDesc.ts:409
nodeNodeViewDesc.ts:409
offsetnumberViewDesc.ts:409

Inherited from

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

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

ViewDesc.getDesc


getType()

ts
getType(): ViewDescType;

Defined in: MarkViewDesc.ts:174

Returns

ViewDescType

Overrides

ViewDesc.getType


ignoreMutation()

ts
ignoreMutation(mutation): boolean;

Defined in: MarkViewDesc.ts:160

Delegates mutation handling to custom spec if available, otherwise uses default behavior.

Parameters

ParameterTypeDescription
mutationViewMutationRecordThe mutation to check

Returns

boolean

True if the mutation should be ignored

Overrides

ViewDesc.ignoreMutation


isText()

ts
isText(_text): boolean;

Defined in: ViewDesc.ts:549

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

Inherited from

ViewDesc.isText


localPosFromDOM()

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

Defined in: ViewDesc.ts:316

Converts a DOM position within this view to a document position.

Uses two strategies:

  1. If position is inside contentDOM: scans through children to find nearest view desc
  2. If position is outside contentDOM: uses heuristics based on DOM structure

Parameters

ParameterTypeDescription
domNodeThe DOM node where the position is
offsetnumberThe offset within the DOM node
biasnumberDirection bias for ambiguous positions (-1 for before, 1 for after)

Returns

number

The document position corresponding to the DOM position

Inherited from

ViewDesc.localPosFromDOM


markDirty()

ts
markDirty(from, to): void;

Defined in: MarkViewDesc.ts:106

Marks a range as dirty and propagates to parent node view. Mark views don't maintain their own dirty state - it's moved to the nearest node view.

Parameters

ParameterTypeDescription
fromnumberStart position of the dirty range
tonumberEnd position of the dirty range

Returns

void

Overrides

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

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

ViewDesc.matchesHack


matchesMark()

ts
matchesMark(mark): boolean;

Defined in: MarkViewDesc.ts:95

Checks if this mark view matches a given mark.

Parameters

ParameterTypeDescription
markMarkThe mark to check against

Returns

boolean

True if not dirty and marks are equal

Overrides

ViewDesc.matchesMark


matchesNode()

ts
matchesNode(
   _node,
   _outerDeco,
   _innerDeco): boolean;

Defined in: ViewDesc.ts:226

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

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

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

ViewDesc.parseRange


parseRule()

ts
parseRule(): {
  attrs: Readonly<Record<string, any>>;
  contentElement: HTMLElement;
  mark: string;
};

Defined in: MarkViewDesc.ts:77

Returns a parse rule for this mark, or null if it should be reparsed.

Returns

ts
{
  attrs: Readonly<Record<string, any>>;
  contentElement: HTMLElement;
  mark: string;
}

Parse rule with mark info, or null if dirty or needs reparsing

NameTypeDefined in
attrsReadonly<Record<string, any>>MarkViewDesc.ts:84
contentElementHTMLElementMarkViewDesc.ts:85
markstringMarkViewDesc.ts:83

Overrides

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

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

ViewDesc.posFromDOM


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

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

ViewDesc.setSelection


slice()

ts
slice(
   from,
   to,
   view): MarkViewDesc;

Defined in: MarkViewDesc.ts:131

Creates a sliced copy of this mark view with a subset of its children.

Parameters

ParameterTypeDescription
fromnumberStart position of the slice
tonumberEnd position of the slice
viewPmEditorViewThe editor view

Returns

MarkViewDesc

A new MarkViewDesc with sliced children


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

ViewDesc.stopEvent


create()

ts
static create(
   parent,
   mark,
   inline,
   view): MarkViewDesc;

Defined in: MarkViewDesc.ts:53

Creates a mark view description, using custom mark views if available.

Parameters

ParameterTypeDescription
parentViewDescThe parent view description
markMarkThe mark to create a view for
inlinebooleanWhether the mark is in inline content
viewPmEditorViewThe editor view

Returns

MarkViewDesc

A new MarkViewDesc instance