@prismicio/api-renderer
Advanced tools
Comparing version 3.2.4-alpha.8 to 3.3.0
@@ -141,3 +141,2 @@ import * as t from "io-ts"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -312,3 +311,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -484,3 +482,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -652,3 +649,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -826,3 +822,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -994,3 +989,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -997,0 +991,0 @@ }) | ({ |
@@ -1,13 +0,6 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
import * as t from "io-ts"; | ||
declare const codec: t.IntersectionC<[t.PartialC<{ | ||
select: t.UnionC<[t.LiteralC<"any">, t.NullC, t.UndefinedC]>; | ||
}>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>; | ||
export type AnyLinkDef = { | ||
select: null; | ||
} & Pick<t.TypeOf<typeof codec>, "allowText">; | ||
}; | ||
export declare const AnyLinkDef: t.Type<AnyLinkDef, AnyLinkDef, unknown>; | ||
export declare function defaultAnyLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): AnyLinkDef; | ||
export {}; | ||
export declare function defaultAnyLinkDef(): AnyLinkDef; |
@@ -8,10 +8,5 @@ "use strict"; | ||
const t = tslib_1.__importStar(require("io-ts")); | ||
const codec = t.intersection([ | ||
t.partial({ | ||
select: t.union([t.literal("any"), t.null, t.undefined]), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]); | ||
const codec = t.partial({ | ||
select: t.union([t.literal("any"), t.null, t.undefined]), | ||
}); | ||
exports.AnyLinkDef = new t.Type("AnyLinkDef", (u) => u.select === "any", (u) => { | ||
@@ -24,9 +19,7 @@ return (0, function_1.pipe)(codec.decode(u), fp_ts_1.either.map(() => { | ||
}, (l) => l); | ||
function defaultAnyLinkDef(config) { | ||
function defaultAnyLinkDef() { | ||
return { | ||
select: null, | ||
allowText: true, | ||
...config, | ||
}; | ||
} | ||
exports.defaultAnyLinkDef = defaultAnyLinkDef; |
@@ -1,10 +0,7 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
import * as t from "io-ts"; | ||
export declare const DocumentLinkDef: t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
export declare const DocumentLinkDef: t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"document">; | ||
customtypes: t.ReadonlyArrayC<t.StringC>; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>; | ||
}>>; | ||
export type DocumentLinkDef = t.TypeOf<typeof DocumentLinkDef>; | ||
export declare function defaultDocumentLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): DocumentLinkDef; | ||
export declare function defaultDocumentLinkDef(): DocumentLinkDef; |
@@ -6,19 +6,12 @@ "use strict"; | ||
const t = tslib_1.__importStar(require("io-ts")); | ||
exports.DocumentLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("document"), | ||
customtypes: t.readonlyArray(t.string), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]); | ||
function defaultDocumentLinkDef(config) { | ||
exports.DocumentLinkDef = t.strict({ | ||
select: t.literal("document"), | ||
customtypes: t.readonlyArray(t.string), | ||
}); | ||
function defaultDocumentLinkDef() { | ||
return { | ||
select: "document", | ||
customtypes: [], | ||
allowText: true, | ||
...config, | ||
}; | ||
} | ||
exports.defaultDocumentLinkDef = defaultDocumentLinkDef; |
@@ -5,16 +5,10 @@ import { Link } from "@prismicio/types-internal/lib/customtypes/widgets/nestable"; | ||
import { AnyLinkDef } from "./AnyLinkDef"; | ||
declare const LinkConfig: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
declare const LinkConfig: t.UnionC<[t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"media">; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
}>>, t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"document">; | ||
customtypes: t.ReadonlyArrayC<t.StringC>; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
}>>, t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"web">; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>, t.Type<AnyLinkDef, AnyLinkDef, unknown>]>; | ||
}>>, t.Type<AnyLinkDef, AnyLinkDef, unknown>]>; | ||
type LinkConfig = t.TypeOf<typeof LinkConfig>; | ||
@@ -34,3 +28,2 @@ export declare const LinkDef: t.Type<WithKey<{ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -50,6 +43,5 @@ }>, WithKey<{ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
}>, unknown>; | ||
export declare function defaultLink(type: LinkConfig["select"], config?: Omit<LinkConfig, "select" | "customtypes">): Link; | ||
export declare function defaultLink(type: LinkConfig["select"]): Link; | ||
export declare function isMediaLinkDef(def: Link): boolean; | ||
@@ -56,0 +48,0 @@ export declare function isAnyLinkDef(def: Link): boolean; |
@@ -30,13 +30,13 @@ "use strict"; | ||
}, (l) => l); | ||
function defaultLink(type, config) { | ||
const resolvedConfig = (() => { | ||
function defaultLink(type) { | ||
const config = (() => { | ||
switch (type) { | ||
case "document": | ||
return (0, DocumentLinkDef_1.defaultDocumentLinkDef)(config); | ||
return (0, DocumentLinkDef_1.defaultDocumentLinkDef)(); | ||
case "media": | ||
return (0, MediaLinkDef_1.defaultMediaLinkDef)(config); | ||
return (0, MediaLinkDef_1.defaultMediaLinkDef)(); | ||
case "web": | ||
return (0, WebLinkDef_1.defaultWebLinkDef)(config); | ||
return (0, WebLinkDef_1.defaultWebLinkDef)(); | ||
case null: | ||
return (0, AnyLinkDef_1.defaultAnyLinkDef)(config); | ||
return (0, AnyLinkDef_1.defaultAnyLinkDef)(); | ||
} | ||
@@ -46,3 +46,3 @@ })(); | ||
type: "Link", | ||
config: resolvedConfig, | ||
config, | ||
}; | ||
@@ -49,0 +49,0 @@ } |
@@ -1,9 +0,6 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
import * as t from "io-ts"; | ||
export declare const MediaLinkDef: t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
export declare const MediaLinkDef: t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"media">; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>; | ||
}>>; | ||
export type MediaLinkDef = t.TypeOf<typeof MediaLinkDef>; | ||
export declare function defaultMediaLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): MediaLinkDef; | ||
export declare function defaultMediaLinkDef(): MediaLinkDef; |
@@ -6,17 +6,10 @@ "use strict"; | ||
const t = tslib_1.__importStar(require("io-ts")); | ||
exports.MediaLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("media"), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]); | ||
function defaultMediaLinkDef(config) { | ||
exports.MediaLinkDef = t.strict({ | ||
select: t.literal("media"), | ||
}); | ||
function defaultMediaLinkDef() { | ||
return { | ||
select: "media", | ||
allowText: true, | ||
...config, | ||
}; | ||
} | ||
exports.defaultMediaLinkDef = defaultMediaLinkDef; |
@@ -1,9 +0,6 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
import * as t from "io-ts"; | ||
export declare const WebLinkDef: t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
export declare const WebLinkDef: t.ExactC<t.TypeC<{ | ||
select: t.LiteralC<"web">; | ||
}>>, t.PartialC<{ | ||
allowText: t.BooleanC; | ||
}>]>; | ||
}>>; | ||
export type WebLinkDef = t.TypeOf<typeof WebLinkDef>; | ||
export declare function defaultWebLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): WebLinkDef; | ||
export declare function defaultWebLinkDef(): WebLinkDef; |
@@ -6,17 +6,10 @@ "use strict"; | ||
const t = tslib_1.__importStar(require("io-ts")); | ||
exports.WebLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("web"), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]); | ||
function defaultWebLinkDef(config) { | ||
exports.WebLinkDef = t.strict({ | ||
select: t.literal("web"), | ||
}); | ||
function defaultWebLinkDef() { | ||
return { | ||
select: "web", | ||
allowText: true, | ||
...config, | ||
}; | ||
} | ||
exports.defaultWebLinkDef = defaultWebLinkDef; |
@@ -299,3 +299,2 @@ import * as t from "io-ts"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -315,4 +314,3 @@ }>, import("../..").WithKey<{ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
}>, unknown>]>; |
@@ -139,3 +139,2 @@ import * as t from "io-ts"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -300,3 +299,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -471,3 +469,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -632,3 +629,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -635,0 +631,0 @@ }) | ({ |
@@ -131,3 +131,2 @@ import * as t from "io-ts"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -299,3 +298,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -460,3 +458,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -628,3 +625,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -631,0 +627,0 @@ }) | ({ |
@@ -0,3 +1,11 @@ | ||
export declare function encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string; | ||
export declare function decodeDocId(id: string, handlerType: string): [string, string?]; | ||
export interface IDEncoder { | ||
encode: (strId: string) => string; | ||
} | ||
export declare function IDEncoder(prefix: string): IDEncoder; | ||
export declare const IDEncoders: { | ||
documentLinks: IDEncoder; | ||
documentUrls: IDEncoder; | ||
integrationFields: IDEncoder; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IDEncoders = exports.IDEncoder = exports.decodeDocId = exports.encodeDocId = void 0; | ||
const DOC_SEPARATOR = "%%"; | ||
function encodeDocId(documentId, maybeAdditionalData) { | ||
return `${documentId}${DOC_SEPARATOR}${maybeAdditionalData !== null && maybeAdditionalData !== void 0 ? maybeAdditionalData : ""}`; | ||
} | ||
exports.encodeDocId = encodeDocId; | ||
function decodeDocId(id, handlerType) { | ||
const [docId, maybeAdditionalData] = id.split(DOC_SEPARATOR); | ||
if (docId && maybeAdditionalData) { | ||
return [docId, maybeAdditionalData]; | ||
} | ||
else if (docId) { | ||
return [docId]; | ||
} | ||
else { | ||
throw new Error(`Unable to read from for extension ${handlerType} with encoded api key ${id}`); | ||
} | ||
} | ||
exports.decodeDocId = decodeDocId; | ||
function IDEncoder(prefix) { | ||
const BYTES_SIZE_LENGTH = 3; | ||
return { | ||
encode: (strId) => { | ||
const idLength = strId.length; | ||
if (Buffer.byteLength(idLength.toString(), "utf8") <= BYTES_SIZE_LENGTH) { | ||
const length = `${idLength}`.padStart(BYTES_SIZE_LENGTH, "0"); // util.format(`%0${BYTES_SIZE_LENGTH}d`, idLength) | ||
return prefix + length + strId; | ||
} | ||
else { | ||
throw new Error(`ID is too long. Its size is ${idLength} and should be inferior to 1000`); | ||
} | ||
}, | ||
}; | ||
} | ||
exports.IDEncoder = IDEncoder; | ||
exports.IDEncoders = { | ||
documentLinks: IDEncoder("=&="), | ||
documentUrls: IDEncoder(">&<"), | ||
integrationFields: IDEncoder("%!%"), | ||
}; |
@@ -1,1 +0,1 @@ | ||
export { type IDEncoder } from "./Encoder"; | ||
export { type IDEncoder, encodeDocId, IDEncoders } from "./Encoder"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.IDEncoders = exports.encodeDocId = void 0; | ||
var Encoder_1 = require("./Encoder"); | ||
Object.defineProperty(exports, "encodeDocId", { enumerable: true, get: function () { return Encoder_1.encodeDocId; } }); | ||
Object.defineProperty(exports, "IDEncoders", { enumerable: true, get: function () { return Encoder_1.IDEncoders; } }); |
@@ -8,3 +8,3 @@ import type { ApiDocument } from "./ApiDocument"; | ||
DocEncoder: { | ||
encodeDocId(documentId: string, fetchUuidOrRelationName: string | undefined, additionalData: (string | undefined)[]): string; | ||
encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string; | ||
}; | ||
@@ -11,0 +11,0 @@ encoders: { |
@@ -1,2 +0,2 @@ | ||
import type { AnyLinkContent, DocumentLinkContent, ExternalLinkContent, FileLinkContent, ImageLinkContent, MediaLinkContent, SliceContent, WidgetContent } from "@prismicio/types-internal/lib/content"; | ||
import type { DocumentLinkContent, ExternalLinkContent, FileLinkContent, ImageLinkContent, SliceContent, WidgetContent } from "@prismicio/types-internal/lib/content"; | ||
import type { StaticSlice, StaticWidget } from "@prismicio/types-internal/lib/customtypes"; | ||
@@ -8,6 +8,6 @@ import type { AnyLinkDef, DocumentLinkDef, MediaLinkDef, WebLinkDef } from "./customtypes"; | ||
renderV2(definition: D, content: C, fetch?: F | undefined): unknown; | ||
renderDefault(definition: D, content?: C): unknown; | ||
renderDefault(definition: D): unknown; | ||
renderMocks(definition: D, content: C): unknown; | ||
} | ||
export interface LinkRenderer<D extends MediaLinkDef | DocumentLinkDef | WebLinkDef | MediaLinkDef | AnyLinkDef, C extends DocumentLinkContent | FileLinkContent | ExternalLinkContent | ImageLinkContent | MediaLinkContent | AnyLinkContent, F extends Field | undefined = undefined> { | ||
export interface LinkRenderer<D extends MediaLinkDef | DocumentLinkDef | WebLinkDef, C extends DocumentLinkContent | FileLinkContent | ExternalLinkContent | ImageLinkContent, F extends Field | undefined = undefined> { | ||
renderV1(content: C, fetch?: F | undefined): unknown; | ||
@@ -14,0 +14,0 @@ renderV2(definition: D | AnyLinkDef, content: C, fetch?: F | undefined): unknown; |
@@ -39,3 +39,3 @@ "use strict"; | ||
type: "Image", | ||
value: { main: renderImageContentView(content, ctx, models_1.ApiVersion.v1), views: views }, | ||
value: { main: renderImageContentView(content, ctx, models_1.ApiVersion.v1), views }, | ||
}; | ||
@@ -45,3 +45,3 @@ } | ||
type: "Image", | ||
value: { main: renderImageContentView(content, ctx, models_1.ApiVersion.v1), views: [] }, | ||
value: { main: renderImageContentView(content, ctx, models_1.ApiVersion.v1), views: {} }, | ||
}; | ||
@@ -51,3 +51,3 @@ }, | ||
const main = renderImageContentView(content, ctx, models_1.ApiVersion.v2); | ||
if (content.thumbnails && content.thumbnails) { | ||
if (content.thumbnails) { | ||
const views = Object.entries(content.thumbnails).reduce((acc, [k, v]) => { | ||
@@ -54,0 +54,0 @@ return Object.assign(acc, { [k]: renderImageContentView(v, ctx, models_1.ApiVersion.v2) }); |
@@ -6,16 +6,13 @@ "use strict"; | ||
exports.BROKEN_CUSTOM_TYPE = "broken_type"; | ||
function brokenLinkV1(link) { | ||
function brokenLinkV2(id) { | ||
return { | ||
...("id" in link && { id: link.id, tags: [] }), | ||
id: id, | ||
type: exports.BROKEN_CUSTOM_TYPE, | ||
tags: [], | ||
isBroken: true, | ||
...(link.text && { text: link.text }), | ||
}; | ||
} | ||
function brokenLinkV2(link, def) { | ||
function brokenLinkV1(id) { | ||
return { | ||
...("id" in link && { id: link.id, tags: [] }), | ||
type: exports.BROKEN_CUSTOM_TYPE, | ||
isBroken: true, | ||
...(((def === null || def === void 0 ? void 0 : def.allowText) || !def) && link.text && { text: link.text }), | ||
value: brokenLinkV2(id), | ||
}; | ||
@@ -27,53 +24,36 @@ } | ||
try { | ||
if ("id" in link) { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid, [link.text]); | ||
return { | ||
type: "Link.document", | ||
value: ctx.Extension.encoders.documentLinks.encode(id), | ||
}; | ||
} | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid); | ||
return { | ||
type: "Link.document", | ||
...brokenLinkV1(link), | ||
value: ctx.Extension.encoders.documentLinks.encode(id), | ||
}; | ||
} | ||
catch (e) { | ||
return brokenLinkV1(link); | ||
return brokenLinkV1(link.id); | ||
} | ||
}, | ||
renderV2(def, link, fetch) { | ||
renderV2(_def, link, fetch) { | ||
//todo check fetch type | ||
try { | ||
const linkText = def.allowText ? link.text : undefined; | ||
if ("id" in link) { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid, [linkText]); | ||
return ctx.Extension.encoders.documentLinks.encode(id); | ||
} | ||
return { | ||
link_type: "Document", | ||
...brokenLinkV2(link, def), | ||
}; | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid); | ||
return ctx.Extension.encoders.documentLinks.encode(id); | ||
} | ||
catch (e) { | ||
return brokenLinkV2(link, def); | ||
return brokenLinkV2(link.id); | ||
} | ||
}, | ||
renderMocks(def, link) { | ||
if ("id" in link) { | ||
const type = (models_1.DocumentLinkDef.is(def) && def.customtypes[0]) || "mock"; | ||
return { | ||
id: link.id, | ||
...(def.allowText && link.text && { text: link.text }), | ||
link_type: "Document", | ||
type, | ||
tags: [], | ||
lang: "en-us", | ||
slug: null, | ||
first_publication_date: "1970-01-01T00:00:01+0000", | ||
last_publication_date: "1970-01-01T01:00:00+0000", | ||
}; | ||
} | ||
return brokenLinkV2(link, def); | ||
const type = (models_1.DocumentLinkDef.is(def) && def.customtypes[0]) || "mock"; | ||
return { | ||
id: link.id, | ||
link_type: "Document", | ||
type, | ||
tags: [], | ||
lang: "en-us", | ||
slug: null, | ||
first_publication_date: "1970-01-01T00:00:01+0000", | ||
last_publication_date: "1970-01-01T01:00:00+0000", | ||
}; | ||
}, | ||
}); | ||
exports.default = DocumentLinkRenderer; |
@@ -5,38 +5,17 @@ "use strict"; | ||
renderV1(link) { | ||
let render = { | ||
...(link.text && { text: link.text }), | ||
}; | ||
if ("url" in link) { | ||
const target = typeof link.target === "string" ? { target: link.target } : {}; | ||
render = { | ||
...render, | ||
...(link.url && { url: link.url }), | ||
...(link.text && { text: link.text }), | ||
...target, | ||
}; | ||
} | ||
const target = typeof link.target === "string" ? { target: link.target } : {}; | ||
return { | ||
type: "Link.web", | ||
value: { | ||
...render, | ||
url: link.url, | ||
...target, | ||
}, | ||
}; | ||
}, | ||
renderV2(def, link) { | ||
let render = { | ||
...(def.allowText && link.text && { text: link.text }), | ||
}; | ||
if ("url" in link) { | ||
const target = typeof link.target === "string" ? { target: link.target } : {}; | ||
render = { | ||
...render, | ||
...(link.url && { url: link.url }), | ||
...(def.allowText && link.text && { text: link.text }), | ||
...target, | ||
}; | ||
} | ||
return { | ||
renderV2(_def, link) { | ||
const partialRender = { | ||
link_type: "Web", | ||
...render, | ||
url: link.url, | ||
}; | ||
return Object.assign(partialRender, typeof link.target === "string" ? { target: link.target } : {}); | ||
}, | ||
@@ -43,0 +22,0 @@ renderMocks(def, link) { |
@@ -5,42 +5,34 @@ "use strict"; | ||
renderV1(link) { | ||
let render = { | ||
kind: link.kind, | ||
...(link.text && { text: link.text }), | ||
}; | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
name: link.name, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
}; | ||
} | ||
return { | ||
type: "Link.file", | ||
value: { | ||
file: render, | ||
file: { | ||
name: link.name, | ||
kind: link.kind, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
}, | ||
}, | ||
}; | ||
}, | ||
renderV2(def, link) { | ||
let render = { | ||
renderV2(_def, link) { | ||
return { | ||
link_type: "Media", | ||
id: link.id, | ||
name: link.name, | ||
kind: link.kind, | ||
...(def.allowText && link.text && { text: link.text }), | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
}; | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
}; | ||
} | ||
return render; | ||
}, | ||
renderMocks(def, link) { | ||
return this.renderV2(def, link); | ||
renderMocks(_def, _link) { | ||
return { | ||
link_type: "Media", | ||
name: "mock", | ||
kind: "image", | ||
url: "https://source.unsplash.com/random", | ||
size: "10kB", | ||
}; | ||
}, | ||
}); | ||
exports.default = FileLinkRenderer; |
@@ -5,47 +5,40 @@ "use strict"; | ||
renderV1(link) { | ||
let render = { | ||
kind: link.kind, | ||
...(link.text && { text: link.text }), | ||
}; | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
}; | ||
} | ||
return { | ||
type: "Link.image", | ||
value: { | ||
image: render, | ||
image: { | ||
name: link.name, | ||
kind: link.kind, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
}, | ||
}, | ||
}; | ||
}, | ||
renderV2(def, link) { | ||
let render = { | ||
renderV2(_def, link) { | ||
return { | ||
id: link.id, | ||
link_type: "Media", | ||
name: link.name, | ||
kind: link.kind, | ||
...(def.allowText && link.text && { text: link.text }), | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
}; | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
}; | ||
} | ||
return render; | ||
}, | ||
renderMocks(def, link) { | ||
return this.renderV2(def, link); | ||
renderMocks(_def, _link) { | ||
return { | ||
link_type: "Media", | ||
name: "mock", | ||
kind: "image", | ||
url: "https://source.unsplash.com/random", | ||
size: "10kB", | ||
height: "1920px", | ||
width: "1080px", | ||
}; | ||
}, | ||
}); | ||
exports.default = ImageLinkRenderer; |
@@ -6,3 +6,2 @@ "use strict"; | ||
const models_1 = require("../../../models"); | ||
const AnyLinkRenderer_1 = tslib_1.__importDefault(require("./AnyLinkRenderer")); | ||
const DocumentLinkRenderer_1 = tslib_1.__importDefault(require("./DocumentLinkRenderer")); | ||
@@ -16,3 +15,2 @@ exports.DocumentLinkRenderer = DocumentLinkRenderer_1.default; | ||
exports.ImageLinkRenderer = ImageLinkRenderer_1.default; | ||
const MediaLinkRenderer_1 = tslib_1.__importDefault(require("./MediaLinkRenderer")); | ||
const LinkRenderer = (ctx) => ({ | ||
@@ -32,8 +30,2 @@ renderV1(link, fetch) { | ||
} | ||
else if (link.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer_1.default.renderV1(link.value); | ||
} | ||
else if (link.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer_1.default.renderV1(link.value); | ||
} | ||
else { | ||
@@ -44,3 +36,3 @@ throw new Error(`No rendered found for link ${JSON.stringify(link)}`); // normally unreachable | ||
renderV2(def, content, fetch) { | ||
if (((0, models_1.isMediaLinkDef)(def) || (0, models_1.isAnyLinkDef)(def)) && content.value.__TYPE__ === "ImageLink") { | ||
if (content.value.__TYPE__ === "ImageLink" && ((0, models_1.isMediaLinkDef)(def) || (0, models_1.isAnyLinkDef)(def))) { | ||
return (0, ImageLinkRenderer_1.default)(ctx).renderV2(def.config, content.value); | ||
@@ -57,20 +49,12 @@ } | ||
} | ||
else if (((0, models_1.isMediaLinkDef)(def) || (0, models_1.isAnyLinkDef)(def)) && content.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer_1.default.renderV2(def.config, content.value); | ||
} | ||
else if ((0, models_1.isAnyLinkDef)(def) && content.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer_1.default.renderV2(def.config, content.value); | ||
} | ||
else { | ||
return this.renderDefault(def, content); | ||
return this.renderDefault(def); | ||
} | ||
}, | ||
renderDefault(def, content) { | ||
var _a, _b; | ||
const linkText = ((_a = def === null || def === void 0 ? void 0 : def.config) === null || _a === void 0 ? void 0 : _a.allowText) && (content === null || content === void 0 ? void 0 : content.value.text) ? { text: content.value.text } : undefined; | ||
switch ((_b = def.config) === null || _b === void 0 ? void 0 : _b.select) { | ||
renderDefault(def) { | ||
var _a; | ||
switch ((_a = def.config) === null || _a === void 0 ? void 0 : _a.select) { | ||
case "media": | ||
return { | ||
link_type: "Media", | ||
...linkText, | ||
}; | ||
@@ -80,3 +64,2 @@ case "document": | ||
link_type: "Document", | ||
...linkText, | ||
}; | ||
@@ -86,3 +69,2 @@ case "web": | ||
link_type: "Web", | ||
...linkText, | ||
}; | ||
@@ -92,3 +74,2 @@ default: | ||
link_type: "Any", | ||
...linkText, | ||
}; | ||
@@ -110,10 +91,4 @@ } | ||
} | ||
else if (((0, models_1.isMediaLinkDef)(def) || (0, models_1.isAnyLinkDef)(def)) && content.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer_1.default.renderMocks(def.config, content.value); | ||
} | ||
else if ((0, models_1.isAnyLinkDef)(def) && content.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer_1.default.renderMocks(def.config, content.value); | ||
} | ||
else { | ||
return this.renderDefault(def, content); | ||
return this.renderDefault(def); | ||
} | ||
@@ -120,0 +95,0 @@ }, |
@@ -131,3 +131,2 @@ import type { RenderContext } from "../models"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -277,5 +276,3 @@ }) | ({ | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -287,39 +284,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -332,10 +314,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -371,5 +345,3 @@ } | { | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -381,39 +353,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -426,10 +383,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}) | null | undefined; | ||
@@ -472,5 +421,3 @@ }; | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -482,39 +429,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -527,10 +459,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -685,3 +609,2 @@ start: number; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -831,5 +754,3 @@ }) | ({ | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -841,39 +762,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -886,10 +792,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -925,5 +823,3 @@ } | { | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -935,39 +831,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -980,10 +861,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}) | null | undefined; | ||
@@ -1026,5 +899,3 @@ }; | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -1036,39 +907,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -1081,10 +937,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -1091,0 +939,0 @@ start: number; |
@@ -142,3 +142,2 @@ import { GroupContent } from "@prismicio/types-internal/lib/content"; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -310,3 +309,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -474,3 +472,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -620,5 +617,3 @@ }) | ({ | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -630,39 +625,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -675,10 +655,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -714,5 +686,3 @@ } | { | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -724,39 +694,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -769,10 +724,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}) | null | undefined; | ||
@@ -815,5 +762,3 @@ }; | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -825,39 +770,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -870,10 +800,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -1038,3 +960,2 @@ start: number; | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -1206,3 +1127,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -1370,3 +1290,2 @@ }) | ({ | ||
allowTargetBlank?: boolean | undefined; | ||
allowText?: boolean | undefined; | ||
} | undefined; | ||
@@ -1516,5 +1435,3 @@ }) | ({ | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -1526,39 +1443,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -1571,10 +1473,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -1610,5 +1504,3 @@ } | { | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -1620,39 +1512,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -1665,10 +1542,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}) | null | undefined; | ||
@@ -1711,5 +1580,3 @@ }; | ||
__TYPE__: "ImageLink"; | ||
} & ({ | ||
kind: "image"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
@@ -1721,39 +1588,24 @@ url: string; | ||
name: string; | ||
kind: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "FileLink"; | ||
} & ({ | ||
kind: "file"; | ||
} & (({ | ||
}) | ({ | ||
id: string; | ||
url: string; | ||
name: string; | ||
kind: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
text: string; | ||
}))) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
__TYPE__: "FileLink"; | ||
} & { | ||
size?: string | undefined; | ||
}) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
} & { | ||
id: string; | ||
}) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & { | ||
kind?: "document" | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
@@ -1766,10 +1618,2 @@ } & { | ||
} | null | undefined; | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
@@ -1776,0 +1620,0 @@ start: number; |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "3.2.4-alpha.8", | ||
"version": "3.3.0", | ||
"description": "Prismic renderers for the content API", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@prismicio/types-internal": "2.7.0-alpha.5", | ||
"@prismicio/types-internal": "2.6.0", | ||
"tslib": "^2.5.0", | ||
@@ -41,0 +41,0 @@ "uuid": "^9.0.0" |
@@ -1,2 +0,1 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
import { either } from "fp-ts" | ||
@@ -6,14 +5,9 @@ import { pipe } from "fp-ts/lib/function" | ||
const codec = t.intersection([ | ||
t.partial({ | ||
select: t.union([t.literal("any"), t.null, t.undefined]), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]) | ||
const codec = t.partial({ | ||
select: t.union([t.literal("any"), t.null, t.undefined]), | ||
}) | ||
export type AnyLinkDef = { | ||
select: null | ||
} & Pick<t.TypeOf<typeof codec>, "allowText"> | ||
} | ||
export const AnyLinkDef = new t.Type<AnyLinkDef>( | ||
@@ -35,8 +29,6 @@ "AnyLinkDef", | ||
export function defaultAnyLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): AnyLinkDef { | ||
export function defaultAnyLinkDef(): AnyLinkDef { | ||
return { | ||
select: null, | ||
allowText: true, | ||
...config, | ||
} | ||
} |
@@ -1,23 +0,15 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
import * as t from "io-ts" | ||
export const DocumentLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("document"), | ||
customtypes: t.readonlyArray(t.string), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]) | ||
export const DocumentLinkDef = t.strict({ | ||
select: t.literal("document"), | ||
customtypes: t.readonlyArray(t.string), | ||
}) | ||
export type DocumentLinkDef = t.TypeOf<typeof DocumentLinkDef> | ||
export function defaultDocumentLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): DocumentLinkDef { | ||
export function defaultDocumentLinkDef(): DocumentLinkDef { | ||
return { | ||
select: "document", | ||
customtypes: [], | ||
allowText: true, | ||
...config, | ||
} | ||
} |
@@ -40,13 +40,13 @@ import { Link } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
export function defaultLink(type: LinkConfig["select"], config?: Omit<LinkConfig, "select" | "customtypes">): Link { | ||
const resolvedConfig: LinkConfig = (() => { | ||
export function defaultLink(type: LinkConfig["select"]): Link { | ||
const config: LinkConfig = (() => { | ||
switch (type) { | ||
case "document": | ||
return defaultDocumentLinkDef(config) | ||
return defaultDocumentLinkDef() | ||
case "media": | ||
return defaultMediaLinkDef(config) | ||
return defaultMediaLinkDef() | ||
case "web": | ||
return defaultWebLinkDef(config) | ||
return defaultWebLinkDef() | ||
case null: | ||
return defaultAnyLinkDef(config) | ||
return defaultAnyLinkDef() | ||
} | ||
@@ -57,3 +57,3 @@ })() | ||
type: "Link", | ||
config: resolvedConfig, | ||
config, | ||
} | ||
@@ -60,0 +60,0 @@ } |
@@ -1,21 +0,13 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
import * as t from "io-ts" | ||
export const MediaLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("media"), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]) | ||
export const MediaLinkDef = t.strict({ | ||
select: t.literal("media"), | ||
}) | ||
export type MediaLinkDef = t.TypeOf<typeof MediaLinkDef> | ||
export function defaultMediaLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): MediaLinkDef { | ||
export function defaultMediaLinkDef(): MediaLinkDef { | ||
return { | ||
select: "media", | ||
allowText: true, | ||
...config, | ||
} | ||
} |
@@ -1,21 +0,12 @@ | ||
import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
import * as t from "io-ts" | ||
export const WebLinkDef = t.intersection([ | ||
t.strict({ | ||
select: t.literal("web"), | ||
}), | ||
t.partial({ | ||
allowText: t.boolean, | ||
}), | ||
]) | ||
export const WebLinkDef = t.strict({ | ||
select: t.literal("web"), | ||
}) | ||
export type WebLinkDef = t.TypeOf<typeof WebLinkDef> | ||
export function defaultWebLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): WebLinkDef { | ||
export function defaultWebLinkDef(): WebLinkDef { | ||
return { | ||
select: "web", | ||
allowText: true, | ||
...config, | ||
} | ||
} |
@@ -0,3 +1,41 @@ | ||
const DOC_SEPARATOR = "%%" | ||
export function encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string { | ||
return `${documentId}${DOC_SEPARATOR}${maybeAdditionalData ?? ""}` | ||
} | ||
export function decodeDocId(id: string, handlerType: string): [string, string?] { | ||
const [docId, maybeAdditionalData] = id.split(DOC_SEPARATOR) | ||
if (docId && maybeAdditionalData) { | ||
return [docId, maybeAdditionalData] | ||
} else if (docId) { | ||
return [docId] | ||
} else { | ||
throw new Error(`Unable to read from for extension ${handlerType} with encoded api key ${id}`) | ||
} | ||
} | ||
export interface IDEncoder { | ||
encode: (strId: string) => string | ||
} | ||
export function IDEncoder(prefix: string): IDEncoder { | ||
const BYTES_SIZE_LENGTH = 3 | ||
return { | ||
encode: (strId: string): string => { | ||
const idLength = strId.length | ||
if (Buffer.byteLength(idLength.toString(), "utf8") <= BYTES_SIZE_LENGTH) { | ||
const length = `${idLength}`.padStart(BYTES_SIZE_LENGTH, "0") // util.format(`%0${BYTES_SIZE_LENGTH}d`, idLength) | ||
return prefix + length + strId | ||
} else { | ||
throw new Error(`ID is too long. Its size is ${idLength} and should be inferior to 1000`) | ||
} | ||
}, | ||
} | ||
} | ||
export const IDEncoders = { | ||
documentLinks: IDEncoder("=&="), | ||
documentUrls: IDEncoder(">&<"), | ||
integrationFields: IDEncoder("%!%"), | ||
} |
@@ -1,1 +0,1 @@ | ||
export { type IDEncoder } from "./Encoder" | ||
export { type IDEncoder, encodeDocId, IDEncoders } from "./Encoder" |
@@ -9,7 +9,3 @@ import type { ApiDocument } from "./ApiDocument" | ||
DocEncoder: { | ||
encodeDocId( | ||
documentId: string, | ||
fetchUuidOrRelationName: string | undefined, | ||
additionalData: (string | undefined)[], | ||
): string | ||
encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string | ||
} | ||
@@ -16,0 +12,0 @@ encoders: { |
import type { | ||
AnyLinkContent, | ||
DocumentLinkContent, | ||
@@ -7,3 +6,2 @@ ExternalLinkContent, | ||
ImageLinkContent, | ||
MediaLinkContent, | ||
SliceContent, | ||
@@ -20,3 +18,3 @@ WidgetContent, | ||
renderV2(definition: D, content: C, fetch?: F | undefined): unknown | ||
renderDefault(definition: D, content?: C): unknown | ||
renderDefault(definition: D): unknown | ||
renderMocks(definition: D, content: C): unknown | ||
@@ -26,10 +24,4 @@ } | ||
export interface LinkRenderer< | ||
D extends MediaLinkDef | DocumentLinkDef | WebLinkDef | MediaLinkDef | AnyLinkDef, | ||
C extends | ||
| DocumentLinkContent | ||
| FileLinkContent | ||
| ExternalLinkContent | ||
| ImageLinkContent | ||
| MediaLinkContent | ||
| AnyLinkContent, | ||
D extends MediaLinkDef | DocumentLinkDef | WebLinkDef, | ||
C extends DocumentLinkContent | FileLinkContent | ExternalLinkContent | ImageLinkContent, | ||
F extends Field | undefined = undefined, | ||
@@ -36,0 +28,0 @@ > { |
@@ -43,10 +43,12 @@ import type { ImageContent, ImageContentView } from "@prismicio/types-internal/lib/content" | ||
}, {}) | ||
return { | ||
type: "Image", | ||
value: { main: renderImageContentView(content, ctx, ApiVersion.v1), views: views }, | ||
value: { main: renderImageContentView(content, ctx, ApiVersion.v1), views }, | ||
} | ||
} | ||
return { | ||
type: "Image", | ||
value: { main: renderImageContentView(content, ctx, ApiVersion.v1), views: [] }, | ||
value: { main: renderImageContentView(content, ctx, ApiVersion.v1), views: {} }, | ||
} | ||
@@ -57,3 +59,3 @@ }, | ||
const main = renderImageContentView(content, ctx, ApiVersion.v2) | ||
if (content.thumbnails && content.thumbnails) { | ||
if (content.thumbnails) { | ||
const views = Object.entries(content.thumbnails).reduce((acc, [k, v]) => { | ||
@@ -60,0 +62,0 @@ return Object.assign(acc, { [k]: renderImageContentView(v, ctx, ApiVersion.v2) }) |
@@ -9,17 +9,15 @@ import type { DocumentLinkContent } from "@prismicio/types-internal/lib/content" | ||
function brokenLinkV1(link: DocumentLinkContent): Record<string, unknown> { | ||
function brokenLinkV2(id: string): unknown { | ||
return { | ||
...("id" in link && { id: link.id, tags: [] }), | ||
id: id, | ||
type: BROKEN_CUSTOM_TYPE, | ||
tags: [], | ||
isBroken: true, | ||
...(link.text && { text: link.text }), | ||
} | ||
} | ||
function brokenLinkV2(link: DocumentLinkContent, def: DocumentLinkDef | AnyLinkDef): Record<string, unknown> { | ||
function brokenLinkV1(id: string): unknown { | ||
return { | ||
...("id" in link && { id: link.id, tags: [] }), | ||
type: BROKEN_CUSTOM_TYPE, | ||
isBroken: true, | ||
...((def?.allowText || !def) && link.text && { text: link.text }), | ||
value: brokenLinkV2(id), | ||
} | ||
@@ -34,37 +32,19 @@ } | ||
try { | ||
if ("id" in link) { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid, [link.text]) | ||
return { | ||
type: "Link.document", | ||
value: ctx.Extension.encoders.documentLinks.encode(id), | ||
} | ||
} | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid) | ||
return { | ||
type: "Link.document", | ||
...brokenLinkV1(link), | ||
value: ctx.Extension.encoders.documentLinks.encode(id), | ||
} | ||
} catch (e) { | ||
return brokenLinkV1(link) | ||
return brokenLinkV1(link.id) | ||
} | ||
}, | ||
renderV2(def: DocumentLinkDef | AnyLinkDef, link: DocumentLinkContent, fetch: DocRelation | undefined): unknown { | ||
renderV2(_def: DocumentLinkDef | AnyLinkDef, link: DocumentLinkContent, fetch: DocRelation | undefined): unknown { | ||
//todo check fetch type | ||
try { | ||
const linkText = def.allowText ? link.text : undefined | ||
if ("id" in link) { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid, [linkText]) | ||
return ctx.Extension.encoders.documentLinks.encode(id) | ||
} | ||
return { | ||
link_type: "Document", | ||
...brokenLinkV2(link, def), | ||
} | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid) | ||
return ctx.Extension.encoders.documentLinks.encode(id) | ||
} catch (e) { | ||
return brokenLinkV2(link, def) | ||
return brokenLinkV2(link.id) | ||
} | ||
@@ -74,19 +54,13 @@ }, | ||
renderMocks(def: DocumentLinkDef | AnyLinkDef, link: DocumentLinkContent): unknown { | ||
if ("id" in link) { | ||
const type = (DocumentLinkDef.is(def) && def.customtypes[0]) || "mock" | ||
return { | ||
id: link.id, | ||
...(def.allowText && link.text && { text: link.text }), | ||
link_type: "Document", | ||
type, | ||
tags: [], | ||
lang: "en-us", | ||
slug: null, | ||
first_publication_date: "1970-01-01T00:00:01+0000", | ||
last_publication_date: "1970-01-01T01:00:00+0000", | ||
} | ||
const type = (DocumentLinkDef.is(def) && def.customtypes[0]) || "mock" | ||
return { | ||
id: link.id, | ||
link_type: "Document", | ||
type, | ||
tags: [], | ||
lang: "en-us", | ||
slug: null, | ||
first_publication_date: "1970-01-01T00:00:01+0000", | ||
last_publication_date: "1970-01-01T01:00:00+0000", | ||
} | ||
return brokenLinkV2(link, def) | ||
}, | ||
@@ -93,0 +67,0 @@ }) |
@@ -7,21 +7,8 @@ import type { ExternalLinkContent } from "@prismicio/types-internal/lib/content" | ||
renderV1(link: ExternalLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
...(link.text && { text: link.text }), | ||
} | ||
if ("url" in link) { | ||
const target = typeof link.target === "string" ? { target: link.target } : {} | ||
render = { | ||
...render, | ||
...(link.url && { url: link.url }), | ||
...(link.text && { text: link.text }), | ||
...target, | ||
} | ||
} | ||
const target = typeof link.target === "string" ? { target: link.target } : {} | ||
return { | ||
type: "Link.web", | ||
value: { | ||
...render, | ||
url: link.url, | ||
...target, | ||
}, | ||
@@ -31,22 +18,9 @@ } | ||
renderV2(def: WebLinkDef | AnyLinkDef, link: ExternalLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
...(def.allowText && link.text && { text: link.text }), | ||
renderV2(_def: WebLinkDef | AnyLinkDef, link: ExternalLinkContent): unknown { | ||
const partialRender = { | ||
link_type: "Web", | ||
url: link.url, | ||
} | ||
if ("url" in link) { | ||
const target = typeof link.target === "string" ? { target: link.target } : {} | ||
render = { | ||
...render, | ||
...(link.url && { url: link.url }), | ||
...(def.allowText && link.text && { text: link.text }), | ||
...target, | ||
} | ||
} | ||
return { | ||
link_type: "Web", | ||
...render, | ||
} | ||
return Object.assign(partialRender, typeof link.target === "string" ? { target: link.target } : {}) | ||
}, | ||
@@ -53,0 +27,0 @@ |
@@ -8,20 +8,11 @@ import type { FileLinkContent } from "@prismicio/types-internal/lib/content" | ||
renderV1(link: FileLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
kind: link.kind, | ||
...(link.text && { text: link.text }), | ||
} | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
name: link.name, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
} | ||
} | ||
return { | ||
type: "Link.file", | ||
value: { | ||
file: render, | ||
file: { | ||
name: link.name, | ||
kind: link.kind, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
}, | ||
}, | ||
@@ -31,27 +22,24 @@ } | ||
renderV2(def: MediaLinkDef | AnyLinkDef, link: FileLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
renderV2(_def: MediaLinkDef | AnyLinkDef, link: FileLinkContent): unknown { | ||
return { | ||
link_type: "Media", | ||
id: link.id, | ||
name: link.name, | ||
kind: link.kind, | ||
...(def.allowText && link.text && { text: link.text }), | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
} | ||
}, | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.rewriteFileUrl(link.url), | ||
size: link.size, | ||
} | ||
renderMocks(_def: MediaLinkDef | AnyLinkDef, _link: FileLinkContent): unknown { | ||
return { | ||
link_type: "Media", | ||
name: "mock", | ||
kind: "image", | ||
url: "https://source.unsplash.com/random", | ||
size: "10kB", | ||
} | ||
return render | ||
}, | ||
renderMocks(def: MediaLinkDef | AnyLinkDef, link: FileLinkContent): unknown { | ||
return this.renderV2(def, link) | ||
}, | ||
}) | ||
export default FileLinkRenderer |
@@ -8,23 +8,13 @@ import type { ImageLinkContent } from "@prismicio/types-internal/lib/content" | ||
renderV1(link: ImageLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
kind: link.kind, | ||
...(link.text && { text: link.text }), | ||
} | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
} | ||
} | ||
return { | ||
type: "Link.image", | ||
value: { | ||
image: render, | ||
image: { | ||
name: link.name, | ||
kind: link.kind, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
}, | ||
}, | ||
@@ -34,29 +24,28 @@ } | ||
renderV2(def: MediaLinkDef | AnyLinkDef, link: ImageLinkContent): unknown { | ||
let render: Record<string, unknown> = { | ||
renderV2(_def: MediaLinkDef | AnyLinkDef, link: ImageLinkContent): unknown { | ||
return { | ||
id: link.id, | ||
link_type: "Media", | ||
name: link.name, | ||
kind: link.kind, | ||
...(def.allowText && link.text && { text: link.text }), | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
} | ||
}, | ||
if ("url" in link) { | ||
render = { | ||
...render, | ||
id: link.id, | ||
name: link.name, | ||
url: ctx.urlRewriter.optimizeImageUrl(link.url), | ||
size: link.size, | ||
height: link.height, | ||
width: link.width, | ||
} | ||
renderMocks(_def: MediaLinkDef | AnyLinkDef, _link: ImageLinkContent): unknown { | ||
return { | ||
link_type: "Media", | ||
name: "mock", | ||
kind: "image", | ||
url: "https://source.unsplash.com/random", | ||
size: "10kB", | ||
height: "1920px", | ||
width: "1080px", | ||
} | ||
return render | ||
}, | ||
renderMocks(def: MediaLinkDef | AnyLinkDef, link: ImageLinkContent): unknown { | ||
return this.renderV2(def, link) | ||
}, | ||
}) | ||
export default ImageLinkRenderer |
@@ -7,3 +7,2 @@ import type { LinkContent } from "@prismicio/types-internal/lib/content" | ||
import type { DocRelation } from "../../../models/fetch" | ||
import AnyLinkRenderer from "./AnyLinkRenderer" | ||
import DocumentLinkRenderer from "./DocumentLinkRenderer" | ||
@@ -13,3 +12,2 @@ import ExternalLinkRenderer from "./ExternalLinkRenderer" | ||
import ImageLinkRenderer from "./ImageLinkRenderer" | ||
import MediaLinkRenderer from "./MediaLinkRenderer" | ||
@@ -26,6 +24,2 @@ const LinkRenderer: (ctx: RenderContext) => Renderer<Link, LinkContent, DocRelation> = (ctx) => ({ | ||
return ExternalLinkRenderer.renderV1(link.value) | ||
} else if (link.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer.renderV1(link.value) | ||
} else if (link.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer.renderV1(link.value) | ||
} else { | ||
@@ -37,3 +31,3 @@ throw new Error(`No rendered found for link ${JSON.stringify(link)}`) // normally unreachable | ||
renderV2(def: Link, content: LinkContent, fetch: DocRelation | undefined): unknown { | ||
if ((isMediaLinkDef(def) || isAnyLinkDef(def)) && content.value.__TYPE__ === "ImageLink") { | ||
if (content.value.__TYPE__ === "ImageLink" && (isMediaLinkDef(def) || isAnyLinkDef(def))) { | ||
return ImageLinkRenderer(ctx).renderV2(def.config as MediaLinkDef | AnyLinkDef, content.value) | ||
@@ -46,14 +40,8 @@ } else if ((isDocumentLinkDef(def) || isAnyLinkDef(def)) && content.value.__TYPE__ === "DocumentLink") { | ||
return ExternalLinkRenderer.renderV2(def.config as WebLinkDef | AnyLinkDef, content.value) | ||
} else if ((isMediaLinkDef(def) || isAnyLinkDef(def)) && content.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer.renderV2(def.config as MediaLinkDef, content.value) | ||
} else if (isAnyLinkDef(def) && content.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer.renderV2(def.config as AnyLinkDef, content.value) | ||
} else { | ||
return this.renderDefault(def, content) | ||
return this.renderDefault(def) | ||
} | ||
}, | ||
renderDefault(def: Link, content?: LinkContent): unknown { | ||
const linkText = def?.config?.allowText && content?.value.text ? { text: content.value.text } : undefined | ||
renderDefault(def: Link): unknown { | ||
switch (def.config?.select) { | ||
@@ -63,3 +51,2 @@ case "media": | ||
link_type: "Media", | ||
...linkText, | ||
} | ||
@@ -69,3 +56,2 @@ case "document": | ||
link_type: "Document", | ||
...linkText, | ||
} | ||
@@ -75,3 +61,2 @@ case "web": | ||
link_type: "Web", | ||
...linkText, | ||
} | ||
@@ -81,3 +66,2 @@ default: | ||
link_type: "Any", | ||
...linkText, | ||
} | ||
@@ -96,8 +80,4 @@ } | ||
return ExternalLinkRenderer.renderMocks(def.config as WebLinkDef | AnyLinkDef, content.value) | ||
} else if ((isMediaLinkDef(def) || isAnyLinkDef(def)) && content.value.__TYPE__ === "MediaLink") { | ||
return MediaLinkRenderer.renderMocks(def.config as MediaLinkDef, content.value) | ||
} else if (isAnyLinkDef(def) && content.value.__TYPE__ === "AnyLink") { | ||
return AnyLinkRenderer.renderMocks(def.config as AnyLinkDef, content.value) | ||
} else { | ||
return this.renderDefault(def, content) | ||
return this.renderDefault(def) | ||
} | ||
@@ -104,0 +84,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1273500
298
32473
1
+ Added@prismicio/types-internal@2.6.0(transitive)
- Removed@prismicio/types-internal@2.7.0-alpha.5(transitive)