@prismicio/api-renderer
Advanced tools
Comparing version 0.1.7 to 0.2.0
import { WidgetContent } from "@prismicio/types-internal/lib/documents/widgets"; | ||
import { type ApiDocument, type ApiModel, type RelatedDocument, type RenderContext, Fetch } from "./models"; | ||
import { WidgetDefO } from "./models/ApiModel"; | ||
import { type ApiDocument, type ApiModel, type RelatedDocument, type RenderContext, Fetch, WidgetDefO } from "./models"; | ||
declare const DocumentRenderer: (ctx: RenderContext) => { | ||
@@ -5,0 +4,0 @@ renderV1: (doc: ApiDocument, content: [string, WidgetContent][], searchURL: string, i18n: { |
@@ -7,3 +7,2 @@ "use strict"; | ||
const models_1 = require("./models"); | ||
const ApiModel_1 = require("./models/ApiModel"); | ||
const utils_1 = require("./utils"); | ||
@@ -49,5 +48,3 @@ const widgets_2 = require("./widgets"); | ||
const newKey = (isDeprecatedArray ? deprecatedArray[1] : key); | ||
const maybeContent = isDeprecatedArray | ||
? renderedContent[newKey] | ||
: undefined; | ||
const maybeContent = isDeprecatedArray ? renderedContent[newKey] : undefined; | ||
if (fetch !== undefined) { | ||
@@ -58,6 +55,3 @@ const field = fetch.fields[key]; | ||
renderedContent[newKey] = Array.isArray(maybeContent) | ||
? [ | ||
...maybeContent, | ||
renderWidgetV1(ctx)(widgetContent, field), | ||
] | ||
? [...maybeContent, renderWidgetV1(ctx)(widgetContent, field)] | ||
: [renderWidgetV1(ctx)(widgetContent, field)]; | ||
@@ -73,6 +67,3 @@ } | ||
renderedContent[newKey] = Array.isArray(maybeContent) | ||
? [ | ||
...maybeContent, | ||
renderWidgetV1(ctx)(widgetContent, undefined), | ||
] | ||
? [...maybeContent, renderWidgetV1(ctx)(widgetContent, undefined)] | ||
: [renderWidgetV1(ctx)(widgetContent, undefined)]; | ||
@@ -107,8 +98,4 @@ } | ||
tags: doc.tags, | ||
first_publication_date: doc.first_publication_date | ||
? (0, utils_1.formatDateTime)(doc.first_publication_date) | ||
: null, | ||
last_publication_date: doc.last_publication_date | ||
? (0, utils_1.formatDateTime)(doc.last_publication_date) | ||
: null, | ||
first_publication_date: doc.first_publication_date ? (0, utils_1.formatDateTime)(doc.first_publication_date) : null, | ||
last_publication_date: doc.last_publication_date ? (0, utils_1.formatDateTime)(doc.last_publication_date) : null, | ||
slugs: doc.data.slugs, | ||
@@ -125,7 +112,6 @@ linked_documents: [], | ||
return (mask, content, fetchOpt) => { | ||
if (content.__TYPE__ === slices_1.SlicesContentType && | ||
mask.__TYPE__ === ApiModel_1.SlicesDefType) { | ||
if (content.__TYPE__ === slices_1.SlicesContentType && mask.__TYPE__ === models_1.SlicesDefType) { | ||
return (0, SlicesRenderer_1.default)(ctx).renderV2(mask, content, models_1.Fetch.extractSliceFetchIfAny(fetchOpt)); | ||
} | ||
else if (widgets_1.StaticWidgetContent.is(content) && (0, ApiModel_1.isStaticFieldDef)(mask)) { | ||
else if (widgets_1.StaticWidgetContent.is(content) && (0, models_1.isStaticFieldDef)(mask)) { | ||
return (0, widgets_2.StaticWidgetRenderer)(ctx).renderV2(mask, content, models_1.Fetch.extractGroupOrFieldIfAny(fetchOpt)); | ||
@@ -150,9 +136,7 @@ } | ||
const correspondingContent = content.find(([id]) => id === name.apiId); | ||
const encodedWidgetDef = ApiModel_1.WidgetDef.encode(widgetDef); | ||
const encodedWidgetDef = models_1.WidgetDef.encode(widgetDef); | ||
const fetchField = fetchDoc === null || fetchDoc === void 0 ? void 0 : fetchDoc.fields[name.apiId]; | ||
const deprecatedArray = name.apiId.match(DEPRECATED_ARRAY_REGEX); | ||
const isDeprecatedArray = Boolean(deprecatedArray && deprecatedArray[1]); | ||
const newKey = (isDeprecatedArray | ||
? deprecatedArray[1] | ||
: name.apiId); | ||
const newKey = (isDeprecatedArray ? deprecatedArray[1] : name.apiId); | ||
if (correspondingContent) { | ||
@@ -173,7 +157,3 @@ if (fetchDoc === undefined || fetchField !== undefined) { | ||
if (fetchDoc === undefined || fetchField !== undefined) { | ||
return [ | ||
newKey, | ||
renderDefaultWidget(ctx)(encodedWidgetDef), | ||
isDeprecatedArray, | ||
]; | ||
return [newKey, renderDefaultWidget(ctx)(encodedWidgetDef), isDeprecatedArray]; | ||
} | ||
@@ -229,8 +209,4 @@ else { | ||
tags: doc.tags, | ||
first_publication_date: doc.first_publication_date | ||
? (0, utils_1.formatDateTime)(doc.first_publication_date) | ||
: null, | ||
last_publication_date: doc.last_publication_date | ||
? (0, utils_1.formatDateTime)(doc.last_publication_date) | ||
: null, | ||
first_publication_date: doc.first_publication_date ? (0, utils_1.formatDateTime)(doc.first_publication_date) : null, | ||
last_publication_date: doc.last_publication_date ? (0, utils_1.formatDateTime)(doc.last_publication_date) : null, | ||
slugs: doc.data.slugs, | ||
@@ -247,7 +223,6 @@ linked_documents: [], | ||
return (mask, content) => { | ||
if (content.__TYPE__ === slices_1.SlicesContentType && | ||
mask.__TYPE__ === ApiModel_1.SlicesDefType) { | ||
if (content.__TYPE__ === slices_1.SlicesContentType && mask.__TYPE__ === models_1.SlicesDefType) { | ||
return (0, SlicesRenderer_1.default)(ctx).renderMocks(mask, content); | ||
} | ||
else if (widgets_1.StaticWidgetContent.is(content) && (0, ApiModel_1.isStaticFieldDef)(mask)) { | ||
else if (widgets_1.StaticWidgetContent.is(content) && (0, models_1.isStaticFieldDef)(mask)) { | ||
return (0, widgets_2.StaticWidgetRenderer)(ctx).renderMocks(mask, content); | ||
@@ -276,21 +251,11 @@ } | ||
const correspondingContent = content.find(([id]) => id === name.apiId); | ||
const encodedWidgetDef = ApiModel_1.WidgetDef.encode(widgetDef); | ||
const encodedWidgetDef = models_1.WidgetDef.encode(widgetDef); | ||
const deprecatedArray = name.apiId.match(DEPRECATED_ARRAY_REGEX); | ||
const isDeprecatedArray = Boolean(deprecatedArray && deprecatedArray[1]); | ||
const newKey = (isDeprecatedArray | ||
? deprecatedArray[1] | ||
: name.apiId); | ||
const newKey = (isDeprecatedArray ? deprecatedArray[1] : name.apiId); | ||
if (correspondingContent) { | ||
return [ | ||
newKey, | ||
renderWidgetMocks(ctx)(encodedWidgetDef, correspondingContent[1]), | ||
isDeprecatedArray, | ||
]; | ||
return [newKey, renderWidgetMocks(ctx)(encodedWidgetDef, correspondingContent[1]), isDeprecatedArray]; | ||
} | ||
else { | ||
return [ | ||
newKey, | ||
renderDefaultWidget(ctx)(encodedWidgetDef), | ||
isDeprecatedArray, | ||
]; | ||
return [newKey, renderDefaultWidget(ctx)(encodedWidgetDef), isDeprecatedArray]; | ||
} | ||
@@ -347,8 +312,8 @@ } | ||
return (widgetDef) => { | ||
if (widgetDef.__TYPE__ === ApiModel_1.SlicesDefType) { | ||
if (widgetDef.__TYPE__ === models_1.SlicesDefType) { | ||
(0, SlicesRenderer_1.default)(ctx).renderDefault(widgetDef); | ||
} | ||
else if (widgetDef.__TYPE__ === ApiModel_1.SimpleSliceDefType || | ||
widgetDef.__TYPE__ === ApiModel_1.SharedSliceDefType || | ||
widgetDef.__TYPE__ === ApiModel_1.CompositeSliceDefType) { | ||
else if (widgetDef.__TYPE__ === models_1.SimpleSliceDefType || | ||
widgetDef.__TYPE__ === models_1.SharedSliceDefType || | ||
widgetDef.__TYPE__ === models_1.CompositeSliceDefType) { | ||
return (0, widgets_2.SliceWidgetRenderer)(ctx).renderDefault(widgetDef); | ||
@@ -355,0 +320,0 @@ } |
@@ -53,3 +53,5 @@ "use strict"; | ||
getWidget(key) { | ||
return documents_1.DocumentData.getWidget(key, this.widgets, this.fieldTypes, this.fieldPositions, this.parsed); | ||
const widget = documents_1.DocumentData.getWidget(key, this.widgets, this.fieldTypes, this.fieldPositions, this.parsed); | ||
this.parsed.set(key, widget); | ||
return widget; | ||
} | ||
@@ -56,0 +58,0 @@ parseAll() { |
@@ -12,8 +12,3 @@ "use strict"; | ||
const WebLink_1 = require("./WebLink"); | ||
const LinkDefConfig = t.union([ | ||
MediaLink_1.MediaLinkDef, | ||
DocumentLink_1.DocumentLinkDef, | ||
WebLink_1.WebLinkDef, | ||
AnyLink_1.AnyLinkDef, | ||
]); | ||
const LinkDefConfig = t.union([MediaLink_1.MediaLinkDef, DocumentLink_1.DocumentLinkDef, WebLink_1.WebLinkDef, AnyLink_1.AnyLinkDef]); | ||
exports.LinkDefType = "LinkDefType"; | ||
@@ -51,4 +46,2 @@ exports.LinkDef = (0, mapOutput_1.mapOutput)(t.strict({ | ||
return (0, WebLink_1.defaultWebLinkDef)(); | ||
default: | ||
throw new Error(`[UNREACHABLE] ${type} is unknown`); | ||
} | ||
@@ -55,0 +48,0 @@ })(); |
@@ -11,7 +11,3 @@ "use strict"; | ||
const SimpleSlice_1 = require("./SimpleSlice"); | ||
exports.SliceDef = t.union([ | ||
SimpleSlice_1.SimpleSliceDef, | ||
SharedSlice_1.SharedSliceDef, | ||
CompositeSlice_1.CompositeSliceDef, | ||
]); | ||
exports.SliceDef = t.union([SimpleSlice_1.SimpleSliceDef, SharedSlice_1.SharedSliceDef, CompositeSlice_1.CompositeSliceDef]); | ||
function fromSlice(key, model) { | ||
@@ -18,0 +14,0 @@ switch (model.type) { |
@@ -79,5 +79,3 @@ "use strict"; | ||
if (fetchOpt !== undefined && | ||
(fetchOpt.TYPE === exports.SimpleFieldType || | ||
fetchOpt.TYPE === exports.DocRelationType || | ||
fetchOpt.TYPE === exports.GroupType)) { | ||
(fetchOpt.TYPE === exports.SimpleFieldType || fetchOpt.TYPE === exports.DocRelationType || fetchOpt.TYPE === exports.GroupType)) { | ||
return fetchOpt; | ||
@@ -84,0 +82,0 @@ } |
import type { GroupContent } from "@prismicio/types-internal/lib/documents/widgets"; | ||
import type { GroupDefO } from "../models/ApiModel"; | ||
import type { GroupDefO, Renderer } from "../models"; | ||
import type { Group as GroupFetch } from "../models/fetch"; | ||
import type RenderContext from "../models/RenderContext"; | ||
import type { Renderer } from "../models/Renderer"; | ||
declare const GroupRenderer: (ctx: RenderContext) => Renderer<GroupDefO, GroupContent, GroupFetch>; | ||
export default GroupRenderer; |
import type { BooleanContent } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { BooleanFieldDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { BooleanFieldDefO, Renderer } from "../../models"; | ||
declare const BooleanRenderer: Renderer<BooleanFieldDefO, BooleanContent>; | ||
export default BooleanRenderer; |
import type { EmbedContentO } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { EmbedDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { EmbedDefO, Renderer } from "../../models"; | ||
declare const EmbedRenderer: Renderer<EmbedDefO, EmbedContentO>; | ||
export default EmbedRenderer; |
import type { FieldContent } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { FieldDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { FieldDefO, Renderer } from "../../models"; | ||
declare const FieldRenderer: Renderer<FieldDefO, FieldContent>; | ||
export default FieldRenderer; |
import type { GeoPointContentO } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { GeoPointDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { GeoPointDefO, Renderer } from "../../models"; | ||
declare const GeoPointRenderer: Renderer<GeoPointDefO, GeoPointContentO>; | ||
export default GeoPointRenderer; |
import type { ImageContentO } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { RenderContext } from "../../models"; | ||
import type { ImageDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { ImageDefO, RenderContext, Renderer } from "../../models"; | ||
declare const ImageRenderer: (ctx: RenderContext) => Renderer<ImageDefO, ImageContentO>; | ||
export default ImageRenderer; |
import type { IntegrationFieldsContent } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { IntegrationFieldDefO } from "../../models/ApiModel"; | ||
import type { IntegrationFieldDefO, Renderer } from "../../models"; | ||
import type RenderContext from "../../models/RenderContext"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
declare const IntegrationFieldRenderer: (ctx: RenderContext) => Renderer<IntegrationFieldDefO, IntegrationFieldsContent>; | ||
export default IntegrationFieldRenderer; |
import { type DocumentLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link"; | ||
import type { RenderContext } from "../../../models"; | ||
import { DocumentLinkDef } from "../../../models/ApiModel"; | ||
import { DocumentLinkDef, LinkRenderer } from "../../../models"; | ||
import type { DocRelation } from "../../../models/fetch"; | ||
import type { LinkRenderer } from "../../../models/Renderer"; | ||
declare const DocumentLinkRenderer: (ctx: RenderContext) => LinkRenderer<DocumentLinkDef, DocumentLink, DocRelation>; | ||
export default DocumentLinkRenderer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Link_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/Link"); | ||
const ApiModel_1 = require("../../../models/ApiModel"); | ||
const models_1 = require("../../../models"); | ||
function brokenLinkV2(id) { | ||
@@ -43,3 +43,3 @@ return { | ||
renderMocks(def, link) { | ||
const type = (ApiModel_1.DocumentLinkDef.is(def) && def.customtypes[0]) || "mock"; | ||
const type = (models_1.DocumentLinkDef.is(def) && def.customtypes[0]) || "mock"; | ||
return { | ||
@@ -46,0 +46,0 @@ id: link.id, |
import type { ExternalLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link"; | ||
import type { WebLinkDef } from "../../../models/ApiModel"; | ||
import type { LinkRenderer } from "../../../models/Renderer"; | ||
import type { LinkRenderer, WebLinkDef } from "../../../models"; | ||
declare const ExternalLinkRenderer: LinkRenderer<WebLinkDef, ExternalLink>; | ||
export default ExternalLinkRenderer; |
import type { FileLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link"; | ||
import type { RenderContext } from "../../../models"; | ||
import type { MediaLinkDef } from "../../../models/ApiModel"; | ||
import type { LinkRenderer } from "../../../models/Renderer"; | ||
import type { LinkRenderer, MediaLinkDef } from "../../../models"; | ||
declare const FileLinkRenderer: (ctx: RenderContext) => LinkRenderer<MediaLinkDef, FileLink>; | ||
export default FileLinkRenderer; |
import type { ImageLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link"; | ||
import type { RenderContext } from "../../../models"; | ||
import type { MediaLinkDef } from "../../../models/ApiModel"; | ||
import type { LinkRenderer } from "../../../models/Renderer"; | ||
import type { LinkRenderer, MediaLinkDef } from "../../../models"; | ||
declare const ImageLinkRenderer: (ctx: RenderContext) => LinkRenderer<MediaLinkDef, ImageLink>; | ||
export default ImageLinkRenderer; |
@@ -11,2 +11,2 @@ import { type LinkContent } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link"; | ||
export default LinkRenderer; | ||
export { DocumentLinkRenderer, ExternalLinkRenderer, FileLinkRenderer, ImageLinkRenderer, }; | ||
export { DocumentLinkRenderer, ExternalLinkRenderer, FileLinkRenderer, ImageLinkRenderer }; |
@@ -36,16 +36,12 @@ "use strict"; | ||
const encoded = Link_1.Link.encode(content.value); | ||
if (encoded.__TYPE__ === "ImageLink" && | ||
((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def))) { | ||
if (encoded.__TYPE__ === "ImageLink" && ((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def))) { | ||
return (0, ImageLinkRenderer_1.default)(ctx).renderV2(def.config, encoded); | ||
} | ||
else if (((0, ApiModel_1.isDocumentLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "DocumentLink") { | ||
else if (((0, ApiModel_1.isDocumentLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "DocumentLink") { | ||
return (0, DocumentLinkRenderer_1.default)(ctx).renderV2(def.config, encoded, fetch); | ||
} | ||
else if (((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "FileLink") { | ||
else if (((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "FileLink") { | ||
return (0, FileLinkRenderer_1.default)(ctx).renderV2(def.config, encoded); | ||
} | ||
else if (((0, ApiModel_1.isWebLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "ExternalLink") { | ||
else if (((0, ApiModel_1.isWebLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "ExternalLink") { | ||
return ExternalLinkRenderer_1.default.renderV2(def.config, encoded); | ||
@@ -79,16 +75,12 @@ } | ||
const encoded = Link_1.Link.encode(content.value); | ||
if (encoded.__TYPE__ === "ImageLink" && | ||
((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def))) { | ||
if (encoded.__TYPE__ === "ImageLink" && ((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def))) { | ||
return (0, ImageLinkRenderer_1.default)(ctx).renderMocks(def.config, encoded); | ||
} | ||
else if (((0, ApiModel_1.isDocumentLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "DocumentLink") { | ||
else if (((0, ApiModel_1.isDocumentLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "DocumentLink") { | ||
return (0, DocumentLinkRenderer_1.default)(ctx).renderMocks(def.config, encoded); | ||
} | ||
else if (((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "FileLink") { | ||
else if (((0, ApiModel_1.isMediaLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "FileLink") { | ||
return (0, FileLinkRenderer_1.default)(ctx).renderMocks(def.config, encoded); | ||
} | ||
else if (((0, ApiModel_1.isWebLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && | ||
encoded.__TYPE__ === "ExternalLink") { | ||
else if (((0, ApiModel_1.isWebLinkDef)(def) || (0, ApiModel_1.isAnyLinkDef)(def)) && encoded.__TYPE__ === "ExternalLink") { | ||
return ExternalLinkRenderer_1.default.renderMocks(def.config, encoded); | ||
@@ -95,0 +87,0 @@ } |
import type { SeparatorContent } from "@prismicio/types-internal/lib/documents/widgets/nestable"; | ||
import type { SeparatorDefO } from "../../models/ApiModel"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
import type { Renderer, SeparatorDefO } from "../../models"; | ||
declare const SeparatorRenderer: Renderer<SeparatorDefO, SeparatorContent>; | ||
export default SeparatorRenderer; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const models_1 = require("../../../models"); | ||
const ApiModel_1 = require("../../../models/ApiModel"); | ||
const models_2 = require("../../../models"); | ||
const utils_1 = require("../../../utils"); | ||
@@ -28,6 +28,6 @@ const Link_2 = (0, tslib_1.__importDefault)(require("../Link")); | ||
else if (apiVersion === models_1.ApiVersion.v2) { | ||
return (0, Link_2.default)(ctx).renderV2((0, ApiModel_1.defaultLinkDef)(linkType()), link, undefined); | ||
return (0, Link_2.default)(ctx).renderV2((0, models_2.defaultLinkDef)(linkType()), link, undefined); | ||
} | ||
else if (apiVersion === models_1.ApiVersion.mocks) { | ||
return (0, Link_2.default)(ctx).renderMocks((0, ApiModel_1.defaultLinkDef)(linkType()), link); | ||
return (0, Link_2.default)(ctx).renderMocks((0, models_2.defaultLinkDef)(linkType()), link); | ||
} | ||
@@ -34,0 +34,0 @@ } |
import type { SimpleWidgetContent } from "@prismicio/types-internal/lib/documents/widgets"; | ||
import type { RenderContext } from "../models"; | ||
import { SimpleFieldDefO } from "../models/ApiModel"; | ||
import type { Renderer } from "../models"; | ||
import { SimpleFieldDefO } from "../models"; | ||
import { Field } from "../models/fetch"; | ||
import type { Renderer } from "../models/Renderer"; | ||
declare const SimpleWidgetRenderer: (ctx: RenderContext) => Renderer<SimpleFieldDefO, SimpleWidgetContent, Field> & { | ||
@@ -7,0 +7,0 @@ renderObjectOfSimpleWidgetV1(content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, fetch: Record<string, Field> | undefined): object; |
@@ -6,5 +6,10 @@ "use strict"; | ||
const nestable_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable"); | ||
const BooleanContent_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/BooleanContent"); | ||
const GeoPointContent_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/GeoPointContent"); | ||
const ImageContent_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/ImageContent"); | ||
const IntegrationFieldsContent_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/IntegrationFieldsContent"); | ||
const LinkContent_1 = require("@prismicio/types-internal/lib/documents/widgets/nestable/Link/LinkContent"); | ||
const Array_1 = require("fp-ts/lib/Array"); | ||
const O = (0, tslib_1.__importStar)(require("fp-ts/lib/Option")); | ||
const ApiModel_1 = require("../models/ApiModel"); | ||
const models_1 = require("../models"); | ||
const fetch_1 = require("../models/fetch"); | ||
@@ -32,6 +37,6 @@ const utils_1 = require("../utils"); | ||
renderV1(content, fetch) { | ||
if (nestable_1.StructuredTextContent.is(content)) { | ||
if (content.__TYPE__ === nestable_1.StructuredTextContentType) { | ||
return (0, nestable_2.StructuredTextRenderer)(ctx).renderV1(content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
else if (nestable_1.ImageContent.is(content)) { | ||
else if (content.__TYPE__ === ImageContent_1.ImageContentType) { | ||
return (0, nestable_2.ImageRenderer)(ctx).renderV1(content); | ||
@@ -42,21 +47,21 @@ } | ||
} | ||
else if (nestable_1.Links.LinkContent.is(content)) { | ||
else if (content.__TYPE__ === LinkContent_1.LinkContentType) { | ||
return (0, nestable_2.LinkRenderer)(ctx).renderV1(content, extractFetchDocRelationIfAny(fetch)); | ||
} | ||
else if (nestable_1.EmbedContent.is(content)) { | ||
else if (content.__TYPE__ === nestable_1.EmbedContentType) { | ||
return nestable_2.EmbedRenderer.renderV1(content); | ||
} | ||
else if (nestable_1.GeoPointContent.is(content)) { | ||
else if (content.__TYPE__ === GeoPointContent_1.GeoPointContentType) { | ||
return nestable_2.GeoPointRenderer.renderV1(content); | ||
} | ||
else if (widgets_1.UIDContent.is(content)) { | ||
else if (content.__TYPE__ === widgets_1.UIDContentType) { | ||
return UIDRenderer_1.default.renderV1(content); | ||
} | ||
else if (nestable_1.IntegrationFieldsContent.is(content)) { | ||
else if (content.__TYPE__ === IntegrationFieldsContent_1.IntegrationFieldsContentType) { | ||
return (0, nestable_2.IntegrationFieldsRenderer)(ctx).renderV1(content); | ||
} | ||
else if (nestable_1.SeparatorContent.is(content)) { | ||
else if (content.__TYPE__ === nestable_1.SeparatorContentType) { | ||
return nestable_2.SeparatorRenderer.renderV1(content); | ||
} | ||
else if (nestable_1.BooleanContent.is(content)) { | ||
else if (content.__TYPE__ === BooleanContent_1.BooleanContentType) { | ||
return nestable_2.BooleanRenderer.renderV1(content); | ||
@@ -69,32 +74,27 @@ } | ||
renderV2(def, content, fetch) { | ||
if (def.__TYPE__ === ApiModel_1.StructuredTextDefType && | ||
nestable_1.StructuredTextContent.is(content)) { | ||
if (def.__TYPE__ === models_1.StructuredTextDefType && nestable_1.StructuredTextContent.is(content)) { | ||
return (0, nestable_2.StructuredTextRenderer)(ctx).renderV2(def, content, extractSimpleFieldIfAny(fetch)); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.ImageDefType && nestable_1.ImageContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.ImageDefType && nestable_1.ImageContent.is(content)) { | ||
return (0, nestable_2.ImageRenderer)(ctx).renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.LinkDefType && nestable_1.Links.LinkContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.LinkDefType && nestable_1.Links.LinkContent.is(content)) { | ||
return (0, nestable_2.LinkRenderer)(ctx).renderV2(def, content, extractFetchDocRelationIfAny(fetch)); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.EmbedDefType && nestable_1.EmbedContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.EmbedDefType && nestable_1.EmbedContent.is(content)) { | ||
return nestable_2.EmbedRenderer.renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.GeoPointDefType && | ||
nestable_1.GeoPointContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.GeoPointDefType && nestable_1.GeoPointContent.is(content)) { | ||
return nestable_2.GeoPointRenderer.renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.UIDDefType && widgets_1.UIDContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.UIDDefType && widgets_1.UIDContent.is(content)) { | ||
return UIDRenderer_1.default.renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.IntegrationFieldDefType && | ||
nestable_1.IntegrationFieldsContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.IntegrationFieldDefType && nestable_1.IntegrationFieldsContent.is(content)) { | ||
return (0, nestable_2.IntegrationFieldsRenderer)(ctx).renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.SeparatorDefType && | ||
nestable_1.SeparatorContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.SeparatorDefType && nestable_1.SeparatorContent.is(content)) { | ||
return nestable_2.SeparatorRenderer.renderV2(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.BooleanFieldDefType && | ||
nestable_1.BooleanContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.BooleanFieldDefType && nestable_1.BooleanContent.is(content)) { | ||
return nestable_2.BooleanRenderer.renderV2(def, content); | ||
@@ -110,27 +110,27 @@ } | ||
renderDefault(def) { | ||
if (def.__TYPE__ === ApiModel_1.LinkDefType) { | ||
if (def.__TYPE__ === models_1.LinkDefType) { | ||
return (0, nestable_2.LinkRenderer)(ctx).renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.EmbedDefType) { | ||
else if (def.__TYPE__ === models_1.EmbedDefType) { | ||
return nestable_2.EmbedRenderer.renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.GeoPointDefType) { | ||
else if (def.__TYPE__ === models_1.GeoPointDefType) { | ||
return nestable_2.GeoPointRenderer.renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.StructuredTextDefType) { | ||
else if (def.__TYPE__ === models_1.StructuredTextDefType) { | ||
return (0, nestable_2.StructuredTextRenderer)(ctx).renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.ImageDefType) { | ||
else if (def.__TYPE__ === models_1.ImageDefType) { | ||
return (0, nestable_2.ImageRenderer)(ctx).renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.SeparatorDefType) { | ||
else if (def.__TYPE__ === models_1.SeparatorDefType) { | ||
return nestable_2.SeparatorRenderer.renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.UIDDefType) { | ||
else if (def.__TYPE__ === models_1.UIDDefType) { | ||
return UIDRenderer_1.default.renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.BooleanFieldDefType) { | ||
else if (def.__TYPE__ === models_1.BooleanFieldDefType) { | ||
return nestable_2.BooleanRenderer.renderDefault(def); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.IntegrationFieldDefType) { | ||
else if (def.__TYPE__ === models_1.IntegrationFieldDefType) { | ||
return (0, nestable_2.IntegrationFieldsRenderer)(ctx).renderDefault(def); | ||
@@ -143,32 +143,27 @@ } | ||
renderMocks(def, content) { | ||
if (def.__TYPE__ === ApiModel_1.StructuredTextDefType && | ||
nestable_1.StructuredTextContent.is(content)) { | ||
if (def.__TYPE__ === models_1.StructuredTextDefType && nestable_1.StructuredTextContent.is(content)) { | ||
return (0, nestable_2.StructuredTextRenderer)(ctx).renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.ImageDefType && nestable_1.ImageContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.ImageDefType && nestable_1.ImageContent.is(content)) { | ||
return (0, nestable_2.ImageRenderer)(ctx).renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.LinkDefType && nestable_1.Links.LinkContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.LinkDefType && nestable_1.Links.LinkContent.is(content)) { | ||
return (0, nestable_2.LinkRenderer)(ctx).renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.EmbedDefType && nestable_1.EmbedContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.EmbedDefType && nestable_1.EmbedContent.is(content)) { | ||
return nestable_2.EmbedRenderer.renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.GeoPointDefType && | ||
nestable_1.GeoPointContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.GeoPointDefType && nestable_1.GeoPointContent.is(content)) { | ||
return nestable_2.GeoPointRenderer.renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.UIDDefType && widgets_1.UIDContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.UIDDefType && widgets_1.UIDContent.is(content)) { | ||
return UIDRenderer_1.default.renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.IntegrationFieldDefType && | ||
nestable_1.IntegrationFieldsContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.IntegrationFieldDefType && nestable_1.IntegrationFieldsContent.is(content)) { | ||
return (0, nestable_2.IntegrationFieldsRenderer)(ctx).renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.SeparatorDefType && | ||
nestable_1.SeparatorContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.SeparatorDefType && nestable_1.SeparatorContent.is(content)) { | ||
return nestable_2.SeparatorRenderer.renderMocks(def, content); | ||
} | ||
else if (def.__TYPE__ === ApiModel_1.BooleanFieldDefType && | ||
nestable_1.BooleanContent.is(content)) { | ||
else if (def.__TYPE__ === models_1.BooleanFieldDefType && nestable_1.BooleanContent.is(content)) { | ||
return nestable_2.BooleanRenderer.renderMocks(def, content); | ||
@@ -175,0 +170,0 @@ } |
import type { CompositeSliceContent } from "@prismicio/types-internal/lib/documents/widgets/slices"; | ||
import type { RenderContext } from "../../models"; | ||
import type { CompositeSliceDefO } from "../../models/ApiModel"; | ||
import type { CompositeSliceDefO, RenderContext } from "../../models"; | ||
import { CompositeSlice } from "../../models/fetch"; | ||
@@ -5,0 +4,0 @@ import type { SliceRenderer } from "../../models/Renderer"; |
import type { SharedSliceContent } from "@prismicio/types-internal/lib/documents/widgets/slices"; | ||
import type { RenderContext } from "../../models"; | ||
import type { SharedSliceDefO } from "../../models/ApiModel"; | ||
import type { RenderContext, SharedSliceDefO } from "../../models"; | ||
import type { SharedSlice } from "../../models/fetch"; | ||
@@ -5,0 +4,0 @@ import type { SliceRenderer } from "../../models/Renderer"; |
import type { SimpleSliceContent } from "@prismicio/types-internal/lib/documents/widgets/slices"; | ||
import type { RenderContext } from "../../models"; | ||
import type { SimpleSliceDefO } from "../../models/ApiModel"; | ||
import type { RenderContext, SimpleSliceDefO } from "../../models"; | ||
import type { GroupOrField } from "../../models/fetch"; | ||
@@ -5,0 +4,0 @@ import type { SliceRenderer } from "../../models/Renderer"; |
import type { SlicesContent } from "@prismicio/types-internal/lib/documents/widgets/slices"; | ||
import type { RenderContext } from "../../models"; | ||
import type { SlicesDefO } from "../../models/ApiModel"; | ||
import type { Renderer, SlicesDefO } from "../../models"; | ||
import type { SliceZone } from "../../models/fetch"; | ||
import type { Renderer } from "../../models/Renderer"; | ||
declare const SlicesRenderer: (ctx: RenderContext) => Renderer<SlicesDefO, SlicesContent, SliceZone>; | ||
export default SlicesRenderer; |
@@ -8,4 +8,11 @@ "use strict"; | ||
const O = (0, tslib_1.__importStar)(require("fp-ts/Option")); | ||
const uuid_1 = require("uuid"); | ||
const utils_1 = require("../../utils"); | ||
const SliceWidgetRenderer_1 = (0, tslib_1.__importDefault)(require("./SliceWidgetRenderer")); | ||
function sliceId(sliceKey, sliceName) { | ||
const IdRegexp = new RegExp(`^(${sliceName})\\$\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$`); | ||
if (sliceKey.match(IdRegexp)) | ||
return sliceKey; | ||
return `${sliceName}$${(0, uuid_1.v4)()}`; | ||
} | ||
function renderItemAndFilterOutEmptyOne(slicesContent, sliceFetch, ctx) { | ||
@@ -19,4 +26,3 @@ const fetchRecord = sliceFetch === null || sliceFetch === void 0 ? void 0 : sliceFetch.slices; | ||
function renderContent(slice, sliceFetch, ctx, keyToSliceDef) { | ||
if ("__TYPE__" in slice.widget && | ||
slice.widget.__TYPE__ === EmptyContent_1.EmptyContentType) { | ||
if ("__TYPE__" in slice.widget && slice.widget.__TYPE__ === EmptyContent_1.EmptyContentType) { | ||
return O.none; | ||
@@ -33,2 +39,3 @@ } | ||
...render, | ||
slice_id: sliceId(slice.key, slice.name), | ||
slice_type: slice.name, | ||
@@ -48,2 +55,3 @@ slice_label: (_a = slice.maybeLabel) !== null && _a !== void 0 ? _a : null, | ||
...renderedItem, | ||
slice_id: sliceId(item.key, item.name), | ||
slice_type: item.name, | ||
@@ -50,0 +58,0 @@ slice_label: (_a = item.maybeLabel) !== null && _a !== void 0 ? _a : null, |
import { type SliceWidgetContent } from "@prismicio/types-internal/lib/documents/widgets/slices"; | ||
import type { RenderContext } from "../../models"; | ||
import { SliceDefO } from "../../models/ApiModel"; | ||
import { SliceDefO } from "../../models"; | ||
import { GroupOrField, Slice } from "../../models/fetch"; | ||
@@ -5,0 +5,0 @@ import type { SliceRenderer } from "../../models/Renderer"; |
@@ -6,3 +6,3 @@ "use strict"; | ||
const O = (0, tslib_1.__importStar)(require("fp-ts/lib/Option")); | ||
const ApiModel_1 = require("../../models/ApiModel"); | ||
const models_1 = require("../../models"); | ||
const fetch_1 = require("../../models/fetch"); | ||
@@ -26,5 +26,3 @@ const CompositeSliceRenderer_1 = (0, tslib_1.__importDefault)(require("./CompositeSliceRenderer")); | ||
extractGroupOrField(fetch) { | ||
if (fetch !== undefined && | ||
fetch.TYPE !== fetch_1.CompositeSliceType && | ||
fetch.TYPE !== fetch_1.SharedSliceType) { | ||
if (fetch !== undefined && fetch.TYPE !== fetch_1.CompositeSliceType && fetch.TYPE !== fetch_1.SharedSliceType) { | ||
return fetch; | ||
@@ -49,3 +47,3 @@ } | ||
if (content.__TYPE__ === slices_1.CompositeSliceContentType) { | ||
if (def.__TYPE__ === ApiModel_1.CompositeSliceDefType) { | ||
if (def.__TYPE__ === models_1.CompositeSliceDefType) { | ||
return O.some((0, CompositeSliceRenderer_1.default)(ctx).renderV2(def, content, Fetch.extractCompositeSlice(fetch))); | ||
@@ -55,3 +53,3 @@ } | ||
else if (content && content.__TYPE__ === slices_1.SharedSliceContentType) { | ||
if (def.__TYPE__ === ApiModel_1.SharedSliceDefType) { | ||
if (def.__TYPE__ === models_1.SharedSliceDefType) { | ||
return O.some((0, SharedSliceRenderer_1.default)(ctx).renderV2(def, content, Fetch.extractSharedSlice(fetch))); | ||
@@ -61,3 +59,3 @@ } | ||
else { | ||
if (def.__TYPE__ === ApiModel_1.SimpleSliceDefType) { | ||
if (def.__TYPE__ === models_1.SimpleSliceDefType) { | ||
return (0, SimpleSliceRenderer_1.default)(ctx).renderV2(def, content, Fetch.extractGroupOrField(fetch)); | ||
@@ -73,3 +71,3 @@ } | ||
if (content.__TYPE__ === slices_1.CompositeSliceContentType) { | ||
if (def.__TYPE__ === ApiModel_1.CompositeSliceDefType) { | ||
if (def.__TYPE__ === models_1.CompositeSliceDefType) { | ||
return O.some((0, CompositeSliceRenderer_1.default)(ctx).renderMocks(def, content)); | ||
@@ -79,3 +77,3 @@ } | ||
else if (content && content.__TYPE__ === slices_1.SharedSliceContentType) { | ||
if (def.__TYPE__ === ApiModel_1.SharedSliceDefType) { | ||
if (def.__TYPE__ === models_1.SharedSliceDefType) { | ||
return O.some((0, SharedSliceRenderer_1.default)(ctx).renderMocks(def, content)); | ||
@@ -85,3 +83,3 @@ } | ||
else { | ||
if (def.__TYPE__ === ApiModel_1.SimpleSliceDefType) { | ||
if (def.__TYPE__ === models_1.SimpleSliceDefType) { | ||
return (0, SimpleSliceRenderer_1.default)(ctx).renderMocks(def, content); | ||
@@ -88,0 +86,0 @@ } |
import type { StaticWidgetContent } from "@prismicio/types-internal/lib/documents/widgets"; | ||
import type { RenderContext, Renderer } from "../models"; | ||
import { type StaticDefO } from "../models/ApiModel"; | ||
import { type StaticDefO } from "../models"; | ||
import { GroupOrField } from "../models/fetch"; | ||
declare const StaticWidgetRenderer: (ctx: RenderContext) => Renderer<StaticDefO, StaticWidgetContent, GroupOrField>; | ||
export default StaticWidgetRenderer; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const widgets_1 = require("@prismicio/types-internal/lib/documents/widgets"); | ||
const ApiModel_1 = require("../models/ApiModel"); | ||
const models_1 = require("../models"); | ||
const fetch_1 = require("../models/fetch"); | ||
@@ -36,8 +36,7 @@ const GroupRenderer_1 = (0, tslib_1.__importDefault)(require("./GroupRenderer")); | ||
renderV2(def, content, fetch) { | ||
if (widgets_1.SimpleWidgetContent.is(content) && (0, ApiModel_1.isSimpleFieldDef)(def)) { | ||
if (widgets_1.SimpleWidgetContent.is(content) && (0, models_1.isSimpleFieldDef)(def)) { | ||
// todo maybe find an other condition | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)); | ||
} | ||
else if (content.__TYPE__ === widgets_1.WidgetTypes.Group && | ||
def.__TYPE__ === ApiModel_1.GroupDefType) { | ||
else if (content.__TYPE__ === widgets_1.WidgetTypes.Group && def.__TYPE__ === models_1.GroupDefType) { | ||
return (0, GroupRenderer_1.default)(ctx).renderV2(def, content, extractFetchGroupIfAny(fetch)); | ||
@@ -50,3 +49,3 @@ } | ||
renderDefault(def) { | ||
if (def.__TYPE__ === ApiModel_1.GroupDefType) { | ||
if (def.__TYPE__ === models_1.GroupDefType) { | ||
return (0, GroupRenderer_1.default)(ctx).renderDefault(def); | ||
@@ -59,7 +58,6 @@ } | ||
renderMocks(def, content) { | ||
if (widgets_1.SimpleWidgetContent.is(content) && (0, ApiModel_1.isSimpleFieldDef)(def)) { | ||
if (widgets_1.SimpleWidgetContent.is(content) && (0, models_1.isSimpleFieldDef)(def)) { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderMocks(def, content); | ||
} | ||
else if (content.__TYPE__ === widgets_1.WidgetTypes.Group && | ||
def.__TYPE__ === ApiModel_1.GroupDefType) { | ||
else if (content.__TYPE__ === widgets_1.WidgetTypes.Group && def.__TYPE__ === models_1.GroupDefType) { | ||
return (0, GroupRenderer_1.default)(ctx).renderMocks(def, content); | ||
@@ -66,0 +64,0 @@ } |
import { UIDContent } from "@prismicio/types-internal/lib/documents/widgets"; | ||
import type { UIDDefO } from "../models/ApiModel"; | ||
import type { Renderer } from "../models/Renderer"; | ||
import type { Renderer, UIDDefO } from "../models"; | ||
declare const UIDRenderer: Renderer<UIDDefO, UIDContent>; | ||
export default UIDRenderer; |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Prismic renderers for the content API", | ||
@@ -38,4 +38,5 @@ "keywords": [ | ||
"dependencies": { | ||
"@prismicio/types-internal": "0.2.10", | ||
"tslib": "^2.3.1" | ||
"@prismicio/types-internal": "0.2.11", | ||
"tslib": "^2.3.1", | ||
"uuid": "^8.3.2" | ||
}, | ||
@@ -45,2 +46,3 @@ "devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/uuid": "^8.3.4", | ||
"@typescript-eslint/eslint-plugin": "^5.8.1", | ||
@@ -47,0 +49,0 @@ "@typescript-eslint/parser": "^5.8.1", |
@@ -16,6 +16,4 @@ import { | ||
type RenderContext, | ||
CompositeSliceDefType, | ||
Fetch, | ||
} from "./models" | ||
import { | ||
CompositeSliceDefType, | ||
isStaticFieldDef, | ||
@@ -27,3 +25,3 @@ SharedSliceDefType, | ||
WidgetDefO, | ||
} from "./models/ApiModel" | ||
} from "./models" | ||
import { formatDateTime } from "./utils" | ||
@@ -51,18 +49,9 @@ import { SliceWidgetRenderer, StaticWidgetRenderer } from "./widgets" | ||
function renderWidgetV1(ctx: RenderContext) { | ||
return ( | ||
content: WidgetContent, | ||
fetchOpt: Fetch.Field | undefined, | ||
): unknown => { | ||
return (content: WidgetContent, fetchOpt: Fetch.Field | undefined): unknown => { | ||
if (content.__TYPE__ === EmptyContentType) { | ||
return undefined | ||
} else if (StaticWidgetContent.is(content) && !EmptyContent.is(content)) { | ||
return StaticWidgetRenderer(ctx).renderV1( | ||
content, | ||
Fetch.extractGroupOrFieldIfAny(fetchOpt), | ||
) | ||
return StaticWidgetRenderer(ctx).renderV1(content, Fetch.extractGroupOrFieldIfAny(fetchOpt)) | ||
} else { | ||
return SlicesRenderer(ctx).renderV1( | ||
content, | ||
Fetch.extractSliceFetchIfAny(fetchOpt), | ||
) | ||
return SlicesRenderer(ctx).renderV1(content, Fetch.extractSliceFetchIfAny(fetchOpt)) | ||
} | ||
@@ -73,7 +62,3 @@ } | ||
function renderWidgetsV1(ctx: RenderContext) { | ||
return ( | ||
doc: ApiDocument, | ||
content: [string, WidgetContent][], | ||
fetch: Fetch.Doc | undefined, | ||
): unknown => { | ||
return (doc: ApiDocument, content: [string, WidgetContent][], fetch: Fetch.Doc | undefined): unknown => { | ||
const renderedContent: Record<string, unknown> = {} | ||
@@ -86,5 +71,3 @@ for (const [key, widgetContent] of content) { | ||
const newKey = (isDeprecatedArray ? deprecatedArray[1] : key) as string | ||
const maybeContent: undefined | unknown = isDeprecatedArray | ||
? renderedContent[newKey] | ||
: undefined | ||
const maybeContent: undefined | unknown = isDeprecatedArray ? renderedContent[newKey] : undefined | ||
@@ -96,12 +79,6 @@ if (fetch !== undefined) { | ||
renderedContent[newKey] = Array.isArray(maybeContent) | ||
? [ | ||
...(maybeContent as unknown[]), | ||
renderWidgetV1(ctx)(widgetContent, field), | ||
] | ||
? [...(maybeContent as unknown[]), renderWidgetV1(ctx)(widgetContent, field)] | ||
: [renderWidgetV1(ctx)(widgetContent, field)] | ||
} else { | ||
renderedContent[newKey] = renderWidgetV1(ctx)( | ||
widgetContent, | ||
field, | ||
) | ||
renderedContent[newKey] = renderWidgetV1(ctx)(widgetContent, field) | ||
} | ||
@@ -112,12 +89,6 @@ } | ||
renderedContent[newKey] = Array.isArray(maybeContent) | ||
? [ | ||
...(maybeContent as unknown[]), | ||
renderWidgetV1(ctx)(widgetContent, undefined), | ||
] | ||
? [...(maybeContent as unknown[]), renderWidgetV1(ctx)(widgetContent, undefined)] | ||
: [renderWidgetV1(ctx)(widgetContent, undefined)] | ||
} else { | ||
renderedContent[newKey] = renderWidgetV1(ctx)( | ||
widgetContent, | ||
undefined, | ||
) | ||
renderedContent[newKey] = renderWidgetV1(ctx)(widgetContent, undefined) | ||
} | ||
@@ -159,8 +130,4 @@ } | ||
tags: doc.tags, | ||
first_publication_date: doc.first_publication_date | ||
? formatDateTime(doc.first_publication_date) | ||
: null, | ||
last_publication_date: doc.last_publication_date | ||
? formatDateTime(doc.last_publication_date) | ||
: null, | ||
first_publication_date: doc.first_publication_date ? formatDateTime(doc.first_publication_date) : null, | ||
last_publication_date: doc.last_publication_date ? formatDateTime(doc.last_publication_date) : null, | ||
slugs: doc.data.slugs, | ||
@@ -177,22 +144,7 @@ linked_documents: [], | ||
function renderWidgetV2(ctx: RenderContext) { | ||
return ( | ||
mask: WidgetDefO, | ||
content: WidgetContent, | ||
fetchOpt: Fetch.Field | undefined, | ||
): unknown => { | ||
if ( | ||
content.__TYPE__ === SlicesContentType && | ||
mask.__TYPE__ === SlicesDefType | ||
) { | ||
return SlicesRenderer(ctx).renderV2( | ||
mask, | ||
content, | ||
Fetch.extractSliceFetchIfAny(fetchOpt), | ||
) | ||
return (mask: WidgetDefO, content: WidgetContent, fetchOpt: Fetch.Field | undefined): unknown => { | ||
if (content.__TYPE__ === SlicesContentType && mask.__TYPE__ === SlicesDefType) { | ||
return SlicesRenderer(ctx).renderV2(mask, content, Fetch.extractSliceFetchIfAny(fetchOpt)) | ||
} else if (StaticWidgetContent.is(content) && isStaticFieldDef(mask)) { | ||
return StaticWidgetRenderer(ctx).renderV2( | ||
mask, | ||
content, | ||
Fetch.extractGroupOrFieldIfAny(fetchOpt), | ||
) | ||
return StaticWidgetRenderer(ctx).renderV2(mask, content, Fetch.extractGroupOrFieldIfAny(fetchOpt)) | ||
} else { | ||
@@ -218,5 +170,3 @@ return renderDefaultWidget(ctx)(mask) | ||
.map<[string, unknown, boolean] | undefined>((widgetDef: WidgetDef) => { | ||
const filteredWidget = Object.entries(widgetDef).find( | ||
([k]) => k !== "config", | ||
) // name[0] is the SimpleFieldDef name i.e. the widget name and apiId the api id of the field | ||
const filteredWidget = Object.entries(widgetDef).find(([k]) => k !== "config") // name[0] is the SimpleFieldDef name i.e. the widget name and apiId the api id of the field | ||
const name: { apiId: string } | undefined = filteredWidget && { | ||
@@ -232,10 +182,4 @@ apiId: filteredWidget[1] as string, | ||
const deprecatedArray = name.apiId.match(DEPRECATED_ARRAY_REGEX) | ||
const isDeprecatedArray = Boolean( | ||
deprecatedArray && deprecatedArray[1], | ||
) | ||
const newKey = ( | ||
isDeprecatedArray | ||
? (deprecatedArray as RegExpExecArray)[1] | ||
: name.apiId | ||
) as string | ||
const isDeprecatedArray = Boolean(deprecatedArray && deprecatedArray[1]) | ||
const newKey = (isDeprecatedArray ? (deprecatedArray as RegExpExecArray)[1] : name.apiId) as string | ||
@@ -246,7 +190,3 @@ if (correspondingContent) { | ||
newKey, | ||
renderWidgetV2(ctx)( | ||
encodedWidgetDef, | ||
correspondingContent[1], | ||
fetchField, | ||
), | ||
renderWidgetV2(ctx)(encodedWidgetDef, correspondingContent[1], fetchField), | ||
isDeprecatedArray, | ||
@@ -260,7 +200,3 @@ ] | ||
if (fetchDoc === undefined || fetchField !== undefined) { | ||
return [ | ||
newKey, | ||
renderDefaultWidget(ctx)(encodedWidgetDef), | ||
isDeprecatedArray, | ||
] | ||
return [newKey, renderDefaultWidget(ctx)(encodedWidgetDef), isDeprecatedArray] | ||
} else { | ||
@@ -285,7 +221,3 @@ return undefined | ||
} else { | ||
throw new Error( | ||
`[UNEXPECTED ERROR] ${JSON.stringify( | ||
maybeContent, | ||
)} should be an Array`, | ||
) | ||
throw new Error(`[UNEXPECTED ERROR] ${JSON.stringify(maybeContent)} should be an Array`) | ||
} | ||
@@ -322,8 +254,4 @@ } | ||
tags: doc.tags, | ||
first_publication_date: doc.first_publication_date | ||
? formatDateTime(doc.first_publication_date) | ||
: null, | ||
last_publication_date: doc.last_publication_date | ||
? formatDateTime(doc.last_publication_date) | ||
: null, | ||
first_publication_date: doc.first_publication_date ? formatDateTime(doc.first_publication_date) : null, | ||
last_publication_date: doc.last_publication_date ? formatDateTime(doc.last_publication_date) : null, | ||
slugs: doc.data.slugs, | ||
@@ -341,6 +269,3 @@ linked_documents: [], | ||
return (mask: WidgetDefO, content: WidgetContent): unknown => { | ||
if ( | ||
content.__TYPE__ === SlicesContentType && | ||
mask.__TYPE__ === SlicesDefType | ||
) { | ||
if (content.__TYPE__ === SlicesContentType && mask.__TYPE__ === SlicesDefType) { | ||
return SlicesRenderer(ctx).renderMocks(mask, content) | ||
@@ -365,5 +290,3 @@ } else if (StaticWidgetContent.is(content) && isStaticFieldDef(mask)) { | ||
.map<[string, unknown, boolean]>((widgetDef: WidgetDef) => { | ||
const filteredWidget = Object.entries(widgetDef).find( | ||
([k]) => k !== "config", | ||
) // name[0] is the SimpleFieldDef name i.e. the widget name and apiId the api id of the field | ||
const filteredWidget = Object.entries(widgetDef).find(([k]) => k !== "config") // name[0] is the SimpleFieldDef name i.e. the widget name and apiId the api id of the field | ||
const name: { apiId: string } | undefined = filteredWidget && { | ||
@@ -378,23 +301,9 @@ apiId: filteredWidget[1] as string, | ||
const deprecatedArray = name.apiId.match(DEPRECATED_ARRAY_REGEX) | ||
const isDeprecatedArray = Boolean( | ||
deprecatedArray && deprecatedArray[1], | ||
) | ||
const newKey = ( | ||
isDeprecatedArray | ||
? (deprecatedArray as RegExpExecArray)[1] | ||
: name.apiId | ||
) as string | ||
const isDeprecatedArray = Boolean(deprecatedArray && deprecatedArray[1]) | ||
const newKey = (isDeprecatedArray ? (deprecatedArray as RegExpExecArray)[1] : name.apiId) as string | ||
if (correspondingContent) { | ||
return [ | ||
newKey, | ||
renderWidgetMocks(ctx)(encodedWidgetDef, correspondingContent[1]), | ||
isDeprecatedArray, | ||
] | ||
return [newKey, renderWidgetMocks(ctx)(encodedWidgetDef, correspondingContent[1]), isDeprecatedArray] | ||
} else { | ||
return [ | ||
newKey, | ||
renderDefaultWidget(ctx)(encodedWidgetDef), | ||
isDeprecatedArray, | ||
] | ||
return [newKey, renderDefaultWidget(ctx)(encodedWidgetDef), isDeprecatedArray] | ||
} | ||
@@ -416,7 +325,3 @@ } | ||
} else { | ||
throw new Error( | ||
`[UNEXPECTED ERROR] ${JSON.stringify( | ||
maybeContent, | ||
)} should be an Array`, | ||
) | ||
throw new Error(`[UNEXPECTED ERROR] ${JSON.stringify(maybeContent)} should be an Array`) | ||
} | ||
@@ -423,0 +328,0 @@ } |
import { DocumentData } from "@prismicio/types-internal/lib/documents" | ||
import type { | ||
WidgetContent, | ||
WidgetKey, | ||
} from "@prismicio/types-internal/lib/documents/widgets" | ||
import type { WidgetContent, WidgetKey } from "@prismicio/types-internal/lib/documents/widgets" | ||
import type * as O from "fp-ts/lib/Option" | ||
export class DocumentContent { | ||
@@ -19,4 +17,3 @@ fieldTypes: Map<WidgetKey, string> | ||
constructor(data: { [p: string]: unknown }) { | ||
const { widgets, types, positions, slugs, uid } = | ||
DocumentData.partitionData(data) | ||
const { widgets, types, positions, slugs, uid } = DocumentData.partitionData(data) | ||
this.fieldTypes = types | ||
@@ -30,17 +27,9 @@ this.fieldPositions = positions | ||
getWidget(key: string): O.Option<WidgetContent> { | ||
return DocumentData.getWidget( | ||
key, | ||
this.widgets, | ||
this.fieldTypes, | ||
this.fieldPositions, | ||
this.parsed, | ||
) | ||
const widget = DocumentData.getWidget(key, this.widgets, this.fieldTypes, this.fieldPositions, this.parsed) | ||
this.parsed.set(key, widget) | ||
return widget | ||
} | ||
parseAll(): DocumentData { | ||
const parsed = DocumentData.fromJson( | ||
this.widgets, | ||
this.fieldTypes, | ||
this.fieldPositions, | ||
) | ||
const parsed = DocumentData.fromJson(this.widgets, this.fieldTypes, this.fieldPositions) | ||
this.parsed = parsed | ||
@@ -47,0 +36,0 @@ return parsed |
@@ -1,5 +0,2 @@ | ||
import { | ||
DateFromStringOrNumber, | ||
Function, | ||
} from "@prismicio/types-internal/lib/validators" | ||
import { DateFromStringOrNumber, Function } from "@prismicio/types-internal/lib/validators" | ||
import { either } from "fp-ts" | ||
@@ -30,6 +27,3 @@ import { pipe } from "fp-ts/function" | ||
last_publication_date: Function.nullable(DateFromStringOrNumber), | ||
metadata: withFallback( | ||
Function.nullable(DocumentMetadata.codec), | ||
DocumentMetadata.empty, | ||
), | ||
metadata: withFallback(Function.nullable(DocumentMetadata.codec), DocumentMetadata.empty), | ||
}), | ||
@@ -36,0 +30,0 @@ ]), |
@@ -9,18 +9,4 @@ import type { ColorDef, ColorDefO } from "./Color" | ||
export type FieldDef = | ||
| TextDef | ||
| DateDef | ||
| TimestampDef | ||
| ColorDef | ||
| NumberDef | ||
| RangeDef | ||
| SelectDef | ||
export type FieldDef = TextDef | DateDef | TimestampDef | ColorDef | NumberDef | RangeDef | SelectDef | ||
export type FieldDefO = | ||
| TextDefO | ||
| DateDefO | ||
| TimestampDefO | ||
| ColorDefO | ||
| NumberDefO | ||
| RangeDefO | ||
| SelectDefO | ||
export type FieldDefO = TextDefO | DateDefO | TimestampDefO | ColorDefO | NumberDefO | RangeDefO | SelectDefO |
@@ -20,5 +20,3 @@ import type { Group } from "@prismicio/types-internal/lib/customtypes/widgets" | ||
export function fromGroup(key: string, model: Group): GroupDef { | ||
const fields = Object.entries(model.config?.fields || {}).map(([key, f]) => | ||
fromSimpleField(key, f), | ||
) | ||
const fields = Object.entries(model.config?.fields || {}).map(([key, f]) => fromSimpleField(key, f)) | ||
return { | ||
@@ -25,0 +23,0 @@ name: key, |
@@ -15,6 +15,3 @@ import type { CustomType } from "@prismicio/types-internal/lib/customtypes" | ||
export function fromCustomType( | ||
model: CustomType, | ||
sharedSlices: Partial<Record<string, SharedSlice>>, | ||
): ApiModel { | ||
export function fromCustomType(model: CustomType, sharedSlices: Partial<Record<string, SharedSlice>>): ApiModel { | ||
const flattenWidgets = Object.values(model.json) | ||
@@ -24,5 +21,3 @@ .map((tab) => Object.entries(tab)) | ||
const definitions = flattenWidgets.map(([key, widget]) => | ||
fromWidget(key, widget, sharedSlices), | ||
) | ||
const definitions = flattenWidgets.map(([key, widget]) => fromWidget(key, widget, sharedSlices)) | ||
return { | ||
@@ -29,0 +24,0 @@ id: model.id, |
@@ -9,4 +9,3 @@ import * as t from "io-ts" | ||
}), | ||
(o) => | ||
({ name: o.integrationFields, __TYPE__: IntegrationFieldDefType } as const), | ||
(o) => ({ name: o.integrationFields, __TYPE__: IntegrationFieldDefType } as const), | ||
) | ||
@@ -13,0 +12,0 @@ export type IntegrationFieldDef = t.TypeOf<typeof IntegrationFieldDef> |
import type Link from "@prismicio/types-internal/lib/customtypes/widgets/nestable/Link" | ||
import { | ||
addType, | ||
nullable, | ||
} from "@prismicio/types-internal/lib/validators/function" | ||
import { addType, nullable } from "@prismicio/types-internal/lib/validators/function" | ||
import * as t from "io-ts" | ||
@@ -18,5 +15,4 @@ | ||
export function fromAnyLink(link: Link): AnyLinkDef { | ||
if (link.config?.select) | ||
throw new Error("Invalid link type provided, should not be of type any") | ||
if (link.config?.select) throw new Error("Invalid link type provided, should not be of type any") | ||
return AnyLinkDef.encode({ select: "any" }) | ||
} |
@@ -17,5 +17,3 @@ import type Link from "@prismicio/types-internal/lib/customtypes/widgets/nestable/Link" | ||
if (!("document" === link.config?.select)) | ||
throw new Error( | ||
'Invalid link type provided, should contain { select: "document" }', | ||
) | ||
throw new Error('Invalid link type provided, should contain { select: "document" }') | ||
return DocumentLinkDef.encode({ | ||
@@ -22,0 +20,0 @@ select: "document", |
@@ -7,27 +7,7 @@ import type { Link } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
import { AnyLinkDef, AnyLinkDefType, fromAnyLink } from "./AnyLink" | ||
import { | ||
defaultDocumentLinkDef, | ||
DocumentLinkDef, | ||
DocumentLinkDefType, | ||
fromDocumentLink, | ||
} from "./DocumentLink" | ||
import { | ||
defaultMediaLinkDef, | ||
fromMediaLink, | ||
MediaLinkDef, | ||
MediaLinkDefType, | ||
} from "./MediaLink" | ||
import { | ||
defaultWebLinkDef, | ||
fromWebLink, | ||
WebLinkDef, | ||
WebLinkDefType, | ||
} from "./WebLink" | ||
import { defaultDocumentLinkDef, DocumentLinkDef, DocumentLinkDefType, fromDocumentLink } from "./DocumentLink" | ||
import { defaultMediaLinkDef, fromMediaLink, MediaLinkDef, MediaLinkDefType } from "./MediaLink" | ||
import { defaultWebLinkDef, fromWebLink, WebLinkDef, WebLinkDefType } from "./WebLink" | ||
const LinkDefConfig = t.union([ | ||
MediaLinkDef, | ||
DocumentLinkDef, | ||
WebLinkDef, | ||
AnyLinkDef, | ||
]) | ||
const LinkDefConfig = t.union([MediaLinkDef, DocumentLinkDef, WebLinkDef, AnyLinkDef]) | ||
@@ -80,4 +60,2 @@ type LinkDefConfig = t.OutputOf<typeof LinkDefConfig> | ||
return defaultWebLinkDef() | ||
default: | ||
throw new Error(`[UNREACHABLE] ${type} is unknown`) | ||
} | ||
@@ -93,17 +71,13 @@ })() | ||
export const isMediaLinkDef: (linkDef: LinkDefO) => boolean = ( | ||
linkDef: LinkDefO, | ||
) => linkDef.config.__TYPE__ === MediaLinkDefType | ||
export const isMediaLinkDef: (linkDef: LinkDefO) => boolean = (linkDef: LinkDefO) => | ||
linkDef.config.__TYPE__ === MediaLinkDefType | ||
export const isAnyLinkDef: (linkDef: LinkDefO) => boolean = ( | ||
linkDef: LinkDefO, | ||
) => linkDef.config.__TYPE__ === AnyLinkDefType | ||
export const isAnyLinkDef: (linkDef: LinkDefO) => boolean = (linkDef: LinkDefO) => | ||
linkDef.config.__TYPE__ === AnyLinkDefType | ||
export const isDocumentLinkDef: (linkDef: LinkDefO) => boolean = ( | ||
linkDef: LinkDefO, | ||
) => linkDef.config.__TYPE__ === DocumentLinkDefType | ||
export const isDocumentLinkDef: (linkDef: LinkDefO) => boolean = (linkDef: LinkDefO) => | ||
linkDef.config.__TYPE__ === DocumentLinkDefType | ||
export const isWebLinkDef: (linkDef: LinkDefO) => boolean = ( | ||
linkDef: LinkDefO, | ||
) => linkDef.config.__TYPE__ === WebLinkDefType | ||
export const isWebLinkDef: (linkDef: LinkDefO) => boolean = (linkDef: LinkDefO) => | ||
linkDef.config.__TYPE__ === WebLinkDefType | ||
@@ -110,0 +84,0 @@ export * from "./AnyLink" |
@@ -16,5 +16,3 @@ import type Link from "@prismicio/types-internal/lib/customtypes/widgets/nestable/Link" | ||
if (!("media" === link.config?.select)) | ||
throw new Error( | ||
'Invalid link type provided, should contain { select: "media" }', | ||
) | ||
throw new Error('Invalid link type provided, should contain { select: "media" }') | ||
return MediaLinkDef.encode({ select: "media" }) | ||
@@ -21,0 +19,0 @@ } |
@@ -15,6 +15,3 @@ import type Link from "@prismicio/types-internal/lib/customtypes/widgets/nestable/Link" | ||
export function fromWebLink(link: Link): WebLinkDef { | ||
if (!("web" === link.config?.select)) | ||
throw new Error( | ||
'Invalid link type provided, should contain { select: "web" }', | ||
) | ||
if (!("web" === link.config?.select)) throw new Error('Invalid link type provided, should contain { select: "web" }') | ||
return WebLinkDef.encode({ select: "web" }) | ||
@@ -21,0 +18,0 @@ } |
@@ -13,4 +13,3 @@ import type { Select } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
}), | ||
(o) => | ||
({ name: o.select, config: o.config, __TYPE__: SelectDefType } as const), | ||
(o) => ({ name: o.select, config: o.config, __TYPE__: SelectDefType } as const), | ||
) | ||
@@ -17,0 +16,0 @@ export type SelectDef = t.TypeOf<typeof SelectDef> |
@@ -1,5 +0,2 @@ | ||
import { | ||
type UID, | ||
WidgetTypes, | ||
} from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import { type UID, WidgetTypes } from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import type { NestableWidget } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
@@ -46,6 +43,3 @@ import * as t from "io-ts" | ||
export function fromSimpleField( | ||
key: string, | ||
model: NestableWidget | UID, | ||
): SimpleFieldDef { | ||
export function fromSimpleField(key: string, model: NestableWidget | UID): SimpleFieldDef { | ||
switch (model.type) { | ||
@@ -52,0 +46,0 @@ case WidgetTypes.UID: |
@@ -21,11 +21,6 @@ import { WidgetTypes } from "@prismicio/types-internal/lib/customtypes/widgets" | ||
export function fromCompositeSlice( | ||
key: string, | ||
model: CompositeSlice, | ||
): CompositeSliceDef { | ||
export function fromCompositeSlice(key: string, model: CompositeSlice): CompositeSliceDef { | ||
return { | ||
name: key, | ||
primary: Object.entries(model["non-repeat"] || {}).map(([k, w]) => | ||
fromSimpleField(k, w), | ||
), | ||
primary: Object.entries(model["non-repeat"] || {}).map(([k, w]) => fromSimpleField(k, w)), | ||
items: fromGroup(key, { | ||
@@ -32,0 +27,0 @@ type: WidgetTypes.Group, |
@@ -30,6 +30,3 @@ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes/widgets/slices" | ||
export function fromSharedSlice( | ||
key: string, | ||
model: SharedSlice, | ||
): SharedSliceDef { | ||
export function fromSharedSlice(key: string, model: SharedSlice): SharedSliceDef { | ||
return { | ||
@@ -39,8 +36,4 @@ name: key, | ||
id: v.id, | ||
primary: Object.entries(v.primary || {}).map(([k, w]) => | ||
fromSimpleField(k, w), | ||
), | ||
items: Object.entries(v.items || {}).map(([k, w]) => | ||
fromSimpleField(k, w), | ||
), | ||
primary: Object.entries(v.primary || {}).map(([k, w]) => fromSimpleField(k, w)), | ||
items: Object.entries(v.items || {}).map(([k, w]) => fromSimpleField(k, w)), | ||
version: v.version, | ||
@@ -47,0 +40,0 @@ })), |
@@ -18,6 +18,3 @@ import type { LegacySlice } from "@prismicio/types-internal/lib/customtypes/widgets/slices" | ||
export function fromSimpleSlice( | ||
key: string, | ||
model: LegacySlice, | ||
): SimpleSliceDef { | ||
export function fromSimpleSlice(key: string, model: LegacySlice): SimpleSliceDef { | ||
return { | ||
@@ -24,0 +21,0 @@ name: key, |
@@ -14,14 +14,7 @@ import { | ||
export const SliceDef = t.union([ | ||
SimpleSliceDef, | ||
SharedSliceDef, | ||
CompositeSliceDef, | ||
]) | ||
export const SliceDef = t.union([SimpleSliceDef, SharedSliceDef, CompositeSliceDef]) | ||
export type SliceDef = t.TypeOf<typeof SliceDef> | ||
export type SliceDefO = t.OutputOf<typeof SliceDef> | ||
export function fromSlice( | ||
key: string, | ||
model: SharedSlice | CompositeSlice | LegacySlice, | ||
): SliceDef { | ||
export function fromSlice(key: string, model: SharedSlice | CompositeSlice | LegacySlice): SliceDef { | ||
switch (model.type) { | ||
@@ -28,0 +21,0 @@ case SlicesTypes.SharedSlice: |
@@ -1,5 +0,2 @@ | ||
import { | ||
SharedSlice, | ||
SlicesTypes, | ||
} from "@prismicio/types-internal/lib/customtypes/widgets/slices" | ||
import { SharedSlice, SlicesTypes } from "@prismicio/types-internal/lib/customtypes/widgets/slices" | ||
import type { DynamicSlices } from "@prismicio/types-internal/lib/customtypes/widgets/slices/Slices" | ||
@@ -6,0 +3,0 @@ import { addType } from "@prismicio/types-internal/lib/validators/function" |
@@ -1,6 +0,2 @@ | ||
import { | ||
type Group, | ||
type UID, | ||
WidgetTypes, | ||
} from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import { type Group, type UID, WidgetTypes } from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import type { NestableWidget } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
@@ -10,7 +6,3 @@ import * as t from "io-ts" | ||
import { fromGroup, GroupDef, GroupDefType } from "./Group" | ||
import { | ||
type SimpleFieldDefO, | ||
fromSimpleField, | ||
SimpleFieldDef, | ||
} from "./SimpleField" | ||
import { type SimpleFieldDefO, fromSimpleField, SimpleFieldDef } from "./SimpleField" | ||
@@ -21,12 +13,7 @@ export const StaticDef = t.union([GroupDef, SimpleFieldDef]) | ||
export function isSimpleFieldDef( | ||
staticDef: StaticDefO, | ||
): staticDef is SimpleFieldDefO { | ||
export function isSimpleFieldDef(staticDef: StaticDefO): staticDef is SimpleFieldDefO { | ||
return staticDef.__TYPE__ !== GroupDefType | ||
} | ||
export function fromStatic( | ||
key: string, | ||
model: NestableWidget | UID | Group, | ||
): StaticDef { | ||
export function fromStatic(key: string, model: NestableWidget | UID | Group): StaticDef { | ||
switch (model.type) { | ||
@@ -33,0 +20,0 @@ case WidgetTypes.Group: |
@@ -1,6 +0,2 @@ | ||
import { | ||
type Group, | ||
type UID, | ||
WidgetTypes, | ||
} from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import { type Group, type UID, WidgetTypes } from "@prismicio/types-internal/lib/customtypes/widgets" | ||
import type { NestableWidget } from "@prismicio/types-internal/lib/customtypes/widgets/nestable" | ||
@@ -7,0 +3,0 @@ import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes/widgets/slices" |
const DOC_SEPARATOR = "%%" | ||
export function encodeDocId( | ||
documentId: string, | ||
maybeAdditionalData: string | undefined, | ||
): string { | ||
export function encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string { | ||
return `${documentId}${DOC_SEPARATOR}${maybeAdditionalData ?? ""}` | ||
} | ||
export function decodeDocId( | ||
id: string, | ||
handlerType: string, | ||
): [string, string?] { | ||
export function decodeDocId(id: string, handlerType: string): [string, string?] { | ||
const [docId, maybeAdditionalData] = id.split(DOC_SEPARATOR) | ||
@@ -19,5 +13,3 @@ | ||
} else { | ||
throw new Error( | ||
`Unable to read from for extension ${handlerType} with encoded api key ${id}`, | ||
) | ||
throw new Error(`Unable to read from for extension ${handlerType} with encoded api key ${id}`) | ||
} | ||
@@ -40,5 +32,3 @@ } | ||
} else { | ||
throw new Error( | ||
`ID is too long. Its size is ${idLength} and should be inferior to 1000`, | ||
) | ||
throw new Error(`ID is too long. Its size is ${idLength} and should be inferior to 1000`) | ||
} | ||
@@ -45,0 +35,0 @@ }, |
@@ -28,11 +28,6 @@ import * as t from "io-ts" | ||
export type GroupOrField = Simple | Group | ||
export const GroupOrFieldC: t.Type<GroupOrField> = t.recursion( | ||
"GroupOrField", | ||
() => t.union([Simple, Group]), | ||
) | ||
export const GroupOrFieldC: t.Type<GroupOrField> = t.recursion("GroupOrField", () => t.union([Simple, Group])) | ||
export type Field = GroupOrField | SliceZone | ||
export const FieldC: t.Type<Field> = t.recursion("Field", () => | ||
t.union([GroupOrFieldC, SliceZone]), | ||
) | ||
export const FieldC: t.Type<Field> = t.recursion("Field", () => t.union([GroupOrFieldC, SliceZone])) | ||
@@ -120,13 +115,10 @@ export const SliceZoneType = "SliceZone" | ||
export const DocRelationC: t.Type<DocRelation> = t.recursion( | ||
"DocRelation", | ||
() => { | ||
return t.strict({ | ||
TYPE: t.literal(DocRelationType), | ||
name: t.string, | ||
uuid: t.string, | ||
fields: t.record(t.string, t.record(t.string, FieldC)), | ||
}) | ||
}, | ||
) | ||
export const DocRelationC: t.Type<DocRelation> = t.recursion("DocRelation", () => { | ||
return t.strict({ | ||
TYPE: t.literal(DocRelationType), | ||
name: t.string, | ||
uuid: t.string, | ||
fields: t.record(t.string, t.record(t.string, FieldC)), | ||
}) | ||
}) | ||
@@ -155,6 +147,3 @@ export type Simple = DocRelation | SimpleField | ||
t.strict({ | ||
docs: t.record( | ||
t.string, | ||
t.union([DocRelationC, SimpleField, Group, SliceZone]), | ||
), | ||
docs: t.record(t.string, t.union([DocRelationC, SimpleField, Group, SliceZone])), | ||
docRelationsMap: t.record(t.string, DocRelationC), | ||
@@ -167,10 +156,6 @@ }), | ||
export function extractGroupOrFieldIfAny( | ||
fetchOpt: Field | undefined, | ||
): GroupOrField | undefined { | ||
export function extractGroupOrFieldIfAny(fetchOpt: Field | undefined): GroupOrField | undefined { | ||
if ( | ||
fetchOpt !== undefined && | ||
(fetchOpt.TYPE === SimpleFieldType || | ||
fetchOpt.TYPE === DocRelationType || | ||
fetchOpt.TYPE === GroupType) | ||
(fetchOpt.TYPE === SimpleFieldType || fetchOpt.TYPE === DocRelationType || fetchOpt.TYPE === GroupType) | ||
) { | ||
@@ -183,5 +168,3 @@ return fetchOpt | ||
export function extractSliceFetchIfAny( | ||
fetchOpt: Field | undefined, | ||
): SliceZone | undefined { | ||
export function extractSliceFetchIfAny(fetchOpt: Field | undefined): SliceZone | undefined { | ||
if (fetchOpt !== undefined && fetchOpt.TYPE === SliceZoneType) { | ||
@@ -188,0 +171,0 @@ return fetchOpt |
@@ -9,6 +9,3 @@ import type { ApiDocument } from "./ApiDocument" | ||
DocEncoder: { | ||
encodeDocId( | ||
documentId: string, | ||
maybeAdditionalData: string | undefined, | ||
): string | ||
encodeDocId(documentId: string, maybeAdditionalData: string | undefined): string | ||
} | ||
@@ -15,0 +12,0 @@ encoders: { |
@@ -10,17 +10,6 @@ import type { WidgetContent } from "@prismicio/types-internal/lib/documents/widgets" | ||
import type { | ||
AnyLinkDef, | ||
DocumentLinkDef, | ||
MediaLinkDef, | ||
SliceDefO, | ||
WebLinkDef, | ||
WidgetDefO, | ||
} from "./ApiModel" | ||
import type { AnyLinkDef, DocumentLinkDef, MediaLinkDef, SliceDefO, WebLinkDef, WidgetDefO } from "./ApiModel" | ||
import type { Field, GroupOrField, Slice } from "./fetch" | ||
export interface Renderer< | ||
D extends WidgetDefO, | ||
C extends WidgetContent, | ||
F extends Field | undefined = undefined, | ||
> { | ||
export interface Renderer<D extends WidgetDefO, C extends WidgetContent, F extends Field | undefined = undefined> { | ||
renderV1(content: C, fetch?: F | undefined): unknown | ||
@@ -38,15 +27,7 @@ renderV2(definition: D, content: C, fetch?: F | undefined): unknown | ||
renderV1(content: C, fetch?: F | undefined): unknown | ||
renderV2( | ||
definition: D | AnyLinkDef, | ||
content: C, | ||
fetch?: F | undefined, | ||
): unknown | ||
renderV2(definition: D | AnyLinkDef, content: C, fetch?: F | undefined): unknown | ||
renderMocks(definition: D | AnyLinkDef, content: C): unknown | ||
} | ||
export interface SliceRenderer< | ||
D extends SliceDefO, | ||
C extends SliceWidgetContent, | ||
F extends Slice | GroupOrField, | ||
> { | ||
export interface SliceRenderer<D extends SliceDefO, C extends SliceWidgetContent, F extends Slice | GroupOrField> { | ||
renderV1(content: C, fetch?: F | undefined): unknown | ||
@@ -53,0 +34,0 @@ renderV2(definition: D, content: C, fetch?: F | undefined): unknown |
@@ -20,6 +20,3 @@ import * as O from "fp-ts/lib/Option" | ||
export function writeEmptyStringOrNull( | ||
s: string | null | undefined, | ||
emptyStringInsteadOfNull: boolean, | ||
): string | null { | ||
export function writeEmptyStringOrNull(s: string | null | undefined, emptyStringInsteadOfNull: boolean): string | null { | ||
if (s === null || s === undefined) { | ||
@@ -26,0 +23,0 @@ return emptyStringInsteadOfNull ? "" : null |
import type { GroupContent } from "@prismicio/types-internal/lib/documents/widgets" | ||
import type { GroupDefO } from "../models/ApiModel" | ||
import type { GroupDefO, Renderer } from "../models" | ||
import type { Group as GroupFetch } from "../models/fetch" | ||
import type RenderContext from "../models/RenderContext" | ||
import type { Renderer } from "../models/Renderer" | ||
import SimpleWidgetRenderer from "./SimpleWidgetRenderer" | ||
const GroupRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<GroupDefO, GroupContent, GroupFetch> = (ctx) => ({ | ||
const GroupRenderer: (ctx: RenderContext) => Renderer<GroupDefO, GroupContent, GroupFetch> = (ctx) => ({ | ||
renderV1(content: GroupContent, fetch?: GroupFetch | undefined): unknown { | ||
@@ -16,6 +13,3 @@ return { | ||
value: content.value.map((items) => { | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1( | ||
items.value, | ||
fetch?.fields, | ||
) | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1(items.value, fetch?.fields) | ||
}), | ||
@@ -25,7 +19,3 @@ } | ||
renderV2( | ||
groupDef: GroupDefO, | ||
content: GroupContent, | ||
fetch?: GroupFetch | undefined, | ||
): unknown { | ||
renderV2(groupDef: GroupDefO, content: GroupContent, fetch?: GroupFetch | undefined): unknown { | ||
return content.value.map((items) => | ||
@@ -54,6 +44,3 @@ SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV2( | ||
return content.value.map((items) => | ||
SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks( | ||
items.value, | ||
def.fields, | ||
), | ||
SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks(items.value, def.fields), | ||
) | ||
@@ -60,0 +47,0 @@ }, |
import type { BooleanContent } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { BooleanFieldDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { BooleanFieldDefO, Renderer } from "../../models" | ||
@@ -6,0 +5,0 @@ const BooleanRenderer: Renderer<BooleanFieldDefO, BooleanContent> = { |
import type { EmbedContentO } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { EmbedDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { EmbedDefO, Renderer } from "../../models" | ||
@@ -6,0 +5,0 @@ const EmbedRenderer: Renderer<EmbedDefO, EmbedContentO> = { |
import type { FieldContent } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { FieldDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { FieldDefO, Renderer } from "../../models" | ||
import { filterDouble, formatDate, formatDateTime } from "../../utils" | ||
@@ -13,6 +12,3 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
return `${year!.padStart(4, "0")}-${month!.padStart(2, "0")}-${day!.padStart( | ||
2, | ||
"0", | ||
)}T00:00:00.000+0000` | ||
return `${year!.padStart(4, "0")}-${month!.padStart(2, "0")}-${day!.padStart(2, "0")}T00:00:00.000+0000` | ||
} | ||
@@ -44,7 +40,3 @@ | ||
} catch (e) { | ||
console.warn( | ||
`Unable to render Date value with ${content.value}: ${( | ||
e as Error | ||
).toString()}`, | ||
) | ||
console.warn(`Unable to render Date value with ${content.value}: ${(e as Error).toString()}`) | ||
return partialResult | ||
@@ -63,7 +55,3 @@ } | ||
} catch (e) { | ||
console.warn( | ||
`Unable to render Timestamp value with ${content.value}: ${( | ||
e as Error | ||
).toString()}`, | ||
) | ||
console.warn(`Unable to render Timestamp value with ${content.value}: ${(e as Error).toString()}`) | ||
return partialResult | ||
@@ -92,7 +80,3 @@ } | ||
} catch (e) { | ||
console.warn( | ||
`Unable to render Date value with ${content.value}: ${( | ||
e as Error | ||
).toString()}`, | ||
) | ||
console.warn(`Unable to render Date value with ${content.value}: ${(e as Error).toString()}`) | ||
return null | ||
@@ -108,7 +92,3 @@ } | ||
} catch (e) { | ||
console.warn( | ||
`Unable to render Timestamp value with ${content.value}: ${( | ||
e as Error | ||
).toString()}`, | ||
) | ||
console.warn(`Unable to render Timestamp value with ${content.value}: ${(e as Error).toString()}`) | ||
return null | ||
@@ -115,0 +95,0 @@ } |
import type { GeoPointContentO } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { GeoPointDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { GeoPointDefO, Renderer } from "../../models" | ||
@@ -6,0 +5,0 @@ const GeoPointRenderer: Renderer<GeoPointDefO, GeoPointContentO> = { |
@@ -1,15 +0,7 @@ | ||
import type { | ||
ImageContentO, | ||
ImageContentView, | ||
} from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { ImageContentO, ImageContentView } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { RenderContext } from "../../models" | ||
import type { ImageDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { ImageDefO, RenderContext, Renderer } from "../../models" | ||
import { writeEmptyStringOrNull } from "../../utils" | ||
function renderImageContentView( | ||
imageContentView: ImageContentView, | ||
ctx: RenderContext, | ||
) { | ||
function renderImageContentView(imageContentView: ImageContentView, ctx: RenderContext) { | ||
return { | ||
@@ -20,10 +12,4 @@ dimensions: { | ||
}, | ||
alt: writeEmptyStringOrNull( | ||
imageContentView.alt, | ||
ctx.emptyStringInsteadOfNull, | ||
), | ||
copyright: writeEmptyStringOrNull( | ||
imageContentView.credits, | ||
ctx.emptyStringInsteadOfNull, | ||
), | ||
alt: writeEmptyStringOrNull(imageContentView.alt, ctx.emptyStringInsteadOfNull), | ||
copyright: writeEmptyStringOrNull(imageContentView.credits, ctx.emptyStringInsteadOfNull), | ||
url: ctx.urlRewriter.rewriteImageUrl(imageContentView), | ||
@@ -33,5 +19,3 @@ } | ||
const ImageRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<ImageDefO, ImageContentO> = (ctx) => ({ | ||
const ImageRenderer: (ctx: RenderContext) => Renderer<ImageDefO, ImageContentO> = (ctx) => ({ | ||
renderV1(content: ImageContentO): unknown { | ||
@@ -38,0 +22,0 @@ if (content.thumbnails) { |
import type { IntegrationFieldsContent } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { IntegrationFieldDefO } from "../../models/ApiModel" | ||
import type { IntegrationFieldDefO, Renderer } from "../../models" | ||
import type RenderContext from "../../models/RenderContext" | ||
import type { Renderer } from "../../models/Renderer" | ||
const IntegrationFieldRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<IntegrationFieldDefO, IntegrationFieldsContent> = (ctx) => ({ | ||
const IntegrationFieldRenderer: (ctx: RenderContext) => Renderer<IntegrationFieldDefO, IntegrationFieldsContent> = ( | ||
ctx, | ||
) => ({ | ||
renderV1(content: IntegrationFieldsContent): unknown { | ||
@@ -24,6 +23,3 @@ try { | ||
renderV2( | ||
_def: IntegrationFieldDefO, | ||
content: IntegrationFieldsContent, | ||
): unknown { | ||
renderV2(_def: IntegrationFieldDefO, content: IntegrationFieldsContent): unknown { | ||
try { | ||
@@ -30,0 +26,0 @@ return ctx.Extension.encoders.integrationFields.encode(content.value) |
@@ -1,10 +0,6 @@ | ||
import { | ||
type DocumentLink, | ||
BROKEN_CUSTOM_TYPE, | ||
} from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import { type DocumentLink, BROKEN_CUSTOM_TYPE } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import type { RenderContext } from "../../../models" | ||
import { AnyLinkDef, DocumentLinkDef } from "../../../models/ApiModel" | ||
import { AnyLinkDef, DocumentLinkDef, LinkRenderer } from "../../../models" | ||
import type { DocRelation } from "../../../models/fetch" | ||
import type { LinkRenderer } from "../../../models/Renderer" | ||
@@ -27,5 +23,5 @@ function brokenLinkV2(id: string): unknown { | ||
const DocumentLinkRenderer: ( | ||
ctx: RenderContext, | ||
) => LinkRenderer<DocumentLinkDef, DocumentLink, DocRelation> = (ctx) => ({ | ||
const DocumentLinkRenderer: (ctx: RenderContext) => LinkRenderer<DocumentLinkDef, DocumentLink, DocRelation> = ( | ||
ctx, | ||
) => ({ | ||
renderV1(link: DocumentLink, fetch: DocRelation | undefined): unknown { | ||
@@ -44,7 +40,3 @@ //todo check fetch type | ||
renderV2( | ||
_def: DocumentLinkDef | AnyLinkDef, | ||
link: DocumentLink, | ||
fetch: DocRelation | undefined, | ||
): unknown { | ||
renderV2(_def: DocumentLinkDef | AnyLinkDef, link: DocumentLink, fetch: DocRelation | undefined): unknown { | ||
//todo check fetch type | ||
@@ -51,0 +43,0 @@ try { |
import type { ExternalLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import type { AnyLinkDef, WebLinkDef } from "../../../models/ApiModel" | ||
import type { LinkRenderer } from "../../../models/Renderer" | ||
import type { AnyLinkDef, LinkRenderer, WebLinkDef } from "../../../models" | ||
const ExternalLinkRenderer: LinkRenderer<WebLinkDef, ExternalLink> = { | ||
renderV1(link: ExternalLink): unknown { | ||
const target = | ||
typeof link.target === "string" ? { target: link.target } : {} | ||
const target = typeof link.target === "string" ? { target: link.target } : {} | ||
return { | ||
@@ -25,6 +23,3 @@ type: "Link.web", | ||
return Object.assign( | ||
partialRender, | ||
typeof link.target === "string" ? { target: link.target } : {}, | ||
) | ||
return Object.assign(partialRender, typeof link.target === "string" ? { target: link.target } : {}) | ||
}, | ||
@@ -31,0 +26,0 @@ |
import type { FileLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import type { RenderContext } from "../../../models" | ||
import type { AnyLinkDef, MediaLinkDef } from "../../../models/ApiModel" | ||
import type { LinkRenderer } from "../../../models/Renderer" | ||
import type { AnyLinkDef, LinkRenderer, MediaLinkDef } from "../../../models" | ||
const FileLinkRenderer: ( | ||
ctx: RenderContext, | ||
) => LinkRenderer<MediaLinkDef, FileLink> = (ctx) => ({ | ||
const FileLinkRenderer: (ctx: RenderContext) => LinkRenderer<MediaLinkDef, FileLink> = (ctx) => ({ | ||
renderV1(link: FileLink): unknown { | ||
@@ -11,0 +8,0 @@ return { |
import type { ImageLink } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import type { RenderContext } from "../../../models" | ||
import type { AnyLinkDef, MediaLinkDef } from "../../../models/ApiModel" | ||
import type { LinkRenderer } from "../../../models/Renderer" | ||
import type { AnyLinkDef, LinkRenderer, MediaLinkDef } from "../../../models" | ||
const ImageLinkRenderer: ( | ||
ctx: RenderContext, | ||
) => LinkRenderer<MediaLinkDef, ImageLink> = (ctx) => ({ | ||
const ImageLinkRenderer: (ctx: RenderContext) => LinkRenderer<MediaLinkDef, ImageLink> = (ctx) => ({ | ||
renderV1(link: ImageLink): unknown { | ||
@@ -11,0 +8,0 @@ return { |
@@ -1,5 +0,2 @@ | ||
import { | ||
type LinkContent, | ||
Link, | ||
} from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import { type LinkContent, Link } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
@@ -24,5 +21,3 @@ import type { RenderContext, Renderer } from "../../../models" | ||
const LinkRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<LinkDefO, LinkContent, DocRelation> = (ctx) => ({ | ||
const LinkRenderer: (ctx: RenderContext) => Renderer<LinkDefO, LinkContent, DocRelation> = (ctx) => ({ | ||
renderV1(link: LinkContent, fetch: DocRelation | undefined): unknown { | ||
@@ -43,41 +38,12 @@ const encoded = Link.encode(link.value) | ||
renderV2( | ||
def: LinkDefO, | ||
content: LinkContent, | ||
fetch: DocRelation | undefined, | ||
): unknown { | ||
renderV2(def: LinkDefO, content: LinkContent, fetch: DocRelation | undefined): unknown { | ||
const encoded = Link.encode(content.value) | ||
if ( | ||
encoded.__TYPE__ === "ImageLink" && | ||
(isMediaLinkDef(def) || isAnyLinkDef(def)) | ||
) { | ||
return ImageLinkRenderer(ctx).renderV2( | ||
def.config as MediaLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
} else if ( | ||
(isDocumentLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "DocumentLink" | ||
) { | ||
return DocumentLinkRenderer(ctx).renderV2( | ||
def.config as DocumentLinkDef | AnyLinkDef, | ||
encoded, | ||
fetch, | ||
) | ||
} else if ( | ||
(isMediaLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "FileLink" | ||
) { | ||
return FileLinkRenderer(ctx).renderV2( | ||
def.config as MediaLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
} else if ( | ||
(isWebLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "ExternalLink" | ||
) { | ||
return ExternalLinkRenderer.renderV2( | ||
def.config as WebLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
if (encoded.__TYPE__ === "ImageLink" && (isMediaLinkDef(def) || isAnyLinkDef(def))) { | ||
return ImageLinkRenderer(ctx).renderV2(def.config as MediaLinkDef | AnyLinkDef, encoded) | ||
} else if ((isDocumentLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "DocumentLink") { | ||
return DocumentLinkRenderer(ctx).renderV2(def.config as DocumentLinkDef | AnyLinkDef, encoded, fetch) | ||
} else if ((isMediaLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "FileLink") { | ||
return FileLinkRenderer(ctx).renderV2(def.config as MediaLinkDef | AnyLinkDef, encoded) | ||
} else if ((isWebLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "ExternalLink") { | ||
return ExternalLinkRenderer.renderV2(def.config as WebLinkDef | AnyLinkDef, encoded) | ||
} else { | ||
@@ -111,34 +77,10 @@ return this.renderDefault(def) | ||
const encoded = Link.encode(content.value) | ||
if ( | ||
encoded.__TYPE__ === "ImageLink" && | ||
(isMediaLinkDef(def) || isAnyLinkDef(def)) | ||
) { | ||
return ImageLinkRenderer(ctx).renderMocks( | ||
def.config as MediaLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
} else if ( | ||
(isDocumentLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "DocumentLink" | ||
) { | ||
return DocumentLinkRenderer(ctx).renderMocks( | ||
def.config as DocumentLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
} else if ( | ||
(isMediaLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "FileLink" | ||
) { | ||
return FileLinkRenderer(ctx).renderMocks( | ||
def.config as MediaLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
} else if ( | ||
(isWebLinkDef(def) || isAnyLinkDef(def)) && | ||
encoded.__TYPE__ === "ExternalLink" | ||
) { | ||
return ExternalLinkRenderer.renderMocks( | ||
def.config as WebLinkDef | AnyLinkDef, | ||
encoded, | ||
) | ||
if (encoded.__TYPE__ === "ImageLink" && (isMediaLinkDef(def) || isAnyLinkDef(def))) { | ||
return ImageLinkRenderer(ctx).renderMocks(def.config as MediaLinkDef | AnyLinkDef, encoded) | ||
} else if ((isDocumentLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "DocumentLink") { | ||
return DocumentLinkRenderer(ctx).renderMocks(def.config as DocumentLinkDef | AnyLinkDef, encoded) | ||
} else if ((isMediaLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "FileLink") { | ||
return FileLinkRenderer(ctx).renderMocks(def.config as MediaLinkDef | AnyLinkDef, encoded) | ||
} else if ((isWebLinkDef(def) || isAnyLinkDef(def)) && encoded.__TYPE__ === "ExternalLink") { | ||
return ExternalLinkRenderer.renderMocks(def.config as WebLinkDef | AnyLinkDef, encoded) | ||
} else { | ||
@@ -152,7 +94,2 @@ return this.renderDefault(def) | ||
export { | ||
DocumentLinkRenderer, | ||
ExternalLinkRenderer, | ||
FileLinkRenderer, | ||
ImageLinkRenderer, | ||
} | ||
export { DocumentLinkRenderer, ExternalLinkRenderer, FileLinkRenderer, ImageLinkRenderer } |
import type { SeparatorContent } from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import type { SeparatorDefO } from "../../models/ApiModel" | ||
import type { Renderer } from "../../models/Renderer" | ||
import type { Renderer, SeparatorDefO } from "../../models" | ||
@@ -6,0 +5,0 @@ const SeparatorRenderer: Renderer<SeparatorDefO, SeparatorContent> = { |
@@ -0,8 +1,3 @@ | ||
import { is, Link, LinkContent, LinksTypes } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import { | ||
is, | ||
Link, | ||
LinkContent, | ||
LinksTypes, | ||
} from "@prismicio/types-internal/lib/documents/widgets/nestable/Link" | ||
import { | ||
type Block, | ||
@@ -15,11 +10,7 @@ checkEmbedBlock, | ||
import { type RenderContext, ApiVersion } from "../../../models" | ||
import { defaultLinkDef } from "../../../models/ApiModel" | ||
import { defaultLinkDef } from "../../../models" | ||
import { writeEmptyStringOrNull } from "../../../utils" | ||
import LinkRenderer from "../Link" | ||
function renderStructuredTextLink( | ||
link: LinkContent, | ||
apiVersion: ApiVersion, | ||
ctx: RenderContext, | ||
) { | ||
function renderStructuredTextLink(link: LinkContent, apiVersion: ApiVersion, ctx: RenderContext) { | ||
const linkType = () => { | ||
@@ -30,5 +21,3 @@ if (is.documentLink(link.value)) return LinksTypes.DocumentLink | ||
if (is.externalLink(link.value)) return LinksTypes.ExternalLink | ||
throw new Error( | ||
`[UNREACHABLE] unknown Link type for ${JSON.stringify(link)}`, | ||
) | ||
throw new Error(`[UNREACHABLE] unknown Link type for ${JSON.stringify(link)}`) | ||
} | ||
@@ -39,7 +28,3 @@ | ||
} else if (apiVersion === ApiVersion.v2) { | ||
return LinkRenderer(ctx).renderV2( | ||
defaultLinkDef(linkType()), | ||
link, | ||
undefined, | ||
) | ||
return LinkRenderer(ctx).renderV2(defaultLinkDef(linkType()), link, undefined) | ||
} else if (apiVersion === ApiVersion.mocks) { | ||
@@ -74,10 +59,4 @@ return LinkRenderer(ctx).renderMocks(defaultLinkDef(linkType()), link) | ||
url: ctx.urlRewriter.rewriteImageUrl(block.data), | ||
alt: writeEmptyStringOrNull( | ||
block.data.alt, | ||
ctx.emptyStringInsteadOfNull, | ||
), | ||
copyright: writeEmptyStringOrNull( | ||
block.data.credits, | ||
ctx.emptyStringInsteadOfNull, | ||
), | ||
alt: writeEmptyStringOrNull(block.data.alt, ctx.emptyStringInsteadOfNull), | ||
copyright: writeEmptyStringOrNull(block.data.credits, ctx.emptyStringInsteadOfNull), | ||
dimensions: { | ||
@@ -84,0 +63,0 @@ width: block.data.width, |
@@ -16,6 +16,3 @@ import { | ||
function renderSummaryJson( | ||
text: StructuredTextContent, | ||
renderer: (text: StructuredTextContent) => unknown, | ||
): unknown { | ||
function renderSummaryJson(text: StructuredTextContent, renderer: (text: StructuredTextContent) => unknown): unknown { | ||
const firstBlock = pipe< | ||
@@ -27,12 +24,7 @@ O.Option<Blocks.TextBlock>, | ||
>( | ||
O.fromNullable( | ||
text.value.find((block: Blocks.Block) => block.type === "header"), | ||
) as O.Option<Blocks.TextBlock>, | ||
O.fromNullable(text.value.find((block: Blocks.Block) => block.type === "header")) as O.Option<Blocks.TextBlock>, | ||
O.alt( | ||
() => | ||
O.fromNullable( | ||
text.value.find( | ||
(block: Blocks.Block) => | ||
block.type !== "embed" && block.type !== "image", | ||
), | ||
text.value.find((block: Blocks.Block) => block.type !== "embed" && block.type !== "image"), | ||
) as O.Option<Blocks.TextBlock>, | ||
@@ -52,19 +44,10 @@ ), | ||
ctx: RenderContext, | ||
) => Renderer<StructuredTextDefO, StructuredTextContent, SimpleField> = ( | ||
ctx, | ||
) => ({ | ||
renderV1( | ||
content: StructuredTextContent, | ||
fetch: SimpleField | undefined, | ||
): unknown { | ||
) => Renderer<StructuredTextDefO, StructuredTextContent, SimpleField> = (ctx) => ({ | ||
renderV1(content: StructuredTextContent, fetch: SimpleField | undefined): unknown { | ||
//TODO: factorize that | ||
const renderedBlocks = content.value.map((block) => | ||
BlockRenderer(ctx).renderBlock(block)(ApiVersion.v1), | ||
) | ||
const renderedBlocks = content.value.map((block) => BlockRenderer(ctx).renderBlock(block)(ApiVersion.v1)) | ||
if (fetch !== undefined && fetch.legacy) { | ||
return renderSummaryJson(content, (text) => | ||
text.value.map((block) => | ||
BlockRenderer(ctx).renderBlock(block)(ApiVersion.v1), | ||
), | ||
text.value.map((block) => BlockRenderer(ctx).renderBlock(block)(ApiVersion.v1)), | ||
) | ||
@@ -79,16 +62,8 @@ } | ||
renderV2( | ||
def: StructuredTextDefO, | ||
content: StructuredTextContent, | ||
fetch: SimpleField | undefined, | ||
): unknown { | ||
renderV2(def: StructuredTextDefO, content: StructuredTextContent, fetch: SimpleField | undefined): unknown { | ||
if (fetch != undefined && fetch.legacy) { | ||
return renderSummaryJson(content, (text) => | ||
this.renderV2(def, text, undefined), | ||
) | ||
return renderSummaryJson(content, (text) => this.renderV2(def, text, undefined)) | ||
} | ||
return content.value.map((block) => | ||
BlockRenderer(ctx).renderBlock(block)(ApiVersion.v2), | ||
) | ||
return content.value.map((block) => BlockRenderer(ctx).renderBlock(block)(ApiVersion.v2)) | ||
}, | ||
@@ -100,9 +75,4 @@ | ||
renderMocks( | ||
_def: StructuredTextDefO, | ||
content: StructuredTextContent, | ||
): unknown { | ||
return content.value.map((block) => | ||
BlockRenderer(ctx).renderBlock(block)(ApiVersion.mocks), | ||
) | ||
renderMocks(_def: StructuredTextDefO, content: StructuredTextContent): unknown { | ||
return content.value.map((block) => BlockRenderer(ctx).renderBlock(block)(ApiVersion.mocks)) | ||
}, | ||
@@ -109,0 +79,0 @@ }) |
import type { SimpleWidgetContent } from "@prismicio/types-internal/lib/documents/widgets" | ||
import { EmptyContent, UIDContent, UIDContentType, WidgetTypes } from "@prismicio/types-internal/lib/documents/widgets" | ||
import { | ||
EmptyContent, | ||
UIDContent, | ||
WidgetTypes, | ||
} from "@prismicio/types-internal/lib/documents/widgets" | ||
import { | ||
BooleanContent, | ||
EmbedContent, | ||
FieldContent, | ||
EmbedContentType, | ||
GeoPointContent, | ||
@@ -16,4 +12,11 @@ ImageContent, | ||
SeparatorContent, | ||
SeparatorContentType, | ||
StructuredTextContent, | ||
StructuredTextContentType, | ||
} from "@prismicio/types-internal/lib/documents/widgets/nestable" | ||
import { BooleanContentType } from "@prismicio/types-internal/lib/documents/widgets/nestable/BooleanContent" | ||
import { GeoPointContentType } from "@prismicio/types-internal/lib/documents/widgets/nestable/GeoPointContent" | ||
import { ImageContentType } from "@prismicio/types-internal/lib/documents/widgets/nestable/ImageContent" | ||
import { IntegrationFieldsContentType } from "@prismicio/types-internal/lib/documents/widgets/nestable/IntegrationFieldsContent" | ||
import { LinkContentType } from "@prismicio/types-internal/lib/documents/widgets/nestable/Link/LinkContent" | ||
import { compact } from "fp-ts/lib/Array" | ||
@@ -23,2 +26,3 @@ import * as O from "fp-ts/lib/Option" | ||
import type { RenderContext } from "../models" | ||
import type { Renderer } from "../models" | ||
import { | ||
@@ -36,11 +40,4 @@ BooleanFieldDefType, | ||
UIDDefType, | ||
} from "../models/ApiModel" | ||
import { | ||
DocRelation, | ||
DocRelationType, | ||
Field, | ||
SimpleField, | ||
SimpleFieldType, | ||
} from "../models/fetch" | ||
import type { Renderer } from "../models/Renderer" | ||
} from "../models" | ||
import { DocRelation, DocRelationType, Field, SimpleField, SimpleFieldType } from "../models/fetch" | ||
import { renderIfNoFetchOrFetchDefined } from "../utils" | ||
@@ -60,5 +57,3 @@ import { | ||
function extractSimpleFieldIfAny( | ||
field: Field | undefined, | ||
): SimpleField | undefined { | ||
function extractSimpleFieldIfAny(field: Field | undefined): SimpleField | undefined { | ||
if (field !== undefined && field.TYPE === SimpleFieldType) { | ||
@@ -71,5 +66,3 @@ return field | ||
function extractFetchDocRelationIfAny( | ||
field: Field | undefined, | ||
): DocRelation | undefined { | ||
function extractFetchDocRelationIfAny(field: Field | undefined): DocRelation | undefined { | ||
if (field !== undefined && field.TYPE === DocRelationType) { | ||
@@ -82,17 +75,9 @@ return field | ||
const SimpleWidgetRenderer: (ctx: RenderContext) => Renderer< | ||
SimpleFieldDefO, | ||
SimpleWidgetContent, | ||
Field | ||
> & { | ||
const SimpleWidgetRenderer: (ctx: RenderContext) => Renderer<SimpleFieldDefO, SimpleWidgetContent, Field> & { | ||
renderObjectOfSimpleWidgetV1( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fetch: Record<string, Field> | undefined, | ||
): object | ||
renderObjectOfSimpleWidgetV2( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fetch: Record<string, Field> | undefined, | ||
@@ -110,5 +95,3 @@ fieldsDef: SimpleFieldDefO[], | ||
renderObjectOfSimpleWidgetMocks( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fieldsDef: SimpleFieldDefO[], | ||
@@ -118,27 +101,21 @@ ): Record<string, unknown> | ||
renderV1(content: SimpleWidgetContent, fetch: Field | undefined): unknown { | ||
if (StructuredTextContent.is(content)) { | ||
return StructuredTextRenderer(ctx).renderV1( | ||
content, | ||
extractSimpleFieldIfAny(fetch), | ||
) | ||
} else if (ImageContent.is(content)) { | ||
if (content.__TYPE__ === StructuredTextContentType) { | ||
return StructuredTextRenderer(ctx).renderV1(content, extractSimpleFieldIfAny(fetch)) | ||
} else if (content.__TYPE__ === ImageContentType) { | ||
return ImageRenderer(ctx).renderV1(content) | ||
} else if (content.__TYPE__ === WidgetTypes.Field) { | ||
return FieldRenderer.renderV1(content as FieldContent) | ||
} else if (Links.LinkContent.is(content)) { | ||
return LinkRenderer(ctx).renderV1( | ||
content, | ||
extractFetchDocRelationIfAny(fetch), | ||
) | ||
} else if (EmbedContent.is(content)) { | ||
return FieldRenderer.renderV1(content) | ||
} else if (content.__TYPE__ === LinkContentType) { | ||
return LinkRenderer(ctx).renderV1(content, extractFetchDocRelationIfAny(fetch)) | ||
} else if (content.__TYPE__ === EmbedContentType) { | ||
return EmbedRenderer.renderV1(content) | ||
} else if (GeoPointContent.is(content)) { | ||
} else if (content.__TYPE__ === GeoPointContentType) { | ||
return GeoPointRenderer.renderV1(content) | ||
} else if (UIDContent.is(content)) { | ||
} else if (content.__TYPE__ === UIDContentType) { | ||
return UIDRenderer.renderV1(content) | ||
} else if (IntegrationFieldsContent.is(content)) { | ||
} else if (content.__TYPE__ === IntegrationFieldsContentType) { | ||
return IntegrationFieldsRenderer(ctx).renderV1(content) | ||
} else if (SeparatorContent.is(content)) { | ||
} else if (content.__TYPE__ === SeparatorContentType) { | ||
return SeparatorRenderer.renderV1(content) | ||
} else if (BooleanContent.is(content)) { | ||
} else if (content.__TYPE__ === BooleanContentType) { | ||
return BooleanRenderer.renderV1(content) | ||
@@ -150,50 +127,23 @@ } else { | ||
renderV2( | ||
def: SimpleFieldDefO, | ||
content: SimpleWidgetContent, | ||
fetch: Field | undefined, | ||
): unknown { | ||
if ( | ||
def.__TYPE__ === StructuredTextDefType && | ||
StructuredTextContent.is(content) | ||
) { | ||
return StructuredTextRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
extractSimpleFieldIfAny(fetch), | ||
) | ||
renderV2(def: SimpleFieldDefO, content: SimpleWidgetContent, fetch: Field | undefined): unknown { | ||
if (def.__TYPE__ === StructuredTextDefType && StructuredTextContent.is(content)) { | ||
return StructuredTextRenderer(ctx).renderV2(def, content, extractSimpleFieldIfAny(fetch)) | ||
} else if (def.__TYPE__ === ImageDefType && ImageContent.is(content)) { | ||
return ImageRenderer(ctx).renderV2(def, content) | ||
} else if (def.__TYPE__ === LinkDefType && Links.LinkContent.is(content)) { | ||
return LinkRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
extractFetchDocRelationIfAny(fetch), | ||
) | ||
return LinkRenderer(ctx).renderV2(def, content, extractFetchDocRelationIfAny(fetch)) | ||
} else if (def.__TYPE__ === EmbedDefType && EmbedContent.is(content)) { | ||
return EmbedRenderer.renderV2(def, content) | ||
} else if ( | ||
def.__TYPE__ === GeoPointDefType && | ||
GeoPointContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === GeoPointDefType && GeoPointContent.is(content)) { | ||
return GeoPointRenderer.renderV2(def, content) | ||
} else if (def.__TYPE__ === UIDDefType && UIDContent.is(content)) { | ||
return UIDRenderer.renderV2(def, content) | ||
} else if ( | ||
def.__TYPE__ === IntegrationFieldDefType && | ||
IntegrationFieldsContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === IntegrationFieldDefType && IntegrationFieldsContent.is(content)) { | ||
return IntegrationFieldsRenderer(ctx).renderV2(def, content) | ||
} else if ( | ||
def.__TYPE__ === SeparatorDefType && | ||
SeparatorContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === SeparatorDefType && SeparatorContent.is(content)) { | ||
return SeparatorRenderer.renderV2(def, content) | ||
} else if ( | ||
def.__TYPE__ === BooleanFieldDefType && | ||
BooleanContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === BooleanFieldDefType && BooleanContent.is(content)) { | ||
return BooleanRenderer.renderV2(def, content) | ||
} else if (content?.__TYPE__ === WidgetTypes.Field) { | ||
return FieldRenderer.renderV2(def as FieldDefO, content as FieldContent) | ||
return FieldRenderer.renderV2(def as FieldDefO, content) | ||
} else { | ||
@@ -229,6 +179,3 @@ return null | ||
renderMocks(def: SimpleFieldDefO, content: SimpleWidgetContent): unknown { | ||
if ( | ||
def.__TYPE__ === StructuredTextDefType && | ||
StructuredTextContent.is(content) | ||
) { | ||
if (def.__TYPE__ === StructuredTextDefType && StructuredTextContent.is(content)) { | ||
return StructuredTextRenderer(ctx).renderMocks(def, content) | ||
@@ -241,29 +188,14 @@ } else if (def.__TYPE__ === ImageDefType && ImageContent.is(content)) { | ||
return EmbedRenderer.renderMocks(def, content) | ||
} else if ( | ||
def.__TYPE__ === GeoPointDefType && | ||
GeoPointContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === GeoPointDefType && GeoPointContent.is(content)) { | ||
return GeoPointRenderer.renderMocks(def, content) | ||
} else if (def.__TYPE__ === UIDDefType && UIDContent.is(content)) { | ||
return UIDRenderer.renderMocks(def, content) | ||
} else if ( | ||
def.__TYPE__ === IntegrationFieldDefType && | ||
IntegrationFieldsContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === IntegrationFieldDefType && IntegrationFieldsContent.is(content)) { | ||
return IntegrationFieldsRenderer(ctx).renderMocks(def, content) | ||
} else if ( | ||
def.__TYPE__ === SeparatorDefType && | ||
SeparatorContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === SeparatorDefType && SeparatorContent.is(content)) { | ||
return SeparatorRenderer.renderMocks(def, content) | ||
} else if ( | ||
def.__TYPE__ === BooleanFieldDefType && | ||
BooleanContent.is(content) | ||
) { | ||
} else if (def.__TYPE__ === BooleanFieldDefType && BooleanContent.is(content)) { | ||
return BooleanRenderer.renderMocks(def, content) | ||
} else if (content?.__TYPE__ === WidgetTypes.Field) { | ||
return FieldRenderer.renderMocks( | ||
def as FieldDefO, | ||
content as FieldContent, | ||
) | ||
return FieldRenderer.renderMocks(def as FieldDefO, content) | ||
} else { | ||
@@ -275,9 +207,6 @@ return null | ||
renderObjectOfSimpleWidgetV1( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fetch: Record<string, Field> | undefined, | ||
): object { | ||
const c: Array<[string, SimpleWidgetContent]> = | ||
content instanceof Array ? content : Object.entries(content) | ||
const c: Array<[string, SimpleWidgetContent]> = content instanceof Array ? content : Object.entries(content) | ||
@@ -291,6 +220,4 @@ return Object.fromEntries( | ||
return renderIfNoFetchOrFetchDefined( | ||
fetch, | ||
key, | ||
(f: Field | undefined) => O.some([key, this.renderV1(widget, f)]), | ||
return renderIfNoFetchOrFetchDefined(fetch, key, (f: Field | undefined) => | ||
O.some([key, this.renderV1(widget, f)]), | ||
) | ||
@@ -303,5 +230,3 @@ }), | ||
renderObjectOfSimpleWidgetV2( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fetch: Record<string, Field> | undefined, | ||
@@ -352,5 +277,3 @@ fieldsDef: SimpleFieldDefO[], | ||
} else { | ||
const renderedO = renderIfNoFetchOrFetchDefined(fetch, key, (f) => | ||
O.some(this.renderV2(def, item, f)), | ||
) | ||
const renderedO = renderIfNoFetchOrFetchDefined(fetch, key, (f) => O.some(this.renderV2(def, item, f))) | ||
if (O.isSome(renderedO)) { | ||
@@ -366,5 +289,3 @@ result[key] = renderedO.value | ||
renderObjectOfSimpleWidgetMocks( | ||
content: | ||
| Array<[string, SimpleWidgetContent]> | ||
| Record<string, SimpleWidgetContent>, | ||
content: Array<[string, SimpleWidgetContent]> | Record<string, SimpleWidgetContent>, | ||
fieldsDef: SimpleFieldDefO[], | ||
@@ -384,5 +305,3 @@ ): Record<string, unknown> { | ||
} else { | ||
const renderedO = renderIfNoFetchOrFetchDefined(undefined, key, () => | ||
O.some(this.renderMocks(def, item)), | ||
) | ||
const renderedO = renderIfNoFetchOrFetchDefined(undefined, key, () => O.some(this.renderMocks(def, item))) | ||
if (O.isSome(renderedO)) { | ||
@@ -389,0 +308,0 @@ result[key] = renderedO.value |
import type { CompositeSliceContent } from "@prismicio/types-internal/lib/documents/widgets/slices" | ||
import type { RenderContext } from "../../models" | ||
import type { CompositeSliceDefO } from "../../models/ApiModel" | ||
import type { CompositeSliceDefO, RenderContext } from "../../models" | ||
import { CompositeSlice, Group, GroupType } from "../../models/fetch" | ||
@@ -12,11 +11,4 @@ import type { SliceRenderer } from "../../models/Renderer" | ||
ctx: RenderContext, | ||
) => SliceRenderer< | ||
CompositeSliceDefO, | ||
CompositeSliceContent, | ||
CompositeSlice | ||
> = (ctx) => ({ | ||
renderV1( | ||
content: CompositeSliceContent, | ||
fetch: CompositeSlice | undefined, | ||
): unknown { | ||
) => SliceRenderer<CompositeSliceDefO, CompositeSliceContent, CompositeSlice> = (ctx) => ({ | ||
renderV1(content: CompositeSliceContent, fetch: CompositeSlice | undefined): unknown { | ||
const repeatFetch = fetch?.repeat?.fields | ||
@@ -26,6 +18,3 @@ const nonRepeatFetch = fetch?.nonRepeat?.fields | ||
const itemsValue = content.repeat.flatMap((groupItem) => { | ||
const rendered = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1( | ||
groupItem.value, | ||
repeatFetch, | ||
) | ||
const rendered = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1(groupItem.value, repeatFetch) | ||
if (isEmpty(rendered)) { | ||
@@ -36,6 +25,3 @@ return [] | ||
}) | ||
const primaryValue = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1( | ||
content.nonRepeat, | ||
nonRepeatFetch, | ||
) | ||
const primaryValue = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1(content.nonRepeat, nonRepeatFetch) | ||
return { | ||
@@ -47,7 +33,3 @@ "non-repeat": primaryValue, | ||
renderV2( | ||
def: CompositeSliceDefO, | ||
content: CompositeSliceContent, | ||
fetch: CompositeSlice | undefined, | ||
): unknown { | ||
renderV2(def: CompositeSliceDefO, content: CompositeSliceContent, fetch: CompositeSlice | undefined): unknown { | ||
const repeatFetch: Group | undefined = | ||
@@ -103,15 +85,7 @@ fetch === undefined | ||
renderMocks( | ||
def: CompositeSliceDefO, | ||
content: CompositeSliceContent, | ||
): unknown { | ||
renderMocks(def: CompositeSliceDefO, content: CompositeSliceContent): unknown { | ||
const itemsValue = content.repeat.map((items) => { | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks( | ||
items.value, | ||
def.items.fields, | ||
) | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks(items.value, def.items.fields) | ||
}) | ||
const primaryValue = SimpleWidgetRenderer( | ||
ctx, | ||
).renderObjectOfSimpleWidgetMocks(content.nonRepeat, def.primary) | ||
const primaryValue = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks(content.nonRepeat, def.primary) | ||
@@ -118,0 +92,0 @@ return { |
import type { SharedSliceContent } from "@prismicio/types-internal/lib/documents/widgets/slices" | ||
import type { RenderContext } from "../../models" | ||
import type { SharedSliceDefO, VariationDef } from "../../models/ApiModel" | ||
import type { RenderContext, SharedSliceDefO, VariationDef } from "../../models" | ||
import type { Field, SharedSlice } from "../../models/fetch" | ||
@@ -17,11 +16,6 @@ import type { SliceRenderer } from "../../models/Renderer" | ||
const SharedSliceRenderer: ( | ||
ctx: RenderContext, | ||
) => SliceRenderer<SharedSliceDefO, SharedSliceContent, SharedSlice> = ( | ||
const SharedSliceRenderer: (ctx: RenderContext) => SliceRenderer<SharedSliceDefO, SharedSliceContent, SharedSlice> = ( | ||
ctx, | ||
) => ({ | ||
renderV1( | ||
content: SharedSliceContent, | ||
fetch: SharedSlice | undefined, | ||
): unknown { | ||
renderV1(content: SharedSliceContent, fetch: SharedSlice | undefined): unknown { | ||
const itemsValue = content.items.map((groupItem) => { | ||
@@ -44,10 +38,4 @@ return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetV1( | ||
renderV2( | ||
def: SharedSliceDefO, | ||
content: SharedSliceContent, | ||
fetch: SharedSlice | undefined, | ||
): unknown { | ||
const variation = def.variations.find( | ||
(variation: VariationDef) => variation.id === content.variation, | ||
) | ||
renderV2(def: SharedSliceDefO, content: SharedSliceContent, fetch: SharedSlice | undefined): unknown { | ||
const variation = def.variations.find((variation: VariationDef) => variation.id === content.variation) | ||
if (variation === undefined) { | ||
@@ -99,5 +87,3 @@ return this.renderDefault(def) | ||
renderMocks(def: SharedSliceDefO, content: SharedSliceContent): unknown { | ||
const variation = def.variations.find( | ||
(variation: VariationDef) => variation.id === content.variation, | ||
) | ||
const variation = def.variations.find((variation: VariationDef) => variation.id === content.variation) | ||
if (variation === undefined) { | ||
@@ -108,10 +94,5 @@ return this.renderDefault(def) | ||
const itemsValue = content.items.map((groupItem) => { | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks( | ||
groupItem.value, | ||
variation.items, | ||
) | ||
return SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks(groupItem.value, variation.items) | ||
}) | ||
const primaryValue = SimpleWidgetRenderer( | ||
ctx, | ||
).renderObjectOfSimpleWidgetMocks(content.primary, variation.primary) | ||
const primaryValue = SimpleWidgetRenderer(ctx).renderObjectOfSimpleWidgetMocks(content.primary, variation.primary) | ||
@@ -118,0 +99,0 @@ return { |
@@ -5,4 +5,3 @@ import { EmptyContentType } from "@prismicio/types-internal/lib/documents/widgets/EmptyContent" | ||
import type { RenderContext } from "../../models" | ||
import type { SimpleSliceDefO } from "../../models/ApiModel" | ||
import type { RenderContext, SimpleSliceDefO } from "../../models" | ||
import type { GroupOrField } from "../../models/fetch" | ||
@@ -12,11 +11,6 @@ import type { SliceRenderer } from "../../models/Renderer" | ||
const SimpleSliceRenderer: ( | ||
ctx: RenderContext, | ||
) => SliceRenderer<SimpleSliceDefO, SimpleSliceContent, GroupOrField> = ( | ||
const SimpleSliceRenderer: (ctx: RenderContext) => SliceRenderer<SimpleSliceDefO, SimpleSliceContent, GroupOrField> = ( | ||
ctx, | ||
) => ({ | ||
renderV1( | ||
content: SimpleSliceContent, | ||
fetch: GroupOrField | undefined, | ||
): unknown { | ||
renderV1(content: SimpleSliceContent, fetch: GroupOrField | undefined): unknown { | ||
if (content.__TYPE__ === EmptyContentType) { | ||
@@ -31,7 +25,3 @@ return O.none | ||
renderV2( | ||
def: SimpleSliceDefO, | ||
content: SimpleSliceContent, | ||
fetch: GroupOrField | undefined, | ||
): unknown { | ||
renderV2(def: SimpleSliceDefO, content: SimpleSliceContent, fetch: GroupOrField | undefined): unknown { | ||
if (content.__TYPE__ === EmptyContentType) { | ||
@@ -38,0 +28,0 @@ return O.none |
import { EmptyContentType } from "@prismicio/types-internal/lib/documents/widgets/EmptyContent" | ||
import type { | ||
SlicesContent, | ||
SlicesContentItem, | ||
} from "@prismicio/types-internal/lib/documents/widgets/slices" | ||
import type { SlicesContent, SlicesContentItem } from "@prismicio/types-internal/lib/documents/widgets/slices" | ||
import { pipe } from "fp-ts/function" | ||
import { compact } from "fp-ts/lib/Array" | ||
import * as O from "fp-ts/Option" | ||
import { v4 as uuid } from "uuid" | ||
import type { RenderContext } from "../../models" | ||
import type { SliceDefO, SlicesDefO } from "../../models/ApiModel" | ||
import type { Renderer, SliceDefO, SlicesDefO } from "../../models" | ||
import type { GroupOrField, Slice, SliceZone } from "../../models/fetch" | ||
import type { Renderer } from "../../models/Renderer" | ||
import { renderIfNoFetchOrFetchDefined } from "../../utils" | ||
import SliceWidgetRenderer from "./SliceWidgetRenderer" | ||
function sliceId(sliceKey: string, sliceName: string): string { | ||
const IdRegexp = new RegExp(`^(${sliceName})\\$\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$`) | ||
if (sliceKey.match(IdRegexp)) return sliceKey | ||
return `${sliceName}$${uuid()}` | ||
} | ||
function renderItemAndFilterOutEmptyOne( | ||
@@ -29,11 +33,5 @@ slicesContent: SlicesContent, | ||
item.key, | ||
(f) => | ||
SliceWidgetRenderer(ctx).renderV1( | ||
item.widget, | ||
f, | ||
) as O.Option<unknown>, | ||
(f) => SliceWidgetRenderer(ctx).renderV1(item.widget, f) as O.Option<unknown>, | ||
), //TODO: add fetch | ||
O.map( | ||
(renderedItem) => [item, renderedItem] as [SlicesContentItem, object], | ||
), | ||
O.map((renderedItem) => [item, renderedItem] as [SlicesContentItem, object]), | ||
) | ||
@@ -50,6 +48,3 @@ }), | ||
): O.Option<unknown> { | ||
if ( | ||
"__TYPE__" in slice.widget && | ||
slice.widget.__TYPE__ === EmptyContentType | ||
) { | ||
if ("__TYPE__" in slice.widget && slice.widget.__TYPE__ === EmptyContentType) { | ||
return O.none | ||
@@ -68,2 +63,3 @@ } else if (!(slice.name in keyToSliceDef)) { | ||
...(render as object), | ||
slice_id: sliceId(slice.key, slice.name), | ||
slice_type: slice.name, | ||
@@ -76,29 +72,20 @@ slice_label: slice.maybeLabel ?? null, | ||
const SlicesRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<SlicesDefO, SlicesContent, SliceZone> = (ctx) => ({ | ||
const SlicesRenderer: (ctx: RenderContext) => Renderer<SlicesDefO, SlicesContent, SliceZone> = (ctx) => ({ | ||
renderV1(content: SlicesContent, fetch: SliceZone | undefined): unknown { | ||
return { | ||
type: "SliceZone", | ||
value: renderItemAndFilterOutEmptyOne(content, fetch, ctx).map( | ||
([item, renderedItem]) => { | ||
return { | ||
...renderedItem, | ||
slice_type: item.name, | ||
slice_label: item.maybeLabel ?? null, | ||
type: "Slice", | ||
} | ||
}, | ||
), | ||
value: renderItemAndFilterOutEmptyOne(content, fetch, ctx).map(([item, renderedItem]) => { | ||
return { | ||
...renderedItem, | ||
slice_id: sliceId(item.key, item.name), | ||
slice_type: item.name, | ||
slice_label: item.maybeLabel ?? null, | ||
type: "Slice", | ||
} | ||
}), | ||
} | ||
}, | ||
renderV2( | ||
def: SlicesDefO, | ||
content: SlicesContent, | ||
fetch: SliceZone | undefined, | ||
): unknown { | ||
const keyToSliceDef = Object.fromEntries( | ||
def.slices.map((slice) => [slice.name, slice]), | ||
) | ||
renderV2(def: SlicesDefO, content: SlicesContent, fetch: SliceZone | undefined): unknown { | ||
const keyToSliceDef = Object.fromEntries(def.slices.map((slice) => [slice.name, slice])) | ||
const fetchRecord = fetch?.slices | ||
@@ -108,6 +95,4 @@ | ||
content.value.map((contentValue) => { | ||
return renderIfNoFetchOrFetchDefined( | ||
fetchRecord, | ||
contentValue.name, | ||
(f) => renderContent(contentValue, f, ctx, keyToSliceDef), | ||
return renderIfNoFetchOrFetchDefined(fetchRecord, contentValue.name, (f) => | ||
renderContent(contentValue, f, ctx, keyToSliceDef), | ||
) | ||
@@ -114,0 +99,0 @@ }), |
@@ -9,9 +9,4 @@ import { | ||
import type { RenderContext } from "../../models" | ||
import { CompositeSliceDefType, SharedSliceDefType, SimpleSliceDefType, SliceDefO } from "../../models" | ||
import { | ||
CompositeSliceDefType, | ||
SharedSliceDefType, | ||
SimpleSliceDefType, | ||
SliceDefO, | ||
} from "../../models/ApiModel" | ||
import { | ||
CompositeSlice, | ||
@@ -30,5 +25,3 @@ CompositeSliceType, | ||
const Fetch = { | ||
extractCompositeSlice( | ||
fetch: GroupOrField | Slice | undefined, | ||
): CompositeSlice | undefined { | ||
extractCompositeSlice(fetch: GroupOrField | Slice | undefined): CompositeSlice | undefined { | ||
if (fetch !== undefined && fetch.TYPE === CompositeSliceType) { | ||
@@ -39,5 +32,3 @@ return fetch | ||
}, | ||
extractSharedSlice( | ||
fetch: GroupOrField | Slice | undefined, | ||
): SharedSlice | undefined { | ||
extractSharedSlice(fetch: GroupOrField | Slice | undefined): SharedSlice | undefined { | ||
if (fetch !== undefined && fetch.TYPE === SharedSliceType) { | ||
@@ -48,10 +39,4 @@ return fetch | ||
}, | ||
extractGroupOrField( | ||
fetch: GroupOrField | Slice | undefined, | ||
): GroupOrField | undefined { | ||
if ( | ||
fetch !== undefined && | ||
fetch.TYPE !== CompositeSliceType && | ||
fetch.TYPE !== SharedSliceType | ||
) { | ||
extractGroupOrField(fetch: GroupOrField | Slice | undefined): GroupOrField | undefined { | ||
if (fetch !== undefined && fetch.TYPE !== CompositeSliceType && fetch.TYPE !== SharedSliceType) { | ||
return fetch | ||
@@ -65,63 +50,25 @@ } | ||
ctx: RenderContext, | ||
) => SliceRenderer<SliceDefO, SliceWidgetContent, Slice | GroupOrField> = ( | ||
ctx, | ||
) => ({ | ||
renderV1( | ||
content: SliceWidgetContent, | ||
fetch: Slice | GroupOrField | undefined, | ||
): unknown { | ||
) => SliceRenderer<SliceDefO, SliceWidgetContent, Slice | GroupOrField> = (ctx) => ({ | ||
renderV1(content: SliceWidgetContent, fetch: Slice | GroupOrField | undefined): unknown { | ||
if (content.__TYPE__ === CompositeSliceContentType) { | ||
return O.some( | ||
CompositeSliceRenderer(ctx).renderV1( | ||
content, | ||
Fetch.extractCompositeSlice(fetch), | ||
), | ||
) | ||
return O.some(CompositeSliceRenderer(ctx).renderV1(content, Fetch.extractCompositeSlice(fetch))) | ||
} else if (content.__TYPE__ === SharedSliceContentType) { | ||
return O.some( | ||
SharedSliceRenderer(ctx).renderV1( | ||
content, | ||
Fetch.extractSharedSlice(fetch), | ||
), | ||
) | ||
return O.some(SharedSliceRenderer(ctx).renderV1(content, Fetch.extractSharedSlice(fetch))) | ||
} else { | ||
return SimpleSliceRenderer(ctx).renderV1( | ||
content, | ||
Fetch.extractGroupOrField(fetch), | ||
) | ||
return SimpleSliceRenderer(ctx).renderV1(content, Fetch.extractGroupOrField(fetch)) | ||
} | ||
}, | ||
renderV2( | ||
def: SliceDefO, | ||
content: SliceWidgetContent, | ||
fetch: Slice | GroupOrField | undefined, | ||
): unknown { | ||
renderV2(def: SliceDefO, content: SliceWidgetContent, fetch: Slice | GroupOrField | undefined): unknown { | ||
if (content.__TYPE__ === CompositeSliceContentType) { | ||
if (def.__TYPE__ === CompositeSliceDefType) { | ||
return O.some( | ||
CompositeSliceRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
Fetch.extractCompositeSlice(fetch), | ||
), | ||
) | ||
return O.some(CompositeSliceRenderer(ctx).renderV2(def, content, Fetch.extractCompositeSlice(fetch))) | ||
} | ||
} else if (content && content.__TYPE__ === SharedSliceContentType) { | ||
if (def.__TYPE__ === SharedSliceDefType) { | ||
return O.some( | ||
SharedSliceRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
Fetch.extractSharedSlice(fetch), | ||
), | ||
) | ||
return O.some(SharedSliceRenderer(ctx).renderV2(def, content, Fetch.extractSharedSlice(fetch))) | ||
} | ||
} else { | ||
if (def.__TYPE__ === SimpleSliceDefType) { | ||
return SimpleSliceRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
Fetch.extractGroupOrField(fetch), | ||
) | ||
return SimpleSliceRenderer(ctx).renderV2(def, content, Fetch.extractGroupOrField(fetch)) | ||
} | ||
@@ -128,0 +75,0 @@ } |
import type { StaticWidgetContent } from "@prismicio/types-internal/lib/documents/widgets" | ||
import { | ||
GroupContent, | ||
SimpleWidgetContent, | ||
WidgetTypes, | ||
} from "@prismicio/types-internal/lib/documents/widgets" | ||
import { SimpleWidgetContent, WidgetTypes } from "@prismicio/types-internal/lib/documents/widgets" | ||
import type { RenderContext, Renderer } from "../models" | ||
import { | ||
type StaticDefO, | ||
GroupDefType, | ||
isSimpleFieldDef, | ||
} from "../models/ApiModel" | ||
import { type StaticDefO, GroupDefType, isSimpleFieldDef } from "../models" | ||
import { Field, Group, GroupOrField, GroupType } from "../models/fetch" | ||
@@ -18,5 +10,3 @@ import GroupRenderer from "./GroupRenderer" | ||
function extractFetchGroupIfAny( | ||
fetch: GroupOrField | undefined, | ||
): Group | undefined { | ||
function extractFetchGroupIfAny(fetch: GroupOrField | undefined): Group | undefined { | ||
if (fetch !== undefined && fetch.TYPE === GroupType) { | ||
@@ -29,5 +19,3 @@ return fetch | ||
function extractFetchFieldIfAny( | ||
fetch: GroupOrField | undefined, | ||
): Field | undefined { | ||
function extractFetchFieldIfAny(fetch: GroupOrField | undefined): Field | undefined { | ||
if (fetch !== undefined && fetch.TYPE !== GroupType) { | ||
@@ -40,43 +28,19 @@ return fetch | ||
const StaticWidgetRenderer: ( | ||
ctx: RenderContext, | ||
) => Renderer<StaticDefO, StaticWidgetContent, GroupOrField> = (ctx) => ({ | ||
renderV1( | ||
content: StaticWidgetContent, | ||
fetch: GroupOrField | undefined, | ||
): unknown { | ||
const StaticWidgetRenderer: (ctx: RenderContext) => Renderer<StaticDefO, StaticWidgetContent, GroupOrField> = ( | ||
ctx, | ||
) => ({ | ||
renderV1(content: StaticWidgetContent, fetch: GroupOrField | undefined): unknown { | ||
if (content.__TYPE__ === WidgetTypes.Group) { | ||
return GroupRenderer(ctx).renderV1( | ||
content as GroupContent, | ||
extractFetchGroupIfAny(fetch), | ||
) | ||
return GroupRenderer(ctx).renderV1(content, extractFetchGroupIfAny(fetch)) | ||
} else { | ||
return SimpleWidgetRenderer(ctx).renderV1( | ||
content as SimpleWidgetContent, | ||
extractFetchFieldIfAny(fetch), | ||
) | ||
return SimpleWidgetRenderer(ctx).renderV1(content, extractFetchFieldIfAny(fetch)) | ||
} | ||
}, | ||
renderV2( | ||
def: StaticDefO, | ||
content: StaticWidgetContent, | ||
fetch: GroupOrField | undefined, | ||
): unknown { | ||
renderV2(def: StaticDefO, content: StaticWidgetContent, fetch: GroupOrField | undefined): unknown { | ||
if (SimpleWidgetContent.is(content) && isSimpleFieldDef(def)) { | ||
// todo maybe find an other condition | ||
return SimpleWidgetRenderer(ctx).renderV2( | ||
def, | ||
content, | ||
extractFetchFieldIfAny(fetch), | ||
) | ||
} else if ( | ||
content.__TYPE__ === WidgetTypes.Group && | ||
def.__TYPE__ === GroupDefType | ||
) { | ||
return GroupRenderer(ctx).renderV2( | ||
def, | ||
content as GroupContent, | ||
extractFetchGroupIfAny(fetch), | ||
) | ||
return SimpleWidgetRenderer(ctx).renderV2(def, content, extractFetchFieldIfAny(fetch)) | ||
} else if (content.__TYPE__ === WidgetTypes.Group && def.__TYPE__ === GroupDefType) { | ||
return GroupRenderer(ctx).renderV2(def, content, extractFetchGroupIfAny(fetch)) | ||
} else { | ||
@@ -98,7 +62,4 @@ return this.renderDefault(def) | ||
return SimpleWidgetRenderer(ctx).renderMocks(def, content) | ||
} else if ( | ||
content.__TYPE__ === WidgetTypes.Group && | ||
def.__TYPE__ === GroupDefType | ||
) { | ||
return GroupRenderer(ctx).renderMocks(def, content as GroupContent) | ||
} else if (content.__TYPE__ === WidgetTypes.Group && def.__TYPE__ === GroupDefType) { | ||
return GroupRenderer(ctx).renderMocks(def, content) | ||
} else { | ||
@@ -105,0 +66,0 @@ return this.renderDefault(def) |
import { UIDContent } from "@prismicio/types-internal/lib/documents/widgets" | ||
import type { UIDDefO } from "../models/ApiModel" | ||
import type { Renderer } from "../models/Renderer" | ||
import type { Renderer, UIDDefO } from "../models" | ||
@@ -6,0 +5,0 @@ const UIDRenderer: Renderer<UIDDefO, UIDContent> = { |
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
86
492040
6
21
225
14118
+ Addeduuid@^8.3.2
+ Added@prismicio/types-internal@0.2.11(transitive)
+ Addeduuid@8.3.2(transitive)
- Removed@prismicio/types-internal@0.2.10(transitive)