@prismicio/api-renderer
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -87,2 +87,3 @@ "use strict"; | ||
return (doc, content, searchURL, i18n, withMeta, linkResolver, fetchDoc) => { | ||
var _a, _b; | ||
const relatedDocs = (i18n[doc.groupLangId] || []) | ||
@@ -94,8 +95,8 @@ .filter((relatedDocument) => relatedDocument.id !== doc.id) | ||
id: doc.id, | ||
uid: doc.data.uid ?? null, | ||
url: ctx.LinkResolver.buildUrl({ | ||
uid: (_a = doc.data.uid) !== null && _a !== void 0 ? _a : null, | ||
url: (_b = ctx.LinkResolver.buildUrl({ | ||
linkResolver: linkResolver, | ||
pageType: doc.type, | ||
doc, | ||
}) ?? null, | ||
})) !== null && _b !== void 0 ? _b : null, | ||
type: doc.type, | ||
@@ -135,2 +136,3 @@ href: ctx.urlRewriter.enforceCDN(searchURL), | ||
return (mask, doc, content, searchURL, i18n, withMeta, linkResolver, fetchDoc) => { | ||
var _a, _b; | ||
const widgets = mask.definitions | ||
@@ -146,3 +148,3 @@ .filter((def) => Object.keys(def).every((v) => v !== "uid")) | ||
const encodedWidgetDef = ApiModel_1.WidgetDef.encode(widgetDef); | ||
const fetchField = fetchDoc?.fields[name.apiId]; | ||
const fetchField = fetchDoc === null || fetchDoc === void 0 ? void 0 : fetchDoc.fields[name.apiId]; | ||
const deprecatedArray = name.apiId.match(DEPRECATED_ARRAY_REGEX); | ||
@@ -214,8 +216,8 @@ const isDeprecatedArray = Boolean(deprecatedArray && deprecatedArray[1]); | ||
id: doc.id, | ||
uid: doc.data.uid ?? null, | ||
url: ctx.LinkResolver.buildUrl({ | ||
uid: (_a = doc.data.uid) !== null && _a !== void 0 ? _a : null, | ||
url: (_b = ctx.LinkResolver.buildUrl({ | ||
linkResolver: linkResolver, | ||
pageType: doc.type, | ||
doc, | ||
}) ?? null, | ||
})) !== null && _b !== void 0 ? _b : null, | ||
type: doc.type, | ||
@@ -222,0 +224,0 @@ href: ctx.urlRewriter.enforceCDN(searchURL), |
@@ -15,6 +15,7 @@ "use strict"; | ||
function fromBoolean(key, model) { | ||
var _a; | ||
return { | ||
booleanField: key, | ||
config: { | ||
default_value: model.config?.default_value || false, | ||
default_value: ((_a = model.config) === null || _a === void 0 ? void 0 : _a.default_value) || false, | ||
}, | ||
@@ -21,0 +22,0 @@ }; |
@@ -14,3 +14,4 @@ "use strict"; | ||
function fromGroup(key, model) { | ||
const fields = Object.entries(model.config?.fields || {}).map(([key, f]) => (0, SimpleField_1.fromSimpleField)(key, f)); | ||
var _a; | ||
const fields = Object.entries(((_a = model.config) === null || _a === void 0 ? void 0 : _a.fields) || {}).map(([key, f]) => (0, SimpleField_1.fromSimpleField)(key, f)); | ||
return { | ||
@@ -17,0 +18,0 @@ name: key, |
@@ -15,6 +15,7 @@ "use strict"; | ||
function fromImage(key, def) { | ||
var _a, _b; | ||
return { | ||
image: key, | ||
config: { | ||
thumbnails: def.config?.thumbnails?.map((t) => t.name) || [], | ||
thumbnails: ((_b = (_a = def.config) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.map((t) => t.name)) || [], | ||
}, | ||
@@ -21,0 +22,0 @@ }; |
@@ -12,3 +12,4 @@ "use strict"; | ||
function fromAnyLink(link) { | ||
if (link.config?.select) | ||
var _a; | ||
if ((_a = link.config) === null || _a === void 0 ? void 0 : _a.select) | ||
throw new Error("Invalid link type provided, should not be of type any"); | ||
@@ -15,0 +16,0 @@ return exports.AnyLinkDef.encode({ select: "any" }); |
@@ -13,3 +13,4 @@ "use strict"; | ||
function fromDocumentLink(link) { | ||
if (!("document" === link.config?.select)) | ||
var _a; | ||
if (!("document" === ((_a = link.config) === null || _a === void 0 ? void 0 : _a.select))) | ||
throw new Error('Invalid link type provided, should contain { select: "document" }'); | ||
@@ -16,0 +17,0 @@ return exports.DocumentLinkDef.encode({ |
@@ -25,3 +25,4 @@ "use strict"; | ||
const config = (() => { | ||
switch (model.config?.select) { | ||
var _a; | ||
switch ((_a = model.config) === null || _a === void 0 ? void 0 : _a.select) { | ||
case "document": | ||
@@ -28,0 +29,0 @@ return (0, DocumentLink_1.fromDocumentLink)(model); |
@@ -12,3 +12,4 @@ "use strict"; | ||
function fromMediaLink(link) { | ||
if (!("media" === link.config?.select)) | ||
var _a; | ||
if (!("media" === ((_a = link.config) === null || _a === void 0 ? void 0 : _a.select))) | ||
throw new Error('Invalid link type provided, should contain { select: "media" }'); | ||
@@ -15,0 +16,0 @@ return exports.MediaLinkDef.encode({ select: "media" }); |
@@ -12,3 +12,4 @@ "use strict"; | ||
function fromWebLink(link) { | ||
if (!("web" === link.config?.select)) | ||
var _a; | ||
if (!("web" === ((_a = link.config) === null || _a === void 0 ? void 0 : _a.select))) | ||
throw new Error('Invalid link type provided, should contain { select: "web" }'); | ||
@@ -15,0 +16,0 @@ return exports.WebLinkDef.encode({ select: "web" }); |
@@ -15,6 +15,7 @@ "use strict"; | ||
function fromSelect(key, model) { | ||
var _a; | ||
return { | ||
select: key, | ||
config: { | ||
options: model.config?.options || [], | ||
options: ((_a = model.config) === null || _a === void 0 ? void 0 : _a.options) || [], | ||
}, | ||
@@ -21,0 +22,0 @@ }; |
@@ -15,5 +15,6 @@ "use strict"; | ||
function fromSlices(key, model, sharedSlices) { | ||
var _a; | ||
return { | ||
name: key, | ||
slices: Object.entries(model.config?.choices || {}) | ||
slices: Object.entries(((_a = model.config) === null || _a === void 0 ? void 0 : _a.choices) || {}) | ||
.reduce((acc, [key, slice]) => { | ||
@@ -20,0 +21,0 @@ switch (slice.type) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
function encodeDocId(documentId, maybeAdditionalData) { | ||
return `${documentId}${DOC_SEPARATOR}${maybeAdditionalData ?? ""}`; | ||
return `${documentId}${DOC_SEPARATOR}${maybeAdditionalData !== null && maybeAdditionalData !== void 0 ? maybeAdditionalData : ""}`; | ||
} | ||
@@ -9,0 +9,0 @@ exports.encodeDocId = encodeDocId; |
@@ -10,3 +10,3 @@ "use strict"; | ||
value: content.value.map((items) => { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV1(items.value, fetch?.fields); | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV1(items.value, fetch === null || fetch === void 0 ? void 0 : fetch.fields); | ||
}), | ||
@@ -16,3 +16,3 @@ }; | ||
renderV2(groupDef, content, fetch) { | ||
return content.value.map((items) => (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV2(items.value, fetch?.fields, groupDef.fields, { | ||
return content.value.map((items) => (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV2(items.value, fetch === null || fetch === void 0 ? void 0 : fetch.fields, groupDef.fields, { | ||
withFetch: "filter", | ||
@@ -19,0 +19,0 @@ }, { |
@@ -22,3 +22,3 @@ "use strict"; | ||
try { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid); | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid); | ||
return { | ||
@@ -36,3 +36,3 @@ type: "Link.document", | ||
try { | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch?.uuid); | ||
const id = ctx.Extension.DocEncoder.encodeDocId(link.id, fetch === null || fetch === void 0 ? void 0 : fetch.uuid); | ||
return ctx.Extension.encoders.documentLinks.encode(id); | ||
@@ -39,0 +39,0 @@ } |
@@ -98,3 +98,3 @@ "use strict"; | ||
} | ||
else if (content?.__TYPE__ === widgets_1.WidgetTypes.Field) { | ||
else if ((content === null || content === void 0 ? void 0 : content.__TYPE__) === widgets_1.WidgetTypes.Field) { | ||
return nestable_2.FieldRenderer.renderV2(def, content); | ||
@@ -171,3 +171,3 @@ } | ||
} | ||
else if (content?.__TYPE__ === widgets_1.WidgetTypes.Field) { | ||
else if ((content === null || content === void 0 ? void 0 : content.__TYPE__) === widgets_1.WidgetTypes.Field) { | ||
return nestable_2.FieldRenderer.renderMocks(def, content); | ||
@@ -174,0 +174,0 @@ } |
@@ -9,4 +9,5 @@ "use strict"; | ||
renderV1(content, fetch) { | ||
const repeatFetch = fetch?.repeat?.fields; | ||
const nonRepeatFetch = fetch?.nonRepeat?.fields; | ||
var _a, _b; | ||
const repeatFetch = (_a = fetch === null || fetch === void 0 ? void 0 : fetch.repeat) === null || _a === void 0 ? void 0 : _a.fields; | ||
const nonRepeatFetch = (_b = fetch === null || fetch === void 0 ? void 0 : fetch.nonRepeat) === null || _b === void 0 ? void 0 : _b.fields; | ||
const itemsValue = content.repeat.flatMap((groupItem) => { | ||
@@ -26,2 +27,3 @@ const rendered = (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV1(groupItem.value, repeatFetch); | ||
renderV2(def, content, fetch) { | ||
var _a; | ||
const repeatFetch = fetch === undefined | ||
@@ -34,5 +36,5 @@ ? undefined | ||
}; | ||
const nonRepeatFetch = fetch?.nonRepeat?.fields; | ||
const nonRepeatFetch = (_a = fetch === null || fetch === void 0 ? void 0 : fetch.nonRepeat) === null || _a === void 0 ? void 0 : _a.fields; | ||
const itemsValue = content.repeat.map((items) => { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV2(items.value, repeatFetch?.fields, def.items.fields, { | ||
return (0, SimpleWidgetRenderer_1.default)(ctx).renderObjectOfSimpleWidgetV2(items.value, repeatFetch === null || repeatFetch === void 0 ? void 0 : repeatFetch.fields, def.items.fields, { | ||
withFetch: "default", | ||
@@ -39,0 +41,0 @@ }, { |
@@ -6,3 +6,4 @@ "use strict"; | ||
function getFetchField(variation, part, fetch) { | ||
return fetch?.variations?.[variation]?.[part]?.fields; | ||
var _a, _b, _c; | ||
return (_c = (_b = (_a = fetch === null || fetch === void 0 ? void 0 : fetch.variations) === null || _a === void 0 ? void 0 : _a[variation]) === null || _b === void 0 ? void 0 : _b[part]) === null || _c === void 0 ? void 0 : _c.fields; | ||
} | ||
@@ -9,0 +10,0 @@ const SharedSliceRenderer = (ctx) => ({ |
@@ -11,3 +11,3 @@ "use strict"; | ||
function renderItemAndFilterOutEmptyOne(slicesContent, sliceFetch, ctx) { | ||
const fetchRecord = sliceFetch?.slices; | ||
const fetchRecord = sliceFetch === null || sliceFetch === void 0 ? void 0 : sliceFetch.slices; | ||
return (0, Array_1.compact)(slicesContent.value.map((item) => { | ||
@@ -27,8 +27,11 @@ return (0, function_1.pipe)((0, utils_1.renderIfNoFetchOrFetchDefined)(fetchRecord, item.key, (f) => (0, SliceWidgetRenderer_1.default)(ctx).renderV1(item.widget, f)), //TODO: add fetch | ||
else { | ||
return (0, function_1.pipe)((0, SliceWidgetRenderer_1.default)(ctx).renderV2(keyToSliceDef[slice.name], slice.widget, sliceFetch), O.map((render) => ({ | ||
//TODO: clean type here, must case because of unknown coming from the renderer | ||
...render, | ||
slice_type: slice.name, | ||
slice_label: slice.maybeLabel ?? null, | ||
}))); | ||
return (0, function_1.pipe)((0, SliceWidgetRenderer_1.default)(ctx).renderV2(keyToSliceDef[slice.name], slice.widget, sliceFetch), O.map((render) => { | ||
var _a; | ||
return ({ | ||
//TODO: clean type here, must case because of unknown coming from the renderer | ||
...render, | ||
slice_type: slice.name, | ||
slice_label: (_a = slice.maybeLabel) !== null && _a !== void 0 ? _a : null, | ||
}); | ||
})); | ||
} | ||
@@ -41,6 +44,7 @@ } | ||
value: renderItemAndFilterOutEmptyOne(content, fetch, ctx).map(([item, renderedItem]) => { | ||
var _a; | ||
return { | ||
...renderedItem, | ||
slice_type: item.name, | ||
slice_label: item.maybeLabel ?? null, | ||
slice_label: (_a = item.maybeLabel) !== null && _a !== void 0 ? _a : null, | ||
type: "Slice", | ||
@@ -53,3 +57,3 @@ }; | ||
const keyToSliceDef = Object.fromEntries(def.slices.map((slice) => [slice.name, slice])); | ||
const fetchRecord = fetch?.slices; | ||
const fetchRecord = fetch === null || fetch === void 0 ? void 0 : fetch.slices; | ||
return (0, Array_1.compact)(content.value.map((contentValue) => { | ||
@@ -56,0 +60,0 @@ return (0, utils_1.renderIfNoFetchOrFetchDefined)(fetchRecord, contentValue.name, (f) => renderContent(contentValue, f, ctx, keyToSliceDef)); |
{ | ||
"name": "@prismicio/api-renderer", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Prismic renderers for the content API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
736844
23034
116