@prismicio/api-renderer
Advanced tools
Comparing version 4.0.0 to 5.0.0-alpha.0
@@ -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 @@ }) | ({ |
@@ -132,2 +132,3 @@ import type { RenderContext } from "../models"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -496,2 +497,74 @@ }) | ({ | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Color" | "Boolean" | "Number" | "Embed" | "GeoPoint" | "Date" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Link" | "Image" | "IntegrationFields"; | ||
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>, ({ | ||
@@ -626,2 +699,3 @@ type: "Color"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -990,3 +1064,75 @@ }) | ({ | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Color" | "Boolean" | "Number" | "Embed" | "GeoPoint" | "Date" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Link" | "Image" | "IntegrationFields"; | ||
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; |
import { GroupContent } from "@prismicio/types-internal/lib/content"; | ||
import type { RenderContext } from "../models"; | ||
import type { RenderContext, Renderer } from "../models"; | ||
import { GroupOrField } from "../models/fetch"; | ||
declare const StaticWidgetRenderer: (ctx: RenderContext) => import("../object").WithObjectRenderers<import("../models").Renderer<({ | ||
declare const StaticWidgetRenderer: (ctx: RenderContext) => import("../object").WithObjectRenderers<Renderer<({ | ||
type: "Group"; | ||
@@ -143,2 +143,3 @@ } & { | ||
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; | ||
@@ -839,2 +842,74 @@ }) | ({ | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Color" | "Boolean" | "Number" | "Embed" | "GeoPoint" | "Date" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Link" | "Image" | "IntegrationFields"; | ||
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>, ({ | ||
@@ -979,2 +1054,3 @@ type: "Group"; | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1147,2 +1223,3 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1311,2 +1388,3 @@ }) | ({ | ||
allowText?: boolean | undefined; | ||
repeat?: boolean | undefined; | ||
} | undefined; | ||
@@ -1675,3 +1753,75 @@ }) | ({ | ||
__TYPE__: "SeparatorContent"; | ||
} | { | ||
__TYPE__: "RepeatableContent"; | ||
type: "Color" | "Boolean" | "Number" | "Embed" | "GeoPoint" | "Date" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Link" | "Image" | "IntegrationFields"; | ||
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,2 +5,3 @@ "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"); | ||
@@ -26,2 +27,10 @@ const object_1 = require("../object"); | ||
} | ||
function extractSimpleFieldIfAny(field) { | ||
if (field !== undefined && (field.TYPE === "SimpleField" || field.TYPE === "DocRelation")) { | ||
return field; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
const StaticWidgetRenderer = (ctx) => (0, object_1.withObjectRenderers)({ | ||
@@ -32,2 +41,5 @@ renderV1(content, fetch) { | ||
} | ||
else if ((0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return RepeatableRenderer(ctx).renderV1(content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
else { | ||
@@ -38,3 +50,7 @@ return (0, SimpleWidgetRenderer_1.default)(ctx).renderV1(content, extractFetchFieldIfAny(fetch)); | ||
renderV2(def, content, fetch) { | ||
if (def.type !== "Group" && (0, content_1.isNestableContent)(content)) { | ||
var _a; | ||
if (def.type === "Link" && ((_a = def.config) === null || _a === void 0 ? void 0 : _a.repeat) && (0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return RepeatableRenderer(ctx).renderV2(def, content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
else if (def.type !== "Group" && (0, content_1.isNestableContent)(content)) { | ||
// todo maybe find an other condition | ||
@@ -51,3 +67,7 @@ return (0, SimpleWidgetRenderer_1.default)(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)); | ||
renderDefault(def) { | ||
if (def.type === "Group") { | ||
var _a; | ||
if (def.type === "Link" && ((_a = def.config) === null || _a === void 0 ? void 0 : _a.repeat)) { | ||
return RepeatableRenderer(ctx).renderDefault(def); | ||
} | ||
else if (def.type === "Group") { | ||
return (0, GroupRenderer_1.default)(ctx).renderDefault(def); | ||
@@ -60,3 +80,7 @@ } | ||
renderMocks(def, content) { | ||
if ((0, content_1.isNestableContent)(content) && def.type !== "Group") { | ||
var _a; | ||
if (def.type === "Link" && ((_a = def.config) === null || _a === void 0 ? void 0 : _a.repeat) && (0, RepeatableContent_1.isRepeatableContent)(content)) { | ||
return RepeatableRenderer(ctx).renderMocks(def, content); | ||
} | ||
else if ((0, content_1.isNestableContent)(content) && def.type !== "Group") { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderMocks(def, content); | ||
@@ -73,1 +97,23 @@ } | ||
exports.default = StaticWidgetRenderer; | ||
const RepeatableRenderer = (ctx) => { | ||
return { | ||
renderV1(content, fetch) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderV1(item, fetch); | ||
}); | ||
}, | ||
renderV2(def, content, fetch) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderV2(def, item, fetch); | ||
}); | ||
}, | ||
renderDefault(def) { | ||
return [StaticWidgetRenderer(ctx).renderDefault(def)]; | ||
}, | ||
renderMocks(def, content) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderMocks(def, item); | ||
}); | ||
}, | ||
}; | ||
}; |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "4.0.0", | ||
"version": "5.0.0-alpha.0", | ||
"description": "Prismic renderers for the content API", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@prismicio/types-internal": "2.8.0", | ||
"@prismicio/types-internal": "2.9.0-alpha.0", | ||
"tslib": "^2.5.0", | ||
@@ -41,0 +41,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 @@ ]) |
import { GroupContent, isGroupContent, isNestableContent, NestableContent } from "@prismicio/types-internal/lib/content" | ||
import { isRepeatableContent, RepeatableContent } from "@prismicio/types-internal/lib/content/fields/RepeatableContent" | ||
import type { Group as GroupField, NestableWidget } from "@prismicio/types-internal/lib/customtypes" | ||
import type { RenderContext } from "../models" | ||
import { Field, Group, GroupOrField, GroupType } from "../models/fetch" | ||
import type { RenderContext, Renderer } from "../models" | ||
import { Field, Group, GroupOrField, GroupType, Simple } from "../models/fetch" | ||
import { withObjectRenderers } from "../object" | ||
@@ -26,2 +27,10 @@ import GroupRenderer from "./GroupRenderer" | ||
function extractSimpleFieldIfAny(field: Field | undefined): Simple | undefined { | ||
if (field !== undefined && (field.TYPE === "SimpleField" || field.TYPE === "DocRelation")) { | ||
return field | ||
} else { | ||
return undefined | ||
} | ||
} | ||
const StaticWidgetRenderer = (ctx: RenderContext) => | ||
@@ -32,2 +41,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,3 +50,5 @@ return SimpleWidgetRenderer(ctx).renderV1(content, extractFetchFieldIfAny(fetch)) | ||
renderV2(def, content, fetch) { | ||
if (def.type !== "Group" && isNestableContent(content)) { | ||
if (def.type === "Link" && def.config?.repeat && isRepeatableContent(content)) { | ||
return RepeatableRenderer(ctx).renderV2(def, content, extractSimpleFieldIfAny(fetch)) | ||
} else if (def.type !== "Group" && isNestableContent(content)) { | ||
// todo maybe find an other condition | ||
@@ -51,3 +64,5 @@ return SimpleWidgetRenderer(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)) | ||
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) | ||
@@ -60,3 +75,5 @@ } else { | ||
renderMocks(def, content) { | ||
if (isNestableContent(content) && def.type !== "Group") { | ||
if (def.type === "Link" && def.config?.repeat && isRepeatableContent(content)) { | ||
return RepeatableRenderer(ctx).renderMocks(def, content) | ||
} else if (isNestableContent(content) && def.type !== "Group") { | ||
return SimpleWidgetRenderer(ctx).renderMocks(def, content) | ||
@@ -72,1 +89,27 @@ } else if (isGroupContent(content) && def.type === "Group") { | ||
export default StaticWidgetRenderer | ||
const RepeatableRenderer: (ctx: RenderContext) => Renderer<NestableWidget, RepeatableContent, Simple> = (ctx) => { | ||
return { | ||
renderV1(content, fetch) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderV1(item, fetch) | ||
}) | ||
}, | ||
renderV2(def, content, fetch) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderV2(def, item, fetch) | ||
}) | ||
}, | ||
renderDefault(def) { | ||
return [StaticWidgetRenderer(ctx).renderDefault(def)] | ||
}, | ||
renderMocks(def, content) { | ||
return content.value.map((item) => { | ||
return StaticWidgetRenderer(ctx).renderMocks(def, item) | ||
}) | ||
}, | ||
} | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
1069713
25426
2
90
+ Added@prismicio/types-internal@2.9.0-alpha.0(transitive)
- Removed@prismicio/types-internal@2.8.0(transitive)