Skip to content

refactor(core): simplify BlockInfo with derived positions and consolidated producers - #3007

Closed
nperez0111 wants to merge 1 commit into
container-blocks/corefrom
container-blocks/block-info
Closed

refactor(core): simplify BlockInfo with derived positions and consolidated producers#3007
nperez0111 wants to merge 1 commit into
container-blocks/corefrom
container-blocks/block-info

Conversation

@nperez0111

Copy link
Copy Markdown
Contributor

Part of the container-blocks stack: sits between #2997 (core container API) and #2998 (multi-column migration).

What changed

Field renamesBlockInfo drops the internal jargon:

Before After
bnBlock block
blockContent content
childContainer children
isWrappedBlock hasContent

(ProseMirror group name strings like "bnBlock" are unchanged — only the TS API is renamed.)

Precomputed derived fields — callers kept re-deriving the same positions with hand arithmetic (blockContent.beforePos + 1 at 25+ sites, afterPos - 1 at ~12, empty-inline-block checks at ~6). BlockInfo now carries them directly:

  • contentStart / contentEnd — inside edges of the content node
  • children.childrenStart / children.childrenEnd — inside edges of the child container
  • contentKind: "inline" | "none" | "table" | "other" — replaces raw spec.content string checks
  • isContentEmpty

These stay a discriminated union on hasContent, so the existing narrowing guards keep working.

Producer consolidation — 6 overlapping producers → 4, named by what you have; the module doc comment carries the decision table:

You have Call
a PM node + its before-pos getBlockInfoFromNode(node, beforePos)
a position just before a block getBlockInfoAt(doc, posBeforeBlock)
an arbitrary position getBlockInfoNearPos(source, pos)
a selection getBlockInfoFromSelection(source)

getBlockInfo and getBlockInfoFromResolvedPos are deleted; getBlockInfoWithManualOffset, getBlockInfoAtNearest, and getBottomNestedBlockInfo are renamed (getBlockInfoFromNode, getBlockInfoNearPos, getLastDescendantBlockInfo).

Navigation helpers movedgetParentBlockInfo / getPrevBlockInfo / getNextBlockInfo / getLastDescendantBlockInfo move from mergeBlocks.ts to getBlockInfoFromPos.ts (they're generic navigation, not merge logic) and become public.

Testing

Red-green throughout: new shape tests for the derived fields, characterization tests for the navigation helpers on plain nested blocks, and 11 inline-snapshot characterization tests for the migrated KeyboardShortcuts handlers (Backspace/Delete/Enter/Shift-Tab), written before each migration. Core suite 866 passing (+22 over baseline), xl-multi-column and xl-ai green, keyboardhandlers e2e 96/96.

Excluding test files the migration is nearly line-neutral (+643/−609): the added lines are the derived-field machinery and doc comments; every callsite shrank.

…dated producers

Renames BlockInfo fields (bnBlock->block, blockContent->content,
childContainer->children, isWrappedBlock->hasContent) and precomputes the
derived positions callers kept re-deriving by hand (contentStart/contentEnd,
childrenStart/childrenEnd) plus contentKind and isContentEmpty predicates.

Consolidates the producer family from 6 to 4, named by input:
getBlockInfoFromNode, getBlockInfoAt, getBlockInfoNearPos,
getBlockInfoFromSelection. Moves the generic navigation helpers
(getParentBlockInfo, getPrevBlockInfo, getNextBlockInfo,
getLastDescendantBlockInfo) out of mergeBlocks next to the producers.

Adds shape tests for the derived fields, characterization tests for the
navigation helpers and the migrated KeyboardShortcuts handlers.
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a194120-0ba1-49bd-85c7-d26571e41d32

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blocknote Ready Ready Preview Aug 25, 2026 11:34am
blocknote-website Ready Ready Preview Aug 25, 2026 11:34am

Request Review

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-25 14:44 UTC

@nperez0111

Copy link
Copy Markdown
Contributor Author

Folded into #3010: the BlockInfo simplification and the BlockInfo consolidation are now one API-simplification change at the top of the stack. The rest of the stack has been rebased accordingly (#2998 now sits directly on container-blocks/core).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant