@prismicio/api-renderer
Advanced tools
Comparing version 5.0.0-alpha.1 to 5.0.0-alpha.2
@@ -5,4 +5,2 @@ "use strict"; | ||
const content_1 = require("@prismicio/types-internal/lib/content"); | ||
// TODO: Import from`@prismicio/types-internal/lib/content` when the types are available. | ||
const RepeatableContent_1 = require("@prismicio/types-internal/lib/content/fields/RepeatableContent"); | ||
const customtypes_1 = require("@prismicio/types-internal/lib/customtypes"); | ||
@@ -15,3 +13,3 @@ const models_1 = require("./models"); | ||
function isStaticWidgetContent(content) { | ||
return (0, content_1.isGroupContent)(content) || (0, RepeatableContent_1.isRepeatableContent)(content) || (0, content_1.isNestableContent)(content); | ||
return (0, content_1.isGroupContent)(content) || (0, content_1.isNestableContent)(content); | ||
} | ||
@@ -18,0 +16,0 @@ function i18nWriter(doc) { |
@@ -142,3 +142,2 @@ import * as t from "io-ts"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -314,3 +313,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -487,3 +485,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -656,3 +653,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -831,3 +827,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1000,3 +995,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1003,0 +997,0 @@ }) | ({ |
@@ -6,9 +6,8 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>; | ||
export type AnyLinkDef = Omit<t.TypeOf<typeof codec>, "select"> & { | ||
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 {}; |
@@ -11,3 +11,2 @@ "use strict"; | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}); | ||
@@ -17,4 +16,4 @@ exports.AnyLinkDef = new t.Type("AnyLinkDef", (u) => u.select === "any", (u) => { | ||
return { | ||
...decoded, | ||
select: null, | ||
allowText: decoded.allowText, | ||
}; | ||
@@ -21,0 +20,0 @@ })); |
@@ -8,5 +8,4 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>; | ||
export type DocumentLinkDef = t.TypeOf<typeof DocumentLinkDef>; | ||
export declare function defaultDocumentLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): DocumentLinkDef; |
@@ -13,3 +13,2 @@ "use strict"; | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -16,0 +15,0 @@ ]); |
@@ -9,3 +9,2 @@ import { Link } from "@prismicio/types-internal/lib/customtypes/widgets/nestable"; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
@@ -16,3 +15,2 @@ select: t.LiteralC<"document">; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{ | ||
@@ -22,3 +20,2 @@ select: t.LiteralC<"web">; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>, t.Type<AnyLinkDef, AnyLinkDef, unknown>]>; | ||
@@ -40,3 +37,2 @@ type LinkConfig = t.TypeOf<typeof LinkConfig>; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -57,3 +53,2 @@ }>, WithKey<{ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -60,0 +55,0 @@ }>, unknown>; |
@@ -7,5 +7,4 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>; | ||
export type MediaLinkDef = t.TypeOf<typeof MediaLinkDef>; | ||
export declare function defaultMediaLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): MediaLinkDef; |
@@ -12,3 +12,2 @@ "use strict"; | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -15,0 +14,0 @@ ]); |
@@ -7,5 +7,4 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"; | ||
allowText: t.BooleanC; | ||
repeat: t.BooleanC; | ||
}>]>; | ||
export type WebLinkDef = t.TypeOf<typeof WebLinkDef>; | ||
export declare function defaultWebLinkDef(config?: Omit<LinkConfig, "select" | "customtypes">): WebLinkDef; |
@@ -12,3 +12,2 @@ "use strict"; | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -15,0 +14,0 @@ ]); |
@@ -300,3 +300,2 @@ import * as t from "io-ts"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -317,4 +316,3 @@ }>, import("../..").WithKey<{ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
}>, unknown>]>; |
@@ -140,3 +140,2 @@ import * as t from "io-ts"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -302,3 +301,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -474,3 +472,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -636,3 +633,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -639,0 +635,0 @@ }) | ({ |
@@ -132,3 +132,2 @@ import * as t from "io-ts"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -301,3 +300,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -463,3 +461,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -632,3 +629,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -635,0 +631,0 @@ }) | ({ |
@@ -132,3 +132,2 @@ import type { RenderContext } from "../models"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -279,3 +278,3 @@ }) | ({ | ||
} & (({ | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -297,3 +296,3 @@ url: string; | ||
} & (({ | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -374,3 +373,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -387,3 +386,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -447,3 +446,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -460,3 +459,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -503,74 +502,2 @@ url: string; | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Link"; | ||
value: { | ||
__TYPE__: "LinkContent"; | ||
value: ({ | ||
__TYPE__: "ImageLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
height: string; | ||
width: string; | ||
size: string; | ||
name: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "image"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "FileLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
name: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "file"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
id: string; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
} & { | ||
kind?: "web" | undefined; | ||
target?: string | null | undefined; | ||
preview?: { | ||
title?: string | undefined; | ||
} | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
}) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
}[]; | ||
}, Field>, ({ | ||
@@ -705,3 +632,2 @@ type: "Color"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -852,3 +778,3 @@ }) | ({ | ||
} & (({ | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -870,3 +796,3 @@ url: string; | ||
} & (({ | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -947,3 +873,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -960,3 +886,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -1020,3 +946,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -1033,3 +959,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -1076,75 +1002,3 @@ url: string; | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Link"; | ||
value: { | ||
__TYPE__: "LinkContent"; | ||
value: ({ | ||
__TYPE__: "ImageLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
height: string; | ||
width: string; | ||
size: string; | ||
name: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "image"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "FileLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
name: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "file"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
id: string; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
} & { | ||
kind?: "web" | undefined; | ||
target?: string | null | undefined; | ||
preview?: { | ||
title?: string | undefined; | ||
} | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
}) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
}[]; | ||
}, Field>; | ||
export default SimpleWidgetRenderer; |
@@ -143,3 +143,2 @@ import { GroupContent } from "@prismicio/types-internal/lib/content"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -312,3 +311,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -477,3 +475,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -624,3 +621,3 @@ }) | ({ | ||
} & (({ | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -642,3 +639,3 @@ url: string; | ||
} & (({ | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -719,3 +716,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -732,3 +729,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -792,3 +789,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -805,3 +802,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -848,74 +845,2 @@ url: string; | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Link"; | ||
value: { | ||
__TYPE__: "LinkContent"; | ||
value: ({ | ||
__TYPE__: "ImageLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
height: string; | ||
width: string; | ||
size: string; | ||
name: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "image"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "FileLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
name: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "file"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
id: string; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
} & { | ||
kind?: "web" | undefined; | ||
target?: string | null | undefined; | ||
preview?: { | ||
title?: string | undefined; | ||
} | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
}) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
}[]; | ||
}, GroupOrField>, ({ | ||
@@ -1060,3 +985,2 @@ type: "Group"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1229,3 +1153,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1394,3 +1317,2 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1541,3 +1463,3 @@ }) | ({ | ||
} & (({ | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -1559,3 +1481,3 @@ url: string; | ||
} & (({ | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -1636,3 +1558,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -1649,3 +1571,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -1709,3 +1631,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "image"; | ||
id: string; | ||
@@ -1722,3 +1644,3 @@ url: string; | ||
} & { | ||
kind: string; | ||
kind: "file"; | ||
id: string; | ||
@@ -1765,75 +1687,3 @@ url: string; | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Link"; | ||
value: { | ||
__TYPE__: "LinkContent"; | ||
value: ({ | ||
__TYPE__: "ImageLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
height: string; | ||
width: string; | ||
size: string; | ||
name: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "image"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "FileLink"; | ||
} & (({ | ||
kind: string; | ||
id: string; | ||
url: string; | ||
name: string; | ||
size: string; | ||
} & { | ||
date?: string | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "file"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "DocumentLink"; | ||
} & (({ | ||
id: string; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "document"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "ExternalLink"; | ||
} & (({ | ||
url: string; | ||
} & { | ||
kind?: "web" | undefined; | ||
target?: string | null | undefined; | ||
preview?: { | ||
title?: string | undefined; | ||
} | null | undefined; | ||
} & { | ||
text?: string | undefined; | ||
}) | { | ||
kind: "web"; | ||
text: string; | ||
})) | ({ | ||
__TYPE__: "MediaLink"; | ||
} & { | ||
kind: "media"; | ||
text: string; | ||
}) | ({ | ||
__TYPE__: "AnyLink"; | ||
} & { | ||
text: string; | ||
}); | ||
}[]; | ||
}, GroupOrField>; | ||
export default StaticWidgetRenderer; |
@@ -5,7 +5,5 @@ "use strict"; | ||
const content_1 = require("@prismicio/types-internal/lib/content"); | ||
const RepeatableContent_1 = require("@prismicio/types-internal/lib/content/fields/RepeatableContent"); | ||
const fetch_1 = require("../models/fetch"); | ||
const object_1 = require("../object"); | ||
const GroupRenderer_1 = tslib_1.__importDefault(require("./GroupRenderer")); | ||
const RepeatableRenderer_1 = tslib_1.__importDefault(require("./RepeatableRenderer")); | ||
const SimpleWidgetRenderer_1 = tslib_1.__importDefault(require("./SimpleWidgetRenderer")); | ||
@@ -28,47 +26,2 @@ function extractFetchGroupIfAny(fetch) { | ||
} | ||
function extractSimpleFieldIfAny(field) { | ||
if (field !== undefined && (field.TYPE === "SimpleField" || field.TYPE === "DocRelation")) { | ||
return field; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
function renderContent(def, content, fetch, renderer) { | ||
var _a, _b, _c, _d; | ||
// When def is a Link, there is a special management with the fact it can be repeated or not. | ||
// The custom type is always the one deciding the return type of the content. | ||
// If repeat is true, it will always return an array, and if repeat is false, it will always return an object. | ||
if (def.type === "Link") { | ||
// When repeat is true and existing content is repeatable, render the content as is | ||
if (((_a = def.config) === null || _a === void 0 ? void 0 : _a.repeat) && (0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return renderer.repeatable(def, content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
// When repeat is true and existing content is not repeatable, render as repeatable | ||
if (((_b = def.config) === null || _b === void 0 ? void 0 : _b.repeat) && (0, content_1.isLinkContent)(content)) { | ||
return renderer.repeatable(def, { | ||
__TYPE__: "RepeatableContent", | ||
type: def.type, | ||
value: [content], | ||
}, extractSimpleFieldIfAny(fetch)); | ||
} | ||
// When repeat is false and existing content is repeatable with data, render the first item | ||
if (!((_c = def.config) === null || _c === void 0 ? void 0 : _c.repeat) && (0, RepeatableContent_1.isRepeatableContent)(content) && content.value[0]) { | ||
return renderer.simple(def, content.value[0], extractFetchFieldIfAny(fetch)); | ||
} | ||
// When repeat is false and existing content is repeatable but empty, render the default widget | ||
if (!((_d = def.config) === null || _d === void 0 ? void 0 : _d.repeat) && (0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return renderer.default(def); | ||
} | ||
// When repeat is false and existing content is not repeatable, render the content as is, | ||
// using the normal nestable content renderer condition bellow | ||
} | ||
if (def.type !== "Group" && (0, content_1.isNestableContent)(content)) { | ||
return renderer.simple(def, content, extractFetchFieldIfAny(fetch)); | ||
} | ||
if (def.type === "Group" && (0, content_1.isGroupContent)(content)) { | ||
return renderer.group(def, content, extractFetchGroupIfAny(fetch)); | ||
} | ||
return renderer.default(def); | ||
} | ||
const StaticWidgetRenderer = (ctx) => (0, object_1.withObjectRenderers)({ | ||
@@ -79,5 +32,2 @@ renderV1(content, fetch) { | ||
} | ||
else if ((0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return (0, RepeatableRenderer_1.default)(ctx).renderV1(content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
else { | ||
@@ -88,15 +38,15 @@ return (0, SimpleWidgetRenderer_1.default)(ctx).renderV1(content, extractFetchFieldIfAny(fetch)); | ||
renderV2(def, content, fetch) { | ||
return renderContent(def, content, fetch, { | ||
group: (def, content, fetch) => (0, GroupRenderer_1.default)(ctx).renderV2(def, content, fetch), | ||
repeatable: (def, content, fetch) => (0, RepeatableRenderer_1.default)(ctx).renderV2(def, content, fetch), | ||
simple: (def, content, fetch) => (0, SimpleWidgetRenderer_1.default)(ctx).renderV2(def, content, fetch), | ||
default: (def) => this.renderDefault(def), | ||
}); | ||
if (def.type !== "Group" && (0, content_1.isNestableContent)(content)) { | ||
// todo maybe find an other condition | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)); | ||
} | ||
else if (def.type === "Group" && (0, content_1.isGroupContent)(content)) { | ||
return (0, GroupRenderer_1.default)(ctx).renderV2(def, content, extractFetchGroupIfAny(fetch)); | ||
} | ||
else { | ||
return this.renderDefault(def); | ||
} | ||
}, | ||
renderDefault(def) { | ||
var _a; | ||
if (def.type === "Link" && ((_a = def.config) === null || _a === void 0 ? void 0 : _a.repeat)) { | ||
return (0, RepeatableRenderer_1.default)(ctx).renderDefault(def); | ||
} | ||
else if (def.type === "Group") { | ||
if (def.type === "Group") { | ||
return (0, GroupRenderer_1.default)(ctx).renderDefault(def); | ||
@@ -109,10 +59,13 @@ } | ||
renderMocks(def, content) { | ||
return renderContent(def, content, undefined, { | ||
group: (def, content) => (0, GroupRenderer_1.default)(ctx).renderMocks(def, content), | ||
repeatable: (def, content) => (0, RepeatableRenderer_1.default)(ctx).renderMocks(def, content), | ||
simple: (def, content) => (0, SimpleWidgetRenderer_1.default)(ctx).renderMocks(def, content), | ||
default: (def) => this.renderDefault(def), | ||
}); | ||
if ((0, content_1.isNestableContent)(content) && def.type !== "Group") { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderMocks(def, content); | ||
} | ||
else if ((0, content_1.isGroupContent)(content) && def.type === "Group") { | ||
return (0, GroupRenderer_1.default)(ctx).renderMocks(def, content); | ||
} | ||
else { | ||
return this.renderDefault(def); | ||
} | ||
}, | ||
}); | ||
exports.default = StaticWidgetRenderer; |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "5.0.0-alpha.1", | ||
"version": "5.0.0-alpha.2", | ||
"description": "Prismic renderers for the content API", | ||
@@ -26,6 +26,6 @@ "keywords": [ | ||
"prepare": "npm run build", | ||
"release": "npm run test && standard-version --release-as patch && git push --follow-tags && npm run build && npm publish", | ||
"release:dry": "standard-version --release-as patch --dry-run", | ||
"release:alpha": "npm run test && standard-version --release-as patch --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha", | ||
"release:alpha:dry": "standard-version --release-as patch --prerelease alpha --dry-run", | ||
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish", | ||
"release:dry": "standard-version --dry-run", | ||
"release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha", | ||
"release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run", | ||
"test": "jest --no-cache --silent=false --verbose=false --coverage", | ||
@@ -39,3 +39,3 @@ "eslint": "eslint . --cache --cache-location .caches/eslint --cache-strategy content --ext js,ts,tsx --max-warnings 0", | ||
"dependencies": { | ||
"@prismicio/types-internal": "2.9.0-alpha.3", | ||
"@prismicio/types-internal": "3.0.0", | ||
"tslib": "^2.5.0", | ||
@@ -42,0 +42,0 @@ "uuid": "^9.0.0" |
@@ -13,4 +13,2 @@ import { | ||
} from "@prismicio/types-internal/lib/content" | ||
// TODO: Import from`@prismicio/types-internal/lib/content` when the types are available. | ||
import { isRepeatableContent, RepeatableContent } from "@prismicio/types-internal/lib/content/fields/RepeatableContent" | ||
import { NestableWidget, StaticWidget } from "@prismicio/types-internal/lib/customtypes" | ||
@@ -32,4 +30,4 @@ | ||
function isStaticWidgetContent(content: WidgetContent): content is GroupContent | RepeatableContent | NestableContent { | ||
return isGroupContent(content) || isRepeatableContent(content) || isNestableContent(content) | ||
function isStaticWidgetContent(content: WidgetContent): content is GroupContent | NestableContent { | ||
return isGroupContent(content) || isNestableContent(content) | ||
} | ||
@@ -36,0 +34,0 @@ |
@@ -9,8 +9,7 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}) | ||
export type AnyLinkDef = Omit<t.TypeOf<typeof codec>, "select"> & { | ||
export type AnyLinkDef = { | ||
select: null | ||
} | ||
} & Pick<t.TypeOf<typeof codec>, "allowText"> | ||
export const AnyLinkDef = new t.Type<AnyLinkDef>( | ||
@@ -24,4 +23,4 @@ "AnyLinkDef", | ||
return { | ||
...decoded, | ||
select: null, | ||
allowText: decoded.allowText, | ||
} | ||
@@ -28,0 +27,0 @@ }), |
@@ -11,3 +11,2 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -14,0 +13,0 @@ ]) |
@@ -10,3 +10,2 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -13,0 +12,0 @@ ]) |
@@ -10,3 +10,2 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes" | ||
allowText: t.boolean, | ||
repeat: t.boolean, | ||
}), | ||
@@ -13,0 +12,0 @@ ]) |
@@ -1,16 +0,8 @@ | ||
import { | ||
GroupContent, | ||
isGroupContent, | ||
isLinkContent, | ||
isNestableContent, | ||
NestableContent, | ||
} from "@prismicio/types-internal/lib/content" | ||
import { isRepeatableContent, RepeatableContent } from "@prismicio/types-internal/lib/content/fields/RepeatableContent" | ||
import type { Group as GroupField, Link, NestableWidget } from "@prismicio/types-internal/lib/customtypes" | ||
import { GroupContent, isGroupContent, isNestableContent, NestableContent } from "@prismicio/types-internal/lib/content" | ||
import type { Group as GroupField, NestableWidget } from "@prismicio/types-internal/lib/customtypes" | ||
import type { RenderContext } from "../models" | ||
import { Field, Group, GroupOrField, GroupType, Simple } from "../models/fetch" | ||
import { Field, Group, GroupOrField, GroupType } from "../models/fetch" | ||
import { withObjectRenderers } from "../object" | ||
import GroupRenderer from "./GroupRenderer" | ||
import RepeatableRenderer from "./RepeatableRenderer" | ||
import SimpleWidgetRenderer from "./SimpleWidgetRenderer" | ||
@@ -34,68 +26,2 @@ | ||
function extractSimpleFieldIfAny(field: Field | undefined): Simple | undefined { | ||
if (field !== undefined && (field.TYPE === "SimpleField" || field.TYPE === "DocRelation")) { | ||
return field | ||
} else { | ||
return undefined | ||
} | ||
} | ||
function renderContent( | ||
def: NestableWidget | GroupField, | ||
content: NestableContent | GroupContent, | ||
fetch: GroupOrField | Simple | undefined, | ||
renderer: { | ||
group: (def: GroupField, content: GroupContent, fetch?: Group) => unknown | ||
repeatable: (def: Link, content: RepeatableContent, fetch?: Simple) => unknown | ||
simple: (def: NestableWidget, content: NestableContent, fetch?: Field) => unknown | ||
default: (def: NestableWidget | GroupField) => unknown | ||
}, | ||
) { | ||
// When def is a Link, there is a special management with the fact it can be repeated or not. | ||
// The custom type is always the one deciding the return type of the content. | ||
// If repeat is true, it will always return an array, and if repeat is false, it will always return an object. | ||
if (def.type === "Link") { | ||
// When repeat is true and existing content is repeatable, render the content as is | ||
if (def.config?.repeat && isRepeatableContent(content)) { | ||
return renderer.repeatable(def, content, extractSimpleFieldIfAny(fetch)) | ||
} | ||
// When repeat is true and existing content is not repeatable, render as repeatable | ||
if (def.config?.repeat && isLinkContent(content)) { | ||
return renderer.repeatable( | ||
def, | ||
{ | ||
__TYPE__: "RepeatableContent", | ||
type: def.type, | ||
value: [content], | ||
}, | ||
extractSimpleFieldIfAny(fetch), | ||
) | ||
} | ||
// When repeat is false and existing content is repeatable with data, render the first item | ||
if (!def.config?.repeat && isRepeatableContent(content) && content.value[0]) { | ||
return renderer.simple(def, content.value[0], extractFetchFieldIfAny(fetch)) | ||
} | ||
// When repeat is false and existing content is repeatable but empty, render the default widget | ||
if (!def.config?.repeat && isRepeatableContent(content)) { | ||
return renderer.default(def) | ||
} | ||
// When repeat is false and existing content is not repeatable, render the content as is, | ||
// using the normal nestable content renderer condition bellow | ||
} | ||
if (def.type !== "Group" && isNestableContent(content)) { | ||
return renderer.simple(def, content, extractFetchFieldIfAny(fetch)) | ||
} | ||
if (def.type === "Group" && isGroupContent(content)) { | ||
return renderer.group(def, content, extractFetchGroupIfAny(fetch)) | ||
} | ||
return renderer.default(def) | ||
} | ||
const StaticWidgetRenderer = (ctx: RenderContext) => | ||
@@ -106,4 +32,2 @@ withObjectRenderers<NestableWidget | GroupField, NestableContent | GroupContent, GroupOrField>({ | ||
return GroupRenderer(ctx).renderV1(content, extractFetchGroupIfAny(fetch)) | ||
} else if (isRepeatableContent(content)) { | ||
return RepeatableRenderer(ctx).renderV1(content, extractSimpleFieldIfAny(fetch)) | ||
} else { | ||
@@ -115,17 +39,14 @@ return SimpleWidgetRenderer(ctx).renderV1(content, extractFetchFieldIfAny(fetch)) | ||
renderV2(def, content, fetch) { | ||
return renderContent(def, content, fetch, { | ||
group: (def: GroupField, content: GroupContent, fetch?: Group) => | ||
GroupRenderer(ctx).renderV2(def, content, fetch), | ||
repeatable: (def: Link, content: RepeatableContent, fetch?: Simple) => | ||
RepeatableRenderer(ctx).renderV2(def, content, fetch), | ||
simple: (def: NestableWidget, content: NestableContent, fetch?: Field) => | ||
SimpleWidgetRenderer(ctx).renderV2(def, content, fetch), | ||
default: (def: NestableWidget | GroupField) => this.renderDefault(def), | ||
}) | ||
if (def.type !== "Group" && isNestableContent(content)) { | ||
// todo maybe find an other condition | ||
return SimpleWidgetRenderer(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)) | ||
} else if (def.type === "Group" && isGroupContent(content)) { | ||
return GroupRenderer(ctx).renderV2(def, content, extractFetchGroupIfAny(fetch)) | ||
} else { | ||
return this.renderDefault(def) | ||
} | ||
}, | ||
renderDefault(def) { | ||
if (def.type === "Link" && def.config?.repeat) { | ||
return RepeatableRenderer(ctx).renderDefault(def) | ||
} else if (def.type === "Group") { | ||
if (def.type === "Group") { | ||
return GroupRenderer(ctx).renderDefault(def) | ||
@@ -138,8 +59,9 @@ } else { | ||
renderMocks(def, content) { | ||
return renderContent(def, content, undefined, { | ||
group: (def: GroupField, content: GroupContent) => GroupRenderer(ctx).renderMocks(def, content), | ||
repeatable: (def: Link, content: RepeatableContent) => RepeatableRenderer(ctx).renderMocks(def, content), | ||
simple: (def: NestableWidget, content: NestableContent) => SimpleWidgetRenderer(ctx).renderMocks(def, content), | ||
default: (def: NestableWidget | GroupField) => this.renderDefault(def), | ||
}) | ||
if (isNestableContent(content) && def.type !== "Group") { | ||
return SimpleWidgetRenderer(ctx).renderMocks(def, content) | ||
} else if (isGroupContent(content) && def.type === "Group") { | ||
return GroupRenderer(ctx).renderMocks(def, content) | ||
} else { | ||
return this.renderDefault(def) | ||
} | ||
}, | ||
@@ -146,0 +68,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
88
1054444
242
24992
+ Added@prismicio/types-internal@3.0.0(transitive)
- Removed@prismicio/types-internal@2.9.0-alpha.3(transitive)