From 5b5e87895cc6d55fd1043b11f609ef8f27b58450 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Tue, 6 Dec 2022 09:23:44 +0100 Subject: [PATCH] refactor(schema): allow for .components in block schema + ensure that the result has a name --- .../@sanity/schema/src/sanity/validation/types/block.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/@sanity/schema/src/sanity/validation/types/block.ts b/packages/@sanity/schema/src/sanity/validation/types/block.ts index 4eecaa0065c..47b84986a15 100644 --- a/packages/@sanity/schema/src/sanity/validation/types/block.ts +++ b/packages/@sanity/schema/src/sanity/validation/types/block.ts @@ -6,6 +6,7 @@ import {isJSONTypeOf} from '../utils/isJSONTypeOf' const getTypeOf = (thing) => (Array.isArray(thing) ? 'array' : typeof thing) const quote = (str) => `"${str}"` const allowedKeys = [ + 'components', 'lists', 'marks', 'name', @@ -17,8 +18,8 @@ const allowedKeys = [ 'validation', ] const allowedMarkKeys = ['decorators', 'annotations'] -const allowedStyleKeys = ['title', 'value', 'blockEditor'] -const allowedDecoratorKeys = ['title', 'value', 'blockEditor', 'icon'] +const allowedStyleKeys = ['title', 'value', 'components'] +const allowedDecoratorKeys = ['title', 'value', 'icon', 'components'] export default function validateBlockType(typeDef, visitorContext) { const problems = [] @@ -49,11 +50,11 @@ export default function validateBlockType(typeDef, visitorContext) { if (members) { members = validateMembers(members, visitorContext, problems) } - return { ...omit(typeDef, disallowedKeys), marks, styles, + name: typeDef.name || typeDef.type, of: members, _problems: problems, }