refactor(core): simplify BlockInfo with derived positions and consolidated producers - #3007
refactor(core): simplify BlockInfo with derived positions and consolidated producers#3007nperez0111 wants to merge 1 commit into
Conversation
…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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Part of the container-blocks stack: sits between #2997 (core container API) and #2998 (multi-column migration).
What changed
Field renames —
BlockInfodrops the internal jargon:bnBlockblockblockContentcontentchildContainerchildrenisWrappedBlockhasContent(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 + 1at 25+ sites,afterPos - 1at ~12, empty-inline-block checks at ~6).BlockInfonow carries them directly:contentStart/contentEnd— inside edges of the content nodechildren.childrenStart/children.childrenEnd— inside edges of the child containercontentKind: "inline" | "none" | "table" | "other"— replaces rawspec.contentstring checksisContentEmptyThese 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:
getBlockInfoFromNode(node, beforePos)getBlockInfoAt(doc, posBeforeBlock)getBlockInfoNearPos(source, pos)getBlockInfoFromSelection(source)getBlockInfoandgetBlockInfoFromResolvedPosare deleted;getBlockInfoWithManualOffset,getBlockInfoAtNearest, andgetBottomNestedBlockInfoare renamed (getBlockInfoFromNode,getBlockInfoNearPos,getLastDescendantBlockInfo).Navigation helpers moved —
getParentBlockInfo/getPrevBlockInfo/getNextBlockInfo/getLastDescendantBlockInfomove frommergeBlocks.tstogetBlockInfoFromPos.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,
keyboardhandlerse2e 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.