feat(core): container blocks, compartments and frames (second pass on #3014) - #3050
Draft
YousefED wants to merge 2 commits into
Draft
feat(core): container blocks, compartments and frames (second pass on #3014)#3050YousefED wants to merge 2 commits into
YousefED wants to merge 2 commits into
Conversation
Builds on the container-block API from #2997 / #3014: `children` on the block config, compiled into the node's content expression, columns and column lists declared through the ordinary `createBlockSpec`, and a repair pass that keeps containers valid as children are removed. Adds two things on top of that: - compartments — a block that keeps content of its own *and* declares `children`, so a callout can have a rich text title above a body of blocks. Editing gestures treat title and body as one unit. - `renderFrame` — markup wrapping a block's content and children together, so the author draws the box. Independent of `children`: a toggle frames itself but keeps ordinary nesting. Narrows the rest of the API: no `default` seeds, no `whenEmptied`, no `boundary`, no `rootDOM`, and `allow` is `"any"` or a list of container type names. BREAKING CHANGE: `fixColumnList`, `removeEmptyColumns` and `isEmptyColumn` are replaced by `fixContainer`, `removeEmptyChildren`, `isEmptyContainerChild`, `containerAncestorIds` and `fixContainersById`. Columns no longer serialize `data-width` when the width is the default.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
A toggle heading is a heading either way - it is only a toggle when `props.isToggleable` says so - so `renderFrame` may now decline by returning `undefined`. Whether a block is framed is decided when the frame is built, so a block whose type frames itself now rebuilds its node view when its props change, the way an unframed block already does. `frame.update` still handles content changes, which ProseMirror would not rebuild for.
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 #3014 got right, and what this keeps
The container-block API in #2997 / #3014 is the foundation this builds on, kept close to verbatim:
children: { allow, min }on the block config, compiled straight into the node's content expression, so the schema enforces the shape instead of runtime checks.placement: "anywhere" | "containerOnly", so acolumncan only exist inside acolumnList.createBlockSpec— no bespoke ProseMirror nodes for authors to write.Column.tsandColumnList.ts.Those decisions are unchanged and most of the doc comments came across as written. The two additions below are what this PR is actually for.
What's new: a callout can have a title
In #3014 a block declaring
childrenhas its content expression replaced by those children, so a container's node holds blocks instead of content. That makes a rich text title impossible — the shape behind the long-standing toggle-block reports (#2020, #2378).This PR splits the one config knob into two independent ones:
childrenrenderFrameslotthey render into.Neither implies the other, which is what makes the three shapes below fall out of one API.
How columns, callouts, alerts and toggles relate
content: "none"+childrencontent: "inline"+children+renderFrameblockGroupcontent: "none"+children+ arenderthat draws the boxrenderFrameonlyblockGroupTwo things worth pulling out of that table:
An alert without a title is just a container. It is the same shape as a column list — a box that holds blocks — so it needs no new machinery at all. Its own
renderdraws the box;renderFrameis for the case where content and children must sit inside the same author markup.A toggle is deliberately not a compartment. In Notion, Shift-Tab moves a block out of a toggle but keeps it inside a callout, because a toggle's children are nesting while a callout's are a body. Declaring
renderFramewithoutchildrengives exactly that: the chevron and the box, with untouched nesting behaviour. Two tests incompartments.test.tspin this down.That covers both toggle shapes in #2988. A toggle list is a block type that is always a toggle, so it declares
renderFrameoutright. A toggle heading is a heading either way, and is only a toggle whenprops.isToggleable— sorenderFramemay returnundefinedto decline, and a block whose type frames itself rebuilds its node view when its props change, the way an unframed block already does. The per-user collapse state itself is orthogonal to all of this and stays where #2988 put it: outside the document, in an extension. What this PR removes from that picture is the need for a wrapper block.What compartments change about editing
A body belongs to its block, so gestures treat title and body as one unit:
The guard for all of this is one predicate,
isCompartment, which is true for a container block and for a block with a body.compartmentBodyerases the shape difference between the two, so the column code and the callout code are the same code. What stays container-specific is only the part that moves between sibling children — the previous or next column — which a compartment has none of.What was dropped from #3014
Each of these was cut because nothing in columns, callouts or toggles needed it, not because it was wrong:
children.default— seed children for a new containerwhenEmptied: "refill" | "unwrap"containerOnlyone is paddedboundary: "open" | "sealed"allow: "any" | "blocks" | "containers" | string[]"any" | string[]rootDOMon the render outputThe result, source only, excluding tests and snapshots:
packages/core/srcpackages/Tests
All green: core 798, shared matrix 913, multi-column 82, react 4.
New coverage:
containers.test.ts(schema and node shape),compartments.test.ts(the keyboard behaviour above, plus the toggle case),renderFrame.test.ts,reactContainer.test.tsx(a container written withcreateReactBlockSpec— renders, holds children, round-trips through HTML),reactFrame.test.tsx, andfixContainer.test.ts(renamed fromfixColumnLists.test.ts).There is a runnable example at
examples/06-custom-schema/13-callout-block.Breaking changes
fixColumnList,removeEmptyColumnsandisEmptyColumnare replaced byfixContainer,removeEmptyChildren,isEmptyContainerChild,containerAncestorIdsandfixContainersById.data-widthwhen its width is the default, matching how every other block omits default props.Known gaps
renderFrame— the callout example does — but the frame itself is plain DOM, so a frame with its own React UI isn't expressible yet.main(reproduced at 63c2389 with plain nesting and no custom schema): Delete at the end of the last nested block silently deletes the following block when it can't merge as text — a table, say. Callouts inherit it; containers don't, because they intercept that key first. Worth a fix in the generic branch, not here.🤖 Generated with Claude Code