Skip to content

Commit

Permalink
feat: support extended media API response
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Sep 29, 2023
1 parent 1e22703 commit 87ca2e0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/types/value/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,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/types/value/linkToMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type LinkToMediaField<State extends FieldState = FieldState> =
* A 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/types/value/richText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,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/types/fields-image.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,32 @@ expectType<prismic.ImageField<never, "filled">>({
alt: "alt",
copyright: "copyright",
});
expectType<prismic.ImageField>({
id: "id",
url: "url",
dimensions: { width: 1, height: 1 },
edit: { x: 0, y: 0, zoom: 1, background: "background" },
alt: "alt",
copyright: "copyright",
});
expectType<prismic.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<prismic.ImageField<never, "empty">>({
// @ts-expect-error - Empty fields cannot contain a filled 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 +81,14 @@ expectType<prismic.ImageField<never, "empty">>({
copyright: null,
});
expectType<prismic.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 Down
21 changes: 21 additions & 0 deletions test/types/fields-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,30 @@ expectType<prismic.LinkToMediaField<"filled">>({
height: "string",
width: "string",
});
expectType<prismic.LinkToMediaField>({
id: "string",
link_type: prismic.LinkType.Media,
name: "string",
kind: "string",
url: "string",
size: "string",
height: "string",
width: "string",
});
expectType<prismic.LinkToMediaField<"filled">>({
id: "string",
link_type: prismic.LinkType.Media,
name: "string",
kind: "string",
url: "string",
size: "string",
height: "string",
width: "string",
});
expectType<prismic.LinkToMediaField<"empty">>({
link_type: prismic.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/types/fields-richText.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ expectType<prismic.RichTextField>([
{ type: prismic.RichTextNodeType.oListItem, text: "string", spans: [] },
{
type: prismic.RichTextNodeType.image,
id: "string",
alt: "string",
url: "string",
copyright: "string",
dimensions: {
width: 0,
height: 0,
},
edit: { x: 0, y: 0, zoom: 0, background: "string" },
linkTo: {
link_type: prismic.LinkType.Web,
url: "string",
Expand Down

0 comments on commit 87ca2e0

Please sign in to comment.