Skip to content

StateFieldSpec<Value>

A specification for a state field.

Import:

import type { StateFieldSpec } from 'obsidian-dev-utils/codemirror/state-field-spec';

Signature:

export interface StateFieldSpec<Value>

Methods

MethodReturnsDescription
compare(a, b)booleanCompare two values of the field, returning true when they are the same. This is used to avoid recomputing facets that depend on the field when its value did not change. Defaults to using ===.
create(state)ValueCreates the initial value for the field when a state is created.
fromJSON(json, state)ValueA function that deserializes the JSON representation of this field's content.
provide(field)ExtensionProvide extensions based on this field. The given function will be called once with the initialized field. It will usually want to call some facet's from method to create facet inputs from this field, but can also return other extensions that should be enabled when the field is present in a configuration.
toJSON(value, state)unknownA function used to serialize this field's content to JSON. Only necessary when this field is included in the argument to EditorState.toJSON.
update(value, transaction)ValueCompute a new value from the field's previous value and a transaction.