@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.
Files changed (46) hide show
  1. package/lib/formatted-text.d.ts +26 -56
  2. package/lib/formatted-text.js +7 -48
  3. package/lib/formatted-text.js.map +1 -1
  4. package/lib/formatted-text.spec.js +0 -10
  5. package/lib/formatted-text.spec.js.map +1 -1
  6. package/lib/layout-content.d.ts +322 -516
  7. package/lib/layout-content.js +30 -24
  8. package/lib/layout-content.js.map +1 -1
  9. package/lib/layout-content.spec.js +49 -10
  10. package/lib/layout-content.spec.js.map +1 -1
  11. package/lib/layouts/custom-layout.d.ts +6 -1056
  12. package/lib/layouts/index.d.ts +10 -4683
  13. package/lib/layouts/index.js +0 -6
  14. package/lib/layouts/index.js.map +1 -1
  15. package/lib/layouts/raw.layout.d.ts +5 -927
  16. package/lib/mocks/PageContentsHelpers.d.ts +37 -6359
  17. package/lib/mocks/PageContentsHelpers.js +40 -76
  18. package/lib/mocks/PageContentsHelpers.js.map +1 -1
  19. package/lib/mocks/PageContentsMocks.d.ts +7 -6
  20. package/lib/mocks/PageContentsMocks.js +56 -38
  21. package/lib/mocks/PageContentsMocks.js.map +1 -1
  22. package/lib/page-contents-lib.d.ts +19 -238
  23. package/lib/page-contents-lib.js +40 -67
  24. package/lib/page-contents-lib.js.map +1 -1
  25. package/lib/page-contents-lib.spec.js +231 -254
  26. package/lib/page-contents-lib.spec.js.map +1 -1
  27. package/lib/resolvers/create-variant-resolver.js +1 -1
  28. package/lib/resolvers/create-variant-resolver.js.map +1 -1
  29. package/lib/resolvers/create-variant-resolver.spec.js +50 -20
  30. package/lib/resolvers/create-variant-resolver.spec.js.map +1 -1
  31. package/lib/resolvers/default-layout-resolver.d.ts +2 -2
  32. package/lib/resolvers/default-layout-resolver.js +10 -4
  33. package/lib/resolvers/default-layout-resolver.js.map +1 -1
  34. package/lib/resolvers/default-layout-resolver.spec.js.map +1 -1
  35. package/lib/resolvers/default-variation-resolver.d.ts +2 -2
  36. package/lib/resolvers/default-variation-resolver.js +15 -5
  37. package/lib/resolvers/default-variation-resolver.js.map +1 -1
  38. package/lib/resolvers/default-variation-resolver.spec.js +22 -5
  39. package/lib/resolvers/default-variation-resolver.spec.js.map +1 -1
  40. package/package.json +2 -2
  41. package/lib/layouts/single-column.layout.d.ts +0 -950
  42. package/lib/layouts/single-column.layout.js +0 -15
  43. package/lib/layouts/single-column.layout.js.map +0 -1
  44. package/lib/layouts/two-column.layout.d.ts +0 -1883
  45. package/lib/layouts/two-column.layout.js +0 -16
  46. package/lib/layouts/two-column.layout.js.map +0 -1
