Skip to content

Type Editor


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

Class: MarkType

Defined in: packages/model/src/schema/MarkType.ts:19

Marks

Like nodes, marks (which are associated with nodes to signify things like emphasis or being part of a link) are tagged with type objects, which are instantiated once per Schema.

Extends

Constructors

Constructor

ts
new MarkType(
   name,
   rank,
   schema,
   spec): MarkType;

Defined in: packages/model/src/schema/MarkType.ts:38

Creates a new MarkType instance.

Parameters

ParameterTypeDescription
namestringThe name of the mark type
ranknumberThe numeric rank for ordering marks (lower ranks come first)
schemaSchemaThe schema that this mark type instance is part of
specMarkSpecThe specification on which the type is based

Returns

MarkType

Overrides

TypeBase.constructor

Properties

PropertyModifierTypeDefault valueInherited fromDefined in
attrsreadonlyRecord<string, Attribute>undefinedTypeBase.attrspackages/model/src/schema/TypeBase.ts:16
excludedTypesprotectedreadonly MarkType[]undefined-packages/model/src/schema/MarkType.ts:23
ELEMENTS_ID_ATTR_NAMEreadonly"id"'id'-packages/model/src/schema/MarkType.ts:21

Accessors

attributeSpecs

Get Signature

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

Defined in: packages/model/src/schema/MarkType.ts:99

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

Returns

Record<string, Attribute>


excluded

Get Signature

ts
get excluded(): readonly MarkType[];

Defined in: packages/model/src/schema/MarkType.ts:54

The array of mark types that are excluded by this mark type. By default, marks exclude themselves, preventing multiple instances of the same mark.

Returns

readonly MarkType[]

Set Signature

ts
set excluded(value): void;

Defined in: packages/model/src/schema/MarkType.ts:62

Sets the array of mark types excluded by this mark.

Parameters
ParameterTypeDescription
valuereadonly MarkType[]The array of MarkType instances to exclude
Returns

void


name

Get Signature

ts
get name(): string;

Defined in: packages/model/src/schema/MarkType.ts:69

The name of this mark type.

Returns

string


rank

Get Signature

ts
get rank(): number;

Defined in: packages/model/src/schema/MarkType.ts:91

The numeric rank of this mark type, used for ordering marks. Lower rank numbers appear first when marks are sorted.

Returns

number


schema

Get Signature

ts
get schema(): Schema;

Defined in: packages/model/src/schema/MarkType.ts:76

The schema that this mark type is part of.

Returns

Schema


spec

Get Signature

ts
get spec(): MarkSpec;

Defined in: packages/model/src/schema/MarkType.ts:83

The spec that this mark type is based on.

Returns

MarkSpec

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

Inherited from

TypeBase.checkAttributes


checkAttrs()

ts
checkAttrs(attrs): void;

Defined in: packages/model/src/schema/MarkType.ts:181

Validates attributes for this mark type.

Parameters

ParameterTypeDescription
attrsAttrsThe attributes to validate

Returns

void

Throws

If any attribute is invalid


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?): Mark;

Defined in: packages/model/src/schema/MarkType.ts:128

Creates a mark of this type with the specified attributes. Attributes are merged with defaults. Returns a cached instance if possible.

Parameters

ParameterTypeDefault valueDescription
attrsReadonly<Record<string, any>>nullAttribute values for the mark, or null to use all defaults

Returns

Mark

A Mark instance


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


excludes()

ts
excludes(other): boolean;

Defined in: packages/model/src/schema/MarkType.ts:192

Checks whether the given mark type is excluded by this one. Based on the excludes specification in the mark's schema spec.

Parameters

ParameterTypeDescription
otherMarkTypeThe mark type to check exclusion for

Returns

boolean

True if the other mark type is excluded by this one


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


isInSet()

ts
isInSet(set): Mark;

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

Searches for a mark of this type in the given set.

Parameters

ParameterTypeDescription
setreadonly Mark[]The array of marks to search

Returns

Mark

The first mark of this type found, or undefined if none exists


removeFromSet()

ts
removeFromSet(set): readonly Mark[];

Defined in: packages/model/src/schema/MarkType.ts:142

Removes all marks of this type from the given set. Returns a new array without marks of this type, or the original if none found.

Parameters

ParameterTypeDescription
setreadonly Mark[]The array of marks to filter

Returns

readonly Mark[]

A new array without marks of this type


compile()

ts
static compile(marks, schema): Record<string, MarkType>;

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

Compiles a set of mark specifications into MarkType instances. Assigns sequential rank numbers to maintain mark ordering.

Parameters

ParameterTypeDescription
marksOrderedMap<MarkSpec>An OrderedMap of mark specifications
schemaSchemaThe schema these mark types belong to

Returns

Record<string, MarkType>

A record mapping mark names to MarkType instances