From 0902fa59ab0b2648ad1e80a01ba86cfc7e000820 Mon Sep 17 00:00:00 2001 From: Per-Kristian Nordnes Date: Thu, 15 Dec 2022 11:16:05 +0100 Subject: [PATCH] refactor(core/form): update render callback support for block types --- .../form/types/definitionExtensions.test.ts | 12 ++++++ .../core/form/types/definitionExtensions.ts | 41 +++++++++++-------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/sanity/src/core/form/types/definitionExtensions.test.ts b/packages/sanity/src/core/form/types/definitionExtensions.test.ts index 4f6e44a1330..8fd9db27375 100644 --- a/packages/sanity/src/core/form/types/definitionExtensions.test.ts +++ b/packages/sanity/src/core/form/types/definitionExtensions.test.ts @@ -3,6 +3,7 @@ import { CrossDatasetReferenceValue, + defineArrayMember, defineField, defineType, FileValue, @@ -153,6 +154,17 @@ describe('definitionExtensions', () => { }) }) + it('should extend components for block .of and .components', () => { + defineArrayMember({ + type: 'block', + name: 'test', + of: [{type: 'author', components: {inlineBlock: () => null}}], + components: { + block: () => null, + }, + }) + }) + it('should extend components for boolean', () => { const type = defineType({ type: 'boolean', diff --git a/packages/sanity/src/core/form/types/definitionExtensions.ts b/packages/sanity/src/core/form/types/definitionExtensions.ts index 7ba75a18ad8..0978cb5be36 100644 --- a/packages/sanity/src/core/form/types/definitionExtensions.ts +++ b/packages/sanity/src/core/form/types/definitionExtensions.ts @@ -38,10 +38,11 @@ import { * @beta */ export interface ArrayOfObjectsComponents { - annotation?: ComponentType - block?: ComponentType + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType + inlineBlock?: ComponentType input?: ComponentType item?: ComponentType preview?: ComponentType @@ -106,8 +107,11 @@ export interface DocumentComponents { * @beta */ export interface FileComponents { + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType> + inlineBlock?: ComponentType input?: ComponentType> item?: ComponentType> preview?: ComponentType @@ -117,8 +121,11 @@ export interface FileComponents { * @beta */ export interface GeopointComponents { + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType> + inlineBlock?: ComponentType input?: ComponentType> item?: ComponentType> preview?: ComponentType @@ -128,8 +135,11 @@ export interface GeopointComponents { * @beta */ export interface ImageComponents { + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType> + inlineBlock?: ComponentType input?: ComponentType> item?: ComponentType> preview?: ComponentType @@ -150,10 +160,11 @@ export interface NumberComponents { * @beta */ export interface ObjectComponents { - annotation?: ComponentType - block?: ComponentType + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType + inlineBlock?: ComponentType input?: ComponentType item?: ComponentType preview?: ComponentType @@ -163,10 +174,11 @@ export interface ObjectComponents { * @beta */ export interface ReferenceComponents { - annotation?: ComponentType - block?: ComponentType + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType> + inlineBlock?: ComponentType input?: ComponentType item?: ComponentType> preview?: ComponentType @@ -176,10 +188,11 @@ export interface ReferenceComponents { * @beta */ export interface CrossDatasetReferenceComponents { - annotation?: ComponentType - block?: ComponentType + annotation?: ComponentType + block?: ComponentType diff?: ComponentType field?: ComponentType> + inlineBlock?: ComponentType input?: ComponentType item?: ComponentType> preview?: ComponentType @@ -273,26 +286,20 @@ declare module '@sanity/types' { /** * @beta */ - components?: { - item?: ComponentType - } + component: ComponentType } export interface BlockStyleDefinition { /** * @beta */ - components?: { - item?: ComponentType - } + component: ComponentType } export interface BlockListDefinition { /** * @beta */ - components?: { - item?: ComponentType - } + component: ComponentType } export interface BlockAnnotationDefinition {