Skip to content

Type Editor


Type Editor / @type-editor/model / schema/NodeType / NodeType

Class: NodeType

Defined in: packages/model/src/schema/NodeType.ts:23

Node types are objects allocated once per Schema and used to tag Node instances. They contain information about the node type, such as its name and what kind of node it represents.

Extends

Constructors

Constructor

ts
new NodeType(
   name,
   schema,
   spec): NodeType;

Defined in: packages/model/src/schema/NodeType.ts:82

Creates a new NodeType instance.

Parameters

ParameterTypeDescription
namestringThe name the node type has in this schema
schemaSchemaA link back to the Schema the node type belongs to
specNodeSpecThe specification that this type is based on

Returns

NodeType

Overrides

TypeBase.constructor

Properties

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_contentMatchprotectedContentMatchundefinedThe starting match of the node type's content expression.-packages/model/src/schema/NodeType.ts:30
attrsreadonlyRecord<string, Attribute>undefined-TypeBase.attrspackages/model/src/schema/TypeBase.ts:16
isInlineContentprotectedbooleanfalseTrue if this node type has inline content.-packages/model/src/schema/NodeType.ts:34
ELEMENTS_ID_ATTR_NAMEreadonly"id"'id'--packages/model/src/schema/NodeType.ts:25

Accessors

attributeSpecs

Get Signature

ts
get attributeSpecs(): Record<string, Attribute>;

Defined in: packages/model/src/schema/NodeType.ts:160

The attribute specifications for this node type. Contains metadata about each attribute including validation and comparison behavior.

Returns

Record<string, Attribute>


contentMatch

Get Signature

ts
get contentMatch(): ContentMatch;

Defined in: packages/model/src/schema/NodeType.ts:119

The starting match of the node type's content expression. Used to validate and match content during node operations.

Returns

ContentMatch

Set Signature

ts
set contentMatch(value): void;

Defined in: packages/model/src/schema/NodeType.ts:127

Sets the content match for this node type.

Parameters
ParameterTypeDescription
valueContentMatchThe ContentMatch instance to set
Returns

void


defaultAttrs

Get Signature

ts
get defaultAttrs(): Attrs;

Defined in: packages/model/src/schema/NodeType.ts:152

The default attributes for this node type. When creating nodes without specifying attributes, these defaults are used.

Returns

Attrs


inlineContent

Get Signature

