Skip to content

Commit

Permalink
support link text with boolean config & empty link
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Sep 9, 2024
1 parent 68ff687 commit 732816c
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/types/model/contentRelationship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"
import type { CustomTypeModelLinkSelectType } from "./link"

/**
Expand All @@ -19,6 +18,5 @@ export interface CustomTypeModelContentRelationshipField<
select: typeof CustomTypeModelLinkSelectType.Document
customtypes?: readonly CustomTypeIDs[]
tags?: readonly Tags[]
text?: CustomTypeModelKeyTextField
}
}
4 changes: 1 addition & 3 deletions src/types/model/link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"

/**
* A link custom type field.
*
Expand All @@ -15,7 +13,7 @@ export interface CustomTypeModelLinkField {
select?:
| null
| (typeof CustomTypeModelLinkSelectType)[keyof typeof CustomTypeModelLinkSelectType]
text?: CustomTypeModelKeyTextField
allowText?: boolean
allowTargetBlank?: boolean
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/types/model/linkToMedia.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"
import type { CustomTypeModelLinkSelectType } from "./link"

/**
Expand All @@ -14,6 +13,6 @@ export interface CustomTypeModelLinkToMediaField {
label?: string | null
placeholder?: string
select: typeof CustomTypeModelLinkSelectType.Media
text?: CustomTypeModelKeyTextField
allowText?: boolean
}
}
1 change: 1 addition & 0 deletions src/types/value/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type EmptyLinkField<
Type extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,
> = {
link_type: Type | string
text?: string
}

/**
Expand Down
3 changes: 0 additions & 3 deletions test/types/customType-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ expectType<prismic.CustomTypeModelContentRelationshipField>({
config: {
label: "string",
select: prismic.CustomTypeModelLinkSelectType.Document,
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
},
})

Expand Down
4 changes: 1 addition & 3 deletions test/types/customType-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ expectType<prismic.CustomTypeModelLinkField>({
type: prismic.CustomTypeModelFieldType.Link,
config: {
label: "string",
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
allowText: true,
},
})

Expand Down
4 changes: 1 addition & 3 deletions test/types/customType-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ expectType<prismic.CustomTypeModelLinkToMediaField>({
config: {
label: "string",
select: prismic.CustomTypeModelLinkSelectType.Media,
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
allowText: true,
},
})

Expand Down
19 changes: 19 additions & 0 deletions test/types/fields-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
},
)

/**
* Empty state with text.
*/
expectType<prismic.ContentRelationshipField>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
text: "string",
},
)

/**
* Supports custom document type.
*/
Expand Down
70 changes: 70 additions & 0 deletions test/types/fields-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,82 @@ expectType<prismic.LinkField<string, string, never, "empty">>({
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Any,
})
expectType<prismic.LinkField<string, string, never, "filled">>({
// @ts-expect-error - Filled fields cannot contain an empty value.
link_type: prismic.LinkType.Any,
})
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Web,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Web,
},
)
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Document,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
},
)
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Media,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
},
)

/**
* Empty state with text.
*/
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Web,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Web,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Any,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>({
// @ts-expect-error - Filled fields cannot contain an empty value.
link_type: prismic.LinkType.Any,
text: "string",
})

/**
Expand Down
19 changes: 19 additions & 0 deletions test/types/fields-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ expectType<prismic.LinkToMediaField<"filled">>(
link_type: prismic.LinkType.Media,
},
)

/**
* Empty state with text.
*/
expectType<prismic.LinkToMediaField>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkToMediaField<"empty">>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkToMediaField<"filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
text: "string",
},
)

0 comments on commit 732816c

Please sign in to comment.