defineBlock
testedIdentity factory that narrows a block definition's literal type (cf. definePlugin).
Signature
export function defineBlock<const D extends BlockDefinition>(def: D): D{ ... }Type Parameters
Dextends BlockDefinitionParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
def | D | — | — |
Returns
DRelated Types
InputRuleSpec
A pattern that transforms the current block or marks when typed (e.g. '# '
→ heading, '**x**' → bold). The matching engine lands in M2; the type is
declared now so block/mark definitions can carry their rules as data.
interface InputRuleSpec| Property | Type | Default | Description |
|---|---|---|---|
matchreadonly | RegExp | — | Pattern tested against the text ending at the caret. |
type?readonly | string | — | Target block/mark type to apply on match. |
attrs?readonly | Attrs | — | Attrs to apply with the transformation. |
BlockComponentProps
Props passed to an atom/void block's Vue component.
interface BlockComponentProps| Property | Type | Default | Description |
|---|---|---|---|
node | Node | — | The block's model node (read its attrs). |
selected | boolean | — | Whether the block is currently node-selected. |
editable | boolean | — | Writekit-level editable flag. |
update | (attrs: Attrs) => void | — | Merge new attrs into the block (e.g. image src/caption). |
BlockMeta
Presentational/discovery metadata: powers slash menu, conversion, toolbars.
interface BlockMeta| Property | Type | Default | Description |
|---|---|---|---|
titlereadonly | string | — | — |
icon?readonly | string | — | — |
keywords?readonly | readonly string[] | — | — |
group?readonly | string | — | — |
BlockBehavior
Optional block-specific behaviors used by core commands.
interface BlockBehavior| Property | Type | Default | Description |
|---|---|---|---|
empty?readonly | () => Content | — | Content for a fresh empty block of this type (defaults to empty inline). |
toText?readonly | (node: Node) => string | — | Plain-text extraction (defaults to inline text). |
BlockDefinition
A block definition: schema contribution + behavior + an opaque Vue component.
Non-view layers treat component as an opaque value; only the view resolves
it. The type is Component purely for authoring ergonomics (type-only import).
interface BlockDefinition| Property | Type | Default | Description |
|---|---|---|---|
typereadonly | string | — | — |
specreadonly | NodeSpec | — | — |
component?readonly | Component | — | — |
meta?readonly | BlockMeta | — | — |
behavior?readonly | BlockBehavior | — | — |
commands?readonly | Record<string, CommandFactory> | — | — |
as?readonly | string | — | Wrapper element tag for the block (default 'div'). |
placeholder?readonly | string | — | Placeholder text shown when an empty text block has focus. |
inputRules?readonly | readonly InputRuleSpec[] | — | — |
MarkMeta
Presentational/discovery metadata for a mark (toolbar label, shortcut hint).
interface MarkMeta| Property | Type | Default | Description |
|---|---|---|---|
titlereadonly | string | — | — |
icon?readonly | string | — | — |
hotkey?readonly | string | — | — |
MarkDefinition
A mark definition: schema contribution (attrs, exclusivity, rank, toDOM, parseDOM) + metadata. Marks are data-only — the view renders/parses them via the spec, which is what makes them fully modular through the registry.
interface MarkDefinition| Property | Type | Default | Description |
|---|---|---|---|
typereadonly | string | — | — |
specreadonly | MarkSpec | — | — |
meta?readonly | MarkMeta | — | — |
inputRules?readonly | readonly InputRuleSpec[] | — | — |
Registry
The single source of truth for which block and mark types exist and how they
behave. Immutable: built once via createRegistry; extendRegistry
returns a new registry. The Schema is projected from the definitions.
interface Registry| Property | Type | Default | Description |
|---|---|---|---|
blocksreadonly | ReadonlyMap<string, BlockDefinition> | — | — |
marksreadonly | ReadonlyMap<string, MarkDefinition> | — | — |
schemareadonly | Schema | — | — |
getBlock | (type: string) => BlockDefinition | undefined | — | — |
getMark | (type: string) => MarkDefinition | undefined | — | — |
listBlocks | () => readonly BlockDefinition[] | — | Definitions in registration order (drives slash menu / toolbars). |
listMarks | () => readonly MarkDefinition[] | — | — |
allMarks | () => readonly MarkDefinition[] | — | Alias of listMarks, for the inline renderer/parser. |
hasBlock | (type: string) => boolean | — | — |
hasMark | (type: string) => boolean | — | — |
ConflictPolicy
How to resolve two definitions registered under the same type.
export type ConflictPolicy = 'throw' | 'last-wins' | 'first-wins';