@squiz/dx-page-contents-lib 1.78.0 → 1.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/formatted-text.d.ts +26 -56
- package/lib/formatted-text.js +7 -48
- package/lib/formatted-text.js.map +1 -1
- package/lib/formatted-text.spec.js +0 -10
- package/lib/formatted-text.spec.js.map +1 -1
- package/lib/layout-content.d.ts +322 -516
- package/lib/layout-content.js +30 -24
- package/lib/layout-content.js.map +1 -1
- package/lib/layout-content.spec.js +49 -10
- package/lib/layout-content.spec.js.map +1 -1
- package/lib/layouts/custom-layout.d.ts +6 -1056
- package/lib/layouts/index.d.ts +10 -4683
- package/lib/layouts/index.js +0 -6
- package/lib/layouts/index.js.map +1 -1
- package/lib/layouts/raw.layout.d.ts +5 -927
- package/lib/mocks/PageContentsHelpers.d.ts +37 -6359
- package/lib/mocks/PageContentsHelpers.js +40 -76
- package/lib/mocks/PageContentsHelpers.js.map +1 -1
- package/lib/mocks/PageContentsMocks.d.ts +7 -6
- package/lib/mocks/PageContentsMocks.js +56 -38
- package/lib/mocks/PageContentsMocks.js.map +1 -1
- package/lib/page-contents-lib.d.ts +19 -238
- package/lib/page-contents-lib.js +40 -67
- package/lib/page-contents-lib.js.map +1 -1
- package/lib/page-contents-lib.spec.js +231 -254
- package/lib/page-contents-lib.spec.js.map +1 -1
- package/lib/resolvers/create-variant-resolver.js +1 -1
- package/lib/resolvers/create-variant-resolver.js.map +1 -1
- package/lib/resolvers/create-variant-resolver.spec.js +50 -20
- package/lib/resolvers/create-variant-resolver.spec.js.map +1 -1
- package/lib/resolvers/default-layout-resolver.d.ts +2 -2
- package/lib/resolvers/default-layout-resolver.js +10 -4
- package/lib/resolvers/default-layout-resolver.js.map +1 -1
- package/lib/resolvers/default-layout-resolver.spec.js.map +1 -1
- package/lib/resolvers/default-variation-resolver.d.ts +2 -2
- package/lib/resolvers/default-variation-resolver.js +15 -5
- package/lib/resolvers/default-variation-resolver.js.map +1 -1
- package/lib/resolvers/default-variation-resolver.spec.js +22 -5
- package/lib/resolvers/default-variation-resolver.spec.js.map +1 -1
- package/package.json +2 -2
- package/lib/layouts/single-column.layout.d.ts +0 -950
- package/lib/layouts/single-column.layout.js +0 -15
- package/lib/layouts/single-column.layout.js.map +0 -1
- package/lib/layouts/two-column.layout.d.ts +0 -1883
- package/lib/layouts/two-column.layout.js +0 -16
- package/lib/layouts/two-column.layout.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormattedTextResolverConfig } from '@squiz/formatted-text-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { LayoutContentNodes, PageLayoutContentResolver } from './layout-content';
|
|
3
3
|
import { PageLayout } from './layouts';
|
|
4
4
|
import { CustomLayout } from './layouts/custom-layout';
|
|
5
5
|
import { FullyResolvedNodesMap } from '@squiz/dx-json-schema-lib';
|
|
@@ -8,12 +8,12 @@ export type RenderLayoutConfig = FormattedTextResolverConfig;
|
|
|
8
8
|
export interface ExtendedResolversMap extends FullyResolvedNodesMap {
|
|
9
9
|
layout: (node: DeveloperDefinedLayoutNode, blockIndex?: number) => Promise<string>;
|
|
10
10
|
}
|
|
11
|
-
type CustomLayoutRenderer = (layout:
|
|
11
|
+
type CustomLayoutRenderer = (layout: DeveloperDefinedLayoutNode, resolvers: ExtendedResolversMap) => Promise<string>;
|
|
12
12
|
export declare const addLayoutSupport: (baseResolvers: FullyResolvedNodesMap, renderLayoutFn: CustomLayoutRenderer) => ExtendedResolversMap;
|
|
13
13
|
/**
|
|
14
14
|
* Validate that the provided layout is a valid page layout
|
|
15
15
|
*/
|
|
16
|
-
export declare function assertIsPageLayout(layout: unknown):
|
|
16
|
+
export declare function assertIsPageLayout(layout: unknown): PageLayout;
|
|
17
17
|
export declare function resolveLayout(layout: PageLayout, resolver: PageLayoutContentResolver): Promise<PageLayout>;
|
|
18
18
|
export declare function renderLayout(layout: PageLayout, config: RenderLayoutConfig): Promise<string>;
|
|
19
19
|
/**
|
|
@@ -23,245 +23,14 @@ export declare function renderLayout(layout: PageLayout, config: RenderLayoutCon
|
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
25
|
export declare function translateLanguageNodes(contentNodes: PageLayout['content'], config: RenderLayoutConfig): void;
|
|
26
|
-
export declare function isDeveloperDefinedLayoutNode(node: any): node is DeveloperDefinedLayoutNode;
|
|
27
26
|
export declare function isCustomLayout(layout: any): layout is CustomLayout;
|
|
28
|
-
export declare const renderCustomLayout:
|
|
27
|
+
export declare const renderCustomLayout: (layout: CustomLayout | DeveloperDefinedLayoutNode, resolvers: ExtendedResolversMap) => Promise<string>;
|
|
29
28
|
/**
|
|
30
29
|
* The representation of the page content as a map of zone ID to content nodes.
|
|
31
30
|
*/
|
|
32
|
-
export declare const ContentStructure: z.ZodRecord<z.ZodString, z.ZodArray<z.
|
|
33
|
-
value: string;
|
|
34
|
-
type: "text";
|
|
35
|
-
nodeId: string;
|
|
36
|
-
} | {
|
|
37
|
-
type: "matrix-image";
|
|
38
|
-
nodeId: string;
|
|
39
|
-
matrixDomain: string;
|
|
40
|
-
matrixAssetId: string;
|
|
41
|
-
attributes?: (Record<string, string> & {
|
|
42
|
-
src?: undefined;
|
|
43
|
-
}) | undefined;
|
|
44
|
-
formattingOptions?: {
|
|
45
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
46
|
-
} | undefined;
|
|
47
|
-
matrixIdentifier?: string | undefined;
|
|
48
|
-
} | {
|
|
49
|
-
type: "dam-image";
|
|
50
|
-
nodeId: string;
|
|
51
|
-
damSystemType: "bynder";
|
|
52
|
-
damSystemIdentifier: string;
|
|
53
|
-
damObjectId: string;
|
|
54
|
-
attributes?: (Record<string, string> & {
|
|
55
|
-
src?: undefined;
|
|
56
|
-
}) | undefined;
|
|
57
|
-
formattingOptions?: {
|
|
58
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
59
|
-
} | undefined;
|
|
60
|
-
damAdditional?: {
|
|
61
|
-
variant?: string | undefined;
|
|
62
|
-
} | undefined;
|
|
63
|
-
} | {
|
|
64
|
-
type: "component";
|
|
65
|
-
nodeId: string;
|
|
66
|
-
componentId: string;
|
|
67
|
-
componentSet: string;
|
|
68
|
-
i18n?: Record<string, {
|
|
69
|
-
id: string;
|
|
70
|
-
} | {
|
|
71
|
-
content: Record<string, unknown>;
|
|
72
|
-
schemaName: string;
|
|
73
|
-
}> | undefined;
|
|
74
|
-
componentType?: "server" | "edge" | undefined;
|
|
75
|
-
contentItem?: {
|
|
76
|
-
id: string;
|
|
77
|
-
} | {
|
|
78
|
-
content: Record<string, unknown>;
|
|
79
|
-
schemaName: string;
|
|
80
|
-
} | undefined;
|
|
81
|
-
} | (({
|
|
82
|
-
type: "tag";
|
|
83
|
-
nodeId: string;
|
|
84
|
-
tag: string;
|
|
85
|
-
attributes?: Record<string, string> | undefined;
|
|
86
|
-
font?: {
|
|
87
|
-
bold?: boolean | undefined;
|
|
88
|
-
italics?: boolean | undefined;
|
|
89
|
-
underline?: boolean | undefined;
|
|
90
|
-
color?: string | undefined;
|
|
91
|
-
size?: string | undefined;
|
|
92
|
-
fontFamily?: string | undefined;
|
|
93
|
-
} | undefined;
|
|
94
|
-
formattingOptions?: {
|
|
95
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
96
|
-
} | undefined;
|
|
97
|
-
} | {
|
|
98
|
-
type: "fragment";
|
|
99
|
-
nodeId: string;
|
|
100
|
-
i18n?: Record<string, {}> | undefined;
|
|
101
|
-
} | {
|
|
102
|
-
type: "link-to-matrix-asset";
|
|
103
|
-
nodeId: string;
|
|
104
|
-
matrixDomain: string;
|
|
105
|
-
matrixAssetId: string;
|
|
106
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
107
|
-
attributes?: (Record<string, string> & {
|
|
108
|
-
target?: undefined;
|
|
109
|
-
href?: undefined;
|
|
110
|
-
}) | undefined;
|
|
111
|
-
formattingOptions?: {
|
|
112
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
113
|
-
} | undefined;
|
|
114
|
-
matrixIdentifier?: string | undefined;
|
|
115
|
-
} | {
|
|
116
|
-
type: "link-to-dam-asset";
|
|
117
|
-
nodeId: string;
|
|
118
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
119
|
-
damSystemType: "bynder";
|
|
120
|
-
damSystemIdentifier: string;
|
|
121
|
-
damObjectId: string;
|
|
122
|
-
attributes?: (Record<string, string> & {
|
|
123
|
-
target?: undefined;
|
|
124
|
-
href?: undefined;
|
|
125
|
-
}) | undefined;
|
|
126
|
-
formattingOptions?: {
|
|
127
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
128
|
-
} | undefined;
|
|
129
|
-
damAdditional?: {
|
|
130
|
-
variant?: string | undefined;
|
|
131
|
-
} | undefined;
|
|
132
|
-
}) & {
|
|
133
|
-
children: LayoutContentNodes[];
|
|
134
|
-
}), z.ZodTypeDef, {
|
|
135
|
-
value: string;
|
|
136
|
-
type: "text";
|
|
31
|
+
export declare const ContentStructure: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodType<LayoutContentNodes, z.ZodTypeDef, Omit<LayoutContentNodes, "nodeId"> & {
|
|
137
32
|
nodeId?: string | undefined;
|
|
138
|
-
}
|
|
139
|
-
type: "tag";
|
|
140
|
-
tag: string;
|
|
141
|
-
nodeId?: string | undefined;
|
|
142
|
-
attributes?: Record<string, string> | undefined;
|
|
143
|
-
font?: {
|
|
144
|
-
bold?: boolean | undefined;
|
|
145
|
-
italics?: boolean | undefined;
|
|
146
|
-
underline?: boolean | undefined;
|
|
147
|
-
color?: string | undefined;
|
|
148
|
-
size?: string | undefined;
|
|
149
|
-
fontFamily?: string | undefined;
|
|
150
|
-
} | undefined;
|
|
151
|
-
formattingOptions?: {
|
|
152
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
153
|
-
} | undefined;
|
|
154
|
-
} | {
|
|
155
|
-
type: "fragment";
|
|
156
|
-
nodeId?: string | undefined;
|
|
157
|
-
i18n?: Record<string, {}> | undefined;
|
|
158
|
-
} | {
|
|
159
|
-
type: "link-to-matrix-asset";
|
|
160
|
-
matrixDomain: string;
|
|
161
|
-
matrixAssetId: string;
|
|
162
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
163
|
-
nodeId?: string | undefined;
|
|
164
|
-
attributes?: (Record<string, string> & {
|
|
165
|
-
target?: undefined;
|
|
166
|
-
href?: undefined;
|
|
167
|
-
}) | undefined;
|
|
168
|
-
formattingOptions?: {
|
|
169
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
170
|
-
} | undefined;
|
|
171
|
-
matrixIdentifier?: string | undefined;
|
|
172
|
-
} | {
|
|
173
|
-
type: "link-to-dam-asset";
|
|
174
|
-
target: "_blank" | "_self" | "_parent" | "_top";
|
|
175
|
-
damSystemType: "bynder";
|
|
176
|
-
damSystemIdentifier: string;
|
|
177
|
-
damObjectId: string;
|
|
178
|
-
nodeId?: string | undefined;
|
|
179
|
-
attributes?: (Record<string, string> & {
|
|
180
|
-
target?: undefined;
|
|
181
|
-
href?: undefined;
|
|
182
|
-
}) | undefined;
|
|
183
|
-
formattingOptions?: {
|
|
184
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
185
|
-
} | undefined;
|
|
186
|
-
damAdditional?: {
|
|
187
|
-
variant?: string | undefined;
|
|
188
|
-
} | undefined;
|
|
189
|
-
} | {
|
|
190
|
-
type: "matrix-image";
|
|
191
|
-
matrixDomain: string;
|
|
192
|
-
matrixAssetId: string;
|
|
193
|
-
nodeId?: string | undefined;
|
|
194
|
-
attributes?: (Record<string, string> & {
|
|
195
|
-
src?: undefined;
|
|
196
|
-
}) | undefined;
|
|
197
|
-
formattingOptions?: {
|
|
198
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
199
|
-
} | undefined;
|
|
200
|
-
matrixIdentifier?: string | undefined;
|
|
201
|
-
} | {
|
|
202
|
-
type: "dam-image";
|
|
203
|
-
damSystemType: "bynder";
|
|
204
|
-
damSystemIdentifier: string;
|
|
205
|
-
damObjectId: string;
|
|
206
|
-
nodeId?: string | undefined;
|
|
207
|
-
attributes?: (Record<string, string> & {
|
|
208
|
-
src?: undefined;
|
|
209
|
-
}) | undefined;
|
|
210
|
-
formattingOptions?: {
|
|
211
|
-
alignment: "left" | "center" | "right" | "justify";
|
|
212
|
-
} | undefined;
|
|
213
|
-
damAdditional?: {
|
|
214
|
-
variant?: string | undefined;
|
|
215
|
-
} | undefined;
|
|
216
|
-
} | {
|
|
217
|
-
type: "component";
|
|
218
|
-
componentId: string;
|
|
219
|
-
componentSet: string;
|
|
220
|
-
nodeId?: string | undefined;
|
|
221
|
-
i18n?: Record<string, {
|
|
222
|
-
id: string;
|
|
223
|
-
} | {
|
|
224
|
-
content: Record<string, unknown>;
|
|
225
|
-
schemaName: string;
|
|
226
|
-
}> | undefined;
|
|
227
|
-
componentType?: "server" | "edge" | undefined;
|
|
228
|
-
contentItem?: {
|
|
229
|
-
id: string;
|
|
230
|
-
} | {
|
|
231
|
-
content: Record<string, unknown>;
|
|
232
|
-
schemaName: string;
|
|
233
|
-
} | undefined;
|
|
234
|
-
}>, z.ZodType<import("./layout-content").LayoutVariationNode, z.ZodTypeDef, {
|
|
235
|
-
type: "variation";
|
|
236
|
-
default: {};
|
|
237
|
-
nodeId?: string | undefined;
|
|
238
|
-
}>, z.ZodType<DeveloperDefinedLayoutNode, z.ZodTypeDef, {
|
|
239
|
-
type: "layout";
|
|
240
|
-
layout: {
|
|
241
|
-
options: Record<string, {
|
|
242
|
-
values: string[];
|
|
243
|
-
displayName: string;
|
|
244
|
-
description: string;
|
|
245
|
-
selectedValue: string;
|
|
246
|
-
}>;
|
|
247
|
-
name: string;
|
|
248
|
-
displayName: string;
|
|
249
|
-
description: string;
|
|
250
|
-
template: string;
|
|
251
|
-
zones: Record<string, {
|
|
252
|
-
displayName: string;
|
|
253
|
-
description: string;
|
|
254
|
-
minNodes: number;
|
|
255
|
-
maxNodes?: number | undefined;
|
|
256
|
-
}>;
|
|
257
|
-
} | {
|
|
258
|
-
options: Record<string, {
|
|
259
|
-
selectedValue: string;
|
|
260
|
-
}>;
|
|
261
|
-
name: string;
|
|
262
|
-
};
|
|
263
|
-
nodeId?: string | undefined;
|
|
264
|
-
}>]>, "many">>;
|
|
33
|
+
}>, "many">>;
|
|
265
34
|
export type ContentStructure = z.infer<typeof ContentStructure>;
|
|
266
35
|
/**
|
|
267
36
|
* Validate the provided page content structure.
|
|
@@ -278,8 +47,20 @@ export declare enum ResolutionType {
|
|
|
278
47
|
PREVIEW = "PREVIEW",// Preview mode with variant resolution
|
|
279
48
|
LIVE_PREVIEW = "LIVE_PREVIEW"
|
|
280
49
|
}
|
|
50
|
+
export type DeveloperDefinedLayoutNode = Extract<LayoutContentNodes, {
|
|
51
|
+
type: 'layout';
|
|
52
|
+
}>;
|
|
53
|
+
export type LayoutVariationNode = Extract<LayoutContentNodes, {
|
|
54
|
+
type: 'variation';
|
|
55
|
+
}>;
|
|
56
|
+
export type FragmentNodeWithChildren = Extract<LayoutContentNodes, {
|
|
57
|
+
type: 'fragment';
|
|
58
|
+
}>;
|
|
59
|
+
export type ComponentNode = Extract<LayoutContentNodes, {
|
|
60
|
+
type: 'component';
|
|
61
|
+
}>;
|
|
281
62
|
export { PageLayoutContentResolver };
|
|
282
|
-
export { PageLayoutContent, LayoutContentNodes, LayoutVariant,
|
|
63
|
+
export { PageLayoutContent, LayoutContentNodes, LayoutVariant, SimpleContentNodes } from './layout-content';
|
|
283
64
|
export { PageLayout } from './layouts';
|
|
284
65
|
export * from './resolvers';
|
|
285
66
|
export * from './mocks';
|
package/lib/page-contents-lib.js
CHANGED
|
@@ -17,12 +17,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.PageLayout = exports.
|
|
20
|
+
exports.PageLayout = exports.LayoutContentNodes = exports.PageLayoutContent = exports.PageLayoutContentResolver = exports.ResolutionType = exports.ContentStructure = exports.renderCustomLayout = exports.addLayoutSupport = void 0;
|
|
21
21
|
exports.assertIsPageLayout = assertIsPageLayout;
|
|
22
22
|
exports.resolveLayout = resolveLayout;
|
|
23
23
|
exports.renderLayout = renderLayout;
|
|
24
24
|
exports.translateLanguageNodes = translateLanguageNodes;
|
|
25
|
-
exports.isDeveloperDefinedLayoutNode = isDeveloperDefinedLayoutNode;
|
|
26
25
|
exports.isCustomLayout = isCustomLayout;
|
|
27
26
|
exports.assertIsContentStructure = assertIsContentStructure;
|
|
28
27
|
const formatted_text_lib_1 = require("@squiz/formatted-text-lib");
|
|
@@ -58,26 +57,18 @@ function assertIsPageLayout(layout) {
|
|
|
58
57
|
if (firstParse.name === 'custom-layout') {
|
|
59
58
|
custom_layout_1.CustomLayout.parse(firstParse);
|
|
60
59
|
}
|
|
60
|
+
return firstParse;
|
|
61
61
|
}
|
|
62
62
|
// TODO: Make the layout resolution more generic
|
|
63
63
|
async function resolveLayout(layout, resolver) {
|
|
64
64
|
switch (layout.name) {
|
|
65
65
|
case 'layout-raw':
|
|
66
|
-
case 'single-column':
|
|
67
66
|
return {
|
|
68
67
|
...layout,
|
|
69
68
|
content: {
|
|
70
69
|
main: await resolver.resolve(layout.content.main),
|
|
71
70
|
},
|
|
72
71
|
};
|
|
73
|
-
case 'two-column':
|
|
74
|
-
return {
|
|
75
|
-
...layout,
|
|
76
|
-
content: {
|
|
77
|
-
left: await resolver.resolve(layout.content.left),
|
|
78
|
-
right: await resolver.resolve(layout.content.right),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
72
|
case 'custom-layout':
|
|
82
73
|
return {
|
|
83
74
|
...layout,
|
|
@@ -95,7 +86,8 @@ async function renderLayout(layout, config) {
|
|
|
95
86
|
return '';
|
|
96
87
|
translateLanguageNodes(layout.content, config);
|
|
97
88
|
const baseResolvers = (0, formatted_text_lib_1.createFormattedTextToHtmlStringResolvers)(config);
|
|
98
|
-
const
|
|
89
|
+
const developerLayoutRenderer = buildDeveloperLayoutRenderer(config);
|
|
90
|
+
const extendedResolvers = (0, exports.addLayoutSupport)(baseResolvers, developerLayoutRenderer);
|
|
99
91
|
//This could probably be improved, by cleaning up the resolver implementation
|
|
100
92
|
//Then rendering the result and using these functions to just call the top level template render dressing.
|
|
101
93
|
if (layout.name === 'custom-layout') {
|
|
@@ -147,67 +139,50 @@ function translateLanguageNodes(contentNodes, config) {
|
|
|
147
139
|
contentNodes[key] = translatedNodes;
|
|
148
140
|
}
|
|
149
141
|
}
|
|
150
|
-
function isDeveloperDefinedLayoutNode(node) {
|
|
151
|
-
try {
|
|
152
|
-
layout_content_1.DeveloperDefinedLayoutNode.parse(node);
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
142
|
function isCustomLayout(layout) {
|
|
160
143
|
return layout && typeof layout === 'object' && layout.name === 'custom-layout' && 'config' in layout;
|
|
161
144
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const templateString = layout.layout.template;
|
|
167
|
-
const developerTemplate = handlebars_1.default.compile(templateString);
|
|
168
|
-
const contentSections = {};
|
|
169
|
-
for (const [sectionName, nodes] of Object.entries(layout.content)) {
|
|
170
|
-
const renderedNodes = await Promise.all(nodes.map(async (node, index) => {
|
|
171
|
-
const nodeType = node.type;
|
|
172
|
-
const resolver = resolvers[nodeType] || resolvers.default;
|
|
173
|
-
if (resolver) {
|
|
174
|
-
return await resolver(node, index);
|
|
175
|
-
}
|
|
176
|
-
return `<p class="invalid-node-type">No resolver for node of type "${node.type}"</p>`;
|
|
177
|
-
}));
|
|
178
|
-
contentSections[sectionName] = renderedNodes.join('');
|
|
179
|
-
}
|
|
180
|
-
//Prevent double encoding of the html
|
|
181
|
-
const safeContentSections = {};
|
|
182
|
-
for (const [key, value] of Object.entries(contentSections)) {
|
|
183
|
-
safeContentSections[key] = new handlebars_1.default.SafeString(value);
|
|
145
|
+
function buildDeveloperLayoutRenderer(config) {
|
|
146
|
+
return async (layoutNode, resolvers) => {
|
|
147
|
+
if (!layoutNode.layout || !('template' in layoutNode.layout)) {
|
|
148
|
+
return `<p class="invalid-node-type">Invalid layout: Not a CustomLayout or DeveloperDefinedLayoutNode with template</p>`;
|
|
184
149
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
flattenedOptions[key] = value;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
150
|
+
const layoutTemplate = handlebars_1.default.compile(layoutNode.layout.template);
|
|
151
|
+
const contentSections = await Promise.all(Object.entries(layoutNode.content).map(async ([sectionName, zoneNodes]) => {
|
|
152
|
+
let renderedNodes = await Promise.all(zoneNodes.map((node) => (0, formatted_text_lib_1.formattedTextToHtmlString)(node, resolvers)));
|
|
153
|
+
if (config.isPreview) {
|
|
154
|
+
renderedNodes = [
|
|
155
|
+
`<!-- start:zone:${sectionName}:${layoutNode.nodeId} -->`,
|
|
156
|
+
...renderedNodes,
|
|
157
|
+
`<!-- end:zone:${sectionName}:${layoutNode.nodeId} -->`,
|
|
158
|
+
];
|
|
199
159
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
160
|
+
return [sectionName, new handlebars_1.default.SafeString(renderedNodes.join(''))];
|
|
161
|
+
}));
|
|
162
|
+
const selectedOptions = Object.entries(layoutNode.layout.options).map(([key, value]) => {
|
|
163
|
+
if (value && typeof value === 'object' && 'selectedValue' in value) {
|
|
164
|
+
return [key, value.selectedValue];
|
|
165
|
+
}
|
|
166
|
+
return [key, value];
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
const renderedTemplate = layoutTemplate({
|
|
170
|
+
zones: Object.fromEntries(contentSections),
|
|
171
|
+
layout: layoutNode.layout,
|
|
172
|
+
options: Object.fromEntries(selectedOptions),
|
|
205
173
|
});
|
|
174
|
+
if (config.isPreview) {
|
|
175
|
+
return `<!-- start:layout:${layoutNode.layout.name}:${layoutNode.nodeId} -->${renderedTemplate}<!-- end:layout:${layoutNode.layout.name}:${layoutNode.nodeId} -->`;
|
|
176
|
+
}
|
|
177
|
+
return renderedTemplate;
|
|
206
178
|
}
|
|
207
179
|
catch (error) {
|
|
208
|
-
return `<p class="invalid-node-type">Error rendering developer template ${
|
|
180
|
+
return `<p class="invalid-node-type">Error rendering developer template ${layoutNode.layout.name}</p>`;
|
|
209
181
|
}
|
|
210
|
-
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const renderCustomLayout = async (layout, resolvers) => {
|
|
185
|
+
var _a, _b;
|
|
211
186
|
// Narrow the types here for the return,
|
|
212
187
|
if (!isCustomLayout(layout)) {
|
|
213
188
|
return `<p class="invalid-node-type">Invalid layout: Not a CustomLayout or DeveloperDefinedLayoutNode with template</p>`;
|
|
@@ -217,7 +192,7 @@ const renderCustomLayout = async (layout, resolvers) => {
|
|
|
217
192
|
const nodeContent = await Promise.all(nodeArrays.map(async (node, index) => {
|
|
218
193
|
const nodeType = node.type;
|
|
219
194
|
const resolver = resolvers[nodeType] || resolvers.default;
|
|
220
|
-
if (node.type === '
|
|
195
|
+
if (node.type === 'fragment') {
|
|
221
196
|
return await (0, formatted_text_lib_1.formattedTextToHtmlString)(node, resolvers, index);
|
|
222
197
|
}
|
|
223
198
|
if (resolver) {
|
|
@@ -279,8 +254,6 @@ var ResolutionType;
|
|
|
279
254
|
var layout_content_2 = require("./layout-content");
|
|
280
255
|
Object.defineProperty(exports, "PageLayoutContent", { enumerable: true, get: function () { return layout_content_2.PageLayoutContent; } });
|
|
281
256
|
Object.defineProperty(exports, "LayoutContentNodes", { enumerable: true, get: function () { return layout_content_2.LayoutContentNodes; } });
|
|
282
|
-
Object.defineProperty(exports, "LayoutVariationNode", { enumerable: true, get: function () { return layout_content_2.LayoutVariationNode; } });
|
|
283
|
-
Object.defineProperty(exports, "DeveloperDefinedLayoutNode", { enumerable: true, get: function () { return layout_content_2.DeveloperDefinedLayoutNode; } });
|
|
284
257
|
var layouts_2 = require("./layouts");
|
|
285
258
|
Object.defineProperty(exports, "PageLayout", { enumerable: true, get: function () { return layouts_2.PageLayout; } });
|
|
286
259
|
__exportStar(require("./resolvers"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-contents-lib.js","sourceRoot":"","sources":["../src/page-contents-lib.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"page-contents-lib.js","sourceRoot":"","sources":["../src/page-contents-lib.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA0CA,gDASC;AAGD,sCAmBC;AAED,oCAkBC;AAQD,wDAgCC;AAED,wCAEC;AA8HD,4DAEC;AAzQD,kEAImC;AACnC,qDAA6G;AAuRpG,0GAvRgD,0CAAyB,OAuRhD;AAtRlC,uCAAyD;AACzD,4DAAoC;AACpC,2DAA+E;AAE/E,6BAAwB;AASjB,MAAM,gBAAgB,GAAG,CAC9B,aAAoC,EACpC,cAAoC,EACd,EAAE;IACxB,MAAM,iBAAiB,GAAyB;QAC9C,GAAI,aAAqB;QACzB,MAAM,EAAE,KAAK,EAAE,IAAgC,EAAE,WAAoB,EAAE,EAAE;YACvE,OAAO,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAZW,QAAA,gBAAgB,oBAY3B;AAEF,uCAAuC;AACvC,oBAAU,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,EAAE;IACnD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IA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