Skip to content

Type Editor


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

Class: Schema<Nodes, Marks>

Defined in: packages/model/src/schema/Schema.ts:28

A document schema. Holds node and mark type objects for the nodes and marks that may occur in conforming documents, and provides functionality for creating and deserializing such documents.

When given, the type parameters provide the names of the nodes and marks in this schema.

Type Parameters

Type ParameterDefault type
Nodes extends stringstring
Marks extends stringstring

Constructors

Constructor

ts
new Schema<Nodes, Marks>(spec): Schema<Nodes, Marks>;

Defined in: packages/model/src/schema/Schema.ts:90

Constructs a schema from a schema specification. Compiles node and mark types, validates the schema structure, and initializes content matching and mark restrictions.

Parameters

ParameterTypeDescription
specSchemaSpec<Nodes, Marks>The schema specification containing node and mark definitions

Returns

Schema<Nodes, Marks>

Throws

If the schema is invalid (e.g., duplicate node/mark names, multiple linebreak nodes, invalid linebreak node configuration)

Accessors

cached

Get Signature

ts
get cached(): Record<string, any>;

Defined in: packages/model/src/schema/Schema.ts:165

An object for storing cached values computed from the schema. Modules can use this to cache expensive computations. Use unique property names to avoid conflicts.

Returns

Record<string, any>


linebreakReplacement

Get Signature

ts
get linebreakReplacement(): NodeType;

Defined in: packages/model/src/schema/Schema.ts:148

The linebreak replacement node type, if one is defined in this schema. This node type is used to replace newline characters in pasted content.

Returns

NodeType


markFromJSON

Get Signature

ts
get markFromJSON(): (json) => Mark;

Defined in: packages/model/src/schema/Schema.ts:183

Deserialize a mark from its JSON representation. This method is bound.

Returns
ts
(json): Mark;
Parameters
ParameterType
jsonMarkJSON
Returns

Mark


marks

Get Signature

ts
get marks(): Readonly<Record<Marks, MarkType>> & Readonly<Record<string, MarkType>>;

Defined in: packages/model/src/schema/Schema.ts:140

An object mapping mark names to MarkType instances. Contains all mark types defined in this schema.

Returns

Readonly<Record<Marks, MarkType>> & Readonly<Record<string, MarkType>>


nodeFromJSON

Get Signature

ts
get nodeFromJSON(): (json) => Node;

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

Deserialize a node from its JSON representation. This method is bound.

NodeJSON as array for backwards compatibility

Returns
ts
(json): Node;
Parameters
ParameterType
json| NodeJSON | NodeJSON[]
Returns

Node


nodes

Get Signature

ts
get nodes(): Readonly<Record<Nodes, NodeType>> & Readonly<Record<string, NodeType>>;

Defined in: packages/model/src/schema/Schema.ts:132

An object mapping node names to NodeType instances. Contains all node types defined in this schema.

Returns

Readonly<Record<Nodes, NodeType>> & Readonly<Record<string, NodeType>>


spec

Get Signature

ts
get spec(): BasicSchemaSpec<NodeSpec, MarkSpec>;

Defined in: packages/model/src/schema/Schema.ts:124

The schema specification this schema is based on, with nodes and marks converted to OrderedMap instances for consistent ordering.

Returns

BasicSchemaSpec<NodeSpec, MarkSpec>


topNodeType

Get Signature

ts
get topNodeType(): NodeType;

Defined in: packages/model/src/schema/Schema.ts:156

The top-level node type for this schema (defaults to 'doc'). This is the root node type that contains the document content.

Returns

NodeType

Methods

mark()

ts
mark(type, attrs?): Mark;

Defined in: packages/model/src/schema/Schema.ts:236

Create a mark with the given type and attributes.

Parameters

ParameterTypeDescription
typestring | MarkTypeThe mark type name or MarkType instance
attrs?AttrsAttribute values for the mark, or undefined to use defaults

Returns

Mark

A new Mark instance

Throws

If the mark type is not found in this schema


node()

ts
node(
   type,
   attrs?,
   content?,
   marks?): Node;

Defined in: packages/model/src/schema/Schema.ts:200

Create a node in this schema. The type may be a string or a NodeType instance. Attributes will be extended with defaults, content may be a Fragment, null, a Node, or an array of nodes.

Parameters

ParameterTypeDefault valueDescription
typestring | NodeTypeundefinedThe node type name or NodeType instance
attrsReadonly<Record<string, any>>nullAttribute values for the node, or null to use defaults
content?| Fragment | Node | readonly Node[]undefinedFragment, single node, array of nodes, or undefined 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 type is invalid or from a different schema


nodeType()

ts
nodeType(name): NodeType;

Defined in: packages/model/src/schema/Schema.ts:254

Retrieves a node type by name.

Parameters

ParameterTypeDescription
namestringThe name of the node type to retrieve

Returns

NodeType

The NodeType instance

Throws

If the node type is not found in this schema


text()

ts
text(text, marks?): Node;

Defined in: packages/model/src/schema/Schema.ts:223

Create a text node in this schema. Empty text nodes are not allowed.

Parameters

ParameterTypeDescription
textstringThe text content for the node
marks?readonly Mark[]Array of marks to apply to the text node, or undefined for no marks

Returns

Node

A new text Node instance