Skip to content

Commit

Permalink
Merge pull request #348 from prismicio/lg/text-in-links
Browse files Browse the repository at this point in the history
feat: add support for `text` property in link fields
  • Loading branch information
dani-mp authored Sep 25, 2024
2 parents 56bf0ba + 8739e02 commit 9b0c72b
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 29 deletions.
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,57 @@

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.11.0](https://github.com/prismicio/prismic-client/compare/v7.10.1...v7.11.0) (2024-09-25)

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


### Chore

* **release:** 7.10.0-alpha.0 ([c801c12](https://github.com/prismicio/prismic-client/commit/c801c12b3f2a1175530a17a0c45d414ef3412797))

## [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.10.1](https://github.com/prismicio/prismic-client/compare/v7.10.0...v7.10.1) (2024-09-23)


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.10.1",
"version": "7.11.0",
"description": "The official JavaScript + TypeScript client library for Prismic",
"keywords": [
"typescript",
Expand Down
6 changes: 0 additions & 6 deletions src/Migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,13 @@ export class Migration<TDocuments extends PrismicDocument = PrismicDocument> {
// ID needs to be 16 characters long to be considered valid by the API
id: "_____broken_____",
isBroken: true,
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
text: input.text,
}
}

return {
link_type: LinkType.Document,
id: () => this._getByOriginalID(input.id),
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
text: input.text,
}
}
Expand All @@ -429,8 +425,6 @@ export class Migration<TDocuments extends PrismicDocument = PrismicDocument> {
return {
link_type: LinkType.Media,
id: this.createAsset(input),
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
text: input.text,
}
}
Expand Down
11 changes: 1 addition & 10 deletions src/types/migration/Asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,7 @@ export type MigrationLinkToMedia = Pick<
LinkToMediaField<"filled">,
"link_type"
> &
Partial<
Pick<
LinkToMediaField<"filled">,
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
"text"
>
> & {
Partial<Pick<LinkToMediaField<"filled">, "text">> & {
/**
* A reference to the migration asset used to resolve the link to media
* field's value.
Expand All @@ -95,8 +88,6 @@ export type MigrationLinkToMedia = Pick<
* with the migration API.
*/
export type MigrationLinkToMediaField =
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
| Pick<LinkToMediaField<"filled">, "link_type" | "id" | "text">
| EmptyLinkField<"Media">

Expand Down
9 changes: 1 addition & 8 deletions src/types/migration/ContentRelationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ export type MigrationContentRelationship<
> =
| ValueOrThunk<TDocuments | PrismicMigrationDocument<TDocuments> | undefined>
| (Pick<FilledContentRelationshipField, "link_type"> &
Partial<
Pick<
FilledContentRelationshipField,
// TODO: Remove when link text PR is merged
// @ts-expect-error - Future-proofing for link text
"text"
>
> & {
Partial<Pick<FilledContentRelationshipField, "text">> & {
id: ValueOrThunk<
TDocuments | PrismicMigrationDocument<TDocuments> | undefined
>
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
}
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
}

/**
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
}
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",
},
)

/**
* Supports custom document type.
*/
Expand Down
Loading

0 comments on commit 9b0c72b

Please sign in to comment.