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
new MarkType(
name,
rank,
schema,
spec): MarkType;Defined in: packages/model/src/schema/MarkType.ts:38
Creates a new MarkType instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the mark type |
rank | number | The numeric rank for ordering marks (lower ranks come first) |
schema | Schema | The schema that this mark type instance is part of |
spec | MarkSpec | The specification on which the type is based |
Returns
MarkType
Overrides
Properties
| Property | Modifier | Type | Default value | Inherited from | Defined in |
|---|---|---|---|---|---|
attrs | readonly | Record<string, Attribute> | undefined | TypeBase.attrs | packages/model/src/schema/TypeBase.ts:16 |
excludedTypes | protected | readonly MarkType[] | undefined | - | packages/model/src/schema/MarkType.ts:23 |
ELEMENTS_ID_ATTR_NAME | readonly | "id" | 'id' | - | packages/model/src/schema/MarkType.ts:21 |
Accessors
attributeSpecs
Get Signature
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
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
set excluded(value): void;Defined in: packages/model/src/schema/MarkType.ts:62
Sets the array of mark types excluded by this mark.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | readonly MarkType[] | The array of MarkType instances to exclude |
Returns
void
name
Get Signature
get name(): string;Defined in: packages/model/src/schema/MarkType.ts:69
The name of this mark type.
Returns
string
rank
Get Signature
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
get schema(): Schema;Defined in: packages/model/src/schema/MarkType.ts:76
The schema that this mark type is part of.
Returns
spec
Get Signature
get spec(): MarkSpec;Defined in: packages/model/src/schema/MarkType.ts:83
The spec that this mark type is based on.
Returns
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
Inherited from
checkAttrs()
checkAttrs(attrs): void;Defined in: packages/model/src/schema/MarkType.ts:181
Validates attributes for this mark type.
Parameters
| Parameter | Type | Description |
|---|---|---|
attrs | Attrs | The attributes to validate |
Returns
void
Throws
If any attribute is invalid
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?): 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
| Parameter | Type | Default value | Description |
|---|---|---|---|
attrs | Readonly<Record<string, any>> | null | Attribute values for the mark, or null to use all defaults |
Returns
A Mark instance
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
excludes()
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
| Parameter | Type | Description |
|---|---|---|
other | MarkType | The mark type to check exclusion for |
Returns
boolean
True if the other mark type is excluded by this one
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
isInSet()
isInSet(set): Mark;Defined in: packages/model/src/schema/MarkType.ts:167
Searches for a mark of this type in the given set.
Parameters
| Parameter | Type | Description |
|---|---|---|
set | readonly Mark[] | The array of marks to search |
Returns
The first mark of this type found, or undefined if none exists
removeFromSet()
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
| Parameter | Type | Description |
|---|---|---|
set | readonly Mark[] | The array of marks to filter |
Returns
readonly Mark[]
A new array without marks of this type
compile()
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
| Parameter | Type | Description |
|---|---|---|
marks | OrderedMap<MarkSpec> | An OrderedMap of mark specifications |
schema | Schema | The schema these mark types belong to |
Returns
Record<string, MarkType>
A record mapping mark names to MarkType instances