ts
get inlineContent(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:167

True if this node type has inline content.

Returns

boolean

Set Signature

ts
set inlineContent(value): void;

Defined in: packages/model/src/schema/NodeType.ts:175

Sets whether this node type has inline content.

Parameters
ParameterTypeDescription
valuebooleanTrue if the node should have inline content
Returns

void


isAtom

Get Signature

ts
get isAtom(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:218

True when this node is an atom, i.e. when it does not have directly editable content.

Returns

boolean


isBlock

Get Signature

ts
get isBlock(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:196

True if this is a block type (not inline).

Returns

boolean


isInline

Get Signature

ts
get isInline(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:182

True if this is an inline type.

Returns

boolean


isLeaf

Get Signature

ts
get isLeaf(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:210

True for node types that allow no content.

Returns

boolean


isText

Get Signature

ts
get isText(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:203

True if this is the text node type.

Returns

boolean


isTextblock

Get Signature

ts
get isTextblock(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:189

True if this is a textblock type, a block that contains inline content.

Returns

boolean


markSet

Get Signature

ts
get markSet(): readonly MarkType[];

Defined in: packages/model/src/schema/NodeType.ts:136

The set of marks allowed in this node. null means all marks are allowed, an empty array means no marks are allowed, and a populated array restricts marks to the specified types.

Returns

readonly MarkType[]

Set Signature

ts
set markSet(value): void;

Defined in: packages/model/src/schema/NodeType.ts:144

Sets the mark restrictions for this node type.

Parameters
ParameterTypeDescription
valuereadonly MarkType[]The array of allowed mark types, null for all marks, or empty array for no marks
Returns

void


name

Get Signature

ts
get name(): string;

Defined in: packages/model/src/schema/NodeType.ts:97

The name of this node type.

Returns

string


schema

Get Signature

ts
get schema(): Schema;

Defined in: packages/model/src/schema/NodeType.ts:104

The schema that this node type is part of.

Returns

Schema


spec

Get Signature

ts
get spec(): NodeSpec;

Defined in: packages/model/src/schema/NodeType.ts:111

The spec that this node type is based on.

Returns

NodeSpec


whitespace

Get Signature

ts
get whitespace(): "pre" | "normal";

Defined in: packages/model/src/schema/NodeType.ts:226

The node type's whitespace option.

Returns

"pre" | "normal"

Methods

allowedMarks()

ts
allowedMarks(marks): readonly Mark[];

Defined in: packages/model/src/schema/NodeType.ts:454

Filters the given marks to only those allowed in this node. Returns a new array with disallowed marks removed.

Parameters

ParameterTypeDescription
marksreadonly Mark[]The array of marks to filter

Returns

readonly Mark[]

A new array containing only the marks allowed in this node


allowsMarks()

ts
allowsMarks(marks): boolean;

Defined in: packages/model/src/schema/NodeType.ts:434

Tests whether the given set of marks are all allowed in this node.

Parameters

ParameterTypeDescription
marksreadonly Mark[]The array of marks to test

Returns

boolean

True if all marks in the set are allowed in this node


allowsMarkType()

ts
allowsMarkType(markType): boolean;

Defined in: packages/model/src/schema/NodeType.ts:424

Checks whether the given mark type is allowed in this node.

Parameters

ParameterTypeDescription
markTypeMarkTypeThe mark type to check

Returns

boolean

True if the mark type is allowed in this node


checkAttributes()

ts
protected checkAttributes(values, type): void;

Defined in: packages/model/src/schema/TypeBase.ts:36

Validates attribute values against the type's attribute specifications. Throws a RangeError if any attribute is unsupported or fails validation.

Parameters

ParameterTypeDescription
valuesAttrsThe attribute values to validate
typestringThe type name for error messages (e.g., 'node' or 'mark')

Returns

void

Throws

If an unsupported attribute is found or validation fails

Inherited from

TypeBase.checkAttributes


checkAttrs()

ts
checkAttrs(attrs): void;

Defined in: packages/model/src/schema/NodeType.ts:414

Validates attributes for this node type.

Parameters

ParameterTypeDescription
attrsAttrsThe attributes to validate

Returns

void

Throws

If any attribute is invalid


checkContent()

ts
checkContent(content): void;

Defined in: packages/model/src/schema/NodeType.ts:402

Validates that the given fragment is valid content for this node type.

Parameters

ParameterTypeDescription
contentFragmentThe fragment to validate

Returns

void

Throws

If the content is not valid for this node type


compatibleContent()

ts
compatibleContent(other): boolean;

Defined in: packages/model/src/schema/NodeType.ts:302

Checks whether this node type allows some of the same content as another node type. Used to determine if content can be transferred between different node types.

Parameters

ParameterTypeDescription
otherNodeTypeThe node type to compare content compatibility with

Returns

boolean

True if the content expressions are compatible


computeAttributes()

ts
protected computeAttributes(providedAttrs): Attrs;

Defined in: packages/model/src/schema/TypeBase.ts:86

Computes a complete set of attributes by merging provided values with defaults. Ensures all required attributes are present and applies defaults where needed.

Parameters

ParameterTypeDescription
providedAttrsReadonly<Record<string, any>>The attributes provided by the caller, or null

Returns

Attrs

A complete Attrs object with all attributes resolved

Throws

If a required attribute (one without a default) is missing

Inherited from

TypeBase.computeAttributes


create()

ts
create(
   attrs?,
   content?,
   marks?): Node;

Defined in: packages/model/src/schema/NodeType.ts:316

Creates a Node of this type with the specified attributes, content, and marks. Attributes are merged with defaults. This method does not validate content.

Parameters

ParameterTypeDescription
attrs?Readonly<Record<string, any>>Attribute values for the node, or null to use all defaults
content?| Fragment | Node | readonly Node[]Fragment, single node, array of nodes, or null for empty content
marks?readonly Mark[]Array of marks to apply to the node, or undefined for no marks

Returns

Node

A new Node instance

Throws

If called on the text node type (use schema.text() instead)


createAndFill()

ts
createAndFill(
   attrs?,
   content?,
   marks?): Node;

Defined in: packages/model/src/schema/NodeType.ts:355

Creates a Node like create(), but attempts to add required nodes to the start or end of the content to satisfy the node type's content expression. Returns null if the content cannot be made valid.

Parameters

ParameterTypeDefault valueDescription
attrsReadonly<Record<string, any>>nullAttribute values for the node, or null to use all defaults
content?| Fragment | Node | readonly Node[]undefinedFragment, single node, array of nodes, or null for empty content
marks?readonly Mark[]undefinedArray of marks to apply to the node, or undefined for no marks

Returns

Node

A new Node instance with filled content, or null if content cannot be fixed

Remarks

This will always succeed with null or empty content since required nodes can be automatically created


createChecked()

ts
createChecked(
   attrs?,
   content?,
   marks?): Node;

Defined in: packages/model/src/schema/NodeType.ts:335

Creates a Node like create(), but validates content against the node type's content restrictions before creating the node.

Parameters

ParameterTypeDefault valueDescription
attrsReadonly<Record<string, any>>nullAttribute values for the node, or null to use all defaults
content?| Fragment | Node | readonly Node[]undefinedFragment, single node, array of nodes, or null for empty content
marks?readonly Mark[]undefinedArray of marks to apply to the node, or undefined for no marks

Returns

Node

A new Node instance

Throws

If the content doesn't match the node type's content expression


createDefaultAttrs()

ts
protected createDefaultAttrs(): Readonly<Record<string, any>>;

Defined in: packages/model/src/schema/TypeBase.ts:63

Creates a reusable default attributes object for types where all attributes have default values. This optimization allows sharing the same object across multiple instances when no custom attributes are specified.

Returns

Readonly<Record<string, any>>

An Attrs object with all default values, or null if any attribute lacks a default value (indicating required attributes exist)

Inherited from

TypeBase.createDefaultAttrs


hasRequiredAttrs()

ts
hasRequiredAttrs(): boolean;

Defined in: packages/model/src/schema/NodeType.ts:286

Checks whether this node type has any required attributes (attributes without default values).

Returns

boolean

True if at least one attribute is required, false otherwise


initAttrs()

ts
protected initAttrs(typeName, attrs?): Record<string, Attribute>;

Defined in: packages/model/src/schema/TypeBase.ts:120

Initializes attribute descriptors from the provided specification. Creates Attribute objects that encapsulate validation and default values.

Parameters

ParameterTypeDescription
typeNamestringThe name of the type (used in error messages)
attrs?Record<string, PmAttributeSpec>The attribute specifications from the schema spec

Returns

Record<string, Attribute>

A record mapping attribute names to Attribute descriptors

Inherited from

TypeBase.initAttrs


isInGroup()

ts
isInGroup(group): boolean;

Defined in: packages/model/src/schema/NodeType.ts:277

Checks whether this node type is part of the given group. Groups are defined in the node spec and allow categorizing node types.

Parameters

ParameterTypeDescription
groupstringThe group name to check membership for

Returns

boolean

True if this node type belongs to the specified group


validContent()

ts
validContent(content): boolean;

Defined in: packages/model/src/schema/NodeType.ts:382

Checks whether the given fragment is valid content for this node type. Validates both the content structure and that all marks are allowed.

Parameters

ParameterTypeDescription
contentFragmentThe fragment to validate

Returns

boolean

True if the content is valid for this node type


compile()

ts
static compile<Nodes>(nodes, schema): Readonly<Record<Nodes, NodeType>>;

Defined in: packages/model/src/schema/NodeType.ts:244

Compiles a set of node specifications into NodeType instances. Validates that required node types (top node and text) are present and correctly configured.

Type Parameters

Type Parameter
Nodes extends string

Parameters

ParameterTypeDescription
nodesOrderedMap<NodeSpec>An OrderedMap of node specifications
schemaSchema<Nodes>The schema these node types belong to

Returns

Readonly<Record<Nodes, NodeType>>

A readonly record mapping node names to NodeType instances

Throws

If the top node type is missing, text type is missing, or text type has attributes