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: backport extended media API response #58

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/value/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ export type ImageFieldImage<State extends FieldState = FieldState> =
State extends "empty" ? EmptyImageFieldImage : FilledImageFieldImage;

export interface FilledImageFieldImage {
id: string;
url: string;
dimensions: {
width: number;
height: number;
};
edit: {
x: number;
y: number;
zoom: number;
background: string;
};
alt: string | null;
copyright: string | null;
}

export interface EmptyImageFieldImage {
id?: null;
url?: null;
dimensions?: null;
edit?: null;
alt?: null;
copyright?: null;
}
Expand Down
1 change: 1 addition & 0 deletions src/value/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type LinkToMediaField<State extends FieldState = FieldState> =
* Link that points to media
*/
export interface FilledLinkToMediaField {
id: string;
link_type: typeof LinkType.Media;
name: string;
kind: string;
Expand Down
7 changes: 7 additions & 0 deletions src/value/richText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,20 @@ export interface RTLabelNode extends RTSpanNodeBase {
*/
export type RTImageNode = {
type: typeof RichTextNodeType.image;
id: string;
url: string;
alt: string | null;
copyright: string | null;
dimensions: {
width: number;
height: number;
};
edit: {
x: number;
y: number;
zoom: number;
background: string;
};
linkTo?:
| FilledContentRelationshipField
| FilledLinkToWebField
Expand Down
24 changes: 24 additions & 0 deletions test/fields-image.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@ import * as prismicT from "../src";
* Filled state.
*/
expectType<prismicT.ImageField>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
});
expectType<prismicT.ImageField<never, "filled">>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
});
expectType<prismicT.ImageField<never, "empty">>({
// @ts-expect-error - Empty fields cannot contain an empty value.
id: "id",
// @ts-expect-error - Empty fields cannot contain a filled value.
url: "url",
// @ts-expect-error - Empty fields cannot contain a filled value.
dimensions: { width: 1, height: 1 },
// @ts-expect-error - Empty fields cannot contain a filled value.
edit: { x: 0, y: 0, zoom: 1, background: "background" },
// @ts-expect-error - Empty fields cannot contain a filled value.
alt: "alt",
// @ts-expect-error - Empty fields cannot contain a filled value.
copyright: "copyright",
Expand All @@ -61,10 +69,14 @@ expectType<prismicT.ImageField<never, "empty">>({
copyright: null,
});
expectType<prismicT.ImageField<never, "filled">>({
// @ts-expect-error - Filled fields cannot contain an empty value.
id: null,
// @ts-expect-error - Filled fields cannot contain an empty value.
url: null,
// @ts-expect-error - Filled fields cannot contain an empty value.
dimensions: null,
// @ts-expect-error - Filled fields cannot contain an empty value.
edit: null,
alt: null,
copyright: null,
});
Expand All @@ -73,8 +85,10 @@ expectType<prismicT.ImageField<never, "filled">>({
* Allows null alt and copyright.
*/
expectType<prismicT.ImageField>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: null,
copyright: null,
});
Expand All @@ -95,19 +109,25 @@ expectType<prismicT.ImageField>({
* Supports thumbnails.
*/
expectType<prismicT.ImageField<"Foo" | "Bar">>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
Foo: {
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
},
Bar: {
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
},
Expand Down Expand Up @@ -180,13 +200,17 @@ expectType<prismicT.ImageField>({
},
});
expectType<prismicT.ImageField<"length">>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
length: {
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
},
Expand Down
3 changes: 3 additions & 0 deletions test/fields-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as prismicT from "../src";
*/
expectType<prismicT.LinkToMediaField>({
link_type: prismicT.LinkType.Media,
id: "string",
name: "string",
kind: "string",
url: "string",
Expand All @@ -32,6 +33,7 @@ expectType<prismicT.LinkToMediaField>({
});
expectType<prismicT.LinkToMediaField<"filled">>({
link_type: prismicT.LinkType.Media,
id: "string",
name: "string",
kind: "string",
url: "string",
Expand All @@ -42,6 +44,7 @@ expectType<prismicT.LinkToMediaField<"filled">>({
expectType<prismicT.LinkToMediaField<"empty">>({
link_type: prismicT.LinkType.Media,
// @ts-expect-error - Empty fields cannot contain a filled value.
id: "string",
name: "string",
kind: "string",
url: "string",
Expand Down
2 changes: 2 additions & 0 deletions test/fields-richText.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ expectType<prismicT.RichTextField>([
{ type: prismicT.RichTextNodeType.oListItem, text: "string", spans: [] },
{
type: prismicT.RichTextNodeType.image,
id: "string",
alt: "string",
url: "string",
copyright: "string",
dimensions: {
width: 0,
height: 0,
},
edit: { x: 0, y: 0, zoom: 1, background: "background" },
linkTo: {
link_type: prismicT.LinkType.Web,
url: "string",
Expand Down
Loading