feat: add nested blocks schema support#2187
Open
christianhg wants to merge 2 commits intofeat-containersfrom
Open
feat: add nested blocks schema support#2187christianhg wants to merge 2 commits intofeat-containersfrom
christianhg wants to merge 2 commits intofeat-containersfrom
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
… of on FieldDefinition - Add NestedBlockSchemaType/NestedBlockDefinition for block types that appear inside block objects (e.g. table cells containing PTE content) - Add OfDefinition = BlockOfDefinition | ObjectOfDefinition discriminated union on FieldDefinition.of for array field member types - BlockOfDefinition (type: 'block') carries PTE sub-schema: styles, decorators, annotations, lists - ObjectOfDefinition (type: string) carries fields for non-block types - compileSchema() emits nestedBlocks: [] for existing schemas (additive) - 8 tests: backwards compat, nested blocks, of with block/object types, full table schema example
…f on array fields - Add nestedBlocks to PortableTextMemberSchemaTypes - Walk block object fields recursively to detect objects containing array-of-blocks fields (nested block containers like table cells) - Emit nestedBlocks in portableTextMemberSchemaTypesToSchema() - Carry OfDefinition (block vs object) through on array fields via sanityFieldToFieldDefinition() and sanityFieldToOfDefinition() - Use safeGetOf() to handle Sanity schema getter edge cases - Add table schema integration test: table → tableRow → tableCell with nested block content correctly detected - All existing tests updated with nestedBlocks: [] (additive)
22b9888 to
bdad5de
Compare
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.
Summary
Adds nested block support to
@portabletext/schemaand@portabletext/sanity-bridge, enabling block types that appear inside block objects (e.g. table cells containing PTE content).Ref:
task-schema-nested-blockson the board (Phase 0.1 + 0.2)Changes
@portabletext/schema(commit 1)NestedBlockSchemaType/NestedBlockDefinition— new types for block types inside block objectsOfDefinitiondiscriminated union —BlockOfDefinition | ObjectOfDefinitiononFieldDefinition.ofBlockOfDefinition(type: 'block') carries PTE sub-schema: styles, decorators, annotations, listsObjectOfDefinition(type: string) carries fields for non-block typescompileSchema()processesnestedBlocksandofrecursivelynestedBlocks: [])@portabletext/sanity-bridge(commit 2)PortableTextMemberSchemaTypes.nestedBlocks— new fieldcreatePortableTextMemberSchemaTypes()walks block object fields recursively to detect objects containing array-of-blocks fieldsportableTextMemberSchemaTypesToSchema()emitsnestedBlocksand carriesofthrough on array fieldssafeGetOf()handles Sanity schema getter edge casesnestedBlocks: [](additive)Design note: bridge auto-detection scope
The bridge detects nested blocks by finding objects that directly contain an array-of-blocks field (e.g.
tableCellwithcontent: array of [block]). Intermediate containers liketableRow(which hascells: array of [tableCell]but no blocks directly) are not auto-classified.The task spec example lists both
tableRowandtableCellasnestedBlocksindefineSchema()— works fine on the schema side since users declare them explicitly. Question: should the bridge also auto-detect intermediate containers? Happy to adjust.Test results
packages/schema: 8 tests ✅packages/sanity-bridge: 18 tests ✅