Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prismicio/api-renderer

Package Overview
Dependencies
Maintainers
26
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prismicio/api-renderer - npm Package Compare versions

Comparing version 5.0.0-alpha.2 to 5.0.0-alpha.3

src/widgets/RepeatableRenderer.ts

4

lib/DocumentRenderer.js

@@ -5,2 +5,4 @@ "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");

@@ -13,3 +15,3 @@ const models_1 = require("./models");

function isStaticWidgetContent(content) {
return (0, content_1.isGroupContent)(content) || (0, content_1.isNestableContent)(content);
return (0, content_1.isGroupContent)(content) || (0, RepeatableContent_1.isRepeatableContent)(content) || (0, content_1.isNestableContent)(content);
}

@@ -16,0 +18,0 @@ function i18nWriter(doc) {

@@ -142,2 +142,3 @@ import * as t from "io-ts";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -313,2 +314,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -485,2 +487,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -653,2 +656,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -827,2 +831,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -995,2 +1000,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -997,0 +1003,0 @@ }) | ({

@@ -6,8 +6,9 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes";

allowText: t.BooleanC;
repeat: t.BooleanC;
}>;
export type AnyLinkDef = {
export type AnyLinkDef = Omit<t.TypeOf<typeof codec>, "select"> & {
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,2 +11,3 @@ "use strict";

allowText: t.boolean,
repeat: t.boolean,
});

@@ -16,4 +17,4 @@ exports.AnyLinkDef = new t.Type("AnyLinkDef", (u) => u.select === "any", (u) => {

return {
...decoded,
select: null,
allowText: decoded.allowText,
};

@@ -20,0 +21,0 @@ }));

@@ -8,4 +8,5 @@ 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,2 +13,3 @@ "use strict";

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -15,0 +16,0 @@ ]);

@@ -9,2 +9,3 @@ import { Link } from "@prismicio/types-internal/lib/customtypes/widgets/nestable";

allowText: t.BooleanC;
repeat: t.BooleanC;
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{

@@ -15,2 +16,3 @@ select: t.LiteralC<"document">;

allowText: t.BooleanC;
repeat: t.BooleanC;
}>]>, t.IntersectionC<[t.ExactC<t.TypeC<{

@@ -20,2 +22,3 @@ select: t.LiteralC<"web">;

allowText: t.BooleanC;
repeat: t.BooleanC;
}>]>, t.Type<AnyLinkDef, AnyLinkDef, unknown>]>;

@@ -37,2 +40,3 @@ type LinkConfig = t.TypeOf<typeof LinkConfig>;

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -53,2 +57,3 @@ }>, WithKey<{

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -55,0 +60,0 @@ }>, unknown>;

@@ -7,4 +7,5 @@ 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,2 +12,3 @@ "use strict";

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -14,0 +15,0 @@ ]);

@@ -7,4 +7,5 @@ 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,2 +12,3 @@ "use strict";

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -14,0 +15,0 @@ ]);

@@ -300,2 +300,3 @@ import * as t from "io-ts";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -316,3 +317,4 @@ }>, import("../..").WithKey<{

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;
}>, unknown>]>;

