Skip to Content

BlockEditor

Add, duplicate, remove, and reorder schema-defined serializable content blocks.

BlockEditor edits arrays of serializable { type, fields } values using caller-provided CmsBlockDefinition records with keyed field descriptors. It never stores HTML as the canonical document. Use renderBlock to map known field definitions to specialized controls; otherwise fields remain editable as JSON.

390 × 844

API

PropTypeRequiredDefault
labelReactNodeYes—
definitionsreadonly CmsBlockDefinition[]Yes—
valuereadonly CmsBlockValue[]Yes—
onChange(value: CmsBlockValue[]) => voidYes—
onInvalidDraftChange(invalid: boolean) => voidNo—
renderBlock(definition, fields, onChange) => ReactNodeNoJSON fields editor
disabledbooleanNofalse
errorReactNodeNo—
classNamestringNo—
import { BlockEditor } from "@puzzle-ui/pieces";

<BlockEditor
  label="Page blocks"
  definitions={blockDefinitions}
  value={blocks}
  onChange={setBlocks}
/>;

Blocks can be added from available definitions, duplicated, removed, and moved with buttons. New blocks begin with field defaults from the definition. Invalid stored values remain visible and are not silently discarded; the user can remove an invalid block explicitly. Server-side schema validation remains authoritative.

The built-in JSON editor requires an object and reports invalid local drafts via onInvalidDraftChange; use that state to block host save and navigation actions. Block actions are disabled while a draft is invalid, so the draft is not lost. Custom renderBlock controls must report and guard their own invalid state.

Accessibility and composition

Actions are native keyboard-operable buttons with visible focus. Pass renderBlock to compose ContentEditor, FieldArray, JsonEditor, MediaField, or other controls. The component does not validate authorization or persistence.

API maturity

API maturity: Stable.