Skip to content

Type Editor


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

Abstract Class: TypeBase

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

Abstract base class for type objects (NodeType and MarkType). Provides common functionality for attribute management and validation.

Extended by

Constructors

Constructor

ts
protected new TypeBase(name, spec): TypeBase;

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

Creates a new TypeBase instance.

Parameters

ParameterTypeDescription
namestringThe name of the type
specNodeSpecThe specification containing attribute definitions

Returns

TypeBase

Properties

PropertyModifierTypeDefined in
attrsreadonlyRecord<string, Attribute>packages/model/src/schema/TypeBase.ts:16

Methods

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


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


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)


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