Skip to content

getApplicableSchema

const getApplicableSchema: EditorSelector<ApplicableSchema>

Defined in: selector.get-applicable-schema.ts:56

Resolve which schema members are applicable at the current selection. For each named category (decorators, annotations, lists, styles, block objects, inline objects) returns the set of names that the editor allows at the current selection.

Categories split by what they apply to:

Text-only (decorators, annotations, lists, styles): require text-block content in the selection. A name is applicable when at least one text block the range covers declares it (union). The underlying operations apply per-block, validating each block’s sub-schema and skipping blocks that don’t declare the type, so the result reflects “will this produce any effect?” semantics. Selection on a void block, or no selection, returns empty sets.

Insertion (blockObjects, inlineObjects): the things consumers might insert AT the current selection. The focus block’s sub-schema applies even when the selection is on a void block (the question “what can I insert here?” still has an answer). No selection returns empty sets.

Useful for gating toolbar buttons, slash-command items, command palettes, keyboard-shortcut hints and other selection-aware UIs.

Pair with getUnionSchema (from @portabletext/editor/traversal) to render a static toolbar whose buttons stay stable across selection moves while gating their enabled state on whether the corresponding name is in the relevant set.

Note for React consumers: the returned object is a fresh value on every call, so subscribing via useEditorSelector requires a structural compare to avoid re-rendering on every editor tick. Use compareApplicableSchema as the third argument.