@@ -140,2 +140,3 @@ import * as t from "io-ts";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -301,2 +302,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -472,2 +474,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -633,2 +636,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -635,0 +639,0 @@ }) | ({

@@ -132,2 +132,3 @@ import * as t from "io-ts";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -300,2 +301,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -461,2 +463,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -629,2 +632,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -631,0 +635,0 @@ }) | ({

@@ -15,5 +15,4 @@ "use strict";

return (0, StaticWidgetRenderer_1.default)(ctx).renderV2(
// We need to override the repeat value to false in order to not
// propagate the fact the item is this repeatable.
// Each item inside a repeatable array is not repeatable anymore.
// Override the repeat value to false to prevent propagating the repeat configuration.
// Items inside a repeatable array should not be repeatable.
{

@@ -34,5 +33,4 @@ ...def,

return (0, StaticWidgetRenderer_1.default)(ctx).renderMocks(
// We need to override the repeat value to false in order to not
// propagate the fact the item is this repeatable.
// Each item inside a repeatable array is not repeatable anymore.
// Override the repeat value to false to prevent propagating the repeat configuration.
// Items inside a repeatable array should not be repeatable.
{

@@ -39,0 +37,0 @@ ...def,

@@ -132,2 +132,3 @@ import type { RenderContext } from "../models";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -277,4 +278,4 @@ }) | ({

__TYPE__: "ImageLink";
} & (({
kind: "image";
} & ((({
kind: string;
id: string;

@@ -288,11 +289,10 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "image";
text: string;
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & (({
kind: "file";
} & ((({
kind: string;
id: string;

@@ -304,7 +304,6 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "file";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -314,10 +313,9 @@ __TYPE__: "DocumentLink";

id: string;
} & {
} | {
kind: "document";
}) & {
text?: string | undefined;
}) | {
kind: "document";
text: string;
})) | ({
__TYPE__: "ExternalLink";
} & (({
} & ((({
url: string;

@@ -330,7 +328,6 @@ } & {

} | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "web";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -340,7 +337,8 @@ __TYPE__: "MediaLink";

kind: "media";
text: string;
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text: string;
text?: string | undefined;
});

@@ -377,3 +375,3 @@ } | {

} & {
kind: "image";
kind: string;
id: string;

@@ -390,3 +388,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -450,3 +448,3 @@ url: string;

} & {
kind: "image";
kind: string;
id: string;

@@ -463,3 +461,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -506,2 +504,71 @@ 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;
}) | {
kind: "image";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & ((({
kind: string;
id: string;
url: string;
name: string;
size: string;
} & {
date?: string | null | undefined;
}) | {
kind: "file";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "DocumentLink";
} & (({
id: string;
} | {
kind: "document";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "ExternalLink";
} & ((({
url: string;
} & {
kind?: "web" | undefined;
target?: string | null | undefined;
preview?: {
title?: string | undefined;
} | null | undefined;
}) | {
kind: "web";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "MediaLink";
} & {
kind: "media";
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text?: string | undefined;
});
}[];
}, Field>, ({

@@ -636,2 +703,3 @@ type: "Color";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -781,4 +849,4 @@ }) | ({

__TYPE__: "ImageLink";
} & (({
kind: "image";
} & ((({
kind: string;
id: string;

@@ -792,11 +860,10 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "image";
text: string;
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & (({
kind: "file";
} & ((({
kind: string;
id: string;

@@ -808,7 +875,6 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "file";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -818,10 +884,9 @@ __TYPE__: "DocumentLink";

id: string;
} & {
} | {
kind: "document";
}) & {
text?: string | undefined;
}) | {
kind: "document";
text: string;
})) | ({
__TYPE__: "ExternalLink";
} & (({
} & ((({
url: string;

@@ -834,7 +899,6 @@ } & {

} | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "web";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -844,7 +908,8 @@ __TYPE__: "MediaLink";

kind: "media";
text: string;
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text: string;
text?: string | undefined;
});

@@ -881,3 +946,3 @@ } | {

} & {
kind: "image";
kind: string;
id: string;

@@ -894,3 +959,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -954,3 +1019,3 @@ url: string;

} & {
kind: "image";
kind: string;
id: string;

@@ -967,3 +1032,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -1010,3 +1075,72 @@ 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;
}) | {
kind: "image";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & ((({
kind: string;
id: string;
url: string;
name: string;
size: string;
} & {
date?: string | null | undefined;
}) | {
kind: "file";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "DocumentLink";
} & (({
id: string;
} | {
kind: "document";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "ExternalLink";
} & ((({
url: string;
} & {
kind?: "web" | undefined;
target?: string | null | undefined;
preview?: {
title?: string | undefined;
} | null | undefined;
}) | {
kind: "web";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "MediaLink";
} & {
kind: "media";
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text?: string | undefined;
});
}[];
}, Field>;
export default SimpleWidgetRenderer;

@@ -143,2 +143,3 @@ import { GroupContent } from "@prismicio/types-internal/lib/content";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -311,2 +312,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -475,2 +477,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -620,4 +623,4 @@ }) | ({

__TYPE__: "ImageLink";
} & (({
kind: "image";
} & ((({
kind: string;
id: string;

@@ -631,11 +634,10 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "image";
text: string;
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & (({
kind: "file";
} & ((({
kind: string;
id: string;

@@ -647,7 +649,6 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "file";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -657,10 +658,9 @@ __TYPE__: "DocumentLink";

id: string;
} & {
} | {
kind: "document";
}) & {
text?: string | undefined;
}) | {
kind: "document";
text: string;
})) | ({
__TYPE__: "ExternalLink";
} & (({
} & ((({
url: string;

@@ -673,7 +673,6 @@ } & {

} | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "web";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -683,7 +682,8 @@ __TYPE__: "MediaLink";

kind: "media";
text: string;
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text: string;
text?: string | undefined;
});

@@ -720,3 +720,3 @@ } | {

} & {
kind: "image";
kind: string;
id: string;

@@ -733,3 +733,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -793,3 +793,3 @@ url: string;

} & {
kind: "image";
kind: string;
id: string;

@@ -806,3 +806,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -849,2 +849,71 @@ 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;
}) | {
kind: "image";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & ((({
kind: string;
id: string;
url: string;
name: string;
size: string;
} & {
date?: string | null | undefined;
}) | {
kind: "file";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "DocumentLink";
} & (({
id: string;
} | {
kind: "document";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "ExternalLink";
} & ((({
url: string;
} & {
kind?: "web" | undefined;
target?: string | null | undefined;
preview?: {
title?: string | undefined;
} | null | undefined;
}) | {
kind: "web";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "MediaLink";
} & {
kind: "media";
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text?: string | undefined;
});
}[];
}, GroupOrField>, ({

@@ -989,2 +1058,3 @@ type: "Group";

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -1157,2 +1227,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -1321,2 +1392,3 @@ }) | ({

allowText?: boolean | undefined;
repeat?: boolean | undefined;
} | undefined;

@@ -1466,4 +1538,4 @@ }) | ({

__TYPE__: "ImageLink";
} & (({
kind: "image";
} & ((({
kind: string;
id: string;

@@ -1477,11 +1549,10 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "image";
text: string;
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & (({
kind: "file";
} & ((({
kind: string;
id: string;

@@ -1493,7 +1564,6 @@ url: string;

date?: string | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "file";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -1503,10 +1573,9 @@ __TYPE__: "DocumentLink";

id: string;
} & {
} | {
kind: "document";
}) & {
text?: string | undefined;
}) | {
kind: "document";
text: string;
})) | ({
__TYPE__: "ExternalLink";
} & (({
} & ((({
url: string;

@@ -1519,7 +1588,6 @@ } & {

} | null | undefined;
} & {
text?: string | undefined;
}) | {
kind: "web";
text: string;
}) & {
text?: string | undefined;
})) | ({

@@ -1529,7 +1597,8 @@ __TYPE__: "MediaLink";

kind: "media";
text: string;
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text: string;
text?: string | undefined;
});

@@ -1566,3 +1635,3 @@ } | {

} & {
kind: "image";
kind: string;
id: string;

@@ -1579,3 +1648,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -1639,3 +1708,3 @@ url: string;

} & {
kind: "image";
kind: string;
id: string;

@@ -1652,3 +1721,3 @@ url: string;

} & {
kind: "file";
kind: string;
id: string;

@@ -1695,3 +1764,72 @@ 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;
}) | {
kind: "image";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "FileLink";
} & ((({
kind: string;
id: string;
url: string;
name: string;
size: string;
} & {
date?: string | null | undefined;
}) | {
kind: "file";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "DocumentLink";
} & (({
id: string;
} | {
kind: "document";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "ExternalLink";
} & ((({
url: string;
} & {
kind?: "web" | undefined;
target?: string | null | undefined;
preview?: {
title?: string | undefined;
} | null | undefined;
}) | {
kind: "web";
}) & {
text?: string | undefined;
})) | ({
__TYPE__: "MediaLink";
} & {
kind: "media";
} & {
text?: string | undefined;
}) | ({
__TYPE__: "AnyLink";
} & {
text?: string | undefined;
});
}[];
}, GroupOrField>;
export default StaticWidgetRenderer;

@@ -5,5 +5,7 @@ "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"));

@@ -26,2 +28,47 @@ 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)({

@@ -32,2 +79,5 @@ renderV1(content, fetch) {

}
else if ((0, RepeatableContent_1.isRepeatableContent)(content)) {
return (0, RepeatableRenderer_1.default)(ctx).renderV1(content, extractSimpleFieldIfAny(fetch));
}
else {

@@ -38,15 +88,15 @@ return (0, SimpleWidgetRenderer_1.default)(ctx).renderV1(content, extractFetchFieldIfAny(fetch));

renderV2(def, content, fetch) {
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);
}
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),
});
},
renderDefault(def) {
if (def.type === "Group") {
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") {
return (0, GroupRenderer_1.default)(ctx).renderDefault(def);

@@ -59,13 +109,10 @@ }

renderMocks(def, content) {
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);
}
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),
});
},
});
exports.default = StaticWidgetRenderer;
{
"name": "@prismicio/api-renderer",
"version": "5.0.0-alpha.2",
"version": "5.0.0-alpha.3",
"description": "Prismic renderers for the content API",

@@ -26,6 +26,6 @@ "keywords": [

"prepare": "npm run build",
"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",
"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",
"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": "3.0.0",
"@prismicio/types-internal": "2.9.0-alpha.5",
"tslib": "^2.5.0",

@@ -42,0 +42,0 @@ "uuid": "^9.0.0"

@@ -13,2 +13,4 @@ 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"

@@ -30,4 +32,4 @@

function isStaticWidgetContent(content: WidgetContent): content is GroupContent | NestableContent {
return isGroupContent(content) || isNestableContent(content)
function isStaticWidgetContent(content: WidgetContent): content is GroupContent | RepeatableContent | NestableContent {
return isGroupContent(content) || isRepeatableContent(content) || isNestableContent(content)
}

@@ -34,0 +36,0 @@

@@ -9,7 +9,8 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"

allowText: t.boolean,
repeat: t.boolean,
})
export type AnyLinkDef = {
export type AnyLinkDef = Omit<t.TypeOf<typeof codec>, "select"> & {
select: null
} & Pick<t.TypeOf<typeof codec>, "allowText">
}
export const AnyLinkDef = new t.Type<AnyLinkDef>(

@@ -23,4 +24,4 @@ "AnyLinkDef",

return {
...decoded,
select: null,
allowText: decoded.allowText,
}

@@ -27,0 +28,0 @@ }),

@@ -11,2 +11,3 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -13,0 +14,0 @@ ])

@@ -10,2 +10,3 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -12,0 +13,0 @@ ])

@@ -10,2 +10,3 @@ import type { LinkConfig } from "@prismicio/types-internal/lib/customtypes"

allowText: t.boolean,
repeat: t.boolean,
}),

@@ -12,0 +13,0 @@ ])

@@ -1,8 +0,16 @@

import { GroupContent, isGroupContent, isNestableContent, NestableContent } from "@prismicio/types-internal/lib/content"
import type { Group as GroupField, NestableWidget } from "@prismicio/types-internal/lib/customtypes"
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 type { RenderContext } from "../models"
import { Field, Group, GroupOrField, GroupType } from "../models/fetch"
import { Field, Group, GroupOrField, GroupType, Simple } from "../models/fetch"
import { withObjectRenderers } from "../object"
import GroupRenderer from "./GroupRenderer"
import RepeatableRenderer from "./RepeatableRenderer"
import SimpleWidgetRenderer from "./SimpleWidgetRenderer"

@@ -26,2 +34,68 @@

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) =>

@@ -32,2 +106,4 @@ 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 {

@@ -39,14 +115,17 @@ return SimpleWidgetRenderer(ctx).renderV1(content, extractFetchFieldIfAny(fetch))

renderV2(def, content, fetch) {
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)
}
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),
})
},
renderDefault(def) {
if (def.type === "Group") {
if (def.type === "Link" && def.config?.repeat) {
return RepeatableRenderer(ctx).renderDefault(def)
} else if (def.type === "Group") {
return GroupRenderer(ctx).renderDefault(def)

@@ -59,9 +138,8 @@ } else {

renderMocks(def, content) {
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)
}
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),
})
},

@@ -68,0 +146,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc