feat(react)!: structure parts, block actions and typed child refs - #98
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BREAKING CHANGE: useChildren(parentId) returns child refs ({ id, type, index })
instead of a string array. Read child.id where an id was used before; the
factory's useChildren narrows type to the schema's block types.
weepaho3
force-pushed
the
cms-45-structure-parts
branch
from
August 16, 2026 17:41
dc34974 to
cb35dcc
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds the structure layer to
@createcms/react/editor: child refs fromuseChildren, placement-gated block actions, a keyboard-operable outline row, and a palette insert button. Together they let a consumer build a stacked form (recurseuseChildren+Editor.Form) and add, reorder, duplicate and delete blocks without a canvas.useChildren(parentId)returns{ id, type, index }in order (same array reference until ids or types change). The factory narrowstypeto the schema's block types (ChildRefOf<S>).useBlockActions(id)returnsBlockActions:canMoveUp/canMoveDown/canHaveChildren/allowedChildTypes, plusadd/remove/duplicate/moveUp/moveDown(each returns the store's verdict). Root: onlyaddapplies. Unknown id:typeisnulland everything is inert. Factory:TypedBlockActions<S>.Editor.OutlineItem blockId:divwithrole="treeitem",aria-selected/aria-level/aria-expanded, rovingtabIndex,data-selected/data-depth/data-has-children/data-block-id/data-block-type. Click selects. ArrowUp/Down select and focus the previous/next tree item in DOM order inside the closest[role="tree"]. Alt+Arrow moves among siblings. Delete/Backspace runonDelete(returnfalseto keep), then remove and land focus on the next item outside the subtree (else the previous). Escape clears the selection. Nested rows own their own events; keys inside an input are left alone. No drag and drop.Editor.AddBlock type:buttonwith the palette label as default children. Insert point whenparentIdis omitted: the selected block if it acceptstype(append), else after the selected block in its parent, else the root (append). Disabled when the target cannot taketype. Click inserts and selects the new id.Editornamespace grows toRoot, Field, FieldLabel, FieldControl, FieldDescription, FieldError, Form, OutlineItem, AddBlock.Tests:
structure/structure.test.tsx(happy-dom) covers roles/aria/data attributes, click, roving tabIndex, arrow navigation, Alt+arrow reorder, Delete/Backspace withonDeleteveto and focus return, Escape, nested-row ownership,renderprop, unknown id, AddBlock insert-point and disabled gating, stacked-form acceptance; plusstructure/structure.type-check.ts, updatedhooks.test.tsx/factory.test.tsx/editor.test.tsx.Changeset:
@createcms/reactminor.Checklist
bun run check-typespassesbun run testpasses (packages/react: 384 tests; the cms suite is unaffected)bun run lintpassesbunx changeset) if this changes published behaviorBREAKING CHANGE: useChildren(parentId) returns child refs ({ id, type, index })
instead of a string array. Read child.id where an id was used before; the
factory's useChildren narrows type to the schema's block types.