Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for text property in link fields #348

Merged
merged 21 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [7.10.0-alpha.0](https://github.com/prismicio/prismic-client/compare/v7.9.0...v7.10.0-alpha.0) (2024-09-20)

## [7.9.0-alpha.3](https://github.com/prismicio/prismic-client/compare/v7.8.1...v7.9.0-alpha.3) (2024-09-10)


### Chore

* **release:** 7.9.0-alpha.3 ([0d3fb98](https://github.com/prismicio/prismic-client/commit/0d3fb98743b79d3fc2a41dcb2fc6edfc67857478))

## [7.9.0-alpha.2](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.1...v7.9.0-alpha.2) (2024-08-27)


### Chore

* **release:** 7.9.0-alpha.2 ([000f146](https://github.com/prismicio/prismic-client/commit/000f146d25b84b2937c3accaffa54ab936a78de8))
* revert previous changes ([c53de86](https://github.com/prismicio/prismic-client/commit/c53de86a7ed749f0f9d8999b9e58564d9a8efe35))

## [7.9.0-alpha.1](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.0...v7.9.0-alpha.1) (2024-08-27)


### Features

* use KeyTextField for link text value definition ([1a4c51a](https://github.com/prismicio/prismic-client/commit/1a4c51a389ed4d06cf69c3edcb215559ba91fe99))


### Chore

* **release:** 7.9.0-alpha.1 ([d940fcd](https://github.com/prismicio/prismic-client/commit/d940fcdb023de34765006607f7f34481de00a6ef))
* remove changelog for alpha ([50fc797](https://github.com/prismicio/prismic-client/commit/50fc797372726c0abc575b9f1b0a56d5db939bb1))

## [7.9.0-alpha.0](https://github.com/prismicio/prismic-client/compare/v7.8.0...v7.9.0-alpha.0) (2024-08-14)


### Features

* add text property to link models ([40d0e0b](https://github.com/prismicio/prismic-client/commit/40d0e0be3ce8038cd36e8cdf3350ffa9893ada98))
* add text to link value models ([8459d75](https://github.com/prismicio/prismic-client/commit/8459d75608c1af8319adafd2b3bf73555569a434))


### Chore

* **release:** 7.9.0-alpha.0 ([f2021c0](https://github.com/prismicio/prismic-client/commit/f2021c053b9aac1c17b7bbd1845c91eab7b0d176))
* update package version ([c06b383](https://github.com/prismicio/prismic-client/commit/c06b383ff41f01e253641c7852a4e9701725bdba))

## [7.9.0](https://github.com/prismicio/prismic-client/compare/v7.8.1...v7.9.0) (2024-09-17)


Expand All @@ -21,6 +65,13 @@ All notable changes to this project will be documented in this file. See [standa

* add missing `is_master` property on repository type ([0289698](https://github.com/prismicio/prismic-client/commit/0289698cc9ca7ed5b264f71f2a9f8d39e3710058))

## [7.9.0-alpha.2](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.1...v7.9.0-alpha.2) (2024-08-27)


### Chore

* revert previous changes ([c53de86](https://github.com/prismicio/prismic-client/commit/c53de86a7ed749f0f9d8999b9e58564d9a8efe35))

## [7.8.0](https://github.com/prismicio/prismic-client/compare/v7.7.4...v7.8.0) (2024-08-01)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/client",
"version": "7.9.0",
"version": "7.10.0-alpha.0",
"description": "The official JavaScript + TypeScript client library for Prismic",
"keywords": [
"typescript",
Expand Down
1 change: 1 addition & 0 deletions src/types/model/contentRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export interface CustomTypeModelContentRelationshipField<
select: typeof CustomTypeModelLinkSelectType.Document
customtypes?: readonly CustomTypeIDs[]
tags?: readonly Tags[]
allowText?: boolean
}
}
1 change: 1 addition & 0 deletions src/types/model/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CustomTypeModelLinkField {
select?:
| null
| (typeof CustomTypeModelLinkSelectType)[keyof typeof CustomTypeModelLinkSelectType]
allowText?: boolean
allowTargetBlank?: boolean
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types/model/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export interface CustomTypeModelLinkToMediaField {
label?: string | null
placeholder?: string
select: typeof CustomTypeModelLinkSelectType.Media
allowText?: boolean
}
}
1 change: 1 addition & 0 deletions src/types/value/contentRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export interface FilledContentRelationshipField<
slug?: string
isBroken?: boolean
data?: DataInterface
text?: string
levimykel marked this conversation as resolved.
Show resolved Hide resolved
dani-mp marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 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 All @@ -33,6 +34,7 @@ export interface FilledLinkToWebField {
link_type: typeof LinkType.Web
url: string
target?: string
text?: string
levimykel marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/types/value/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export interface FilledLinkToMediaField {
size: string
height?: string | null
width?: string | null
text?: string
levimykel marked this conversation as resolved.
Show resolved Hide resolved
}
11 changes: 11 additions & 0 deletions test/types/customType-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ expectType<prismic.CustomTypeModelLinkField>({
},
})

/**
* Supports optional `text` property.
*/
expectType<prismic.CustomTypeModelLinkField>({
type: prismic.CustomTypeModelFieldType.Link,
config: {
label: "string",
allowText: true,
},
})

/**
* `@prismicio/types` extends `@prismicio/types-internal`
*/
Expand Down
12 changes: 12 additions & 0 deletions test/types/customType-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ expectType<prismic.CustomTypeModelLinkToMediaField>({
},
})

/**
* Supports optional `text` property.
*/
expectType<prismic.CustomTypeModelLinkToMediaField>({
type: prismic.CustomTypeModelFieldType.Link,
config: {
label: "string",
select: prismic.CustomTypeModelLinkSelectType.Media,
allowText: true,
},
})

/**
* `@prismicio/types` extends `@prismicio/types-internal`
*/
Expand Down
22 changes: 22 additions & 0 deletions test/types/fields-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ expectType<prismic.ContentRelationshipField>({
slug: "string",
isBroken: true,
data: undefined,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "filled">>({
link_type: prismic.LinkType.Document,
Expand All @@ -44,6 +45,7 @@ expectType<prismic.ContentRelationshipField<string, string, never, "filled">>({
slug: "string",
isBroken: true,
data: undefined,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>({
link_type: prismic.LinkType.Document,
Expand All @@ -57,6 +59,7 @@ expectType<prismic.ContentRelationshipField<string, string, never, "empty">>({
slug: "string",
isBroken: true,
data: undefined,
text: "string",
})

/**
Expand All @@ -75,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",
},
)

dani-mp marked this conversation as resolved.
Show resolved Hide resolved
/**
* Supports custom document type.
*/
Expand Down
75 changes: 75 additions & 0 deletions test/types/fields-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ expectType<prismic.LinkField>({
link_type: prismic.LinkType.Web,
url: "string",
target: "string",
text: "string",
})
// Content relationship link
expectType<prismic.LinkField>({
Expand All @@ -54,6 +55,7 @@ expectType<prismic.LinkField>({
slug: "string",
isBroken: true,
data: undefined,
text: "string",
})
// Media link
expectType<prismic.LinkField>({
Expand All @@ -64,17 +66,20 @@ expectType<prismic.LinkField>({
size: "string",
height: "string",
width: "string",
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>({
link_type: prismic.LinkType.Web,
url: "string",
target: "string",
text: "string",
})
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Web,
// @ts-expect-error - Empty fields cannot contain a filled value.
url: "string",
target: "string",
text: "string",
})

/**
Expand All @@ -83,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
22 changes: 22 additions & 0 deletions test/types/fields-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ expectType<prismic.LinkToMediaField>({
size: "string",
height: "string",
width: "string",
text: "string",
})
expectType<prismic.LinkToMediaField<"filled">>({
id: "string",
Expand All @@ -40,6 +41,7 @@ expectType<prismic.LinkToMediaField<"filled">>({
size: "string",
height: "string",
width: "string",
text: "string",
})
expectType<prismic.LinkToMediaField<"empty">>({
link_type: prismic.LinkType.Media,
Expand All @@ -51,6 +53,7 @@ expectType<prismic.LinkToMediaField<"empty">>({
size: "string",
height: "string",
width: "string",
text: "string",
})

/**
Expand All @@ -68,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",
},
)
Loading