From 5593b182ca570cf9bcaebd495e2e796971fbccf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Tue, 12 Nov 2024 12:03:02 +0100 Subject: [PATCH 1/2] chore(example): upgrade @sanity/sanitype dependency --- examples/web/lib/form/FormNode.tsx | 5 ++++- examples/web/lib/form/inputs/UnionInput.tsx | 14 ++++++++++---- examples/web/package.json | 2 +- pnpm-lock.yaml | 18 +++++++++--------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/examples/web/lib/form/FormNode.tsx b/examples/web/lib/form/FormNode.tsx index 53529b3..6c7b2e9 100644 --- a/examples/web/lib/form/FormNode.tsx +++ b/examples/web/lib/form/FormNode.tsx @@ -9,6 +9,7 @@ import { getInstanceName, type Infer, isDocumentSchema, + isNeverSchema, isObjectSchema, isObjectUnionSchema, isOptionalSchema, @@ -74,7 +75,9 @@ function resolveNode( if (isObjectUnionSchema(schema)) { const type = value?._type - const valueType = schema.union.find(ut => getInstanceName(ut) === type)! + const valueType = schema.union.find( + ut => !isNeverSchema(ut) && getInstanceName(ut) === type, + )! const typeForm = ( (form as ObjectUnionFormDef).types as any )[type] diff --git a/examples/web/lib/form/inputs/UnionInput.tsx b/examples/web/lib/form/inputs/UnionInput.tsx index 7e56ff5..2220d6a 100644 --- a/examples/web/lib/form/inputs/UnionInput.tsx +++ b/examples/web/lib/form/inputs/UnionInput.tsx @@ -2,6 +2,7 @@ import {EllipsisVerticalIcon, TransferIcon, TrashIcon} from '@sanity/icons' import {assign, at, set, unset} from '@sanity/mutate' import { getInstanceName, + isNeverSchema, isObjectSchema, type ObjectUnionFormDef, pickDeep, @@ -39,7 +40,9 @@ export function UnionInput(props: InputProps) { const valueTypeName = value?._type const currentSchema = valueTypeName - ? schema.union.find(ut => getInstanceName(ut) === valueTypeName) + ? schema.union.find( + ut => !isNeverSchema(ut) && getInstanceName(ut) === valueTypeName, + ) : undefined const handlePatch = useCallback( @@ -56,7 +59,7 @@ export function UnionInput(props: InputProps) { const handleTurnInto = useCallback( (nextTypeName: string) => { const nextSchema = schema.union.find( - ut => getInstanceName(ut) === nextTypeName, + ut => !isNeverSchema(ut) && getInstanceName(ut) === nextTypeName, ) if (!nextSchema) { throw new Error(`No valid union type named ${nextTypeName}.`) @@ -74,7 +77,7 @@ export function UnionInput(props: InputProps) { const handleSelectType = useCallback( (nextTypeName: string) => { const nextSchema = schema.union.find( - ut => getInstanceName(ut) === nextTypeName, + ut => !isNeverSchema(ut) && getInstanceName(ut) === nextTypeName, ) if (!nextSchema) { throw new Error(`No valid union type named ${nextTypeName}.`) @@ -99,7 +102,7 @@ export function UnionInput(props: InputProps) {