Type Editor / @type-editor/viewdesc / CustomNodeViewDesc / CustomNodeViewDesc
Class: CustomNodeViewDesc
Defined in: CustomNodeViewDesc.ts:24
A separate subclass is used for customized node views, so that the extra checks only have to be made for nodes that are actually customized.
Custom node views allow developers to override default rendering and behavior for specific node types. This class delegates to the custom spec methods (update, selectNode, setSelection, etc.) when available.
Extends
Constructors
Constructor
new CustomNodeViewDesc(
parent,
node,
outerDeco,
innerDeco,
dom,
contentDOM,
nodeDOM,
spec): CustomNodeViewDesc;Defined in: CustomNodeViewDesc.ts:40
Creates a new CustomNodeViewDesc.
Parameters
| Parameter | Type | Description |
|---|---|---|
parent | ViewDesc | The parent view description |
node | Node_2 | The ProseMirror node |
outerDeco | readonly PmDecoration[] | Outer decorations |
innerDeco | DecorationSource | Inner decorations |
dom | Node | The outer DOM node |
contentDOM | HTMLElement | The content DOM node (if any) |
nodeDOM | Node | The node's main DOM element |
spec | NodeView | The custom node view specification |
Returns
CustomNodeViewDesc
Overrides
Properties
| Property | Modifier | Type | Default value | Inherited from | Defined in |
|---|---|---|---|---|---|
_children | protected | ViewDesc[] | undefined | NodeViewDesc._children | ViewDesc.ts:28 |
_contentDOM | readonly | HTMLElement | undefined | NodeViewDesc._contentDOM | ViewDesc.ts:24 |
_dirty | protected | ViewDirtyState | ViewDirtyState.NOT_DIRTY | NodeViewDesc._dirty | ViewDesc.ts:25 |
_dom | protected | Node | undefined | NodeViewDesc._dom | ViewDesc.ts:29 |
_innerDeco | protected | DecorationSource | null | NodeViewDesc._innerDeco | NodeViewDesc.ts:22 |
_node | protected | Node_2 | undefined | NodeViewDesc._node | ViewDesc.ts:26 |
_nodeDOM | readonly | Node | undefined | NodeViewDesc._nodeDOM | NodeViewDesc.ts:20 |
_outerDeco | protected | readonly PmDecoration[] | null | NodeViewDesc._outerDeco | NodeViewDesc.ts:21 |
_parent | protected | ViewDesc | undefined | NodeViewDesc._parent | ViewDesc.ts:27 |
Accessors
border
Get Signature
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
children
Get Signature
get children(): ViewDesc[];Defined in: ViewDesc.ts:88
The child view descriptions of this view.
Returns
ViewDesc[]
Set Signature
set children(children): void;Defined in: ViewDesc.ts:92
Parameters
| Parameter | Type |
|---|---|
children | ViewDesc[] |
Returns
void
Inherited from
contentDOM
Get Signature
get contentDOM(): HTMLElement;Defined in: ViewDesc.ts:106
The DOM node that contains child content, if any.
Returns
HTMLElement
Inherited from
contentLost
Get Signature
get contentLost(): boolean;Defined in: ViewDesc.ts:134
Checks if the content DOM has been detached from the main DOM.
Returns
boolean
Inherited from
dirty
Get Signature
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
Set Signature
set dirty(dirty): void;Defined in: ViewDesc.ts:63
Parameters
| Parameter | Type |
|---|---|
dirty | ViewDirtyState |
Returns
void
Inherited from
dom
Get Signature
get dom(): Node;Defined in: ViewDesc.ts:99
The DOM node this description represents.
Returns
Node
Inherited from
domAtom
Get Signature
get domAtom(): boolean;Defined in: NodeViewDesc.ts:81
Whether this description represents an atomic node that should be treated as a single unit.
Returns
boolean
Inherited from
ignoreForCoords
Get Signature
get ignoreForCoords(): boolean;Defined in: ViewDesc.ts:120
Whether this view should be ignored when determining coordinates.
Returns
boolean
Inherited from
ignoreForSelection
Get Signature
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
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
node
Get Signature
get node(): Node_2;Defined in: ViewDesc.ts:70
The ProseMirror node this description represents, if any.
Returns
Node_2
Inherited from
nodeDOM
Get Signature
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
outerDeco
Get Signature
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
parent
Get Signature
get parent(): ViewDesc;Defined in: ViewDesc.ts:77
The parent view description in the tree.
Returns
Set Signature
set parent(parent): void;Defined in: ViewDesc.ts:81
Parameters
| Parameter | Type |
|---|---|
parent | ViewDesc |
Returns
void
Inherited from
posAfter
Get Signature
get posAfter(): number;Defined in: ViewDesc.ts:155
The document position just after this view.
Returns
number
Inherited from
posAtEnd
Get Signature
get posAtEnd(): number;Defined in: ViewDesc.ts:162
The document position at the end of this view's content.
Returns
number
Inherited from
posAtStart
Get Signature
get posAtStart(): number;Defined in: ViewDesc.ts:148
The document position at the start of this view's content.
Returns
number
Inherited from
posBefore
Get Signature
get posBefore(): number;Defined in: ViewDesc.ts:141
The document position just before this view.
Returns
number
Inherited from
side
Get Signature
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
size
Get Signature
get size(): number;Defined in: NodeViewDesc.ts:73
The size of the content represented by this desc.
Returns
number
Inherited from
spec
Get Signature
get spec(): NodeView;Defined in: CustomNodeViewDesc.ts:52
Returns
NodeView
Methods
descAt()
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
| Parameter | Type | Description |
|---|---|---|
pos | number | The document position to search for |
Returns
The view description at that position, or undefined
Inherited from
deselectNode()
deselectNode(): void;Defined in: CustomNodeViewDesc.ts:70
Delegates to custom deselectNode if defined, otherwise uses default behavior.
Returns
void
Overrides
destroy()
destroy(): void;Defined in: CustomNodeViewDesc.ts:100
Calls custom destroy handler if defined, then performs default cleanup.
Returns
void
Overrides
domAfterPos()
domAfterPos(pos): Node;Defined in: ViewDesc.ts:468
Gets the DOM node immediately after a given document position.
Parameters
| Parameter | Type | Description |
|---|---|---|
pos | number | The document position |
Returns
Node
The DOM node after the position
Throws
RangeError if there's no node after the position
Inherited from
domFromPos()
domFromPos(pos, side): {
atom?: number;
node: Node;
offset: number;
};Defined in: ViewDesc.ts:408
Converts a document position to a DOM position.
The algorithm:
- For leaf nodes: return the DOM node itself with atom marker
- For container nodes: find which child contains the position
- If inside a child: recurse into that child
- If at boundary: adjust for zero-width widgets and find DOM position
Parameters
| Parameter | Type | Description |
|---|---|---|
pos | number | The document position (relative to this view's start) |
side | number | Direction to favor (-1 for before, 0 for neutral, 1 for after) |
Returns
{
atom?: number;
node: Node;
offset: number;
}Object containing the DOM node, offset, and optionally an atom marker
| Name | Type | Defined in |
|---|---|---|
atom? | number | ViewDesc.ts:409 |
node | Node | ViewDesc.ts:409 |
offset | number | ViewDesc.ts:409 |
Inherited from
emptyChildAt()
emptyChildAt(side): boolean;Defined in: ViewDesc.ts:452
Checks if there's an empty child at the start or end of this view.
Parameters
| Parameter | Type | Description |
|---|---|---|
side | number | Direction to check (-1 for start, 1 for end) |
Returns
boolean
True if there's an empty child at the specified side
Inherited from
getDesc()
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
| Parameter | Type | Description |
|---|---|---|
dom | Node | The DOM node to check |
Returns
The view description if it's a descendant, undefined otherwise
Inherited from
getType()
getType(): ViewDescType;Defined in: CustomNodeViewDesc.ts:127
Returns
Overrides
ignoreMutation()
ignoreMutation(mutation): boolean;Defined in: CustomNodeViewDesc.ts:123
Delegates mutation handling to custom ignoreMutation if defined.
Parameters
| Parameter | Type | Description |
|---|---|---|
mutation | ViewMutationRecord | The mutation to check |
Returns
boolean
True if mutation should be ignored
Overrides
isText()
isText(_text): boolean;Defined in: ViewDesc.ts:549
Checks if this view represents text with a specific content.
Parameters
| Parameter | Type | Description |
|---|---|---|
_text | string | The text content to check against |
Returns
boolean
True if this is a text view with the given content
Inherited from
localPosFromDOM()
localPosFromDOM(
dom,
offset,
bias): number;Defined in: ViewDesc.ts:316
Converts a DOM position within this view to a document position.
Uses two strategies:
- If position is inside contentDOM: scans through children to find nearest view desc
- If position is outside contentDOM: uses heuristics based on DOM structure
Parameters
| Parameter | Type | Description |
|---|---|---|
dom | Node | The DOM node where the position is |
offset | number | The offset within the DOM node |
bias | number | Direction bias for ambiguous positions (-1 for before, 1 for after) |
Returns
number
The document position corresponding to the DOM position
Inherited from
markDirty()
markDirty(from, to): void;Defined in: ViewDesc.ts:524
Marks a subtree that has been touched by a DOM change for redrawing.
The algorithm walks through children to find which ones overlap with the dirty range, then either:
- Recursively marks the child if range is fully contained
- Marks the child for full recreation if range partially overlaps
Parameters
| Parameter | Type | Description |
|---|---|---|
from | number | Start position of the dirty range |
to | number | End position of the dirty range |
Returns
void
Inherited from
markParentsDirty()
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
matchesHack()
matchesHack(_nodeName): boolean;Defined in: ViewDesc.ts:236
Checks if this description matches a hack node with a specific name.
Parameters
| Parameter | Type | Description |
|---|---|---|
_nodeName | string | The node name to check against |
Returns
boolean
True if this is a hack node with the given name
Inherited from
matchesMark()
matchesMark(_mark): boolean;Defined in: ViewDesc.ts:214
Checks if this description matches a given mark.
Parameters
| Parameter | Type | Description |
|---|---|---|
_mark | Mark | The mark to check against |
Returns
boolean
True if this description represents the given mark
Inherited from
matchesNode()
matchesNode(
node,
outerDeco,
innerDeco): boolean;Defined in: NodeViewDesc.ts:434
Checks if this description matches a given node with decorations.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The node to check against |
outerDeco | readonly PmDecoration[] | The outer decorations to check |
innerDeco | DecorationSource | The inner decoration source to check |
Returns
boolean
True if this description represents the given node with matching decorations
Inherited from
matchesWidget()
matchesWidget(_widget): boolean;Defined in: ViewDesc.ts:199
Checks if this description matches a given widget decoration.
Parameters
| Parameter | Type | Description |
|---|---|---|
_widget | PmDecoration | The widget decoration to check against |
Returns
boolean
True if this description represents the given widget
Inherited from
parseRange()
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
from | number | undefined | Start position of the range |
to | number | undefined | End position of the range |
base | number | 0 | Base offset for position calculations (default: 0) |
Returns
{
from: number;
fromOffset: number;
node: Node;
to: number;
toOffset: number;
}Object containing the DOM node and offsets for the range
| Name | Type | Defined in |
|---|---|---|
from | number | ViewDesc.ts:437 |
fromOffset | number | ViewDesc.ts:437 |
node | Node | ViewDesc.ts:437 |
to | number | ViewDesc.ts:437 |
toOffset | number | ViewDesc.ts:437 |
Inherited from
parseRule()
parseRule(): Omit<TagParseRule, "tag">;Defined in: NodeViewDesc.ts:396
When parsing in-editor content (in domchange.js), we allow descriptions to determine the parse rules that should be used to parse them.
Returns
Omit<TagParseRule, "tag">
Inherited from
posBeforeChild()
posBeforeChild(child): number;Defined in: ViewDesc.ts:293
Calculates the document position just before a given child view.
Parameters
| Parameter | Type | Description |
|---|---|---|
child | PmViewDesc | The child view to locate |
Returns
number
The document position before the child
Inherited from
posFromDOM()
posFromDOM(
dom,
offset,
bias): number;Defined in: ViewDesc.ts:354
Converts a DOM position to a document position.
Parameters
| Parameter | Type | Description |
|---|---|---|
dom | Node | The DOM node containing the position |
offset | number | The offset within the DOM node |
bias | number | Direction bias for ambiguous positions |
Returns
number
The document position, or -1 if not found
Inherited from
selectNode()
selectNode(): void;Defined in: CustomNodeViewDesc.ts:59
Delegates to custom selectNode if defined, otherwise uses default behavior.
Returns
void
Overrides
setDomNode()
protected setDomNode(dom): void;Defined in: ViewDesc.ts:575
Sets the DOM node for this description and establishes the bidirectional link.
Parameters
| Parameter | Type | Description |
|---|---|---|
dom | Node | The DOM node to associate with this description |
Returns
void
Inherited from
setSelection()
setSelection(
anchor,
head,
view,
force): void;Defined in: CustomNodeViewDesc.ts:86
Delegates to custom setSelection if defined, otherwise uses default behavior.
Parameters
| Parameter | Type | Description |
|---|---|---|
anchor | number | Anchor position relative to node start |
head | number | Head position relative to node start |
view | PmEditorView | The editor view |
force | boolean | Whether to force selection update |
Returns
void
Overrides
stopEvent()
stopEvent(event): boolean;Defined in: CustomNodeViewDesc.ts:113
Delegates event handling to custom stopEvent if defined.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | Event | The DOM event |
Returns
boolean
True if event should be stopped
Overrides
updateInner()
updateInner(
node,
outerDeco,
innerDeco): void;Defined in: NodeViewDesc.ts:450
Updates the internal state of this node view with new node and decorations.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | Node_2 | The new node |
outerDeco | readonly PmDecoration[] | New outer decorations |
innerDeco | DecorationSource | New inner decorations |
Returns
void
Inherited from
updateOuterDeco()
updateOuterDeco(outerDeco): void;Defined in: NodeViewDesc.ts:463
Updates the outer decorations on this node, patching the DOM as needed.
Parameters
| Parameter | Type | Description |
|---|---|---|
outerDeco | readonly PmDecoration[] | The new array of outer decorations |
Returns
void
Inherited from
applyOuterDeco()
static applyOuterDeco(
dom,
deco,
node): Node;Defined in: NodeViewDesc.ts:93
Apply outer decorations to a DOM node.
Parameters
| Parameter | Type | Description |
|---|---|---|
dom | Node | The DOM node to decorate |
deco | readonly PmDecoration[] | Array of decorations to apply |
node | Node_2 | The ProseMirror node |
Returns
Node
The decorated DOM node