@@ -16,11 +16,10 @@ describe('assertIsContentStructure', () => {
16
16
  {
17
17
  type: 'tag',
18
18
  tag: 'p',
19
- nodeId: (0, crypto_1.randomUUID)(),
20
19
  children: [
21
- { type: 'text', value: 'MY DEFAULT BLOCK', nodeId: (0, crypto_1.randomUUID)() },
22
- { type: 'tag', tag: 'p', children: [], nodeId: (0, crypto_1.randomUUID)() },
23
- { type: 'tag', tag: 'br', children: [], nodeId: (0, crypto_1.randomUUID)() },
20
+ { type: 'text', value: 'MY DEFAULT BLOCK' },
21
+ { type: 'tag', tag: 'p', children: [] },
22
+ { type: 'tag', tag: 'br', children: [] },
24
23
  ],
25
24
  },
26
25
  ],
@@ -82,8 +81,7 @@ describe('assertIsContentStructure', () => {
82
81
  {
83
82
  type: 'tag',
84
83
  tag: 'p',
85
- nodeId: (0, crypto_1.randomUUID)(),
86
- children: [{ type: 'text', value: 'FOUR', nodeId: (0, crypto_1.randomUUID)() }],
84
+ children: [{ type: 'text', value: 'FOUR' }],
87
85
  },
88
86
  ],
89
87
  type: 'fragment',
@@ -110,8 +108,13 @@ describe('assertIsContentStructure', () => {
110
108
  it.each(['text', 'component', 'matrix-image', 'variation'])('should not allow children on %s node', (nodeType) => {
111
109
  content[zoneId] = [
112
110
  {
113
- ...mocks_1.VALID_CONTENT_NODES[nodeType],
114
- children: [],
111
+ type: 'fragment',
112
+ children: [
113
+ {
114
+ ...mocks_1.VALID_CONTENT_NODES[nodeType],
115
+ children: [],
116
+ },
117
+ ],
115
118
  },
116
119
  ];
117
120
  expect(() => (0, page_contents_lib_1.assertIsContentStructure)(content)).toThrow();
@@ -120,67 +123,46 @@ describe('assertIsContentStructure', () => {
120
123
  content[zoneId] = [
121
124
  {
122
125
  nodeId: (0, crypto_1.randomUUID)(),
123
- type: 'tag',
124
- tag: 'div',
125
- children: [mocks_1.VALID_CONTENT_NODES.component],
126
+ type: 'fragment',
127
+ children: [mocks_1.VALID_CONTENT_NODES['link-to-matrix-asset']],
126
128
  },
127
129
  ];
128
130
  expect(() => (0, page_contents_lib_1.assertIsContentStructure)(content)).not.toThrow();
129
131
  });
130
132
  });
131
133
  describe('assertIsPageLayout', () => {
132
- describe('single-column', () => {
133
- it('should validate a single-column layout', () => {
134
+ describe('layout-raw', () => {
135
+ it('should validate a layout-raw layout', () => {
134
136
  const layout = {
135
- name: 'single-column',
137
+ name: 'layout-raw',
136
138
  content: {
137
139
  main: [mocks_1.VALID_CONTENT_NODES.component],
138
140
  },
139
141
  };
140
142
  expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
141
143
  });
142
- it('should validate a two-column layout', () => {
143
- const layout = {
144
- name: 'two-column',
145
- content: {
146
- left: [mocks_1.VALID_CONTENT_NODES.component],
147
- right: [mocks_1.VALID_CONTENT_NODES.component],
148
- },
149
- };
150
- expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
151
- });
152
144
  it.each(['text', 'component', 'matrix-image', 'variation'])('should not allow children on %s node', (nodeType) => {
153
145
  const layout = {
154
- name: 'single-column',
146
+ name: 'layout-raw',
155
147
  content: {
156
148
  main: [
157
149
  {
158
- ...mocks_1.VALID_CONTENT_NODES[nodeType],
159
- children: [],
150
+ type: 'fragment',
151
+ children: [
152
+ {
153
+ ...mocks_1.VALID_CONTENT_NODES[nodeType],
154
+ children: [],
155
+ },
156
+ ],
160
157
  },
161
158
  ],
162
159
  },
163
160
  };
164
161
  expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).toThrow();
165
162
  });
166
- it('should validate a deeply nested layout', () => {
167
- const layout = {
168
- name: 'single-column',
169
- content: {
170
- main: [
171
- {
172
- type: 'tag',
173
- tag: 'div',
174
- children: [mocks_1.VALID_CONTENT_NODES.component],
175
- },
176
- ],
177
- },
178
- };
179
- expect(() => (0, page_contents_lib_1.assertIsPageLayout)(layout)).not.toThrow();
180
- });
181
163
  it('should allow variation nodes with no content', () => {
182
164
  const layout = {
183
- name: 'single-column',
165
+ name: 'layout-raw',
184
166
  content: {
185
167
  main: [mocks_1.VALID_CONTENT_NODES.variation],
186
168
  },
@@ -189,7 +171,7 @@ describe('assertIsPageLayout', () => {
189
171
  });
190
172
  it('should allow variation nodes with content', () => {
191
173
  const layout = {
192
- name: 'single-column',
174
+ name: 'layout-raw',
193
175
  content: {
194
176
  main: [
195
177
  {
@@ -198,16 +180,26 @@ describe('assertIsPageLayout', () => {
198
180
  default: {
199
181
  node: {
200
182
  nodeId: (0, crypto_1.randomUUID)(),
201
- type: 'text',
202
- value: 'Default content',
183
+ type: 'fragment',
184
+ children: [
185
+ {
186
+ type: 'text',
187
+ value: 'Default content',
188
+ },
189
+ ],
203
190
  },
204
191
  },
205
192
  variants: [
206
193
  {
207
194
  node: {
208
195
  nodeId: (0, crypto_1.randomUUID)(),
209
- type: 'text',
210
- value: 'Variant content',
196
+ type: 'fragment',
197
+ children: [
198
+ {
199
+ type: 'text',
200
+ value: 'Variant content',
201
+ },
202
+ ],
211
203
  },
212
204
  conditions: {
213
205
  segment: {
@@ -224,7 +216,7 @@ describe('assertIsPageLayout', () => {
224
216
  });
225
217
  it('should not allow variation nodes with no variants', () => {
226
218
  const layout = {
227
- name: 'single-column',
219
+ name: 'layout-raw',
228
220
  content: {
229
221
  main: [
230
222
  {
@@ -245,7 +237,7 @@ describe('assertIsPageLayout', () => {
245
237
  ['experiment', { experiment: { id: 'experiment-1', variant: 'A' } }],
246
238
  ])('should not allow variants with duplicate %s condition', (description, conditions) => {
247
239
  const layout = {
248
- name: 'single-column',
240
+ name: 'layout-raw',
249
241
  content: {
250
242
  main: [
251
243
  {
@@ -258,16 +250,26 @@ describe('assertIsPageLayout', () => {
258
250
  {
259
251
  node: {
260
252
  nodeId: (0, crypto_1.randomUUID)(),
261
- type: 'text',
262
- value: 'Variant content 1',
253
+ type: 'fragment',
254
+ children: [
255
+ {
256
+ type: 'text',
257
+ value: 'Variant content 1',
258
+ },
259
+ ],
263
260
  },
264
261
  conditions,
265
262
  },
266
263
  {
267
264
  node: {
268
265
  nodeId: (0, crypto_1.randomUUID)(),
269
- type: 'text',
270
- value: 'Variant content 2',
266
+ type: 'fragment',
267
+ children: [
268
+ {
269
+ type: 'text',
270
+ value: 'Variant content 2',
271
+ },
272
+ ],
271
273
  },
272
274
  conditions,
273
275
  },
@@ -292,7 +294,7 @@ describe('assertIsPageLayout', () => {
292
294
  ],
293
295
  ])('should allow variants with non-duplication %s conditions', (description, firstConditions, secondConditions) => {
294
296
  const layout = {
295
- name: 'single-column',
297
+ name: 'layout-raw',
296
298
  content: {
297
299
  main: [
298
300
  {
@@ -305,16 +307,26 @@ describe('assertIsPageLayout', () => {
305
307
  {
306
308
  node: {
307
309
  nodeId: (0, crypto_1.randomUUID)(),
308
- type: 'text',
309
- value: 'Variant content 1',
310
+ type: 'fragment',
311
+ children: [
312
+ {
313
+ type: 'text',
314
+ value: 'Variant content 1',
315
+ },
316
+ ],
310
317
  },
311
318
  conditions: firstConditions,
312
319
  },
313
320
  {
314
321
  node: {
315
322
  nodeId: (0, crypto_1.randomUUID)(),
316
- type: 'text',
317
- value: 'Variant content 2',
323
+ type: 'fragment',
324
+ children: [
325
+ {
326
+ type: 'text',
327
+ value: 'Variant content 2',
328
+ },
329
+ ],
318
330
  },
319
331
  conditions: secondConditions,
320
332
  },
@@ -401,8 +413,8 @@ describe('assertIsPageLayout', () => {
401
413
  },
402
414
  content: {
403
415
  main: [
404
- { type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
405
- { type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
416
+ { type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
417
+ { type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
406
418
  ],
407
419
  },
408
420
  };
@@ -428,8 +440,8 @@ describe('assertIsPageLayout', () => {
428
440
  },
429
441
  content: {
430
442
  main: [
431
- { type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
432
- { type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
443
+ { type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
444
+ { type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
433
445
  ],
434
446
  },
435
447
  };
@@ -447,8 +459,8 @@ describe('assertIsPageLayout', () => {
447
459
  },
448
460
  content: {
449
461
  main: [
450
- { type: 'text', value: 'First Node', nodeId: (0, crypto_1.randomUUID)() },
451
- { type: 'text', value: 'Second Node', nodeId: (0, crypto_1.randomUUID)() },
462
+ { type: 'fragment', children: [{ type: 'text', value: 'First Node' }], nodeId: (0, crypto_1.randomUUID)() },
463
+ { type: 'fragment', children: [{ type: 'text', value: 'Second Node' }], nodeId: (0, crypto_1.randomUUID)() },
452
464
  ],
453
465
  },
454
466
  };
@@ -466,56 +478,24 @@ describe('PageLayoutContentResolver', () => {
466
478
  it('should resolve nested component nodes', async () => {
467
479
  const layoutContent = [
468
480
  {
469
- type: 'tag',
470
- tag: 'div',
471
- children: [mocks_1.VALID_CONTENT_NODES.component],
472
- nodeId: (0, crypto_1.randomUUID)(),
473
- },
474
- ];
475
- const resolver = new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver });
476
- const resolvedContent = await resolver.resolve(layoutContent);
477
- expect(resolvedContent).toEqual([
478
- {
479
- type: 'tag',
480
- nodeId: expect.any(String),
481
- tag: 'div',
482
- children: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
483
- },
484
- ]);
485
- });
486
- it('should resolve nested component nodes in multiple levels', async () => {
487
- const layoutContent = [
488
- {
489
- type: 'tag',
490
- tag: 'div',
481
+ type: 'variation',
482
+ default: {
483
+ node: mocks_1.VALID_CONTENT_NODES.component,
484
+ },
491
485
  nodeId: (0, crypto_1.randomUUID)(),
492
- children: [
493
- mocks_1.VALID_CONTENT_NODES.component,
494
- {
495
- nodeId: (0, crypto_1.randomUUID)(),
496
- type: 'tag',
497
- tag: 'div',
498
- children: [mocks_1.VALID_CONTENT_NODES.component],
499
- },
500
- ],
486
+ variants: [],
501
487
  },
502
488
  ];
503
489
  const resolver = new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver });
504
490
  const resolvedContent = await resolver.resolve(layoutContent);
505
491
  expect(resolvedContent).toEqual([
506
492
  {
507
- type: 'tag',
508
- tag: 'div',
493
+ type: 'variation',
509
494
  nodeId: expect.any(String),
510
- children: [
511
- expect.objectContaining({ contentItem: mocks_1.mockContentItem }),
512
- {
513
- type: 'tag',
514
- nodeId: expect.any(String),
515
- tag: 'div',
516
- children: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
517
- },
518
- ],
495
+ default: {
496
+ node: expect.objectContaining({ contentItem: mocks_1.mockContentItem }),
497
+ },
498
+ variants: [],
519
499
  },
520
500
  ]);
521
501
  });
@@ -560,16 +540,16 @@ describe('resolveLayout', () => {
560
540
  },
561
541
  });
562
542
  });
563
- it('should resolve a single-column layout', async () => {
543
+ it('should resolve a layout-raw layout', async () => {
564
544
  const layout = {
565
- name: 'single-column',
545
+ name: 'layout-raw',
566
546
  content: {
567
547
  main: [mocks_1.VALID_CONTENT_NODES.component],
568
548
  },
569
549
  };
570
550
  const resolvedLayout = await (0, page_contents_lib_1.resolveLayout)(layout, new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver }));
571
551
  expect(resolvedLayout).toEqual({
572
- name: 'single-column',
552
+ name: 'layout-raw',
573
553
  content: {
574
554
  main: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
575
555
  },
@@ -602,23 +582,6 @@ describe('resolveLayout', () => {
602
582
  },
603
583
  });
604
584
  });
605
- it('should resolve a two-column layout', async () => {
606
- const layout = {
607
- name: 'two-column',
608
- content: {
609
- left: [mocks_1.VALID_CONTENT_NODES.component],
610
- right: [mocks_1.VALID_CONTENT_NODES.component],
611
- },
612
- };
613
- const resolvedLayout = await (0, page_contents_lib_1.resolveLayout)(layout, new page_contents_lib_1.PageLayoutContentResolver({ component: mocks_1.mockComponentResolver }));
614
- expect(resolvedLayout).toEqual({
615
- name: 'two-column',
616
- content: {
617
- left: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
618
- right: [expect.objectContaining({ contentItem: mocks_1.mockContentItem })],
619
- },
620
- });
621
- });
622
585
  it('should return the layout if does not match resolver', async () => {
623
586
  const layout = {
624
587
  // @ts-expect-error not a layout name
@@ -637,24 +600,22 @@ describe('renderLayout', () => {
637
600
  it.each([
638
601
  [
639
602
  'component',
640
- `<div class="container"><esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/></div>`,
603
+ `<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/>`,
641
604
  ],
642
- ['tag', '<div class="container"><div></div></div>'],
643
- ['text', '<div class="container">test</div>'],
605
+ ['tag', '<div></div>'],
606
+ ['text', 'test'],
644
607
  ])('should render a page layout with a %s node', async (nodeType, expectedHtml) => {
645
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
646
- .addNode(mockNodeFactory.createNode(nodeType))
647
- .build();
608
+ const layout = new mocks_1.PageRawLayoutBuilder().addNode(mockNodeFactory.createNode(nodeType)).build();
648
609
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
649
610
  expect(result).toBe(expectedHtml);
650
611
  });
651
612
  it('should render a page layout with multiple types of nodes', async () => {
652
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
613
+ const layout = new mocks_1.PageRawLayoutBuilder()
653
614
  .addNode(mockNodeFactory.createNode('component'))
654
615
  .addNode(mockNodeFactory.createNode('tag'))
655
616
  .build();
656
617
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
657
- expect(result).toBe(`<div class="container"><esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/><div></div></div>`);
618
+ expect(result).toBe(`<esi:include src="${config.componentRootUrl}/r/my-component-1?_componentSet=my-component-set&_contentItemId=123"/><div></div>`);
658
619
  });
659
620
  it.each([['span', 'div', 'nav', 'article', 'aside', 'header', 'footer']])('should render a page custom-layout with a %s tag replaced', async (tag) => {
660
621
  const layout = new mocks_1.CustomLayoutBuilder({
@@ -688,7 +649,7 @@ describe('renderLayout', () => {
688
649
  type: 'layout',
689
650
  nodeId: (0, crypto_1.randomUUID)(),
690
651
  layout: {
691
- template: '<div class="container custom-class">{{top}}</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
652
+ template: '<div class="container custom-class">{{zones.top}}</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
692
653
  name: 'mock-dev-layout-with-classes',
693
654
  options: {},
694
655
  },
@@ -718,7 +679,7 @@ describe('renderLayout', () => {
718
679
  type: 'layout',
719
680
  nodeId: (0, crypto_1.randomUUID)(),
720
681
  layout: {
721
- template: '<div class="container custom-class">{{top</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
682
+ template: '<div class="container custom-class">{{zones.top</div><div class="section">{{zones.bottom}}</div><div class="sidebar">{{zones.side}}</div>',
722
683
  name: 'mock-dev-layout-with-classes',
723
684
  options: {},
724
685
  },
@@ -742,83 +703,38 @@ describe('renderLayout', () => {
742
703
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
743
704
  expect(normalizeHtml(result)).toBe(normalizeHtml(`<span class=""><span class="test"><p class="invalid-node-type">Error rendering developer template mock-dev-layout-with-classes</p></span></span>`));
744
705
  });
745
- it('should render a developer layout node inside a single-column layout', async () => {
706
+ it('should render a developer layout node inside a layout-raw layout', async () => {
746
707
  const mockBuilder = new mocks_1.MockNodeFactory();
747
708
  const developerLayoutNode = {
748
709
  type: 'layout',
749
710
  nodeId: (0, crypto_1.randomUUID)(),
750
711
  layout: {
751
- template: '<div class="dev-layout">{{content}}</div>',
752
- name: 'dev-layout-in-single-column',
712
+ template: '<div class="dev-layout">{{zones.content}}</div>',
713
+ name: 'dev-layout-in-layout-raw',
753
714
  options: {},
754
715
  },
755
716
  content: {
756
717
  content: [mockBuilder.createNodeWithId('component', 'nested-component')],
757
718
  },
758
719
  };
759
- const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(developerLayoutNode).build();
760
- const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
761
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container"><div class="dev-layout"><esi:include src="${config.componentRootUrl}/r/nested-component?_componentSet=my-component-set&_contentItemId=123"/></div></div>`));
762
- });
763
- it('should render developer layout nodes in a two-column layout', async () => {
764
- const mockBuilder = new mocks_1.MockNodeFactory();
765
- const leftLayoutNode = {
766
- type: 'layout',
767
- nodeId: (0, crypto_1.randomUUID)(),
768
- layout: {
769
- template: '<section class="left-dev-layout">{{content}}</section>',
770
- name: 'dev-layout-left',
771
- options: {},
772
- },
773
- content: {
774
- content: [mockBuilder.createNodeWithId('component', 'left-component')],
775
- },
776
- };
777
- const rightLayoutNode = {
778
- type: 'layout',
779
- nodeId: (0, crypto_1.randomUUID)(),
780
- layout: {
781
- template: '<aside class="right-dev-layout">{{content}}</aside>',
782
- name: 'dev-layout-right',
783
- options: {},
784
- },
785
- content: {
786
- content: [mockBuilder.createNodeWithId('component', 'right-component')],
787
- },
788
- };
789
- const layout = {
790
- name: 'two-column',
791
- content: {
792
- left: [leftLayoutNode],
793
- right: [rightLayoutNode],
794
- },
795
- };
720
+ const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
796
721
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
797
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
798
- <div class="left">
799
- <section class="left-dev-layout">
800
- <esi:include src="${config.componentRootUrl}/r/left-component?_componentSet=my-component-set&_contentItemId=123"/>
801
- </section>
802
- </div>
803
- <div class="right">
804
- <aside class="right-dev-layout">
805
- <esi:include src="${config.componentRootUrl}/r/right-component?_componentSet=my-component-set&_contentItemId=123"/>
806
- </aside>
807
- </div>
808
- </div>`));
722
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="dev-layout"><esi:include src="${config.componentRootUrl}/r/nested-component?_componentSet=my-component-set&_contentItemId=123"/></div>`));
809
723
  });
810
724
  it('should render a developer layout node with text nodes inside a layout-raw layout', async () => {
811
725
  const developerLayoutNode = {
812
726
  type: 'layout',
813
727
  nodeId: (0, crypto_1.randomUUID)(),
814
728
  layout: {
815
- template: '<article class="article-layout"><h1>{{title}}</h1><div class="content">{{body}}</div></article>',
729
+ template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
816
730
  name: 'article-layout',
817
731
  options: {},
818
732
  },
819
733
  content: {
820
- title: [{ type: 'text', value: 'Article Title', nodeId: (0, crypto_1.randomUUID)() }],
821
- body: [{ type: 'text', value: 'Article content goes here.', nodeId: (0, crypto_1.randomUUID)() }],
734
+ title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
735
+ body: [
736
+ { type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
737
+ ],
822
738
  },
823
739
  };
824
740
  const layout = {
@@ -836,7 +752,7 @@ describe('renderLayout', () => {
836
752
  type: 'layout',
837
753
  nodeId: (0, crypto_1.randomUUID)(),
838
754
  layout: {
839
- template: '<div class="inner-layout">{{innerContent}}</div>',
755
+ template: '<div class="inner-layout">{{zones.innerContent}}</div>',
840
756
  name: 'inner-dev-layout',
841
757
  options: {},
842
758
  },
@@ -848,7 +764,7 @@ describe('renderLayout', () => {
848
764
  type: 'layout',
849
765
  nodeId: (0, crypto_1.randomUUID)(),
850
766
  layout: {
851
- template: '<div class="outer-layout">{{outerContent}}</div>',
767
+ template: '<div class="outer-layout">{{zones.outerContent}}</div>',
852
768
  name: 'outer-dev-layout',
853
769
  options: {},
854
770
  },
@@ -856,15 +772,14 @@ describe('renderLayout', () => {
856
772
  outerContent: [innerLayoutNode],
857
773
  },
858
774
  };
859
- const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(outerLayoutNode).build();
775
+ const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayoutNode).build();
860
776
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
861
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
777
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`
862
778
  <div class="outer-layout">
863
779
  <div class="inner-layout">
864
780
  <esi:include src="${config.componentRootUrl}/r/inner-component?_componentSet=my-component-set&_contentItemId=123"/>
865
781
  </div>
866
- </div>
867
- </div>`));
782
+ </div>`));
868
783
  });
869
784
  it('should handle deeply nested layout nodes', async () => {
870
785
  const mockBuilder = new mocks_1.MockNodeFactory();
@@ -872,7 +787,7 @@ describe('renderLayout', () => {
872
787
  nodeId: (0, crypto_1.randomUUID)(),
873
788
  type: 'layout',
874
789
  layout: {
875
- template: '<section class="level-3">{{content}}</section>',
790
+ template: '<section class="level-3">{{zones.content}}</section>',
876
791
  name: 'level-3-layout',
877
792
  options: {},
878
793
  },
@@ -884,7 +799,7 @@ describe('renderLayout', () => {
884
799
  nodeId: (0, crypto_1.randomUUID)(),
885
800
  type: 'layout',
886
801
  layout: {
887
- template: '<article class="level-2">{{nestedContent}}</article>',
802
+ template: '<article class="level-2">{{zones.nestedContent}}</article>',
888
803
  name: 'level-2-layout',
889
804
  options: {},
890
805
  },
@@ -896,7 +811,7 @@ describe('renderLayout', () => {
896
811
  nodeId: (0, crypto_1.randomUUID)(),
897
812
  type: 'layout',
898
813
  layout: {
899
- template: '<div class="level-1">{{rootContent}}</div>',
814
+ template: '<div class="level-1">{{zones.rootContent}}</div>',
900
815
  name: 'level-1-layout',
901
816
  options: {},
902
817
  },
@@ -925,12 +840,12 @@ describe('renderLayout', () => {
925
840
  type: 'layout',
926
841
  nodeId: (0, crypto_1.randomUUID)(),
927
842
  layout: {
928
- template: '<div class="inner-mixed"><h2>{{heading}}</h2><div>{{content}}</div></div>',
843
+ template: '<div class="inner-mixed"><h2>{{zones.heading}}</h2><div>{{zones.content}}</div></div>',
929
844
  name: 'inner-mixed-layout',
930
845
  options: {},
931
846
  },
932
847
  content: {
933
- heading: [{ type: 'text', value: 'Inner Heading', nodeId: (0, crypto_1.randomUUID)() }],
848
+ heading: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner Heading' }], nodeId: (0, crypto_1.randomUUID)() }],
934
849
  content: [mockBuilder.createNodeWithId('component', 'inner-mixed-component')],
935
850
  },
936
851
  };
@@ -938,19 +853,20 @@ describe('renderLayout', () => {
938
853
  type: 'layout',
939
854
  nodeId: (0, crypto_1.randomUUID)(),
940
855
  layout: {
941
- template: '<div class="outer-mixed"><div class="intro">{{intro}}</div><div class="main">{{main}}</div></div>',
856
+ template: '<div class="outer-mixed"><div class="intro">{{zones.intro}}</div><div class="main">{{zones.main}}</div></div>',
942
857
  name: 'outer-mixed-layout',
943
858
  options: {},
944
859
  },
945
860
  content: {
946
- intro: [{ type: 'text', value: '<p>Introduction text</p>', nodeId: (0, crypto_1.randomUUID)() }],
861
+ intro: [
862
+ { type: 'fragment', children: [{ type: 'text', value: '<p>Introduction text</p>' }], nodeId: (0, crypto_1.randomUUID)() },
863
+ ],
947
864
  main: [innerLayout],
948
865
  },
949
866
  };
950
- const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(outerLayout).build();
867
+ const layout = new mocks_1.PageRawLayoutBuilder().addNode(outerLayout).build();
951
868
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config);
952
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
953
- <div class="outer-mixed">
869
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-mixed">
954
870
  <div class="intro"><p>Introduction text</p></div>
955
871
  <div class="main">
956
872
  <div class="inner-mixed">
@@ -960,8 +876,95 @@ describe('renderLayout', () => {
960
876
  </div>
961
877
  </div>
962
878
  </div>
963
- </div>
964
- </div>`));
879
+ </div>`));
880
+ });
881
+ it('should add HTML comments for developer defined layouts in preview mode', async () => {
882
+ const developerLayoutNode = {
883
+ type: 'layout',
884
+ nodeId: (0, crypto_1.randomUUID)(),
885
+ layout: {
886
+ template: '<article class="article-layout"><h1>{{zones.title}}</h1><div class="content">{{zones.body}}</div></article>',
887
+ name: 'article-layout',
888
+ options: {},
889
+ },
890
+ content: {
891
+ title: [{ type: 'fragment', children: [{ type: 'text', value: 'Article Title' }], nodeId: (0, crypto_1.randomUUID)() }],
892
+ body: [
893
+ { type: 'fragment', children: [{ type: 'text', value: 'Article content goes here.' }], nodeId: (0, crypto_1.randomUUID)() },
894
+ ],
895
+ },
896
+ };
897
+ const contentPage = {
898
+ name: 'layout-raw',
899
+ content: {
900
+ main: [developerLayoutNode],
901
+ },
902
+ };
903
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
904
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<!-- start:layout:article-layout:${developerLayoutNode.nodeId} --><article class="article-layout"><h1><!-- start:zone:title:${developerLayoutNode.nodeId} -->Article Title<!-- end:zone:title:${developerLayoutNode.nodeId} --></h1><div class="content"><!-- start:zone:body:${developerLayoutNode.nodeId} -->Article content goes here.<!-- end:zone:body:${developerLayoutNode.nodeId} --></div></article><!-- end:layout:article-layout:${developerLayoutNode.nodeId} -->`));
905
+ });
906
+ it('should use the correct nodeId in the HTML comments for nested layouts', async () => {
907
+ const innerLayoutNode = {
908
+ type: 'layout',
909
+ nodeId: (0, crypto_1.randomUUID)(),
910
+ layout: {
911
+ template: '<div class="inner-layout">{{zones.content}}</div>',
912
+ name: 'inner-layout',
913
+ options: {},
914
+ },
915
+ content: {
916
+ content: [{ type: 'fragment', children: [{ type: 'text', value: 'Inner content' }], nodeId: (0, crypto_1.randomUUID)() }],
917
+ },
918
+ };
919
+ const developerLayoutNode = {
920
+ type: 'layout',
921
+ nodeId: (0, crypto_1.randomUUID)(),
922
+ layout: {
923
+ template: '<div class="outer-layout">{{zones.content}}</div>',
924
+ name: 'outer-layout',
925
+ options: {},
926
+ },
927
+ content: {
928
+ content: [innerLayoutNode],
929
+ },
930
+ };
931
+ const contentPage = {
932
+ name: 'layout-raw',
933
+ content: {
934
+ main: [developerLayoutNode],
935
+ },
936
+ };
937
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, { ...config, isPreview: true });
938
+ const expectedInnerHtml = `<!-- start:layout:inner-layout:${innerLayoutNode.nodeId} --><div class="inner-layout"><!-- start:zone:content:${innerLayoutNode.nodeId} -->Inner content<!-- end:zone:content:${innerLayoutNode.nodeId} --></div><!-- end:layout:inner-layout:${innerLayoutNode.nodeId} -->`;
939
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<!-- start:layout:outer-layout:${developerLayoutNode.nodeId} --><div class="outer-layout"><!-- start:zone:content:${developerLayoutNode.nodeId} -->${expectedInnerHtml}<!-- end:zone:content:${developerLayoutNode.nodeId} --></div><!-- end:layout:outer-layout:${developerLayoutNode.nodeId} -->`));
940
+ });
941
+ it('should allow fragment nodes in layout content', async () => {
942
+ const developerLayoutNode = {
943
+ type: 'layout',
944
+ nodeId: (0, crypto_1.randomUUID)(),
945
+ layout: {
946
+ template: '<div class="outer-layout">{{zones.content}}</div>',
947
+ name: 'outer-layout',
948
+ options: {},
949
+ },
950
+ content: {
951
+ content: [
952
+ {
953
+ type: 'fragment',
954
+ children: [{ type: 'text', value: 'Fragment content' }],
955
+ nodeId: (0, crypto_1.randomUUID)(),
956
+ },
957
+ ],
958
+ },
959
+ };
960
+ const contentPage = {
961
+ name: 'layout-raw',
962
+ content: {
963
+ main: [developerLayoutNode],
964
+ },
965
+ };
966
+ const result = await (0, page_contents_lib_1.renderLayout)(contentPage, config);
967
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="outer-layout">Fragment content</div>`));
965
968
  });
966
969
  describe('with language translation', () => {
967
970
  const langConfig = {
@@ -972,7 +975,7 @@ describe('renderLayout', () => {
972
975
  },
973
976
  };
974
977
  it('should render translated fragment nodes', async () => {
975
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
978
+ const layout = new mocks_1.PageRawLayoutBuilder()
976
979
  .addNode({
977
980
  nodeId: (0, crypto_1.randomUUID)(),
978
981
  type: 'fragment',
@@ -980,7 +983,6 @@ describe('renderLayout', () => {
980
983
  {
981
984
  type: 'text',
982
985
  value: 'English text',
983
- nodeId: (0, crypto_1.randomUUID)(),
984
986
  },
985
987
  ],
986
988
  i18n: {
@@ -996,10 +998,10 @@ describe('renderLayout', () => {
996
998
  })
997
999
  .build();
998
1000
  const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
999
- expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">French text</div>'));
1001
+ expect(normalizeHtml(result)).toBe(normalizeHtml('French text'));
1000
1002
  });
1001
1003
  it('should render translated component nodes', async () => {
1002
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
1004
+ const layout = new mocks_1.PageRawLayoutBuilder()
1003
1005
  .addNode({
1004
1006
  nodeId: (0, crypto_1.randomUUID)(),
1005
1007
  type: 'component',
@@ -1013,10 +1015,10 @@ describe('renderLayout', () => {
1013
1015
  })
1014
1016
  .build();
1015
1017
  const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1016
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container"><esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/></div>`));
1018
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-content"/>`));
1017
1019
  });
1018
1020
  it('should render mixed translated and untranslated nodes', async () => {
1019
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
1021
+ const layout = new mocks_1.PageRawLayoutBuilder()
1020
1022
  .addNode({
1021
1023
  // Translated fragment
1022
1024
  nodeId: (0, crypto_1.randomUUID)(),
@@ -1025,7 +1027,6 @@ describe('renderLayout', () => {
1025
1027
  {
1026
1028
  type: 'text',
1027
1029
  value: 'English text',
1028
- nodeId: (0, crypto_1.randomUUID)(),
1029
1030
  },
1030
1031
  ],
1031
1032
  i18n: {
@@ -1050,14 +1051,14 @@ describe('renderLayout', () => {
1050
1051
  })
1051
1052
  .build();
1052
1053
  const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1053
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/></div>`));
1054
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`French text<esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=en-content"/>`));
1054
1055
  });
1055
1056
  it('should render developer layout with translated content', async () => {
1056
1057
  const developerLayoutNode = {
1057
1058
  type: 'layout',
1058
1059
  nodeId: (0, crypto_1.randomUUID)(),
1059
1060
  layout: {
1060
- template: '<div class="top">{{top}}</div><div class="side">{{side}}</div>',
1061
+ template: '<div class="top">{{zones.top}}</div><div class="side">{{zones.side}}</div>',
1061
1062
  name: 'article-layout',
1062
1063
  options: {},
1063
1064
  },
@@ -1090,19 +1091,19 @@ describe('renderLayout', () => {
1090
1091
  ],
1091
1092
  },
1092
1093
  };
1093
- const layout = new mocks_1.PageSingleColumLayoutBuilder().addNode(developerLayoutNode).build();
1094
+ const layout = new mocks_1.PageRawLayoutBuilder().addNode(developerLayoutNode).build();
1094
1095
  const result = await (0, page_contents_lib_1.renderLayout)(layout, langConfig);
1095
- expect(normalizeHtml(result)).toBe(normalizeHtml(`<div class="container">
1096
+ expect(normalizeHtml(result)).toBe(normalizeHtml(`
1096
1097
  <div class="top">
1097
1098
  <esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-top"/>
1098
1099
  </div>
1099
1100
  <div class="side">
1100
1101
  <esi:include src="${config.componentRootUrl}/r/test/component/1.0.0?_componentSet=test-set&_contentItemId=fr-side"/>
1101
1102
  </div>
1102
- </div>`));
1103
+ `));
1103
1104
  });
1104
1105
  it('should render layout with no translations when language config is missing', async () => {
1105
- const layout = new mocks_1.PageSingleColumLayoutBuilder()
1106
+ const layout = new mocks_1.PageRawLayoutBuilder()
1106
1107
  .addNode({
1107
1108
  nodeId: (0, crypto_1.randomUUID)(),
1108
1109
  type: 'fragment',
@@ -1110,7 +1111,6 @@ describe('renderLayout', () => {
1110
1111
  {
1111
1112
  type: 'text',
1112
1113
  value: 'English text',
1113
- nodeId: (0, crypto_1.randomUUID)(),
1114
1114
  },
1115
1115
  ],
1116
1116
  i18n: {
@@ -1119,7 +1119,6 @@ describe('renderLayout', () => {
1119
1119
  {
1120
1120
  type: 'text',
1121
1121
  value: 'French text',
1122
- nodeId: (0, crypto_1.randomUUID)(),
1123
1122
  },
1124
1123
  ],
1125
1124
  },
@@ -1127,31 +1126,11 @@ describe('renderLayout', () => {
1127
1126
  })
1128
1127
  .build();
1129
1128
  const result = await (0, page_contents_lib_1.renderLayout)(layout, config); // Using config without lang
1130
- expect(normalizeHtml(result)).toBe(normalizeHtml('<div class="container">English text</div>'));
1129
+ expect(normalizeHtml(result)).toBe(normalizeHtml('English text'));
1131
1130
  });
1132
1131
  });
1133
1132
  });
1134
1133
  describe('Helper functions', () => {
1135
- it('isDeveloperDefinedLayoutNode returns true for valid developer layouts', () => {
1136
- const layoutNode = {
1137
- type: 'layout',
1138
- layout: {
1139
- template: '<div class="container custom-class">{{top}}</div><div class="section">{{bottom}}</div><div class="sidebar">{{side}}</div>',
1140
- name: 'mock-dev-layout-with-classes',
1141
- options: {},
1142
- },
1143
- content: {
1144
- top: [],
1145
- },
1146
- };
1147
- expect((0, page_contents_lib_1.isDeveloperDefinedLayoutNode)(layoutNode)).toEqual(true);
1148
- });
1149
- it('isDeveloperDefinedLayoutNode returns false for invalid developer layouts', () => {
1150
- const layoutNode = {
1151
- foo: 'bar',
1152
- };
1153
- expect((0, page_contents_lib_1.isDeveloperDefinedLayoutNode)(layoutNode)).toEqual(false);
1154
- });
1155
1134
  it('isCustomLayout returns true for valid custom layouts', () => {
1156
1135
  const layout = new mocks_1.CustomLayoutBuilder({
1157
1136
  rootWrapper: {
@@ -1311,8 +1290,8 @@ describe('translateLanguageNodes', () => {
1311
1290
  default: {
1312
1291
  node: {
1313
1292
  nodeId: (0, crypto_1.randomUUID)(),
1314
- type: 'text',
1315
- value: 'Default text',
1293
+ type: 'fragment',
1294
+ children: [{ type: 'text', value: 'Default text' }],
1316
1295
  },
1317
1296
  },
1318
1297
  variants: [],
@@ -1343,7 +1322,6 @@ describe('translateLanguageNodes', () => {
1343
1322
  {
1344
1323
  type: 'text',
1345
1324
  value: 'English text',
1346
- nodeId: (0, crypto_1.randomUUID)(),
1347
1325
  },
1348
1326
  ],
1349
1327
  i18n: {
@@ -1352,7 +1330,6 @@ describe('translateLanguageNodes', () => {
1352
1330
  {
1353
1331
  type: 'text',
1354
1332
  value: 'Spanish text',
1355
- nodeId: (0, crypto_1.randomUUID)(),
1356
1333
  },
1357
1334
  ],
1358
1335
  },
@@ -1569,7 +1546,7 @@ describe('translateLanguageNodes', () => {
1569
1546
  nodeId: (0, crypto_1.randomUUID)(),
1570
1547
  type: 'layout',
1571
1548
  layout: {
1572
- template: '<div>{{content}}</div>',
1549
+ template: '<div>{{zones.content}}</div>',
1573
1550
  name: 'test-layout',
1574
1551
  options: {},
1575
1552
  },
@@ -1627,7 +1604,7 @@ describe('translateLanguageNodes', () => {
1627
1604
  nodeId: (0, crypto_1.randomUUID)(),
1628
1605
  type: 'layout',
1629
1606
  layout: {
1630
- template: '<div><h1>{{title}}</h1><div>{{content}}</div></div>',
1607
+ template: '<div><h1>{{zones.title}}</h1><div>{{zones.content}}</div></div>',
1631
1608
  name: 'test-layout',
1632
1609
  options: {},
1633
1610
  },
@@ -1673,7 +1650,7 @@ describe('translateLanguageNodes', () => {
1673
1650
  nodeId: (0, crypto_1.randomUUID)(),
1674
1651
  type: 'layout',
1675
1652
  layout: {
1676
- template: '<div>{{inner}}</div>',
1653
+ template: '<div>{{zones.inner}}</div>',
1677
1654
  name: 'inner-layout',
1678
1655
  options: {},
1679
1656
  },
@@ -1689,7 +1666,7 @@ describe('translateLanguageNodes', () => {
1689
1666
  nodeId: (0, crypto_1.randomUUID)(),
1690
1667
  type: 'layout',
1691
1668
  layout: {
1692
- template: '<div>{{outer}}</div>',
1669
+ template: '<div>{{zones.outer}}</div>',
1693
1670
  name: 'outer-layout',
1694
1671
  options: {},
1695
1672
  },