From 732816c342525bd8252f92fe3a9ac01801e35d17 Mon Sep 17 00:00:00 2001 From: Xavier Rutayisire Date: Mon, 9 Sep 2024 17:12:05 +0200 Subject: [PATCH] support link text with boolean config & empty link --- src/types/model/contentRelationship.ts | 2 - src/types/model/link.ts | 4 +- src/types/model/linkToMedia.ts | 3 +- src/types/value/link.ts | 1 + .../customType-contentRelationship.types.ts | 3 - test/types/customType-link.types.ts | 4 +- test/types/customType-linkToMedia.types.ts | 4 +- .../types/fields-contentRelationship.types.ts | 19 +++++ test/types/fields-link.types.ts | 70 +++++++++++++++++++ test/types/fields-linkToMedia.types.ts | 19 +++++ 10 files changed, 113 insertions(+), 16 deletions(-) diff --git a/src/types/model/contentRelationship.ts b/src/types/model/contentRelationship.ts index 4e172240..09f06294 100644 --- a/src/types/model/contentRelationship.ts +++ b/src/types/model/contentRelationship.ts @@ -1,6 +1,5 @@ import type { CustomTypeModelFieldType } from "./types" -import type { CustomTypeModelKeyTextField } from "./keyText" import type { CustomTypeModelLinkSelectType } from "./link" /** @@ -19,6 +18,5 @@ export interface CustomTypeModelContentRelationshipField< select: typeof CustomTypeModelLinkSelectType.Document customtypes?: readonly CustomTypeIDs[] tags?: readonly Tags[] - text?: CustomTypeModelKeyTextField } } diff --git a/src/types/model/link.ts b/src/types/model/link.ts index 3867f377..13793999 100644 --- a/src/types/model/link.ts +++ b/src/types/model/link.ts @@ -1,7 +1,5 @@ import type { CustomTypeModelFieldType } from "./types" -import type { CustomTypeModelKeyTextField } from "./keyText" - /** * A link custom type field. * @@ -15,7 +13,7 @@ export interface CustomTypeModelLinkField { select?: | null | (typeof CustomTypeModelLinkSelectType)[keyof typeof CustomTypeModelLinkSelectType] - text?: CustomTypeModelKeyTextField + allowText?: boolean allowTargetBlank?: boolean } } diff --git a/src/types/model/linkToMedia.ts b/src/types/model/linkToMedia.ts index c8c3f062..bf4dbddc 100644 --- a/src/types/model/linkToMedia.ts +++ b/src/types/model/linkToMedia.ts @@ -1,6 +1,5 @@ import type { CustomTypeModelFieldType } from "./types" -import type { CustomTypeModelKeyTextField } from "./keyText" import type { CustomTypeModelLinkSelectType } from "./link" /** @@ -14,6 +13,6 @@ export interface CustomTypeModelLinkToMediaField { label?: string | null placeholder?: string select: typeof CustomTypeModelLinkSelectType.Media - text?: CustomTypeModelKeyTextField + allowText?: boolean } } diff --git a/src/types/value/link.ts b/src/types/value/link.ts index d0a67791..870004b1 100644 --- a/src/types/value/link.ts +++ b/src/types/value/link.ts @@ -24,6 +24,7 @@ export type EmptyLinkField< Type extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any, > = { link_type: Type | string + text?: string } /** diff --git a/test/types/customType-contentRelationship.types.ts b/test/types/customType-contentRelationship.types.ts index 00f51093..9df1cdd2 100644 --- a/test/types/customType-contentRelationship.types.ts +++ b/test/types/customType-contentRelationship.types.ts @@ -104,9 +104,6 @@ expectType({ config: { label: "string", select: prismic.CustomTypeModelLinkSelectType.Document, - text: { - type: prismic.CustomTypeModelFieldType.Text, - }, }, }) diff --git a/test/types/customType-link.types.ts b/test/types/customType-link.types.ts index a6acd23d..d4808957 100644 --- a/test/types/customType-link.types.ts +++ b/test/types/customType-link.types.ts @@ -67,9 +67,7 @@ expectType({ type: prismic.CustomTypeModelFieldType.Link, config: { label: "string", - text: { - type: prismic.CustomTypeModelFieldType.Text, - }, + allowText: true, }, }) diff --git a/test/types/customType-linkToMedia.types.ts b/test/types/customType-linkToMedia.types.ts index 9553ad2b..168934f6 100644 --- a/test/types/customType-linkToMedia.types.ts +++ b/test/types/customType-linkToMedia.types.ts @@ -48,9 +48,7 @@ expectType({ config: { label: "string", select: prismic.CustomTypeModelLinkSelectType.Media, - text: { - type: prismic.CustomTypeModelFieldType.Text, - }, + allowText: true, }, }) diff --git a/test/types/fields-contentRelationship.types.ts b/test/types/fields-contentRelationship.types.ts index 1b8f49c0..71f455f3 100644 --- a/test/types/fields-contentRelationship.types.ts +++ b/test/types/fields-contentRelationship.types.ts @@ -78,6 +78,25 @@ expectType>( }, ) +/** + * Empty state with text. + */ +expectType({ + link_type: prismic.LinkType.Document, + text: "string", +}) +expectType>({ + link_type: prismic.LinkType.Document, + text: "string", +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Document, + text: "string", + }, +) + /** * Supports custom document type. */ diff --git a/test/types/fields-link.types.ts b/test/types/fields-link.types.ts index 65e4e019..2f8a3a5d 100644 --- a/test/types/fields-link.types.ts +++ b/test/types/fields-link.types.ts @@ -88,12 +88,82 @@ expectType>({ expectType({ link_type: prismic.LinkType.Any, }) +expectType>({ + // @ts-expect-error - Filled fields cannot contain an empty value. + link_type: prismic.LinkType.Any, +}) +expectType({ + link_type: prismic.LinkType.Web, +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Web, + }, +) +expectType({ + link_type: prismic.LinkType.Document, +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Document, + }, +) +expectType({ + link_type: prismic.LinkType.Media, +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Media, + }, +) + +/** + * Empty state with text. + */ +expectType>({ + link_type: prismic.LinkType.Web, + text: "string", +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Web, + text: "string", + }, +) +expectType>({ + link_type: prismic.LinkType.Document, + text: "string", +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Document, + text: "string", + }, +) +expectType>({ + link_type: prismic.LinkType.Media, + text: "string", +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Media, + text: "string", + }, +) expectType>({ link_type: prismic.LinkType.Any, + text: "string", }) expectType>({ // @ts-expect-error - Filled fields cannot contain an empty value. link_type: prismic.LinkType.Any, + text: "string", }) /** diff --git a/test/types/fields-linkToMedia.types.ts b/test/types/fields-linkToMedia.types.ts index 873b0ed4..c5b63fbf 100644 --- a/test/types/fields-linkToMedia.types.ts +++ b/test/types/fields-linkToMedia.types.ts @@ -71,3 +71,22 @@ expectType>( link_type: prismic.LinkType.Media, }, ) + +/** + * Empty state with text. + */ +expectType({ + link_type: prismic.LinkType.Media, + text: "string", +}) +expectType>({ + link_type: prismic.LinkType.Media, + text: "string", +}) +expectType>( + // @ts-expect-error - Filled fields cannot contain an empty value. + { + link_type: prismic.LinkType.Media, + text: "string", + }, +)