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
new NodeType(
name,
schema,
spec): NodeType;Defined in: packages/model/src/schema/NodeType.ts:82
Creates a new NodeType instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name the node type has in this schema |
schema | Schema | A link back to the Schema the node type belongs to |
spec | NodeSpec | The specification that this type is based on |
Returns
NodeType
Overrides
Properties
| Property | Modifier | Type | Default value | Description | Inherited from | Defined in |
|---|---|---|---|---|---|---|
_contentMatch | protected | ContentMatch | undefined | The starting match of the node type's content expression. | - | packages/model/src/schema/NodeType.ts:30 |
attrs | readonly | Record<string, Attribute> | undefined | - | TypeBase.attrs | packages/model/src/schema/TypeBase.ts:16 |
isInlineContent | protected | boolean | false | True if this node type has inline content. | - | packages/model/src/schema/NodeType.ts:34 |
ELEMENTS_ID_ATTR_NAME | readonly | "id" | 'id' | - | - | packages/model/src/schema/NodeType.ts:25 |
Accessors
attributeSpecs
Get Signature
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
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
Set Signature
set contentMatch(value): void;Defined in: packages/model/src/schema/NodeType.ts:127
Sets the content match for this node type.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | ContentMatch | The ContentMatch instance to set |
Returns
void
defaultAttrs
Get Signature
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
inlineContent
Get Signature
get inlineContent(): boolean;Defined in: packages/model/src/schema/NodeType.ts:167
True if this node type has inline content.
Returns
boolean
Set Signature
set inlineContent(value): void;Defined in: packages/model/src/schema/NodeType.ts:175
Sets whether this node type has inline content.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | boolean | True if the node should have inline content |
Returns
void
isAtom
Get Signature
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
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
get isInline(): boolean;Defined in: packages/model/src/schema/NodeType.ts:182
True if this is an inline type.
Returns
boolean
isLeaf
Get Signature
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
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
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
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
set markSet(value): void;Defined in: packages/model/src/schema/NodeType.ts:144
Sets the mark restrictions for this node type.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | readonly MarkType[] | The array of allowed mark types, null for all marks, or empty array for no marks |
Returns
void
name
Get Signature
get name(): string;Defined in: packages/model/src/schema/NodeType.ts:97
The name of this node type.
Returns
string
schema
Get Signature
get schema(): Schema;Defined in: packages/model/src/schema/NodeType.ts:104
The schema that this node type is part of.
Returns
spec
Get Signature
get spec(): NodeSpec;Defined in: packages/model/src/schema/NodeType.ts:111
The spec that this node type is based on.
Returns
whitespace
Get Signature
get whitespace(): "pre" | "normal";Defined in: packages/model/src/schema/NodeType.ts:226
The node type's whitespace option.
Returns
"pre" | "normal"
Methods
allowedMarks()
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
| Parameter | Type | Description |
|---|---|---|
marks | readonly Mark[] | The array of marks to filter |
Returns
readonly Mark[]
A new array containing only the marks allowed in this node
allowsMarks()
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
| Parameter | Type | Description |
|---|---|---|
marks | readonly Mark[] | The array of marks to test |
Returns
boolean
True if all marks in the set are allowed in this node
allowsMarkType()
allowsMarkType(markType): boolean;Defined in: packages/model/src/schema/NodeType.ts:424
Checks whether the given mark type is allowed in this node.
Parameters
| Parameter | Type | Description |
|---|---|---|
markType | MarkType | The mark type to check |
Returns
boolean
True if the mark type is allowed in this node
checkAttributes()
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
| Parameter | Type | Description |
|---|---|---|
values | Attrs | The attribute values to validate |
type | string | The type name for error messages (e.g., 'node' or 'mark') |
Returns
void
Throws
If an unsupported attribute is found or validation fails
Inherited from
checkAttrs()
checkAttrs(attrs): void;Defined in: packages/model/src/schema/NodeType.ts:414
Validates attributes for this node type.
Parameters
| Parameter | Type | Description |
|---|---|---|
attrs | Attrs | The attributes to validate |
Returns
void
Throws
If any attribute is invalid
checkContent()
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
| Parameter | Type | Description |
|---|---|---|
content | Fragment | The fragment to validate |
Returns
void
Throws
If the content is not valid for this node type
compatibleContent()
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
| Parameter | Type | Description |
|---|---|---|
other | NodeType | The node type to compare content compatibility with |
Returns
boolean
True if the content expressions are compatible
computeAttributes()
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
| Parameter | Type | Description |
|---|---|---|
providedAttrs | Readonly<Record<string, any>> | The attributes provided by the caller, or null |
Returns
A complete Attrs object with all attributes resolved
Throws
If a required attribute (one without a default) is missing
Inherited from
create()
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
| Parameter | Type | Description |
|---|---|---|
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
A new Node instance
Throws
If called on the text node type (use schema.text() instead)
createAndFill()
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
attrs | Readonly<Record<string, any>> | null | Attribute values for the node, or null to use all defaults |
content? | | Fragment | Node | readonly Node[] | undefined | Fragment, single node, array of nodes, or null for empty content |
marks? | readonly Mark[] | undefined | Array of marks to apply to the node, or undefined for no marks |
Returns
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()
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
attrs | Readonly<Record<string, any>> | null | Attribute values for the node, or null to use all defaults |
content? | | Fragment | Node | readonly Node[] | undefined | Fragment, single node, array of nodes, or null for empty content |
marks? | readonly Mark[] | undefined | Array of marks to apply to the node, or undefined for no marks |
Returns
A new Node instance
Throws
If the content doesn't match the node type's content expression
createDefaultAttrs()
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
hasRequiredAttrs()
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()
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
| Parameter | Type | Description |
|---|---|---|
typeName | string | The 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
isInGroup()
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
| Parameter | Type | Description |
|---|---|---|
group | string | The group name to check membership for |
Returns
boolean
True if this node type belongs to the specified group
validContent()
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
| Parameter | Type | Description |
|---|---|---|
content | Fragment | The fragment to validate |
Returns
boolean
True if the content is valid for this node type
compile()
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
| Parameter | Type | Description |
|---|---|---|
nodes | OrderedMap<NodeSpec> | An OrderedMap of node specifications |
schema | Schema<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