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
protected new TypeBase(name, spec): TypeBase;Defined in: packages/model/src/schema/TypeBase.ts:24
Creates a new TypeBase instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the type |
spec | NodeSpec | The specification containing attribute definitions |
Returns
TypeBase
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
attrs | readonly | Record<string, Attribute> | packages/model/src/schema/TypeBase.ts:16 |
Methods
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
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
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)
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