withField
functionReturn a copy of `schema` that declares the serialized property to *be* a node field rather than a pair of accessor methods. This is the fast path in both directions: exporting reads the field, and importing assigns it, with no method call on either side — and no version resolution either way, since the node being parsed into is writable by construction and the node being exported is one the walk already resolved from the EditorState. Because the name is recorded on the schema, an introspecting tool (a codegen pass emitting a specialized parser for a hot node type) can see that a property is a plain field and compile it to a direct assignment. Use withAccessors with a `{field}` on one side only when the two directions differ — reading the field but writing through a method that normalizes, as TableCellNode's `headerState` does. The trade-off is that a field access is exactly that: normalization, validation or bookkeeping a `set<Prop>` method would do is skipped, and a subclass override of that method is not consulted. Use it when the property really is the field — which is also what makes it safe to compile away. Each direction still stands in for an accessor, so a subclass that overrode one still decides; see SchemaFieldBase.method. That accessor is the conventional `get<Prop>`/`set<Prop>` unless `getter`/`setter` name a different one, so most declarations need neither — name one only where the accessor is spelled differently, as TextNode's `text` is (`getTextContent`). A node with no such method defers to nothing, which needs no declaring. `getterTable`/`setterTable` declare a property whose stored and serialized forms differ (SchemaGetterField.getterTable / SchemaSetterField.setterTable), and `when` names the predicate gating the export direction (SchemaGetterField.when).
Import
import { withField } from '@modular/sdk/editor';Notes
- example
- ```ts nodeSchema<TextNode>()({ // TextNode's own field in both directions, deferring to getStyle/setStyle // for a subclass that overrides either — neither is spelled here, since // both are the conventional name for a `style` property. style: withField(stringValue(), {field: '__style'}), // LinkNode's own field, standing in for getURL/setURL rather than the // getUrl/setUrl the property name would derive. url: withField(stringValue(), { field: '__url', getter: 'getURL', setter: 'setURL', }), }); ```
- __NO_SIDE_EFFECTS__